Lines Matching full:fifo

38 /* Virtual devices sharing the TM FIFO. */
67 * @fifo: pointer to the tmfifo structure
83 struct mlxbf_tmfifo *fifo; member
113 * @tx_buf: tx buffer used to buffer data before writing into the FIFO
129 * @fifo: pointer to the tmfifo structure
134 struct mlxbf_tmfifo *fifo; member
143 * @rx_base: mapped register base address for the Rx FIFO
144 * @tx_base: mapped register base address for the Tx FIFO
145 * @rx_fifo_size: number of entries of the Rx FIFO
146 * @tx_fifo_size: number of entries of the Tx FIFO
174 * @len: payload length in network byte order. Messages sent into the FIFO
207 /* Free vrings of the FIFO device. */
208 static void mlxbf_tmfifo_free_vrings(struct mlxbf_tmfifo *fifo, in mlxbf_tmfifo_free_vrings() argument
229 /* Allocate vrings for the FIFO. */
230 static int mlxbf_tmfifo_alloc_vrings(struct mlxbf_tmfifo *fifo, in mlxbf_tmfifo_alloc_vrings() argument
241 vring->fifo = fifo; in mlxbf_tmfifo_alloc_vrings()
251 mlxbf_tmfifo_free_vrings(fifo, tm_vdev); in mlxbf_tmfifo_alloc_vrings()
263 /* Disable interrupts of the FIFO device. */
264 static void mlxbf_tmfifo_disable_irqs(struct mlxbf_tmfifo *fifo) in mlxbf_tmfifo_disable_irqs() argument
269 irq = fifo->irq_info[i].irq; in mlxbf_tmfifo_disable_irqs()
270 fifo->irq_info[i].irq = 0; in mlxbf_tmfifo_disable_irqs()
280 if (!test_and_set_bit(irq_info->index, &irq_info->fifo->pend_events)) in mlxbf_tmfifo_irq_handler()
281 schedule_work(&irq_info->fifo->work); in mlxbf_tmfifo_irq_handler()
398 struct mlxbf_tmfifo *fifo = container_of(t, struct mlxbf_tmfifo, timer); in mlxbf_tmfifo_timer() local
401 rx = !test_and_set_bit(MLXBF_TM_RX_HWM_IRQ, &fifo->pend_events); in mlxbf_tmfifo_timer()
402 tx = !test_and_set_bit(MLXBF_TM_TX_LWM_IRQ, &fifo->pend_events); in mlxbf_tmfifo_timer()
405 schedule_work(&fifo->work); in mlxbf_tmfifo_timer()
407 mod_timer(&fifo->timer, jiffies + MLXBF_TMFIFO_TIMER_INTERVAL); in mlxbf_tmfifo_timer()
467 /* Get the number of available words in Rx FIFO for receiving. */
468 static int mlxbf_tmfifo_get_rx_avail(struct mlxbf_tmfifo *fifo) in mlxbf_tmfifo_get_rx_avail() argument
472 sts = readq(fifo->rx_base + MLXBF_TMFIFO_RX_STS); in mlxbf_tmfifo_get_rx_avail()
477 static int mlxbf_tmfifo_get_tx_avail(struct mlxbf_tmfifo *fifo, int vdev_id) in mlxbf_tmfifo_get_tx_avail() argument
483 /* Reserve some room in FIFO for console messages. */ in mlxbf_tmfifo_get_tx_avail()
485 tx_reserve = fifo->tx_fifo_size / MLXBF_TMFIFO_RESERVE_RATIO; in mlxbf_tmfifo_get_tx_avail()
489 sts = readq(fifo->tx_base + MLXBF_TMFIFO_TX_STS); in mlxbf_tmfifo_get_tx_avail()
491 return fifo->tx_fifo_size - tx_reserve - count; in mlxbf_tmfifo_get_tx_avail()
495 static void mlxbf_tmfifo_console_tx(struct mlxbf_tmfifo *fifo, int avail) in mlxbf_tmfifo_console_tx() argument
508 cons = fifo->vdev[VIRTIO_ID_CONSOLE]; in mlxbf_tmfifo_console_tx()
525 writeq(*(u64 *)&hdr, fifo->tx_base + MLXBF_TMFIFO_TX_DATA); in mlxbf_tmfifo_console_tx()
528 spin_lock_irqsave(&fifo->spin_lock[0], flags); in mlxbf_tmfifo_console_tx()
542 writeq(data, fifo->tx_base + MLXBF_TMFIFO_TX_DATA); in mlxbf_tmfifo_console_tx()
555 spin_unlock_irqrestore(&fifo->spin_lock[0], flags); in mlxbf_tmfifo_console_tx()
564 struct mlxbf_tmfifo *fifo = vring->fifo; in mlxbf_tmfifo_rxtx_word() local
571 /* Read a word from FIFO for Rx. */ in mlxbf_tmfifo_rxtx_word()
573 data = readq(fifo->rx_base + MLXBF_TMFIFO_RX_DATA); in mlxbf_tmfifo_rxtx_word()
593 /* Write the word into FIFO for Tx. */ in mlxbf_tmfifo_rxtx_word()
595 writeq(data, fifo->tx_base + MLXBF_TMFIFO_TX_DATA); in mlxbf_tmfifo_rxtx_word()
609 struct mlxbf_tmfifo *fifo = vring->fifo; in mlxbf_tmfifo_rxtx_header() local
616 /* Drain one word from the FIFO. */ in mlxbf_tmfifo_rxtx_header()
617 *(u64 *)&hdr = readq(fifo->rx_base + MLXBF_TMFIFO_RX_DATA); in mlxbf_tmfifo_rxtx_header()
627 config = &fifo->vdev[vdev_id]->config.net; in mlxbf_tmfifo_rxtx_header()
644 struct mlxbf_tmfifo_vdev *tm_dev2 = fifo->vdev[vdev_id]; in mlxbf_tmfifo_rxtx_header()
661 writeq(*(u64 *)&hdr, fifo->tx_base + MLXBF_TMFIFO_TX_DATA); in mlxbf_tmfifo_rxtx_header()
666 fifo->vring[is_rx] = vring; in mlxbf_tmfifo_rxtx_header()
678 struct mlxbf_tmfifo *fifo = vring->fifo; in mlxbf_tmfifo_rxtx_one_desc() local
685 vdev = &fifo->vdev[vring->vdev_id]->vdev; in mlxbf_tmfifo_rxtx_one_desc()
734 fifo->vring[is_rx] = NULL; in mlxbf_tmfifo_rxtx_one_desc()
737 spin_lock_irqsave(&fifo->spin_lock[is_rx], flags); in mlxbf_tmfifo_rxtx_one_desc()
739 spin_unlock_irqrestore(&fifo->spin_lock[is_rx], flags); in mlxbf_tmfifo_rxtx_one_desc()
753 struct mlxbf_tmfifo *fifo; in mlxbf_tmfifo_rxtx() local
756 fifo = vring->fifo; in mlxbf_tmfifo_rxtx()
759 if (!fifo->vdev[devid]) in mlxbf_tmfifo_rxtx()
763 if (fifo->vring[is_rx] && fifo->vring[is_rx] != vring) in mlxbf_tmfifo_rxtx()
771 /* Get available FIFO space. */ in mlxbf_tmfifo_rxtx()
774 avail = mlxbf_tmfifo_get_rx_avail(fifo); in mlxbf_tmfifo_rxtx()
776 avail = mlxbf_tmfifo_get_tx_avail(fifo, devid); in mlxbf_tmfifo_rxtx()
783 mlxbf_tmfifo_console_tx(fifo, avail); in mlxbf_tmfifo_rxtx()
793 static void mlxbf_tmfifo_work_rxtx(struct mlxbf_tmfifo *fifo, int queue_id, in mlxbf_tmfifo_work_rxtx() argument
800 if (!test_and_clear_bit(irq_id, &fifo->pend_events) || in mlxbf_tmfifo_work_rxtx()
801 !fifo->irq_info[irq_id].irq) in mlxbf_tmfifo_work_rxtx()
805 tm_vdev = fifo->vdev[i]; in mlxbf_tmfifo_work_rxtx()
817 struct mlxbf_tmfifo *fifo; in mlxbf_tmfifo_work_handler() local
819 fifo = container_of(work, struct mlxbf_tmfifo, work); in mlxbf_tmfifo_work_handler()
820 if (!fifo->is_ready) in mlxbf_tmfifo_work_handler()
823 mutex_lock(&fifo->lock); in mlxbf_tmfifo_work_handler()
826 mlxbf_tmfifo_work_rxtx(fifo, MLXBF_TMFIFO_VRING_TX, in mlxbf_tmfifo_work_handler()
830 mlxbf_tmfifo_work_rxtx(fifo, MLXBF_TMFIFO_VRING_RX, in mlxbf_tmfifo_work_handler()
833 mutex_unlock(&fifo->lock); in mlxbf_tmfifo_work_handler()
841 struct mlxbf_tmfifo *fifo; in mlxbf_tmfifo_virtio_notify() local
844 fifo = vring->fifo; in mlxbf_tmfifo_virtio_notify()
858 spin_lock_irqsave(&fifo->spin_lock[0], flags); in mlxbf_tmfifo_virtio_notify()
859 tm_vdev = fifo->vdev[VIRTIO_ID_CONSOLE]; in mlxbf_tmfifo_virtio_notify()
861 spin_unlock_irqrestore(&fifo->spin_lock[0], flags); in mlxbf_tmfifo_virtio_notify()
863 &fifo->pend_events)) { in mlxbf_tmfifo_virtio_notify()
867 if (test_and_set_bit(MLXBF_TM_RX_HWM_IRQ, &fifo->pend_events)) in mlxbf_tmfifo_virtio_notify()
871 schedule_work(&fifo->work); in mlxbf_tmfifo_virtio_notify()
1040 /* Create vdev for the FIFO. */
1042 struct mlxbf_tmfifo *fifo, in mlxbf_tmfifo_create_vdev() argument
1049 mutex_lock(&fifo->lock); in mlxbf_tmfifo_create_vdev()
1051 tm_vdev = fifo->vdev[vdev_id]; in mlxbf_tmfifo_create_vdev()
1072 if (mlxbf_tmfifo_alloc_vrings(fifo, tm_vdev)) { in mlxbf_tmfifo_create_vdev()
1083 fifo->vdev[vdev_id] = tm_vdev; in mlxbf_tmfifo_create_vdev()
1093 mutex_unlock(&fifo->lock); in mlxbf_tmfifo_create_vdev()
1097 mlxbf_tmfifo_free_vrings(fifo, tm_vdev); in mlxbf_tmfifo_create_vdev()
1098 fifo->vdev[vdev_id] = NULL; in mlxbf_tmfifo_create_vdev()
1104 mutex_unlock(&fifo->lock); in mlxbf_tmfifo_create_vdev()
1108 /* Delete vdev for the FIFO. */
1109 static int mlxbf_tmfifo_delete_vdev(struct mlxbf_tmfifo *fifo, int vdev_id) in mlxbf_tmfifo_delete_vdev() argument
1113 mutex_lock(&fifo->lock); in mlxbf_tmfifo_delete_vdev()
1116 tm_vdev = fifo->vdev[vdev_id]; in mlxbf_tmfifo_delete_vdev()
1119 mlxbf_tmfifo_free_vrings(fifo, tm_vdev); in mlxbf_tmfifo_delete_vdev()
1120 fifo->vdev[vdev_id] = NULL; in mlxbf_tmfifo_delete_vdev()
1123 mutex_unlock(&fifo->lock); in mlxbf_tmfifo_delete_vdev()
1144 static void mlxbf_tmfifo_set_threshold(struct mlxbf_tmfifo *fifo) in mlxbf_tmfifo_set_threshold() argument
1148 /* Get Tx FIFO size and set the low/high watermark. */ in mlxbf_tmfifo_set_threshold()
1149 ctl = readq(fifo->tx_base + MLXBF_TMFIFO_TX_CTL); in mlxbf_tmfifo_set_threshold()
1150 fifo->tx_fifo_size = in mlxbf_tmfifo_set_threshold()
1154 fifo->tx_fifo_size / 2); in mlxbf_tmfifo_set_threshold()
1157 fifo->tx_fifo_size - 1); in mlxbf_tmfifo_set_threshold()
1158 writeq(ctl, fifo->tx_base + MLXBF_TMFIFO_TX_CTL); in mlxbf_tmfifo_set_threshold()
1160 /* Get Rx FIFO size and set the low/high watermark. */ in mlxbf_tmfifo_set_threshold()
1161 ctl = readq(fifo->rx_base + MLXBF_TMFIFO_RX_CTL); in mlxbf_tmfifo_set_threshold()
1162 fifo->rx_fifo_size = in mlxbf_tmfifo_set_threshold()
1168 writeq(ctl, fifo->rx_base + MLXBF_TMFIFO_RX_CTL); in mlxbf_tmfifo_set_threshold()
1171 static void mlxbf_tmfifo_cleanup(struct mlxbf_tmfifo *fifo) in mlxbf_tmfifo_cleanup() argument
1175 fifo->is_ready = false; in mlxbf_tmfifo_cleanup()
1176 del_timer_sync(&fifo->timer); in mlxbf_tmfifo_cleanup()
1177 mlxbf_tmfifo_disable_irqs(fifo); in mlxbf_tmfifo_cleanup()
1178 cancel_work_sync(&fifo->work); in mlxbf_tmfifo_cleanup()
1180 mlxbf_tmfifo_delete_vdev(fifo, i); in mlxbf_tmfifo_cleanup()
1188 struct mlxbf_tmfifo *fifo; in mlxbf_tmfifo_probe() local
1191 fifo = devm_kzalloc(dev, sizeof(*fifo), GFP_KERNEL); in mlxbf_tmfifo_probe()
1192 if (!fifo) in mlxbf_tmfifo_probe()
1195 spin_lock_init(&fifo->spin_lock[0]); in mlxbf_tmfifo_probe()
1196 spin_lock_init(&fifo->spin_lock[1]); in mlxbf_tmfifo_probe()
1197 INIT_WORK(&fifo->work, mlxbf_tmfifo_work_handler); in mlxbf_tmfifo_probe()
1198 mutex_init(&fifo->lock); in mlxbf_tmfifo_probe()
1200 /* Get the resource of the Rx FIFO. */ in mlxbf_tmfifo_probe()
1201 fifo->rx_base = devm_platform_ioremap_resource(pdev, 0); in mlxbf_tmfifo_probe()
1202 if (IS_ERR(fifo->rx_base)) in mlxbf_tmfifo_probe()
1203 return PTR_ERR(fifo->rx_base); in mlxbf_tmfifo_probe()
1205 /* Get the resource of the Tx FIFO. */ in mlxbf_tmfifo_probe()
1206 fifo->tx_base = devm_platform_ioremap_resource(pdev, 1); in mlxbf_tmfifo_probe()
1207 if (IS_ERR(fifo->tx_base)) in mlxbf_tmfifo_probe()
1208 return PTR_ERR(fifo->tx_base); in mlxbf_tmfifo_probe()
1210 platform_set_drvdata(pdev, fifo); in mlxbf_tmfifo_probe()
1212 timer_setup(&fifo->timer, mlxbf_tmfifo_timer, 0); in mlxbf_tmfifo_probe()
1215 fifo->irq_info[i].index = i; in mlxbf_tmfifo_probe()
1216 fifo->irq_info[i].fifo = fifo; in mlxbf_tmfifo_probe()
1217 fifo->irq_info[i].irq = platform_get_irq(pdev, i); in mlxbf_tmfifo_probe()
1218 rc = devm_request_irq(dev, fifo->irq_info[i].irq, in mlxbf_tmfifo_probe()
1220 "tmfifo", &fifo->irq_info[i]); in mlxbf_tmfifo_probe()
1223 fifo->irq_info[i].irq = 0; in mlxbf_tmfifo_probe()
1228 mlxbf_tmfifo_set_threshold(fifo); in mlxbf_tmfifo_probe()
1231 rc = mlxbf_tmfifo_create_vdev(dev, fifo, VIRTIO_ID_CONSOLE, 0, NULL, 0); in mlxbf_tmfifo_probe()
1244 rc = mlxbf_tmfifo_create_vdev(dev, fifo, VIRTIO_ID_NET, in mlxbf_tmfifo_probe()
1250 mod_timer(&fifo->timer, jiffies + MLXBF_TMFIFO_TIMER_INTERVAL); in mlxbf_tmfifo_probe()
1252 fifo->is_ready = true; in mlxbf_tmfifo_probe()
1256 mlxbf_tmfifo_cleanup(fifo); in mlxbf_tmfifo_probe()
1263 struct mlxbf_tmfifo *fifo = platform_get_drvdata(pdev); in mlxbf_tmfifo_remove() local
1265 mlxbf_tmfifo_cleanup(fifo); in mlxbf_tmfifo_remove()