Code example for packet transmission mentioned in PCIe blog

Comments and questions related to the "Down to the TLP" pages

Code example for packet transmission mentioned in PCIe blog

Postby Guest »

hi Eli

Is there any code example we can look at to understand the theory in the blog better? I am very new to PCIe and feel this would be very helpful.

Thanks
Guest
 

Re: Code example for packet transmission mentioned in PCIe b

Postby support »

Hi.

The question would be: Code example of what? Logic implementing interface with a PCIe bus? Xilinx gives you that when you create the PCIe block plus IP core (which is free of charge). Software drivers using PCIe? Any Linux driver for a PCIe device demonstrates that. Windows supplies examples in its WDK.

But in the end of the day, PCIe is just a bus, so on the PC side you'll see plain memory reads and writes, and the logic design munching the packets. I'm not sure dissecting a state machine implemented in Verilog or VHDL is the easiest path.
support
 
Posts: 802
Joined:

Re: Code example for packet transmission mentioned in PCIe b

Postby Guest »

Hi Eli

Thanks for the quick reply.
I am not looking at hardware/VHDL side. I was looking more for example code on the read/write request packets, their formation and transmission for memory/IO/config space access,etc by a CPU core to a PCIe periphral. (linux drivers)

Thanks
Guest
 

Re: Code example for packet transmission mentioned in PCIe b

Postby support »

I see.

Well, as I mentioned, PCIe is a bus. So when you write (as in *p = a) to an address within the range mapped to a PCIe card, a write request packet is generated by the root complex (i.e. the processor or memory controller chip). When you read from such an address (as in a = *p) a read request is sent, and a completion waited for. In reality, these operations are wrapped by calls such as iowrite32() (in Linux) to make the casts to volatile pointers and handling memory barriers and caches properly. But deep down, you'll have a plain memory write or read using a pointer.

So the packets aren't generated by software. To the programmer, the PCIe bus is just another chunk of memory. Or I/O space, if you insist on being old-fashioned.
support
 
Posts: 802
Joined:

Re: Code example for packet transmission mentioned in PCIe b

Postby Guest »

hi Eli

Thanks for the quick reply again.

So by address the PCIe card is mapped to do you mean the address obtained by reading the BAR register? and then we ioremap this addr on the CPU?
Also what happens if the PCIe periphral the CPU wants to talk to is another processor? Would it make a difference in the way the read/write happens?

Thanks
Guest
 

Re: Code example for packet transmission mentioned in PCIe b

Postby support »

Guest wrote:So by address the PCIe card is mapped to do you mean the address obtained by reading the BAR register? and then we ioremap this addr on the CPU?
Also what happens if the PCIe periphral the CPU wants to talk to is another processor? Would it make a difference in the way the read/write happens?

Actually, it's any physical address that the processor has mapped to its PCIe root port. The BAR addresses are necessarily in that range. ioremap() is the function used in the Linux kernel to map such a physical address into a virtual address (pci_iomap(), actually). The address known by software is the latter.

As for CPUs talking with each other, it depends on whether one of them has the capability to behave as a peripheral. If not, Non-Transparent Bridging is the common solution, which was discussed briefly on http://xillybus.com/forum/viewtopic.php?f=2&t=88:
support
 
Posts: 802
Joined:

Re: Code example for packet transmission mentioned in PCIe b

Postby Guest »

hello Eli

There are multiple (more than 2) processors that are identical with same capabilities of being configured as RC or EP devices. My confusion is all will have same vendor and device id. So even if one of them is in RC mode and others in EP, how is possible to enumerate/find the devices with identical ids? Is there any alternate method to device/vendor id search?

Thanks
Guest
 

Re: Code example for packet transmission mentioned in PCIe b

Postby support »

Well, that's the same problem you have when there are several identical cards installed on a computer. For example, if you have several NICs in a computer, how do you make sure their networking setup is retained every time the system boots up?

One solution is to rely on the order of enumeration, which should be repeatable. A safer path is to find a way to identify each entity, based upon information available after enumeration has completed. A NIC defined by its MAC address, for example.

So processors or just devices, how to tell which is which is an implementation choice.
support
 
Posts: 802
Joined:


Return to General PCIe

cron