Subject: Re: [RFC v1 15/19] RDMA/irdma: Add miscellaneous utility definitions

From: Jason Gunthorpe <[email-masked]>
Date: Wed, 20 Feb 2019 09:53:55 -0700

On Wed, Feb 20, 2019 at 02:53:18PM +0000, Saleem, Shiraz wrote:
> >Subject: Re: [RFC v1 15/19] RDMA/irdma: Add miscellaneous utility definitions
> >
> >On Fri, Feb 15, 2019 at 11:11:02AM -0600, Shiraz Saleem wrote:
> >> From: Mustafa Ismail <[email-masked]>
> >>
> >> Add miscellaneous utility functions and headers.
> >>
> 
> [....]
> 
> >
> >> +#define to_device(ptr)						\
> >> +	(&((struct pci_dev *)((ptr)->hw->dev_context))->dev)
> >
> >?? Seems like this wants to be container_of??
> 
> Yes.
> 
> >
> >> +/**
> >> + * irdma_insert_wqe_hdr - write wqe header
> >> + * @wqe: cqp wqe for header
> >> + * @header: header for the cqp wqe
> >> + */
> >> +static inline void irdma_insert_wqe_hdr(__le64 *wqe, u64 hdr) {
> >> +	wmb();   /* make sure WQE is populated before polarity is set */
> >> +	set_64bit_val(wqe, 24, hdr);
> >
> >Generally don't like seeing wmbs in drivers.. Are you sure this isn't supposed to
> >be smp_store_release(), or dma_wmb() perhaps?
> 
> Why is wmb() an issue in drivers?

There are many ways to get a barrier that are much clearer and
maintainable then some random wmb. Rarely do drivers actually need
wmb.

> >> +/**
> >> + * irdma_allocate_dma_mem - Memory alloc helper fn
> >> + * @hw:   pointer to the HW structure
> >> + * @mem:  ptr to mem struct to fill out
> >> + * @size: size of memory requested
> >> + * @alignment: what to align the allocation to  */ enum
> >> +irdma_status_code irdma_allocate_dma_mem(struct irdma_hw *hw,
> >> +					      struct irdma_dma_mem *mem,
> >> +					      u64 size,
> >> +					      u32 alignment)
> >> +{
> >> +	struct pci_dev *pcidev = (struct pci_dev *)hw->dev_context;
> >> +
> >> +	if (!mem)
> >> +		return IRDMA_ERR_PARAM;
> >> +
> >> +	mem->size = ALIGN(size, alignment);
> >> +	mem->va = dma_alloc_coherent(&pcidev->dev, mem->size,
> >> +				     (dma_addr_t *)&mem->pa, GFP_KERNEL);
> >> +	if (!mem->va)
> >> +		return IRDMA_ERR_NO_MEMORY;
> >> +
> >> +	return 0;
> >> +}
> >
> >More wrappers? Why?
> 
> I agree on your previous comment on wrapper for usecnt tracking but this does
> consolidate some common code and avoid duplication.

IRDMA_ERR_PARAM seems like an nonsense thing to do, and why does this
driver have its own custom error codes anyhow? Don't like it, it is
very stange. Once you strip that away there is no code to share.

Jason