Lines Matching refs:qca
70 start_spi_intr_handling(struct qcaspi *qca, u16 *intr_cause) in start_spi_intr_handling() argument
74 qcaspi_write_register(qca, SPI_REG_INTR_ENABLE, 0, wr_verify); in start_spi_intr_handling()
75 qcaspi_read_register(qca, SPI_REG_INTR_CAUSE, intr_cause); in start_spi_intr_handling()
76 netdev_dbg(qca->net_dev, "interrupts: 0x%04x\n", *intr_cause); in start_spi_intr_handling()
80 end_spi_intr_handling(struct qcaspi *qca, u16 intr_cause) in end_spi_intr_handling() argument
87 qcaspi_write_register(qca, SPI_REG_INTR_CAUSE, intr_cause, 0); in end_spi_intr_handling()
88 qcaspi_write_register(qca, SPI_REG_INTR_ENABLE, intr_enable, wr_verify); in end_spi_intr_handling()
89 netdev_dbg(qca->net_dev, "acking int: 0x%04x\n", intr_cause); in end_spi_intr_handling()
93 qcaspi_write_burst(struct qcaspi *qca, u8 *src, u32 len) in qcaspi_write_burst() argument
111 ret = spi_sync(qca->spi_dev, &msg); in qcaspi_write_burst()
114 qcaspi_spi_error(qca); in qcaspi_write_burst()
122 qcaspi_write_legacy(struct qcaspi *qca, u8 *src, u32 len) in qcaspi_write_legacy() argument
135 ret = spi_sync(qca->spi_dev, &msg); in qcaspi_write_legacy()
138 qcaspi_spi_error(qca); in qcaspi_write_legacy()
146 qcaspi_read_burst(struct qcaspi *qca, u8 *dst, u32 len) in qcaspi_read_burst() argument
164 ret = spi_sync(qca->spi_dev, &msg); in qcaspi_read_burst()
167 qcaspi_spi_error(qca); in qcaspi_read_burst()
175 qcaspi_read_legacy(struct qcaspi *qca, u8 *dst, u32 len) in qcaspi_read_legacy() argument
188 ret = spi_sync(qca->spi_dev, &msg); in qcaspi_read_legacy()
191 qcaspi_spi_error(qca); in qcaspi_read_legacy()
199 qcaspi_tx_cmd(struct qcaspi *qca, u16 cmd) in qcaspi_tx_cmd() argument
215 ret = spi_sync(qca->spi_dev, &msg); in qcaspi_tx_cmd()
221 qcaspi_spi_error(qca); in qcaspi_tx_cmd()
227 qcaspi_tx_frame(struct qcaspi *qca, struct sk_buff *skb) in qcaspi_tx_frame() argument
236 qcaspi_write_register(qca, SPI_REG_BFR_SIZE, len, wr_verify); in qcaspi_tx_frame()
237 if (qca->legacy_mode) in qcaspi_tx_frame()
238 qcaspi_tx_cmd(qca, QCA7K_SPI_WRITE | QCA7K_SPI_EXTERNAL); in qcaspi_tx_frame()
243 if (count > qca->burst_len) in qcaspi_tx_frame()
244 count = qca->burst_len; in qcaspi_tx_frame()
246 if (qca->legacy_mode) { in qcaspi_tx_frame()
247 written = qcaspi_write_legacy(qca, in qcaspi_tx_frame()
251 written = qcaspi_write_burst(qca, in qcaspi_tx_frame()
267 qcaspi_transmit(struct qcaspi *qca) in qcaspi_transmit() argument
269 struct net_device_stats *n_stats = &qca->net_dev->stats; in qcaspi_transmit()
275 if (qca->txr.skb[qca->txr.head] == NULL) in qcaspi_transmit()
278 qcaspi_read_register(qca, SPI_REG_WRBUF_SPC_AVA, &available); in qcaspi_transmit()
284 qca->stats.buf_avail_err++; in qcaspi_transmit()
288 while (qca->txr.skb[qca->txr.head]) { in qcaspi_transmit()
289 pkt_len = qca->txr.skb[qca->txr.head]->len + QCASPI_HW_PKT_LEN; in qcaspi_transmit()
293 qca->stats.write_buf_miss++; in qcaspi_transmit()
297 if (qcaspi_tx_frame(qca, qca->txr.skb[qca->txr.head]) == -1) { in qcaspi_transmit()
298 qca->stats.write_err++; in qcaspi_transmit()
304 n_stats->tx_bytes += qca->txr.skb[qca->txr.head]->len; in qcaspi_transmit()
311 netif_tx_lock_bh(qca->net_dev); in qcaspi_transmit()
312 dev_kfree_skb(qca->txr.skb[qca->txr.head]); in qcaspi_transmit()
313 qca->txr.skb[qca->txr.head] = NULL; in qcaspi_transmit()
314 qca->txr.size -= pkt_len; in qcaspi_transmit()
315 new_head = qca->txr.head + 1; in qcaspi_transmit()
316 if (new_head >= qca->txr.count) in qcaspi_transmit()
318 qca->txr.head = new_head; in qcaspi_transmit()
319 if (netif_queue_stopped(qca->net_dev)) in qcaspi_transmit()
320 netif_wake_queue(qca->net_dev); in qcaspi_transmit()
321 netif_tx_unlock_bh(qca->net_dev); in qcaspi_transmit()
328 qcaspi_receive(struct qcaspi *qca) in qcaspi_receive() argument
330 struct net_device *net_dev = qca->net_dev; in qcaspi_receive()
337 if (!qca->rx_skb) { in qcaspi_receive()
338 qca->rx_skb = netdev_alloc_skb_ip_align(net_dev, in qcaspi_receive()
341 if (!qca->rx_skb) { in qcaspi_receive()
343 qca->stats.out_of_mem++; in qcaspi_receive()
349 qcaspi_read_register(qca, SPI_REG_RDBUF_BYTE_AVA, &available); in qcaspi_receive()
358 qca->stats.buf_avail_err++; in qcaspi_receive()
365 qcaspi_write_register(qca, SPI_REG_BFR_SIZE, available, wr_verify); in qcaspi_receive()
367 if (qca->legacy_mode) in qcaspi_receive()
368 qcaspi_tx_cmd(qca, QCA7K_SPI_READ | QCA7K_SPI_EXTERNAL); in qcaspi_receive()
373 if (count > qca->burst_len) in qcaspi_receive()
374 count = qca->burst_len; in qcaspi_receive()
376 if (qca->legacy_mode) { in qcaspi_receive()
377 bytes_read = qcaspi_read_legacy(qca, qca->rx_buffer, in qcaspi_receive()
380 bytes_read = qcaspi_read_burst(qca, qca->rx_buffer, in qcaspi_receive()
390 qca->stats.read_err++; in qcaspi_receive()
394 cp = qca->rx_buffer; in qcaspi_receive()
396 while ((bytes_read--) && (qca->rx_skb)) { in qcaspi_receive()
399 retcode = qcafrm_fsm_decode(&qca->frm_handle, in qcaspi_receive()
400 qca->rx_skb->data, in qcaspi_receive()
401 skb_tailroom(qca->rx_skb), in qcaspi_receive()
419 qca->rx_skb->dev = qca->net_dev; in qcaspi_receive()
422 skb_put(qca->rx_skb, retcode); in qcaspi_receive()
423 qca->rx_skb->protocol = eth_type_trans( in qcaspi_receive()
424 qca->rx_skb, qca->rx_skb->dev); in qcaspi_receive()
425 skb_checksum_none_assert(qca->rx_skb); in qcaspi_receive()
426 netif_rx(qca->rx_skb); in qcaspi_receive()
427 qca->rx_skb = netdev_alloc_skb_ip_align(net_dev, in qcaspi_receive()
429 if (!qca->rx_skb) { in qcaspi_receive()
432 qca->stats.out_of_mem++; in qcaspi_receive()
460 qcaspi_flush_tx_ring(struct qcaspi *qca) in qcaspi_flush_tx_ring() argument
467 netif_tx_lock_bh(qca->net_dev); in qcaspi_flush_tx_ring()
469 if (qca->txr.skb[i]) { in qcaspi_flush_tx_ring()
470 dev_kfree_skb(qca->txr.skb[i]); in qcaspi_flush_tx_ring()
471 qca->txr.skb[i] = NULL; in qcaspi_flush_tx_ring()
472 qca->net_dev->stats.tx_dropped++; in qcaspi_flush_tx_ring()
475 qca->txr.tail = 0; in qcaspi_flush_tx_ring()
476 qca->txr.head = 0; in qcaspi_flush_tx_ring()
477 qca->txr.size = 0; in qcaspi_flush_tx_ring()
478 netif_tx_unlock_bh(qca->net_dev); in qcaspi_flush_tx_ring()
482 qcaspi_qca7k_sync(struct qcaspi *qca, int event) in qcaspi_qca7k_sync() argument
492 qcaspi_read_register(qca, SPI_REG_SIGNATURE, &signature); in qcaspi_qca7k_sync()
493 qcaspi_read_register(qca, SPI_REG_SIGNATURE, &signature); in qcaspi_qca7k_sync()
495 if (qca->sync == QCASPI_SYNC_READY) in qcaspi_qca7k_sync()
496 qca->stats.bad_signature++; in qcaspi_qca7k_sync()
498 qca->sync = QCASPI_SYNC_UNKNOWN; in qcaspi_qca7k_sync()
499 netdev_dbg(qca->net_dev, "sync: got CPU on, but signature was invalid, restart\n"); in qcaspi_qca7k_sync()
503 qcaspi_read_register(qca, SPI_REG_WRBUF_SPC_AVA, in qcaspi_qca7k_sync()
506 netdev_dbg(qca->net_dev, "sync: got CPU on, but wrbuf not empty. reset!\n"); in qcaspi_qca7k_sync()
507 qca->sync = QCASPI_SYNC_UNKNOWN; in qcaspi_qca7k_sync()
509 netdev_dbg(qca->net_dev, "sync: got CPU on, now in sync\n"); in qcaspi_qca7k_sync()
510 qca->sync = QCASPI_SYNC_READY; in qcaspi_qca7k_sync()
516 switch (qca->sync) { in qcaspi_qca7k_sync()
519 qcaspi_read_register(qca, SPI_REG_SIGNATURE, &signature); in qcaspi_qca7k_sync()
521 qcaspi_read_register(qca, SPI_REG_SIGNATURE, &signature); in qcaspi_qca7k_sync()
524 qca->sync = QCASPI_SYNC_UNKNOWN; in qcaspi_qca7k_sync()
525 qca->stats.bad_signature++; in qcaspi_qca7k_sync()
526 netdev_dbg(qca->net_dev, "sync: bad signature, restart\n"); in qcaspi_qca7k_sync()
533 qcaspi_read_register(qca, SPI_REG_SIGNATURE, &signature); in qcaspi_qca7k_sync()
535 netdev_dbg(qca->net_dev, "sync: could not read signature to reset device, retry.\n"); in qcaspi_qca7k_sync()
540 netdev_dbg(qca->net_dev, "sync: resetting device.\n"); in qcaspi_qca7k_sync()
541 qcaspi_read_register(qca, SPI_REG_SPI_CONFIG, &spi_config); in qcaspi_qca7k_sync()
543 qcaspi_write_register(qca, SPI_REG_SPI_CONFIG, spi_config, 0); in qcaspi_qca7k_sync()
545 qca->sync = QCASPI_SYNC_RESET; in qcaspi_qca7k_sync()
546 qca->stats.trig_reset++; in qcaspi_qca7k_sync()
547 qca->reset_count = 0; in qcaspi_qca7k_sync()
550 qca->reset_count++; in qcaspi_qca7k_sync()
551 netdev_dbg(qca->net_dev, "sync: waiting for CPU on, count %u.\n", in qcaspi_qca7k_sync()
552 qca->reset_count); in qcaspi_qca7k_sync()
553 if (qca->reset_count >= QCASPI_RESET_TIMEOUT) { in qcaspi_qca7k_sync()
555 qca->sync = QCASPI_SYNC_UNKNOWN; in qcaspi_qca7k_sync()
556 qca->stats.reset_timeout++; in qcaspi_qca7k_sync()
557 netdev_dbg(qca->net_dev, "sync: reset timeout, restarting process.\n"); in qcaspi_qca7k_sync()
566 struct qcaspi *qca = data; in qcaspi_spi_thread() local
569 netdev_info(qca->net_dev, "SPI thread created\n"); in qcaspi_spi_thread()
573 netif_tx_disable(qca->net_dev); in qcaspi_spi_thread()
574 netif_carrier_off(qca->net_dev); in qcaspi_spi_thread()
575 qcaspi_flush_tx_ring(qca); in qcaspi_spi_thread()
577 if (qca->sync == QCASPI_SYNC_READY) { in qcaspi_spi_thread()
578 netif_carrier_on(qca->net_dev); in qcaspi_spi_thread()
579 netif_wake_queue(qca->net_dev); in qcaspi_spi_thread()
584 if (!test_bit(SPI_INTR, &qca->intr) && in qcaspi_spi_thread()
585 !qca->txr.skb[qca->txr.head]) in qcaspi_spi_thread()
590 netdev_dbg(qca->net_dev, "have work to do. int: %lu, tx_skb: %p\n", in qcaspi_spi_thread()
591 qca->intr, in qcaspi_spi_thread()
592 qca->txr.skb[qca->txr.head]); in qcaspi_spi_thread()
594 qcaspi_qca7k_sync(qca, QCASPI_EVENT_UPDATE); in qcaspi_spi_thread()
596 if (qca->sync != QCASPI_SYNC_READY) { in qcaspi_spi_thread()
597 netdev_dbg(qca->net_dev, "sync: not ready %u, turn off carrier and flush\n", in qcaspi_spi_thread()
598 (unsigned int)qca->sync); in qcaspi_spi_thread()
599 netif_stop_queue(qca->net_dev); in qcaspi_spi_thread()
600 netif_carrier_off(qca->net_dev); in qcaspi_spi_thread()
601 qcaspi_flush_tx_ring(qca); in qcaspi_spi_thread()
605 if (test_and_clear_bit(SPI_INTR, &qca->intr)) { in qcaspi_spi_thread()
606 start_spi_intr_handling(qca, &intr_cause); in qcaspi_spi_thread()
609 qcaspi_qca7k_sync(qca, QCASPI_EVENT_CPUON); in qcaspi_spi_thread()
612 if (qca->frm_handle.state != qca->frm_handle.init) in qcaspi_spi_thread()
613 qca->net_dev->stats.rx_dropped++; in qcaspi_spi_thread()
615 qcafrm_fsm_init_spi(&qca->frm_handle); in qcaspi_spi_thread()
616 qca->stats.device_reset++; in qcaspi_spi_thread()
619 if (qca->sync != QCASPI_SYNC_READY) in qcaspi_spi_thread()
622 netif_wake_queue(qca->net_dev); in qcaspi_spi_thread()
623 netif_carrier_on(qca->net_dev); in qcaspi_spi_thread()
628 netdev_dbg(qca->net_dev, "===> rdbuf error!\n"); in qcaspi_spi_thread()
629 qca->stats.read_buf_err++; in qcaspi_spi_thread()
630 qca->sync = QCASPI_SYNC_UNKNOWN; in qcaspi_spi_thread()
636 netdev_dbg(qca->net_dev, "===> wrbuf error!\n"); in qcaspi_spi_thread()
637 qca->stats.write_buf_err++; in qcaspi_spi_thread()
638 qca->sync = QCASPI_SYNC_UNKNOWN; in qcaspi_spi_thread()
645 if (qca->sync == QCASPI_SYNC_READY) { in qcaspi_spi_thread()
647 qcaspi_receive(qca); in qcaspi_spi_thread()
650 end_spi_intr_handling(qca, intr_cause); in qcaspi_spi_thread()
653 if (qca->sync == QCASPI_SYNC_READY) in qcaspi_spi_thread()
654 qcaspi_transmit(qca); in qcaspi_spi_thread()
657 netdev_info(qca->net_dev, "SPI thread exit\n"); in qcaspi_spi_thread()
665 struct qcaspi *qca = data; in qcaspi_intr_handler() local
667 set_bit(SPI_INTR, &qca->intr); in qcaspi_intr_handler()
668 if (qca->spi_thread) in qcaspi_intr_handler()
669 wake_up_process(qca->spi_thread); in qcaspi_intr_handler()
677 struct qcaspi *qca = netdev_priv(dev); in qcaspi_netdev_open() local
680 if (!qca) in qcaspi_netdev_open()
683 set_bit(SPI_INTR, &qca->intr); in qcaspi_netdev_open()
684 qca->sync = QCASPI_SYNC_UNKNOWN; in qcaspi_netdev_open()
685 qcafrm_fsm_init_spi(&qca->frm_handle); in qcaspi_netdev_open()
688 qca, "%s", dev->name); in qcaspi_netdev_open()
696 qca->spi_thread = thread; in qcaspi_netdev_open()
698 enable_irq(qca->spi_dev->irq); in qcaspi_netdev_open()
708 struct qcaspi *qca = netdev_priv(dev); in qcaspi_netdev_close() local
712 qcaspi_write_register(qca, SPI_REG_INTR_ENABLE, 0, wr_verify); in qcaspi_netdev_close()
713 disable_irq(qca->spi_dev->irq); in qcaspi_netdev_close()
715 if (qca->spi_thread) { in qcaspi_netdev_close()
716 kthread_stop(qca->spi_thread); in qcaspi_netdev_close()
717 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 = (QCAFRM_MAX_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
876 qca = netdev_priv(dev); in qcaspi_netdev_setup()
877 memset(qca, 0, sizeof(struct qcaspi)); in qcaspi_netdev_setup()
879 memset(&qca->txr, 0, sizeof(qca->txr)); in qcaspi_netdev_setup()
880 qca->txr.count = QCASPI_TX_RING_MAX_LEN; in qcaspi_netdev_setup()
892 struct qcaspi *qca = NULL; in qca_spi_probe() local
961 qca = netdev_priv(qcaspi_devs); in qca_spi_probe()
962 if (!qca) { in qca_spi_probe()
967 qca->net_dev = qcaspi_devs; in qca_spi_probe()
968 qca->spi_dev = spi; in qca_spi_probe()
969 qca->legacy_mode = legacy_mode; in qca_spi_probe()
974 IRQF_NO_AUTOEN, qca->net_dev->name, qca); in qca_spi_probe()
982 ret = of_get_ethdev_address(spi->dev.of_node, qca->net_dev); in qca_spi_probe()
984 eth_hw_addr_random(qca->net_dev); in qca_spi_probe()
986 qca->net_dev->dev_addr); in qca_spi_probe()
989 netif_carrier_off(qca->net_dev); in qca_spi_probe()
992 qcaspi_read_register(qca, SPI_REG_SIGNATURE, &signature); in qca_spi_probe()
993 qcaspi_read_register(qca, SPI_REG_SIGNATURE, &signature); in qca_spi_probe()
1010 qcaspi_init_device_debugfs(qca); in qca_spi_probe()
1019 struct qcaspi *qca = netdev_priv(qcaspi_devs); in qca_spi_remove() local
1021 qcaspi_remove_device_debugfs(qca); in qca_spi_remove()