Lines Matching refs:dev
24 #include <linux/can/dev.h>
313 static void at91_setup_mailboxes(struct net_device *dev)
315 struct at91_priv *priv = netdev_priv(dev);
352 static int at91_set_bittiming(struct net_device *dev)
354 const struct at91_priv *priv = netdev_priv(dev);
363 netdev_info(dev, "writing AT91_BR: 0x%08x\n", reg_br);
370 static int at91_get_berr_counter(const struct net_device *dev,
373 const struct at91_priv *priv = netdev_priv(dev);
382 static void at91_chip_start(struct net_device *dev)
384 struct at91_priv *priv = netdev_priv(dev);
394 at91_set_bittiming(dev);
395 at91_setup_mailboxes(dev);
412 static void at91_chip_stop(struct net_device *dev, enum can_state state)
414 struct at91_priv *priv = netdev_priv(dev);
449 static netdev_tx_t at91_start_xmit(struct sk_buff *skb, struct net_device *dev)
451 struct at91_priv *priv = netdev_priv(dev);
452 struct net_device_stats *stats = &dev->stats;
457 if (can_dropped_invalid_skb(dev, skb))
464 netif_stop_queue(dev);
466 netdev_err(dev, "BUG! TX buffer full when queue awake!\n");
487 can_put_echo_skb(skb, dev, mb - get_mb_tx_first(priv));
501 netif_stop_queue(dev);
537 * @dev: net device
539 static void at91_rx_overflow_err(struct net_device *dev)
541 struct net_device_stats *stats = &dev->stats;
545 netdev_dbg(dev, "RX buffer overflow\n");
549 skb = alloc_can_err_skb(dev, &cf);
563 * @dev: net device
570 static void at91_read_mb(struct net_device *dev, unsigned int mb,
573 const struct at91_priv *priv = netdev_priv(dev);
596 at91_rx_overflow_err(dev);
601 * @dev: net device
607 static void at91_read_msg(struct net_device *dev, unsigned int mb)
609 struct net_device_stats *stats = &dev->stats;
613 skb = alloc_can_skb(dev, &cf);
619 at91_read_mb(dev, mb, cf);
625 can_led_event(dev, CAN_LED_EVENT_RX);
630 * @dev: net device
677 static int at91_poll_rx(struct net_device *dev, int quota)
679 struct at91_priv *priv = netdev_priv(dev);
687 netdev_info(dev,
695 at91_read_msg(dev, mb);
720 static void at91_poll_err_frame(struct net_device *dev,
723 struct at91_priv *priv = netdev_priv(dev);
727 netdev_dbg(dev, "CERR irq\n");
728 dev->stats.rx_errors++;
735 netdev_dbg(dev, "SERR irq\n");
736 dev->stats.rx_errors++;
744 netdev_dbg(dev, "AERR irq\n");
745 dev->stats.tx_errors++;
751 netdev_dbg(dev, "FERR irq\n");
752 dev->stats.rx_errors++;
760 netdev_dbg(dev, "BERR irq\n");
761 dev->stats.tx_errors++;
768 static int at91_poll_err(struct net_device *dev, int quota, u32 reg_sr)
776 skb = alloc_can_err_skb(dev, &cf);
780 at91_poll_err_frame(dev, cf, reg_sr);
782 dev->stats.rx_packets++;
783 dev->stats.rx_bytes += cf->can_dlc;
791 struct net_device *dev = napi->dev;
792 const struct at91_priv *priv = netdev_priv(dev);
797 work_done += at91_poll_rx(dev, quota - work_done);
805 work_done += at91_poll_err(dev, quota - work_done, reg_sr);
831 static void at91_irq_tx(struct net_device *dev, u32 reg_sr)
833 struct at91_priv *priv = netdev_priv(dev);
859 can_get_echo_skb(dev, mb - get_mb_tx_first(priv));
860 dev->stats.tx_packets++;
861 can_led_event(dev, CAN_LED_EVENT_TX);
872 netif_wake_queue(dev);
875 static void at91_irq_err_state(struct net_device *dev,
878 struct at91_priv *priv = netdev_priv(dev);
882 at91_get_berr_counter(dev, &bec);
893 netdev_dbg(dev, "Error Warning IRQ\n");
910 netdev_dbg(dev, "Error Passive IRQ\n");
927 netdev_dbg(dev, "restarted\n");
930 netif_carrier_on(dev);
931 netif_wake_queue(dev);
948 netdev_dbg(dev, "Error Active\n");
967 netdev_dbg(dev, "bus-off\n");
968 netif_carrier_off(dev);
973 at91_chip_stop(dev, CAN_STATE_BUS_OFF);
985 static int at91_get_state_by_bec(const struct net_device *dev,
991 err = at91_get_berr_counter(dev, &bec);
1008 static void at91_irq_err(struct net_device *dev)
1010 struct at91_priv *priv = netdev_priv(dev);
1030 netdev_err(dev, "BUG! hardware in undefined state\n");
1034 err = at91_get_state_by_bec(dev, &new_state);
1043 skb = alloc_can_err_skb(dev, &cf);
1047 at91_irq_err_state(dev, cf, new_state);
1049 dev->stats.rx_packets++;
1050 dev->stats.rx_bytes += cf->can_dlc;
1061 struct net_device *dev = dev_id;
1062 struct at91_priv *priv = netdev_priv(dev);
1090 at91_irq_tx(dev, reg_sr);
1092 at91_irq_err(dev);
1098 static int at91_open(struct net_device *dev)
1100 struct at91_priv *priv = netdev_priv(dev);
1108 err = open_candev(dev);
1113 if (request_irq(dev->irq, at91_irq, IRQF_SHARED,
1114 dev->name, dev)) {
1119 can_led_event(dev, CAN_LED_EVENT_OPEN);
1122 at91_chip_start(dev);
1124 netif_start_queue(dev);
1129 close_candev(dev);
1139 static int at91_close(struct net_device *dev)
1141 struct at91_priv *priv = netdev_priv(dev);
1143 netif_stop_queue(dev);
1145 at91_chip_stop(dev, CAN_STATE_STOPPED);
1147 free_irq(dev->irq, dev);
1150 close_candev(dev);
1152 can_led_event(dev, CAN_LED_EVENT_STOP);
1157 static int at91_set_mode(struct net_device *dev, enum can_mode mode)
1161 at91_chip_start(dev);
1162 netif_wake_queue(dev);
1179 static ssize_t at91_sysfs_show_mb0_id(struct device *dev,
1182 struct at91_priv *priv = netdev_priv(to_net_dev(dev));
1190 static ssize_t at91_sysfs_set_mb0_id(struct device *dev,
1193 struct net_device *ndev = to_net_dev(dev);
1253 if (pdev->dev.of_node) {
1256 match = of_match_node(at91_can_dt_ids, pdev->dev.of_node);
1258 dev_err(&pdev->dev, "no matching node found in dtb\n");
1270 struct net_device *dev;
1279 dev_err(&pdev->dev, "no driver data\n");
1284 clk = clk_get(&pdev->dev, "can_clk");
1286 dev_err(&pdev->dev, "no clock defined\n");
1311 dev = alloc_candev(sizeof(struct at91_priv),
1313 if (!dev) {
1318 dev->netdev_ops = &at91_netdev_ops;
1319 dev->irq = irq;
1320 dev->flags |= IFF_ECHO;
1322 priv = netdev_priv(dev);
1332 priv->pdata = dev_get_platdata(&pdev->dev);
1335 netif_napi_add(dev, &priv->napi, at91_poll, get_mb_rx_num(priv));
1338 dev->sysfs_groups[0] = &at91_sysfs_attr_group;
1340 platform_set_drvdata(pdev, dev);
1341 SET_NETDEV_DEV(dev, &pdev->dev);
1343 err = register_candev(dev);
1345 dev_err(&pdev->dev, "registering netdev failed\n");
1349 devm_can_led_init(dev);
1351 dev_info(&pdev->dev, "device registered (reg_base=%p, irq=%d)\n",
1352 priv->reg_base, dev->irq);
1357 free_candev(dev);
1370 struct net_device *dev = platform_get_drvdata(pdev);
1371 struct at91_priv *priv = netdev_priv(dev);
1374 unregister_netdev(dev);
1383 free_candev(dev);