^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) * This file is subject to the terms and conditions of the GNU General Public
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * License. See the file "COPYING" in the main directory of this archive
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * for more details.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * (C) Copyright 2020 Hewlett Packard Enterprise Development LP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * Copyright (C) 1999-2009 Silicon Graphics, Inc. All rights reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) * Cross Partition Network Interface (XPNET) support
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) * XPNET provides a virtual network layered on top of the Cross
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) * Partition communication layer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) * XPNET provides direct point-to-point and broadcast-like support
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) * for an ethernet-like device. The ethernet broadcast medium is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) * replaced with a point-to-point message structure which passes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) * pointers to a DMA-capable block that a remote partition should
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) * retrieve and pass to the upper level networking layer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #include <linux/netdevice.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #include <linux/etherdevice.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #include "xp.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) * The message payload transferred by XPC.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) * buf_pa is the physical address where the DMA should pull from.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) * NOTE: for performance reasons, buf_pa should _ALWAYS_ begin on a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) * cacheline boundary. To accomplish this, we record the number of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) * bytes from the beginning of the first cacheline to the first useful
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) * byte of the skb (leadin_ignore) and the number of bytes from the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) * last useful byte of the skb to the end of the last cacheline
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) * (tailout_ignore).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) * size is the number of bytes to transfer which includes the skb->len
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) * (useful bytes of the senders skb) plus the leadin and tailout
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) struct xpnet_message {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) u16 version; /* Version for this message */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) u16 embedded_bytes; /* #of bytes embedded in XPC message */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) u32 magic; /* Special number indicating this is xpnet */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) unsigned long buf_pa; /* phys address of buffer to retrieve */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) u32 size; /* #of bytes in buffer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) u8 leadin_ignore; /* #of bytes to ignore at the beginning */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) u8 tailout_ignore; /* #of bytes to ignore at the end */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) unsigned char data; /* body of small packets */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) * Determine the size of our message, the cacheline aligned size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) * and then the number of message will request from XPC.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) * XPC expects each message to exist in an individual cacheline.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) #define XPNET_MSG_SIZE XPC_MSG_PAYLOAD_MAX_SIZE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) #define XPNET_MSG_DATA_MAX \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) (XPNET_MSG_SIZE - offsetof(struct xpnet_message, data))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) #define XPNET_MSG_NENTRIES (PAGE_SIZE / XPC_MSG_MAX_SIZE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) #define XPNET_MAX_KTHREADS (XPNET_MSG_NENTRIES + 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) #define XPNET_MAX_IDLE_KTHREADS (XPNET_MSG_NENTRIES + 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) * Version number of XPNET implementation. XPNET can always talk to versions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) * with same major #, and never talk to versions with a different version.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) #define _XPNET_VERSION(_major, _minor) (((_major) << 4) | (_minor))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) #define XPNET_VERSION_MAJOR(_v) ((_v) >> 4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) #define XPNET_VERSION_MINOR(_v) ((_v) & 0xf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) #define XPNET_VERSION _XPNET_VERSION(1, 0) /* version 1.0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) #define XPNET_VERSION_EMBED _XPNET_VERSION(1, 1) /* version 1.1 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) #define XPNET_MAGIC 0x88786984 /* "XNET" */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) #define XPNET_VALID_MSG(_m) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) ((XPNET_VERSION_MAJOR(_m->version) == XPNET_VERSION_MAJOR(XPNET_VERSION)) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) && (msg->magic == XPNET_MAGIC))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) #define XPNET_DEVICE_NAME "xp0"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) * When messages are queued with xpc_send_notify, a kmalloc'd buffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) * of the following type is passed as a notification cookie. When the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) * notification function is called, we use the cookie to decide
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) * whether all outstanding message sends have completed. The skb can
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) * then be released.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) struct xpnet_pending_msg {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) atomic_t use_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) static struct net_device *xpnet_device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) * When we are notified of other partitions activating, we add them to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) * our bitmask of partitions to which we broadcast.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) static unsigned long *xpnet_broadcast_partitions;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) /* protect above */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) static DEFINE_SPINLOCK(xpnet_broadcast_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) * Since the Block Transfer Engine (BTE) is being used for the transfer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) * and it relies upon cache-line size transfers, we need to reserve at
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) * least one cache-line for head and tail alignment. The BTE is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) * limited to 8MB transfers.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) * Testing has shown that changing MTU to greater than 64KB has no effect
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) * on TCP as the two sides negotiate a Max Segment Size that is limited
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) * to 64K. Other protocols May use packets greater than this, but for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) * now, the default is 64KB.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) #define XPNET_MAX_MTU (0x800000UL - L1_CACHE_BYTES)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) /* 68 comes from min TCP+IP+MAC header */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) #define XPNET_MIN_MTU 68
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) /* 32KB has been determined to be the ideal */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) #define XPNET_DEF_MTU (0x8000UL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) * The partid is encapsulated in the MAC address beginning in the following
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) * octet and it consists of two octets.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) #define XPNET_PARTID_OCTET 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) /* Define the XPNET debug device structures to be used with dev_dbg() et al */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) static struct device_driver xpnet_dbg_name = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) .name = "xpnet"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) static struct device xpnet_dbg_subname = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) .init_name = "", /* set to "" */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) .driver = &xpnet_dbg_name
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) static struct device *xpnet = &xpnet_dbg_subname;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) * Packet was recevied by XPC and forwarded to us.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) xpnet_receive(short partid, int channel, struct xpnet_message *msg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) void *dst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) enum xp_retval ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) if (!XPNET_VALID_MSG(msg)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) * Packet with a different XPC version. Ignore.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) xpc_received(partid, channel, (void *)msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) xpnet_device->stats.rx_errors++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) dev_dbg(xpnet, "received 0x%lx, %d, %d, %d\n", msg->buf_pa, msg->size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) msg->leadin_ignore, msg->tailout_ignore);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) /* reserve an extra cache line */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) skb = dev_alloc_skb(msg->size + L1_CACHE_BYTES);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) if (!skb) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) dev_err(xpnet, "failed on dev_alloc_skb(%d)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) msg->size + L1_CACHE_BYTES);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) xpc_received(partid, channel, (void *)msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) xpnet_device->stats.rx_errors++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) * The allocated skb has some reserved space.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) * In order to use xp_remote_memcpy(), we need to get the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) * skb->data pointer moved forward.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) skb_reserve(skb, (L1_CACHE_BYTES - ((u64)skb->data &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) (L1_CACHE_BYTES - 1)) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) msg->leadin_ignore));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) * Update the tail pointer to indicate data actually
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) * transferred.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) skb_put(skb, (msg->size - msg->leadin_ignore - msg->tailout_ignore));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) * Move the data over from the other side.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) if ((XPNET_VERSION_MINOR(msg->version) == 1) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) (msg->embedded_bytes != 0)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) dev_dbg(xpnet, "copying embedded message. memcpy(0x%p, 0x%p, "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) "%lu)\n", skb->data, &msg->data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) (size_t)msg->embedded_bytes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) skb_copy_to_linear_data(skb, &msg->data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) (size_t)msg->embedded_bytes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) dst = (void *)((u64)skb->data & ~(L1_CACHE_BYTES - 1));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) dev_dbg(xpnet, "transferring buffer to the skb->data area;\n\t"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) "xp_remote_memcpy(0x%p, 0x%p, %hu)\n", dst,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) (void *)msg->buf_pa, msg->size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) ret = xp_remote_memcpy(xp_pa(dst), msg->buf_pa, msg->size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) if (ret != xpSuccess) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) * !!! Need better way of cleaning skb. Currently skb
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) * !!! appears in_use and we can't just call
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) * !!! dev_kfree_skb.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) dev_err(xpnet, "xp_remote_memcpy(0x%p, 0x%p, 0x%hx) "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) "returned error=0x%x\n", dst,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) (void *)msg->buf_pa, msg->size, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) xpc_received(partid, channel, (void *)msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) xpnet_device->stats.rx_errors++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) dev_dbg(xpnet, "<skb->head=0x%p skb->data=0x%p skb->tail=0x%p "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) "skb->end=0x%p skb->len=%d\n", (void *)skb->head,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) (void *)skb->data, skb_tail_pointer(skb), skb_end_pointer(skb),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) skb->len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) skb->protocol = eth_type_trans(skb, xpnet_device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) skb->ip_summed = CHECKSUM_UNNECESSARY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) dev_dbg(xpnet, "passing skb to network layer\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) "\tskb->head=0x%p skb->data=0x%p skb->tail=0x%p "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) "skb->end=0x%p skb->len=%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) (void *)skb->head, (void *)skb->data, skb_tail_pointer(skb),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) skb_end_pointer(skb), skb->len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) xpnet_device->stats.rx_packets++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) xpnet_device->stats.rx_bytes += skb->len + ETH_HLEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) netif_rx_ni(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) xpc_received(partid, channel, (void *)msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) * This is the handler which XPC calls during any sort of change in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) * state or message reception on a connection.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) xpnet_connection_activity(enum xp_retval reason, short partid, int channel,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) void *data, void *key)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) DBUG_ON(partid < 0 || partid >= xp_max_npartitions);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) DBUG_ON(channel != XPC_NET_CHANNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) switch (reason) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) case xpMsgReceived: /* message received */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) DBUG_ON(data == NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) xpnet_receive(partid, channel, (struct xpnet_message *)data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) case xpConnected: /* connection completed to a partition */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) spin_lock_bh(&xpnet_broadcast_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) __set_bit(partid, xpnet_broadcast_partitions);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) spin_unlock_bh(&xpnet_broadcast_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) netif_carrier_on(xpnet_device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) dev_dbg(xpnet, "%s connected to partition %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) xpnet_device->name, partid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) spin_lock_bh(&xpnet_broadcast_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) __clear_bit(partid, xpnet_broadcast_partitions);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) spin_unlock_bh(&xpnet_broadcast_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) if (bitmap_empty((unsigned long *)xpnet_broadcast_partitions,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) xp_max_npartitions)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) netif_carrier_off(xpnet_device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) dev_dbg(xpnet, "%s disconnected from partition %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) xpnet_device->name, partid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) xpnet_dev_open(struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) enum xp_retval ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) dev_dbg(xpnet, "calling xpc_connect(%d, 0x%p, NULL, %ld, %ld, %ld, "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) "%ld)\n", XPC_NET_CHANNEL, xpnet_connection_activity,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) (unsigned long)XPNET_MSG_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) (unsigned long)XPNET_MSG_NENTRIES,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) (unsigned long)XPNET_MAX_KTHREADS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) (unsigned long)XPNET_MAX_IDLE_KTHREADS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) ret = xpc_connect(XPC_NET_CHANNEL, xpnet_connection_activity, NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) XPNET_MSG_SIZE, XPNET_MSG_NENTRIES,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) XPNET_MAX_KTHREADS, XPNET_MAX_IDLE_KTHREADS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) if (ret != xpSuccess) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) dev_err(xpnet, "ifconfig up of %s failed on XPC connect, "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) "ret=%d\n", dev->name, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) dev_dbg(xpnet, "ifconfig up of %s; XPC connected\n", dev->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) xpnet_dev_stop(struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) xpc_disconnect(XPC_NET_CHANNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) dev_dbg(xpnet, "ifconfig down of %s; XPC disconnected\n", dev->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) * Notification that the other end has received the message and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) * DMA'd the skb information. At this point, they are done with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) * our side. When all recipients are done processing, we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) * release the skb and then release our pending message structure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) xpnet_send_completed(enum xp_retval reason, short partid, int channel,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) void *__qm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) struct xpnet_pending_msg *queued_msg = (struct xpnet_pending_msg *)__qm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) DBUG_ON(queued_msg == NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) dev_dbg(xpnet, "message to %d notified with reason %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) partid, reason);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) if (atomic_dec_return(&queued_msg->use_count) == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) dev_dbg(xpnet, "all acks for skb->head=-x%p\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) (void *)queued_msg->skb->head);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) dev_kfree_skb_any(queued_msg->skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) kfree(queued_msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) xpnet_send(struct sk_buff *skb, struct xpnet_pending_msg *queued_msg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) u64 start_addr, u64 end_addr, u16 embedded_bytes, int dest_partid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) u8 msg_buffer[XPNET_MSG_SIZE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) struct xpnet_message *msg = (struct xpnet_message *)&msg_buffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) u16 msg_size = sizeof(struct xpnet_message);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) enum xp_retval ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) msg->embedded_bytes = embedded_bytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) if (unlikely(embedded_bytes != 0)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) msg->version = XPNET_VERSION_EMBED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) dev_dbg(xpnet, "calling memcpy(0x%p, 0x%p, 0x%lx)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) &msg->data, skb->data, (size_t)embedded_bytes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) skb_copy_from_linear_data(skb, &msg->data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) (size_t)embedded_bytes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) msg_size += embedded_bytes - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) msg->version = XPNET_VERSION;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) msg->magic = XPNET_MAGIC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) msg->size = end_addr - start_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) msg->leadin_ignore = (u64)skb->data - start_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) msg->tailout_ignore = end_addr - (u64)skb_tail_pointer(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) msg->buf_pa = xp_pa((void *)start_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) dev_dbg(xpnet, "sending XPC message to %d:%d\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) "msg->buf_pa=0x%lx, msg->size=%u, "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) "msg->leadin_ignore=%u, msg->tailout_ignore=%u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) dest_partid, XPC_NET_CHANNEL, msg->buf_pa, msg->size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) msg->leadin_ignore, msg->tailout_ignore);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) atomic_inc(&queued_msg->use_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) ret = xpc_send_notify(dest_partid, XPC_NET_CHANNEL, XPC_NOWAIT, msg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) msg_size, xpnet_send_completed, queued_msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) if (unlikely(ret != xpSuccess))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) atomic_dec(&queued_msg->use_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) * Network layer has formatted a packet (skb) and is ready to place it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) * "on the wire". Prepare and send an xpnet_message to all partitions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) * which have connected with us and are targets of this packet.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) * MAC-NOTE: For the XPNET driver, the MAC address contains the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) * destination partid. If the destination partid octets are 0xffff,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) * this packet is to be broadcast to all connected partitions.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) static netdev_tx_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) xpnet_dev_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) struct xpnet_pending_msg *queued_msg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) u64 start_addr, end_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) short dest_partid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) u16 embedded_bytes = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) dev_dbg(xpnet, ">skb->head=0x%p skb->data=0x%p skb->tail=0x%p "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) "skb->end=0x%p skb->len=%d\n", (void *)skb->head,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) (void *)skb->data, skb_tail_pointer(skb), skb_end_pointer(skb),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) skb->len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) if (skb->data[0] == 0x33) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) dev_kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) return NETDEV_TX_OK; /* nothing needed to be done */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) * The xpnet_pending_msg tracks how many outstanding
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) * xpc_send_notifies are relying on this skb. When none
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) * remain, release the skb.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) queued_msg = kmalloc(sizeof(struct xpnet_pending_msg), GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) if (queued_msg == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) dev_warn(xpnet, "failed to kmalloc %ld bytes; dropping "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) "packet\n", sizeof(struct xpnet_pending_msg));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) dev->stats.tx_errors++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) dev_kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) return NETDEV_TX_OK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) /* get the beginning of the first cacheline and end of last */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) start_addr = ((u64)skb->data & ~(L1_CACHE_BYTES - 1));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) end_addr = L1_CACHE_ALIGN((u64)skb_tail_pointer(skb));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) /* calculate how many bytes to embed in the XPC message */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) if (unlikely(skb->len <= XPNET_MSG_DATA_MAX)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) /* skb->data does fit so embed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) embedded_bytes = skb->len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) * Since the send occurs asynchronously, we set the count to one
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) * and begin sending. Any sends that happen to complete before
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) * we are done sending will not free the skb. We will be left
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) * with that task during exit. This also handles the case of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) * a packet destined for a partition which is no longer up.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) atomic_set(&queued_msg->use_count, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) queued_msg->skb = skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) if (skb->data[0] == 0xff) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) /* we are being asked to broadcast to all partitions */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) for_each_set_bit(dest_partid, xpnet_broadcast_partitions,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) xp_max_npartitions) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) xpnet_send(skb, queued_msg, start_addr, end_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) embedded_bytes, dest_partid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) dest_partid = (short)skb->data[XPNET_PARTID_OCTET + 1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) dest_partid |= (short)skb->data[XPNET_PARTID_OCTET + 0] << 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) if (dest_partid >= 0 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) dest_partid < xp_max_npartitions &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) test_bit(dest_partid, xpnet_broadcast_partitions) != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) xpnet_send(skb, queued_msg, start_addr, end_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) embedded_bytes, dest_partid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) dev->stats.tx_packets++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) dev->stats.tx_bytes += skb->len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) if (atomic_dec_return(&queued_msg->use_count) == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) dev_kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) kfree(queued_msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) return NETDEV_TX_OK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) * Deal with transmit timeouts coming from the network layer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) xpnet_dev_tx_timeout(struct net_device *dev, unsigned int txqueue)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) dev->stats.tx_errors++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) static const struct net_device_ops xpnet_netdev_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) .ndo_open = xpnet_dev_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) .ndo_stop = xpnet_dev_stop,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) .ndo_start_xmit = xpnet_dev_hard_start_xmit,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) .ndo_tx_timeout = xpnet_dev_tx_timeout,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) .ndo_set_mac_address = eth_mac_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) .ndo_validate_addr = eth_validate_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) static int __init
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) xpnet_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) int result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) if (!is_uv_system())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) dev_info(xpnet, "registering network device %s\n", XPNET_DEVICE_NAME);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) xpnet_broadcast_partitions = kcalloc(BITS_TO_LONGS(xp_max_npartitions),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) sizeof(long),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) if (xpnet_broadcast_partitions == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) * use ether_setup() to init the majority of our device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) * structure and then override the necessary pieces.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) xpnet_device = alloc_netdev(0, XPNET_DEVICE_NAME, NET_NAME_UNKNOWN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) ether_setup);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) if (xpnet_device == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) kfree(xpnet_broadcast_partitions);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) netif_carrier_off(xpnet_device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) xpnet_device->netdev_ops = &xpnet_netdev_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) xpnet_device->mtu = XPNET_DEF_MTU;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) xpnet_device->min_mtu = XPNET_MIN_MTU;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) xpnet_device->max_mtu = XPNET_MAX_MTU;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) * Multicast assumes the LSB of the first octet is set for multicast
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) * MAC addresses. We chose the first octet of the MAC to be unlikely
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) * to collide with any vendor's officially issued MAC.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) xpnet_device->dev_addr[0] = 0x02; /* locally administered, no OUI */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) xpnet_device->dev_addr[XPNET_PARTID_OCTET + 1] = xp_partition_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) xpnet_device->dev_addr[XPNET_PARTID_OCTET + 0] = (xp_partition_id >> 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) * ether_setup() sets this to a multicast device. We are
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) * really not supporting multicast at this time.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) xpnet_device->flags &= ~IFF_MULTICAST;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) * No need to checksum as it is a DMA transfer. The BTE will
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) * report an error if the data is not retrievable and the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) * packet will be dropped.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) xpnet_device->features = NETIF_F_HW_CSUM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) result = register_netdev(xpnet_device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) if (result != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) free_netdev(xpnet_device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) kfree(xpnet_broadcast_partitions);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) module_init(xpnet_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) static void __exit
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) xpnet_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) dev_info(xpnet, "unregistering network device %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) xpnet_device[0].name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) unregister_netdev(xpnet_device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) free_netdev(xpnet_device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) kfree(xpnet_broadcast_partitions);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) module_exit(xpnet_exit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) MODULE_AUTHOR("Silicon Graphics, Inc.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) MODULE_DESCRIPTION("Cross Partition Network adapter (XPNET)");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) MODULE_LICENSE("GPL");