Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit da18656c authored by Linux Build Service Account's avatar Linux Build Service Account Committed by Gerrit - the friendly Code Review server
Browse files

Merge "net: danipc: Add support for danipc"

parents affbcee4 d50d111c
Loading
Loading
Loading
Loading
+66 −0
Original line number Diff line number Diff line
Qualcomm Technologies Inc. DANIPC driver

This is a kernel driver which makes use of DAN IPC hardware module.
DAN IPC is an inter-processor communication network which provides facilities
for fast and reliable data passing between processors.

Required properties:
- compatible:	should be "qcom,danipc"
- reg-names:	"ipc_bufs" - Krait IPC buffers region
		"agent_table" - IPC global agent table region
		"krait_ipc_intr_en" - Krait IPC interrupt enable MUX region
		"cpu0_ipc" - CPU0 IPC region
		"cpu1_ipc" - CPU1 IPC region
		"cpu2_ipc" - CPU2 IPC region
		"cpu3_ipc" - CPU3 IPC region
		"dsp0_ipc" - DSP0 IPC region
		"dsp1_ipc" - DSP1 IPC region
		"dsp2_ipc" - DSP2 IPC region
		"krait_ipc" - Krait IPC region
		"qdsp6_0_ipc" - QDSP6 0 IPC region
		"qdsp6_1_ipc" - QDSP6 1 IPC region
		"qdsp6_2_ipc" - QDSP6 2 IPC region
		"qdsp6_3_ipc" - QDSP6 3 IPC region
- reg:		location and size of Krait IPC buffers
		location and size of IPC global agent table
		location and size of Krait IPC interrupt enable MUX
		location and size of CPU0 IPC region
		location and size of CPU1 IPC region
		location and size of CPU2 IPC region
		location and size of CPU3 IPC region
		location and size of DSP0 IPC region
		location and size of DSP1 IPC region
		location and size of DSP2 IPC region
		location and size of Krait IPC region
		location and size of QDSP6 0 IPC region
		location and size of QDSP6 1 IPC region
		location and size of QDSP6 2 IPC region
		location and size of QDSP6 3 IPC region
- interrupts:	IPC interrupt line

Examples:

	qcom,danipc@251f8000 {
		compatible = "qcom,danipc";
		reg-names = "ipc_bufs", "agent_table", "krait_ipc_intr_en",
				"cpu0_ipc", "cpu1_ipc", "cpu2_ipc", "cpu3_ipc",
				"dsp0_ipc", "dsp1_ipc", "dsp2_ipc", "krait_ipc",
				"qdsp6_0_ipc", "qdsp6_1_ipc", "qdsp6_2_ipc",
				"qdsp6_3_ipc";
		reg = <0x251f8000 0x8000>, /* ipc_bufs */
			<0xf601ac00 0x2000>, /* agent_table */
			<0xfd4a3500 0x100>, /* krait_ipc_intr_en */
			<0xf683a000 0x100>, /* cpu0_ipc */
			<0xf683a000 0x100>, /* cpu1_ipc */
			<0xf683c000 0x100>, /* cpu2_ipc */
			<0xf683c000 0x100>, /* cpu3_ipc */
			<0xf6862000 0x100>, /* dsp0_ipc */
			<0xf6862000 0x100>, /* dsp1_ipc */
			<0xf6878000 0x100>, /* dsp2_ipc */
			<0xfd490000 0x100>, /* krait_ipc */
			<0xfd491000 0x100>, /* qdsp6_0_ipc */
			<0xfd492000 0x100>, /* qdsp6_1_ipc */
			<0xfd493000 0x100>, /* qdsp6_2_ipc */
			<0xfd494000 0x100>; /* qdsp6_3_ipc */
		interrupts = <0 234 0>;
	};
+9 −0
Original line number Diff line number Diff line
@@ -307,6 +307,15 @@ source "drivers/net/wan/Kconfig"

source "drivers/net/ieee802154/Kconfig"

