linux/drivers/ntb/test/ntb_tool.c

/*
 * This file is provided under a dual BSD/GPLv2 license.  When using or
 *   redistributing this file, you may do so under either license.
 *
 *   GPL LICENSE SUMMARY
 *
 *   Copyright (C) 2015 EMC Corporation. All Rights Reserved.
 *   Copyright (C) 2017 T-Platforms All Rights Reserved.
 *
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of version 2 of the GNU General Public License as
 *   published by the Free Software Foundation.
 *
 *   This program is distributed in the hope that it will be useful, but
 *   WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *   General Public License for more details.
 *
 *   BSD LICENSE
 *
 *   Copyright (C) 2015 EMC Corporation. All Rights Reserved.
 *   Copyright (C) 2017 T-Platforms All Rights Reserved.
 *
 *   Redistribution and use in source and binary forms, with or without
 *   modification, are permitted provided that the following conditions
 *   are met:
 *
 *     * Redistributions of source code must retain the above copyright
 *       notice, this list of conditions and the following disclaimer.
 *     * Redistributions in binary form must reproduce the above copy
 *       notice, this list of conditions and the following disclaimer in
 *       the documentation and/or other materials provided with the
 *       distribution.
 *     * Neither the name of Intel Corporation nor the names of its
 *       contributors may be used to endorse or promote products derived
 *       from this software without specific prior written permission.
 *
 *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 * PCIe NTB Debugging Tool Linux driver
 */

/*
 * How to use this tool, by example.
 *
 * Assuming $DBG_DIR is something like:
 * '/sys/kernel/debug/ntb_tool/0000:00:03.0'
 * Suppose aside from local device there is at least one remote device
 * connected to NTB with index 0.
 *-----------------------------------------------------------------------------
 * Eg: check local/peer device information.
 *
 * # Get local device port number
 * root@self# cat $DBG_DIR/port
 *
 * # Check local device functionality
 * root@self# ls $DBG_DIR
 * db            msg1          msg_sts     peer4/        port
 * db_event      msg2          peer0/      peer5/        spad0
 * db_mask       msg3          peer1/      peer_db       spad1
 * link          msg_event     peer2/      peer_db_mask  spad2
 * msg0          msg_mask      peer3/      peer_spad     spad3
 * # As one can see it supports:
 * # 1) four inbound message registers
 * # 2) four inbound scratchpads
 * # 3) up to six peer devices
 *
 * # Check peer device port number
 * root@self# cat $DBG_DIR/peer0/port
 *
 * # Check peer device(s) functionality to be used
 * root@self# ls $DBG_DIR/peer0
 * link             mw_trans0       mw_trans6        port
 * link_event       mw_trans1       mw_trans7        spad0
 * msg0             mw_trans2       peer_mw_trans0   spad1
 * msg1             mw_trans3       peer_mw_trans1   spad2
 * msg2             mw_trans4       peer_mw_trans2   spad3
 * msg3             mw_trans5       peer_mw_trans3
 * # As one can see we got:
 * # 1) four outbound message registers
 * # 2) four outbound scratchpads
 * # 3) eight inbound memory windows
 * # 4) four outbound memory windows
 *-----------------------------------------------------------------------------
 * Eg: NTB link tests
 *
 * # Set local link up/down
 * root@self# echo Y > $DBG_DIR/link
 * root@self# echo N > $DBG_DIR/link
 *
 * # Check if link with peer device is up/down:
 * root@self# cat $DBG_DIR/peer0/link
 *
 * # Block until the link is up/down
 * root@self# echo Y > $DBG_DIR/peer0/link_event
 * root@self# echo N > $DBG_DIR/peer0/link_event
 *-----------------------------------------------------------------------------
 * Eg: Doorbell registers tests (some functionality might be absent)
 *
 * # Set/clear/get local doorbell
 * root@self# echo 's 1' > $DBG_DIR/db
 * root@self# echo 'c 1' > $DBG_DIR/db
 * root@self# cat  $DBG_DIR/db
 *
 * # Set/clear/get local doorbell mask
 * root@self# echo 's 1' > $DBG_DIR/db_mask
 * root@self# echo 'c 1' > $DBG_DIR/db_mask
 * root@self# cat $DBG_DIR/db_mask
 *
 * # Ring/clear/get peer doorbell
 * root@peer# echo 's 1' > $DBG_DIR/peer_db
 * root@peer# echo 'c 1' > $DBG_DIR/peer_db
 * root@peer# cat $DBG_DIR/peer_db
 *
 * # Set/clear/get peer doorbell mask
 * root@self# echo 's 1' > $DBG_DIR/peer_db_mask
 * root@self# echo 'c 1' > $DBG_DIR/peer_db_mask
 * root@self# cat $DBG_DIR/peer_db_mask
 *
 * # Block until local doorbell is set with specified value
 * root@self# echo 1 > $DBG_DIR/db_event
 *-----------------------------------------------------------------------------
 * Eg: Message registers tests (functionality might be absent)
 *
 * # Set/clear/get in/out message registers status
 * root@self# echo 's 1' > $DBG_DIR/msg_sts
 * root@self# echo 'c 1' > $DBG_DIR/msg_sts
 * root@self# cat $DBG_DIR/msg_sts
 *
 * # Set/clear in/out message registers mask
 * root@self# echo 's 1' > $DBG_DIR/msg_mask
 * root@self# echo 'c 1' > $DBG_DIR/msg_mask
 *
 * # Get inbound message register #0 value and source of port index
 * root@self# cat  $DBG_DIR/msg0
 *
 * # Send some data to peer over outbound message register #0
 * root@self# echo 0x01020304 > $DBG_DIR/peer0/msg0
 *-----------------------------------------------------------------------------
 * Eg: Scratchpad registers tests (functionality might be absent)
 *
 * # Write/read to/from local scratchpad register #0
 * root@peer# echo 0x01020304 > $DBG_DIR/spad0
 * root@peer# cat $DBG_DIR/spad0
 *
 * # Write/read to/from peer scratchpad register #0
 * root@peer# echo 0x01020304 > $DBG_DIR/peer0/spad0
 * root@peer# cat $DBG_DIR/peer0/spad0
 *-----------------------------------------------------------------------------
 * Eg: Memory windows tests
 *
 * # Create inbound memory window buffer of specified size/get its base address
 * root@peer# echo 16384 > $DBG_DIR/peer0/mw_trans0
 * root@peer# cat $DBG_DIR/peer0/mw_trans0
 *
 * # Write/read data to/from inbound memory window
 * root@peer# echo Hello > $DBG_DIR/peer0/mw0
 * root@peer# head -c 7 $DBG_DIR/peer0/mw0
 *
 * # Map outbound memory window/check it settings (on peer device)
 * root@peer# echo 0xADD0BA5E:16384 > $DBG_DIR/peer0/peer_mw_trans0
 * root@peer# cat $DBG_DIR/peer0/peer_mw_trans0
 *
 * # Write/read data to/from outbound memory window (on peer device)
 * root@peer# echo olleH > $DBG_DIR/peer0/peer_mw0
 * root@peer# head -c 7 $DBG_DIR/peer0/peer_mw0
 */

