Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Ethernet Passthrough
#1
Some people have been interested in a guide on doing ethernet passthrough, so I thought I would write one here. 

First off you need to modify your Xen device tree that is loaded through U-Boot. Disable the Ethernet gem and enable Xen passthrough:

Code:
        gem1: ethernet@ff0c0000 {
            #stream-id-cells = <0x1>;
            compatible = "cdns,gem";
            interrupt-parent = <0x1>;
            interrupts = <0x0 0x4b 0x4>;
            reg = <0x0 0xff0c0000 0x1000>;
            clock-names = "pclk", "hclk", "tx_clk";
            clocks = <0x2 0x2 0x2>;
            #address-cells = <0x1>;
            #size-cells = <0x0>;

+            xen,passthrough = <1>;
+            status = "disabled";
        };

Then add the device as an mmu-master to the smmu in the same device tree:

Code:
              smmu0: smmu0@0xFD800000 {
                       compatible = "arm,mmu-500";
                       reg = <0x0 0xfd800000 0x20000>;
                       #global-interrupts = <1>;
                       interrupt-parent = <&gic>;
                       interrupts = <0 157 4>,
                               <0 157 4>, <0 157 4>, <0 157 4>, <0 157 4>,
                               <0 157 4>, <0 157 4>, <0 157 4>, <0 157 4>,
                               <0 157 4>, <0 157 4>, <0 157 4>, <0 157 4>,
                               <0 157 4>, <0 157 4>, <0 157 4>, <0 157 4>;

-                        mmu-masters = <&gem0 0x874 >;
+                        mmu-masters = <&gem0 0x874 &gem1 0x875 >;
               };

After that, you will need to modify the configuration file for the guest through which you are passing the Ethernet gem. You will need to define the following options:

dtdev - The absolute path of the device to passthrough in the device tree
device_tree - dom0 path to partial device tree to be passed to the guest
irqs - irq to be given to the guest
iomem = the physical pages to be passed in to the guest

Here are the values added to a configuration file for gem1 being passed through:

Code:
dtdev = [ "/amba/ethernet@ff0d0000" ]
device_tree = "/etc/xen/xen-partial.dtb"
irqs = [ 109 ]
iomem = [ "0xff0c0,1" ]
 
The last step is to create the partial device tree that the configuration file points to. This is used to let the guest know how to setup the passthrough device. Here is how to configure the file:
Code:
/dts-v1/;

/ {
    #address-cells = <0x2>;
    #size-cells = <0x1>;

    passthrough {
        compatible = "simple-bus";
        ranges;
        #address-cells = <0x2>;
        #size-cells = <0x1>;

        misc_clk {
            #clock-cells = <0x0>;
            clock-frequency = <0x17d7840>;
            compatible = "fixed-clock";
            linux,phandle = <0x2>;
            phandle = <0x2>;
        };

        ethernet@ff0c0000 {
            #stream-id-cells = <0x1>;
            compatible = "cdns,gem";
            reg = <0x0 0xff0c0000 0x1000>;
            interrupts = <0x0 0x4b 0x4>;
            clock-names = "pclk", "hclk", "tx_clk";
            clocks = <0x2 0x2 0x2>;
            #address-cells = <0x1>;
            #size-cells = <0x0>;
            local-mac-address = [00 0a 35 00 02 02];
            phy-handle = <0x1>;
            phy-mode = "rgmii-id";

            phy@0 {
                reg = <0x0>;
                max-speed = <0x64>;
                linux,phandle = <0x1>;
                phandle = <0x1>;
            };
        };
    };
};

Then generate the dtb using the following command:
Code:
dtc -I dts -O dtb -o xen-partial.dtb xen-partial.dts

Then when you start your guest, it should initialize gem1 and have exclusive access to the device.
Reply
#2
Robbie, do you know why the interrupt specified in the xen.dts is 0x4B (75) but the in the dom1.cfg it's set to 109? I know that on the first generation Zynq the actual IRQ number is 32 more than what's specified in the .dts file, but adding that offset only puts us at 107... still 2 shy of the 109.
Reply
#3
Robbie, do you know why both GEMs have to be added as MMU masters if we're only trying to pass GEM1 through to the guest?
Reply
#4
(09-17-2015, 12:46 PM)jarvis_roach Wrote: Robbie, do you know why both GEMs have to be added as MMU masters if we're only trying to pass GEM1 through to the guest?

I agree this is a good question that I'd like to understand also.

I also don't understand where the 0x874 and 0x875 values in the mmu-master property come from?

Thanks
John
Reply
#5
(04-06-2016, 07:32 PM)linnj Wrote:
(09-17-2015, 12:46 PM)jarvis_roach Wrote: Robbie, do you know why both GEMs have to be added as MMU masters if we're only trying to pass GEM1 through to the guest?

I agree this is a good question that I'd like to understand also.

I also don't understand where the 0x874 and 0x875 values in the mmu-master property come from?

Thanks
John

I found part of the answer in the h/w TRM, the 0x74 is the AXI Master ID of the GEM.  I'm still looking for the 8 in it.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)