Implement NTB Controller using multiple PCI EP
Subsystems (7)
v9 cover Implement NTB Controller using multiple PCI EP
This series is about implementing SW defined Non-Transparent Bridge (NTB) using multiple endpoint (EP) instances. This series has been tested using 2 endpoint instances in J7 connected to J7 board on one end and DRA7 board on the other end. However there is nothing platform specific for the NTB functionality.
This was presented in Linux Plumbers Conference. Link to presentation and video can be found @ [1]
Created a video demo @ [9]
RFC patch series can be found @ [2]
v1 patch series can be found @ [3]
v2 patch series can be found @ [4]
v3 patch series can be found @ [5]
v4 patch series can be found @ [6]
v5 patch series can be found @ [7]
v6 patch series can be found @ [8]
v7 patch series can be found @ [10]
v8 patch series can be found @ [11]
Changes from v8:
1) Do not use devm_request_irq/devm_free_irq as pci_free_irq_vectors() has to be used after free_irq
2) Drop "NTB: tool: Enable the NTB/PCIe link on the local or remote side of bridge" as there is a debugfs entry to enable the link
Changes from v7:
1) Used values stored in ctrl_reg_bar, peer_spad_reg_bar and db_reg_bar instead of hardcoded values in pci_iomap of ntb_hw_epf.c driver
Changes from v6:
1) Fixed issues when multiple NTB devices are creating using multiple functions
2) Fixed issue with writing scratchpad register
3) Created a video demo @ [9]
Changes from v5:
1) Fixed a formatting issue in Kconfig pointed out by Randy
2) Checked for Error or Null in pci_epc_add_epf()
Changes from v4:
1) Fixed error condition checks in pci_epc_add_epf()
Changes from v3:
1) Fixed Documentation edits suggested by Randy Dunlap <[email protected]>
Changes from v2:
1) Add support for the user to create sub-directory of 'EPF Device' directory (for endpoint function specific configuration using configfs).
2) Add documentation for NTB specific attributes in configfs
3) Check for PCI_CLASS_MEMORY_RAM (PCIe class) before binding ntb_hw_epf driver
4) Other documentation fixes
Changes from v1:
1) As per Rob's comment, removed support for creating NTB function device from DT
2) Add support to create NTB EPF device using configfs (added support in configfs to associate primary and secondary EPC with EPF.
Changes from RFC:
1) Converted the DT binding patches to YAML schema and merged the DT binding patches together
2) NTB documentation is converted to .rst
3) One HOST can now interrupt the other HOST using MSI-X interrupts
4) Added support for teardown of memory window and doorbell configuration
5) Add support to provide support 64-bit memory window size from DT
[1] -> https://linuxplumbersconf.org/event/4/contributions/395/
[2] -> http://lore.kernel.org/r/[email protected]
[3] -> http://lore.kernel.org/r/[email protected]
[4] -> http://lore.kernel.org/r/[email protected]
[5] -> http://lore.kernel.org/r/[email protected]
[6] -> http://lore.kernel.org/r/[email protected]
[7] -> http://lore.kernel.org/r/[email protected]
[8] -> http://lore.kernel.org/r/[email protected]
[9] -> https://youtu.be/dLKKxrg5-rY
[10] -> http://lore.kernel.org/r/[email protected]
[11] -> http://lore.kernel.org/r/[email protected]
Kishon Vijay Abraham I (17):
Documentation: PCI: Add specification for the *PCI NTB* function
device
PCI: endpoint: Make *_get_first_free_bar() take into account 64 bit
BAR
PCI: endpoint: Add helper API to get the 'next' unreserved BAR
PCI: endpoint: Make *_free_bar() to return error codes on failure
PCI: endpoint: Remove unused pci_epf_match_device()
PCI: endpoint: Add support to associate secondary EPC with EPF
PCI: endpoint: Add support in configfs to associate two EPCs with EPF
PCI: endpoint: Add pci_epc_ops to map MSI irq
PCI: endpoint: Add pci_epf_ops for epf drivers to expose function
specific attrs
PCI: endpoint: Allow user to create sub-directory of 'EPF Device'
directory
PCI: cadence: Implement ->msi_map_irq() ops
PCI: cadence: Configure LM_EP_FUNC_CFG based on epc->function_num_map
PCI: endpoint: Add EP function driver to provide NTB functionality
PCI: Add TI J721E device to pci ids
NTB: Add support for EPF PCI-Express Non-Transparent Bridge
Documentation: PCI: Add configfs binding documentation for pci-ntb
endpoint function
Documentation: PCI: Add userguide for PCI endpoint NTB function
.../PCI/endpoint/function/binding/pci-ntb.rst | 38 + Documentation/PCI/endpoint/index.rst | 3 + .../PCI/endpoint/pci-endpoint-cfs.rst | 10 + .../PCI/endpoint/pci-ntb-function.rst | 351 +++ Documentation/PCI/endpoint/pci-ntb-howto.rst | 160 ++ drivers/misc/pci_endpoint_test.c | 1 - drivers/ntb/hw/Kconfig | 1 + drivers/ntb/hw/Makefile | 1 + drivers/ntb/hw/epf/Kconfig | 6 + drivers/ntb/hw/epf/Makefile | 1 + drivers/ntb/hw/epf/ntb_hw_epf.c | 754 ++++++ .../pci/controller/cadence/pcie-cadence-ep.c | 60 +- drivers/pci/endpoint/functions/Kconfig | 12 + drivers/pci/endpoint/functions/Makefile | 1 + drivers/pci/endpoint/functions/pci-epf-ntb.c | 2114 +++++++++++++++++ drivers/pci/endpoint/functions/pci-epf-test.c | 13 +- drivers/pci/endpoint/pci-ep-cfs.c | 176 +- drivers/pci/endpoint/pci-epc-core.c | 130 +- drivers/pci/endpoint/pci-epf-core.c | 105 +- include/linux/pci-epc.h | 39 +- include/linux/pci-epf.h | 28 +- include/linux/pci_ids.h | 1 + 22 files changed, 3932 insertions(+), 73 deletions(-) create mode 100644 Documentation/PCI/endpoint/function/binding/pci-ntb.rst create mode 100644 Documentation/PCI/endpoint/pci-ntb-function.rst create mode 100644 Documentation/PCI/endpoint/pci-ntb-howto.rst create mode 100644 drivers/ntb/hw/epf/Kconfig create mode 100644 drivers/ntb/hw/epf/Makefile create mode 100644 drivers/ntb/hw/epf/ntb_hw_epf.c create mode 100644 drivers/pci/endpoint/functions/pci-epf-ntb.c
Signature · 1 line
2.17.1
PATCH v9 1/17 Documentation: PCI: Add specification for the *PCI NTB* function device
Add specification for the *PCI NTB* function device. The endpoint function driver and the host PCI driver should be created based on this specification.
--- Documentation/PCI/endpoint/index.rst | 1 + .../PCI/endpoint/pci-ntb-function.rst | 351 ++++++++++++++++++ 2 files changed, 352 insertions(+) create mode 100644 Documentation/PCI/endpoint/pci-ntb-function.rst
Documentation/PCI/endpoint/index.rst +1 -0
@@ -11,5 +11,6 @@ PCI Endpoint Framework pci-endpoint-cfs pci-test-function pci-test-howto + pci-ntb-function function/binding/pci-test
Documentation/PCI/endpoint/pci-ntb-function.rst new file +351 -0
351 lines not on this page · raw message
Signature · 1 line
2.17.1
Re: [PATCH v9 01/17] Documentation: PCI: Add specification for the *PCI NTB* function device
Quoted 5 lines · Kishon Vijay Abraham I
Add specification for the *PCI NTB* function device. The endpoint function driver and the host PCI driver should be created based on this specification.
Signed-off-by Kishon Vijay Abraham I <[email protected]>
A few typos below if there's opportunity for revisions.
Quoted 31 lines
--- Documentation/PCI/endpoint/index.rst | 1 + .../PCI/endpoint/pci-ntb-function.rst | 351 ++++++++++++++++++ 2 files changed, 352 insertions(+) create mode 100644 Documentation/PCI/endpoint/pci-ntb-function.rstDocumentation/PCI/endpoint/index.rst +1
-0@@ -11,5 +11,6 @@ PCI Endpoint Framework pci-endpoint-cfs pci-test-function pci-test-howto + pci-ntb-function function/binding/pci-testDocumentation/PCI/endpoint/pci-ntb-function.rst new file +8
-0@@ -0,0 +1,351 @@ +.. SPDX-License-Identifier: GPL-2.0 + +================= +PCI NTB Function +================= + +:Author: Kishon Vijay Abraham I <[email protected]> +
Documentation/PCI/endpoint/pci-ntb-function.rst line 18
Quoted 10 lines
Documentation/PCI/endpoint/pci-ntb-function.rst new file +10
-0+PCI Non Transparent Bridges (NTB) allow two host systems to communicate +with each other by exposing each host as a device to the other host. +NTBs typically support the ability to generate interrupts on the remote +machine, expose memory ranges as BARs and perform DMA. They also support +scratchpads which are areas of memory within the NTB that are accessible +from both machines. + +PCI NTB Function allows two different systems (or hosts) to communicate +with each other by configurig the endpoint instances in such a way that +transactions from one system is routed to the other system.
s/is/are/
Documentation/PCI/endpoint/pci-ntb-function.rst line 22
Quoted 3 lines
Documentation/PCI/endpoint/pci-ntb-function.rst new file +3
-0+In the below diagram, PCI NTB function configures the SoC with multiple +PCIe Endpoint (EP) instances in such a way that transaction from one EP +controller is routed to the other EP controller. Once PCI NTB function
s/transaction ... is/transactions ... are/
Quoted 33 lines
Documentation/PCI/endpoint/pci-ntb-function.rst new file +33
-0+configures the SoC with multiple EP instances, HOST1 and HOST2 can +communicate with each other using SoC as a bridge. + +.. code-block:: text + + +-------------+ +-------------+ + | | | | + | HOST1 | | HOST2 | + | | | | + +------^------+ +------^------+ + | | + | | + +---------|-------------------------------------------------|---------+ + | +------v------+ +------v------+ | + | | | | | | + | | EP | | EP | | + | | CONTROLLER1 | | CONTROLLER2 | | + | | <-----------------------------------> | | + | | | | | | + | | | | | | + | | | SoC With Multiple EP Instances | | | + | | | (Configured using NTB Function) | | | + | +-------------+ +-------------+ | + +---------------------------------------------------------------------+ + +Constructs used for Implementing NTB +==================================== + + 1) Config Region + 2) Self Scratchpad Registers + 3) Peer Scratchpad Registers + 4) Doorbell Registers + 5) Memory Window
Documentation/PCI/endpoint/pci-ntb-function.rst line 65
Quoted 10 lines
Documentation/PCI/endpoint/pci-ntb-function.rst new file +10
-0+ + +Config Region: +-------------- + +Config Region is a construct that is specific to NTB implemented using NTB +Endpoint Function Driver. The host and endpoint side NTB function driver will +exchange information with each other using this region. Config Region has +Control/Status Registers for configuring the Endpoint Controller. Host can +write into this region for configuring the outbound ATU and to indicate the
Expand "ATU" since this is the first mention.
Documentation/PCI/endpoint/pci-ntb-function.rst line 68
Quoted 3 lines
Documentation/PCI/endpoint/pci-ntb-function.rst new file +3
-0+link status. Endpoint can indicate the status of commands issued be host in +this region. Endpoint can also indicate the scratchpad offset, number of +memory windows to the host using this region.
s/be host/by host/
s/offset, number/offset and number/
Documentation/PCI/endpoint/pci-ntb-function.rst line 71
Quoted 2 lines
Documentation/PCI/endpoint/pci-ntb-function.rst new file +2
-0+The format of Config Region is given below. Each of the fields here are 32 +bits.
s/Each ... are/All ... are/
Quoted 35 lines
Documentation/PCI/endpoint/pci-ntb-function.rst new file +35
-0+ +.. code-block:: text + + +------------------------+ + | COMMAND | + +------------------------+ + | ARGUMENT | + +------------------------+ + | STATUS | + +------------------------+ + | TOPOLOGY | + +------------------------+ + | ADDRESS (LOWER 32) | + +------------------------+ + | ADDRESS (UPPER 32) | + +------------------------+ + | SIZE | + +------------------------+ + | NO OF MEMORY WINDOW | + +------------------------+ + | MEMORY WINDOW1 OFFSET | + +------------------------+ + | SPAD OFFSET | + +------------------------+ + | SPAD COUNT | + +------------------------+ + | DB ENTRY SIZE | + +------------------------+ + | DB DATA | + +------------------------+ + | : | + +------------------------+ + | : | + +------------------------+ + | DB DATA |
Documentation/PCI/endpoint/pci-ntb-function.rst line 116
Quoted 10 lines
Documentation/PCI/endpoint/pci-ntb-function.rst new file +10
-0+ +------------------------+ + + + COMMAND: + + NTB function supports three commands: + + CMD_CONFIGURE_DOORBELL (0x1): Command to configure doorbell. Before + invoking this command, the host should allocate and initialize + MSI/MSI-X vectors (i.e initialize the MSI/MSI-X capability in the
s/i.e/i.e.,/
Documentation/PCI/endpoint/pci-ntb-function.rst line 119
Quoted 3 lines
Documentation/PCI/endpoint/pci-ntb-function.rst new file +3
-0+ Endpoint). The endpoint on receiving this command will configure + the outbound ATU such that transaction to DB BAR will be routed + to the MSI/MSI-X address programmed by the host. The ARGUMENT
s/transaction to/transactions to/
Expand "DB BAR". I assume this refers to "Doorbell BAR" (which itself is not defined). How do we know which is the Doorbell BAR?
Also, "DB" itself needs to be expanded somehow for uses like below:
Documentation/PCI/endpoint/pci-ntb-function.rst line 131
Quoted 12 lines
Documentation/PCI/endpoint/pci-ntb-function.rst new file +12
-0+ register should be populated with number of DBs to configure (in the + lower 16 bits) and if MSI or MSI-X should be configured (BIT 16). + (TODO: Add support for MSI-X). + + CMD_CONFIGURE_MW (0x2): Command to configure memory window. The + host invokes this command after allocating a buffer that can be + accessed by remote host. The allocated address should be programmed + in the ADDRESS register (64 bit), the size should be programmed in + the SIZE register and the memory window index should be programmed + in the ARGUMENT register. The endpoint on receiving this command + will configure the outbound ATU such that trasaction to MW BAR + will be routed to the address provided by the host.
How do we know which is the MW BAR? I assume "MW" refers to "Memory Window".
Documentation/PCI/endpoint/pci-ntb-function.rst line 137
Quoted 6 lines
Documentation/PCI/endpoint/pci-ntb-function.rst new file +6
-0+ + CMD_LINK_UP (0x3): Command to indicate an NTB application is + bound to the EP device on the host side. Once the endpoint + receives this command from both the hosts, the endpoint will + raise an LINK_UP event to both the hosts to indicate the hosts + can start communicating with each other.
s/raise an/raise a/
I guess this "LINK_UP event" is something other than the PCIe DL_Up state, because each host has already been communicating with the endpoint. Right? Is this LINK_UP a software construct?
Quoted 59 lines
Documentation/PCI/endpoint/pci-ntb-function.rst new file +59
-0+ + ARGUMENT: + + The value of this register is based on the commands issued in + command register. See COMMAND section for more information. + + TOPOLOGY: + + Set to NTB_TOPO_B2B_USD for Primary interface + Set to NTB_TOPO_B2B_DSD for Secondary interface + + ADDRESS/SIZE: + + Address and Size to be used while configuring the memory window. + See "CMD_CONFIGURE_MW" for more info. + + MEMORY WINDOW1 OFFSET: + + Memory Window 1 and Doorbell registers are packed together in the + same BAR. The initial portion of the region will have doorbell + registers and the latter portion of the region is for memory window 1. + This register will specify the offset of the memory window 1. + + NO OF MEMORY WINDOW: + + Specifies the number of memory windows supported by the NTB device. + + SPAD OFFSET: + + Self scratchpad region and config region are packed together in the + same BAR. The initial portion of the region will have config region + and the latter portion of the region is for self scratchpad. This + register will specify the offset of the self scratchpad registers. + + SPAD COUNT: + + Specifies the number of scratchpad registers supported by the NTB + device. + + DB ENTRY SIZE: + + Used to determine the offset within the DB BAR that should be written + in order to raise doorbell. EPF NTB can use either MSI/MSI-X to + ring doorbell (MSI-X support will be added later). MSI uses same + address for all the interrupts and MSI-X can provide different + addresses for different interrupts. The MSI/MSI-X address is provided + by the host and the address it gives is based on the MSI/MSI-X + implementation supported by the host. For instance, ARM platform + using GIC ITS will have same MSI-X address for all the interrupts. + In order to support all the combinations and use the same mechanism + for both MSI and MSI-X, EPF NTB allocates separate region in the + Outbound Address Space for each of the interrupts. This region will + be mapped to the MSI/MSI-X address provided by the host. If a host + provides the same address for all the interrupts, all the regions + will be translated to the same address. If a host provides different + address, the regions will be translated to different address. This + will ensure there is no difference while raising the doorbell. + + DB DATA:
Documentation/PCI/endpoint/pci-ntb-function.rst line 206
Quoted 10 lines
Documentation/PCI/endpoint/pci-ntb-function.rst new file +10
-0+ + EPF NTB supports 32 interrupts. So there are 32 DB DATA registers. + This holds the MSI/MSI-X data that has to be written to MSI address + for raising doorbell interrupt. This will be populated by EPF NTB + while invoking CMD_CONFIGURE_DOORBELL. + +Scratchpad Registers: +--------------------- + + Each host has it's own register space allocated in the memory of NTB EPC.
s/it's/its/
Quoted 15 lines
Documentation/PCI/endpoint/pci-ntb-function.rst new file +15
-0+ They are both readable and writable from both sides of the bridge. They + are used by applications built over NTB and can be used to pass control + and status information between both sides of a device. + + Scratchpad registers has 2 parts + 1) Self Scratchpad: Host's own register space + 2) Peer Scratchpad: Remote host's register space. + +Doorbell Registers: +------------------- + + Registers using which one host can interrupt the other host. + +Memory Window: +--------------
Documentation/PCI/endpoint/pci-ntb-function.rst line 231
Quoted 10 lines
Documentation/PCI/endpoint/pci-ntb-function.rst new file +10
-0+ + Actual transfer of data between the two hosts will happen using the + memory window. + +Modeling Constructs: +==================== + +There are 5 or more distinct regions (config, self scratchpad, peer +scratchpad, doorbell, one or more memory windows) to be modeled to achieve +NTB functionality. Atleast one memory window is required while more than
s/Atleast/At least/
Quoted 123 lines
Documentation/PCI/endpoint/pci-ntb-function.rst new file +120
-0+one is permitted. All these regions should be mapped to BAR for hosts to +access these regions. + +If one 32-bit BAR is allocated for each of these regions, the scheme would +look like + +====== =============== +BAR NO CONSTRUCTS USED +====== =============== +BAR0 Config Region +BAR1 Self Scratchpad +BAR2 Peer Scratchpad +BAR3 Doorbell +BAR4 Memory Window 1 +BAR5 Memory Window 2 +====== =============== + +However if we allocate a separate BAR for each of the region, there would not +be enough BARs for all the regions in a platform that supports only 64-bit +BAR. + +In order to be supported by most of the platforms, the regions should be +packed and mapped to BARs in a way that provides NTB functionality and +also making sure the hosts doesn't access any region that it is not supposed +to. + +The following scheme is used in EPF NTB Function + +====== =============================== +BAR NO CONSTRUCTS USED +====== =============================== +BAR0 Config Region + Self Scratchpad +BAR1 Peer Scratchpad +BAR2 Doorbell + Memory Window 1 +BAR3 Memory Window 2 +BAR4 Memory Window 3 +BAR5 Memory Window 4 +====== =============================== + +With this scheme, for the basic NTB functionality 3 BARs should be sufficient. + +Modeling Config/Scratchpad Region: +---------------------------------- + +.. code-block:: text + + +-----------------+------->+------------------+ +-----------------+ + | BAR0 | | CONFIG REGION | | BAR0 | + +-----------------+----+ +------------------+<-------+-----------------+ + | BAR1 | | |SCRATCHPAD REGION | | BAR1 | + +-----------------+ +-->+------------------+<-------+-----------------+ + | BAR2 | Local Memory | BAR2 | + +-----------------+ +-----------------+ + | BAR3 | | BAR3 | + +-----------------+ +-----------------+ + | BAR4 | | BAR4 | + +-----------------+ +-----------------+ + | BAR5 | | BAR5 | + +-----------------+ +-----------------+ + EP CONTROLLER 1 EP CONTROLLER 2 + +Above diagram shows Config region + Scratchpad region for HOST1 (connected to +EP controller 1) allocated in local memory. The HOST1 can access the config +region and scratchpad region (self scratchpad) using BAR0 of EP controller 1. +The peer host (HOST2 connected to EP controller 2) can also access this +scratchpad region (peer scratchpad) using BAR1 of EP controller 2. This +diagram shows the case where Config region and Scratchpad region is allocated +for HOST1, however the same is applicable for HOST2. + +Modeling Doorbell/Memory Window 1: +---------------------------------- + +.. code-block:: text + + +-----------------+ +----->+----------------+-----------+-----------------+ + | BAR0 | | | Doorbell 1 +-----------> MSI-X ADDRESS 1 | + +-----------------+ | +----------------+ +-----------------+ + | BAR1 | | | Doorbell 2 +---------+ | | + +-----------------+----+ +----------------+ | | | + | BAR2 | | Doorbell 3 +-------+ | +-----------------+ + +-----------------+----+ +----------------+ | +-> MSI-X ADDRESS 2 | + | BAR3 | | | Doorbell 4 +-----+ | +-----------------+ + +-----------------+ | |----------------+ | | | | + | BAR4 | | | | | | +-----------------+ + +-----------------+ | | MW1 +---+ | +-->+ MSI-X ADDRESS 3|| + | BAR5 | | | | | | +-----------------+ + +-----------------+ +----->-----------------+ | | | | + EP CONTROLLER 1 | | | | +-----------------+ + | | | +---->+ MSI-X ADDRESS 4 | + +----------------+ | +-----------------+ + EP CONTROLLER 2 | | | + (OB SPACE) | | | + +-------> MW1 | + | | + | | + +-----------------+ + | | + | | + | | + | | + | | + +-----------------+ + PCI Address Space + (Managed by HOST2) + +Above diagram shows how the doorbell and memory window 1 is mapped so that +HOST1 can raise doorbell interrupt on HOST2 and also how HOST1 can access +buffers exposed by HOST2 using memory window1 (MW1). Here doorbell and +memory window 1 regions are allocated in EP controller 2 outbound (OB) address +space. Allocating and configuring BARs for doorbell and memory window1 +is done during the initialization phase of NTB endpoint function driver. +Mapping from EP controller 2 OB space to PCI address space is done when HOST2 +sends CMD_CONFIGURE_MW/CMD_CONFIGURE_DOORBELL. The commands are explained +below. + +Modeling Optional Memory Windows: +--------------------------------- + +This is modeled the same was as MW1 but each of the additional memory windows +is mapped to separate BARs.Signature · 1 line
2.17.1
Re: [PATCH v9 01/17] Documentation: PCI: Add specification for the *PCI NTB* function device
Hi Bjorn,
Quoted 8 lines · Bjorn Helgaas
Quoted 5 lines · Kishon Vijay Abraham I
Add specification for the *PCI NTB* function device. The endpoint function driver and the host PCI driver should be created based on this specification.
Signed-off-by Kishon Vijay Abraham I <[email protected]>A few typos below if there's opportunity for revisions.
I'll fix them.
Quoted 157 lines
Quoted 32 lines
--- Documentation/PCI/endpoint/index.rst | 1 + .../PCI/endpoint/pci-ntb-function.rst | 351 ++++++++++++++++++ 2 files changed, 352 insertions(+) create mode 100644 Documentation/PCI/endpoint/pci-ntb-function.rstDocumentation/PCI/endpoint/index.rst +1
-0@@ -11,5 +11,6 @@ PCI Endpoint Framework pci-endpoint-cfs pci-test-function pci-test-howto + pci-ntb-function function/binding/pci-testDocumentation/PCI/endpoint/pci-ntb-function.rst new file +8
-0@@ -0,0 +1,351 @@ +.. SPDX-License-Identifier: GPL-2.0 + +================= +PCI NTB Function +================= + +:Author: Kishon Vijay Abraham I <[email protected]> +Documentation/PCI/endpoint/pci-ntb-function.rst line 18
Quoted 10 lines
Documentation/PCI/endpoint/pci-ntb-function.rst new file +10
-0+PCI Non Transparent Bridges (NTB) allow two host systems to communicate +with each other by exposing each host as a device to the other host. +NTBs typically support the ability to generate interrupts on the remote +machine, expose memory ranges as BARs and perform DMA. They also support +scratchpads which are areas of memory within the NTB that are accessible +from both machines. + +PCI NTB Function allows two different systems (or hosts) to communicate +with each other by configurig the endpoint instances in such a way that +transactions from one system is routed to the other system.s/is/are/
Documentation/PCI/endpoint/pci-ntb-function.rst line 22
Quoted 3 lines
Documentation/PCI/endpoint/pci-ntb-function.rst new file +3
-0+In the below diagram, PCI NTB function configures the SoC with multiple +PCIe Endpoint (EP) instances in such a way that transaction from one EP +controller is routed to the other EP controller. Once PCI NTB functions/transaction ... is/transactions ... are/
Quoted 33 lines
Documentation/PCI/endpoint/pci-ntb-function.rst new file +33
-0+configures the SoC with multiple EP instances, HOST1 and HOST2 can +communicate with each other using SoC as a bridge. + +.. code-block:: text + + +-------------+ +-------------+ + | | | | + | HOST1 | | HOST2 | + | | | | + +------^------+ +------^------+ + | | + | | + +---------|-------------------------------------------------|---------+ + | +------v------+ +------v------+ | + | | | | | | + | | EP | | EP | | + | | CONTROLLER1 | | CONTROLLER2 | | + | | <-----------------------------------> | | + | | | | | | + | | | | | | + | | | SoC With Multiple EP Instances | | | + | | | (Configured using NTB Function) | | | + | +-------------+ +-------------+ | + +---------------------------------------------------------------------+ + +Constructs used for Implementing NTB +==================================== + + 1) Config Region + 2) Self Scratchpad Registers + 3) Peer Scratchpad Registers + 4) Doorbell Registers + 5) Memory WindowDocumentation/PCI/endpoint/pci-ntb-function.rst line 65
Quoted 10 lines
Documentation/PCI/endpoint/pci-ntb-function.rst new file +10
-0+ + +Config Region: +-------------- + +Config Region is a construct that is specific to NTB implemented using NTB +Endpoint Function Driver. The host and endpoint side NTB function driver will +exchange information with each other using this region. Config Region has +Control/Status Registers for configuring the Endpoint Controller. Host can +write into this region for configuring the outbound ATU and to indicate theExpand "ATU" since this is the first mention.
Documentation/PCI/endpoint/pci-ntb-function.rst line 68
Quoted 3 lines
Documentation/PCI/endpoint/pci-ntb-function.rst new file +3
-0+link status. Endpoint can indicate the status of commands issued be host in +this region. Endpoint can also indicate the scratchpad offset, number of +memory windows to the host using this region.s/be host/by host/
s/offset, number/offset and number/Documentation/PCI/endpoint/pci-ntb-function.rst line 71
Quoted 2 lines
Documentation/PCI/endpoint/pci-ntb-function.rst new file +2
-0+The format of Config Region is given below. Each of the fields here are 32 +bits.s/Each ... are/All ... are/
Quoted 35 lines
Documentation/PCI/endpoint/pci-ntb-function.rst new file +35
-0+ +.. code-block:: text + + +------------------------+ + | COMMAND | + +------------------------+ + | ARGUMENT | + +------------------------+ + | STATUS | + +------------------------+ + | TOPOLOGY | + +------------------------+ + | ADDRESS (LOWER 32) | + +------------------------+ + | ADDRESS (UPPER 32) | + +------------------------+ + | SIZE | + +------------------------+ + | NO OF MEMORY WINDOW | + +------------------------+ + | MEMORY WINDOW1 OFFSET | + +------------------------+ + | SPAD OFFSET | + +------------------------+ + | SPAD COUNT | + +------------------------+ + | DB ENTRY SIZE | + +------------------------+ + | DB DATA | + +------------------------+ + | : | + +------------------------+ + | : | + +------------------------+ + | DB DATA |Documentation/PCI/endpoint/pci-ntb-function.rst line 116
Quoted 10 lines
Documentation/PCI/endpoint/pci-ntb-function.rst new file +10
-0+ +------------------------+ + + + COMMAND: + + NTB function supports three commands: + + CMD_CONFIGURE_DOORBELL (0x1): Command to configure doorbell. Before + invoking this command, the host should allocate and initialize + MSI/MSI-X vectors (i.e initialize the MSI/MSI-X capability in thes/i.e/i.e.,/
Quoted 8 lines
Documentation/PCI/endpoint/pci-ntb-function.rst line 119
Quoted 3 lines
Documentation/PCI/endpoint/pci-ntb-function.rst new file +3
-0+ Endpoint). The endpoint on receiving this command will configure + the outbound ATU such that transaction to DB BAR will be routed + to the MSI/MSI-X address programmed by the host. The ARGUMENTs/transaction to/transactions to/
Expand "DB BAR". I assume this refers to "Doorbell BAR" (which itself is not defined). How do we know which is the Doorbell BAR?
right doorbell. That part is explained in the "Modeling Constructs" section below.
Quoted 18 lines
Also, "DB" itself needs to be expanded somehow for uses like below:
Documentation/PCI/endpoint/pci-ntb-function.rst line 131
Quoted 12 lines
Documentation/PCI/endpoint/pci-ntb-function.rst new file +12
-0+ register should be populated with number of DBs to configure (in the + lower 16 bits) and if MSI or MSI-X should be configured (BIT 16). + (TODO: Add support for MSI-X). + + CMD_CONFIGURE_MW (0x2): Command to configure memory window. The + host invokes this command after allocating a buffer that can be + accessed by remote host. The allocated address should be programmed + in the ADDRESS register (64 bit), the size should be programmed in + the SIZE register and the memory window index should be programmed + in the ARGUMENT register. The endpoint on receiving this command + will configure the outbound ATU such that trasaction to MW BAR + will be routed to the address provided by the host.How do we know which is the MW BAR? I assume "MW" refers to "Memory Window".
right memory window. That's again explained in the "Modeling Constructs" section below.
Quoted 10 lines
Documentation/PCI/endpoint/pci-ntb-function.rst line 137
Quoted 7 lines
Documentation/PCI/endpoint/pci-ntb-function.rst new file +6
-0+ + CMD_LINK_UP (0x3): Command to indicate an NTB application is + bound to the EP device on the host side. Once the endpoint + receives this command from both the hosts, the endpoint will + raise an LINK_UP event to both the hosts to indicate the hosts + can start communicating with each other.s/raise an/raise a/
Quoted 3 lines
I guess this "
LINK_UPevent" is something other than the PCIeDL_Upstate, because each host has already been communicating with the endpoint. Right? Is thisLINK_UPa software construct?
Yeah. This is when an NTB client application is bound to the NTB device. This is used for handshake between the applications running on the two hosts.
Thanks
Kishon
Re: [PATCH v9 01/17] Documentation: PCI: Add specification for the *PCI NTB* function device
Quoted 8 lines · Kishon Vijay Abraham I
Hi Bjorn,
Quoted 5 lines · Bjorn Helgaas
Quoted 4 lines · Kishon Vijay Abraham I
Add specification for the *PCI NTB* function device. The endpoint function driver and the host PCI driver should be created based on this specification.
Quoted 5 lines
Quoted 3 lines
Quoted 1 line
Signed-off-by Kishon Vijay Abraham I <[email protected]>A few typos below if there's opportunity for revisions.
I'll fix them.
Hi Kishon,
if you have changes please send them along and I will re-merge the whole series.
Thanks,
Lorenzo
Quoted 208 lines
Quoted 156 lines
Quoted 31 lines
--- Documentation/PCI/endpoint/index.rst | 1 + .../PCI/endpoint/pci-ntb-function.rst | 351 ++++++++++++++++++ 2 files changed, 352 insertions(+) create mode 100644 Documentation/PCI/endpoint/pci-ntb-function.rstDocumentation/PCI/endpoint/index.rst +1
-0@@ -11,5 +11,6 @@ PCI Endpoint Framework pci-endpoint-cfs pci-test-function pci-test-howto + pci-ntb-function function/binding/pci-testDocumentation/PCI/endpoint/pci-ntb-function.rst new file +8
-0@@ -0,0 +1,351 @@ +.. SPDX-License-Identifier: GPL-2.0 + +================= +PCI NTB Function +================= + +:Author: Kishon Vijay Abraham I <[email protected]> +Documentation/PCI/endpoint/pci-ntb-function.rst line 18
Quoted 10 lines
Documentation/PCI/endpoint/pci-ntb-function.rst new file +10
-0+PCI Non Transparent Bridges (NTB) allow two host systems to communicate +with each other by exposing each host as a device to the other host. +NTBs typically support the ability to generate interrupts on the remote +machine, expose memory ranges as BARs and perform DMA. They also support +scratchpads which are areas of memory within the NTB that are accessible +from both machines. + +PCI NTB Function allows two different systems (or hosts) to communicate +with each other by configurig the endpoint instances in such a way that +transactions from one system is routed to the other system.s/is/are/
Documentation/PCI/endpoint/pci-ntb-function.rst line 22
Quoted 3 lines
Documentation/PCI/endpoint/pci-ntb-function.rst new file +3
-0+In the below diagram, PCI NTB function configures the SoC with multiple +PCIe Endpoint (EP) instances in such a way that transaction from one EP +controller is routed to the other EP controller. Once PCI NTB functions/transaction ... is/transactions ... are/
Quoted 33 lines
Documentation/PCI/endpoint/pci-ntb-function.rst new file +33
-0+configures the SoC with multiple EP instances, HOST1 and HOST2 can +communicate with each other using SoC as a bridge. + +.. code-block:: text + + +-------------+ +-------------+ + | | | | + | HOST1 | | HOST2 | + | | | | + +------^------+ +------^------+ + | | + | | + +---------|-------------------------------------------------|---------+ + | +------v------+ +------v------+ | + | | | | | | + | | EP | | EP | | + | | CONTROLLER1 | | CONTROLLER2 | | + | | <-----------------------------------> | | + | | | | | | + | | | | | | + | | | SoC With Multiple EP Instances | | | + | | | (Configured using NTB Function) | | | + | +-------------+ +-------------+ | + +---------------------------------------------------------------------+ + +Constructs used for Implementing NTB +==================================== + + 1) Config Region + 2) Self Scratchpad Registers + 3) Peer Scratchpad Registers + 4) Doorbell Registers + 5) Memory WindowDocumentation/PCI/endpoint/pci-ntb-function.rst line 65
Quoted 10 lines
Documentation/PCI/endpoint/pci-ntb-function.rst new file +10
-0+ + +Config Region: +-------------- + +Config Region is a construct that is specific to NTB implemented using NTB +Endpoint Function Driver. The host and endpoint side NTB function driver will +exchange information with each other using this region. Config Region has +Control/Status Registers for configuring the Endpoint Controller. Host can +write into this region for configuring the outbound ATU and to indicate theExpand "ATU" since this is the first mention.
Documentation/PCI/endpoint/pci-ntb-function.rst line 68
Quoted 3 lines
Documentation/PCI/endpoint/pci-ntb-function.rst new file +3
-0+link status. Endpoint can indicate the status of commands issued be host in +this region. Endpoint can also indicate the scratchpad offset, number of +memory windows to the host using this region.s/be host/by host/
s/offset, number/offset and number/Documentation/PCI/endpoint/pci-ntb-function.rst line 71
Quoted 2 lines
Documentation/PCI/endpoint/pci-ntb-function.rst new file +2
-0+The format of Config Region is given below. Each of the fields here are 32 +bits.s/Each ... are/All ... are/
Quoted 35 lines
Documentation/PCI/endpoint/pci-ntb-function.rst new file +35
-0+ +.. code-block:: text + + +------------------------+ + | COMMAND | + +------------------------+ + | ARGUMENT | + +------------------------+ + | STATUS | + +------------------------+ + | TOPOLOGY | + +------------------------+ + | ADDRESS (LOWER 32) | + +------------------------+ + | ADDRESS (UPPER 32) | + +------------------------+ + | SIZE | + +------------------------+ + | NO OF MEMORY WINDOW | + +------------------------+ + | MEMORY WINDOW1 OFFSET | + +------------------------+ + | SPAD OFFSET | + +------------------------+ + | SPAD COUNT | + +------------------------+ + | DB ENTRY SIZE | + +------------------------+ + | DB DATA | + +------------------------+ + | : | + +------------------------+ + | : | + +------------------------+ + | DB DATA |Documentation/PCI/endpoint/pci-ntb-function.rst line 116
Quoted 10 lines
Documentation/PCI/endpoint/pci-ntb-function.rst new file +10
-0+ +------------------------+ + + + COMMAND: + + NTB function supports three commands: + + CMD_CONFIGURE_DOORBELL (0x1): Command to configure doorbell. Before + invoking this command, the host should allocate and initialize + MSI/MSI-X vectors (i.e initialize the MSI/MSI-X capability in thes/i.e/i.e.,/
Quoted 8 lines
Documentation/PCI/endpoint/pci-ntb-function.rst line 119
Quoted 3 lines
Documentation/PCI/endpoint/pci-ntb-function.rst new file +3
-0+ Endpoint). The endpoint on receiving this command will configure + the outbound ATU such that transaction to DB BAR will be routed + to the MSI/MSI-X address programmed by the host. The ARGUMENTs/transaction to/transactions to/
Expand "DB BAR". I assume this refers to "Doorbell BAR" (which itself is not defined). How do we know which is the Doorbell BAR?
right doorbell. That part is explained in the "Modeling Constructs" section below.
Quoted 18 lines
Also, "DB" itself needs to be expanded somehow for uses like below:
Documentation/PCI/endpoint/pci-ntb-function.rst line 131
Quoted 12 lines
Documentation/PCI/endpoint/pci-ntb-function.rst new file +12
-0+ register should be populated with number of DBs to configure (in the + lower 16 bits) and if MSI or MSI-X should be configured (BIT 16). + (TODO: Add support for MSI-X). + + CMD_CONFIGURE_MW (0x2): Command to configure memory window. The + host invokes this command after allocating a buffer that can be + accessed by remote host. The allocated address should be programmed + in the ADDRESS register (64 bit), the size should be programmed in + the SIZE register and the memory window index should be programmed + in the ARGUMENT register. The endpoint on receiving this command + will configure the outbound ATU such that trasaction to MW BAR + will be routed to the address provided by the host.How do we know which is the MW BAR? I assume "MW" refers to "Memory Window".
right memory window. That's again explained in the "Modeling Constructs" section below.
Quoted 10 lines
Documentation/PCI/endpoint/pci-ntb-function.rst line 137
Quoted 7 lines
Documentation/PCI/endpoint/pci-ntb-function.rst new file +6
-0+ + CMD_LINK_UP (0x3): Command to indicate an NTB application is + bound to the EP device on the host side. Once the endpoint + receives this command from both the hosts, the endpoint will + raise an LINK_UP event to both the hosts to indicate the hosts + can start communicating with each other.s/raise an/raise a/
Quoted 3 lines
I guess this "
LINK_UPevent" is something other than the PCIeDL_Upstate, because each host has already been communicating with the endpoint. Right? Is thisLINK_UPa software construct?Yeah. This is when an NTB client application is bound to the NTB device. This is used for handshake between the applications running on the two hosts.
Thanks
Kishon
Re: [PATCH v9 01/17] Documentation: PCI: Add specification for the *PCI NTB* function device
Hi Lorenzo,
Quoted 11 lines · Lorenzo Pieralisi
Quoted 10 lines · Kishon Vijay Abraham I
Hi Bjorn,
Quoted 7 lines · Bjorn Helgaas
Quoted 5 lines · Kishon Vijay Abraham I
Add specification for the *PCI NTB* function device. The endpoint function driver and the host PCI driver should be created based on this specification.
Signed-off-by Kishon Vijay Abraham I <[email protected]>
Quoted 8 lines
Quoted 3 lines
Quoted 1 line
A few typos below if there's opportunity for revisions.
I'll fix them.
Hi Kishon,
if you have changes please send them along and I will re-merge the whole series.
I'll resend by tomorrow. Hope that's fine.
Thank You,
Kishon
Quoted 212 lines
Thanks,
LorenzoQuoted 208 lines
Quoted 156 lines
Quoted 31 lines
--- Documentation/PCI/endpoint/index.rst | 1 + .../PCI/endpoint/pci-ntb-function.rst | 351 ++++++++++++++++++ 2 files changed, 352 insertions(+) create mode 100644 Documentation/PCI/endpoint/pci-ntb-function.rstDocumentation/PCI/endpoint/index.rst +1
-0@@ -11,5 +11,6 @@ PCI Endpoint Framework pci-endpoint-cfs pci-test-function pci-test-howto + pci-ntb-function function/binding/pci-testDocumentation/PCI/endpoint/pci-ntb-function.rst new file +8
-0@@ -0,0 +1,351 @@ +.. SPDX-License-Identifier: GPL-2.0 + +================= +PCI NTB Function +================= + +:Author: Kishon Vijay Abraham I <[email protected]> +Documentation/PCI/endpoint/pci-ntb-function.rst line 18
Quoted 10 lines
Documentation/PCI/endpoint/pci-ntb-function.rst new file +10
-0+PCI Non Transparent Bridges (NTB) allow two host systems to communicate +with each other by exposing each host as a device to the other host. +NTBs typically support the ability to generate interrupts on the remote +machine, expose memory ranges as BARs and perform DMA. They also support +scratchpads which are areas of memory within the NTB that are accessible +from both machines. + +PCI NTB Function allows two different systems (or hosts) to communicate +with each other by configurig the endpoint instances in such a way that +transactions from one system is routed to the other system.s/is/are/
Documentation/PCI/endpoint/pci-ntb-function.rst line 22
Quoted 3 lines
Documentation/PCI/endpoint/pci-ntb-function.rst new file +3
-0+In the below diagram, PCI NTB function configures the SoC with multiple +PCIe Endpoint (EP) instances in such a way that transaction from one EP +controller is routed to the other EP controller. Once PCI NTB functions/transaction ... is/transactions ... are/
Quoted 33 lines
Documentation/PCI/endpoint/pci-ntb-function.rst new file +33
-0+configures the SoC with multiple EP instances, HOST1 and HOST2 can +communicate with each other using SoC as a bridge. + +.. code-block:: text + + +-------------+ +-------------+ + | | | | + | HOST1 | | HOST2 | + | | | | + +------^------+ +------^------+ + | | + | | + +---------|-------------------------------------------------|---------+ + | +------v------+ +------v------+ | + | | | | | | + | | EP | | EP | | + | | CONTROLLER1 | | CONTROLLER2 | | + | | <-----------------------------------> | | + | | | | | | + | | | | | | + | | | SoC With Multiple EP Instances | | | + | | | (Configured using NTB Function) | | | + | +-------------+ +-------------+ | + +---------------------------------------------------------------------+ + +Constructs used for Implementing NTB +==================================== + + 1) Config Region + 2) Self Scratchpad Registers + 3) Peer Scratchpad Registers + 4) Doorbell Registers + 5) Memory WindowDocumentation/PCI/endpoint/pci-ntb-function.rst line 65
Quoted 10 lines
Documentation/PCI/endpoint/pci-ntb-function.rst new file +10
-0+ + +Config Region: +-------------- + +Config Region is a construct that is specific to NTB implemented using NTB +Endpoint Function Driver. The host and endpoint side NTB function driver will +exchange information with each other using this region. Config Region has +Control/Status Registers for configuring the Endpoint Controller. Host can +write into this region for configuring the outbound ATU and to indicate theExpand "ATU" since this is the first mention.
Documentation/PCI/endpoint/pci-ntb-function.rst line 68
Quoted 3 lines
Documentation/PCI/endpoint/pci-ntb-function.rst new file +3
-0+link status. Endpoint can indicate the status of commands issued be host in +this region. Endpoint can also indicate the scratchpad offset, number of +memory windows to the host using this region.s/be host/by host/
s/offset, number/offset and number/Documentation/PCI/endpoint/pci-ntb-function.rst line 71
Quoted 2 lines
Documentation/PCI/endpoint/pci-ntb-function.rst new file +2
-0+The format of Config Region is given below. Each of the fields here are 32 +bits.s/Each ... are/All ... are/
Quoted 35 lines
Documentation/PCI/endpoint/pci-ntb-function.rst new file +35
-0+ +.. code-block:: text + + +------------------------+ + | COMMAND | + +------------------------+ + | ARGUMENT | + +------------------------+ + | STATUS | + +------------------------+ + | TOPOLOGY | + +------------------------+ + | ADDRESS (LOWER 32) | + +------------------------+ + | ADDRESS (UPPER 32) | + +------------------------+ + | SIZE | + +------------------------+ + | NO OF MEMORY WINDOW | + +------------------------+ + | MEMORY WINDOW1 OFFSET | + +------------------------+ + | SPAD OFFSET | + +------------------------+ + | SPAD COUNT | + +------------------------+ + | DB ENTRY SIZE | + +------------------------+ + | DB DATA | + +------------------------+ + | : | + +------------------------+ + | : | + +------------------------+ + | DB DATA |Documentation/PCI/endpoint/pci-ntb-function.rst line 116
Quoted 10 lines
Documentation/PCI/endpoint/pci-ntb-function.rst new file +10
-0+ +------------------------+ + + + COMMAND: + + NTB function supports three commands: + + CMD_CONFIGURE_DOORBELL (0x1): Command to configure doorbell. Before + invoking this command, the host should allocate and initialize + MSI/MSI-X vectors (i.e initialize the MSI/MSI-X capability in thes/i.e/i.e.,/
Quoted 8 lines
Documentation/PCI/endpoint/pci-ntb-function.rst line 119
Quoted 3 lines
Documentation/PCI/endpoint/pci-ntb-function.rst new file +3
-0+ Endpoint). The endpoint on receiving this command will configure + the outbound ATU such that transaction to DB BAR will be routed + to the MSI/MSI-X address programmed by the host. The ARGUMENTs/transaction to/transactions to/
Expand "DB BAR". I assume this refers to "Doorbell BAR" (which itself is not defined). How do we know which is the Doorbell BAR?
right doorbell. That part is explained in the "Modeling Constructs" section below.
Quoted 18 lines
Also, "DB" itself needs to be expanded somehow for uses like below:
Documentation/PCI/endpoint/pci-ntb-function.rst line 131
Quoted 12 lines
Documentation/PCI/endpoint/pci-ntb-function.rst new file +12
-0+ register should be populated with number of DBs to configure (in the + lower 16 bits) and if MSI or MSI-X should be configured (BIT 16). + (TODO: Add support for MSI-X). + + CMD_CONFIGURE_MW (0x2): Command to configure memory window. The + host invokes this command after allocating a buffer that can be + accessed by remote host. The allocated address should be programmed + in the ADDRESS register (64 bit), the size should be programmed in + the SIZE register and the memory window index should be programmed + in the ARGUMENT register. The endpoint on receiving this command + will configure the outbound ATU such that trasaction to MW BAR + will be routed to the address provided by the host.How do we know which is the MW BAR? I assume "MW" refers to "Memory Window".
right memory window. That's again explained in the "Modeling Constructs" section below.
Quoted 10 lines
Documentation/PCI/endpoint/pci-ntb-function.rst line 137
Quoted 7 lines
Documentation/PCI/endpoint/pci-ntb-function.rst new file +6
-0+ + CMD_LINK_UP (0x3): Command to indicate an NTB application is + bound to the EP device on the host side. Once the endpoint + receives this command from both the hosts, the endpoint will + raise an LINK_UP event to both the hosts to indicate the hosts + can start communicating with each other.s/raise an/raise a/
Quoted 3 lines
I guess this "
LINK_UPevent" is something other than the PCIeDL_Upstate, because each host has already been communicating with the endpoint. Right? Is thisLINK_UPa software construct?Yeah. This is when an NTB client application is bound to the NTB device. This is used for handshake between the applications running on the two hosts.
Thanks
Kishon
Randy Dunlap
reviewerRe: [PATCH v9 01/17] Documentation: PCI: Add specification for the *PCI NTB* function device
In reply to Kishon Vijay Abraham IQuoted 18 lines · Kishon Vijay Abraham I
Add specification for the *PCI NTB* function device. The endpoint function driver and the host PCI driver should be created based on this specification.
Signed-off-by Kishon Vijay Abraham I <[email protected]>--- Documentation/PCI/endpoint/index.rst | 1 + .../PCI/endpoint/pci-ntb-function.rst | 351 ++++++++++++++++++ 2 files changed, 352 insertions(+) create mode 100644 Documentation/PCI/endpoint/pci-ntb-function.rstDocumentation/PCI/endpoint/pci-ntb-function.rst new file +0
-0
Documentation/PCI/endpoint/pci-ntb-function.rst line 9
Quoted 9 lines
Documentation/PCI/endpoint/pci-ntb-function.rst new file +9
-0@@ -0,0 +1,351 @@ +.. SPDX-License-Identifier: GPL-2.0 + +================= +PCI NTB Function +================= + +:Author: Kishon Vijay Abraham I <[email protected]> + +PCI Non Transparent Bridges (NTB) allow two host systems to communicate
preferably
Non-Transparent
Quoted 46 lines
Documentation/PCI/endpoint/pci-ntb-function.rst new file +46
-0+with each other by exposing each host as a device to the other host. +NTBs typically support the ability to generate interrupts on the remote +machine, expose memory ranges as BARs and perform DMA. They also support +scratchpads which are areas of memory within the NTB that are accessible +from both machines. + +PCI NTB Function allows two different systems (or hosts) to communicate +with each other by configurig the endpoint instances in such a way that +transactions from one system is routed to the other system. + +In the below diagram, PCI NTB function configures the SoC with multiple +PCIe Endpoint (EP) instances in such a way that transaction from one EP +controller is routed to the other EP controller. Once PCI NTB function +configures the SoC with multiple EP instances, HOST1 and HOST2 can +communicate with each other using SoC as a bridge. + +.. code-block:: text + + +-------------+ +-------------+ + | | | | + | HOST1 | | HOST2 | + | | | | + +------^------+ +------^------+ + | | + | | + +---------|-------------------------------------------------|---------+ + | +------v------+ +------v------+ | + | | | | | | + | | EP | | EP | | + | | CONTROLLER1 | | CONTROLLER2 | | + | | <-----------------------------------> | | + | | | | | | + | | | | | | + | | | SoC With Multiple EP Instances | | | + | | | (Configured using NTB Function) | | | + | +-------------+ +-------------+ | + +---------------------------------------------------------------------+ + +Constructs used for Implementing NTB +==================================== + + 1) Config Region + 2) Self Scratchpad Registers + 3) Peer Scratchpad Registers + 4) Doorbell Registers + 5) Memory Window
Documentation/PCI/endpoint/pci-ntb-function.rst line 65
Quoted 10 lines
Documentation/PCI/endpoint/pci-ntb-function.rst new file +10
-0+ + +Config Region: +-------------- + +Config Region is a construct that is specific to NTB implemented using NTB +Endpoint Function Driver. The host and endpoint side NTB function driver will +exchange information with each other using this region. Config Region has +Control/Status Registers for configuring the Endpoint Controller. Host can +write into this region for configuring the outbound ATU and to indicate the
what is ATU?
Documentation/PCI/endpoint/pci-ntb-function.rst line 66
Quoted 1 line
Documentation/PCI/endpoint/pci-ntb-function.rst new file +1
-0+link status. Endpoint can indicate the status of commands issued be host in
by ??
Documentation/PCI/endpoint/pci-ntb-function.rst line 70
Quoted 4 lines
Documentation/PCI/endpoint/pci-ntb-function.rst new file +4
-0+this region. Endpoint can also indicate the scratchpad offset, number of +memory windows to the host using this region. + +The format of Config Region is given below. Each of the fields here are 32
Each is
Quoted 36 lines
Documentation/PCI/endpoint/pci-ntb-function.rst new file +36
-0+bits. + +.. code-block:: text + + +------------------------+ + | COMMAND | + +------------------------+ + | ARGUMENT | + +------------------------+ + | STATUS | + +------------------------+ + | TOPOLOGY | + +------------------------+ + | ADDRESS (LOWER 32) | + +------------------------+ + | ADDRESS (UPPER 32) | + +------------------------+ + | SIZE | + +------------------------+ + | NO OF MEMORY WINDOW | + +------------------------+ + | MEMORY WINDOW1 OFFSET | + +------------------------+ + | SPAD OFFSET | + +------------------------+ + | SPAD COUNT | + +------------------------+ + | DB ENTRY SIZE | + +------------------------+ + | DB DATA | + +------------------------+ + | : | + +------------------------+ + | : | + +------------------------+ + | DB DATA |
Documentation/PCI/endpoint/pci-ntb-function.rst line 116
Quoted 10 lines
Documentation/PCI/endpoint/pci-ntb-function.rst new file +10
-0+ +------------------------+ + + + COMMAND: + + NTB function supports three commands: + + CMD_CONFIGURE_DOORBELL (0x1): Command to configure doorbell. Before + invoking this command, the host should allocate and initialize + MSI/MSI-X vectors (i.e initialize the MSI/MSI-X capability in the
i.e.
Quoted 4 lines
Documentation/PCI/endpoint/pci-ntb-function.rst new file +4
-0+ Endpoint). The endpoint on receiving this command will configure + the outbound ATU such that transaction to DB BAR will be routed + to the MSI/MSI-X address programmed by the host. The ARGUMENT + register should be populated with number of DBs to configure (in the
Documentation/PCI/endpoint/pci-ntb-function.rst line 130
Quoted 10 lines
Documentation/PCI/endpoint/pci-ntb-function.rst new file +10
-0+ lower 16 bits) and if MSI or MSI-X should be configured (BIT 16). + (TODO: Add support for MSI-X). + + CMD_CONFIGURE_MW (0x2): Command to configure memory window. The + host invokes this command after allocating a buffer that can be + accessed by remote host. The allocated address should be programmed + in the ADDRESS register (64 bit), the size should be programmed in + the SIZE register and the memory window index should be programmed + in the ARGUMENT register. The endpoint on receiving this command + will configure the outbound ATU such that trasaction to MW BAR
transaction
Quoted 66 lines
Documentation/PCI/endpoint/pci-ntb-function.rst new file +66
-0+ will be routed to the address provided by the host. + + CMD_LINK_UP (0x3): Command to indicate an NTB application is + bound to the EP device on the host side. Once the endpoint + receives this command from both the hosts, the endpoint will + raise an LINK_UP event to both the hosts to indicate the hosts + can start communicating with each other. + + ARGUMENT: + + The value of this register is based on the commands issued in + command register. See COMMAND section for more information. + + TOPOLOGY: + + Set to NTB_TOPO_B2B_USD for Primary interface + Set to NTB_TOPO_B2B_DSD for Secondary interface + + ADDRESS/SIZE: + + Address and Size to be used while configuring the memory window. + See "CMD_CONFIGURE_MW" for more info. + + MEMORY WINDOW1 OFFSET: + + Memory Window 1 and Doorbell registers are packed together in the + same BAR. The initial portion of the region will have doorbell + registers and the latter portion of the region is for memory window 1. + This register will specify the offset of the memory window 1. + + NO OF MEMORY WINDOW: + + Specifies the number of memory windows supported by the NTB device. + + SPAD OFFSET: + + Self scratchpad region and config region are packed together in the + same BAR. The initial portion of the region will have config region + and the latter portion of the region is for self scratchpad. This + register will specify the offset of the self scratchpad registers. + + SPAD COUNT: + + Specifies the number of scratchpad registers supported by the NTB + device. + + DB ENTRY SIZE: + + Used to determine the offset within the DB BAR that should be written + in order to raise doorbell. EPF NTB can use either MSI/MSI-X to + ring doorbell (MSI-X support will be added later). MSI uses same + address for all the interrupts and MSI-X can provide different + addresses for different interrupts. The MSI/MSI-X address is provided + by the host and the address it gives is based on the MSI/MSI-X + implementation supported by the host. For instance, ARM platform + using GIC ITS will have same MSI-X address for all the interrupts. + In order to support all the combinations and use the same mechanism + for both MSI and MSI-X, EPF NTB allocates separate region in the + Outbound Address Space for each of the interrupts. This region will + be mapped to the MSI/MSI-X address provided by the host. If a host + provides the same address for all the interrupts, all the regions + will be translated to the same address. If a host provides different + address, the regions will be translated to different address. This + will ensure there is no difference while raising the doorbell. + + DB DATA:
Documentation/PCI/endpoint/pci-ntb-function.rst line 206
Quoted 10 lines
Documentation/PCI/endpoint/pci-ntb-function.rst new file +10
-0+ + EPF NTB supports 32 interrupts. So there are 32 DB DATA registers. + This holds the MSI/MSI-X data that has to be written to MSI address + for raising doorbell interrupt. This will be populated by EPF NTB + while invoking CMD_CONFIGURE_DOORBELL. + +Scratchpad Registers: +--------------------- + + Each host has it's own register space allocated in the memory of NTB EPC.
its
[it's means "it is"]
Documentation/PCI/endpoint/pci-ntb-function.rst line 218
Quoted 12 lines
Documentation/PCI/endpoint/pci-ntb-function.rst new file +12
-0+ They are both readable and writable from both sides of the bridge. They + are used by applications built over NTB and can be used to pass control + and status information between both sides of a device. + + Scratchpad registers has 2 parts + 1) Self Scratchpad: Host's own register space + 2) Peer Scratchpad: Remote host's register space. + +Doorbell Registers: +------------------- + + Registers using which one host can interrupt the other host.
eh? ENOPARSE.
Documentation/PCI/endpoint/pci-ntb-function.rst line 231
Quoted 13 lines
Documentation/PCI/endpoint/pci-ntb-function.rst new file +13
-0+ +Memory Window: +-------------- + + Actual transfer of data between the two hosts will happen using the + memory window. + +Modeling Constructs: +==================== + +There are 5 or more distinct regions (config, self scratchpad, peer +scratchpad, doorbell, one or more memory windows) to be modeled to achieve +NTB functionality. Atleast one memory window is required while more than
At least
Quoted 8 lines
Documentation/PCI/endpoint/pci-ntb-function.rst new file +8
-0+one is permitted. All these regions should be mapped to BAR for hosts to +access these regions. + +If one 32-bit BAR is allocated for each of these regions, the scheme would +look like + +====== =============== +BAR NO CONSTRUCTS USED
Documentation/PCI/endpoint/pci-ntb-function.rst line 249
Quoted 10 lines
Documentation/PCI/endpoint/pci-ntb-function.rst new file +10
-0+====== =============== +BAR0 Config Region +BAR1 Self Scratchpad +BAR2 Peer Scratchpad +BAR3 Doorbell +BAR4 Memory Window 1 +BAR5 Memory Window 2 +====== =============== + +However if we allocate a separate BAR for each of the region, there would not
regions,
Quoted 86 lines
Documentation/PCI/endpoint/pci-ntb-function.rst new file +86
-0+be enough BARs for all the regions in a platform that supports only 64-bit +BAR. + +In order to be supported by most of the platforms, the regions should be +packed and mapped to BARs in a way that provides NTB functionality and +also making sure the hosts doesn't access any region that it is not supposed +to. + +The following scheme is used in EPF NTB Function + +====== =============================== +BAR NO CONSTRUCTS USED +====== =============================== +BAR0 Config Region + Self Scratchpad +BAR1 Peer Scratchpad +BAR2 Doorbell + Memory Window 1 +BAR3 Memory Window 2 +BAR4 Memory Window 3 +BAR5 Memory Window 4 +====== =============================== + +With this scheme, for the basic NTB functionality 3 BARs should be sufficient. + +Modeling Config/Scratchpad Region: +---------------------------------- + +.. code-block:: text + + +-----------------+------->+------------------+ +-----------------+ + | BAR0 | | CONFIG REGION | | BAR0 | + +-----------------+----+ +------------------+<-------+-----------------+ + | BAR1 | | |SCRATCHPAD REGION | | BAR1 | + +-----------------+ +-->+------------------+<-------+-----------------+ + | BAR2 | Local Memory | BAR2 | + +-----------------+ +-----------------+ + | BAR3 | | BAR3 | + +-----------------+ +-----------------+ + | BAR4 | | BAR4 | + +-----------------+ +-----------------+ + | BAR5 | | BAR5 | + +-----------------+ +-----------------+ + EP CONTROLLER 1 EP CONTROLLER 2 + +Above diagram shows Config region + Scratchpad region for HOST1 (connected to +EP controller 1) allocated in local memory. The HOST1 can access the config +region and scratchpad region (self scratchpad) using BAR0 of EP controller 1. +The peer host (HOST2 connected to EP controller 2) can also access this +scratchpad region (peer scratchpad) using BAR1 of EP controller 2. This +diagram shows the case where Config region and Scratchpad region is allocated +for HOST1, however the same is applicable for HOST2. + +Modeling Doorbell/Memory Window 1: +---------------------------------- + +.. code-block:: text + + +-----------------+ +----->+----------------+-----------+-----------------+ + | BAR0 | | | Doorbell 1 +-----------> MSI-X ADDRESS 1 | + +-----------------+ | +----------------+ +-----------------+ + | BAR1 | | | Doorbell 2 +---------+ | | + +-----------------+----+ +----------------+ | | | + | BAR2 | | Doorbell 3 +-------+ | +-----------------+ + +-----------------+----+ +----------------+ | +-> MSI-X ADDRESS 2 | + | BAR3 | | | Doorbell 4 +-----+ | +-----------------+ + +-----------------+ | |----------------+ | | | | + | BAR4 | | | | | | +-----------------+ + +-----------------+ | | MW1 +---+ | +-->+ MSI-X ADDRESS 3|| + | BAR5 | | | | | | +-----------------+ + +-----------------+ +----->-----------------+ | | | | + EP CONTROLLER 1 | | | | +-----------------+ + | | | +---->+ MSI-X ADDRESS 4 | + +----------------+ | +-----------------+ + EP CONTROLLER 2 | | | + (OB SPACE) | | | + +-------> MW1 | + | | + | | + +-----------------+ + | | + | | + | | + | | + | | + +-----------------+ + PCI Address Space + (Managed by HOST2)
Documentation/PCI/endpoint/pci-ntb-function.rst line 345
Quoted 10 lines
Documentation/PCI/endpoint/pci-ntb-function.rst new file +10
-0+ +Above diagram shows how the doorbell and memory window 1 is mapped so that +HOST1 can raise doorbell interrupt on HOST2 and also how HOST1 can access +buffers exposed by HOST2 using memory window1 (MW1). Here doorbell and +memory window 1 regions are allocated in EP controller 2 outbound (OB) address +space. Allocating and configuring BARs for doorbell and memory window1 +is done during the initialization phase of NTB endpoint function driver. +Mapping from EP controller 2 OB space to PCI address space is done when HOST2 +sends CMD_CONFIGURE_MW/CMD_CONFIGURE_DOORBELL. The commands are explained +below.
below??
Documentation/PCI/endpoint/pci-ntb-function.rst line 351
Quoted 7 lines
Documentation/PCI/endpoint/pci-ntb-function.rst new file +6
-0+ +Modeling Optional Memory Windows: +--------------------------------- + +This is modeled the same was as MW1 but each of the additional memory windows +is mapped to separate BARs.
Is all of this register/memory space mapping defined in some PCI NTB spec or is this specific to some hardware/SoC implementation?
HTH.
Signature · 1 line
~Randy
Re: [PATCH v9 01/17] Documentation: PCI: Add specification for the *PCI NTB* function device
Hi Randy,
Quoted 390 lines · Randy Dunlap
Quoted 18 lines · Kishon Vijay Abraham I
Add specification for the *PCI NTB* function device. The endpoint function driver and the host PCI driver should be created based on this specification.
Signed-off-by Kishon Vijay Abraham I <[email protected]>--- Documentation/PCI/endpoint/index.rst | 1 + .../PCI/endpoint/pci-ntb-function.rst | 351 ++++++++++++++++++ 2 files changed, 352 insertions(+) create mode 100644 Documentation/PCI/endpoint/pci-ntb-function.rstDocumentation/PCI/endpoint/pci-ntb-function.rst new file +0
-0Documentation/PCI/endpoint/pci-ntb-function.rst line 9
Quoted 9 lines
Documentation/PCI/endpoint/pci-ntb-function.rst new file +9
-0@@ -0,0 +1,351 @@ +.. SPDX-License-Identifier: GPL-2.0 + +================= +PCI NTB Function +================= + +:Author: Kishon Vijay Abraham I <[email protected]> + +PCI Non Transparent Bridges (NTB) allow two host systems to communicatepreferably
Non-TransparentQuoted 46 lines
Documentation/PCI/endpoint/pci-ntb-function.rst new file +46
-0+with each other by exposing each host as a device to the other host. +NTBs typically support the ability to generate interrupts on the remote +machine, expose memory ranges as BARs and perform DMA. They also support +scratchpads which are areas of memory within the NTB that are accessible +from both machines. + +PCI NTB Function allows two different systems (or hosts) to communicate +with each other by configurig the endpoint instances in such a way that +transactions from one system is routed to the other system. + +In the below diagram, PCI NTB function configures the SoC with multiple +PCIe Endpoint (EP) instances in such a way that transaction from one EP +controller is routed to the other EP controller. Once PCI NTB function +configures the SoC with multiple EP instances, HOST1 and HOST2 can +communicate with each other using SoC as a bridge. + +.. code-block:: text + + +-------------+ +-------------+ + | | | | + | HOST1 | | HOST2 | + | | | | + +------^------+ +------^------+ + | | + | | + +---------|-------------------------------------------------|---------+ + | +------v------+ +------v------+ | + | | | | | | + | | EP | | EP | | + | | CONTROLLER1 | | CONTROLLER2 | | + | | <-----------------------------------> | | + | | | | | | + | | | | | | + | | | SoC With Multiple EP Instances | | | + | | | (Configured using NTB Function) | | | + | +-------------+ +-------------+ | + +---------------------------------------------------------------------+ + +Constructs used for Implementing NTB +==================================== + + 1) Config Region + 2) Self Scratchpad Registers + 3) Peer Scratchpad Registers + 4) Doorbell Registers + 5) Memory WindowDocumentation/PCI/endpoint/pci-ntb-function.rst line 65
Quoted 10 lines
Documentation/PCI/endpoint/pci-ntb-function.rst new file +10
-0+ + +Config Region: +-------------- + +Config Region is a construct that is specific to NTB implemented using NTB +Endpoint Function Driver. The host and endpoint side NTB function driver will +exchange information with each other using this region. Config Region has +Control/Status Registers for configuring the Endpoint Controller. Host can +write into this region for configuring the outbound ATU and to indicate thewhat is ATU?
Documentation/PCI/endpoint/pci-ntb-function.rst line 66
Quoted 1 line
Documentation/PCI/endpoint/pci-ntb-function.rst new file +1
-0+link status. Endpoint can indicate the status of commands issued be host inby ??Documentation/PCI/endpoint/pci-ntb-function.rst line 70
Quoted 4 lines
Documentation/PCI/endpoint/pci-ntb-function.rst new file +4
-0+this region. Endpoint can also indicate the scratchpad offset, number of +memory windows to the host using this region. + +The format of Config Region is given below. Each of the fields here are 32Each is
Quoted 36 lines
Documentation/PCI/endpoint/pci-ntb-function.rst new file +36
-0+bits. + +.. code-block:: text + + +------------------------+ + | COMMAND | + +------------------------+ + | ARGUMENT | + +------------------------+ + | STATUS | + +------------------------+ + | TOPOLOGY | + +------------------------+ + | ADDRESS (LOWER 32) | + +------------------------+ + | ADDRESS (UPPER 32) | + +------------------------+ + | SIZE | + +------------------------+ + | NO OF MEMORY WINDOW | + +------------------------+ + | MEMORY WINDOW1 OFFSET | + +------------------------+ + | SPAD OFFSET | + +------------------------+ + | SPAD COUNT | + +------------------------+ + | DB ENTRY SIZE | + +------------------------+ + | DB DATA | + +------------------------+ + | : | + +------------------------+ + | : | + +------------------------+ + | DB DATA |Documentation/PCI/endpoint/pci-ntb-function.rst line 116
Quoted 10 lines
Documentation/PCI/endpoint/pci-ntb-function.rst new file +10
-0+ +------------------------+ + + + COMMAND: + + NTB function supports three commands: + + CMD_CONFIGURE_DOORBELL (0x1): Command to configure doorbell. Before + invoking this command, the host should allocate and initialize + MSI/MSI-X vectors (i.e initialize the MSI/MSI-X capability in thei.e.Quoted 4 lines
Documentation/PCI/endpoint/pci-ntb-function.rst new file +4
-0+ Endpoint). The endpoint on receiving this command will configure + the outbound ATU such that transaction to DB BAR will be routed + to the MSI/MSI-X address programmed by the host. The ARGUMENT + register should be populated with number of DBs to configure (in theDocumentation/PCI/endpoint/pci-ntb-function.rst line 130
Quoted 10 lines
Documentation/PCI/endpoint/pci-ntb-function.rst new file +10
-0+ lower 16 bits) and if MSI or MSI-X should be configured (BIT 16). + (TODO: Add support for MSI-X). + + CMD_CONFIGURE_MW (0x2): Command to configure memory window. The + host invokes this command after allocating a buffer that can be + accessed by remote host. The allocated address should be programmed + in the ADDRESS register (64 bit), the size should be programmed in + the SIZE register and the memory window index should be programmed + in the ARGUMENT register. The endpoint on receiving this command + will configure the outbound ATU such that trasaction to MW BARtransaction
Quoted 66 lines
Documentation/PCI/endpoint/pci-ntb-function.rst new file +66
-0+ will be routed to the address provided by the host. + + CMD_LINK_UP (0x3): Command to indicate an NTB application is + bound to the EP device on the host side. Once the endpoint + receives this command from both the hosts, the endpoint will + raise an LINK_UP event to both the hosts to indicate the hosts + can start communicating with each other. + + ARGUMENT: + + The value of this register is based on the commands issued in + command register. See COMMAND section for more information. + + TOPOLOGY: + + Set to NTB_TOPO_B2B_USD for Primary interface + Set to NTB_TOPO_B2B_DSD for Secondary interface + + ADDRESS/SIZE: + + Address and Size to be used while configuring the memory window. + See "CMD_CONFIGURE_MW" for more info. + + MEMORY WINDOW1 OFFSET: + + Memory Window 1 and Doorbell registers are packed together in the + same BAR. The initial portion of the region will have doorbell + registers and the latter portion of the region is for memory window 1. + This register will specify the offset of the memory window 1. + + NO OF MEMORY WINDOW: + + Specifies the number of memory windows supported by the NTB device. + + SPAD OFFSET: + + Self scratchpad region and config region are packed together in the + same BAR. The initial portion of the region will have config region + and the latter portion of the region is for self scratchpad. This + register will specify the offset of the self scratchpad registers. + + SPAD COUNT: + + Specifies the number of scratchpad registers supported by the NTB + device. + + DB ENTRY SIZE: + + Used to determine the offset within the DB BAR that should be written + in order to raise doorbell. EPF NTB can use either MSI/MSI-X to + ring doorbell (MSI-X support will be added later). MSI uses same + address for all the interrupts and MSI-X can provide different + addresses for different interrupts. The MSI/MSI-X address is provided + by the host and the address it gives is based on the MSI/MSI-X + implementation supported by the host. For instance, ARM platform + using GIC ITS will have same MSI-X address for all the interrupts. + In order to support all the combinations and use the same mechanism + for both MSI and MSI-X, EPF NTB allocates separate region in the + Outbound Address Space for each of the interrupts. This region will + be mapped to the MSI/MSI-X address provided by the host. If a host + provides the same address for all the interrupts, all the regions + will be translated to the same address. If a host provides different + address, the regions will be translated to different address. This + will ensure there is no difference while raising the doorbell. + + DB DATA:Documentation/PCI/endpoint/pci-ntb-function.rst line 206
Quoted 10 lines
Documentation/PCI/endpoint/pci-ntb-function.rst new file +10
-0+ + EPF NTB supports 32 interrupts. So there are 32 DB DATA registers. + This holds the MSI/MSI-X data that has to be written to MSI address + for raising doorbell interrupt. This will be populated by EPF NTB + while invoking CMD_CONFIGURE_DOORBELL. + +Scratchpad Registers: +--------------------- + + Each host has it's own register space allocated in the memory of NTB EPC.its
[it's means "it is"]Documentation/PCI/endpoint/pci-ntb-function.rst line 218
Quoted 12 lines
Documentation/PCI/endpoint/pci-ntb-function.rst new file +12
-0+ They are both readable and writable from both sides of the bridge. They + are used by applications built over NTB and can be used to pass control + and status information between both sides of a device. + + Scratchpad registers has 2 parts + 1) Self Scratchpad: Host's own register space + 2) Peer Scratchpad: Remote host's register space. + +Doorbell Registers: +------------------- + + Registers using which one host can interrupt the other host.eh? ENOPARSE.
Documentation/PCI/endpoint/pci-ntb-function.rst line 231
Quoted 13 lines
Documentation/PCI/endpoint/pci-ntb-function.rst new file +13
-0+ +Memory Window: +-------------- + + Actual transfer of data between the two hosts will happen using the + memory window. + +Modeling Constructs: +==================== + +There are 5 or more distinct regions (config, self scratchpad, peer +scratchpad, doorbell, one or more memory windows) to be modeled to achieve +NTB functionality. Atleast one memory window is required while more thanAt least
Quoted 8 lines
Documentation/PCI/endpoint/pci-ntb-function.rst new file +8
-0+one is permitted. All these regions should be mapped to BAR for hosts to +access these regions. + +If one 32-bit BAR is allocated for each of these regions, the scheme would +look like + +====== =============== +BAR NO CONSTRUCTS USEDDocumentation/PCI/endpoint/pci-ntb-function.rst line 249
Quoted 10 lines
Documentation/PCI/endpoint/pci-ntb-function.rst new file +10
-0+====== =============== +BAR0 Config Region +BAR1 Self Scratchpad +BAR2 Peer Scratchpad +BAR3 Doorbell +BAR4 Memory Window 1 +BAR5 Memory Window 2 +====== =============== + +However if we allocate a separate BAR for each of the region, there would notregions,
Quoted 90 lines
Documentation/PCI/endpoint/pci-ntb-function.rst new file +90
-0+be enough BARs for all the regions in a platform that supports only 64-bit +BAR. + +In order to be supported by most of the platforms, the regions should be +packed and mapped to BARs in a way that provides NTB functionality and +also making sure the hosts doesn't access any region that it is not supposed +to. + +The following scheme is used in EPF NTB Function + +====== =============================== +BAR NO CONSTRUCTS USED +====== =============================== +BAR0 Config Region + Self Scratchpad +BAR1 Peer Scratchpad +BAR2 Doorbell + Memory Window 1 +BAR3 Memory Window 2 +BAR4 Memory Window 3 +BAR5 Memory Window 4 +====== =============================== + +With this scheme, for the basic NTB functionality 3 BARs should be sufficient. + +Modeling Config/Scratchpad Region: +---------------------------------- + +.. code-block:: text + + +-----------------+------->+------------------+ +-----------------+ + | BAR0 | | CONFIG REGION | | BAR0 | + +-----------------+----+ +------------------+<-------+-----------------+ + | BAR1 | | |SCRATCHPAD REGION | | BAR1 | + +-----------------+ +-->+------------------+<-------+-----------------+ + | BAR2 | Local Memory | BAR2 | + +-----------------+ +-----------------+ + | BAR3 | | BAR3 | + +-----------------+ +-----------------+ + | BAR4 | | BAR4 | + +-----------------+ +-----------------+ + | BAR5 | | BAR5 | + +-----------------+ +-----------------+ + EP CONTROLLER 1 EP CONTROLLER 2 + +Above diagram shows Config region + Scratchpad region for HOST1 (connected to +EP controller 1) allocated in local memory. The HOST1 can access the config +region and scratchpad region (self scratchpad) using BAR0 of EP controller 1. +The peer host (HOST2 connected to EP controller 2) can also access this +scratchpad region (peer scratchpad) using BAR1 of EP controller 2. This +diagram shows the case where Config region and Scratchpad region is allocated +for HOST1, however the same is applicable for HOST2. + +Modeling Doorbell/Memory Window 1: +---------------------------------- + +.. code-block:: text + + +-----------------+ +----->+----------------+-----------+-----------------+ + | BAR0 | | | Doorbell 1 +-----------> MSI-X ADDRESS 1 | + +-----------------+ | +----------------+ +-----------------+ + | BAR1 | | | Doorbell 2 +---------+ | | + +-----------------+----+ +----------------+ | | | + | BAR2 | | Doorbell 3 +-------+ | +-----------------+ + +-----------------+----+ +----------------+ | +-> MSI-X ADDRESS 2 | + | BAR3 | | | Doorbell 4 +-----+ | +-----------------+ + +-----------------+ | |----------------+ | | | | + | BAR4 | | | | | | +-----------------+ + +-----------------+ | | MW1 +---+ | +-->+ MSI-X ADDRESS 3|| + | BAR5 | | | | | | +-----------------+ + +-----------------+ +----->-----------------+ | | | | + EP CONTROLLER 1 | | | | +-----------------+ + | | | +---->+ MSI-X ADDRESS 4 | + +----------------+ | +-----------------+ + EP CONTROLLER 2 | | | + (OB SPACE) | | | + +-------> MW1 | + | | + | | + +-----------------+ + | | + | | + | | + | | + | | + +-----------------+ + PCI Address Space + (Managed by HOST2) + +Above diagram shows how the doorbell and memory window 1 is mapped so that +HOST1 can raise doorbell interrupt on HOST2 and also how HOST1 can access +buffers exposed by HOST2 using memory window1 (MW1). Here doorbell and
Quoted 8 lines
Documentation/PCI/endpoint/pci-ntb-function.rst line 345
Quoted 6 lines
Documentation/PCI/endpoint/pci-ntb-function.rst new file +6
-0+memory window 1 regions are allocated in EP controller 2 outbound (OB) address +space. Allocating and configuring BARs for doorbell and memory window1 +is done during the initialization phase of NTB endpoint function driver. +Mapping from EP controller 2 OB space to PCI address space is done when HOST2 +sends CMD_CONFIGURE_MW/CMD_CONFIGURE_DOORBELL. The commands are explained +below.below??
Actually it's explained in the "Config Region" section under COMMAND.
Quoted 11 lines
Documentation/PCI/endpoint/pci-ntb-function.rst line 351
Quoted 8 lines
Documentation/PCI/endpoint/pci-ntb-function.rst new file +6
-0+ +Modeling Optional Memory Windows: +--------------------------------- + +This is modeled the same was as MW1 but each of the additional memory windows +is mapped to separate BARs.Is all of this register/memory space mapping defined in some PCI NTB spec or is this specific to some hardware/SoC implementation?
This is specific to the configurable PCIe endpoint controllers integrated in SoC (not specific to a particular hardware or SoC implementation) i.e., any vendors whose SoC has a configurable PCIe endpoint controller can use this. The NTB spec [1] (whitepaper rather) doesn't define the exact mapping or registers but only defines the constructs used for communication between two hosts. All of this is well abstracted in the existing NTB framework (using struct ntb_dev_ops) and supports different NTB implementations (IDT NTB PCIe-switch, AMD NTB, Intel NTB and with this series SW defined NTB implemented using multiple endpoint controllers in an SoC).
Thank You,
Kishon
[1] -> https://docs.broadcom.com/doc/12353428
Quoted 4 lines
HTH.
PATCH v9 2/17 PCI: endpoint: Make *_get_first_free_bar() take into account 64 bit BAR
In reply to Kishon Vijay Abraham Ipci_epc_get_first_free_bar() uses only "reserved_bar" member in epc_features to get the first unreserved BAR. However if the reserved BAR is also a 64-bit BAR, then the next BAR shouldn't be returned (since 64-bit BAR uses two BARs).
Make pci_epc_get_first_free_bar() take into account 64 bit BAR while returning the first free unreserved BAR.
--- drivers/pci/endpoint/pci-epc-core.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-)
drivers/pci/endpoint/pci-epc-core.c +10 -2
@@ -93,12 +93,20 @@ EXPORT_SYMBOL_GPL(pci_epc_get);unsigned int pci_epc_get_first_free_bar (const struct pci_epc_features *epc_features) { -int free_bar; +unsigned long free_bar;if (!epc_features)return 0 ; - free_bar =ffz (epc_features->reserved_bar); +/* Find if the reserved BAR is also a 64-bit BAR */ + free_bar = epc_features->reserved_bar & epc_features->bar_fixed_64bit; + +/* Set the adjacent bit if the reserved BAR is also a 64-bit BAR */ + free_bar <<=1 ; + free_bar |= epc_features->reserved_bar; + +/* Now find the free BAR */ + free_bar =ffz (free_bar);if (free_bar >5 )return 0 ;
Signature · 1 line
2.17.1
PATCH v9 3/17 PCI: endpoint: Add helper API to get the 'next' unreserved BAR
In reply to Kishon Vijay Abraham IAdd an API to get the next unreserved BAR starting from a given BAR number that can be used by the endpoint function.
--- drivers/pci/endpoint/pci-epc-core.c | 26 ++++++++++++++++++++++---- include/linux/pci-epc.h | 2 ++ 2 files changed, 24 insertions(+), 4 deletions(-)
drivers/pci/endpoint/pci-epc-core.c +22 -4
@@ -87,17 +87,36 @@ EXPORT_SYMBOL_GPL(pci_epc_get);* pci_epc_get_first_free_bar() - helper to get first unreserved BAR * @epc_features: pci_epc_features structure that holds the reserved bar bitmap * -* Invoke to get the first unreserved BAR that can be used for endpoint +* Invoke to get the first unreserved BAR that can be used by the endpoint * function. For any incorrect value in reserved_bar return '0'. */ unsigned int pci_epc_get_first_free_bar (const struct pci_epc_features *epc_features) +{ +return pci_epc_get_next_free_bar (epc_features,BAR_0 ); +} +EXPORT_SYMBOL_GPL (pci_epc_get_first_free_bar); + +/** +* pci_epc_get_next_free_bar() - helper to get unreserved BAR starting from @bar +* @epc_features: pci_epc_features structure that holds the reserved bar bitmap +* @bar: the starting BAR number from where unreserved BAR should be searched +* +* Invoke to get the next unreserved BAR starting from @bar that can be used +* for endpoint function. For any incorrect value in reserved_bar return '0'. +*/ +unsigned int pci_epc_get_next_free_bar (const struct pci_epc_features + *epc_features,enum pci_barno bar) {unsigned long free_bar;if (!epc_features)return 0 ; +/* If 'bar - 1' is a 64-bit BAR, move to the next BAR */ +if ((epc_features->bar_fixed_64bit <<1 ) &1 << bar) + bar++; +/* Find if the reserved BAR is also a 64-bit BAR */ free_bar = epc_features->reserved_bar & epc_features->bar_fixed_64bit;
@@ -105,14 +124,13 @@ unsigned int pci_epc_get_first_free_bar(const struct pci_epc_features free_bar <<=1 ; free_bar |= epc_features->reserved_bar; -/* Now find the free BAR */ - free_bar =ffz (free_bar); + free_bar =find_next_zero_bit (&free_bar,6 , bar);if (free_bar >5 )return 0 ;return free_bar; } -EXPORT_SYMBOL_GPL (pci_epc_get_first_free_bar); +EXPORT_SYMBOL_GPL (pci_epc_get_next_free_bar);/** * pci_epc_get_features() - get the features supported by EPC
include/linux/pci-epc.h +2 -0
@@ -203,6 +203,8 @@ const struct pci_epc_features *pci_epc_get_features(struct pci_epc *epc, u8 func_no);unsigned int pci_epc_get_first_free_bar (const struct pci_epc_features *epc_features); +unsigned int pci_epc_get_next_free_bar (const struct pci_epc_features + *epc_features,enum pci_barno bar);struct pci_epc *pci_epc_get (const char *epc_name);void pci_epc_put (struct pci_epc *epc);
Signature · 1 line
2.17.1
PATCH v9 4/17 PCI: endpoint: Make *_free_bar() to return error codes on failure
In reply to Kishon Vijay Abraham IModify pci_epc_get_next_free_bar() and pci_epc_get_first_free_bar() to return error values if there are no free BARs available.
--- drivers/pci/endpoint/functions/pci-epf-test.c | 2 ++ drivers/pci/endpoint/pci-epc-core.c | 12 ++++++------ include/linux/pci-epc.h | 8 ++++---- include/linux/pci-epf.h | 1 + 4 files changed, 13 insertions(+), 10 deletions(-)
drivers/pci/endpoint/functions/pci-epf-test.c +2 -0
@@ -834,6 +834,8 @@ static int pci_epf_test_bind(struct pci_epf *epf) linkup_notifier = epc_features->linkup_notifier; core_init_notifier = epc_features->core_init_notifier; test_reg_bar =pci_epc_get_first_free_bar (epc_features); +if (test_reg_bar <0 ) +return -EINVAL ;pci_epf_configure_bar (epf, epc_features); }
drivers/pci/endpoint/pci-epc-core.c +6 -6
@@ -90,8 +90,8 @@ EXPORT_SYMBOL_GPL(pci_epc_get);* Invoke to get the first unreserved BAR that can be used by the endpoint * function. For any incorrect value in reserved_bar return '0'. */ -unsigned int pci_epc_get_first_free_bar (const struct pci_epc_features - *epc_features) +enum pci_barno +pci_epc_get_first_free_bar (const struct pci_epc_features *epc_features) {return pci_epc_get_next_free_bar (epc_features,BAR_0 ); }
@@ -105,13 +105,13 @@ EXPORT_SYMBOL_GPL(pci_epc_get_first_free_bar);* Invoke to get the next unreserved BAR starting from @bar that can be used * for endpoint function. For any incorrect value in reserved_bar return '0'. */ -unsigned int pci_epc_get_next_free_bar (const struct pci_epc_features - *epc_features,enum pci_barno bar) +enum pci_barno pci_epc_get_next_free_bar (const struct pci_epc_features + *epc_features,enum pci_barno bar) {unsigned long free_bar;if (!epc_features) -return 0 ; +return BAR_0 ;/* If 'bar - 1' is a 64-bit BAR, move to the next BAR */ if ((epc_features->bar_fixed_64bit <<1 ) &1 << bar)
@@ -126,7 +126,7 @@ unsigned int pci_epc_get_next_free_bar(const struct pci_epc_features free_bar =find_next_zero_bit (&free_bar,6 , bar);if (free_bar >5 ) -return 0 ; +return NO_BAR ;return free_bar; }
include/linux/pci-epc.h +4 -4
@@ -201,10 +201,10 @@ int pci_epc_start(struct pci_epc *epc);void pci_epc_stop (struct pci_epc *epc);const struct pci_epc_features *pci_epc_get_features (struct pci_epc *epc,u8 func_no); -unsigned int pci_epc_get_first_free_bar (const struct pci_epc_features - *epc_features); -unsigned int pci_epc_get_next_free_bar (const struct pci_epc_features - *epc_features,enum pci_barno bar); +enum pci_barno +pci_epc_get_first_free_bar (const struct pci_epc_features *epc_features); +enum pci_barno pci_epc_get_next_free_bar (const struct pci_epc_features + *epc_features,enum pci_barno bar);struct pci_epc *pci_epc_get (const char *epc_name);void pci_epc_put (struct pci_epc *epc);
include/linux/pci-epf.h +1 -0
@@ -21,6 +21,7 @@ enum pci_notify_event { };enum pci_barno { +NO_BAR =-1 ,BAR_0 ,BAR_1 ,BAR_2 ,
Signature · 1 line
2.17.1
PATCH v9 5/17 PCI: endpoint: Remove unused pci_epf_match_device()
In reply to Kishon Vijay Abraham IRemove unused pci_epf_match_device() function added in pci-epf-core.c
--- drivers/pci/endpoint/pci-epf-core.c | 16 ---------------- include/linux/pci-epf.h | 2 -- 2 files changed, 18 deletions(-)
drivers/pci/endpoint/pci-epf-core.c +0 -16
@@ -282,22 +282,6 @@ struct pci_epf *pci_epf_create(const char *name) }EXPORT_SYMBOL_GPL (pci_epf_create); -const struct pci_epf_device_id * -pci_epf_match_device (const struct pci_epf_device_id *id,struct pci_epf *epf) -{ -if (!id || !epf) -return NULL ; - -while (*id->name) { -if (strcmp (epf->name, id->name) ==0 ) -return id; - id++; - } - -return NULL ; -} -EXPORT_SYMBOL_GPL (pci_epf_match_device); -static void pci_epf_dev_release (struct device *dev) {struct pci_epf *epf =to_pci_epf (dev);
include/linux/pci-epf.h +0 -2
@@ -165,8 +165,6 @@ static inline void *epf_get_drvdata(struct pci_epf *epf)return dev_get_drvdata (&epf->dev); } -const struct pci_epf_device_id * -pci_epf_match_device (const struct pci_epf_device_id *id,struct pci_epf *epf);struct pci_epf *pci_epf_create (const char *name);void pci_epf_destroy (struct pci_epf *epf); int __pci_epf_register_driver(struct pci_epf_driver *driver,
Signature · 1 line
2.17.1
PATCH v9 6/17 PCI: endpoint: Add support to associate secondary EPC with EPF
In reply to Kishon Vijay Abraham IIn the case of standard endpoint functions, only one endpoint controller (EPC) will be associated with an endpoint function (EPF). However for providing NTB (non transparent bridge) functionality, two EPCs should be associated with a single EPF. Add support to associate secondary EPC with EPF. This is in preparation for adding NTB endpoint function driver.
--- drivers/pci/endpoint/functions/pci-epf-test.c | 11 ++-- drivers/pci/endpoint/pci-ep-cfs.c | 6 +- drivers/pci/endpoint/pci-epc-core.c | 47 +++++++++++---- drivers/pci/endpoint/pci-epf-core.c | 57 +++++++++++++------ include/linux/pci-epc.h | 25 +++++++- include/linux/pci-epf.h | 17 +++++- 6 files changed, 125 insertions(+), 38 deletions(-)
drivers/pci/endpoint/functions/pci-epf-test.c +7 -4
@@ -619,7 +619,8 @@ static void pci_epf_test_unbind(struct pci_epf *epf)if (epf_test->reg[bar]) {pci_epc_clear_bar (epc, epf->func_no, epf_bar); -pci_epf_free_space (epf, epf_test->reg[bar], bar); +pci_epf_free_space (epf, epf_test->reg[bar], bar, +PRIMARY_INTERFACE ); } } }
@@ -651,7 +652,8 @@ static int pci_epf_test_set_bar(struct pci_epf *epf) ret =pci_epc_set_bar (epc, epf->func_no, epf_bar);if (ret) { -pci_epf_free_space (epf, epf_test->reg[bar], bar); +pci_epf_free_space (epf, epf_test->reg[bar], bar, +PRIMARY_INTERFACE );dev_err (dev,"Failed to set BAR%d\n" , bar);if (bar == test_reg_bar)return ret;
@@ -771,7 +773,7 @@ static int pci_epf_test_alloc_space(struct pci_epf *epf) } base =pci_epf_alloc_space (epf, test_reg_size, test_reg_bar, - epc_features->align); + epc_features->align,PRIMARY_INTERFACE );if (!base) {dev_err (dev,"Failed to allocated register space\n" );return -ENOMEM ;
@@ -789,7 +791,8 @@ static int pci_epf_test_alloc_space(struct pci_epf *epf)continue ; base =pci_epf_alloc_space (epf, bar_size[bar], bar, - epc_features->align); + epc_features->align, +PRIMARY_INTERFACE );if (!base)dev_err (dev,"Failed to allocate space for BAR%d\n" , bar);
drivers/pci/endpoint/pci-ep-cfs.c +3 -3
@@ -94,13 +94,13 @@ static int pci_epc_epf_link(struct config_item *epc_item,struct pci_epc *epc = epc_group->epc;struct pci_epf *epf = epf_group->epf; - ret =pci_epc_add_epf (epc, epf); + ret =pci_epc_add_epf (epc, epf,PRIMARY_INTERFACE );if (ret)return ret; ret =pci_epf_bind (epf);if (ret) { -pci_epc_remove_epf (epc, epf); +pci_epc_remove_epf (epc, epf,PRIMARY_INTERFACE );return ret; }
@@ -120,7 +120,7 @@ static void pci_epc_epf_unlink(struct config_item *epc_item, epc = epc_group->epc; epf = epf_group->epf;pci_epf_unbind (epf); -pci_epc_remove_epf (epc, epf); +pci_epc_remove_epf (epc, epf,PRIMARY_INTERFACE ); }static struct configfs_item_operations pci_epc_item_ops = {
drivers/pci/endpoint/pci-epc-core.c +36 -11
82 lines not on this page · raw message
drivers/pci/endpoint/pci-epf-core.c +41 -16
97 lines not on this page · raw message
include/linux/pci-epc.h +23 -2
@@ -13,6 +13,12 @@struct pci_epc ; +enum pci_epc_interface_type { +UNKNOWN_INTERFACE =-1 , +PRIMARY_INTERFACE , +SECONDARY_INTERFACE , +}; +enum pci_epc_irq_type {PCI_EPC_IRQ_UNKNOWN ,PCI_EPC_IRQ_LEGACY ,
@@ -20,6 +26,19 @@ enum pci_epc_irq_type { PCI_EPC_IRQ_MSIX, }; +static inline const char * +pci_epc_interface_string (enum pci_epc_interface_type type) +{ +switch (type) { +case PRIMARY_INTERFACE : +return "primary" ; +case SECONDARY_INTERFACE : +return "secondary" ; +default : +return "UNKNOWN interface" ; + } +} +/** * struct pci_epc_ops - set of function pointers for performing EPC operations * @write_header: ops to populate configuration space header
@@ -175,10 +194,12 @@ __pci_epc_create(struct device *dev, const struct pci_epc_ops *ops, struct module *owner);void devm_pci_epc_destroy (struct device *dev,struct pci_epc *epc);void pci_epc_destroy (struct pci_epc *epc); -int pci_epc_add_epf (struct pci_epc *epc,struct pci_epf *epf); +int pci_epc_add_epf (struct pci_epc *epc,struct pci_epf *epf, +enum pci_epc_interface_type type);void pci_epc_linkup (struct pci_epc *epc);void pci_epc_init_notify (struct pci_epc *epc); -void pci_epc_remove_epf (struct pci_epc *epc,struct pci_epf *epf); +void pci_epc_remove_epf (struct pci_epc *epc,struct pci_epf *epf, +enum pci_epc_interface_type type);int pci_epc_write_header (struct pci_epc *epc,u8 func_no,struct pci_epf_header *hdr); int pci_epc_set_bar(struct pci_epc *epc, u8 func_no,
include/linux/pci-epf.h +15 -2
@@ -14,6 +14,7 @@#include <linux/pci.h> struct pci_epf ; +enum pci_epc_interface_type ;enum pci_notify_event {CORE_INIT ,
@@ -119,6 +120,11 @@ struct pci_epf_bar {* @list: to add pci_epf as a list of PCI endpoint functions to pci_epc * @nb: notifier block to notify EPF of any EPC events (like linkup) * @lock: mutex to protect pci_epf_ops +* @sec_epc: the secondary EPC device to which this EPF device is bound +* @sec_epc_list: to add pci_epf as list of PCI endpoint functions to secondary +* EPC device +* @sec_epc_bar: represents the BAR of EPF device associated with secondary EPC +* @sec_epc_func_no: unique (physical) function number within the secondary EPC */ struct pci_epf {struct device dev;
@@ -135,6 +141,12 @@ struct pci_epf {struct notifier_block nb;/* mutex to protect against concurrent access of pci_epf_ops */ struct mutex lock; + +/* Below members are to attach secondary EPC to an endpoint function */ +struct pci_epc *sec_epc; +struct list_head sec_epc_list; +struct pci_epf_bar sec_epc_bar[6 ]; +u8 sec_epc_func_no; };/**
@@ -171,8 +183,9 @@ int __pci_epf_register_driver(struct pci_epf_driver *driver, struct module *owner);void pci_epf_unregister_driver (struct pci_epf_driver *driver);void *pci_epf_alloc_space (struct pci_epf *epf,size_t size,enum pci_barno bar, -size_t align); -void pci_epf_free_space (struct pci_epf *epf,void *addr,enum pci_barno bar); +size_t align,enum pci_epc_interface_type type); +void pci_epf_free_space (struct pci_epf *epf,void *addr,enum pci_barno bar, +enum pci_epc_interface_type type);int pci_epf_bind (struct pci_epf *epf);void pci_epf_unbind (struct pci_epf *epf);#endif /* __LINUX_PCI_EPF_H */
Signature · 1 line
2.17.1
PATCH v9 7/17 PCI: endpoint: Add support in configfs to associate two EPCs with EPF
In reply to Kishon Vijay Abraham INow that PCI endpoint core supports to add secondary endpoint controller (EPC) with endpoint function (EPF), Add support in configfs to associate two EPCs with EPF. This creates "primary" and "secondary" directory inside the directory created by users for EPF device. Users have to add a symlink of endpoint controller (pci_ep/controllers/) to "primary" or "secondary" directory to bind EPF to primary and secondary EPF interfaces respectively. Existing method of linking directory representing EPF device to directory representing EPC device to associate a single EPC device with a EPF device will continue to work.
--- .../PCI/endpoint/pci-endpoint-cfs.rst | 10 ++ drivers/pci/endpoint/pci-ep-cfs.c | 147 ++++++++++++++++++ 2 files changed, 157 insertions(+)
Documentation/PCI/endpoint/pci-endpoint-cfs.rst +10 -0
@@ -68,6 +68,16 @@ created) ... subsys_vendor_id ... subsys_id ... interrupt_pin + ... primary/ + ... <Symlink EPC Device1>/ + ... secondary/ + ... <Symlink EPC Device2>/ + +If an EPF device has to be associated with 2 EPCs (like in the case of +Non-transparent bridge), symlink of endpoint controller connected to primary +interface should be added in 'primary' directory and symlink of endpoint +controller connected to secondary interface should be added in 'secondary' +directory. EPC Device ==========
drivers/pci/endpoint/pci-ep-cfs.c +147 -0
171 lines not on this page · raw message
Signature · 1 line
2.17.1
PATCH v9 8/17 PCI: endpoint: Add pci_epc_ops to map MSI irq
In reply to Kishon Vijay Abraham IAdd pci_epc_ops to map physical address to MSI address and return MSI data. The physical address is an address in the outbound region. This is required to implement doorbell functionality of NTB (non transparent bridge) wherein EPC on either side of the interface (primary and secondary) can directly write to the physical address (in outbound region) of the other interface to ring doorbell using MSI.
--- drivers/pci/endpoint/pci-epc-core.c | 41 +++++++++++++++++++++++++++++ include/linux/pci-epc.h | 8 ++++++ 2 files changed, 49 insertions(+)
drivers/pci/endpoint/pci-epc-core.c +41 -0
@@ -230,6 +230,47 @@ int pci_epc_raise_irq(struct pci_epc *epc, u8 func_no, }EXPORT_SYMBOL_GPL (pci_epc_raise_irq); +/** +* pci_epc_map_msi_irq() - Map physical address to MSI address and return +* MSI data +* @epc: the EPC device which has the MSI capability +* @func_no: the physical endpoint function number in the EPC device +* @phys_addr: the physical address of the outbound region +* @interrupt_num: the MSI interrupt number +* @entry_size: Size of Outbound address region for each interrupt +* @msi_data: the data that should be written in order to raise MSI interrupt +* with interrupt number as 'interrupt num' +* @msi_addr_offset: Offset of MSI address from the aligned outbound address +* to which the MSI address is mapped +* +* Invoke to map physical address to MSI address and return MSI data. The +* physical address should be an address in the outbound region. This is +* required to implement doorbell functionality of NTB wherein EPC on either +* side of the interface (primary and secondary) can directly write to the +* physical address (in outbound region) of the other interface to ring +* doorbell. +*/ +int pci_epc_map_msi_irq (struct pci_epc *epc,u8 func_no,phys_addr_t phys_addr, +u8 interrupt_num,u32 entry_size,u32 *msi_data, +u32 *msi_addr_offset) +{ +int ret; + +if (IS_ERR_OR_NULL (epc)) +return -EINVAL ; + +if (!epc->ops->map_msi_irq) +return -EINVAL ; + +mutex_lock (&epc->lock); + ret = epc->ops->map_msi_irq (epc, func_no, phys_addr, interrupt_num, + entry_size, msi_data, msi_addr_offset); +mutex_unlock (&epc->lock); + +return ret; +} +EXPORT_SYMBOL_GPL (pci_epc_map_msi_irq); +/** * pci_epc_get_msi() - get the number of MSI interrupt numbers allocated * @epc: the EPC device to which MSI interrupts was requested
include/linux/pci-epc.h +8 -0
@@ -55,6 +55,7 @@ pci_epc_interface_string(enum pci_epc_interface_type type)* @get_msix: ops to get the number of MSI-X interrupts allocated by the RC * from the MSI-X capability register * @raise_irq: ops to raise a legacy, MSI or MSI-X interrupt +* @map_msi_irq: ops to map physical address to MSI address and return MSI data * @start: ops to start the PCI link * @stop: ops to stop the PCI link * @owner: the module owner containing the ops
@@ -77,6 +78,10 @@ struct pci_epc_ops {int (*get_msix)(struct pci_epc *epc,u8 func_no);int (*raise_irq)(struct pci_epc *epc,u8 func_no,enum pci_epc_irq_type type,u16 interrupt_num); +int (*map_msi_irq)(struct pci_epc *epc,u8 func_no, +phys_addr_t phys_addr,u8 interrupt_num, +u32 entry_size,u32 *msi_data, +u32 *msi_addr_offset);int (*start)(struct pci_epc *epc);void (*stop)(struct pci_epc *epc); const struct pci_epc_features* (*get_features)(struct pci_epc *epc,
@@ -216,6 +221,9 @@ int pci_epc_get_msi(struct pci_epc *epc, u8 func_no);int pci_epc_set_msix (struct pci_epc *epc,u8 func_no,u16 interrupts,enum pci_barno ,u32 offset);int pci_epc_get_msix (struct pci_epc *epc,u8 func_no); +int pci_epc_map_msi_irq (struct pci_epc *epc,u8 func_no, +phys_addr_t phys_addr,u8 interrupt_num, +u32 entry_size,u32 *msi_data,u32 *msi_addr_offset);int pci_epc_raise_irq (struct pci_epc *epc,u8 func_no,enum pci_epc_irq_type type,u16 interrupt_num);int pci_epc_start (struct pci_epc *epc);
Signature · 1 line
2.17.1
PATCH v9 9/17 PCI: endpoint: Add pci_epf_ops for epf drivers to expose function specific attrs
In reply to Kishon Vijay Abraham IIn addition to the attributes that are generic across function drivers documented in Documentation/PCI/endpoint/pci-endpoint-cfs.rst, there could be function specific attributes that has to be exposed by the function driver to be configured by the user. Add ->add_cfs() in pci_epf_ops to be populated by the function driver if it has to expose any function specific attributes and pci_epf_type_add_cfs() to be invoked by pci-ep-cfs.c when sub-directory to main function directory is created.
--- drivers/pci/endpoint/pci-epf-core.c | 32 +++++++++++++++++++++++++++++ include/linux/pci-epf.h | 5 +++++ 2 files changed, 37 insertions(+)
drivers/pci/endpoint/pci-epf-core.c +32 -0
@@ -20,6 +20,38 @@ static DEFINE_MUTEX(pci_epf_mutex);static struct bus_type pci_epf_bus_type;static const struct device_type pci_epf_type; +/** +* pci_epf_type_add_cfs() - Help function drivers to expose function specific +* attributes in configfs +* @epf: the EPF device that has to be configured using configfs +* @group: the parent configfs group (corresponding to entries in +* pci_epf_device_id) +* +* Invoke to expose function specific attributes in configfs. If the function +* driver does not have anything to expose (attributes configured by user), +* return NULL. +*/ +struct config_group *pci_epf_type_add_cfs (struct pci_epf *epf, +struct config_group *group) +{ +struct config_group *epf_type_group; + +if (!epf->driver) { +dev_err (&epf->dev,"epf device not bound to driver\n" ); +return NULL ; + } + +if (!epf->driver->ops->add_cfs) +return NULL ; + +mutex_lock (&epf->lock); + epf_type_group = epf->driver->ops->add_cfs (epf, group); +mutex_unlock (&epf->lock); + +return epf_type_group; +} +EXPORT_SYMBOL_GPL (pci_epf_type_add_cfs); +/** * pci_epf_unbind() - Notify the function driver that the binding between the * EPF device and EPC device has been lost
include/linux/pci-epf.h +5 -0
@@ -62,10 +62,13 @@ struct pci_epf_header {* @bind: ops to perform when a EPC device has been bound to EPF device * @unbind: ops to perform when a binding has been lost between a EPC device * and EPF device +* @add_cfs: ops to initialize function specific configfs attributes */ struct pci_epf_ops {int (*bind)(struct pci_epf *epf);void (*unbind)(struct pci_epf *epf); +struct config_group *(*add_cfs)(struct pci_epf *epf, +struct config_group *group); };/**
@@ -188,4 +191,6 @@ void pci_epf_free_space(struct pci_epf *epf, void *addr, enum pci_barno bar, enum pci_epc_interface_type type);int pci_epf_bind (struct pci_epf *epf);void pci_epf_unbind (struct pci_epf *epf); +struct config_group *pci_epf_type_add_cfs (struct pci_epf *epf, +struct config_group *group);#endif /* __LINUX_PCI_EPF_H */
Signature · 1 line
2.17.1
PATCH v9 10/17 PCI: endpoint: Allow user to create sub-directory of 'EPF Device' directory
In reply to Kishon Vijay Abraham IDocumentation/PCI/endpoint/pci-endpoint-cfs.rst explains how a user has to create a directory in-order to create a 'EPF Device' that can be configured/probed by 'EPF Driver'.
Allow user to create a sub-directory of 'EPF Device' directory for any function specific attributes that has to be exposed to the user.
--- drivers/pci/endpoint/pci-ep-cfs.c | 23 +++++++++++++++++++++++ include/linux/pci-epf.h | 3 +++ 2 files changed, 26 insertions(+)
drivers/pci/endpoint/pci-ep-cfs.c +23 -0
@@ -490,7 +490,29 @@ static struct configfs_item_operations pci_epf_ops = { .release = pci_epf_release, }; +static struct config_group *pci_epf_type_make (struct config_group *group, +const char *name) +{ +struct pci_epf_group *epf_group =to_pci_epf_group (&group->cg_item); +struct config_group *epf_type_group; + + epf_type_group =pci_epf_type_add_cfs (epf_group->epf, group); +return epf_type_group; +} + +static void pci_epf_type_drop (struct config_group *group, +struct config_item *item) +{ +config_item_put (item); +} + +static struct configfs_group_operations pci_epf_type_group_ops = { + .make_group = &pci_epf_type_make, + .drop_item = &pci_epf_type_drop, +}; +static const struct config_item_type pci_epf_type = { + .ct_group_ops = &pci_epf_type_group_ops, .ct_item_ops = &pci_epf_ops, .ct_attrs = pci_epf_attrs, .ct_owner =THIS_MODULE ,
@@ -553,6 +575,7 @@ static struct config_group *pci_epf_make(struct config_group *group, goto free_name; } + epf->group = &epf_group->group; epf_group->epf = epf;kfree (epf_name);
include/linux/pci-epf.h +3 -0
@@ -9,6 +9,7 @@#ifndef __LINUX_PCI_EPF_H#define __LINUX_PCI_EPF_H +#include <linux/configfs.h> #include <linux/device.h> #include <linux/mod_devicetable.h> #include <linux/pci.h>
@@ -128,6 +129,7 @@ struct pci_epf_bar {* EPC device * @sec_epc_bar: represents the BAR of EPF device associated with secondary EPC * @sec_epc_func_no: unique (physical) function number within the secondary EPC +* @group: configfs group associated with the EPF device */ struct pci_epf {struct device dev;
@@ -150,6 +152,7 @@ struct pci_epf {struct list_head sec_epc_list;struct pci_epf_bar sec_epc_bar[6 ];u8 sec_epc_func_no; +struct config_group *group; };/**
Signature · 1 line
2.17.1
Re: [PATCH v9 10/17] PCI: endpoint: Allow user to create sub-directory of 'EPF Device' directory
[cc->to Greg]
Quoted 6 lines · Kishon Vijay Abraham I
Documentation/PCI/endpoint/pci-endpoint-cfs.rstexplains how a user has to create a directory in-order to create a 'EPF Device' that can be configured/probed by 'EPF Driver'.Allow user to create a sub-directory of 'EPF Device' directory for any function specific attributes that has to be exposed to the user.
Maybe add an example sysfs path in the commit log?
Seems like there's restriction on hierarchy depth in sysfs, but I don't remember the details. Moved Greg to "to" in case he wants to comment.
Quoted 79 lines
Signed-off-by Kishon Vijay Abraham I <[email protected]>--- drivers/pci/endpoint/pci-ep-cfs.c | 23 +++++++++++++++++++++++ include/linux/pci-epf.h | 3 +++ 2 files changed, 26 insertions(+)drivers/pci/endpoint/pci-ep-cfs.c +23
-0@@ -490,7 +490,29 @@ static struct configfs_item_operations pci_epf_ops = { .release = pci_epf_release, }; +static struct config_group *pci_epf_type_make (struct config_group *group, +const char *name) +{ +struct pci_epf_group *epf_group =to_pci_epf_group (&group->cg_item); +struct config_group *epf_type_group; + + epf_type_group =pci_epf_type_add_cfs (epf_group->epf, group); +return epf_type_group; +} + +static void pci_epf_type_drop (struct config_group *group, +struct config_item *item) +{ +config_item_put (item); +} + +static struct configfs_group_operations pci_epf_type_group_ops = { + .make_group = &pci_epf_type_make, + .drop_item = &pci_epf_type_drop, +}; +static const struct config_item_type pci_epf_type = { + .ct_group_ops = &pci_epf_type_group_ops, .ct_item_ops = &pci_epf_ops, .ct_attrs = pci_epf_attrs, .ct_owner =THIS_MODULE ,@@ -553,6 +575,7 @@ static struct config_group *pci_epf_make(struct config_group *group, goto free_name; } + epf->group = &epf_group->group; epf_group->epf = epf;kfree (epf_name);include/linux/pci-epf.h +3
-0@@ -9,6 +9,7 @@#ifndef __LINUX_PCI_EPF_H#define __LINUX_PCI_EPF_H +#include <linux/configfs.h> #include <linux/device.h> #include <linux/mod_devicetable.h> #include <linux/pci.h> @@ -128,6 +129,7 @@ struct pci_epf_bar {* EPC device * @sec_epc_bar: represents the BAR of EPF device associated with secondary EPC * @sec_epc_func_no: unique (physical) function number within the secondary EPC +* @group: configfs group associated with the EPF device */ struct pci_epf {struct device dev;@@ -150,6 +152,7 @@ struct pci_epf {struct list_head sec_epc_list;struct pci_epf_bar sec_epc_bar[6 ];u8 sec_epc_func_no; +struct config_group *group; };/** Signature · 1 line
2.17.1
Re: [PATCH v9 10/17] PCI: endpoint: Allow user to create sub-directory of 'EPF Device' directory
Quoted 7 lines · Bjorn Helgaas
[
cc->toGreg]Quoted 4 lines · Kishon Vijay Abraham I
Documentation/PCI/endpoint/pci-endpoint-cfs.rstexplains how a user has to create a directory in-order to create a 'EPF Device' that can be configured/probed by 'EPF Driver'.
Quoted 8 lines
Quoted 2 lines
Allow user to create a sub-directory of 'EPF Device' directory for any function specific attributes that has to be exposed to the user.
Maybe add an example sysfs path in the commit log?
Seems like there's restriction on hierarchy depth in sysfs, but I don't remember the details. Moved Greg to "to" in case he wants to comment.
Oh, I see this is for *configfs*, not for *sysfs*. Sorry for the noise.
Quoted 79 lines
Quoted 79 lines
Signed-off-by Kishon Vijay Abraham I <[email protected]>--- drivers/pci/endpoint/pci-ep-cfs.c | 23 +++++++++++++++++++++++ include/linux/pci-epf.h | 3 +++ 2 files changed, 26 insertions(+)drivers/pci/endpoint/pci-ep-cfs.c +23
-0@@ -490,7 +490,29 @@ static struct configfs_item_operations pci_epf_ops = { .release = pci_epf_release, }; +static struct config_group *pci_epf_type_make (struct config_group *group, +const char *name) +{ +struct pci_epf_group *epf_group =to_pci_epf_group (&group->cg_item); +struct config_group *epf_type_group; + + epf_type_group =pci_epf_type_add_cfs (epf_group->epf, group); +return epf_type_group; +} + +static void pci_epf_type_drop (struct config_group *group, +struct config_item *item) +{ +config_item_put (item); +} + +static struct configfs_group_operations pci_epf_type_group_ops = { + .make_group = &pci_epf_type_make, + .drop_item = &pci_epf_type_drop, +}; +static const struct config_item_type pci_epf_type = { + .ct_group_ops = &pci_epf_type_group_ops, .ct_item_ops = &pci_epf_ops, .ct_attrs = pci_epf_attrs, .ct_owner =THIS_MODULE ,@@ -553,6 +575,7 @@ static struct config_group *pci_epf_make(struct config_group *group, goto free_name; } + epf->group = &epf_group->group; epf_group->epf = epf;kfree (epf_name);include/linux/pci-epf.h +3
-0@@ -9,6 +9,7 @@#ifndef __LINUX_PCI_EPF_H#define __LINUX_PCI_EPF_H +#include <linux/configfs.h> #include <linux/device.h> #include <linux/mod_devicetable.h> #include <linux/pci.h> @@ -128,6 +129,7 @@ struct pci_epf_bar {* EPC device * @sec_epc_bar: represents the BAR of EPF device associated with secondary EPC * @sec_epc_func_no: unique (physical) function number within the secondary EPC +* @group: configfs group associated with the EPF device */ struct pci_epf {struct device dev;@@ -150,6 +152,7 @@ struct pci_epf {struct list_head sec_epc_list;struct pci_epf_bar sec_epc_bar[6 ];u8 sec_epc_func_no; +struct config_group *group; };/** Signature · 1 line
2.17.1
Greg Kroah-Hartman
maintainerRe: [PATCH v9 10/17] PCI: endpoint: Allow user to create sub-directory of 'EPF Device' directory
In reply to Bjorn HelgaasQuoted 7 lines · Bjorn Helgaas
[
cc->toGreg]Quoted 4 lines · Kishon Vijay Abraham I
Documentation/PCI/endpoint/pci-endpoint-cfs.rstexplains how a user has to create a directory in-order to create a 'EPF Device' that can be configured/probed by 'EPF Driver'.
Quoted 8 lines
Quoted 2 lines
Allow user to create a sub-directory of 'EPF Device' directory for any function specific attributes that has to be exposed to the user.
Maybe add an example sysfs path in the commit log?
Seems like there's restriction on hierarchy depth in sysfs, but I don't remember the details. Moved Greg to "to" in case he wants to comment.
This is configfs, not sysfs, so I really do not know, sorry.
greg k-h
PATCH v9 11/17 PCI: cadence: Implement ->msi_map_irq() ops
In reply to Kishon Vijay Abraham IImplement ->msi_map_irq() ops in order to map physical address to MSI address and return MSI data.
--- .../pci/controller/cadence/pcie-cadence-ep.c | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+)
drivers/pci/controller/cadence/pcie-cadence-ep.c +53 -0
@@ -382,6 +382,57 @@ static int cdns_pcie_ep_send_msi_irq(struct cdns_pcie_ep *ep, u8 fn,return 0 ; } +static int cdns_pcie_ep_map_msi_irq (struct pci_epc *epc,u8 fn, +phys_addr_t addr,u8 interrupt_num, +u32 entry_size,u32 *msi_data, +u32 *msi_addr_offset) +{ +struct cdns_pcie_ep *ep =epc_get_drvdata (epc); +u32 cap =CDNS_PCIE_EP_FUNC_MSI_CAP_OFFSET ; +struct cdns_pcie *pcie = &ep->pcie; +u64 pci_addr, pci_addr_mask =0xff ; +u16 flags, mme, data, data_mask; +u8 msi_count; +int ret; +int i; + +/* Check whether the MSI feature has been enabled by the PCI host. */ + flags =cdns_pcie_ep_fn_readw (pcie, fn, cap +PCI_MSI_FLAGS ); +if (!(flags &PCI_MSI_FLAGS_ENABLE )) +return -EINVAL ; + +/* Get the number of enabled MSIs */ + mme = (flags &PCI_MSI_FLAGS_QSIZE ) >>4 ; + msi_count =1 << mme; +if (!interrupt_num || interrupt_num > msi_count) +return -EINVAL ; + +/* Compute the data value to be written. */ + data_mask = msi_count -1 ; + data =cdns_pcie_ep_fn_readw (pcie, fn, cap +PCI_MSI_DATA_64 ); + data = data & ~data_mask; + +/* Get the PCI address where to write the data into. */ + pci_addr =cdns_pcie_ep_fn_readl (pcie, fn, cap +PCI_MSI_ADDRESS_HI ); + pci_addr <<=32 ; + pci_addr |=cdns_pcie_ep_fn_readl (pcie, fn, cap +PCI_MSI_ADDRESS_LO ); + pci_addr &=GENMASK_ULL (63 ,2 ); + +for (i =0 ; i < interrupt_num; i++) { + ret =cdns_pcie_ep_map_addr (epc, fn, addr, + pci_addr & ~pci_addr_mask, + entry_size); +if (ret) +return ret; + addr = addr + entry_size; + } + + *msi_data = data; + *msi_addr_offset = pci_addr & pci_addr_mask; + +return 0 ; +} +static int cdns_pcie_ep_send_msix_irq (struct cdns_pcie_ep *ep,u8 fn,u16 interrupt_num) {
@@ -481,6 +532,7 @@ static const struct pci_epc_features cdns_pcie_epc_features = { .linkup_notifier = false, .msi_capable = true, .msix_capable = true, + .align = 256, }; static const struct pci_epc_features*
@@ -500,6 +552,7 @@ static const struct pci_epc_ops cdns_pcie_epc_ops = { .set_msix = cdns_pcie_ep_set_msix, .get_msix = cdns_pcie_ep_get_msix, .raise_irq = cdns_pcie_ep_raise_irq, + .map_msi_irq = cdns_pcie_ep_map_msi_irq, .start = cdns_pcie_ep_start, .get_features = cdns_pcie_ep_get_features, };
Signature · 1 line
2.17.1
PATCH v9 12/17 PCI: cadence: Configure LM_EP_FUNC_CFG based on epc->function_num_map
In reply to Kishon Vijay Abraham IThe number of functions supported by the endpoint controller is configured in LM_EP_FUNC_CFG based on func_no member of struct pci_epf. Now that an endpoint function can be associated with two endpoint controllers (primary and secondary), just using func_no will not suffice as that will take into account only if the endpoint controller is associated with the primary interface of endpoint function. Instead use epc->function_num_map which will already have the configured functions information (irrespective of whether the endpoint controller is associated with primary or secondary interface).
--- drivers/pci/controller/cadence/pcie-cadence-ep.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-)
drivers/pci/controller/cadence/pcie-cadence-ep.c +1 -6
@@ -506,18 +506,13 @@ static int cdns_pcie_ep_start(struct pci_epc *epc)struct cdns_pcie_ep *ep =epc_get_drvdata (epc);struct cdns_pcie *pcie = &ep->pcie;struct device *dev = pcie->dev; -struct pci_epf *epf; -u32 cfg;int ret;/* * BIT(0) is hardwired to 1, hence function 0 is always enabled * and can't be disabled anyway. */ - cfg =BIT (0 ); -list_for_each_entry (epf, &epc->pci_epf, list) - cfg |=BIT (epf->func_no); -cdns_pcie_writel (pcie,CDNS_PCIE_LM_EP_FUNC_CFG , cfg); +cdns_pcie_writel (pcie,CDNS_PCIE_LM_EP_FUNC_CFG , epc->function_num_map); ret =cdns_pcie_start_link (pcie);if (ret) {
Signature · 1 line
2.17.1
PATCH v9 13/17 PCI: endpoint: Add EP function driver to provide NTB functionality
In reply to Kishon Vijay Abraham IAdd a new endpoint function driver to provide NTB functionality using multiple PCIe endpoint instances.
--- drivers/pci/endpoint/functions/Kconfig | 12 + drivers/pci/endpoint/functions/Makefile | 1 + drivers/pci/endpoint/functions/pci-epf-ntb.c | 2114 ++++++++++++++++++ 3 files changed, 2127 insertions(+) create mode 100644 drivers/pci/endpoint/functions/pci-epf-ntb.c
drivers/pci/endpoint/functions/Kconfig +12 -0
@@ -12,3 +12,15 @@ config PCI_EPF_TEST for PCI Endpoint. If in doubt, say "N" to disable Endpoint test driver. + +config PCI_EPF_NTB + tristate "PCI Endpoint NTB driver" + depends on PCI_ENDPOINT + help + Select this configuration option to enable the NTB driver + for PCI Endpoint. NTB driver implements NTB controller + functionality using multiple PCIe endpoint instances. It + can support NTB endpoint function devices created using + device tree. + + If in doubt, say "N" to disable Endpoint NTB driver.
drivers/pci/endpoint/functions/Makefile +1 -0
@@ -4,3 +4,4 @@ # obj-$(CONFIG_PCI_EPF_TEST) += pci-epf-test.o +obj-$(CONFIG_PCI_EPF_NTB) += pci-epf-ntb.o
drivers/pci/endpoint/functions/pci-epf-ntb.c new file +2114 -0
2,114 lines not on this page · raw message
Signature · 1 line
2.17.1
Re: [PATCH v9 13/17] PCI: endpoint: Add EP function driver to provide NTB functionality
Quoted 4 lines · Kishon Vijay Abraham I
Add a new endpoint function driver to provide NTB functionality using multiple PCIe endpoint instances.
Signed-off-by Kishon Vijay Abraham I <[email protected]>
Several typos below if there's any opportunity for revision.
Quoted 46 lines
--- drivers/pci/endpoint/functions/Kconfig | 12 + drivers/pci/endpoint/functions/Makefile | 1 + drivers/pci/endpoint/functions/pci-epf-ntb.c | 2114 ++++++++++++++++++ 3 files changed, 2127 insertions(+) create mode 100644 drivers/pci/endpoint/functions/pci-epf-ntb.cdrivers/pci/endpoint/functions/Kconfig +12
-0@@ -12,3 +12,15 @@ config PCI_EPF_TEST for PCI Endpoint. If in doubt, say "N" to disable Endpoint test driver. + +config PCI_EPF_NTB + tristate "PCI Endpoint NTB driver" + depends on PCI_ENDPOINT + help + Select this configuration option to enable the NTB driver + for PCI Endpoint. NTB driver implements NTB controller + functionality using multiple PCIe endpoint instances. It + can support NTB endpoint function devices created using + device tree. + + If in doubt, say "N" to disable Endpoint NTB driver.drivers/pci/endpoint/functions/Makefile +1
-0@@ -4,3 +4,4 @@ # obj-$(CONFIG_PCI_EPF_TEST) += pci-epf-test.o +obj-$(CONFIG_PCI_EPF_NTB) += pci-epf-ntb.odrivers/pci/endpoint/functions/pci-epf-ntb.c new file +4
-0@@ -0,0 +1,2114 @@ +// SPDX-License-Identifier: GPL-2.0 +/** +* Endpoint Function Driver to implement Non-Transparent Bridge functionality +*
drivers/pci/endpoint/functions/pci-epf-ntb.c line 14
Quoted 10 lines
drivers/pci/endpoint/functions/pci-epf-ntb.c new file +10
-0+* Copyright (C) 2020 Texas Instruments +* Author: Kishon Vijay Abraham I <[email protected]> +*/ + +/* +*The PCI NTB function driver configures the SoC with multiple PCIe Endpoint(EP) +*controller instances (see diagram below) in such a way that transaction from +*one EP controller is routed to the other EP controller. Once PCI NTB function +*driver configures the SoC with multiple EP instances, HOST1 and HOST2 can +*communicate with each other using SoC as a bridge.
It's typical to use a space between the "*" and the text (also diagrams below).
s/transaction from ... is/transactions from ... are/
Quoted 139 lines
drivers/pci/endpoint/functions/pci-epf-ntb.c new file +139
-0+* +* +-------------+ +-------------+ +* | | | | +* | HOST1 | | HOST2 | +* | | | | +* +------^------+ +------^------+ +* | | +* | | +*+---------|-------------------------------------------------|---------+ +*| +------v------+ +------v------+ | +*| | | | | | +*| | EP | | EP | | +*| | CONTROLLER1 | | CONTROLLER2 | | +*| | <-----------------------------------> | | +*| | | | | | +*| | | | | | +*| | | SoC With Multiple EP Instances | | | +*| | | (Configured using NTB Function) | | | +*| +-------------+ +-------------+ | +*+---------------------------------------------------------------------+ +*/ + +#include <linux/delay.h> +#include <linux/io.h> +#include <linux/module.h> +#include <linux/slab.h> + +#include <linux/pci-epc.h> +#include <linux/pci-epf.h> + +static struct workqueue_struct *kpcintb_workqueue; + +#define COMMAND_CONFIGURE_DOORBELL 1 +#define COMMAND_TEARDOWN_DOORBELL 2 +#define COMMAND_CONFIGURE_MW 3 +#define COMMAND_TEARDOWN_MW 4 +#define COMMAND_LINK_UP 5 +#define COMMAND_LINK_DOWN 6 + +#define COMMAND_STATUS_OK 1 +#define COMMAND_STATUS_ERROR 2 + +#define LINK_STATUS_UP BIT(0) + +#define SPAD_COUNT 64 +#define DB_COUNT 4 +#define NTB_MW_OFFSET 2 +#define DB_COUNT_MASK GENMASK(15, 0) +#define MSIX_ENABLE BIT(16) +#define MAX_DB_COUNT 32 +#define MAX_MW 4 + +enum epf_ntb_bar { +BAR_CONFIG , +BAR_PEER_SPAD , +BAR_DB_MW1 , +BAR_MW2 , +BAR_MW3 , +BAR_MW4 , +}; + +struct epf_ntb { +u32 num_mws; +u32 db_count; +u32 spad_count; +struct pci_epf *epf; +u64 mws_size[MAX_MW ]; +struct config_group group; +struct epf_ntb_epc *epc[2 ]; +}; + +#define to_epf_ntb (epf_group) container_of((epf_group), struct epf_ntb, group) + +struct epf_ntb_epc { +u8 func_no; +bool linkup; +bool is_msix; +int msix_bar; +u32 spad_size; +struct pci_epc *epc; +struct epf_ntb *epf_ntb; +void __iomem *mw_addr[6 ]; +size_t msix_table_offset; +struct epf_ntb_ctrl *reg; +struct pci_epf_bar *epf_bar; +enum pci_barno epf_ntb_bar[6 ]; +struct delayed_work cmd_handler; +enum pci_epc_interface_type type; +const struct pci_epc_features *epc_features; +}; + +struct epf_ntb_ctrl { +u32 command; +u32 argument; +u16 command_status; +u16 link_status; +u32 topology; +u64 addr; +u64 size; +u32 num_mws; +u32 mw1_offset; +u32 spad_offset; +u32 spad_count; +u32 db_entry_size; +u32 db_data[MAX_DB_COUNT ]; +u32 db_offset[MAX_DB_COUNT ]; +} __packed; + +static struct pci_epf_header epf_ntb_header = { + .vendorid =PCI_ANY_ID , + .deviceid =PCI_ANY_ID , + .baseclass_code =PCI_BASE_CLASS_MEMORY , + .interrupt_pin =PCI_INTERRUPT_INTA , +}; + +/** +* epf_ntb_link_up() - Raise link_up interrupt to both the hosts +* @ntb: NTB device that facilitates communication between HOST1 and HOST2 +* @link_up: true or false indicating Link is UP or Down +* +* Once NTB function in HOST1 and the NTB function in HOST2 invoke +* ntb_link_enable(), this NTB function driver will trigger a link event to +* the NTB client in both the hosts. +*/ +static int epf_ntb_link_up (struct epf_ntb *ntb,bool link_up) +{ +enum pci_epc_interface_type type; +enum pci_epc_irq_type irq_type; +struct epf_ntb_epc *ntb_epc; +struct epf_ntb_ctrl *ctrl; +bool is_msix; +u8 func_no; +int ret; + +for (type =PRIMARY_INTERFACE ; type <=SECONDARY_INTERFACE ; type++) { + ntb_epc = ntb->epc[type]; + func_no = ntb_epc->func_no; + is_msix = ntb_epc->is_msix; + ctrl = ntb_epc->reg;
drivers/pci/endpoint/functions/pci-epf-ntb.c line 163
Quoted 10 lines
drivers/pci/endpoint/functions/pci-epf-ntb.c new file +10
-0+if (link_up) + ctrl->link_status |=LINK_STATUS_UP ; +else + ctrl->link_status &= ~LINK_STATUS_UP ; + irq_type = is_msix ?PCI_EPC_IRQ_MSIX :PCI_EPC_IRQ_MSI ; + ret =pci_epc_raise_irq (ntb_epc->epc, func_no, irq_type, +1 ); +if (ret <0 ) { +WARN (1 ,"%s intf: Failed to raise Link Up IRQ\n" , +pci_epc_interface_string (type));
Do we not have a dev available here? Several messages below use dev_err(); can we do the same here?
Quoted 37 lines
drivers/pci/endpoint/functions/pci-epf-ntb.c new file +37
-0+return ret; + } + } + +return 0 ; +} + +/** +* epf_ntb_configure_mw() - Configure the Outbound Address Space for one host +* to access the memory window of other host +* @ntb: NTB device that facilitates communication between HOST1 and HOST2 +* @type: PRIMARY interface or SECONDARY interface +* @mw: Index of the memory window (either 0, 1, 2 or 3) +* +*+-----------------+ +----->+----------------+-----------+-----------------+ +*| BAR0 | | | Doorbell 1 +-----------> MSI|X ADDRESS 1 | +*+-----------------+ | +----------------+ +-----------------+ +*| BAR1 | | | Doorbell 2 +---------+ | | +*+-----------------+----+ +----------------+ | | | +*| BAR2 | | Doorbell 3 +-------+ | +-----------------+ +*+-----------------+----+ +----------------+ | +-> MSI|X ADDRESS 2 | +*| BAR3 | | | Doorbell 4 +-----+ | +-----------------+ +*+-----------------+ | |----------------+ | | | | +*| BAR4 | | | | | | +-----------------+ +*+-----------------+ | | MW1 +---+ | +-->+ MSI|X ADDRESS 3|| +*| BAR5 | | | | | | +-----------------+ +*+-----------------+ +----->-----------------+ | | | | +* EP CONTROLLER 1 | | | | +-----------------+ +* | | | +---->+ MSI|X ADDRESS 4 | +* +----------------+ | +-----------------+ +* (A) EP CONTROLLER 2 | | | +* (OB SPACE) | | | +* +-------> MW1 | +* | | +* | | +* (B) +-----------------+ +* | |
drivers/pci/endpoint/functions/pci-epf-ntb.c line 210
Quoted 10 lines
drivers/pci/endpoint/functions/pci-epf-ntb.c new file +10
-0+* | | +* | | +* | | +* | | +* +-----------------+ +* PCI Address Space +* (Managed by HOST2) +* +* This function performs stage (B) in the above diagram (see MW1) i.e map OB +* address space of memory window to PCI address space.
s/i.e/i.e.,/
drivers/pci/endpoint/functions/pci-epf-ntb.c line 214
Quoted 4 lines
drivers/pci/endpoint/functions/pci-epf-ntb.c new file +4
-0+* +* This operation requires 3 parameters +* 1) Address in the outbound address space +* 2) Address in the PCIe Address space
s/PCIe/PCI/ (since that's what you called it above and there really isn't anything PCIe-specific here)
drivers/pci/endpoint/functions/pci-epf-ntb.c line 215
Quoted 1 line
drivers/pci/endpoint/functions/pci-epf-ntb.c new file +1
-0+* 3) Size of the address region that is requested to be mapped
s/that is requested to be/to be/
drivers/pci/endpoint/functions/pci-epf-ntb.c line 222
Quoted 6 lines
drivers/pci/endpoint/functions/pci-epf-ntb.c new file +6
-0+* The address in the outbound address space (for MW1, MW2, MW3 and MW4) is +* stored in epf_bar corresponding to BAR_DB_MW1 for MW1 and BAR_MW2, BAR_MW3 +* BAR_MW4 for rest of the BARs of epf_ntb_epc that is connected to HOST1. This +* is populated in epf_ntb_alloc_peer_mem() in this driver. +* +* The address and size of the PCIe address region that has to be mapped would
s/PCIe/PCI/ again
drivers/pci/endpoint/functions/pci-epf-ntb.c line 233
Quoted 11 lines
drivers/pci/endpoint/functions/pci-epf-ntb.c new file +11
-0+* be provided by HOST2 in ctrl->addr and ctrl->size of epf_ntb_epc that is +* connected to HOST2. +* +* Please note Memory window1 (MW1) and Doorbell registers together will be +* mapped to a single BAR (BAR2) above for 32-bit BARs. The exact BAR that's +* used for Memory window (MW) can be obtained from epf_ntb_bar[BAR_DB_MW1], +* epf_ntb_bar[BAR_MW2], epf_ntb_bar[BAR_MW2], epf_ntb_bar[BAR_MW2]. +*/ +static int +epf_ntb_configure_mw (struct epf_ntb *ntb,enum pci_epc_interface_type type, +u32 mw)
Return type & function name normally on same line (more occurrences below).
Quoted 224 lines
drivers/pci/endpoint/functions/pci-epf-ntb.c new file +224
-0+{ +struct epf_ntb_epc *peer_ntb_epc, *ntb_epc; +struct pci_epf_bar *peer_epf_bar; +enum pci_barno peer_barno; +struct epf_ntb_ctrl *ctrl; +phys_addr_t phys_addr; +struct pci_epc *epc; +u64 addr, size; +int ret =0 ; +u8 func_no; + + ntb_epc = ntb->epc[type]; + epc = ntb_epc->epc; + + peer_ntb_epc = ntb->epc[!type]; + peer_barno = peer_ntb_epc->epf_ntb_bar[mw +NTB_MW_OFFSET ]; + peer_epf_bar = &peer_ntb_epc->epf_bar[peer_barno]; + + phys_addr = peer_epf_bar->phys_addr; + ctrl = ntb_epc->reg; + addr = ctrl->addr; + size = ctrl->size; +if (mw +NTB_MW_OFFSET ==BAR_DB_MW1 ) + phys_addr += ctrl->mw1_offset; + +if (size > ntb->mws_size[mw]) { +WARN (1 ,"%s intf: MW: %d Req Sz:%llxx > Supported Sz:%llx\n" , +pci_epc_interface_string (type), mw, size, + ntb->mws_size[mw]); + ret = -EINVAL ; + goto err_invalid_size; + } + + func_no = ntb_epc->func_no; + + ret =pci_epc_map_addr (epc, func_no, phys_addr, addr, size); +WARN (ret <0 ,"%s intf: Failed to map memory window %d address\n" , +pci_epc_interface_string (type), mw); + +err_invalid_size: + +return ret; +} + +/** +* epf_ntb_teardown_mw() - Teardown the configured OB ATU +* @ntb: NTB device that facilitates communication between HOST1 and HOST2 +* @type: PRIMARY interface or SECONDARY interface +* @mw: Index of the memory window (either 0, 1, 2 or 3) +* +* Teardown the configured OB ATU configured in epf_ntb_configure_mw() using +* pci_epc_unmap_addr() +*/ +static void +epf_ntb_teardown_mw (struct epf_ntb *ntb,enum pci_epc_interface_type type, +u32 mw) +{ +struct epf_ntb_epc *peer_ntb_epc, *ntb_epc; +struct pci_epf_bar *peer_epf_bar; +enum pci_barno peer_barno; +struct epf_ntb_ctrl *ctrl; +phys_addr_t phys_addr; +struct pci_epc *epc; +u8 func_no; + + ntb_epc = ntb->epc[type]; + epc = ntb_epc->epc; + + peer_ntb_epc = ntb->epc[!type]; + peer_barno = peer_ntb_epc->epf_ntb_bar[mw +NTB_MW_OFFSET ]; + peer_epf_bar = &peer_ntb_epc->epf_bar[peer_barno]; + + phys_addr = peer_epf_bar->phys_addr; + ctrl = ntb_epc->reg; +if (mw +NTB_MW_OFFSET ==BAR_DB_MW1 ) + phys_addr += ctrl->mw1_offset; + func_no = ntb_epc->func_no; + +pci_epc_unmap_addr (epc, func_no, phys_addr); +} + +/** +* epf_ntb_configure_msi() - Map OB address space to MSI address +* @ntb: NTB device that facilitates communication between HOST1 and HOST2 +* @type: PRIMARY interface or SECONDARY interface +* @db_count: Number of doorbell interrupts to map +* +*+-----------------+ +----->+----------------+-----------+-----------------+ +*| BAR0 | | | Doorbell 1 +---+-------> MSI ADDRESS | +*+-----------------+ | +----------------+ | +-----------------+ +*| BAR1 | | | Doorbell 2 +---+ | | +*+-----------------+----+ +----------------+ | | | +*| BAR2 | | Doorbell 3 +---+ | | +*+-----------------+----+ +----------------+ | | | +*| BAR3 | | | Doorbell 4 +---+ | | +*+-----------------+ | |----------------+ | | +*| BAR4 | | | | | | +*+-----------------+ | | MW1 | | | +*| BAR5 | | | | | | +*+-----------------+ +----->-----------------+ | | +* EP CONTROLLER 1 | | | | +* | | | | +* +----------------+ +-----------------+ +* (A) EP CONTROLLER 2 | | +* (OB SPACE) | | +* | MW1 | +* | | +* | | +* (B) +-----------------+ +* | | +* | | +* | | +* | | +* | | +* +-----------------+ +* PCI Address Space +* (Managed by HOST2) +* +* +* This function performs stage (B) in the above diagram (see Doorbell 1, +* Doorbell 2, Doorbell 3, Doorbell 4) i.e map OB address space corresponding to +* doorbell to MSI address in PCI address space. +* +* This operation requires 3 parameters +* 1) Address reserved for doorbell in the outbound address space +* 2) MSI-X address in the PCIe Address space +* 3) Number of MSI-X interrupts that has to be configured +* +* The address in the outbound address space (for the Doorbell) is stored in +* epf_bar corresponding to BAR_DB_MW1 of epf_ntb_epc that is connected to +* HOST1. This is populated in epf_ntb_alloc_peer_mem() in this driver along +* with address for MW1. +* +* pci_epc_map_msi_irq() takes the MSI address from MSI capability register +* and maps the OB address (obtained in epf_ntb_alloc_peer_mem()) to the MSI +* address. +* +* epf_ntb_configure_msi() also stores the MSI data to raise each interrupt +* in db_data of the peer's control region. This helps the peer to raise +* doorbell of the other host by writing db_data to the BAR corresponding to +* BAR_DB_MW1. +*/ +static int +epf_ntb_configure_msi (struct epf_ntb *ntb,enum pci_epc_interface_type type, +u16 db_count) +{ +struct epf_ntb_epc *peer_ntb_epc, *ntb_epc; +u32 db_entry_size, db_data, db_offset; +struct pci_epf_bar *peer_epf_bar; +struct epf_ntb_ctrl *peer_ctrl; +enum pci_barno peer_barno; +phys_addr_t phys_addr; +struct pci_epc *epc; +u8 func_no; +int ret, i; + + ntb_epc = ntb->epc[type]; + epc = ntb_epc->epc; + + peer_ntb_epc = ntb->epc[!type]; + peer_barno = peer_ntb_epc->epf_ntb_bar[BAR_DB_MW1 ]; + peer_epf_bar = &peer_ntb_epc->epf_bar[peer_barno]; + peer_ctrl = peer_ntb_epc->reg; + db_entry_size = peer_ctrl->db_entry_size; + + phys_addr = peer_epf_bar->phys_addr; + func_no = ntb_epc->func_no; + + ret =pci_epc_map_msi_irq (epc, func_no, phys_addr, db_count, + db_entry_size, &db_data, &db_offset); +if (ret <0 ) { +WARN (1 ,"%s intf: Failed to map MSI IRQ\n" , +pci_epc_interface_string (type)); +return ret; + } + +for (i =0 ; i < db_count; i++) { + peer_ctrl->db_data[i] = db_data | i; + peer_ctrl->db_offset[i] = db_offset; + } + +return 0 ; +} + +/** +* epf_ntb_configure_msix() - Map OB address space to MSI-X address +* @ntb: NTB device that facilitates communication between HOST1 and HOST2 +* @type: PRIMARY interface or SECONDARY interface +* @db_count: Number of doorbell interrupts to map +* +*+-----------------+ +----->+----------------+-----------+-----------------+ +*| BAR0 | | | Doorbell 1 +-----------> MSI-X ADDRESS 1 | +*+-----------------+ | +----------------+ +-----------------+ +*| BAR1 | | | Doorbell 2 +---------+ | | +*+-----------------+----+ +----------------+ | | | +*| BAR2 | | Doorbell 3 +-------+ | +-----------------+ +*+-----------------+----+ +----------------+ | +-> MSI-X ADDRESS 2 | +*| BAR3 | | | Doorbell 4 +-----+ | +-----------------+ +*+-----------------+ | |----------------+ | | | | +*| BAR4 | | | | | | +-----------------+ +*+-----------------+ | | MW1 + | +-->+ MSI-X ADDRESS 3|| +*| BAR5 | | | | | +-----------------+ +*+-----------------+ +----->-----------------+ | | | +* EP CONTROLLER 1 | | | +-----------------+ +* | | +---->+ MSI-X ADDRESS 4 | +* +----------------+ +-----------------+ +* (A) EP CONTROLLER 2 | | +* (OB SPACE) | | +* | MW1 | +* | | +* | | +* (B) +-----------------+ +* | | +* | | +* | | +* | | +* | | +* +-----------------+ +* PCI Address Space +* (Managed by HOST2) +* +* This function performs stage (B) in the above diagram (see Doorbell 1, +* Doorbell 2, Doorbell 3, Doorbell 4) i.e map OB address space corresponding to +* doorbell to MSI-X address in PCI address space.
drivers/pci/endpoint/functions/pci-epf-ntb.c line 467
Quoted 10 lines
drivers/pci/endpoint/functions/pci-epf-ntb.c new file +10
-0+* +* This operation requires 3 parameters +* 1) Address reserved for doorbell in the outbound address space +* 2) MSI-X address in the PCIe Address space +* 3) Number of MSI-X interrupts that has to be configured +* +* The address in the outbound address space (for the Doorbell) is stored in +* epf_bar corresponding to BAR_DB_MW1 of epf_ntb_epc that is connected to +* HOST1. This is populated in epf_ntb_alloc_peer_mem() in this driver along +* with address for MW1.
Add blank line if the below is a new paragraph. Otherwise, reflow.
drivers/pci/endpoint/functions/pci-epf-ntb.c line 472
Quoted 5 lines
drivers/pci/endpoint/functions/pci-epf-ntb.c new file +5
-0+* The MSI-X address is in the MSI-X table of EP CONTROLLER 2 and +* the count of doorbell is in ctrl->argument of epf_ntb_epc that is connected +* to HOST2. MSI-X table is stored memory mapped to ntb_epc->msix_bar and the +* offset is in ntb_epc->msix_table_offset. From this epf_ntb_configure_msix() +* gets the MSI-X address and MSI-X data
s/MSI-X address and MSI-X data/MSI-X address and data/ Period at end of sentence.
Quoted 203 lines
drivers/pci/endpoint/functions/pci-epf-ntb.c new file +203
-0+* +* epf_ntb_configure_msix() also stores the MSI-X data to raise each interrupt +* in db_data of the peer's control region. This helps the peer to raise +* doorbell of the other host by writing db_data to the BAR corresponding to +* BAR_DB_MW1. +*/ +static int epf_ntb_configure_msix (struct epf_ntb *ntb, +enum pci_epc_interface_type type, +u16 db_count) +{ +const struct pci_epc_features *epc_features; +struct epf_ntb_epc *peer_ntb_epc, *ntb_epc; +struct pci_epf_bar *peer_epf_bar, *epf_bar; +struct pci_epf_msix_tbl *msix_tbl; +struct epf_ntb_ctrl *peer_ctrl; +u32 db_entry_size, msg_data; +enum pci_barno peer_barno; +phys_addr_t phys_addr; +struct pci_epc *epc; +size_t align; +u64 msg_addr; +u8 func_no; +int ret, i; + + ntb_epc = ntb->epc[type]; + epc = ntb_epc->epc; + + epf_bar = &ntb_epc->epf_bar[ntb_epc->msix_bar]; + msix_tbl = epf_bar->addr + ntb_epc->msix_table_offset; + + peer_ntb_epc = ntb->epc[!type]; + peer_barno = peer_ntb_epc->epf_ntb_bar[BAR_DB_MW1 ]; + peer_epf_bar = &peer_ntb_epc->epf_bar[peer_barno]; + phys_addr = peer_epf_bar->phys_addr; + peer_ctrl = peer_ntb_epc->reg; + epc_features = ntb_epc->epc_features; + align = epc_features->align; + + func_no = ntb_epc->func_no; + db_entry_size = peer_ctrl->db_entry_size; + +for (i =0 ; i < db_count; i++) { + msg_addr =ALIGN_DOWN (msix_tbl[i].msg_addr, align); + msg_data = msix_tbl[i].msg_data; + ret =pci_epc_map_addr (epc, func_no, phys_addr, msg_addr, + db_entry_size); +if (ret) +return ret; + phys_addr = phys_addr + db_entry_size; + peer_ctrl->db_data[i] = msg_data; + peer_ctrl->db_offset[i] = msix_tbl[i].msg_addr & (align -1 ); + } + ntb_epc->is_msix = true; + +return 0 ; +} + +/** +* epf_ntb_configure_db() - Configure the Outbound Address Space for one host +* to ring the doorbell of other host +* @ntb: NTB device that facilitates communication between HOST1 and HOST2 +* @type: PRIMARY interface or SECONDARY interface +* @db_count: Count of the number of doorbells that has to be configured +* @msix: Indicates whether MSI-X or MSI should be used +* +* Invokes epf_ntb_configure_msix() or epf_ntb_configure_msi() required for +* one HOST to ring the doorbell of other HOST. +*/ +static int +epf_ntb_configure_db (struct epf_ntb *ntb,enum pci_epc_interface_type type, +u16 db_count,bool msix) +{ +int ret; + +if (db_count >MAX_DB_COUNT ) +return -EINVAL ; + +if (msix) + ret =epf_ntb_configure_msix (ntb, type, db_count); +else + ret =epf_ntb_configure_msi (ntb, type, db_count); + +WARN (ret <0 ,"%s intf: Failed to configure DB\n" , +pci_epc_interface_string (type)); + +return ret; +} + +/** +* epf_ntb_teardown_db() - Unmap address in OB address space to MSI/MSI-X +* address +* @ntb: NTB device that facilitates communication between HOST1 and HOST2 +* @type: PRIMARY interface or SECONDARY interface +* +* Invoke pci_epc_unmap_addr() to unmap OB address to MSI/MSI-X address. +*/ +static void +epf_ntb_teardown_db (struct epf_ntb *ntb,enum pci_epc_interface_type type) +{ +struct epf_ntb_epc *peer_ntb_epc, *ntb_epc; +struct pci_epf_bar *peer_epf_bar; +enum pci_barno peer_barno; +phys_addr_t phys_addr; +struct pci_epc *epc; +u8 func_no; + + ntb_epc = ntb->epc[type]; + epc = ntb_epc->epc; + + peer_ntb_epc = ntb->epc[!type]; + peer_barno = peer_ntb_epc->epf_ntb_bar[BAR_DB_MW1 ]; + peer_epf_bar = &peer_ntb_epc->epf_bar[peer_barno]; + phys_addr = peer_epf_bar->phys_addr; + func_no = ntb_epc->func_no; + +pci_epc_unmap_addr (epc, func_no, phys_addr); +} + +/** +* epf_ntb_cmd_handler() - Handle commands provided by the NTB Host +* @work: work_struct for the two epf_ntb_epc (PRIMARY and SECONDARY) +* +* Workqueue function that gets invoked for the two epf_ntb_epc +* periodically (once every 5ms) to see if it has received any commands +* from NTB host. The host can send commands to configure doorbell or +* configure memory window or to update link status. +*/ +static void epf_ntb_cmd_handler (struct work_struct *work) +{ +enum pci_epc_interface_type type; +struct epf_ntb_epc *ntb_epc; +struct epf_ntb_ctrl *ctrl; +u32 command, argument; +struct epf_ntb *ntb; +struct device *dev; +u16 db_count; +bool is_msix; +int ret; + + ntb_epc = container_of(work, struct epf_ntb_epc, cmd_handler.work); + ctrl = ntb_epc->reg; + command = ctrl->command; +if (!command) + goto reset_handler; + argument = ctrl->argument; + + ctrl->command =0 ; + ctrl->argument =0 ; + + ctrl = ntb_epc->reg; + type = ntb_epc->type; + ntb = ntb_epc->epf_ntb; + dev = &ntb->epf->dev; + +switch (command) { +case COMMAND_CONFIGURE_DOORBELL : + db_count = argument &DB_COUNT_MASK ; + is_msix = argument &MSIX_ENABLE ; + ret =epf_ntb_configure_db (ntb, type, db_count, is_msix); +if (ret <0 ) + ctrl->command_status =COMMAND_STATUS_ERROR ; +else + ctrl->command_status =COMMAND_STATUS_OK ; +break ; +case COMMAND_TEARDOWN_DOORBELL : +epf_ntb_teardown_db (ntb, type); + ctrl->command_status =COMMAND_STATUS_OK ; +break ; +case COMMAND_CONFIGURE_MW : + ret =epf_ntb_configure_mw (ntb, type, argument); +if (ret <0 ) + ctrl->command_status =COMMAND_STATUS_ERROR ; +else + ctrl->command_status =COMMAND_STATUS_OK ; +break ; +case COMMAND_TEARDOWN_MW : +epf_ntb_teardown_mw (ntb, type, argument); + ctrl->command_status =COMMAND_STATUS_OK ; +break ; +case COMMAND_LINK_UP : + ntb_epc->linkup = true; +if (ntb->epc[PRIMARY_INTERFACE ]->linkup && + ntb->epc[SECONDARY_INTERFACE ]->linkup) { + ret =epf_ntb_link_up (ntb, true); +if (ret <0 ) + ctrl->command_status =COMMAND_STATUS_ERROR ; +else + ctrl->command_status =COMMAND_STATUS_OK ; + goto reset_handler; + } + ctrl->command_status =COMMAND_STATUS_OK ; +break ; +case COMMAND_LINK_DOWN : + ntb_epc->linkup = false; + ret =epf_ntb_link_up (ntb, false); +if (ret <0 ) + ctrl->command_status =COMMAND_STATUS_ERROR ; +else + ctrl->command_status =COMMAND_STATUS_OK ; +break ; +default : +dev_err (dev,"%s intf UNKNOWN command: %d\n" , +pci_epc_interface_string (type), command);
drivers/pci/endpoint/functions/pci-epf-ntb.c line 685
Quoted 10 lines
drivers/pci/endpoint/functions/pci-epf-ntb.c new file +10
-0+break ; + } + +reset_handler: +queue_delayed_work (kpcintb_workqueue, &ntb_epc->cmd_handler, +msecs_to_jiffies (5 )); +} + +/** +* epf_ntb_peer_spad_bar_clear() - Clears Peer Scratchpad BAR
s/Clears/Clear/
Quoted 12 lines
drivers/pci/endpoint/functions/pci-epf-ntb.c new file +12
-0+* @ntb: NTB device that facilitates communication between HOST1 and HOST2 +* +*+-----------------+------->+------------------+ +-----------------+ +*| BAR0 | | CONFIG REGION | | BAR0 | +*+-----------------+----+ +------------------+<-------+-----------------+ +*| BAR1 | | |SCRATCHPAD REGION | | BAR1 | +*+-----------------+ +-->+------------------+<-------+-----------------+ +*| BAR2 | Local Memory | BAR2 | +*+-----------------+ +-----------------+ +*| BAR3 | | BAR3 | +*+-----------------+ +-----------------+ +*| BAR4 | | BAR4 |
drivers/pci/endpoint/functions/pci-epf-ntb.c line 707
Quoted 10 lines
drivers/pci/endpoint/functions/pci-epf-ntb.c new file +10
-0+ *+-----------------+ +-----------------+ + *| BAR5 | | BAR5 | + *+-----------------+ +-----------------+ + * EP CONTROLLER 1 EP CONTROLLER 2 + * + * It clears BAR1 of EP CONTROLLER 2 which contains the HOST2's peer scratchpad + * region. While BAR1 is the default peer scratchpad BAR, an NTB could have + * other BARs for peer scratchpad (because of 64-bit BARs or reserved BARs). + * This function can get the exact BAR used for peer scratchpad from + * epf_ntb_bar[BAR_PEER_SPAD].
/It clears/Clear/
drivers/pci/endpoint/functions/pci-epf-ntb.c line 711
Quoted 4 lines
drivers/pci/endpoint/functions/pci-epf-ntb.c new file +4
-0+* +* Since HOST2's peer scratchpad is also HOST1's self scratchpad, this function +* gets the address of peer scratchpad from +* peer_ntb_epc->epf_ntb_bar[BAR_CONFIG]
Period at end of sentence.
Quoted 7 lines
drivers/pci/endpoint/functions/pci-epf-ntb.c new file +7
-0+*/ +static void epf_ntb_peer_spad_bar_clear (struct epf_ntb_epc *ntb_epc) +{ +struct pci_epf_bar *epf_bar; +enum pci_barno barno; +struct pci_epc *epc; +u8 func_no;
drivers/pci/endpoint/functions/pci-epf-ntb.c line 728
Quoted 10 lines
drivers/pci/endpoint/functions/pci-epf-ntb.c new file +10
-0+ + epc = ntb_epc->epc; + func_no = ntb_epc->func_no; + barno = ntb_epc->epf_ntb_bar[BAR_PEER_SPAD ]; + epf_bar = &ntb_epc->epf_bar[barno]; +pci_epc_clear_bar (epc, func_no, epf_bar); +} + +/** +* epf_ntb_peer_spad_bar_set() - Sets peer scratchpad BAR
s/Sets/Set/
Quoted 12 lines
drivers/pci/endpoint/functions/pci-epf-ntb.c new file +12
-0+* @ntb: NTB device that facilitates communication between HOST1 and HOST2 +* +*+-----------------+------->+------------------+ +-----------------+ +*| BAR0 | | CONFIG REGION | | BAR0 | +*+-----------------+----+ +------------------+<-------+-----------------+ +*| BAR1 | | |SCRATCHPAD REGION | | BAR1 | +*+-----------------+ +-->+------------------+<-------+-----------------+ +*| BAR2 | Local Memory | BAR2 | +*+-----------------+ +-----------------+ +*| BAR3 | | BAR3 | +*+-----------------+ +-----------------+ +*| BAR4 | | BAR4 |
drivers/pci/endpoint/functions/pci-epf-ntb.c line 750
Quoted 10 lines
drivers/pci/endpoint/functions/pci-epf-ntb.c new file +10
-0+ *+-----------------+ +-----------------+ + *| BAR5 | | BAR5 | + *+-----------------+ +-----------------+ + * EP CONTROLLER 1 EP CONTROLLER 2 + * + * It sets BAR1 of EP CONTROLLER 2 which contains the HOST2's peer scratchpad + * region. While BAR1 is the default peer scratchpad BAR, an NTB could have + * other BARs for peer scratchpad (because of 64-bit BARs or reserved BARs). + * This function can get the exact BAR used for peer scratchpad from + * epf_ntb_bar[BAR_PEER_SPAD].
s/It sets/Set/
drivers/pci/endpoint/functions/pci-epf-ntb.c line 711
Quoted 4 lines
drivers/pci/endpoint/functions/pci-epf-ntb.c new file +4
-0+* +* Since HOST2's peer scratchpad is also HOST1's self scratchpad, this function +* gets the address of peer scratchpad from +* peer_ntb_epc->epf_ntb_bar[BAR_CONFIG]
Period at end.
Quoted 33 lines
drivers/pci/endpoint/functions/pci-epf-ntb.c new file +33
-0+*/ +static int +epf_ntb_peer_spad_bar_set (struct epf_ntb *ntb,enum pci_epc_interface_type type) +{ +struct epf_ntb_epc *peer_ntb_epc, *ntb_epc; +struct pci_epf_bar *peer_epf_bar, *epf_bar; +enum pci_barno peer_barno, barno; +u32 peer_spad_offset; +struct pci_epc *epc; +struct device *dev; +u8 func_no; +int ret; + + dev = &ntb->epf->dev; + + peer_ntb_epc = ntb->epc[!type]; + peer_barno = peer_ntb_epc->epf_ntb_bar[BAR_CONFIG ]; + peer_epf_bar = &peer_ntb_epc->epf_bar[peer_barno]; + + ntb_epc = ntb->epc[type]; + barno = ntb_epc->epf_ntb_bar[BAR_PEER_SPAD ]; + epf_bar = &ntb_epc->epf_bar[barno]; + func_no = ntb_epc->func_no; + epc = ntb_epc->epc; + + peer_spad_offset = peer_ntb_epc->reg->spad_offset; + epf_bar->phys_addr = peer_epf_bar->phys_addr + peer_spad_offset; + epf_bar->size = peer_ntb_epc->spad_size; + epf_bar->barno = barno; + epf_bar->flags =PCI_BASE_ADDRESS_MEM_TYPE_32 ; + + ret =pci_epc_set_bar (ntb_epc->epc, func_no, epf_bar); +if (ret) {
drivers/pci/endpoint/functions/pci-epf-ntb.c line 797
Quoted 10 lines
drivers/pci/endpoint/functions/pci-epf-ntb.c new file +10
-0+dev_err (dev,"%s intf: peer SPAD BAR set failed\n" , +pci_epc_interface_string (type)); +return ret; + } + +return 0 ; +} + +/** +* epf_ntb_config_sspad_bar_clear() - Clears Config + Self scratchpad BAR
s/Clears/Clear/
Quoted 12 lines
drivers/pci/endpoint/functions/pci-epf-ntb.c new file +12
-0+* @ntb: NTB device that facilitates communication between HOST1 and HOST2 +* +*+-----------------+------->+------------------+ +-----------------+ +*| BAR0 | | CONFIG REGION | | BAR0 | +*+-----------------+----+ +------------------+<-------+-----------------+ +*| BAR1 | | |SCRATCHPAD REGION | | BAR1 | +*+-----------------+ +-->+------------------+<-------+-----------------+ +*| BAR2 | Local Memory | BAR2 | +*+-----------------+ +-----------------+ +*| BAR3 | | BAR3 | +*+-----------------+ +-----------------+ +*| BAR4 | | BAR4 |
drivers/pci/endpoint/functions/pci-epf-ntb.c line 819
Quoted 10 lines
drivers/pci/endpoint/functions/pci-epf-ntb.c new file +10
-0+ *+-----------------+ +-----------------+ + *| BAR5 | | BAR5 | + *+-----------------+ +-----------------+ + * EP CONTROLLER 1 EP CONTROLLER 2 + * + * It clears BAR0 of EP CONTROLLER 1 which contains the HOST1's config and + * self scratchpad region (removes inbound ATU configuration). While BAR0 is + * the default self scratchpad BAR, an NTB could have other BARs for self + * scratchpad (because of reserved BARs). This function can get the exact BAR + * used for self scratchpad from epf_ntb_bar[BAR_CONFIG].
s/It clears/Clear/
Quoted 11 lines
drivers/pci/endpoint/functions/pci-epf-ntb.c new file +11
-0+* +* Please note the self scratchpad region and config region is combined to +* a single region and mapped using the same BAR. Also note HOST2's peer +* scratchpad is HOST1's self scratchpad. +*/ +static void epf_ntb_config_sspad_bar_clear (struct epf_ntb_epc *ntb_epc) +{ +struct pci_epf_bar *epf_bar; +enum pci_barno barno; +struct pci_epc *epc; +u8 func_no;
drivers/pci/endpoint/functions/pci-epf-ntb.c line 840
Quoted 10 lines
drivers/pci/endpoint/functions/pci-epf-ntb.c new file +10
-0+ + epc = ntb_epc->epc; + func_no = ntb_epc->func_no; + barno = ntb_epc->epf_ntb_bar[BAR_CONFIG ]; + epf_bar = &ntb_epc->epf_bar[barno]; +pci_epc_clear_bar (epc, func_no, epf_bar); +} + +/** +* epf_ntb_config_sspad_bar_set() - Sets Config + Self scratchpad BAR
s/Sets/Set/
Quoted 8 lines
drivers/pci/endpoint/functions/pci-epf-ntb.c new file +8
-0+* @ntb: NTB device that facilitates communication between HOST1 and HOST2 +* +*+-----------------+------->+------------------+ +-----------------+ +*| BAR0 | | CONFIG REGION | | BAR0 | +*+-----------------+----+ +------------------+<-------+-----------------+ +*| BAR1 | | |SCRATCHPAD REGION | | BAR1 | +*+-----------------+ +-->+------------------+<-------+-----------------+ +*| BAR2 | Local Memory | BAR2 |
drivers/pci/endpoint/functions/pci-epf-ntb.c line 858
Quoted 10 lines
drivers/pci/endpoint/functions/pci-epf-ntb.c new file +10
-0+ *+-----------------+ +-----------------+ + *| BAR3 | | BAR3 | + *+-----------------+ +-----------------+ + *| BAR4 | | BAR4 | + *+-----------------+ +-----------------+ + *| BAR5 | | BAR5 | + *+-----------------+ +-----------------+ + * EP CONTROLLER 1 EP CONTROLLER 2 + * + * It maps BAR0 of EP CONTROLLER 1 which contains the HOST1's config and
s/It maps/Map/
Quoted 50 lines
drivers/pci/endpoint/functions/pci-epf-ntb.c new file +50
-0+* self scratchpad region. While BAR0 is the default self scratchpad BAR, an +* NTB could have other BARs for self scratchpad (because of reserved BARs). +* This function can get the exact BAR used for self scratchpad from +* epf_ntb_bar[BAR_CONFIG]. +* +* Please note the self scratchpad region and config region is combined to +* a single region and mapped using the same BAR. Also note HOST2's peer +* scratchpad is HOST1's self scratchpad. +*/ +static int epf_ntb_config_sspad_bar_set (struct epf_ntb_epc *ntb_epc) +{ +struct pci_epf_bar *epf_bar; +enum pci_barno barno; +struct epf_ntb *ntb; +struct pci_epc *epc; +struct device *dev; +u8 func_no; +int ret; + + ntb = ntb_epc->epf_ntb; + dev = &ntb->epf->dev; + + epc = ntb_epc->epc; + func_no = ntb_epc->func_no; + barno = ntb_epc->epf_ntb_bar[BAR_CONFIG ]; + epf_bar = &ntb_epc->epf_bar[barno]; + + ret =pci_epc_set_bar (epc, func_no, epf_bar); +if (ret) { +dev_err (dev,"%s inft: Config/Status/SPAD BAR set failed\n" , +pci_epc_interface_string (ntb_epc->type)); +return ret; + } + +return 0 ; +} + +/** +* epf_ntb_config_spad_bar_free() - Free the physical memory associated with +* config + scratchpad region +* @ntb: NTB device that facilitates communication between HOST1 and HOST2 +* +*+-----------------+------->+------------------+ +-----------------+ +*| BAR0 | | CONFIG REGION | | BAR0 | +*+-----------------+----+ +------------------+<-------+-----------------+ +*| BAR1 | | |SCRATCHPAD REGION | | BAR1 | +*+-----------------+ +-->+------------------+<-------+-----------------+ +*| BAR2 | Local Memory | BAR2 | +*+-----------------+ +-----------------+ +*| BAR3 | | BAR3 |
drivers/pci/endpoint/functions/pci-epf-ntb.c line 918
Quoted 10 lines
drivers/pci/endpoint/functions/pci-epf-ntb.c new file +10
-0+ *+-----------------+ +-----------------+ + *| BAR4 | | BAR4 | + *+-----------------+ +-----------------+ + *| BAR5 | | BAR5 | + *+-----------------+ +-----------------+ + * EP CONTROLLER 1 EP CONTROLLER 2 + * + * This function frees the Local Memory mentioned in the above diagram. After + * invoking this function, any of config + self scrathpad region of HOST1 or + * peer scratchpad region of HOST2 should not be accessed.
s/This function frees/Free/
s/scrathpad/scratchpad/
Quoted 31 lines
drivers/pci/endpoint/functions/pci-epf-ntb.c new file +31
-0+*/ +static void epf_ntb_config_spad_bar_free (struct epf_ntb *ntb) +{ +enum pci_epc_interface_type type; +struct epf_ntb_epc *ntb_epc; +enum pci_barno barno; +struct pci_epf *epf; + + epf = ntb->epf; +for (type =PRIMARY_INTERFACE ; type <=SECONDARY_INTERFACE ; type++) { + ntb_epc = ntb->epc[type]; + barno = ntb_epc->epf_ntb_bar[BAR_CONFIG ]; +if (ntb_epc->reg) +pci_epf_free_space (epf, ntb_epc->reg, barno, type); + } +} + +/** +* epf_ntb_config_spad_bar_alloc() - Allocate memory for config + scratchpad +* region +* @ntb: NTB device that facilitates communication between HOST1 and HOST2 +* @type: PRIMARY interface or SECONDARY interface +* +*+-----------------+------->+------------------+ +-----------------+ +*| BAR0 | | CONFIG REGION | | BAR0 | +*+-----------------+----+ +------------------+<-------+-----------------+ +*| BAR1 | | |SCRATCHPAD REGION | | BAR1 | +*+-----------------+ +-->+------------------+<-------+-----------------+ +*| BAR2 | Local Memory | BAR2 | +*+-----------------+ +-----------------+ +*| BAR3 | | BAR3 |
drivers/pci/endpoint/functions/pci-epf-ntb.c line 959
Quoted 10 lines
drivers/pci/endpoint/functions/pci-epf-ntb.c new file +10
-0+ *+-----------------+ +-----------------+ + *| BAR4 | | BAR4 | + *+-----------------+ +-----------------+ + *| BAR5 | | BAR5 | + *+-----------------+ +-----------------+ + * EP CONTROLLER 1 EP CONTROLLER 2 + * + * This function allocates the Local Memory mentioned in the above diagram. + * The size of CONFIG REGION is sizeof(struct epf_ntb_ctrl) and size of + * SCRATCHPAD REGION is obtained from "spad-count" device tree property.
s/This function allocates/Allocate/
Quoted 124 lines
drivers/pci/endpoint/functions/pci-epf-ntb.c new file +124
-0+* +* The size of both config region and scratchpad region has to be aligned, +* since the scratchpad region will also be mapped as PEER SCRATCHPAD of +* other host using a separate BAR. +*/ +static int +epf_ntb_config_spad_bar_alloc (struct epf_ntb *ntb, +enum pci_epc_interface_type type) +{ +const struct pci_epc_features *peer_epc_features, *epc_features; +struct epf_ntb_epc *peer_ntb_epc, *ntb_epc; +size_t msix_table_size, pba_size, align; +enum pci_barno peer_barno, barno; +struct epf_ntb_ctrl *ctrl; +u32 spad_size, ctrl_size; +u64 size, peer_size; +struct pci_epc *epc; +struct pci_epf *epf; +struct device *dev; +bool msix_capable; +u32 spad_count; +void *base; + + epf = ntb->epf; + dev = &epf->dev; + ntb_epc = ntb->epc[type]; + epc = ntb_epc->epc; + + epc_features = ntb_epc->epc_features; + barno = ntb_epc->epf_ntb_bar[BAR_CONFIG ]; + size = epc_features->bar_fixed_size[barno]; + align = epc_features->align; + + peer_ntb_epc = ntb->epc[!type]; + peer_epc_features = peer_ntb_epc->epc_features; + peer_barno = ntb_epc->epf_ntb_bar[BAR_PEER_SPAD ]; + peer_size = peer_epc_features->bar_fixed_size[barno]; + +/* Check if epc_features is populated incorrectly */ +if ((!IS_ALIGNED (size, align))) +return -EINVAL ; + + spad_count = ntb->spad_count; + + ctrl_size =sizeof (struct epf_ntb_ctrl ); + spad_size = spad_count *4 ; + + msix_capable = epc_features->msix_capable; +if (msix_capable) { + msix_table_size =PCI_MSIX_ENTRY_SIZE * ntb->db_count; + ctrl_size =ALIGN (ctrl_size,8 ); + ntb_epc->msix_table_offset = ctrl_size; + ntb_epc->msix_bar = barno; +/* Align to QWORD or 8 Bytes */ + pba_size =ALIGN (DIV_ROUND_UP (ntb->db_count,8 ),8 ); + ctrl_size = ctrl_size + msix_table_size + pba_size; + } + +if (!align) { + ctrl_size =roundup_pow_of_two (ctrl_size); + spad_size =roundup_pow_of_two (spad_size); + }else { + ctrl_size =ALIGN (ctrl_size, align); + spad_size =ALIGN (spad_size, align); + } + +if (peer_size) { +if (peer_size < spad_size) + spad_count = peer_size /4 ; + spad_size = peer_size; + } + +/* +* In order to make sure SPAD offset is aligned to its size, +* expand control region size to the size of SPAD if SPAD size +* is greater than control region size. +*/ +if (spad_size > ctrl_size) + ctrl_size = spad_size; + +if (!size) + size = ctrl_size + spad_size; +else if (size < ctrl_size + spad_size) +return -EINVAL ; + + base =pci_epf_alloc_space (epf, size, barno, align, type); +if (!base) { +dev_err (dev,"%s intf: Config/Status/SPAD alloc region fail\n" , +pci_epc_interface_string (type)); +return -ENOMEM ; + } + + ntb_epc->reg = base; + + ctrl = ntb_epc->reg; + ctrl->spad_offset = ctrl_size; + ctrl->spad_count = spad_count; + ctrl->num_mws = ntb->num_mws; + ctrl->db_entry_size = align ? align :4 ; + ntb_epc->spad_size = spad_size; + +return 0 ; +} + +/** +* epf_ntb_config_spad_bar_alloc_interface() - Allocate memory for config + +* scratchpad region for each of PRIMARY and SECONDARY interface +* @ntb: NTB device that facilitates communication between HOST1 and HOST2 +* +* Wrapper for epf_ntb_config_spad_bar_alloc() which allocates memory for +* config + scratchpad region for a specific interface +*/ +static int epf_ntb_config_spad_bar_alloc_interface (struct epf_ntb *ntb) +{ +enum pci_epc_interface_type type; +struct device *dev; +int ret; + + dev = &ntb->epf->dev; + +for (type =PRIMARY_INTERFACE ; type <=SECONDARY_INTERFACE ; type++) { + ret =epf_ntb_config_spad_bar_alloc (ntb, type); +if (ret) { + dev_err(dev, "%s intf: Config/SPAD BAR alloc failed\n",
drivers/pci/endpoint/functions/pci-epf-ntb.c line 1093
Quoted 10 lines
drivers/pci/endpoint/functions/pci-epf-ntb.c new file +10
-0+ pci_epc_interface_string(type)); +return ret; + } + } + +return 0 ; +} + +/** +* epf_ntb_free_peer_mem() - Free's memory allocated in peers outbound address
s/Free's/Free/
Quoted 26 lines
drivers/pci/endpoint/functions/pci-epf-ntb.c new file +26
-0+* space +* @ntb_epc: EPC associated with one of the HOST which holds peers outbound +* address regions +* +*+-----------------+ +----->+----------------+-----------+-----------------+ +*| BAR0 | | | Doorbell 1 +-----------> MSI|X ADDRESS 1 | +*+-----------------+ | +----------------+ +-----------------+ +*| BAR1 | | | Doorbell 2 +---------+ | | +*+-----------------+----+ +----------------+ | | | +*| BAR2 | | Doorbell 3 +-------+ | +-----------------+ +*+-----------------+----+ +----------------+ | +-> MSI|X ADDRESS 2 | +*| BAR3 | | | Doorbell 4 +-----+ | +-----------------+ +*+-----------------+ | |----------------+ | | | | +*| BAR4 | | | | | | +-----------------+ +*+-----------------+ | | MW1 +---+ | +-->+ MSI|X ADDRESS 3|| +*| BAR5 | | | | | | +-----------------+ +*+-----------------+ +----->-----------------+ | | | | +* EP CONTROLLER 1 | | | | +-----------------+ +* | | | +---->+ MSI|X ADDRESS 4 | +* +----------------+ | +-----------------+ +* (A) EP CONTROLLER 2 | | | +* (OB SPACE) | | | +* +-------> MW1 | +* | | +* | | +* (B) +-----------------+
drivers/pci/endpoint/functions/pci-epf-ntb.c line 1129
Quoted 10 lines
drivers/pci/endpoint/functions/pci-epf-ntb.c new file +10
-0+* | | +* | | +* | | +* | | +* | | +* +-----------------+ +* PCI Address Space +* (Managed by HOST2) +* +* This function frees memory allocated in EP CONTROLLER 2 (OB SPACE) in the
s/This function frees/Free/
Quoted 20 lines
drivers/pci/endpoint/functions/pci-epf-ntb.c new file +20
-0+* above diagram. It'll free Doorbell 1, Doorbell 2, Doorbell 3, Doorbell 4, +* MW1 (and MW2, MW3, MW4). +*/ +static void epf_ntb_free_peer_mem (struct epf_ntb_epc *ntb_epc) +{ +struct pci_epf_bar *epf_bar; +void __iomem *mw_addr; +phys_addr_t phys_addr; +enum epf_ntb_bar bar; +enum pci_barno barno; +struct pci_epc *epc; +size_t size; + + epc = ntb_epc->epc; + +for (bar =BAR_DB_MW1 ; bar <BAR_MW4 ; bar++) { + barno = ntb_epc->epf_ntb_bar[bar]; + mw_addr = ntb_epc->mw_addr[barno]; + epf_bar = &ntb_epc->epf_bar[barno]; + phys_addr = epf_bar->phys_addr;
drivers/pci/endpoint/functions/pci-epf-ntb.c line 1159
Quoted 10 lines
drivers/pci/endpoint/functions/pci-epf-ntb.c new file +10
-0+ size = epf_bar->size; +if (mw_addr) { +pci_epc_mem_free_addr (epc, phys_addr, mw_addr, size); + ntb_epc->mw_addr[barno] =NULL ; + } + } +} + +/** +* epf_ntb_db_mw_bar_clear() - Clears doorbell and memory BAR
s/Clears/Clear/
drivers/pci/endpoint/functions/pci-epf-ntb.c line 1159
Quoted 1 line
drivers/pci/endpoint/functions/pci-epf-ntb.c new file +1
-0+* @ntb_epc: EPC associated with one of the HOST which holds peers outbound
s/peers/peer's/
Quoted 26 lines
drivers/pci/endpoint/functions/pci-epf-ntb.c new file +26
-0+* address +* +*+-----------------+ +----->+----------------+-----------+-----------------+ +*| BAR0 | | | Doorbell 1 +-----------> MSI|X ADDRESS 1 | +*+-----------------+ | +----------------+ +-----------------+ +*| BAR1 | | | Doorbell 2 +---------+ | | +*+-----------------+----+ +----------------+ | | | +*| BAR2 | | Doorbell 3 +-------+ | +-----------------+ +*+-----------------+----+ +----------------+ | +-> MSI|X ADDRESS 2 | +*| BAR3 | | | Doorbell 4 +-----+ | +-----------------+ +*+-----------------+ | |----------------+ | | | | +*| BAR4 | | | | | | +-----------------+ +*+-----------------+ | | MW1 +---+ | +-->+ MSI|X ADDRESS 3|| +*| BAR5 | | | | | | +-----------------+ +*+-----------------+ +----->-----------------+ | | | | +* EP CONTROLLER 1 | | | | +-----------------+ +* | | | +---->+ MSI|X ADDRESS 4 | +* +----------------+ | +-----------------+ +* (A) EP CONTROLLER 2 | | | +* (OB SPACE) | | | +* +-------> MW1 | +* | | +* | | +* (B) +-----------------+ +* | | +* | |
drivers/pci/endpoint/functions/pci-epf-ntb.c line 1196
Quoted 10 lines
drivers/pci/endpoint/functions/pci-epf-ntb.c new file +10
-0+* | | +* | | +* | | +* +-----------------+ +* PCI Address Space +* (Managed by HOST2) +* +* This function clears doorbell and memory BARs (remove inbound ATU +* configuration). In the above diagram it clears BAR2 TO BAR5 of EP +* CONTROLLER 1 (Doorbell BAR, MW1 BAR, MW2 BAR, MW3 BAR and MW4 BAR).
s/This function clears/Clear/
Quoted 19 lines
drivers/pci/endpoint/functions/pci-epf-ntb.c new file +19
-0+*/ +static void epf_ntb_db_mw_bar_clear (struct epf_ntb_epc *ntb_epc) +{ +struct pci_epf_bar *epf_bar; +enum epf_ntb_bar bar; +enum pci_barno barno; +struct pci_epc *epc; +u8 func_no; + + epc = ntb_epc->epc; + + func_no = ntb_epc->func_no; + +for (bar =BAR_DB_MW1 ; bar <BAR_MW4 ; bar++) { + barno = ntb_epc->epf_ntb_bar[bar]; + epf_bar = &ntb_epc->epf_bar[barno]; +pci_epc_clear_bar (epc, func_no, epf_bar); + } +}
drivers/pci/endpoint/functions/pci-epf-ntb.c line 1225
Quoted 10 lines
drivers/pci/endpoint/functions/pci-epf-ntb.c new file +10
-0+ +/** +* epf_ntb_db_mw_bar_cleanup() - Clears doorbell/memory BAR and free memory +* allocated in peers outbound address space +* @ntb: NTB device that facilitates communication between HOST1 and HOST2 +* @type: PRIMARY interface or SECONDARY interface +* +* This function is a wrapper for epf_ntb_db_mw_bar_clear() which clears +* HOST1's BAR and epf_ntb_free_peer_mem() which frees up HOST2 outbound +* memory.
Ditto.
Quoted 10 lines
drivers/pci/endpoint/functions/pci-epf-ntb.c new file +10
-0+*/ +static void epf_ntb_db_mw_bar_cleanup (struct epf_ntb *ntb, +enum pci_epc_interface_type type) +{ +struct epf_ntb_epc *peer_ntb_epc, *ntb_epc; + + ntb_epc = ntb->epc[type]; + peer_ntb_epc = ntb->epc[!type]; + +epf_ntb_db_mw_bar_clear (ntb_epc);
drivers/pci/endpoint/functions/pci-epf-ntb.c line 1245
Quoted 10 lines
drivers/pci/endpoint/functions/pci-epf-ntb.c new file +10
-0+epf_ntb_free_peer_mem (peer_ntb_epc); +} + +/** +* epf_ntb_configure_interrupt() - Configure MSI/MSI-X capaiblity +* @ntb: NTB device that facilitates communication between HOST1 and HOST2 +* @type: PRIMARY interface or SECONDARY interface +* +* Configures MSI/MSI-X capability for each interface with number of +* interrupts equal to "db-count" device tree parameter.
Ditto.
Quoted 50 lines
drivers/pci/endpoint/functions/pci-epf-ntb.c new file +50
-0+*/ +static int epf_ntb_configure_interrupt (struct epf_ntb *ntb, +enum pci_epc_interface_type type) +{ +const struct pci_epc_features *epc_features; +bool msix_capable, msi_capable; +struct epf_ntb_epc *ntb_epc; +struct pci_epc *epc; +struct device *dev; +u32 db_count; +u8 func_no; +int ret; + + ntb_epc = ntb->epc[type]; + dev = &ntb->epf->dev; + + epc_features = ntb_epc->epc_features; + msix_capable = epc_features->msix_capable; + msi_capable = epc_features->msi_capable; + +if (!(msix_capable || msi_capable)) { +dev_err (dev,"MSI or MSI-X is required for doorbell\n" ); +return -EINVAL ; + } + + func_no = ntb_epc->func_no; + + db_count = ntb->db_count; +if (db_count >MAX_DB_COUNT ) { +dev_err (dev,"DB count cannot be more than %d\n" ,MAX_DB_COUNT ); +return -EINVAL ; + } + + ntb->db_count = db_count; + epc = ntb_epc->epc; + +if (msi_capable) { + ret =pci_epc_set_msi (epc, func_no, db_count); +if (ret) { +dev_err (dev,"%s intf: MSI configuration failed\n" , +pci_epc_interface_string (type)); +return ret; + } + } + +if (msix_capable) { + ret =pci_epc_set_msix (epc, func_no, db_count, + ntb_epc->msix_bar, + ntb_epc->msix_table_offset); +if (ret) {
drivers/pci/endpoint/functions/pci-epf-ntb.c line 1305
Quoted 10 lines
drivers/pci/endpoint/functions/pci-epf-ntb.c new file +10
-0+dev_err (dev,"MSI configuration failed\n" ); +return ret; + } + } + +return 0 ; +} + +/** +* epf_ntb_alloc_peer_mem() - Allocate memory in peers outbound address space
s/peers/peer's/
drivers/pci/endpoint/functions/pci-epf-ntb.c line 1306
Quoted 1 line
drivers/pci/endpoint/functions/pci-epf-ntb.c new file +1
-0+* @ntb_epc: EPC associated with one of the HOST whose BAR holds peers outbound
Ditto.
Quoted 32 lines
drivers/pci/endpoint/functions/pci-epf-ntb.c new file +32
-0+* address +* @bar: BAR of @ntb_epc in for which memory has to be allocated (could be +* BAR_DB_MW1, BAR_MW2, BAR_MW3, BAR_MW4) +* @peer_ntb_epc: EPC associated with HOST whose outbound address space is +* used by @ntb_epc +* @size: Size of the address region that has to be allocated in peers OB SPACE +* +* +*+-----------------+ +----->+----------------+-----------+-----------------+ +*| BAR0 | | | Doorbell 1 +-----------> MSI|X ADDRESS 1 | +*+-----------------+ | +----------------+ +-----------------+ +*| BAR1 | | | Doorbell 2 +---------+ | | +*+-----------------+----+ +----------------+ | | | +*| BAR2 | | Doorbell 3 +-------+ | +-----------------+ +*+-----------------+----+ +----------------+ | +-> MSI|X ADDRESS 2 | +*| BAR3 | | | Doorbell 4 +-----+ | +-----------------+ +*+-----------------+ | |----------------+ | | | | +*| BAR4 | | | | | | +-----------------+ +*+-----------------+ | | MW1 +---+ | +-->+ MSI|X ADDRESS 3|| +*| BAR5 | | | | | | +-----------------+ +*+-----------------+ +----->-----------------+ | | | | +* EP CONTROLLER 1 | | | | +-----------------+ +* | | | +---->+ MSI|X ADDRESS 4 | +* +----------------+ | +-----------------+ +* (A) EP CONTROLLER 2 | | | +* (OB SPACE) | | | +* +-------> MW1 | +* | | +* | | +* (B) +-----------------+ +* | | +* | |
drivers/pci/endpoint/functions/pci-epf-ntb.c line 1348
Quoted 10 lines
drivers/pci/endpoint/functions/pci-epf-ntb.c new file +10
-0+* | | +* | | +* | | +* +-----------------+ +* PCI Address Space +* (Managed by HOST2) +* +* This function allocates memory in OB space of EP CONTROLLER 2 in the +* above diagram. It'll allocate for Doorbell 1, Doorbell 2, Doorbell 3, +* Doorbell 4, MW1 (and MW2, MW3, MW4).
Ditto.
Quoted 114 lines
drivers/pci/endpoint/functions/pci-epf-ntb.c new file +114
-0+*/ +static int +epf_ntb_alloc_peer_mem (struct device *dev,struct epf_ntb_epc *ntb_epc, +enum epf_ntb_bar bar,struct epf_ntb_epc *peer_ntb_epc, +size_t size) +{ +const struct pci_epc_features *epc_features; +struct pci_epf_bar *epf_bar; +struct pci_epc *peer_epc; +phys_addr_t phys_addr; +void __iomem *mw_addr; +enum pci_barno barno; +size_t align; + + epc_features = ntb_epc->epc_features; + align = epc_features->align; + +if (size <128 ) + size =128 ; + +if (align) + size =ALIGN (size, align); +else + size =roundup_pow_of_two (size); + + peer_epc = peer_ntb_epc->epc; + mw_addr =pci_epc_mem_alloc_addr (peer_epc, &phys_addr, size); +if (!mw_addr) { +dev_err (dev,"%s intf: Failed to allocate OB address\n" , +pci_epc_interface_string (peer_ntb_epc->type)); +return -ENOMEM ; + } + + barno = ntb_epc->epf_ntb_bar[bar]; + epf_bar = &ntb_epc->epf_bar[barno]; + ntb_epc->mw_addr[barno] = mw_addr; + + epf_bar->phys_addr = phys_addr; + epf_bar->size = size; + epf_bar->barno = barno; + epf_bar->flags =PCI_BASE_ADDRESS_MEM_TYPE_32 ; + +return 0 ; +} + +/** +* epf_ntb_db_mw_bar_init() - Configure Doorbell and Memory window BARs +* @ntb: NTB device that facilitates communication between HOST1 and HOST2 +* @type: PRIMARY interface or SECONDARY interface +* +* Wrapper for epf_ntb_alloc_peer_mem() and pci_epc_set_bar() that allocates +* memory in OB address space of HOST2 and configures BAR of HOST1 +*/ +static int epf_ntb_db_mw_bar_init (struct epf_ntb *ntb, +enum pci_epc_interface_type type) +{ +const struct pci_epc_features *epc_features; +struct epf_ntb_epc *peer_ntb_epc, *ntb_epc; +struct pci_epf_bar *epf_bar; +struct epf_ntb_ctrl *ctrl; +u32 num_mws, db_count; +enum epf_ntb_bar bar; +enum pci_barno barno; +struct pci_epc *epc; +struct device *dev; +size_t align; +int ret, i; +u8 func_no; +u64 size; + + ntb_epc = ntb->epc[type]; + peer_ntb_epc = ntb->epc[!type]; + + dev = &ntb->epf->dev; + epc_features = ntb_epc->epc_features; + align = epc_features->align; + func_no = ntb_epc->func_no; + epc = ntb_epc->epc; + num_mws = ntb->num_mws; + db_count = ntb->db_count; + +for (bar =BAR_DB_MW1 , i =0 ; i < num_mws; bar++, i++) { +if (bar ==BAR_DB_MW1 ) { + align = align ? align :4 ; + size = db_count * align; + size =ALIGN (size, ntb->mws_size[i]); + ctrl = ntb_epc->reg; + ctrl->mw1_offset = size; + size += ntb->mws_size[i]; + }else { + size = ntb->mws_size[i]; + } + + ret =epf_ntb_alloc_peer_mem (dev, ntb_epc, bar, + peer_ntb_epc, size); +if (ret) + goto err_alloc_peer_mem; + + barno = ntb_epc->epf_ntb_bar[bar]; + epf_bar = &ntb_epc->epf_bar[barno]; + + ret =pci_epc_set_bar (epc, func_no, epf_bar); +if (ret) { +dev_err (dev,"%s intf: DoorBell BAR set failed\n" , +pci_epc_interface_string (type)); + goto err_alloc_peer_mem; + } + } + +return 0 ; + +err_alloc_peer_mem: +epf_ntb_db_mw_bar_cleanup (ntb, type); +
drivers/pci/endpoint/functions/pci-epf-ntb.c line 1472
Quoted 10 lines
drivers/pci/endpoint/functions/pci-epf-ntb.c new file +10
-0+return ret; +} + +/** +* epf_ntb_epc_destroy_interface() - Cleanup NTB EPC interface +* @ntb: NTB device that facilitates communication between HOST1 and HOST2 +* @type: PRIMARY interface or SECONDARY interface +* +* Unbind NTB function device from EPC and Relinquish reference to pci_epc +* for each of the interface.
s/Relinquish/relinquish/
Quoted 122 lines
drivers/pci/endpoint/functions/pci-epf-ntb.c new file +122
-0+*/ +static void epf_ntb_epc_destroy_interface (struct epf_ntb *ntb, +enum pci_epc_interface_type type) +{ +struct epf_ntb_epc *ntb_epc; +struct pci_epc *epc; +struct pci_epf *epf; + +if (type <0 ) +return ; + + epf = ntb->epf; + ntb_epc = ntb->epc[type]; +if (!ntb_epc) +return ; + epc = ntb_epc->epc; +pci_epc_remove_epf (epc, epf, type); +pci_epc_put (epc); +} + +/** +* epf_ntb_epc_destroy() - Cleanup NTB EPC interface +* @ntb: NTB device that facilitates communication between HOST1 and HOST2 +* +* Wrapper for epf_ntb_epc_destroy_interface() to cleanup all the NTB interfaces +*/ +static void epf_ntb_epc_destroy (struct epf_ntb *ntb) +{ +enum pci_epc_interface_type type; + +for (type =PRIMARY_INTERFACE ; type <=SECONDARY_INTERFACE ; type++) +epf_ntb_epc_destroy_interface (ntb, type); +} + +/** +* epf_ntb_epc_create_interface() - Create and initialize NTB EPC interface +* @ntb: NTB device that facilitates communication between HOST1 and HOST2 +* @epc: struct pci_epc to which a particular NTB interface should be associated +* @type: PRIMARY interface or SECONDARY interface +* +* Allocate memory for NTB EPC interface and initialize it. +*/ +static int +epf_ntb_epc_create_interface (struct epf_ntb *ntb,struct pci_epc *epc, +enum pci_epc_interface_type type) +{ +const struct pci_epc_features *epc_features; +struct pci_epf_bar *epf_bar; +struct epf_ntb_epc *ntb_epc; +struct pci_epf *epf; +struct device *dev; +u8 func_no; + + dev = &ntb->epf->dev; + + ntb_epc =devm_kzalloc (dev,sizeof (*ntb_epc),GFP_KERNEL ); +if (!ntb_epc) +return -ENOMEM ; + + epf = ntb->epf; +if (type ==PRIMARY_INTERFACE ) { + func_no = epf->func_no; + epf_bar = epf->bar; + }else { + func_no = epf->sec_epc_func_no; + epf_bar = epf->sec_epc_bar; + } + + ntb_epc->linkup = false; + ntb_epc->epc = epc; + ntb_epc->func_no = func_no; + ntb_epc->type = type; + ntb_epc->epf_bar = epf_bar; + ntb_epc->epf_ntb = ntb; + + epc_features =pci_epc_get_features (epc, func_no); +if (!epc_features) +return -EINVAL ; + ntb_epc->epc_features = epc_features; + + ntb->epc[type] = ntb_epc; + +return 0 ; +} + +/** +* epf_ntb_epc_create() - Create and initialize NTB EPC interface +* @ntb: NTB device that facilitates communication between HOST1 and HOST2 +* +* Get a reference to EPC device and bind NTB function device to that EPC +* for each of the interface. It is also a wrapper to +* epf_ntb_epc_create_interface() to allocate memory for NTB EPC interface +* and initialize it +*/ +static int epf_ntb_epc_create (struct epf_ntb *ntb) +{ +struct pci_epf *epf; +struct device *dev; +int ret; + + epf = ntb->epf; + dev = &epf->dev; + + ret =epf_ntb_epc_create_interface (ntb, epf->epc,PRIMARY_INTERFACE ); +if (ret) { +dev_err (dev,"PRIMARY intf: Fail to create NTB EPC\n" ); +return ret; + } + + ret =epf_ntb_epc_create_interface (ntb, epf->sec_epc, +SECONDARY_INTERFACE ); +if (ret) { +dev_err (dev,"SECONDARY intf: Fail to create NTB EPC\n" ); + goto err_epc_create; + } + +return 0 ; + +err_epc_create: +epf_ntb_epc_destroy_interface (ntb,PRIMARY_INTERFACE ); + +return ret;
drivers/pci/endpoint/functions/pci-epf-ntb.c line 1604
Quoted 10 lines
drivers/pci/endpoint/functions/pci-epf-ntb.c new file +10
-0+} + +/** +* epf_ntb_init_epc_bar_interface() - Identify BARs to be used for each of +* the NTB constructs (scratchpad region, doorbell, memorywindow) +* @ntb: NTB device that facilitates communication between HOST1 and HOST2 +* @type: PRIMARY interface or SECONDARY interface +* +* Identify the free BAR's to be used for each of BAR_CONFIG, BAR_PEER_SPAD, +* BAR_DB_MW1, BAR_MW2, BAR_MW3 and BAR_MW4.
s/BAR's/BARs/
Quoted 20 lines
drivers/pci/endpoint/functions/pci-epf-ntb.c new file +20
-0+*/ +static int epf_ntb_init_epc_bar_interface (struct epf_ntb *ntb, +enum pci_epc_interface_type type) +{ +const struct pci_epc_features *epc_features; +struct epf_ntb_epc *ntb_epc; +enum pci_barno barno; +enum epf_ntb_bar bar; +struct device *dev; +u32 num_mws; +int i; + + barno =BAR_0 ; + ntb_epc = ntb->epc[type]; + num_mws = ntb->num_mws; + dev = &ntb->epf->dev; + epc_features = ntb_epc->epc_features; + +/* These are required BARs which are mandatory for NTB functionality */ +for (bar =BAR_CONFIG ; bar <=BAR_DB_MW1 ; bar++, barno++) {
drivers/pci/endpoint/functions/pci-epf-ntb.c line 1634
Quoted 10 lines
drivers/pci/endpoint/functions/pci-epf-ntb.c new file +10
-0+ barno =pci_epc_get_next_free_bar (epc_features, barno); +if (barno <0 ) { +dev_err (dev,"%s intf: Fail to get NTB function BAR\n" , +pci_epc_interface_string (type)); +return barno; + } + ntb_epc->epf_ntb_bar[bar] = barno; + } + +/* These are optional BARs which doesn't impact NTB functionality */
s/doesn't/don't/
Quoted 11 lines
drivers/pci/endpoint/functions/pci-epf-ntb.c new file +11
-0+for (bar =BAR_MW2 , i =1 ; i < num_mws; bar++, barno++, i++) { + barno =pci_epc_get_next_free_bar (epc_features, barno); +if (barno <0 ) { + ntb->num_mws = i; +dev_dbg (dev,"BAR not available for > MW%d\n" , i +1 ); + } + ntb_epc->epf_ntb_bar[bar] = barno; + } + +return 0 ; +}
drivers/pci/endpoint/functions/pci-epf-ntb.c line 1655
Quoted 10 lines
drivers/pci/endpoint/functions/pci-epf-ntb.c new file +10
-0+ +/** +* epf_ntb_init_epc_bar() - Identify BARs to be used for each of the NTB +* constructs (scratchpad region, doorbell, memorywindow) +* @ntb: NTB device that facilitates communication between HOST1 and HOST2 +* @type: PRIMARY interface or SECONDARY interface +* +* Wrapper to epf_ntb_init_epc_bar_interface() to identify the free BAR's +* to be used for each of BAR_CONFIG, BAR_PEER_SPAD, BAR_DB_MW1, BAR_MW2, +* BAR_MW3 and BAR_MW4 for all the interfaces.
s/BAR's/BARs/
Quoted 157 lines
drivers/pci/endpoint/functions/pci-epf-ntb.c new file +157
-0+*/ +static int epf_ntb_init_epc_bar (struct epf_ntb *ntb) +{ +enum pci_epc_interface_type type; +struct device *dev; +int ret; + + dev = &ntb->epf->dev; +for (type =PRIMARY_INTERFACE ; type <=SECONDARY_INTERFACE ; type++) { + ret =epf_ntb_init_epc_bar_interface (ntb, type); +if (ret) { +dev_err (dev,"Fail to init EPC bar for %s interface\n" , +pci_epc_interface_string (type)); +return ret; + } + } + +return 0 ; +} + +/** +* epf_ntb_epc_init_interface() - Initialize NTB interface +* @ntb: NTB device that facilitates communication between HOST1 and HOST2 +* @type: PRIMARY interface or SECONDARY interface +* +* Wrapper to initialize a particular EPC interface and start the workqueue +* to check for commands from host. This function will write to the +* EP controller HW for configuring it. +*/ +static int epf_ntb_epc_init_interface (struct epf_ntb *ntb, +enum pci_epc_interface_type type) +{ +struct epf_ntb_epc *ntb_epc; +struct pci_epc *epc; +struct pci_epf *epf; +struct device *dev; +u8 func_no; +int ret; + + ntb_epc = ntb->epc[type]; + epf = ntb->epf; + dev = &epf->dev; + epc = ntb_epc->epc; + func_no = ntb_epc->func_no; + + ret =epf_ntb_config_sspad_bar_set (ntb->epc[type]); +if (ret) { +dev_err (dev,"%s intf: Config/self SPAD BAR init failed\n" , +pci_epc_interface_string (type)); +return ret; + } + + ret =epf_ntb_peer_spad_bar_set (ntb, type); +if (ret) { +dev_err (dev,"%s intf: Peer SPAD BAR init failed\n" , +pci_epc_interface_string (type)); + goto err_peer_spad_bar_init; + } + + ret =epf_ntb_configure_interrupt (ntb, type); +if (ret) { +dev_err (dev,"%s intf: Interrupt configuration failed\n" , +pci_epc_interface_string (type)); + goto err_peer_spad_bar_init; + } + + ret =epf_ntb_db_mw_bar_init (ntb, type); +if (ret) { +dev_err (dev,"%s intf: DB/MW BAR init failed\n" , +pci_epc_interface_string (type)); + goto err_db_mw_bar_init; + } + + ret =pci_epc_write_header (epc, func_no, epf->header); +if (ret) { +dev_err (dev,"%s intf: Configuration header write failed\n" , +pci_epc_interface_string (type)); + goto err_write_header; + } + +INIT_DELAYED_WORK (&ntb->epc[type]->cmd_handler, epf_ntb_cmd_handler); +queue_work (kpcintb_workqueue, &ntb->epc[type]->cmd_handler.work); + +return 0 ; + +err_write_header: +epf_ntb_db_mw_bar_cleanup (ntb, type); + +err_db_mw_bar_init: +epf_ntb_peer_spad_bar_clear (ntb->epc[type]); + +err_peer_spad_bar_init: +epf_ntb_config_sspad_bar_clear (ntb->epc[type]); + +return ret; +} + +/** +* epf_ntb_epc_cleanup_interface() - Cleanup NTB interface +* @ntb: NTB device that facilitates communication between HOST1 and HOST2 +* @type: PRIMARY interface or SECONDARY interface +* +* Wrapper to cleanup a particular NTB interface. +*/ +static void epf_ntb_epc_cleanup_interface (struct epf_ntb *ntb, +enum pci_epc_interface_type type) +{ +struct epf_ntb_epc *ntb_epc; + +if (type <0 ) +return ; + + ntb_epc = ntb->epc[type]; +cancel_delayed_work (&ntb_epc->cmd_handler); +epf_ntb_db_mw_bar_cleanup (ntb, type); +epf_ntb_peer_spad_bar_clear (ntb_epc); +epf_ntb_config_sspad_bar_clear (ntb_epc); +} + +/** +* epf_ntb_epc_cleanup() - Cleanup all NTB interfaces +* @ntb: NTB device that facilitates communication between HOST1 and HOST2 +* +* Wrapper to cleanup all NTB interfaces. +*/ +static void epf_ntb_epc_cleanup (struct epf_ntb *ntb) +{ +enum pci_epc_interface_type type; + +for (type =PRIMARY_INTERFACE ; type <=SECONDARY_INTERFACE ; type++) +epf_ntb_epc_cleanup_interface (ntb, type); +} + +/** +* epf_ntb_epc_init() - Initialize all NTB interfaces +* @ntb: NTB device that facilitates communication between HOST1 and HOST2 +* +* Wrapper to initialize all NTB interface and start the workqueue +* to check for commands from host. +*/ +static int epf_ntb_epc_init (struct epf_ntb *ntb) +{ +enum pci_epc_interface_type type; +struct device *dev; +int ret; + + dev = &ntb->epf->dev; + +for (type =PRIMARY_INTERFACE ; type <=SECONDARY_INTERFACE ; type++) { + ret =epf_ntb_epc_init_interface (ntb, type); +if (ret) { +dev_err (dev,"%s intf: Failed to initialize\n" , +pci_epc_interface_string (type)); + goto err_init_type; + } + } +
drivers/pci/endpoint/functions/pci-epf-ntb.c line 1822
Quoted 10 lines
drivers/pci/endpoint/functions/pci-epf-ntb.c new file +10
-0+return 0 ; + +err_init_type: +epf_ntb_epc_cleanup_interface (ntb, type -1 ); + +return ret; +} + +/** +* epf_ntb_bind() - Invoked when a EPC is bound to NTB EPF device
Should say what this function does, not when it is invoked.
Quoted 295 lines
drivers/pci/endpoint/functions/pci-epf-ntb.c new file +292
-0+* @epf: NTB endpoint function device +* +* This is invoked when a primary interface or secondary interface is +* bound to EPC device. This function will complete only when EPC is bound +* to both the interfaces. This initializes both the endpoint controllers +* associated with NTB function device. +*/ +static int epf_ntb_bind (struct pci_epf *epf) +{ +struct epf_ntb *ntb =epf_get_drvdata (epf); +struct device *dev = &epf->dev; +int ret; + +if (!epf->epc) { +dev_dbg (dev,"PRIMARY EPC interface not yet bound\n" ); +return 0 ; + } + +if (!epf->sec_epc) { +dev_dbg (dev,"SECONDARY EPC interface not yet bound\n" ); +return 0 ; + } + + ret =epf_ntb_epc_create (ntb); +if (ret) { +dev_err (dev,"Failed to create NTB EPC\n" ); +return ret; + } + + ret =epf_ntb_init_epc_bar (ntb); +if (ret) { +dev_err (dev,"Failed to create NTB EPC\n" ); + goto err_bar_init; + } + + ret =epf_ntb_config_spad_bar_alloc_interface (ntb); +if (ret) { +dev_err (dev,"Failed to allocate BAR memory\n" ); + goto err_bar_alloc; + } + + ret =epf_ntb_epc_init (ntb); +if (ret) { +dev_err (dev,"Failed to initialize EPC\n" ); + goto err_bar_alloc; + } + +epf_set_drvdata (epf, ntb); + +return 0 ; + +err_bar_alloc: +epf_ntb_config_spad_bar_free (ntb); + +err_bar_init: +epf_ntb_epc_destroy (ntb); + +return ret; +} + +/** +* epf_ntb_unbind() - Cleanup the initialization from epf_ntb_bind() +* @epf: NTB endpoint function device +* +* Cleanup the initialization from epf_ntb_bind() +*/ +static void epf_ntb_unbind (struct pci_epf *epf) +{ +struct epf_ntb *ntb =epf_get_drvdata (epf); + +epf_ntb_epc_cleanup (ntb); +epf_ntb_config_spad_bar_free (ntb); +epf_ntb_epc_destroy (ntb); +} + +#define EPF_NTB_R (_name) \ +static ssize_t epf_ntb_##_name##_show(struct config_item *item, \ + char *page) \ +{ \ + struct config_group *group = to_config_group(item); \ + struct epf_ntb *ntb = to_epf_ntb(group); \ + \ + return sprintf(page, "%d\n", ntb->_name); \ +} + +#define EPF_NTB_W (_name) \ +static ssize_t epf_ntb_##_name##_store(struct config_item *item, \ + const char *page, size_t len) \ +{ \ + struct config_group *group = to_config_group(item); \ + struct epf_ntb *ntb = to_epf_ntb(group); \ + u32 val; \ + int ret; \ + \ + ret = kstrtou32(page, 0, &val); \ + if (ret) \ + return ret; \ + \ + ntb->_name = val; \ + \ + return len; \ +} + +#define EPF_NTB_MW_R (_name) \ +static ssize_t epf_ntb_##_name##_show(struct config_item *item, \ + char *page) \ +{ \ + struct config_group *group = to_config_group(item); \ + struct epf_ntb *ntb = to_epf_ntb(group); \ + int win_no; \ + \ + sscanf(#_name, "mw%d", &win_no); \ + \ + return sprintf(page, "%lld\n", ntb->mws_size[win_no - 1]); \ +} + +#define EPF_NTB_MW_W (_name) \ +static ssize_t epf_ntb_##_name##_store(struct config_item *item, \ + const char *page, size_t len) \ +{ \ + struct config_group *group = to_config_group(item); \ + struct epf_ntb *ntb = to_epf_ntb(group); \ + struct device *dev = &ntb->epf->dev; \ + int win_no; \ + u64 val; \ + int ret; \ + \ + ret = kstrtou64(page, 0, &val); \ + if (ret) \ + return ret; \ + \ + if (sscanf(#_name, "mw%d", &win_no) != 1) \ + return -EINVAL; \ + \ + if (ntb->num_mws < win_no) { \ + dev_err(dev, "Invalid num_nws: %d value\n", ntb->num_mws); \ + return -EINVAL; \ + } \ + \ + ntb->mws_size[win_no - 1] = val; \ + \ + return len; \ +} + +static ssize_t epf_ntb_num_mws_store (struct config_item *item, +const char *page,size_t len) +{ +struct config_group *group =to_config_group (item); +struct epf_ntb *ntb =to_epf_ntb (group); +u32 val; +int ret; + + ret =kstrtou32 (page,0 , &val); +if (ret) +return ret; + +if (val >MAX_MW ) +return -EINVAL ; + + ntb->num_mws = val; + +return len; +} + +EPF_NTB_R (spad_count) +EPF_NTB_W(spad_count) +EPF_NTB_R(db_count) +EPF_NTB_W(db_count) +EPF_NTB_R(num_mws) +EPF_NTB_MW_R(mw1) +EPF_NTB_MW_W(mw1) +EPF_NTB_MW_R(mw2) +EPF_NTB_MW_W(mw2) +EPF_NTB_MW_R(mw3) +EPF_NTB_MW_W(mw3) +EPF_NTB_MW_R(mw4) +EPF_NTB_MW_W(mw4) + +CONFIGFS_ATTR(epf_ntb_, spad_count); +CONFIGFS_ATTR (epf_ntb_, db_count); +CONFIGFS_ATTR (epf_ntb_, num_mws); +CONFIGFS_ATTR (epf_ntb_, mw1); +CONFIGFS_ATTR (epf_ntb_, mw2); +CONFIGFS_ATTR (epf_ntb_, mw3); +CONFIGFS_ATTR (epf_ntb_, mw4); + +static struct configfs_attribute *epf_ntb_attrs[] = { + &epf_ntb_attr_spad_count, + &epf_ntb_attr_db_count, + &epf_ntb_attr_num_mws, + &epf_ntb_attr_mw1, + &epf_ntb_attr_mw2, + &epf_ntb_attr_mw3, + &epf_ntb_attr_mw4, +NULL , +}; + +static const struct config_item_type ntb_group_type = { + .ct_attrs = epf_ntb_attrs, + .ct_owner =THIS_MODULE , +}; + +/** +* epf_ntb_add_cfs() - Add configfs directory specific to NTB +* @epf: NTB endpoint function device +* +* Add configfs directory specific to NTB. This directory will hold +* NTB specific properties like db_count, spad_count, num_mws etc., +*/ +static struct config_group *epf_ntb_add_cfs (struct pci_epf *epf, +struct config_group *group) +{ +struct epf_ntb *ntb =epf_get_drvdata (epf); +struct config_group *ntb_group = &ntb->group; +struct device *dev = &epf->dev; + +config_group_init_type_name (ntb_group,dev_name (dev), &ntb_group_type); + +return ntb_group; +} + +/** +* epf_ntb_probe() - Probe NTB function driver +* @epf: NTB endpoint function device +* +* Probe NTB function driver when endpoint function bus detects a NTB +* endpoint function. +*/ +static int epf_ntb_probe (struct pci_epf *epf) +{ +struct epf_ntb *ntb; +struct device *dev; + + dev = &epf->dev; + + ntb =devm_kzalloc (dev,sizeof (*ntb),GFP_KERNEL ); +if (!ntb) +return -ENOMEM ; + + epf->header = &epf_ntb_header; + ntb->epf = epf; +epf_set_drvdata (epf, ntb); + +return 0 ; +} + +static struct pci_epf_ops epf_ntb_ops = { + .bind = epf_ntb_bind, + .unbind = epf_ntb_unbind, + .add_cfs = epf_ntb_add_cfs, +}; + +static const struct pci_epf_device_id epf_ntb_ids[] = { + { + .name ="pci_epf_ntb" , + }, + {}, +}; + +static struct pci_epf_driver epf_ntb_driver = { + .driver.name ="pci_epf_ntb" , + .probe = epf_ntb_probe, + .id_table = epf_ntb_ids, + .ops = &epf_ntb_ops, + .owner =THIS_MODULE , +}; + +static int __init epf_ntb_init (void ) +{ +int ret; + + kpcintb_workqueue =alloc_workqueue ("kpcintb" ,WQ_MEM_RECLAIM | +WQ_HIGHPRI ,0 ); + ret =pci_epf_register_driver (&epf_ntb_driver); +if (ret) { +pr_err ("Failed to register pci epf ntb driver --> %d\n" , ret); +return ret; + } + +return 0 ; +} +module_init (epf_ntb_init); + +static void __exit epf_ntb_exit(void) +{ +pci_epf_unregister_driver (&epf_ntb_driver); +} +module_exit (epf_ntb_exit); + +MODULE_DESCRIPTION ("PCI EPF NTB DRIVER" ); +MODULE_AUTHOR ("Kishon Vijay Abraham I <[email protected]>" ); +MODULE_LICENSE ("GPL v2" );Signature · 1 line
2.17.1
PATCH v9 14/17 PCI: Add TI J721E device to pci ids
In reply to Kishon Vijay Abraham IAdd TI J721E device to the pci id database. Since this device has a configurable PCIe endpoint, it could be used with different drivers.
--- drivers/misc/pci_endpoint_test.c | 1 - include/linux/pci_ids.h | 1 + 2 files changed, 1 insertion(+), 1 deletion(-)
drivers/misc/pci_endpoint_test.c +0 -1
@@ -68,7 +68,6 @@#define PCI_ENDPOINT_TEST_FLAGS 0x2c#define FLAG_USE_DMA BIT(0) -#define PCI_DEVICE_ID_TI_J721E 0xb00d#define PCI_DEVICE_ID_TI_AM654 0xb00c#define PCI_DEVICE_ID_LS1088A 0x80c0
include/linux/pci_ids.h +1 -0
@@ -881,6 +881,7 @@#define PCI_DEVICE_ID_TI_X620 0xac8d#define PCI_DEVICE_ID_TI_X420 0xac8e#define PCI_DEVICE_ID_TI_XX20_FM 0xac8f +#define PCI_DEVICE_ID_TI_J721E 0xb00d#define PCI_DEVICE_ID_TI_DRA74x 0xb500#define PCI_DEVICE_ID_TI_DRA72x 0xb501
Signature · 1 line
2.17.1
PATCH v9 15/17 NTB: Add support for EPF PCI-Express Non-Transparent Bridge
In reply to Kishon Vijay Abraham IAdd support for EPF PCI-Express Non-Transparent Bridge (NTB) device. This driver is platform independent and could be used by any platform which have multiple PCIe endpoint instances configured using the pci-epf-ntb driver. The driver connnects to the standard NTB sub-system interface. The EPF NTB device has configurable number of memory windows (Max 4), configurable number of doorbell (Max 32), and configurable number of scratch-pad registers.
--- drivers/ntb/hw/Kconfig | 1 + drivers/ntb/hw/Makefile | 1 + drivers/ntb/hw/epf/Kconfig | 6 + drivers/ntb/hw/epf/Makefile | 1 + drivers/ntb/hw/epf/ntb_hw_epf.c | 754 ++++++++++++++++++++++++++++++++ 5 files changed, 763 insertions(+) create mode 100644 drivers/ntb/hw/epf/Kconfig create mode 100644 drivers/ntb/hw/epf/Makefile create mode 100644 drivers/ntb/hw/epf/ntb_hw_epf.c
drivers/ntb/hw/Kconfig +1 -0
@@ -2,4 +2,5 @@ source "drivers/ntb/hw/amd/Kconfig" source "drivers/ntb/hw/idt/Kconfig" source "drivers/ntb/hw/intel/Kconfig" +source "drivers/ntb/hw/epf/Kconfig" source "drivers/ntb/hw/mscc/Kconfig"
drivers/ntb/hw/Makefile +1 -0
@@ -2,4 +2,5 @@ obj-$(CONFIG_NTB_AMD) += amd/ obj-$(CONFIG_NTB_IDT) += idt/ obj-$(CONFIG_NTB_INTEL) += intel/ +obj-$(CONFIG_NTB_EPF) += epf/ obj-$(CONFIG_NTB_SWITCHTEC) += mscc/
drivers/ntb/hw/epf/Kconfig new file +6 -0
@@ -0,0 +1,6 @@ +config NTB_EPF + tristate "Generic EPF Non-Transparent Bridge support" + depends on m + help + This driver supports EPF NTB on configurable endpoint. + If unsure, say N.
drivers/ntb/hw/epf/Makefile new file +1 -0
@@ -0,0 +1 @@ +obj-$(CONFIG_NTB_EPF) += ntb_hw_epf.o
drivers/ntb/hw/epf/ntb_hw_epf.c new file +754 -0
754 lines not on this page · raw message
Signature · 1 line
2.17.1
Re: [PATCH v9 15/17] NTB: Add support for EPF PCI-Express Non-Transparent Bridge
Quoted 9 lines · Kishon Vijay Abraham I
Add support for EPF PCI-Express Non-Transparent Bridge (NTB) device. This driver is platform independent and could be used by any platform which have multiple PCIe endpoint instances configured using the pci-epf-ntb driver. The driver connnects to the standard NTB sub-system interface. The EPF NTB device has configurable number of memory windows (Max 4), configurable number of doorbell (Max 32), and configurable number of scratch-pad registers.
Signed-off-by Kishon Vijay Abraham I <[email protected]>
Quoted 810 lines
--- drivers/ntb/hw/Kconfig | 1 + drivers/ntb/hw/Makefile | 1 + drivers/ntb/hw/epf/Kconfig | 6 + drivers/ntb/hw/epf/Makefile | 1 + drivers/ntb/hw/epf/ntb_hw_epf.c | 754 ++++++++++++++++++++++++++++++++ 5 files changed, 763 insertions(+)create mode 100644
drivers/ntb/hw/epf/Kconfigcreate mode 100644drivers/ntb/hw/epf/Makefilecreate mode 100644drivers/ntb/hw/epf/ntb_hw_epf.cdrivers/ntb/hw/Kconfig +1
-0@@ -2,4 +2,5 @@ source "drivers/ntb/hw/amd/Kconfig" source "drivers/ntb/hw/idt/Kconfig" source "drivers/ntb/hw/intel/Kconfig" +source "drivers/ntb/hw/epf/Kconfig" source "drivers/ntb/hw/mscc/Kconfig"drivers/ntb/hw/Makefile +1
-0@@ -2,4 +2,5 @@ obj-$(CONFIG_NTB_AMD) += amd/ obj-$(CONFIG_NTB_IDT) += idt/ obj-$(CONFIG_NTB_INTEL) += intel/ +obj-$(CONFIG_NTB_EPF) += epf/ obj-$(CONFIG_NTB_SWITCHTEC) += mscc/drivers/ntb/hw/epf/Kconfig new file +6
-0@@ -0,0 +1,6 @@ +config NTB_EPF + tristate "Generic EPF Non-Transparent Bridge support" + depends on m + help + This driver supports EPF NTB on configurable endpoint. + If unsure, say N.drivers/ntb/hw/epf/Makefile new file +1
-0@@ -0,0 +1 @@ +obj-$(CONFIG_NTB_EPF) += ntb_hw_epf.odrivers/ntb/hw/epf/ntb_hw_epf.c new file +754
-0@@ -0,0 +1,754 @@ +// SPDX-License-Identifier: GPL-2.0 +/** +* Host side endpoint driver to implement Non-Transparent Bridge functionality +* +* Copyright (C) 2020 Texas Instruments +* Author: Kishon Vijay Abraham I <[email protected]> +*/ + +#include <linux/delay.h> +#include <linux/module.h> +#include <linux/pci.h> +#include <linux/slab.h> +#include <linux/ntb.h> + +#define NTB_EPF_COMMAND 0x0 +#define CMD_CONFIGURE_DOORBELL 1 +#define CMD_TEARDOWN_DOORBELL 2 +#define CMD_CONFIGURE_MW 3 +#define CMD_TEARDOWN_MW 4 +#define CMD_LINK_UP 5 +#define CMD_LINK_DOWN 6 + +#define NTB_EPF_ARGUMENT 0x4 +#define MSIX_ENABLE BIT(16) + +#define NTB_EPF_CMD_STATUS 0x8 +#define COMMAND_STATUS_OK 1 +#define COMMAND_STATUS_ERROR 2 + +#define NTB_EPF_LINK_STATUS 0x0A +#define LINK_STATUS_UP BIT(0) + +#define NTB_EPF_TOPOLOGY 0x0C +#define NTB_EPF_LOWER_ADDR 0x10 +#define NTB_EPF_UPPER_ADDR 0x14 +#define NTB_EPF_LOWER_SIZE 0x18 +#define NTB_EPF_UPPER_SIZE 0x1C +#define NTB_EPF_MW_COUNT 0x20 +#define NTB_EPF_MW1_OFFSET 0x24 +#define NTB_EPF_SPAD_OFFSET 0x28 +#define NTB_EPF_SPAD_COUNT 0x2C +#define NTB_EPF_DB_ENTRY_SIZE 0x30 +#define NTB_EPF_DB_DATA (n) (0x34 + (n) * 4) +#define NTB_EPF_DB_OFFSET (n) (0xB4 + (n) * 4) + +#define NTB_EPF_MIN_DB_COUNT 3 +#define NTB_EPF_MAX_DB_COUNT 31 +#define NTB_EPF_MW_OFFSET 2 + +#define NTB_EPF_COMMAND_TIMEOUT 1000/* 1 Sec */ + +enum pci_barno { +BAR_0 , +BAR_1 , +BAR_2 , +BAR_3 , +BAR_4 , +BAR_5 , +}; + +struct ntb_epf_dev { +struct ntb_dev ntb; +struct device *dev; +/* Mutex to protect providing commands to NTB EPF */ +struct mutex cmd_lock; + +enum pci_barno ctrl_reg_bar; +enum pci_barno peer_spad_reg_bar; +enum pci_barno db_reg_bar; + +unsigned int mw_count; +unsigned int spad_count; +unsigned int db_count; + +void __iomem *ctrl_reg; +void __iomem *db_reg; +void __iomem *peer_spad_reg; + +unsigned int self_spad; +unsigned int peer_spad; + +int db_val; +u64 db_valid_mask; +}; + +#define ntb_ndev (__ntb) container_of(__ntb, struct ntb_epf_dev, ntb) + +struct ntb_epf_data { +/* BAR that contains both control region and self spad region */ +enum pci_barno ctrl_reg_bar; +/* BAR that contains peer spad region */ +enum pci_barno peer_spad_reg_bar; +/* BAR that contains Doorbell region and Memory window '1' */ +enum pci_barno db_reg_bar; +}; + +static int ntb_epf_send_command (struct ntb_epf_dev *ndev,u32 command, +u32 argument) +{ +ktime_t timeout; +bool timedout; +int ret =0 ; +u32 status; + +mutex_lock (&ndev->cmd_lock); +writel (argument, ndev->ctrl_reg +NTB_EPF_ARGUMENT ); +writel (command, ndev->ctrl_reg +NTB_EPF_COMMAND ); + + timeout =ktime_add_ms (ktime_get (),NTB_EPF_COMMAND_TIMEOUT ); +while (1 ) { + timedout =ktime_after (ktime_get (), timeout); + status =readw (ndev->ctrl_reg +NTB_EPF_CMD_STATUS ); + +if (status ==COMMAND_STATUS_ERROR ) { + ret = -EINVAL ; +break ; + } + +if (status ==COMMAND_STATUS_OK ) +break ; + +if (WARN_ON (timedout)) { + ret = -ETIMEDOUT ; +break ; + } + +usleep_range (5 ,10 ); + } + +writew (0 , ndev->ctrl_reg +NTB_EPF_CMD_STATUS ); +mutex_unlock (&ndev->cmd_lock); + +return ret; +} + +static int ntb_epf_mw_to_bar (struct ntb_epf_dev *ndev,int idx) +{ +struct device *dev = ndev->dev; + +if (idx <0 || idx > ndev->mw_count) { +dev_err (dev,"Unsupported Memory Window index %d\n" , idx); +return -EINVAL ; + } + +return idx +2 ; +} + +static int ntb_epf_mw_count (struct ntb_dev *ntb,int pidx) +{ +struct ntb_epf_dev *ndev =ntb_ndev (ntb); +struct device *dev = ndev->dev; + +if (pidx !=NTB_DEF_PEER_IDX ) { +dev_err (dev,"Unsupported Peer ID %d\n" , pidx); +return -EINVAL ; + } + +return ndev->mw_count; +} + +static int ntb_epf_mw_get_align (struct ntb_dev *ntb,int pidx,int idx, +resource_size_t *addr_align, +resource_size_t *size_align, +resource_size_t *size_max) +{ +struct ntb_epf_dev *ndev =ntb_ndev (ntb); +struct device *dev = ndev->dev; +int bar; + +if (pidx !=NTB_DEF_PEER_IDX ) { +dev_err (dev,"Unsupported Peer ID %d\n" , pidx); +return -EINVAL ; + } + + bar =ntb_epf_mw_to_bar (ndev, idx); +if (bar <0 ) +return bar; + +if (addr_align) + *addr_align =SZ_4K ; + +if (size_align) + *size_align =1 ; + +if (size_max) + *size_max =pci_resource_len (ndev->ntb.pdev, bar); + +return 0 ; +} + +static u64 ntb_epf_link_is_up (struct ntb_dev *ntb, +enum ntb_speed *speed, +enum ntb_width *width) +{ +struct ntb_epf_dev *ndev =ntb_ndev (ntb); +u32 status; + + status =readw (ndev->ctrl_reg +NTB_EPF_LINK_STATUS ); + +return status &LINK_STATUS_UP ; +} + +static u32 ntb_epf_spad_read (struct ntb_dev *ntb,int idx) +{ +struct ntb_epf_dev *ndev =ntb_ndev (ntb); +struct device *dev = ndev->dev; +u32 offset; + +if (idx <0 || idx >= ndev->spad_count) { +dev_err (dev,"READ: Invalid ScratchPad Index %d\n" , idx); +return 0 ; + } + + offset =readl (ndev->ctrl_reg +NTB_EPF_SPAD_OFFSET ); + offset += (idx <<2 ); + +return readl (ndev->ctrl_reg + offset); +} + +static int ntb_epf_spad_write (struct ntb_dev *ntb, +int idx,u32 val) +{ +struct ntb_epf_dev *ndev =ntb_ndev (ntb); +struct device *dev = ndev->dev; +u32 offset; + +if (idx <0 || idx >= ndev->spad_count) { +dev_err (dev,"WRITE: Invalid ScratchPad Index %d\n" , idx); +return -EINVAL ; + } + + offset =readl (ndev->ctrl_reg +NTB_EPF_SPAD_OFFSET ); + offset += (idx <<2 ); +writel (val, ndev->ctrl_reg + offset); + +return 0 ; +} + +static u32 ntb_epf_peer_spad_read (struct ntb_dev *ntb,int pidx,int idx) +{ +struct ntb_epf_dev *ndev =ntb_ndev (ntb); +struct device *dev = ndev->dev; +u32 offset; + +if (pidx !=NTB_DEF_PEER_IDX ) { +dev_err (dev,"Unsupported Peer ID %d\n" , pidx); +return -EINVAL ; + } + +if (idx <0 || idx >= ndev->spad_count) { +dev_err (dev,"WRITE: Invalid Peer ScratchPad Index %d\n" , idx); +return -EINVAL ; + } + + offset = (idx <<2 ); +return readl (ndev->peer_spad_reg + offset); +} + +static int ntb_epf_peer_spad_write (struct ntb_dev *ntb,int pidx, +int idx,u32 val) +{ +struct ntb_epf_dev *ndev =ntb_ndev (ntb); +struct device *dev = ndev->dev; +u32 offset; + +if (pidx !=NTB_DEF_PEER_IDX ) { +dev_err (dev,"Unsupported Peer ID %d\n" , pidx); +return -EINVAL ; + } + +if (idx <0 || idx >= ndev->spad_count) { +dev_err (dev,"WRITE: Invalid Peer ScratchPad Index %d\n" , idx); +return -EINVAL ; + } + + offset = (idx <<2 ); +writel (val, ndev->peer_spad_reg + offset); + +return 0 ; +} + +static int ntb_epf_link_enable (struct ntb_dev *ntb, +enum ntb_speed max_speed, +enum ntb_width max_width) +{ +struct ntb_epf_dev *ndev =ntb_ndev (ntb); +struct device *dev = ndev->dev; +int ret; + + ret =ntb_epf_send_command (ndev,CMD_LINK_UP ,0 ); +if (ret) { +dev_err (dev,"Fail to enable link\n" ); +return ret; + } + +return 0 ; +} + +static int ntb_epf_link_disable (struct ntb_dev *ntb) +{ +struct ntb_epf_dev *ndev =ntb_ndev (ntb); +struct device *dev = ndev->dev; +int ret; + + ret =ntb_epf_send_command (ndev,CMD_LINK_DOWN ,0 ); +if (ret) { +dev_err (dev,"Fail to disable link\n" ); +return ret; + } + +return 0 ; +} + +static irqreturn_t ntb_epf_vec_isr (int irq,void *dev) +{ +struct ntb_epf_dev *ndev = dev; +int irq_no; + + irq_no = irq -pci_irq_vector (ndev->ntb.pdev,0 ); + ndev->db_val = irq_no +1 ; + +if (irq_no ==0 ) +ntb_link_event (&ndev->ntb); +else +ntb_db_event (&ndev->ntb, irq_no); + +return IRQ_HANDLED ; +} + +static int ntb_epf_init_isr (struct ntb_epf_dev *ndev,int msi_min,int msi_max) +{ +struct pci_dev *pdev = ndev->ntb.pdev; +struct device *dev = ndev->dev; +u32 argument =MSIX_ENABLE ; +int irq; +int ret; +int i; + + irq =pci_alloc_irq_vectors (pdev, msi_min, msi_max,PCI_IRQ_MSIX ); +if (irq <0 ) { +dev_dbg (dev,"Failed to get MSIX interrupts\n" ); + irq =pci_alloc_irq_vectors (pdev, msi_min, msi_max, +PCI_IRQ_MSI ); +if (irq <0 ) { +dev_err (dev,"Failed to get MSI interrupts\n" ); +return irq; + } + argument &= ~MSIX_ENABLE ; + } + +for (i =0 ; i < irq; i++) { + ret =request_irq (pci_irq_vector (pdev, i), ntb_epf_vec_isr, +0 ,"ntb_epf" , ndev); +if (ret) { +dev_err (dev,"Failed to request irq\n" ); + goto err_request_irq; + } + } + + ndev->db_count = irq -1 ; + + ret =ntb_epf_send_command (ndev,CMD_CONFIGURE_DOORBELL , + argument | irq); +if (ret) { +dev_err (dev,"Failed to configure doorbell\n" ); + goto err_configure_db; + } + +return 0 ; + +err_configure_db: +for (i =0 ; i < ndev->db_count +1 ; i++) +free_irq (pci_irq_vector (pdev, i), ndev); + +err_request_irq: +pci_free_irq_vectors (pdev); + +return ret; +} + +static int ntb_epf_peer_mw_count (struct ntb_dev *ntb) +{ +return ntb_ndev (ntb)->mw_count; +} + +static int ntb_epf_spad_count (struct ntb_dev *ntb) +{ +return ntb_ndev (ntb)->spad_count; +} + +static u64 ntb_epf_db_valid_mask (struct ntb_dev *ntb) +{ +return ntb_ndev (ntb)->db_valid_mask; +} + +static int ntb_epf_db_set_mask (struct ntb_dev *ntb,u64 db_bits) +{ +return 0 ; +} + +static int ntb_epf_mw_set_trans (struct ntb_dev *ntb,int pidx,int idx, +dma_addr_t addr,resource_size_t size) +{ +struct ntb_epf_dev *ndev =ntb_ndev (ntb); +struct device *dev = ndev->dev; +resource_size_t mw_size; +int bar; + +if (pidx !=NTB_DEF_PEER_IDX ) { +dev_err (dev,"Unsupported Peer ID %d\n" , pidx); +return -EINVAL ; + } + + bar = idx +NTB_EPF_MW_OFFSET ; + + mw_size =pci_resource_len (ntb->pdev, bar); + +if (size > mw_size) { +dev_err (dev,"Size:%pa is greater than the MW size %pa\n" , + &size, &mw_size); +return -EINVAL ; + } + +writel (lower_32_bits (addr), ndev->ctrl_reg +NTB_EPF_LOWER_ADDR ); +writel (upper_32_bits (addr), ndev->ctrl_reg +NTB_EPF_UPPER_ADDR ); +writel (lower_32_bits (size), ndev->ctrl_reg +NTB_EPF_LOWER_SIZE ); +writel (upper_32_bits (size), ndev->ctrl_reg +NTB_EPF_UPPER_SIZE ); +ntb_epf_send_command (ndev,CMD_CONFIGURE_MW , idx); + +return 0 ; +} + +static int ntb_epf_mw_clear_trans (struct ntb_dev *ntb,int pidx,int idx) +{ +struct ntb_epf_dev *ndev =ntb_ndev (ntb); +struct device *dev = ndev->dev; +int ret =0 ; + +ntb_epf_send_command (ndev,CMD_TEARDOWN_MW , idx); +if (ret) +dev_err (dev,"Failed to teardown memory window\n" ); + +return ret; +} + +static int ntb_epf_peer_mw_get_addr (struct ntb_dev *ntb,int idx, +phys_addr_t *base,resource_size_t *size) +{ +struct ntb_epf_dev *ndev =ntb_ndev (ntb); +u32 offset =0 ; +int bar; + +if (idx ==0 ) + offset =readl (ndev->ctrl_reg +NTB_EPF_MW1_OFFSET ); + + bar = idx +NTB_EPF_MW_OFFSET ; + +if (base) + *base =pci_resource_start (ndev->ntb.pdev, bar) + offset; + +if (size) + *size =pci_resource_len (ndev->ntb.pdev, bar) - offset; + +return 0 ; +} + +static int ntb_epf_peer_db_set (struct ntb_dev *ntb,u64 db_bits) +{ +struct ntb_epf_dev *ndev =ntb_ndev (ntb); +u32 interrupt_num =ffs (db_bits) +1 ; +struct device *dev = ndev->dev; +u32 db_entry_size; +u32 db_offset; +u32 db_data; + +if (interrupt_num > ndev->db_count) { +dev_err (dev,"DB interrupt %d greater than Max Supported %d\n" , + interrupt_num, ndev->db_count); +return -EINVAL ; + } + + db_entry_size =readl (ndev->ctrl_reg +NTB_EPF_DB_ENTRY_SIZE ); + + db_data =readl (ndev->ctrl_reg +NTB_EPF_DB_DATA (interrupt_num)); + db_offset =readl (ndev->ctrl_reg +NTB_EPF_DB_OFFSET (interrupt_num)); +writel (db_data, ndev->db_reg + (db_entry_size * interrupt_num) + + db_offset); + +return 0 ; +} + +static u64 ntb_epf_db_read (struct ntb_dev *ntb) +{ +struct ntb_epf_dev *ndev =ntb_ndev (ntb); + +return ndev->db_val; +} + +static int ntb_epf_db_clear_mask (struct ntb_dev *ntb,u64 db_bits) +{ +return 0 ; +} + +static int ntb_epf_db_clear (struct ntb_dev *ntb,u64 db_bits) +{ +struct ntb_epf_dev *ndev =ntb_ndev (ntb); + + ndev->db_val =0 ; + +return 0 ; +} + +static const struct ntb_dev_ops ntb_epf_ops = { + .mw_count = ntb_epf_mw_count, + .spad_count = ntb_epf_spad_count, + .peer_mw_count = ntb_epf_peer_mw_count, + .db_valid_mask = ntb_epf_db_valid_mask, + .db_set_mask = ntb_epf_db_set_mask, + .mw_set_trans = ntb_epf_mw_set_trans, + .mw_clear_trans = ntb_epf_mw_clear_trans, + .peer_mw_get_addr = ntb_epf_peer_mw_get_addr, + .link_enable = ntb_epf_link_enable, + .spad_read = ntb_epf_spad_read, + .spad_write = ntb_epf_spad_write, + .peer_spad_read = ntb_epf_peer_spad_read, + .peer_spad_write = ntb_epf_peer_spad_write, + .peer_db_set = ntb_epf_peer_db_set, + .db_read = ntb_epf_db_read, + .mw_get_align = ntb_epf_mw_get_align, + .link_is_up = ntb_epf_link_is_up, + .db_clear_mask = ntb_epf_db_clear_mask, + .db_clear = ntb_epf_db_clear, + .link_disable = ntb_epf_link_disable, +}; + +static inline void ntb_epf_init_struct (struct ntb_epf_dev *ndev, +struct pci_dev *pdev) +{ + ndev->ntb.pdev = pdev; + ndev->ntb.topo =NTB_TOPO_NONE ; + ndev->ntb.ops = &ntb_epf_ops; +} + +static int ntb_epf_init_dev (struct ntb_epf_dev *ndev) +{ +struct device *dev = ndev->dev; +int ret; + +/* One Link interrupt and rest doorbell interrupt */ + ret =ntb_epf_init_isr (ndev,NTB_EPF_MIN_DB_COUNT +1 , +NTB_EPF_MAX_DB_COUNT +1 ); +if (ret) { +dev_err (dev,"Failed to init ISR\n" ); +return ret; + } + + ndev->db_valid_mask =BIT_ULL (ndev->db_count) -1 ; + ndev->mw_count =readl (ndev->ctrl_reg +NTB_EPF_MW_COUNT ); + ndev->spad_count =readl (ndev->ctrl_reg +NTB_EPF_SPAD_COUNT ); + +return 0 ; +} + +static int ntb_epf_init_pci (struct ntb_epf_dev *ndev, +struct pci_dev *pdev) +{ +struct device *dev = ndev->dev; +int ret; + +pci_set_drvdata (pdev, ndev); + + ret =pci_enable_device (pdev); +if (ret) { +dev_err (dev,"Cannot enable PCI device\n" ); + goto err_pci_enable; + } + + ret =pci_request_regions (pdev,"ntb" ); +if (ret) { +dev_err (dev,"Cannot obtain PCI resources\n" ); + goto err_pci_regions; + } + +pci_set_master (pdev); + + ret =dma_set_mask_and_coherent (dev,DMA_BIT_MASK (64 )); +if (ret) { + ret =dma_set_mask_and_coherent (dev,DMA_BIT_MASK (32 )); +if (ret) { +dev_err (dev,"Cannot set DMA mask\n" ); + goto err_dma_mask; + } +dev_warn (&pdev->dev,"Cannot DMA highmem\n" ); + } + + ndev->ctrl_reg =pci_iomap (pdev, ndev->ctrl_reg_bar,0 ); +if (!ndev->ctrl_reg) { + ret = -EIO ; + goto err_dma_mask; + } + + ndev->peer_spad_reg =pci_iomap (pdev, ndev->peer_spad_reg_bar,0 ); +if (!ndev->peer_spad_reg) { + ret = -EIO ; + goto err_dma_mask; + } + + ndev->db_reg =pci_iomap (pdev, ndev->db_reg_bar,0 ); +if (!ndev->db_reg) { + ret = -EIO ; + goto err_dma_mask; + } + +return 0 ; + +err_dma_mask: +pci_clear_master (pdev); + +err_pci_regions: +pci_disable_device (pdev); + +err_pci_enable: +pci_set_drvdata (pdev,NULL ); + +return ret; +} + +static void ntb_epf_deinit_pci (struct ntb_epf_dev *ndev) +{ +struct pci_dev *pdev = ndev->ntb.pdev; + +pci_iounmap (pdev, ndev->ctrl_reg); +pci_iounmap (pdev, ndev->peer_spad_reg); +pci_iounmap (pdev, ndev->db_reg); + +pci_clear_master (pdev); +pci_release_regions (pdev); +pci_disable_device (pdev); +pci_set_drvdata (pdev,NULL ); +} + +static void ntb_epf_cleanup_isr (struct ntb_epf_dev *ndev) +{ +struct pci_dev *pdev = ndev->ntb.pdev; +int i; + +ntb_epf_send_command (ndev,CMD_TEARDOWN_DOORBELL , ndev->db_count +1 ); + +for (i =0 ; i < ndev->db_count +1 ; i++) +free_irq (pci_irq_vector (pdev, i), ndev); +pci_free_irq_vectors (pdev); +} + +static int ntb_epf_pci_probe (struct pci_dev *pdev, +const struct pci_device_id *id) +{ +enum pci_barno peer_spad_reg_bar =BAR_1 ; +enum pci_barno ctrl_reg_bar =BAR_0 ; +enum pci_barno db_reg_bar =BAR_2 ; +struct device *dev = &pdev->dev; +struct ntb_epf_data *data; +struct ntb_epf_dev *ndev; +int ret; + +if (pci_is_bridge (pdev)) +return -ENODEV ; + + ndev =devm_kzalloc (dev,sizeof (*ndev),GFP_KERNEL ); +if (!ndev) +return -ENOMEM ; + + data = (struct ntb_epf_data *)id->driver_data; +if (data) { +if (data->peer_spad_reg_bar) + peer_spad_reg_bar = data->peer_spad_reg_bar; +if (data->ctrl_reg_bar) + ctrl_reg_bar = data->ctrl_reg_bar; +if (data->db_reg_bar) + db_reg_bar = data->db_reg_bar; + } + + ndev->peer_spad_reg_bar = peer_spad_reg_bar; + ndev->ctrl_reg_bar = ctrl_reg_bar; + ndev->db_reg_bar = db_reg_bar; + ndev->dev = dev; + +ntb_epf_init_struct (ndev, pdev); +mutex_init (&ndev->cmd_lock); + + ret =ntb_epf_init_pci (ndev, pdev); +if (ret) { +dev_err (dev,"Failed to init PCI\n" ); +return ret; + } + + ret =ntb_epf_init_dev (ndev); +if (ret) { +dev_err (dev,"Failed to init device\n" ); + goto err_init_dev; + } + + ret =ntb_register_device (&ndev->ntb); +if (ret) { +dev_err (dev,"Failed to register NTB device\n" ); + goto err_register_dev; + } + +return 0 ; + +err_register_dev: +ntb_epf_cleanup_isr (ndev); + +err_init_dev: +ntb_epf_deinit_pci (ndev); + +return ret; +} + +static void ntb_epf_pci_remove (struct pci_dev *pdev) +{ +struct ntb_epf_dev *ndev =pci_get_drvdata (pdev); + +ntb_unregister_device (&ndev->ntb); +ntb_epf_cleanup_isr (ndev); +ntb_epf_deinit_pci (ndev); +kfree (ndev); +} + +static const struct ntb_epf_data j721e_data = { + .ctrl_reg_bar =BAR_0 , + .peer_spad_reg_bar =BAR_1 , + .db_reg_bar =BAR_2 , +}; + +static const struct pci_device_id ntb_epf_pci_tbl[] = { + { +PCI_DEVICE (PCI_VENDOR_ID_TI ,PCI_DEVICE_ID_TI_J721E ), + .class =PCI_CLASS_MEMORY_RAM <<8 , .class_mask =0xffff00 , + .driver_data = (kernel_ulong_t)&j721e_data, + }, + { }, +}; + +static struct pci_driver ntb_epf_pci_driver = { + .name =KBUILD_MODNAME , + .id_table = ntb_epf_pci_tbl, + .probe = ntb_epf_pci_probe, + .remove = ntb_epf_pci_remove, +}; +module_pci_driver (ntb_epf_pci_driver); + +MODULE_DESCRIPTION ("PCI ENDPOINT NTB HOST DRIVER" ); +MODULE_AUTHOR ("Kishon Vijay Abraham I <[email protected]>" ); +MODULE_LICENSE ("GPL v2" );
PATCH v9 16/17 Documentation: PCI: Add configfs binding documentation for pci-ntb endpoint function
In reply to Kishon Vijay Abraham IAdd binding documentation for pci-ntb endpoint function that helps in adding and configuring pci-ntb endpoint function.
--- .../PCI/endpoint/function/binding/pci-ntb.rst | 38 +++++++++++++++++++ Documentation/PCI/endpoint/index.rst | 1 + 2 files changed, 39 insertions(+) create mode 100644 Documentation/PCI/endpoint/function/binding/pci-ntb.rst
Documentation/PCI/endpoint/function/binding/pci-ntb.rst new file +38 -0
@@ -0,0 +1,38 @@ +.. SPDX-License-Identifier: GPL-2.0 + +========================== +PCI NTB Endpoint Function +========================== + +1) Create a subdirectory to pci_epf_ntb directory in configfs. + +Standard EPF Configurable Fields: + +================ =========================================================== +vendorid should be 0x104c +deviceid should be 0xb00d for TI's J721E SoC +revid don't care +progif_code don't care +subclass_code should be 0x00 +baseclass_code should be 0x5 +cache_line_size don't care +subsys_vendor_id don't care +subsys_id don't care +interrupt_pin don't care +msi_interrupts don't care +msix_interrupts don't care +================ =========================================================== + +2) Create a subdirectory to directory created in 1 + +NTB EPF specific configurable fields: + +================ =========================================================== +db_count Number of doorbells; default = 4 +mw1 size of memory window1 +mw2 size of memory window2 +mw3 size of memory window3 +mw4 size of memory window4 +num_mws Number of memory windows; max = 4 +spad_count Number of scratchpad registers; default = 64 +================ ===========================================================
Documentation/PCI/endpoint/index.rst +1 -0
@@ -14,3 +14,4 @@ PCI Endpoint Framework pci-ntb-function function/binding/pci-test + function/binding/pci-ntb
Signature · 1 line
2.17.1
PATCH v9 17/17 Documentation: PCI: Add userguide for PCI endpoint NTB function
In reply to Kishon Vijay Abraham IAdd documentation to help users use pci-epf-ntb function driver and existing host side NTB infrastructure for NTB functionality.
--- Documentation/PCI/endpoint/index.rst | 1 + Documentation/PCI/endpoint/pci-ntb-howto.rst | 160 +++++++++++++++++++ 2 files changed, 161 insertions(+) create mode 100644 Documentation/PCI/endpoint/pci-ntb-howto.rst
Documentation/PCI/endpoint/index.rst +1 -0
@@ -12,6 +12,7 @@ PCI Endpoint Framework pci-test-function pci-test-howto pci-ntb-function + pci-ntb-howto function/binding/pci-test function/binding/pci-ntb
Documentation/PCI/endpoint/pci-ntb-howto.rst new file +160 -0
160 lines not on this page · raw message
Signature · 1 line
2.17.1
Re: [PATCH v9 17/17] Documentation: PCI: Add userguide for PCI endpoint NTB function
Quoted 42 lines · Kishon Vijay Abraham I
Add documentation to help users use pci-epf-ntb function driver and existing host side NTB infrastructure for NTB functionality.
Signed-off-by Kishon Vijay Abraham I <[email protected]>Reviewed-by Randy Dunlap <[email protected]>--- Documentation/PCI/endpoint/index.rst | 1 + Documentation/PCI/endpoint/pci-ntb-howto.rst | 160 +++++++++++++++++++ 2 files changed, 161 insertions(+) create mode 100644 Documentation/PCI/endpoint/pci-ntb-howto.rstDocumentation/PCI/endpoint/index.rst +1
-0@@ -12,6 +12,7 @@ PCI Endpoint Framework pci-test-function pci-test-howto pci-ntb-function + pci-ntb-howto function/binding/pci-test function/binding/pci-ntbDocumentation/PCI/endpoint/pci-ntb-howto.rst new file +13
-0@@ -0,0 +1,160 @@ +.. SPDX-License-Identifier: GPL-2.0 + +=================================================================== +PCI Non-Transparent Bridge (NTB) Endpoint Function (EPF) User Guide +=================================================================== + +:Author: Kishon Vijay Abraham I <[email protected]> + +This document is a guide to help users use pci-epf-ntb function driver +and ntb_hw_epf host driver for NTB functionality. The list of steps to +be followed in the host side and EP side is given below. For the hardware +configuration and internals of NTB using configurable endpoints see +Documentation/PCI/endpoint/pci-ntb-function.rst
Documentation/PCI/endpoint/pci-ntb-howto.rst line 23
Quoted 10 lines
Documentation/PCI/endpoint/pci-ntb-howto.rst new file +10
-0+ +Endpoint Device +=============== + +Endpoint Controller Devices +--------------------------- + +For implementing NTB functionality at least two endpoint controller devices +are required. +To find the list of endpoint controller devices in the system::
Is the above one paragraph or two? Reflow or add blank line as appropriate.
Re: [PATCH v9 17/17] Documentation: PCI: Add userguide for PCI endpoint NTB function
Hi Bjorn,
Quoted 48 lines · Bjorn Helgaas
Quoted 47 lines · Kishon Vijay Abraham I
Add documentation to help users use pci-epf-ntb function driver and existing host side NTB infrastructure for NTB functionality.
Signed-off-by Kishon Vijay Abraham I <[email protected]>Reviewed-by Randy Dunlap <[email protected]>--- Documentation/PCI/endpoint/index.rst | 1 + Documentation/PCI/endpoint/pci-ntb-howto.rst | 160 +++++++++++++++++++ 2 files changed, 161 insertions(+) create mode 100644 Documentation/PCI/endpoint/pci-ntb-howto.rstDocumentation/PCI/endpoint/index.rst +1
-0@@ -12,6 +12,7 @@ PCI Endpoint Framework pci-test-function pci-test-howto pci-ntb-function + pci-ntb-howto function/binding/pci-test function/binding/pci-ntbDocumentation/PCI/endpoint/pci-ntb-howto.rst new file +18
-0@@ -0,0 +1,160 @@ +.. SPDX-License-Identifier: GPL-2.0 + +=================================================================== +PCI Non-Transparent Bridge (NTB) Endpoint Function (EPF) User Guide +=================================================================== + +:Author: Kishon Vijay Abraham I <[email protected]> + +This document is a guide to help users use pci-epf-ntb function driver +and ntb_hw_epf host driver for NTB functionality. The list of steps to +be followed in the host side and EP side is given below. For the hardware +configuration and internals of NTB using configurable endpoints see +Documentation/PCI/endpoint/pci-ntb-function.rst + +Endpoint Device +=============== + +Endpoint Controller Devices
Quoted 8 lines
Documentation/PCI/endpoint/pci-ntb-howto.rst line 23
Quoted 5 lines
Documentation/PCI/endpoint/pci-ntb-howto.rst new file +5
-0+--------------------------- + +For implementing NTB functionality at least two endpoint controller devices +are required. +To find the list of endpoint controller devices in the system::Is the above one paragraph or two? Reflow or add blank line as appropriate.
I'll add blank line above.
Thanks
Kishon
+MAINTAINERS for platforms supporting PCIe EP mode
Hi All,
I've looped you in since the platform you maintain supports PCIe EP mode. This series builds NTB functionality on top of PCIe endpoint framework. For NTB functionality it needs atleast two endpoint instances. I'm trying to see if someone can help me test this series in any of the platforms you support.
Even if your platform cannot enable NTB, if you can just apply this patch series and test pci_epf_test that would be very much helpful.
Thanks in advance for your help.
Best Regards,
Kishon
Quoted 138 lines · Kishon Vijay Abraham I
This series is about implementing SW defined Non-Transparent Bridge (NTB) using multiple endpoint (EP) instances. This series has been tested using 2 endpoint instances in J7 connected to J7 board on one end and DRA7 board on the other end. However there is nothing platform specific for the NTB functionality.
This was presented in Linux Plumbers Conference. Link to presentation and video can be found @ [1]
Created a video demo @ [9]RFC patch series can be found @ [2]
v1 patch series can be found @ [3]
v2 patch series can be found @ [4]
v3 patch series can be found @ [5]
v4 patch series can be found @ [6]
v5 patch series can be found @ [7]
v6 patch series can be found @ [8]
v7 patch series can be found @ [10]
v8 patch series can be found @ [11]Changes from v8:
1) Do not use devm_request_irq/devm_free_irq aspci_free_irq_vectors()has to be used afterfree_irq
2) Drop "NTB: tool: Enable the NTB/PCIe link on the local or remote side of bridge" as there is a debugfs entry to enable the linkChanges from v7:
1) Used values stored inctrl_reg_bar,peer_spad_reg_baranddb_reg_barinstead of hardcoded values inpci_iomapofntb_hw_epf.cdriverChanges from v6:
1) Fixed issues when multiple NTB devices are creating using multiple functions
2) Fixed issue with writing scratchpad register
3) Created a video demo @ [9]Changes from v5:
1) Fixed a formatting issue inKconfigpointed out by Randy
2) Checked for Error or Null inpci_epc_add_epf()Changes from v4:
1) Fixed error condition checks inpci_epc_add_epf()Changes from v3:
1) Fixed Documentation edits suggested by Randy Dunlap <[email protected]>Changes from v2:
1) Add support for the user to create sub-directory of 'EPF Device' directory (for endpoint function specific configuration using configfs).
2) Add documentation for NTB specific attributes in configfs
3) Check forPCI_CLASS_MEMORY_RAM(PCIe class) before bindingntb_hw_epfdriver
4) Other documentation fixesChanges from v1:
1) As per Rob's comment, removed support for creating NTB function device from DT
2) Add support to create NTB EPF device using configfs (added support in configfs to associate primary and secondary EPC with EPF.Changes from RFC:
1) Converted the DT binding patches to YAML schema and merged the DT binding patches together
2) NTB documentation is converted to .rst
3) One HOST can now interrupt the other HOST using MSI-X interrupts
4) Added support for teardown of memory window and doorbell configuration
5) Add support to provide support 64-bit memory window size from DT[1] -> https://linuxplumbersconf.org/event/4/contributions/395/
[2] -> http://lore.kernel.org/r/[email protected]
[3] -> http://lore.kernel.org/r/[email protected]
[4] -> http://lore.kernel.org/r/[email protected]
[5] -> http://lore.kernel.org/r/[email protected]
[6] -> http://lore.kernel.org/r/[email protected]
[7] -> http://lore.kernel.org/r/[email protected]
[8] -> http://lore.kernel.org/r/[email protected]
[9] -> https://youtu.be/dLKKxrg5-rY
[10] -> http://lore.kernel.org/r/[email protected]
[11] -> http://lore.kernel.org/r/[email protected]Kishon Vijay Abraham I (17):
Documentation: PCI: Add specification for the *PCI NTB* function
device
PCI: endpoint: Make*_get_first_free_bar()take into account 64 bit
BAR
PCI: endpoint: Add helper API to get the 'next' unreserved BAR
PCI: endpoint: Make*_free_bar()to return error codes on failure
PCI: endpoint: Remove unusedpci_epf_match_device()
PCI: endpoint: Add support to associate secondary EPC with EPF
PCI: endpoint: Add support in configfs to associate two EPCs with EPF
PCI: endpoint: Addpci_epc_opsto map MSI irq
PCI: endpoint: Addpci_epf_opsfor epf drivers to expose function
specific attrs
PCI: endpoint: Allow user to create sub-directory of 'EPF Device'
directory
PCI: cadence: Implement ->msi_map_irq() ops
PCI: cadence: ConfigureLM_EP_FUNC_CFGbased onepc->function_num_map
PCI: endpoint: Add EP function driver to provide NTB functionality
PCI: Add TI J721E device to pci ids
NTB: Add support for EPF PCI-Express Non-Transparent Bridge
Documentation: PCI: Add configfs binding documentation for pci-ntb
endpoint function
Documentation: PCI: Add userguide for PCI endpoint NTB function.../PCI/endpoint/function/binding/pci-ntb.rst | 38 + Documentation/PCI/endpoint/index.rst | 3 + .../PCI/endpoint/pci-endpoint-cfs.rst | 10 + .../PCI/endpoint/pci-ntb-function.rst | 351 +++ Documentation/PCI/endpoint/pci-ntb-howto.rst | 160 ++ drivers/misc/pci_endpoint_test.c | 1 - drivers/ntb/hw/Kconfig | 1 + drivers/ntb/hw/Makefile | 1 + drivers/ntb/hw/epf/Kconfig | 6 + drivers/ntb/hw/epf/Makefile | 1 + drivers/ntb/hw/epf/ntb_hw_epf.c | 754 ++++++ .../pci/controller/cadence/pcie-cadence-ep.c | 60 +- drivers/pci/endpoint/functions/Kconfig | 12 + drivers/pci/endpoint/functions/Makefile | 1 + drivers/pci/endpoint/functions/pci-epf-ntb.c | 2114 +++++++++++++++++ drivers/pci/endpoint/functions/pci-epf-test.c | 13 +- drivers/pci/endpoint/pci-ep-cfs.c | 176 +- drivers/pci/endpoint/pci-epc-core.c | 130 +- drivers/pci/endpoint/pci-epf-core.c | 105 +- include/linux/pci-epc.h | 39 +- include/linux/pci-epf.h | 28 +- include/linux/pci_ids.h | 1 + 22 files changed, 3932 insertions(+), 73 deletions(-) create mode 100644 Documentation/PCI/endpoint/function/binding/pci-ntb.rst create mode 100644 Documentation/PCI/endpoint/pci-ntb-function.rst create mode 100644 Documentation/PCI/endpoint/pci-ntb-howto.rst create mode 100644 drivers/ntb/hw/epf/Kconfig create mode 100644 drivers/ntb/hw/epf/Makefile create mode 100644 drivers/ntb/hw/epf/ntb_hw_epf.c create mode 100644 drivers/pci/endpoint/functions/pci-epf-ntb.c
Hi,
Quoted 10 lines · Kishon Vijay Abraham I
+MAINTAINERS for platforms supporting PCIe EP mode
Hi All,
I've looped you in since the platform you maintain supports PCIe EP mode. This series builds NTB functionality on top of PCIe endpoint framework. For NTB functionality it needs atleast two endpoint instances. I'm trying to see if someone can help me test this series in any of the platforms you support.
Quoted 4 lines
Even if your platform cannot enable NTB, if you can just apply this patch series and test
pci_epf_testthat would be very much helpful.Thanks in advance for your help.
Gentle ping for providing your "Reviewed-by" and "Tested-by".
Thank You,
Kishon
Quoted 143 lines
Best Regards,
KishonQuoted 138 lines · Kishon Vijay Abraham I
This series is about implementing SW defined Non-Transparent Bridge (NTB) using multiple endpoint (EP) instances. This series has been tested using 2 endpoint instances in J7 connected to J7 board on one end and DRA7 board on the other end. However there is nothing platform specific for the NTB functionality.
This was presented in Linux Plumbers Conference. Link to presentation and video can be found @ [1]
Created a video demo @ [9]RFC patch series can be found @ [2]
v1 patch series can be found @ [3]
v2 patch series can be found @ [4]
v3 patch series can be found @ [5]
v4 patch series can be found @ [6]
v5 patch series can be found @ [7]
v6 patch series can be found @ [8]
v7 patch series can be found @ [10]
v8 patch series can be found @ [11]Changes from v8:
1) Do not use devm_request_irq/devm_free_irq aspci_free_irq_vectors()has to be used afterfree_irq
2) Drop "NTB: tool: Enable the NTB/PCIe link on the local or remote side of bridge" as there is a debugfs entry to enable the linkChanges from v7:
1) Used values stored inctrl_reg_bar,peer_spad_reg_baranddb_reg_barinstead of hardcoded values inpci_iomapofntb_hw_epf.cdriverChanges from v6:
1) Fixed issues when multiple NTB devices are creating using multiple functions
2) Fixed issue with writing scratchpad register
3) Created a video demo @ [9]Changes from v5:
1) Fixed a formatting issue inKconfigpointed out by Randy
2) Checked for Error or Null inpci_epc_add_epf()Changes from v4:
1) Fixed error condition checks inpci_epc_add_epf()Changes from v3:
1) Fixed Documentation edits suggested by Randy Dunlap <[email protected]>Changes from v2:
1) Add support for the user to create sub-directory of 'EPF Device' directory (for endpoint function specific configuration using configfs).
2) Add documentation for NTB specific attributes in configfs
3) Check forPCI_CLASS_MEMORY_RAM(PCIe class) before bindingntb_hw_epfdriver
4) Other documentation fixesChanges from v1:
1) As per Rob's comment, removed support for creating NTB function device from DT
2) Add support to create NTB EPF device using configfs (added support in configfs to associate primary and secondary EPC with EPF.Changes from RFC:
1) Converted the DT binding patches to YAML schema and merged the DT binding patches together
2) NTB documentation is converted to .rst
3) One HOST can now interrupt the other HOST using MSI-X interrupts
4) Added support for teardown of memory window and doorbell configuration
5) Add support to provide support 64-bit memory window size from DT[1] -> https://linuxplumbersconf.org/event/4/contributions/395/
[2] -> http://lore.kernel.org/r/[email protected]
[3] -> http://lore.kernel.org/r/[email protected]
[4] -> http://lore.kernel.org/r/[email protected]
[5] -> http://lore.kernel.org/r/[email protected]
[6] -> http://lore.kernel.org/r/[email protected]
[7] -> http://lore.kernel.org/r/[email protected]
[8] -> http://lore.kernel.org/r/[email protected]
[9] -> https://youtu.be/dLKKxrg5-rY
[10] -> http://lore.kernel.org/r/[email protected]
[11] -> http://lore.kernel.org/r/[email protected]Kishon Vijay Abraham I (17):
Documentation: PCI: Add specification for the *PCI NTB* function
device
PCI: endpoint: Make*_get_first_free_bar()take into account 64 bit
BAR
PCI: endpoint: Add helper API to get the 'next' unreserved BAR
PCI: endpoint: Make*_free_bar()to return error codes on failure
PCI: endpoint: Remove unusedpci_epf_match_device()
PCI: endpoint: Add support to associate secondary EPC with EPF
PCI: endpoint: Add support in configfs to associate two EPCs with EPF
PCI: endpoint: Addpci_epc_opsto map MSI irq
PCI: endpoint: Addpci_epf_opsfor epf drivers to expose function
specific attrs
PCI: endpoint: Allow user to create sub-directory of 'EPF Device'
directory
PCI: cadence: Implement ->msi_map_irq() ops
PCI: cadence: ConfigureLM_EP_FUNC_CFGbased onepc->function_num_map
PCI: endpoint: Add EP function driver to provide NTB functionality
PCI: Add TI J721E device to pci ids
NTB: Add support for EPF PCI-Express Non-Transparent Bridge
Documentation: PCI: Add configfs binding documentation for pci-ntb
endpoint function
Documentation: PCI: Add userguide for PCI endpoint NTB function.../PCI/endpoint/function/binding/pci-ntb.rst | 38 + Documentation/PCI/endpoint/index.rst | 3 + .../PCI/endpoint/pci-endpoint-cfs.rst | 10 + .../PCI/endpoint/pci-ntb-function.rst | 351 +++ Documentation/PCI/endpoint/pci-ntb-howto.rst | 160 ++ drivers/misc/pci_endpoint_test.c | 1 - drivers/ntb/hw/Kconfig | 1 + drivers/ntb/hw/Makefile | 1 + drivers/ntb/hw/epf/Kconfig | 6 + drivers/ntb/hw/epf/Makefile | 1 + drivers/ntb/hw/epf/ntb_hw_epf.c | 754 ++++++ .../pci/controller/cadence/pcie-cadence-ep.c | 60 +- drivers/pci/endpoint/functions/Kconfig | 12 + drivers/pci/endpoint/functions/Makefile | 1 + drivers/pci/endpoint/functions/pci-epf-ntb.c | 2114 +++++++++++++++++ drivers/pci/endpoint/functions/pci-epf-test.c | 13 +- drivers/pci/endpoint/pci-ep-cfs.c | 176 +- drivers/pci/endpoint/pci-epc-core.c | 130 +- drivers/pci/endpoint/pci-epf-core.c | 105 +- include/linux/pci-epc.h | 39 +- include/linux/pci-epf.h | 28 +- include/linux/pci_ids.h | 1 + 22 files changed, 3932 insertions(+), 73 deletions(-) create mode 100644 Documentation/PCI/endpoint/function/binding/pci-ntb.rst create mode 100644 Documentation/PCI/endpoint/pci-ntb-function.rst create mode 100644 Documentation/PCI/endpoint/pci-ntb-howto.rst create mode 100644 drivers/ntb/hw/epf/Kconfig create mode 100644 drivers/ntb/hw/epf/Makefile create mode 100644 drivers/ntb/hw/epf/ntb_hw_epf.c create mode 100644 drivers/pci/endpoint/functions/pci-epf-ntb.c
Quoted 11 lines · Kishon Vijay Abraham I
This series is about implementing SW defined Non-Transparent Bridge (NTB) using multiple endpoint (EP) instances. This series has been tested using 2 endpoint instances in J7 connected to J7 board on one end and DRA7 board on the other end. However there is nothing platform specific for the NTB functionality.
This was presented in Linux Plumbers Conference. Link to presentation and video can be found @ [1]
Created a video demo @ [9][...]
Applied to pci/ntb to give it more visibility and testing, aiming for v5.12.
[01/17] Documentation: PCI: Add specification for the *PCI NTB* function device
https://git.kernel.org/lpieralisi/pci/c/75e6ac86ca [02/17] PCI: endpoint: Make *_get_first_free_bar() take into account 64 bit BAR https://git.kernel.org/lpieralisi/pci/c/b6c7a2a2b5 [03/17] PCI: endpoint: Add helper API to get the 'next' unreserved BAR https://git.kernel.org/lpieralisi/pci/c/43e293914d [04/17] PCI: endpoint: Make *_free_bar() to return error codes on failure https://git.kernel.org/lpieralisi/pci/c/293e2c258c [05/17] PCI: endpoint: Remove unused pci_epf_match_device() https://git.kernel.org/lpieralisi/pci/c/9a25bdab98 [06/17] PCI: endpoint: Add support to associate secondary EPC with EPF https://git.kernel.org/lpieralisi/pci/c/868fe90ea4 [07/17] PCI: endpoint: Add support in configfs to associate two EPCs with EPF https://git.kernel.org/lpieralisi/pci/c/632c92ec12 [08/17] PCI: endpoint: Add pci_epc_ops to map MSI irq https://git.kernel.org/lpieralisi/pci/c/310511a301 [09/17] PCI: endpoint: Add pci_epf_ops for epf drivers to expose function specific attrs https://git.kernel.org/lpieralisi/pci/c/34fb8ab2e3 [10/17] PCI: endpoint: Allow user to create sub-directory of 'EPF Device' directory https://git.kernel.org/lpieralisi/pci/c/3a5c112c7a [11/17] PCI: cadence: Implement ->msi_map_irq() ops https://git.kernel.org/lpieralisi/pci/c/d5c3d2ae7c [12/17] PCI: cadence: Configure LM_EP_FUNC_CFG based on epc->function_num_map https://git.kernel.org/lpieralisi/pci/c/d3f4973104 [13/17] PCI: endpoint: Add EP function driver to provide NTB functionality https://git.kernel.org/lpieralisi/pci/c/7dc64244f9 [14/17] PCI: Add TI J721E device to pci ids https://git.kernel.org/lpieralisi/pci/c/17d49876c3 [15/17] NTB: Add support for EPF PCI-Express Non-Transparent Bridge https://git.kernel.org/lpieralisi/pci/c/5d0db3f429 [16/17] Documentation: PCI: Add configfs binding documentation for pci-ntb endpoint function https://git.kernel.org/lpieralisi/pci/c/099f07051e [17/17] Documentation: PCI: Add userguide for PCI endpoint NTB function https://git.kernel.org/lpieralisi/pci/c/27f22f76c3
Thanks,
Lorenzo