config DANIPC
	tristate "DAN IPC network device"
	depends on PACKET
	help
		Linux implementation of DANIPC (Inter Processor Communication)
		driver. DANIPC is a hardware block providing the means to
		enable an efficient and reliable communication between
		the different processors in the SoC.

config XEN_NETDEV_FRONTEND
	tristate "Xen network device frontend driver"
	depends on XEN
+1 −0
Original line number Diff line number Diff line
@@ -55,6 +55,7 @@ obj-$(CONFIG_WAN) += wan/
obj-$(CONFIG_WLAN) += wireless/
obj-$(CONFIG_WIMAX) += wimax/
obj-$(CONFIG_IEEE802154) += ieee802154/
obj-$(CONFIG_DANIPC) += danipc/

obj-$(CONFIG_VMXNET3) += vmxnet3/
obj-$(CONFIG_XEN_NETDEV_FRONTEND) += xen-netfront.o
+10 −0
Original line number Diff line number Diff line
obj-$(CONFIG_DANIPC) :=		danipc.o

danipc-objs :=		danipc_main.o		\
			danipc_ioctl.o		\
			danipc_data.o		\
			danipc_lowlevel.o	\
			ipc_trns_fifo.o		\
			ipc_cfg.o		\
			ipc.o			\
			danipc_wq.o
+197 −0
Original line number Diff line number Diff line
/*
	All files except if stated otherwise in the begining of the file
	are under the ISC license:
	----------------------------------------------------------------------

	Copyright (c) 2010-2012 Design Art Networks Ltd.

	Permission to use, copy, modify, and/or distribute this software for any
	purpose with or without fee is hereby granted, provided that the above
	copyright notice and this permission notice appear in all copies.

	THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
	WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
	MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
	ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
	WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
	ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
	OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/


#include <linux/module.h>
#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/mutex.h>
#include <linux/skbuff.h>
#include <linux/netdevice.h>

#include "ipc_api.h"

#include "danipc_k.h"
#include "danipc_lowlevel.h"

#define SPURIOUS_FRAME_WORKAROUND

void send_pkt(struct sk_buff *skb)
{
	struct danipc_pair	*pair = (struct danipc_pair *)
						&(skb->cb[HADDR_CB_OFFSET]);
	char			*msg;

	netdev_dbg(skb->dev, "%s: pair={dst=0x%x src=0x%x}\n", __func__,
		pair->dst, pair->src);

	msg = IPC_msg_alloc(pair->src,
			pair->dst,
			skb->data,
			skb->len,
			0x12,
			NULL,
			pair->prio
		);

	if (likely(msg)) {
		IPC_msg_send(msg, pair->prio);
		skb->dev->stats.tx_packets++;
		skb->dev->stats.tx_bytes += skb->len;
	} else {
		pr_err("%s: IPC_msg_alloc failed!", __func__);
		skb->dev->stats.tx_dropped++;
	}

	dev_kfree_skb(skb);
}


static int delay_skb(struct sk_buff *skb, struct ipc_to_virt_map *map)
{
	int			rc;
	struct delayed_skb	*dskb = kmalloc(sizeof(*dskb), GFP_ATOMIC);

	if (dskb) {
		unsigned long	flags;
		dskb->skb = skb;
		INIT_LIST_HEAD(&dskb->list);

		spin_lock_irqsave(&skbs_lock, flags);
		list_add_tail(&delayed_skbs, &dskb->list);
		atomic_inc(&map->pending_skbs);
		spin_unlock_irqrestore(&skbs_lock, flags);

		schedule_work(&delayed_skbs_work);
		rc = NETDEV_TX_OK;
	} else {
		netdev_err(skb->dev, "cannot allocate struct delayed_skb\n");
		rc = NETDEV_TX_BUSY;	/* Try again sometime */
	}
	return rc;
}

