Lines Matching full:fifo
38 /* Virtual devices sharing the TM FIFO. */
68 * @fifo: pointer to the tmfifo structure
85 struct mlxbf_tmfifo *fifo; member
123 * @tx_buf: tx buffer used to buffer data before writing into the FIFO
139 * @fifo: pointer to the tmfifo structure
144 struct mlxbf_tmfifo *fifo; member
153 * @rx_base: mapped register base address for the Rx FIFO
154 * @tx_base: mapped register base address for the Tx FIFO
155 * @rx_fifo_size: number of entries of the Rx FIFO
156 * @tx_fifo_size: number of entries of the Tx FIFO
184 * @len: payload length in network byte order. Messages sent into the FIFO
217 /* Free vrings of the FIFO device. */
218 static void mlxbf_tmfifo_free_vrings(struct mlxbf_tmfifo *fifo, in mlxbf_tmfifo_free_vrings() argument
239 /* Allocate vrings for the FIFO. */
240 static int mlxbf_tmfifo_alloc_vrings(struct mlxbf_tmfifo *fifo, in mlxbf_tmfifo_alloc_vrings() argument
251 vring->fifo = fifo; in mlxbf_tmfifo_alloc_vrings()
262 mlxbf_tmfifo_free_vrings(fifo, tm_vdev); in mlxbf_tmfifo_alloc_vrings()
274 /* Disable interrupts of the FIFO device. */
275 static void mlxbf_tmfifo_disable_irqs(struct mlxbf_tmfifo *fifo) in mlxbf_tmfifo_disable_irqs() argument
280 irq = fifo->irq_info[i].irq; in mlxbf_tmfifo_disable_irqs()
281 fifo->irq_info[i].irq = 0; in mlxbf_tmfifo_disable_irqs()
291 if (!test_and_set_bit(irq_info->index, &irq_info->fifo->pend_events)) in mlxbf_tmfifo_irq_handler()
292 schedule_work(&irq_info->fifo->work); in mlxbf_tmfifo_irq_handler()
412 struct mlxbf_tmfifo *fifo = container_of(t, struct mlxbf_tmfifo, timer); in mlxbf_tmfifo_timer() local
415 rx = !test_and_set_bit(MLXBF_TM_RX_HWM_IRQ, &fifo->pend_events); in mlxbf_tmfifo_timer()
416 tx = !test_and_set_bit(MLXBF_TM_TX_LWM_IRQ, &fifo->pend_events); in mlxbf_tmfifo_timer()
419 schedule_work(&fifo->work); in mlxbf_tmfifo_timer()
421 mod_timer(&fifo->timer, jiffies + MLXBF_TMFIFO_TIMER_INTERVAL); in mlxbf_tmfifo_timer()
481 /* Get the number of available words in Rx FIFO for receiving. */
482 static int mlxbf_tmfifo_get_rx_avail(struct mlxbf_tmfifo *fifo) in mlxbf_tmfifo_get_rx_avail() argument
486 sts = readq(fifo->rx_base + MLXBF_TMFIFO_RX_STS); in mlxbf_tmfifo_get_rx_avail()
491 static int mlxbf_tmfifo_get_tx_avail(struct mlxbf_tmfifo *fifo, int vdev_id) in mlxbf_tmfifo_get_tx_avail() argument
497 /* Reserve some room in FIFO for console messages. */ in mlxbf_tmfifo_get_tx_avail()
499 tx_reserve = fifo->tx_fifo_size / MLXBF_TMFIFO_RESERVE_RATIO; in mlxbf_tmfifo_get_tx_avail()
503 sts = readq(fifo->tx_base + MLXBF_TMFIFO_TX_STS); in mlxbf_tmfifo_get_tx_avail()
505 return fifo->tx_fifo_size - tx_reserve - count; in mlxbf_tmfifo_get_tx_avail()
509 static void mlxbf_tmfifo_console_tx(struct mlxbf_tmfifo *fifo, int avail) in mlxbf_tmfifo_console_tx() argument
522 cons = fifo->vdev[VIRTIO_ID_CONSOLE]; in mlxbf_tmfifo_console_tx()
539 writeq(*(u64 *)&hdr, fifo->tx_base + MLXBF_TMFIFO_TX_DATA); in mlxbf_tmfifo_console_tx()
542 spin_lock_irqsave(&fifo->spin_lock[0], flags); in mlxbf_tmfifo_console_tx()
556 writeq(data, fifo->tx_base + MLXBF_TMFIFO_TX_DATA); in mlxbf_tmfifo_console_tx()
569 spin_unlock_irqrestore(&fifo->spin_lock[0], flags); in mlxbf_tmfifo_console_tx()
578 struct mlxbf_tmfifo *fifo = vring->fifo; in mlxbf_tmfifo_rxtx_word() local
585 /* Read a word from FIFO for Rx. */ in mlxbf_tmfifo_rxtx_word()
587 data = readq(fifo->rx_base + MLXBF_TMFIFO_RX_DATA); in mlxbf_tmfifo_rxtx_word()
614 /* Write the word into FIFO for Tx. */ in mlxbf_tmfifo_rxtx_word()
616 writeq(data, fifo->tx_base + MLXBF_TMFIFO_TX_DATA); in mlxbf_tmfifo_rxtx_word()
630 struct mlxbf_tmfifo *fifo = vring->fifo; in mlxbf_tmfifo_rxtx_header() local
638 /* Drain one word from the FIFO. */ in mlxbf_tmfifo_rxtx_header()
639 *(u64 *)&hdr = readq(fifo->rx_base + MLXBF_TMFIFO_RX_DATA); in mlxbf_tmfifo_rxtx_header()
649 config = &fifo->vdev[vdev_id]->config.net; in mlxbf_tmfifo_rxtx_header()
666 struct mlxbf_tmfifo_vdev *tm_dev2 = fifo->vdev[vdev_id]; in mlxbf_tmfifo_rxtx_header()
692 writeq(*(u64 *)&hdr, fifo->tx_base + MLXBF_TMFIFO_TX_DATA); in mlxbf_tmfifo_rxtx_header()
697 fifo->vring[is_rx] = vring; in mlxbf_tmfifo_rxtx_header()
709 struct mlxbf_tmfifo *fifo = vring->fifo; in mlxbf_tmfifo_rxtx_one_desc() local
716 vdev = &fifo->vdev[vring->vdev_id]->vdev; in mlxbf_tmfifo_rxtx_one_desc()
772 fifo->vring[is_rx] = NULL; in mlxbf_tmfifo_rxtx_one_desc()
789 spin_lock_irqsave(&fifo->spin_lock[is_rx], flags); in mlxbf_tmfifo_rxtx_one_desc()
791 spin_unlock_irqrestore(&fifo->spin_lock[is_rx], flags); in mlxbf_tmfifo_rxtx_one_desc()
805 struct mlxbf_tmfifo *fifo; in mlxbf_tmfifo_rxtx() local
808 fifo = vring->fifo; in mlxbf_tmfifo_rxtx()
811 if (!fifo->vdev[devid]) in mlxbf_tmfifo_rxtx()
815 if (fifo->vring[is_rx] && fifo->vring[is_rx] != vring) in mlxbf_tmfifo_rxtx()
823 /* Get available FIFO space. */ in mlxbf_tmfifo_rxtx()
826 avail = mlxbf_tmfifo_get_rx_avail(fifo); in mlxbf_tmfifo_rxtx()
828 avail = mlxbf_tmfifo_get_tx_avail(fifo, devid); in mlxbf_tmfifo_rxtx()
835 mlxbf_tmfifo_console_tx(fifo, avail); in mlxbf_tmfifo_rxtx()
845 static void mlxbf_tmfifo_work_rxtx(struct mlxbf_tmfifo *fifo, int queue_id, in mlxbf_tmfifo_work_rxtx() argument
852 if (!test_and_clear_bit(irq_id, &fifo->pend_events) || in mlxbf_tmfifo_work_rxtx()
853 !fifo->irq_info[irq_id].irq) in mlxbf_tmfifo_work_rxtx()
857 tm_vdev = fifo->vdev[i]; in mlxbf_tmfifo_work_rxtx()
869 struct mlxbf_tmfifo *fifo; in mlxbf_tmfifo_work_handler() local
871 fifo = container_of(work, struct mlxbf_tmfifo, work); in mlxbf_tmfifo_work_handler()
872 if (!fifo->is_ready) in mlxbf_tmfifo_work_handler()
875 mutex_lock(&fifo->lock); in mlxbf_tmfifo_work_handler()
878 mlxbf_tmfifo_work_rxtx(fifo, MLXBF_TMFIFO_VRING_TX, in mlxbf_tmfifo_work_handler()
882 mlxbf_tmfifo_work_rxtx(fifo, MLXBF_TMFIFO_VRING_RX, in mlxbf_tmfifo_work_handler()
885 mutex_unlock(&fifo->lock); in mlxbf_tmfifo_work_handler()
893 struct mlxbf_tmfifo *fifo; in mlxbf_tmfifo_virtio_notify() local
896 fifo = vring->fifo; in mlxbf_tmfifo_virtio_notify()
910 spin_lock_irqsave(&fifo->spin_lock[0], flags); in mlxbf_tmfifo_virtio_notify()
911 tm_vdev = fifo->vdev[VIRTIO_ID_CONSOLE]; in mlxbf_tmfifo_virtio_notify()
913 spin_unlock_irqrestore(&fifo->spin_lock[0], flags); in mlxbf_tmfifo_virtio_notify()
914 set_bit(MLXBF_TM_TX_LWM_IRQ, &fifo->pend_events); in mlxbf_tmfifo_virtio_notify()
916 &fifo->pend_events)) { in mlxbf_tmfifo_virtio_notify()
920 if (test_and_set_bit(MLXBF_TM_RX_HWM_IRQ, &fifo->pend_events)) in mlxbf_tmfifo_virtio_notify()
924 schedule_work(&fifo->work); in mlxbf_tmfifo_virtio_notify()
1093 /* Create vdev for the FIFO. */
1095 struct mlxbf_tmfifo *fifo, in mlxbf_tmfifo_create_vdev() argument
1102 mutex_lock(&fifo->lock); in mlxbf_tmfifo_create_vdev()
1104 tm_vdev = fifo->vdev[vdev_id]; in mlxbf_tmfifo_create_vdev()
1125 if (mlxbf_tmfifo_alloc_vrings(fifo, tm_vdev)) { in mlxbf_tmfifo_create_vdev()
1136 fifo->vdev[vdev_id] = tm_vdev; in mlxbf_tmfifo_create_vdev()
1146 mutex_unlock(&fifo->lock); in mlxbf_tmfifo_create_vdev()
1150 mlxbf_tmfifo_free_vrings(fifo, tm_vdev); in mlxbf_tmfifo_create_vdev()
1151 fifo->vdev[vdev_id] = NULL; in mlxbf_tmfifo_create_vdev()
1157 mutex_unlock(&fifo->lock); in mlxbf_tmfifo_create_vdev()
1161 /* Delete vdev for the FIFO. */
1162 static int mlxbf_tmfifo_delete_vdev(struct mlxbf_tmfifo *fifo, int vdev_id) in mlxbf_tmfifo_delete_vdev() argument
1166 mutex_lock(&fifo->lock); in mlxbf_tmfifo_delete_vdev()
1169 tm_vdev = fifo->vdev[vdev_id]; in mlxbf_tmfifo_delete_vdev()
1172 mlxbf_tmfifo_free_vrings(fifo, tm_vdev); in mlxbf_tmfifo_delete_vdev()
1173 fifo->vdev[vdev_id] = NULL; in mlxbf_tmfifo_delete_vdev()
1176 mutex_unlock(&fifo->lock); in mlxbf_tmfifo_delete_vdev()
1197 static void mlxbf_tmfifo_set_threshold(struct mlxbf_tmfifo *fifo) in mlxbf_tmfifo_set_threshold() argument
1201 /* Get Tx FIFO size and set the low/high watermark. */ in mlxbf_tmfifo_set_threshold()
1202 ctl = readq(fifo->tx_base + MLXBF_TMFIFO_TX_CTL); in mlxbf_tmfifo_set_threshold()
1203 fifo->tx_fifo_size = in mlxbf_tmfifo_set_threshold()
1207 fifo->tx_fifo_size / 2); in mlxbf_tmfifo_set_threshold()
1210 fifo->tx_fifo_size - 1); in mlxbf_tmfifo_set_threshold()
1211 writeq(ctl, fifo->tx_base + MLXBF_TMFIFO_TX_CTL); in mlxbf_tmfifo_set_threshold()
1213 /* Get Rx FIFO size and set the low/high watermark. */ in mlxbf_tmfifo_set_threshold()
1214 ctl = readq(fifo->rx_base + MLXBF_TMFIFO_RX_CTL); in mlxbf_tmfifo_set_threshold()
1215 fifo->rx_fifo_size = in mlxbf_tmfifo_set_threshold()
1221 writeq(ctl, fifo->rx_base + MLXBF_TMFIFO_RX_CTL); in mlxbf_tmfifo_set_threshold()
1224 static void mlxbf_tmfifo_cleanup(struct mlxbf_tmfifo *fifo) in mlxbf_tmfifo_cleanup() argument
1228 fifo->is_ready = false; in mlxbf_tmfifo_cleanup()
1229 del_timer_sync(&fifo->timer); in mlxbf_tmfifo_cleanup()
1230 mlxbf_tmfifo_disable_irqs(fifo); in mlxbf_tmfifo_cleanup()
1231 cancel_work_sync(&fifo->work); in mlxbf_tmfifo_cleanup()
1233 mlxbf_tmfifo_delete_vdev(fifo, i); in mlxbf_tmfifo_cleanup()
1241 struct mlxbf_tmfifo *fifo; in mlxbf_tmfifo_probe() local
1244 fifo = devm_kzalloc(dev, sizeof(*fifo), GFP_KERNEL); in mlxbf_tmfifo_probe()
1245 if (!fifo) in mlxbf_tmfifo_probe()
1248 spin_lock_init(&fifo->spin_lock[0]); in mlxbf_tmfifo_probe()
1249 spin_lock_init(&fifo->spin_lock[1]); in mlxbf_tmfifo_probe()
1250 INIT_WORK(&fifo->work, mlxbf_tmfifo_work_handler); in mlxbf_tmfifo_probe()
1251 mutex_init(&fifo->lock); in mlxbf_tmfifo_probe()
1253 /* Get the resource of the Rx FIFO. */ in mlxbf_tmfifo_probe()
1254 fifo->rx_base = devm_platform_ioremap_resource(pdev, 0); in mlxbf_tmfifo_probe()
1255 if (IS_ERR(fifo->rx_base)) in mlxbf_tmfifo_probe()
1256 return PTR_ERR(fifo->rx_base); in mlxbf_tmfifo_probe()
1258 /* Get the resource of the Tx FIFO. */ in mlxbf_tmfifo_probe()
1259 fifo->tx_base = devm_platform_ioremap_resource(pdev, 1); in mlxbf_tmfifo_probe()
1260 if (IS_ERR(fifo->tx_base)) in mlxbf_tmfifo_probe()
1261 return PTR_ERR(fifo->tx_base); in mlxbf_tmfifo_probe()
1263 platform_set_drvdata(pdev, fifo); in mlxbf_tmfifo_probe()
1265 timer_setup(&fifo->timer, mlxbf_tmfifo_timer, 0); in mlxbf_tmfifo_probe()
1268 fifo->irq_info[i].index = i; in mlxbf_tmfifo_probe()
1269 fifo->irq_info[i].fifo = fifo; in mlxbf_tmfifo_probe()
1270 fifo->irq_info[i].irq = platform_get_irq(pdev, i); in mlxbf_tmfifo_probe()
1271 rc = devm_request_irq(dev, fifo->irq_info[i].irq, in mlxbf_tmfifo_probe()
1273 "tmfifo", &fifo->irq_info[i]); in mlxbf_tmfifo_probe()
1276 fifo->irq_info[i].irq = 0; in mlxbf_tmfifo_probe()
1281 mlxbf_tmfifo_set_threshold(fifo); in mlxbf_tmfifo_probe()
1284 rc = mlxbf_tmfifo_create_vdev(dev, fifo, VIRTIO_ID_CONSOLE, 0, NULL, 0); in mlxbf_tmfifo_probe()
1297 rc = mlxbf_tmfifo_create_vdev(dev, fifo, VIRTIO_ID_NET, in mlxbf_tmfifo_probe()
1303 mod_timer(&fifo->timer, jiffies + MLXBF_TMFIFO_TIMER_INTERVAL); in mlxbf_tmfifo_probe()
1305 fifo->is_ready = true; in mlxbf_tmfifo_probe()
1309 mlxbf_tmfifo_cleanup(fifo); in mlxbf_tmfifo_probe()
1316 struct mlxbf_tmfifo *fifo = platform_get_drvdata(pdev); in mlxbf_tmfifo_remove() local
1318 mlxbf_tmfifo_cleanup(fifo); in mlxbf_tmfifo_remove()