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 idx = vring->next_avail % vr->num; in mlxbf_tmfifo_get_next_desc()
298 head = virtio16_to_cpu(vdev, vr->avail->ring[idx]); in mlxbf_tmfifo_get_next_desc()
299 if (WARN_ON(head >= vr->num)) in mlxbf_tmfifo_get_next_desc()
302 vring->next_avail++; in mlxbf_tmfifo_get_next_desc()
304 return &vr->desc[head]; in mlxbf_tmfifo_get_next_desc()
311 const struct vring *vr = virtqueue_get_vring(vring->vq); in mlxbf_tmfifo_release_desc()
312 struct virtio_device *vdev = vring->vq->vdev; in mlxbf_tmfifo_release_desc()
315 vr_idx = virtio16_to_cpu(vdev, vr->used->idx); in mlxbf_tmfifo_release_desc()
316 idx = vr_idx % vr->num; in mlxbf_tmfifo_release_desc()
317 vr->used->ring[idx].id = cpu_to_virtio32(vdev, desc - vr->desc); in mlxbf_tmfifo_release_desc()
318 vr->used->ring[idx].len = cpu_to_virtio32(vdev, len); in mlxbf_tmfifo_release_desc()
326 vr->used->idx = cpu_to_virtio16(vdev, vr_idx + 1); in mlxbf_tmfifo_release_desc()
333 const struct vring *vr = virtqueue_get_vring(vring->vq); in mlxbf_tmfifo_get_pkt_len()
334 struct virtio_device *vdev = vring->vq->vdev; in mlxbf_tmfifo_get_pkt_len()
338 len += virtio32_to_cpu(vdev, desc->len); in mlxbf_tmfifo_get_pkt_len()
339 if (!(virtio16_to_cpu(vdev, desc->flags) & VRING_DESC_F_NEXT)) in mlxbf_tmfifo_get_pkt_len()
341 idx = virtio16_to_cpu(vdev, desc->next); in mlxbf_tmfifo_get_pkt_len()
342 desc = &vr->desc[idx]; in mlxbf_tmfifo_get_pkt_len()
353 if (vring->desc_head) { in mlxbf_tmfifo_release_pending_pkt()
354 desc_head = vring->desc_head; in mlxbf_tmfifo_release_pending_pkt()
355 len = vring->pkt_len; in mlxbf_tmfifo_release_pending_pkt()
364 vring->pkt_len = 0; in mlxbf_tmfifo_release_pending_pkt()
365 vring->desc = NULL; in mlxbf_tmfifo_release_pending_pkt()
366 vring->desc_head = NULL; in mlxbf_tmfifo_release_pending_pkt()
372 struct virtio_device *vdev = vring->vq->vdev; in mlxbf_tmfifo_init_net_desc()
375 net_hdr = phys_to_virt(virtio64_to_cpu(vdev, desc->addr)); in mlxbf_tmfifo_init_net_desc()
386 if (desc && is_rx && vring->vdev_id == VIRTIO_ID_NET) in mlxbf_tmfifo_get_next_pkt()
389 vring->desc_head = desc; in mlxbf_tmfifo_get_next_pkt()
390 vring->desc = desc; in mlxbf_tmfifo_get_next_pkt()
395 /* House-keeping timer. */
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()
415 const struct vring *vr = virtqueue_get_vring(vring->vq); in mlxbf_tmfifo_console_output_one()
416 struct virtio_device *vdev = &cons->vdev; in mlxbf_tmfifo_console_output_one()
421 addr = phys_to_virt(virtio64_to_cpu(vdev, desc->addr)); in mlxbf_tmfifo_console_output_one()
422 len = virtio32_to_cpu(vdev, desc->len); in mlxbf_tmfifo_console_output_one()
424 seg = CIRC_SPACE_TO_END(cons->tx_buf.head, cons->tx_buf.tail, in mlxbf_tmfifo_console_output_one()
427 memcpy(cons->tx_buf.buf + cons->tx_buf.head, addr, len); in mlxbf_tmfifo_console_output_one()
429 memcpy(cons->tx_buf.buf + cons->tx_buf.head, addr, seg); in mlxbf_tmfifo_console_output_one()
431 memcpy(cons->tx_buf.buf, addr, len - seg); in mlxbf_tmfifo_console_output_one()
433 cons->tx_buf.head = (cons->tx_buf.head + len) % in mlxbf_tmfifo_console_output_one()
436 if (!(virtio16_to_cpu(vdev, desc->flags) & VRING_DESC_F_NEXT)) in mlxbf_tmfifo_console_output_one()
438 idx = virtio16_to_cpu(vdev, desc->next); in mlxbf_tmfifo_console_output_one()
439 desc = &vr->desc[idx]; in mlxbf_tmfifo_console_output_one()
454 avail = CIRC_SPACE(cons->tx_buf.head, cons->tx_buf.tail, in mlxbf_tmfifo_console_output()
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
500 int size, seg; in mlxbf_tmfifo_console_tx() local
508 cons = fifo->vdev[VIRTIO_ID_CONSOLE]; in mlxbf_tmfifo_console_tx()
509 if (!cons || !cons->tx_buf.buf) in mlxbf_tmfifo_console_tx()
513 size = CIRC_CNT(cons->tx_buf.head, cons->tx_buf.tail, in mlxbf_tmfifo_console_tx()
515 if (size == 0) in mlxbf_tmfifo_console_tx()
518 /* Adjust the size to available space. */ in mlxbf_tmfifo_console_tx()
519 if (size + sizeof(hdr) > avail * sizeof(u64)) in mlxbf_tmfifo_console_tx()
520 size = avail * sizeof(u64) - sizeof(hdr); in mlxbf_tmfifo_console_tx()
524 hdr.len = htons(size); in mlxbf_tmfifo_console_tx()
525 writeq(*(u64 *)&hdr, fifo->tx_base + MLXBF_TMFIFO_TX_DATA); in mlxbf_tmfifo_console_tx()
527 /* Use spin-lock to protect the 'cons->tx_buf'. */ in mlxbf_tmfifo_console_tx()
528 spin_lock_irqsave(&fifo->spin_lock[0], flags); in mlxbf_tmfifo_console_tx()
530 while (size > 0) { in mlxbf_tmfifo_console_tx()
531 addr = cons->tx_buf.buf + cons->tx_buf.tail; in mlxbf_tmfifo_console_tx()
533 seg = CIRC_CNT_TO_END(cons->tx_buf.head, cons->tx_buf.tail, in mlxbf_tmfifo_console_tx()
539 memcpy((u8 *)&data + seg, cons->tx_buf.buf, in mlxbf_tmfifo_console_tx()
540 sizeof(u64) - seg); in mlxbf_tmfifo_console_tx()
542 writeq(data, fifo->tx_base + MLXBF_TMFIFO_TX_DATA); in mlxbf_tmfifo_console_tx()
544 if (size >= sizeof(u64)) { in mlxbf_tmfifo_console_tx()
545 cons->tx_buf.tail = (cons->tx_buf.tail + sizeof(u64)) % in mlxbf_tmfifo_console_tx()
547 size -= sizeof(u64); in mlxbf_tmfifo_console_tx()
549 cons->tx_buf.tail = (cons->tx_buf.tail + size) % in mlxbf_tmfifo_console_tx()
551 size = 0; in mlxbf_tmfifo_console_tx()
555 spin_unlock_irqrestore(&fifo->spin_lock[0], flags); in mlxbf_tmfifo_console_tx()
563 struct virtio_device *vdev = vring->vq->vdev; in mlxbf_tmfifo_rxtx_word()
564 struct mlxbf_tmfifo *fifo = vring->fifo; in mlxbf_tmfifo_rxtx_word() local
569 addr = phys_to_virt(virtio64_to_cpu(vdev, desc->addr)); in mlxbf_tmfifo_rxtx_word()
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()
575 if (vring->cur_len + sizeof(u64) <= len) { in mlxbf_tmfifo_rxtx_word()
578 memcpy(addr + vring->cur_len, &data, sizeof(u64)); in mlxbf_tmfifo_rxtx_word()
580 memcpy(&data, addr + vring->cur_len, sizeof(u64)); in mlxbf_tmfifo_rxtx_word()
581 vring->cur_len += sizeof(u64); in mlxbf_tmfifo_rxtx_word()
585 memcpy(addr + vring->cur_len, &data, in mlxbf_tmfifo_rxtx_word()
586 len - vring->cur_len); in mlxbf_tmfifo_rxtx_word()
588 memcpy(&data, addr + vring->cur_len, in mlxbf_tmfifo_rxtx_word()
589 len - vring->cur_len); in mlxbf_tmfifo_rxtx_word()
590 vring->cur_len = len; 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()
628 /* A legacy-only interface for now. */ in mlxbf_tmfifo_rxtx_header()
631 config->mtu) + in mlxbf_tmfifo_rxtx_header()
643 if (vdev_id != vring->vdev_id) { in mlxbf_tmfifo_rxtx_header()
644 struct mlxbf_tmfifo_vdev *tm_dev2 = fifo->vdev[vdev_id]; in mlxbf_tmfifo_rxtx_header()
648 vring->desc = desc; in mlxbf_tmfifo_rxtx_header()
649 vring = &tm_dev2->vrings[MLXBF_TMFIFO_VRING_RX]; in mlxbf_tmfifo_rxtx_header()
652 vring->pkt_len = ntohs(hdr.len) + hdr_len; in mlxbf_tmfifo_rxtx_header()
655 hdr_len = (vring->vdev_id == VIRTIO_ID_NET) ? in mlxbf_tmfifo_rxtx_header()
657 vring->pkt_len = mlxbf_tmfifo_get_pkt_len(vring, desc); in mlxbf_tmfifo_rxtx_header()
658 hdr.type = (vring->vdev_id == VIRTIO_ID_NET) ? in mlxbf_tmfifo_rxtx_header()
660 hdr.len = htons(vring->pkt_len - hdr_len); in mlxbf_tmfifo_rxtx_header()
661 writeq(*(u64 *)&hdr, fifo->tx_base + MLXBF_TMFIFO_TX_DATA); in mlxbf_tmfifo_rxtx_header()
664 vring->cur_len = hdr_len; in mlxbf_tmfifo_rxtx_header()
665 vring->rem_len = vring->pkt_len; in mlxbf_tmfifo_rxtx_header()
666 fifo->vring[is_rx] = vring; in mlxbf_tmfifo_rxtx_header()
677 const struct vring *vr = virtqueue_get_vring(vring->vq); in mlxbf_tmfifo_rxtx_one_desc()
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()
688 if (!vring->desc) { in mlxbf_tmfifo_rxtx_one_desc()
693 desc = vring->desc; in mlxbf_tmfifo_rxtx_one_desc()
697 if (vring->pkt_len == 0) { in mlxbf_tmfifo_rxtx_one_desc()
699 (*avail)--; in mlxbf_tmfifo_rxtx_one_desc()
708 len = virtio32_to_cpu(vdev, desc->len); in mlxbf_tmfifo_rxtx_one_desc()
709 if (len > vring->rem_len) in mlxbf_tmfifo_rxtx_one_desc()
710 len = vring->rem_len; in mlxbf_tmfifo_rxtx_one_desc()
713 if (vring->cur_len < len) { in mlxbf_tmfifo_rxtx_one_desc()
715 (*avail)--; in mlxbf_tmfifo_rxtx_one_desc()
719 if (vring->cur_len == len) { in mlxbf_tmfifo_rxtx_one_desc()
720 vring->cur_len = 0; in mlxbf_tmfifo_rxtx_one_desc()
721 vring->rem_len -= len; in mlxbf_tmfifo_rxtx_one_desc()
724 if (vring->rem_len > 0 && in mlxbf_tmfifo_rxtx_one_desc()
725 (virtio16_to_cpu(vdev, desc->flags) & VRING_DESC_F_NEXT)) { in mlxbf_tmfifo_rxtx_one_desc()
726 idx = virtio16_to_cpu(vdev, desc->next); in mlxbf_tmfifo_rxtx_one_desc()
727 desc = &vr->desc[idx]; 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()
738 vring_interrupt(0, vring->vq); in mlxbf_tmfifo_rxtx_one_desc()
739 spin_unlock_irqrestore(&fifo->spin_lock[is_rx], flags); in mlxbf_tmfifo_rxtx_one_desc()
744 vring->desc = desc; in mlxbf_tmfifo_rxtx_one_desc()
752 int avail = 0, devid = vring->vdev_id; in mlxbf_tmfifo_rxtx()
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()
807 vring = &tm_vdev->vrings[queue_id]; in mlxbf_tmfifo_work_rxtx()
808 if (vring->vq) 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()
839 struct mlxbf_tmfifo_vring *vring = vq->priv; in mlxbf_tmfifo_virtio_notify()
841 struct mlxbf_tmfifo *fifo; in mlxbf_tmfifo_virtio_notify() local
844 fifo = vring->fifo; in mlxbf_tmfifo_virtio_notify()
850 if (vring->index & BIT(0)) { in mlxbf_tmfifo_virtio_notify()
857 if (vring->vdev_id == VIRTIO_ID_CONSOLE) { 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()
881 return tm_vdev->features; in mlxbf_tmfifo_virtio_get_features()
889 tm_vdev->features = vdev->features; in mlxbf_tmfifo_virtio_finalize_features()
902 for (i = 0; i < ARRAY_SIZE(tm_vdev->vrings); i++) { in mlxbf_tmfifo_virtio_del_vqs()
903 vring = &tm_vdev->vrings[i]; in mlxbf_tmfifo_virtio_del_vqs()
906 if (vring->desc) in mlxbf_tmfifo_virtio_del_vqs()
908 vq = vring->vq; in mlxbf_tmfifo_virtio_del_vqs()
910 vring->vq = NULL; in mlxbf_tmfifo_virtio_del_vqs()
928 int i, ret, size; in mlxbf_tmfifo_virtio_find_vqs() local
930 if (nvqs > ARRAY_SIZE(tm_vdev->vrings)) in mlxbf_tmfifo_virtio_find_vqs()
931 return -EINVAL; in mlxbf_tmfifo_virtio_find_vqs()
935 ret = -EINVAL; in mlxbf_tmfifo_virtio_find_vqs()
938 vring = &tm_vdev->vrings[i]; in mlxbf_tmfifo_virtio_find_vqs()
941 size = vring_size(vring->num, vring->align); in mlxbf_tmfifo_virtio_find_vqs()
942 memset(vring->va, 0, size); in mlxbf_tmfifo_virtio_find_vqs()
943 vq = vring_new_virtqueue(i, vring->num, vring->align, vdev, in mlxbf_tmfifo_virtio_find_vqs()
944 false, false, vring->va, in mlxbf_tmfifo_virtio_find_vqs()
948 dev_err(&vdev->dev, "vring_new_virtqueue failed\n"); in mlxbf_tmfifo_virtio_find_vqs()
949 ret = -ENOMEM; in mlxbf_tmfifo_virtio_find_vqs()
954 vring->vq = vq; in mlxbf_tmfifo_virtio_find_vqs()
955 vq->priv = vring; in mlxbf_tmfifo_virtio_find_vqs()
970 return tm_vdev->status; in mlxbf_tmfifo_virtio_get_status()
979 tm_vdev->status = status; in mlxbf_tmfifo_virtio_set_status()
987 tm_vdev->status = 0; in mlxbf_tmfifo_virtio_reset()
998 if ((u64)offset + len > sizeof(tm_vdev->config)) in mlxbf_tmfifo_virtio_get()
1001 memcpy(buf, (u8 *)&tm_vdev->config + offset, len); in mlxbf_tmfifo_virtio_get()
1012 if ((u64)offset + len > sizeof(tm_vdev->config)) in mlxbf_tmfifo_virtio_set()
1015 memcpy((u8 *)&tm_vdev->config + offset, buf, len); in mlxbf_tmfifo_virtio_set()
1040 /* Create vdev for the FIFO. */
1042 struct mlxbf_tmfifo *fifo, in mlxbf_tmfifo_create_vdev() argument
1044 void *config, u32 size) 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()
1054 ret = -EEXIST; in mlxbf_tmfifo_create_vdev()
1060 ret = -ENOMEM; in mlxbf_tmfifo_create_vdev()
1064 tm_vdev->vdev.id.device = vdev_id; in mlxbf_tmfifo_create_vdev()
1065 tm_vdev->vdev.config = &mlxbf_tmfifo_virtio_config_ops; in mlxbf_tmfifo_create_vdev()
1066 tm_vdev->vdev.dev.parent = dev; in mlxbf_tmfifo_create_vdev()
1067 tm_vdev->vdev.dev.release = tmfifo_virtio_dev_release; in mlxbf_tmfifo_create_vdev()
1068 tm_vdev->features = features; in mlxbf_tmfifo_create_vdev()
1070 memcpy(&tm_vdev->config, config, size); in mlxbf_tmfifo_create_vdev()
1072 if (mlxbf_tmfifo_alloc_vrings(fifo, tm_vdev)) { in mlxbf_tmfifo_create_vdev()
1074 ret = -ENOMEM; in mlxbf_tmfifo_create_vdev()
1080 tm_vdev->tx_buf.buf = devm_kmalloc(dev, in mlxbf_tmfifo_create_vdev()
1083 fifo->vdev[vdev_id] = tm_vdev; in mlxbf_tmfifo_create_vdev()
1086 ret = register_virtio_device(&tm_vdev->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()
1100 put_device(&tm_vdev->vdev.dev); 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()
1118 unregister_virtio_device(&tm_vdev->vdev); 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()
1132 unsigned long size = ETH_ALEN; in mlxbf_tmfifo_get_cfg_mac() local
1136 rc = efi.get_variable(mlxbf_tmfifo_efi_name, &guid, NULL, &size, buf); in mlxbf_tmfifo_get_cfg_mac()
1137 if (rc == EFI_SUCCESS && size == ETH_ALEN) in mlxbf_tmfifo_get_cfg_mac()
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()
1187 struct device *dev = &pdev->dev; in mlxbf_tmfifo_probe()
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()
1193 return -ENOMEM; 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()
1238 /* A legacy-only interface for now. */ 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()
1280 .name = "bf-tmfifo",