/*
* linux/drivers/net/ehea/ehea_qmr.c
*
* eHEA ethernet device driver for IBM eServer System p
*
* (C) Copyright IBM Corp. 2006
*
* Authors:
* Christoph Raisch <raisch@de.ibm.com>
* Jan-Bernd Themann <themann@de.ibm.com>
* Thomas Klein <tklein@de.ibm.com>
*
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <linux/mm.h>
#include <linux/slab.h>
#include "ehea.h"
#include "ehea_phyp.h"
#include "ehea_qmr.h"
struct ehea_bmap *ehea_bmap = NULL;
static void *hw_qpageit_get_inc(struct hw_queue *queue)
{
void *retvalue = hw_qeit_get(queue);
queue->current_q_offset += queue->pagesize;
if (queue->current_q_offset > queue->queue_length) {
queue->current_q_offset -= queue->pagesize;
retvalue = NULL;
} else if (((u64) retvalue) & (EHEA_PAGESIZE-1)) {
ehea_error("not on pageboundary");
retvalue = NULL;
}
return retvalue;
}
static int hw_queue_ctor(struct hw_queue *queue, const u32 nr_of_pages,
const u32 pagesize, const u32 qe_size)
{
int pages_per_kpage = PAGE_SIZE / pagesize;
int i, k;
if ((pagesize > PAGE_SIZE) || (!pages_per_kpage)) {
ehea_error("pagesize conflict! kernel pagesize=%d, "
"ehea pagesize=%d", (int)PAGE_SIZE, (int)pagesize);
return -EINVAL;
}
queue->queue_length = nr_of_pages * pagesize;
queue->queue_pages = kmalloc(nr_of_pages * sizeof(void *), GFP_KERNEL);
if (!queue->queue_pages) {
ehea_error("no mem for queue_pages");
return -ENOMEM;
}
/*
* allocate pages for queue:
* outer loop allocates whole kernel pages (page aligned) and
* inner loop divides a kernel page into smaller hea queue pages
*/
i = 0;
while (i < nr_of_pages) {
u8 *kpage = (u8 *)get_zeroed_page(GFP_KERNEL);
if (!kpage)
goto out_nomem;
for (k = 0; k < pages_per_kpage && i < nr_of_pages; k++) {
(queue->queue_pages)[i] = (struct ehea_page *)kpage;
kpage += pagesize;
i++;
}
}
queue->current_q_offset = 0;
queue->qe_size = qe_size;
queue->pagesize = pagesize;
queue->toggle_state = 1;
return 0;
out_nomem:
for (i = 0; i < nr_of_pages; i += pages_per_kpage) {
if (!(queue->queue_pages)[i])
break;
free_page((unsigned long)(queue->queue_pages)[i]);
}
return -ENOMEM;
}
static void hw_queue_dtor(struct hw_queue *queue)
{
int pages_per_kpage = PAGE_SIZE / queue->pagesize;
int i, nr_pages;
if (!queue || !queue->queue_pages)
return;
nr_pages = queue->queue_length / queue->pagesize;
for (i = 0; i < nr_pages; i += pages_per_kpage)
free_page((unsigned long)(queue->queue_pages)[i]);
kfree(queue->queue_pages);
}
struct ehea_cq *ehea_create_cq(struct ehea_adapter *adapter,
int nr_of_cqe, u64 eq_handle, u32 cq_token)
{
struct ehea_cq *cq;
struct h_epa epa;
u64 *cq_handle_ref, hret, rpage;
u32 act_nr_of_entries, act_pages, counter;
int ret;
void *vpage;
cq = kzalloc(sizeof(*cq), GFP_KERNEL);
if (!cq) {
ehea_error("no mem for cq");
goto out_nomem;
<