Skip to contentSkip to conversation

ntb: Asynchronous NTB devices support

PATCH Superseded Serge Semin 2 participants 12 messages Jul 26, 2016 – Aug 1, 2016

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

cover ntb: Asynchronous NTB devices support

Currently developed NTB-bus supports AMD and Intel Non-transparent PCIe-bridges only. These bridges implement "synchronous" interfaces, which means that memory window translated addresses can be direcly specified from one side to another by writing to a corresponding value to a register. Unlike Intel and AMD there is another vendor - IDT, which produces synchronous and asynchrnous NTB PCIe-switches. If synchronous NTB IDT PCIe-switches works almost the same way as AMD and Intel devices do, the asynchronous ones don't. Due to the registers field specification the translated base addresses of memory windows can not be directly specified to a peer. To solve the problem IDT asynchronous PCIe-switches implement messaging interface to send any kind of information from one RC to another including translated base addresses. In the framework of this patches we developed a set of callback functions for the NTB-bus devices programming interface and drivers for the NT-functions of the following IDT PCIe-switches:
- 89HPES24NT6AG2,
- 89HPES32NT8AG2,
- 89HPES32NT8BG2,
- 89HPES12NT12G2,
- 89HPES16NT16G2,
- 89HPES24NT24G2,
- 89HPES32NT24AG2,
- 89HPES32NT24BG2,
and a set of NTB client drivers to test each subsystem of the IDT NTB drivers separately.

The patches source code was tested on the hardware with IDT 89HPES32NT8AG2 PCIe-switch connected to root complexes running x64 big endian and x32 little endian CPUs. The code was warningless built by x86_64, MIPS64 BE and MIPS32 LE GNU GCC compilers.

To make it easely applicable to the Linux kernel NTB subsystem, the patches were taken from the top of the "ntb-next" branch of the forked NTB git repository:
https://github.com/fancer/ntb/tree/ntb-next
(it is the fork of https://github.com/jonmason/ntb/tree/ntb-next)
so the hash of the last preceding branch commit was:
04a819bbee3fa4dfe22034e2724dab4efb63f0bd

There are a some types of checkpatch warnings I left unfixed in the framework of the source code. Here is the reason why:

1) WARNING: Comparisons should place the constant on the right side of the test
Reason: The whole code is written for typos safety. Writing the constants on the left side of comparisons prevents the code from compiling if "=" and "==" are mistakenly confused.

2) WARNING: braces {} are not necessary for any arm of this statement
Reason: Even though the braces aren't really necessary, I left them in there to make the code better distinguishable from the rest of the code.

3) WARNING: Avoid crashing the kernel - try using WARN_ON & recovery code rather than BUG() or BUG_ON()
Reason: If the BUG()/BUG_ON() macro were invoked, something was really wrong, so the developer should make sure all the configurations are correct. Otherwise one should not use the driver.

4) WARNING: line over 80 characters
Reason: Most of these warnings appear due to just 3-5 excess characters, which can not be excluded without reducing the code readability. The exception is the registers tables, which are described in the item 8).

5) WARNING: Block comments use a trailing */ on a separate line
Reason: All of those warnings mean that the comment closure pattern"*/" is specified in the end of the last comment line. If one puts the pattern to a next line, comments visually get separated from the code they are made for. It reduces the readability.

6) WARNING: quoted string split across lines
Reason: There was no way to reduce string lengths, so the only way to split it across lines.

7) WARNING: do not add new typedefs
Reason: They are really needed there and added with full respect to the coding style document.

8) ERROR: Macros with multiple statements should be enclosed in a do - while loop
ERROR: Macros with complex values should be enclosed in parentheses
Reason: Those macros are used to create a very suitable registers table using "enum-switch-case-macro" design pattern with o(1) access to the register address, size and description. So adding the parentheses and do - while statements will break the pattern. Additionally they aren't used anywhere else, than in the framework of the pattern functions.

Of course all of these warnings are discussable, except the last one. It would be really painful to remove it from the code =)

As one can see I thoroughly annotated and commented the drivers source code, so it would be easier to study it by kernel hackers.

Here is what the current design of NTB-bus and IDT NTB function drivers lacks of:
1) No support of Punch-Through functionlity of IDT PCIe-switches
2) DMA is not supported by the current revision of IDT NTB driver
3) Theoretically local and peer root complexes can have different CPU architecture like x86 and x64. In this way, the dma_addr_t type will have different size, which may lead to errors when x64 RC allocates a shared buffer above 4GB memory.

One more suggestion. Since after adding this set of patches there will be two types of devices the NTB-bus supports, we may want to implement the traditional linux kernel bus device-drivers matching algorithm using some new struct ntb_device_id and id_tables.

Thanks,

=============================
Serge V. Semin
Leading Programmer
Embedded SW development group
T-platforms
=============================

fancer (3):
ntb: Add asynchronous devices support to NTB-bus interface
ntb: IDT 89HPES*NT* PCIe-switches NTB device driver
ntb: Test client drivers for asynchronous NTB devices

 drivers/ntb/Kconfig                    |    4 +-
 drivers/ntb/hw/Kconfig                 |    1 +
 drivers/ntb/hw/Makefile                |    6 +-
 drivers/ntb/hw/amd/ntb_hw_amd.c        |   49 +-
 drivers/ntb/hw/idt/Kconfig             |   21 +
 drivers/ntb/hw/idt/Makefile            |    5 +
 drivers/ntb/hw/idt/ntb_hw_idt.c        | 4050 ++++++++++++++++++++++++++++++++
 drivers/ntb/hw/idt/ntb_hw_idt.h        |  390 +++
 drivers/ntb/hw/idt/ntb_hw_idt_quirks.c |  163 ++
 drivers/ntb/hw/idt/ntb_hw_idt_quirks.h |  114 +
 drivers/ntb/hw/idt/ntb_hw_idt_regmap.h |  877 +++++++
 drivers/ntb/hw/intel/ntb_hw_intel.c    |   59 +-
 drivers/ntb/ntb.c                      |   86 +-
 drivers/ntb/ntb_transport.c            |   19 +-
 drivers/ntb/test/Kconfig               |   32 +
 drivers/ntb/test/Makefile              |    9 +-
 drivers/ntb/test/ntb_db_test.c         |  677 ++++++
 drivers/ntb/test/ntb_msg_test.c        |  736 ++++++
 drivers/ntb/test/ntb_mw_test.c         | 1531 ++++++++++++
 drivers/ntb/test/ntb_perf.c            |   16 +-
 drivers/ntb/test/ntb_pingpong.c        |    5 +
 drivers/ntb/test/ntb_tool.c            |   25 +-
 include/linux/ntb.h                    |  600 ++++-
 23 files changed, 9309 insertions(+), 166 deletions(-)
 create mode 100644 drivers/ntb/hw/idt/Kconfig
 create mode 100644 drivers/ntb/hw/idt/Makefile
 create mode 100644 drivers/ntb/hw/idt/ntb_hw_idt.c
 create mode 100644 drivers/ntb/hw/idt/ntb_hw_idt.h
 create mode 100644 drivers/ntb/hw/idt/ntb_hw_idt_quirks.c
 create mode 100644 drivers/ntb/hw/idt/ntb_hw_idt_quirks.h
 create mode 100644 drivers/ntb/hw/idt/ntb_hw_idt_regmap.h
 create mode 100644 drivers/ntb/test/ntb_db_test.c
 create mode 100644 drivers/ntb/test/ntb_msg_test.c
 create mode 100644 drivers/ntb/test/ntb_mw_test.c
Signature · 1 line
2.6.6
#1 lore raw

PATCH 1/3 ntb: Add asynchronous devices support to NTB-bus interface

Currently supported AMD and Intel Non-transparent PCIe-bridges are synchronous devices, so translated base address of memory windows can be direcly written to peer registers. But there are some IDT PCIe-switches which implement complex interfaces using Lookup Tables of translation addresses. Due to the way the table is accessed, it can not be done synchronously from different RCs, that's why the asynchronous interface should be developed.

For these purpose the Memory Window related interface is correspondingly split as it is for Doorbell and Scratchpad registers. The definition of Memory Window is following: "It is a virtual memory region, which locally reflects a physical memory of peer device." So to speak the "ntb_peer_mw_"-prefixed methods control the peers memory windows, "ntb_mw_"-prefixed functions work with the local memory windows.
Here is the description of the Memory Window related NTB-bus callback functions:
- ntb_mw_count() - number of local memory windows.
- ntb_mw_get_maprsc() - get the physical address and size of the local memory window to map.
- ntb_mw_set_trans() - set translation address of local memory window (this address should be somehow retrieved from a peer).
- ntb_mw_get_trans() - get translation address of local memory window.
- ntb_mw_get_align() - get alignment of translated base address and size of local memory window. Additionally one can get the upper size limit of the memory window.
- ntb_peer_mw_count() - number of peer memory windows (it can differ from the local number).
- ntb_peer_mw_set_trans() - set translation address of peer memory window
- ntb_peer_mw_get_trans() - get translation address of peer memory window
- ntb_peer_mw_get_align() - get alignment of translated base address and size of peer memory window.Additionally one can get the upper size limit of the memory window.

As one can see current AMD and Intel NTB drivers mostly implement the "ntb_peer_mw_"-prefixed methods. So this patch correspondingly renames the driver functions. IDT NTB driver mostly expose "ntb_nw_"-prefixed methods, since it doesn't have convenient access to the peer Lookup Table.

In order to pass information from one RC to another NTB functions of IDT PCIe-switch implement Messaging subsystem. They currently support four message registers to transfer DWORD sized data to a specified peer. So there are two new callback methods are introduced:
- ntb_msg_size() - get the number of DWORDs supported by NTB function to send and receive messages
- ntb_msg_post() - send message of size retrieved from ntb_msg_size() to a peer
Additionally there is a new event function:
- ntb_msg_event() - it is invoked when either a new message was retrieved (NTB_MSG_NEW), or last message was successfully sent (NTB_MSG_SENT), or the last message failed to be sent (NTB_MSG_FAIL).

The last change concerns the IDs (practically names) of NTB-devices on the NTB-bus. It is not good to have the devices with same names in the system and it brakes my IDT NTB driver from being loaded =) So I developed a simple algorithm of NTB devices naming. Particulary it generates names "ntbS{N}" for synchronous devices, "ntbA{N}" for asynchronous devices, and "ntbAS{N}" for devices supporting both interfaces.

---
 drivers/ntb/Kconfig                 |   4 +-
 drivers/ntb/hw/amd/ntb_hw_amd.c     |  49 ++-
 drivers/ntb/hw/intel/ntb_hw_intel.c |  59 +++-
 drivers/ntb/ntb.c                   |  86 +++++-
 drivers/ntb/ntb_transport.c         |  19 +-
 drivers/ntb/test/ntb_perf.c         |  16 +-
 drivers/ntb/test/ntb_pingpong.c     |   5 +
 drivers/ntb/test/ntb_tool.c         |  25 +-
 include/linux/ntb.h                 | 600 +++++++++++++++++++++++++++++-------
 9 files changed, 701 insertions(+), 162 deletions(-)
drivers/ntb/Kconfig +2 -2
index 95944e5..67d80c4 100644
@@ -14,8 +14,6 @@ if NTB
 
 source "drivers/ntb/hw/Kconfig"
 
-source "drivers/ntb/test/Kconfig"
-
 config NTB_TRANSPORT
 	tristate "NTB Transport Client"
 	help
@@ -25,4 +23,6 @@ config NTB_TRANSPORT
 
 	 If unsure, say N.
 
+source "drivers/ntb/test/Kconfig"
+
 endif # NTB
drivers/ntb/hw/amd/ntb_hw_amd.c +36 -13

78 lines not on this page · raw message

drivers/ntb/hw/intel/ntb_hw_intel.c +46 -13

82 lines not on this page · raw message

drivers/ntb/ntb.c +83 -3

135 lines not on this page · raw message

drivers/ntb/ntb_transport.c +14 -5
index d5c5894..2626ba0 100644
@@ -673,7 +673,7 @@ static void ntb_free_mw(struct ntb_transport_ctx *nt, int num_mw)
 	if (!mw->virt_addr)
 		return;
 
-	ntb_mw_clear_trans(nt->ndev, num_mw);
+	ntb_peer_mw_set_trans(nt->ndev, num_mw, 0, 0);
 	dma_free_coherent(&pdev->dev, mw->buff_size,
 			  mw->virt_addr, mw->dma_addr);
 	mw->xlat_size = 0;
@@ -730,7 +730,8 @@ static int ntb_set_mw(struct ntb_transport_ctx *nt, int num_mw,
 	}
 
 	/* Notify HW the memory location of the receive buffer */
