virtio: add virtio-over-PCI driver
Subsystems (6)
RFC v2 1/1 virtio: add virtio-over-PCI driver
This adds support to Linux for using virtio between two computers linked by a PCI interface. This allows the use of virtio_net to create a familiar, fast interface for communication. It should be possible to use other virtio devices in the future, but this has not been tested.
I have implemented guest support for the Freescale MPC8349EMDS board, which is capable of running in PCI agent mode (It acts like a PCI card, but is a complete computer system, running Linux). The driver is trivial to port to any MPC83xx system.
It was developed to work in a CompactPCI crate of computers, one of which is a standard x86 system (acting as the host) and many PowerPC systems (acting as guests).
I have only tested this driver with a single board in my system. The host is a 1066MHz Pentium3-M, and the guest is a 533MHz PowerPC. I am able achieve transfer rates of about 150 mbit host->guest and 350 mbit guest->host. A few tests showed that using an mtu of 4000 provided much better results than an mtu of 1500. Using an mtu of 64000 significantly dropped performance. The performance is equivalent to my PCINet driver for host->guest, and about 20% faster for guest->host transfers.
I have included a short document explaining what I think is the most complicated part of the driver: using the DMA engine to transfer data. I hope everything else is readily obvious from the code. Questions are welcome.
I will not be able to work on this full time for at least a few weeks, so I would appreciate actual review of this driver. Nitpicks are fine, I just won't be able to respond to them quickly.
RFCv1 -> RFCv2:
* fix major brokenness of host detach_buf()
* support VIRTIO_NET_F_CSUM
* support VIRTIO_NET_F_GSO
* support VIRTIO_NET_F_MRG_RXBUF
* rewrote DMA transfers to support merged rxbufs
* added a hack to fix the endianness of virtio_net's metadata
* lots more performance for guest->host transfers (~40MB/sec)
* updated documentation
* allocate 128 feature bits instead of 32
---
Yes, the commit message has too much information. This is an RFC after all. I fully expect to have to make changes. In fact, I posting this more to "get it out there" than anything else, since I have other tasks that need doing.
I'd appreciate a serious review of the design by the people who have been pressuring me to use virtio. I'm very happy to answer any questions you have.
Thanks to everyone who gave feedback for RFCv1!
Ira
Documentation/virtio-over-PCI.txt | 60 + arch/powerpc/boot/dts/mpc834x_mds.dts | 7 + drivers/virtio/Kconfig | 22 + drivers/virtio/Makefile | 2 + drivers/virtio/vop.h | 119 ++ drivers/virtio/vop_fsl.c | 2020 +++++++++++++++++++++++++++++++++ drivers/virtio/vop_host.c | 1071 +++++++++++++++++ drivers/virtio/vop_hw.h | 80 ++ 8 files changed, 3381 insertions(+), 0 deletions(-) create mode 100644 Documentation/virtio-over-PCI.txt create mode 100644 drivers/virtio/vop.h create mode 100644 drivers/virtio/vop_fsl.c create mode 100644 drivers/virtio/vop_host.c create mode 100644 drivers/virtio/vop_hw.h
Documentation/virtio-over-PCI.txt new file +60 -0
@@ -0,0 +1,60 @@ +The implementation of virtio-over-PCI was driven with the following goals: +* Avoid MMIO reads, try to use only MMIO writes +* Use the onboard DMA engine, for speed + +The implementation also borrows many of the details from the only other +implementation, virtio_ring. + +It succeeds in avoiding all MMIO reads on the critical paths. I did not +see any reason to avoid the use of MMIO reads during device probing, since +it is not a critical path. + +=== Avoiding MMIO reads === +To avoid MMIO reads, both the host and guest systems have a copy of the +descriptors. Both sides need to read the descriptors after they have been +written, but only the host system writes to them. This allows us to keep a +local copy for later use. + +=== Using the DMA engine === +This is the only truly complicated part of the system. Since this +implementation was designed for use with virtio_net, it may be biased +towards virtio_net's usage of the virtio interface. + +In merged rxbufs mode, the virtio_net driver provides a receive ring, which +it fills with empty PAGE_SIZE buffers. The DMA code sets up transfers +directly from the guest transmit queue to the empty packets in the host +receive queue. Data transfer in the other direction works in a similar +fashion. + +The guest (PowerPC) system keeps its own local set of descriptors, which are +filled by the virtio add_buf() call. Whenever this happens, the avail ring is +changed, and therefore we try to transfer data. + +The algorithm is essentially as follows: +1) Check for an available local or remote entry +2) Check that the other side has enough room for the packet +3) Transfer the chain, joining small packets and splitting large packets +4) Move the entries to the used rings, but do not update the used index +5) Schedule a DMA callback to happen when the transfer completes +6) Start the DMA transfer +7) When the DMA finishes, the callback updates the used indices and + triggers any necessary callbacks + +The algorithm can only handle chains that are to be coalesced together. It +puts all data sequentially into the PAGE_SIZE buffers exposed by the +receiving side, including both the virtio_net header and packet data. + +=== Startup Sequence === +There are currently problems in the startup sequence between the host and +guest drivers. The current scheme assumes that the guest is up and waiting +before the host is ready. I am having a very hard time coming up with a scheme +that is perfectly safe, where either side could win the race and be ready +first. + +Even harder is a situation where you would like to use the "network device" +from your bootloader to tftp a kernel, then boot Linux. In this case, +Linux has no knowledge of where the device descriptors were before it booted. +You'd need to stop and re-start the host driver to make sure it re-initializes +the new descriptor memory after Linux has booted. + +This is a definite "needs work" item.
arch/powerpc/boot/dts/mpc834x_mds.dts +7 -0
@@ -104,6 +104,13 @@ mode = "cpu"; }; + message-unit@8030 { + compatible = "fsl,mpc8349-mu"; + reg = <0x8030 0xd0>; + interrupts = <69 0x8>; + interrupt-parent = <&ipic>; + }; + dma@82a8 { #address-cells = <1>; #size-cells = <1>;
drivers/virtio/Kconfig +22 -0
@@ -33,3 +33,25 @@ config VIRTIO_BALLOON If unsure, say M. +config VIRTIO_OVER_PCI_HOST + tristate "Virtio-over-PCI Host support (EXPERIMENTAL)" + depends on PCI && EXPERIMENTAL + select VIRTIO + ---help--- + This driver provides the host support necessary for using virtio + over the PCI bus with a Freescale MPC8349EMDS evaluation board. + + If unsure, say N. + +config VIRTIO_OVER_PCI_FSL + tristate "Virtio-over-PCI Guest support (EXPERIMENTAL)" + depends on MPC834x_MDS && EXPERIMENTAL + select VIRTIO + select DMA_ENGINE + select FSL_DMA + ---help--- + This driver provides the guest support necessary for using virtio + over the PCI bus. + + If unsure, say N. +
drivers/virtio/Makefile +2 -0
@@ -2,3 +2,5 @@ obj-$(CONFIG_VIRTIO) += virtio.o obj-$(CONFIG_VIRTIO_RING) += virtio_ring.o obj-$(CONFIG_VIRTIO_PCI) += virtio_pci.o obj-$(CONFIG_VIRTIO_BALLOON) += virtio_balloon.o +obj-$(CONFIG_VIRTIO_OVER_PCI_HOST) += vop_host.o +obj-$(CONFIG_VIRTIO_OVER_PCI_FSL) += vop_fsl.o
drivers/virtio/vop.h new file +119 -0
119 lines not on this page · raw message
drivers/virtio/vop_fsl.c new file +2020 -0
2,020 lines not on this page · raw message
drivers/virtio/vop_host.c new file +1071 -0
758 lines not on this page · raw message
drivers/virtio/vop_hw.h new file +80 -0
80 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
1.5.4.3
Part of the diff is not shown here. View the raw message.
Quoted 4 lines · Ira Snyder
This adds support to Linux for using virtio between two computers linked by a PCI interface. This allows the use of
virtio_netto create a familiar, fast interface for communication. It should be possible to use other virtio devices in the future, but this has not been tested.
Wonderful, I like it a lot!
One major aspect that I hope can be improved is the layering of the driver to make it easier to reuse parts for other hardware implementations and also for sharing code between the two sides. Most of my comments below are about this.
A better split I can imagine would be:
1. of_device hardware specific probing, and creation of virtqueues
2. pci hardware specific probing, and detection of virtqueues
3. library with common code, hardware independent
4. library with common code, hardware specific but used by both of_device and pci.
5. interface to virtio-net on top of that (symmetric)
drivers/virtio/vop.h line 37
Quoted 11 lines
drivers/virtio/vop.h new file +11
-0+/* Virtio-over-PCI descriptors: 12 bytes. These can chain together via "next" */ +struct vop_desc { +/* Address (host physical) */ +__le32 addr; +/* Length (bytes) */ +__le32 len; +/* Flags */ +__le16 flags; +/* Chaining for descriptors */ +__le16 next; +} __attribute__((packed));
I would drop the "packed" attribute in the structure definitions. It would imply that only byte accesses are allowed on these data structures, because the attribute invalidates any assumptions about alignment. None of your structures require padding, so the attribute does not have any positive effect either.
drivers/virtio/vop_fsl.c line 27
Quoted 2 lines
drivers/virtio/vop_fsl.c new file +2
-0+/* MPC8349EMDS specific get_immrbase() */ +#include <sysdev/fsl_soc.h>
Do you really need get_immrbase? I would expect that you can find all the registers you need in the device tree, or exported from other low-level drivers per subsystem.
immrbase is a concept from the time before our device trees.
Quoted 18 lines
drivers/virtio/vop_fsl.c new file +18
-0+/* +* These are internal use only versions of the structures that +* are exported over PCI by this driver +* +* They are used internally to keep track of the PowerPC queues so that +* we don't have to keep flipping endianness all the time +*/ +struct vop_loc_desc { +u32 addr; +u32 len; +u16 flags; +u16 next; +}; + +struct vop_loc_avail { +u16 index; +u16 ring[VOP_RING_SIZE ]; +};
drivers/virtio/vop_fsl.c line 59
Quoted 10 lines
drivers/virtio/vop_fsl.c new file +10
-0+ +struct vop_loc_used_elem { +u32 id; +u32 len; +}; + +struct vop_loc_used { +u16 index; +struct vop_loc_used_elem ring[VOP_RING_SIZE ]; +};
Are you worried about the overhead of having to do byte flips, or the code complexity? I would guess that the overhead is near zero, but I'm not sure about the source code complexity. Generally, I'd expect that you'd be better off just using the wire-level data structures directly.
Quoted 41 lines
drivers/virtio/vop_fsl.c new file +41
-0+/* +* DMA Resolver state information +*/ +struct vop_dma_info { +struct dma_chan *chan; + +/* The currently processing avail entry */ +u16 loc_avail; +u16 rem_avail; + +/* The currently processing used entries */ +u16 loc_used; +u16 rem_used; +}; + +struct vop_vq { + +/* The actual virtqueue itself */ +struct virtqueue vq; +struct device *dev; + +/* The host ring address */ +struct vop_host_ring __iomem *host; + +/* The guest ring address */ +struct vop_guest_ring *guest; + +/* Our own memory descriptors */ +struct vop_loc_desc desc[VOP_RING_SIZE ]; +struct vop_loc_avail avail; +struct vop_loc_used used; +unsigned int flags; + +/* Data tokens from add_buf() */ +void *data[VOP_RING_SIZE ]; + +unsigned int num_free;/* number of free descriptors in desc */ +unsigned int free_head;/* start of the free descriptors in desc */ +unsigned int num_added;/* number of entries added to desc */ + +u16 loc_last_used;/* the last local used entry processed */
drivers/virtio/vop_fsl.c line 111
Quoted 10 lines
drivers/virtio/vop_fsl.c new file +10
-0+u16 rem_last_used;/* the current value of remote used_idx */ + +/* DMA resolver state */ +struct vop_dma_info dma; +struct work_struct work; +int (*resolve)(struct vop_vq *vq); + +void __iomem *immr; +int kick_val; +};
This data structure mixes generic information with fsl-834x specific members. I think you should try to split this better into a common part (also common for host and guest) to allow sharing the code across other low-level implementations:
struct vop_vq {
struct virtqueue vq;
struct vop_host_ring __iomem *host;
struct vop_guest_ring *guest;
...
};and in another file:
struct fsl834x_vq {
struct vop_vq;
struct fsl834x_vop_regs __iomem *regs; /* instead of immr */
}If you split the structures this way, the abstraction should come naturally.
Quoted 30 lines
drivers/virtio/vop_fsl.c new file +30
-0+/* +* This represents a virtio_device for our driver. It follows the memory +* layout shown above. It has pointers to all of the host and guest memory +* areas that we need to access +*/ +struct vop_vdev { + +/* The specific virtio device (console, net, blk) */ +struct virtio_device vdev; + +#define VOP_DEVICE_REGISTERED 1 +int status; + +/* Start address of local and remote memory */ +void *loc; +void __iomem *rem; + +/* +* These are the status, feature, and configuration information +* for this virtio device. They are exposed in our memory block +* starting at offset 0. +*/ +struct vop_status __iomem *host_status; + +/* +* These are the status, feature, and configuration information +* for the guest virtio device. They are exposed in the guest +* memory block starting at offset 0. +*/ +struct vop_status *guest_status;
drivers/virtio/vop_fsl.c line 155
Quoted 10 lines
drivers/virtio/vop_fsl.c new file +10
-0+ +/* +* These are the virtqueues for the virtio driver running this +* device to use. The host portions are exposed in our memory block +* starting at offset 1024. The exposed areas are aligned to 1024 byte +* boundaries, so they appear at offets 1024, 2048, and 3072 +* respectively. +*/ +struct vop_vq virtqueues[3 ]; +};
Unfortunately, that structure layout implies an extra pointer level here:
struct vop_vq *virtqueues[3];
I also wonder if the number of virtqueues should be variable here.
Quoted 18 lines
drivers/virtio/vop_fsl.c new file +18
-0+struct vop_dev { + +struct of_device *op; +struct device *dev; + +/* Reset and start */ +struct mutex mutex; +struct work_struct reset_work; +struct work_struct start_work; + +int irq; + +/* Our board control registers */ +void __iomem *immr; + +/* The guest memory, exposed at PCI BAR1 */ +#define VOP_GUEST_MEM_SIZE 16384 +void *guest_mem;
drivers/virtio/vop_fsl.c line 186
Quoted 10 lines
drivers/virtio/vop_fsl.c new file +10
-0+dma_addr_t guest_mem_addr; + +/* Host memory, given to us by host in OMR0 */ +#define VOP_HOST_MEM_SIZE 16384 +void __iomem *host_mem; + +/* The virtio devices */ +struct vop_vdev devices[4 ]; +struct dma_chan *chan; +};
This one again is hardware specific, right? If so, it should go together with what I call fsl834x_vq above.
Quoted 23 lines
drivers/virtio/vop_fsl.c new file +23
-0+/*----------------------------------------------------------------------------*/ +/* Local descriptor ring access helpers */ +/*----------------------------------------------------------------------------*/ + +static void vop_set_desc_addr (struct vop_vq *vq,unsigned int idx,u32 addr) +{ + vq->desc[idx].addr = addr; +} + +static void vop_set_desc_len (struct vop_vq *vq,unsigned int idx,u32 len) +{ + vq->desc[idx].len = len; +} + +static void vop_set_desc_flags (struct vop_vq *vq,unsigned int idx,u16 flags) +{ + vq->desc[idx].flags = flags; +} + +static void vop_set_desc_next (struct vop_vq *vq,unsigned int idx,u16 next) +{ + vq->desc[idx].next = next; +}
drivers/virtio/vop_fsl.c line 278
Quoted 10 lines
drivers/virtio/vop_fsl.c new file +10
-0+ +static u16 vop_get_desc_flags (struct vop_vq *vq,unsigned int idx) +{ +return vq->desc[idx].flags; +} + +static u16 vop_get_desc_next (struct vop_vq *vq,unsigned int idx) +{ +return vq->desc[idx].next; +}
I don't quite get the point in these accessors. Calling one of these functions would be longer than open-coding the content.
Quoted 6 lines
drivers/virtio/vop_fsl.c new file +6
-0+/*----------------------------------------------------------------------------*/ +/* Scatterlist DMA helpers */ +/*----------------------------------------------------------------------------*/ + +/* +* This function abuses some of the scatterlist code and implements
drivers/virtio/vop_fsl.c line 429
Quoted 10 lines
drivers/virtio/vop_fsl.c new file +10
-0+* dma_map_sg() in such a way that we don't need to keep the scatterlist +* around in order to unmap it. +* +* It is also designed to never merge scatterlist entries, which is +* never what we want for virtio. +* +* When it is time to unmap the buffer, you can use dma_unmap_single() to +* unmap each entry in the chain. Get the address, length, and direction +* from the descriptors! (keep a local copy for speed) +*/
Why is that an advantage over dma_unmap_sg?
Quoted 14 lines
drivers/virtio/vop_fsl.c new file +14
-0+static int vop_dma_map_sg (struct device *dev,struct scatterlist sg[], +unsigned int out,unsigned int in) +{ +dma_addr_t addr; +enum dma_data_direction dir; +struct scatterlist *start; +unsigned int i, failure; + + start = sg; + +for (i =0 ; i < out + in; i++) { + +/* Check for scatterlist chaining abuse */ +BUG_ON (sg ==NULL );
drivers/virtio/vop_fsl.c line 453
Quoted 10 lines
drivers/virtio/vop_fsl.c new file +10
-0+ + dir = (i < out) ?DMA_TO_DEVICE :DMA_FROM_DEVICE ; + addr =dma_map_single (dev,sg_virt (sg), sg->length, dir); + +if (dma_mapping_error (dev, addr)) + goto unwind; + +sg_dma_address (sg) = addr; + sg =sg_next (sg); + }
I believe this kind of loop can be simplified using for_each_sg().
drivers/virtio/vop_fsl.c line 1910
Quoted 7 lines
drivers/virtio/vop_fsl.c new file +7
-0+/* Remap IMMR */ + priv->immr =ioremap (get_immrbase (),0x100000 ); +if (!priv->immr) { +dev_err (&op->dev,"Unable to remap IMMR registers\n" ); + ret = -ENOMEM ; + goto out_dma_release_channel; + }
As mentioned above, this should be something like an of_iomap(op, ...)
Quoted 20 lines
drivers/virtio/vop_host.c new file +20
-0+struct vop_vq { + +/* The actual virtqueue itself */ +struct virtqueue vq; + +struct device *dev; + +/* The host ring address */ +struct vop_host_ring *host; + +/* The guest ring address */ +struct vop_guest_ring __iomem *guest; + +/* Local copy of the descriptors for fast access */ +struct vop_loc_desc desc[VOP_RING_SIZE ]; + +/* The data token from add_buf() */ +void *data[VOP_RING_SIZE ]; + +unsigned int num_free;
drivers/virtio/vop_host.c line 64
Quoted 10 lines
drivers/virtio/vop_host.c new file +10
-0+unsigned int free_head; +unsigned int num_added; + +u16 avail_idx; +u16 last_used_idx; + +/* The doorbell to kick() */ +unsigned int kick_val; +void __iomem *immr; +};
I find it very confusing to have almost-identical data structures by the same name in two files. Obviously, you have a lot of common code between the two sides, but rather than making the implementation files *look* similar, it would be better to focus on splitting out the shared code into a common file and keep the different/duplicated code small.
drivers/virtio/vop_host.c line 705
Quoted 13 lines
drivers/virtio/vop_host.c new file +13
-0+switch (index) { +case 0 :/* x86 recv virtqueue -- ppc xmit virtqueue */ + vq->guest = vdev->rem +1024 ; + vq->host = vdev->loc +1024 ; +break ; +case 1 :/* x86 xmit virtqueue -- ppc recv virtqueue */ + vq->guest = vdev->rem +2048 ; + vq->host = vdev->loc +2048 ; +break ; +default : +dev_err (vq->dev,"unknown virtqueue %d\n" , index); +return ERR_PTR (-ENODEV ); + }
I'd avoid making assumptions or comments about the architectures. Rather than "x86" and "ppc", I'd write "local" and "remote".
Arnd <><
Quoted 5 lines · Arnd Bergmann
drivers/virtio/vop.h line 30
Quoted 4 lines · Ira Snyder
drivers/virtio/vop.h new file +4
-0+/* Virtio-over-PCI descriptors: 12 bytes. These can chain together via "next" */ +struct vop_desc { +/* Address (host physical) */ +__le32 addr;
^^^^
Only 32-bit? Is this future-proof?
Quoted 23 lines
drivers/virtio/vop.h line 37
Quoted 7 lines
drivers/virtio/vop.h new file +7
-0+/* Length (bytes) */ +__le32 len; +/* Flags */ +__le16 flags; +/* Chaining for descriptors */ +__le16 next; +} __attribute__((packed));I would drop the "packed" attribute in the structure definitions. It would imply that only byte accesses are allowed on these data structures, because the attribute invalidates any assumptions about alignment. None of your structures require padding, so the attribute does not have any positive effect either.
drivers/virtio/vop_fsl.c line 27
Quoted 2 lines
drivers/virtio/vop_fsl.c new file +2
-0+/* MPC8349EMDS specific get_immrbase() */ +#include <sysdev/fsl_soc.h> Do you really need
get_immrbase? I would expect that you can find all the registers you need in the device tree, or exported from other low-level drivers per subsystem.immrbase is a concept from the time before our device trees.
Quoted 9 lines
drivers/virtio/vop_fsl.c line 40
Quoted 9 lines
drivers/virtio/vop_fsl.c new file +9
-0+/* +* These are internal use only versions of the structures that +* are exported over PCI by this driver +* +* They are used internally to keep track of the PowerPC queues so that +* we don't have to keep flipping endianness all the time +*/ +struct vop_loc_desc { +u32 addr;
^^^
Same here.
With kind regards,
Geert Uytterhoeven
Software Architect
Sony Techsoft Centre Europe
The Corporate Village · Da Vincilaan 7-D1 · B-1935 Zaventem · Belgium
Phone: +32 (0)2 700 8453 Fax: +32 (0)2 700 8622 E-mail: [email protected] Internet: http://www.sony-europe.com/
A division of Sony Europe (Belgium) N.V. VAT BE 0413.825.160 · RPR Brussels Fortis · BIC GEBABEBB · IBAN BE41293037680010
Quoted 9 lines · Geert Uytterhoeven
Quoted 5 lines · Arnd Bergmann
drivers/virtio/vop.h line 30
Quoted 4 lines · Ira Snyder
drivers/virtio/vop.h new file +4
-0+/* Virtio-over-PCI descriptors: 12 bytes. These can chain together via "next" */ +struct vop_desc { +/* Address (host physical) */ +__le32 addr;^^^^Only 32-bit? Is this future-proof?
Probably not. If I use __le64 instead, how do I write 64 bytes over the PCI bus? There isn't an iowrite64()/ioread64() anywhere in Linux.
Thanks,
Ira
Quoted 13 lines · Arnd Bergmann
Quoted 4 lines · Ira Snyder
This adds support to Linux for using virtio between two computers linked by a PCI interface. This allows the use of
virtio_netto create a familiar, fast interface for communication. It should be possible to use other virtio devices in the future, but this has not been tested.Wonderful, I like it a lot!
One major aspect that I hope can be improved is the layering of the driver to make it easier to reuse parts for other hardware implementations and also for sharing code between the two sides. Most of my comments below are about this.
Quoted 9 lines
A better split I can imagine would be:
1.
of_devicehardware specific probing, and creation of virtqueues
2. pci hardware specific probing, and detection of virtqueues
3. library with common code, hardware independent
4. library with common code, hardware specific but used by bothof_deviceand pci.
5. interface to virtio-net on top of that (symmetric)
I think so too. I was just getting something working, and thought it would be better to have it "out there" rather than be working on it forever. I'll try to break things up as I have time.
For the "libraries", would you suggest breaking things into seperate code files, and using EXPORT_SYMBOL_GPL()? I'm not very familiar with doing that, I've mostly been writing code within the existing device driver frameworks. Or do I need export symbol at all? I'm not sure...
Quoted 9 lines
Quoted 9 lines
drivers/virtio/vop.h new file +9
-0+/* Virtio-over-PCI descriptors: 12 bytes. These can chain together via "next" */ +struct vop_desc { +/* Address (host physical) */ +__le32 addr; +/* Length (bytes) */ +__le32 len; +/* Flags */ +__le16 flags; +/* Chaining for descriptors */
Quoted 9 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+ __le16 next; +} __attribute__((packed));I would drop the "packed" attribute in the structure definitions. It would imply that only byte accesses are allowed on these data structures, because the attribute invalidates any assumptions about alignment. None of your structures require padding, so the attribute does not have any positive effect either.
I always thought you were supposed to use packed for data structures that are external to the system. I purposely designed the structures so they wouldn't need padding.
I'll drop it and check for any problems.
Quoted 9 lines
drivers/virtio/vop_fsl.c line 27
Quoted 2 lines
drivers/virtio/vop_fsl.c new file +2
-0+/* MPC8349EMDS specific get_immrbase() */ +#include <sysdev/fsl_soc.h> Do you really need
get_immrbase? I would expect that you can find all the registers you need in the device tree, or exported from other low-level drivers per subsystem.immrbase is a concept from the time before our device trees.
I mostly don't need it. In fact, the only place I'm using registers not specific to the messaging unit is in the probe routine, where I setup the 1GB window into host memory and setting up access to the guest memory on the PCI bus.
Now, I wouldn't need to access these registers at all if the bootloader could handle it. I just don't know if it is possible to have Linux not use some memory that the bootloader allocated, other than with the mem=XXX trick, which I'm sure wouldn't be acceptable. I've just used regular RAM so this is portable to my custom board (mpc8349emds based) and a regular mpc8349emds. I didn't want to change anything board specific.
I would love to have the bootloader allocate (or reserve somewhere in the memory map) 16K of RAM, and not be required to allocate it with dma_alloc_coherent(). It would save me plenty of headaches.
Quoted 26 lines
Quoted 26 lines
drivers/virtio/vop_fsl.c new file +26
-0+/* +* These are internal use only versions of the structures that +* are exported over PCI by this driver +* +* They are used internally to keep track of the PowerPC queues so that +* we don't have to keep flipping endianness all the time +*/ +struct vop_loc_desc { +u32 addr; +u32 len; +u16 flags; +u16 next; +}; + +struct vop_loc_avail { +u16 index; +u16 ring[VOP_RING_SIZE ]; +}; + +struct vop_loc_used_elem { +u32 id; +u32 len; +}; + +struct vop_loc_used { +u16 index;
Quoted 9 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+ struct vop_loc_used_elem ring[VOP_RING_SIZE]; +};Are you worried about the overhead of having to do byte flips, or the code complexity? I would guess that the overhead is near zero, but I'm not sure about the source code complexity. Generally, I'd expect that you'd be better off just using the wire-level data structures directly.
Code complexity only. Also, it was easier to write 80-char lines with something like:
vop_get_desc(vq, idx, &desc);
if (desc.flags & VOP_DESC_F_NEXT) {
/* do something */
}Instead of:
if (le16_to_cpu(vq->desc[idx].flags) & VOP_DESC_F_NEXT) {
/* do something */
}Plus, I didn't have to remember how many bits were in each field. I just thought it made everything simpler to understand. Suggestions?
Quoted 66 lines
Quoted 41 lines
drivers/virtio/vop_fsl.c new file +41
-0+/* +* DMA Resolver state information +*/ +struct vop_dma_info { +struct dma_chan *chan; + +/* The currently processing avail entry */ +u16 loc_avail; +u16 rem_avail; + +/* The currently processing used entries */ +u16 loc_used; +u16 rem_used; +}; + +struct vop_vq { + +/* The actual virtqueue itself */ +struct virtqueue vq; +struct device *dev; + +/* The host ring address */ +struct vop_host_ring __iomem *host; + +/* The guest ring address */ +struct vop_guest_ring *guest; + +/* Our own memory descriptors */ +struct vop_loc_desc desc[VOP_RING_SIZE ]; +struct vop_loc_avail avail; +struct vop_loc_used used; +unsigned int flags; + +/* Data tokens from add_buf() */ +void *data[VOP_RING_SIZE ]; + +unsigned int num_free;/* number of free descriptors in desc */ +unsigned int free_head;/* start of the free descriptors in desc */ +unsigned int num_added;/* number of entries added to desc */ + +u16 loc_last_used;/* the last local used entry processed */ drivers/virtio/vop_fsl.c line 111
Quoted 10 lines
drivers/virtio/vop_fsl.c new file +10
-0+u16 rem_last_used;/* the current value of remote used_idx */ + +/* DMA resolver state */ +struct vop_dma_info dma; +struct work_struct work; +int (*resolve)(struct vop_vq *vq); + +void __iomem *immr; +int kick_val; +};This data structure mixes generic information with fsl-834x specific members. I think you should try to split this better into a common part (also common for host and guest) to allow sharing the code across other low-level implementations:
struct vop_vq { struct virtqueue vq; struct vop_host_ring __iomem *host; struct vop_guest_ring *guest; ... };and in another file:
Quoted 8 lines
struct fsl834x_vq { struct vop_vq; struct fsl834x_vop_regs __iomem *regs; /* instead of immr */ }If you split the structures this way, the abstraction should come naturally.
Looks good to me. I'll work towards this in my next version.
Quoted 43 lines
Quoted 30 lines
drivers/virtio/vop_fsl.c new file +30
-0+/* +* This represents a virtio_device for our driver. It follows the memory +* layout shown above. It has pointers to all of the host and guest memory +* areas that we need to access +*/ +struct vop_vdev { + +/* The specific virtio device (console, net, blk) */ +struct virtio_device vdev; + +#define VOP_DEVICE_REGISTERED 1 +int status; + +/* Start address of local and remote memory */ +void *loc; +void __iomem *rem; + +/* +* These are the status, feature, and configuration information +* for this virtio device. They are exposed in our memory block +* starting at offset 0. +*/ +struct vop_status __iomem *host_status; + +/* +* These are the status, feature, and configuration information +* for the guest virtio device. They are exposed in the guest +* memory block starting at offset 0. +*/ +struct vop_status *guest_status;drivers/virtio/vop_fsl.c line 155
Quoted 10 lines
drivers/virtio/vop_fsl.c new file +10
-0+ +/* +* These are the virtqueues for the virtio driver running this +* device to use. The host portions are exposed in our memory block +* starting at offset 1024. The exposed areas are aligned to 1024 byte +* boundaries, so they appear at offets 1024, 2048, and 3072 +* respectively. +*/ +struct vop_vq virtqueues[3 ]; +};Unfortunately, that structure layout implies an extra pointer level here:
Quoted 4 lines
struct vop_vq *virtqueues[3];I also wonder if the number of virtqueues should be variable here.
I used 3 so they would would align to 1024 byte boundaries within a 4K page. Then the layout was 16K on the bus, each 4K page is a single virtio-device, and each 1K block is a single virtqueue. The first 1K is for virtio-device status and feature bits, etc.
Packing them differently isn't a problem. It was just easier to code because setting up a window with the correct size is so platform specific.
Quoted 23 lines
Quoted 23 lines
drivers/virtio/vop_fsl.c new file +23
-0+struct vop_dev { + +struct of_device *op; +struct device *dev; + +/* Reset and start */ +struct mutex mutex; +struct work_struct reset_work; +struct work_struct start_work; + +int irq; + +/* Our board control registers */ +void __iomem *immr; + +/* The guest memory, exposed at PCI BAR1 */ +#define VOP_GUEST_MEM_SIZE 16384 +void *guest_mem; +dma_addr_t guest_mem_addr; + +/* Host memory, given to us by host in OMR0 */ +#define VOP_HOST_MEM_SIZE 16384 +void __iomem *host_mem;
Quoted 9 lines
drivers/virtio/vop_fsl.c line 186
Quoted 5 lines
drivers/virtio/vop_fsl.c new file +5
-0+ +/* The virtio devices */ +struct vop_vdev devices[4 ]; +struct dma_chan *chan; +};This one again is hardware specific, right? If so, it should go together with what I call
fsl834x_vqabove.
Yeah. It is the per-device private data, setup in the probe() routine. Some of the data isn't needed in each virtqueue, so I left it seperate.
Quoted 28 lines
Quoted 28 lines
drivers/virtio/vop_fsl.c new file +28
-0+/*----------------------------------------------------------------------------*/ +/* Local descriptor ring access helpers */ +/*----------------------------------------------------------------------------*/ + +static void vop_set_desc_addr (struct vop_vq *vq,unsigned int idx,u32 addr) +{ + vq->desc[idx].addr = addr; +} + +static void vop_set_desc_len (struct vop_vq *vq,unsigned int idx,u32 len) +{ + vq->desc[idx].len = len; +} + +static void vop_set_desc_flags (struct vop_vq *vq,unsigned int idx,u16 flags) +{ + vq->desc[idx].flags = flags; +} + +static void vop_set_desc_next (struct vop_vq *vq,unsigned int idx,u16 next) +{ + vq->desc[idx].next = next; +} + +static u16 vop_get_desc_flags (struct vop_vq *vq,unsigned int idx) +{ +return vq->desc[idx].flags; +}
Quoted 9 lines
drivers/virtio/vop_fsl.c line 278
Quoted 5 lines
drivers/virtio/vop_fsl.c new file +5
-0+ +static u16 vop_get_desc_next (struct vop_vq *vq,unsigned int idx) +{ +return vq->desc[idx].next; +}I don't quite get the point in these accessors. Calling one of these functions would be longer than open-coding the content.
They're leftovers from the host code. I'll get rid of them. It would be even better if I just returned pointers into the vq->desc array rather than copying the descriptors out of them.
Quoted 10 lines
Quoted 10 lines
drivers/virtio/vop_fsl.c new file +10
-0+/*----------------------------------------------------------------------------*/ +/* Scatterlist DMA helpers */ +/*----------------------------------------------------------------------------*/ + +/* +* This function abuses some of the scatterlist code and implements +* dma_map_sg() in such a way that we don't need to keep the scatterlist +* around in order to unmap it. +* +* It is also designed to never merge scatterlist entries, which is
Quoted 9 lines
Quoted 6 lines
+ * never what we want for virtio.
+ *
+ * When it is time to unmap the buffer, you can usedma_unmap_single()to
+ * unmap each entry in the chain. Get the address, length, and direction
+ * from the descriptors! (keep a local copy for speed)
+ */Why is that an advantage over
dma_unmap_sg?
When running dma_map_sg(), the scatterlist code is allowed to alter the scatterlist to store data it needs for dma_unmap_sg(), along with merging adjacent buffers, etc.
I don't want any of that behavior. The generic virtio code does not handle merging of buffers.
Also, all of the generic virtio code allocates its scatterlists on the stack. This means I cannot save the pointers between add_buf() and get_buf(). If I used dma_map_sg(), I'd have to allocate memory to copy the scatterlist, map it, and save the pointer. Later, retrieve the pointer, unmap it, and free the memory.
This is simpler than all of that.
Quoted 18 lines
Quoted 18 lines
drivers/virtio/vop_fsl.c new file +18
-0+static int vop_dma_map_sg (struct device *dev,struct scatterlist sg[], +unsigned int out,unsigned int in) +{ +dma_addr_t addr; +enum dma_data_direction dir; +struct scatterlist *start; +unsigned int i, failure; + + start = sg; + +for (i =0 ; i < out + in; i++) { + +/* Check for scatterlist chaining abuse */ +BUG_ON (sg ==NULL ); + + dir = (i < out) ?DMA_TO_DEVICE :DMA_FROM_DEVICE ; + addr =dma_map_single (dev,sg_virt (sg), sg->length, dir); +
Quoted 10 lines
drivers/virtio/vop_fsl.c line 453
Quoted 6 lines
drivers/virtio/vop_fsl.c new file +6
-0+if (dma_mapping_error (dev, addr)) + goto unwind; + +sg_dma_address (sg) = addr; + sg =sg_next (sg); + }I believe this kind of loop can be simplified using
for_each_sg().
Yep, you're right. The scatterlists that the virtio_net driver sent used to be improperly terminated (they ended early, according to the scatterlist chaining code). This caused me some null pointer oopses. I submitted a patch to fix virtio_net, so I can use for_each_sg() now.
I'll make the change for my next version.
Quoted 10 lines
drivers/virtio/vop_fsl.c line 1910
Quoted 7 lines
drivers/virtio/vop_fsl.c new file +7
-0+/* Remap IMMR */ + priv->immr =ioremap (get_immrbase (),0x100000 ); +if (!priv->immr) { +dev_err (&op->dev,"Unable to remap IMMR registers\n" ); + ret = -ENOMEM ; + goto out_dma_release_channel; + }As mentioned above, this should be something like an
of_iomap(op, ...)
Yep. See my comments above.
Quoted 28 lines
Quoted 28 lines
drivers/virtio/vop_host.c new file +28
-0+struct vop_vq { + +/* The actual virtqueue itself */ +struct virtqueue vq; + +struct device *dev; + +/* The host ring address */ +struct vop_host_ring *host; + +/* The guest ring address */ +struct vop_guest_ring __iomem *guest; + +/* Local copy of the descriptors for fast access */ +struct vop_loc_desc desc[VOP_RING_SIZE ]; + +/* The data token from add_buf() */ +void *data[VOP_RING_SIZE ]; + +unsigned int num_free; +unsigned int free_head; +unsigned int num_added; + +u16 avail_idx; +u16 last_used_idx; + +/* The doorbell to kick() */ +unsigned int kick_val;
Quoted 9 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+ void __iomem *immr; +};I find it very confusing to have almost-identical data structures by the same name in two files. Obviously, you have a lot of common code between the two sides, but rather than making the implementation files *look* similar, it would be better to focus on splitting out the shared code into a common file and keep the different/duplicated code small.
I kept the names the same because they served the same purpose on both sides. When the sides use common code, they'll mostly go away.
Quoted 8 lines
Quoted 8 lines
drivers/virtio/vop_host.c new file +8
-0+switch (index) { +case 0 :/* x86 recv virtqueue -- ppc xmit virtqueue */ + vq->guest = vdev->rem +1024 ; + vq->host = vdev->loc +1024 ; +break ; +case 1 :/* x86 xmit virtqueue -- ppc recv virtqueue */ + vq->guest = vdev->rem +2048 ; + vq->host = vdev->loc +2048 ;
Quoted 9 lines
drivers/virtio/vop_host.c line 705
Quoted 5 lines
drivers/virtio/vop_host.c new file +5
-0+break ; +default : +dev_err (vq->dev,"unknown virtqueue %d\n" , index); +return ERR_PTR (-ENODEV ); + }I'd avoid making assumptions or comments about the architectures. Rather than "x86" and "ppc", I'd write "local" and "remote".
Yep, just artifacts of my design here. I'll change it.
Thanks for the review. I really appreciate it.
Ira
Quoted 5 lines · Ira Snyder
On Thu, Feb 26, 2009 at 05:15:27PM +0100, Arnd Bergmann wrote:
I think so too. I was just getting something working, and thought it would be better to have it "out there" rather than be working on it forever. I'll try to break things up as I have time.
Ok, perfect!
Quoted 4 lines
For the "libraries", would you suggest breaking things into seperate code files, and using
EXPORT_SYMBOL_GPL()? I'm not very familiar with doing that, I've mostly been writing code within the existing device driver frameworks. Or do I need export symbol at all? I'm not sure...
You have both options. When you list each file as a separate module in the Makefile, you use EXPORT_SYMBOL_GPL to mark functions that get called by dependent modules, but this will work only in one way.
You can also link multiple files together into one module, although it is less common to link a single source file into multiple modules.
Quoted 3 lines
I always thought you were supposed to use packed for data structures that are external to the system. I purposely designed the structures so they wouldn't need padding.
That would only make sense for structures that are explicitly unaligned, like a register layout using
struct my_registers {
__le16 first;
__le32 second __attribute__((packed));
__le16 third;
};Even here, I'd recommend listing the individual members as packed rather than the entire struct. Obviously if you layout the members in a sane way, you don't need either.
Quoted 4 lines
I mostly don't need it. In fact, the only place I'm using registers not specific to the messaging unit is in the probe routine, where I setup the 1GB window into host memory and setting up access to the guest memory on the PCI bus.
You could add the registers you need for this to the "reg" property of your device, to be mapped with of_iomap.
If the registers for setting up this window don't logically fit into the same device as the one you already use, the cleanest solution would be to have another device just for this and then make a function call into that driver to set up the window.
Quoted 11 lines
Now, I wouldn't need to access these registers at all if the bootloader could handle it. I just don't know if it is possible to have Linux not use some memory that the bootloader allocated, other than with the mem=XXX trick, which I'm sure wouldn't be acceptable. I've just used regular RAM so this is portable to my custom board (mpc8349emds based) and a regular mpc8349emds. I didn't want to change anything board specific.
I would love to have the bootloader allocate (or reserve somewhere in the memory map) 16K of RAM, and not be required to allocate it with
dma_alloc_coherent(). It would save me plenty of headaches.
I believe you can do that through the "memory" devices in the device tree, by leaving out a small part of the description of main memory, at putting it into the "reg" property of your own device.
Quoted 8 lines
Code complexity only. Also, it was easier to write 80-char lines with something like:
vop_get_desc(vq, idx, &desc);if (desc.flags & VOP_DESC_F_NEXT) { /* do something */ }
Quoted 7 lines
Instead of:
if (le16_to_cpu(vq->desc[idx].flags) & VOP_DESC_F_NEXT) { /* do something */ }Plus, I didn't have to remember how many bits were in each field. I just thought it made everything simpler to understand. Suggestions?
hmm, in this particular case, you could change the definition of VOP_DESC_F_NEXT to
#define VOP_DESC_F_NEXT cpu_to_le16(1)
and then do the code as the even simpler (source and object code wise)
if (vq->desc[idx].flags) & VOP_DESC_F_NEXT)
I'm not sure if you can do something along these lines for the other cases as well though.
Quoted 8 lines
I used 3 so they would would align to 1024 byte boundaries within a 4K page. Then the layout was 16K on the bus, each 4K page is a single virtio-device, and each 1K block is a single virtqueue. The first 1K is for virtio-device status and feature bits, etc.
Packing them differently isn't a problem. It was just easier to code because setting up a window with the correct size is so platform specific.
Ok. I guess the important question is what part of the code makes this decision. Ideally, the virtio-net glue would instantiate the device with the right number of queues.
Quoted 23 lines
Quoted 13 lines
Quoted 4 lines
+/*
+ * This function abuses some of the scatterlist code and implements
+ *dma_map_sg()in such a way that we don't need to keep the scatterlist
+ * around in order to unmap it.Quoted 8 lines
+ *
+ * It is also designed to never merge scatterlist entries, which is
+ * never what we want for virtio.
+ *
+ * When it is time to unmap the buffer, you can usedma_unmap_single()to
+ * unmap each entry in the chain. Get the address, length, and direction
+ * from the descriptors! (keep a local copy for speed)
+ */Quoted 2 lines
Why is that an advantage over
dma_unmap_sg?When running
dma_map_sg(), the scatterlist code is allowed to alter the scatterlist to store data it needs fordma_unmap_sg(), along with merging adjacent buffers, etc.I don't want any of that behavior. The generic virtio code does not handle merging of buffers.
Quoted 7 lines
Also, all of the generic virtio code allocates its scatterlists on the stack. This means I cannot save the pointers between
add_buf()andget_buf(). If I useddma_map_sg(), I'd have to allocate memory to copy the scatterlist, map it, and save the pointer. Later, retrieve the pointer, unmap it, and free the memory.This is simpler than all of that.
Not sure if I'm following, but you seem to have put enough thought into it ;-)
Arnd <><
Quoted 14 lines · Arnd Bergmann
Quoted 5 lines · Ira Snyder
On Thu, Feb 26, 2009 at 05:15:27PM +0100, Arnd Bergmann wrote:
I think so too. I was just getting something working, and thought it would be better to have it "out there" rather than be working on it forever. I'll try to break things up as I have time.
Ok, perfect!
Quoted 4 lines
For the "libraries", would you suggest breaking things into seperate code files, and using
EXPORT_SYMBOL_GPL()? I'm not very familiar with doing that, I've mostly been writing code within the existing device driver frameworks. Or do I need export symbol at all? I'm not sure...
Quoted 7 lines
You have both options. When you list each file as a separate module in the
Makefile, you useEXPORT_SYMBOL_GPLto mark functions that get called by dependent modules, but this will work only in one way.You can also link multiple files together into one module, although it is less common to link a single source file into multiple modules.
Ok. I'm more familiar with the EXPORT_SYMBOL_GPL interface, so I'll do that. If we decide it sucks later, we'll change it.
Quoted 13 lines
Quoted 3 lines
I always thought you were supposed to use packed for data structures that are external to the system. I purposely designed the structures so they wouldn't need padding.
That would only make sense for structures that are explicitly unaligned, like a register layout using
struct my_registers { __le16 first; __le32 second __attribute__((packed)); __le16 third; };
Quoted 4 lines
Even here, I'd recommend listing the individual members as packed rather than the entire struct. Obviously if you layout the members in a sane way, you don't need either.
Ok. I'll drop the __attribute__((packed)) and make sure there aren't problems. I don't suspect any, though.
Quoted 5 lines
Quoted 4 lines
I mostly don't need it. In fact, the only place I'm using registers not specific to the messaging unit is in the probe routine, where I setup the 1GB window into host memory and setting up access to the guest memory on the PCI bus.
Quoted 8 lines
You could add the registers you need for this to the "reg" property of your device, to be mapped with
of_iomap.If the registers for setting up this window don't logically fit into the same device as the one you already use, the cleanest solution would be to have another device just for this and then make a function call into that driver to set up the window.
The registers are part of the board control registers. They don't fit at all in the message unit. Doing this in the bootloader seems like a logical place, but that would require any testers to flash a new U-Boot image into their mpc8349emds boards.
The first set of access is used to set up a 1GB region in the memory map that accesses the host's memory. Any reads/writes to addresses 0x80000000-0xc0000000 actually hit the host's memory.
The last access sets up PCI BAR1 to hit the memory from dma_alloc_coherent(). The bootloader already sets up the window as 16K, it just doesn't point it anywhere. Maybe this /should/ go into the bootloader. Like above, it would require testers to flash a new U-Boot image into their mpc8349emds boards.
Quoted 8 lines
Quoted 8 lines
Now, I wouldn't need to access these registers at all if the bootloader could handle it. I just don't know if it is possible to have Linux not use some memory that the bootloader allocated, other than with the mem=XXX trick, which I'm sure wouldn't be acceptable. I've just used regular RAM so this is portable to my custom board (mpc8349emds based) and a regular mpc8349emds. I didn't want to change anything board specific.
Quoted 9 lines
Quoted 3 lines
I would love to have the bootloader allocate (or reserve somewhere in the memory map) 16K of RAM, and not be required to allocate it with
dma_alloc_coherent(). It would save me plenty of headaches.I believe you can do that through the "memory" devices in the device tree, by leaving out a small part of the description of main memory, at putting it into the "reg" property of your own device.
I'll explore this option. I didn't even know you could do this. Is a driver that requires the trick acceptable for mainline inclusion? Just like setting up the 16K PCI window, this is very platform specific.
This limits the guest driver to systems which are able to change Linux's view of their memory somehow. Maybe this isn't a problem.
Quoted 19 lines
Quoted 8 lines
Code complexity only. Also, it was easier to write 80-char lines with something like:
vop_get_desc(vq, idx, &desc);if (desc.flags & VOP_DESC_F_NEXT) { /* do something */ }Quoted 7 lines
Instead of:
if (le16_to_cpu(vq->desc[idx].flags) & VOP_DESC_F_NEXT) { /* do something */ }Plus, I didn't have to remember how many bits were in each field. I just thought it made everything simpler to understand. Suggestions?
hmm, in this particular case, you could change the definition of
VOP_DESC_F_NEXTto
Quoted 9 lines
#define
VOP_DESC_F_NEXTcpu_to_le16(1)and then do the code as the even simpler (source and object code wise)
if (vq->desc[idx].flags) &
VOP_DESC_F_NEXT)I'm not sure if you can do something along these lines for the other cases as well though.
That's a good idea. It wouldn't fix the addresses, lengths, and next fields, though. I'll make the change and see how bad it is, then report back. It may not be so bad after all.
Quoted 5 lines
Quoted 5 lines
I used 3 so they would would align to 1024 byte boundaries within a 4K page. Then the layout was 16K on the bus, each 4K page is a single virtio-device, and each 1K block is a single virtqueue. The first 1K is for virtio-device status and feature bits, etc.
Quoted 8 lines
Quoted 3 lines
Packing them differently isn't a problem. It was just easier to code because setting up a window with the correct size is so platform specific.
Ok. I guess the important question is what part of the code makes this decision. Ideally, the virtio-net glue would instantiate the device with the right number of queues.
Yeah, virtio doesn't work that way.
The virtio drivers just call find_vq() with a different index for each queue they want to use. You have no way of knowing how many queues each virtio driver will want, unless you go read their source code.
virtio-net currently uses 3 queues, but we only support the first two. The third is optional (for now...), and non-symmetric.
Thanks again,
Ira
Quoted 11 lines · Ira Snyder
On Thu, Feb 26, 2009 at 09:37:14PM +0100, Arnd Bergmann wrote:
The registers are part of the board control registers. They don't fit at all in the message unit. Doing this in the bootloader seems like a logical place, but that would require any testers to flash a new U-Boot image into their mpc8349emds boards.
The first set of access is used to set up a 1GB region in the memory map that accesses the host's memory. Any reads/writes to addresses 0x80000000-0xc0000000 actually hit the host's memory.
Quoted 5 lines
The last access sets up PCI BAR1 to hit the memory from
dma_alloc_coherent(). The bootloader already sets up the window as 16K, it just doesn't point it anywhere. Maybe this /should/ go into the bootloader. Like above, it would require testers to flash a new U-Boot image into their mpc8349emds boards.
Ok, I see.
I guess the best option for doing it in Linux then would be to have a board control driver (not sure if this already exists) that exports high-level functions to set up the inbound and outbound windows.
Quoted 8 lines
Yeah, virtio doesn't work that way.
The virtio drivers just call
find_vq()with a different index for each queue they want to use. You have no way of knowing how many queues each virtio driver will want, unless you go read their source code.virtio-net currently uses 3 queues, but we only support the first two. The third is optional (for now...), and non-symmetric.
I mean the part of your driver that calls register_virtio_device() could make the decision, this is the one I was referring to as virtio_net glue because it is the only part that actually needs to know about the features etc.
Right now, you just call register_virtio_net from vop_probe(), which is absolutely appropriate for the specific use case. In the most general case though, you would have a user interface on one or both sides that allows a (root) user to trigger the creation of a virtio_net (or other virtio) device with specific characteristics such as MAC address or number of virtqueues.
One idea I had earlier was that there could be a special device with just one virtqueue that is always present and that allows you do communicate configuration changes regarding the available devices to the remote VOP driver.
Arnd <><
Quoted 18 lines · Arnd Bergmann
Quoted 11 lines · Ira Snyder
On Thu, Feb 26, 2009 at 09:37:14PM +0100, Arnd Bergmann wrote:
The registers are part of the board control registers. They don't fit at all in the message unit. Doing this in the bootloader seems like a logical place, but that would require any testers to flash a new U-Boot image into their mpc8349emds boards.
The first set of access is used to set up a 1GB region in the memory map that accesses the host's memory. Any reads/writes to addresses 0x80000000-0xc0000000 actually hit the host's memory.
Quoted 5 lines
The last access sets up PCI BAR1 to hit the memory from
dma_alloc_coherent(). The bootloader already sets up the window as 16K, it just doesn't point it anywhere. Maybe this /should/ go into the bootloader. Like above, it would require testers to flash a new U-Boot image into their mpc8349emds boards.
Quoted 6 lines
Ok, I see.
I guess the best option for doing it in Linux then would be to have a board control driver (not sure if this already exists) that exports high-level functions to set up the inbound and outbound windows.
Nothing like it exists. The OF device tree doesn't even describe these registers. The code in arch/powerpc/sysdev/fsl_pci.c uses some registers near these, but it gets their address by masking the low bits off the addresses from the device tree and adding the offsets of the new registers. Nasty.
I'll do this for now:
1) Get the message unit registers from my device tree
2) Encapsulate all use of get_immrbase() to a single function
That way it could be easily replaced in the future when something more suitable comes along.
Quoted 14 lines
Quoted 8 lines
Yeah, virtio doesn't work that way.
The virtio drivers just call
find_vq()with a different index for each queue they want to use. You have no way of knowing how many queues each virtio driver will want, unless you go read their source code.virtio-net currently uses 3 queues, but we only support the first two. The third is optional (for now...), and non-symmetric.
I mean the part of your driver that calls
register_virtio_device()could make the decision, this is the one I was referring to asvirtio_netglue because it is the only part that actually needs to know about the features etc.
Quoted 7 lines
Right now, you just call
register_virtio_netfromvop_probe(), which is absolutely appropriate for the specific use case. In the most general case though, you would have a user interface on one or both sides that allows a (root) user to trigger the creation of avirtio_net(or other virtio) device with specific characteristics such as MAC address or number of virtqueues.
I didn't think about this at all. This driver could be used to boot a (guest) system over NFS, so in that case there isn't a userspace running yet, to allow configuration. This is essentially my use case, though I haven't implemented it yet.
Also, I hate designing user interfaces :) Any concrete suggestions on design would be most welcome.
Quoted 5 lines
One idea I had earlier was that there could be a special device with just one virtqueue that is always present and that allows you do communicate configuration changes regarding the available devices to the remote VOP driver.
That's an interesting idea that I didn't consider, either. It wouldn't have to be fast, just reliable. When you're doing small transfers, the CPU is just fine.
Ira
Quoted 12 lines · Ira Snyder
Quoted 4 lines · Arnd Bergmann
I guess the best option for doing it in Linux then would be to have a board control driver (not sure if this already exists) that exports high-level functions to set up the inbound and outbound windows.
Nothing like it exists. The OF device tree doesn't even describe these registers. The code in
arch/powerpc/sysdev/fsl_pci.cuses some registers near these, but it gets their address by masking the low bits off the addresses from the device tree and adding the offsets of the new registers. Nasty.
Quoted 6 lines
I'll do this for now:
1) Get the message unit registers from my device tree
2) Encapsulate all use ofget_immrbase()to a single functionThat way it could be easily replaced in the future when something more suitable comes along.
Ok. However, I don't expect this to get fixed magically. Ideally, you would start a new file for the board control in arch/powerpc/sysdev and export the function from there, otherwise you do it the way you suggested.
Then we can tell the fsl_pci and other people to use the same method and source file to access the board control.
Quoted 8 lines
I didn't think about this at all. This driver could be used to boot a (guest) system over NFS, so in that case there isn't a userspace running yet, to allow configuration. This is essentially my use case, though I haven't implemented it yet.
Also, I hate designing user interfaces :) Any concrete suggestions on design would be most welcome.
Don't worry about it for now, just put all the hardcoded virtio_net specific stuff into a file separate from the hardware specific files so that we have a nice kernel level abstraction to build a user abstraction on top of.
Arnd <><
Quoted 10 lines · Ira Snyder
Quoted 4 lines · Arnd Bergmann
If the registers for setting up this window don't logically fit into the same device as the one you already use, the cleanest solution would be to have another device just for this and then make a function call into that driver to set up the window.
The registers are part of the board control registers. They don't fit at all in the message unit. Doing this in the bootloader seems like a logical place, but that would require any testers to flash a new U-Boot image into their mpc8349emds boards.
Alternately, the board platform code (arch/powerpc/platforms/83xx) is an ideal place for 'fixups'. ie. to setup things that the firmware really should be do, but doesn't.
Quoted 1 line
Quoted 1 line
Quoted 1 line
Now, I wouldn't need to access these registers at all if the bootloade=
r
Quoted 17 lines
Quoted 7 lines
Quoted 7 lines
could handle it. I just don't know if it is possible to have Linux not use some memory that the bootloader allocated, other than with the mem=3DXXX trick, which I'm sure wouldn't be acceptable. I've just used regular RAM so this is portable to my custom board (mpc8349emds based) and a regular mpc8349emds. I didn't want to change anything board specific.
Quoted 9 lines
Quoted 3 lines
I would love to have the bootloader allocate (or reserve somewhere in the memory map) 16K of RAM, and not be required to allocate it with
dma_alloc_coherent(). It would save me plenty of headaches.I believe you can do that through the "memory" devices in the device tree, by leaving out a small part of the description of main memory, at putting it into the "reg" property of your own device.
Quoted 3 lines
I'll explore this option. I didn't even know you could do this. =A0Is a driver that requires the trick acceptable for mainline inclusion? Just like setting up the 16K PCI window, this is very platform specific.
Yup. You wouldn't even need to write any code to do this. Just reduce the memory node's RAM size listed in the .dts file by 16k and add a 16K region to the reg property for the messaging region.
Speaking of which, the device tree changes should be adding 2 nodes; 1 node to describe the messaging unit, and 1 node to describe the virtio instance. The messaging unit is a general purpose piece of hardware, so it is not appropriate to write a usage-specific device driver that binds against it. I'm kind of working on this right now, so I'll show you what I mean in patch form when I actually get things running.
g.
--=20
Grant Likely, B.Sc., P.Eng.
Secret Lab Technologies Ltd.
Quoted 1 line · Ira Snyder
This adds support to Linux for using virtio between two computers linked =
by
Quoted 2 lines
a PCI interface. This allows the use of
virtio_netto create a familiar, fast interface for communication. It should be possible to use other virt=
io
Quoted 1 line
devices in the future, but this has not been tested.
Hey Ira,
I like this a lot. I need to do much the same thing on one of my platforms, so I'm going to use your patch as my starting point. Have you made many changes since you posted this version of your patch? I'd like to collaborate on the development and help to get it mainlined.
In my case I've got an MPC5200 as the 'host' and a Xilinx Virtex (ppc440) as the 'client'. I intend set aside a region of the Xilinx Virtex's memory space for the shared queues. I'm starting work on it now, and I'll provide you with feedback and/or patches as I make progress.
g.
Quoted 2 lines
I have implemented guest support for the Freescale MPC8349EMDS board, whi=
ch
Quoted 1 line
is capable of running in PCI agent mode (It acts like a PCI card, but is =
a
Quoted 1 line
complete computer system, running Linux). The driver is trivial to port t=
o
Quoted 6 lines
any MPC83xx system.
It was developed to work in a CompactPCI crate of computers, one of which is a standard x86 system (acting as the host) and many PowerPC systems (acting as guests).
Quoted 6 lines
I have only tested this driver with a single board in my system. The host is a 1066MHz Pentium3-M, and the guest is a 533MHz PowerPC. I am able achieve transfer rates of about 150 mbit
host->guestand 350 mbitguest->host. A few tests showed that using an mtu of 4000 provided much better results than an mtu of 1500. Using an mtu of 64000 significantly dropped performance. The performance is equivalent to my PCINet driver fo=
r
Quoted 8 lines
host->guest, and about 20% faster forguest->hosttransfers.I have included a short document explaining what I think is the most complicated part of the driver: using the DMA engine to transfer data. I hope everything else is readily obvious from the code. Questions are welcome.
I will not be able to work on this full time for at least a few weeks, so=
I
Quoted 1 line
would appreciate actual review of this driver. =A0Nitpicks are fine, I ju=
st
Quoted 28 lines
won't be able to respond to them quickly.
RFCv1 -> RFCv2:
=A0* fix major brokenness of hostdetach_buf()
=A0* supportVIRTIO_NET_F_CSUM
=A0* supportVIRTIO_NET_F_GSO
=A0* supportVIRTIO_NET_F_MRG_RXBUF
=A0* rewrote DMA transfers to support merged rxbufs =A0* added a hack to fix the endianness of virtio_net's metadata =A0* lots more performance forguest->hosttransfers (~40MB/sec) =A0* updated documentation
=A0* allocate 128 feature bits instead of 32Signed-off-by Ira W. Snyder <[email protected]>---
Yes, the commit message has too much information. This is an RFC after all. I fully expect to have to make changes. In fact, I posting this more to "get it out there" than anything else, since I have other tasks that need doing.
I'd appreciate a serious review of the design by the people who have been pressuring me to use virtio. I'm very happy to answer any questions you have.
Thanks to everyone who gave feedback for RFCv1!
Ira
Quoted 6 lines
=A0Documentation/virtio-over-PCI.txt =A0 =A0 | =A0 60 + =A0arch/powerpc/boot/dts/mpc834x_mds.dts | =A0 =A07 + =A0drivers/virtio/Kconfig =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0| =A0 22 + =A0drivers/virtio/Makefile =A0 =A0 =A0 =A0 =A0 =A0 =A0 | =A0 =A02 + =A0drivers/virtio/vop.h =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0| =A0119 ++ =A0drivers/virtio/vop_fsl.c =A0 =A0 =A0 =A0 =A0 =A0 =A0| 2020 +++++++++++=
++++++++++++++++++++++
Quoted 1 line
=A0drivers/virtio/vop_host.c =A0 =A0 =A0 =A0 =A0 =A0 | 1071 +++++++++++++=
++++
Documentation/virtio-ove=
Quoted 9 lines
=A0drivers/virtio/vop_hw.h =A0 =A0 =A0 =A0 =A0 =A0 =A0 | =A0 80 ++ =A08 files changed, 3381 insertions(+), 0 deletions(-) =A0create mode 100644
Documentation/virtio-over-PCI.txt=A0create mode 100644drivers/virtio/vop.h
=A0create mode 100644drivers/virtio/vop_fsl.c=A0create mode 100644drivers/virtio/vop_host.c=A0create mode 100644drivers/virtio/vop_hw.hDocumentation/virtio-ove= renamed from Documentation/virtio-over-PCI.txt +0
-0
r-PCI.txt
Documentation/virtio-over-PCI.txt line 1
Quoted 6 lines
new file mode 100644
index 0000000..e4520d4Documentation/virtio-over-PCI.txt new file +1
-0@@ -0,0 +1,60 @@ +The implementation of virtio-over-PCI was driven with the following goal=
s:
Documentation/virtio-over-PCI.txt
Quoted 8 lines
Documentation/virtio-over-PCI.txt new file +8
-0+* Avoid MMIO reads, try to use only MMIO writes +* Use the onboard DMA engine, for speed + +The implementation also borrows many of the details from the only other +implementation, virtio_ring. + +It succeeds in avoiding all MMIO reads on the critical paths. I did not +see any reason to avoid the use of MMIO reads during device probing, sin=
ce
Documentation/virtio-over-PCI.txt
Quoted 5 lines
Documentation/virtio-over-PCI.txt new file +5
-0+it is not a critical path. + +=3D=3D=3D Avoiding MMIO reads =3D=3D=3D +To avoid MMIO reads, both the host and guest systems have a copy of the +descriptors. Both sides need to read the descriptors after they have bee=
n
Documentation/virtio-over-PCI.txt line 15
Quoted 1 line
Documentation/virtio-over-PCI.txt new file +1
-0+written, but only the host system writes to them. This allows us to keep=
a
Documentation/virtio-over-PCI.txt
Quoted 8 lines
Documentation/virtio-over-PCI.txt new file +8
-0+local copy for later use. + +=3D=3D=3D Using the DMA engine =3D=3D=3D +This is the only truly complicated part of the system. Since this +implementation was designed for use with virtio_net, it may be biased +towards virtio_net's usage of the virtio interface. + +In merged rxbufs mode, the virtio_net driver provides a receive ring, wh=
ich
Documentation/virtio-over-PCI.txt
Quoted 6 lines
Documentation/virtio-over-PCI.txt new file +6
-0+it fills with empty PAGE_SIZE buffers. The DMA code sets up transfers +directly from the guest transmit queue to the empty packets in the host +receive queue. Data transfer in the other direction works in a similar +fashion. + +The guest (PowerPC) system keeps its own local set of descriptors, which=
are
Documentation/virtio-over-PCI.txt line 30
Quoted 1 line
Documentation/virtio-over-PCI.txt new file +1
-0+filled by the virtio add_buf() call. Whenever this happens, the avail ri=
ng is
Documentation/virtio-over-PCI.txt
Quoted 13 lines
Documentation/virtio-over-PCI.txt new file +13
-0+changed, and therefore we try to transfer data. + +The algorithm is essentially as follows: +1) Check for an available local or remote entry +2) Check that the other side has enough room for the packet +3) Transfer the chain, joining small packets and splitting large packets +4) Move the entries to the used rings, but do not update the used index +5) Schedule a DMA callback to happen when the transfer completes +6) Start the DMA transfer +7) When the DMA finishes, the callback updates the used indices and + =A0 triggers any necessary callbacks + +The algorithm can only handle chains that are to be coalesced together. =
It
Documentation/virtio-over-PCI.txt
Quoted 5 lines
Documentation/virtio-over-PCI.txt new file +5
-0+puts all data sequentially into the PAGE_SIZE buffers exposed by the +receiving side, including both the virtio_net header and packet data. + +=3D=3D=3D Startup Sequence =3D=3D=3D +There are currently problems in the startup sequence between the host an=
d
Documentation/virtio-over-PCI.txt line 49
Quoted 1 line
Documentation/virtio-over-PCI.txt new file +1
-0+guest drivers. The current scheme assumes that the guest is up and waiti=
ng
Documentation/virtio-over-PCI.txt line 50
Quoted 1 line
Documentation/virtio-over-PCI.txt new file +1
-0+before the host is ready. I am having a very hard time coming up with a =
scheme
Documentation/virtio-over-PCI.txt line 51
Quoted 1 line
Documentation/virtio-over-PCI.txt new file +1
-0+that is perfectly safe, where either side could win the race and be read=
y
Documentation/virtio-over-PCI.txt
Quoted 3 lines
Documentation/virtio-over-PCI.txt new file +3
-0+first. + +Even harder is a situation where you would like to use the "network devi=
ce"
Documentation/virtio-over-PCI.txt line 56
Quoted 2 lines
Documentation/virtio-over-PCI.txt new file +2
-0+from your bootloader to tftp a kernel, then boot Linux. In this case, +Linux has no knowledge of where the device descriptors were before it bo=
oted.
Documentation/virtio-over-PCI.txt line 57
Quoted 1 line
Documentation/virtio-over-PCI.txt new file +1
-0+You'd need to stop and re-start the host driver to make sure it re-initi=
alizes
arch/powerpc/boot/dt=
Quoted 4 lines
Documentation/virtio-over-PCI.txt new file +3
-0+the new descriptor memory after Linux has booted. + +This is a definite "needs work" item.arch/powerpc/boot/dt= renamed from arch/powerpc/boot/dts/mpc834x_mds.dts +0
-0
s/mpc834x_mds.dts
arch/powerpc/boot/dts/mpc834x_mds.dts line 108
Quoted 9 lines
index d9adba0..5c7617d 100644
arch/powerpc/boot/dts/mpc834x_mds.dts +2
-0@@ -104,6 +104,13 @@ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0mode =3D "cpu"; =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0}; + =A0 =A0 =A0 =A0 =A0 =A0 =A0 message-unit@8030 { + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 compatible =3D "fsl,mpc8349=
-mu";
Quoted 17 lines
arch/powerpc/boot/dts/mpc834x_mds.dts +5
-0+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 reg =3D <0x8030 0xd0>; + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 interrupts =3D <69 0x8>; + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 interrupt-parent =3D <&ipic= ; + =A0 =A0 =A0 =A0 =A0 =A0 =A0 }; + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0dma@82a8 { =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0#address-cells =3D <1>;=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0#size-cells =3D <1>;
drivers/virtio/Kconfig +0
-0@@ -33,3 +33,25 @@ config VIRTIO_BALLOON=A0 =A0 =A0 =A0 If unsure, say M.
Quoted 6 lines
+config
VIRTIO_OVER_PCI_HOST
+ =A0 =A0 =A0 tristate "Virtio-over-PCI Host support (EXPERIMENTAL)"
+ =A0 =A0 =A0 depends on PCI && EXPERIMENTAL
+ =A0 =A0 =A0 select VIRTIO
+ =A0 =A0 =A0 ---help---
+ =A0 =A0 =A0 =A0 This driver provides the host support necessary for usi=
ng virtio
Quoted 1 line
+ =A0 =A0 =A0 =A0 over the PCI bus with a Freescale MPC8349EMDS evaluatio=
n board.
drivers/virtio/Kconfig
Quoted 11 lines
drivers/virtio/Kconfig +11
-0+ + =A0 =A0 =A0 =A0 If unsure, say N. + +config VIRTIO_OVER_PCI_FSL + =A0 =A0 =A0 tristate "Virtio-over-PCI Guest support (EXPERIMENTAL)" + =A0 =A0 =A0 depends on MPC834x_MDS && EXPERIMENTAL + =A0 =A0 =A0 select VIRTIO + =A0 =A0 =A0 select DMA_ENGINE + =A0 =A0 =A0 select FSL_DMA + =A0 =A0 =A0 ---help--- + =A0 =A0 =A0 =A0 This driver provides the guest support necessary for us=
ing virtio
Quoted 20 lines
+ =A0 =A0 =A0 =A0 over the PCI bus.
drivers/virtio/Kconfig +3
-0+ + =A0 =A0 =A0 =A0 If unsure, say N. +drivers/virtio/Makefile +0
-0@@ -2,3 +2,5 @@ obj-$(CONFIG_VIRTIO) +=3D virtio.o=A0obj-$(CONFIG_VIRTIO_RING) +=3D virtio_ring.o =A0obj-$(CONFIG_VIRTIO_PCI) +=3D virtio_pci.o =A0obj-$(CONFIG_VIRTIO_BALLOON) +=3D virtio_balloon.o
drivers/virtio/Makefile +2
-0+obj-$(CONFIG_VIRTIO_OVER_PCI_HOST) +=3D vop_host.o +obj-$(CONFIG_VIRTIO_OVER_PCI_FSL) +=3D vop_fsl.odrivers/virtio/vop.h new file +0
-0
drivers/virtio/vop.h line 6
Quoted 6 lines
drivers/virtio/vop.h new file +6
-0@@ -0,0 +1,119 @@ +/* +* Virtio-over-PCI definitions +* +* Copyright (c) 2009 Ira W. Snyder <[email protected]> +* +* This file is licensed under the terms of the GNU General Public Licen=
se
drivers/virtio/vop.h line 7
Quoted 1 line
drivers/virtio/vop.h new file +1
-0+* version 2. This program is licensed "as is" without any warranty of a=
ny
Quoted 10 lines
drivers/virtio/vop.h new file +10
-0+* kind, whether express or implied. +*/ + +#ifndef VOP_H +#define VOP_H + +#include <linux/types.h> + +/* The number of entries per ring (MUST be a power of two) */ +#define VOP_RING_SIZE =A0 =A0 =A0 =A0 =A064
drivers/virtio/vop.h
Quoted 10 lines
drivers/virtio/vop.h new file +10
-0+ +/* Marks a buffer as continuing via the next field */ +#define VOP_DESC_F_NEXT =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A01 +/* Marks a buffer as write-only (otherwise read-only) */ +#define VOP_DESC_F_WRITE =A0 =A0 =A0 2 + +/* Interrupts should not be generated when adding to avail or used */ +#define VOP_F_NO_INTERRUPT =A0 =A0 1 + +/* Virtio-over-PCI descriptors: 12 bytes. These can chain together via "=
next" */
Quoted 6 lines
drivers/virtio/vop.h new file +6
-0+struct vop_desc { + =A0 =A0 =A0 /* Address (host physical) */ + =A0 =A0 =A0 __le32 addr; + =A0 =A0 =A0 /* Length (bytes) */ + =A0 =A0 =A0 __le32 len; + =A0 =A0 =A0 /* Flags */
drivers/virtio/vop.h line 43
Quoted 10 lines
drivers/virtio/vop.h new file +10
-0+ =A0 =A0 =A0 __le16 flags; + =A0 =A0 =A0 /* Chaining for descriptors */ + =A0 =A0 =A0 __le16 next; +} __attribute__((packed)); + +/* Virtio-over-PCI used descriptor chains: 8 bytes */ +struct vop_used_elem { + =A0 =A0 =A0 /* Start index of used descriptor chain */ + =A0 =A0 =A0 __le32 id; + =A0 =A0 =A0 /* Total length of the descriptor chain which was used (wri=
tten to) */
drivers/virtio/vop.h
Quoted 7 lines
drivers/virtio/vop.h new file +7
-0+ =A0 =A0 =A0 __le32 len; +} __attribute__((packed)); + +/* The ring in host memory, only written by the guest */ +/* NOTE: with VOP_RING_SIZE =3D=3D 64, this is 520 bytes */ +struct vop_host_ring { + =A0 =A0 =A0 /* The flags, so the guest can indicate that it doesn't wan=
t
drivers/virtio/vop.h line 54
Quoted 4 lines
drivers/virtio/vop.h new file +4
-0+=A0 =A0 =A0 =A0* interrupts when things are added to the avail ring */ + =A0 =A0 =A0 __le16 flags; + + =A0 =A0 =A0 /* The index, which points at the next slot where a chain i=
ndex
Quoted 8 lines
drivers/virtio/vop.h new file +8
-0+=A0 =A0 =A0 =A0* will be added to the used ring */ + =A0 =A0 =A0 __le16 used_idx; + + =A0 =A0 =A0 /* The used ring */ + =A0 =A0 =A0 struct vop_used_elem used[VOP_RING_SIZE]; +} __attribute__((packed)); + +/* The ring in guest memory, only written by the host */
drivers/virtio/vop.h line 72
Quoted 10 lines
drivers/virtio/vop.h new file +10
-0+/* NOTE: with VOP_RING_SIZE =3D=3D 64, this is 904 bytes! */ +struct vop_guest_ring { + =A0 =A0 =A0 /* The descriptors */ + =A0 =A0 =A0 struct vop_desc desc[VOP_RING_SIZE]; + + =A0 =A0 =A0 /* The flags, so the host can indicate that it doesn't want +=A0 =A0 =A0 =A0* interrupts when things are added to the used ring */ + =A0 =A0 =A0 __le16 flags; + + =A0 =A0 =A0 /* The index, which points at the next slot where a chain i=
ndex
Quoted 53 lines
drivers/virtio/vop.h new file +47
-0+=A0 =A0 =A0 =A0* will be added to the avail ring */ + =A0 =A0 =A0 __le16 avail_idx; + + =A0 =A0 =A0 /* The avail ring */ + =A0 =A0 =A0 __le16 avail[VOP_RING_SIZE]; +} __attribute__((packed)); + +/* +* This is the status structure holding the virtio_device status +* as well as the feature bits for this device and the configuration +* space. +* +* NOTE: it is for the LOCAL device. This is the slow path, so +* NOTE: the mmio reads won't cause any speed problems +*/ +struct vop_status { + =A0 =A0 =A0 /* Status bits for the device */ + =A0 =A0 =A0 __le32 status; + + =A0 =A0 =A0 /* Feature bits for the device (128 bits) */ + =A0 =A0 =A0 __le32 features[4]; + + =A0 =A0 =A0 /* Configuration space (different for each device type) */ + =A0 =A0 =A0 u8 config[1004]; + +} __attribute__((packed)); + +/* +* Layout in memory +* +* |--------------------------| +* | 0: local device status =A0 | +* |--------------------------| +* | 1024: host/guest ring 1 =A0| +* |--------------------------| +* | 2048: host/guest ring 2 =A0| +* |--------------------------| +* | 3072: host/guest ring 3 =A0| +* |--------------------------| +* +* Now, you have one of these for each virtio device, and +* then you're pretty much set. You can expose 16K of memory +* out on the bus (on each side) and have 4 virtio devices, +* each with a different type, and 3 virtqueues +*/ + +#endif /* VOP_H */ drivers/virtio/vop_fsl.c new file +0
-0
drivers/virtio/vop_fsl.c line 6
Quoted 6 lines
drivers/virtio/vop_fsl.c new file +6
-0@@ -0,0 +1,2020 @@ +/* +* Virtio-over-PCI MPC8349EMDS Guest Driver +* +* Copyright (c) 2009 Ira W. Snyder <[email protected]> +* +* This file is licensed under the terms of the GNU General Public Licen=
se
drivers/virtio/vop_fsl.c line 7
Quoted 1 line
drivers/virtio/vop_fsl.c new file +1
-0+* version 2. This program is licensed "as is" without any warranty of a=
ny
Quoted 80 lines
drivers/virtio/vop_fsl.c new file +80
-0+* kind, whether express or implied. +*/ + +#include <linux/kernel.h> +#include <linux/module.h> +#include <linux/init.h> +#include <linux/of_platform.h> +#include <linux/io.h> +#include <linux/dma-mapping.h> +#include <linux/virtio.h> +#include <linux/virtio_config.h> +#include <linux/virtio_net.h> +#include <linux/interrupt.h> +#include <linux/virtio_net.h> +#include <linux/dmaengine.h> +#include <linux/workqueue.h> +#include <linux/etherdevice.h> + +/* MPC8349EMDS specific get_immrbase() */ +#include <sysdev/fsl_soc.h> + +#include "vop_hw.h" +#include "vop.h" + +/* +* These are internal use only versions of the structures that +* are exported over PCI by this driver +* +* They are used internally to keep track of the PowerPC queues so that +* we don't have to keep flipping endianness all the time +*/ +struct vop_loc_desc { + =A0 =A0 =A0 u32 addr; + =A0 =A0 =A0 u32 len; + =A0 =A0 =A0 u16 flags; + =A0 =A0 =A0 u16 next; +}; + +struct vop_loc_avail { + =A0 =A0 =A0 u16 index; + =A0 =A0 =A0 u16 ring[VOP_RING_SIZE]; +}; + +struct vop_loc_used_elem { + =A0 =A0 =A0 u32 id; + =A0 =A0 =A0 u32 len; +}; + +struct vop_loc_used { + =A0 =A0 =A0 u16 index; + =A0 =A0 =A0 struct vop_loc_used_elem ring[VOP_RING_SIZE]; +}; + +/* +* DMA Resolver state information +*/ +struct vop_dma_info { + =A0 =A0 =A0 struct dma_chan *chan; + + =A0 =A0 =A0 /* The currently processing avail entry */ + =A0 =A0 =A0 u16 loc_avail; + =A0 =A0 =A0 u16 rem_avail; + + =A0 =A0 =A0 /* The currently processing used entries */ + =A0 =A0 =A0 u16 loc_used; + =A0 =A0 =A0 u16 rem_used; +}; + +struct vop_vq { + + =A0 =A0 =A0 /* The actual virtqueue itself */ + =A0 =A0 =A0 struct virtqueue vq; + =A0 =A0 =A0 struct device *dev; + + =A0 =A0 =A0 /* The host ring address */ + =A0 =A0 =A0 struct vop_host_ring __iomem *host; + + =A0 =A0 =A0 /* The guest ring address */ + =A0 =A0 =A0 struct vop_guest_ring *guest; +
drivers/virtio/vop_fsl.c
Quoted 10 lines
drivers/virtio/vop_fsl.c new file +10
-0+ =A0 =A0 =A0 /* Our own memory descriptors */ + =A0 =A0 =A0 struct vop_loc_desc desc[VOP_RING_SIZE]; + =A0 =A0 =A0 struct vop_loc_avail avail; + =A0 =A0 =A0 struct vop_loc_used used; + =A0 =A0 =A0 unsigned int flags; + + =A0 =A0 =A0 /* Data tokens from add_buf() */ + =A0 =A0 =A0 void *data[VOP_RING_SIZE]; + + =A0 =A0 =A0 unsigned int num_free; =A0/* number of free descriptors in =
desc */
drivers/virtio/vop_fsl.c line 98
Quoted 1 line
drivers/virtio/vop_fsl.c new file +1
-0+ =A0 =A0 =A0 unsigned int free_head; /* start of the free descriptors in=
desc */
drivers/virtio/vop_fsl.c line 99
Quoted 1 line
drivers/virtio/vop_fsl.c new file +1
-0+ =A0 =A0 =A0 unsigned int num_added; /* number of entries added to desc =
*/
drivers/virtio/vop_fsl.c line 101
Quoted 2 lines
drivers/virtio/vop_fsl.c new file +2
-0+ + =A0 =A0 =A0 u16 loc_last_used; =A0 =A0 =A0/* the last local used entry =
processed */
drivers/virtio/vop_fsl.c line 102
Quoted 1 line
drivers/virtio/vop_fsl.c new file +1
-0+ =A0 =A0 =A0 u16 rem_last_used; =A0 =A0 =A0/* the current value of remot=
e used_idx */
Quoted 6 lines
drivers/virtio/vop_fsl.c new file +6
-0+ + =A0 =A0 =A0 /* DMA resolver state */ + =A0 =A0 =A0 struct vop_dma_info dma; + =A0 =A0 =A0 struct work_struct work; + =A0 =A0 =A0 int (*resolve)(struct vop_vq *vq); +
drivers/virtio/vop_fsl.c
Quoted 10 lines
drivers/virtio/vop_fsl.c new file +10
-0+ =A0 =A0 =A0 void __iomem *immr; + =A0 =A0 =A0 int kick_val; +}; + +/* Convert from a struct virtqueue to a struct vop_vq */ +#define to_vop_vq (X ) container_of(X, struct vop_vq, vq) + +/* +* This represents a virtio_device for our driver. It follows the memory +* layout shown above. It has pointers to all of the host and guest memo=
ry
Quoted 6 lines
drivers/virtio/vop_fsl.c new file +6
-0+* areas that we need to access +*/ +struct vop_vdev { + + =A0 =A0 =A0 /* The specific virtio device (console, net, blk) */ + =A0 =A0 =A0 struct virtio_device vdev;
drivers/virtio/vop_fsl.c line 134
Quoted 10 lines
drivers/virtio/vop_fsl.c new file +10
-0+ + =A0 =A0 =A0 #define VOP_DEVICE_REGISTERED 1 + =A0 =A0 =A0 int status; + + =A0 =A0 =A0 /* Start address of local and remote memory */ + =A0 =A0 =A0 void *loc; + =A0 =A0 =A0 void __iomem *rem; + + =A0 =A0 =A0 /* +=A0 =A0 =A0 =A0* These are the status, feature, and configuration infor=
mation
drivers/virtio/vop_fsl.c line 135
Quoted 1 line
drivers/virtio/vop_fsl.c new file +1
-0+ =A0 =A0 =A0 =A0* for this virtio device. They are exposed in our memory=
block
drivers/virtio/vop_fsl.c line 141
Quoted 6 lines
drivers/virtio/vop_fsl.c new file +6
-0+=A0 =A0 =A0 =A0* starting at offset 0. +=A0 =A0 =A0 =A0*/ + =A0 =A0 =A0 struct vop_status __iomem *host_status; + + =A0 =A0 =A0 /* +=A0 =A0 =A0 =A0* These are the status, feature, and configuration infor=
mation
drivers/virtio/vop_fsl.c line 142
Quoted 1 line
drivers/virtio/vop_fsl.c new file +1
-0+ =A0 =A0 =A0 =A0* for the guest virtio device. They are exposed in the g=
uest
drivers/virtio/vop_fsl.c line 148
Quoted 6 lines
drivers/virtio/vop_fsl.c new file +6
-0+=A0 =A0 =A0 =A0* memory block starting at offset 0. +=A0 =A0 =A0 =A0*/ + =A0 =A0 =A0 struct vop_status *guest_status; + + =A0 =A0 =A0 /* +=A0 =A0 =A0 =A0* These are the virtqueues for the virtio driver running=
this
drivers/virtio/vop_fsl.c line 149
Quoted 1 line
drivers/virtio/vop_fsl.c new file +1
-0+ =A0 =A0 =A0 =A0* device to use. The host portions are exposed in our me=
mory block
drivers/virtio/vop_fsl.c line 150
Quoted 1 line
drivers/virtio/vop_fsl.c new file +1
-0+ =A0 =A0 =A0 =A0* starting at offset 1024. The exposed areas are aligned=
to 1024 byte
drivers/virtio/vop_fsl.c line 151
Quoted 1 line
drivers/virtio/vop_fsl.c new file +1
-0+ =A0 =A0 =A0 =A0* boundaries, so they appear at offets 1024, 2048, and 3=
072
Quoted 41 lines
drivers/virtio/vop_fsl.c new file +41
-0+=A0 =A0 =A0 =A0* respectively. +=A0 =A0 =A0 =A0*/ + =A0 =A0 =A0 struct vop_vq virtqueues[3]; +}; + +#define to_vop_vdev (X ) container_of(X, struct vop_vdev, vdev) + +struct vop_dev { + + =A0 =A0 =A0 struct of_device *op; + =A0 =A0 =A0 struct device *dev; + + =A0 =A0 =A0 /* Reset and start */ + =A0 =A0 =A0 struct mutex mutex; + =A0 =A0 =A0 struct work_struct reset_work; + =A0 =A0 =A0 struct work_struct start_work; + + =A0 =A0 =A0 int irq; + + =A0 =A0 =A0 /* Our board control registers */ + =A0 =A0 =A0 void __iomem *immr; + + =A0 =A0 =A0 /* The guest memory, exposed at PCI BAR1 */ + =A0 =A0 =A0 #define VOP_GUEST_MEM_SIZE 16384 + =A0 =A0 =A0 void *guest_mem; + =A0 =A0 =A0 dma_addr_t guest_mem_addr; + + =A0 =A0 =A0 /* Host memory, given to us by host in OMR0 */ + =A0 =A0 =A0 #define VOP_HOST_MEM_SIZE 16384 + =A0 =A0 =A0 void __iomem *host_mem; + + =A0 =A0 =A0 /* The virtio devices */ + =A0 =A0 =A0 struct vop_vdev devices[4]; + =A0 =A0 =A0 struct dma_chan *chan; +}; + +/* +* DMA callback information +*/ +struct vop_dma_cbinfo { + =A0 =A0 =A0 struct vop_vq *vq;
drivers/virtio/vop_fsl.c line 202
Quoted 10 lines
drivers/virtio/vop_fsl.c new file +10
-0+ + =A0 =A0 =A0 /* The amount to increment the used rings */ + =A0 =A0 =A0 unsigned int loc; + =A0 =A0 =A0 unsigned int rem; +}; + +static const char driver_name[] =3D "vdev"; +static struct kmem_cache *dma_cache; + +/*----------------------------------------------------------------------=
------*/
drivers/virtio/vop_fsl.c line 203
Quoted 1 line
drivers/virtio/vop_fsl.c new file +1
-0+/* Whole-descriptor access helpers =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0*/
drivers/virtio/vop_fsl.c line 204
Quoted 1 line
drivers/virtio/vop_fsl.c new file +1
-0+/*----------------------------------------------------------------------=
------*/
drivers/virtio/vop_fsl.c
Quoted 11 lines
drivers/virtio/vop_fsl.c new file +11
-0+ +/* +* Return a copy of a local descriptor in native format for easy use +* of all fields +* +* @vq the virtqueue +* @idx the descriptor index +* @desc pointer to the structure to copy into +*/ +static void vop_loc_desc(struct vop_vq *vq, unsigned int idx, + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0struct vop_loc_desc *des=
c)
Quoted 10 lines
drivers/virtio/vop_fsl.c new file +10
-0+{ + =A0 =A0 =A0 BUG_ON(idx >=3D VOP_RING_SIZE); + =A0 =A0 =A0 BUG_ON(!desc); + + =A0 =A0 =A0 desc->addr =A0=3D vq->desc[idx].addr; + =A0 =A0 =A0 desc->len =A0 =3D vq->desc[idx].len; + =A0 =A0 =A0 desc->flags =3D vq->desc[idx].flags; + =A0 =A0 =A0 desc->next =A0=3D vq->desc[idx].next; +} +
drivers/virtio/vop_fsl.c
Quoted 10 lines
drivers/virtio/vop_fsl.c new file +10
-0+/* +* Return a copy of a remote descriptor in native format for easy use +* of all fields +* +* @vq the virtqueue +* @idx the descriptor index +* @desc pointer to the structure to copy into +*/ +static void vop_rem_desc(struct vop_vq *vq, unsigned int idx, + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0struct vop_loc_desc *des=
c)
drivers/virtio/vop_fsl.c line 246
Quoted 11 lines
drivers/virtio/vop_fsl.c new file +11
-0+{ + =A0 =A0 =A0 BUG_ON(idx >=3D VOP_RING_SIZE); + =A0 =A0 =A0 BUG_ON(!desc); + + =A0 =A0 =A0 desc->addr =A0=3D le32_to_cpu(vq->guest->desc[idx].addr); + =A0 =A0 =A0 desc->len =A0 =3D le32_to_cpu(vq->guest->desc[idx].len); + =A0 =A0 =A0 desc->flags =3D le16_to_cpu(vq->guest->desc[idx].flags); + =A0 =A0 =A0 desc->next =A0=3D le16_to_cpu(vq->guest->desc[idx].next); +} + +/*----------------------------------------------------------------------=
------*/
drivers/virtio/vop_fsl.c line 247
Quoted 1 line
drivers/virtio/vop_fsl.c new file +1
-0+/* Local descriptor ring access helpers =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 */
drivers/virtio/vop_fsl.c line 248
Quoted 1 line
drivers/virtio/vop_fsl.c new file +1
-0+/*----------------------------------------------------------------------=
------*/
drivers/virtio/vop_fsl.c line 250
Quoted 2 lines
drivers/virtio/vop_fsl.c new file +2
-0+ +static void vop_set_desc_addr(struct vop_vq *vq, unsigned int idx, u32 a=
ddr)
drivers/virtio/vop_fsl.c
Quoted 5 lines
drivers/virtio/vop_fsl.c new file +5
-0+{ + =A0 =A0 =A0 vq->desc[idx].addr =3D addr; +} + +static void vop_set_desc_len(struct vop_vq *vq, unsigned int idx, u32 le=
n)
drivers/virtio/vop_fsl.c
Quoted 5 lines
drivers/virtio/vop_fsl.c new file +5
-0+{ + =A0 =A0 =A0 vq->desc[idx].len =3D len; +} + +static void vop_set_desc_flags(struct vop_vq *vq, unsigned int idx, u16 =
flags)
drivers/virtio/vop_fsl.c
Quoted 5 lines
drivers/virtio/vop_fsl.c new file +5
-0+{ + =A0 =A0 =A0 vq->desc[idx].flags =3D flags; +} + +static void vop_set_desc_next(struct vop_vq *vq, unsigned int idx, u16 n=
ext)
Quoted 5 lines
drivers/virtio/vop_fsl.c new file +5
-0+{ + =A0 =A0 =A0 vq->desc[idx].next =3D next; +} + +static u16 vop_get_desc_flags (struct vop_vq *vq,unsigned int idx)
drivers/virtio/vop_fsl.c
Quoted 10 lines
drivers/virtio/vop_fsl.c new file +10
-0+{ + =A0 =A0 =A0 return vq->desc[idx].flags; +} + +static u16 vop_get_desc_next (struct vop_vq *vq,unsigned int idx) +{ + =A0 =A0 =A0 return vq->desc[idx].next; +} + +/*----------------------------------------------------------------------=
------*/
drivers/virtio/vop_fsl.c line 281
Quoted 1 line
drivers/virtio/vop_fsl.c new file +1
-0+/* Status Helpers =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 */
drivers/virtio/vop_fsl.c line 282
Quoted 1 line
drivers/virtio/vop_fsl.c new file +1
-0+/*----------------------------------------------------------------------=
------*/
Quoted 15 lines
drivers/virtio/vop_fsl.c new file +15
-0+ +static u32 vop_get_host_status (struct vop_vdev *vdev) +{ + =A0 =A0 =A0 return ioread32(&vdev->host_status->status); +} + +static u32 vop_get_host_features (struct vop_vdev *vdev) +{ + =A0 =A0 =A0 return ioread32(&vdev->host_status->features[0]); +} + +static u16 vop_get_host_flags (struct vop_vq *vq) +{ + =A0 =A0 =A0 return le16_to_cpu(vq->guest->flags); +}
drivers/virtio/vop_fsl.c
Quoted 10 lines
drivers/virtio/vop_fsl.c new file +10
-0+ +/* +* Set the guest's flags variable (lives in host memory) +*/ +static void vop_set_guest_flags (struct vop_vq *vq,u16 flags) +{ + =A0 =A0 =A0 iowrite16(flags, &vq->host->flags); +} + +/*----------------------------------------------------------------------=
------*/
drivers/virtio/vop_fsl.c line 308
Quoted 1 line
drivers/virtio/vop_fsl.c new file +1
-0+/* Remote Ring Debugging Helpers =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0=
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0*/
drivers/virtio/vop_fsl.c line 309
Quoted 1 line
drivers/virtio/vop_fsl.c new file +1
-0+/*----------------------------------------------------------------------=
------*/
drivers/virtio/vop_fsl.c
Quoted 8 lines
drivers/virtio/vop_fsl.c new file +8
-0+ +#ifdef DEBUG_DUMP_RINGS +static void dump_rem_desc(struct vop_vq *vq) +{ + =A0 =A0 =A0 struct vop_loc_desc desc; + =A0 =A0 =A0 int i; + + =A0 =A0 =A0 dev_dbg(vq->dev, "REM DESC 0xADDRESSX LENGTH 0xFLAG NEXT\n"=
);
drivers/virtio/vop_fsl.c line 320
Quoted 3 lines
drivers/virtio/vop_fsl.c new file +3
-0+ =A0 =A0 =A0 for (i =3D 0; i < VOP_RING_SIZE; i++) { + =A0 =A0 =A0 =A0 =A0 =A0 =A0 vop_rem_desc(vq, i, &desc); + =A0 =A0 =A0 =A0 =A0 =A0 =A0 dev_dbg(vq->dev, "DESC %.2d: 0x%.8x %.6d 0x=
%.4x %.2d\n",
drivers/virtio/vop_fsl.c line 321
Quoted 1 line
drivers/virtio/vop_fsl.c new file +1
-0+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 i, desc.add=
r, desc.len, desc.flags, desc.next);
drivers/virtio/vop_fsl.c
Quoted 8 lines
drivers/virtio/vop_fsl.c new file +8
-0+ =A0 =A0 =A0 } +} + +static void dump_rem_avail (struct vop_vq *vq) +{ + =A0 =A0 =A0 int i; + + =A0 =A0 =A0 dev_dbg(vq->dev, "REM AVAIL IDX %.2d\n", le16_to_cpu(vq->gu=
est->avail_idx));
drivers/virtio/vop_fsl.c line 332
Quoted 3 lines
drivers/virtio/vop_fsl.c new file +3
-0+ =A0 =A0 =A0 for (i =3D 0; i < VOP_RING_SIZE; i++) { + =A0 =A0 =A0 =A0 =A0 =A0 =A0 dev_dbg(vq->dev, "REM AVAIL %.2d: %.2d\n", + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 i, le16_to_=
cpu(vq->guest->avail[i]));
Quoted 11 lines
drivers/virtio/vop_fsl.c new file +8
-0+ =A0 =A0 =A0 } +} + +static void dump_rem_used (struct vop_vq *vq) +{ + =A0 =A0 =A0 int i; + + =A0 =A0 =A0 dev_dbg(vq->dev, "REM USED IDX %.2d\n", ioread16(&vq->host-=
used_idx));
+ =A0 =A0 =A0 for (i =3D 0; i <VOP_RING_SIZE; i++) {
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 dev_dbg(vq->dev, "REM USED %.2d: %.2d %.6d\=
n", i,
Quoted 1 line
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 ioread32(&v=
q->host->used[i].id),
Quoted 1 line
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 ioread32(&v=
q->host->used[i].len));
drivers/virtio/vop_fsl.c
Quoted 11 lines
+ =A0 =A0 =A0 }
drivers/virtio/vop_fsl.c new file +10
-0+} + +static void dump_rem_rings (struct vop_vq *vq) +{ + =A0 =A0 =A0 dump_rem_desc(vq); + =A0 =A0 =A0 dump_rem_avail(vq); + =A0 =A0 =A0 dump_rem_used(vq); +} + +/*----------------------------------------------------------------------=
------*/
Quoted 1 line
+/* Local Ring Debugging Helpers =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 */
Quoted 1 line
+/*----------------------------------------------------------------------=
------*/
drivers/virtio/vop_fsl.c
Quoted 7 lines
drivers/virtio/vop_fsl.c new file +7
-0+ +static void dump_loc_desc (struct vop_vq *vq) +{ + =A0 =A0 =A0 struct vop_loc_desc desc; + =A0 =A0 =A0 int i; + + =A0 =A0 =A0 dev_dbg(vq->dev, "LOC DESC 0xADDRESSX LENGTH 0xFLAG NEXT\n"=
);
Quoted 3 lines
+ =A0 =A0 =A0 for (i =3D 0 ; i <
VOP_RING_SIZE; i++) {
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0vop_loc_desc(vq, i, &desc);
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 dev_dbg(vq->dev, "DESC %.2d: 0x%.8x %.6d 0x=
%.4x %.2d\n",
Quoted 1 line
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 i, desc.add=
r, desc.len, desc.flags, desc.next);
drivers/virtio/vop_fsl.c
Quoted 10 lines
+ =A0 =A0 =A0 }
drivers/virtio/vop_fsl.c new file +9
-0+} + +static void dump_loc_avail(struct vop_vq *vq) +{ + =A0 =A0 =A0 int i; + + =A0 =A0 =A0 dev_dbg(vq->dev, "LOC AVAIL IDX %.2d\n", vq->avail.index); + =A0 =A0 =A0 for (i =3D 0; i < VOP_RING_SIZE; i++) + =A0 =A0 =A0 =A0 =A0 =A0 =A0 dev_dbg(vq->dev, "LOC AVAIL %.2d: %.2d\n", =
i, vq->avail.ring[i]);
drivers/virtio/vop_fsl.c
Quoted 9 lines
drivers/virtio/vop_fsl.c new file +9
-0+} + +static void dump_loc_used(struct vop_vq *vq) +{ + =A0 =A0 =A0 int i; + + =A0 =A0 =A0 dev_dbg(vq->dev, "LOC USED IDX %.2hu\n", vq->used.index); + =A0 =A0 =A0 for (i =3D 0; i < VOP_RING_SIZE; i++) { + =A0 =A0 =A0 =A0 =A0 =A0 =A0 dev_dbg(vq->dev, "LOC USED %.2d: %.2d %.6d\=
n", i,
Quoted 1 line
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 vq->used.ri=
ng[i].id, vq->used.ring[i].len);
Quoted 16 lines
+ =A0 =A0 =A0 }
drivers/virtio/vop_fsl.c new file +15
-0+} + +static void dump_loc_rings (struct vop_vq *vq) +{ + =A0 =A0 =A0 dump_loc_desc(vq); + =A0 =A0 =A0 dump_loc_avail(vq); + =A0 =A0 =A0 dump_loc_used(vq); +} + +static void debug_dump_rings (struct vop_vq *vq,const char *msg) +{ + =A0 =A0 =A0 dev_dbg(vq->dev, "\n"); + =A0 =A0 =A0 dev_dbg(vq->dev, "%s\n", msg); + =A0 =A0 =A0 dump_loc_rings(vq); + =A0 =A0 =A0 dump_rem_rings(vq);
drivers/virtio/vop_fsl.c
Quoted 10 lines
drivers/virtio/vop_fsl.c new file +10
-0+ =A0 =A0 =A0 dev_dbg(vq->dev, "\n"); +} +#else +static void debug_dump_rings (struct vop_vq *vq,const char *msg) +{ + =A0 =A0 =A0 /* Nothing */ +} +#endif + +/*----------------------------------------------------------------------=
------*/
Quoted 1 line
+/* Scatterlist DMA helpers =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0*/
Quoted 1 line
+/*----------------------------------------------------------------------=
------*/
drivers/virtio/vop_fsl.c
Quoted 10 lines
drivers/virtio/vop_fsl.c new file +10
-0+ +/* +* This function abuses some of the scatterlist code and implements +* dma_map_sg() in such a way that we don't need to keep the scatterlist +* around in order to unmap it. +* +* It is also designed to never merge scatterlist entries, which is +* never what we want for virtio. +* +* When it is time to unmap the buffer, you can use dma_unmap_single() t=
o
Quoted 5 lines
+ * unmap each entry in the chain. Get the address, length, and direction
+ * from the descriptors! (keep a local copy for speed)
+ */
+static int vop_dma_map_sg(struct device *dev, struct scatterlist sg[],
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 unsigned int out, unsig=
ned int in)
Quoted 4 lines
drivers/virtio/vop_fsl.c new file +4
-0+{ + =A0 =A0 =A0 dma_addr_t addr; + =A0 =A0 =A0 enum dma_data_direction dir; + =A0 =A0 =A0 struct scatterlist *start;
drivers/virtio/vop_fsl.c
Quoted 10 lines
drivers/virtio/vop_fsl.c new file +10
-0+ =A0 =A0 =A0 unsigned int i, failure; + + =A0 =A0 =A0 start =3D sg; + + =A0 =A0 =A0 for (i =3D 0; i < out + in; i++) { + + =A0 =A0 =A0 =A0 =A0 =A0 =A0 /* Check for scatterlist chaining abuse */ + =A0 =A0 =A0 =A0 =A0 =A0 =A0 BUG_ON(sg =3D=3D NULL); + + =A0 =A0 =A0 =A0 =A0 =A0 =A0 dir =3D (i < out) ? DMA_TO_DEVICE : DMA_FRO=
M_DEVICE;
Quoted 1 line
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 addr =3D dma_map_single(dev,
sg_virt(sg), s=
g->length, dir);
Quoted 6 lines
drivers/virtio/vop_fsl.c new file +6
-0+ + =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (dma_mapping_error(dev, addr)) + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 goto unwind; + + =A0 =A0 =A0 =A0 =A0 =A0 =A0 sg_dma_address(sg) =3D addr; + =A0 =A0 =A0 =A0 =A0 =A0 =A0 sg =3D sg_next(sg);
drivers/virtio/vop_fsl.c
Quoted 10 lines
drivers/virtio/vop_fsl.c new file +10
-0+ =A0 =A0 =A0 } + + =A0 =A0 =A0 return 0; + +unwind: + =A0 =A0 =A0 failure =3D i; + =A0 =A0 =A0 sg =3D start; + + =A0 =A0 =A0 for (i =3D 0; i < failure; i++) { + =A0 =A0 =A0 =A0 =A0 =A0 =A0 dir =3D (i < out) ? DMA_TO_DEVICE : DMA_FRO=
M_DEVICE;
Quoted 3 lines
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 addr =3D
sg_dma_address(sg);
+
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 dma_unmap_single(dev, addr,sg->length, dir=
);
drivers/virtio/vop_fsl.c
Quoted 7 lines
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 sg =3D
sg_next(sg);
+ =A0 =A0 =A0 }drivers/virtio/vop_fsl.c new file +5
-0+ + =A0 =A0 =A0 return -ENOMEM; +} + +/*----------------------------------------------------------------------=
------*/
Quoted 1 line
+/* DMA Helpers =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0*/
Quoted 1 line
+/*----------------------------------------------------------------------=
------*/
Quoted 4 lines
drivers/virtio/vop_fsl.c new file +4
-0+ +/* +* Transfer data between two physical addresses with DMA +*
drivers/virtio/vop_fsl.c
Quoted 10 lines
drivers/virtio/vop_fsl.c new file +10
-0+* NOTE: does not automatically unmap the src and dst addresses +* +* @chan the channel to use +* @dst the physical destination address +* @src the physical source address +* @len the length to transfer (in bytes) +* @return a valid cookie, or -ERRNO +*/ +static dma_cookie_t dma_async_memcpy_raw_to_raw(struct dma_chan *chan, + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0=
=A0 =A0 =A0 =A0 =A0dma_addr_t dst,
Quoted 1 line
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0=
=A0 =A0 =A0 =A0 =A0dma_addr_t src,
Quoted 1 line
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0=
=A0 =A0 =A0 =A0 =A0size_t len)
drivers/virtio/vop_fsl.c
Quoted 8 lines
drivers/virtio/vop_fsl.c new file +8
-0+{ + =A0 =A0 =A0 struct dma_device *dev =3D chan->device; + =A0 =A0 =A0 struct dma_async_tx_descriptor *tx; + =A0 =A0 =A0 enum dma_ctrl_flags flags; + =A0 =A0 =A0 dma_cookie_t cookie; + =A0 =A0 =A0 int cpu; + + =A0 =A0 =A0 flags =3D DMA_COMPL_SKIP_SRC_UNMAP | DMA_COMPL_SKIP_DEST_UN=
MAP;
Quoted 1 line
+ =A0 =A0 =A0 tx =3D dev->device_prep_dma_memcpy(chan, dst, src, len, fla=
gs);
Quoted 16 lines
+ =A0 =A0 =A0 if (!tx)
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 return-ENOMEM;drivers/virtio/vop_fsl.c new file +14
-0+ + =A0 =A0 =A0 tx->callback =3D NULL; + =A0 =A0 =A0 cookie =3D tx->tx_submit(tx); + + =A0 =A0 =A0 cpu =3D get_cpu(); + =A0 =A0 =A0 per_cpu_ptr(chan->local, cpu)->bytes_transferred +=3D len; + =A0 =A0 =A0 per_cpu_ptr(chan->local, cpu)->memcpy_count++; + =A0 =A0 =A0 put_cpu(); + + =A0 =A0 =A0 return cookie; +} + +/* +* Trigger an interrupt after all DMA issued up to this point
drivers/virtio/vop_fsl.c
Quoted 10 lines
drivers/virtio/vop_fsl.c new file +10
-0+* have been processed +* +* @chan the channel to use +* @callback the function to call (must not sleep) +* @data the data to send to the callback +* +* @return a valid cookie, or -ERRNO +*/ +static dma_cookie_t dma_async_interrupt(struct dma_chan *chan, + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0=
=A0 dma_async_tx_callback callback,
Quoted 1 line
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0=
=A0 void *data)
drivers/virtio/vop_fsl.c
Quoted 6 lines
drivers/virtio/vop_fsl.c new file +6
-0+{ + =A0 =A0 =A0 struct dma_device *dev =3D chan->device; + =A0 =A0 =A0 struct dma_async_tx_descriptor *tx; + + =A0 =A0 =A0 /* Set up the DMA */ + =A0 =A0 =A0 tx =3D dev->device_prep_dma_interrupt(chan, DMA_PREP_INTERR=
UPT);
drivers/virtio/vop_fsl.c
Quoted 10 lines
+ =A0 =A0 =A0 if (!tx)
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 return-ENOMEM;drivers/virtio/vop_fsl.c new file +8
-0+ + =A0 =A0 =A0 tx->callback =3D callback; + =A0 =A0 =A0 tx->callback_param =3D data; + + =A0 =A0 =A0 return tx->tx_submit(tx); +} + +/*----------------------------------------------------------------------=
------*/
Quoted 1 line
+/* DMA Resolver =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 */
Quoted 1 line
+/*----------------------------------------------------------------------=
------*/
drivers/virtio/vop_fsl.c
Quoted 5 lines
drivers/virtio/vop_fsl.c new file +5
-0+ +static void vop_remote_used_changed(struct vop_vq *vq) +{ + =A0 =A0 =A0 if (!(vop_get_host_flags(vq) & VOP_F_NO_INTERRUPT)) { + =A0 =A0 =A0 =A0 =A0 =A0 =A0 dev_dbg(vq->dev, "notifying the host (new b=
uffers in used)\n");
Quoted 1 line
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 iowrite32(vq->kick_val,
vq->immr+ ODR_OFFS=
ET);
drivers/virtio/vop_fsl.c
Quoted 7 lines
+ =A0 =A0 =A0 }
drivers/virtio/vop_fsl.c new file +6
-0+} + +static void vop_local_used_changed(struct vop_vq *vq) +{ + =A0 =A0 =A0 if (!(vq->flags & VOP_F_NO_INTERRUPT)) { + =A0 =A0 =A0 =A0 =A0 =A0 =A0 dev_dbg(vq->dev, "notifying self (new buffe=
rs in used)\n");
drivers/virtio/vop_fsl.c
Quoted 8 lines
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0
vq->vq.callback(&vq->vq);
+ =A0 =A0 =A0 }drivers/virtio/vop_fsl.c new file +6
-0+} + +/* +* DMA callback function for merged rxbufs +* +* This is called every time a DMA transfer completes, and will update t=
he
Quoted 1 line
+ * indices in the local and remote used rings, then notify both sides th=
at
Quoted 3 lines
+ * their used ring has changed
+ *
+ * You must be sure that the data was actually written to the used rings=
before
drivers/virtio/vop_fsl.c
Quoted 8 lines
+ * this function is called
+ */drivers/virtio/vop_fsl.c new file +6
-0+static void dma_callback (void *data) +{ + =A0 =A0 =A0 struct vop_dma_cbinfo *cb =3D data; + =A0 =A0 =A0 struct vop_vq *vq =3D cb->vq; + + =A0 =A0 =A0 dev_dbg(vq->dev, "%s: vq %p loc %d rem %d\n", __func__, vq,=
cb->loc, cb->rem);
drivers/virtio/vop_fsl.c
Quoted 9 lines
drivers/virtio/vop_fsl.c new file +9
-0+ + =A0 =A0 =A0 /* Write the local used index */ + =A0 =A0 =A0 vq->used.index +=3D cb->loc; + + =A0 =A0 =A0 /* Write the remote used index */ + =A0 =A0 =A0 vq->rem_last_used +=3D cb->rem; + =A0 =A0 =A0 iowrite16(vq->rem_last_used, &vq->host->used_idx); + + =A0 =A0 =A0 /* Make sure the indices are written before triggering call=
backs */
drivers/virtio/vop_fsl.c
Quoted 8 lines
+ =A0 =A0 =A0
wmb();drivers/virtio/vop_fsl.c new file +7
-0+ + =A0 =A0 =A0 /* Trigger the local used callback */ + =A0 =A0 =A0 dev_dbg(vq->dev, "local used changed, running callback\n"); + =A0 =A0 =A0 vop_local_used_changed(vq); + + =A0 =A0 =A0 /* Trigger the remote used callback */ + =A0 =A0 =A0 dev_dbg(vq->dev, "remote used changed, running callback\n")=
;
Quoted 8 lines
+ =A0 =A0 =A0
vop_remote_used_changed(vq);drivers/virtio/vop_fsl.c new file +7
-0+ + =A0 =A0 =A0 /* Free the callback data */ + =A0 =A0 =A0 kmem_cache_free(dma_cache, cb); +} + +/* +* Take an entry from the local avail ring and add it to the local
drivers/virtio/vop_fsl.c
Quoted 10 lines
drivers/virtio/vop_fsl.c new file +10
-0+* used ring with the given length +* +* NOTE: does not update the used index +* +* @vq the virtqueue +* @avail_idx the index in the avail ring to take the entry from +* @used_idx the index in the used ring to put the entry +* @used_len the length used +*/ +static void vop_loc_avail_to_used(struct vop_vq *vq, unsigned int avail_=
idx,
Quoted 1 line
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 unsigne=
d int used_idx, u32 used_len)
Quoted 17 lines
drivers/virtio/vop_fsl.c new file +17
-0+{ + =A0 =A0 =A0 u16 id; + + =A0 =A0 =A0 /* Make sure the indices are inside the rings */ + =A0 =A0 =A0 avail_idx &=3D (VOP_RING_SIZE - 1); + =A0 =A0 =A0 used_idx =A0&=3D (VOP_RING_SIZE - 1); + + =A0 =A0 =A0 /* Get the index stored in the avail ring */ + =A0 =A0 =A0 id =3D vq->avail.ring[avail_idx]; + + =A0 =A0 =A0 /* Copy the index and length to the used ring */ + =A0 =A0 =A0 vq->used.ring[used_idx].id =3D id; + =A0 =A0 =A0 vq->used.ring[used_idx].len =3D used_len; +} + +/* +* Take an entry from the remote avail ring and add it to the remote
drivers/virtio/vop_fsl.c
Quoted 10 lines
drivers/virtio/vop_fsl.c new file +10
-0+* used ring with the given length +* +* NOTE: does not update the used index +* +* @vq the virtqueue +* @avail_idx the index in the avail ring to take the entry from +* @used_idx the index in the used ring to put the entry +* @used_len the length used +*/ +static void vop_rem_avail_to_used(struct vop_vq *vq, unsigned int avail_=
idx,
Quoted 1 line
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 unsigne=
d int used_idx, u32 used_len)
Quoted 19 lines
drivers/virtio/vop_fsl.c new file +19
-0+{ + =A0 =A0 =A0 u16 id; + + =A0 =A0 =A0 /* Make sure the indices are inside the rings */ + =A0 =A0 =A0 avail_idx &=3D (VOP_RING_SIZE - 1); + =A0 =A0 =A0 used_idx =A0&=3D (VOP_RING_SIZE - 1); + + =A0 =A0 =A0 /* Get the index stored in the avail ring */ + =A0 =A0 =A0 id =3D le16_to_cpu(vq->guest->avail[avail_idx]); + + =A0 =A0 =A0 /* Copy the index and length to the used ring */ + =A0 =A0 =A0 iowrite32(id, &vq->host->used[used_idx].id); + =A0 =A0 =A0 iowrite32(used_len, &vq->host->used[used_idx].len); +} + +/* +* Return the number of entries available in the local avail ring +*/ +static unsigned int loc_num_avail (struct vop_vq *vq)
drivers/virtio/vop_fsl.c
Quoted 10 lines
drivers/virtio/vop_fsl.c new file +10
-0+{ + =A0 =A0 =A0 return vq->avail.index - vq->dma.loc_avail; +} + +/* +* Return the number of entries available in the remote avail ring +*/ +static unsigned int rem_num_avail (struct vop_vq *vq) +{ + =A0 =A0 =A0 return le16_to_cpu(vq->guest->avail_idx) - vq->dma.rem_avai=
l;
Quoted 17 lines
drivers/virtio/vop_fsl.c new file +17
-0+} + +/* +* Return a descriptor id from the local avail ring +* +* @vq the virtqueue +* @idx the index to return the id from +*/ +static u16 vop_loc_avail_id (struct vop_vq *vq,unsigned int idx) +{ + =A0 =A0 =A0 idx &=3D (VOP_RING_SIZE - 1); + =A0 =A0 =A0 return vq->avail.ring[idx]; +} + +/* +* Return a descriptor id from the remote avail ring +*
drivers/virtio/vop_fsl.c
Quoted 10 lines
drivers/virtio/vop_fsl.c new file +10
-0+* @vq the virtqueue +* @idx the index to return the id from +*/ +static u16 vop_rem_avail_id (struct vop_vq *vq,unsigned int idx) +{ + =A0 =A0 =A0 idx &=3D (VOP_RING_SIZE - 1); + =A0 =A0 =A0 return le16_to_cpu(vq->guest->avail[idx]); +} + +/*----------------------------------------------------------------------=
------*/
Quoted 1 line
+/* Extra helpers for mergeable DMA =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0*/
Quoted 1 line
+/*----------------------------------------------------------------------=
------*/
drivers/virtio/vop_fsl.c
Quoted 3 lines
drivers/virtio/vop_fsl.c new file +3
-0+ +/* +* TODO: the number of bytes being transmitted could be added to the ava=
il
Quoted 1 line
+ * TODO: ring, rather than just an index. I'm not sure it would make muc=
h
Quoted 71 lines
+ * TODO: difference, though.
+ */drivers/virtio/vop_fsl.c new file +69
-0+ +/* +* Calculate the number of bytes used in a local descriptor chain +* +* @vq the virtqueue +* @idx the start descriptor index +* @return the number of bytes +*/ +static unsigned int loc_num_bytes (struct vop_vq *vq,unsigned int idx) +{ + =A0 =A0 =A0 struct vop_loc_desc desc; + =A0 =A0 =A0 unsigned int bytes =3D 0; + + =A0 =A0 =A0 while (true) { + =A0 =A0 =A0 =A0 =A0 =A0 =A0 vop_loc_desc(vq, idx, &desc); + =A0 =A0 =A0 =A0 =A0 =A0 =A0 bytes +=3D desc.len; + + =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (!(desc.flags & VOP_DESC_F_NEXT)) + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 break; + + =A0 =A0 =A0 =A0 =A0 =A0 =A0 idx =3D desc.next; + =A0 =A0 =A0 } + + =A0 =A0 =A0 return bytes; +} + +/* +* Calculate the number of bytes used in a remote descriptor chain +* +* @vq the virtqueue +* @idx the start descriptor index +* @return the number of bytes +*/ +static unsigned int rem_num_bytes (struct vop_vq *vq,unsigned int idx) +{ + =A0 =A0 =A0 struct vop_loc_desc desc; + =A0 =A0 =A0 unsigned int bytes =3D 0; + + =A0 =A0 =A0 while (true) { + =A0 =A0 =A0 =A0 =A0 =A0 =A0 vop_rem_desc(vq, idx, &desc); + =A0 =A0 =A0 =A0 =A0 =A0 =A0 bytes +=3D desc.len; + + =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (!(desc.flags & VOP_DESC_F_NEXT)) + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 break; + + =A0 =A0 =A0 =A0 =A0 =A0 =A0 idx =3D desc.next; + =A0 =A0 =A0 } + + =A0 =A0 =A0 return bytes; +} + +/* +* Transmit the next local available entry to the remote side, splitting +* up the local descriptor as needed +* +* This routine makes the following assumptions: +* 1) The header already has the correct number of buffers set +* 2) The available buffers are all PAGE_SIZE +*/ +static int vop_dma_xmit (struct vop_vq *vq) +{ + =A0 =A0 =A0 struct vop_dma_info *dma =3D &vq->dma; + =A0 =A0 =A0 struct dma_chan *chan =3D dma->chan; + =A0 =A0 =A0 dma_cookie_t cookie; + + =A0 =A0 =A0 unsigned int loc_idx, rem_idx; + =A0 =A0 =A0 struct vop_loc_desc loc, rem; + + =A0 =A0 =A0 struct vop_dma_cbinfo *cb;
drivers/virtio/vop_fsl.c
Quoted 10 lines
drivers/virtio/vop_fsl.c new file +10
-0+ =A0 =A0 =A0 dma_addr_t src, dst; + =A0 =A0 =A0 size_t len; + + =A0 =A0 =A0 unsigned int loc_total =3D 0; + =A0 =A0 =A0 unsigned int rem_total =3D 0; + =A0 =A0 =A0 unsigned int bufs_used =3D 0; + + =A0 =A0 =A0 /* Check that there is a local descriptor available */ + =A0 =A0 =A0 if (!loc_num_avail(vq)) { + =A0 =A0 =A0 =A0 =A0 =A0 =A0 dev_dbg(vq->dev, "No local descriptors avai=
lable\n");
drivers/virtio/vop_fsl.c
Quoted 8 lines
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 return
-ENOSPC;
+ =A0 =A0 =A0 }drivers/virtio/vop_fsl.c new file +6
-0+ + =A0 =A0 =A0 /* Get the starting entry from each available ring */ + =A0 =A0 =A0 loc_idx =3D vop_loc_avail_id(vq, dma->loc_avail); + =A0 =A0 =A0 rem_idx =3D vop_rem_avail_id(vq, dma->rem_avail); + + =A0 =A0 =A0 dev_dbg(vq->dev, "rem_avail %d loc_num_bytes %d\n", rem_num=
_avail(vq), loc_num_bytes(vq, loc_idx));
Quoted 3 lines
+
+ =A0 =A0 =A0 /* Check that there are enough remote buffers available */
+ =A0 =A0 =A0 if (rem_num_avail(vq)*PAGE_SIZE< loc_num_bytes(vq, loc_i=
dx)) {
Quoted 1 line
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 dev_dbg(vq->dev, "Insufficient remote descr=
iptors available\n");
Quoted 7 lines
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 return
-ENOSPC;
+ =A0 =A0 =A0 }
+
+ =A0 =A0 =A0 /* Allocate DMA callback data */
+ =A0 =A0 =A0 cb =3Dkmem_cache_alloc(dma_cache, GFP_KERNEL);
+ =A0 =A0 =A0 if (!cb) {
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 dev_dbg(vq->dev, "Unable to allocate DMA ca=
llback data\n");
Quoted 4 lines
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 return
-ENOMEM;
+ =A0 =A0 =A0 }drivers/virtio/vop_fsl.c new file +2
-0+ + =A0 =A0 =A0 /* Load the starting descriptors */
drivers/virtio/vop_fsl.c
Quoted 10 lines
drivers/virtio/vop_fsl.c new file +10
-0+ =A0 =A0 =A0 vop_loc_desc(vq, loc_idx, &loc); + =A0 =A0 =A0 vop_rem_desc(vq, rem_idx, &rem); + + =A0 =A0 =A0 while (true) { + + =A0 =A0 =A0 =A0 =A0 =A0 =A0 dst =3D rem.addr + 0x80000000; + =A0 =A0 =A0 =A0 =A0 =A0 =A0 src =3D loc.addr; + =A0 =A0 =A0 =A0 =A0 =A0 =A0 len =3D min(loc.len, rem.len); + + =A0 =A0 =A0 =A0 =A0 =A0 =A0 dev_dbg(vq->dev, "DMA xmit dst %.8x src %.8=
x len %d\n", dst, src, len);
Quoted 1 line
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 cookie =3D dma_async_memcpy_raw_to_raw(chan=
, dst, src, len);
Quoted 2 lines
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (
dma_submit_error(cookie)) {
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 dev_err(vq->dev, "DMA submi=
t error\n");
drivers/virtio/vop_fsl.c
Quoted 12 lines
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 goto
out_free_cb;
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 }drivers/virtio/vop_fsl.c new file +10
-0+ + =A0 =A0 =A0 =A0 =A0 =A0 =A0 loc.len -=3D len; + =A0 =A0 =A0 =A0 =A0 =A0 =A0 rem.len -=3D len; + =A0 =A0 =A0 =A0 =A0 =A0 =A0 loc.addr +=3D len; + =A0 =A0 =A0 =A0 =A0 =A0 =A0 rem.addr +=3D len; + + =A0 =A0 =A0 =A0 =A0 =A0 =A0 loc_total +=3D len; + =A0 =A0 =A0 =A0 =A0 =A0 =A0 rem_total +=3D len; + + =A0 =A0 =A0 =A0 =A0 =A0 =A0 dev_dbg(vq->dev, "loc.len %d rem.len %d\n",=
loc.len, rem.len);
Quoted 1 line
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 dev_dbg(vq->dev, "loc.addr %.8x rem.addr %.=
8x\n", loc.addr, rem.addr);
Quoted 1 line
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 dev_dbg(vq->dev, "
loc_total%drem_total%d=
\n", loc_total, rem_total);
Quoted 3 lines
+
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (loc.len =3D=3D 0) {
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 dev_dbg(vq->dev, "local: de=
scriptor depleted, loading next\n");
Quoted 2 lines
+
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (!(loc.flags & VOP_DESC_=
F_NEXT)) {
Quoted 6 lines
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0
dev_dbg(vq-= dev, "local: no next descriptor, chain finished\n");
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 break;
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 }
+
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 dev_dbg(vq->dev, "local: fe=
tching next descriptor\n");
Quoted 2 lines
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0
loc_idx=3D loc.next;
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 vop_loc_desc(vq,loc_idx, &=
loc);
Quoted 4 lines
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 }
+
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (rem.len =3D=3D 0) {
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 dev_dbg(vq->dev, "remote: d=
escriptor depleted, adding to used\n");
Quoted 1 line
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 vop_rem_avail_to_used(vq, d=
ma->rem_avail + bufs_used, dma->rem_used + bufs_used, rem_total);
Quoted 3 lines
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 bufs_used++;
+
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 dev_dbg(vq->dev, "remote: f=
etching next descriptor\n");
Quoted 1 line
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0
rem_idx=3D vop_rem_avail_i=
d(vq, dma->rem_avail + bufs_used);
Quoted 1 line
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 vop_rem_desc(vq,
rem_idx, &=
rem);
Quoted 7 lines
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0
rem_total=3D 0;
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 }
+ =A0 =A0 =A0 }
+
+ =A0 =A0 =A0 /* Add the last remote descriptor to the used ring */
+ =A0 =A0 =A0BUG_ON(rem_total =3D=3D 0);
+ =A0 =A0 =A0 dev_dbg(vq->dev, "adding last remote descriptor to used rin=
g\n");
Quoted 1 line
+ =A0 =A0 =A0 vop_rem_avail_to_used(vq,
dma->rem_avail+bufs_used, dma->=
rem_used + bufs_used, rem_total);
Quoted 4 lines
+ =A0 =A0 =A0 bufs_used++;
+
+ =A0 =A0 =A0 /* Add the local descriptor to the sude ring */
+ =A0 =A0 =A0 dev_dbg(vq->dev, "adding only local descriptor to used ring=
\n");
Quoted 1 line
+ =A0 =A0 =A0 vop_loc_avail_to_used(vq,
dma->loc_avail,dma->loc_used, lo=
c_total);
Quoted 2 lines
+
+ =A0 =A0 =A0 /* Make very sure that everything written to the rings actu=
ally happened
drivers/virtio/vop_fsl.c
Quoted 9 lines
+ =A0 =A0 =A0 =A0* bofer the DMA callback can be triggered */
+ =A0 =A0 =A0wmb();drivers/virtio/vop_fsl.c new file +7
-0+ + =A0 =A0 =A0 /* Set up the DMA callback information */ + =A0 =A0 =A0 cb->vq =3D vq; + =A0 =A0 =A0 cb->loc =3D 1; + =A0 =A0 =A0 cb->rem =3D bufs_used; + + =A0 =A0 =A0 dev_dbg(vq->dev, "setup DMA callback vq %p loc %d rem %d\n"=
, vq, 1, bufs_used);
Quoted 2 lines
+
+ =A0 =A0 =A0 /* Trigger an interrupt when the DMA completes to update th=
e used
Quoted 4 lines
+ =A0 =A0 =A0 =A0* indices and trigger the necessary callbacks */
+ =A0 =A0 =A0 cookie =3Ddma_async_interrupt(chan, dma_callback, cb);
+ =A0 =A0 =A0 if (dma_submit_error(cookie)) {
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 dev_err(vq->dev, "DMA interrupt submit erro=
r\n");
Quoted 4 lines
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 goto
out_free_cb;
+ =A0 =A0 =A0 }
+
+ =A0 =A0 =A0 /* Everything was successful, so update the DMA resolver's =
state */
Quoted 34 lines
+ =A0 =A0 =A0 dma->loc_avail++;
+ =A0 =A0 =A0dma->rem_avail+=3Dbufs_used;
+ =A0 =A0 =A0 dma->loc_used++;
+ =A0 =A0 =A0dma->rem_used+=3Dbufs_used;drivers/virtio/vop_fsl.c new file +30
-0+ + =A0 =A0 =A0 /* Start the DMA */ + =A0 =A0 =A0 dev_dbg(vq->dev, "DMA xmit setup successful, starting\n"); + =A0 =A0 =A0 dma_async_memcpy_issue_pending(chan); + + =A0 =A0 =A0 return 0; + +out_free_cb: + =A0 =A0 =A0 kmem_cache_free(dma_cache, cb); + =A0 =A0 =A0 return -ENOMEM; +} + +/* +* Receive the next remote available entry to the local side, splitting +* up the remote descriptor as needed +* +* This routine makes the following assumptions: +* 1) The header already has the correct number of buffers set +* 2) The available buffers are all PAGE_SIZE +*/ +static int vop_dma_recv (struct vop_vq *vq) +{ + =A0 =A0 =A0 struct vop_dma_info *dma =3D &vq->dma; + =A0 =A0 =A0 struct dma_chan *chan =3D dma->chan; + =A0 =A0 =A0 dma_cookie_t cookie; + + =A0 =A0 =A0 unsigned int loc_idx, rem_idx; + =A0 =A0 =A0 struct vop_loc_desc loc, rem; + + =A0 =A0 =A0 struct vop_dma_cbinfo *cb;
drivers/virtio/vop_fsl.c
Quoted 10 lines
drivers/virtio/vop_fsl.c new file +10
-0+ =A0 =A0 =A0 dma_addr_t src, dst; + =A0 =A0 =A0 size_t len; + + =A0 =A0 =A0 unsigned int loc_total =3D 0; + =A0 =A0 =A0 unsigned int rem_total =3D 0; + =A0 =A0 =A0 unsigned int bufs_used =3D 0; + + =A0 =A0 =A0 /* Check that there is a remote descriptor available */ + =A0 =A0 =A0 if (!rem_num_avail(vq)) { + =A0 =A0 =A0 =A0 =A0 =A0 =A0 dev_dbg(vq->dev, "No remote descriptors ava=
ilable\n");
drivers/virtio/vop_fsl.c
Quoted 9 lines
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 return
-ENOSPC;
+ =A0 =A0 =A0 }drivers/virtio/vop_fsl.c new file +7
-0+ + =A0 =A0 =A0 /* Get the starting entry from each available ring */ + =A0 =A0 =A0 loc_idx =3D vop_loc_avail_id(vq, dma->loc_avail); + =A0 =A0 =A0 rem_idx =3D vop_rem_avail_id(vq, dma->rem_avail); + + =A0 =A0 =A0 /* Check that there are enough local buffers available */ + =A0 =A0 =A0 if (loc_num_avail(vq) * PAGE_SIZE < rem_num_bytes(vq, rem_i=
dx)) {
Quoted 1 line
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 dev_dbg(vq->dev, "Insufficient local descri=
ptors available\n");
Quoted 7 lines
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 return
-ENOSPC;
+ =A0 =A0 =A0 }
+
+ =A0 =A0 =A0 /* Allocate DMA callback data */
+ =A0 =A0 =A0 cb =3Dkmem_cache_alloc(dma_cache, GFP_KERNEL);
+ =A0 =A0 =A0 if (!cb) {
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 dev_dbg(vq->dev, "Unable to allocate DMA ca=
llback data\n");
Quoted 4 lines
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 return
-ENOMEM;
+ =A0 =A0 =A0 }drivers/virtio/vop_fsl.c new file +2
-0+ + =A0 =A0 =A0 /* Load the starting descriptors */
drivers/virtio/vop_fsl.c
Quoted 10 lines
drivers/virtio/vop_fsl.c new file +10
-0+ =A0 =A0 =A0 vop_loc_desc(vq, loc_idx, &loc); + =A0 =A0 =A0 vop_rem_desc(vq, rem_idx, &rem); + + =A0 =A0 =A0 while (true) { + + =A0 =A0 =A0 =A0 =A0 =A0 =A0 dst =3D loc.addr; + =A0 =A0 =A0 =A0 =A0 =A0 =A0 src =3D rem.addr + 0x80000000; + =A0 =A0 =A0 =A0 =A0 =A0 =A0 len =3D min(loc.len, rem.len); + + =A0 =A0 =A0 =A0 =A0 =A0 =A0 dev_dbg(vq->dev, "DMA recv dst %.8x src %.8=
x len %d\n", dst, src, len);
Quoted 1 line
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 cookie =3D dma_async_memcpy_raw_to_raw(chan=
, dst, src, len);
Quoted 2 lines
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (
dma_submit_error(cookie)) {
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 dev_err(vq->dev, "DMA submi=
t error\n");
drivers/virtio/vop_fsl.c
Quoted 13 lines
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 goto
out_free_cb;
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 }drivers/virtio/vop_fsl.c new file +11
-0+ + =A0 =A0 =A0 =A0 =A0 =A0 =A0 loc.len -=3D len; + =A0 =A0 =A0 =A0 =A0 =A0 =A0 rem.len -=3D len; + =A0 =A0 =A0 =A0 =A0 =A0 =A0 loc.addr +=3D len; + =A0 =A0 =A0 =A0 =A0 =A0 =A0 rem.addr +=3D len; + + =A0 =A0 =A0 =A0 =A0 =A0 =A0 loc_total +=3D len; + =A0 =A0 =A0 =A0 =A0 =A0 =A0 rem_total +=3D len; + + =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (rem.len =3D=3D 0) { + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (!(rem.flags & VOP_DESC_=
F_NEXT))
Quoted 4 lines
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 break; +
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0rem_idx=3D rem.next;
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 vop_rem_desc(vq,rem_idx, &=
rem);
Quoted 4 lines
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 }
+
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (loc.len =3D=3D 0) {
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 vop_loc_avail_to_used(vq, d=
ma->loc_avail + bufs_used, dma->loc_used + bufs_used, loc_total);
Quoted 3 lines
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 bufs_used++;
+
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0loc_idx=3D vop_loc_avail_i=
d(vq, dma->loc_avail + bufs_used);
Quoted 1 line
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 vop_loc_desc(vq,
loc_idx, &=
loc);
Quoted 7 lines
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0
loc_total=3D 0;
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 }
+ =A0 =A0 =A0 }
+
+ =A0 =A0 =A0 /* Add the last local descriptor to the used ring */
+ =A0 =A0 =A0BUG_ON(loc_total =3D=3D 0);
+ =A0 =A0 =A0 vop_loc_avail_to_used(vq,dma->loc_avail+bufs_used, dma->=
loc_used + bufs_used, loc_total);
Quoted 4 lines
+ =A0 =A0 =A0 bufs_used++;
+
+ =A0 =A0 =A0 /* Add the remote descriptor to the used ring */
+ =A0 =A0 =A0 vop_rem_avail_to_used(vq,dma->rem_avail,dma->rem_used, re=
m_total);
Quoted 2 lines
+
+ =A0 =A0 =A0 /* Make very sure that everything written to the rings actu=
ally happened
drivers/virtio/vop_fsl.c
Quoted 9 lines
+ =A0 =A0 =A0 =A0* before the DMA callback can be triggered */
+ =A0 =A0 =A0wmb();drivers/virtio/vop_fsl.c new file +7
-0+ + =A0 =A0 =A0 /* Set up the DMA callback information */ + =A0 =A0 =A0 cb->vq =3D vq; + =A0 =A0 =A0 cb->loc =3D bufs_used; + =A0 =A0 =A0 cb->rem =3D 1; + + =A0 =A0 =A0 /* Trigger an interrupt when the DMA completes to update th=
e used
Quoted 4 lines
+ =A0 =A0 =A0 =A0* indices and trigger the necessary callbacks */
+ =A0 =A0 =A0 cookie =3Ddma_async_interrupt(chan, dma_callback, cb);
+ =A0 =A0 =A0 if (dma_submit_error(cookie)) {
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 dev_err(vq->dev, "DMA interrupt submit erro=
r\n");
Quoted 4 lines
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 goto
out_free_cb;
+ =A0 =A0 =A0 }
+
+ =A0 =A0 =A0 /* Everything was successful, so update the DMA resolver's =
state */
Quoted 7 lines
+ =A0 =A0 =A0
dma->loc_avail+=3Dbufs_used;
+ =A0 =A0 =A0 dma->rem_avail++;
+ =A0 =A0 =A0dma->loc_used+=3Dbufs_used;
+ =A0 =A0 =A0 dma->rem_used++;drivers/virtio/vop_fsl.c new file +3
-0+ + =A0 =A0 =A0 /* Start the DMA */ + =A0 =A0 =A0 dev_dbg(vq->dev, "DMA recv setup successful, starting\n");
drivers/virtio/vop_fsl.c
Quoted 10 lines
drivers/virtio/vop_fsl.c new file +10
-0+ =A0 =A0 =A0 dma_async_memcpy_issue_pending(chan); + + =A0 =A0 =A0 return 0; + +out_free_cb: + =A0 =A0 =A0 kmem_cache_free(dma_cache, cb); + =A0 =A0 =A0 return -ENOMEM; +} + +/*----------------------------------------------------------------------=
------*/
Quoted 1 line
+/* Virtqueue Ops Infrastructure =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 */
Quoted 1 line
+/*----------------------------------------------------------------------=
------*/
drivers/virtio/vop_fsl.c
Quoted 3 lines
drivers/virtio/vop_fsl.c new file +3
-0+ +/* +* Modify the struct virtio_net_hdr_mrg_rxbuf's num_buffers field to acc=
ount
Quoted 5 lines
+ * for the split that will happen in the DMA xmit routine
+ *
+ * This assumes that both sides have the samePAGE_SIZE
+ */
+static void vop_fixup_vnet_mrg_hdr(struct scatterlist sg[], unsigned int=
out)
drivers/virtio/vop_fsl.c
Quoted 10 lines
drivers/virtio/vop_fsl.c new file +10
-0+{ + =A0 =A0 =A0 struct virtio_net_hdr *hdr; + =A0 =A0 =A0 struct virtio_net_hdr_mrg_rxbuf *mhdr; + =A0 =A0 =A0 unsigned int bytes =3D 0; + + =A0 =A0 =A0 /* There must be a header + data, at the least */ + =A0 =A0 =A0 BUG_ON(out < 2); + + =A0 =A0 =A0 /* The first entry must be the structure */ + =A0 =A0 =A0 BUG_ON(sg->length !=3D sizeof(struct virtio_net_hdr_mrg_rxb=
uf));
drivers/virtio/vop_fsl.c
Quoted 5 lines
drivers/virtio/vop_fsl.c new file +5
-0+ + =A0 =A0 =A0 hdr =3D sg_virt(sg); + =A0 =A0 =A0 mhdr =3D sg_virt(sg); + + =A0 =A0 =A0 /* We merge buffers together, so just count up the number o=
f bytes
Quoted 5 lines
+ =A0 =A0 =A0 =A0* needed, then figure out how many pages that will be */
+ =A0 =A0 =A0 for (/* none */; out; out--, sg =3Dsg_next(sg))
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 bytes +=3Dsg->length;
+
+ =A0 =A0 =A0 /* Of course, nobody ever imagined that we might actually u=
se
Quoted 3 lines
+ =A0 =A0 =A0 =A0* this on machines with different endianness...
+ =A0 =A0 =A0 =A0*
+ =A0 =A0 =A0 =A0* We force little-endian for now, since that's what our =
host is */
Quoted 1 line
+ =A0 =A0 =A0
mhdr->num_buffers=3D cpu_to_le16(DIV_ROUND_UP(bytes, PAGE_=
SIZE));
Quoted 2 lines
+
+ =A0 =A0 =A0 /* Might as well fix up the other fields while we're at it =
*/
Quoted 6 lines
+ =A0 =A0 =A0
hdr->hdr_len=3Dcpu_to_le16(hdr->hdr_len);
+ =A0 =A0 =A0hdr->gso_size=3Dcpu_to_le16(hdr->gso_size);
+ =A0 =A0 =A0hdr->csum_start=3Dcpu_to_le16(hdr->csum_start);
+ =A0 =A0 =A0hdr->csum_offset=3Dcpu_to_le16(hdr->csum_offset);drivers/virtio/vop_fsl.c new file +2
-0+} +
drivers/virtio/vop_fsl.c
Quoted 10 lines
drivers/virtio/vop_fsl.c new file +10
-0+/* +* Add a buffer to our local descriptors and the local avail ring +* +* NOTE: there hasn't been any transfer yet, just adding to local +* NOTE: rings. The kick() will process any DMA that needs to happen +* +* @return 0 on success, -ERRNO otherwise +*/ +static int vop_add_buf(struct virtqueue *_vq, struct scatterlist sg[], + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0unsigned int out, unsigned i=
nt in, void *data)
Quoted 2 lines
+{
+ =A0 =A0 =A0 /* For now, we'll just add the buffers to our local descrip=
tors and
drivers/virtio/vop_fsl.c
Quoted 10 lines
+ =A0 =A0 =A0 =A0* avail ring */
+ =A0 =A0 =A0 structvop_vq*vq =3Dto_vop_vq(_vq);
+ =A0 =A0 =A0 unsigned int i, avail, head,uninitialized_var(prev);drivers/virtio/vop_fsl.c new file +7
-0+ + =A0 =A0 =A0 BUG_ON(data =3D=3D NULL); + =A0 =A0 =A0 BUG_ON(out + in =3D=3D 0); + + =A0 =A0 =A0 /* Make sure we have space for this to succeed */ + =A0 =A0 =A0 if (vq->num_free < out + in) { + =A0 =A0 =A0 =A0 =A0 =A0 =A0 dev_dbg(vq->dev, "No free space left: len=
=3D%d free=3D%d\n",
Quoted 1 line
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 out + in, v=
q->num_free);
Quoted 4 lines
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 return
-ENOSPC;
+ =A0 =A0 =A0 }
+
+ =A0 =A0 =A0 /* If this is an xmit buffer fromvirtio_net, fixup the hea=
der */
Quoted 2 lines
+ =A0 =A0 =A0 if (out > 1) {
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 dev_dbg(vq->dev, "Fixing upvirtio_nethead=
er\n");
drivers/virtio/vop_fsl.c
Quoted 8 lines
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0
vop_fixup_vnet_mrg_hdr(sg, out);
+ =A0 =A0 =A0 }drivers/virtio/vop_fsl.c new file +6
-0+ + =A0 =A0 =A0 head =3D vq->free_head; + + =A0 =A0 =A0 /* DMA map the scatterlist */ + =A0 =A0 =A0 if (vop_dma_map_sg(vq->dev, sg, out, in)) { + =A0 =A0 =A0 =A0 =A0 =A0 =A0 dev_err(vq->dev, "Failed to DMA map scatter=
list\n");
drivers/virtio/vop_fsl.c
Quoted 7 lines
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 return
-ENOMEM;
+ =A0 =A0 =A0 }drivers/virtio/vop_fsl.c new file +5
-0+ + =A0 =A0 =A0 /* We're about to use some buffers from the free list */ + =A0 =A0 =A0 vq->num_free -=3D out + in; + + =A0 =A0 =A0 for (i =3D vq->free_head; out; i =3D vop_get_desc_next(vq, =
i), out--) {
Quoted 2 lines
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0
vop_set_desc_flags(vq, i, VOP_DESC_F_NEXT);
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 vop_set_desc_addr(vq, i, sg_dma_address(sg)=
);
drivers/virtio/vop_fsl.c
Quoted 7 lines
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0
vop_set_desc_len(vq, i, sg->length);drivers/virtio/vop_fsl.c new file +6
-0+ + =A0 =A0 =A0 =A0 =A0 =A0 =A0 prev =3D i; + =A0 =A0 =A0 =A0 =A0 =A0 =A0 sg =3D sg_next(sg); + =A0 =A0 =A0 } + + =A0 =A0 =A0 for (/* none */; in; i =3D vop_get_desc_next(vq, i), in--) =
{
Quoted 1 line
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 vop_set_desc_flags(vq, i,
VOP_DESC_F_NEXT|=
VOP_DESC_F_WRITE);
Quoted 1 line
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 vop_set_desc_addr(vq, i, sg_dma_address(sg)=
);
drivers/virtio/vop_fsl.c
Quoted 8 lines
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0
vop_set_desc_len(vq, i, sg->length);drivers/virtio/vop_fsl.c new file +7
-0+ + =A0 =A0 =A0 =A0 =A0 =A0 =A0 prev =3D i; + =A0 =A0 =A0 =A0 =A0 =A0 =A0 sg =3D sg_next(sg); + =A0 =A0 =A0 } + + =A0 =A0 =A0 /* Last one doesn't continue */ + =A0 =A0 =A0 vop_set_desc_flags(vq, prev, vop_get_desc_flags(vq, prev) &=
~VOP_DESC_F_NEXT);
drivers/virtio/vop_fsl.c
Quoted 8 lines
drivers/virtio/vop_fsl.c new file +8
-0+ + =A0 =A0 =A0 /* Update the free pointer */ + =A0 =A0 =A0 vq->free_head =3D i; + + =A0 =A0 =A0 /* Set token */ + =A0 =A0 =A0 vq->data[head] =3D data; + + =A0 =A0 =A0 /* Add an entry for the head of the chain into the avail ar=
ray, but
Quoted 2 lines
+ =A0 =A0 =A0 =A0* don't update
avail->idxuntilkick()*/
+ =A0 =A0 =A0 avail =3D (vq->avail.index+ vq->num_added++) & (VOP_RING_S=
IZE - 1);
Quoted 14 lines
+ =A0 =A0 =A0 vq->avail.ring[avail] =3D head;
drivers/virtio/vop_fsl.c new file +13
-0+ + =A0 =A0 =A0 dev_dbg(vq->dev, "Added buffer head %i to %p\n", head, vq); + =A0 =A0 =A0 debug_dump_rings(vq, "Added buffer(s), dumping rings"); + + =A0 =A0 =A0 return 0; +} + +static inline bool loc_more_used (const struct vop_vq *vq) +{ + =A0 =A0 =A0 return vq->loc_last_used !=3D vq->used.index; +} + +static void detach_buf (struct vop_vq *vq,unsigned int head)
drivers/virtio/vop_fsl.c
Quoted 10 lines
drivers/virtio/vop_fsl.c new file +10
-0+{ + =A0 =A0 =A0 dma_addr_t addr; + =A0 =A0 =A0 unsigned int idx, len; + =A0 =A0 =A0 enum dma_data_direction dir; + =A0 =A0 =A0 struct vop_loc_desc desc; + + =A0 =A0 =A0 /* Clear data pointer */ + =A0 =A0 =A0 vq->data[head] =3D NULL; + + =A0 =A0 =A0 /* Put the chain back on the free list, unmapping as we go =
*/
Quoted 7 lines
+ =A0 =A0 =A0 idx =3D head;
+ =A0 =A0 =A0 while (true) {
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0vop_loc_desc(vq, idx, &desc);
+
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 addr =3D desc.addr;
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 len =A0=3D desc.len;
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 dir =A0=3D (desc.flags &VOP_DESC_F_WRITE) =
? DMA_FROM_DEVICE : DMA_TO_DEVICE;
drivers/virtio/vop_fsl.c
Quoted 6 lines
drivers/virtio/vop_fsl.c new file +6
-0+ + =A0 =A0 =A0 =A0 =A0 =A0 =A0 /* Unmap the entry */ + =A0 =A0 =A0 =A0 =A0 =A0 =A0 dma_unmap_single(vq->dev, addr, len, dir); + =A0 =A0 =A0 =A0 =A0 =A0 =A0 vq->num_free++; + + =A0 =A0 =A0 =A0 =A0 =A0 =A0 /* If there is no next descriptor, we're do=
ne */
Quoted 14 lines
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (!(desc.flags &
VOP_DESC_F_NEXT))
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 break;drivers/virtio/vop_fsl.c new file +12
-0+ + =A0 =A0 =A0 =A0 =A0 =A0 =A0 idx =3D desc.next; + =A0 =A0 =A0 } + + =A0 =A0 =A0 vop_set_desc_next(vq, idx, vq->free_head); + =A0 =A0 =A0 vq->free_head =3D head; +} + +/* +* Get a buffer from the used ring +* +* @return the data token given to add_buf(), or NULL if there
drivers/virtio/vop_fsl.c
Quoted 10 lines
drivers/virtio/vop_fsl.c new file +10
-0+ * =A0 =A0 =A0 =A0 are no remaining buffers + */ +static void *vop_get_buf(struct virtqueue *_vq, unsigned int *len) +{ + =A0 =A0 =A0 struct vop_vq *vq =3D to_vop_vq(_vq); + =A0 =A0 =A0 unsigned int head, used; + =A0 =A0 =A0 void *ret; + + =A0 =A0 =A0 if (!loc_more_used(vq)) { + =A0 =A0 =A0 =A0 =A0 =A0 =A0 dev_dbg(vq->dev, "No more buffers in queue\=
n");
Quoted 18 lines
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 return NULL;
+ =A0 =A0 =A0 }drivers/virtio/vop_fsl.c new file +16
-0+ + =A0 =A0 =A0 used =3D vq->loc_last_used & (VOP_RING_SIZE - 1); + =A0 =A0 =A0 head =3D vq->used.ring[used].id; + =A0 =A0 =A0 *len =3D vq->used.ring[used].len; + + =A0 =A0 =A0 BUG_ON(head >=3D VOP_RING_SIZE); + =A0 =A0 =A0 BUG_ON(!vq->data[head]); + + =A0 =A0 =A0 /* detach_buf() clears data, save it now */ + =A0 =A0 =A0 ret =3D vq->data[head]; + =A0 =A0 =A0 detach_buf(vq, head); + + =A0 =A0 =A0 /* Update the last local used_idx */ + =A0 =A0 =A0 vq->loc_last_used++; + + =A0 =A0 =A0 return ret;
drivers/virtio/vop_fsl.c
Quoted 10 lines
drivers/virtio/vop_fsl.c new file +10
-0+} + +/* +* The avail ring changed, so we need to start as much DMA as we can +*/ +static void vop_kick (struct virtqueue *_vq) +{ + =A0 =A0 =A0 struct vop_vq *vq =3D to_vop_vq(_vq); + + =A0 =A0 =A0 dev_dbg(vq->dev, "kick: making %d new buffers available\n",=
vq->num_added);
Quoted 5 lines
+ =A0 =A0 =A0
vq->avail.index+=3Dvq->num_added;
+ =A0 =A0 =A0vq->num_added=3D 0;
+
+ =A0 =A0 =A0 /* Run the DMA resolver */
+ =A0 =A0 =A0dev_dbg(vq->dev, "kick: using resolver %pS\n", vq->resolve)=
;
Quoted 6 lines
+ =A0 =A0 =A0
schedule_work(&vq->work);drivers/virtio/vop_fsl.c new file +5
-0+} + +/* +* Try to disable callbacks on the used ring (unreliable) +*/
drivers/virtio/vop_fsl.c
Quoted 10 lines
drivers/virtio/vop_fsl.c new file +10
-0+static void vop_disable_cb (struct virtqueue *_vq) +{ + =A0 =A0 =A0 struct vop_vq *vq =3D to_vop_vq(_vq); + =A0 =A0 =A0 struct virtio_device *vdev =3D _vq->vdev; + + =A0 =A0 =A0 dev_dbg(&vdev->dev, "disable callbacks\n"); + =A0 =A0 =A0 vq->flags =3D VOP_F_NO_INTERRUPT; +#if 0 + =A0 =A0 =A0 /* +=A0 =A0 =A0 =A0* FIXME: using this causes the host -> guest transfer ra=
te to
Quoted 1 line
+ =A0 =A0 =A0 =A0* FIXME: intermittently slow to 1/10th of the normal rat=
e
Quoted 12 lines
+ =A0 =A0 =A0 =A0*/
+ =A0 =A0 =A0vop_set_guest_flags(vq, vq->flags);drivers/virtio/vop_fsl.c new file +10
-0+#endif +} + +/* +* Enable callbacks on changes to the used ring +* +* @return false if there are more pending buffers +* =A0 =A0 =A0 =A0 true otherwise +*/ +static bool vop_enable_cb (struct virtqueue *_vq)
drivers/virtio/vop_fsl.c
Quoted 10 lines
drivers/virtio/vop_fsl.c new file +10
-0+{ + =A0 =A0 =A0 struct vop_vq *vq =3D to_vop_vq(_vq); + + =A0 =A0 =A0 /* We optimistically enable interrupts, then check if there +=A0 =A0 =A0 =A0* was more work to do */ + =A0 =A0 =A0 dev_dbg(vq->dev, "enable callbacks\n"); + =A0 =A0 =A0 vq->flags =3D 0; +#if 0 + =A0 =A0 =A0 /* +=A0 =A0 =A0 =A0* FIXME: using this causes the host -> guest transfer ra=
te to
Quoted 1 line
+ =A0 =A0 =A0 =A0* FIXME: intermittently slow to 1/10th of the normal rat=
e
Quoted 9 lines
+ =A0 =A0 =A0 =A0*/
+ =A0 =A0 =A0vop_set_guest_flags(vq, vq->flags);drivers/virtio/vop_fsl.c new file +7
-0+#endif + + =A0 =A0 =A0 if (unlikely(loc_more_used(vq))) + =A0 =A0 =A0 =A0 =A0 =A0 =A0 return false; + + =A0 =A0 =A0 return true; +}
drivers/virtio/vop_fsl.c
Quoted 10 lines
drivers/virtio/vop_fsl.c new file +10
-0+ +static struct virtqueue_ops vop_vq_ops =3D { + =A0 =A0 =A0 .add_buf =A0 =A0 =A0 =A0=3D vop_add_buf, + =A0 =A0 =A0 .get_buf =A0 =A0 =A0 =A0=3D vop_get_buf, + =A0 =A0 =A0 .kick =A0 =A0 =A0 =A0 =A0 =3D vop_kick, + =A0 =A0 =A0 .disable_cb =A0 =A0 =3D vop_disable_cb, + =A0 =A0 =A0 .enable_cb =A0 =A0 =A0=3D vop_enable_cb, +}; + +/*----------------------------------------------------------------------=
------*/
Quoted 1 line
+/* Virtio Device Infrastructure =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 */
Quoted 1 line
+/*----------------------------------------------------------------------=
------*/
drivers/virtio/vop_fsl.c
Quoted 3 lines
drivers/virtio/vop_fsl.c new file +3
-0+ +/* Read some bytes from the host's configuration area */ +static void vopc_get(struct virtio_device *_vdev, unsigned offset, void =
*buf,
Quoted 16 lines
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0unsigned len)
drivers/virtio/vop_fsl.c new file +15
-0+{ + =A0 =A0 =A0 struct vop_vdev *vdev =3D to_vop_vdev(_vdev); + =A0 =A0 =A0 void __iomem *config =3D vdev->host_status->config; + + =A0 =A0 =A0 memcpy_fromio(buf, config + offset, len); +} + +/* Write some bytes to the host's configuration area */ +static void vopc_set(struct virtio_device *_vdev, unsigned offset, + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0const void *buf, unsigned len) +{ + =A0 =A0 =A0 struct vop_vdev *vdev =3D to_vop_vdev(_vdev); + =A0 =A0 =A0 void __iomem *config =3D vdev->host_status->config; + + =A0 =A0 =A0 memcpy_toio(config + offset, buf, len);
drivers/virtio/vop_fsl.c
Quoted 10 lines
drivers/virtio/vop_fsl.c new file +10
-0+} + +/* Read your own status bits */ +static u8 vopc_get_status (struct virtio_device *_vdev) +{ + =A0 =A0 =A0 struct vop_vdev *vdev =3D to_vop_vdev(_vdev); + =A0 =A0 =A0 u32 status; + + =A0 =A0 =A0 status =3D le32_to_cpu(vdev->guest_status->status); + =A0 =A0 =A0 dev_dbg(&vdev->vdev.dev, "%s(): -> 0x%.2x\n", __func__, (u8=
)status);
Quoted 4 lines
drivers/virtio/vop_fsl.c new file +4
-0+ + =A0 =A0 =A0 return (u8)status; +} +
drivers/virtio/vop_fsl.c
Quoted 10 lines
drivers/virtio/vop_fsl.c new file +10
-0+static void vopc_set_status (struct virtio_device *_vdev,u8 status) +{ + =A0 =A0 =A0 struct vop_vdev *vdev =3D to_vop_vdev(_vdev); + =A0 =A0 =A0 u32 old_status; + + =A0 =A0 =A0 old_status =3D le32_to_cpu(vdev->guest_status->status); + =A0 =A0 =A0 vdev->guest_status->status =3D cpu_to_le32(status); + + =A0 =A0 =A0 dev_dbg(&vdev->vdev.dev, "%s(): <- 0x%.2x (was 0x%.2x)\n", + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 __func__, status, old_statu=
s);
Quoted 3 lines
+
+ =A0 =A0 =A0 /*
+ =A0 =A0 =A0 =A0* FIXME: we really need to notify the other side when st=
atus changes
Quoted 5 lines
+ =A0 =A0 =A0 =A0* FIXME: happen, so that they can take some action
+ =A0 =A0 =A0 =A0*/drivers/virtio/vop_fsl.c new file +3
-0+} + +static void vopc_reset (struct virtio_device *_vdev)
drivers/virtio/vop_fsl.c
Quoted 10 lines
drivers/virtio/vop_fsl.c new file +10
-0+{ + =A0 =A0 =A0 struct vop_vdev *vdev =3D to_vop_vdev(_vdev); + + =A0 =A0 =A0 dev_dbg(&vdev->vdev.dev, "%s(): status reset\n", __func__); + =A0 =A0 =A0 vdev->guest_status->status =3D cpu_to_le32(0); +} + +/* Find the given virtqueue */ +static struct virtqueue *vopc_find_vq(struct virtio_device *_vdev, + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0=
=A0 =A0 =A0 =A0unsigned index,
Quoted 1 line
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0=
=A0 =A0 =A0 =A0void (*cb)(struct virtqueue *vq))
drivers/virtio/vop_fsl.c
Quoted 8 lines
drivers/virtio/vop_fsl.c new file +8
-0+{ + =A0 =A0 =A0 struct vop_vdev *vdev =3D to_vop_vdev(_vdev); + =A0 =A0 =A0 struct vop_vq *vq =3D &vdev->virtqueues[index]; + =A0 =A0 =A0 int i; + + =A0 =A0 =A0 /* Check that we support the virtqueue at this index */ + =A0 =A0 =A0 if (index >=3D ARRAY_SIZE(vdev->virtqueues)) { + =A0 =A0 =A0 =A0 =A0 =A0 =A0 dev_err(&vdev->vdev.dev, "no virtqueue for =
index %d\n", index);
Quoted 6 lines
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 return
ERR_PTR(-ENODEV);
+ =A0 =A0 =A0 }
+
+ =A0 =A0 =A0 /* HACK: we only supportvirtio_netfor now */
+ =A0 =A0 =A0 if (vdev->vdev.id.device!=3DVIRTIO_ID_NET) {
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 dev_err(&vdev->vdev.dev, "onlyvirtio_neti=
s supported\n");
drivers/virtio/vop_fsl.c
Quoted 9 lines
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 return
ERR_PTR(-ENODEV);
+ =A0 =A0 =A0 }drivers/virtio/vop_fsl.c new file +7
-0+ + =A0 =A0 =A0 /* Initialize the virtqueue to a clean state */ + =A0 =A0 =A0 vq->num_free =3D VOP_RING_SIZE; + =A0 =A0 =A0 vq->dev =3D &vdev->vdev.dev; + =A0 =A0 =A0 vq->vq.vq_ops =3D &vop_vq_ops; + + =A0 =A0 =A0 /* Hook up the local virtqueues to the corresponding remote=
virtqueues */
Quoted 1 line
+ =A0 =A0 =A0 /* TODO: maybe move this to the
setup_virtio_net()function=
*/
Quoted 2 lines
+ =A0 =A0 =A0 switch (index) {
+ =A0 =A0 =A0 case 0: /* x86 xmit virtqueue, hook to ppc recv virtqueue *=
/
Quoted 6 lines
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0
vq->guest=3Dvdev->loc+ 2048;
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0vq->host=A0=3Dvdev->rem+ 2048;
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0vq->resolve=3Dvop_dma_recv;
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0vq->kick_val=3D0x8;
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 break;
+ =A0 =A0 =A0 case 1: /* x86 recv virtqueue, hook to ppc xmit virtqueue *=
/
Quoted 8 lines
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0
vq->guest=3Dvdev->loc+ 1024;
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0vq->host=A0=3Dvdev->rem+ 1024;
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0vq->resolve=3Dvop_dma_xmit;
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0vq->kick_val=3D0x4;
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 break;
+ =A0 =A0 =A0 case 2: /* x86 ctrl virtqueue -- ppc ctrl virtqueue */
+ =A0 =A0 =A0 default:
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0dev_err(vq->dev, "Unsupported virtqueue\n")=
;
Quoted 4 lines
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 return
ERR_PTR(-ENODEV);
+ =A0 =A0 =A0 }
+
+ =A0 =A0 =A0 dev_dbg(vq->dev, "vq %d guest %p host %p\n", index, vq->gue=
st, vq->host);
Quoted 7 lines
+
+ =A0 =A0 =A0 /* Initialize the descriptor, avail, and used rings */
+ =A0 =A0 =A0 for (i =3D 0; i <VOP_RING_SIZE; i++) {
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0vop_set_desc_addr(vq, i, 0x0);
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0vop_set_desc_len(vq, i, 0);
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0vop_set_desc_flags(vq, i, 0);
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 vop_set_desc_next(vq, i, (i + 1) & (VOP_RIN=
G_SIZE - 1));
drivers/virtio/vop_fsl.c
Quoted 10 lines
drivers/virtio/vop_fsl.c new file +10
-0+ + =A0 =A0 =A0 =A0 =A0 =A0 =A0 vq->avail.ring[i] =3D 0; + =A0 =A0 =A0 =A0 =A0 =A0 =A0 vq->used.ring[i].id =3D 0; + =A0 =A0 =A0 =A0 =A0 =A0 =A0 vq->used.ring[i].len =3D 0; + =A0 =A0 =A0 } + + =A0 =A0 =A0 vq->avail.index =3D 0; + =A0 =A0 =A0 vop_set_guest_flags(vq, 0); + + =A0 =A0 =A0 /* This is the guest, the host has already initialized the =
rings for us */
Quoted 6 lines
+ =A0 =A0 =A0
debug_dump_rings(vq, "found a virtqueue, dumping rings");drivers/virtio/vop_fsl.c new file +5
-0+ + =A0 =A0 =A0 vq->vq.callback =3D cb; + =A0 =A0 =A0 vq->vq.vdev =3D &vdev->vdev; + + =A0 =A0 =A0 return &vq->vq;
drivers/virtio/vop_fsl.c
Quoted 10 lines
drivers/virtio/vop_fsl.c new file +10
-0+} + +static void vopc_del_vq (struct virtqueue *_vq) +{ + =A0 =A0 =A0 struct vop_vq *vq =3D to_vop_vq(_vq); + =A0 =A0 =A0 int i; + + =A0 =A0 =A0 /* FIXME: make sure that DMA has stopped by this point */ + + =A0 =A0 =A0 /* Unmap and remove all outstanding descriptors from the ri=
ng */
Quoted 3 lines
+ =A0 =A0 =A0 for (i =3D 0; i <
VOP_RING_SIZE; i++) {
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (vq->data[i]) {
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 dev_dbg(vq->dev, "cleanup d=
etach buffer at index %d\n", i);
Quoted 5 lines
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0
detach_buf(vq, i);
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 }
+ =A0 =A0 =A0 }drivers/virtio/vop_fsl.c new file +2
-0+ + =A0 =A0 =A0 debug_dump_rings(vq, "virtqueue destroyed, dumping rings");
drivers/virtio/vop_fsl.c
Quoted 10 lines
drivers/virtio/vop_fsl.c new file +10
-0+} + +/* Read the host's advertised features */ +static u32 vopc_get_features (struct virtio_device *_vdev) +{ + =A0 =A0 =A0 struct vop_vdev *vdev =3D to_vop_vdev(_vdev); + =A0 =A0 =A0 u32 ret; + + =A0 =A0 =A0 ret =3D vop_get_host_features(vdev); + =A0 =A0 =A0 dev_dbg(&vdev->vdev.dev, "%s(): host features 0x%.8x\n", __=
func__, ret);
Quoted 7 lines
drivers/virtio/vop_fsl.c new file +7
-0+ + =A0 =A0 =A0 return ret; +} + +/* At this point, we've chosen whichever features we can use and +* put them into the vdev->features array. We should probably notify +* the host at this point, but how will virtio react? */
drivers/virtio/vop_fsl.c
Quoted 10 lines
drivers/virtio/vop_fsl.c new file +10
-0+static void vopc_finalize_features (struct virtio_device *_vdev) +{ + =A0 =A0 =A0 struct vop_vdev *vdev =3D to_vop_vdev(_vdev); + =A0 =A0 =A0 struct device *dev =3D &vdev->vdev.dev; + + =A0 =A0 =A0 /* + =A0 =A0 =A0 =A0* TODO: notify the other side at this point + =A0 =A0 =A0 =A0*/ + + =A0 =A0 =A0 vdev->guest_status->features[0] =3D cpu_to_le32(vdev->vdev.=
features[0]);
Quoted 1 line
+ =A0 =A0 =A0 dev_dbg(dev, "%s(): final features 0x%.8lx\n",
__func__, vd=
ev->vdev.features[0]);
Quoted 5 lines
drivers/virtio/vop_fsl.c new file +5
-0+} + +static struct virtio_config_ops vop_config_ops =3D { + =A0 =A0 =A0 .get =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0=3D vopc_get, + =A0 =A0 =A0 .set =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0=3D vopc_set,
drivers/virtio/vop_fsl.c
Quoted 10 lines
drivers/virtio/vop_fsl.c new file +10
-0+ =A0 =A0 =A0 .get_status =A0 =A0 =A0 =A0 =A0 =A0 =3D vopc_get_status, + =A0 =A0 =A0 .set_status =A0 =A0 =A0 =A0 =A0 =A0 =3D vopc_set_status, + =A0 =A0 =A0 .reset =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0=3D vopc_reset, + =A0 =A0 =A0 .find_vq =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0=3D vopc_find_vq, + =A0 =A0 =A0 .del_vq =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =3D vopc_del_vq, + =A0 =A0 =A0 .get_features =A0 =A0 =A0 =A0 =A0 =3D vopc_get_features, + =A0 =A0 =A0 .finalize_features =A0 =A0 =A0=3D vopc_finalize_features, +}; + +/*----------------------------------------------------------------------=
------*/
Quoted 1 line
+/* Last-minute device setup code =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0=
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0*/
Quoted 1 line
+/*----------------------------------------------------------------------=
------*/
drivers/virtio/vop_fsl.c
Quoted 4 lines
drivers/virtio/vop_fsl.c new file +4
-0+ +/* +* Do the last minute setup for virtio_net, now that the host memory is +* valid. This includes setting up pointers to the correct queues so tha=
t
drivers/virtio/vop_fsl.c
Quoted 11 lines
+ * we can just start the virtqueues when the driver registers
+ */drivers/virtio/vop_fsl.c new file +9
-0+static void setup_virtio_net (struct vop_vdev *vdev) +{ + =A0 =A0 =A0 /* TODO: move some of the setup code from find_vq() here */ +} + +/* +* Do any last minute setup for a device just before starting it +* +* The host memory is now valid, so you should be setting up any pointer=
s
drivers/virtio/vop_fsl.c
Quoted 9 lines
+ * the device needs to the host memory
+ */drivers/virtio/vop_fsl.c new file +7
-0+static int vop_setup_device(struct vop_dev *priv, int devnum) +{ + =A0 =A0 =A0 struct vop_vdev *vdev =3D &priv->devices[devnum]; + =A0 =A0 =A0 struct device *dev =3D priv->dev; + + =A0 =A0 =A0 if (devnum >=3D ARRAY_SIZE(priv->devices)) { + =A0 =A0 =A0 =A0 =A0 =A0 =A0 dev_err(dev, "Unknown virtio_device %d\n", =
devnum);
drivers/virtio/vop_fsl.c
Quoted 13 lines
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 return
-ENODEV;
+ =A0 =A0 =A0 }drivers/virtio/vop_fsl.c new file +11
-0+ + =A0 =A0 =A0 /* Setup the device's pointers to host memory */ + =A0 =A0 =A0 vdev->rem =3D priv->host_mem =A0+ (devnum * 4096); + =A0 =A0 =A0 vdev->host_status =3D vdev->rem; + + =A0 =A0 =A0 switch (devnum) { + =A0 =A0 =A0 case 0: /* virtio_net */ + =A0 =A0 =A0 =A0 =A0 =A0 =A0 setup_virtio_net(vdev); + =A0 =A0 =A0 =A0 =A0 =A0 =A0 break; + =A0 =A0 =A0 default: + =A0 =A0 =A0 =A0 =A0 =A0 =A0 dev_err(dev, "Device %d not implemented\n",=
devnum);
Quoted 11 lines
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 return
-ENODEV;
+ =A0 =A0 =A0 }drivers/virtio/vop_fsl.c new file +9
-0+ + =A0 =A0 =A0 return 0; +} + +/* +* Initialize and attempt to register a virtio_device +* +* @priv the driver data +* @devnum the virtio_device number (index into priv->devices)
drivers/virtio/vop_fsl.c
Quoted 10 lines
drivers/virtio/vop_fsl.c new file +10
-0+ */ +static int vop_start_device(struct vop_dev *priv, int devnum) +{ + =A0 =A0 =A0 struct vop_vdev *vdev =3D &priv->devices[devnum]; + =A0 =A0 =A0 struct device *dev =3D priv->dev; + =A0 =A0 =A0 int ret; + + =A0 =A0 =A0 /* Check that we know about the device */ + =A0 =A0 =A0 if (devnum >=3D ARRAY_SIZE(priv->devices)) { + =A0 =A0 =A0 =A0 =A0 =A0 =A0 dev_err(dev, "Unknown virtio_device %d\n", =
devnum);
drivers/virtio/vop_fsl.c
Quoted 10 lines
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 return
-ENODEV;
+ =A0 =A0 =A0 }drivers/virtio/vop_fsl.c new file +8
-0+ + =A0 =A0 =A0 vdev->status =3D 0; + + =A0 =A0 =A0 /* Do any last minute device-specific setup now that the + =A0 =A0 =A0 =A0* host memory is valid */ + =A0 =A0 =A0 ret =3D vop_setup_device(priv, devnum); + =A0 =A0 =A0 if (ret) { + =A0 =A0 =A0 =A0 =A0 =A0 =A0 dev_err(dev, "Unable to setup device %d\n",=
devnum);
Quoted 7 lines
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 return ret;
+ =A0 =A0 =A0 }
+
+ =A0 =A0 =A0 /* Register the device with the virtio subsystem */
+ =A0 =A0 =A0 ret =3Dregister_virtio_device(&vdev->vdev);
+ =A0 =A0 =A0 if (ret) {
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 dev_err(dev, "Unable to register device %d\=
n", devnum);
drivers/virtio/vop_fsl.c
Quoted 8 lines
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 return ret;
+ =A0 =A0 =A0 }drivers/virtio/vop_fsl.c new file +6
-0+ + =A0 =A0 =A0 vdev->status =3D VOP_DEVICE_REGISTERED; + =A0 =A0 =A0 return 0; +} + +/*----------------------------------------------------------------------=
------*/
Quoted 1 line
+/* Work Functions =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 */
Quoted 1 line
+/*----------------------------------------------------------------------=
------*/
drivers/virtio/vop_fsl.c
Quoted 5 lines
drivers/virtio/vop_fsl.c new file +5
-0+ +/* +* Start as much DMA as we can on the given virtqueue +* +* This is put on the system shared queue, and will start us much DMA as=
is
Quoted 1 line
+ * available when it is called. This should be triggered when the host a=
dds
Quoted 1 line
+ * things to the avail rings, and when the guest adds things to the inte=
rnal
drivers/virtio/vop_fsl.c
Quoted 7 lines
+ * avail rings
+ *
+ * Make sure it doesn't sleep for too long, you're on the shared queue
+ */drivers/virtio/vop_fsl.c new file +3
-0+static void vop_dma_work(struct work_struct *work) +{ + =A0 =A0 =A0 struct vop_vq *vq =3D container_of(work, struct vop_vq, wor=
k);
Quoted 11 lines
+ =A0 =A0 =A0 int ret;
drivers/virtio/vop_fsl.c new file +10
-0+ + =A0 =A0 =A0 /* Start as many DMA transactions as we can, immediately */ + =A0 =A0 =A0 while (true) { + =A0 =A0 =A0 =A0 =A0 =A0 =A0 ret =3D vq->resolve(vq); + =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (ret) + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 break; + =A0 =A0 =A0 } +} + +/*
drivers/virtio/vop_fsl.c
Quoted 10 lines
drivers/virtio/vop_fsl.c new file +10
-0+* Remove all virtio devices immediately +* +* This will be called by the host to make sure that we are in a stopped +* state. It should be callable when everything is already stopped. +* +* Make sure it doesn't sleep for too long, you're on the shared queue +*/ +static void vop_reset_work (struct work_struct *work) +{ + =A0 =A0 =A0 struct vop_dev *priv =3D container_of(work, struct vop_dev,=
reset_work);
drivers/virtio/vop_fsl.c
Quoted 12 lines
+ =A0 =A0 =A0 struct device *dev =3D
priv->dev;
+ =A0 =A0 =A0 structvop_vdev*vdev;
+ =A0 =A0 =A0 int i;drivers/virtio/vop_fsl.c new file +9
-0+ + =A0 =A0 =A0 dev_dbg(dev, "Resetting all virtio devices\n"); + =A0 =A0 =A0 mutex_lock(&priv->mutex); + + =A0 =A0 =A0 for (i =3D 0; i < ARRAY_SIZE(priv->devices); i++) { + =A0 =A0 =A0 =A0 =A0 =A0 =A0 vdev =3D &priv->devices[i]; + + =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (vdev->status & VOP_DEVICE_REGISTERED) { + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 dev_dbg(dev, "Unregistering=
virtio_device #%d\n", i);
Quoted 1 line
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 unregister_virtio_device(&v=
dev->vdev);
Quoted 5 lines
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 }
drivers/virtio/vop_fsl.c new file +4
-0+ + =A0 =A0 =A0 =A0 =A0 =A0 =A0 vdev->status &=3D ~VOP_DEVICE_REGISTERED; + =A0 =A0 =A0 } +
drivers/virtio/vop_fsl.c
Quoted 10 lines
drivers/virtio/vop_fsl.c new file +10
-0+ =A0 =A0 =A0 if (priv->host_mem) { + =A0 =A0 =A0 =A0 =A0 =A0 =A0 iounmap(priv->host_mem); + =A0 =A0 =A0 =A0 =A0 =A0 =A0 priv->host_mem =3D NULL; + =A0 =A0 =A0 } + + =A0 =A0 =A0 mutex_unlock(&priv->mutex); +} + +/* +* This will map the host's memory, as well as start the devices that th=
e host
drivers/virtio/vop_fsl.c
Quoted 9 lines
+ * requested
+ *
+ * Mailbox registers contents:
+ * IMR0 - the host memory physical address (must be <1GB)
+ * IMR1 - the devices the host wants started
+ */drivers/virtio/vop_fsl.c new file +3
-0+static void vop_start_work (struct work_struct *work) +{ + =A0 =A0 =A0 struct vop_dev *priv =3D container_of(work, struct vop_dev,=
start_work);
drivers/virtio/vop_fsl.c
Quoted 9 lines
+ =A0 =A0 =A0 struct device *dev =3D
priv->dev;
+ =A0 =A0 =A0 structvop_vdev*vdev;
+ =A0 =A0 =A0 u32 address, devices;
+ =A0 =A0 =A0 int i;drivers/virtio/vop_fsl.c new file +5
-0+ + =A0 =A0 =A0 dev_dbg(dev, "Starting requested virtio devices\n"); + =A0 =A0 =A0 mutex_lock(&priv->mutex); + + =A0 =A0 =A0 /* Read the requested address and devices from the mailbox =
registers */
drivers/virtio/vop_fsl.c
Quoted 8 lines
+ =A0 =A0 =A0 address =3D
ioread32(priv->immr + IMR0_OFFSET);
+ =A0 =A0 =A0 devices =3Dioread32(priv->immr + IMR1_OFFSET);drivers/virtio/vop_fsl.c new file +6
-0+ + =A0 =A0 =A0 dev_dbg(dev, "address 0x%.8x\n", address); + =A0 =A0 =A0 dev_dbg(dev, "devices 0x%.8x\n", devices); + + =A0 =A0 =A0 /* Remap the host's registers */ + =A0 =A0 =A0 priv->host_mem =3D ioremap(address + 0x80000000, VOP_HOST_M=
EM_SIZE);
Quoted 2 lines
+ =A0 =A0 =A0 if (!priv->host_mem) {
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 dev_err(dev, "Unable to ioremap host memory=
\n");
drivers/virtio/vop_fsl.c
Quoted 9 lines
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 goto
out_unlock;
+ =A0 =A0 =A0 }drivers/virtio/vop_fsl.c new file +7
-0+ + =A0 =A0 =A0 /* Start the requested devices */ + =A0 =A0 =A0 for (i =3D 0; i < ARRAY_SIZE(priv->devices); i++) { + =A0 =A0 =A0 =A0 =A0 =A0 =A0 vdev =3D &priv->devices[i]; + + =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (devices & (1 << i)) { + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 dev_dbg(dev, "Starting virt=
io_device #%d\n", i);
drivers/virtio/vop_fsl.c
Quoted 9 lines
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0
vop_start_device(priv, i);
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 }
+ =A0 =A0 =A0 }drivers/virtio/vop_fsl.c new file +6
-0+ +out_unlock: + =A0 =A0 =A0 mutex_unlock(&priv->mutex); +} + +/*----------------------------------------------------------------------=
------*/
Quoted 1 line
+/* Interrupt Handling =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 */
Quoted 1 line
+/*----------------------------------------------------------------------=
------*/
drivers/virtio/vop_fsl.c
Quoted 3 lines
drivers/virtio/vop_fsl.c new file +3
-0+ +/* +* Schedule the work function for a given virtqueue only if the associat=
ed
Quoted 7 lines
+ * device is up and running. Otherwise, ignore the request
+ *
+ * @priv the private driver data
+ * @dev thevirtio_devicenumber in priv->devices[]
+ * @queue the virtqueue in vdev->virtqueues[]
+ */
+static void schedule_work_if_ready(structvop_dev*priv, int dev, int qu=
eue)
Quoted 34 lines
drivers/virtio/vop_fsl.c new file +34
-0+{ + =A0 =A0 =A0 struct vop_vdev *vdev =3D &priv->devices[dev]; + =A0 =A0 =A0 struct vop_vq *vq =3D &vdev->virtqueues[queue]; + + =A0 =A0 =A0 if (vdev->status & VOP_DEVICE_REGISTERED) + =A0 =A0 =A0 =A0 =A0 =A0 =A0 schedule_work(&vq->work); +} + +static irqreturn_t vdev_interrupt (int irq,void *dev_id) +{ + =A0 =A0 =A0 struct vop_dev *priv =3D dev_id; + =A0 =A0 =A0 struct device *dev =3D priv->dev; + =A0 =A0 =A0 u32 imisr, idr; + + =A0 =A0 =A0 imisr =3D ioread32(priv->immr + IMISR_OFFSET); + =A0 =A0 =A0 idr =A0 =3D ioread32(priv->immr + IDR_OFFSET); + + =A0 =A0 =A0 dev_dbg(dev, "INTERRUPT idr 0x%.8x\n", idr); + + =A0 =A0 =A0 /* Check the status register for doorbell interrupts */ + =A0 =A0 =A0 if (!(imisr & 0x8)) + =A0 =A0 =A0 =A0 =A0 =A0 =A0 return IRQ_NONE; + + =A0 =A0 =A0 /* Clear all doorbell interrupts */ + =A0 =A0 =A0 iowrite32(idr, priv->immr + IDR_OFFSET); + + =A0 =A0 =A0 /* Reset */ + =A0 =A0 =A0 if (idr & 0x1) + =A0 =A0 =A0 =A0 =A0 =A0 =A0 schedule_work(&priv->reset_work); + + =A0 =A0 =A0 /* Start */ + =A0 =A0 =A0 if (idr & 0x2) + =A0 =A0 =A0 =A0 =A0 =A0 =A0 schedule_work(&priv->start_work); +
drivers/virtio/vop_fsl.c
Quoted 10 lines
drivers/virtio/vop_fsl.c new file +10
-0+ =A0 =A0 =A0 /* vdev 0 vq 1 kick */ + =A0 =A0 =A0 if (idr & 0x4) + =A0 =A0 =A0 =A0 =A0 =A0 =A0 schedule_work_if_ready(priv, 0, 1); + + =A0 =A0 =A0 /* vdev 0 vq 0 kick */ + =A0 =A0 =A0 if (idr & 0x8) + =A0 =A0 =A0 =A0 =A0 =A0 =A0 schedule_work_if_ready(priv, 0, 0); + + =A0 =A0 =A0 if (idr & 0xfffffff0) + =A0 =A0 =A0 =A0 =A0 =A0 =A0 dev_dbg(dev, "INTERRUPT unhandled 0x%.8x\n"=
, idr & 0xfffffff0);
drivers/virtio/vop_fsl.c
Quoted 5 lines
drivers/virtio/vop_fsl.c new file +5
-0+ + =A0 =A0 =A0 return IRQ_HANDLED; +} + +/*----------------------------------------------------------------------=
------*/
Quoted 1 line
+/* Driver insertion time virtio device initialization =A0 =A0 =A0 =A0 =
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 */
Quoted 1 line
+/*----------------------------------------------------------------------=
------*/
Quoted 12 lines
drivers/virtio/vop_fsl.c new file +12
-0+ +static void vdev_release (struct device *dev) +{ + =A0 =A0 =A0 /* TODO: this should probably do something useful */ + =A0 =A0 =A0 dev_dbg(dev, "%s: called\n", __func__); +} + +/* +* Do any device-specific setup for a virtio device +* +* This would include things like setting the feature bits for the +* device, as well as the device type.
drivers/virtio/vop_fsl.c
Quoted 10 lines
drivers/virtio/vop_fsl.c new file +10
-0+* +* There is no access to host memory at this point, so don't access it +*/ +static void vop_setup_virtio_device (struct vop_dev *priv,int devnum) +{ + =A0 =A0 =A0 struct vop_vdev *vdev =3D &priv->devices[devnum]; + =A0 =A0 =A0 struct virtio_net_config *config; + =A0 =A0 =A0 unsigned long features =3D 0; + + =A0 =A0 =A0 /* HACK: we only support device #0 (virtio_net) right now *=
/
Quoted 6 lines
+ =A0 =A0 =A0 if (devnum !=3D 0)
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 return;
+
+ =A0 =A0 =A0 /* Generate a random ethernet address for the host to have
+ =A0 =A0 =A0 =A0*
+ =A0 =A0 =A0 =A0* This way, we could do something board-specific and get=
an
Quoted 3 lines
+ =A0 =A0 =A0 =A0* ethernet address that is consistent per-slot
+ =A0 =A0 =A0 =A0*/
+ =A0 =A0 =A0 config =3D (structvirtio_net_config*)vdev->guest_status->=
config;
Quoted 5 lines
+ =A0 =A0 =A0
random_ether_addr(config->mac);
+ =A0 =A0 =A0dev_info(priv->dev, "Generated MAC %pM\n", config->mac);drivers/virtio/vop_fsl.c new file +3
-0+ + =A0 =A0 =A0 /* Set the feature bits for the device */ + =A0 =A0 =A0 set_bit(VIRTIO_NET_F_MAC, =A0 =A0 =A0 &features);
drivers/virtio/vop_fsl.c
Quoted 10 lines
drivers/virtio/vop_fsl.c new file +10
-0+ =A0 =A0 =A0 set_bit(VIRTIO_NET_F_CSUM, =A0 =A0 =A0&features); + =A0 =A0 =A0 set_bit(VIRTIO_NET_F_GSO, =A0 =A0 =A0 &features); + =A0 =A0 =A0 set_bit(VIRTIO_NET_F_MRG_RXBUF, &features); + + =A0 =A0 =A0 vdev->guest_status->features[0] =3D cpu_to_le32(features); + =A0 =A0 =A0 vdev->vdev.id.device =3D VIRTIO_ID_NET; +} + +/* +* Do all of the initialization of all of the virtqueues for a given vir=
tio
Quoted 1 line
+ * device. There is no access to host memory at this point, so don't acc=
ess it
Quoted 11 lines
+ *
+ * @devnum the device number in the priv->devices[] array
+ */drivers/virtio/vop_fsl.c new file +8
-0+static void vop_initialize_virtqueues (struct vop_dev *priv,int devnum) +{ + =A0 =A0 =A0 struct vop_vdev *vdev =3D &priv->devices[devnum]; + =A0 =A0 =A0 struct vop_vq *vq; + =A0 =A0 =A0 int i; + + =A0 =A0 =A0 for (i =3D 0; i < ARRAY_SIZE(vdev->virtqueues); i++) { + =A0 =A0 =A0 =A0 =A0 =A0 =A0 vq =3D &vdev->virtqueues[i];
drivers/virtio/vop_fsl.c
Quoted 10 lines
drivers/virtio/vop_fsl.c new file +10
-0+ + =A0 =A0 =A0 =A0 =A0 =A0 =A0 memset(vq, 0, sizeof(struct vop_vq)); + =A0 =A0 =A0 =A0 =A0 =A0 =A0 vq->immr =3D priv->immr; + =A0 =A0 =A0 =A0 =A0 =A0 =A0 vq->dma.chan =3D priv->chan; + =A0 =A0 =A0 =A0 =A0 =A0 =A0 INIT_WORK(&vq->work, vop_dma_work); + =A0 =A0 =A0 } +} + +/* +* Do all of the initialization for the virtio devices that is possible =
without
Quoted 3 lines
+ * access to the host memory
+ *
+ * This includes setting up the pointers that you can and setting the fe=
ature
Quoted 4 lines
+ * bits so that the host can read them before he starts us
+ */drivers/virtio/vop_fsl.c new file +2
-0+static void vop_initialize_devices (struct vop_dev *priv) +{
drivers/virtio/vop_fsl.c
Quoted 10 lines
drivers/virtio/vop_fsl.c new file +10
-0+ =A0 =A0 =A0 struct device *parent =3D priv->dev; + =A0 =A0 =A0 struct vop_vdev *vdev; + =A0 =A0 =A0 struct device *vdev_dev; + =A0 =A0 =A0 int i; + + =A0 =A0 =A0 for (i =3D 0; i < ARRAY_SIZE(priv->devices); i++) { + =A0 =A0 =A0 =A0 =A0 =A0 =A0 vdev =3D &priv->devices[i]; + =A0 =A0 =A0 =A0 =A0 =A0 =A0 vdev_dev =3D &vdev->vdev.dev; + + =A0 =A0 =A0 =A0 =A0 =A0 =A0 /* Set up access to the guest memory, host =
memory isn't valid
Quoted 1 line
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0* yet, and will have to be set up just b=
efore we start */
Quoted 4 lines
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0
vdev->loc=3Dpriv->guest_mem+ (i * 4096);
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0vdev->guest_status=3Dvdev->loc; +
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 /* Initialize all of the device's virtqueue=
s */
drivers/virtio/vop_fsl.c
Quoted 6 lines
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0
vop_initialize_virtqueues(priv, i);drivers/virtio/vop_fsl.c new file +5
-0+ + =A0 =A0 =A0 =A0 =A0 =A0 =A0 /* Zero the configuration space */ + =A0 =A0 =A0 =A0 =A0 =A0 =A0 memset(vdev->guest_status, 0, 1024); + + =A0 =A0 =A0 =A0 =A0 =A0 =A0 /* Copy parent DMA parameters to this devic=
e */
Quoted 3 lines
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0
vdev_dev->dma_mask=3Dparent->dma_mask;
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0vdev_dev->dma_parms=3Dparent->dma_parms;
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0vdev_dev->coherent_dma_mask=3D parent->coh=
erent_dma_mask;
drivers/virtio/vop_fsl.c
Quoted 11 lines
drivers/virtio/vop_fsl.c new file +11
-0+ + =A0 =A0 =A0 =A0 =A0 =A0 =A0 vdev_dev->release =3D &vdev_release; + =A0 =A0 =A0 =A0 =A0 =A0 =A0 vdev_dev->parent =A0=3D parent; + =A0 =A0 =A0 =A0 =A0 =A0 =A0 vdev->vdev.config =3D &vop_config_ops; + + =A0 =A0 =A0 =A0 =A0 =A0 =A0 /* Do any device-specific setup */ + =A0 =A0 =A0 =A0 =A0 =A0 =A0 vop_setup_virtio_device(priv, i); + =A0 =A0 =A0 } +} + +/*----------------------------------------------------------------------=
------*/
Quoted 1 line
+/* OpenFirmware Device Subsystem =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0=
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0*/
Quoted 1 line
+/*----------------------------------------------------------------------=
------*/
drivers/virtio/vop_fsl.c
Quoted 2 lines
drivers/virtio/vop_fsl.c new file +2
-0+ +static int vdev_of_probe(struct of_device *op, const struct of_device_id=
*match)
drivers/virtio/vop_fsl.c
Quoted 9 lines
drivers/virtio/vop_fsl.c new file +9
-0+{ + =A0 =A0 =A0 struct vop_dev *priv; + =A0 =A0 =A0 dma_cap_mask_t mask; + =A0 =A0 =A0 int ret; + + =A0 =A0 =A0 /* Allocate private data */ + =A0 =A0 =A0 priv =3D kzalloc(sizeof(*priv), GFP_KERNEL); + =A0 =A0 =A0 if (!priv) { + =A0 =A0 =A0 =A0 =A0 =A0 =A0 dev_err(&op->dev, "Unable to allocate devic=
e private data\n");
Quoted 7 lines
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 ret =3D
-ENOMEM;
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 gotoout_return;
+ =A0 =A0 =A0 }drivers/virtio/vop_fsl.c new file +4
-0+ + =A0 =A0 =A0 dev_set_drvdata(&op->dev, priv); + =A0 =A0 =A0 priv->dev =3D &op->dev; + =A0 =A0 =A0 mutex_init(&priv->mutex);
drivers/virtio/vop_fsl.c
Quoted 10 lines
drivers/virtio/vop_fsl.c new file +10
-0+ =A0 =A0 =A0 INIT_WORK(&priv->reset_work, vop_reset_work); + =A0 =A0 =A0 INIT_WORK(&priv->start_work, vop_start_work); + + =A0 =A0 =A0 /* Get a DMA channel */ + =A0 =A0 =A0 dma_cap_zero(mask); + =A0 =A0 =A0 dma_cap_set(DMA_MEMCPY, mask); + =A0 =A0 =A0 dma_cap_set(DMA_INTERRUPT, mask); + =A0 =A0 =A0 priv->chan =3D dma_request_channel(mask, NULL, NULL); + =A0 =A0 =A0 if (!priv->chan) { + =A0 =A0 =A0 =A0 =A0 =A0 =A0 dev_err(&op->dev, "Unable to get DMA channe=
l\n");
Quoted 8 lines
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 ret =3D
-ENODEV;
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 gotoout_free_priv;
+ =A0 =A0 =A0 }
+
+ =A0 =A0 =A0 /* Remap IMMR */
+ =A0 =A0 =A0priv->immr=3Dioremap(get_immrbase(), 0x100000);
+ =A0 =A0 =A0 if (!priv->immr) {
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 dev_err(&op->dev, "Unable to remap IMMR reg=
isters\n");
Quoted 6 lines
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 ret =3D
-ENOMEM;
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 gotoout_dma_release_channel;
+ =A0 =A0 =A0 }
+
+ =A0 =A0 =A0 /* Set up a static 1GB window into host memory */
+ =A0 =A0 =A0 iowrite32be(LAWAR0_ENABLE |0x1D,priv->immr+ LAWAR0_OFFSE=
T);
Quoted 1 line
+ =A0 =A0 =A0 iowrite32be(POCMR0_ENABLE |
0xC0000,priv->immr+ POCMR0_OF=
FSET);
Quoted 4 lines
+ =A0 =A0 =A0
iowrite32be(0x0, priv->immr + POTAR0_OFFSET);
+
+ =A0 =A0 =A0 /* Allocate guest memory */
+ =A0 =A0 =A0priv->guest_mem=3D dma_alloc_coherent(&op->dev, VOP_GUEST_=
MEM_SIZE,
Quoted 1 line
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0=
=A0 =A0 =A0 =A0&priv->guest_mem_addr, GFP_KERNEL);
Quoted 2 lines
+ =A0 =A0 =A0 if (!priv->guest_mem) {
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 dev_err(&op->dev, "Unable to allocate guest=
memory\n");
drivers/virtio/vop_fsl.c
Quoted 8 lines
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 ret =3D
-ENOMEM;
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 gotoout_iounmap_immr;
+ =A0 =A0 =A0 }drivers/virtio/vop_fsl.c new file +5
-0+ + =A0 =A0 =A0 memset(priv->guest_mem, 0, VOP_GUEST_MEM_SIZE); + + =A0 =A0 =A0 /* Program BAR1 so that it will hit the guest memory */ + =A0 =A0 =A0 iowrite32be(priv->guest_mem_addr >> 12, priv->immr + PITAR0=
_OFFSET);
Quoted 2 lines
+
+ =A0 =A0 =A0 /* Initialize all of the virtio devices with their features=
, etc */
drivers/virtio/vop_fsl.c
Quoted 8 lines
+ =A0 =A0 =A0
vop_initialize_devices(priv);drivers/virtio/vop_fsl.c new file +7
-0+ + =A0 =A0 =A0 /* Disable mailbox interrupts */ + =A0 =A0 =A0 iowrite32(0x2 | 0x1, priv->immr + IMIMR_OFFSET); + + =A0 =A0 =A0 /* Hook up the irq handler */ + =A0 =A0 =A0 priv->irq =3D irq_of_parse_and_map(op->node, 0); + =A0 =A0 =A0 ret =3D request_irq(priv->irq, vdev_interrupt, IRQF_SHARED,=
driver_name, priv);
Quoted 4 lines
+ =A0 =A0 =A0 if (ret)
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 gotoout_free_guest_mem;
+
+ =A0 =A0 =A0 dev_info(&op->dev, "Virtio-over-PCI guest driver installed\=
n");
Quoted 1 line
+ =A0 =A0 =A0 dev_info(&op->dev, "Physical memory @ 0x%.8x\n", priv->gues=
t_mem_addr);
Quoted 1 line
+ =A0 =A0 =A0 dev_info(&op->dev, "Descriptor ring size: %d entries\n", VO=
P_RING_SIZE);
drivers/virtio/vop_fsl.c
Quoted 4 lines
+ =A0 =A0 =A0 return 0;
drivers/virtio/vop_fsl.c new file +3
-0+ +out_free_guest_mem: + =A0 =A0 =A0 dma_free_coherent(&op->dev, VOP_GUEST_MEM_SIZE, priv->guest=
_mem,
Quoted 13 lines
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0
priv->guest_mem_addr);drivers/virtio/vop_fsl.c new file +12
-0+out_iounmap_immr: + =A0 =A0 =A0 iounmap(priv->immr); +out_dma_release_channel: + =A0 =A0 =A0 dma_release_channel(priv->chan); +out_free_priv: + =A0 =A0 =A0 kfree(priv); +out_return: + =A0 =A0 =A0 return ret; +} + +static int vdev_of_remove (struct of_device *op) +{
drivers/virtio/vop_fsl.c
Quoted 10 lines
drivers/virtio/vop_fsl.c new file +10
-0+ =A0 =A0 =A0 struct vop_dev *priv =3D dev_get_drvdata(&op->dev); + + =A0 =A0 =A0 /* Stop the irq handler */ + =A0 =A0 =A0 free_irq(priv->irq, priv); + + =A0 =A0 =A0 /* Unregister and reset all of the devices */ + =A0 =A0 =A0 schedule_work(&priv->reset_work); + =A0 =A0 =A0 flush_scheduled_work(); + + =A0 =A0 =A0 dma_free_coherent(&op->dev, VOP_GUEST_MEM_SIZE, priv->guest=
_mem,
Quoted 12 lines
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0
priv->guest_mem_addr);
+ =A0 =A0 =A0iounmap(priv->immr);
+ =A0 =A0 =A0dma_release_channel(priv->chan);
+ =A0 =A0 =A0 kfree(priv);drivers/virtio/vop_fsl.c new file +8
-0+ + =A0 =A0 =A0 return 0; +} + +static struct of_device_id vdev_of_match[] =3D { + =A0 =A0 =A0 { .compatible =3D "fsl,mpc8349-mu", }, + =A0 =A0 =A0 {}, +};
drivers/virtio/vop_fsl.c
Quoted 10 lines
drivers/virtio/vop_fsl.c new file +10
-0+ +static struct of_platform_driver vdev_of_driver =3D { + =A0 =A0 =A0 .owner =A0 =A0 =A0 =A0 =A0=3D THIS_MODULE, + =A0 =A0 =A0 .name =A0 =A0 =A0 =A0 =A0 =3D driver_name, + =A0 =A0 =A0 .match_table =A0 =A0=3D vdev_of_match, + =A0 =A0 =A0 .probe =A0 =A0 =A0 =A0 =A0=3D vdev_of_probe, + =A0 =A0 =A0 .remove =A0 =A0 =A0 =A0 =3D vdev_of_remove, +}; + +/*----------------------------------------------------------------------=
------*/
Quoted 1 line
+/* Module Init / Exit =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 */
Quoted 1 line
+/*----------------------------------------------------------------------=
------*/
drivers/virtio/vop_fsl.c
Quoted 6 lines
drivers/virtio/vop_fsl.c new file +6
-0+ +static int __init vdev_init(void) +{ + =A0 =A0 =A0 dma_cache =3D KMEM_CACHE(vop_dma_cbinfo, 0); + =A0 =A0 =A0 if (!dma_cache) { + =A0 =A0 =A0 =A0 =A0 =A0 =A0 pr_err("%s: unable to create dma cache\n", =
driver_name);
Quoted 24 lines
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 return
-ENOMEM;
+ =A0 =A0 =A0 }drivers/virtio/vop_fsl.c new file +16
-0+ + =A0 =A0 =A0 return of_register_platform_driver(&vdev_of_driver); +} + +static void __exit vdev_exit(void) +{ + =A0 =A0 =A0 of_unregister_platform_driver(&vdev_of_driver); + =A0 =A0 =A0 kmem_cache_destroy(dma_cache); +} + +MODULE_AUTHOR ("Ira W. Snyder <[email protected]>" ); +MODULE_DESCRIPTION ("Freescale Virtio-over-PCI Test Driver" ); +MODULE_LICENSE ("GPL" ); + +module_init (vdev_init); +module_exit (vdev_exit);drivers/virtio/vop_host.c new file +0
-0
drivers/virtio/vop_host.c line 6
Quoted 6 lines
drivers/virtio/vop_host.c new file +6
-0@@ -0,0 +1,1071 @@ +/* +* Virtio-over-PCI Host Driver for MPC8349EMDS Guest +* +* Copyright (c) 2009 Ira W. Snyder <[email protected]> +* +* This file is licensed under the terms of the GNU General Public Licen=
se
drivers/virtio/vop_host.c line 7
Quoted 1 line
drivers/virtio/vop_host.c new file +1
-0+* version 2. This program is licensed "as is" without any warranty of a=
ny
Quoted 54 lines
drivers/virtio/vop_host.c new file +54
-0+* kind, whether express or implied. +*/ + +#include <linux/kernel.h> +#include <linux/module.h> +#include <linux/init.h> +#include <linux/pci.h> +#include <linux/virtio.h> +#include <linux/virtio_config.h> +#include <linux/virtio_net.h> +#include <linux/workqueue.h> +#include <linux/interrupt.h> + +#include <linux/etherdevice.h> + +#include "vop_hw.h" +#include "vop.h" + +static const char driver_name[] =3D "vdev"; + +struct vop_loc_desc { + =A0 =A0 =A0 u32 addr; + =A0 =A0 =A0 u32 len; + =A0 =A0 =A0 u16 flags; + =A0 =A0 =A0 u16 next; +}; + +struct vop_vq { + + =A0 =A0 =A0 /* The actual virtqueue itself */ + =A0 =A0 =A0 struct virtqueue vq; + + =A0 =A0 =A0 struct device *dev; + + =A0 =A0 =A0 /* The host ring address */ + =A0 =A0 =A0 struct vop_host_ring *host; + + =A0 =A0 =A0 /* The guest ring address */ + =A0 =A0 =A0 struct vop_guest_ring __iomem *guest; + + =A0 =A0 =A0 /* Local copy of the descriptors for fast access */ + =A0 =A0 =A0 struct vop_loc_desc desc[VOP_RING_SIZE]; + + =A0 =A0 =A0 /* The data token from add_buf() */ + =A0 =A0 =A0 void *data[VOP_RING_SIZE]; + + =A0 =A0 =A0 unsigned int num_free; + =A0 =A0 =A0 unsigned int free_head; + =A0 =A0 =A0 unsigned int num_added; + + =A0 =A0 =A0 u16 avail_idx; + =A0 =A0 =A0 u16 last_used_idx; + + =A0 =A0 =A0 /* The doorbell to kick() */
drivers/virtio/vop_host.c
Quoted 10 lines
drivers/virtio/vop_host.c new file +10
-0+ =A0 =A0 =A0 unsigned int kick_val; + =A0 =A0 =A0 void __iomem *immr; +}; + +/* Convert from a struct virtqueue to a struct vop_vq */ +#define to_vop_vq (X ) container_of(X, struct vop_vq, vq) + +/* +* This represents a virtio_device for our driver. It follows the memory +* layout shown above. It has pointers to all of the host and guest memo=
ry
drivers/virtio/vop_host.c line 84
Quoted 13 lines
drivers/virtio/vop_host.c new file +13
-0+* areas that we need to access +*/ +struct vop_vdev { + + =A0 =A0 =A0 /* The specific virtio device (console, net, blk) */ + =A0 =A0 =A0 struct virtio_device vdev; + + =A0 =A0 =A0 /* Local and remote memory */ + =A0 =A0 =A0 void *loc; + =A0 =A0 =A0 void __iomem *rem; + + =A0 =A0 =A0 /* +=A0 =A0 =A0 =A0* These are the status, feature, and configuration infor=
mation
drivers/virtio/vop_host.c line 85
Quoted 1 line
drivers/virtio/vop_host.c new file +1
-0+ =A0 =A0 =A0 =A0* for this virtio device. They are exposed in our memory=
block
drivers/virtio/vop_host.c line 91
Quoted 6 lines
drivers/virtio/vop_host.c new file +6
-0+=A0 =A0 =A0 =A0* starting at offset 0. +=A0 =A0 =A0 =A0*/ + =A0 =A0 =A0 struct vop_status *host_status; + + =A0 =A0 =A0 /* +=A0 =A0 =A0 =A0* These are the status, feature, and configuration infor=
mation
drivers/virtio/vop_host.c line 92
Quoted 1 line
drivers/virtio/vop_host.c new file +1
-0+ =A0 =A0 =A0 =A0* for the guest virtio device. They are exposed in the g=
uest
drivers/virtio/vop_host.c line 98
Quoted 6 lines
drivers/virtio/vop_host.c new file +6
-0+=A0 =A0 =A0 =A0* memory block starting at offset 0. +=A0 =A0 =A0 =A0*/ + =A0 =A0 =A0 struct vop_status __iomem *guest_status; + + =A0 =A0 =A0 /* +=A0 =A0 =A0 =A0* These are the virtqueues for the virtio driver running=
this
drivers/virtio/vop_host.c line 99
Quoted 1 line
drivers/virtio/vop_host.c new file +1
-0+ =A0 =A0 =A0 =A0* device to use. The host portions are exposed in our me=
mory block
drivers/virtio/vop_host.c line 100
Quoted 1 line
drivers/virtio/vop_host.c new file +1
-0+ =A0 =A0 =A0 =A0* starting at offset 1024. The exposed areas are aligned=
to 1024 byte
drivers/virtio/vop_host.c line 101
Quoted 1 line
drivers/virtio/vop_host.c new file +1
-0+ =A0 =A0 =A0 =A0* boundaries, so they appear at offets 1024, 2048, and 3=
072
drivers/virtio/vop_host.c line 110
Quoted 9 lines
drivers/virtio/vop_host.c new file +9
-0+=A0 =A0 =A0 =A0* respectively. +=A0 =A0 =A0 =A0*/ + =A0 =A0 =A0 struct vop_vq virtqueues[3]; +}; + +#define to_vop_vdev (X ) container_of(X, struct vop_vdev, vdev) + +/* +* This is information from the PCI subsystem about each MPC8349EMDS boa=
rd
Quoted 14 lines
drivers/virtio/vop_host.c new file +14
-0+* +* It holds information for all of the possible virtio_devices that are +* attached to this board. +*/ +struct vop_dev { + + =A0 =A0 =A0 struct pci_dev *pdev; + =A0 =A0 =A0 struct device *dev; + + =A0 =A0 =A0 /* PowerPC memory (PCI BAR0 and BAR1, respectively) */ + =A0 =A0 =A0 #define VOP_GUEST_MEM_SIZE 16384 + =A0 =A0 =A0 void __iomem *immr; + =A0 =A0 =A0 void __iomem *netregs; +
drivers/virtio/vop_host.c line 134
Quoted 10 lines
drivers/virtio/vop_host.c new file +10
-0+ =A0 =A0 =A0 /* Host memory, visible to the PowerPC */ + =A0 =A0 =A0 #define VOP_HOST_MEM_SIZE 16384 + =A0 =A0 =A0 void *host_mem; + =A0 =A0 =A0 dma_addr_t host_mem_addr; + + =A0 =A0 =A0 /* The virtio devices */ + =A0 =A0 =A0 struct vop_vdev devices[4]; +}; + +/*----------------------------------------------------------------------=
------*/
drivers/virtio/vop_host.c line 135
Quoted 1 line
drivers/virtio/vop_host.c new file +1
-0+/* Ring Debugging Helpers =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 */
drivers/virtio/vop_host.c line 136
Quoted 1 line
drivers/virtio/vop_host.c new file +1
-0+/*----------------------------------------------------------------------=
------*/
drivers/virtio/vop_host.c line 147
Quoted 11 lines
drivers/virtio/vop_host.c new file +11
-0+ +#ifdef DEBUG_DUMP_RINGS +static void dump_guest_descriptors (struct vop_vq *vq) +{ + =A0 =A0 =A0 int i; + =A0 =A0 =A0 struct vop_desc __iomem *desc; + + =A0 =A0 =A0 pr_debug("DESC BG: 0xADDRESSX LENGTH 0xFLAG 0xNEXT\n"); + =A0 =A0 =A0 for (i =3D 0; i < VOP_RING_SIZE; i++) { + =A0 =A0 =A0 =A0 =A0 =A0 =A0 desc =3D &vq->guest->desc[i]; + =A0 =A0 =A0 =A0 =A0 =A0 =A0 pr_debug("DESC %.2d: 0x%.8x %.6d 0x%.4x 0x%=
.4x\n", i,
drivers/virtio/vop_host.c line 148
Quoted 1 line
drivers/virtio/vop_host.c new file +1
-0+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 ioread32(&d=
esc->addr), ioread32(&desc->len),
drivers/virtio/vop_host.c line 149
Quoted 1 line
drivers/virtio/vop_host.c new file +1
-0+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 ioread16(&d=
esc->flags), ioread16(&desc->next));
drivers/virtio/vop_host.c line 160
Quoted 11 lines
drivers/virtio/vop_host.c new file +11
-0+ =A0 =A0 =A0 } + =A0 =A0 =A0 pr_debug("DESC ED\n"); +} + +static void dump_guest_avail(struct vop_vq *vq) +{ + =A0 =A0 =A0 int i; + + =A0 =A0 =A0 pr_debug("BEGIN AVAIL DUMP\n"); + =A0 =A0 =A0 for (i =3D 0; i < VOP_RING_SIZE; i++) + =A0 =A0 =A0 =A0 =A0 =A0 =A0 pr_debug("AVAIL %.2d: 0x%.4x\n", i, ioread1=
6(&vq->guest->avail[i]));
drivers/virtio/vop_host.c
Quoted 8 lines
drivers/virtio/vop_host.c new file +8
-0+ =A0 =A0 =A0 pr_debug("END AVAIL DUMP\n"); +} + +static void dump_guest_ring (struct vop_vq *vq) +{ + =A0 =A0 =A0 pr_debug("BEGIN GUEST RING DUMP\n"); + =A0 =A0 =A0 dump_guest_descriptors(vq); + =A0 =A0 =A0 pr_debug("GUEST FLAGS: 0x%.4x\n", ioread16(&vq->guest->flag=
s));
drivers/virtio/vop_host.c line 169
Quoted 1 line
drivers/virtio/vop_host.c new file +1
-0+ =A0 =A0 =A0 pr_debug("GUEST AVAIL_IDX: %d\n", ioread16(&vq->guest->avai=
l_idx));
drivers/virtio/vop_host.c line 182
Quoted 13 lines
drivers/virtio/vop_host.c new file +13
-0+ =A0 =A0 =A0 dump_guest_avail(vq); + =A0 =A0 =A0 pr_debug("END GUEST RING DUMP\n"); +} + +static void dump_host_used(struct vop_vq *vq) +{ + =A0 =A0 =A0 int i; + =A0 =A0 =A0 struct vop_used_elem *used; + + =A0 =A0 =A0 pr_debug("USED BG: 0xIDID LENGTH\n"); + =A0 =A0 =A0 for (i =3D 0; i < VOP_RING_SIZE; i++) { + =A0 =A0 =A0 =A0 =A0 =A0 =A0 used =3D &vq->host->used[i]; + =A0 =A0 =A0 =A0 =A0 =A0 =A0 pr_debug("USED %.2d: 0x%.4x %.6d\n", i, use=
d->id, used->len);
Quoted 18 lines
drivers/virtio/vop_host.c new file +18
-0+ =A0 =A0 =A0 } + =A0 =A0 =A0 pr_debug("USED ED\n"); +} + +static void dump_host_ring (struct vop_vq *vq) +{ + =A0 =A0 =A0 pr_debug("BEGIN HOST RING DUMP\n"); + =A0 =A0 =A0 pr_debug("HOST FLAGS: 0x%.4x\n", vq->host->flags); + =A0 =A0 =A0 pr_debug("HOST USED_IDX: 0x%.2d\n", vq->host->used_idx); + =A0 =A0 =A0 dump_host_used(vq); + =A0 =A0 =A0 pr_debug("END HOST RING DUMP\n"); +} + +static void debug_dump_rings (struct vop_vq *vq,const char *msg) +{ + =A0 =A0 =A0 dev_dbg(vq->dev, "%s\n", msg); + =A0 =A0 =A0 dump_guest_ring(vq); + =A0 =A0 =A0 dump_host_ring(vq);
drivers/virtio/vop_host.c
Quoted 10 lines
drivers/virtio/vop_host.c new file +10
-0+ =A0 =A0 =A0 pr_debug("\n"); +} +#else +static void debug_dump_rings (struct vop_vq *vq,const char *msg) +{ + =A0 =A0 =A0 /* Nothing */ +} +#endif /* DEBUG_DUMP_RINGS */ + +/*----------------------------------------------------------------------=
------*/
drivers/virtio/vop_host.c line 211
Quoted 1 line
drivers/virtio/vop_host.c new file +1
-0+/* Ring Access Helpers =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0*/
drivers/virtio/vop_host.c line 212
Quoted 1 line
drivers/virtio/vop_host.c new file +1
-0+/*----------------------------------------------------------------------=
------*/
drivers/virtio/vop_host.c line 214
Quoted 2 lines
drivers/virtio/vop_host.c new file +2
-0+ +static void vop_set_desc_addr(struct vop_vq *vq, unsigned int idx, u32 a=
ddr)
drivers/virtio/vop_host.c line 220
Quoted 6 lines
drivers/virtio/vop_host.c new file +6
-0+{ + =A0 =A0 =A0 vq->desc[idx].addr =3D addr; + =A0 =A0 =A0 iowrite32(addr, &vq->guest->desc[idx].addr); +} + +static void vop_set_desc_len(struct vop_vq *vq, unsigned int idx, u32 le=
n)
drivers/virtio/vop_host.c line 226
Quoted 6 lines
drivers/virtio/vop_host.c new file +6
-0+{ + =A0 =A0 =A0 vq->desc[idx].len =3D len; + =A0 =A0 =A0 iowrite32(len, &vq->guest->desc[idx].len); +} + +static void vop_set_desc_flags(struct vop_vq *vq, unsigned int idx, u16 =
flags)
drivers/virtio/vop_host.c line 232
Quoted 6 lines
drivers/virtio/vop_host.c new file +6
-0+{ + =A0 =A0 =A0 vq->desc[idx].flags =3D flags; + =A0 =A0 =A0 iowrite16(flags, &vq->guest->desc[idx].flags); +} + +static void vop_set_desc_next(struct vop_vq *vq, unsigned int idx, u16 n=
ext)
Quoted 17 lines
drivers/virtio/vop_host.c new file +17
-0+{ + =A0 =A0 =A0 vq->desc[idx].next =3D next; + =A0 =A0 =A0 iowrite16(next, &vq->guest->desc[idx].next); +} + +static u32 vop_get_desc_addr (struct vop_vq *vq,unsigned int idx) +{ + =A0 =A0 =A0 return vq->desc[idx].addr; +} + +static u32 vop_get_desc_len (struct vop_vq *vq,unsigned int idx) +{ + =A0 =A0 =A0 return vq->desc[idx].len; +} + +static u16 vop_get_desc_flags (struct vop_vq *vq,unsigned int idx) +{
drivers/virtio/vop_host.c
Quoted 10 lines
drivers/virtio/vop_host.c new file +10
-0+ =A0 =A0 =A0 return vq->desc[idx].flags; +} + +static u16 vop_get_desc_next (struct vop_vq *vq,unsigned int idx) +{ + =A0 =A0 =A0 return vq->desc[idx].next; +} + +/* +* Add an entry to the available ring at avail_idx pointing to the descr=
iptor
drivers/virtio/vop_host.c
Quoted 13 lines
drivers/virtio/vop_host.c new file +13
-0+* chain at index head +* +* @vq the virtqueue +* @idx the index in the avail ring +* @val the value to write +*/ +static void vop_set_avail_entry (struct vop_vq *vq,u16 idx,u16 val) +{ + =A0 =A0 =A0 iowrite16(val, &vq->guest->avail[idx]); +} + +/* +* Set the available index so the guest knows about buffers that were ad=
ded
Quoted 23 lines
drivers/virtio/vop_host.c new file +23
-0+* with vop_set_avail_entry() +* +* @vq the virtqueue +* @idx the new avail_idx that the guest sees +*/ +static void vop_set_avail_idx (struct vop_vq *vq,u16 idx) +{ + =A0 =A0 =A0 iowrite16(idx, &vq->guest->avail_idx); +} + +/* +* Set the host's flags (in the guest memory) +* +* @vq the virtqueue +* @flags the new flags that the guest will see +*/ +static void vop_set_host_flags (struct vop_vq *vq,u16 flags) +{ + =A0 =A0 =A0 iowrite16(flags, &vq->guest->flags); +} + +/* +* Read the guests flags (in local memory)
drivers/virtio/vop_host.c
Quoted 10 lines
drivers/virtio/vop_host.c new file +10
-0+* +* @vq the virtqueue +* @return the guest's flags +*/ +static u16 vop_get_guest_flags (struct vop_vq *vq) +{ + =A0 =A0 =A0 return le16_to_cpu(vq->host->flags); +} + +/*----------------------------------------------------------------------=
------*/
drivers/virtio/vop_host.c line 306
Quoted 1 line
drivers/virtio/vop_host.c new file +1
-0+/* Remote status helpers =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0=
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0*/
drivers/virtio/vop_host.c line 307
Quoted 1 line
drivers/virtio/vop_host.c new file +1
-0+/*----------------------------------------------------------------------=
------*/
drivers/virtio/vop_host.c
Quoted 12 lines
drivers/virtio/vop_host.c new file +12
-0+ +static u32 vop_get_guest_status (struct vop_vdev *vdev) +{ + =A0 =A0 =A0 return ioread32(&vdev->guest_status->status); +} + +static u32 vop_get_guest_features (struct vop_vdev *vdev) +{ + =A0 =A0 =A0 return ioread32(&vdev->guest_status->features[0]); +} + +/*----------------------------------------------------------------------=
------*/
drivers/virtio/vop_host.c line 320
Quoted 1 line
drivers/virtio/vop_host.c new file +1
-0+/* Scatterlist DMA helpers =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0*/
drivers/virtio/vop_host.c line 321
Quoted 1 line
drivers/virtio/vop_host.c new file +1
-0+/*----------------------------------------------------------------------=
------*/
drivers/virtio/vop_host.c line 331
Quoted 10 lines
drivers/virtio/vop_host.c new file +10
-0+ +/* +* This function abuses some of the scatterlist code and implements +* dma_map_sg() in such a way that we don't need to keep the scatterlist +* around in order to unmap it. +* +* It is also designed to never merge scatterlist entries, which is +* never what we want for virtio. +* +* When it is time to unmap the buffer, you can use dma_unmap_single() t=
o
drivers/virtio/vop_host.c line 336
Quoted 5 lines
drivers/virtio/vop_host.c new file +5
-0+* unmap each entry in the chain. Get the address, length, and direction +* from the descriptors! (keep a local copy for speed) +*/ +static int vop_dma_map_sg(struct device *dev, struct scatterlist sg[], + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 unsigned int out, unsig=
ned int in)
Quoted 4 lines
drivers/virtio/vop_host.c new file +4
-0+{ + =A0 =A0 =A0 dma_addr_t addr; + =A0 =A0 =A0 enum dma_data_direction dir; + =A0 =A0 =A0 struct scatterlist *start;
drivers/virtio/vop_host.c line 350
Quoted 10 lines
drivers/virtio/vop_host.c new file +10
-0+ =A0 =A0 =A0 unsigned int i, failure; + + =A0 =A0 =A0 start =3D sg; + + =A0 =A0 =A0 for (i =3D 0; i < out + in; i++) { + + =A0 =A0 =A0 =A0 =A0 =A0 =A0 /* Check for scatterlist chaining abuse */ + =A0 =A0 =A0 =A0 =A0 =A0 =A0 BUG_ON(sg =3D=3D NULL); + + =A0 =A0 =A0 =A0 =A0 =A0 =A0 dir =3D (i < out) ? DMA_TO_DEVICE : DMA_FRO=
M_DEVICE;
drivers/virtio/vop_host.c line 351
Quoted 1 line
drivers/virtio/vop_host.c new file +1
-0+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 addr =3D dma_map_single(dev, sg_virt(sg), s=
g->length, dir);
Quoted 6 lines
drivers/virtio/vop_host.c new file +6
-0+ + =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (dma_mapping_error(dev, addr)) + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 goto unwind; + + =A0 =A0 =A0 =A0 =A0 =A0 =A0 sg_dma_address(sg) =3D addr; + =A0 =A0 =A0 =A0 =A0 =A0 =A0 sg =3D sg_next(sg);
drivers/virtio/vop_host.c line 367
Quoted 10 lines
drivers/virtio/vop_host.c new file +10
-0+ =A0 =A0 =A0 } + + =A0 =A0 =A0 return 0; + +unwind: + =A0 =A0 =A0 failure =3D i; + =A0 =A0 =A0 sg =3D start; + + =A0 =A0 =A0 for (i =3D 0; i < failure; i++) { + =A0 =A0 =A0 =A0 =A0 =A0 =A0 dir =3D (i < out) ? DMA_TO_DEVICE : DMA_FRO=
M_DEVICE;
drivers/virtio/vop_host.c line 370
Quoted 3 lines
drivers/virtio/vop_host.c new file +3
-0+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 addr =3D sg_dma_address(sg); + + =A0 =A0 =A0 =A0 =A0 =A0 =A0 dma_unmap_single(dev, addr, sg->length, dir=
);
drivers/virtio/vop_host.c line 377
Quoted 7 lines
drivers/virtio/vop_host.c new file +7
-0+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 sg =3D sg_next(sg); + =A0 =A0 =A0 } + + =A0 =A0 =A0 return -ENOMEM; +} + +/*----------------------------------------------------------------------=
------*/
drivers/virtio/vop_host.c line 378
Quoted 1 line
drivers/virtio/vop_host.c new file +1
-0+/* struct virtqueue_ops infrastructure =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0*/
drivers/virtio/vop_host.c line 379
Quoted 1 line
drivers/virtio/vop_host.c new file +1
-0+/*----------------------------------------------------------------------=
------*/
drivers/virtio/vop_host.c line 382
Quoted 3 lines
drivers/virtio/vop_host.c new file +3
-0+ +/* +* Modify the struct virtio_net_hdr_mrg_rxbuf's num_buffers field to acc=
ount
drivers/virtio/vop_host.c line 387
Quoted 5 lines
drivers/virtio/vop_host.c new file +5
-0+* for the split that will happen in the DMA xmit routine +* +* This assumes that both sides have the same PAGE_SIZE +*/ +static void vop_fixup_vnet_mrg_hdr(struct scatterlist sg[], unsigned int=
out)
drivers/virtio/vop_host.c line 397
Quoted 10 lines
drivers/virtio/vop_host.c new file +10
-0+{ + =A0 =A0 =A0 struct virtio_net_hdr *hdr; + =A0 =A0 =A0 struct virtio_net_hdr_mrg_rxbuf *mhdr; + =A0 =A0 =A0 unsigned int bytes =3D 0; + + =A0 =A0 =A0 /* There must be a header + data, at the least */ + =A0 =A0 =A0 BUG_ON(out < 2); + + =A0 =A0 =A0 /* The first entry must be the structure */ + =A0 =A0 =A0 BUG_ON(sg->length !=3D sizeof(struct virtio_net_hdr_mrg_rxb=
uf));
drivers/virtio/vop_host.c line 402
Quoted 5 lines
drivers/virtio/vop_host.c new file +5
-0+ + =A0 =A0 =A0 hdr =3D sg_virt(sg); + =A0 =A0 =A0 mhdr =3D sg_virt(sg); + + =A0 =A0 =A0 /* We merge buffers together, so just count up the number o=
f bytes
drivers/virtio/vop_host.c line 407
Quoted 5 lines
drivers/virtio/vop_host.c new file +5
-0+=A0 =A0 =A0 =A0* needed, then figure out how many pages that will be */ + =A0 =A0 =A0 for (/* none */; out; out--, sg =3D sg_next(sg)) + =A0 =A0 =A0 =A0 =A0 =A0 =A0 bytes +=3D sg->length; + + =A0 =A0 =A0 /* Of course, nobody ever imagined that we might actually u=
se
drivers/virtio/vop_host.c line 410
Quoted 3 lines
drivers/virtio/vop_host.c new file +3
-0+ =A0 =A0 =A0 =A0* this on machines with different endianness... + =A0 =A0 =A0 =A0 * + =A0 =A0 =A0 =A0* We force big-endian for now, since that's what our gue=
st is */
drivers/virtio/vop_host.c line 411
Quoted 1 line
drivers/virtio/vop_host.c new file +1
-0+ =A0 =A0 =A0 mhdr->num_buffers =3D cpu_to_be16(DIV_ROUND_UP(bytes, PAGE_=
SIZE));
drivers/virtio/vop_host.c line 413
Quoted 2 lines
drivers/virtio/vop_host.c new file +2
-0+ + =A0 =A0 =A0 /* Might as well fix up the other fields while we're at it =
*/
drivers/virtio/vop_host.c line 421
Quoted 8 lines
drivers/virtio/vop_host.c new file +8
-0+ =A0 =A0 =A0 hdr->hdr_len =3D cpu_to_be16(hdr->hdr_len); + =A0 =A0 =A0 hdr->gso_size =3D cpu_to_be16(hdr->gso_size); + =A0 =A0 =A0 hdr->csum_start =3D cpu_to_be16(hdr->csum_start); + =A0 =A0 =A0 hdr->csum_offset =3D cpu_to_be16(hdr->csum_offset); +} + +static int vop_add_buf(struct virtqueue *_vq, struct scatterlist sg[], + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 unsigned in=
t out, unsigned int in, void *data)
drivers/virtio/vop_host.c line 431
Quoted 10 lines
drivers/virtio/vop_host.c new file +10
-0+{ + =A0 =A0 =A0 struct vop_vq *vq =3D to_vop_vq(_vq); + =A0 =A0 =A0 unsigned int i, avail, head, uninitialized_var(prev); + + =A0 =A0 =A0 BUG_ON(data =3D=3D NULL); + =A0 =A0 =A0 BUG_ON(out + in =3D=3D 0); + + =A0 =A0 =A0 /* Make sure we have space for this to succeed */ + =A0 =A0 =A0 if (vq->num_free < out + in) { + =A0 =A0 =A0 =A0 =A0 =A0 =A0 dev_dbg(vq->dev, "No free space left: len=
=3D%d free=3D%d\n",
drivers/virtio/vop_host.c line 432
Quoted 1 line
drivers/virtio/vop_host.c new file +1
-0+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 out + in, v=
q->num_free);
drivers/virtio/vop_host.c line 436
Quoted 4 lines
drivers/virtio/vop_host.c new file +4
-0+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 return -ENOSPC; + =A0 =A0 =A0 } + + =A0 =A0 =A0 /* If this is an xmit buffer from virtio_net, fixup the hea=
der */
drivers/virtio/vop_host.c line 438
Quoted 2 lines
drivers/virtio/vop_host.c new file +2
-0+ =A0 =A0 =A0 if (out > 1) { + =A0 =A0 =A0 =A0 =A0 =A0 =A0 dev_dbg(vq->dev, "Fixing up virtio_net head=
er\n");
drivers/virtio/vop_host.c line 446
Quoted 8 lines
drivers/virtio/vop_host.c new file +8
-0+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 vop_fixup_vnet_mrg_hdr(sg, out); + =A0 =A0 =A0 } + + =A0 =A0 =A0 head =3D vq->free_head; + + =A0 =A0 =A0 /* DMA map the scatterlist */ + =A0 =A0 =A0 if (vop_dma_map_sg(vq->dev, sg, out, in)) { + =A0 =A0 =A0 =A0 =A0 =A0 =A0 dev_err(vq->dev, "Failed to DMA map scatter=
list\n");
drivers/virtio/vop_host.c line 453
Quoted 7 lines
drivers/virtio/vop_host.c new file +7
-0+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 return -ENOMEM; + =A0 =A0 =A0 } + + =A0 =A0 =A0 /* We're about to use some buffers from the free list */ + =A0 =A0 =A0 vq->num_free -=3D out + in; + + =A0 =A0 =A0 for (i =3D vq->free_head; out; i =3D vop_get_desc_next(vq, =
i), out--) {
drivers/virtio/vop_host.c line 455
Quoted 2 lines
drivers/virtio/vop_host.c new file +2
-0+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 vop_set_desc_flags(vq, i, VOP_DESC_F_NEXT); + =A0 =A0 =A0 =A0 =A0 =A0 =A0 vop_set_desc_addr(vq, i, sg_dma_address(sg)=
);
drivers/virtio/vop_host.c line 462
Quoted 7 lines
drivers/virtio/vop_host.c new file +7
-0+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 vop_set_desc_len(vq, i, sg->length); + + =A0 =A0 =A0 =A0 =A0 =A0 =A0 prev =3D i; + =A0 =A0 =A0 =A0 =A0 =A0 =A0 sg =3D sg_next(sg); + =A0 =A0 =A0 } + + =A0 =A0 =A0 for (/* none */; in; i =3D vop_get_desc_next(vq, i), in--) =
{
drivers/virtio/vop_host.c line 463
Quoted 1 line
drivers/virtio/vop_host.c new file +1
-0+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 vop_set_desc_flags(vq, i, VOP_DESC_F_NEXT |=
VOP_DESC_F_WRITE);
drivers/virtio/vop_host.c line 464
Quoted 1 line
drivers/virtio/vop_host.c new file +1
-0+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 vop_set_desc_addr(vq, i, sg_dma_address(sg)=
);
drivers/virtio/vop_host.c line 472
Quoted 8 lines
drivers/virtio/vop_host.c new file +8
-0+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 vop_set_desc_len(vq, i, sg->length); + + =A0 =A0 =A0 =A0 =A0 =A0 =A0 prev =3D i; + =A0 =A0 =A0 =A0 =A0 =A0 =A0 sg =3D sg_next(sg); + =A0 =A0 =A0 } + + =A0 =A0 =A0 /* Last one doesn't continue */ + =A0 =A0 =A0 vop_set_desc_flags(vq, prev, vop_get_desc_flags(vq, prev) &=
~VOP_DESC_F_NEXT);
drivers/virtio/vop_host.c line 480
Quoted 8 lines
drivers/virtio/vop_host.c new file +8
-0+ + =A0 =A0 =A0 /* Update the free pointer */ + =A0 =A0 =A0 vq->free_head =3D i; + + =A0 =A0 =A0 /* Set token */ + =A0 =A0 =A0 vq->data[head] =3D data; + + =A0 =A0 =A0 /* Add an entry for the head of the chain into the avail ar=
ray, but
drivers/virtio/vop_host.c line 482
Quoted 2 lines
drivers/virtio/vop_host.c new file +2
-0+=A0 =A0 =A0 =A0* don't update avail->idx until kick() */ + =A0 =A0 =A0 avail =3D (vq->avail_idx + vq->num_added++) & (VOP_RING_SIZ=
E - 1);
drivers/virtio/vop_host.c line 485
Quoted 3 lines
drivers/virtio/vop_host.c new file +3
-0+ =A0 =A0 =A0 vop_set_avail_entry(vq, avail, head); + + =A0 =A0 =A0 dev_dbg(vq->dev, "Added buffer head %i to %p (num_free %d)\=
n", head, vq, vq->num_free);
drivers/virtio/vop_host.c
Quoted 8 lines
drivers/virtio/vop_host.c new file +8
-0+ =A0 =A0 =A0 debug_dump_rings(vq, "Added buffer(s), dumping rings"); + + =A0 =A0 =A0 return 0; +} + +static inline bool more_used(const struct vop_vq *vq) +{ + =A0 =A0 =A0 return vq->last_used_idx !=3D le16_to_cpu(vq->host->used_id=
x);
drivers/virtio/vop_host.c line 505
Quoted 12 lines
drivers/virtio/vop_host.c new file +12
-0+} + +static void detach_buf (struct vop_vq *vq,unsigned int head) +{ + =A0 =A0 =A0 unsigned int i, len; + =A0 =A0 =A0 dma_addr_t addr; + =A0 =A0 =A0 enum dma_data_direction dir; + + =A0 =A0 =A0 /* Clear data pointer */ + =A0 =A0 =A0 vq->data[head] =3D NULL; + + =A0 =A0 =A0 /* Put the chain back on the free list, unmapping as we go =
*/
drivers/virtio/vop_host.c line 510
Quoted 5 lines
drivers/virtio/vop_host.c new file +5
-0+ =A0 =A0 =A0 i =3D head; + =A0 =A0 =A0 while (true) { + =A0 =A0 =A0 =A0 =A0 =A0 =A0 addr =3D vop_get_desc_addr(vq, i); + =A0 =A0 =A0 =A0 =A0 =A0 =A0 len =3D vop_get_desc_len(vq, i); + =A0 =A0 =A0 =A0 =A0 =A0 =A0 dir =3D (vop_get_desc_flags(vq, i) & VOP_DE=
SC_F_WRITE) ?
drivers/virtio/vop_host.c line 511
Quoted 1 line
drivers/virtio/vop_host.c new file +1
-0+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 DMA_FROM_DE=
VICE : DMA_TO_DEVICE;
drivers/virtio/vop_host.c line 518
Quoted 7 lines
drivers/virtio/vop_host.c new file +7
-0+ + =A0 =A0 =A0 =A0 =A0 =A0 =A0 /* Unmap the entry */ + =A0 =A0 =A0 =A0 =A0 =A0 =A0 dma_unmap_single(vq->dev, addr, len, dir); + =A0 =A0 =A0 =A0 =A0 =A0 =A0 vq->num_free++; + + =A0 =A0 =A0 =A0 =A0 =A0 =A0 /* Check for end-of-chain */ + =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (!(vop_get_desc_flags(vq, i) & VOP_DESC_=
F_NEXT))
Quoted 7 lines
drivers/virtio/vop_host.c new file +7
-0+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 break; + + =A0 =A0 =A0 =A0 =A0 =A0 =A0 i =3D vop_get_desc_next(vq, i); + =A0 =A0 =A0 } + + =A0 =A0 =A0 vop_set_desc_next(vq, i, vq->free_head); + =A0 =A0 =A0 vq->free_head =3D head;
drivers/virtio/vop_host.c line 535
Quoted 10 lines
drivers/virtio/vop_host.c new file +10
-0+} + +static void *vop_get_buf(struct virtqueue *_vq, unsigned int *len) +{ + =A0 =A0 =A0 struct vop_vq *vq =3D to_vop_vq(_vq); + =A0 =A0 =A0 unsigned int head, used_idx; + =A0 =A0 =A0 void *ret; + + =A0 =A0 =A0 if (!more_used(vq)) { + =A0 =A0 =A0 =A0 =A0 =A0 =A0 dev_dbg(vq->dev, "No more buffers in queue\=
n");
drivers/virtio/vop_host.c line 543
Quoted 8 lines
drivers/virtio/vop_host.c new file +8
-0+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 return NULL; + =A0 =A0 =A0 } + + =A0 =A0 =A0 used_idx =3D vq->last_used_idx & (VOP_RING_SIZE - 1); + =A0 =A0 =A0 head =3D le32_to_cpu(vq->host->used[used_idx].id); + =A0 =A0 =A0 *len =3D le32_to_cpu(vq->host->used[used_idx].len); + + =A0 =A0 =A0 dev_dbg(vq->dev, "REMOVE buffer head %i from %p (len %d)\n"=
, head, vq, *len);
Quoted 9 lines
drivers/virtio/vop_host.c new file +9
-0+ =A0 =A0 =A0 debug_dump_rings(vq, "Removing buffer, dumping rings"); + + =A0 =A0 =A0 BUG_ON(head >=3D VOP_RING_SIZE); + =A0 =A0 =A0 BUG_ON(!vq->data[head]); + + =A0 =A0 =A0 /* detach_buf() clears data, save it now */ + =A0 =A0 =A0 ret =3D vq->data[head]; + =A0 =A0 =A0 detach_buf(vq, head); +
drivers/virtio/vop_host.c line 562
Quoted 10 lines
drivers/virtio/vop_host.c new file +10
-0+ =A0 =A0 =A0 /* Update the last used_idx we've consumed */ + =A0 =A0 =A0 vq->last_used_idx++; + =A0 =A0 =A0 return ret; +} + +static void vop_kick (struct virtqueue *_vq) +{ + =A0 =A0 =A0 struct vop_vq *vq =3D to_vop_vq(_vq); + + =A0 =A0 =A0 dev_dbg(vq->dev, "making %d new buffers available to guest\=
n", vq->num_added);
drivers/virtio/vop_host.c line 568
Quoted 6 lines
drivers/virtio/vop_host.c new file +6
-0+ =A0 =A0 =A0 vq->avail_idx +=3D vq->num_added; + =A0 =A0 =A0 vq->num_added =3D 0; + =A0 =A0 =A0 vop_set_avail_idx(vq, vq->avail_idx); + + =A0 =A0 =A0 if (!(vop_get_guest_flags(vq) & VOP_F_NO_INTERRUPT)) { + =A0 =A0 =A0 =A0 =A0 =A0 =A0 dev_dbg(vq->dev, "kicking the guest (new bu=
ffers in avail)\n");
drivers/virtio/vop_host.c line 569
Quoted 1 line
drivers/virtio/vop_host.c new file +1
-0+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 iowrite32(vq->kick_val, vq->immr + IDR_OFFS=
ET);
drivers/virtio/vop_host.c line 570
Quoted 1 line
drivers/virtio/vop_host.c new file +1
-0+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 debug_dump_rings(vq, "ran a kick, dumping r=
ings");
Quoted 24 lines
drivers/virtio/vop_host.c new file +24
-0+ =A0 =A0 =A0 } +} + +/* Write to the guest's flags register to disable interrupts */ +static void vop_disable_cb (struct virtqueue *_vq) +{ + =A0 =A0 =A0 struct vop_vq *vq =3D to_vop_vq(_vq); + + =A0 =A0 =A0 vop_set_host_flags(vq, VOP_F_NO_INTERRUPT); +} + +static bool vop_enable_cb (struct virtqueue *_vq) +{ + =A0 =A0 =A0 struct vop_vq *vq =3D to_vop_vq(_vq); + + =A0 =A0 =A0 /* We optimistically enable interrupts, then check if +=A0 =A0 =A0 =A0* there was more to do */ + =A0 =A0 =A0 vop_set_host_flags(vq, 0); + + =A0 =A0 =A0 if (unlikely(more_used(vq))) + =A0 =A0 =A0 =A0 =A0 =A0 =A0 return false; + + =A0 =A0 =A0 return true; +}
drivers/virtio/vop_host.c
Quoted 10 lines
drivers/virtio/vop_host.c new file +10
-0+ +static struct virtqueue_ops vop_vq_ops =3D { + =A0 =A0 =A0 .add_buf =A0 =A0 =A0 =A0=3D vop_add_buf, + =A0 =A0 =A0 .get_buf =A0 =A0 =A0 =A0=3D vop_get_buf, + =A0 =A0 =A0 .kick =A0 =A0 =A0 =A0 =A0 =3D vop_kick, + =A0 =A0 =A0 .disable_cb =A0 =A0 =3D vop_disable_cb, + =A0 =A0 =A0 .enable_cb =A0 =A0 =A0=3D vop_enable_cb, +}; + +/*----------------------------------------------------------------------=
------*/
drivers/virtio/vop_host.c line 605
Quoted 1 line
drivers/virtio/vop_host.c new file +1
-0+/* struct virtio_device infrastructure =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0*/
drivers/virtio/vop_host.c line 606
Quoted 1 line
drivers/virtio/vop_host.c new file +1
-0+/*----------------------------------------------------------------------=
------*/
drivers/virtio/vop_host.c line 608
Quoted 2 lines
drivers/virtio/vop_host.c new file +2
-0+ +/* Get something that the other side wants you to have, from configurati=
on
drivers/virtio/vop_host.c line 609
Quoted 1 line
drivers/virtio/vop_host.c new file +1
-0+* space. This is used to transfer the MAC address from the guest to the=
host,
drivers/virtio/vop_host.c line 610
Quoted 1 line
drivers/virtio/vop_host.c new file +1
-0+* for example. It should be reading something from the guest, in this c=
ase */
drivers/virtio/vop_host.c line 611
Quoted 1 line
drivers/virtio/vop_host.c new file +1
-0+static void vopc_get(struct virtio_device *_vdev, unsigned offset, void =
*buf,
Quoted 16 lines
drivers/virtio/vop_host.c new file +16
-0+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0unsigned len) +{ + =A0 =A0 =A0 struct vop_vdev *vdev =3D to_vop_vdev(_vdev); + =A0 =A0 =A0 void __iomem *config =3D vdev->guest_status->config; + + =A0 =A0 =A0 memcpy_fromio(buf, config + offset, len); +} + +/* Set something in the configuration space (currently unused) */ +static void vopc_set(struct virtio_device *_vdev, unsigned offset, + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0const void *buf, unsigned len) +{ + =A0 =A0 =A0 struct vop_vdev *vdev =3D to_vop_vdev(_vdev); + =A0 =A0 =A0 void __iomem *config =3D vdev->guest_status->config; + + =A0 =A0 =A0 memcpy_toio(config + offset, buf, len);
drivers/virtio/vop_host.c
Quoted 10 lines
drivers/virtio/vop_host.c new file +10
-0+} + +/* Get your own status */ +static u8 vopc_get_status (struct virtio_device *_vdev) +{ + =A0 =A0 =A0 struct vop_vdev *vdev =3D to_vop_vdev(_vdev); + =A0 =A0 =A0 u32 status; + + =A0 =A0 =A0 status =3D le32_to_cpu(vdev->host_status->status); + =A0 =A0 =A0 dev_dbg(&vdev->vdev.dev, "%s(): -> 0x%.2x\n", __func__, (u8=
)status);
Quoted 5 lines
drivers/virtio/vop_host.c new file +5
-0+ + =A0 =A0 =A0 return (u8)status; +} + +/* Set your own status */
drivers/virtio/vop_host.c
Quoted 10 lines
drivers/virtio/vop_host.c new file +10
-0+static void vopc_set_status (struct virtio_device *_vdev,u8 status) +{ + =A0 =A0 =A0 struct vop_vdev *vdev =3D to_vop_vdev(_vdev); + =A0 =A0 =A0 u32 old_status; + + =A0 =A0 =A0 old_status =3D le32_to_cpu(vdev->host_status->status); + =A0 =A0 =A0 vdev->host_status->status =3D cpu_to_le32(status); + + =A0 =A0 =A0 dev_dbg(&vdev->vdev.dev, "%s(): <- 0x%.2x (was 0x%.2x)\n", + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 __func__, status, old_statu=
s);
drivers/virtio/vop_host.c line 655
Quoted 3 lines
drivers/virtio/vop_host.c new file +3
-0+ + =A0 =A0 =A0 /* +=A0 =A0 =A0 =A0* FIXME: we really need to notify the other side when st=
atus changes
Quoted 5 lines
drivers/virtio/vop_host.c new file +5
-0+=A0 =A0 =A0 =A0* FIXME: happen, so that they can take some action +=A0 =A0 =A0 =A0*/ +} + +/* Reset your own status */
drivers/virtio/vop_host.c
Quoted 10 lines
drivers/virtio/vop_host.c new file +10
-0+static void vopc_reset (struct virtio_device *_vdev) +{ + =A0 =A0 =A0 struct vop_vdev *vdev =3D to_vop_vdev(_vdev); + + =A0 =A0 =A0 dev_dbg(&vdev->vdev.dev, "%s(): status reset\n", __func__); + =A0 =A0 =A0 vdev->host_status->status =3D cpu_to_le32(0); +} + +static struct virtqueue *vopc_find_vq(struct virtio_device *_vdev, + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0=
=A0 =A0 =A0 =A0unsigned index,
drivers/virtio/vop_host.c line 671
Quoted 1 line
drivers/virtio/vop_host.c new file +1
-0+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0=
=A0 =A0 =A0 =A0void (*cb)(struct virtqueue *vq))
drivers/virtio/vop_host.c line 679
Quoted 8 lines
drivers/virtio/vop_host.c new file +8
-0+{ + =A0 =A0 =A0 struct vop_vdev *vdev =3D to_vop_vdev(_vdev); + =A0 =A0 =A0 struct vop_vq *vq =3D &vdev->virtqueues[index]; + =A0 =A0 =A0 int i; + + =A0 =A0 =A0 /* Check that we support the virtqueue at this index */ + =A0 =A0 =A0 if (index >=3D ARRAY_SIZE(vdev->virtqueues)) { + =A0 =A0 =A0 =A0 =A0 =A0 =A0 dev_err(&vdev->vdev.dev, "no virtqueue for =
index %d\n", index);
drivers/virtio/vop_host.c line 685
Quoted 6 lines
drivers/virtio/vop_host.c new file +6
-0+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 return ERR_PTR(-ENODEV); + =A0 =A0 =A0 } + + =A0 =A0 =A0 /* HACK: we only support virtio_net for now */ + =A0 =A0 =A0 if (vdev->vdev.id.device !=3D VIRTIO_ID_NET) { + =A0 =A0 =A0 =A0 =A0 =A0 =A0 dev_err(&vdev->vdev.dev, "only virtio_net i=
s supported\n");
Quoted 8 lines
drivers/virtio/vop_host.c new file +8
-0+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 return ERR_PTR(-ENODEV); + =A0 =A0 =A0 } + + =A0 =A0 =A0 /* Initialize the virtqueue to a clean state */ + =A0 =A0 =A0 vq->num_free =3D VOP_RING_SIZE; + =A0 =A0 =A0 vq->dev =3D &vdev->vdev.dev; + + =A0 =A0 =A0 switch (index) {
drivers/virtio/vop_host.c line 703
Quoted 10 lines
drivers/virtio/vop_host.c new file +10
-0+ =A0 =A0 =A0 case 0: /* x86 recv virtqueue -- ppc xmit virtqueue */ + =A0 =A0 =A0 =A0 =A0 =A0 =A0 vq->guest =3D vdev->rem + 1024; + =A0 =A0 =A0 =A0 =A0 =A0 =A0 vq->host =A0=3D vdev->loc + 1024; + =A0 =A0 =A0 =A0 =A0 =A0 =A0 break; + =A0 =A0 =A0 case 1: /* x86 xmit virtqueue -- ppc recv virtqueue */ + =A0 =A0 =A0 =A0 =A0 =A0 =A0 vq->guest =3D vdev->rem + 2048; + =A0 =A0 =A0 =A0 =A0 =A0 =A0 vq->host =A0=3D vdev->loc + 2048; + =A0 =A0 =A0 =A0 =A0 =A0 =A0 break; + =A0 =A0 =A0 default: + =A0 =A0 =A0 =A0 =A0 =A0 =A0 dev_err(vq->dev, "unknown virtqueue %d\n", =
index);
drivers/virtio/vop_host.c line 712
Quoted 9 lines
drivers/virtio/vop_host.c new file +9
-0+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 return ERR_PTR(-ENODEV); + =A0 =A0 =A0 } + + =A0 =A0 =A0 /* Initialize the descriptor, avail, and used rings */ + =A0 =A0 =A0 for (i =3D 0; i < VOP_RING_SIZE; i++) { + =A0 =A0 =A0 =A0 =A0 =A0 =A0 vop_set_desc_addr(vq, i, 0x0); + =A0 =A0 =A0 =A0 =A0 =A0 =A0 vop_set_desc_len(vq, i, 0); + =A0 =A0 =A0 =A0 =A0 =A0 =A0 vop_set_desc_flags(vq, i, 0); + =A0 =A0 =A0 =A0 =A0 =A0 =A0 vop_set_desc_next(vq, i, (i + 1) & (VOP_RIN=
G_SIZE - 1));
Quoted 17 lines
drivers/virtio/vop_host.c new file +17
-0+ + =A0 =A0 =A0 =A0 =A0 =A0 =A0 vop_set_avail_entry(vq, i, 0); + =A0 =A0 =A0 =A0 =A0 =A0 =A0 vq->host->used[i].id =3D cpu_to_le32(0); + =A0 =A0 =A0 =A0 =A0 =A0 =A0 vq->host->used[i].len =3D cpu_to_le32(0); + =A0 =A0 =A0 } + + =A0 =A0 =A0 vq->avail_idx =3D 0; + =A0 =A0 =A0 vop_set_avail_idx(vq, 0); + =A0 =A0 =A0 vop_set_host_flags(vq, 0); + + =A0 =A0 =A0 debug_dump_rings(vq, "found a virtqueue, dumping rings"); + + =A0 =A0 =A0 vq->vq.callback =3D cb; + =A0 =A0 =A0 vq->vq.vdev =3D &vdev->vdev; + =A0 =A0 =A0 vq->vq.vq_ops =3D &vop_vq_ops; + + =A0 =A0 =A0 return &vq->vq;
drivers/virtio/vop_host.c line 739
Quoted 10 lines
drivers/virtio/vop_host.c new file +10
-0+} + +static void vopc_del_vq (struct virtqueue *_vq) +{ + =A0 =A0 =A0 struct vop_vq *vq =3D to_vop_vq(_vq); + =A0 =A0 =A0 int i; + + =A0 =A0 =A0 /* FIXME: make sure that DMA has stopped by this point */ + + =A0 =A0 =A0 /* Unmap and remove all outstanding descriptors from the ri=
ng */
drivers/virtio/vop_host.c line 742
Quoted 3 lines
drivers/virtio/vop_host.c new file +3
-0+ =A0 =A0 =A0 for (i =3D 0; i < VOP_RING_SIZE; i++) { + =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (vq->data[i]) { + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 dev_dbg(vq->dev, "cleanup d=
etach buffer at index %d\n", i);
Quoted 4 lines
drivers/virtio/vop_host.c new file +4
-0+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 detach_buf(vq, i); + =A0 =A0 =A0 =A0 =A0 =A0 =A0 } + =A0 =A0 =A0 } +
drivers/virtio/vop_host.c line 756
Quoted 10 lines
drivers/virtio/vop_host.c new file +10
-0+ =A0 =A0 =A0 debug_dump_rings(vq, "virtqueue destroyed, dumping rings"); +} + +static u32 vopc_get_features (struct virtio_device *_vdev) +{ + =A0 =A0 =A0 struct vop_vdev *vdev =3D to_vop_vdev(_vdev); + =A0 =A0 =A0 u32 ret; + + =A0 =A0 =A0 ret =3D vop_get_guest_features(vdev); + =A0 =A0 =A0 dev_info(&vdev->vdev.dev, "%s(): guest features 0x%.8x\n", =
__func__, ret);
drivers/virtio/vop_host.c line 769
Quoted 13 lines
drivers/virtio/vop_host.c new file +13
-0+ + =A0 =A0 =A0 return ret; +} + +static void vopc_finalize_features (struct virtio_device *_vdev) +{ + =A0 =A0 =A0 struct vop_vdev *vdev =3D to_vop_vdev(_vdev); + + =A0 =A0 =A0 /* + =A0 =A0 =A0 =A0* TODO: notify the other side at this point + =A0 =A0 =A0 =A0*/ + + =A0 =A0 =A0 vdev->host_status->features[0] =3D cpu_to_le32(vdev->vdev.f=
eatures[0]);
drivers/virtio/vop_host.c line 770
Quoted 1 line
drivers/virtio/vop_host.c new file +1
-0+ =A0 =A0 =A0 dev_info(&vdev->vdev.dev, "%s(): final features 0x%.8lx\n",=
__func__, vdev->vdev.features[0]);
Quoted 5 lines
drivers/virtio/vop_host.c new file +5
-0+} + +static struct virtio_config_ops vop_config_ops =3D { + =A0 =A0 =A0 .get =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0=3D vopc_get, + =A0 =A0 =A0 .set =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0=3D vopc_set,
drivers/virtio/vop_host.c line 785
Quoted 10 lines
drivers/virtio/vop_host.c new file +10
-0+ =A0 =A0 =A0 .get_status =A0 =A0 =A0 =A0 =A0 =A0 =3D vopc_get_status, + =A0 =A0 =A0 .set_status =A0 =A0 =A0 =A0 =A0 =A0 =3D vopc_set_status, + =A0 =A0 =A0 .reset =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0=3D vopc_reset, + =A0 =A0 =A0 .find_vq =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0=3D vopc_find_vq, + =A0 =A0 =A0 .del_vq =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =3D vopc_del_vq, + =A0 =A0 =A0 .get_features =A0 =A0 =A0 =A0 =A0 =3D vopc_get_features, + =A0 =A0 =A0 .finalize_features =A0 =A0 =A0=3D vopc_finalize_features, +}; + +/*----------------------------------------------------------------------=
------*/
drivers/virtio/vop_host.c line 786
Quoted 1 line
drivers/virtio/vop_host.c new file +1
-0+/* Setup code for virtio devices =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0=
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0*/
drivers/virtio/vop_host.c line 787
Quoted 1 line
drivers/virtio/vop_host.c new file +1
-0+/*----------------------------------------------------------------------=
------*/
drivers/virtio/vop_host.c
Quoted 13 lines
drivers/virtio/vop_host.c new file +13
-0+ +static void vop_release (struct device *dev) +{ + =A0 =A0 =A0 dev_dbg(dev, "calling device release\n"); +} + +static int setup_virtio_device (struct vop_dev *priv,int devnum) +{ + =A0 =A0 =A0 struct vop_vdev *vdev =3D &priv->devices[devnum]; + =A0 =A0 =A0 struct device *dev =3D priv->dev; + =A0 =A0 =A0 int i; + + =A0 =A0 =A0 /* Set up the pointers to the guest and host memory areas *=
/
drivers/virtio/vop_host.c line 803
Quoted 3 lines
drivers/virtio/vop_host.c new file +3
-0+ =A0 =A0 =A0 vdev->loc =3D priv->host_mem + (devnum * 4096); + =A0 =A0 =A0 vdev->rem =3D priv->netregs =A0+ (devnum * 4096); + =A0 =A0 =A0 dev_dbg(dev, "memory guest 0x%p host 0x%p\n", vdev->rem, vd=
ev->loc);
drivers/virtio/vop_host.c line 805
Quoted 2 lines
drivers/virtio/vop_host.c new file +2
-0+ + =A0 =A0 =A0 /* Set up the pointers to the guest and host status areas *=
/
drivers/virtio/vop_host.c line 808
Quoted 3 lines
drivers/virtio/vop_host.c new file +3
-0+ =A0 =A0 =A0 vdev->guest_status =3D vdev->rem; + =A0 =A0 =A0 vdev->host_status =A0=3D vdev->loc; + =A0 =A0 =A0 dev_dbg(dev, "status guest 0x%p host 0x%p\n", vdev->rem, vd=
ev->loc);
drivers/virtio/vop_host.c line 810
Quoted 2 lines
drivers/virtio/vop_host.c new file +2
-0+ + =A0 =A0 =A0 /* The find_vq() must set up the correct mappings to virtqu=
eues itself,
drivers/virtio/vop_host.c line 813
Quoted 3 lines
drivers/virtio/vop_host.c new file +3
-0+ =A0 =A0 =A0 =A0* so we cannot do it here */ + =A0 =A0 =A0 for (i =3D 0; i < ARRAY_SIZE(vdev->virtqueues); i++) { + =A0 =A0 =A0 =A0 =A0 =A0 =A0 memset(&vdev->virtqueues[i], 0, sizeof(stru=
ct vop_vq));
drivers/virtio/vop_host.c line 815
Quoted 2 lines
drivers/virtio/vop_host.c new file +2
-0+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 vdev->virtqueues[i].immr =3D priv->immr; + =A0 =A0 =A0 =A0 =A0 =A0 =A0 vdev->virtqueues[i].kick_val =3D 1 << ((dev=
num * 4) + i + 2);
drivers/virtio/vop_host.c line 816
Quoted 1 line
drivers/virtio/vop_host.c new file +1
-0+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 dev_dbg(dev, "vq %d cleared, kick %d\n", i,=
(devnum * 4) + i + 2);
drivers/virtio/vop_host.c line 825
Quoted 9 lines
drivers/virtio/vop_host.c new file +9
-0+ =A0 =A0 =A0 } + + =A0 =A0 =A0 /* Zero out the configuration space completely */ + =A0 =A0 =A0 memset(vdev->host_status, 0, 1024); + + =A0 =A0 =A0 /* Copy the parent DMA parameters to this virtio_device */ + =A0 =A0 =A0 vdev->vdev.dev.dma_mask =3D dev->dma_mask; + =A0 =A0 =A0 vdev->vdev.dev.dma_parms =3D dev->dma_parms; + =A0 =A0 =A0 vdev->vdev.dev.coherent_dma_mask =3D dev->coherent_dma_mask=
;
Quoted 10 lines
drivers/virtio/vop_host.c new file +10
-0+ + =A0 =A0 =A0 /* Setup everything except the device type */ + =A0 =A0 =A0 vdev->vdev.dev.release =3D &vop_release; + =A0 =A0 =A0 vdev->vdev.dev.parent =A0=3D dev; + =A0 =A0 =A0 vdev->vdev.config =A0 =A0 =A0=3D &vop_config_ops; + + =A0 =A0 =A0 return 0; +} + +static int register_virtio_net(struct vop_dev *priv)
drivers/virtio/vop_host.c line 845
Quoted 10 lines
drivers/virtio/vop_host.c new file +10
-0+{ + =A0 =A0 =A0 struct vop_vdev *vdev =3D &priv->devices[0]; + =A0 =A0 =A0 struct virtio_net_config *config; + =A0 =A0 =A0 unsigned long features =3D 0; + =A0 =A0 =A0 int ret; + + =A0 =A0 =A0 /* Run the common setup routine */ + =A0 =A0 =A0 ret =3D setup_virtio_device(priv, 0); + =A0 =A0 =A0 if (ret) { + =A0 =A0 =A0 =A0 =A0 =A0 =A0 dev_err(priv->dev, "unable to setup virtio_=
net\n");
drivers/virtio/vop_host.c line 851
Quoted 6 lines
drivers/virtio/vop_host.c new file +6
-0+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 return ret; + =A0 =A0 =A0 } + + =A0 =A0 =A0 /* Generate a random ethernet address for the other side + =A0 =A0 =A0 =A0* + =A0 =A0 =A0 =A0* This is necessary so we can allow it to give us a cons=
istent
drivers/virtio/vop_host.c line 856
Quoted 5 lines
drivers/virtio/vop_host.c new file +5
-0+ =A0 =A0 =A0 =A0* MAC address for itself, using something board-specific + =A0 =A0 =A0 =A0* + =A0 =A0 =A0 =A0* The feature bits must match for it to work correctly + =A0 =A0 =A0 =A0*/ + =A0 =A0 =A0 config =3D (struct virtio_net_config *)vdev->host_status->c=
onfig;
Quoted 7 lines
drivers/virtio/vop_host.c new file +7
-0+ =A0 =A0 =A0 random_ether_addr(config->mac); + =A0 =A0 =A0 dev_info(priv->dev, "Generated MAC %pM\n", config->mac); + + =A0 =A0 =A0 /* Set the feature bits for the device */ + =A0 =A0 =A0 set_bit(VIRTIO_NET_F_MAC, =A0 =A0 =A0 &features); + =A0 =A0 =A0 set_bit(VIRTIO_NET_F_CSUM, =A0 =A0 =A0&features); + =A0 =A0 =A0 set_bit(VIRTIO_NET_F_GSO, =A0 =A0 =A0 &features);
drivers/virtio/vop_host.c line 873
Quoted 10 lines
drivers/virtio/vop_host.c new file +10
-0+ =A0 =A0 =A0 set_bit(VIRTIO_NET_F_MRG_RXBUF, &features); + + =A0 =A0 =A0 vdev->host_status->features[0] =3D cpu_to_le32(features); + =A0 =A0 =A0 vdev->vdev.id.device =3D VIRTIO_ID_NET; + + =A0 =A0 =A0 /* Register the virtio device */ + =A0 =A0 =A0 return register_virtio_device(&vdev->vdev); +} + +/*----------------------------------------------------------------------=
------*/
drivers/virtio/vop_host.c line 874
Quoted 1 line
drivers/virtio/vop_host.c new file +1
-0+/* Interrupt Handling =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 */
drivers/virtio/vop_host.c line 875
Quoted 1 line
drivers/virtio/vop_host.c new file +1
-0+/*----------------------------------------------------------------------=
------*/
Quoted 21 lines
drivers/virtio/vop_host.c new file +21
-0+ +static irqreturn_t vdev_interrupt(int irq, void *dev_id) +{ + =A0 =A0 =A0 struct vop_dev *priv =3D dev_id; + =A0 =A0 =A0 struct virtqueue *vq; + =A0 =A0 =A0 u32 omisr, odr; + + =A0 =A0 =A0 omisr =3D ioread32(priv->immr + OMISR_OFFSET); + =A0 =A0 =A0 odr =A0 =3D ioread32(priv->immr + ODR_OFFSET); + + =A0 =A0 =A0 /* Check the status register for doorbell interrupts */ + =A0 =A0 =A0 if (!(omisr & 0x8)) + =A0 =A0 =A0 =A0 =A0 =A0 =A0 return IRQ_NONE; + + =A0 =A0 =A0 /* Clear all doorbell interrupts */ + =A0 =A0 =A0 iowrite32(odr, priv->immr + ODR_OFFSET); + + =A0 =A0 =A0 if (odr & 0x4) { + =A0 =A0 =A0 =A0 =A0 =A0 =A0 vq =3D &priv->devices[0].virtqueues[0].vq; + =A0 =A0 =A0 =A0 =A0 =A0 =A0 vq->callback(vq); + =A0 =A0 =A0 }
drivers/virtio/vop_host.c line 906
Quoted 10 lines
drivers/virtio/vop_host.c new file +10
-0+ + =A0 =A0 =A0 if (odr & 0x8) { + =A0 =A0 =A0 =A0 =A0 =A0 =A0 vq =3D &priv->devices[0].virtqueues[1].vq; + =A0 =A0 =A0 =A0 =A0 =A0 =A0 vq->callback(vq); + =A0 =A0 =A0 } + + =A0 =A0 =A0 return IRQ_HANDLED; +} + +/*----------------------------------------------------------------------=
------*/
drivers/virtio/vop_host.c line 907
Quoted 1 line
drivers/virtio/vop_host.c new file +1
-0+/* PCI Subsystem =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0=
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0*/
drivers/virtio/vop_host.c line 908
Quoted 1 line
drivers/virtio/vop_host.c new file +1
-0+/*----------------------------------------------------------------------=
------*/
drivers/virtio/vop_host.c line 910
Quoted 2 lines
drivers/virtio/vop_host.c new file +2
-0+ +static int vop_probe(struct pci_dev *dev, const struct pci_device_id *id=
)
Quoted 26 lines
drivers/virtio/vop_host.c new file +26
-0+{ + =A0 =A0 =A0 struct vop_dev *priv; + =A0 =A0 =A0 int ret; + + =A0 =A0 =A0 priv =3D kzalloc(sizeof(*priv), GFP_KERNEL); + =A0 =A0 =A0 if (!priv) { + =A0 =A0 =A0 =A0 =A0 =A0 =A0 ret =3D -ENOMEM; + =A0 =A0 =A0 =A0 =A0 =A0 =A0 goto out_return; + =A0 =A0 =A0 } + + =A0 =A0 =A0 pci_set_drvdata(dev, priv); + =A0 =A0 =A0 priv->dev =3D &dev->dev; + + =A0 =A0 =A0 /* Hardware Initialization */ + =A0 =A0 =A0 ret =3D pci_enable_device(dev); + =A0 =A0 =A0 if (ret) + =A0 =A0 =A0 =A0 =A0 =A0 =A0 goto out_kfree_priv; + + =A0 =A0 =A0 pci_set_master(dev); + =A0 =A0 =A0 ret =3D pci_request_regions(dev, driver_name); + =A0 =A0 =A0 if (ret) + =A0 =A0 =A0 =A0 =A0 =A0 =A0 goto out_pci_disable_device; + + =A0 =A0 =A0 priv->immr =3D pci_ioremap_bar(dev, 0); + =A0 =A0 =A0 if (!priv->immr) { + =A0 =A0 =A0 =A0 =A0 =A0 =A0 ret =3D -ENOMEM;
drivers/virtio/vop_host.c line 946
Quoted 10 lines
drivers/virtio/vop_host.c new file +10
-0+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 goto out_pci_release_regions; + =A0 =A0 =A0 } + + =A0 =A0 =A0 priv->netregs =3D pci_ioremap_bar(dev, 1); + =A0 =A0 =A0 if (!priv->netregs) { + =A0 =A0 =A0 =A0 =A0 =A0 =A0 ret =3D -ENOMEM; + =A0 =A0 =A0 =A0 =A0 =A0 =A0 goto out_iounmap_immr; + =A0 =A0 =A0 } + + =A0 =A0 =A0 /* The device can only see the lowest 1GB of memory over th=
e bus */
drivers/virtio/vop_host.c line 950
Quoted 4 lines
drivers/virtio/vop_host.c new file +4
-0+ =A0 =A0 =A0 dev->dev.coherent_dma_mask =3D DMA_BIT_MASK(30); + =A0 =A0 =A0 ret =3D dma_set_mask(&dev->dev, DMA_BIT_MASK(30)); + =A0 =A0 =A0 if (ret) { + =A0 =A0 =A0 =A0 =A0 =A0 =A0 dev_err(&dev->dev, "Unable to set DMA mask\=
n");
drivers/virtio/vop_host.c line 955
Quoted 5 lines
drivers/virtio/vop_host.c new file +5
-0+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 goto out_iounmap_netregs; + =A0 =A0 =A0 } + + =A0 =A0 =A0 /* Allocate the host memory, for writing by the guest */ + =A0 =A0 =A0 priv->host_mem =3D dma_alloc_coherent(&dev->dev, VOP_HOST_M=
EM_SIZE,
drivers/virtio/vop_host.c line 956
Quoted 1 line
drivers/virtio/vop_host.c new file +1
-0+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 &priv->host_mem_addr, GFP_K=
ERNEL);
drivers/virtio/vop_host.c line 958
Quoted 2 lines
drivers/virtio/vop_host.c new file +2
-0+ =A0 =A0 =A0 if (!priv->host_mem) { + =A0 =A0 =A0 =A0 =A0 =A0 =A0 dev_err(&dev->dev, "Unable to allocate host=
memory\n");
drivers/virtio/vop_host.c line 963
Quoted 5 lines
drivers/virtio/vop_host.c new file +5
-0+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 ret =3D -ENOMEM; + =A0 =A0 =A0 =A0 =A0 =A0 =A0 goto out_iounmap_netregs; + =A0 =A0 =A0 } + + =A0 =A0 =A0 /* We use the guest's mailbox 0 to hold the host memory add=
ress */
drivers/virtio/vop_host.c line 975
Quoted 12 lines
drivers/virtio/vop_host.c new file +12
-0+ =A0 =A0 =A0 iowrite32(priv->host_mem_addr, priv->immr + IMR0_OFFSET); + + =A0 =A0 =A0 /* Reset all of the devices */ + =A0 =A0 =A0 iowrite32(0x1, priv->immr + IDR_OFFSET); + + =A0 =A0 =A0 /* Mask all of the MBOX interrupts */ + =A0 =A0 =A0 iowrite32(0x1 | 0x2, priv->immr + OMIMR_OFFSET); + + =A0 =A0 =A0 /* Setup the virtio_net instance */ + =A0 =A0 =A0 ret =3D register_virtio_net(priv); + =A0 =A0 =A0 if (ret) { + =A0 =A0 =A0 =A0 =A0 =A0 =A0 dev_err(&dev->dev, "Unable to register virt=
io_net\n");
drivers/virtio/vop_host.c line 980
Quoted 5 lines
drivers/virtio/vop_host.c new file +5
-0+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 goto out_free_host_mem; + =A0 =A0 =A0 } + + =A0 =A0 =A0 /* Hook up the interrupt handler */ + =A0 =A0 =A0 ret =3D request_irq(dev->irq, vdev_interrupt, IRQF_SHARED, =
driver_name, priv);
drivers/virtio/vop_host.c line 982
Quoted 2 lines
drivers/virtio/vop_host.c new file +2
-0+ =A0 =A0 =A0 if (ret) { + =A0 =A0 =A0 =A0 =A0 =A0 =A0 dev_err(&dev->dev, "Unable to register inte=
rrupt handler\n");
drivers/virtio/vop_host.c line 995
Quoted 13 lines
drivers/virtio/vop_host.c new file +13
-0+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 goto out_unregister_virtio_net; + =A0 =A0 =A0 } + + =A0 =A0 =A0 /* Start virtio_net */ + =A0 =A0 =A0 iowrite32(0x1, priv->immr + IMR1_OFFSET); + =A0 =A0 =A0 iowrite32(0x2, priv->immr + IDR_OFFSET); + + =A0 =A0 =A0 return 0; + +out_unregister_virtio_net: + =A0 =A0 =A0 unregister_virtio_device(&priv->devices[0].vdev); +out_free_host_mem: + =A0 =A0 =A0 dma_free_coherent(&dev->dev, VOP_HOST_MEM_SIZE, priv->host_=
mem,
Quoted 18 lines
drivers/virtio/vop_host.c new file +18
-0+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 priv->host_mem_addr); +out_iounmap_netregs: + =A0 =A0 =A0 iounmap(priv->netregs); +out_iounmap_immr: + =A0 =A0 =A0 iounmap(priv->immr); +out_pci_release_regions: + =A0 =A0 =A0 pci_release_regions(dev); +out_pci_disable_device: + =A0 =A0 =A0 pci_disable_device(dev); +out_kfree_priv: + =A0 =A0 =A0 kfree(priv); +out_return: + =A0 =A0 =A0 return ret; +} + +static void vop_remove(struct pci_dev *dev) +{ + =A0 =A0 =A0 struct vop_dev *priv =3D pci_get_drvdata(dev);
drivers/virtio/vop_host.c
Quoted 10 lines
drivers/virtio/vop_host.c new file +10
-0+ + =A0 =A0 =A0 free_irq(dev->irq, priv); + + =A0 =A0 =A0 /* Reset everything */ + =A0 =A0 =A0 iowrite32(0x1, priv->immr + IDR_OFFSET); + + =A0 =A0 =A0 /* Unregister virtio_net */ + =A0 =A0 =A0 unregister_virtio_device(&priv->devices[0].vdev); + + =A0 =A0 =A0 /* Clear the host memory address from the guest's mailbox 0=
*/
drivers/virtio/vop_host.c line 1027
Quoted 4 lines
drivers/virtio/vop_host.c new file +4
-0+ =A0 =A0 =A0 iowrite32(0x0, priv->immr + IMR0_OFFSET); + =A0 =A0 =A0 iowrite32(0x0, priv->immr + IMR1_OFFSET); + + =A0 =A0 =A0 dma_free_coherent(&dev->dev, VOP_HOST_MEM_SIZE, priv->host_=
mem,
drivers/virtio/vop_host.c line 1040
Quoted 13 lines
drivers/virtio/vop_host.c new file +13
-0+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 priv->host_mem_addr); + =A0 =A0 =A0 iounmap(priv->netregs); + =A0 =A0 =A0 iounmap(priv->immr); + =A0 =A0 =A0 pci_release_regions(dev); + =A0 =A0 =A0 pci_disable_device(dev); + =A0 =A0 =A0 kfree(priv); +} + +#define PCI_DEVID_FSL_MPC8349EMDS 0x0080 + +/* The list of devices that this module will support */ +static struct pci_device_id vop_ids[] =3D { + =A0 =A0 =A0 { PCI_DEVICE(PCI_VENDOR_ID_FREESCALE, PCI_DEVID_FSL_MPC8349=
EMDS), },
drivers/virtio/vop_host.c line 1052
Quoted 12 lines
drivers/virtio/vop_host.c new file +12
-0+ =A0 =A0 =A0 { 0, } +}; +MODULE_DEVICE_TABLE(pci, vop_ids); + +static struct pci_driver vop_pci_driver =3D { + =A0 =A0 =A0 .name =A0 =A0 =3D (char *)driver_name, + =A0 =A0 =A0 .id_table =3D vop_ids, + =A0 =A0 =A0 .probe =A0 =A0=3D vop_probe, + =A0 =A0 =A0 .remove =A0 =3D vop_remove, +}; + +/*----------------------------------------------------------------------=
------*/
drivers/virtio/vop_host.c line 1053
Quoted 1 line
drivers/virtio/vop_host.c new file +1
-0+/* Module Init / Exit =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 */
drivers/virtio/vop_host.c line 1054
Quoted 1 line
drivers/virtio/vop_host.c new file +1
-0+/*----------------------------------------------------------------------=
------*/
Quoted 23 lines
drivers/virtio/vop_host.c new file +17
-0+ +static int __init vop_init(void) +{ + =A0 =A0 =A0 return pci_register_driver(&vop_pci_driver); +} + +static void __exit vop_exit(void) +{ + =A0 =A0 =A0 pci_unregister_driver(&vop_pci_driver); +} + +MODULE_AUTHOR("Ira W. Snyder <[email protected]>"); +MODULE_DESCRIPTION("Virtio-PCI-Host Test Driver"); +MODULE_LICENSE("GPL"); + +module_init(vop_init); +module_exit(vop_exit);drivers/virtio/vop_hw.h new file +0
-0
drivers/virtio/vop_hw.h line 2
Quoted 2 lines
drivers/virtio/vop_hw.h new file +2
-0@@ -0,0 +1,80 @@ +/* + * Register offsets for the MPC8349EMDS Message Unit from the IMMR base =
address
drivers/virtio/vop_hw.h
Quoted 4 lines
drivers/virtio/vop_hw.h new file +4
-0+ * + * Copyright (c) 2008 Ira W. Snyder <[email protected]> + * + * This file is licensed under the terms of the GNU General Public Licen=
se
drivers/virtio/vop_hw.h line 7
Quoted 1 line
drivers/virtio/vop_hw.h new file +1
-0+ * version 2. This program is licensed "as is" without any warranty of a=
ny
Quoted 76 lines
drivers/virtio/vop_hw.h new file +73
-1+ * kind, whether express or implied. + */ + +#ifndef PCINET_HW_H +#define PCINET_HW_H + +#define SGPRL_OFFSET =A0 =A0 =A0 =A0 =A0 0x0100 +#define SGPRH_OFFSET =A0 =A0 =A0 =A0 =A0 0x0104 + +/* mpc8349emds message unit register offsets */ +#define OMISR_OFFSET =A0 =A0 =A0 =A0 =A0 0x8030 +#define OMIMR_OFFSET =A0 =A0 =A0 =A0 =A0 0x8034 +#define IMR0_OFFSET =A0 =A0 =A0 =A0 =A0 =A00x8050 +#define IMR1_OFFSET =A0 =A0 =A0 =A0 =A0 =A00x8054 +#define OMR0_OFFSET =A0 =A0 =A0 =A0 =A0 =A00x8058 +#define OMR1_OFFSET =A0 =A0 =A0 =A0 =A0 =A00x805C +#define ODR_OFFSET =A0 =A0 =A0 =A0 =A0 =A0 0x8060 +#define IDR_OFFSET =A0 =A0 =A0 =A0 =A0 =A0 0x8068 +#define IMISR_OFFSET =A0 =A0 =A0 =A0 =A0 0x8080 +#define IMIMR_OFFSET =A0 =A0 =A0 =A0 =A0 0x8084 + + +/* mpc8349emds pci and local access window register offsets */ +#define LAWAR0_OFFSET =A0 =A0 =A0 =A0 =A00x0064 +#define LAWAR0_ENABLE =A0 =A0 =A0 =A0 =A0(1<<31) + +#define POCMR0_OFFSET =A0 =A0 =A0 =A0 =A00x8410 +#define POCMR0_ENABLE =A0 =A0 =A0 =A0 =A0(1<<31) + +#define POTAR0_OFFSET =A0 =A0 =A0 =A0 =A00x8400 + +#define LAWAR1_OFFSET =A0 =A0 =A0 =A0 =A00x006c +#define LAWAR1_ENABLE =A0 =A0 =A0 =A0 =A0(1<<31) + +#define POCMR1_OFFSET =A0 =A0 =A0 =A0 =A00x8428 +#define POCMR1_ENABLE =A0 =A0 =A0 =A0 =A0(1<<31) + +#define POTAR1_OFFSET =A0 =A0 =A0 =A0 =A00x8418 + + +/* mpc8349emds dma controller register offsets */ +#define DMAMR0_OFFSET =A0 =A0 =A0 =A0 =A00x8100 +#define DMASR0_OFFSET =A0 =A0 =A0 =A0 =A00x8104 +#define DMASAR0_OFFSET =A0 =A0 =A0 =A0 0x8110 +#define DMADAR0_OFFSET =A0 =A0 =A0 =A0 0x8118 +#define DMABCR0_OFFSET =A0 =A0 =A0 =A0 0x8120 + +#define DMA_CHANNEL_BUSY =A0 =A0 =A0 (1<<2) + +#define DMA_DIRECT_MODE_SNOOP =A0(1<<20) +#define DMA_CHANNEL_MODE_DIRECT =A0 =A0 =A0 =A0(1<<2) +#define DMA_CHANNEL_START =A0 =A0 =A0(1<<0) + + +/* mpc8349emds pci and local access window register offsets */ +#define LAWAR0_OFFSET =A0 =A0 =A0 =A0 =A00x0064 +#define LAWAR0_ENABLE =A0 =A0 =A0 =A0 =A0(1<<31) + +#define POCMR0_OFFSET =A0 =A0 =A0 =A0 =A00x8410 +#define POCMR0_ENABLE =A0 =A0 =A0 =A0 =A0(1<<31) + +#define POTAR0_OFFSET =A0 =A0 =A0 =A0 =A00x8400 + + +/* mpc8349emds pci and inbound window register offsets */ +#define PITAR0_OFFSET =A0 =A0 =A0 =A0 =A00x8568 +#define PIWAR0_OFFSET =A0 =A0 =A0 =A0 =A00x8578 + +#define PIWAR0_ENABLED =A0 =A0 =A0 =A0 (1<<31) +#define PIWAR0_PREFETCH =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0(1<<29) +#define PIWAR0_IWS_4K =A0 =A0 =A0 =A0 =A00xb + +#endif /* PCINET_HW_H */ --1.5.4.3
Quoted 2 lines
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" i=
n
Quoted 4 lines
the body of a message to [email protected]
More majordomo info at =A0http://vger.kernel.org/majordomo-info.html Please read the FAQ at =A0http://www.tux.org/lkml/
--=20
Grant Likely, B.Sc., P.Eng.
Secret Lab Technologies Ltd.
Hi Grant,
Quoted 11 lines
I like this a lot. I need to do much the same thing on one of my platforms, so I'm going to use your patch as my starting point. Have you made many changes since you posted this version of your patch? I'd like to collaborate on the development and help to get it mainlined.
In my case I've got an MPC5200 as the 'host' and a Xilinx Virtex (ppc440) as the 'client'. I intend set aside a region of the Xilinx Virtex's memory space for the shared queues. I'm starting work on it now, and I'll provide you with feedback and/or patches as I make progress.
I'll let Ira update you on the patch status.
If you want someone to chat about the hardware-level interaction, feel free to chat off-list - assuming of course that no one wants to hear us talk hardware :)
I selected the MPC8349EA in-part due to its PCI mailboxes, so that we could implement this type of driver (an interlocked handshake for flow control of data transfers). The previous chip I'd used was a PLX PCI9054 Master/Target, and it has similar registers.
I'm not sure if the Xilinx PCI core, or whatever PCI core you are using, already has something like the mailboxes implemented, but if not, it won't take much to code up some logic. I prefer VHDL myself, but can speak Verilog if forced to :)
Cheers,
Dave
Quoted 12 lines · David Hawkins
I'll let Ira update you on the patch status.
If you want someone to chat about the hardware-level interaction, feel free to chat off-list - assuming of course that no one wants to hear us talk hardware :)
I selected the MPC8349EA in-part due to its PCI mailboxes, so that we could implement this type of driver (an interlocked handshake for flow control of data transfers). The previous chip I'd used was a PLX PCI9054 Master/Target, and it has similar registers.
Quoted 4 lines
I'm not sure if the Xilinx PCI core, or whatever PCI core you are using, already has something like the mailboxes implemented, but if not, it won't take much to code up some logic. I prefer VHDL myself, but can speak Verilog if forced to :)
Thanks David. I haven't looked closely at the xilinx pci data sheet yet, but I don't expect too many issues in this area. As you say, it won't take much to code it up. I'll be poking my VHDL engineer to make it do what I want it to. :-)
I'll keep you up to date on my progress.
g.
Signature · 2 lines
Grant Likely, B.Sc., P.Eng. Secret Lab Technologies Ltd.
Hi Grant,
Quoted 4 lines
Thanks David. I haven't looked closely at the xilinx pci data sheet yet, but I don't expect too many issues in this area. As you say, it won't take much to code it up. I'll be poking my VHDL engineer to make it do what I want it to. :-)
The key aspects of the core will be that it is Master/Target so that it can take over the PCI bus, and that it has a DMA engine that can take care of most of the work. In your case, since you have a DMA controller on the host (MPC5200) and the target (Xilinx), your driver might end up having nicer symmetry than our application. The most efficient implementation will be the one that uses PCI writes, i.e., MPC5200 DMAs to the Xilinx core, and the Xilinx core DMAs to the MPC5200. If you use a PCI Target only core, then the MPC5200 DMA controller will have to do all the work, and read transfers might be slightly less efficient.
Our target boards (PowerPC) live in compactPCI backplanes and talk to x86 boards that do not have DMA controllers. So the PCI target board DMA controllers are used to transfer data efficiently to the x86 host (writes) and less efficiently from the host to the boards (reads). Our bandwidth requirements are 'to the host', so we can live with the asymmetry in performance.
Quoted 1 line
I'll keep you up to date on my progress.
Sounds good.
Cheers,
Dave
On Tue, Apr 14, 2009 at 3:52 PM, David Hawkins <[email protected]> wrote= :
Quoted 7 lines
Hi Grant,
Quoted 4 lines
Thanks David. =A0I haven't looked closely at the xilinx pci data sheet yet, but I don't expect too many issues in this area. =A0As you say, it won't take much to code it up. =A0I'll be poking my VHDL engineer to make it do what I want it to. =A0:-)
Quoted 9 lines
The key aspects of the core will be that it is Master/Target so that it can take over the PCI bus, and that it has a DMA engine that can take care of most of the work. In your case, since you have a DMA controller on the host (MPC5200) and the target (Xilinx), your driver might end up having nicer symmetry than our application. The most efficient implementation will be the one that uses PCI writes, i.e., MPC5200 DMAs to the Xilinx core, and the Xilinx core DMAs to the MPC5200.
Hmmm, I hadn't thought about this. I was intending to use the Virtex's memory region for all virtio, but if I can allocate memory regions on both sides of the PCI bus, then that may be best.
Quoted 4 lines
If you use
a PCI Target only core, then the MPC5200 DMA controller will have to do all the work, and read transfers might be slightly less efficient.
I'll definitely intend to enable master mode on the Xilinx PCI controller.
Quoted 7 lines
Our target boards (PowerPC) live in compactPCI backplanes and talk to x86 boards that do not have DMA controllers. So the PCI target board DMA controllers are used to transfer data efficiently to the x86 host (writes) and less efficiently from the host to the boards (reads). Our bandwidth requirements are 'to the host', so we can live with the asymmetry in performance.
Fortunately I don't have very high bandwidth requirements for the first spin, so I have some room to experiment. :-)
g.
--=20
Grant Likely, B.Sc., P.Eng.
Secret Lab Technologies Ltd.
Hi Grant,
Quoted 3 lines
Hmmm, I hadn't thought about this. I was intending to use the Virtex's memory region for all virtio, but if I can allocate memory regions on both sides of the PCI bus, then that may be best.
Sounds like you can experiment and see what works best :)
Quoted 6 lines
Quoted 4 lines
If you use
a PCI Target only core, then the MPC5200 DMA controller will have to do all the work, and read transfers might be slightly less efficient.I'll definitely intend to enable master mode on the Xilinx PCI controller.
Since you understand the lingo, you clearly understand there are core differences :)
Quoted 10 lines
Quoted 7 lines
Our target boards (PowerPC) live in compactPCI backplanes and talk to x86 boards that do not have DMA controllers. So the PCI target board DMA controllers are used to transfer data efficiently to the x86 host (writes) and less efficiently from the host to the boards (reads). Our bandwidth requirements are 'to the host', so we can live with the asymmetry in performance.
Fortunately I don't have very high bandwidth requirements for the first spin, so I have some room to experiment. :-)
Yes, in theory you have enough bandwidth ... then a few features are added, the PCI core is not quite as fast as advertised, etc etc :)
Cheers,
Dave
Quoted 6 lines · Grant Likely
Quoted 4 lines · Ira Snyder
This adds support to Linux for using virtio between two computers linked by a PCI interface. This allows the use of
virtio_netto create a familiar, fast interface for communication. It should be possible to use other virtio devices in the future, but this has not been tested.
Quoted 8 lines
Hey Ira,
I like this a lot. I need to do much the same thing on one of my platforms, so I'm going to use your patch as my starting point. Have you made many changes since you posted this version of your patch? I'd like to collaborate on the development and help to get it mainlined.
This would be great. I'd really appreciate the help. I haven't had time to make any changes since I last posted the patch. I started work on converting all of the usage of struct vop_loc_* to just use the on-wire structures, but I didn't get very far before other work got in the way.
Quoted 6 lines
In my case I've got an MPC5200 as the 'host' and a Xilinx Virtex (ppc440) as the 'client'. I intend set aside a region of the Xilinx Virtex's memory space for the shared queues. I'm starting work on it now, and I'll provide you with feedback and/or patches as I make progress.
I'm looking forward to seeing your implementation. If you have any questions, I'd be happy to attempt to answer them :)
Ira
Quoted 28 lines · Ira Snyder
Quoted 6 lines · Grant Likely
Quoted 4 lines · Ira Snyder
This adds support to Linux for using virtio between two computers linked by a PCI interface. This allows the use of
virtio_netto create a familiar, fast interface for communication. It should be possible to use other virtio devices in the future, but this has not been tested.Quoted 8 lines
Hey Ira,
I like this a lot. I need to do much the same thing on one of my platforms, so I'm going to use your patch as my starting point. Have you made many changes since you posted this version of your patch? I'd like to collaborate on the development and help to get it mainlined.
This would be great. I'd really appreciate the help. I haven't had time to make any changes since I last posted the patch. I started work on converting all of the usage of struct vop_loc_* to just use the on-wire structures, but I didn't get very far before other work got in the way.
Quoted 6 lines
In my case I've got an MPC5200 as the 'host' and a Xilinx Virtex (ppc440) as the 'client'. I intend set aside a region of the Xilinx Virtex's memory space for the shared queues. I'm starting work on it now, and I'll provide you with feedback and/or patches as I make progress.
Quoted 2 lines
I'm looking forward to seeing your implementation. If you have any questions, I'd be happy to attempt to answer them :)
Hey Ira,
I've been slowly hacking on your virtio-over-pci stuff. I've got an initial series of cleanup patches which address some of the comments from this thread. Before I send them to you, have you made any changes on your end? They likely won't apply without changes to the core code, so I'd like to sync up with you first.
Cheers,
g.
Signature · 2 lines
Grant Likely, B.Sc., P.Eng. Secret Lab Technologies Ltd.
Quoted 32 lines · Grant Likely
Quoted 28 lines · Ira Snyder
Quoted 6 lines · Grant Likely
Quoted 4 lines · Ira Snyder
This adds support to Linux for using virtio between two computers linked by a PCI interface. This allows the use of
virtio_netto create a familiar, fast interface for communication. It should be possible to use other virtio devices in the future, but this has not been tested.Quoted 8 lines
Hey Ira,
I like this a lot. I need to do much the same thing on one of my platforms, so I'm going to use your patch as my starting point. Have you made many changes since you posted this version of your patch? I'd like to collaborate on the development and help to get it mainlined.
This would be great. I'd really appreciate the help. I haven't had time to make any changes since I last posted the patch. I started work on converting all of the usage of struct vop_loc_* to just use the on-wire structures, but I didn't get very far before other work got in the way.
Quoted 6 lines
In my case I've got an MPC5200 as the 'host' and a Xilinx Virtex (ppc440) as the 'client'. I intend set aside a region of the Xilinx Virtex's memory space for the shared queues. I'm starting work on it now, and I'll provide you with feedback and/or patches as I make progress.
Quoted 2 lines
I'm looking forward to seeing your implementation. If you have any questions, I'd be happy to attempt to answer them :)
Quoted 8 lines
Hey Ira,
I've been slowly hacking on your virtio-over-pci stuff. I've got an initial series of cleanup patches which address some of the comments from this thread. Before I send them to you, have you made any changes on your end? They likely won't apply without changes to the core code, so I'd like to sync up with you first.
I haven't made any changes to the code since you've last seen it. I've been busy with other stuff for quite a while now. I can't wait to see what you've done :)
At least for the use of the 83xx DMA controller, the DMA_SLAVE mode patch I posted up about a week ago (to the ppcdev list) could make the DMA setup much simpler. It hasn't been accepted to mainline yet.
Ira