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()
401 struct mlxbf_tmfifo *fifo = container_of(t, struct mlxbf_tmfifo, timer); in mlxbf_tmfifo_timer() local
404 rx = !test_and_set_bit(MLXBF_TM_RX_HWM_IRQ, &fifo->pend_events); in mlxbf_tmfifo_timer()
405 tx = !test_and_set_bit(MLXBF_TM_TX_LWM_IRQ, &fifo->pend_events); in mlxbf_tmfifo_timer()
408 schedule_work(&fifo->work); in mlxbf_tmfifo_timer()
410 mod_timer(&fifo->timer, jiffies + MLXBF_TMFIFO_TIMER_INTERVAL); in mlxbf_tmfifo_timer()
470 /* Get the number of available words in Rx FIFO for receiving. */
471 static int mlxbf_tmfifo_get_rx_avail(struct mlxbf_tmfifo *fifo) in mlxbf_tmfifo_get_rx_avail() argument
475 sts = readq(fifo->rx_base + MLXBF_TMFIFO_RX_STS); in mlxbf_tmfifo_get_rx_avail()
480 static int mlxbf_tmfifo_get_tx_avail(struct mlxbf_tmfifo *fifo, int vdev_id) in mlxbf_tmfifo_get_tx_avail() argument
486 /* Reserve some room in FIFO for console messages. */ in mlxbf_tmfifo_get_tx_avail()
488 tx_reserve = fifo->tx_fifo_size / MLXBF_TMFIFO_RESERVE_RATIO; in mlxbf_tmfifo_get_tx_avail()
492 sts = readq(fifo->tx_base + MLXBF_TMFIFO_TX_STS); in mlxbf_tmfifo_get_tx_avail()
494 return fifo->tx_fifo_size - tx_reserve - count; in mlxbf_tmfifo_get_tx_avail()
498 static void mlxbf_tmfifo_console_tx(struct mlxbf_tmfifo *fifo, int avail) in mlxbf_tmfifo_console_tx() argument
511 cons = fifo->vdev[VIRTIO_ID_CONSOLE]; in mlxbf_tmfifo_console_tx()
528 writeq(*(u64 *)&hdr, fifo->tx_base + MLXBF_TMFIFO_TX_DATA); in mlxbf_tmfifo_console_tx()
531 spin_lock_irqsave(&fifo->spin_lock[0], flags); in mlxbf_tmfifo_console_tx()
545 writeq(data, fifo->tx_base + MLXBF_TMFIFO_TX_DATA); in mlxbf_tmfifo_console_tx()
558 spin_unlock_irqrestore(&fifo->spin_lock[0], flags); in mlxbf_tmfifo_console_tx()
567 struct mlxbf_tmfifo *fifo = vring->fifo; in mlxbf_tmfifo_rxtx_word() local
574 /* Read a word from FIFO for Rx. */ in mlxbf_tmfifo_rxtx_word()
576 data = readq(fifo->rx_base + MLXBF_TMFIFO_RX_DATA); in mlxbf_tmfifo_rxtx_word()
596 /* Write the word into FIFO for Tx. */ in mlxbf_tmfifo_rxtx_word()
598 writeq(data, fifo->tx_base + MLXBF_TMFIFO_TX_DATA); in mlxbf_tmfifo_rxtx_word()
612 struct mlxbf_tmfifo *fifo = vring->fifo; in mlxbf_tmfifo_rxtx_header() local
619 /* Drain one word from the FIFO. */ in mlxbf_tmfifo_rxtx_header()
620 *(u64 *)&hdr = readq(fifo->rx_base + MLXBF_TMFIFO_RX_DATA); in mlxbf_tmfifo_rxtx_header()
630 config = &fifo->vdev[vdev_id]->config.net; in mlxbf_tmfifo_rxtx_header()
647 struct mlxbf_tmfifo_vdev *tm_dev2 = fifo->vdev[vdev_id]; in mlxbf_tmfifo_rxtx_header()
664 writeq(*(u64 *)&hdr, fifo->tx_base + MLXBF_TMFIFO_TX_DATA); in mlxbf_tmfifo_rxtx_header()
669 fifo->vring[is_rx] = vring; in mlxbf_tmfifo_rxtx_header()
681 struct mlxbf_tmfifo *fifo = vring->fifo; in mlxbf_tmfifo_rxtx_one_desc() local
688 vdev = &fifo->vdev[vring->vdev_id]->vdev; in mlxbf_tmfifo_rxtx_one_desc()
737 fifo->vring[is_rx] = NULL; in mlxbf_tmfifo_rxtx_one_desc()
746 spin_lock_irqsave(&fifo->spin_lock[is_rx], flags); in mlxbf_tmfifo_rxtx_one_desc()
748 spin_unlock_irqrestore(&fifo->spin_lock[is_rx], flags); in mlxbf_tmfifo_rxtx_one_desc()
762 struct mlxbf_tmfifo *fifo; in mlxbf_tmfifo_rxtx() local
765 fifo = vring->fifo; in mlxbf_tmfifo_rxtx()
768 if (!fifo->vdev[devid]) in mlxbf_tmfifo_rxtx()
772 if (fifo->vring[is_rx] && fifo->vring[is_rx] != vring) in mlxbf_tmfifo_rxtx()
780 /* Get available FIFO space. */ in mlxbf_tmfifo_rxtx()
783 avail = mlxbf_tmfifo_get_rx_avail(fifo); in mlxbf_tmfifo_rxtx()
785 avail = mlxbf_tmfifo_get_tx_avail(fifo, devid); in mlxbf_tmfifo_rxtx()
792 mlxbf_tmfifo_console_tx(fifo, avail); in mlxbf_tmfifo_rxtx()
802 static void mlxbf_tmfifo_work_rxtx(struct mlxbf_tmfifo *fifo, int queue_id, in mlxbf_tmfifo_work_rxtx() argument
809 if (!test_and_clear_bit(irq_id, &fifo->pend_events) || in mlxbf_tmfifo_work_rxtx()
810 !fifo->irq_info[irq_id].irq) in mlxbf_tmfifo_work_rxtx()
814 tm_vdev = fifo->vdev[i]; in mlxbf_tmfifo_work_rxtx()
826 struct mlxbf_tmfifo *fifo; in mlxbf_tmfifo_work_handler() local
828 fifo = container_of(work, struct mlxbf_tmfifo, work); in mlxbf_tmfifo_work_handler()
829 if (!fifo->is_ready) in mlxbf_tmfifo_work_handler()
832 mutex_lock(&fifo->lock); in mlxbf_tmfifo_work_handler()
835 mlxbf_tmfifo_work_rxtx(fifo, MLXBF_TMFIFO_VRING_TX, in mlxbf_tmfifo_work_handler()
839 mlxbf_tmfifo_work_rxtx(fifo, MLXBF_TMFIFO_VRING_RX, in mlxbf_tmfifo_work_handler()
842 mutex_unlock(&fifo->lock); in mlxbf_tmfifo_work_handler()
850 struct mlxbf_tmfifo *fifo; in mlxbf_tmfifo_virtio_notify() local
853 fifo = vring->fifo; in mlxbf_tmfifo_virtio_notify()
867 spin_lock_irqsave(&fifo->spin_lock[0], flags); in mlxbf_tmfifo_virtio_notify()
868 tm_vdev = fifo->vdev[VIRTIO_ID_CONSOLE]; in mlxbf_tmfifo_virtio_notify()
870 spin_unlock_irqrestore(&fifo->spin_lock[0], flags); in mlxbf_tmfifo_virtio_notify()
872 &fifo->pend_events)) { in mlxbf_tmfifo_virtio_notify()
876 if (test_and_set_bit(MLXBF_TM_RX_HWM_IRQ, &fifo->pend_events)) in mlxbf_tmfifo_virtio_notify()
880 schedule_work(&fifo->work); in mlxbf_tmfifo_virtio_notify()
1049 /* Create vdev for the FIFO. */
1051 struct mlxbf_tmfifo *fifo, in mlxbf_tmfifo_create_vdev() argument
1058 mutex_lock(&fifo->lock); in mlxbf_tmfifo_create_vdev()
1060 tm_vdev = fifo->vdev[vdev_id]; in mlxbf_tmfifo_create_vdev()
1081 if (mlxbf_tmfifo_alloc_vrings(fifo, tm_vdev)) { in mlxbf_tmfifo_create_vdev()
1092 fifo->vdev[vdev_id] = tm_vdev; in mlxbf_tmfifo_create_vdev()
1102 mutex_unlock(&fifo->lock); in mlxbf_tmfifo_create_vdev()
1106 mlxbf_tmfifo_free_vrings(fifo, tm_vdev); in mlxbf_tmfifo_create_vdev()
1107 fifo->vdev[vdev_id] = NULL; in mlxbf_tmfifo_create_vdev()
1113 mutex_unlock(&fifo->lock); in mlxbf_tmfifo_create_vdev()
1117 /* Delete vdev for the FIFO. */
1118 static int mlxbf_tmfifo_delete_vdev(struct mlxbf_tmfifo *fifo, int vdev_id) in mlxbf_tmfifo_delete_vdev() argument
1122 mutex_lock(&fifo->lock); in mlxbf_tmfifo_delete_vdev()
1125 tm_vdev = fifo->vdev[vdev_id]; in mlxbf_tmfifo_delete_vdev()
1128 mlxbf_tmfifo_free_vrings(fifo, tm_vdev); in mlxbf_tmfifo_delete_vdev()
1129 fifo->vdev[vdev_id] = NULL; in mlxbf_tmfifo_delete_vdev()
1132 mutex_unlock(&fifo->lock); in mlxbf_tmfifo_delete_vdev()
1153 static void mlxbf_tmfifo_set_threshold(struct mlxbf_tmfifo *fifo) in mlxbf_tmfifo_set_threshold() argument
1157 /* Get Tx FIFO size and set the low/high watermark. */ in mlxbf_tmfifo_set_threshold()
1158 ctl = readq(fifo->tx_base + MLXBF_TMFIFO_TX_CTL); in mlxbf_tmfifo_set_threshold()
1159 fifo->tx_fifo_size = in mlxbf_tmfifo_set_threshold()
1163 fifo->tx_fifo_size / 2); in mlxbf_tmfifo_set_threshold()
1166 fifo->tx_fifo_size - 1); in mlxbf_tmfifo_set_threshold()
1167 writeq(ctl, fifo->tx_base + MLXBF_TMFIFO_TX_CTL); in mlxbf_tmfifo_set_threshold()
1169 /* Get Rx FIFO size and set the low/high watermark. */ in mlxbf_tmfifo_set_threshold()
1170 ctl = readq(fifo->rx_base + MLXBF_TMFIFO_RX_CTL); in mlxbf_tmfifo_set_threshold()
1171 fifo->rx_fifo_size = in mlxbf_tmfifo_set_threshold()
1177 writeq(ctl, fifo->rx_base + MLXBF_TMFIFO_RX_CTL); in mlxbf_tmfifo_set_threshold()
1180 static void mlxbf_tmfifo_cleanup(struct mlxbf_tmfifo *fifo) in mlxbf_tmfifo_cleanup() argument
1184 fifo->is_ready = false; in mlxbf_tmfifo_cleanup()
1185 del_timer_sync(&fifo->timer); in mlxbf_tmfifo_cleanup()
1186 mlxbf_tmfifo_disable_irqs(fifo); in mlxbf_tmfifo_cleanup()
1187 cancel_work_sync(&fifo->work); in mlxbf_tmfifo_cleanup()
1189 mlxbf_tmfifo_delete_vdev(fifo, i); in mlxbf_tmfifo_cleanup()
1197 struct mlxbf_tmfifo *fifo; in mlxbf_tmfifo_probe() local
1200 fifo = devm_kzalloc(dev, sizeof(*fifo), GFP_KERNEL); in mlxbf_tmfifo_probe()
1201 if (!fifo) in mlxbf_tmfifo_probe()
1204 spin_lock_init(&fifo->spin_lock[0]); in mlxbf_tmfifo_probe()
1205 spin_lock_init(&fifo->spin_lock[1]); in mlxbf_tmfifo_probe()
1206 INIT_WORK(&fifo->work, mlxbf_tmfifo_work_handler); in mlxbf_tmfifo_probe()
1207 mutex_init(&fifo->lock); in mlxbf_tmfifo_probe()
1209 /* Get the resource of the Rx FIFO. */ in mlxbf_tmfifo_probe()
1210 fifo->rx_base = devm_platform_ioremap_resource(pdev, 0); in mlxbf_tmfifo_probe()
1211 if (IS_ERR(fifo->rx_base)) in mlxbf_tmfifo_probe()
1212 return PTR_ERR(fifo->rx_base); in mlxbf_tmfifo_probe()
1214 /* Get the resource of the Tx FIFO. */ in mlxbf_tmfifo_probe()
1215 fifo->tx_base = devm_platform_ioremap_resource(pdev, 1); in mlxbf_tmfifo_probe()
1216 if (IS_ERR(fifo->tx_base)) in mlxbf_tmfifo_probe()
1217 return PTR_ERR(fifo->tx_base); in mlxbf_tmfifo_probe()
1219 platform_set_drvdata(pdev, fifo); in mlxbf_tmfifo_probe()
1221 timer_setup(&fifo->timer, mlxbf_tmfifo_timer, 0); in mlxbf_tmfifo_probe()
1224 fifo->irq_info[i].index = i; in mlxbf_tmfifo_probe()
1225 fifo->irq_info[i].fifo = fifo; in mlxbf_tmfifo_probe()
1226 fifo->irq_info[i].irq = platform_get_irq(pdev, i); in mlxbf_tmfifo_probe()
1227 rc = devm_request_irq(dev, fifo->irq_info[i].irq, in mlxbf_tmfifo_probe()
1229 "tmfifo", &fifo->irq_info[i]); in mlxbf_tmfifo_probe()
1232 fifo->irq_info[i].irq = 0; in mlxbf_tmfifo_probe()
1237 mlxbf_tmfifo_set_threshold(fifo); in mlxbf_tmfifo_probe()
1240 rc = mlxbf_tmfifo_create_vdev(dev, fifo, VIRTIO_ID_CONSOLE, 0, NULL, 0); in mlxbf_tmfifo_probe()
1253 rc = mlxbf_tmfifo_create_vdev(dev, fifo, VIRTIO_ID_NET, in mlxbf_tmfifo_probe()
1259 mod_timer(&fifo->timer, jiffies + MLXBF_TMFIFO_TIMER_INTERVAL); in mlxbf_tmfifo_probe()
1261 fifo->is_ready = true; in mlxbf_tmfifo_probe()
1265 mlxbf_tmfifo_cleanup(fifo); in mlxbf_tmfifo_probe()
1272 struct mlxbf_tmfifo *fifo = platform_get_drvdata(pdev); in mlxbf_tmfifo_remove() local
1274 mlxbf_tmfifo_cleanup(fifo); in mlxbf_tmfifo_remove()