#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/module.h>

#include <linux/debugfs.h>
#include <linux/dma-mapping.h>
#include <linux/pci.h>
#include <linux/slab.h>
#include <linux/uaccess.h>

#include <linux/ntb.h>

#define DRIVER_NAME
#define DRIVER_VERSION

MODULE_LICENSE();
MODULE_VERSION();
MODULE_AUTHOR();
MODULE_DESCRIPTION();

/*
 * Inbound and outbound memory windows descriptor. Union members selection
 * depends on the MW type the structure describes. mm_base/dma_base are the
 * virtual and DMA address of an inbound MW. io_base/tr_base are the MMIO
 * mapped virtual and xlat addresses of an outbound MW respectively.
 */
struct tool_mw {};

/*
 * Wrapper structure is used to distinguish the outbound MW peers reference
 * within the corresponding DebugFS directory IO operation.
 */
struct tool_mw_wrap {};

struct tool_msg {};

struct tool_spad {};

struct tool_peer {};

struct tool_ctx {};

#define TOOL_FOPS_RDWR(__name, __read, __write)

#define TOOL_BUF_LEN

static struct dentry *tool_dbgfs_topdir;

/*==============================================================================
 *                               NTB events handlers
 *==============================================================================
 */

static void tool_link_event(void *ctx)
{}

static void tool_db_event(void *ctx, int vec)
{}

static void tool_msg_event(void *ctx)
{}

static const struct ntb_ctx_ops tool_ops =;

/*==============================================================================
 *                        Common read/write methods
 *==============================================================================
 */

static ssize_t tool_fn_read(struct tool_ctx *tc, char __user *ubuf,
			    size_t size, loff_t *offp,
			    u64 (*fn_read)(struct ntb_dev *))
{}

static ssize_t tool_fn_write(struct tool_ctx *tc,
			     const char __user *ubuf,
			     size_t size, loff_t *offp,
			     int (*fn_set)(struct ntb_dev *, u64),
			     int (*fn_clear)(struct ntb_dev *, u64))
{}

/*==============================================================================
 *                            Port read/write methods
 *==============================================================================
 */

static ssize_t tool_port_read(struct file *filep, char __user *ubuf,
			      size_t size, loff_t *offp)
{}

static TOOL_FOPS_RDWR(tool_port_fops,
		      tool_port_read,
		      NULL);

