On Tue, Oct 31, 2017 at 9:41 PM, Björn Töpel <bjorn.to...@gmail.com> wrote:
> From: Björn Töpel <bjorn.to...@intel.com>
>
> Here, the PACKET_MEMREG setsockopt is implemented for the AF_PACKET
> protocol family. PACKET_MEMREG allows the user to register memory
> regions that can be used by AF_PACKET V4 as packet data buffers.
>
> Signed-off-by: Björn Töpel <bjorn.to...@intel.com>
> ---
> +/*************** V4 QUEUE OPERATIONS *******************************/
> +
> +/**
> + * tp4q_umem_new - Creates a new umem (packet buffer)
> + *
> + * @addr: The address to the umem
> + * @size: The size of the umem
> + * @frame_size: The size of each frame, between 2K and PAGE_SIZE
> + * @data_headroom: The desired data headroom before start of the packet
> + *
> + * Returns a pointer to the new umem or NULL for failure
> + **/
> +static inline struct tp4_umem *tp4q_umem_new(unsigned long addr, size_t size,
> +                                            unsigned int frame_size,
> +                                            unsigned int data_headroom)
> +{
> +       struct tp4_umem *umem;
> +       unsigned int nframes;
> +
> +       if (frame_size < TP4_UMEM_MIN_FRAME_SIZE || frame_size > PAGE_SIZE) {
> +               /* Strictly speaking we could support this, if:
> +                * - huge pages, or*
> +                * - using an IOMMU, or
> +                * - making sure the memory area is consecutive
> +                * but for now, we simply say "computer says no".
> +                */
> +               return ERR_PTR(-EINVAL);
> +       }
> +
> +       if (!is_power_of_2(frame_size))
> +               return ERR_PTR(-EINVAL);
> +
> +       if (!PAGE_ALIGNED(addr)) {
> +               /* Memory area has to be page size aligned. For
> +                * simplicity, this might change.
> +                */
> +               return ERR_PTR(-EINVAL);
> +       }
> +
> +       if ((addr + size) < addr)
> +               return ERR_PTR(-EINVAL);
> +
> +       nframes = size / frame_size;
> +       if (nframes == 0)
> +               return ERR_PTR(-EINVAL);
> +
> +       data_headroom = ALIGN(data_headroom, 64);
> +
> +       if (frame_size - data_headroom - TP4_KERNEL_HEADROOM < 0)
> +               return ERR_PTR(-EINVAL);

signed comparison on unsigned int

Reply via email to