20 #include <linux/module.h>
27 #define TX_ECHO_SKB_MAX (((TXMAX+1)/2)-1)
33 static inline int canif_is_active(
struct net_device *netdev)
35 struct can_priv *can = netdev_priv(netdev);
37 if (!netif_running(netdev))
43 static inline void softing_set_reset_dpram(
struct softing *
card)
45 if (card->
pdat->generation >= 2) {
46 spin_lock_bh(&card->
spin);
49 spin_unlock_bh(&card->
spin);
53 static inline void softing_clr_reset_dpram(
struct softing *card)
55 if (card->
pdat->generation >= 2) {
56 spin_lock_bh(&card->
spin);
59 spin_unlock_bh(&card->
spin);
75 if (can_dropped_invalid_skb(dev, skb))
78 spin_lock(&card->
spin);
87 if (fifo_wr == fifo_rd)
101 *ptr++ = (cf->
can_id >> 0);
102 *ptr++ = (cf->
can_id >> 8);
104 *ptr++ = (cf->
can_id >> 16);
105 *ptr++ = (cf->
can_id >> 24);
117 card->
tx.last_bus = priv->
index;
123 priv->
tx.echo_put = 0;
127 spin_unlock(&card->
spin);
128 if (card->
tx.pending >=
TXMAX) {
132 netif_stop_queue(card->
net[j]);
136 netif_stop_queue(dev);
153 memcpy(cf, msg,
sizeof(*msg));
162 static int softing_handle_1(
struct softing *card)
168 int cnt = 0, lost_msg;
190 netdev = card->
net[
j];
193 if (!canif_is_active(netdev))
196 ++netdev->
stats.rx_over_errors;
209 if (fifo_wr == fifo_rd)
223 netdev = card->
net[0];
225 netdev = card->
net[1];
226 priv = netdev_priv(netdev);
258 ++netdev->
stats.rx_errors;
260 if (can_state != priv->
can.state) {
263 ++priv->
can.can_stats.error_passive;
267 netif_stop_queue(netdev);
296 skb = priv->
can.echo_skb[priv->
tx.echo_get];
302 priv->
tx.echo_get = 0;
303 if (priv->
tx.pending)
305 if (card->
tx.pending)
307 ++netdev->
stats.tx_packets;
309 netdev->
stats.tx_bytes +=
msg.can_dlc;
315 ++netdev->
stats.rx_packets;
317 netdev->
stats.rx_bytes +=
msg.can_dlc;
319 ++netdev->
stats.rx_dropped;
338 spin_lock_bh(&card->
spin);
339 while (softing_handle_1(card) > 0) {
340 ++card->
irq.svc_count;
343 spin_unlock_bh(&card->
spin);
345 offset = card->
tx.last_bus;
349 netdev = card->
net[(j + offset + 1) % card->
pdat->nbus];
352 priv = netdev_priv(netdev);
353 if (!canif_is_active(netdev))
359 netif_wake_queue(netdev);
368 static irqreturn_t softing_irq_v2(
int irq,
void *dev_id)
378 static irqreturn_t softing_irq_v1(
int irq,
void *dev_id)
402 static int softing_netdev_stop(
struct net_device *ndev)
406 netif_stop_queue(ndev);
438 }
else if (card->
irq.requested && !enable) {
440 card->
irq.requested = 0;
441 }
else if (!card->
irq.requested && enable) {
443 (card->
pdat->generation >= 2) ?
444 softing_irq_v2 : softing_irq_v1,
446 dev_name(&card->
pdev->dev), card);
448 dev_alert(&card->
pdev->dev,
449 "request_threaded_irq(%u) failed\n",
453 card->
irq.requested = 1;
458 static void softing_card_shutdown(
struct softing *card)
467 if (card->
irq.requested && card->
irq.nr) {
469 card->
irq.requested = 0;
472 if (card->
pdat->enable_irq)
473 card->
pdat->enable_irq(card->
pdev, 0);
474 softing_set_reset_dpram(card);
475 if (card->
pdat->reset)
485 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, };
486 unsigned char back[
sizeof(stream)];
495 if (card->
pdat->enable_irq)
496 card->
pdat->enable_irq(card->
pdev, 1);
498 softing_set_reset_dpram(card);
499 if (card->
pdat->reset)
501 for (j = 0; (j +
sizeof(stream)) < card->
dpram_size;
502 j +=
sizeof(stream)) {
509 if (!
memcmp(back, stream,
sizeof(stream)))
512 dev_alert(&card->
pdev->dev,
"dpram failed at 0x%04x\n", j);
520 card->
pdat->boot.offs - card->
pdat->boot.addr);
526 card->
pdat->load.offs - card->
pdat->load.addr);
530 if (card->
pdat->reset)
532 softing_clr_reset_dpram(card);
549 if (card->
pdat->enable_irq)
550 card->
pdat->enable_irq(card->
pdev, 0);
551 softing_set_reset_dpram(card);
552 if (card->
pdat->reset)
589 const char *buf,
size_t count)
605 if (netif_running(ndev)) {
618 static const struct attribute *
const netdev_sysfs_attrs[] = {
619 &dev_attr_channel.attr,
621 &dev_attr_output.attr,
626 .attrs = (
struct attribute **)netdev_sysfs_attrs,
630 .ndo_open = softing_netdev_open,
631 .ndo_stop = softing_netdev_stop,
632 .ndo_start_xmit = softing_netdev_start_xmit,
656 dev_alert(&card->
pdev->dev,
"alloc_candev failed\n");
659 priv = netdev_priv(netdev);
666 priv->
can.clock.freq = 8000000;
667 priv->
chip = chip_id;
673 priv->
can.do_set_mode = softing_candev_set_mode;
686 dev_alert(&netdev->
dev,
"register failed\n");
692 static void softing_netdev_cleanup(
struct net_device *netdev)
701 #define DEV_ATTR_RO(name, member) \
702 static ssize_t show_##name(struct device *dev, \
703 struct device_attribute *attr, char *buf) \
705 struct softing *card = platform_get_drvdata(to_platform_device(dev)); \
706 return sprintf(buf, "%u\n", card->member); \
708 static DEVICE_ATTR(name, 0444, show_##name, NULL)
710 #define DEV_ATTR_RO_STR(name, member) \
711 static ssize_t show_##name(struct device *dev, \
712 struct device_attribute *attr, char *buf) \
714 struct softing *card = platform_get_drvdata(to_platform_device(dev)); \
715 return sprintf(buf, "%s\n", card->member); \
717 static DEVICE_ATTR(name, 0444, show_##name, NULL)
728 static struct attribute *softing_pdev_attrs[] = {
729 &dev_attr_serial.attr,
730 &dev_attr_firmware.attr,
731 &dev_attr_firmware_version.attr,
732 &dev_attr_hardware.attr,
733 &dev_attr_hardware_version.attr,
734 &dev_attr_license.attr,
735 &dev_attr_frequency.attr,
736 &dev_attr_txpending.attr,
742 .attrs = softing_pdev_attrs,
750 struct softing *card = platform_get_drvdata(pdev);
754 softing_card_shutdown(card);
759 softing_netdev_cleanup(card->
net[j]);
793 platform_set_drvdata(pdev, card);
800 goto platform_resource_failed;
805 dev_alert(&card->
pdev->dev,
"dpram ioremap failed\n");
814 ret = softing_card_boot(card);
816 dev_alert(&pdev->
dev,
"failed to boot\n");
821 card->
id.freq = card->
pdat->freq;
825 dev_alert(&card->
pdev->dev,
"sysfs failed\n");
830 card->
net[
j] = netdev =
831 softing_netdev_create(card, card->
id.chip[j]);
833 dev_alert(&pdev->
dev,
"failed to make can[%i]", j);
837 priv = netdev_priv(card->
net[j]);
839 ret = softing_netdev_register(netdev);
843 dev_alert(&card->
pdev->dev,
844 "failed to register can[%i]\n", j);
855 softing_netdev_cleanup(card->
net[j]);
859 softing_card_shutdown(card);
863 platform_resource_failed:
873 .probe = softing_pdev_probe,