static ssize_t tool_peer_port_read(struct file *filep, char __user *ubuf,
				   size_t size, loff_t *offp)
{}

static TOOL_FOPS_RDWR(tool_peer_port_fops,
		      tool_peer_port_read,
		      NULL);

static int tool_init_peers(struct tool_ctx *tc)
{}

/*==============================================================================
 *                       Link state read/write methods
 *==============================================================================
 */

static ssize_t tool_link_write(struct file *filep, const char __user *ubuf,
			       size_t size, loff_t *offp)
{}

static TOOL_FOPS_RDWR(tool_link_fops,
		      NULL,
		      tool_link_write);

static ssize_t tool_peer_link_read(struct file *filep, char __user *ubuf,
				   size_t size, loff_t *offp)
{}

static TOOL_FOPS_RDWR(tool_peer_link_fops,
		      tool_peer_link_read,
		      NULL);

static ssize_t tool_peer_link_event_write(struct file *filep,
					  const char __user *ubuf,
					  size_t size, loff_t *offp)
{}

static TOOL_FOPS_RDWR(tool_peer_link_event_fops,
		      NULL,
		      tool_peer_link_event_write);

/*==============================================================================
 *                  Memory windows read/write/setting methods
 *==============================================================================
 */

static ssize_t tool_mw_read(struct file *filep, char __user *ubuf,
			    size_t size, loff_t *offp)
{}

static ssize_t tool_mw_write(struct file *filep, const char __user *ubuf,
			     size_t size, loff_t *offp)
{}

static TOOL_FOPS_RDWR(tool_mw_fops,
		      tool_mw_read,
		      tool_mw_write);

static int tool_setup_mw(struct tool_ctx *tc, int pidx, int widx,
			 size_t req_size)
{}

static void tool_free_mw(struct tool_ctx *tc, int pidx, int widx)
{}

static ssize_t tool_mw_trans_read(struct file *filep, char __user *ubuf,
				  size_t size, loff_t *offp)
{}

static ssize_t tool_mw_trans_write(struct file *filep, const char __user *ubuf,
				   size_t size, loff_t *offp)
{}

static TOOL_FOPS_RDWR(tool_mw_trans_fops,
		      tool_mw_trans_read,
		      tool_mw_trans_write);

static ssize_t tool_peer_mw_read(struct file *filep, char __user *ubuf,
				 size_t size, loff_t *offp)
{}

static ssize_t tool_peer_mw_write(struct file *filep, const char __user *ubuf,
				  size_t size, loff_t *offp)
{}

static TOOL_FOPS_RDWR(tool_peer_mw_fops,
		      tool_peer_mw_read,
		      tool_peer_mw_write);

static int tool_setup_peer_mw(struct tool_ctx *tc, int pidx, int widx,
			      u64 req_addr, size_t req_size)
{}

static void tool_free_peer_mw(struct tool_ctx *tc, int widx)
{}

static ssize_t tool_peer_mw_trans_read(struct file *filep, char __user *ubuf,
					size_t size, loff_t *offp)
{}

static ssize_t tool_peer_mw_trans_write(struct file *filep,
					const char __user *ubuf,
					size_t size, loff_t *offp)
{}

static TOOL_FOPS_RDWR(tool_peer_mw_trans_fops,
		      tool_peer_mw_trans_read,
		      tool_peer_mw_trans_write);

static int tool_init_mws(struct tool_ctx *tc)
{}

static void tool_clear_mws(struct tool_ctx *tc)
{}

/*==============================================================================
 *                       Doorbell read/write methods
 *==============================================================================
 */

static ssize_t tool_db_read(struct file *filep, char __user *ubuf,
			    size_t size, loff_t *offp)
{}

static ssize_t tool_db_write(struct file *filep, const char __user *ubuf,
			     size_t size, loff_t *offp)
{}

static TOOL_FOPS_RDWR(tool_db_fops,
		      tool_db_read,
		      tool_db_write);

static ssize_t tool_db_valid_mask_read(struct file *filep, char __user *ubuf,
				       size_t size, loff_t *offp)
{}

static TOOL_FOPS_RDWR(tool_db_valid_mask_fops,
		      tool_db_valid_mask_read,
		      NULL);

static ssize_t tool_db_mask_read(struct file *filep, char __user *ubuf,
				 size_t size, loff_t *offp)
{}

static ssize_t tool_db_mask_write(struct file *filep, const char __user *ubuf,
			       size_t size, loff_t *offp)
{}

static TOOL_FOPS_RDWR(tool_db_mask_fops,
		      tool_db_mask_read,
		      tool_db_mask_write);

static ssize_t tool_peer_db_read(struct file *filep, char __user *ubuf,
				 size_t size, loff_t *offp)
{}

static ssize_t tool_peer_db_write(struct file *filep, const char __user *ubuf,
				  size_t size, loff_t *offp)
{}

