Lines Matching +full:spin +full:- +full:up
1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (C) 2008-2010
5 * - Kurt Van Dijck, EIA Electronics
15 #define TX_ECHO_SKB_MAX (((TXMAX+1)/2)-1)
19 * is online (ie. up 'n running, not sleeping, not busoff
27 return (can->state <= CAN_STATE_ERROR_PASSIVE); in canif_is_active()
33 if (card->pdat->generation >= 2) { in softing_set_reset_dpram()
34 spin_lock_bh(&card->spin); in softing_set_reset_dpram()
35 iowrite8(ioread8(&card->dpram[DPRAM_V2_RESET]) & ~1, in softing_set_reset_dpram()
36 &card->dpram[DPRAM_V2_RESET]); in softing_set_reset_dpram()
37 spin_unlock_bh(&card->spin); in softing_set_reset_dpram()
43 if (card->pdat->generation >= 2) { in softing_clr_reset_dpram()
44 spin_lock_bh(&card->spin); in softing_clr_reset_dpram()
45 iowrite8(ioread8(&card->dpram[DPRAM_V2_RESET]) | 1, in softing_clr_reset_dpram()
46 &card->dpram[DPRAM_V2_RESET]); in softing_clr_reset_dpram()
47 spin_unlock_bh(&card->spin); in softing_clr_reset_dpram()
51 /* trigger the tx queue-ing */
56 struct softing *card = priv->card; in softing_netdev_start_xmit()
60 struct can_frame *cf = (struct can_frame *)skb->data; in softing_netdev_start_xmit()
66 spin_lock(&card->spin); in softing_netdev_start_xmit()
69 if (!card->fw.up || in softing_netdev_start_xmit()
70 (card->tx.pending >= TXMAX) || in softing_netdev_start_xmit()
71 (priv->tx.pending >= TX_ECHO_SKB_MAX)) in softing_netdev_start_xmit()
73 fifo_wr = ioread8(&card->dpram[DPRAM_TX_WR]); in softing_netdev_start_xmit()
74 fifo_rd = ioread8(&card->dpram[DPRAM_TX_RD]); in softing_netdev_start_xmit()
81 if (cf->can_id & CAN_RTR_FLAG) in softing_netdev_start_xmit()
83 if (cf->can_id & CAN_EFF_FLAG) in softing_netdev_start_xmit()
85 if (priv->index) in softing_netdev_start_xmit()
88 *ptr++ = cf->len; in softing_netdev_start_xmit()
89 *ptr++ = (cf->can_id >> 0); in softing_netdev_start_xmit()
90 *ptr++ = (cf->can_id >> 8); in softing_netdev_start_xmit()
91 if (cf->can_id & CAN_EFF_FLAG) { in softing_netdev_start_xmit()
92 *ptr++ = (cf->can_id >> 16); in softing_netdev_start_xmit()
93 *ptr++ = (cf->can_id >> 24); in softing_netdev_start_xmit()
98 if (!(cf->can_id & CAN_RTR_FLAG)) in softing_netdev_start_xmit()
99 memcpy(ptr, &cf->data[0], cf->len); in softing_netdev_start_xmit()
100 memcpy_toio(&card->dpram[DPRAM_TX + DPRAM_TX_SIZE * fifo_wr], in softing_netdev_start_xmit()
104 iowrite8(fifo_wr, &card->dpram[DPRAM_TX_WR]); in softing_netdev_start_xmit()
105 card->tx.last_bus = priv->index; in softing_netdev_start_xmit()
106 ++card->tx.pending; in softing_netdev_start_xmit()
107 ++priv->tx.pending; in softing_netdev_start_xmit()
108 can_put_echo_skb(skb, dev, priv->tx.echo_put, 0); in softing_netdev_start_xmit()
109 ++priv->tx.echo_put; in softing_netdev_start_xmit()
110 if (priv->tx.echo_put >= TX_ECHO_SKB_MAX) in softing_netdev_start_xmit()
111 priv->tx.echo_put = 0; in softing_netdev_start_xmit()
115 spin_unlock(&card->spin); in softing_netdev_start_xmit()
116 if (card->tx.pending >= TXMAX) { in softing_netdev_start_xmit()
118 for (j = 0; j < ARRAY_SIZE(card->net); ++j) { in softing_netdev_start_xmit()
119 if (card->net[j]) in softing_netdev_start_xmit()
120 netif_stop_queue(card->net[j]); in softing_netdev_start_xmit()
140 return -ENOMEM; in softing_netdev_rx()
142 skb->tstamp = ktime; in softing_netdev_rx()
164 lost_msg = ioread8(&card->dpram[DPRAM_RX_LOST]); in softing_handle_1()
168 iowrite8(0, &card->dpram[DPRAM_RX_LOST]); in softing_handle_1()
177 for (j = 0; j < ARRAY_SIZE(card->net); ++j) { in softing_handle_1()
178 netdev = card->net[j]; in softing_handle_1()
184 ++netdev->stats.rx_over_errors; in softing_handle_1()
192 fifo_rd = ioread8(&card->dpram[DPRAM_RX_RD]); in softing_handle_1()
193 fifo_wr = ioread8(&card->dpram[DPRAM_RX_WR]); in softing_handle_1()
200 memcpy_fromio(buf, &card->dpram[DPRAM_RX + DPRAM_RX_SIZE*fifo_rd], in softing_handle_1()
204 iowrite8(fifo_rd, &card->dpram[DPRAM_RX_RD]); in softing_handle_1()
211 netdev = card->net[0]; in softing_handle_1()
213 netdev = card->net[1]; in softing_handle_1()
239 iowrite8(state, &card->dpram[priv->index ? in softing_handle_1()
245 ++netdev->stats.rx_errors; in softing_handle_1()
247 if (can_state != priv->can.state) { in softing_handle_1()
248 priv->can.state = can_state; in softing_handle_1()
250 ++priv->can.can_stats.error_passive; in softing_handle_1()
253 ++priv->can.can_stats.bus_off; in softing_handle_1()
283 skb = priv->can.echo_skb[priv->tx.echo_get]; in softing_handle_1()
285 skb->tstamp = ktime; in softing_handle_1()
286 ++netdev->stats.tx_packets; in softing_handle_1()
287 netdev->stats.tx_bytes += in softing_handle_1()
288 can_get_echo_skb(netdev, priv->tx.echo_get, in softing_handle_1()
290 ++priv->tx.echo_get; in softing_handle_1()
291 if (priv->tx.echo_get >= TX_ECHO_SKB_MAX) in softing_handle_1()
292 priv->tx.echo_get = 0; in softing_handle_1()
293 if (priv->tx.pending) in softing_handle_1()
294 --priv->tx.pending; in softing_handle_1()
295 if (card->tx.pending) in softing_handle_1()
296 --card->tx.pending; in softing_handle_1()
302 ++netdev->stats.rx_packets; in softing_handle_1()
304 netdev->stats.rx_bytes += msg.len; in softing_handle_1()
306 ++netdev->stats.rx_dropped; in softing_handle_1()
325 spin_lock_bh(&card->spin); in softing_irq_thread()
327 ++card->irq.svc_count; in softing_irq_thread()
330 spin_unlock_bh(&card->spin); in softing_irq_thread()
332 offset = card->tx.last_bus; in softing_irq_thread()
333 for (j = 0; j < ARRAY_SIZE(card->net); ++j) { in softing_irq_thread()
334 if (card->tx.pending >= TXMAX) in softing_irq_thread()
336 netdev = card->net[(j + offset + 1) % card->pdat->nbus]; in softing_irq_thread()
343 if (priv->tx.pending >= TX_ECHO_SKB_MAX) in softing_irq_thread()
360 ir = ioread8(&card->dpram[DPRAM_V2_IRQ_TOHOST]); in softing_irq_v2()
361 iowrite8(0, &card->dpram[DPRAM_V2_IRQ_TOHOST]); in softing_irq_v2()
370 ir = ioread8(&card->dpram[DPRAM_IRQ_TOHOST]); in softing_irq_v1()
371 iowrite8(0, &card->dpram[DPRAM_IRQ_TOHOST]); in softing_irq_v1()
413 return -EOPNOTSUPP; in softing_candev_set_mode()
425 if (!card->irq.nr) { in softing_enable_irq()
427 } else if (card->irq.requested && !enable) { in softing_enable_irq()
428 free_irq(card->irq.nr, card); in softing_enable_irq()
429 card->irq.requested = 0; in softing_enable_irq()
430 } else if (!card->irq.requested && enable) { in softing_enable_irq()
431 ret = request_threaded_irq(card->irq.nr, in softing_enable_irq()
432 (card->pdat->generation >= 2) ? in softing_enable_irq()
435 dev_name(&card->pdev->dev), card); in softing_enable_irq()
437 dev_alert(&card->pdev->dev, in softing_enable_irq()
439 card->irq.nr); in softing_enable_irq()
442 card->irq.requested = 1; in softing_enable_irq()
451 if (mutex_lock_interruptible(&card->fw.lock)) { in softing_card_shutdown()
452 /* return -ERESTARTSYS */; in softing_card_shutdown()
454 fw_up = card->fw.up; in softing_card_shutdown()
455 card->fw.up = 0; in softing_card_shutdown()
457 if (card->irq.requested && card->irq.nr) { in softing_card_shutdown()
458 free_irq(card->irq.nr, card); in softing_card_shutdown()
459 card->irq.requested = 0; in softing_card_shutdown()
462 if (card->pdat->enable_irq) in softing_card_shutdown()
463 card->pdat->enable_irq(card->pdev, 0); in softing_card_shutdown()
465 if (card->pdat->reset) in softing_card_shutdown()
466 card->pdat->reset(card->pdev, 1); in softing_card_shutdown()
468 mutex_unlock(&card->fw.lock); in softing_card_shutdown()
478 if (mutex_lock_interruptible(&card->fw.lock)) in softing_card_boot()
479 return -ERESTARTSYS; in softing_card_boot()
480 if (card->fw.up) { in softing_card_boot()
481 mutex_unlock(&card->fw.lock); in softing_card_boot()
485 if (card->pdat->enable_irq) in softing_card_boot()
486 card->pdat->enable_irq(card->pdev, 1); in softing_card_boot()
489 if (card->pdat->reset) in softing_card_boot()
490 card->pdat->reset(card->pdev, 1); in softing_card_boot()
491 for (j = 0; (j + sizeof(stream)) < card->dpram_size; in softing_card_boot()
494 memcpy_toio(&card->dpram[j], stream, sizeof(stream)); in softing_card_boot()
497 memcpy_fromio(back, &card->dpram[j], sizeof(stream)); in softing_card_boot()
502 dev_alert(&card->pdev->dev, "dpram failed at 0x%04x\n", j); in softing_card_boot()
503 ret = -EIO; in softing_card_boot()
508 ret = softing_load_fw(card->pdat->boot.fw, card, card->dpram, in softing_card_boot()
509 card->dpram_size, in softing_card_boot()
510 card->pdat->boot.offs - card->pdat->boot.addr); in softing_card_boot()
514 ret = softing_load_fw(card->pdat->load.fw, card, card->dpram, in softing_card_boot()
515 card->dpram_size, in softing_card_boot()
516 card->pdat->load.offs - card->pdat->load.addr); in softing_card_boot()
520 if (card->pdat->reset) in softing_card_boot()
521 card->pdat->reset(card->pdev, 0); in softing_card_boot()
526 ret = softing_load_app_fw(card->pdat->app.fw, card); in softing_card_boot()
534 card->fw.up = 1; in softing_card_boot()
535 mutex_unlock(&card->fw.lock); in softing_card_boot()
538 card->fw.up = 0; in softing_card_boot()
539 if (card->pdat->enable_irq) in softing_card_boot()
540 card->pdat->enable_irq(card->pdev, 0); in softing_card_boot()
542 if (card->pdat->reset) in softing_card_boot()
543 card->pdat->reset(card->pdev, 1); in softing_card_boot()
544 mutex_unlock(&card->fw.lock); in softing_card_boot()
557 return sprintf(buf, "%i\n", priv->chip); in show_chip()
566 return sprintf(buf, "0x%02x\n", priv->output); in show_output()
574 struct softing *card = priv->card; in store_output()
583 ret = mutex_lock_interruptible(&card->fw.lock); in store_output()
585 return -ERESTARTSYS; in store_output()
587 mutex_unlock(&card->fw.lock); in store_output()
588 return -EBUSY; in store_output()
590 priv->output = val; in store_output()
591 mutex_unlock(&card->fw.lock); in store_output()
640 dev_alert(&card->pdev->dev, "alloc_candev failed\n"); in softing_netdev_create()
644 priv->netdev = netdev; in softing_netdev_create()
645 priv->card = card; in softing_netdev_create()
646 memcpy(&priv->btr_const, &softing_btr_const, sizeof(priv->btr_const)); in softing_netdev_create()
647 priv->btr_const.brp_max = card->pdat->max_brp; in softing_netdev_create()
648 priv->btr_const.sjw_max = card->pdat->max_sjw; in softing_netdev_create()
649 priv->can.bittiming_const = &priv->btr_const; in softing_netdev_create()
650 priv->can.clock.freq = 8000000; in softing_netdev_create()
651 priv->chip = chip_id; in softing_netdev_create()
652 priv->output = softing_default_output(netdev); in softing_netdev_create()
653 SET_NETDEV_DEV(netdev, &card->pdev->dev); in softing_netdev_create()
655 netdev->flags |= IFF_ECHO; in softing_netdev_create()
656 netdev->netdev_ops = &softing_netdev_ops; in softing_netdev_create()
657 netdev->ethtool_ops = &softing_ethtool_ops; in softing_netdev_create()
658 priv->can.do_set_mode = softing_candev_set_mode; in softing_netdev_create()
659 priv->can.ctrlmode_supported = CAN_CTRLMODE_3_SAMPLES; in softing_netdev_create()
670 dev_alert(&netdev->dev, "register failed\n"); in softing_netdev_register()
673 if (sysfs_create_group(&netdev->dev.kobj, &netdev_sysfs_group) < 0) in softing_netdev_register()
681 sysfs_remove_group(&netdev->dev.kobj, &netdev_sysfs_group); in softing_netdev_cleanup()
694 return sprintf(buf, "%u\n", card->member); \
703 return sprintf(buf, "%s\n", card->member); \
708 DEV_ATTR_RO_STR(firmware, pdat->app.fw);
710 DEV_ATTR_RO_STR(hardware, pdat->name);
740 for (j = 0; j < ARRAY_SIZE(card->net); ++j) { in softing_pdev_remove()
741 if (!card->net[j]) in softing_pdev_remove()
743 softing_netdev_cleanup(card->net[j]); in softing_pdev_remove()
744 card->net[j] = NULL; in softing_pdev_remove()
746 sysfs_remove_group(&pdev->dev.kobj, &softing_pdev_group); in softing_pdev_remove()
748 iounmap(card->dpram); in softing_pdev_remove()
755 const struct softing_platform_data *pdat = dev_get_platdata(&pdev->dev); in softing_pdev_probe()
764 dev_warn(&pdev->dev, "no platform data\n"); in softing_pdev_probe()
765 return -EINVAL; in softing_pdev_probe()
767 if (pdat->nbus > ARRAY_SIZE(card->net)) { in softing_pdev_probe()
768 dev_warn(&pdev->dev, "%u nets??\n", pdat->nbus); in softing_pdev_probe()
769 return -EINVAL; in softing_pdev_probe()
774 return -ENOMEM; in softing_pdev_probe()
775 card->pdat = pdat; in softing_pdev_probe()
776 card->pdev = pdev; in softing_pdev_probe()
778 mutex_init(&card->fw.lock); in softing_pdev_probe()
779 spin_lock_init(&card->spin); in softing_pdev_probe()
781 ret = -EINVAL; in softing_pdev_probe()
785 card->dpram_phys = pres->start; in softing_pdev_probe()
786 card->dpram_size = resource_size(pres); in softing_pdev_probe()
787 card->dpram = ioremap(card->dpram_phys, card->dpram_size); in softing_pdev_probe()
788 if (!card->dpram) { in softing_pdev_probe()
789 dev_alert(&card->pdev->dev, "dpram ioremap failed\n"); in softing_pdev_probe()
795 card->irq.nr = pres->start; in softing_pdev_probe()
800 dev_alert(&pdev->dev, "failed to boot\n"); in softing_pdev_probe()
805 card->id.freq = card->pdat->freq; in softing_pdev_probe()
807 ret = sysfs_create_group(&pdev->dev.kobj, &softing_pdev_group); in softing_pdev_probe()
809 dev_alert(&card->pdev->dev, "sysfs failed\n"); in softing_pdev_probe()
813 for (j = 0; j < ARRAY_SIZE(card->net); ++j) { in softing_pdev_probe()
814 card->net[j] = netdev = in softing_pdev_probe()
815 softing_netdev_create(card, card->id.chip[j]); in softing_pdev_probe()
817 dev_alert(&pdev->dev, "failed to make can[%i]", j); in softing_pdev_probe()
818 ret = -ENOMEM; in softing_pdev_probe()
821 netdev->dev_id = j; in softing_pdev_probe()
822 priv = netdev_priv(card->net[j]); in softing_pdev_probe()
823 priv->index = j; in softing_pdev_probe()
827 card->net[j] = NULL; in softing_pdev_probe()
828 dev_alert(&card->pdev->dev, in softing_pdev_probe()
833 dev_info(&card->pdev->dev, "%s ready.\n", card->pdat->name); in softing_pdev_probe()
837 for (j = 0; j < ARRAY_SIZE(card->net); ++j) { in softing_pdev_probe()
838 if (!card->net[j]) in softing_pdev_probe()
840 softing_netdev_cleanup(card->net[j]); in softing_pdev_probe()
842 sysfs_remove_group(&pdev->dev.kobj, &softing_pdev_group); in softing_pdev_probe()
846 iounmap(card->dpram); in softing_pdev_probe()