Lines Matching +full:fifo +full:- +full:size

1 // SPDX-License-Identifier: GPL-2.0+
24 #include "mlxbf-tmfifo-regs.h"
26 /* Vring size. */
29 /* Console Tx buffer size. */
35 /* House-keeping timer interval. */
38 /* Virtual devices sharing the TM FIFO. */
53 * mlxbf_tmfifo_vring - Structure of the TmFifo virtual ring
63 * @num: vring size (number of descriptors)
64 * @align: vring alignment size
67 * @fifo: pointer to the tmfifo structure
83 struct mlxbf_tmfifo *fifo; member
103 * mlxbf_tmfifo_vdev - Structure of the TmFifo virtual device
109 * @config.cons: virtual console config -
111 * @config.net: virtual network config -
113 * @tx_buf: tx buffer used to buffer data before writing into the FIFO
128 * mlxbf_tmfifo_irq_info - Structure of the interrupt information
129 * @fifo: pointer to the tmfifo structure
134 struct mlxbf_tmfifo *fifo; member
140 * mlxbf_tmfifo - Structure of the TmFifo
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
172 * mlxbf_tmfifo_msg_hdr - Structure of the TmFifo message header
174 * @len: payload length in network byte order. Messages sent into the FIFO
200 /* Supported virtio-net features. */
207 /* Free vrings of the FIFO device. */
208 static void mlxbf_tmfifo_free_vrings(struct mlxbf_tmfifo *fifo, in mlxbf_tmfifo_free_vrings() argument
212 int i, size; in mlxbf_tmfifo_free_vrings() local
214 for (i = 0; i < ARRAY_SIZE(tm_vdev->vrings); i++) { in mlxbf_tmfifo_free_vrings()
215 vring = &tm_vdev->vrings[i]; in mlxbf_tmfifo_free_vrings()
216 if (vring->va) { in mlxbf_tmfifo_free_vrings()
217 size = vring_size(vring->num, vring->align); in mlxbf_tmfifo_free_vrings()
218 dma_free_coherent(tm_vdev->vdev.dev.parent, size, in mlxbf_tmfifo_free_vrings()
219 vring->va, vring->dma); in mlxbf_tmfifo_free_vrings()
220 vring->va = NULL; in mlxbf_tmfifo_free_vrings()
221 if (vring->vq) { in mlxbf_tmfifo_free_vrings()
222 vring_del_virtqueue(vring->vq); in mlxbf_tmfifo_free_vrings()
223 vring->vq = NULL; in mlxbf_tmfifo_free_vrings()
229 /* Allocate vrings for the FIFO. */
230 static int mlxbf_tmfifo_alloc_vrings(struct mlxbf_tmfifo *fifo, in mlxbf_tmfifo_alloc_vrings() argument
236 int i, size; in mlxbf_tmfifo_alloc_vrings() local
239 for (i = 0; i < ARRAY_SIZE(tm_vdev->vrings); i++) { in mlxbf_tmfifo_alloc_vrings()
240 vring = &tm_vdev->vrings[i]; in mlxbf_tmfifo_alloc_vrings()
241 vring->fifo = fifo; in mlxbf_tmfifo_alloc_vrings()
242 vring->num = MLXBF_TMFIFO_VRING_SIZE; in mlxbf_tmfifo_alloc_vrings()
243 vring->align = SMP_CACHE_BYTES; in mlxbf_tmfifo_alloc_vrings()
244 vring->index = i; in mlxbf_tmfifo_alloc_vrings()
245 vring->vdev_id = tm_vdev->vdev.id.device; in mlxbf_tmfifo_alloc_vrings()
246 dev = &tm_vdev->vdev.dev; in mlxbf_tmfifo_alloc_vrings()
248 size = vring_size(vring->num, vring->align); in mlxbf_tmfifo_alloc_vrings()
249 va = dma_alloc_coherent(dev->parent, size, &dma, GFP_KERNEL); in mlxbf_tmfifo_alloc_vrings()
251 mlxbf_tmfifo_free_vrings(fifo, tm_vdev); in mlxbf_tmfifo_alloc_vrings()
252 dev_err(dev->parent, "dma_alloc_coherent failed\n"); in mlxbf_tmfifo_alloc_vrings()
253 return -ENOMEM; in mlxbf_tmfifo_alloc_vrings()
256 vring->va = va; in mlxbf_tmfifo_alloc_vrings()
257 vring->dma = dma; 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()
290 const struct vring *vr = virtqueue_get_vring(vring->vq); in mlxbf_tmfifo_get_next_desc()
291 struct virtio_device *vdev = vring->vq->vdev; in mlxbf_tmfifo_get_next_desc()
294 if (vring->next_avail == virtio16_to_cpu(vdev, vr->avail->idx)) in mlxbf_tmfifo_get_next_desc()
297 /* Make sure 'avail->idx' is visible already. */ in mlxbf_tmfifo_get_next_desc()
300 idx = vring->next_avail % vr->num; in mlxbf_tmfifo_get_next_desc()
301 head = virtio16_to_cpu(vdev, vr->avail->ring[idx]); in mlxbf_tmfifo_get_next_desc()
302 if (WARN_ON(head >= vr->num)) in mlxbf_tmfifo_get_next_desc()
305 vring->next_avail++; in mlxbf_tmfifo_get_next_desc()
307 return &vr->desc[head]; in mlxbf_tmfifo_get_next_desc()
314 const struct vring *vr = virtqueue_get_vring(vring->vq); in mlxbf_tmfifo_release_desc()
315 struct virtio_device *vdev = vring->vq->vdev; in mlxbf_tmfifo_release_desc()
318 vr_idx = virtio16_to_cpu(vdev, vr->used->idx); in mlxbf_tmfifo_release_desc()
319 idx = vr_idx % vr->num; in mlxbf_tmfifo_release_desc()
320 vr->used->ring[idx].id = cpu_to_virtio32(vdev, desc - vr->desc); in mlxbf_tmfifo_release_desc()
321 vr->used->ring[idx].len = cpu_to_virtio32(vdev, len); in mlxbf_tmfifo_release_desc()
329 vr->used->idx = cpu_to_virtio16(vdev, vr_idx + 1); in mlxbf_tmfifo_release_desc()
336 const struct vring *vr = virtqueue_get_vring(vring->vq); in mlxbf_tmfifo_get_pkt_len()
337 struct virtio_device *vdev = vring->vq->vdev; in mlxbf_tmfifo_get_pkt_len()
341 len += virtio32_to_cpu(vdev, desc->len); in mlxbf_tmfifo_get_pkt_len()
342 if (!(virtio16_to_cpu(vdev, desc->flags) & VRING_DESC_F_NEXT)) in mlxbf_tmfifo_get_pkt_len()
344 idx = virtio16_to_cpu(vdev, desc->next); in mlxbf_tmfifo_get_pkt_len()
345 desc = &vr->desc[idx]; in mlxbf_tmfifo_get_pkt_len()
356 if (vring->desc_head) { in mlxbf_tmfifo_release_pending_pkt()
357 desc_head = vring->desc_head; in mlxbf_tmfifo_release_pending_pkt()
358 len = vring->pkt_len; in mlxbf_tmfifo_release_pending_pkt()
367 vring->pkt_len = 0; in mlxbf_tmfifo_release_pending_pkt()
368 vring->desc = NULL; in mlxbf_tmfifo_release_pending_pkt()
369 vring->desc_head = NULL; in mlxbf_tmfifo_release_pending_pkt()
375 struct virtio_device *vdev = vring->vq->vdev; in mlxbf_tmfifo_init_net_desc()
378 net_hdr = phys_to_virt(virtio64_to_cpu(vdev, desc->addr)); in mlxbf_tmfifo_init_net_desc()
389 if (desc && is_rx && vring->vdev_id == VIRTIO_ID_NET) in mlxbf_tmfifo_get_next_pkt()
392 vring->desc_head = desc; in mlxbf_tmfifo_get_next_pkt()
393 vring->desc = desc; in mlxbf_tmfifo_get_next_pkt()
398 /* House-keeping timer. */
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()
418 const struct vring *vr = virtqueue_get_vring(vring->vq); in mlxbf_tmfifo_console_output_one()
419 struct virtio_device *vdev = &cons->vdev; in mlxbf_tmfifo_console_output_one()
424 addr = phys_to_virt(virtio64_to_cpu(vdev, desc->addr)); in mlxbf_tmfifo_console_output_one()
425 len = virtio32_to_cpu(vdev, desc->len); in mlxbf_tmfifo_console_output_one()
427 seg = CIRC_SPACE_TO_END(cons->tx_buf.head, cons->tx_buf.tail, in mlxbf_tmfifo_console_output_one()
430 memcpy(cons->tx_buf.buf + cons->tx_buf.head, addr, len); in mlxbf_tmfifo_console_output_one()
432 memcpy(cons->tx_buf.buf + cons->tx_buf.head, addr, seg); in mlxbf_tmfifo_console_output_one()
434 memcpy(cons->tx_buf.buf, addr, len - seg); in mlxbf_tmfifo_console_output_one()
436 cons->tx_buf.head = (cons->tx_buf.head + len) % in mlxbf_tmfifo_console_output_one()
439 if (!(virtio16_to_cpu(vdev, desc->flags) & VRING_DESC_F_NEXT)) in mlxbf_tmfifo_console_output_one()
441 idx = virtio16_to_cpu(vdev, desc->next); in mlxbf_tmfifo_console_output_one()
442 desc = &vr->desc[idx]; in mlxbf_tmfifo_console_output_one()
457 avail = CIRC_SPACE(cons->tx_buf.head, cons->tx_buf.tail, in mlxbf_tmfifo_console_output()
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
503 int size, seg; in mlxbf_tmfifo_console_tx() local
511 cons = fifo->vdev[VIRTIO_ID_CONSOLE]; in mlxbf_tmfifo_console_tx()
512 if (!cons || !cons->tx_buf.buf) in mlxbf_tmfifo_console_tx()
516 size = CIRC_CNT(cons->tx_buf.head, cons->tx_buf.tail, in mlxbf_tmfifo_console_tx()
518 if (size == 0) in mlxbf_tmfifo_console_tx()
521 /* Adjust the size to available space. */ in mlxbf_tmfifo_console_tx()
522 if (size + sizeof(hdr) > avail * sizeof(u64)) in mlxbf_tmfifo_console_tx()
523 size = avail * sizeof(u64) - sizeof(hdr); in mlxbf_tmfifo_console_tx()
527 hdr.len = htons(size); in mlxbf_tmfifo_console_tx()
528 writeq(*(u64 *)&hdr, fifo->tx_base + MLXBF_TMFIFO_TX_DATA); in mlxbf_tmfifo_console_tx()
530 /* Use spin-lock to protect the 'cons->tx_buf'. */ in mlxbf_tmfifo_console_tx()
531 spin_lock_irqsave(&fifo->spin_lock[0], flags); in mlxbf_tmfifo_console_tx()
533 while (size > 0) { in mlxbf_tmfifo_console_tx()
534 addr = cons->tx_buf.buf + cons->tx_buf.tail; in mlxbf_tmfifo_console_tx()
536 seg = CIRC_CNT_TO_END(cons->tx_buf.head, cons->tx_buf.tail, in mlxbf_tmfifo_console_tx()
542 memcpy((u8 *)&data + seg, cons->tx_buf.buf, in mlxbf_tmfifo_console_tx()
543 sizeof(u64) - seg); in mlxbf_tmfifo_console_tx()
545 writeq(data, fifo->tx_base + MLXBF_TMFIFO_TX_DATA); in mlxbf_tmfifo_console_tx()
547 if (size >= sizeof(u64)) { in mlxbf_tmfifo_console_tx()
548 cons->tx_buf.tail = (cons->tx_buf.tail + sizeof(u64)) % in mlxbf_tmfifo_console_tx()
550 size -= sizeof(u64); in mlxbf_tmfifo_console_tx()
552 cons->tx_buf.tail = (cons->tx_buf.tail + size) % in mlxbf_tmfifo_console_tx()
554 size = 0; in mlxbf_tmfifo_console_tx()
558 spin_unlock_irqrestore(&fifo->spin_lock[0], flags); in mlxbf_tmfifo_console_tx()
566 struct virtio_device *vdev = vring->vq->vdev; in mlxbf_tmfifo_rxtx_word()
567 struct mlxbf_tmfifo *fifo = vring->fifo; in mlxbf_tmfifo_rxtx_word() local
572 addr = phys_to_virt(virtio64_to_cpu(vdev, desc->addr)); in mlxbf_tmfifo_rxtx_word()
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()
578 if (vring->cur_len + sizeof(u64) <= len) { in mlxbf_tmfifo_rxtx_word()
581 memcpy(addr + vring->cur_len, &data, sizeof(u64)); in mlxbf_tmfifo_rxtx_word()
583 memcpy(&data, addr + vring->cur_len, sizeof(u64)); in mlxbf_tmfifo_rxtx_word()
584 vring->cur_len += sizeof(u64); in mlxbf_tmfifo_rxtx_word()
588 memcpy(addr + vring->cur_len, &data, in mlxbf_tmfifo_rxtx_word()
589 len - vring->cur_len); in mlxbf_tmfifo_rxtx_word()
591 memcpy(&data, addr + vring->cur_len, in mlxbf_tmfifo_rxtx_word()
592 len - vring->cur_len); in mlxbf_tmfifo_rxtx_word()
593 vring->cur_len = len; 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()
631 /* A legacy-only interface for now. */ in mlxbf_tmfifo_rxtx_header()
634 config->mtu) + in mlxbf_tmfifo_rxtx_header()
646 if (vdev_id != vring->vdev_id) { in mlxbf_tmfifo_rxtx_header()
647 struct mlxbf_tmfifo_vdev *tm_dev2 = fifo->vdev[vdev_id]; in mlxbf_tmfifo_rxtx_header()
651 vring->desc = desc; in mlxbf_tmfifo_rxtx_header()
652 vring = &tm_dev2->vrings[MLXBF_TMFIFO_VRING_RX]; in mlxbf_tmfifo_rxtx_header()
655 vring->pkt_len = ntohs(hdr.len) + hdr_len; in mlxbf_tmfifo_rxtx_header()
658 hdr_len = (vring->vdev_id == VIRTIO_ID_NET) ? in mlxbf_tmfifo_rxtx_header()
660 vring->pkt_len = mlxbf_tmfifo_get_pkt_len(vring, desc); in mlxbf_tmfifo_rxtx_header()
661 hdr.type = (vring->vdev_id == VIRTIO_ID_NET) ? in mlxbf_tmfifo_rxtx_header()
663 hdr.len = htons(vring->pkt_len - hdr_len); in mlxbf_tmfifo_rxtx_header()
664 writeq(*(u64 *)&hdr, fifo->tx_base + MLXBF_TMFIFO_TX_DATA); in mlxbf_tmfifo_rxtx_header()
667 vring->cur_len = hdr_len; in mlxbf_tmfifo_rxtx_header()
668 vring->rem_len = vring->pkt_len; in mlxbf_tmfifo_rxtx_header()
669 fifo->vring[is_rx] = vring; in mlxbf_tmfifo_rxtx_header()
680 const struct vring *vr = virtqueue_get_vring(vring->vq); in mlxbf_tmfifo_rxtx_one_desc()
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()
691 if (!vring->desc) { in mlxbf_tmfifo_rxtx_one_desc()
696 desc = vring->desc; in mlxbf_tmfifo_rxtx_one_desc()
700 if (vring->pkt_len == 0) { in mlxbf_tmfifo_rxtx_one_desc()
702 (*avail)--; in mlxbf_tmfifo_rxtx_one_desc()
711 len = virtio32_to_cpu(vdev, desc->len); in mlxbf_tmfifo_rxtx_one_desc()
712 if (len > vring->rem_len) in mlxbf_tmfifo_rxtx_one_desc()
713 len = vring->rem_len; in mlxbf_tmfifo_rxtx_one_desc()
716 if (vring->cur_len < len) { in mlxbf_tmfifo_rxtx_one_desc()
718 (*avail)--; in mlxbf_tmfifo_rxtx_one_desc()
722 if (vring->cur_len == len) { in mlxbf_tmfifo_rxtx_one_desc()
723 vring->cur_len = 0; in mlxbf_tmfifo_rxtx_one_desc()
724 vring->rem_len -= len; in mlxbf_tmfifo_rxtx_one_desc()
727 if (vring->rem_len > 0 && in mlxbf_tmfifo_rxtx_one_desc()
728 (virtio16_to_cpu(vdev, desc->flags) & VRING_DESC_F_NEXT)) { in mlxbf_tmfifo_rxtx_one_desc()
729 idx = virtio16_to_cpu(vdev, desc->next); in mlxbf_tmfifo_rxtx_one_desc()
730 desc = &vr->desc[idx]; 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()
747 vring_interrupt(0, vring->vq); in mlxbf_tmfifo_rxtx_one_desc()
748 spin_unlock_irqrestore(&fifo->spin_lock[is_rx], flags); in mlxbf_tmfifo_rxtx_one_desc()
753 vring->desc = desc; in mlxbf_tmfifo_rxtx_one_desc()
761 int avail = 0, devid = vring->vdev_id; in mlxbf_tmfifo_rxtx()
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()
816 vring = &tm_vdev->vrings[queue_id]; in mlxbf_tmfifo_work_rxtx()
817 if (vring->vq) 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()
848 struct mlxbf_tmfifo_vring *vring = vq->priv; in mlxbf_tmfifo_virtio_notify()
850 struct mlxbf_tmfifo *fifo; in mlxbf_tmfifo_virtio_notify() local
853 fifo = vring->fifo; in mlxbf_tmfifo_virtio_notify()
859 if (vring->index & BIT(0)) { in mlxbf_tmfifo_virtio_notify()
866 if (vring->vdev_id == VIRTIO_ID_CONSOLE) { 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()
890 return tm_vdev->features; in mlxbf_tmfifo_virtio_get_features()
898 tm_vdev->features = vdev->features; in mlxbf_tmfifo_virtio_finalize_features()
911 for (i = 0; i < ARRAY_SIZE(tm_vdev->vrings); i++) { in mlxbf_tmfifo_virtio_del_vqs()
912 vring = &tm_vdev->vrings[i]; in mlxbf_tmfifo_virtio_del_vqs()
915 if (vring->desc) in mlxbf_tmfifo_virtio_del_vqs()
917 vq = vring->vq; in mlxbf_tmfifo_virtio_del_vqs()
919 vring->vq = NULL; in mlxbf_tmfifo_virtio_del_vqs()
937 int i, ret, size; in mlxbf_tmfifo_virtio_find_vqs() local
939 if (nvqs > ARRAY_SIZE(tm_vdev->vrings)) in mlxbf_tmfifo_virtio_find_vqs()
940 return -EINVAL; in mlxbf_tmfifo_virtio_find_vqs()
944 ret = -EINVAL; in mlxbf_tmfifo_virtio_find_vqs()
947 vring = &tm_vdev->vrings[i]; in mlxbf_tmfifo_virtio_find_vqs()
950 size = vring_size(vring->num, vring->align); in mlxbf_tmfifo_virtio_find_vqs()
951 memset(vring->va, 0, size); in mlxbf_tmfifo_virtio_find_vqs()
952 vq = vring_new_virtqueue(i, vring->num, vring->align, vdev, in mlxbf_tmfifo_virtio_find_vqs()
953 false, false, vring->va, in mlxbf_tmfifo_virtio_find_vqs()
957 dev_err(&vdev->dev, "vring_new_virtqueue failed\n"); in mlxbf_tmfifo_virtio_find_vqs()
958 ret = -ENOMEM; in mlxbf_tmfifo_virtio_find_vqs()
962 vq->num_max = vring->num; in mlxbf_tmfifo_virtio_find_vqs()
965 vring->vq = vq; in mlxbf_tmfifo_virtio_find_vqs()
966 vq->priv = vring; in mlxbf_tmfifo_virtio_find_vqs()
981 return tm_vdev->status; in mlxbf_tmfifo_virtio_get_status()
990 tm_vdev->status = status; in mlxbf_tmfifo_virtio_set_status()
998 tm_vdev->status = 0; in mlxbf_tmfifo_virtio_reset()
1009 if ((u64)offset + len > sizeof(tm_vdev->config)) in mlxbf_tmfifo_virtio_get()
1012 memcpy(buf, (u8 *)&tm_vdev->config + offset, len); in mlxbf_tmfifo_virtio_get()
1023 if ((u64)offset + len > sizeof(tm_vdev->config)) in mlxbf_tmfifo_virtio_set()
1026 memcpy((u8 *)&tm_vdev->config + offset, buf, len); in mlxbf_tmfifo_virtio_set()
1051 /* Create vdev for the FIFO. */
1053 struct mlxbf_tmfifo *fifo, in mlxbf_tmfifo_create_vdev() argument
1055 void *config, u32 size) in mlxbf_tmfifo_create_vdev() argument
1060 mutex_lock(&fifo->lock); in mlxbf_tmfifo_create_vdev()
1062 tm_vdev = fifo->vdev[vdev_id]; in mlxbf_tmfifo_create_vdev()
1065 ret = -EEXIST; in mlxbf_tmfifo_create_vdev()
1071 ret = -ENOMEM; in mlxbf_tmfifo_create_vdev()
1075 tm_vdev->vdev.id.device = vdev_id; in mlxbf_tmfifo_create_vdev()
1076 tm_vdev->vdev.config = &mlxbf_tmfifo_virtio_config_ops; in mlxbf_tmfifo_create_vdev()
1077 tm_vdev->vdev.dev.parent = dev; in mlxbf_tmfifo_create_vdev()
1078 tm_vdev->vdev.dev.release = tmfifo_virtio_dev_release; in mlxbf_tmfifo_create_vdev()
1079 tm_vdev->features = features; in mlxbf_tmfifo_create_vdev()
1081 memcpy(&tm_vdev->config, config, size); in mlxbf_tmfifo_create_vdev()
1083 if (mlxbf_tmfifo_alloc_vrings(fifo, tm_vdev)) { in mlxbf_tmfifo_create_vdev()
1085 ret = -ENOMEM; in mlxbf_tmfifo_create_vdev()
1091 tm_vdev->tx_buf.buf = devm_kmalloc(dev, in mlxbf_tmfifo_create_vdev()
1094 fifo->vdev[vdev_id] = tm_vdev; in mlxbf_tmfifo_create_vdev()
1097 ret = register_virtio_device(&tm_vdev->vdev); in mlxbf_tmfifo_create_vdev()
1104 mutex_unlock(&fifo->lock); in mlxbf_tmfifo_create_vdev()
1108 mlxbf_tmfifo_free_vrings(fifo, tm_vdev); in mlxbf_tmfifo_create_vdev()
1109 fifo->vdev[vdev_id] = NULL; in mlxbf_tmfifo_create_vdev()
1111 put_device(&tm_vdev->vdev.dev); in mlxbf_tmfifo_create_vdev()
1115 mutex_unlock(&fifo->lock); in mlxbf_tmfifo_create_vdev()
1119 /* Delete vdev for the FIFO. */
1120 static int mlxbf_tmfifo_delete_vdev(struct mlxbf_tmfifo *fifo, int vdev_id) in mlxbf_tmfifo_delete_vdev() argument
1124 mutex_lock(&fifo->lock); in mlxbf_tmfifo_delete_vdev()
1127 tm_vdev = fifo->vdev[vdev_id]; in mlxbf_tmfifo_delete_vdev()
1129 unregister_virtio_device(&tm_vdev->vdev); in mlxbf_tmfifo_delete_vdev()
1130 mlxbf_tmfifo_free_vrings(fifo, tm_vdev); in mlxbf_tmfifo_delete_vdev()
1131 fifo->vdev[vdev_id] = NULL; in mlxbf_tmfifo_delete_vdev()
1134 mutex_unlock(&fifo->lock); in mlxbf_tmfifo_delete_vdev()
1143 unsigned long size = ETH_ALEN; in mlxbf_tmfifo_get_cfg_mac() local
1147 rc = efi.get_variable(mlxbf_tmfifo_efi_name, &guid, NULL, &size, buf); in mlxbf_tmfifo_get_cfg_mac()
1148 if (rc == EFI_SUCCESS && size == ETH_ALEN) in mlxbf_tmfifo_get_cfg_mac()
1155 static void mlxbf_tmfifo_set_threshold(struct mlxbf_tmfifo *fifo) in mlxbf_tmfifo_set_threshold() argument
1159 /* Get Tx FIFO size and set the low/high watermark. */ in mlxbf_tmfifo_set_threshold()
1160 ctl = readq(fifo->tx_base + MLXBF_TMFIFO_TX_CTL); in mlxbf_tmfifo_set_threshold()
1161 fifo->tx_fifo_size = in mlxbf_tmfifo_set_threshold()
1165 fifo->tx_fifo_size / 2); in mlxbf_tmfifo_set_threshold()
1168 fifo->tx_fifo_size - 1); in mlxbf_tmfifo_set_threshold()
1169 writeq(ctl, fifo->tx_base + MLXBF_TMFIFO_TX_CTL); in mlxbf_tmfifo_set_threshold()
1171 /* Get Rx FIFO size and set the low/high watermark. */ in mlxbf_tmfifo_set_threshold()
1172 ctl = readq(fifo->rx_base + MLXBF_TMFIFO_RX_CTL); in mlxbf_tmfifo_set_threshold()
1173 fifo->rx_fifo_size = in mlxbf_tmfifo_set_threshold()
1179 writeq(ctl, fifo->rx_base + MLXBF_TMFIFO_RX_CTL); in mlxbf_tmfifo_set_threshold()
1182 static void mlxbf_tmfifo_cleanup(struct mlxbf_tmfifo *fifo) in mlxbf_tmfifo_cleanup() argument
1186 fifo->is_ready = false; in mlxbf_tmfifo_cleanup()
1187 del_timer_sync(&fifo->timer); in mlxbf_tmfifo_cleanup()
1188 mlxbf_tmfifo_disable_irqs(fifo); in mlxbf_tmfifo_cleanup()
1189 cancel_work_sync(&fifo->work); in mlxbf_tmfifo_cleanup()
1191 mlxbf_tmfifo_delete_vdev(fifo, i); in mlxbf_tmfifo_cleanup()
1198 struct device *dev = &pdev->dev; in mlxbf_tmfifo_probe()
1199 struct mlxbf_tmfifo *fifo; in mlxbf_tmfifo_probe() local
1202 fifo = devm_kzalloc(dev, sizeof(*fifo), GFP_KERNEL); in mlxbf_tmfifo_probe()
1203 if (!fifo) in mlxbf_tmfifo_probe()
1204 return -ENOMEM; in mlxbf_tmfifo_probe()
1206 spin_lock_init(&fifo->spin_lock[0]); in mlxbf_tmfifo_probe()
1207 spin_lock_init(&fifo->spin_lock[1]); in mlxbf_tmfifo_probe()
1208 INIT_WORK(&fifo->work, mlxbf_tmfifo_work_handler); in mlxbf_tmfifo_probe()
1209 mutex_init(&fifo->lock); in mlxbf_tmfifo_probe()
1211 /* Get the resource of the Rx FIFO. */ in mlxbf_tmfifo_probe()
1212 fifo->rx_base = devm_platform_ioremap_resource(pdev, 0); in mlxbf_tmfifo_probe()
1213 if (IS_ERR(fifo->rx_base)) in mlxbf_tmfifo_probe()
1214 return PTR_ERR(fifo->rx_base); in mlxbf_tmfifo_probe()
1216 /* Get the resource of the Tx FIFO. */ in mlxbf_tmfifo_probe()
1217 fifo->tx_base = devm_platform_ioremap_resource(pdev, 1); in mlxbf_tmfifo_probe()
1218 if (IS_ERR(fifo->tx_base)) in mlxbf_tmfifo_probe()
1219 return PTR_ERR(fifo->tx_base); in mlxbf_tmfifo_probe()
1221 platform_set_drvdata(pdev, fifo); in mlxbf_tmfifo_probe()
1223 timer_setup(&fifo->timer, mlxbf_tmfifo_timer, 0); in mlxbf_tmfifo_probe()
1226 fifo->irq_info[i].index = i; in mlxbf_tmfifo_probe()
1227 fifo->irq_info[i].fifo = fifo; in mlxbf_tmfifo_probe()
1228 fifo->irq_info[i].irq = platform_get_irq(pdev, i); in mlxbf_tmfifo_probe()
1229 rc = devm_request_irq(dev, fifo->irq_info[i].irq, in mlxbf_tmfifo_probe()
1231 "tmfifo", &fifo->irq_info[i]); in mlxbf_tmfifo_probe()
1234 fifo->irq_info[i].irq = 0; in mlxbf_tmfifo_probe()
1239 mlxbf_tmfifo_set_threshold(fifo); in mlxbf_tmfifo_probe()
1242 rc = mlxbf_tmfifo_create_vdev(dev, fifo, VIRTIO_ID_CONSOLE, 0, NULL, 0); in mlxbf_tmfifo_probe()
1249 /* A legacy-only interface for now. */ in mlxbf_tmfifo_probe()
1255 rc = mlxbf_tmfifo_create_vdev(dev, fifo, VIRTIO_ID_NET, in mlxbf_tmfifo_probe()
1261 mod_timer(&fifo->timer, jiffies + MLXBF_TMFIFO_TIMER_INTERVAL); in mlxbf_tmfifo_probe()
1263 fifo->is_ready = true; in mlxbf_tmfifo_probe()
1267 mlxbf_tmfifo_cleanup(fifo); in mlxbf_tmfifo_probe()
1274 struct mlxbf_tmfifo *fifo = platform_get_drvdata(pdev); in mlxbf_tmfifo_remove() local
1276 mlxbf_tmfifo_cleanup(fifo); in mlxbf_tmfifo_remove()
1291 .name = "bf-tmfifo",