static TOOL_FOPS_RDWR(tool_peer_db_fops,
		      tool_peer_db_read,
		      tool_peer_db_write);

static ssize_t tool_peer_db_mask_read(struct file *filep, char __user *ubuf,
				   size_t size, loff_t *offp)
{}

static ssize_t tool_peer_db_mask_write(struct file *filep,
				       const char __user *ubuf,
				       size_t size, loff_t *offp)
{}

static TOOL_FOPS_RDWR(tool_peer_db_mask_fops,
		      tool_peer_db_mask_read,
		      tool_peer_db_mask_write);

static ssize_t tool_db_event_write(struct file *filep,
				   const char __user *ubuf,
				   size_t size, loff_t *offp)
{}

static TOOL_FOPS_RDWR(tool_db_event_fops,
		      NULL,
		      tool_db_event_write);

/*==============================================================================
 *                       Scratchpads read/write methods
 *==============================================================================
 */

static ssize_t tool_spad_read(struct file *filep, char __user *ubuf,
			      size_t size, loff_t *offp)
{}

static ssize_t tool_spad_write(struct file *filep, const char __user *ubuf,
			       size_t size, loff_t *offp)
{}

static TOOL_FOPS_RDWR(tool_spad_fops,
		      tool_spad_read,
		      tool_spad_write);

static ssize_t tool_peer_spad_read(struct file *filep, char __user *ubuf,
				   size_t size, loff_t *offp)
{}

static ssize_t tool_peer_spad_write(struct file *filep, const char __user *ubuf,
				    size_t size, loff_t *offp)
{}

static TOOL_FOPS_RDWR(tool_peer_spad_fops,
		      tool_peer_spad_read,
		      tool_peer_spad_write);

static int tool_init_spads(struct tool_ctx *tc)
{}

/*==============================================================================
 *                       Messages read/write methods
 *==============================================================================
 */

static ssize_t tool_inmsg_read(struct file *filep, char __user *ubuf,
			       size_t size, loff_t *offp)
{}

static TOOL_FOPS_RDWR(tool_inmsg_fops,
		      tool_inmsg_read,
		      NULL);

static ssize_t tool_outmsg_write(struct file *filep,
				 const char __user *ubuf,
				 size_t size, loff_t *offp)
{}

static TOOL_FOPS_RDWR(tool_outmsg_fops,
		      NULL,
		      tool_outmsg_write);

static ssize_t tool_msg_sts_read(struct file *filep, char __user *ubuf,
				 size_t size, loff_t *offp)
{}

static ssize_t tool_msg_sts_write(struct file *filep, const char __user *ubuf,
				  size_t size, loff_t *offp)
{}

static TOOL_FOPS_RDWR(tool_msg_sts_fops,
		      tool_msg_sts_read,
		      tool_msg_sts_write);

static ssize_t tool_msg_inbits_read(struct file *filep, char __user *ubuf,
				    size_t size, loff_t *offp)
{}

static TOOL_FOPS_RDWR(tool_msg_inbits_fops,
		      tool_msg_inbits_read,
		      NULL);

static ssize_t tool_msg_outbits_read(struct file *filep, char __user *ubuf,
				     size_t size, loff_t *offp)
{}

static TOOL_FOPS_RDWR(tool_msg_outbits_fops,
		      tool_msg_outbits_read,
		      NULL);

static ssize_t tool_msg_mask_write(struct file *filep, const char __user *ubuf,
				   size_t size, loff_t *offp)
{}

static TOOL_FOPS_RDWR(tool_msg_mask_fops,
		      NULL,
		      tool_msg_mask_write);

static ssize_t tool_msg_event_write(struct file *filep,
				    const char __user *ubuf,
				    size_t size, loff_t *offp)
{}

static TOOL_FOPS_RDWR(tool_msg_event_fops,
		      NULL,
		      tool_msg_event_write);

static int tool_init_msgs(struct tool_ctx *tc)
{}

/*==============================================================================
 *                          Initialization methods
 *==============================================================================
 */

static struct tool_ctx *tool_create_data(struct ntb_dev *ntb)
{}

static void tool_clear_data(struct tool_ctx *tc)
{}

static int tool_init_ntb(struct tool_ctx *tc)
{}

static void tool_clear_ntb(struct tool_ctx *tc)
{}

static void tool_setup_dbgfs(struct tool_ctx *tc)
{}

static void tool_clear_dbgfs(struct tool_ctx *tc)
{}

static int tool_probe(struct ntb_client *self, struct ntb_dev *ntb)
{}

static void tool_remove(struct ntb_client *self, struct ntb_dev *ntb)
{}

static struct ntb_client tool_client =;

static int __init tool_init(void)
{}
module_init();

static void __exit tool_exit(void)
{}
module_exit(tool_exit);