2 * IBM eServer eHCA Infiniband device driver for Linux on POWER
6 * Authors: Waleri Fomin <fomin@de.ibm.com>
7 * Khadija Souissi <souissi@de.ibm.com>
8 * Reinhard Ernst <rernst@de.ibm.com>
9 * Heiko J Schick <schickhj@de.ibm.com>
10 * Hoang-Nam Nguyen <hnguyen@de.ibm.com>
13 * Copyright (c) 2005 IBM Corporation
15 * All rights reserved.
17 * This source code is distributed under a dual license of GPL v2.0 and OpenIB
22 * Redistribution and use in source and binary forms, with or without
23 * modification, are permitted provided that the following conditions are met:
25 * Redistributions of source code must retain the above copyright notice, this
26 * list of conditions and the following disclaimer.
28 * Redistributions in binary form must reproduce the above copyright notice,
29 * this list of conditions and the following disclaimer in the documentation
30 * and/or other materials
31 * provided with the distribution.
33 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
34 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
35 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
36 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
37 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
38 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
39 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
40 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
41 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
42 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
43 * POSSIBILITY OF SUCH DAMAGE.
46 #include "ehca_classes.h"
48 #include "ehca_iverbs.h"
51 #include "ipz_pt_fn.h"
53 int ehca_create_eq(struct ehca_shca
*shca
,
55 const enum ehca_eq_type type
, const u32 length
)
61 struct ib_device
*ib_dev
= &shca
->ib_device
;
63 spin_lock_init(&eq
->spinlock
);
64 spin_lock_init(&eq
->irq_spinlock
);
65 eq
->is_initialized
= 0;
67 if (type
!= EHCA_EQ
&& type
!= EHCA_NEQ
) {
68 ehca_err(ib_dev
, "Invalid EQ type %x. eq=%p", type
, eq
);
72 ehca_err(ib_dev
, "EQ length must not be zero. eq=%p", eq
);
76 ret
= hipz_h_alloc_resource_eq(shca
->ipz_hca_handle
,
84 if (ret
!= H_SUCCESS
) {
85 ehca_err(ib_dev
, "Can't allocate EQ/NEQ. eq=%p", eq
);
89 ret
= ipz_queue_ctor(NULL
, &eq
->ipz_queue
, nr_pages
,
90 EHCA_PAGESIZE
, sizeof(struct ehca_eqe
), 0, 0);
92 ehca_err(ib_dev
, "Can't allocate EQ pages eq=%p", eq
);
96 for (i
= 0; i
< nr_pages
; i
++) {
99 vpage
= ipz_qpageit_get_inc(&eq
->ipz_queue
);
102 goto create_eq_exit2
;
105 rpage
= virt_to_abs(vpage
);
106 ret
= hipz_h_register_rpage_eq(shca
->ipz_hca_handle
,
111 if (i
== (nr_pages
- 1)) {
113 vpage
= ipz_qpageit_get_inc(&eq
->ipz_queue
);
114 if (ret
!= H_SUCCESS
|| vpage
)
115 goto create_eq_exit2
;
117 if (ret
!= H_PAGE_REGISTERED
|| !vpage
)
118 goto create_eq_exit2
;
122 ipz_qeit_reset(&eq
->ipz_queue
);
124 /* register interrupt handlers and initialize work queues */
125 if (type
== EHCA_EQ
) {
126 ret
= ibmebus_request_irq(eq
->ist
, ehca_interrupt_eq
,
127 IRQF_DISABLED
, "ehca_eq",
130 ehca_err(ib_dev
, "Can't map interrupt handler.");
132 tasklet_init(&eq
->interrupt_task
, ehca_tasklet_eq
, (long)shca
);
133 } else if (type
== EHCA_NEQ
) {
134 ret
= ibmebus_request_irq(eq
->ist
, ehca_interrupt_neq
,
135 IRQF_DISABLED
, "ehca_neq",
138 ehca_err(ib_dev
, "Can't map interrupt handler.");
140 tasklet_init(&eq
->interrupt_task
, ehca_tasklet_neq
, (long)shca
);
143 eq
->is_initialized
= 1;
148 ipz_queue_dtor(NULL
, &eq
->ipz_queue
);
151 hipz_h_destroy_eq(shca
->ipz_hca_handle
, eq
);
156 void *ehca_poll_eq(struct ehca_shca
*shca
, struct ehca_eq
*eq
)
161 spin_lock_irqsave(&eq
->spinlock
, flags
);
162 eqe
= ipz_eqit_eq_get_inc_valid(&eq
->ipz_queue
);
163 spin_unlock_irqrestore(&eq
->spinlock
, flags
);
168 int ehca_destroy_eq(struct ehca_shca
*shca
, struct ehca_eq
*eq
)
173 spin_lock_irqsave(&eq
->spinlock
, flags
);
174 ibmebus_free_irq(eq
->ist
, (void *)shca
);
176 h_ret
= hipz_h_destroy_eq(shca
->ipz_hca_handle
, eq
);
178 spin_unlock_irqrestore(&eq
->spinlock
, flags
);
180 if (h_ret
!= H_SUCCESS
) {
181 ehca_err(&shca
->ib_device
, "Can't free EQ resources.");
184 ipz_queue_dtor(NULL
, &eq
->ipz_queue
);