-	rc = ntb_mw_set_trans(nt->ndev, num_mw, mw->dma_addr, mw->xlat_size);
+	rc = ntb_peer_mw_set_trans(nt->ndev, num_mw, mw->dma_addr,
+				   mw->xlat_size);
 	if (rc) {
 		dev_err(&pdev->dev, "Unable to set mw%d translation", num_mw);
 		ntb_free_mw(nt, num_mw);
@@ -1060,7 +1061,11 @@ static int ntb_transport_probe(struct ntb_client *self, struct ntb_dev *ndev)
 	int node;
 	int rc, i;
 
-	mw_count = ntb_mw_count(ndev);
+	/* Synchronous hardware is only supported */
+	if (!ntb_valid_sync_dev_ops(ndev))
+		return -EINVAL;
+
+	mw_count = ntb_peer_mw_count(ndev);
 	if (ntb_spad_count(ndev) < (NUM_MWS + 1 + mw_count * 2)) {
 		dev_err(&ndev->dev, "Not enough scratch pad registers for %s",
 			NTB_TRANSPORT_NAME);
@@ -1094,8 +1099,12 @@ static int ntb_transport_probe(struct ntb_client *self, struct ntb_dev *ndev)
 	for (i = 0; i < mw_count; i++) {
 		mw = &nt->mw_vec[i];
 
-		rc = ntb_mw_get_range(ndev, i, &mw->phys_addr, &mw->phys_size,
-				      &mw->xlat_align, &mw->xlat_align_size);
+		rc = ntb_mw_get_maprsc(ndev, i, &mw->phys_addr, &mw->phys_size);
+		if (rc)
+			goto err1;
+
+		rc = ntb_peer_mw_get_align(ndev, i, &mw->xlat_align,
+					   &mw->xlat_align_size, NULL);
 		if (rc)
 			goto err1;
 
drivers/ntb/test/ntb_perf.c +12 -4
index 6a50f20..f2952f7 100644
@@ -452,7 +452,7 @@ static void perf_free_mw(struct perf_ctx *perf)
 	if (!mw->virt_addr)
 		return;
 
-	ntb_mw_clear_trans(perf->ntb, 0);
+	ntb_peer_mw_set_trans(perf->ntb, 0, 0, 0);
 	dma_free_coherent(&pdev->dev, mw->buf_size,
 			  mw->virt_addr, mw->dma_addr);
 	mw->xlat_size = 0;
@@ -488,7 +488,7 @@ static int perf_set_mw(struct perf_ctx *perf, resource_size_t size)
 		mw->buf_size = 0;
 	}
 
-	rc = ntb_mw_set_trans(perf->ntb, 0, mw->dma_addr, mw->xlat_size);
+	rc = ntb_peer_mw_set_trans(perf->ntb, 0, mw->dma_addr, mw->xlat_size);
 	if (rc) {
 		dev_err(&perf->ntb->dev, "Unable to set mw0 translation\n");
 		perf_free_mw(perf);
@@ -559,8 +559,12 @@ static int perf_setup_mw(struct ntb_dev *ntb, struct perf_ctx *perf)
 
 	mw = &perf->mw;
 
-	rc = ntb_mw_get_range(ntb, 0, &mw->phys_addr, &mw->phys_size,
-			      &mw->xlat_align, &mw->xlat_align_size);
+	rc = ntb_mw_get_maprsc(ntb, 0, &mw->phys_addr, &mw->phys_size);
+	if (rc)
+		return rc;
+
+	rc = ntb_peer_mw_get_align(ntb, 0, &mw->xlat_align,
+				   &mw->xlat_align_size, NULL);
 	if (rc)
 		return rc;
 
@@ -758,6 +762,10 @@ static int perf_probe(struct ntb_client *client, struct ntb_dev *ntb)
 	int node;
 	int rc = 0;
 
+	/* Synchronous hardware is only supported */
+	if (!ntb_valid_sync_dev_ops(ntb))
+		return -EINVAL;
+
 	if (ntb_spad_count(ntb) < MAX_SPAD) {
 		dev_err(&ntb->dev, "Not enough scratch pad registers for %s",
 			DRIVER_NAME);
drivers/ntb/test/ntb_pingpong.c +5 -0
index 7d31179..e833649 100644
@@ -214,6 +214,11 @@ static int pp_probe(struct ntb_client *client,
 	struct pp_ctx *pp;
 	int rc;
 
+	/* Synchronous hardware is only supported */
+	if (!ntb_valid_sync_dev_ops(ntb)) {
+		return -EINVAL;
+	}
+
 	if (ntb_db_is_unsafe(ntb)) {
 		dev_dbg(&ntb->dev, "doorbell is unsafe\n");
 		if (!unsafe) {
drivers/ntb/test/ntb_tool.c +16 -9
index 61bf2ef..5dfe12f 100644
@@ -675,8 +675,11 @@ static int tool_setup_mw(struct tool_ctx *tc, int idx, size_t req_size)
 	if (mw->peer)
 		return 0;
 
-	rc = ntb_mw_get_range(tc->ntb, idx, &base, &size, &align,
-			      &align_size);
+	rc = ntb_mw_get_maprsc(tc->ntb, idx, &base, &size);
+	if (rc)
+		return rc;
+
+	rc = ntb_peer_mw_get_align(tc->ntb, idx, &align, &align_size, NULL);
 	if (rc)
 		return rc;
 
@@ -689,7 +692,7 @@ static int tool_setup_mw(struct tool_ctx *tc, int idx, size_t req_size)
 	if (!mw->peer)
 		return -ENOMEM;
 
-	rc = ntb_mw_set_trans(tc->ntb, idx, mw->peer_dma, mw->size);
+	rc = ntb_peer_mw_set_trans(tc->ntb, idx, mw->peer_dma, mw->size);
 	if (rc)
 		goto err_free_dma;
 
@@ -716,7 +719,7 @@ static void tool_free_mw(struct tool_ctx *tc, int idx)
 	struct tool_mw *mw = &tc->mws[idx];
 
 	if (mw->peer) {
-		ntb_mw_clear_trans(tc->ntb, idx);
+		ntb_peer_mw_set_trans(tc->ntb, idx, 0, 0);
 		dma_free_coherent(&tc->ntb->pdev->dev, mw->size,
 				  mw->peer,
 				  mw->peer_dma);
@@ -751,8 +754,8 @@ static ssize_t tool_peer_mw_trans_read(struct file *filep,
 	if (!buf)
 		return -ENOMEM;
 
-	ntb_mw_get_range(mw->tc->ntb, mw->idx,
-			 &base, &mw_size, &align, &align_size);
+	ntb_mw_get_maprsc(mw->tc->ntb, mw->idx, &base, &mw_size);
+	ntb_peer_mw_get_align(mw->tc->ntb, mw->idx, &align, &align_size, NULL);
 
 	off += scnprintf(buf + off, buf_size - off,
 			 "Peer MW %d Information:\n", mw->idx);
@@ -827,8 +830,7 @@ static int tool_init_mw(struct tool_ctx *tc, int idx)
 	phys_addr_t base;
 	int rc;
 
-	rc = ntb_mw_get_range(tc->ntb, idx, &base, &mw->win_size,
-			      NULL, NULL);
+	rc = ntb_mw_get_maprsc(tc->ntb, idx, &base, &mw->win_size);
 	if (rc)
 		return rc;
 
@@ -913,6 +915,11 @@ static int tool_probe(struct ntb_client *self, struct ntb_dev *ntb)
 	int rc;
 	int i;
 
+	/* Synchronous hardware is only supported */
+	if (!ntb_valid_sync_dev_ops(ntb)) {
+		return -EINVAL;
+	}
+
 	if (ntb_db_is_unsafe(ntb))
 		dev_dbg(&ntb->dev, "doorbell is unsafe\n");
 
@@ -928,7 +935,7 @@ static int tool_probe(struct ntb_client *self, struct ntb_dev *ntb)
 	tc->ntb = ntb;
 	init_waitqueue_head(&tc->link_wq);
 
-	tc->mw_count = min(ntb_mw_count(tc->ntb), MAX_MWS);
+	tc->mw_count = min(ntb_peer_mw_count(tc->ntb), MAX_MWS);
 	for (i = 0; i < tc->mw_count; i++) {
 		rc = tool_init_mw(tc, i);
 		if (rc)
include/linux/ntb.h +487 -113

807 lines not on this page · raw message

Signature · 1 line
2.6.6
#2 lore raw

PATCH 2/3 ntb: IDT 89HPES*NT* PCIe-switches NTB device driver

In reply to Serge Semin

IDT 89HPES*NT* PCIe-switches are the multi-port switches, which can be configured to have more than two NT-functions, connected to each other. Using these facility NT-function of local RC can access any NT-functions of others. This driver implements Port-to-Ports architecture, so only Primary port can have access to prededefined number of Secondary ports. Secondary ports on the other hand can access the primary port memory only. The ports hierarchy is configured using NTSDATA register of each NT-function, which should be preinitialized with corresponding Primary port ID. Then driver will evenly split the IDT PCIe-switch Doorbell and Memory Window resources between all of the NT-function pairs, and add the corresponding devices to the NTB bus. The NTSDATA register preinitialization can be done either by EEPROM or by linux kernel PCI fixup interface. The default value is zero, so the port 0 is considered being primary, the others are secondary.

The supported IDT PCIe-switches do not implement synchronous interface to access Memory Windows configuration registers. There is no way to exclusively access a peer translated base addresses Lookup Table. Instead the messaging subsystem can be used to post the translated base address to a peer, so one could properly initialize the table. In order to resolve the race conditions of possible concurrent messages transfer by parallel tasks and different root complexes, the ntb_msg_post() method places messages into the outbound messages queue. An extra kernel work thread is used to perform an actual message transfer with a constant frequency of attempts. If kernel thread fails to send a message after a constant number of tries, then the corresponding client driver is notified by rising the ntb_msg_event() method with NTB_MSG_FAIL status. Additionaly there is a special tasklet, which reads messages from incoming message registers and puts them into the inbound messages queue. An another kernel thread is then started to deliver a message to a corresponding client driver.

There are only 32 Global doorbell bits, which can be routed between any two NT-functions. So the driver evenly distributes doorbell bits between all the NT-function pairs. Of course it is not always possible being equally done, so depending on the NT Primary/Secondary topology, one pair can have greater number of Doorbell bits than another. The difference cannot exceed for more than one bit.

IDT 89HPES*NT* PCIe-switches don't have Scrathpad registers, so the corresponding callback methods are unsupported.

There are three DebugFS nodes, which can be used to debug the driver:
1. /sys/kernel/debug/ntb_hw_idt/ntbA{N}/info - contain a general information about the local IDT NTB driver and NT-function, like port, partition, role (primary or secondary) and number of connected peers, a link status, of all the locally available pairs, global and local doorbell registers status, doorbells mapping, NTB mapping table, chip teperature and many others.
2. /sys/kernel/debug/ntb_hw_idt/ntbA{N}/ntregs - debug file to print the state of local NT-function registers. Thanks to the "enum-switch-case-macro" pattern it can be easily done just by one loop.
3. /sys/kernel/debug/ntb_hw_idt/ntbA{N}/swregs - debug file to print the state of PCIe-swtich global registers.

The detailed description of the driver design and source code navigation can be found in the header of drivers/ntb/hw/idt/ntb_hw_idt.c file.

NOTE IDT 89HPES12NT3 PCIe-switch is not supported by this driver, since it has synchronous interface.

---
 drivers/ntb/hw/Kconfig                 |    1 +
 drivers/ntb/hw/Makefile                |    6 +-
 drivers/ntb/hw/idt/Kconfig             |   21 +
 drivers/ntb/hw/idt/Makefile            |    5 +
 drivers/ntb/hw/idt/ntb_hw_idt.c        | 4050 ++++++++++++++++++++++++++++++++
 drivers/ntb/hw/idt/ntb_hw_idt.h        |  390 +++
 drivers/ntb/hw/idt/ntb_hw_idt_quirks.c |  163 ++
 drivers/ntb/hw/idt/ntb_hw_idt_quirks.h |  114 +
 drivers/ntb/hw/idt/ntb_hw_idt_regmap.h |  877 +++++++
 9 files changed, 5625 insertions(+), 2 deletions(-)
 create mode 100644 drivers/ntb/hw/idt/Kconfig
 create mode 100644 drivers/ntb/hw/idt/Makefile
 create mode 100644 drivers/ntb/hw/idt/ntb_hw_idt.c
 create mode 100644 drivers/ntb/hw/idt/ntb_hw_idt.h
 create mode 100644 drivers/ntb/hw/idt/ntb_hw_idt_quirks.c
 create mode 100644 drivers/ntb/hw/idt/ntb_hw_idt_quirks.h
 create mode 100644 drivers/ntb/hw/idt/ntb_hw_idt_regmap.h
drivers/ntb/hw/Kconfig +1 -0
index 7116472..a89243c 100644
@@ -1,2 +1,3 @@
 source "drivers/ntb/hw/amd/Kconfig"
+source "drivers/ntb/hw/idt/Kconfig"
 source "drivers/ntb/hw/intel/Kconfig"
drivers/ntb/hw/Makefile +4 -2
index 532e085..5d438ea 100644
@@ -1,2 +1,4 @@
-obj-$(CONFIG_NTB_AMD)	+= amd/
-obj-$(CONFIG_NTB_INTEL)	+= intel/
+obj-$(CONFIG_NTB_AMD)		+= amd/
+obj-$(CONFIG_NTB_IDT)		+= idt/
+obj-$(CONFIG_NTB_IDT_QUIRKS)	+= idt/
+obj-$(CONFIG_NTB_INTEL)		+= intel/
drivers/ntb/hw/idt/Kconfig new file +21 -0
new file mode 100644
index 0000000..45b2b01
@@ -0,0 +1,21 @@
+config NTB_IDT
+	tristate "IDT PCIe-switch Non-Transparent Bridge support"
+	depends on PCI
+	help
+	 This driver supports NTB of cappable IDT PCIe-switches.
+
+	 If unsure, say N.
+
+# BAR's early enable quirks
+config NTB_IDT_QUIRKS
+	bool "Enable PCI fixups built-in kernel for IDT PCIe-switch"
+	depends on NTB_IDT
+	default y if NTB_IDT=y
+	select PCI_QUIRKS # NTB_IDT depends on PCI so it's ok to force quirks
+	help
+	 There are some configurations of IDT PCIe-switch which must be made
+	 before the kernel PCI subsystem starts bus-devices scan and
+	 initialization. For instance, the corresponding NT-function BARs must
+	 be enabled. This option builds the fixups into the kernel to bypass
+	 the basic IDT quirks.
+
drivers/ntb/hw/idt/Makefile new file +5 -0
new file mode 100644
index 0000000..3adcd9b
@@ -0,0 +1,5 @@
+# Driver core
+obj-$(CONFIG_NTB_IDT)		+= ntb_hw_idt.o
+
+# BAR's early activation quirk
+obj-$(CONFIG_NTB_IDT_QUIRKS)	+= ntb_hw_idt_quirks.o
drivers/ntb/hw/idt/ntb_hw_idt.c new file +4050 -0

2,965 lines not on this page · raw message

drivers/ntb/hw/idt/ntb_hw_idt.h new file +390 -0

390 lines not on this page · raw message

drivers/ntb/hw/idt/ntb_hw_idt_quirks.c new file +163 -0

163 lines not on this page · raw message

drivers/ntb/hw/idt/ntb_hw_idt_quirks.h new file +114 -0

114 lines not on this page · raw message

drivers/ntb/hw/idt/ntb_hw_idt_regmap.h new file +877 -0

877 lines not on this page · raw message

The rest of this diff is not shown. View the raw message.

Signature · 1 line
2.6.6

Part of the diff is not shown here. View the raw message.

#3 lore raw

Re: [PATCH 2/3] ntb: IDT 89HPES*NT* PCIe-switches NTB device driver

reproduce: wget https://git.kernel.org/cgit/linux/kernel/git/wfg/lkp-tests.git/plain/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross # save the attached .config to linux build tree…

Hi,

[auto build test WARNING on ntb/ntb-next]
[cannot apply to v4.7 next-20160727]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url:    https://github.com/0day-ci/linux/commits/Serge-Semin/ntb-Asynchronous-NTB-devices-support/20160727-082033
base:   https://github.com/jonmason/ntb ntb-next
config: sparc64-allmodconfig (attached as .config)
compiler: sparc64-linux-gnu-gcc (Debian 5.4.0-6) 5.4.0 20160609

reproduce:
wget https://git.kernel.org/cgit/linux/kernel/git/wfg/lkp-tests.git/plain/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
make.cross ARCH=sparc64

All warnings (new ones prefixed by >>):

drivers/ntb/hw/idt/ntb_hw_idt.c: In function 'idt_ntb_setmw':

>> drivers/ntb/hw/idt/ntb_hw_idt.c:1170:56: warning: right shift count >= width of type [-Wshift-count-overflow]
     idt_ntb_writereg(cfg, IDT_NT_PCI_LUTMDATA, (u32)(addr >> 32));
                                                           ^

vim +1170 drivers/ntb/hw/idt/ntb_hw_idt.c

1154
1155 /* Collect the Lookup table offset */
1156 idt_ntb_writefld_var(&lut_indxbar, IDT_NT_LUT_INDEX,
1157 ndev->mw_self_offset + mwindx);
1158 idt_ntb_writefld_var(&lut_indxbar, IDT_NT_LUT_BAR, BAR2);
1159
1160 /* Collect the Lookup table entry partition and valid bits */
1161 idt_ntb_writefld_var(&lut_partval, IDT_NT_LUT_PART, ndev->part);
1162 idt_ntb_writefld_var(&lut_partval, IDT_NT_LUT_VALID, ON);
1163
1164 /* Start critical section writing to the local port Lookup table */
1165 spin_lock_irqsave(&pdata->lut_lock, irqflags);
1166 /* Write the data to the Lookup table registers of the peer */
1167 idt_ntb_writereg(cfg, IDT_NT_PCI_LUTOFFSET, lut_indxbar);
1168 idt_ntb_writereg(cfg, IDT_NT_PCI_LUTLDATA, (u32)addr);
1169 #ifdef CONFIG_64BIT

> 1170		idt_ntb_writereg(cfg, IDT_NT_PCI_LUTMDATA, (u32)(addr >> 32));

1171 #else
1172 idt_ntb_writereg(cfg, IDT_NT_PCI_LUTMDATA, (u32)0);
1173 #endif /* !CONFIG_64BIT */
1174 idt_ntb_writereg(cfg, IDT_NT_PCI_LUTUDATA, lut_partval);
1175 /* Finally unlock the Lookup table */
1176 spin_unlock_irqrestore(&pdata->lut_lock, irqflags);
1177
1178 return SUCCESS;

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation

#4 lore raw

PATCH 3/3 ntb: Test client drivers for asynchronous NTB devices

In reply to Serge Semin

There are three drivers to independently test all interfaces implemented by the IDT 89HPES*NT* NTB driver.

Doorbells are tested by new NTB Doorbell Pingpong client driver. It implements the so-named algorithm. Driver starts working from setting the peer doorbell of the last locally set doorbell bit. If there has not been locally set doorbell, it sets the very first bit. After that the driver unmasks the events of the just set doorbell bit and waits until the peer sets the same doorbell. When peer does it, the local driver iterates to the next doorbell bit and starts delayed work thread, which will set the corresponding bit and perform doorbell bit umasking on waking up.

Messaging subsystem can be tested by the client driver implementing a simple transmition/reception algorithm. A message can be send to a peer by writing data to /sys/kernel/debug/ntb_msg_test/ntbA{N}/data file. The peer can read it from the same file then.

Memory Windows test driver implements a simple write/read algorithm. The driver allocates the predefined number of local buffers (inbound memory window - inwndw{N}). In order to get a translated base address driver sends a corresponding command to a peer. Then driver initialize the outbound memory windows (outwndw{N}). The read/write operations can be performed using the following debug nodes:
/sys/kernel/debug/ntb_mw_test/ntbA{N}/inwndw{N} /sys/kernel/debug/ntb_mw_test/ntbA{N}/outwndw{N}

---
 drivers/ntb/test/Kconfig        |   32 +
 drivers/ntb/test/Makefile       |    9 +-
 drivers/ntb/test/ntb_db_test.c  |  677 +++++++++++++++++
 drivers/ntb/test/ntb_msg_test.c |  736 +++++++++++++++++++
 drivers/ntb/test/ntb_mw_test.c  | 1531 +++++++++++++++++++++++++++++++++++++++
 5 files changed, 2983 insertions(+), 2 deletions(-)
 create mode 100644 drivers/ntb/test/ntb_db_test.c
 create mode 100644 drivers/ntb/test/ntb_msg_test.c
 create mode 100644 drivers/ntb/test/ntb_mw_test.c
drivers/ntb/test/Kconfig +32 -0
index a5d0eda..80f5058 100644
@@ -25,3 +25,35 @@ config NTB_PERF
 	 to and from the window without additional software interaction.
 
 	 If unsure, say N.
+
+config NTB_DB_TEST
+	tristate "NTB Doorbell Test Client"
+	help
+	 This is a driver to test doorbell subsystem of NTB bus devices.
+	 The design is similar to the ping pong although it exchanges the
+	 doorbell bits one-by-one, waiting for the peer response before getting
+	 to a next doorbell.
+
+	 If unsure, say N.
+
+config NTB_MSG_TEST
+	tristate "NTB Messaging Test Client"
+	help
+	 This is a driver to test messaging subsystem of NTB. It just creates
+	 one file in the DebugFS for each NTB device of asynchronous
+	 architecture. In order to send a message one can just write a text to
+	 the file. It will be immediately sent to the peer so user can get it
+	 by reading from the corresponding file.
+
+	 If unsure, say N.
+
+config NTB_MW_TEST
+	tristate "NTB Memory Windows Test Client"
+	help
+	 This is a driver to test memory sharing amongst devices. It creates a
+	 set of files in the DebugFS, one of which are used to write a text to
+	 outbound memory windows and anothers can be used to read data written
+	 by the peer to our inbound memory window.
+
+	 If unsure, say N.
+
drivers/ntb/test/Makefile +7 -2
index 9e77e0b..6ea6db4 100644
@@ -1,3 +1,8 @@
+# Synchronous hardware clients (Intel/AMD)
 obj-$(CONFIG_NTB_PINGPONG) += ntb_pingpong.o
-obj-$(CONFIG_NTB_TOOL) += ntb_tool.o
-obj-$(CONFIG_NTB_PERF) += ntb_perf.o
+obj-$(CONFIG_NTB_TOOL)     += ntb_tool.o
+obj-$(CONFIG_NTB_PERF)     += ntb_perf.o
+# Asynchronous hardware clients (IDT)
+obj-$(CONFIG_NTB_DB_TEST)  += ntb_db_test.o
+obj-$(CONFIG_NTB_MSG_TEST) += ntb_msg_test.o
+obj-$(CONFIG_NTB_MW_TEST)  += ntb_mw_test.o
drivers/ntb/test/ntb_db_test.c new file +677 -0

677 lines not on this page · raw message

drivers/ntb/test/ntb_msg_test.c new file +736 -0

736 lines not on this page · raw message

drivers/ntb/test/ntb_mw_test.c new file +1531 -0

1,531 lines not on this page · raw message

Signature · 1 line
2.6.6
#5 lore raw

Re: [PATCH 3/3] ntb: Test client drivers for asynchronous NTB devices

reproduce: wget https://git.kernel.org/cgit/linux/kernel/git/wfg/lkp-tests.git/plain/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross # save the attached .config to linux build tree…

Hi,

[auto build test WARNING on ntb/ntb-next]
[cannot apply to v4.7 next-20160728]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url:    https://github.com/0day-ci/linux/commits/Serge-Semin/ntb-Asynchronous-NTB-devices-support/20160727-082033
base:   https://github.com/jonmason/ntb ntb-next
config: sparc64-allyesconfig (attached as .config)
compiler: sparc64-linux-gnu-gcc (Debian 5.4.0-6) 5.4.0 20160609

reproduce:
wget https://git.kernel.org/cgit/linux/kernel/git/wfg/lkp-tests.git/plain/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
make.cross ARCH=sparc64

All warnings (new ones prefixed by >>):

In file included from include/linux/swab.h:4:0,

                    from include/uapi/linux/byteorder/big_endian.h:12,
                    from include/linux/byteorder/big_endian.h:4,
                    from arch/sparc/include/uapi/asm/byteorder.h:4,
                    from arch/sparc/include/asm/bitops_64.h:15,
                    from arch/sparc/include/asm/bitops.h:4,
                    from include/linux/bitops.h:36,
                    from include/linux/kernel.h:10,
                    from drivers/ntb/test/ntb_mw_test.c:57:
   drivers/ntb/test/ntb_mw_test.c: In function 'mw_send_inmw_addrs':
>> drivers/ntb/test/ntb_mw_test.c:353:49: warning: right shift count >= width of type [-Wshift-count-overflow]
      msg.payload[1] = to_sh32((u32)(inmw->dma_addr >> 32));
                                                    ^
   include/uapi/linux/swab.h:116:32: note: in definition of macro '__swab32'
     (__builtin_constant_p((__u32)(x)) ? \
                                   ^
   include/linux/byteorder/generic.h:87:21: note: in expansion of macro '__cpu_to_le32'
    #define cpu_to_le32 __cpu_to_le32
                        ^
>> drivers/ntb/test/ntb_mw_test.c:353:20: note: in expansion of macro 'to_sh32'
      msg.payload[1] = to_sh32((u32)(inmw->dma_addr >> 32));
                       ^
>> drivers/ntb/test/ntb_mw_test.c:353:49: warning: right shift count >= width of type [-Wshift-count-overflow]
      msg.payload[1] = to_sh32((u32)(inmw->dma_addr >> 32));
                                                    ^
   include/uapi/linux/swab.h:17:12: note: in definition of macro '___constant_swab32'
     (((__u32)(x) & (__u32)0x000000ffUL) << 24) |  \
               ^
   include/uapi/linux/byteorder/big_endian.h:32:43: note: in expansion of macro '__swab32'
    #define __cpu_to_le32(x) ((__force __le32)__swab32((x)))
                                              ^
   include/linux/byteorder/generic.h:87:21: note: in expansion of macro '__cpu_to_le32'
    #define cpu_to_le32 __cpu_to_le32
                        ^
>> drivers/ntb/test/ntb_mw_test.c:353:20: note: in expansion of macro 'to_sh32'
      msg.payload[1] = to_sh32((u32)(inmw->dma_addr >> 32));
                       ^
>> drivers/ntb/test/ntb_mw_test.c:353:49: warning: right shift count >= width of type [-Wshift-count-overflow]
      msg.payload[1] = to_sh32((u32)(inmw->dma_addr >> 32));
                                                    ^
   include/uapi/linux/swab.h:18:12: note: in definition of macro '___constant_swab32'
     (((__u32)(x) & (__u32)0x0000ff00UL) <<  8) |  \
               ^
   include/uapi/linux/byteorder/big_endian.h:32:43: note: in expansion of macro '__swab32'
    #define __cpu_to_le32(x) ((__force __le32)__swab32((x)))
                                              ^
   include/linux/byteorder/generic.h:87:21: note: in expansion of macro '__cpu_to_le32'
    #define cpu_to_le32 __cpu_to_le32
                        ^
>> drivers/ntb/test/ntb_mw_test.c:353:20: note: in expansion of macro 'to_sh32'
      msg.payload[1] = to_sh32((u32)(inmw->dma_addr >> 32));
                       ^
>> drivers/ntb/test/ntb_mw_test.c:353:49: warning: right shift count >= width of type [-Wshift-count-overflow]
      msg.payload[1] = to_sh32((u32)(inmw->dma_addr >> 32));
                                                    ^
   include/uapi/linux/swab.h:19:12: note: in definition of macro '___constant_swab32'
     (((__u32)(x) & (__u32)0x00ff0000UL) >>  8) |  \
               ^
   include/uapi/linux/byteorder/big_endian.h:32:43: note: in expansion of macro '__swab32'
    #define __cpu_to_le32(x) ((__force __le32)__swab32((x)))
                                              ^
   include/linux/byteorder/generic.h:87:21: note: in expansion of macro '__cpu_to_le32'
    #define cpu_to_le32 __cpu_to_le32
                        ^
>> drivers/ntb/test/ntb_mw_test.c:353:20: note: in expansion of macro 'to_sh32'
      msg.payload[1] = to_sh32((u32)(inmw->dma_addr >> 32));
                       ^
>> drivers/ntb/test/ntb_mw_test.c:353:49: warning: right shift count >= width of type [-Wshift-count-overflow]
      msg.payload[1] = to_sh32((u32)(inmw->dma_addr >> 32));
                                                    ^
   include/uapi/linux/swab.h:20:12: note: in definition of macro '___constant_swab32'
     (((__u32)(x) & (__u32)0xff000000UL) >> 24)))
               ^
   include/uapi/linux/byteorder/big_endian.h:32:43: note: in expansion of macro '__swab32'
    #define __cpu_to_le32(x) ((__force __le32)__swab32((x)))
                                              ^
   include/linux/byteorder/generic.h:87:21: note: in expansion of macro '__cpu_to_le32'
    #define cpu_to_le32 __cpu_to_le32
                        ^
>> drivers/ntb/test/ntb_mw_test.c:353:20: note: in expansion of macro 'to_sh32'
      msg.payload[1] = to_sh32((u32)(inmw->dma_addr >> 32));
                       ^
>> drivers/ntb/test/ntb_mw_test.c:353:49: warning: right shift count >= width of type [-Wshift-count-overflow]
      msg.payload[1] = to_sh32((u32)(inmw->dma_addr >> 32));
                                                    ^
   include/uapi/linux/swab.h:118:12: note: in definition of macro '__swab32'
     __fswab32(x))
               ^
   include/linux/byteorder/generic.h:87:21: note: in expansion of macro '__cpu_to_le32'
    #define cpu_to_le32 __cpu_to_le32
                        ^
>> drivers/ntb/test/ntb_mw_test.c:353:20: note: in expansion of macro 'to_sh32'
      msg.payload[1] = to_sh32((u32)(inmw->dma_addr >> 32));
                       ^
   drivers/ntb/test/ntb_mw_test.c: In function 'mw_set_outmw_addr':
>> drivers/ntb/test/ntb_mw_test.c:407:61: warning: left shift count >= width of type [-Wshift-count-overflow]
     outmw->dma_addr |= ((dma_addr_t)from_sh32(msg->payload[1]) << 32);
                                                                ^
>> drivers/ntb/test/ntb_mw_test.c:413:23: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
       "within %u bytes", (void *)outmw->dma_addr,
                          ^
   drivers/ntb/test/ntb_mw_test.c:189:29: note: in definition of macro 'dev_err_mw'
     dev_err(&ctx->ntb->dev, ## args)
                                ^
   drivers/ntb/test/ntb_mw_test.c:422:33: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
       "outbound memory window %d", (void *)outmw->dma_addr,
                                    ^
   drivers/ntb/test/ntb_mw_test.c:189:29: note: in definition of macro 'dev_err_mw'
     dev_err(&ctx->ntb->dev, ## args)
                                ^
   In file included from include/linux/printk.h:289:0,
                    from include/linux/kernel.h:13,
                    from drivers/ntb/test/ntb_mw_test.c:57:
   drivers/ntb/test/ntb_mw_test.c:431:27: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
      "address 0x%p", mwindx, (void *)outmw->dma_addr);
                              ^
   include/linux/dynamic_debug.h:87:9: note: in definition of macro 'dynamic_dev_dbg'
          ##__VA_ARGS__);  \
            ^
>> drivers/ntb/test/ntb_mw_test.c:195:2: note: in expansion of macro 'dev_dbg'
     dev_dbg(&ctx->ntb->dev, ## args)
     ^
>> drivers/ntb/test/ntb_mw_test.c:430:2: note: in expansion of macro 'dev_dbg_mw'
     dev_dbg_mw(ctx, "Outbound memory window %d is initialized with "
     ^
   drivers/ntb/test/ntb_mw_test.c: In function 'mw_dbgfs_outmw_cfg_read':
   drivers/ntb/test/ntb_mw_test.c:766:30: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
      "DMA address\t\t- 0x%p\n", (void *)wrap->dma_addr);
                                 ^
   drivers/ntb/test/ntb_mw_test.c: In function 'mw_dbgfs_inmw_cfg_read':
   drivers/ntb/test/ntb_mw_test.c:915:30: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
      "DMA address\t\t- 0x%p\n", (void *)wrap->dma_addr);
                                 ^
   drivers/ntb/test/ntb_mw_test.c: In function 'mw_create_inmws':
   drivers/ntb/test/ntb_mw_test.c:1197:25: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
        "aligned with %lu", (void *)inmw->dma_addr, mwindx,
                            ^
   drivers/ntb/test/ntb_mw_test.c:189:29: note: in definition of macro 'dev_err_mw'
     dev_err(&ctx->ntb->dev, ## args)
                                ^

vim +353 drivers/ntb/test/ntb_mw_test.c

189 dev_err(&ctx->ntb->dev, ## args)
190 #define dev_warn_mw(ctx, args...) \
191 dev_warn(&ctx->ntb->dev, ## args)
192 #define dev_info_mw(ctx, args...) \
193 dev_info(&ctx->ntb->dev, ## args)
194 #define dev_dbg_mw(ctx, args...) \

 > 195		dev_dbg(&ctx->ntb->dev, ## args)
   196	
   197	/*
   198	 * Some common constant used in the driver for better readability:
   199	 * @ON: Enable something
   200	 * @OFF: Disable something
   201	 * @SUCCESS: Success of a function execution
   202	 * @MIN_MW_CNT:	Minimum memory windows count
   203	 * @MAX_MW_CNT: Maximum memory windows count
   204	 */
   205	#define ON ((u32)0x1)
   206	#define OFF ((u32)0x0)
   207	#define SUCCESS 0
   208	#define MIN_MW_CNT ((unsigned char)1)
   209	#define MAX_MW_CNT ((unsigned char)255)
   210	
   211	/*
   212	 * Shared data converter to support the different CPU architectures
   213	 */
   214	#define to_sh32(data) \
   215		cpu_to_le32((data))
   216	#define from_sh32(data) \
   217		le32_to_cpu((data))
   218	
   219	/*
   220	 * Module parameters:
   221	 * @inmw_cnt:	Number of inbound memory windows [1; 255]
   222	 * @outmw_cnt:	Number of outbound memory windows [1; 255]
   223	 * If the specified value exceeds the maximum possible valiue, then it is
   224	 * initialized with maximum one
   225	 */
   226	static unsigned char inmws_cnt = MAX_MW_CNT;
   227	module_param(inmws_cnt, byte, 0000);
   228	MODULE_PARM_DESC(inmws_cnt,
   229		"Inbound memory windows count. Those are the memory windows, which are "
   230		"locally allocated. Their address is sent to the remote host."
   231		" - Parameter can be set within [1; 255], where 255 means maximum possible"
   232		"   number of windows");
   233	
   234	/*===========================================================================
   235	 *                               Helper methods
   236	 *===========================================================================*/
   237	
   238	/*
   239	 * Alter the passed driver paremeters
   240	 */
   241	static void mw_alter_params(struct mw_ctx *ctx)
   242	{
   243		unsigned char inmws_cnt_bak = ctx->inmws_cnt;
   244	
   245		/* Clamp the inbound memory windows parameter */
   246		ctx->inmws_cnt = clamp(inmws_cnt,
   247			MIN_MW_CNT, (unsigned char)ctx->inmws_cnt);
   248		if (inmws_cnt_bak != ctx->inmws_cnt) {
   249			dev_warn_mw(ctx,
   250				"Inbound memory windows count is altered from "
   251				"%hhu to %hhu", inmws_cnt_bak, ctx->inmws_cnt);
   252		}
   253	
   254		dev_dbg_mw(ctx, "Memory windows test driver parameter is verified");
   255	}
   256	
   257	/*
   258	 * Memory block IO write method
   259	 */
   260	static void iomem_write(void __iomem *dst, const void *src, size_t cnt)
   261	{
   262		while (cnt--) {
   263			iowrite8(*(u8 *)src, dst);
   264			dst++;
   265			src++;
   266		}
   267	}
   268	
   269	/*
   270	 * Memory block IO read method
   271	 */
   272	static void iomem_read(void __iomem *src, void *dst, size_t cnt)
   273	{
   274		while (cnt--) {
   275			*(u8 *)dst = ioread8(src);
   276			dst++;
   277			src++;
   278		}
   279	}
   280	
   281	/*===========================================================================
   282	 *                          Message command handlers
   283	 *===========================================================================*/
   284	
   285	/*
   286	 * Send MW_GETADDRS command method
   287	 */
   288	static void mw_send_getaddrs_cmd(struct mw_ctx *ctx)
   289	{
   290		struct ntb_msg msg;
   291		int sts;
   292	
   293		/* Clear the message structure */
   294		memset(&msg, 0, sizeof(msg));
   295	
   296		/* Set the message type only */
   297		msg.type = to_sh32(MW_GETADDRS);
   298	
   299		/* Send the message */
   300		sts = ntb_msg_post(ctx->ntb, &msg);
   301		if (SUCCESS != sts) {
   302			dev_err_mw(ctx, "Failed to send message to get outbound window "
   303				"addresses");
   304		}
   305	}
   306	
   307	/*
   308	 * Send MW_FREEADDRS command method
   309	 */
   310	static void mw_send_freeaddrs_cmd(struct mw_ctx *ctx)
   311	{
   312		struct ntb_msg msg;
   313		int sts;
   314	
   315		/* Clear the message structure */
   316		memset(&msg, 0, sizeof(msg));
   317	
   318		/* Set the message type only */
   319		msg.type = to_sh32(MW_FREEADDRS);
   320	
   321		/* Send the message */
   322		sts = ntb_msg_post(ctx->ntb, &msg);
   323		if (SUCCESS != sts) {
   324			dev_err_mw(ctx, "Failed to send a message to disable the peer "
   325				"outbound windows");
   326		}
   327	}
   328	
   329	/*
   330	 * Callback method for response on the command MW_GETADDRS
   331	 */
   332	static void mw_send_inmw_addrs(struct mw_ctx *ctx)
   333	{
   334		struct ntb_msg msg;
   335		struct inmw_wrap *inmw;
   336		int mwindx, sts;
   337	
   338		/* Clear the message structure */
   339		memset(&msg, 0, sizeof(msg));
   340	
   341		/* Walk through all the inbound memory windows and send the
   342		 * corresponding DMA address of the window */
   343		for (mwindx = 0; mwindx < ctx->inmws_cnt; mwindx++) {
   344			inmw = &ctx->inmws[mwindx];
   345			/* Set the type and the memory window index */
   346			msg.type = to_sh32(MW_DMAADDR | ((u32)mwindx << 16));
   347	
   348			/* First set the size of the memory window */
   349			msg.payload[0] = to_sh32(inmw->size);
   350	
   351			/* Set the Upper part of the memory window address */
   352	#ifdef CONFIG_64BIT
 > 353			msg.payload[1] = to_sh32((u32)(inmw->dma_addr >> 32));
   354	#else
   355			/* WARNING! NTB entpoints must either have the same architecture
   356			 * (x32 or x64) or use lower 4Gb for memory windows */
   357			msg.payload[1] = 0;
   358	#endif /* !CONFIG_64BIT */
   359			/* Set the Lower part of the memory window address */
   360			msg.payload[2] = to_sh32((u32)(inmw->dma_addr));
   361	
   362			/* Send the message */
   363			sts = ntb_msg_post(ctx->ntb, &msg);
   364			if (SUCCESS != sts) {
   365				dev_err_mw(ctx,
   366					"Failed to send a message with window %d "
   367					"address", mwindx);
   368			}
   369		}
   370	}
   371	
   372	/*
   373	 * Method to set the corresponding memory window and enable it
   374	 */
   375	static void mw_set_outmw_addr(struct mw_ctx *ctx, const struct ntb_msg *msg)
   376	{
   377		struct outmw_wrap *outmw;
   378		int mwindx, sts;
   379	
   380		/* Read the memory windows index (it's the part of the message type) */
   381		mwindx = from_sh32(msg->type) >> 16;
   382		if (ctx->outmws_cnt <= mwindx) {
   383			dev_err_mw(ctx,
   384				"Retrieved invalid outbound memory window index %d",
   385				mwindx);
   386			return;
   387		}
   388		outmw = &ctx->outmws[mwindx];
   389	
   390		/* Read the memory window size and check whether it has proper size and
   391		 * alignment */
   392		outmw->size = from_sh32(msg->payload[0]);
   393		if (!IS_ALIGNED(outmw->size, outmw->size_align) ||
   394		    outmw->size_max < outmw->size) {
   395			dev_err_mw(ctx,
   396				"Retrieved invalid memory window %d size %u "
   397				"(max: %u, align: %u)", mwindx, (unsigned int)outmw->size,
   398				(unsigned int)outmw->size_max,
   399				(unsigned int)outmw->size_align);
   400			return;
   401		}
   402	
   403		/* Read the DMA address, where the second DWORD is the upper part and
   404		 * the third DWORD - lower */
   405		outmw->dma_addr = from_sh32(msg->payload[2]);
   406	#ifdef CONFIG_64BIT
 > 407		outmw->dma_addr |= ((dma_addr_t)from_sh32(msg->payload[1]) << 32);
   408	#endif /* CONFIG_64BIT */
   409		/* Check whether the retrieved address is properly aligned */
   410		if (!IS_ALIGNED(outmw->dma_addr, outmw->addr_align)) {
   411			dev_err_mw(ctx,
   412				"Outbound memory window address %p is not aligned "
 > 413				"within %u bytes", (void *)outmw->dma_addr,
   414				(unsigned int)outmw->addr_align);
   415			return;
   416		}
   417	
   418		/* Set the translation address of the outbound memory window */
   419		sts = ntb_mw_set_trans(ctx->ntb, mwindx, outmw->dma_addr, outmw->size);
   420		if (SUCCESS != sts) {
   421			dev_err_mw(ctx, "Failed to set the translated address %p of "
   422				"outbound memory window %d", (void *)outmw->dma_addr,
   423				mwindx);
   424			return;
   425		}
   426	
   427		/* Enable the memory window */
   428		outmw->enabled = true;
   429	
 > 430		dev_dbg_mw(ctx, "Outbound memory window %d is initialized with "
 > 431			"address 0x%p", mwindx, (void *)outmw->dma_addr);

432 }
433
434 /*

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation

#6 lore raw

Re: [PATCH 3/3] ntb: Test client drivers for asynchronous NTB devices

Please, take a look at the next patchset. I've already fixed these issues there.

Regards,
-Sergey

Quoted 495 lines · kbuild test robot

Hi,

[auto build test WARNING on ntb/ntb-next]
[cannot apply to v4.7 next-20160728]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url:
https://github.com/0day-ci/linux/commits/Serge-Semin/ntb-Asynchronous-NTB-devices-support/20160727-082033
base: https://github.com/jonmason/ntb ntb-next
config: sparc64-allyesconfig (attached as .config)
compiler: sparc64-linux-gnu-gcc (Debian 5.4.0-6) 5.4.0 20160609 reproduce:
wget
https://git.kernel.org/cgit/linux/kernel/git/wfg/lkp-tests.git/plain/sbin/make.cross
-O ~/bin/make.cross
chmod +x ~/bin/make.cross
# save the attached .config to linux build tree make.cross ARCH=sparc64

All warnings (new ones prefixed by >>):

In file included from include/linux/swab.h:4:0,

                    from include/uapi/linux/byteorder/big_endian.h:12,
                    from include/linux/byteorder/big_endian.h:4,
                    from arch/sparc/include/uapi/asm/byteorder.h:4,
                    from arch/sparc/include/asm/bitops_64.h:15,
                    from arch/sparc/include/asm/bitops.h:4,
                    from include/linux/bitops.h:36,
                    from include/linux/kernel.h:10,
                    from drivers/ntb/test/ntb_mw_test.c:57:

drivers/ntb/test/ntb_mw_test.c: In function 'mw_send_inmw_addrs':

Quoted 1 line
Quoted 1 line

drivers/ntb/test/ntb_mw_test.c:353:49: warning: right shift count >=

width of type [-Wshift-count-overflow]

      msg.payload[1] = to_sh32((u32)(inmw->dma_addr >> 32));
                                                    ^
   include/uapi/linux/swab.h:116:32: note: in definition of macro
'__swab32'
     (__builtin_constant_p((__u32)(x)) ? \
                                   ^
   include/linux/byteorder/generic.h:87:21: note: in expansion of macro
'__cpu_to_le32'
    #define cpu_to_le32 __cpu_to_le32
                        ^
Quoted 1 line
Quoted 1 line

drivers/ntb/test/ntb_mw_test.c:353:20: note: in expansion of macro

'to_sh32'

      msg.payload[1] = to_sh32((u32)(inmw->dma_addr >> 32));
                       ^
Quoted 1 line
Quoted 1 line

drivers/ntb/test/ntb_mw_test.c:353:49: warning: right shift count >=

width of type [-Wshift-count-overflow]

      msg.payload[1] = to_sh32((u32)(inmw->dma_addr >> 32));
                                                    ^
   include/uapi/linux/swab.h:17:12: note: in definition of macro
'___constant_swab32'
     (((__u32)(x) & (__u32)0x000000ffUL) << 24) |  \
               ^
   include/uapi/linux/byteorder/big_endian.h:32:43: note: in expansion of
macro '__swab32'
    #define __cpu_to_le32(x) ((__force __le32)__swab32((x)))
                                              ^
   include/linux/byteorder/generic.h:87:21: note: in expansion of macro
'__cpu_to_le32'
    #define cpu_to_le32 __cpu_to_le32
                        ^
Quoted 1 line
Quoted 1 line

drivers/ntb/test/ntb_mw_test.c:353:20: note: in expansion of macro

'to_sh32'

      msg.payload[1] = to_sh32((u32)(inmw->dma_addr >> 32));
                       ^
Quoted 1 line
Quoted 1 line

drivers/ntb/test/ntb_mw_test.c:353:49: warning: right shift count >=

width of type [-Wshift-count-overflow]

      msg.payload[1] = to_sh32((u32)(inmw->dma_addr >> 32));
                                                    ^
   include/uapi/linux/swab.h:18:12: note: in definition of macro
'___constant_swab32'
     (((__u32)(x) & (__u32)0x0000ff00UL) <<  8) |  \
               ^
   include/uapi/linux/byteorder/big_endian.h:32:43: note: in expansion of
macro '__swab32'
    #define __cpu_to_le32(x) ((__force __le32)__swab32((x)))
                                              ^
   include/linux/byteorder/generic.h:87:21: note: in expansion of macro
'__cpu_to_le32'
    #define cpu_to_le32 __cpu_to_le32
                        ^
Quoted 1 line
Quoted 1 line

drivers/ntb/test/ntb_mw_test.c:353:20: note: in expansion of macro

'to_sh32'

      msg.payload[1] = to_sh32((u32)(inmw->dma_addr >> 32));
                       ^
Quoted 1 line
Quoted 1 line

drivers/ntb/test/ntb_mw_test.c:353:49: warning: right shift count >=

width of type [-Wshift-count-overflow]

      msg.payload[1] = to_sh32((u32)(inmw->dma_addr >> 32));
                                                    ^
   include/uapi/linux/swab.h:19:12: note: in definition of macro
'___constant_swab32'
     (((__u32)(x) & (__u32)0x00ff0000UL) >>  8) |  \
               ^
   include/uapi/linux/byteorder/big_endian.h:32:43: note: in expansion of
macro '__swab32'
    #define __cpu_to_le32(x) ((__force __le32)__swab32((x)))
                                              ^
   include/linux/byteorder/generic.h:87:21: note: in expansion of macro
'__cpu_to_le32'
    #define cpu_to_le32 __cpu_to_le32
                        ^
Quoted 1 line
Quoted 1 line

drivers/ntb/test/ntb_mw_test.c:353:20: note: in expansion of macro

'to_sh32'

      msg.payload[1] = to_sh32((u32)(inmw->dma_addr >> 32));
                       ^
Quoted 1 line
Quoted 1 line

drivers/ntb/test/ntb_mw_test.c:353:49: warning: right shift count >=

width of type [-Wshift-count-overflow]

      msg.payload[1] = to_sh32((u32)(inmw->dma_addr >> 32));
                                                    ^
   include/uapi/linux/swab.h:20:12: note: in definition of macro
'___constant_swab32'
     (((__u32)(x) & (__u32)0xff000000UL) >> 24)))
               ^
   include/uapi/linux/byteorder/big_endian.h:32:43: note: in expansion of
macro '__swab32'
    #define __cpu_to_le32(x) ((__force __le32)__swab32((x)))
                                              ^
   include/linux/byteorder/generic.h:87:21: note: in expansion of macro
'__cpu_to_le32'
    #define cpu_to_le32 __cpu_to_le32
                        ^
Quoted 1 line
Quoted 1 line

drivers/ntb/test/ntb_mw_test.c:353:20: note: in expansion of macro

'to_sh32'

      msg.payload[1] = to_sh32((u32)(inmw->dma_addr >> 32));
                       ^
Quoted 1 line
Quoted 1 line

drivers/ntb/test/ntb_mw_test.c:353:49: warning: right shift count >=

width of type [-Wshift-count-overflow]

      msg.payload[1] = to_sh32((u32)(inmw->dma_addr >> 32));
                                                    ^
   include/uapi/linux/swab.h:118:12: note: in definition of macro
'__swab32'
     __fswab32(x))
               ^
   include/linux/byteorder/generic.h:87:21: note: in expansion of macro
'__cpu_to_le32'
    #define cpu_to_le32 __cpu_to_le32
                        ^
Quoted 1 line
Quoted 1 line

drivers/ntb/test/ntb_mw_test.c:353:20: note: in expansion of macro

'to_sh32'

      msg.payload[1] = to_sh32((u32)(inmw->dma_addr >> 32));
                       ^

drivers/ntb/test/ntb_mw_test.c: In function 'mw_set_outmw_addr':

Quoted 1 line
Quoted 1 line

drivers/ntb/test/ntb_mw_test.c:407:61: warning: left shift count >=

width of type [-Wshift-count-overflow]

     outmw->dma_addr |= ((dma_addr_t)from_sh32(msg->payload[1]) << 32);
                                                                ^
Quoted 1 line
Quoted 1 line

drivers/ntb/test/ntb_mw_test.c:413:23: warning: cast to pointer from

integer of different size [-Wint-to-pointer-cast]

       "within %u bytes", (void *)outmw->dma_addr,
                          ^
   drivers/ntb/test/ntb_mw_test.c:189:29: note: in definition of macro
'dev_err_mw'
     dev_err(&ctx->ntb->dev, ## args)
                                ^
   drivers/ntb/test/ntb_mw_test.c:422:33: warning: cast to pointer from
integer of different size [-Wint-to-pointer-cast]
       "outbound memory window %d", (void *)outmw->dma_addr,
                                    ^
   drivers/ntb/test/ntb_mw_test.c:189:29: note: in definition of macro
'dev_err_mw'
     dev_err(&ctx->ntb->dev, ## args)
                                ^
   In file included from include/linux/printk.h:289:0,
                    from include/linux/kernel.h:13,
                    from drivers/ntb/test/ntb_mw_test.c:57:
   drivers/ntb/test/ntb_mw_test.c:431:27: warning: cast to pointer from
integer of different size [-Wint-to-pointer-cast]
      "address 0x%p", mwindx, (void *)outmw->dma_addr);
                              ^
   include/linux/dynamic_debug.h:87:9: note: in definition of macro
'dynamic_dev_dbg'
          ##__VA_ARGS__);  \
            ^
Quoted 1 line
Quoted 1 line

drivers/ntb/test/ntb_mw_test.c:195:2: note: in expansion of macro

'dev_dbg'

     dev_dbg(&ctx->ntb->dev, ## args)
     ^
Quoted 1 line
Quoted 1 line

drivers/ntb/test/ntb_mw_test.c:430:2: note: in expansion of macro

'dev_dbg_mw'
dev_dbg_mw(ctx, "Outbound memory window %d is initialized with " ^
drivers/ntb/test/ntb_mw_test.c: In function 'mw_dbgfs_outmw_cfg_read':
drivers/ntb/test/ntb_mw_test.c:766:30: warning: cast to pointer from
integer of different size [-Wint-to-pointer-cast]

      "DMA address\t\t- 0x%p\n", (void *)wrap->dma_addr);
                                 ^
   drivers/ntb/test/ntb_mw_test.c: In function 'mw_dbgfs_inmw_cfg_read':
   drivers/ntb/test/ntb_mw_test.c:915:30: warning: cast to pointer from
integer of different size [-Wint-to-pointer-cast]
      "DMA address\t\t- 0x%p\n", (void *)wrap->dma_addr);
                                 ^
   drivers/ntb/test/ntb_mw_test.c: In function 'mw_create_inmws':
   drivers/ntb/test/ntb_mw_test.c:1197:25: warning: cast to pointer from
integer of different size [-Wint-to-pointer-cast]
        "aligned with %lu", (void *)inmw->dma_addr, mwindx,
                            ^
   drivers/ntb/test/ntb_mw_test.c:189:29: note: in definition of macro
'dev_err_mw'
     dev_err(&ctx->ntb->dev, ## args)
                                ^

vim +353 drivers/ntb/test/ntb_mw_test.c

   189          dev_err(&ctx->ntb->dev, ## args)
   190  #define dev_warn_mw(ctx, args...) \
   191          dev_warn(&ctx->ntb->dev, ## args)
   192  #define dev_info_mw(ctx, args...) \
   193          dev_info(&ctx->ntb->dev, ## args)
   194  #define dev_dbg_mw(ctx, args...) \
Quoted 1 line

195 dev_dbg(&ctx->ntb->dev, ## args)

196
197 /*

   198   * Some common constant used in the driver for better readability:
   199   * @ON: Enable something
   200   * @OFF: Disable something
   201   * @SUCCESS: Success of a function execution
   202   * @MIN_MW_CNT: Minimum memory windows count
   203   * @MAX_MW_CNT: Maximum memory windows count
   204   */
   205  #define ON ((u32)0x1)
   206  #define OFF ((u32)0x0)
   207  #define SUCCESS 0
   208  #define MIN_MW_CNT ((unsigned char)1)
   209  #define MAX_MW_CNT ((unsigned char)255)
   210
   211  /*
   212   * Shared data converter to support the different CPU architectures
   213   */
   214  #define to_sh32(data) \
   215          cpu_to_le32((data))
   216  #define from_sh32(data) \
   217          le32_to_cpu((data))
   218
   219  /*
   220   * Module parameters:
   221   * @inmw_cnt:   Number of inbound memory windows [1; 255]
   222   * @outmw_cnt:  Number of outbound memory windows [1; 255]
   223   * If the specified value exceeds the maximum possible valiue,
then it is
   224   * initialized with maximum one
   225   */
   226  static unsigned char inmws_cnt = MAX_MW_CNT;
   227  module_param(inmws_cnt, byte, 0000);
   228  MODULE_PARM_DESC(inmws_cnt,

229 "Inbound memory windows count. Those are the memory
windows, which are "
230 "locally allocated. Their address is sent to the remote
host."
231 " - Parameter can be set within [1; 255], where 255 means
maximum possible"

   232          "   number of windows");
   233
   234

/*===========================================================================
235 * Helper methods
236
*===========================================================================*/
237
238 /*
239 * Alter the passed driver paremeters
240 */
241 static void mw_alter_params(struct mw_ctx *ctx)

   242  {
   243          unsigned char inmws_cnt_bak = ctx->inmws_cnt;
   244
   245          /* Clamp the inbound memory windows parameter */
   246          ctx->inmws_cnt = clamp(inmws_cnt,
   247                  MIN_MW_CNT, (unsigned char)ctx->inmws_cnt);
   248          if (inmws_cnt_bak != ctx->inmws_cnt) {
   249                  dev_warn_mw(ctx,
   250                          "Inbound memory windows count is altered
from "
   251                          "%hhu to %hhu", inmws_cnt_bak,
ctx->inmws_cnt);
   252          }
   253
   254          dev_dbg_mw(ctx, "Memory windows test driver parameter is
verified");
   255  }
   256
   257  /*
   258   * Memory block IO write method
   259   */
   260  static void iomem_write(void __iomem *dst, const void *src, size_t
cnt)
   261  {
   262          while (cnt--) {
   263                  iowrite8(*(u8 *)src, dst);
   264                  dst++;
   265                  src++;
   266          }
   267  }
   268
   269  /*
   270   * Memory block IO read method
   271   */
   272  static void iomem_read(void __iomem *src, void *dst, size_t cnt)
   273  {
   274          while (cnt--) {
   275                  *(u8 *)dst = ioread8(src);
   276                  dst++;
   277                  src++;
   278          }
   279  }
   280
   281

/*===========================================================================
282 * Message command handlers
283
*===========================================================================*/
284
285 /*
286 * Send MW_GETADDRS command method
287 */
288 static void mw_send_getaddrs_cmd(struct mw_ctx *ctx)

   289  {
   290          struct ntb_msg msg;
   291          int sts;
   292
   293          /* Clear the message structure */
   294          memset(&msg, 0, sizeof(msg));
   295
   296          /* Set the message type only */
   297          msg.type = to_sh32(MW_GETADDRS);
   298
   299          /* Send the message */
   300          sts = ntb_msg_post(ctx->ntb, &msg);
   301          if (SUCCESS != sts) {
   302                  dev_err_mw(ctx, "Failed to send message to get
outbound window "
   303                          "addresses");
   304          }
   305  }
   306
   307  /*
   308   * Send MW_FREEADDRS command method
   309   */
   310  static void mw_send_freeaddrs_cmd(struct mw_ctx *ctx)
   311  {
   312          struct ntb_msg msg;
   313          int sts;
   314
   315          /* Clear the message structure */
   316          memset(&msg, 0, sizeof(msg));
   317
   318          /* Set the message type only */
   319          msg.type = to_sh32(MW_FREEADDRS);
   320
   321          /* Send the message */
   322          sts = ntb_msg_post(ctx->ntb, &msg);
   323          if (SUCCESS != sts) {
   324                  dev_err_mw(ctx, "Failed to send a message to
disable the peer "
   325                          "outbound windows");
   326          }
   327  }
   328
   329  /*
   330   * Callback method for response on the command MW_GETADDRS
   331   */
   332  static void mw_send_inmw_addrs(struct mw_ctx *ctx)
   333  {
   334          struct ntb_msg msg;
   335          struct inmw_wrap *inmw;
   336          int mwindx, sts;
   337
   338          /* Clear the message structure */
   339          memset(&msg, 0, sizeof(msg));
   340
   341          /* Walk through all the inbound memory windows and send the
   342           * corresponding DMA address of the window */
   343          for (mwindx = 0; mwindx < ctx->inmws_cnt; mwindx++) {
   344                  inmw = &ctx->inmws[mwindx];
   345                  /* Set the type and the memory window index */
   346                  msg.type = to_sh32(MW_DMAADDR | ((u32)mwindx <<
16));
   347
   348                  /* First set the size of the memory window */
   349                  msg.payload[0] = to_sh32(inmw->size);
   350
   351                  /* Set the Upper part of the memory window address

*/
352 #ifdef CONFIG_64BIT

Quoted 1 line

353 msg.payload[1] = to_sh32((u32)(inmw->dma_addr >>

32));
354 #else
355 /* WARNING! NTB entpoints must either have the
same architecture
356 * (x32 or x64) or use lower 4Gb for memory
windows */
357 msg.payload[1] = 0;
358 #endif /* !CONFIG_64BIT */
359 /* Set the Lower part of the memory window address
*/

   360                  msg.payload[2] = to_sh32((u32)(inmw->dma_addr));
   361
   362                  /* Send the message */
   363                  sts = ntb_msg_post(ctx->ntb, &msg);
   364                  if (SUCCESS != sts) {
   365                          dev_err_mw(ctx,
   366                                  "Failed to send a message with
window %d "
   367                                  "address", mwindx);
   368                  }
   369          }
   370  }
   371
   372  /*
   373   * Method to set the corresponding memory window and enable it
   374   */
   375  static void mw_set_outmw_addr(struct mw_ctx *ctx, const struct
ntb_msg *msg)
   376  {
   377          struct outmw_wrap *outmw;
   378          int mwindx, sts;
   379
   380          /* Read the memory windows index (it's the part of the

message type) */
381 mwindx = from_sh32(msg->type) >> 16;
382 if (ctx->outmws_cnt <= mwindx) {
383 dev_err_mw(ctx,
384 "Retrieved invalid outbound memory window
index %d",

   385                          mwindx);
   386                  return;
   387          }
   388          outmw = &ctx->outmws[mwindx];
   389
   390          /* Read the memory window size and check whether it has
proper size and
   391           * alignment */
   392          outmw->size = from_sh32(msg->payload[0]);
   393          if (!IS_ALIGNED(outmw->size, outmw->size_align) ||
   394              outmw->size_max < outmw->size) {
   395                  dev_err_mw(ctx,
   396                          "Retrieved invalid memory window %d size

%u "
397 "(max: %u, align: %u)", mwindx, (unsigned
int)outmw->size,
398 (unsigned int)outmw->size_max,

   399                          (unsigned int)outmw->size_align);
   400                  return;
   401          }
   402
   403          /* Read the DMA address, where the second DWORD is the
upper part and
   404           * the third DWORD - lower */
   405          outmw->dma_addr = from_sh32(msg->payload[2]);
   406  #ifdef CONFIG_64BIT
Quoted 1 line

407 outmw->dma_addr |= ((dma_addr_t)from_sh32(msg->payload[1])

<< 32);
408 #endif /* CONFIG_64BIT */
409 /* Check whether the retrieved address is properly aligned
*/
410 if (!IS_ALIGNED(outmw->dma_addr, outmw->addr_align)) {
411 dev_err_mw(ctx,
412 "Outbound memory window address %p is not
aligned "

Quoted 1 line

413 "within %u bytes", (void *)outmw->dma_addr,

   414                          (unsigned int)outmw->addr_align);
   415                  return;
   416          }
   417
   418          /* Set the translation address of the outbound memory

window */
419 sts = ntb_mw_set_trans(ctx->ntb, mwindx, outmw->dma_addr,
outmw->size);
420 if (SUCCESS != sts) {
421 dev_err_mw(ctx, "Failed to set the translated
address %p of "
422 "outbound memory window %d", (void
*)outmw->dma_addr,

   423                          mwindx);
   424                  return;
   425          }
   426
   427          /* Enable the memory window */
   428          outmw->enabled = true;
   429
Quoted 1 line

430 dev_dbg_mw(ctx, "Outbound memory window %d is initialized

with "

Quoted 1 line

431 "address 0x%p", mwindx, (void *)outmw->dma_addr);

432 }
433
434 /*

---
0-DAY kernel test infrastructure Open Source Technology
Center
https://lists.01.org/pipermail/kbuild-all Intel
Corporation

#7 lore raw

v2 cover ntb: Asynchronous NTB devices support

In reply to Serge Semin

Please, find the general patchset description in the cover letter of the first patchset (see the very first message in thread).

Changes in v2:
- Fix sparc64 compilation warning in drivers/ntb/hw/idt/ntb_hw_idt.c :
warning: right shift count >= width of type
- Fix sparc64 compilation warnings in drivers/ntb/test/ntb_mw_test.c :
warning: right shift count >= width of type
warning: cast to pointer from integer of different size

Thanks,

=============================
Serge V. Semin
Leading Programmer
Embedded SW development group
T-platforms
=============================

fancer (3):
ntb: Add asynchronous devices support to NTB-bus interface
ntb: IDT 89HPES*NT* PCIe-switches NTB device driver
ntb: Test client drivers for asynchronous NTB devices

 drivers/ntb/Kconfig                    |    4 +-
 drivers/ntb/hw/Kconfig                 |    1 +
 drivers/ntb/hw/Makefile                |    6 +-
 drivers/ntb/hw/amd/ntb_hw_amd.c        |   49 +-
 drivers/ntb/hw/idt/Kconfig             |   21 +
 drivers/ntb/hw/idt/Makefile            |    5 +
 drivers/ntb/hw/idt/ntb_hw_idt.c        | 4050 ++++++++++++++++++++++++++++++++
 drivers/ntb/hw/idt/ntb_hw_idt.h        |  390 +++
 drivers/ntb/hw/idt/ntb_hw_idt_quirks.c |  163 ++
 drivers/ntb/hw/idt/ntb_hw_idt_quirks.h |  114 +
 drivers/ntb/hw/idt/ntb_hw_idt_regmap.h |  877 +++++++
 drivers/ntb/hw/intel/ntb_hw_intel.c    |   59 +-
 drivers/ntb/ntb.c                      |   86 +-
 drivers/ntb/ntb_transport.c            |   19 +-
 drivers/ntb/test/Kconfig               |   32 +
 drivers/ntb/test/Makefile              |    9 +-
 drivers/ntb/test/ntb_db_test.c         |  677 ++++++
 drivers/ntb/test/ntb_msg_test.c        |  736 ++++++
 drivers/ntb/test/ntb_mw_test.c         | 1539 ++++++++++++
 drivers/ntb/test/ntb_perf.c            |   16 +-
 drivers/ntb/test/ntb_pingpong.c        |    5 +
 drivers/ntb/test/ntb_tool.c            |   25 +-
 include/linux/ntb.h                    |  600 ++++-
 23 files changed, 9317 insertions(+), 166 deletions(-)
 create mode 100644 drivers/ntb/hw/idt/Kconfig
 create mode 100644 drivers/ntb/hw/idt/Makefile
 create mode 100644 drivers/ntb/hw/idt/ntb_hw_idt.c
 create mode 100644 drivers/ntb/hw/idt/ntb_hw_idt.h
 create mode 100644 drivers/ntb/hw/idt/ntb_hw_idt_quirks.c
 create mode 100644 drivers/ntb/hw/idt/ntb_hw_idt_quirks.h
 create mode 100644 drivers/ntb/hw/idt/ntb_hw_idt_regmap.h
 create mode 100644 drivers/ntb/test/ntb_db_test.c
 create mode 100644 drivers/ntb/test/ntb_msg_test.c
 create mode 100644 drivers/ntb/test/ntb_mw_test.c
Signature · 1 line
2.6.6
#8 lore raw

PATCH v2 1/3 ntb: Add asynchronous devices support to NTB-bus interface

Currently supported AMD and Intel Non-transparent PCIe-bridges are synchronous devices, so translated base address of memory windows can be direcly written to peer registers. But there are some IDT PCIe-switches which implement complex interfaces using Lookup Tables of translation addresses. Due to the way the table is accessed, it can not be done synchronously from different RCs, that's why the asynchronous interface should be developed.

For these purpose the Memory Window related interface is correspondingly split as it is for Doorbell and Scratchpad registers. The definition of Memory Window is following: "It is a virtual memory region, which locally reflects a physical memory of peer device." So to speak the "ntb_peer_mw_"-prefixed methods control the peers memory windows, "ntb_mw_"-prefixed functions work with the local memory windows.
Here is the description of the Memory Window related NTB-bus callback functions:
- ntb_mw_count() - number of local memory windows.
- ntb_mw_get_maprsc() - get the physical address and size of the local memory window to map.
- ntb_mw_set_trans() - set translation address of local memory window (this address should be somehow retrieved from a peer).
- ntb_mw_get_trans() - get translation address of local memory window.
- ntb_mw_get_align() - get alignment of translated base address and size of local memory window. Additionally one can get the upper size limit of the memory window.
- ntb_peer_mw_count() - number of peer memory windows (it can differ from the local number).
- ntb_peer_mw_set_trans() - set translation address of peer memory window
- ntb_peer_mw_get_trans() - get translation address of peer memory window
- ntb_peer_mw_get_align() - get alignment of translated base address and size of peer memory window.Additionally one can get the upper size limit of the memory window.

As one can see current AMD and Intel NTB drivers mostly implement the "ntb_peer_mw_"-prefixed methods. So this patch correspondingly renames the driver functions. IDT NTB driver mostly expose "ntb_nw_"-prefixed methods, since it doesn't have convenient access to the peer Lookup Table.

In order to pass information from one RC to another NTB functions of IDT PCIe-switch implement Messaging subsystem. They currently support four message registers to transfer DWORD sized data to a specified peer. So there are two new callback methods are introduced:
- ntb_msg_size() - get the number of DWORDs supported by NTB function to send and receive messages
- ntb_msg_post() - send message of size retrieved from ntb_msg_size() to a peer
Additionally there is a new event function:
- ntb_msg_event() - it is invoked when either a new message was retrieved (NTB_MSG_NEW), or last message was successfully sent (NTB_MSG_SENT), or the last message failed to be sent (NTB_MSG_FAIL).

The last change concerns the IDs (practically names) of NTB-devices on the NTB-bus. It is not good to have the devices with same names in the system and it brakes my IDT NTB driver from being loaded =) So I developed a simple algorithm of NTB devices naming. Particulary it generates names "ntbS{N}" for synchronous devices, "ntbA{N}" for asynchronous devices, and "ntbAS{N}" for devices supporting both interfaces.

---
 drivers/ntb/Kconfig                 |   4 +-
 drivers/ntb/hw/amd/ntb_hw_amd.c     |  49 ++-
 drivers/ntb/hw/intel/ntb_hw_intel.c |  59 +++-
 drivers/ntb/ntb.c                   |  86 +++++-
 drivers/ntb/ntb_transport.c         |  19 +-
 drivers/ntb/test/ntb_perf.c         |  16 +-
 drivers/ntb/test/ntb_pingpong.c     |   5 +
 drivers/ntb/test/ntb_tool.c         |  25 +-
 include/linux/ntb.h                 | 600 +++++++++++++++++++++++++++++-------
 9 files changed, 701 insertions(+), 162 deletions(-)
drivers/ntb/Kconfig +2 -2
index 95944e5..67d80c4 100644
@@ -14,8 +14,6 @@ if NTB
 
 source "drivers/ntb/hw/Kconfig"
 
-source "drivers/ntb/test/Kconfig"
-
 config NTB_TRANSPORT
 	tristate "NTB Transport Client"
 	help
@@ -25,4 +23,6 @@ config NTB_TRANSPORT
 
 	 If unsure, say N.
 
+source "drivers/ntb/test/Kconfig"
+
 endif # NTB
drivers/ntb/hw/amd/ntb_hw_amd.c +36 -13

78 lines not on this page · raw message

drivers/ntb/hw/intel/ntb_hw_intel.c +46 -13

82 lines not on this page · raw message

drivers/ntb/ntb.c +83 -3

135 lines not on this page · raw message

drivers/ntb/ntb_transport.c +14 -5
index d5c5894..2626ba0 100644
@@ -673,7 +673,7 @@ static void ntb_free_mw(struct ntb_transport_ctx *nt, int num_mw)
 	if (!mw->virt_addr)
 		return;
 
-	ntb_mw_clear_trans(nt->ndev, num_mw);
+	ntb_peer_mw_set_trans(nt->ndev, num_mw, 0, 0);
 	dma_free_coherent(&pdev->dev, mw->buff_size,
 			  mw->virt_addr, mw->dma_addr);
 	mw->xlat_size = 0;
@@ -730,7 +730,8 @@ static int ntb_set_mw(struct ntb_transport_ctx *nt, int num_mw,
 	}
 
 	/* Notify HW the memory location of the receive buffer */
-	rc = ntb_mw_set_trans(nt->ndev, num_mw, mw->dma_addr, mw->xlat_size);
+	rc = ntb_peer_mw_set_trans(nt->ndev, num_mw, mw->dma_addr,
+				   mw->xlat_size);
 	if (rc) {
 		dev_err(&pdev->dev, "Unable to set mw%d translation", num_mw);
 		ntb_free_mw(nt, num_mw);
@@ -1060,7 +1061,11 @@ static int ntb_transport_probe(struct ntb_client *self, struct ntb_dev *ndev)
 	int node;
 	int rc, i;
 
-	mw_count = ntb_mw_count(ndev);
+	/* Synchronous hardware is only supported */
+	if (!ntb_valid_sync_dev_ops(ndev))
+		return -EINVAL;
+
+	mw_count = ntb_peer_mw_count(ndev);
 	if (ntb_spad_count(ndev) < (NUM_MWS + 1 + mw_count * 2)) {
 		dev_err(&ndev->dev, "Not enough scratch pad registers for %s",
 			NTB_TRANSPORT_NAME);
@@ -1094,8 +1099,12 @@ static int ntb_transport_probe(struct ntb_client *self, struct ntb_dev *ndev)
 	for (i = 0; i < mw_count; i++) {
 		mw = &nt->mw_vec[i];
 
-		rc = ntb_mw_get_range(ndev, i, &mw->phys_addr, &mw->phys_size,
-				      &mw->xlat_align, &mw->xlat_align_size);
+		rc = ntb_mw_get_maprsc(ndev, i, &mw->phys_addr, &mw->phys_size);
+		if (rc)
+			goto err1;
+
+		rc = ntb_peer_mw_get_align(ndev, i, &mw->xlat_align,
+					   &mw->xlat_align_size, NULL);
 		if (rc)
 			goto err1;
 
drivers/ntb/test/ntb_perf.c +12 -4
index 6a50f20..f2952f7 100644
@@ -452,7 +452,7 @@ static void perf_free_mw(struct perf_ctx *perf)
 	if (!mw->virt_addr)
 		return;
 
-	ntb_mw_clear_trans(perf->ntb, 0);
+	ntb_peer_mw_set_trans(perf->ntb, 0, 0, 0);
 	dma_free_coherent(&pdev->dev, mw->buf_size,
 			  mw->virt_addr, mw->dma_addr);
 	mw->xlat_size = 0;
@@ -488,7 +488,7 @@ static int perf_set_mw(struct perf_ctx *perf, resource_size_t size)
 		mw->buf_size = 0;
 	}
 
-	rc = ntb_mw_set_trans(perf->ntb, 0, mw->dma_addr, mw->xlat_size);
+	rc = ntb_peer_mw_set_trans(perf->ntb, 0, mw->dma_addr, mw->xlat_size);
 	if (rc) {
 		dev_err(&perf->ntb->dev, "Unable to set mw0 translation\n");
 		perf_free_mw(perf);
@@ -559,8 +559,12 @@ static int perf_setup_mw(struct ntb_dev *ntb, struct perf_ctx *perf)
 
 	mw = &perf->mw;
 
-	rc = ntb_mw_get_range(ntb, 0, &mw->phys_addr, &mw->phys_size,
-			      &mw->xlat_align, &mw->xlat_align_size);
+	rc = ntb_mw_get_maprsc(ntb, 0, &mw->phys_addr, &mw->phys_size);
+	if (rc)
+		return rc;
+
+	rc = ntb_peer_mw_get_align(ntb, 0, &mw->xlat_align,
+				   &mw->xlat_align_size, NULL);
 	if (rc)
 		return rc;
 
@@ -758,6 +762,10 @@ static int perf_probe(struct ntb_client *client, struct ntb_dev *ntb)
 	int node;
 	int rc = 0;
 
+	/* Synchronous hardware is only supported */
+	if (!ntb_valid_sync_dev_ops(ntb))
+		return -EINVAL;
+
 	if (ntb_spad_count(ntb) < MAX_SPAD) {
 		dev_err(&ntb->dev, "Not enough scratch pad registers for %s",
 			DRIVER_NAME);
drivers/ntb/test/ntb_pingpong.c +5 -0
index 7d31179..e833649 100644
@@ -214,6 +214,11 @@ static int pp_probe(struct ntb_client *client,
 	struct pp_ctx *pp;
 	int rc;
 
+	/* Synchronous hardware is only supported */
+	if (!ntb_valid_sync_dev_ops(ntb)) {
+		return -EINVAL;
+	}
+
 	if (ntb_db_is_unsafe(ntb)) {
 		dev_dbg(&ntb->dev, "doorbell is unsafe\n");
 		if (!unsafe) {
drivers/ntb/test/ntb_tool.c +16 -9
index 61bf2ef..5dfe12f 100644
@@ -675,8 +675,11 @@ static int tool_setup_mw(struct tool_ctx *tc, int idx, size_t req_size)
 	if (mw->peer)
 		return 0;
 
-	rc = ntb_mw_get_range(tc->ntb, idx, &base, &size, &align,
-			      &align_size);
+	rc = ntb_mw_get_maprsc(tc->ntb, idx, &base, &size);
+	if (rc)
+		return rc;
+
+	rc = ntb_peer_mw_get_align(tc->ntb, idx, &align, &align_size, NULL);
 	if (rc)
 		return rc;
 
@@ -689,7 +692,7 @@ static int tool_setup_mw(struct tool_ctx *tc, int idx, size_t req_size)
 	if (!mw->peer)
 		return -ENOMEM;
 
-	rc = ntb_mw_set_trans(tc->ntb, idx, mw->peer_dma, mw->size);
+	rc = ntb_peer_mw_set_trans(tc->ntb, idx, mw->peer_dma, mw->size);
 	if (rc)
 		goto err_free_dma;
 
@@ -716,7 +719,7 @@ static void tool_free_mw(struct tool_ctx *tc, int idx)
 	struct tool_mw *mw = &tc->mws[idx];
 
 	if (mw->peer) {
-		ntb_mw_clear_trans(tc->ntb, idx);
+		ntb_peer_mw_set_trans(tc->ntb, idx, 0, 0);
 		dma_free_coherent(&tc->ntb->pdev->dev, mw->size,
 				  mw->peer,
 				  mw->peer_dma);
@@ -751,8 +754,8 @@ static ssize_t tool_peer_mw_trans_read(struct file *filep,
 	if (!buf)
 		return -ENOMEM;
 
-	ntb_mw_get_range(mw->tc->ntb, mw->idx,
-			 &base, &mw_size, &align, &align_size);
+	ntb_mw_get_maprsc(mw->tc->ntb, mw->idx, &base, &mw_size);
+	ntb_peer_mw_get_align(mw->tc->ntb, mw->idx, &align, &align_size, NULL);
 
 	off += scnprintf(buf + off, buf_size - off,
 			 "Peer MW %d Information:\n", mw->idx);
@@ -827,8 +830,7 @@ static int tool_init_mw(struct tool_ctx *tc, int idx)
 	phys_addr_t base;
 	int rc;
 
-	rc = ntb_mw_get_range(tc->ntb, idx, &base, &mw->win_size,
-			      NULL, NULL);
+	rc = ntb_mw_get_maprsc(tc->ntb, idx, &base, &mw->win_size);
 	if (rc)
 		return rc;
 
@@ -913,6 +915,11 @@ static int tool_probe(struct ntb_client *self, struct ntb_dev *ntb)
 	int rc;
 	int i;
 
+	/* Synchronous hardware is only supported */
+	if (!ntb_valid_sync_dev_ops(ntb)) {
+		return -EINVAL;
+	}
+
 	if (ntb_db_is_unsafe(ntb))
 		dev_dbg(&ntb->dev, "doorbell is unsafe\n");
 
@@ -928,7 +935,7 @@ static int tool_probe(struct ntb_client *self, struct ntb_dev *ntb)
 	tc->ntb = ntb;
 	init_waitqueue_head(&tc->link_wq);
 
-	tc->mw_count = min(ntb_mw_count(tc->ntb), MAX_MWS);
+	tc->mw_count = min(ntb_peer_mw_count(tc->ntb), MAX_MWS);
 	for (i = 0; i < tc->mw_count; i++) {
 		rc = tool_init_mw(tc, i);
 		if (rc)
include/linux/ntb.h +487 -113

807 lines not on this page · raw message

Signature · 1 line
2.6.6
#9 lore raw

PATCH v2 2/3 ntb: IDT 89HPES*NT* PCIe-switches NTB device driver

In reply to Serge Semin

IDT 89HPES*NT* PCIe-switches are the multi-port switches, which can be configured to have more than two NT-functions, connected to each other. Using these facility NT-function of local RC can access any NT-functions of others. This driver implements Port-to-Ports architecture, so only Primary port can have access to prededefined number of Secondary ports. Secondary ports on the other hand can access the primary port memory only. The ports hierarchy is configured using NTSDATA register of each NT-function, which should be preinitialized with corresponding Primary port ID. Then driver will evenly split the IDT PCIe-switch Doorbell and Memory Window resources between all of the NT-function pairs, and add the corresponding devices to the NTB bus. The NTSDATA register preinitialization can be done either by EEPROM or by linux kernel PCI fixup interface. The default value is zero, so the port 0 is considered being primary, the others are secondary.

The supported IDT PCIe-switches do not implement synchronous interface to access Memory Windows configuration registers. There is no way to exclusively access a peer translated base addresses Lookup Table. Instead the messaging subsystem can be used to post the translated base address to a peer, so one could properly initialize the table. In order to resolve the race conditions of possible concurrent messages transfer by parallel tasks and different root complexes, the ntb_msg_post() method places messages into the outbound messages queue. An extra kernel work thread is used to perform an actual message transfer with a constant frequency of attempts. If kernel thread fails to send a message after a constant number of tries, then the corresponding client driver is notified by rising the ntb_msg_event() method with NTB_MSG_FAIL status. Additionaly there is a special tasklet, which reads messages from incoming message registers and puts them into the inbound messages queue. An another kernel thread is then started to deliver a message to a corresponding client driver.

There are only 32 Global doorbell bits, which can be routed between any two NT-functions. So the driver evenly distributes doorbell bits between all the NT-function pairs. Of course it is not always possible being equally done, so depending on the NT Primary/Secondary topology, one pair can have greater number of Doorbell bits than another. The difference cannot exceed for more than one bit.

IDT 89HPES*NT* PCIe-switches don't have Scrathpad registers, so the corresponding callback methods are unsupported.

There are three DebugFS nodes, which can be used to debug the driver:
1. /sys/kernel/debug/ntb_hw_idt/ntbA{N}/info - contain a general information about the local IDT NTB driver and NT-function, like port, partition, role (primary or secondary) and number of connected peers, a link status, of all the locally available pairs, global and local doorbell registers status, doorbells mapping, NTB mapping table, chip teperature and many others.
2. /sys/kernel/debug/ntb_hw_idt/ntbA{N}/ntregs - debug file to print the state of local NT-function registers. Thanks to the "enum-switch-case-macro" pattern it can be easily done just by one loop.
3. /sys/kernel/debug/ntb_hw_idt/ntbA{N}/swregs - debug file to print the state of PCIe-swtich global registers.

The detailed description of the driver design and source code navigation can be found in the header of drivers/ntb/hw/idt/ntb_hw_idt.c file.

NOTE IDT 89HPES12NT3 PCIe-switch is not supported by this driver, since it has synchronous interface.

---
 drivers/ntb/hw/Kconfig                 |    1 +
 drivers/ntb/hw/Makefile                |    6 +-
 drivers/ntb/hw/idt/Kconfig             |   21 +
 drivers/ntb/hw/idt/Makefile            |    5 +
 drivers/ntb/hw/idt/ntb_hw_idt.c        | 4050 ++++++++++++++++++++++++++++++++
 drivers/ntb/hw/idt/ntb_hw_idt.h        |  390 +++
 drivers/ntb/hw/idt/ntb_hw_idt_quirks.c |  163 ++
 drivers/ntb/hw/idt/ntb_hw_idt_quirks.h |  114 +
 drivers/ntb/hw/idt/ntb_hw_idt_regmap.h |  877 +++++++
 9 files changed, 5625 insertions(+), 2 deletions(-)
 create mode 100644 drivers/ntb/hw/idt/Kconfig
 create mode 100644 drivers/ntb/hw/idt/Makefile
 create mode 100644 drivers/ntb/hw/idt/ntb_hw_idt.c
 create mode 100644 drivers/ntb/hw/idt/ntb_hw_idt.h
 create mode 100644 drivers/ntb/hw/idt/ntb_hw_idt_quirks.c
 create mode 100644 drivers/ntb/hw/idt/ntb_hw_idt_quirks.h
 create mode 100644 drivers/ntb/hw/idt/ntb_hw_idt_regmap.h
drivers/ntb/hw/Kconfig +1 -0
index 7116472..a89243c 100644
@@ -1,2 +1,3 @@
 source "drivers/ntb/hw/amd/Kconfig"
+source "drivers/ntb/hw/idt/Kconfig"
 source "drivers/ntb/hw/intel/Kconfig"
drivers/ntb/hw/Makefile +4 -2
index 532e085..5d438ea 100644
@@ -1,2 +1,4 @@
-obj-$(CONFIG_NTB_AMD)	+= amd/
-obj-$(CONFIG_NTB_INTEL)	+= intel/
+obj-$(CONFIG_NTB_AMD)		+= amd/
+obj-$(CONFIG_NTB_IDT)		+= idt/
+obj-$(CONFIG_NTB_IDT_QUIRKS)	+= idt/
+obj-$(CONFIG_NTB_INTEL)		+= intel/
drivers/ntb/hw/idt/Kconfig new file +21 -0
new file mode 100644
index 0000000..45b2b01
@@ -0,0 +1,21 @@
+config NTB_IDT
+	tristate "IDT PCIe-switch Non-Transparent Bridge support"
+	depends on PCI
+	help
+	 This driver supports NTB of cappable IDT PCIe-switches.
+
+	 If unsure, say N.
+
+# BAR's early enable quirks
+config NTB_IDT_QUIRKS
+	bool "Enable PCI fixups built-in kernel for IDT PCIe-switch"
+	depends on NTB_IDT
+	default y if NTB_IDT=y
+	select PCI_QUIRKS # NTB_IDT depends on PCI so it's ok to force quirks
+	help
+	 There are some configurations of IDT PCIe-switch which must be made
+	 before the kernel PCI subsystem starts bus-devices scan and
+	 initialization. For instance, the corresponding NT-function BARs must
+	 be enabled. This option builds the fixups into the kernel to bypass
+	 the basic IDT quirks.
+
drivers/ntb/hw/idt/Makefile new file +5 -0
new file mode 100644
index 0000000..3adcd9b
@@ -0,0 +1,5 @@
+# Driver core
+obj-$(CONFIG_NTB_IDT)		+= ntb_hw_idt.o
+
+# BAR's early activation quirk
+obj-$(CONFIG_NTB_IDT_QUIRKS)	+= ntb_hw_idt_quirks.o
drivers/ntb/hw/idt/ntb_hw_idt.c new file +4050 -0

2,965 lines not on this page · raw message

drivers/ntb/hw/idt/ntb_hw_idt.h new file +390 -0

390 lines not on this page · raw message

drivers/ntb/hw/idt/ntb_hw_idt_quirks.c new file +163 -0

163 lines not on this page · raw message

drivers/ntb/hw/idt/ntb_hw_idt_quirks.h new file +114 -0

114 lines not on this page · raw message

drivers/ntb/hw/idt/ntb_hw_idt_regmap.h new file +877 -0

877 lines not on this page · raw message

The rest of this diff is not shown. View the raw message.

Signature · 1 line
2.6.6

Part of the diff is not shown here. View the raw message.

#10 lore raw

PATCH v2 3/3 ntb: Test client drivers for asynchronous NTB devices

In reply to Serge Semin

There are three drivers to independently test all interfaces implemented by the IDT 89HPES*NT* NTB driver.

Doorbells are tested by new NTB Doorbell Pingpong client driver. It implements the so-named algorithm. Driver starts working from setting the peer doorbell of the last locally set doorbell bit. If there has not been locally set doorbell, it sets the very first bit. After that the driver unmasks the events of the just set doorbell bit and waits until the peer sets the same doorbell. When peer does it, the local driver iterates to the next doorbell bit and starts delayed work thread, which will set the corresponding bit and perform doorbell bit umasking on waking up.

Messaging subsystem can be tested by the client driver implementing a simple transmition/reception algorithm. A message can be send to a peer by writing data to /sys/kernel/debug/ntb_msg_test/ntbA{N}/data file. The peer can read it from the same file then.

Memory Windows test driver implements a simple write/read algorithm. The driver allocates the predefined number of local buffers (inbound memory window - inwndw{N}). In order to get a translated base address driver sends a corresponding command to a peer. Then driver initialize the outbound memory windows (outwndw{N}). The read/write operations can be performed using the following debug nodes:
/sys/kernel/debug/ntb_mw_test/ntbA{N}/inwndw{N} /sys/kernel/debug/ntb_mw_test/ntbA{N}/outwndw{N}

---
 drivers/ntb/test/Kconfig        |   32 +
 drivers/ntb/test/Makefile       |    9 +-
 drivers/ntb/test/ntb_db_test.c  |  677 +++++++++++++++++
 drivers/ntb/test/ntb_msg_test.c |  736 +++++++++++++++++++
 drivers/ntb/test/ntb_mw_test.c  | 1539 +++++++++++++++++++++++++++++++++++++++
 5 files changed, 2991 insertions(+), 2 deletions(-)
 create mode 100644 drivers/ntb/test/ntb_db_test.c
 create mode 100644 drivers/ntb/test/ntb_msg_test.c
 create mode 100644 drivers/ntb/test/ntb_mw_test.c
drivers/ntb/test/Kconfig +32 -0
index a5d0eda..80f5058 100644
@@ -25,3 +25,35 @@ config NTB_PERF
 	 to and from the window without additional software interaction.
 
 	 If unsure, say N.
+
+config NTB_DB_TEST
+	tristate "NTB Doorbell Test Client"
+	help
+	 This is a driver to test doorbell subsystem of NTB bus devices.
+	 The design is similar to the ping pong although it exchanges the
+	 doorbell bits one-by-one, waiting for the peer response before getting
+	 to a next doorbell.
+
+	 If unsure, say N.
+
+config NTB_MSG_TEST
+	tristate "NTB Messaging Test Client"
+	help
+	 This is a driver to test messaging subsystem of NTB. It just creates
+	 one file in the DebugFS for each NTB device of asynchronous
+	 architecture. In order to send a message one can just write a text to
+	 the file. It will be immediately sent to the peer so user can get it
+	 by reading from the corresponding file.
+
+	 If unsure, say N.
+
+config NTB_MW_TEST
+	tristate "NTB Memory Windows Test Client"
+	help
+	 This is a driver to test memory sharing amongst devices. It creates a
+	 set of files in the DebugFS, one of which are used to write a text to
+	 outbound memory windows and anothers can be used to read data written
+	 by the peer to our inbound memory window.
+
+	 If unsure, say N.
+
drivers/ntb/test/Makefile +7 -2
index 9e77e0b..6ea6db4 100644
@@ -1,3 +1,8 @@
+# Synchronous hardware clients (Intel/AMD)
 obj-$(CONFIG_NTB_PINGPONG) += ntb_pingpong.o
-obj-$(CONFIG_NTB_TOOL) += ntb_tool.o
-obj-$(CONFIG_NTB_PERF) += ntb_perf.o
+obj-$(CONFIG_NTB_TOOL)     += ntb_tool.o
+obj-$(CONFIG_NTB_PERF)     += ntb_perf.o
+# Asynchronous hardware clients (IDT)
+obj-$(CONFIG_NTB_DB_TEST)  += ntb_db_test.o
+obj-$(CONFIG_NTB_MSG_TEST) += ntb_msg_test.o
+obj-$(CONFIG_NTB_MW_TEST)  += ntb_mw_test.o
drivers/ntb/test/ntb_db_test.c new file +677 -0

677 lines not on this page · raw message

drivers/ntb/test/ntb_msg_test.c new file +736 -0

736 lines not on this page · raw message

drivers/ntb/test/ntb_mw_test.c new file +1539 -0

1,539 lines not on this page · raw message

Signature · 1 line
2.6.6
#11 lore raw

Re: [PATCH v2 3/3] ntb: Test client drivers for asynchronous NTB devices

reproduce:

Hi Serge,

[auto build test WARNING on ntb/ntb-next]
[cannot apply to v4.7 next-20160729]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url:    https://github.com/0day-ci/linux/commits/Serge-Semin/ntb-Asynchronous-NTB-devices-support/20160728-183315
base:   https://github.com/jonmason/ntb ntb-next
config: i386-randconfig-x011-08010912 (attached as .config)
compiler: gcc-6 (Debian 6.1.1-9) 6.1.1 20160705
reproduce:
        # save the attached .config to linux build tree
        make ARCH=i386 

All warnings (new ones prefixed by >>):

drivers/ntb/test/ntb_mw_test.c: In function 'mw_set_outmw_addr':
drivers/ntb/test/ntb_mw_test.c:225:3: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]

     ((void *)(phys_addr_t)(addr))
      ^
>> drivers/ntb/test/ntb_mw_test.c:189:29: note: in expansion of macro 'CAST_DMA_PTR'
     dev_err(&ctx->ntb->dev, ## args)
                                ^~~~
>> drivers/ntb/test/ntb_mw_test.c:419:3: note: in expansion of macro 'dev_err_mw'
      dev_err_mw(ctx,
      ^~~~~~~~~~
   drivers/ntb/test/ntb_mw_test.c:225:3: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
     ((void *)(phys_addr_t)(addr))
      ^
>> drivers/ntb/test/ntb_mw_test.c:189:29: note: in expansion of macro 'CAST_DMA_PTR'
     dev_err(&ctx->ntb->dev, ## args)
                                ^~~~
   drivers/ntb/test/ntb_mw_test.c:429:3: note: in expansion of macro 'dev_err_mw'
      dev_err_mw(ctx, "Failed to set the translated address %p of "
      ^~~~~~~~~~
   drivers/ntb/test/ntb_mw_test.c:225:3: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
     ((void *)(phys_addr_t)(addr))
      ^
>> include/linux/device.h:1206:41: note: in expansion of macro 'CAST_DMA_PTR'
      dev_printk(KERN_DEBUG, dev, format, ##arg); \
                                            ^~~
   drivers/ntb/test/ntb_mw_test.c:195:2: note: in expansion of macro 'dev_dbg'
     dev_dbg(&ctx->ntb->dev, ## args)
     ^~~~~~~
   drivers/ntb/test/ntb_mw_test.c:438:2: note: in expansion of macro 'dev_dbg_mw'
     dev_dbg_mw(ctx, "Outbound memory window %d is initialized with "
     ^~~~~~~~~~
   drivers/ntb/test/ntb_mw_test.c: In function 'mw_dbgfs_outmw_cfg_read':
   drivers/ntb/test/ntb_mw_test.c:225:3: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
     ((void *)(phys_addr_t)(addr))
      ^
   drivers/ntb/test/ntb_mw_test.c:774:30: note: in expansion of macro 'CAST_DMA_PTR'
      "DMA address\t\t- 0x%p\n", CAST_DMA_PTR(wrap->dma_addr));
                                 ^~~~~~~~~~~~
   drivers/ntb/test/ntb_mw_test.c:779:37: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
      "Physycal map address\t- 0x%p\n", (void *)wrap->phys_addr);
                                        ^
   drivers/ntb/test/ntb_mw_test.c: In function 'mw_dbgfs_inmw_cfg_read':
   drivers/ntb/test/ntb_mw_test.c:225:3: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
     ((void *)(phys_addr_t)(addr))
      ^
   drivers/ntb/test/ntb_mw_test.c:923:30: note: in expansion of macro 'CAST_DMA_PTR'
      "DMA address\t\t- 0x%p\n", CAST_DMA_PTR(wrap->dma_addr));
                                 ^~~~~~~~~~~~
   drivers/ntb/test/ntb_mw_test.c: In function 'mw_create_inmws':
   drivers/ntb/test/ntb_mw_test.c:225:3: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
     ((void *)(phys_addr_t)(addr))
      ^
>> drivers/ntb/test/ntb_mw_test.c:189:29: note: in expansion of macro 'CAST_DMA_PTR'
     dev_err(&ctx->ntb->dev, ## args)
                                ^~~~

drivers/ntb/test/ntb_mw_test.c:1204:4: note: in expansion of macro 'dev_err_mw'
dev_err_mw(ctx, "DMA address %p of inbound mw %d isn't " ^~~~~~~~~~

vim +/CAST_DMA_PTR +189 drivers/ntb/test/ntb_mw_test.c

183 }
184
185 /*
186 * Wrapper dev_err/dev_warn/dev_info/dev_dbg macros
187 */
188 #define dev_err_mw(ctx, args...) \

 > 189		dev_err(&ctx->ntb->dev, ## args)
   190	#define dev_warn_mw(ctx, args...) \
   191		dev_warn(&ctx->ntb->dev, ## args)
   192	#define dev_info_mw(ctx, args...) \
   193		dev_info(&ctx->ntb->dev, ## args)
   194	#define dev_dbg_mw(ctx, args...) \
   195		dev_dbg(&ctx->ntb->dev, ## args)
   196	
   197	/*
   198	 * Some common constant used in the driver for better readability:
   199	 * @ON: Enable something
   200	 * @OFF: Disable something
   201	 * @SUCCESS: Success of a function execution
   202	 * @MIN_MW_CNT:	Minimum memory windows count
   203	 * @MAX_MW_CNT: Maximum memory windows count
   204	 */
   205	#define ON ((u32)0x1)
   206	#define OFF ((u32)0x0)
   207	#define SUCCESS 0
   208	#define MIN_MW_CNT ((unsigned char)1)
   209	#define MAX_MW_CNT ((unsigned char)255)
   210	
   211	/*
   212	 * Shared data converter to support the different CPU architectures
   213	 */
   214	#define to_sh32(data) \
   215		cpu_to_le32((data))
   216	#define from_sh32(data) \
   217		le32_to_cpu((data))
   218	
   219	/*
   220	 * Cast DMA address to real address pointer
   221	 *
   222	 * NOTE It's used in the printf's to get rid of warnings
   223	 */
   224	#define CAST_DMA_PTR(addr) \
 > 225		((void *)(phys_addr_t)(addr))

226
227 /*
228 * Module parameters:

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation