/* Allocate a buffer in host RAM for service list, RX, or TX Returns buf->start==NULL if no memory Note that the size will be rounded up 2^n bytes, and if we can't allocate that we'll settle for something smaller until minbytes  */
static void lanai_buf_allocate(struct lanai_buffer *buf, size_t bytes, size_t minbytes, struct pci_dev *pci)
/* Allocate a buffer in host RAM for service list, RX, or TX Returns buf->start==NULL if no memory Note that the size will be rounded up 2^n bytes, and if we can't allocate that we'll settle for something smaller until minbytes  */
static void lanai_buf_allocate(struct lanai_buffer *buf, size_t bytes, size_t minbytes, struct pci_dev *pci)
{
	int size;
	if (bytes > (128 * 1024))
		bytes = 128 * 1024;
	for (size = LANAI_PAGE_SIZE; size < bytes; size *= 2)
		;
	if (minbytes < LANAI_PAGE_SIZE)
		minbytes = LANAI_PAGE_SIZE;
	do {
		buf->start = pci_alloc_consistent(pci, size, &buf->dmaaddr);
		if (buf->start != NULL) {
			APRINTK((buf->dmaaddr & ~0xFFFFFF00) == 0,
			    "bad dmaaddr: 0x%lx\n",
			    (unsigned long) buf->dmaaddr);
			buf->ptr = buf->start;
			buf->end = (u32 *)
			    (&((unsigned char *) buf->start)[size]);
			memset(buf->start, 0, size);
			break;
		}
		size /= 2;
	} while (size >= minbytes);
}