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 qca->rx_skb->ip_summed = CHECKSUM_UNNECESSARY; in qcaspi_receive()
438 netif_rx_ni(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 qca->sync = QCASPI_SYNC_UNKNOWN; in qcaspi_qca7k_sync()
508 netdev_dbg(qca->net_dev, "sync: got CPU on, but signature was invalid, restart\n"); in qcaspi_qca7k_sync()
511 qcaspi_read_register(qca, SPI_REG_WRBUF_SPC_AVA, in qcaspi_qca7k_sync()
514 netdev_dbg(qca->net_dev, "sync: got CPU on, but wrbuf not empty. reset!\n"); in qcaspi_qca7k_sync()
515 qca->sync = QCASPI_SYNC_UNKNOWN; in qcaspi_qca7k_sync()
517 netdev_dbg(qca->net_dev, "sync: got CPU on, now in sync\n"); in qcaspi_qca7k_sync()
518 qca->sync = QCASPI_SYNC_READY; in qcaspi_qca7k_sync()
524 switch (qca->sync) { in qcaspi_qca7k_sync()
527 qcaspi_read_register(qca, SPI_REG_SIGNATURE, &signature); in qcaspi_qca7k_sync()
529 qca->sync = QCASPI_SYNC_UNKNOWN; in qcaspi_qca7k_sync()
530 netdev_dbg(qca->net_dev, "sync: bad signature, restart\n"); in qcaspi_qca7k_sync()
537 qcaspi_read_register(qca, SPI_REG_SIGNATURE, &signature); in qcaspi_qca7k_sync()
539 netdev_dbg(qca->net_dev, "sync: could not read signature to reset device, retry.\n"); in qcaspi_qca7k_sync()
544 netdev_dbg(qca->net_dev, "sync: resetting device.\n"); in qcaspi_qca7k_sync()
545 qcaspi_read_register(qca, SPI_REG_SPI_CONFIG, &spi_config); in qcaspi_qca7k_sync()
547 qcaspi_write_register(qca, SPI_REG_SPI_CONFIG, spi_config, 0); in qcaspi_qca7k_sync()
549 qca->sync = QCASPI_SYNC_RESET; in qcaspi_qca7k_sync()
550 qca->stats.trig_reset++; in qcaspi_qca7k_sync()
551 qca->reset_count = 0; in qcaspi_qca7k_sync()
554 qca->reset_count++; in qcaspi_qca7k_sync()
555 netdev_dbg(qca->net_dev, "sync: waiting for CPU on, count %u.\n", in qcaspi_qca7k_sync()
556 qca->reset_count); in qcaspi_qca7k_sync()
557 if (qca->reset_count >= QCASPI_RESET_TIMEOUT) { in qcaspi_qca7k_sync()
559 qca->sync = QCASPI_SYNC_UNKNOWN; in qcaspi_qca7k_sync()
560 qca->stats.reset_timeout++; in qcaspi_qca7k_sync()
561 netdev_dbg(qca->net_dev, "sync: reset timeout, restarting process.\n"); in qcaspi_qca7k_sync()
570 struct qcaspi *qca = data; in qcaspi_spi_thread() local
573 netdev_info(qca->net_dev, "SPI thread created\n"); in qcaspi_spi_thread()
576 if ((qca->intr_req == qca->intr_svc) && in qcaspi_spi_thread()
577 (qca->txr.skb[qca->txr.head] == NULL) && in qcaspi_spi_thread()
578 (qca->sync == QCASPI_SYNC_READY)) in qcaspi_spi_thread()
583 netdev_dbg(qca->net_dev, "have work to do. int: %d, tx_skb: %p\n", in qcaspi_spi_thread()
584 qca->intr_req - qca->intr_svc, in qcaspi_spi_thread()
585 qca->txr.skb[qca->txr.head]); in qcaspi_spi_thread()
587 qcaspi_qca7k_sync(qca, QCASPI_EVENT_UPDATE); in qcaspi_spi_thread()
589 if (qca->sync != QCASPI_SYNC_READY) { in qcaspi_spi_thread()
590 netdev_dbg(qca->net_dev, "sync: not ready %u, turn off carrier and flush\n", in qcaspi_spi_thread()
591 (unsigned int)qca->sync); in qcaspi_spi_thread()
592 netif_stop_queue(qca->net_dev); in qcaspi_spi_thread()
593 netif_carrier_off(qca->net_dev); in qcaspi_spi_thread()
594 qcaspi_flush_tx_ring(qca); in qcaspi_spi_thread()
598 if (qca->intr_svc != qca->intr_req) { in qcaspi_spi_thread()
599 qca->intr_svc = qca->intr_req; in qcaspi_spi_thread()
600 start_spi_intr_handling(qca, &intr_cause); in qcaspi_spi_thread()
603 qcaspi_qca7k_sync(qca, QCASPI_EVENT_CPUON); in qcaspi_spi_thread()
606 if (qca->sync != QCASPI_SYNC_READY) in qcaspi_spi_thread()
609 qca->stats.device_reset++; in qcaspi_spi_thread()
610 netif_wake_queue(qca->net_dev); in qcaspi_spi_thread()
611 netif_carrier_on(qca->net_dev); in qcaspi_spi_thread()
616 netdev_dbg(qca->net_dev, "===> rdbuf error!\n"); in qcaspi_spi_thread()
617 qca->stats.read_buf_err++; in qcaspi_spi_thread()
618 qca->sync = QCASPI_SYNC_UNKNOWN; in qcaspi_spi_thread()
624 netdev_dbg(qca->net_dev, "===> wrbuf error!\n"); in qcaspi_spi_thread()
625 qca->stats.write_buf_err++; in qcaspi_spi_thread()
626 qca->sync = QCASPI_SYNC_UNKNOWN; in qcaspi_spi_thread()
633 if (qca->sync == QCASPI_SYNC_READY) { in qcaspi_spi_thread()
635 qcaspi_receive(qca); in qcaspi_spi_thread()
638 end_spi_intr_handling(qca, intr_cause); in qcaspi_spi_thread()
641 if (qca->sync == QCASPI_SYNC_READY) in qcaspi_spi_thread()
642 qcaspi_transmit(qca); in qcaspi_spi_thread()
645 netdev_info(qca->net_dev, "SPI thread exit\n"); in qcaspi_spi_thread()
653 struct qcaspi *qca = data; in qcaspi_intr_handler() local
655 qca->intr_req++; in qcaspi_intr_handler()
656 if (qca->spi_thread && in qcaspi_intr_handler()
657 qca->spi_thread->state != TASK_RUNNING) in qcaspi_intr_handler()
658 wake_up_process(qca->spi_thread); in qcaspi_intr_handler()
666 struct qcaspi *qca = netdev_priv(dev); in qcaspi_netdev_open() local
669 if (!qca) in qcaspi_netdev_open()
672 qca->intr_req = 1; in qcaspi_netdev_open()
673 qca->intr_svc = 0; in qcaspi_netdev_open()
674 qca->sync = QCASPI_SYNC_UNKNOWN; in qcaspi_netdev_open()
675 qcafrm_fsm_init_spi(&qca->frm_handle); in qcaspi_netdev_open()
677 qca->spi_thread = kthread_run((void *)qcaspi_spi_thread, in qcaspi_netdev_open()
678 qca, "%s", dev->name); in qcaspi_netdev_open()
680 if (IS_ERR(qca->spi_thread)) { in qcaspi_netdev_open()
683 return PTR_ERR(qca->spi_thread); in qcaspi_netdev_open()
686 ret = request_irq(qca->spi_dev->irq, qcaspi_intr_handler, 0, in qcaspi_netdev_open()
687 dev->name, qca); in qcaspi_netdev_open()
690 QCASPI_DRV_NAME, qca->spi_dev->irq, ret); in qcaspi_netdev_open()
691 kthread_stop(qca->spi_thread); in qcaspi_netdev_open()
703 struct qcaspi *qca = netdev_priv(dev); in qcaspi_netdev_close() local
707 qcaspi_write_register(qca, SPI_REG_INTR_ENABLE, 0, wr_verify); in qcaspi_netdev_close()
708 free_irq(qca->spi_dev->irq, qca); in qcaspi_netdev_close()
710 kthread_stop(qca->spi_thread); in qcaspi_netdev_close()
711 qca->spi_thread = NULL; in qcaspi_netdev_close()
712 qcaspi_flush_tx_ring(qca); in qcaspi_netdev_close()
722 struct qcaspi *qca = netdev_priv(dev); in qcaspi_netdev_xmit() local
730 if (qca->txr.skb[qca->txr.tail]) { in qcaspi_netdev_xmit()
731 netdev_warn(qca->net_dev, "queue was unexpectedly full!\n"); in qcaspi_netdev_xmit()
732 netif_stop_queue(qca->net_dev); in qcaspi_netdev_xmit()
733 qca->stats.ring_full++; in qcaspi_netdev_xmit()
742 qca->stats.out_of_mem++; in qcaspi_netdev_xmit()
761 netdev_dbg(qca->net_dev, "Tx-ing packet: Size: 0x%08x\n", in qcaspi_netdev_xmit()
764 qca->txr.size += skb->len + QCASPI_HW_PKT_LEN; in qcaspi_netdev_xmit()
766 new_tail = qca->txr.tail + 1; in qcaspi_netdev_xmit()
767 if (new_tail >= qca->txr.count) in qcaspi_netdev_xmit()
770 qca->txr.skb[qca->txr.tail] = skb; in qcaspi_netdev_xmit()
771 qca->txr.tail = new_tail; in qcaspi_netdev_xmit()
773 if (!qcaspi_tx_ring_has_space(&qca->txr)) { in qcaspi_netdev_xmit()
774 netif_stop_queue(qca->net_dev); in qcaspi_netdev_xmit()
775 qca->stats.ring_full++; in qcaspi_netdev_xmit()
780 if (qca->spi_thread && in qcaspi_netdev_xmit()
781 qca->spi_thread->state != TASK_RUNNING) in qcaspi_netdev_xmit()
782 wake_up_process(qca->spi_thread); in qcaspi_netdev_xmit()
790 struct qcaspi *qca = netdev_priv(dev); in qcaspi_netdev_tx_timeout() local
792 netdev_info(qca->net_dev, "Transmit timeout at %ld, latency %ld\n", in qcaspi_netdev_tx_timeout()
794 qca->net_dev->stats.tx_errors++; in qcaspi_netdev_tx_timeout()
796 qca->sync = QCASPI_SYNC_UNKNOWN; in qcaspi_netdev_tx_timeout()
798 if (qca->spi_thread) in qcaspi_netdev_tx_timeout()
799 wake_up_process(qca->spi_thread); in qcaspi_netdev_tx_timeout()
805 struct qcaspi *qca = netdev_priv(dev); in qcaspi_netdev_init() local
809 qca->clkspeed = qcaspi_clkspeed; in qcaspi_netdev_init()
810 qca->burst_len = qcaspi_burst_len; in qcaspi_netdev_init()
811 qca->spi_thread = NULL; in qcaspi_netdev_init()
812 qca->buffer_size = (dev->mtu + VLAN_ETH_HLEN + QCAFRM_HEADER_LEN + in qcaspi_netdev_init()
815 memset(&qca->stats, 0, sizeof(struct qcaspi_stats)); in qcaspi_netdev_init()
817 qca->rx_buffer = kmalloc(qca->buffer_size, GFP_KERNEL); in qcaspi_netdev_init()
818 if (!qca->rx_buffer) in qcaspi_netdev_init()
821 qca->rx_skb = netdev_alloc_skb_ip_align(dev, qca->net_dev->mtu + in qcaspi_netdev_init()
823 if (!qca->rx_skb) { in qcaspi_netdev_init()
824 kfree(qca->rx_buffer); in qcaspi_netdev_init()
825 netdev_info(qca->net_dev, "Failed to allocate RX sk_buff.\n"); in qcaspi_netdev_init()
835 struct qcaspi *qca = netdev_priv(dev); in qcaspi_netdev_uninit() local
837 kfree(qca->rx_buffer); in qcaspi_netdev_uninit()
838 qca->buffer_size = 0; in qcaspi_netdev_uninit()
839 dev_kfree_skb(qca->rx_skb); in qcaspi_netdev_uninit()
856 struct qcaspi *qca = NULL; in qcaspi_netdev_setup() local
868 qca = netdev_priv(dev); in qcaspi_netdev_setup()
869 memset(qca, 0, sizeof(struct qcaspi)); in qcaspi_netdev_setup()
871 memset(&qca->txr, 0, sizeof(qca->txr)); in qcaspi_netdev_setup()
872 qca->txr.count = TX_RING_MAX_LEN; in qcaspi_netdev_setup()
884 struct qcaspi *qca = NULL; in qca_spi_probe() local
953 qca = netdev_priv(qcaspi_devs); in qca_spi_probe()
954 if (!qca) { in qca_spi_probe()
959 qca->net_dev = qcaspi_devs; in qca_spi_probe()
960 qca->spi_dev = spi; in qca_spi_probe()
961 qca->legacy_mode = legacy_mode; in qca_spi_probe()
968 ether_addr_copy(qca->net_dev->dev_addr, mac); in qca_spi_probe()
970 if (!is_valid_ether_addr(qca->net_dev->dev_addr)) { in qca_spi_probe()
971 eth_hw_addr_random(qca->net_dev); in qca_spi_probe()
973 qca->net_dev->dev_addr); in qca_spi_probe()
976 netif_carrier_off(qca->net_dev); in qca_spi_probe()
979 qcaspi_read_register(qca, SPI_REG_SIGNATURE, &signature); in qca_spi_probe()
980 qcaspi_read_register(qca, SPI_REG_SIGNATURE, &signature); in qca_spi_probe()
997 qcaspi_init_device_debugfs(qca); in qca_spi_probe()
1006 struct qcaspi *qca = netdev_priv(qcaspi_devs); in qca_spi_remove() local
1008 qcaspi_remove_device_debugfs(qca); in qca_spi_remove()