Code example for packet transmission mentioned in PCIe blog

Comments and questions to the author of the "Down to the TLP" posts (Eli Billauer)

Code example for packet transmission mentioned in PCIe blog

Postby Guest » Mon Oct 01, 2012 11:10 am

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 » Mon Oct 01, 2012 11:17 am

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: 619
Joined: Tue Apr 24, 2012 3:46 pm

Re: Code example for packet transmission mentioned in PCIe b

Postby Guest » Mon Oct 01, 2012 11:28 am

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 » Mon Oct 01, 2012 11:41 am

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: 619
Joined: Tue Apr 24, 2012 3:46 pm

Re: Code example for packet transmission mentioned in PCIe b

Postby Guest » Mon Oct 01, 2012 1:39 pm

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 » Mon Oct 01, 2012 4:07 pm

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: 619
Joined: Tue Apr 24, 2012 3:46 pm

Re: Code example for packet transmission mentioned in PCIe b

Postby Guest » Wed Oct 03, 2012 11:35 am

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 » Wed Oct 03, 2012 11:51 am

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: 619
Joined: Tue Apr 24, 2012 3:46 pm


Return to General PCIe

cron