^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) * This file is provided under a dual BSD/GPLv2 license. When using or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * redistributing this file, you may do so under either license.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * GPL LICENSE SUMMARY
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * Copyright(c) 2015 Intel Corporation. All rights reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * Copyright(c) 2017 T-Platforms. All Rights Reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) * This program is free software; you can redistribute it and/or modify
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) * it under the terms of version 2 of the GNU General Public License as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) * published by the Free Software Foundation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) * BSD LICENSE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) * Copyright(c) 2015 Intel Corporation. All rights reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) * Copyright(c) 2017 T-Platforms. All Rights Reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) * Redistribution and use in source and binary forms, with or without
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) * modification, are permitted provided that the following conditions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) * are met:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) * * Redistributions of source code must retain the above copyright
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) * notice, this list of conditions and the following disclaimer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) * * Redistributions in binary form must reproduce the above copy
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) * notice, this list of conditions and the following disclaimer in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) * the documentation and/or other materials provided with the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) * distribution.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) * * Neither the name of Intel Corporation nor the names of its
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) * contributors may be used to endorse or promote products derived
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) * from this software without specific prior written permission.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) * PCIe NTB Perf Linux driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) * How to use this tool, by example.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) * Assuming $DBG_DIR is something like:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) * '/sys/kernel/debug/ntb_perf/0000:00:03.0'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) * Suppose aside from local device there is at least one remote device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) * connected to NTB with index 0.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) *-----------------------------------------------------------------------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) * Eg: install driver with specified chunk/total orders and dma-enabled flag
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) * root@self# insmod ntb_perf.ko chunk_order=19 total_order=28 use_dma
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) *-----------------------------------------------------------------------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) * Eg: check NTB ports (index) and MW mapping information
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) * root@self# cat $DBG_DIR/info
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) *-----------------------------------------------------------------------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) * Eg: start performance test with peer (index 0) and get the test metrics
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) * root@self# echo 0 > $DBG_DIR/run
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) * root@self# cat $DBG_DIR/run
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) #include <linux/sched.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) #include <linux/wait.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) #include <linux/dma-mapping.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) #include <linux/dmaengine.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) #include <linux/pci.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) #include <linux/ktime.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) #include <linux/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) #include <linux/sizes.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) #include <linux/workqueue.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) #include <linux/debugfs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) #include <linux/random.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) #include <linux/ntb.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) #define DRIVER_NAME "ntb_perf"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) #define DRIVER_VERSION "2.0"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) MODULE_LICENSE("Dual BSD/GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) MODULE_VERSION(DRIVER_VERSION);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) MODULE_AUTHOR("Dave Jiang <dave.jiang@intel.com>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) MODULE_DESCRIPTION("PCIe NTB Performance Measurement Tool");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) #define MAX_THREADS_CNT 32
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) #define DEF_THREADS_CNT 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) #define MAX_CHUNK_SIZE SZ_1M
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) #define MAX_CHUNK_ORDER 20 /* no larger than 1M */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) #define DMA_TRIES 100
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) #define DMA_MDELAY 10
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) #define MSG_TRIES 1000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) #define MSG_UDELAY_LOW 1000000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) #define MSG_UDELAY_HIGH 2000000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) #define PERF_BUF_LEN 1024
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) static unsigned long max_mw_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) module_param(max_mw_size, ulong, 0644);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) MODULE_PARM_DESC(max_mw_size, "Upper limit of memory window size");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) static unsigned char chunk_order = 19; /* 512K */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) module_param(chunk_order, byte, 0644);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) MODULE_PARM_DESC(chunk_order, "Data chunk order [2^n] to transfer");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) static unsigned char total_order = 30; /* 1G */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) module_param(total_order, byte, 0644);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) MODULE_PARM_DESC(total_order, "Total data order [2^n] to transfer");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) static bool use_dma; /* default to 0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) module_param(use_dma, bool, 0644);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) MODULE_PARM_DESC(use_dma, "Use DMA engine to measure performance");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) /*==============================================================================
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) * Perf driver data definition
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) *==============================================================================
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) enum perf_cmd {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) PERF_CMD_INVAL = -1,/* invalid spad command */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) PERF_CMD_SSIZE = 0, /* send out buffer size */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) PERF_CMD_RSIZE = 1, /* recv in buffer size */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) PERF_CMD_SXLAT = 2, /* send in buffer xlat */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) PERF_CMD_RXLAT = 3, /* recv out buffer xlat */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) PERF_CMD_CLEAR = 4, /* clear allocated memory */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) PERF_STS_DONE = 5, /* init is done */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) PERF_STS_LNKUP = 6, /* link up state flag */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) struct perf_ctx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) struct perf_peer {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) struct perf_ctx *perf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) int pidx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) int gidx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) /* Outbound MW params */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) u64 outbuf_xlat;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) resource_size_t outbuf_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) void __iomem *outbuf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) phys_addr_t out_phys_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) dma_addr_t dma_dst_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) /* Inbound MW params */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) dma_addr_t inbuf_xlat;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) resource_size_t inbuf_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) void *inbuf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) /* NTB connection setup service */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) struct work_struct service;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) unsigned long sts;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) struct completion init_comp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) #define to_peer_service(__work) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) container_of(__work, struct perf_peer, service)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) struct perf_thread {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) struct perf_ctx *perf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) int tidx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) /* DMA-based test sync parameters */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) atomic_t dma_sync;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) wait_queue_head_t dma_wait;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) struct dma_chan *dma_chan;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) /* Data source and measured statistics */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) void *src;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) u64 copied;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) ktime_t duration;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) int status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) struct work_struct work;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) #define to_thread_work(__work) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) container_of(__work, struct perf_thread, work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) struct perf_ctx {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) struct ntb_dev *ntb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) /* Global device index and peers descriptors */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) int gidx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) int pcnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) struct perf_peer *peers;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) /* Performance measuring work-threads interface */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) unsigned long busy_flag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) wait_queue_head_t twait;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) atomic_t tsync;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) u8 tcnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) struct perf_peer *test_peer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) struct perf_thread threads[MAX_THREADS_CNT];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) /* Scratchpad/Message IO operations */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) int (*cmd_send)(struct perf_peer *peer, enum perf_cmd cmd, u64 data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) int (*cmd_recv)(struct perf_ctx *perf, int *pidx, enum perf_cmd *cmd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) u64 *data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) struct dentry *dbgfs_dir;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) * Scratchpads-base commands interface
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) #define PERF_SPAD_CNT(_pcnt) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) (3*((_pcnt) + 1))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) #define PERF_SPAD_CMD(_gidx) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) (3*(_gidx))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) #define PERF_SPAD_LDATA(_gidx) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) (3*(_gidx) + 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) #define PERF_SPAD_HDATA(_gidx) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) (3*(_gidx) + 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) #define PERF_SPAD_NOTIFY(_gidx) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) (BIT_ULL(_gidx))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) * Messages-base commands interface
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) #define PERF_MSG_CNT 3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) #define PERF_MSG_CMD 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) #define PERF_MSG_LDATA 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) #define PERF_MSG_HDATA 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) /*==============================================================================
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) * Static data declarations
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) *==============================================================================
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) static struct dentry *perf_dbgfs_topdir;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) static struct workqueue_struct *perf_wq __read_mostly;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) /*==============================================================================
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) * NTB cross-link commands execution service
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) *==============================================================================
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) static void perf_terminate_test(struct perf_ctx *perf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) static inline bool perf_link_is_up(struct perf_peer *peer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) u64 link;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) link = ntb_link_is_up(peer->perf->ntb, NULL, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) return !!(link & BIT_ULL_MASK(peer->pidx));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) static int perf_spad_cmd_send(struct perf_peer *peer, enum perf_cmd cmd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) u64 data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) struct perf_ctx *perf = peer->perf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) int try;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) u32 sts;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) dev_dbg(&perf->ntb->dev, "CMD send: %d 0x%llx\n", cmd, data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) * Perform predefined number of attempts before give up.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) * We are sending the data to the port specific scratchpad, so
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) * to prevent a multi-port access race-condition. Additionally
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) * there is no need in local locking since only thread-safe
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) * service work is using this method.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) for (try = 0; try < MSG_TRIES; try++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) if (!perf_link_is_up(peer))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) return -ENOLINK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) sts = ntb_peer_spad_read(perf->ntb, peer->pidx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) PERF_SPAD_CMD(perf->gidx));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) if (sts != PERF_CMD_INVAL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) usleep_range(MSG_UDELAY_LOW, MSG_UDELAY_HIGH);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) ntb_peer_spad_write(perf->ntb, peer->pidx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) PERF_SPAD_LDATA(perf->gidx),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) lower_32_bits(data));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) ntb_peer_spad_write(perf->ntb, peer->pidx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) PERF_SPAD_HDATA(perf->gidx),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) upper_32_bits(data));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) ntb_peer_spad_write(perf->ntb, peer->pidx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) PERF_SPAD_CMD(perf->gidx),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) ntb_peer_db_set(perf->ntb, PERF_SPAD_NOTIFY(peer->gidx));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) dev_dbg(&perf->ntb->dev, "DB ring peer %#llx\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) PERF_SPAD_NOTIFY(peer->gidx));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) return try < MSG_TRIES ? 0 : -EAGAIN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) static int perf_spad_cmd_recv(struct perf_ctx *perf, int *pidx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) enum perf_cmd *cmd, u64 *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) struct perf_peer *peer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) u32 val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) ntb_db_clear(perf->ntb, PERF_SPAD_NOTIFY(perf->gidx));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) * We start scanning all over, since cleared DB may have been set
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) * by any peer. Yes, it makes peer with smaller index being
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) * serviced with greater priority, but it's convenient for spad
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) * and message code unification and simplicity.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) for (*pidx = 0; *pidx < perf->pcnt; (*pidx)++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) peer = &perf->peers[*pidx];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) if (!perf_link_is_up(peer))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) val = ntb_spad_read(perf->ntb, PERF_SPAD_CMD(peer->gidx));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) if (val == PERF_CMD_INVAL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) *cmd = val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) val = ntb_spad_read(perf->ntb, PERF_SPAD_LDATA(peer->gidx));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) *data = val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) val = ntb_spad_read(perf->ntb, PERF_SPAD_HDATA(peer->gidx));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) *data |= (u64)val << 32;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) /* Next command can be retrieved from now */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) ntb_spad_write(perf->ntb, PERF_SPAD_CMD(peer->gidx),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) PERF_CMD_INVAL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) dev_dbg(&perf->ntb->dev, "CMD recv: %d 0x%llx\n", *cmd, *data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) return -ENODATA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) static int perf_msg_cmd_send(struct perf_peer *peer, enum perf_cmd cmd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) u64 data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) struct perf_ctx *perf = peer->perf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) int try, ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) u64 outbits;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) dev_dbg(&perf->ntb->dev, "CMD send: %d 0x%llx\n", cmd, data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) * Perform predefined number of attempts before give up. Message
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) * registers are free of race-condition problem when accessed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) * from different ports, so we don't need splitting registers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) * by global device index. We also won't have local locking,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) * since the method is used from service work only.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) outbits = ntb_msg_outbits(perf->ntb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) for (try = 0; try < MSG_TRIES; try++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) if (!perf_link_is_up(peer))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) return -ENOLINK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) ret = ntb_msg_clear_sts(perf->ntb, outbits);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) ntb_peer_msg_write(perf->ntb, peer->pidx, PERF_MSG_LDATA,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) lower_32_bits(data));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) if (ntb_msg_read_sts(perf->ntb) & outbits) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) usleep_range(MSG_UDELAY_LOW, MSG_UDELAY_HIGH);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) ntb_peer_msg_write(perf->ntb, peer->pidx, PERF_MSG_HDATA,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) upper_32_bits(data));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) /* This call shall trigger peer message event */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) ntb_peer_msg_write(perf->ntb, peer->pidx, PERF_MSG_CMD, cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) return try < MSG_TRIES ? 0 : -EAGAIN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) static int perf_msg_cmd_recv(struct perf_ctx *perf, int *pidx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) enum perf_cmd *cmd, u64 *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) u64 inbits;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) u32 val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) inbits = ntb_msg_inbits(perf->ntb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) if (hweight64(ntb_msg_read_sts(perf->ntb) & inbits) < 3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) return -ENODATA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) val = ntb_msg_read(perf->ntb, pidx, PERF_MSG_CMD);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) *cmd = val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) val = ntb_msg_read(perf->ntb, pidx, PERF_MSG_LDATA);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) *data = val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) val = ntb_msg_read(perf->ntb, pidx, PERF_MSG_HDATA);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) *data |= (u64)val << 32;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) /* Next command can be retrieved from now */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) ntb_msg_clear_sts(perf->ntb, inbits);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) dev_dbg(&perf->ntb->dev, "CMD recv: %d 0x%llx\n", *cmd, *data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) static int perf_cmd_send(struct perf_peer *peer, enum perf_cmd cmd, u64 data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) struct perf_ctx *perf = peer->perf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) if (cmd == PERF_CMD_SSIZE || cmd == PERF_CMD_SXLAT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) return perf->cmd_send(peer, cmd, data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) dev_err(&perf->ntb->dev, "Send invalid command\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) static int perf_cmd_exec(struct perf_peer *peer, enum perf_cmd cmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) switch (cmd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) case PERF_CMD_SSIZE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) case PERF_CMD_RSIZE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) case PERF_CMD_SXLAT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) case PERF_CMD_RXLAT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) case PERF_CMD_CLEAR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) dev_err(&peer->perf->ntb->dev, "Exec invalid command\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) /* No need of memory barrier, since bit ops have invernal lock */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) set_bit(cmd, &peer->sts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) dev_dbg(&peer->perf->ntb->dev, "CMD exec: %d\n", cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) (void)queue_work(system_highpri_wq, &peer->service);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) static int perf_cmd_recv(struct perf_ctx *perf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) struct perf_peer *peer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) int ret, pidx, cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) u64 data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) while (!(ret = perf->cmd_recv(perf, &pidx, &cmd, &data))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) peer = &perf->peers[pidx];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) switch (cmd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) case PERF_CMD_SSIZE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) peer->inbuf_size = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) return perf_cmd_exec(peer, PERF_CMD_RSIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) case PERF_CMD_SXLAT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) peer->outbuf_xlat = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) return perf_cmd_exec(peer, PERF_CMD_RXLAT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) dev_err(&perf->ntb->dev, "Recv invalid command\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) /* Return 0 if no data left to process, otherwise an error */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) return ret == -ENODATA ? 0 : ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) static void perf_link_event(void *ctx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) struct perf_ctx *perf = ctx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) struct perf_peer *peer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) bool lnk_up;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) int pidx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) for (pidx = 0; pidx < perf->pcnt; pidx++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) peer = &perf->peers[pidx];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) lnk_up = perf_link_is_up(peer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) if (lnk_up &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) !test_and_set_bit(PERF_STS_LNKUP, &peer->sts)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) perf_cmd_exec(peer, PERF_CMD_SSIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) } else if (!lnk_up &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) test_and_clear_bit(PERF_STS_LNKUP, &peer->sts)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) perf_cmd_exec(peer, PERF_CMD_CLEAR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) static void perf_db_event(void *ctx, int vec)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) struct perf_ctx *perf = ctx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) dev_dbg(&perf->ntb->dev, "DB vec %d mask %#llx bits %#llx\n", vec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) ntb_db_vector_mask(perf->ntb, vec), ntb_db_read(perf->ntb));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) /* Just receive all available commands */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) (void)perf_cmd_recv(perf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) static void perf_msg_event(void *ctx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) struct perf_ctx *perf = ctx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) dev_dbg(&perf->ntb->dev, "Msg status bits %#llx\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) ntb_msg_read_sts(perf->ntb));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) /* Messages are only sent one-by-one */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) (void)perf_cmd_recv(perf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) static const struct ntb_ctx_ops perf_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) .link_event = perf_link_event,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) .db_event = perf_db_event,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) .msg_event = perf_msg_event
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) static void perf_free_outbuf(struct perf_peer *peer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) (void)ntb_peer_mw_clear_trans(peer->perf->ntb, peer->pidx, peer->gidx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) static int perf_setup_outbuf(struct perf_peer *peer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) struct perf_ctx *perf = peer->perf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) /* Outbuf size can be unaligned due to custom max_mw_size */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) ret = ntb_peer_mw_set_trans(perf->ntb, peer->pidx, peer->gidx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) peer->outbuf_xlat, peer->outbuf_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) dev_err(&perf->ntb->dev, "Failed to set outbuf translation\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) /* Initialization is finally done */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) set_bit(PERF_STS_DONE, &peer->sts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) complete_all(&peer->init_comp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) static void perf_free_inbuf(struct perf_peer *peer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) if (!peer->inbuf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) (void)ntb_mw_clear_trans(peer->perf->ntb, peer->pidx, peer->gidx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) dma_free_coherent(&peer->perf->ntb->pdev->dev, peer->inbuf_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) peer->inbuf, peer->inbuf_xlat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) peer->inbuf = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) static int perf_setup_inbuf(struct perf_peer *peer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) resource_size_t xlat_align, size_align, size_max;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) struct perf_ctx *perf = peer->perf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) /* Get inbound MW parameters */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) ret = ntb_mw_get_align(perf->ntb, peer->pidx, perf->gidx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) &xlat_align, &size_align, &size_max);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) dev_err(&perf->ntb->dev, "Couldn't get inbuf restrictions\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) if (peer->inbuf_size > size_max) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) dev_err(&perf->ntb->dev, "Too big inbuf size %pa > %pa\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) &peer->inbuf_size, &size_max);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) peer->inbuf_size = round_up(peer->inbuf_size, size_align);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) perf_free_inbuf(peer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) peer->inbuf = dma_alloc_coherent(&perf->ntb->pdev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) peer->inbuf_size, &peer->inbuf_xlat,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) if (!peer->inbuf) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) dev_err(&perf->ntb->dev, "Failed to alloc inbuf of %pa\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) &peer->inbuf_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) if (!IS_ALIGNED(peer->inbuf_xlat, xlat_align)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) dev_err(&perf->ntb->dev, "Unaligned inbuf allocated\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) goto err_free_inbuf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) ret = ntb_mw_set_trans(perf->ntb, peer->pidx, peer->gidx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) peer->inbuf_xlat, peer->inbuf_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) dev_err(&perf->ntb->dev, "Failed to set inbuf translation\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) goto err_free_inbuf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) * We submit inbuf xlat transmission cmd for execution here to follow
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) * the code architecture, even though this method is called from service
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) * work itself so the command will be executed right after it returns.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) (void)perf_cmd_exec(peer, PERF_CMD_SXLAT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) err_free_inbuf:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) perf_free_inbuf(peer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) static void perf_service_work(struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) struct perf_peer *peer = to_peer_service(work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) if (test_and_clear_bit(PERF_CMD_SSIZE, &peer->sts))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) perf_cmd_send(peer, PERF_CMD_SSIZE, peer->outbuf_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) if (test_and_clear_bit(PERF_CMD_RSIZE, &peer->sts))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) perf_setup_inbuf(peer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) if (test_and_clear_bit(PERF_CMD_SXLAT, &peer->sts))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) perf_cmd_send(peer, PERF_CMD_SXLAT, peer->inbuf_xlat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) if (test_and_clear_bit(PERF_CMD_RXLAT, &peer->sts))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) perf_setup_outbuf(peer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) if (test_and_clear_bit(PERF_CMD_CLEAR, &peer->sts)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) init_completion(&peer->init_comp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) clear_bit(PERF_STS_DONE, &peer->sts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) if (test_bit(0, &peer->perf->busy_flag) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) peer == peer->perf->test_peer) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) dev_warn(&peer->perf->ntb->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) "Freeing while test on-fly\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) perf_terminate_test(peer->perf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) perf_free_outbuf(peer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) perf_free_inbuf(peer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) static int perf_init_service(struct perf_ctx *perf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) u64 mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) if (ntb_peer_mw_count(perf->ntb) < perf->pcnt) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) dev_err(&perf->ntb->dev, "Not enough memory windows\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) if (ntb_msg_count(perf->ntb) >= PERF_MSG_CNT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) perf->cmd_send = perf_msg_cmd_send;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) perf->cmd_recv = perf_msg_cmd_recv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) dev_dbg(&perf->ntb->dev, "Message service initialized\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) dev_dbg(&perf->ntb->dev, "Message service unsupported\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) mask = GENMASK_ULL(perf->pcnt, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) if (ntb_spad_count(perf->ntb) >= PERF_SPAD_CNT(perf->pcnt) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) (ntb_db_valid_mask(perf->ntb) & mask) == mask) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) perf->cmd_send = perf_spad_cmd_send;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) perf->cmd_recv = perf_spad_cmd_recv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) dev_dbg(&perf->ntb->dev, "Scratchpad service initialized\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) dev_dbg(&perf->ntb->dev, "Scratchpad service unsupported\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) dev_err(&perf->ntb->dev, "Command services unsupported\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) static int perf_enable_service(struct perf_ctx *perf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) u64 mask, incmd_bit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) int ret, sidx, scnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) mask = ntb_db_valid_mask(perf->ntb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) (void)ntb_db_set_mask(perf->ntb, mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) ret = ntb_set_ctx(perf->ntb, perf, &perf_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) if (perf->cmd_send == perf_msg_cmd_send) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) u64 inbits, outbits;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) inbits = ntb_msg_inbits(perf->ntb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) outbits = ntb_msg_outbits(perf->ntb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) (void)ntb_msg_set_mask(perf->ntb, inbits | outbits);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) incmd_bit = BIT_ULL(__ffs64(inbits));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) ret = ntb_msg_clear_mask(perf->ntb, incmd_bit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) dev_dbg(&perf->ntb->dev, "MSG sts unmasked %#llx\n", incmd_bit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) scnt = ntb_spad_count(perf->ntb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) for (sidx = 0; sidx < scnt; sidx++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) ntb_spad_write(perf->ntb, sidx, PERF_CMD_INVAL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) incmd_bit = PERF_SPAD_NOTIFY(perf->gidx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) ret = ntb_db_clear_mask(perf->ntb, incmd_bit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) dev_dbg(&perf->ntb->dev, "DB bits unmasked %#llx\n", incmd_bit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) ntb_clear_ctx(perf->ntb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) ntb_link_enable(perf->ntb, NTB_SPEED_AUTO, NTB_WIDTH_AUTO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) /* Might be not necessary */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) ntb_link_event(perf->ntb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740) static void perf_disable_service(struct perf_ctx *perf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742) int pidx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) if (perf->cmd_send == perf_msg_cmd_send) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) u64 inbits;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) inbits = ntb_msg_inbits(perf->ntb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748) (void)ntb_msg_set_mask(perf->ntb, inbits);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) (void)ntb_db_set_mask(perf->ntb, PERF_SPAD_NOTIFY(perf->gidx));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753) ntb_clear_ctx(perf->ntb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) for (pidx = 0; pidx < perf->pcnt; pidx++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) perf_cmd_exec(&perf->peers[pidx], PERF_CMD_CLEAR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758) for (pidx = 0; pidx < perf->pcnt; pidx++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759) flush_work(&perf->peers[pidx].service);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761) for (pidx = 0; pidx < perf->pcnt; pidx++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762) struct perf_peer *peer = &perf->peers[pidx];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764) ntb_spad_write(perf->ntb, PERF_SPAD_CMD(peer->gidx), 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767) ntb_db_clear(perf->ntb, PERF_SPAD_NOTIFY(perf->gidx));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769) ntb_link_disable(perf->ntb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772) /*==============================================================================
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773) * Performance measuring work-thread
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774) *==============================================================================
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777) static void perf_dma_copy_callback(void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779) struct perf_thread *pthr = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781) atomic_dec(&pthr->dma_sync);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782) wake_up(&pthr->dma_wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785) static int perf_copy_chunk(struct perf_thread *pthr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786) void __iomem *dst, void *src, size_t len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788) struct dma_async_tx_descriptor *tx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789) struct dmaengine_unmap_data *unmap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790) struct device *dma_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791) int try = 0, ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792) struct perf_peer *peer = pthr->perf->test_peer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793) void __iomem *vbase;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794) void __iomem *dst_vaddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795) dma_addr_t dst_dma_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797) if (!use_dma) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798) memcpy_toio(dst, src, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799) goto ret_check_tsync;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802) dma_dev = pthr->dma_chan->device->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804) if (!is_dma_copy_aligned(pthr->dma_chan->device, offset_in_page(src),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805) offset_in_page(dst), len))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 806) return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 807)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 808) vbase = peer->outbuf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 809) dst_vaddr = dst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 810) dst_dma_addr = peer->dma_dst_addr + (dst_vaddr - vbase);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 811)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 812) unmap = dmaengine_get_unmap_data(dma_dev, 1, GFP_NOWAIT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 813) if (!unmap)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 814) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 815)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 816) unmap->len = len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 817) unmap->addr[0] = dma_map_page(dma_dev, virt_to_page(src),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 818) offset_in_page(src), len, DMA_TO_DEVICE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 819) if (dma_mapping_error(dma_dev, unmap->addr[0])) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 820) ret = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 821) goto err_free_resource;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 822) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 823) unmap->to_cnt = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 824)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 825) do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 826) tx = dmaengine_prep_dma_memcpy(pthr->dma_chan, dst_dma_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 827) unmap->addr[0], len, DMA_PREP_INTERRUPT | DMA_CTRL_ACK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 828) if (!tx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 829) msleep(DMA_MDELAY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 830) } while (!tx && (try++ < DMA_TRIES));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 831)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 832) if (!tx) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 833) ret = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 834) goto err_free_resource;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 835) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 836)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 837) tx->callback = perf_dma_copy_callback;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 838) tx->callback_param = pthr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 839) dma_set_unmap(tx, unmap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 840)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 841) ret = dma_submit_error(dmaengine_submit(tx));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 842) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 843) dmaengine_unmap_put(unmap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 844) goto err_free_resource;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 845) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 846)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 847) dmaengine_unmap_put(unmap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 848)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 849) atomic_inc(&pthr->dma_sync);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 850) dma_async_issue_pending(pthr->dma_chan);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 851)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 852) ret_check_tsync:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 853) return likely(atomic_read(&pthr->perf->tsync) > 0) ? 0 : -EINTR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 854)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 855) err_free_resource:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 856) dmaengine_unmap_put(unmap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 857)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 858) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 859) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 860)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 861) static bool perf_dma_filter(struct dma_chan *chan, void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 862) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 863) struct perf_ctx *perf = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 864) int node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 865)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 866) node = dev_to_node(&perf->ntb->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 867)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 868) return node == NUMA_NO_NODE || node == dev_to_node(chan->device->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 869) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 870)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 871) static int perf_init_test(struct perf_thread *pthr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 872) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 873) struct perf_ctx *perf = pthr->perf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 874) dma_cap_mask_t dma_mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 875) struct perf_peer *peer = pthr->perf->test_peer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 876)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 877) pthr->src = kmalloc_node(perf->test_peer->outbuf_size, GFP_KERNEL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 878) dev_to_node(&perf->ntb->dev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 879) if (!pthr->src)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 880) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 881)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 882) get_random_bytes(pthr->src, perf->test_peer->outbuf_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 883)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 884) if (!use_dma)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 885) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 886)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 887) dma_cap_zero(dma_mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 888) dma_cap_set(DMA_MEMCPY, dma_mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 889) pthr->dma_chan = dma_request_channel(dma_mask, perf_dma_filter, perf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 890) if (!pthr->dma_chan) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 891) dev_err(&perf->ntb->dev, "%d: Failed to get DMA channel\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 892) pthr->tidx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 893) goto err_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 894) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 895) peer->dma_dst_addr =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 896) dma_map_resource(pthr->dma_chan->device->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 897) peer->out_phys_addr, peer->outbuf_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 898) DMA_FROM_DEVICE, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 899) if (dma_mapping_error(pthr->dma_chan->device->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 900) peer->dma_dst_addr)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 901) dev_err(pthr->dma_chan->device->dev, "%d: Failed to map DMA addr\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 902) pthr->tidx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 903) peer->dma_dst_addr = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 904) dma_release_channel(pthr->dma_chan);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 905) goto err_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 906) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 907) dev_dbg(pthr->dma_chan->device->dev, "%d: Map MMIO %pa to DMA addr %pad\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 908) pthr->tidx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 909) &peer->out_phys_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 910) &peer->dma_dst_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 911)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 912) atomic_set(&pthr->dma_sync, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 913) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 914)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 915) err_free:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 916) atomic_dec(&perf->tsync);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 917) wake_up(&perf->twait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 918) kfree(pthr->src);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 919) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 920) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 921)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 922) static int perf_run_test(struct perf_thread *pthr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 923) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 924) struct perf_peer *peer = pthr->perf->test_peer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 925) struct perf_ctx *perf = pthr->perf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 926) void __iomem *flt_dst, *bnd_dst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 927) u64 total_size, chunk_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 928) void *flt_src;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 929) int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 930)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 931) total_size = 1ULL << total_order;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 932) chunk_size = 1ULL << chunk_order;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 933) chunk_size = min_t(u64, peer->outbuf_size, chunk_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 934)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 935) flt_src = pthr->src;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 936) bnd_dst = peer->outbuf + peer->outbuf_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 937) flt_dst = peer->outbuf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 938)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 939) pthr->duration = ktime_get();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 940)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 941) /* Copied field is cleared on test launch stage */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 942) while (pthr->copied < total_size) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 943) ret = perf_copy_chunk(pthr, flt_dst, flt_src, chunk_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 944) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 945) dev_err(&perf->ntb->dev, "%d: Got error %d on test\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 946) pthr->tidx, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 947) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 948) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 949)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 950) pthr->copied += chunk_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 951)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 952) flt_dst += chunk_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 953) flt_src += chunk_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 954) if (flt_dst >= bnd_dst || flt_dst < peer->outbuf) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 955) flt_dst = peer->outbuf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 956) flt_src = pthr->src;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 957) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 958)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 959) /* Give up CPU to give a chance for other threads to use it */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 960) schedule();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 961) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 962)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 963) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 964) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 965)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 966) static int perf_sync_test(struct perf_thread *pthr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 967) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 968) struct perf_ctx *perf = pthr->perf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 969)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 970) if (!use_dma)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 971) goto no_dma_ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 972)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 973) wait_event(pthr->dma_wait,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 974) (atomic_read(&pthr->dma_sync) == 0 ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 975) atomic_read(&perf->tsync) < 0));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 976)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 977) if (atomic_read(&perf->tsync) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 978) return -EINTR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 979)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 980) no_dma_ret:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 981) pthr->duration = ktime_sub(ktime_get(), pthr->duration);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 982)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 983) dev_dbg(&perf->ntb->dev, "%d: copied %llu bytes\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 984) pthr->tidx, pthr->copied);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 985)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 986) dev_dbg(&perf->ntb->dev, "%d: lasted %llu usecs\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 987) pthr->tidx, ktime_to_us(pthr->duration));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 988)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 989) dev_dbg(&perf->ntb->dev, "%d: %llu MBytes/s\n", pthr->tidx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 990) div64_u64(pthr->copied, ktime_to_us(pthr->duration)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 991)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 992) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 993) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 994)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 995) static void perf_clear_test(struct perf_thread *pthr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 996) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 997) struct perf_ctx *perf = pthr->perf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 998)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 999) if (!use_dma)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) goto no_dma_notify;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003) * If test finished without errors, termination isn't needed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004) * We call it anyway just to be sure of the transfers completion.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) (void)dmaengine_terminate_sync(pthr->dma_chan);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007) if (pthr->perf->test_peer->dma_dst_addr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008) dma_unmap_resource(pthr->dma_chan->device->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009) pthr->perf->test_peer->dma_dst_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) pthr->perf->test_peer->outbuf_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011) DMA_FROM_DEVICE, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013) dma_release_channel(pthr->dma_chan);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015) no_dma_notify:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016) atomic_dec(&perf->tsync);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017) wake_up(&perf->twait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018) kfree(pthr->src);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) static void perf_thread_work(struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023) struct perf_thread *pthr = to_thread_work(work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027) * Perform stages in compliance with use_dma flag value.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028) * Test status is changed only if error happened, otherwise
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029) * status -ENODATA is kept while test is on-fly. Results
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030) * synchronization is performed only if test fininshed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031) * without an error or interruption.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033) ret = perf_init_test(pthr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035) pthr->status = ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039) ret = perf_run_test(pthr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041) pthr->status = ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042) goto err_clear_test;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045) pthr->status = perf_sync_test(pthr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047) err_clear_test:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048) perf_clear_test(pthr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051) static int perf_set_tcnt(struct perf_ctx *perf, u8 tcnt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053) if (tcnt == 0 || tcnt > MAX_THREADS_CNT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056) if (test_and_set_bit_lock(0, &perf->busy_flag))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057) return -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059) perf->tcnt = tcnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061) clear_bit_unlock(0, &perf->busy_flag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066) static void perf_terminate_test(struct perf_ctx *perf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068) int tidx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070) atomic_set(&perf->tsync, -1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071) wake_up(&perf->twait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073) for (tidx = 0; tidx < MAX_THREADS_CNT; tidx++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074) wake_up(&perf->threads[tidx].dma_wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075) cancel_work_sync(&perf->threads[tidx].work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079) static int perf_submit_test(struct perf_peer *peer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081) struct perf_ctx *perf = peer->perf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082) struct perf_thread *pthr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083) int tidx, ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085) ret = wait_for_completion_interruptible(&peer->init_comp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089) if (test_and_set_bit_lock(0, &perf->busy_flag))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090) return -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092) perf->test_peer = peer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093) atomic_set(&perf->tsync, perf->tcnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095) for (tidx = 0; tidx < MAX_THREADS_CNT; tidx++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1096) pthr = &perf->threads[tidx];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1098) pthr->status = -ENODATA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1099) pthr->copied = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1100) pthr->duration = ktime_set(0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1101) if (tidx < perf->tcnt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102) (void)queue_work(perf_wq, &pthr->work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1103) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1104)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1105) ret = wait_event_interruptible(perf->twait,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106) atomic_read(&perf->tsync) <= 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107) if (ret == -ERESTARTSYS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108) perf_terminate_test(perf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109) ret = -EINTR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112) clear_bit_unlock(0, &perf->busy_flag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1113)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1114) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1115) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1116)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1117) static int perf_read_stats(struct perf_ctx *perf, char *buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1118) size_t size, ssize_t *pos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1119) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1120) struct perf_thread *pthr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1121) int tidx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1122)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1123) if (test_and_set_bit_lock(0, &perf->busy_flag))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1124) return -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1125)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1126) (*pos) += scnprintf(buf + *pos, size - *pos,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1127) " Peer %d test statistics:\n", perf->test_peer->pidx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1128)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1129) for (tidx = 0; tidx < MAX_THREADS_CNT; tidx++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1130) pthr = &perf->threads[tidx];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1131)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1132) if (pthr->status == -ENODATA)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1133) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1134)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1135) if (pthr->status) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1136) (*pos) += scnprintf(buf + *pos, size - *pos,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1137) "%d: error status %d\n", tidx, pthr->status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1138) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1139) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1140)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1141) (*pos) += scnprintf(buf + *pos, size - *pos,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1142) "%d: copied %llu bytes in %llu usecs, %llu MBytes/s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1143) tidx, pthr->copied, ktime_to_us(pthr->duration),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1144) div64_u64(pthr->copied, ktime_to_us(pthr->duration)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1145) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1146)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1147) clear_bit_unlock(0, &perf->busy_flag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1148)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1149) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1150) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1151)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1152) static void perf_init_threads(struct perf_ctx *perf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1153) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1154) struct perf_thread *pthr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1155) int tidx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1156)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1157) perf->tcnt = DEF_THREADS_CNT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1158) perf->test_peer = &perf->peers[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1159) init_waitqueue_head(&perf->twait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1160)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1161) for (tidx = 0; tidx < MAX_THREADS_CNT; tidx++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1162) pthr = &perf->threads[tidx];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1163)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1164) pthr->perf = perf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1165) pthr->tidx = tidx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1166) pthr->status = -ENODATA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1167) init_waitqueue_head(&pthr->dma_wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1168) INIT_WORK(&pthr->work, perf_thread_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1169) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1170) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1171)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1172) static void perf_clear_threads(struct perf_ctx *perf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1173) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1174) perf_terminate_test(perf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1175) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1176)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1177) /*==============================================================================
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1178) * DebugFS nodes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1179) *==============================================================================
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1180) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1181)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1182) static ssize_t perf_dbgfs_read_info(struct file *filep, char __user *ubuf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1183) size_t size, loff_t *offp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1184) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1185) struct perf_ctx *perf = filep->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1186) struct perf_peer *peer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1187) size_t buf_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1188) ssize_t pos = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1189) int ret, pidx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1190) char *buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1191)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1192) buf_size = min_t(size_t, size, 0x1000U);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1193)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1194) buf = kmalloc(buf_size, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1195) if (!buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1196) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1197)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1198) pos += scnprintf(buf + pos, buf_size - pos,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1199) " Performance measuring tool info:\n\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1200)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1201) pos += scnprintf(buf + pos, buf_size - pos,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1202) "Local port %d, Global index %d\n", ntb_port_number(perf->ntb),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1203) perf->gidx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1204) pos += scnprintf(buf + pos, buf_size - pos, "Test status: ");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1205) if (test_bit(0, &perf->busy_flag)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1206) pos += scnprintf(buf + pos, buf_size - pos,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1207) "on-fly with port %d (%d)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1208) ntb_peer_port_number(perf->ntb, perf->test_peer->pidx),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1209) perf->test_peer->pidx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1210) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1211) pos += scnprintf(buf + pos, buf_size - pos, "idle\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1212) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1213)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1214) for (pidx = 0; pidx < perf->pcnt; pidx++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1215) peer = &perf->peers[pidx];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1216)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1217) pos += scnprintf(buf + pos, buf_size - pos,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1218) "Port %d (%d), Global index %d:\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1219) ntb_peer_port_number(perf->ntb, peer->pidx), peer->pidx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1220) peer->gidx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1221)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1222) pos += scnprintf(buf + pos, buf_size - pos,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1223) "\tLink status: %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1224) test_bit(PERF_STS_LNKUP, &peer->sts) ? "up" : "down");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1225)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1226) pos += scnprintf(buf + pos, buf_size - pos,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1227) "\tOut buffer addr 0x%pK\n", peer->outbuf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1228)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1229) pos += scnprintf(buf + pos, buf_size - pos,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1230) "\tOut buff phys addr %pa[p]\n", &peer->out_phys_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1231)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1232) pos += scnprintf(buf + pos, buf_size - pos,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1233) "\tOut buffer size %pa\n", &peer->outbuf_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1234)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1235) pos += scnprintf(buf + pos, buf_size - pos,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1236) "\tOut buffer xlat 0x%016llx[p]\n", peer->outbuf_xlat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1237)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1238) if (!peer->inbuf) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1239) pos += scnprintf(buf + pos, buf_size - pos,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1240) "\tIn buffer addr: unallocated\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1241) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1242) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1243)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1244) pos += scnprintf(buf + pos, buf_size - pos,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1245) "\tIn buffer addr 0x%pK\n", peer->inbuf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1246)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1247) pos += scnprintf(buf + pos, buf_size - pos,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1248) "\tIn buffer size %pa\n", &peer->inbuf_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1249)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1250) pos += scnprintf(buf + pos, buf_size - pos,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1251) "\tIn buffer xlat %pad[p]\n", &peer->inbuf_xlat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1252) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1253)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1254) ret = simple_read_from_buffer(ubuf, size, offp, buf, pos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1255) kfree(buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1256)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1257) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1258) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1259)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1260) static const struct file_operations perf_dbgfs_info = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1261) .open = simple_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1262) .read = perf_dbgfs_read_info
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1263) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1264)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1265) static ssize_t perf_dbgfs_read_run(struct file *filep, char __user *ubuf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1266) size_t size, loff_t *offp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1267) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1268) struct perf_ctx *perf = filep->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1269) ssize_t ret, pos = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1270) char *buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1271)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1272) buf = kmalloc(PERF_BUF_LEN, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1273) if (!buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1274) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1275)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1276) ret = perf_read_stats(perf, buf, PERF_BUF_LEN, &pos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1277) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1278) goto err_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1279)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1280) ret = simple_read_from_buffer(ubuf, size, offp, buf, pos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1281) err_free:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1282) kfree(buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1283)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1284) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1285) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1286)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1287) static ssize_t perf_dbgfs_write_run(struct file *filep, const char __user *ubuf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1288) size_t size, loff_t *offp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1289) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1290) struct perf_ctx *perf = filep->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1291) struct perf_peer *peer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1292) int pidx, ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1293)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1294) ret = kstrtoint_from_user(ubuf, size, 0, &pidx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1295) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1296) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1297)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1298) if (pidx < 0 || pidx >= perf->pcnt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1299) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1300)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1301) peer = &perf->peers[pidx];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1302)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1303) ret = perf_submit_test(peer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1304) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1305) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1306)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1307) return size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1308) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1309)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1310) static const struct file_operations perf_dbgfs_run = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1311) .open = simple_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1312) .read = perf_dbgfs_read_run,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1313) .write = perf_dbgfs_write_run
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1314) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1315)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1316) static ssize_t perf_dbgfs_read_tcnt(struct file *filep, char __user *ubuf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1317) size_t size, loff_t *offp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1318) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1319) struct perf_ctx *perf = filep->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1320) char buf[8];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1321) ssize_t pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1322)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1323) pos = scnprintf(buf, sizeof(buf), "%hhu\n", perf->tcnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1324)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1325) return simple_read_from_buffer(ubuf, size, offp, buf, pos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1326) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1327)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1328) static ssize_t perf_dbgfs_write_tcnt(struct file *filep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1329) const char __user *ubuf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1330) size_t size, loff_t *offp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1331) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1332) struct perf_ctx *perf = filep->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1333) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1334) u8 val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1335)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1336) ret = kstrtou8_from_user(ubuf, size, 0, &val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1337) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1338) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1339)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1340) ret = perf_set_tcnt(perf, val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1341) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1342) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1343)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1344) return size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1345) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1346)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1347) static const struct file_operations perf_dbgfs_tcnt = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1348) .open = simple_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1349) .read = perf_dbgfs_read_tcnt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1350) .write = perf_dbgfs_write_tcnt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1351) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1352)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1353) static void perf_setup_dbgfs(struct perf_ctx *perf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1354) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1355) struct pci_dev *pdev = perf->ntb->pdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1356)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1357) perf->dbgfs_dir = debugfs_create_dir(pci_name(pdev), perf_dbgfs_topdir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1358) if (!perf->dbgfs_dir) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1359) dev_warn(&perf->ntb->dev, "DebugFS unsupported\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1360) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1361) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1362)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1363) debugfs_create_file("info", 0600, perf->dbgfs_dir, perf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1364) &perf_dbgfs_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1365)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1366) debugfs_create_file("run", 0600, perf->dbgfs_dir, perf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1367) &perf_dbgfs_run);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1368)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1369) debugfs_create_file("threads_count", 0600, perf->dbgfs_dir, perf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1370) &perf_dbgfs_tcnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1371)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1372) /* They are made read-only for test exec safety and integrity */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1373) debugfs_create_u8("chunk_order", 0500, perf->dbgfs_dir, &chunk_order);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1374)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1375) debugfs_create_u8("total_order", 0500, perf->dbgfs_dir, &total_order);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1376)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1377) debugfs_create_bool("use_dma", 0500, perf->dbgfs_dir, &use_dma);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1378) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1379)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1380) static void perf_clear_dbgfs(struct perf_ctx *perf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1381) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1382) debugfs_remove_recursive(perf->dbgfs_dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1383) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1384)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1385) /*==============================================================================
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1386) * Basic driver initialization
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1387) *==============================================================================
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1388) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1389)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1390) static struct perf_ctx *perf_create_data(struct ntb_dev *ntb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1391) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1392) struct perf_ctx *perf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1393)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1394) perf = devm_kzalloc(&ntb->dev, sizeof(*perf), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1395) if (!perf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1396) return ERR_PTR(-ENOMEM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1397)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1398) perf->pcnt = ntb_peer_port_count(ntb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1399) perf->peers = devm_kcalloc(&ntb->dev, perf->pcnt, sizeof(*perf->peers),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1400) GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1401) if (!perf->peers)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1402) return ERR_PTR(-ENOMEM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1403)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1404) perf->ntb = ntb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1405)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1406) return perf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1407) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1408)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1409) static int perf_setup_peer_mw(struct perf_peer *peer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1410) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1411) struct perf_ctx *perf = peer->perf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1412) phys_addr_t phys_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1413) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1414)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1415) /* Get outbound MW parameters and map it */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1416) ret = ntb_peer_mw_get_addr(perf->ntb, perf->gidx, &phys_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1417) &peer->outbuf_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1418) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1419) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1420)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1421) peer->outbuf = devm_ioremap_wc(&perf->ntb->dev, phys_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1422) peer->outbuf_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1423) if (!peer->outbuf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1424) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1425)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1426) peer->out_phys_addr = phys_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1427)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1428) if (max_mw_size && peer->outbuf_size > max_mw_size) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1429) peer->outbuf_size = max_mw_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1430) dev_warn(&peer->perf->ntb->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1431) "Peer %d outbuf reduced to %pa\n", peer->pidx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1432) &peer->outbuf_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1433) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1434)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1435) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1436) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1437)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1438) static int perf_init_peers(struct perf_ctx *perf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1439) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1440) struct perf_peer *peer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1441) int pidx, lport, ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1442)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1443) lport = ntb_port_number(perf->ntb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1444) perf->gidx = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1445) for (pidx = 0; pidx < perf->pcnt; pidx++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1446) peer = &perf->peers[pidx];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1447)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1448) peer->perf = perf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1449) peer->pidx = pidx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1450) if (lport < ntb_peer_port_number(perf->ntb, pidx)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1451) if (perf->gidx == -1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1452) perf->gidx = pidx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1453) peer->gidx = pidx + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1454) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1455) peer->gidx = pidx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1456) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1457) INIT_WORK(&peer->service, perf_service_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1458) init_completion(&peer->init_comp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1459) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1460) if (perf->gidx == -1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1461) perf->gidx = pidx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1462)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1463) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1464) * Hardware with only two ports may not have unique port
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1465) * numbers. In this case, the gidxs should all be zero.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1466) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1467) if (perf->pcnt == 1 && ntb_port_number(perf->ntb) == 0 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1468) ntb_peer_port_number(perf->ntb, 0) == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1469) perf->gidx = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1470) perf->peers[0].gidx = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1471) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1472)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1473) for (pidx = 0; pidx < perf->pcnt; pidx++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1474) ret = perf_setup_peer_mw(&perf->peers[pidx]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1475) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1476) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1477) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1478)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1479) dev_dbg(&perf->ntb->dev, "Global port index %d\n", perf->gidx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1480)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1481) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1482) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1483)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1484) static int perf_probe(struct ntb_client *client, struct ntb_dev *ntb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1485) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1486) struct perf_ctx *perf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1487) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1488)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1489) perf = perf_create_data(ntb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1490) if (IS_ERR(perf))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1491) return PTR_ERR(perf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1492)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1493) ret = perf_init_peers(perf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1494) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1495) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1496)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1497) perf_init_threads(perf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1498)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1499) ret = perf_init_service(perf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1500) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1501) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1502)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1503) ret = perf_enable_service(perf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1504) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1505) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1506)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1507) perf_setup_dbgfs(perf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1508)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1509) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1510) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1511)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1512) static void perf_remove(struct ntb_client *client, struct ntb_dev *ntb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1513) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1514) struct perf_ctx *perf = ntb->ctx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1515)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1516) perf_clear_dbgfs(perf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1517)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1518) perf_disable_service(perf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1519)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1520) perf_clear_threads(perf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1521) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1522)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1523) static struct ntb_client perf_client = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1524) .ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1525) .probe = perf_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1526) .remove = perf_remove
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1527) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1528) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1529)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1530) static int __init perf_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1531) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1532) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1533)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1534) if (chunk_order > MAX_CHUNK_ORDER) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1535) chunk_order = MAX_CHUNK_ORDER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1536) pr_info("Chunk order reduced to %hhu\n", chunk_order);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1537) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1538)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1539) if (total_order < chunk_order) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1540) total_order = chunk_order;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1541) pr_info("Total data order reduced to %hhu\n", total_order);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1542) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1543)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1544) perf_wq = alloc_workqueue("perf_wq", WQ_UNBOUND | WQ_SYSFS, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1545) if (!perf_wq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1546) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1547)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1548) if (debugfs_initialized())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1549) perf_dbgfs_topdir = debugfs_create_dir(KBUILD_MODNAME, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1550)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1551) ret = ntb_register_client(&perf_client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1552) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1553) debugfs_remove_recursive(perf_dbgfs_topdir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1554) destroy_workqueue(perf_wq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1555) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1556)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1557) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1558) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1559) module_init(perf_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1560)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1561) static void __exit perf_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1562) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1563) ntb_unregister_client(&perf_client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1564) debugfs_remove_recursive(perf_dbgfs_topdir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1565) destroy_workqueue(perf_wq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1566) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1567) module_exit(perf_exit);