// SPDX-License-Identifier: GPL-2.0+/* * Mellanox BlueField SoC TmFifo driver * * Copyright (C) 2019 Mellanox Technologies */#include<linux/acpi.h>#include<linux/bitfield.h>#include<linux/circ_buf.h>#include<linux/efi.h>#include<linux/irq.h>#include<linux/module.h>#include<linux/mutex.h>#include<linux/platform_device.h>#include<linux/types.h>#include<linux/virtio_config.h>#include<linux/virtio_console.h>#include<linux/virtio_ids.h>#include<linux/virtio_net.h>#include<linux/virtio_ring.h>#include"mlxbf-tmfifo-regs.h"/* Vring size. */#define MLXBF_TMFIFO_VRING_SIZE SZ_1K/* Console Tx buffer size. */#define MLXBF_TMFIFO_CON_TX_BUF_SIZE SZ_32K/* Console Tx buffer reserved space. */#define MLXBF_TMFIFO_CON_TX_BUF_RSV_SIZE 8/* House-keeping timer interval. */#define MLXBF_TMFIFO_TIMER_INTERVAL (HZ / 10)/* Virtual devices sharing the TM FIFO. */#define MLXBF_TMFIFO_VDEV_MAX (VIRTIO_ID_CONSOLE + 1)/* * Reserve 1/16 of TmFifo space, so console messages are not starved by * the networking traffic. */#define MLXBF_TMFIFO_RESERVE_RATIO 16/* Message with data needs at least two words (for header & data). */#define MLXBF_TMFIFO_DATA_MIN_WORDS 2/* Tx timeout in milliseconds. */#define TMFIFO_TX_TIMEOUT 2000/* ACPI UID for BlueField-3. */#define TMFIFO_BF3_UID 1structmlxbf_tmfifo;/** * struct mlxbf_tmfifo_vring - Structure of the TmFifo virtual ring * @va: virtual address of the ring * @dma: dma address of the ring * @vq: pointer to the virtio virtqueue * @desc: current descriptor of the pending packet * @desc_head: head descriptor of the pending packet * @drop_desc: dummy desc for packet dropping * @cur_len: processed length of the current descriptor * @rem_len: remaining length of the pending packet * @rem_padding: remaining bytes to send as paddings * @pkt_len: total length of the pending packet * @next_avail: next avail descriptor id * @num: vring size (number of descriptors) * @align: vring alignment size * @index: vring index * @vdev_id: vring virtio id (VIRTIO_ID_xxx) * @tx_timeout: expire time of last tx packet * @fifo: pointer to the tmfifo structure */structmlxbf_tmfifo_vring{void*va;dma_addr_tdma;structvirtqueue*vq;structvring_desc*desc;structvring_desc*desc_head;structvring_descdrop_desc;intcur_len;intrem_len;intrem_padding;u32pkt_len;u16next_avail;intnum;