Lines Matching refs:qca

82 start_spi_intr_handling(struct qcaspi *qca, u16 *intr_cause)  in start_spi_intr_handling()  argument
86 qcaspi_write_register(qca, SPI_REG_INTR_ENABLE, 0, wr_verify); in start_spi_intr_handling()
87 qcaspi_read_register(qca, SPI_REG_INTR_CAUSE, intr_cause); in start_spi_intr_handling()
88 netdev_dbg(qca->net_dev, "interrupts: 0x%04x\n", *intr_cause); in start_spi_intr_handling()
92 end_spi_intr_handling(struct qcaspi *qca, u16 intr_cause) in end_spi_intr_handling() argument
99 qcaspi_write_register(qca, SPI_REG_INTR_CAUSE, intr_cause, 0); in end_spi_intr_handling()
100 qcaspi_write_register(qca, SPI_REG_INTR_ENABLE, intr_enable, wr_verify); in end_spi_intr_handling()
101 netdev_dbg(qca->net_dev, "acking int: 0x%04x\n", intr_cause); in end_spi_intr_handling()
105 qcaspi_write_burst(struct qcaspi *qca, u8 *src, u32 len) in qcaspi_write_burst() argument
123 ret = spi_sync(qca->spi_dev, &msg); in qcaspi_write_burst()
126 qcaspi_spi_error(qca); in qcaspi_write_burst()
134 qcaspi_write_legacy(struct qcaspi *qca, u8 *src, u32 len) in qcaspi_write_legacy() argument
147 ret = spi_sync(qca->spi_dev, &msg); in qcaspi_write_legacy()
150 qcaspi_spi_error(qca); in qcaspi_write_legacy()
158 qcaspi_read_burst(struct qcaspi *qca, u8 *dst, u32 len) in qcaspi_read_burst() argument
176 ret = spi_sync(qca->spi_dev, &msg); in qcaspi_read_burst()
179 qcaspi_spi_error(qca); in qcaspi_read_burst()
187 qcaspi_read_legacy(struct qcaspi *qca, u8 *dst, u32 len) in qcaspi_read_legacy() argument
200 ret = spi_sync(qca->spi_dev, &msg); in qcaspi_read_legacy()
203 qcaspi_spi_error(qca); in qcaspi_read_legacy()
211 qcaspi_tx_cmd(struct qcaspi *qca, u16 cmd) in qcaspi_tx_cmd() argument
227 ret = spi_sync(qca->spi_dev, &msg); in qcaspi_tx_cmd()
233 qcaspi_spi_error(qca); in qcaspi_tx_cmd()
239 qcaspi_tx_frame(struct qcaspi *qca, struct sk_buff *skb) in qcaspi_tx_frame() argument
248 qcaspi_write_register(qca, SPI_REG_BFR_SIZE, len, wr_verify); in qcaspi_tx_frame()
249 if (qca->legacy_mode) in qcaspi_tx_frame()
250 qcaspi_tx_cmd(qca, QCA7K_SPI_WRITE | QCA7K_SPI_EXTERNAL); in qcaspi_tx_frame()
255 if (count > qca->burst_len) in qcaspi_tx_frame()
256 count = qca->burst_len; in qcaspi_tx_frame()
258 if (qca->legacy_mode) { in qcaspi_tx_frame()
259 written = qcaspi_write_legacy(qca, in qcaspi_tx_frame()
263 written = qcaspi_write_burst(qca, in qcaspi_tx_frame()
279 qcaspi_transmit(struct qcaspi *qca) in qcaspi_transmit() argument
281 struct net_device_stats *n_stats = &qca->net_dev->stats; in qcaspi_transmit()
287 if (qca->txr.skb[qca->txr.head] == NULL) in qcaspi_transmit()
290 qcaspi_read_register(qca, SPI_REG_WRBUF_SPC_AVA, &available); in qcaspi_transmit()
296 qca->stats.buf_avail_err++; in qcaspi_transmit()
300 while (qca->txr.skb[qca->txr.head]) { in qcaspi_transmit()
301 pkt_len = qca->txr.skb[qca->txr.head]->len + QCASPI_HW_PKT_LEN; in qcaspi_transmit()
305 qca->stats.write_buf_miss++; in qcaspi_transmit()
309 if (qcaspi_tx_frame(qca, qca->txr.skb[qca->txr.head]) == -1) { in qcaspi_transmit()
310 qca->stats.write_err++; in qcaspi_transmit()
316 n_stats->tx_bytes += qca->txr.skb[qca->txr.head]->len; in qcaspi_transmit()
323 netif_tx_lock_bh(qca->net_dev); in qcaspi_transmit()
324 dev_kfree_skb(qca->txr.skb[qca->txr.head]); in qcaspi_transmit()
325 qca->txr.skb[qca->txr.head] = NULL; in qcaspi_transmit()
326 qca->txr.size -= pkt_len; in qcaspi_transmit()
327 new_head = qca->txr.head + 1; in qcaspi_transmit()
328 if (new_head >= qca->txr.count) in qcaspi_transmit()
330 qca->txr.head = new_head; in qcaspi_transmit()
331 if (netif_queue_stopped(qca->net_dev)) in qcaspi_transmit()
332 netif_wake_queue(qca->net_dev); in qcaspi_transmit()
333 netif_tx_unlock_bh(qca->net_dev); in qcaspi_transmit()
340 qcaspi_receive(struct qcaspi *qca) in qcaspi_receive() argument
342 struct net_device *net_dev = qca->net_dev; in qcaspi_receive()
349 if (!qca->rx_skb) { in qcaspi_receive()
350 qca->rx_skb = netdev_alloc_skb_ip_align(net_dev, in qcaspi_receive()
353 if (!qca->rx_skb) { in qcaspi_receive()
355 qca->stats.out_of_mem++; in qcaspi_receive()
361 qcaspi_read_register(qca, SPI_REG_RDBUF_BYTE_AVA, &available); in qcaspi_receive()
370 qca->stats.buf_avail_err++; in qcaspi_receive()
377 qcaspi_write_register(qca, SPI_REG_BFR_SIZE, available, wr_verify); in qcaspi_receive()
379 if (qca->legacy_mode) in qcaspi_receive()
380 qcaspi_tx_cmd(qca, QCA7K_SPI_READ | QCA7K_SPI_EXTERNAL); in qcaspi_receive()
385 if (count > qca->burst_len) in qcaspi_receive()
386 count = qca->burst_len; in qcaspi_receive()
388 if (qca->legacy_mode) { in qcaspi_receive()
389 bytes_read = qcaspi_read_legacy(qca, qca->rx_buffer, in qcaspi_receive()
392 bytes_read = qcaspi_read_burst(qca, qca->rx_buffer, in qcaspi_receive()
402 qca->stats.read_err++; in qcaspi_receive()
406 cp = qca->rx_buffer; in qcaspi_receive()
408 while ((bytes_read--) && (qca->rx_skb)) { in qcaspi_receive()
411 retcode = qcafrm_fsm_decode(&qca->frm_handle, in qcaspi_receive()
412 qca->rx_skb->data, in qcaspi_receive()
413 skb_tailroom(qca->rx_skb), in qcaspi_receive()
431 qca->rx_skb->dev = qca->net_dev; in qcaspi_receive()
434 skb_put(qca->rx_skb, retcode); in qcaspi_receive()
435 qca->rx_skb->protocol = eth_type_trans( in qcaspi_receive()
436 qca->rx_skb, qca->rx_skb->dev); in qcaspi_receive()
437 skb_checksum_none_assert(qca->rx_skb); in qcaspi_receive()
438 netif_rx(qca->rx_skb); in qcaspi_receive()
439 qca->rx_skb = netdev_alloc_skb_ip_align(net_dev, in qcaspi_receive()
441 if (!qca->rx_skb) { in qcaspi_receive()
444 qca->stats.out_of_mem++; in qcaspi_receive()
472 qcaspi_flush_tx_ring(struct qcaspi *qca) in qcaspi_flush_tx_ring() argument
479 netif_tx_lock_bh(qca->net_dev); in qcaspi_flush_tx_ring()
481 if (qca->txr.skb[i]) { in qcaspi_flush_tx_ring()
482 dev_kfree_skb(qca->txr.skb[i]); in qcaspi_flush_tx_ring()
483 qca->txr.skb[i] = NULL; in qcaspi_flush_tx_ring()
484 qca->net_dev->stats.tx_dropped++; in qcaspi_flush_tx_ring()
487 qca->txr.tail = 0; in qcaspi_flush_tx_ring()
488 qca->txr.head = 0; in qcaspi_flush_tx_ring()
489 qca->txr.size = 0; in qcaspi_flush_tx_ring()
490 netif_tx_unlock_bh(qca->net_dev); in qcaspi_flush_tx_ring()
494 qcaspi_qca7k_sync(struct qcaspi *qca, int event) in qcaspi_qca7k_sync() argument
504 qcaspi_read_register(qca, SPI_REG_SIGNATURE, &signature); in qcaspi_qca7k_sync()
505 qcaspi_read_register(qca, SPI_REG_SIGNATURE, &signature); in qcaspi_qca7k_sync()
507 if (qca->sync == QCASPI_SYNC_READY) in qcaspi_qca7k_sync()
508 qca->stats.bad_signature++; in qcaspi_qca7k_sync()
510 qca->sync = QCASPI_SYNC_UNKNOWN; in qcaspi_qca7k_sync()
511 netdev_dbg(qca->net_dev, "sync: got CPU on, but signature was invalid, restart\n"); in qcaspi_qca7k_sync()
515 qcaspi_read_register(qca, SPI_REG_WRBUF_SPC_AVA, in qcaspi_qca7k_sync()
518 netdev_dbg(qca->net_dev, "sync: got CPU on, but wrbuf not empty. reset!\n"); in qcaspi_qca7k_sync()
519 qca->sync = QCASPI_SYNC_UNKNOWN; in qcaspi_qca7k_sync()
521 netdev_dbg(qca->net_dev, "sync: got CPU on, now in sync\n"); in qcaspi_qca7k_sync()
522 qca->sync = QCASPI_SYNC_READY; in qcaspi_qca7k_sync()
528 switch (qca->sync) { in qcaspi_qca7k_sync()
531 qcaspi_read_register(qca, SPI_REG_SIGNATURE, &signature); in qcaspi_qca7k_sync()
533 qcaspi_read_register(qca, SPI_REG_SIGNATURE, &signature); in qcaspi_qca7k_sync()
536 qca->sync = QCASPI_SYNC_UNKNOWN; in qcaspi_qca7k_sync()
537 qca->stats.bad_signature++; in qcaspi_qca7k_sync()
538 netdev_dbg(qca->net_dev, "sync: bad signature, restart\n"); in qcaspi_qca7k_sync()
545 qcaspi_read_register(qca, SPI_REG_SIGNATURE, &signature); in qcaspi_qca7k_sync()
547 netdev_dbg(qca->net_dev, "sync: could not read signature to reset device, retry.\n"); in qcaspi_qca7k_sync()
552 netdev_dbg(qca->net_dev, "sync: resetting device.\n"); in qcaspi_qca7k_sync()
553 qcaspi_read_register(qca, SPI_REG_SPI_CONFIG, &spi_config); in qcaspi_qca7k_sync()
555 qcaspi_write_register(qca, SPI_REG_SPI_CONFIG, spi_config, 0); in qcaspi_qca7k_sync()
557 qca->sync = QCASPI_SYNC_RESET; in qcaspi_qca7k_sync()
558 qca->stats.trig_reset++; in qcaspi_qca7k_sync()
559 qca->reset_count = 0; in qcaspi_qca7k_sync()
562 qca->reset_count++; in qcaspi_qca7k_sync()
563 netdev_dbg(qca->net_dev, "sync: waiting for CPU on, count %u.\n", in qcaspi_qca7k_sync()
564 qca->reset_count); in qcaspi_qca7k_sync()
565 if (qca->reset_count >= QCASPI_RESET_TIMEOUT) { in qcaspi_qca7k_sync()
567 qca->sync = QCASPI_SYNC_UNKNOWN; in qcaspi_qca7k_sync()
568 qca->stats.reset_timeout++; in qcaspi_qca7k_sync()
569 netdev_dbg(qca->net_dev, "sync: reset timeout, restarting process.\n"); in qcaspi_qca7k_sync()
578 struct qcaspi *qca = data; in qcaspi_spi_thread() local
581 netdev_info(qca->net_dev, "SPI thread created\n"); in qcaspi_spi_thread()
584 if ((qca->intr_req == qca->intr_svc) && in qcaspi_spi_thread()
585 (qca->txr.skb[qca->txr.head] == NULL) && in qcaspi_spi_thread()
586 (qca->sync == QCASPI_SYNC_READY)) in qcaspi_spi_thread()
591 netdev_dbg(qca->net_dev, "have work to do. int: %d, tx_skb: %p\n", in qcaspi_spi_thread()
592 qca->intr_req - qca->intr_svc, in qcaspi_spi_thread()
593 qca->txr.skb[qca->txr.head]); in qcaspi_spi_thread()
595 qcaspi_qca7k_sync(qca, QCASPI_EVENT_UPDATE); in qcaspi_spi_thread()
597 if (qca->sync != QCASPI_SYNC_READY) { in qcaspi_spi_thread()
598 netdev_dbg(qca->net_dev, "sync: not ready %u, turn off carrier and flush\n", in qcaspi_spi_thread()
599 (unsigned int)qca->sync); in qcaspi_spi_thread()
600 netif_stop_queue(qca->net_dev); in qcaspi_spi_thread()
601 netif_carrier_off(qca->net_dev); in qcaspi_spi_thread()
602 qcaspi_flush_tx_ring(qca); in qcaspi_spi_thread()
606 if (qca->intr_svc != qca->intr_req) { in qcaspi_spi_thread()
607 qca->intr_svc = qca->intr_req; in qcaspi_spi_thread()
608 start_spi_intr_handling(qca, &intr_cause); in qcaspi_spi_thread()
611 qcaspi_qca7k_sync(qca, QCASPI_EVENT_CPUON); in qcaspi_spi_thread()
614 if (qca->sync != QCASPI_SYNC_READY) in qcaspi_spi_thread()
617 qca->stats.device_reset++; in qcaspi_spi_thread()
618 netif_wake_queue(qca->net_dev); in qcaspi_spi_thread()
619 netif_carrier_on(qca->net_dev); in qcaspi_spi_thread()
624 netdev_dbg(qca->net_dev, "===> rdbuf error!\n"); in qcaspi_spi_thread()
625 qca->stats.read_buf_err++; in qcaspi_spi_thread()
626 qca->sync = QCASPI_SYNC_UNKNOWN; in qcaspi_spi_thread()
632 netdev_dbg(qca->net_dev, "===> wrbuf error!\n"); in qcaspi_spi_thread()
633 qca->stats.write_buf_err++; in qcaspi_spi_thread()
634 qca->sync = QCASPI_SYNC_UNKNOWN; in qcaspi_spi_thread()
641 if (qca->sync == QCASPI_SYNC_READY) { in qcaspi_spi_thread()
643 qcaspi_receive(qca); in qcaspi_spi_thread()
646 end_spi_intr_handling(qca, intr_cause); in qcaspi_spi_thread()
649 if (qca->sync == QCASPI_SYNC_READY) in qcaspi_spi_thread()
650 qcaspi_transmit(qca); in qcaspi_spi_thread()
653 netdev_info(qca->net_dev, "SPI thread exit\n"); in qcaspi_spi_thread()
661 struct qcaspi *qca = data; in qcaspi_intr_handler() local
663 qca->intr_req++; in qcaspi_intr_handler()
664 if (qca->spi_thread) in qcaspi_intr_handler()
665 wake_up_process(qca->spi_thread); in qcaspi_intr_handler()
673 struct qcaspi *qca = netdev_priv(dev); in qcaspi_netdev_open() local
676 if (!qca) in qcaspi_netdev_open()
679 qca->intr_req = 1; in qcaspi_netdev_open()
680 qca->intr_svc = 0; in qcaspi_netdev_open()
681 qca->sync = QCASPI_SYNC_UNKNOWN; in qcaspi_netdev_open()
682 qcafrm_fsm_init_spi(&qca->frm_handle); in qcaspi_netdev_open()
684 qca->spi_thread = kthread_run((void *)qcaspi_spi_thread, in qcaspi_netdev_open()
685 qca, "%s", dev->name); in qcaspi_netdev_open()
687 if (IS_ERR(qca->spi_thread)) { in qcaspi_netdev_open()
690 return PTR_ERR(qca->spi_thread); in qcaspi_netdev_open()
693 ret = request_irq(qca->spi_dev->irq, qcaspi_intr_handler, 0, in qcaspi_netdev_open()
694 dev->name, qca); in qcaspi_netdev_open()
697 QCASPI_DRV_NAME, qca->spi_dev->irq, ret); in qcaspi_netdev_open()
698 kthread_stop(qca->spi_thread); in qcaspi_netdev_open()
710 struct qcaspi *qca = netdev_priv(dev); in qcaspi_netdev_close() local
714 qcaspi_write_register(qca, SPI_REG_INTR_ENABLE, 0, wr_verify); in qcaspi_netdev_close()
715 free_irq(qca->spi_dev->irq, qca); in qcaspi_netdev_close()
717 kthread_stop(qca->spi_thread); in qcaspi_netdev_close()
718 qca->spi_thread = NULL; in qcaspi_netdev_close()
719 qcaspi_flush_tx_ring(qca); in qcaspi_netdev_close()
729 struct qcaspi *qca = netdev_priv(dev); in qcaspi_netdev_xmit() local
737 if (qca->txr.skb[qca->txr.tail]) { in qcaspi_netdev_xmit()
738 netdev_warn(qca->net_dev, "queue was unexpectedly full!\n"); in qcaspi_netdev_xmit()
739 netif_stop_queue(qca->net_dev); in qcaspi_netdev_xmit()
740 qca->stats.ring_full++; in qcaspi_netdev_xmit()
749 qca->stats.out_of_mem++; in qcaspi_netdev_xmit()
768 netdev_dbg(qca->net_dev, "Tx-ing packet: Size: 0x%08x\n", in qcaspi_netdev_xmit()
771 qca->txr.size += skb->len + QCASPI_HW_PKT_LEN; in qcaspi_netdev_xmit()
773 new_tail = qca->txr.tail + 1; in qcaspi_netdev_xmit()
774 if (new_tail >= qca->txr.count) in qcaspi_netdev_xmit()
777 qca->txr.skb[qca->txr.tail] = skb; in qcaspi_netdev_xmit()
778 qca->txr.tail = new_tail; in qcaspi_netdev_xmit()
780 if (!qcaspi_tx_ring_has_space(&qca->txr)) { in qcaspi_netdev_xmit()
781 netif_stop_queue(qca->net_dev); in qcaspi_netdev_xmit()
782 qca->stats.ring_full++; in qcaspi_netdev_xmit()
787 if (qca->spi_thread) in qcaspi_netdev_xmit()
788 wake_up_process(qca->spi_thread); in qcaspi_netdev_xmit()
796 struct qcaspi *qca = netdev_priv(dev); in qcaspi_netdev_tx_timeout() local
798 netdev_info(qca->net_dev, "Transmit timeout at %ld, latency %ld\n", in qcaspi_netdev_tx_timeout()
800 qca->net_dev->stats.tx_errors++; in qcaspi_netdev_tx_timeout()
802 qca->sync = QCASPI_SYNC_UNKNOWN; in qcaspi_netdev_tx_timeout()
804 if (qca->spi_thread) in qcaspi_netdev_tx_timeout()
805 wake_up_process(qca->spi_thread); in qcaspi_netdev_tx_timeout()
811 struct qcaspi *qca = netdev_priv(dev); in qcaspi_netdev_init() local
815 qca->clkspeed = qcaspi_clkspeed; in qcaspi_netdev_init()
816 qca->burst_len = qcaspi_burst_len; in qcaspi_netdev_init()
817 qca->spi_thread = NULL; in qcaspi_netdev_init()
818 qca->buffer_size = (dev->mtu + VLAN_ETH_HLEN + QCAFRM_HEADER_LEN + in qcaspi_netdev_init()
821 memset(&qca->stats, 0, sizeof(struct qcaspi_stats)); in qcaspi_netdev_init()
823 qca->rx_buffer = kmalloc(qca->buffer_size, GFP_KERNEL); in qcaspi_netdev_init()
824 if (!qca->rx_buffer) in qcaspi_netdev_init()
827 qca->rx_skb = netdev_alloc_skb_ip_align(dev, qca->net_dev->mtu + in qcaspi_netdev_init()
829 if (!qca->rx_skb) { in qcaspi_netdev_init()
830 kfree(qca->rx_buffer); in qcaspi_netdev_init()
831 netdev_info(qca->net_dev, "Failed to allocate RX sk_buff.\n"); in qcaspi_netdev_init()
841 struct qcaspi *qca = netdev_priv(dev); in qcaspi_netdev_uninit() local
843 kfree(qca->rx_buffer); in qcaspi_netdev_uninit()
844 qca->buffer_size = 0; in qcaspi_netdev_uninit()
845 dev_kfree_skb(qca->rx_skb); in qcaspi_netdev_uninit()
862 struct qcaspi *qca = NULL; in qcaspi_netdev_setup() local
874 qca = netdev_priv(dev); in qcaspi_netdev_setup()
875 memset(qca, 0, sizeof(struct qcaspi)); in qcaspi_netdev_setup()
877 memset(&qca->txr, 0, sizeof(qca->txr)); in qcaspi_netdev_setup()
878 qca->txr.count = TX_RING_MAX_LEN; in qcaspi_netdev_setup()
890 struct qcaspi *qca = NULL; in qca_spi_probe() local
959 qca = netdev_priv(qcaspi_devs); in qca_spi_probe()
960 if (!qca) { in qca_spi_probe()
965 qca->net_dev = qcaspi_devs; in qca_spi_probe()
966 qca->spi_dev = spi; in qca_spi_probe()
967 qca->legacy_mode = legacy_mode; in qca_spi_probe()
971 ret = of_get_ethdev_address(spi->dev.of_node, qca->net_dev); in qca_spi_probe()
973 eth_hw_addr_random(qca->net_dev); in qca_spi_probe()
975 qca->net_dev->dev_addr); in qca_spi_probe()
978 netif_carrier_off(qca->net_dev); in qca_spi_probe()
981 qcaspi_read_register(qca, SPI_REG_SIGNATURE, &signature); in qca_spi_probe()
982 qcaspi_read_register(qca, SPI_REG_SIGNATURE, &signature); in qca_spi_probe()
999 qcaspi_init_device_debugfs(qca); in qca_spi_probe()
1008 struct qcaspi *qca = netdev_priv(qcaspi_devs); in qca_spi_remove() local
1010 qcaspi_remove_device_debugfs(qca); in qca_spi_remove()