int danipc_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
{
	struct danipc_pair	*pair = (struct danipc_pair *)
						&(skb->cb[HADDR_CB_OFFSET]);
	struct ipc_to_virt_map	*map = &ipc_to_virt_map[IPC_GetNode(pair->dst)]
								[pair->prio];
	int			rc = NETDEV_TX_OK;

#ifdef SPURIOUS_FRAME_WORKAROUND
	/* After the device is opened (ifconfig danipc up) someone (kernel?)
	 * sends 6 weird packets to our interface. Meantime just discard
	 * these packages, afterwards will need to understand the source and
	 * handle them properly.
	 * Vladik, 27.11.2013
	 */
	if (pair->prio == 13) {
		printk(
			"%s: unknown packet; pair {src=0x%x dst=0x%x prio=%u}, ignoring\n",
				__func__, pair->src, pair->dst, pair->prio);
		dev_kfree_skb(skb);
		return rc;
	}
#endif

	if (map->paddr && atomic_read(&map->pending_skbs) == 0)
		send_pkt(skb);
	else
		rc = delay_skb(skb, map);

	return rc;
}

static void
read_ipc_message(char *const packet, char *buf,
		struct IPC_message_hdr *const first_hdr, const unsigned len,
		u8 cpu_id,
		enum IPC_trns_priority pri)
{
	unsigned		data_len = IPC_FIRST_BUF_DATA_SIZE_MAX;
	unsigned		total_len = 0;
	unsigned		rest_len = len;
	uint8_t			*data_ptr = (uint8_t *)(first_hdr) +
						sizeof(struct IPC_message_hdr);
	struct IPC_buffer_hdr	*next_ptr = NULL;

	if (first_hdr->nextBufPtr)
		first_hdr->nextBufPtr = ipc_to_virt(cpu_id, pri,
						(u32)first_hdr->nextBufPtr);
	next_ptr = first_hdr->nextBufPtr;

	do {
		if (total_len != 0) {
			data_len = IPC_NEXT_BUF_DATA_SIZE_MAX;
			data_ptr = (uint8_t *)(next_ptr) +
						sizeof(struct IPC_buffer_hdr);
			if (next_ptr->nextBufPtr)
				next_ptr->nextBufPtr = ipc_to_virt(cpu_id, pri,
						(u32)next_ptr->nextBufPtr);
			next_ptr = next_ptr->nextBufPtr;
		}

		/* Clean 2 last bits (service information) */
		next_ptr = (struct IPC_buffer_hdr *)(((uint32_t)next_ptr) &
							(~IPC_BUF_TYPE_BITS));
		data_len = min(rest_len, data_len);
		rest_len -= data_len;
		memcpy(buf + total_len, data_ptr, data_len);
		total_len += data_len;
	} while ((next_ptr != NULL) && (rest_len != 0));

	IPC_buf_free(packet, pri);
}

void
handle_incoming_packet(char *const packet, u8 cpu_id,
						enum IPC_trns_priority pri)
{
	struct IPC_message_hdr *const first_hdr =
					    (struct IPC_message_hdr *)packet;
	const unsigned			msg_len = first_hdr->msgLen;

	struct sk_buff *skb = netdev_alloc_skb(danipc_dev, msg_len);

	if (skb) {
		struct danipc_pair	*pair = (struct danipc_pair *)
						&(skb->cb[HADDR_CB_OFFSET]);

		pair->dst = first_hdr->destAgentId;
		pair->src = first_hdr->srcAgentId;

		read_ipc_message(packet, skb->data, first_hdr, msg_len, cpu_id,
					pri);

		netdev_dbg(danipc_dev, "%s() pair={dst=0x%x src=0x%x}\n",
			__func__, pair->dst, pair->src);

		skb_put(skb, msg_len);
		skb_reset_mac_header(skb);

		skb->protocol = cpu_to_be16(AGENTID_TO_COOKIE(pair->dst, pri));

		netif_rx(skb);
		danipc_dev->stats.rx_packets++;
		danipc_dev->stats.rx_bytes += skb->len;
	} else
		danipc_dev->stats.rx_dropped++;
}
Loading