Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 1 | /* |
Paul Gortmaker | 3396c78 | 2012-01-27 13:36:01 +0000 | [diff] [blame] | 2 | * linux/drivers/net/ethernet/ibm/ehea/ehea_qmr.c |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 3 | * |
| 4 | * eHEA ethernet device driver for IBM eServer System p |
| 5 | * |
| 6 | * (C) Copyright IBM Corp. 2006 |
| 7 | * |
| 8 | * Authors: |
| 9 | * Christoph Raisch <raisch@de.ibm.com> |
| 10 | * Jan-Bernd Themann <themann@de.ibm.com> |
| 11 | * Thomas Klein <tklein@de.ibm.com> |
| 12 | * |
| 13 | * |
| 14 | * This program is free software; you can redistribute it and/or modify |
| 15 | * it under the terms of the GNU General Public License as published by |
| 16 | * the Free Software Foundation; either version 2, or (at your option) |
| 17 | * any later version. |
| 18 | * |
| 19 | * This program is distributed in the hope that it will be useful, |
| 20 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 21 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 22 | * GNU General Public License for more details. |
| 23 | * |
| 24 | * You should have received a copy of the GNU General Public License |
| 25 | * along with this program; if not, write to the Free Software |
| 26 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 27 | */ |
| 28 | |
Joe Perches | 8c4877a | 2010-12-13 10:05:14 -0800 | [diff] [blame] | 29 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 30 | |
Al Viro | d7fe0f2 | 2006-12-03 23:15:30 -0500 | [diff] [blame] | 31 | #include <linux/mm.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 32 | #include <linux/slab.h> |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 33 | #include "ehea.h" |
| 34 | #include "ehea_phyp.h" |
| 35 | #include "ehea_qmr.h" |
| 36 | |
Thadeu Lima de Souza Cascardo | 1886e5d | 2012-01-13 08:06:32 +0000 | [diff] [blame] | 37 | static struct ehea_bmap *ehea_bmap; |
Thomas Klein | 44c8215 | 2007-07-11 16:32:00 +0200 | [diff] [blame] | 38 | |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 39 | static void *hw_qpageit_get_inc(struct hw_queue *queue) |
| 40 | { |
| 41 | void *retvalue = hw_qeit_get(queue); |
| 42 | |
| 43 | queue->current_q_offset += queue->pagesize; |
| 44 | if (queue->current_q_offset > queue->queue_length) { |
| 45 | queue->current_q_offset -= queue->pagesize; |
| 46 | retvalue = NULL; |
| 47 | } else if (((u64) retvalue) & (EHEA_PAGESIZE-1)) { |
Joe Perches | 8c4877a | 2010-12-13 10:05:14 -0800 | [diff] [blame] | 48 | pr_err("not on pageboundary\n"); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 49 | retvalue = NULL; |
| 50 | } |
| 51 | return retvalue; |
| 52 | } |
| 53 | |
| 54 | static int hw_queue_ctor(struct hw_queue *queue, const u32 nr_of_pages, |
| 55 | const u32 pagesize, const u32 qe_size) |
| 56 | { |
| 57 | int pages_per_kpage = PAGE_SIZE / pagesize; |
| 58 | int i, k; |
| 59 | |
| 60 | if ((pagesize > PAGE_SIZE) || (!pages_per_kpage)) { |
Joe Perches | 8c4877a | 2010-12-13 10:05:14 -0800 | [diff] [blame] | 61 | pr_err("pagesize conflict! kernel pagesize=%d, ehea pagesize=%d\n", |
| 62 | (int)PAGE_SIZE, (int)pagesize); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 63 | return -EINVAL; |
| 64 | } |
| 65 | |
| 66 | queue->queue_length = nr_of_pages * pagesize; |
Doug Maxey | f67c627 | 2008-01-31 20:20:51 -0600 | [diff] [blame] | 67 | queue->queue_pages = kmalloc(nr_of_pages * sizeof(void *), GFP_KERNEL); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 68 | if (!queue->queue_pages) { |
Joe Perches | 8c4877a | 2010-12-13 10:05:14 -0800 | [diff] [blame] | 69 | pr_err("no mem for queue_pages\n"); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 70 | return -ENOMEM; |
| 71 | } |
| 72 | |
| 73 | /* |
| 74 | * allocate pages for queue: |
| 75 | * outer loop allocates whole kernel pages (page aligned) and |
| 76 | * inner loop divides a kernel page into smaller hea queue pages |
| 77 | */ |
| 78 | i = 0; |
| 79 | while (i < nr_of_pages) { |
Doug Maxey | f67c627 | 2008-01-31 20:20:51 -0600 | [diff] [blame] | 80 | u8 *kpage = (u8 *)get_zeroed_page(GFP_KERNEL); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 81 | if (!kpage) |
| 82 | goto out_nomem; |
| 83 | for (k = 0; k < pages_per_kpage && i < nr_of_pages; k++) { |
Doug Maxey | f67c627 | 2008-01-31 20:20:51 -0600 | [diff] [blame] | 84 | (queue->queue_pages)[i] = (struct ehea_page *)kpage; |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 85 | kpage += pagesize; |
| 86 | i++; |
| 87 | } |
| 88 | } |
| 89 | |
| 90 | queue->current_q_offset = 0; |
| 91 | queue->qe_size = qe_size; |
| 92 | queue->pagesize = pagesize; |
| 93 | queue->toggle_state = 1; |
| 94 | |
| 95 | return 0; |
| 96 | out_nomem: |
| 97 | for (i = 0; i < nr_of_pages; i += pages_per_kpage) { |
| 98 | if (!(queue->queue_pages)[i]) |
| 99 | break; |
| 100 | free_page((unsigned long)(queue->queue_pages)[i]); |
| 101 | } |
| 102 | return -ENOMEM; |
| 103 | } |
| 104 | |
| 105 | static void hw_queue_dtor(struct hw_queue *queue) |
| 106 | { |
| 107 | int pages_per_kpage = PAGE_SIZE / queue->pagesize; |
| 108 | int i, nr_pages; |
| 109 | |
| 110 | if (!queue || !queue->queue_pages) |
| 111 | return; |
| 112 | |
| 113 | nr_pages = queue->queue_length / queue->pagesize; |
| 114 | |
| 115 | for (i = 0; i < nr_pages; i += pages_per_kpage) |
| 116 | free_page((unsigned long)(queue->queue_pages)[i]); |
| 117 | |
| 118 | kfree(queue->queue_pages); |
| 119 | } |
| 120 | |
| 121 | struct ehea_cq *ehea_create_cq(struct ehea_adapter *adapter, |
| 122 | int nr_of_cqe, u64 eq_handle, u32 cq_token) |
| 123 | { |
| 124 | struct ehea_cq *cq; |
| 125 | struct h_epa epa; |
| 126 | u64 *cq_handle_ref, hret, rpage; |
| 127 | u32 act_nr_of_entries, act_pages, counter; |
| 128 | int ret; |
| 129 | void *vpage; |
| 130 | |
| 131 | cq = kzalloc(sizeof(*cq), GFP_KERNEL); |
| 132 | if (!cq) { |
Joe Perches | 8c4877a | 2010-12-13 10:05:14 -0800 | [diff] [blame] | 133 | pr_err("no mem for cq\n"); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 134 | goto out_nomem; |
| 135 | } |
| 136 | |
| 137 | cq->attr.max_nr_of_cqes = nr_of_cqe; |
| 138 | cq->attr.cq_token = cq_token; |
| 139 | cq->attr.eq_handle = eq_handle; |
| 140 | |
| 141 | cq->adapter = adapter; |
| 142 | |
| 143 | cq_handle_ref = &cq->fw_handle; |
| 144 | act_nr_of_entries = 0; |
| 145 | act_pages = 0; |
| 146 | |
| 147 | hret = ehea_h_alloc_resource_cq(adapter->handle, &cq->attr, |
| 148 | &cq->fw_handle, &cq->epas); |
| 149 | if (hret != H_SUCCESS) { |
Joe Perches | 8c4877a | 2010-12-13 10:05:14 -0800 | [diff] [blame] | 150 | pr_err("alloc_resource_cq failed\n"); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 151 | goto out_freemem; |
| 152 | } |
| 153 | |
| 154 | ret = hw_queue_ctor(&cq->hw_queue, cq->attr.nr_pages, |
| 155 | EHEA_PAGESIZE, sizeof(struct ehea_cqe)); |
| 156 | if (ret) |
| 157 | goto out_freeres; |
| 158 | |
| 159 | for (counter = 0; counter < cq->attr.nr_pages; counter++) { |
| 160 | vpage = hw_qpageit_get_inc(&cq->hw_queue); |
| 161 | if (!vpage) { |
Joe Perches | 8c4877a | 2010-12-13 10:05:14 -0800 | [diff] [blame] | 162 | pr_err("hw_qpageit_get_inc failed\n"); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 163 | goto out_kill_hwq; |
| 164 | } |
| 165 | |
Michael Ellerman | 67e1dbc | 2012-07-25 21:19:55 +0000 | [diff] [blame] | 166 | rpage = __pa(vpage); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 167 | hret = ehea_h_register_rpage(adapter->handle, |
| 168 | 0, EHEA_CQ_REGISTER_ORIG, |
| 169 | cq->fw_handle, rpage, 1); |
| 170 | if (hret < H_SUCCESS) { |
Joe Perches | 8c4877a | 2010-12-13 10:05:14 -0800 | [diff] [blame] | 171 | pr_err("register_rpage_cq failed ehea_cq=%p hret=%llx counter=%i act_pages=%i\n", |
| 172 | cq, hret, counter, cq->attr.nr_pages); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 173 | goto out_kill_hwq; |
| 174 | } |
| 175 | |
| 176 | if (counter == (cq->attr.nr_pages - 1)) { |
| 177 | vpage = hw_qpageit_get_inc(&cq->hw_queue); |
| 178 | |
| 179 | if ((hret != H_SUCCESS) || (vpage)) { |
Joe Perches | 8c4877a | 2010-12-13 10:05:14 -0800 | [diff] [blame] | 180 | pr_err("registration of pages not complete hret=%llx\n", |
| 181 | hret); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 182 | goto out_kill_hwq; |
| 183 | } |
| 184 | } else { |
Julia Lawall | 662f44a | 2008-12-25 18:03:09 -0800 | [diff] [blame] | 185 | if (hret != H_PAGE_REGISTERED) { |
Joe Perches | 8c4877a | 2010-12-13 10:05:14 -0800 | [diff] [blame] | 186 | pr_err("CQ: registration of page failed hret=%llx\n", |
| 187 | hret); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 188 | goto out_kill_hwq; |
| 189 | } |
| 190 | } |
| 191 | } |
| 192 | |
| 193 | hw_qeit_reset(&cq->hw_queue); |
| 194 | epa = cq->epas.kernel; |
| 195 | ehea_reset_cq_ep(cq); |
| 196 | ehea_reset_cq_n1(cq); |
| 197 | |
| 198 | return cq; |
| 199 | |
| 200 | out_kill_hwq: |
| 201 | hw_queue_dtor(&cq->hw_queue); |
| 202 | |
| 203 | out_freeres: |
Jan-Bernd Themann | e542aa6 | 2007-03-22 17:50:24 +0100 | [diff] [blame] | 204 | ehea_h_free_resource(adapter->handle, cq->fw_handle, FORCE_FREE); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 205 | |
| 206 | out_freemem: |
| 207 | kfree(cq); |
| 208 | |
| 209 | out_nomem: |
| 210 | return NULL; |
| 211 | } |
| 212 | |
Thadeu Lima de Souza Cascardo | 1886e5d | 2012-01-13 08:06:32 +0000 | [diff] [blame] | 213 | static u64 ehea_destroy_cq_res(struct ehea_cq *cq, u64 force) |
Jan-Bernd Themann | e542aa6 | 2007-03-22 17:50:24 +0100 | [diff] [blame] | 214 | { |
| 215 | u64 hret; |
| 216 | u64 adapter_handle = cq->adapter->handle; |
| 217 | |
Jan-Bernd Themann | d1d25aa | 2007-07-02 13:00:46 +0200 | [diff] [blame] | 218 | /* deregister all previous registered pages */ |
Jan-Bernd Themann | e542aa6 | 2007-03-22 17:50:24 +0100 | [diff] [blame] | 219 | hret = ehea_h_free_resource(adapter_handle, cq->fw_handle, force); |
| 220 | if (hret != H_SUCCESS) |
| 221 | return hret; |
| 222 | |
| 223 | hw_queue_dtor(&cq->hw_queue); |
| 224 | kfree(cq); |
| 225 | |
| 226 | return hret; |
| 227 | } |
| 228 | |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 229 | int ehea_destroy_cq(struct ehea_cq *cq) |
| 230 | { |
Thomas Klein | ea96cea | 2010-04-20 23:10:55 +0000 | [diff] [blame] | 231 | u64 hret, aer, aerr; |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 232 | if (!cq) |
| 233 | return 0; |
| 234 | |
Jan-Bernd Themann | 28721c8 | 2007-08-22 16:21:28 +0200 | [diff] [blame] | 235 | hcp_epas_dtor(&cq->epas); |
Doug Maxey | f67c627 | 2008-01-31 20:20:51 -0600 | [diff] [blame] | 236 | hret = ehea_destroy_cq_res(cq, NORMAL_FREE); |
| 237 | if (hret == H_R_STATE) { |
Thomas Klein | ea96cea | 2010-04-20 23:10:55 +0000 | [diff] [blame] | 238 | ehea_error_data(cq->adapter, cq->fw_handle, &aer, &aerr); |
Jan-Bernd Themann | e542aa6 | 2007-03-22 17:50:24 +0100 | [diff] [blame] | 239 | hret = ehea_destroy_cq_res(cq, FORCE_FREE); |
| 240 | } |
Thomas Klein | 1b5135d | 2006-11-03 17:47:20 +0100 | [diff] [blame] | 241 | |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 242 | if (hret != H_SUCCESS) { |
Joe Perches | 8c4877a | 2010-12-13 10:05:14 -0800 | [diff] [blame] | 243 | pr_err("destroy CQ failed\n"); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 244 | return -EIO; |
| 245 | } |
| 246 | |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 247 | return 0; |
| 248 | } |
| 249 | |
| 250 | struct ehea_eq *ehea_create_eq(struct ehea_adapter *adapter, |
| 251 | const enum ehea_eq_type type, |
| 252 | const u32 max_nr_of_eqes, const u8 eqe_gen) |
| 253 | { |
| 254 | int ret, i; |
| 255 | u64 hret, rpage; |
| 256 | void *vpage; |
| 257 | struct ehea_eq *eq; |
| 258 | |
| 259 | eq = kzalloc(sizeof(*eq), GFP_KERNEL); |
| 260 | if (!eq) { |
Joe Perches | 8c4877a | 2010-12-13 10:05:14 -0800 | [diff] [blame] | 261 | pr_err("no mem for eq\n"); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 262 | return NULL; |
| 263 | } |
| 264 | |
| 265 | eq->adapter = adapter; |
| 266 | eq->attr.type = type; |
| 267 | eq->attr.max_nr_of_eqes = max_nr_of_eqes; |
| 268 | eq->attr.eqe_gen = eqe_gen; |
| 269 | spin_lock_init(&eq->spinlock); |
| 270 | |
| 271 | hret = ehea_h_alloc_resource_eq(adapter->handle, |
| 272 | &eq->attr, &eq->fw_handle); |
| 273 | if (hret != H_SUCCESS) { |
Joe Perches | 8c4877a | 2010-12-13 10:05:14 -0800 | [diff] [blame] | 274 | pr_err("alloc_resource_eq failed\n"); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 275 | goto out_freemem; |
| 276 | } |
| 277 | |
| 278 | ret = hw_queue_ctor(&eq->hw_queue, eq->attr.nr_pages, |
| 279 | EHEA_PAGESIZE, sizeof(struct ehea_eqe)); |
| 280 | if (ret) { |
Joe Perches | 8c4877a | 2010-12-13 10:05:14 -0800 | [diff] [blame] | 281 | pr_err("can't allocate eq pages\n"); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 282 | goto out_freeres; |
| 283 | } |
| 284 | |
| 285 | for (i = 0; i < eq->attr.nr_pages; i++) { |
| 286 | vpage = hw_qpageit_get_inc(&eq->hw_queue); |
| 287 | if (!vpage) { |
Joe Perches | 8c4877a | 2010-12-13 10:05:14 -0800 | [diff] [blame] | 288 | pr_err("hw_qpageit_get_inc failed\n"); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 289 | hret = H_RESOURCE; |
| 290 | goto out_kill_hwq; |
| 291 | } |
| 292 | |
Michael Ellerman | 67e1dbc | 2012-07-25 21:19:55 +0000 | [diff] [blame] | 293 | rpage = __pa(vpage); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 294 | |
| 295 | hret = ehea_h_register_rpage(adapter->handle, 0, |
| 296 | EHEA_EQ_REGISTER_ORIG, |
| 297 | eq->fw_handle, rpage, 1); |
| 298 | |
| 299 | if (i == (eq->attr.nr_pages - 1)) { |
| 300 | /* last page */ |
| 301 | vpage = hw_qpageit_get_inc(&eq->hw_queue); |
Doug Maxey | f67c627 | 2008-01-31 20:20:51 -0600 | [diff] [blame] | 302 | if ((hret != H_SUCCESS) || (vpage)) |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 303 | goto out_kill_hwq; |
Doug Maxey | f67c627 | 2008-01-31 20:20:51 -0600 | [diff] [blame] | 304 | |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 305 | } else { |
Julia Lawall | 662f44a | 2008-12-25 18:03:09 -0800 | [diff] [blame] | 306 | if (hret != H_PAGE_REGISTERED) |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 307 | goto out_kill_hwq; |
Doug Maxey | f67c627 | 2008-01-31 20:20:51 -0600 | [diff] [blame] | 308 | |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 309 | } |
| 310 | } |
| 311 | |
| 312 | hw_qeit_reset(&eq->hw_queue); |
| 313 | return eq; |
| 314 | |
| 315 | out_kill_hwq: |
| 316 | hw_queue_dtor(&eq->hw_queue); |
| 317 | |
| 318 | out_freeres: |
Jan-Bernd Themann | e542aa6 | 2007-03-22 17:50:24 +0100 | [diff] [blame] | 319 | ehea_h_free_resource(adapter->handle, eq->fw_handle, FORCE_FREE); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 320 | |
| 321 | out_freemem: |
| 322 | kfree(eq); |
| 323 | return NULL; |
| 324 | } |
| 325 | |
| 326 | struct ehea_eqe *ehea_poll_eq(struct ehea_eq *eq) |
| 327 | { |
| 328 | struct ehea_eqe *eqe; |
| 329 | unsigned long flags; |
| 330 | |
| 331 | spin_lock_irqsave(&eq->spinlock, flags); |
Joe Perches | 43d620c | 2011-06-16 19:08:06 +0000 | [diff] [blame] | 332 | eqe = hw_eqit_eq_get_inc_valid(&eq->hw_queue); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 333 | spin_unlock_irqrestore(&eq->spinlock, flags); |
| 334 | |
| 335 | return eqe; |
| 336 | } |
| 337 | |
Thadeu Lima de Souza Cascardo | 1886e5d | 2012-01-13 08:06:32 +0000 | [diff] [blame] | 338 | static u64 ehea_destroy_eq_res(struct ehea_eq *eq, u64 force) |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 339 | { |
| 340 | u64 hret; |
| 341 | unsigned long flags; |
| 342 | |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 343 | spin_lock_irqsave(&eq->spinlock, flags); |
| 344 | |
Jan-Bernd Themann | e542aa6 | 2007-03-22 17:50:24 +0100 | [diff] [blame] | 345 | hret = ehea_h_free_resource(eq->adapter->handle, eq->fw_handle, force); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 346 | spin_unlock_irqrestore(&eq->spinlock, flags); |
| 347 | |
Jan-Bernd Themann | e542aa6 | 2007-03-22 17:50:24 +0100 | [diff] [blame] | 348 | if (hret != H_SUCCESS) |
| 349 | return hret; |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 350 | |
| 351 | hw_queue_dtor(&eq->hw_queue); |
| 352 | kfree(eq); |
| 353 | |
Jan-Bernd Themann | e542aa6 | 2007-03-22 17:50:24 +0100 | [diff] [blame] | 354 | return hret; |
| 355 | } |
| 356 | |
| 357 | int ehea_destroy_eq(struct ehea_eq *eq) |
| 358 | { |
Thomas Klein | ea96cea | 2010-04-20 23:10:55 +0000 | [diff] [blame] | 359 | u64 hret, aer, aerr; |
Jan-Bernd Themann | e542aa6 | 2007-03-22 17:50:24 +0100 | [diff] [blame] | 360 | if (!eq) |
| 361 | return 0; |
| 362 | |
Jan-Bernd Themann | 28721c8 | 2007-08-22 16:21:28 +0200 | [diff] [blame] | 363 | hcp_epas_dtor(&eq->epas); |
| 364 | |
Doug Maxey | f67c627 | 2008-01-31 20:20:51 -0600 | [diff] [blame] | 365 | hret = ehea_destroy_eq_res(eq, NORMAL_FREE); |
| 366 | if (hret == H_R_STATE) { |
Thomas Klein | ea96cea | 2010-04-20 23:10:55 +0000 | [diff] [blame] | 367 | ehea_error_data(eq->adapter, eq->fw_handle, &aer, &aerr); |
Jan-Bernd Themann | e542aa6 | 2007-03-22 17:50:24 +0100 | [diff] [blame] | 368 | hret = ehea_destroy_eq_res(eq, FORCE_FREE); |
| 369 | } |
| 370 | |
| 371 | if (hret != H_SUCCESS) { |
Joe Perches | 8c4877a | 2010-12-13 10:05:14 -0800 | [diff] [blame] | 372 | pr_err("destroy EQ failed\n"); |
Jan-Bernd Themann | e542aa6 | 2007-03-22 17:50:24 +0100 | [diff] [blame] | 373 | return -EIO; |
Jan-Bernd Themann | d1d25aa | 2007-07-02 13:00:46 +0200 | [diff] [blame] | 374 | } |
Jan-Bernd Themann | e542aa6 | 2007-03-22 17:50:24 +0100 | [diff] [blame] | 375 | |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 376 | return 0; |
| 377 | } |
| 378 | |
Ben Hutchings | 1aa8b47 | 2012-07-10 10:56:59 +0000 | [diff] [blame] | 379 | /* allocates memory for a queue and registers pages in phyp */ |
Thadeu Lima de Souza Cascardo | 1886e5d | 2012-01-13 08:06:32 +0000 | [diff] [blame] | 380 | static int ehea_qp_alloc_register(struct ehea_qp *qp, struct hw_queue *hw_queue, |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 381 | int nr_pages, int wqe_size, int act_nr_sges, |
| 382 | struct ehea_adapter *adapter, int h_call_q_selector) |
| 383 | { |
| 384 | u64 hret, rpage; |
| 385 | int ret, cnt; |
| 386 | void *vpage; |
| 387 | |
| 388 | ret = hw_queue_ctor(hw_queue, nr_pages, EHEA_PAGESIZE, wqe_size); |
| 389 | if (ret) |
| 390 | return ret; |
| 391 | |
| 392 | for (cnt = 0; cnt < nr_pages; cnt++) { |
| 393 | vpage = hw_qpageit_get_inc(hw_queue); |
| 394 | if (!vpage) { |
Joe Perches | 8c4877a | 2010-12-13 10:05:14 -0800 | [diff] [blame] | 395 | pr_err("hw_qpageit_get_inc failed\n"); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 396 | goto out_kill_hwq; |
| 397 | } |
Michael Ellerman | 67e1dbc | 2012-07-25 21:19:55 +0000 | [diff] [blame] | 398 | rpage = __pa(vpage); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 399 | hret = ehea_h_register_rpage(adapter->handle, |
| 400 | 0, h_call_q_selector, |
| 401 | qp->fw_handle, rpage, 1); |
| 402 | if (hret < H_SUCCESS) { |
Joe Perches | 8c4877a | 2010-12-13 10:05:14 -0800 | [diff] [blame] | 403 | pr_err("register_rpage_qp failed\n"); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 404 | goto out_kill_hwq; |
| 405 | } |
| 406 | } |
| 407 | hw_qeit_reset(hw_queue); |
| 408 | return 0; |
| 409 | |
| 410 | out_kill_hwq: |
| 411 | hw_queue_dtor(hw_queue); |
| 412 | return -EIO; |
| 413 | } |
| 414 | |
| 415 | static inline u32 map_wqe_size(u8 wqe_enc_size) |
| 416 | { |
| 417 | return 128 << wqe_enc_size; |
| 418 | } |
| 419 | |
| 420 | struct ehea_qp *ehea_create_qp(struct ehea_adapter *adapter, |
| 421 | u32 pd, struct ehea_qp_init_attr *init_attr) |
| 422 | { |
| 423 | int ret; |
| 424 | u64 hret; |
| 425 | struct ehea_qp *qp; |
| 426 | u32 wqe_size_in_bytes_sq, wqe_size_in_bytes_rq1; |
| 427 | u32 wqe_size_in_bytes_rq2, wqe_size_in_bytes_rq3; |
| 428 | |
| 429 | |
| 430 | qp = kzalloc(sizeof(*qp), GFP_KERNEL); |
| 431 | if (!qp) { |
Joe Perches | 8c4877a | 2010-12-13 10:05:14 -0800 | [diff] [blame] | 432 | pr_err("no mem for qp\n"); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 433 | return NULL; |
| 434 | } |
| 435 | |
| 436 | qp->adapter = adapter; |
| 437 | |
| 438 | hret = ehea_h_alloc_resource_qp(adapter->handle, init_attr, pd, |
| 439 | &qp->fw_handle, &qp->epas); |
| 440 | if (hret != H_SUCCESS) { |
Joe Perches | 8c4877a | 2010-12-13 10:05:14 -0800 | [diff] [blame] | 441 | pr_err("ehea_h_alloc_resource_qp failed\n"); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 442 | goto out_freemem; |
| 443 | } |
| 444 | |
| 445 | wqe_size_in_bytes_sq = map_wqe_size(init_attr->act_wqe_size_enc_sq); |
| 446 | wqe_size_in_bytes_rq1 = map_wqe_size(init_attr->act_wqe_size_enc_rq1); |
| 447 | wqe_size_in_bytes_rq2 = map_wqe_size(init_attr->act_wqe_size_enc_rq2); |
| 448 | wqe_size_in_bytes_rq3 = map_wqe_size(init_attr->act_wqe_size_enc_rq3); |
| 449 | |
| 450 | ret = ehea_qp_alloc_register(qp, &qp->hw_squeue, init_attr->nr_sq_pages, |
| 451 | wqe_size_in_bytes_sq, |
| 452 | init_attr->act_wqe_size_enc_sq, adapter, |
| 453 | 0); |
| 454 | if (ret) { |
Joe Perches | 8c4877a | 2010-12-13 10:05:14 -0800 | [diff] [blame] | 455 | pr_err("can't register for sq ret=%x\n", ret); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 456 | goto out_freeres; |
| 457 | } |
| 458 | |
| 459 | ret = ehea_qp_alloc_register(qp, &qp->hw_rqueue1, |
| 460 | init_attr->nr_rq1_pages, |
| 461 | wqe_size_in_bytes_rq1, |
| 462 | init_attr->act_wqe_size_enc_rq1, |
| 463 | adapter, 1); |
| 464 | if (ret) { |
Joe Perches | 8c4877a | 2010-12-13 10:05:14 -0800 | [diff] [blame] | 465 | pr_err("can't register for rq1 ret=%x\n", ret); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 466 | goto out_kill_hwsq; |
| 467 | } |
| 468 | |
| 469 | if (init_attr->rq_count > 1) { |
| 470 | ret = ehea_qp_alloc_register(qp, &qp->hw_rqueue2, |
| 471 | init_attr->nr_rq2_pages, |
| 472 | wqe_size_in_bytes_rq2, |
| 473 | init_attr->act_wqe_size_enc_rq2, |
| 474 | adapter, 2); |
| 475 | if (ret) { |
Joe Perches | 8c4877a | 2010-12-13 10:05:14 -0800 | [diff] [blame] | 476 | pr_err("can't register for rq2 ret=%x\n", ret); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 477 | goto out_kill_hwr1q; |
| 478 | } |
| 479 | } |
| 480 | |
| 481 | if (init_attr->rq_count > 2) { |
| 482 | ret = ehea_qp_alloc_register(qp, &qp->hw_rqueue3, |
| 483 | init_attr->nr_rq3_pages, |
| 484 | wqe_size_in_bytes_rq3, |
| 485 | init_attr->act_wqe_size_enc_rq3, |
| 486 | adapter, 3); |
| 487 | if (ret) { |
Joe Perches | 8c4877a | 2010-12-13 10:05:14 -0800 | [diff] [blame] | 488 | pr_err("can't register for rq3 ret=%x\n", ret); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 489 | goto out_kill_hwr2q; |
| 490 | } |
| 491 | } |
| 492 | |
| 493 | qp->init_attr = *init_attr; |
| 494 | |
| 495 | return qp; |
| 496 | |
| 497 | out_kill_hwr2q: |
| 498 | hw_queue_dtor(&qp->hw_rqueue2); |
| 499 | |
| 500 | out_kill_hwr1q: |
| 501 | hw_queue_dtor(&qp->hw_rqueue1); |
| 502 | |
| 503 | out_kill_hwsq: |
| 504 | hw_queue_dtor(&qp->hw_squeue); |
| 505 | |
| 506 | out_freeres: |
| 507 | ehea_h_disable_and_get_hea(adapter->handle, qp->fw_handle); |
Jan-Bernd Themann | e542aa6 | 2007-03-22 17:50:24 +0100 | [diff] [blame] | 508 | ehea_h_free_resource(adapter->handle, qp->fw_handle, FORCE_FREE); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 509 | |
| 510 | out_freemem: |
| 511 | kfree(qp); |
| 512 | return NULL; |
| 513 | } |
| 514 | |
Thadeu Lima de Souza Cascardo | 1886e5d | 2012-01-13 08:06:32 +0000 | [diff] [blame] | 515 | static u64 ehea_destroy_qp_res(struct ehea_qp *qp, u64 force) |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 516 | { |
Jan-Bernd Themann | d1d25aa | 2007-07-02 13:00:46 +0200 | [diff] [blame] | 517 | u64 hret; |
| 518 | struct ehea_qp_init_attr *qp_attr = &qp->init_attr; |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 519 | |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 520 | |
Jan-Bernd Themann | d1d25aa | 2007-07-02 13:00:46 +0200 | [diff] [blame] | 521 | ehea_h_disable_and_get_hea(qp->adapter->handle, qp->fw_handle); |
| 522 | hret = ehea_h_free_resource(qp->adapter->handle, qp->fw_handle, force); |
| 523 | if (hret != H_SUCCESS) |
| 524 | return hret; |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 525 | |
Jan-Bernd Themann | d1d25aa | 2007-07-02 13:00:46 +0200 | [diff] [blame] | 526 | hw_queue_dtor(&qp->hw_squeue); |
| 527 | hw_queue_dtor(&qp->hw_rqueue1); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 528 | |
Jan-Bernd Themann | d1d25aa | 2007-07-02 13:00:46 +0200 | [diff] [blame] | 529 | if (qp_attr->rq_count > 1) |
| 530 | hw_queue_dtor(&qp->hw_rqueue2); |
| 531 | if (qp_attr->rq_count > 2) |
| 532 | hw_queue_dtor(&qp->hw_rqueue3); |
| 533 | kfree(qp); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 534 | |
Jan-Bernd Themann | d1d25aa | 2007-07-02 13:00:46 +0200 | [diff] [blame] | 535 | return hret; |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 536 | } |
| 537 | |
Jan-Bernd Themann | e542aa6 | 2007-03-22 17:50:24 +0100 | [diff] [blame] | 538 | int ehea_destroy_qp(struct ehea_qp *qp) |
| 539 | { |
Thomas Klein | ea96cea | 2010-04-20 23:10:55 +0000 | [diff] [blame] | 540 | u64 hret, aer, aerr; |
Jan-Bernd Themann | d1d25aa | 2007-07-02 13:00:46 +0200 | [diff] [blame] | 541 | if (!qp) |
| 542 | return 0; |
Jan-Bernd Themann | e542aa6 | 2007-03-22 17:50:24 +0100 | [diff] [blame] | 543 | |
Jan-Bernd Themann | 28721c8 | 2007-08-22 16:21:28 +0200 | [diff] [blame] | 544 | hcp_epas_dtor(&qp->epas); |
| 545 | |
Doug Maxey | f67c627 | 2008-01-31 20:20:51 -0600 | [diff] [blame] | 546 | hret = ehea_destroy_qp_res(qp, NORMAL_FREE); |
| 547 | if (hret == H_R_STATE) { |
Thomas Klein | ea96cea | 2010-04-20 23:10:55 +0000 | [diff] [blame] | 548 | ehea_error_data(qp->adapter, qp->fw_handle, &aer, &aerr); |
Jan-Bernd Themann | d1d25aa | 2007-07-02 13:00:46 +0200 | [diff] [blame] | 549 | hret = ehea_destroy_qp_res(qp, FORCE_FREE); |
| 550 | } |
Jan-Bernd Themann | e542aa6 | 2007-03-22 17:50:24 +0100 | [diff] [blame] | 551 | |
Jan-Bernd Themann | d1d25aa | 2007-07-02 13:00:46 +0200 | [diff] [blame] | 552 | if (hret != H_SUCCESS) { |
Joe Perches | 8c4877a | 2010-12-13 10:05:14 -0800 | [diff] [blame] | 553 | pr_err("destroy QP failed\n"); |
Jan-Bernd Themann | d1d25aa | 2007-07-02 13:00:46 +0200 | [diff] [blame] | 554 | return -EIO; |
| 555 | } |
Jan-Bernd Themann | e542aa6 | 2007-03-22 17:50:24 +0100 | [diff] [blame] | 556 | |
Jan-Bernd Themann | d1d25aa | 2007-07-02 13:00:46 +0200 | [diff] [blame] | 557 | return 0; |
Jan-Bernd Themann | e542aa6 | 2007-03-22 17:50:24 +0100 | [diff] [blame] | 558 | } |
| 559 | |
Hannes Hering | 48cfb14 | 2008-05-07 14:43:36 +0200 | [diff] [blame] | 560 | static inline int ehea_calc_index(unsigned long i, unsigned long s) |
Thomas Klein | 44c8215 | 2007-07-11 16:32:00 +0200 | [diff] [blame] | 561 | { |
Hannes Hering | 48cfb14 | 2008-05-07 14:43:36 +0200 | [diff] [blame] | 562 | return (i >> s) & EHEA_INDEX_MASK; |
| 563 | } |
Thomas Klein | 44c8215 | 2007-07-11 16:32:00 +0200 | [diff] [blame] | 564 | |
Hannes Hering | 48cfb14 | 2008-05-07 14:43:36 +0200 | [diff] [blame] | 565 | static inline int ehea_init_top_bmap(struct ehea_top_bmap *ehea_top_bmap, |
| 566 | int dir) |
| 567 | { |
Hannes Hering | d4f12da | 2008-10-16 11:36:42 +0200 | [diff] [blame] | 568 | if (!ehea_top_bmap->dir[dir]) { |
Hannes Hering | 48cfb14 | 2008-05-07 14:43:36 +0200 | [diff] [blame] | 569 | ehea_top_bmap->dir[dir] = |
| 570 | kzalloc(sizeof(struct ehea_dir_bmap), GFP_KERNEL); |
| 571 | if (!ehea_top_bmap->dir[dir]) |
| 572 | return -ENOMEM; |
| 573 | } |
| 574 | return 0; |
| 575 | } |
Thomas Klein | 44c8215 | 2007-07-11 16:32:00 +0200 | [diff] [blame] | 576 | |
Hannes Hering | 48cfb14 | 2008-05-07 14:43:36 +0200 | [diff] [blame] | 577 | static inline int ehea_init_bmap(struct ehea_bmap *ehea_bmap, int top, int dir) |
| 578 | { |
Hannes Hering | d4f12da | 2008-10-16 11:36:42 +0200 | [diff] [blame] | 579 | if (!ehea_bmap->top[top]) { |
Hannes Hering | 48cfb14 | 2008-05-07 14:43:36 +0200 | [diff] [blame] | 580 | ehea_bmap->top[top] = |
| 581 | kzalloc(sizeof(struct ehea_top_bmap), GFP_KERNEL); |
| 582 | if (!ehea_bmap->top[top]) |
| 583 | return -ENOMEM; |
| 584 | } |
| 585 | return ehea_init_top_bmap(ehea_bmap->top[top], dir); |
| 586 | } |
Thomas Klein | 44c8215 | 2007-07-11 16:32:00 +0200 | [diff] [blame] | 587 | |
Hannes Hering | d4f12da | 2008-10-16 11:36:42 +0200 | [diff] [blame] | 588 | static DEFINE_MUTEX(ehea_busmap_mutex); |
| 589 | static unsigned long ehea_mr_len; |
| 590 | |
| 591 | #define EHEA_BUSMAP_ADD_SECT 1 |
| 592 | #define EHEA_BUSMAP_REM_SECT 0 |
| 593 | |
| 594 | static void ehea_rebuild_busmap(void) |
Hannes Hering | 48cfb14 | 2008-05-07 14:43:36 +0200 | [diff] [blame] | 595 | { |
Hannes Hering | d4f12da | 2008-10-16 11:36:42 +0200 | [diff] [blame] | 596 | u64 vaddr = EHEA_BUSMAP_START; |
| 597 | int top, dir, idx; |
Thomas Klein | 44c8215 | 2007-07-11 16:32:00 +0200 | [diff] [blame] | 598 | |
Hannes Hering | d4f12da | 2008-10-16 11:36:42 +0200 | [diff] [blame] | 599 | for (top = 0; top < EHEA_MAP_ENTRIES; top++) { |
| 600 | struct ehea_top_bmap *ehea_top; |
| 601 | int valid_dir_entries = 0; |
| 602 | |
| 603 | if (!ehea_bmap->top[top]) |
| 604 | continue; |
| 605 | ehea_top = ehea_bmap->top[top]; |
| 606 | for (dir = 0; dir < EHEA_MAP_ENTRIES; dir++) { |
| 607 | struct ehea_dir_bmap *ehea_dir; |
| 608 | int valid_entries = 0; |
| 609 | |
| 610 | if (!ehea_top->dir[dir]) |
| 611 | continue; |
| 612 | valid_dir_entries++; |
| 613 | ehea_dir = ehea_top->dir[dir]; |
| 614 | for (idx = 0; idx < EHEA_MAP_ENTRIES; idx++) { |
| 615 | if (!ehea_dir->ent[idx]) |
| 616 | continue; |
| 617 | valid_entries++; |
| 618 | ehea_dir->ent[idx] = vaddr; |
| 619 | vaddr += EHEA_SECTSIZE; |
| 620 | } |
| 621 | if (!valid_entries) { |
| 622 | ehea_top->dir[dir] = NULL; |
| 623 | kfree(ehea_dir); |
| 624 | } |
| 625 | } |
| 626 | if (!valid_dir_entries) { |
| 627 | ehea_bmap->top[top] = NULL; |
| 628 | kfree(ehea_top); |
| 629 | } |
| 630 | } |
| 631 | } |
| 632 | |
Thomas Klein | 3fd09c4 | 2008-10-27 10:38:46 +0100 | [diff] [blame] | 633 | static int ehea_update_busmap(unsigned long pfn, unsigned long nr_pages, int add) |
Hannes Hering | d4f12da | 2008-10-16 11:36:42 +0200 | [diff] [blame] | 634 | { |
| 635 | unsigned long i, start_section, end_section; |
| 636 | |
Thomas Klein | 3fd09c4 | 2008-10-27 10:38:46 +0100 | [diff] [blame] | 637 | if (!nr_pages) |
| 638 | return 0; |
| 639 | |
Hannes Hering | d4f12da | 2008-10-16 11:36:42 +0200 | [diff] [blame] | 640 | if (!ehea_bmap) { |
Hannes Hering | 70666c7 | 2008-09-05 16:36:26 +0200 | [diff] [blame] | 641 | ehea_bmap = kzalloc(sizeof(struct ehea_bmap), GFP_KERNEL); |
Hannes Hering | d4f12da | 2008-10-16 11:36:42 +0200 | [diff] [blame] | 642 | if (!ehea_bmap) |
| 643 | return -ENOMEM; |
Thomas Klein | 44c8215 | 2007-07-11 16:32:00 +0200 | [diff] [blame] | 644 | } |
| 645 | |
Hannes Hering | d4f12da | 2008-10-16 11:36:42 +0200 | [diff] [blame] | 646 | start_section = (pfn * PAGE_SIZE) / EHEA_SECTSIZE; |
Thomas Klein | 3fd09c4 | 2008-10-27 10:38:46 +0100 | [diff] [blame] | 647 | end_section = start_section + ((nr_pages * PAGE_SIZE) / EHEA_SECTSIZE); |
Hannes Hering | d4f12da | 2008-10-16 11:36:42 +0200 | [diff] [blame] | 648 | /* Mark entries as valid or invalid only; address is assigned later */ |
| 649 | for (i = start_section; i < end_section; i++) { |
| 650 | u64 flag; |
| 651 | int top = ehea_calc_index(i, EHEA_TOP_INDEX_SHIFT); |
| 652 | int dir = ehea_calc_index(i, EHEA_DIR_INDEX_SHIFT); |
| 653 | int idx = i & EHEA_INDEX_MASK; |
Hannes Hering | c5916cf | 2008-11-05 13:18:21 +0100 | [diff] [blame] | 654 | |
Hannes Hering | d4f12da | 2008-10-16 11:36:42 +0200 | [diff] [blame] | 655 | if (add) { |
| 656 | int ret = ehea_init_bmap(ehea_bmap, top, dir); |
| 657 | if (ret) |
| 658 | return ret; |
| 659 | flag = 1; /* valid */ |
| 660 | ehea_mr_len += EHEA_SECTSIZE; |
| 661 | } else { |
| 662 | if (!ehea_bmap->top[top]) |
| 663 | continue; |
| 664 | if (!ehea_bmap->top[top]->dir[dir]) |
| 665 | continue; |
| 666 | flag = 0; /* invalid */ |
| 667 | ehea_mr_len -= EHEA_SECTSIZE; |
| 668 | } |
Hannes Hering | 48cfb14 | 2008-05-07 14:43:36 +0200 | [diff] [blame] | 669 | |
Hannes Hering | d4f12da | 2008-10-16 11:36:42 +0200 | [diff] [blame] | 670 | ehea_bmap->top[top]->dir[dir]->ent[idx] = flag; |
| 671 | } |
| 672 | ehea_rebuild_busmap(); /* Assign contiguous addresses for mr */ |
Thomas Klein | 44c8215 | 2007-07-11 16:32:00 +0200 | [diff] [blame] | 673 | return 0; |
| 674 | } |
| 675 | |
Hannes Hering | d4f12da | 2008-10-16 11:36:42 +0200 | [diff] [blame] | 676 | int ehea_add_sect_bmap(unsigned long pfn, unsigned long nr_pages) |
| 677 | { |
| 678 | int ret; |
Hannes Hering | 48cfb14 | 2008-05-07 14:43:36 +0200 | [diff] [blame] | 679 | |
Hannes Hering | d4f12da | 2008-10-16 11:36:42 +0200 | [diff] [blame] | 680 | mutex_lock(&ehea_busmap_mutex); |
| 681 | ret = ehea_update_busmap(pfn, nr_pages, EHEA_BUSMAP_ADD_SECT); |
| 682 | mutex_unlock(&ehea_busmap_mutex); |
| 683 | return ret; |
| 684 | } |
| 685 | |
| 686 | int ehea_rem_sect_bmap(unsigned long pfn, unsigned long nr_pages) |
| 687 | { |
| 688 | int ret; |
| 689 | |
| 690 | mutex_lock(&ehea_busmap_mutex); |
| 691 | ret = ehea_update_busmap(pfn, nr_pages, EHEA_BUSMAP_REM_SECT); |
| 692 | mutex_unlock(&ehea_busmap_mutex); |
| 693 | return ret; |
| 694 | } |
| 695 | |
Thomas Klein | 3fd09c4 | 2008-10-27 10:38:46 +0100 | [diff] [blame] | 696 | static int ehea_is_hugepage(unsigned long pfn) |
Hannes Hering | d4f12da | 2008-10-16 11:36:42 +0200 | [diff] [blame] | 697 | { |
Thomas Klein | 3fd09c4 | 2008-10-27 10:38:46 +0100 | [diff] [blame] | 698 | int page_order; |
| 699 | |
| 700 | if (pfn & EHEA_HUGEPAGE_PFN_MASK) |
| 701 | return 0; |
| 702 | |
| 703 | page_order = compound_order(pfn_to_page(pfn)); |
| 704 | if (page_order + PAGE_SHIFT != EHEA_HUGEPAGESHIFT) |
| 705 | return 0; |
| 706 | |
| 707 | return 1; |
| 708 | } |
| 709 | |
| 710 | static int ehea_create_busmap_callback(unsigned long initial_pfn, |
| 711 | unsigned long total_nr_pages, void *arg) |
| 712 | { |
| 713 | int ret; |
| 714 | unsigned long pfn, start_pfn, end_pfn, nr_pages; |
| 715 | |
| 716 | if ((total_nr_pages * PAGE_SIZE) < EHEA_HUGEPAGE_SIZE) |
| 717 | return ehea_update_busmap(initial_pfn, total_nr_pages, |
| 718 | EHEA_BUSMAP_ADD_SECT); |
| 719 | |
| 720 | /* Given chunk is >= 16GB -> check for hugepages */ |
| 721 | start_pfn = initial_pfn; |
| 722 | end_pfn = initial_pfn + total_nr_pages; |
| 723 | pfn = start_pfn; |
| 724 | |
| 725 | while (pfn < end_pfn) { |
| 726 | if (ehea_is_hugepage(pfn)) { |
| 727 | /* Add mem found in front of the hugepage */ |
| 728 | nr_pages = pfn - start_pfn; |
| 729 | ret = ehea_update_busmap(start_pfn, nr_pages, |
| 730 | EHEA_BUSMAP_ADD_SECT); |
| 731 | if (ret) |
| 732 | return ret; |
| 733 | |
| 734 | /* Skip the hugepage */ |
| 735 | pfn += (EHEA_HUGEPAGE_SIZE / PAGE_SIZE); |
| 736 | start_pfn = pfn; |
| 737 | } else |
| 738 | pfn += (EHEA_SECTSIZE / PAGE_SIZE); |
| 739 | } |
| 740 | |
| 741 | /* Add mem found behind the hugepage(s) */ |
| 742 | nr_pages = pfn - start_pfn; |
| 743 | return ehea_update_busmap(start_pfn, nr_pages, EHEA_BUSMAP_ADD_SECT); |
Hannes Hering | d4f12da | 2008-10-16 11:36:42 +0200 | [diff] [blame] | 744 | } |
Hannes Hering | 48cfb14 | 2008-05-07 14:43:36 +0200 | [diff] [blame] | 745 | |
| 746 | int ehea_create_busmap(void) |
| 747 | { |
| 748 | int ret; |
Hannes Hering | d4f12da | 2008-10-16 11:36:42 +0200 | [diff] [blame] | 749 | |
Hannes Hering | 48cfb14 | 2008-05-07 14:43:36 +0200 | [diff] [blame] | 750 | mutex_lock(&ehea_busmap_mutex); |
| 751 | ehea_mr_len = 0; |
KAMEZAWA Hiroyuki | 908eedc | 2009-09-22 16:45:46 -0700 | [diff] [blame] | 752 | ret = walk_system_ram_range(0, 1ULL << MAX_PHYSMEM_BITS, NULL, |
Hannes Hering | 48cfb14 | 2008-05-07 14:43:36 +0200 | [diff] [blame] | 753 | ehea_create_busmap_callback); |
| 754 | mutex_unlock(&ehea_busmap_mutex); |
| 755 | return ret; |
| 756 | } |
| 757 | |
Doug Maxey | f67c627 | 2008-01-31 20:20:51 -0600 | [diff] [blame] | 758 | void ehea_destroy_busmap(void) |
Thomas Klein | 44c8215 | 2007-07-11 16:32:00 +0200 | [diff] [blame] | 759 | { |
Hannes Hering | 48cfb14 | 2008-05-07 14:43:36 +0200 | [diff] [blame] | 760 | int top, dir; |
| 761 | mutex_lock(&ehea_busmap_mutex); |
| 762 | if (!ehea_bmap) |
| 763 | goto out_destroy; |
| 764 | |
| 765 | for (top = 0; top < EHEA_MAP_ENTRIES; top++) { |
| 766 | if (!ehea_bmap->top[top]) |
| 767 | continue; |
| 768 | |
| 769 | for (dir = 0; dir < EHEA_MAP_ENTRIES; dir++) { |
| 770 | if (!ehea_bmap->top[top]->dir[dir]) |
| 771 | continue; |
| 772 | |
| 773 | kfree(ehea_bmap->top[top]->dir[dir]); |
| 774 | } |
| 775 | |
| 776 | kfree(ehea_bmap->top[top]); |
| 777 | } |
| 778 | |
| 779 | kfree(ehea_bmap); |
| 780 | ehea_bmap = NULL; |
Hannes Hering | c5916cf | 2008-11-05 13:18:21 +0100 | [diff] [blame] | 781 | out_destroy: |
Hannes Hering | 48cfb14 | 2008-05-07 14:43:36 +0200 | [diff] [blame] | 782 | mutex_unlock(&ehea_busmap_mutex); |
Thomas Klein | 44c8215 | 2007-07-11 16:32:00 +0200 | [diff] [blame] | 783 | } |
| 784 | |
| 785 | u64 ehea_map_vaddr(void *caddr) |
| 786 | { |
Hannes Hering | 48cfb14 | 2008-05-07 14:43:36 +0200 | [diff] [blame] | 787 | int top, dir, idx; |
| 788 | unsigned long index, offset; |
Thomas Klein | 44c8215 | 2007-07-11 16:32:00 +0200 | [diff] [blame] | 789 | |
Hannes Hering | 48cfb14 | 2008-05-07 14:43:36 +0200 | [diff] [blame] | 790 | if (!ehea_bmap) |
| 791 | return EHEA_INVAL_ADDR; |
Thomas Klein | 44c8215 | 2007-07-11 16:32:00 +0200 | [diff] [blame] | 792 | |
Michael Ellerman | 67e1dbc | 2012-07-25 21:19:55 +0000 | [diff] [blame] | 793 | index = __pa(caddr) >> SECTION_SIZE_BITS; |
Hannes Hering | 48cfb14 | 2008-05-07 14:43:36 +0200 | [diff] [blame] | 794 | top = (index >> EHEA_TOP_INDEX_SHIFT) & EHEA_INDEX_MASK; |
| 795 | if (!ehea_bmap->top[top]) |
| 796 | return EHEA_INVAL_ADDR; |
Thomas Klein | 44c8215 | 2007-07-11 16:32:00 +0200 | [diff] [blame] | 797 | |
Hannes Hering | 48cfb14 | 2008-05-07 14:43:36 +0200 | [diff] [blame] | 798 | dir = (index >> EHEA_DIR_INDEX_SHIFT) & EHEA_INDEX_MASK; |
| 799 | if (!ehea_bmap->top[top]->dir[dir]) |
| 800 | return EHEA_INVAL_ADDR; |
| 801 | |
| 802 | idx = index & EHEA_INDEX_MASK; |
| 803 | if (!ehea_bmap->top[top]->dir[dir]->ent[idx]) |
| 804 | return EHEA_INVAL_ADDR; |
| 805 | |
| 806 | offset = (unsigned long)caddr & (EHEA_SECTSIZE - 1); |
| 807 | return ehea_bmap->top[top]->dir[dir]->ent[idx] | offset; |
| 808 | } |
| 809 | |
| 810 | static inline void *ehea_calc_sectbase(int top, int dir, int idx) |
| 811 | { |
| 812 | unsigned long ret = idx; |
| 813 | ret |= dir << EHEA_DIR_INDEX_SHIFT; |
| 814 | ret |= top << EHEA_TOP_INDEX_SHIFT; |
Michael Ellerman | 67e1dbc | 2012-07-25 21:19:55 +0000 | [diff] [blame] | 815 | return __va(ret << SECTION_SIZE_BITS); |
Hannes Hering | 48cfb14 | 2008-05-07 14:43:36 +0200 | [diff] [blame] | 816 | } |
| 817 | |
| 818 | static u64 ehea_reg_mr_section(int top, int dir, int idx, u64 *pt, |
| 819 | struct ehea_adapter *adapter, |
| 820 | struct ehea_mr *mr) |
| 821 | { |
| 822 | void *pg; |
| 823 | u64 j, m, hret; |
| 824 | unsigned long k = 0; |
Michael Ellerman | 67e1dbc | 2012-07-25 21:19:55 +0000 | [diff] [blame] | 825 | u64 pt_abs = __pa(pt); |
Hannes Hering | 48cfb14 | 2008-05-07 14:43:36 +0200 | [diff] [blame] | 826 | |
| 827 | void *sectbase = ehea_calc_sectbase(top, dir, idx); |
| 828 | |
| 829 | for (j = 0; j < (EHEA_PAGES_PER_SECTION / EHEA_MAX_RPAGE); j++) { |
| 830 | |
| 831 | for (m = 0; m < EHEA_MAX_RPAGE; m++) { |
| 832 | pg = sectbase + ((k++) * EHEA_PAGESIZE); |
Michael Ellerman | 67e1dbc | 2012-07-25 21:19:55 +0000 | [diff] [blame] | 833 | pt[m] = __pa(pg); |
Hannes Hering | 48cfb14 | 2008-05-07 14:43:36 +0200 | [diff] [blame] | 834 | } |
| 835 | hret = ehea_h_register_rpage_mr(adapter->handle, mr->handle, 0, |
| 836 | 0, pt_abs, EHEA_MAX_RPAGE); |
| 837 | |
Joe Perches | 8e95a20 | 2009-12-03 07:58:21 +0000 | [diff] [blame] | 838 | if ((hret != H_SUCCESS) && |
| 839 | (hret != H_PAGE_REGISTERED)) { |
Hannes Hering | 48cfb14 | 2008-05-07 14:43:36 +0200 | [diff] [blame] | 840 | ehea_h_free_resource(adapter->handle, mr->handle, |
| 841 | FORCE_FREE); |
Joe Perches | 8c4877a | 2010-12-13 10:05:14 -0800 | [diff] [blame] | 842 | pr_err("register_rpage_mr failed\n"); |
Hannes Hering | 48cfb14 | 2008-05-07 14:43:36 +0200 | [diff] [blame] | 843 | return hret; |
| 844 | } |
| 845 | } |
| 846 | return hret; |
| 847 | } |
| 848 | |
| 849 | static u64 ehea_reg_mr_sections(int top, int dir, u64 *pt, |
| 850 | struct ehea_adapter *adapter, |
| 851 | struct ehea_mr *mr) |
| 852 | { |
| 853 | u64 hret = H_SUCCESS; |
| 854 | int idx; |
| 855 | |
| 856 | for (idx = 0; idx < EHEA_MAP_ENTRIES; idx++) { |
| 857 | if (!ehea_bmap->top[top]->dir[dir]->ent[idx]) |
| 858 | continue; |
Hannes Hering | c5916cf | 2008-11-05 13:18:21 +0100 | [diff] [blame] | 859 | |
Hannes Hering | 48cfb14 | 2008-05-07 14:43:36 +0200 | [diff] [blame] | 860 | hret = ehea_reg_mr_section(top, dir, idx, pt, adapter, mr); |
| 861 | if ((hret != H_SUCCESS) && (hret != H_PAGE_REGISTERED)) |
Hannes Hering | c5916cf | 2008-11-05 13:18:21 +0100 | [diff] [blame] | 862 | return hret; |
Hannes Hering | 48cfb14 | 2008-05-07 14:43:36 +0200 | [diff] [blame] | 863 | } |
| 864 | return hret; |
| 865 | } |
| 866 | |
| 867 | static u64 ehea_reg_mr_dir_sections(int top, u64 *pt, |
| 868 | struct ehea_adapter *adapter, |
| 869 | struct ehea_mr *mr) |
| 870 | { |
| 871 | u64 hret = H_SUCCESS; |
| 872 | int dir; |
| 873 | |
| 874 | for (dir = 0; dir < EHEA_MAP_ENTRIES; dir++) { |
| 875 | if (!ehea_bmap->top[top]->dir[dir]) |
| 876 | continue; |
| 877 | |
| 878 | hret = ehea_reg_mr_sections(top, dir, pt, adapter, mr); |
| 879 | if ((hret != H_SUCCESS) && (hret != H_PAGE_REGISTERED)) |
Hannes Hering | c5916cf | 2008-11-05 13:18:21 +0100 | [diff] [blame] | 880 | return hret; |
Hannes Hering | 48cfb14 | 2008-05-07 14:43:36 +0200 | [diff] [blame] | 881 | } |
| 882 | return hret; |
Thomas Klein | 44c8215 | 2007-07-11 16:32:00 +0200 | [diff] [blame] | 883 | } |
| 884 | |
Jan-Bernd Themann | e542aa6 | 2007-03-22 17:50:24 +0100 | [diff] [blame] | 885 | int ehea_reg_kernel_mr(struct ehea_adapter *adapter, struct ehea_mr *mr) |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 886 | { |
Thomas Klein | 44c8215 | 2007-07-11 16:32:00 +0200 | [diff] [blame] | 887 | int ret; |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 888 | u64 *pt; |
Hannes Hering | 48cfb14 | 2008-05-07 14:43:36 +0200 | [diff] [blame] | 889 | u64 hret; |
Thomas Klein | 44c8215 | 2007-07-11 16:32:00 +0200 | [diff] [blame] | 890 | u32 acc_ctrl = EHEA_MR_ACC_CTRL; |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 891 | |
Hannes Hering | 48cfb14 | 2008-05-07 14:43:36 +0200 | [diff] [blame] | 892 | unsigned long top; |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 893 | |
Nathan Lynch | d76e56b | 2008-12-22 08:42:11 +0000 | [diff] [blame] | 894 | pt = (void *)get_zeroed_page(GFP_KERNEL); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 895 | if (!pt) { |
Joe Perches | 8c4877a | 2010-12-13 10:05:14 -0800 | [diff] [blame] | 896 | pr_err("no mem\n"); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 897 | ret = -ENOMEM; |
| 898 | goto out; |
| 899 | } |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 900 | |
Hannes Hering | 48cfb14 | 2008-05-07 14:43:36 +0200 | [diff] [blame] | 901 | hret = ehea_h_alloc_resource_mr(adapter->handle, EHEA_BUSMAP_START, |
| 902 | ehea_mr_len, acc_ctrl, adapter->pd, |
Jan-Bernd Themann | e542aa6 | 2007-03-22 17:50:24 +0100 | [diff] [blame] | 903 | &mr->handle, &mr->lkey); |
Hannes Hering | 48cfb14 | 2008-05-07 14:43:36 +0200 | [diff] [blame] | 904 | |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 905 | if (hret != H_SUCCESS) { |
Joe Perches | 8c4877a | 2010-12-13 10:05:14 -0800 | [diff] [blame] | 906 | pr_err("alloc_resource_mr failed\n"); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 907 | ret = -EIO; |
| 908 | goto out; |
| 909 | } |
| 910 | |
Hannes Hering | 48cfb14 | 2008-05-07 14:43:36 +0200 | [diff] [blame] | 911 | if (!ehea_bmap) { |
| 912 | ehea_h_free_resource(adapter->handle, mr->handle, FORCE_FREE); |
Joe Perches | 8c4877a | 2010-12-13 10:05:14 -0800 | [diff] [blame] | 913 | pr_err("no busmap available\n"); |
Hannes Hering | 48cfb14 | 2008-05-07 14:43:36 +0200 | [diff] [blame] | 914 | ret = -EIO; |
| 915 | goto out; |
| 916 | } |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 917 | |
Hannes Hering | 48cfb14 | 2008-05-07 14:43:36 +0200 | [diff] [blame] | 918 | for (top = 0; top < EHEA_MAP_ENTRIES; top++) { |
| 919 | if (!ehea_bmap->top[top]) |
| 920 | continue; |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 921 | |
Hannes Hering | 48cfb14 | 2008-05-07 14:43:36 +0200 | [diff] [blame] | 922 | hret = ehea_reg_mr_dir_sections(top, pt, adapter, mr); |
| 923 | if((hret != H_PAGE_REGISTERED) && (hret != H_SUCCESS)) |
| 924 | break; |
| 925 | } |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 926 | |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 927 | if (hret != H_SUCCESS) { |
Thomas Klein | 44c8215 | 2007-07-11 16:32:00 +0200 | [diff] [blame] | 928 | ehea_h_free_resource(adapter->handle, mr->handle, FORCE_FREE); |
Joe Perches | 8c4877a | 2010-12-13 10:05:14 -0800 | [diff] [blame] | 929 | pr_err("registering mr failed\n"); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 930 | ret = -EIO; |
| 931 | goto out; |
| 932 | } |
Jan-Bernd Themann | e542aa6 | 2007-03-22 17:50:24 +0100 | [diff] [blame] | 933 | |
Thomas Klein | 44c8215 | 2007-07-11 16:32:00 +0200 | [diff] [blame] | 934 | mr->vaddr = EHEA_BUSMAP_START; |
Jan-Bernd Themann | e542aa6 | 2007-03-22 17:50:24 +0100 | [diff] [blame] | 935 | mr->adapter = adapter; |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 936 | ret = 0; |
| 937 | out: |
Nathan Lynch | d76e56b | 2008-12-22 08:42:11 +0000 | [diff] [blame] | 938 | free_page((unsigned long)pt); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 939 | return ret; |
| 940 | } |
| 941 | |
Jan-Bernd Themann | e542aa6 | 2007-03-22 17:50:24 +0100 | [diff] [blame] | 942 | int ehea_rem_mr(struct ehea_mr *mr) |
| 943 | { |
| 944 | u64 hret; |
| 945 | |
| 946 | if (!mr || !mr->adapter) |
| 947 | return -EINVAL; |
| 948 | |
| 949 | hret = ehea_h_free_resource(mr->adapter->handle, mr->handle, |
| 950 | FORCE_FREE); |
| 951 | if (hret != H_SUCCESS) { |
Joe Perches | 8c4877a | 2010-12-13 10:05:14 -0800 | [diff] [blame] | 952 | pr_err("destroy MR failed\n"); |
Jan-Bernd Themann | e542aa6 | 2007-03-22 17:50:24 +0100 | [diff] [blame] | 953 | return -EIO; |
| 954 | } |
| 955 | |
| 956 | return 0; |
| 957 | } |
| 958 | |
| 959 | int ehea_gen_smr(struct ehea_adapter *adapter, struct ehea_mr *old_mr, |
| 960 | struct ehea_mr *shared_mr) |
| 961 | { |
| 962 | u64 hret; |
| 963 | |
| 964 | hret = ehea_h_register_smr(adapter->handle, old_mr->handle, |
| 965 | old_mr->vaddr, EHEA_MR_ACC_CTRL, |
| 966 | adapter->pd, shared_mr); |
| 967 | if (hret != H_SUCCESS) |
| 968 | return -EIO; |
| 969 | |
| 970 | shared_mr->adapter = adapter; |
| 971 | |
| 972 | return 0; |
| 973 | } |
| 974 | |
Thadeu Lima de Souza Cascardo | 1886e5d | 2012-01-13 08:06:32 +0000 | [diff] [blame] | 975 | static void print_error_data(u64 *data) |
Jan-Bernd Themann | d2db9ee | 2007-02-09 09:10:51 +0100 | [diff] [blame] | 976 | { |
| 977 | int length; |
| 978 | u64 type = EHEA_BMASK_GET(ERROR_DATA_TYPE, data[2]); |
| 979 | u64 resource = data[1]; |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 980 | |
Jan-Bernd Themann | d2db9ee | 2007-02-09 09:10:51 +0100 | [diff] [blame] | 981 | length = EHEA_BMASK_GET(ERROR_DATA_LENGTH, data[0]); |
| 982 | |
| 983 | if (length > EHEA_PAGESIZE) |
| 984 | length = EHEA_PAGESIZE; |
| 985 | |
Thomas Klein | ea96cea | 2010-04-20 23:10:55 +0000 | [diff] [blame] | 986 | if (type == EHEA_AER_RESTYPE_QP) |
Joe Perches | 8c4877a | 2010-12-13 10:05:14 -0800 | [diff] [blame] | 987 | pr_err("QP (resource=%llX) state: AER=0x%llX, AERR=0x%llX, port=%llX\n", |
| 988 | resource, data[6], data[12], data[22]); |
Thomas Klein | ea96cea | 2010-04-20 23:10:55 +0000 | [diff] [blame] | 989 | else if (type == EHEA_AER_RESTYPE_CQ) |
Joe Perches | 8c4877a | 2010-12-13 10:05:14 -0800 | [diff] [blame] | 990 | pr_err("CQ (resource=%llX) state: AER=0x%llX\n", |
| 991 | resource, data[6]); |
Thomas Klein | ea96cea | 2010-04-20 23:10:55 +0000 | [diff] [blame] | 992 | else if (type == EHEA_AER_RESTYPE_EQ) |
Joe Perches | 8c4877a | 2010-12-13 10:05:14 -0800 | [diff] [blame] | 993 | pr_err("EQ (resource=%llX) state: AER=0x%llX\n", |
| 994 | resource, data[6]); |
Jan-Bernd Themann | e542aa6 | 2007-03-22 17:50:24 +0100 | [diff] [blame] | 995 | |
Jan-Bernd Themann | d2db9ee | 2007-02-09 09:10:51 +0100 | [diff] [blame] | 996 | ehea_dump(data, length, "error data"); |
| 997 | } |
| 998 | |
Thomas Klein | ea96cea | 2010-04-20 23:10:55 +0000 | [diff] [blame] | 999 | u64 ehea_error_data(struct ehea_adapter *adapter, u64 res_handle, |
| 1000 | u64 *aer, u64 *aerr) |
Jan-Bernd Themann | d2db9ee | 2007-02-09 09:10:51 +0100 | [diff] [blame] | 1001 | { |
| 1002 | unsigned long ret; |
| 1003 | u64 *rblock; |
Thomas Klein | ea96cea | 2010-04-20 23:10:55 +0000 | [diff] [blame] | 1004 | u64 type = 0; |
Jan-Bernd Themann | d2db9ee | 2007-02-09 09:10:51 +0100 | [diff] [blame] | 1005 | |
Thomas Klein | 3faf269 | 2009-01-21 14:45:33 -0800 | [diff] [blame] | 1006 | rblock = (void *)get_zeroed_page(GFP_KERNEL); |
Jan-Bernd Themann | d2db9ee | 2007-02-09 09:10:51 +0100 | [diff] [blame] | 1007 | if (!rblock) { |
Joe Perches | 8c4877a | 2010-12-13 10:05:14 -0800 | [diff] [blame] | 1008 | pr_err("Cannot allocate rblock memory\n"); |
Thomas Klein | ea96cea | 2010-04-20 23:10:55 +0000 | [diff] [blame] | 1009 | goto out; |
Jan-Bernd Themann | d2db9ee | 2007-02-09 09:10:51 +0100 | [diff] [blame] | 1010 | } |
| 1011 | |
Thomas Klein | ea96cea | 2010-04-20 23:10:55 +0000 | [diff] [blame] | 1012 | ret = ehea_h_error_data(adapter->handle, res_handle, rblock); |
Jan-Bernd Themann | d2db9ee | 2007-02-09 09:10:51 +0100 | [diff] [blame] | 1013 | |
Thomas Klein | ea96cea | 2010-04-20 23:10:55 +0000 | [diff] [blame] | 1014 | if (ret == H_SUCCESS) { |
| 1015 | type = EHEA_BMASK_GET(ERROR_DATA_TYPE, rblock[2]); |
| 1016 | *aer = rblock[6]; |
| 1017 | *aerr = rblock[12]; |
Jan-Bernd Themann | d2db9ee | 2007-02-09 09:10:51 +0100 | [diff] [blame] | 1018 | print_error_data(rblock); |
Thomas Klein | ea96cea | 2010-04-20 23:10:55 +0000 | [diff] [blame] | 1019 | } else if (ret == H_R_STATE) { |
Joe Perches | 8c4877a | 2010-12-13 10:05:14 -0800 | [diff] [blame] | 1020 | pr_err("No error data available: %llX\n", res_handle); |
Thomas Klein | ea96cea | 2010-04-20 23:10:55 +0000 | [diff] [blame] | 1021 | } else |
Joe Perches | 8c4877a | 2010-12-13 10:05:14 -0800 | [diff] [blame] | 1022 | pr_err("Error data could not be fetched: %llX\n", res_handle); |
Jan-Bernd Themann | d2db9ee | 2007-02-09 09:10:51 +0100 | [diff] [blame] | 1023 | |
Thomas Klein | 3faf269 | 2009-01-21 14:45:33 -0800 | [diff] [blame] | 1024 | free_page((unsigned long)rblock); |
Thomas Klein | ea96cea | 2010-04-20 23:10:55 +0000 | [diff] [blame] | 1025 | out: |
| 1026 | return type; |
Jan-Bernd Themann | d2db9ee | 2007-02-09 09:10:51 +0100 | [diff] [blame] | 1027 | } |