Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 1 | /* |
| 2 | * IBM eServer eHCA Infiniband device driver for Linux on POWER |
| 3 | * |
| 4 | * Event queue handling |
| 5 | * |
| 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> |
| 11 | * |
| 12 | * |
| 13 | * Copyright (c) 2005 IBM Corporation |
| 14 | * |
| 15 | * All rights reserved. |
| 16 | * |
| 17 | * This source code is distributed under a dual license of GPL v2.0 and OpenIB |
| 18 | * BSD. |
| 19 | * |
| 20 | * OpenIB BSD License |
| 21 | * |
| 22 | * Redistribution and use in source and binary forms, with or without |
| 23 | * modification, are permitted provided that the following conditions are met: |
| 24 | * |
| 25 | * Redistributions of source code must retain the above copyright notice, this |
| 26 | * list of conditions and the following disclaimer. |
| 27 | * |
| 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. |
| 32 | * |
| 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. |
| 44 | */ |
| 45 | |
| 46 | #include "ehca_classes.h" |
| 47 | #include "ehca_irq.h" |
| 48 | #include "ehca_iverbs.h" |
| 49 | #include "ehca_qes.h" |
| 50 | #include "hcp_if.h" |
| 51 | #include "ipz_pt_fn.h" |
| 52 | |
| 53 | int ehca_create_eq(struct ehca_shca *shca, |
| 54 | struct ehca_eq *eq, |
| 55 | const enum ehca_eq_type type, const u32 length) |
| 56 | { |
Hoang-Nam Nguyen | 7df109d | 2008-04-29 13:46:52 -0700 | [diff] [blame] | 57 | int ret; |
| 58 | u64 h_ret; |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 59 | u32 nr_pages; |
| 60 | u32 i; |
| 61 | void *vpage; |
| 62 | struct ib_device *ib_dev = &shca->ib_device; |
| 63 | |
| 64 | spin_lock_init(&eq->spinlock); |
Hoang-Nam Nguyen | 78d8d5f | 2007-02-15 17:06:33 +0100 | [diff] [blame] | 65 | spin_lock_init(&eq->irq_spinlock); |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 66 | eq->is_initialized = 0; |
| 67 | |
| 68 | if (type != EHCA_EQ && type != EHCA_NEQ) { |
| 69 | ehca_err(ib_dev, "Invalid EQ type %x. eq=%p", type, eq); |
| 70 | return -EINVAL; |
| 71 | } |
| 72 | if (!length) { |
| 73 | ehca_err(ib_dev, "EQ length must not be zero. eq=%p", eq); |
| 74 | return -EINVAL; |
| 75 | } |
| 76 | |
Hoang-Nam Nguyen | 7df109d | 2008-04-29 13:46:52 -0700 | [diff] [blame] | 77 | h_ret = hipz_h_alloc_resource_eq(shca->ipz_hca_handle, |
| 78 | &eq->pf, |
| 79 | type, |
| 80 | length, |
| 81 | &eq->ipz_eq_handle, |
| 82 | &eq->length, |
| 83 | &nr_pages, &eq->ist); |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 84 | |
Hoang-Nam Nguyen | 7df109d | 2008-04-29 13:46:52 -0700 | [diff] [blame] | 85 | if (h_ret != H_SUCCESS) { |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 86 | ehca_err(ib_dev, "Can't allocate EQ/NEQ. eq=%p", eq); |
| 87 | return -EINVAL; |
| 88 | } |
| 89 | |
Stefan Roscher | e2f81da | 2007-07-20 16:04:17 +0200 | [diff] [blame] | 90 | ret = ipz_queue_ctor(NULL, &eq->ipz_queue, nr_pages, |
| 91 | EHCA_PAGESIZE, sizeof(struct ehca_eqe), 0, 0); |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 92 | if (!ret) { |
| 93 | ehca_err(ib_dev, "Can't allocate EQ pages eq=%p", eq); |
| 94 | goto create_eq_exit1; |
| 95 | } |
| 96 | |
| 97 | for (i = 0; i < nr_pages; i++) { |
| 98 | u64 rpage; |
| 99 | |
Hoang-Nam Nguyen | 2b94397 | 2007-07-12 17:53:47 +0200 | [diff] [blame] | 100 | vpage = ipz_qpageit_get_inc(&eq->ipz_queue); |
Hoang-Nam Nguyen | 7df109d | 2008-04-29 13:46:52 -0700 | [diff] [blame] | 101 | if (!vpage) |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 102 | goto create_eq_exit2; |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 103 | |
| 104 | rpage = virt_to_abs(vpage); |
Hoang-Nam Nguyen | 7df109d | 2008-04-29 13:46:52 -0700 | [diff] [blame] | 105 | h_ret = hipz_h_register_rpage_eq(shca->ipz_hca_handle, |
| 106 | eq->ipz_eq_handle, |
| 107 | &eq->pf, |
| 108 | 0, 0, rpage, 1); |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 109 | |
| 110 | if (i == (nr_pages - 1)) { |
| 111 | /* last page */ |
| 112 | vpage = ipz_qpageit_get_inc(&eq->ipz_queue); |
Hoang-Nam Nguyen | 7df109d | 2008-04-29 13:46:52 -0700 | [diff] [blame] | 113 | if (h_ret != H_SUCCESS || vpage) |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 114 | goto create_eq_exit2; |
| 115 | } else { |
Julia Lawall | 139cdab | 2008-12-21 13:29:13 -0800 | [diff] [blame] | 116 | if (h_ret != H_PAGE_REGISTERED) |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 117 | goto create_eq_exit2; |
| 118 | } |
| 119 | } |
| 120 | |
| 121 | ipz_qeit_reset(&eq->ipz_queue); |
| 122 | |
| 123 | /* register interrupt handlers and initialize work queues */ |
| 124 | if (type == EHCA_EQ) { |
Alexander Schmidt | bd5d0cc | 2010-07-05 11:41:56 +0000 | [diff] [blame] | 125 | tasklet_init(&eq->interrupt_task, ehca_tasklet_eq, (long)shca); |
| 126 | |
Joachim Fenkes | 6b08f3a | 2007-09-26 19:45:51 +1000 | [diff] [blame] | 127 | ret = ibmebus_request_irq(eq->ist, ehca_interrupt_eq, |
Thomas Gleixner | 38515e9 | 2007-02-14 00:33:16 -0800 | [diff] [blame] | 128 | IRQF_DISABLED, "ehca_eq", |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 129 | (void *)shca); |
| 130 | if (ret < 0) |
| 131 | ehca_err(ib_dev, "Can't map interrupt handler."); |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 132 | } else if (type == EHCA_NEQ) { |
Alexander Schmidt | bd5d0cc | 2010-07-05 11:41:56 +0000 | [diff] [blame] | 133 | tasklet_init(&eq->interrupt_task, ehca_tasklet_neq, (long)shca); |
| 134 | |
Joachim Fenkes | 6b08f3a | 2007-09-26 19:45:51 +1000 | [diff] [blame] | 135 | ret = ibmebus_request_irq(eq->ist, ehca_interrupt_neq, |
Thomas Gleixner | 38515e9 | 2007-02-14 00:33:16 -0800 | [diff] [blame] | 136 | IRQF_DISABLED, "ehca_neq", |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 137 | (void *)shca); |
| 138 | if (ret < 0) |
| 139 | ehca_err(ib_dev, "Can't map interrupt handler."); |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 140 | } |
| 141 | |
| 142 | eq->is_initialized = 1; |
| 143 | |
| 144 | return 0; |
| 145 | |
| 146 | create_eq_exit2: |
Stefan Roscher | e2f81da | 2007-07-20 16:04:17 +0200 | [diff] [blame] | 147 | ipz_queue_dtor(NULL, &eq->ipz_queue); |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 148 | |
| 149 | create_eq_exit1: |
| 150 | hipz_h_destroy_eq(shca->ipz_hca_handle, eq); |
| 151 | |
| 152 | return -EINVAL; |
| 153 | } |
| 154 | |
| 155 | void *ehca_poll_eq(struct ehca_shca *shca, struct ehca_eq *eq) |
| 156 | { |
| 157 | unsigned long flags; |
| 158 | void *eqe; |
| 159 | |
| 160 | spin_lock_irqsave(&eq->spinlock, flags); |
| 161 | eqe = ipz_eqit_eq_get_inc_valid(&eq->ipz_queue); |
| 162 | spin_unlock_irqrestore(&eq->spinlock, flags); |
| 163 | |
| 164 | return eqe; |
| 165 | } |
| 166 | |
| 167 | int ehca_destroy_eq(struct ehca_shca *shca, struct ehca_eq *eq) |
| 168 | { |
| 169 | unsigned long flags; |
| 170 | u64 h_ret; |
| 171 | |
Joachim Fenkes | 6b08f3a | 2007-09-26 19:45:51 +1000 | [diff] [blame] | 172 | ibmebus_free_irq(eq->ist, (void *)shca); |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 173 | |
Alexander Schmidt | 9420269 | 2009-12-09 10:11:04 -0800 | [diff] [blame] | 174 | spin_lock_irqsave(&shca_list_lock, flags); |
| 175 | eq->is_initialized = 0; |
| 176 | spin_unlock_irqrestore(&shca_list_lock, flags); |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 177 | |
Alexander Schmidt | 9420269 | 2009-12-09 10:11:04 -0800 | [diff] [blame] | 178 | tasklet_kill(&eq->interrupt_task); |
| 179 | |
| 180 | h_ret = hipz_h_destroy_eq(shca->ipz_hca_handle, eq); |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 181 | |
| 182 | if (h_ret != H_SUCCESS) { |
| 183 | ehca_err(&shca->ib_device, "Can't free EQ resources."); |
| 184 | return -EINVAL; |
| 185 | } |
Stefan Roscher | e2f81da | 2007-07-20 16:04:17 +0200 | [diff] [blame] | 186 | ipz_queue_dtor(NULL, &eq->ipz_queue); |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 187 | |
| 188 | return 0; |
| 189 | } |