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 | * Functions for EQs, NEQs and interrupts |
| 5 | * |
| 6 | * Authors: Heiko J Schick <schickhj@de.ibm.com> |
| 7 | * Khadija Souissi <souissi@de.ibm.com> |
Joachim Fenkes | 28db6be | 2007-07-09 15:30:39 +0200 | [diff] [blame] | 8 | * Hoang-Nam Nguyen <hnguyen@de.ibm.com> |
| 9 | * Joachim Fenkes <fenkes@de.ibm.com> |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 10 | * |
| 11 | * Copyright (c) 2005 IBM Corporation |
| 12 | * |
| 13 | * All rights reserved. |
| 14 | * |
| 15 | * This source code is distributed under a dual license of GPL v2.0 and OpenIB |
| 16 | * BSD. |
| 17 | * |
| 18 | * OpenIB BSD License |
| 19 | * |
| 20 | * Redistribution and use in source and binary forms, with or without |
| 21 | * modification, are permitted provided that the following conditions are met: |
| 22 | * |
| 23 | * Redistributions of source code must retain the above copyright notice, this |
| 24 | * list of conditions and the following disclaimer. |
| 25 | * |
| 26 | * Redistributions in binary form must reproduce the above copyright notice, |
| 27 | * this list of conditions and the following disclaimer in the documentation |
| 28 | * and/or other materials |
| 29 | * provided with the distribution. |
| 30 | * |
| 31 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 32 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 33 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 34 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
| 35 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 36 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 37 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR |
| 38 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER |
| 39 | * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 40 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 41 | * POSSIBILITY OF SUCH DAMAGE. |
| 42 | */ |
| 43 | |
| 44 | #include "ehca_classes.h" |
| 45 | #include "ehca_irq.h" |
| 46 | #include "ehca_iverbs.h" |
| 47 | #include "ehca_tools.h" |
| 48 | #include "hcp_if.h" |
| 49 | #include "hipz_fns.h" |
Hoang-Nam Nguyen | 7e28db5 | 2006-11-07 00:56:39 +0100 | [diff] [blame] | 50 | #include "ipz_pt_fn.h" |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 51 | |
Hoang-Nam Nguyen | 2b94397 | 2007-07-12 17:53:47 +0200 | [diff] [blame] | 52 | #define EQE_COMPLETION_EVENT EHCA_BMASK_IBM( 1, 1) |
| 53 | #define EQE_CQ_QP_NUMBER EHCA_BMASK_IBM( 8, 31) |
| 54 | #define EQE_EE_IDENTIFIER EHCA_BMASK_IBM( 2, 7) |
| 55 | #define EQE_CQ_NUMBER EHCA_BMASK_IBM( 8, 31) |
| 56 | #define EQE_QP_NUMBER EHCA_BMASK_IBM( 8, 31) |
| 57 | #define EQE_QP_TOKEN EHCA_BMASK_IBM(32, 63) |
| 58 | #define EQE_CQ_TOKEN EHCA_BMASK_IBM(32, 63) |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 59 | |
Hoang-Nam Nguyen | 2b94397 | 2007-07-12 17:53:47 +0200 | [diff] [blame] | 60 | #define NEQE_COMPLETION_EVENT EHCA_BMASK_IBM( 1, 1) |
| 61 | #define NEQE_EVENT_CODE EHCA_BMASK_IBM( 2, 7) |
| 62 | #define NEQE_PORT_NUMBER EHCA_BMASK_IBM( 8, 15) |
| 63 | #define NEQE_PORT_AVAILABILITY EHCA_BMASK_IBM(16, 16) |
| 64 | #define NEQE_DISRUPTIVE EHCA_BMASK_IBM(16, 16) |
Hoang-Nam Nguyen | e57d62a | 2007-12-20 15:06:33 +0100 | [diff] [blame] | 65 | #define NEQE_SPECIFIC_EVENT EHCA_BMASK_IBM(16, 23) |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 66 | |
Hoang-Nam Nguyen | 2b94397 | 2007-07-12 17:53:47 +0200 | [diff] [blame] | 67 | #define ERROR_DATA_LENGTH EHCA_BMASK_IBM(52, 63) |
| 68 | #define ERROR_DATA_TYPE EHCA_BMASK_IBM( 0, 7) |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 69 | |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 70 | static void queue_comp_task(struct ehca_cq *__cq); |
| 71 | |
Hoang-Nam Nguyen | 2b94397 | 2007-07-12 17:53:47 +0200 | [diff] [blame] | 72 | static struct ehca_comp_pool *pool; |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 73 | |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 74 | static inline void comp_event_callback(struct ehca_cq *cq) |
| 75 | { |
| 76 | if (!cq->ib_cq.comp_handler) |
| 77 | return; |
| 78 | |
| 79 | spin_lock(&cq->cb_lock); |
| 80 | cq->ib_cq.comp_handler(&cq->ib_cq, cq->ib_cq.cq_context); |
| 81 | spin_unlock(&cq->cb_lock); |
| 82 | |
| 83 | return; |
| 84 | } |
| 85 | |
Hoang-Nam Nguyen | 2b94397 | 2007-07-12 17:53:47 +0200 | [diff] [blame] | 86 | static void print_error_data(struct ehca_shca *shca, void *data, |
| 87 | u64 *rblock, int length) |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 88 | { |
| 89 | u64 type = EHCA_BMASK_GET(ERROR_DATA_TYPE, rblock[2]); |
| 90 | u64 resource = rblock[1]; |
| 91 | |
| 92 | switch (type) { |
| 93 | case 0x1: /* Queue Pair */ |
| 94 | { |
Hoang-Nam Nguyen | 2b94397 | 2007-07-12 17:53:47 +0200 | [diff] [blame] | 95 | struct ehca_qp *qp = (struct ehca_qp *)data; |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 96 | |
| 97 | /* only print error data if AER is set */ |
| 98 | if (rblock[6] == 0) |
| 99 | return; |
| 100 | |
| 101 | ehca_err(&shca->ib_device, |
| 102 | "QP 0x%x (resource=%lx) has errors.", |
| 103 | qp->ib_qp.qp_num, resource); |
| 104 | break; |
| 105 | } |
| 106 | case 0x4: /* Completion Queue */ |
| 107 | { |
Hoang-Nam Nguyen | 2b94397 | 2007-07-12 17:53:47 +0200 | [diff] [blame] | 108 | struct ehca_cq *cq = (struct ehca_cq *)data; |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 109 | |
| 110 | ehca_err(&shca->ib_device, |
| 111 | "CQ 0x%x (resource=%lx) has errors.", |
| 112 | cq->cq_number, resource); |
| 113 | break; |
| 114 | } |
| 115 | default: |
| 116 | ehca_err(&shca->ib_device, |
Eddy L O Jansson | 0e6ff15 | 2007-07-31 00:38:53 -0700 | [diff] [blame] | 117 | "Unknown error type: %lx on %s.", |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 118 | type, shca->ib_device.name); |
| 119 | break; |
| 120 | } |
| 121 | |
| 122 | ehca_err(&shca->ib_device, "Error data is available: %lx.", resource); |
| 123 | ehca_err(&shca->ib_device, "EHCA ----- error data begin " |
| 124 | "---------------------------------------------------"); |
| 125 | ehca_dmp(rblock, length, "resource=%lx", resource); |
| 126 | ehca_err(&shca->ib_device, "EHCA ----- error data end " |
| 127 | "----------------------------------------------------"); |
| 128 | |
| 129 | return; |
| 130 | } |
| 131 | |
| 132 | int ehca_error_data(struct ehca_shca *shca, void *data, |
| 133 | u64 resource) |
| 134 | { |
| 135 | |
| 136 | unsigned long ret; |
| 137 | u64 *rblock; |
| 138 | unsigned long block_count; |
| 139 | |
Hoang-Nam Nguyen | f2d9136 | 2007-01-09 18:04:14 +0100 | [diff] [blame] | 140 | rblock = ehca_alloc_fw_ctrlblock(GFP_ATOMIC); |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 141 | if (!rblock) { |
| 142 | ehca_err(&shca->ib_device, "Cannot allocate rblock memory."); |
| 143 | ret = -ENOMEM; |
| 144 | goto error_data1; |
| 145 | } |
| 146 | |
Hoang-Nam Nguyen | 7e28db5 | 2006-11-07 00:56:39 +0100 | [diff] [blame] | 147 | /* rblock must be 4K aligned and should be 4K large */ |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 148 | ret = hipz_h_error_data(shca->ipz_hca_handle, |
| 149 | resource, |
| 150 | rblock, |
| 151 | &block_count); |
| 152 | |
Hoang-Nam Nguyen | 7e28db5 | 2006-11-07 00:56:39 +0100 | [diff] [blame] | 153 | if (ret == H_R_STATE) |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 154 | ehca_err(&shca->ib_device, |
| 155 | "No error data is available: %lx.", resource); |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 156 | else if (ret == H_SUCCESS) { |
| 157 | int length; |
| 158 | |
| 159 | length = EHCA_BMASK_GET(ERROR_DATA_LENGTH, rblock[0]); |
| 160 | |
Hoang-Nam Nguyen | 7e28db5 | 2006-11-07 00:56:39 +0100 | [diff] [blame] | 161 | if (length > EHCA_PAGESIZE) |
| 162 | length = EHCA_PAGESIZE; |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 163 | |
| 164 | print_error_data(shca, data, rblock, length); |
Hoang-Nam Nguyen | 7e28db5 | 2006-11-07 00:56:39 +0100 | [diff] [blame] | 165 | } else |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 166 | ehca_err(&shca->ib_device, |
| 167 | "Error data could not be fetched: %lx", resource); |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 168 | |
Hoang-Nam Nguyen | 7e28db5 | 2006-11-07 00:56:39 +0100 | [diff] [blame] | 169 | ehca_free_fw_ctrlblock(rblock); |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 170 | |
| 171 | error_data1: |
| 172 | return ret; |
| 173 | |
| 174 | } |
| 175 | |
Joachim Fenkes | 5ff70cac | 2007-08-31 16:03:37 +0200 | [diff] [blame] | 176 | static void dispatch_qp_event(struct ehca_shca *shca, struct ehca_qp *qp, |
| 177 | enum ib_event_type event_type) |
| 178 | { |
| 179 | struct ib_event event; |
| 180 | |
| 181 | event.device = &shca->ib_device; |
| 182 | event.event = event_type; |
| 183 | |
| 184 | if (qp->ext_type == EQPT_SRQ) { |
| 185 | if (!qp->ib_srq.event_handler) |
| 186 | return; |
| 187 | |
| 188 | event.element.srq = &qp->ib_srq; |
| 189 | qp->ib_srq.event_handler(&event, qp->ib_srq.srq_context); |
| 190 | } else { |
| 191 | if (!qp->ib_qp.event_handler) |
| 192 | return; |
| 193 | |
| 194 | event.element.qp = &qp->ib_qp; |
| 195 | qp->ib_qp.event_handler(&event, qp->ib_qp.qp_context); |
| 196 | } |
| 197 | } |
| 198 | |
Hoang-Nam Nguyen | 633a5ae | 2007-07-20 16:02:18 +0200 | [diff] [blame] | 199 | static void qp_event_callback(struct ehca_shca *shca, u64 eqe, |
| 200 | enum ib_event_type event_type, int fatal) |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 201 | { |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 202 | struct ehca_qp *qp; |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 203 | u32 token = EHCA_BMASK_GET(EQE_QP_TOKEN, eqe); |
| 204 | |
Joachim Fenkes | 26ed687 | 2007-07-09 15:31:10 +0200 | [diff] [blame] | 205 | read_lock(&ehca_qp_idr_lock); |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 206 | qp = idr_find(&ehca_qp_idr, token); |
Joachim Fenkes | 26ed687 | 2007-07-09 15:31:10 +0200 | [diff] [blame] | 207 | read_unlock(&ehca_qp_idr_lock); |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 208 | |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 209 | if (!qp) |
| 210 | return; |
| 211 | |
Hoang-Nam Nguyen | 633a5ae | 2007-07-20 16:02:18 +0200 | [diff] [blame] | 212 | if (fatal) |
| 213 | ehca_error_data(shca, qp, qp->ipz_qp_handle.handle); |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 214 | |
Joachim Fenkes | 5ff70cac | 2007-08-31 16:03:37 +0200 | [diff] [blame] | 215 | dispatch_qp_event(shca, qp, fatal && qp->ext_type == EQPT_SRQ ? |
| 216 | IB_EVENT_SRQ_ERR : event_type); |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 217 | |
Joachim Fenkes | 5ff70cac | 2007-08-31 16:03:37 +0200 | [diff] [blame] | 218 | /* |
| 219 | * eHCA only processes one WQE at a time for SRQ base QPs, |
| 220 | * so the last WQE has been processed as soon as the QP enters |
| 221 | * error state. |
| 222 | */ |
| 223 | if (fatal && qp->ext_type == EQPT_SRQBASE) |
| 224 | dispatch_qp_event(shca, qp, IB_EVENT_QP_LAST_WQE_REACHED); |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 225 | |
| 226 | return; |
| 227 | } |
| 228 | |
| 229 | static void cq_event_callback(struct ehca_shca *shca, |
Hoang-Nam Nguyen | 78d8d5f | 2007-02-15 17:06:33 +0100 | [diff] [blame] | 230 | u64 eqe) |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 231 | { |
| 232 | struct ehca_cq *cq; |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 233 | u32 token = EHCA_BMASK_GET(EQE_CQ_TOKEN, eqe); |
| 234 | |
Joachim Fenkes | 26ed687 | 2007-07-09 15:31:10 +0200 | [diff] [blame] | 235 | read_lock(&ehca_cq_idr_lock); |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 236 | cq = idr_find(&ehca_cq_idr, token); |
Joachim Fenkes | 28db6be | 2007-07-09 15:30:39 +0200 | [diff] [blame] | 237 | if (cq) |
| 238 | atomic_inc(&cq->nr_events); |
Joachim Fenkes | 26ed687 | 2007-07-09 15:31:10 +0200 | [diff] [blame] | 239 | read_unlock(&ehca_cq_idr_lock); |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 240 | |
| 241 | if (!cq) |
| 242 | return; |
| 243 | |
| 244 | ehca_error_data(shca, cq, cq->ipz_cq_handle.handle); |
| 245 | |
Joachim Fenkes | 28db6be | 2007-07-09 15:30:39 +0200 | [diff] [blame] | 246 | if (atomic_dec_and_test(&cq->nr_events)) |
| 247 | wake_up(&cq->wait_completion); |
| 248 | |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 249 | return; |
| 250 | } |
| 251 | |
| 252 | static void parse_identifier(struct ehca_shca *shca, u64 eqe) |
| 253 | { |
| 254 | u8 identifier = EHCA_BMASK_GET(EQE_EE_IDENTIFIER, eqe); |
| 255 | |
| 256 | switch (identifier) { |
| 257 | case 0x02: /* path migrated */ |
Hoang-Nam Nguyen | 633a5ae | 2007-07-20 16:02:18 +0200 | [diff] [blame] | 258 | qp_event_callback(shca, eqe, IB_EVENT_PATH_MIG, 0); |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 259 | break; |
| 260 | case 0x03: /* communication established */ |
Hoang-Nam Nguyen | 633a5ae | 2007-07-20 16:02:18 +0200 | [diff] [blame] | 261 | qp_event_callback(shca, eqe, IB_EVENT_COMM_EST, 0); |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 262 | break; |
| 263 | case 0x04: /* send queue drained */ |
Hoang-Nam Nguyen | 633a5ae | 2007-07-20 16:02:18 +0200 | [diff] [blame] | 264 | qp_event_callback(shca, eqe, IB_EVENT_SQ_DRAINED, 0); |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 265 | break; |
| 266 | case 0x05: /* QP error */ |
| 267 | case 0x06: /* QP error */ |
Hoang-Nam Nguyen | 633a5ae | 2007-07-20 16:02:18 +0200 | [diff] [blame] | 268 | qp_event_callback(shca, eqe, IB_EVENT_QP_FATAL, 1); |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 269 | break; |
| 270 | case 0x07: /* CQ error */ |
| 271 | case 0x08: /* CQ error */ |
| 272 | cq_event_callback(shca, eqe); |
| 273 | break; |
| 274 | case 0x09: /* MRMWPTE error */ |
| 275 | ehca_err(&shca->ib_device, "MRMWPTE error."); |
| 276 | break; |
| 277 | case 0x0A: /* port event */ |
| 278 | ehca_err(&shca->ib_device, "Port event."); |
| 279 | break; |
| 280 | case 0x0B: /* MR access error */ |
| 281 | ehca_err(&shca->ib_device, "MR access error."); |
| 282 | break; |
| 283 | case 0x0C: /* EQ error */ |
| 284 | ehca_err(&shca->ib_device, "EQ error."); |
| 285 | break; |
| 286 | case 0x0D: /* P/Q_Key mismatch */ |
| 287 | ehca_err(&shca->ib_device, "P/Q_Key mismatch."); |
| 288 | break; |
| 289 | case 0x10: /* sampling complete */ |
| 290 | ehca_err(&shca->ib_device, "Sampling complete."); |
| 291 | break; |
| 292 | case 0x11: /* unaffiliated access error */ |
| 293 | ehca_err(&shca->ib_device, "Unaffiliated access error."); |
| 294 | break; |
Joachim Fenkes | e90d0b3 | 2007-09-11 15:34:04 +0200 | [diff] [blame] | 295 | case 0x12: /* path migrating */ |
| 296 | ehca_err(&shca->ib_device, "Path migrating."); |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 297 | break; |
| 298 | case 0x13: /* interface trace stopped */ |
| 299 | ehca_err(&shca->ib_device, "Interface trace stopped."); |
| 300 | break; |
| 301 | case 0x14: /* first error capture info available */ |
Hoang-Nam Nguyen | 633a5ae | 2007-07-20 16:02:18 +0200 | [diff] [blame] | 302 | ehca_info(&shca->ib_device, "First error capture available"); |
| 303 | break; |
| 304 | case 0x15: /* SRQ limit reached */ |
| 305 | qp_event_callback(shca, eqe, IB_EVENT_SRQ_LIMIT_REACHED, 0); |
| 306 | break; |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 307 | default: |
| 308 | ehca_err(&shca->ib_device, "Unknown identifier: %x on %s.", |
| 309 | identifier, shca->ib_device.name); |
| 310 | break; |
| 311 | } |
| 312 | |
| 313 | return; |
| 314 | } |
| 315 | |
Joachim Fenkes | 8705ce5 | 2007-07-09 15:32:22 +0200 | [diff] [blame] | 316 | static void dispatch_port_event(struct ehca_shca *shca, int port_num, |
| 317 | enum ib_event_type type, const char *msg) |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 318 | { |
| 319 | struct ib_event event; |
Joachim Fenkes | 8705ce5 | 2007-07-09 15:32:22 +0200 | [diff] [blame] | 320 | |
| 321 | ehca_info(&shca->ib_device, "port %d %s.", port_num, msg); |
| 322 | event.device = &shca->ib_device; |
| 323 | event.event = type; |
| 324 | event.element.port_num = port_num; |
| 325 | ib_dispatch_event(&event); |
| 326 | } |
| 327 | |
| 328 | static void notify_port_conf_change(struct ehca_shca *shca, int port_num) |
| 329 | { |
| 330 | struct ehca_sma_attr new_attr; |
| 331 | struct ehca_sma_attr *old_attr = &shca->sport[port_num - 1].saved_attr; |
| 332 | |
| 333 | ehca_query_sma_attr(shca, port_num, &new_attr); |
| 334 | |
| 335 | if (new_attr.sm_sl != old_attr->sm_sl || |
| 336 | new_attr.sm_lid != old_attr->sm_lid) |
| 337 | dispatch_port_event(shca, port_num, IB_EVENT_SM_CHANGE, |
| 338 | "SM changed"); |
| 339 | |
| 340 | if (new_attr.lid != old_attr->lid || |
| 341 | new_attr.lmc != old_attr->lmc) |
| 342 | dispatch_port_event(shca, port_num, IB_EVENT_LID_CHANGE, |
| 343 | "LID changed"); |
| 344 | |
| 345 | if (new_attr.pkey_tbl_len != old_attr->pkey_tbl_len || |
| 346 | memcmp(new_attr.pkeys, old_attr->pkeys, |
| 347 | sizeof(u16) * new_attr.pkey_tbl_len)) |
| 348 | dispatch_port_event(shca, port_num, IB_EVENT_PKEY_CHANGE, |
| 349 | "P_Key changed"); |
| 350 | |
| 351 | *old_attr = new_attr; |
| 352 | } |
| 353 | |
| 354 | static void parse_ec(struct ehca_shca *shca, u64 eqe) |
| 355 | { |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 356 | u8 ec = EHCA_BMASK_GET(NEQE_EVENT_CODE, eqe); |
| 357 | u8 port = EHCA_BMASK_GET(NEQE_PORT_NUMBER, eqe); |
Hoang-Nam Nguyen | e57d62a | 2007-12-20 15:06:33 +0100 | [diff] [blame] | 358 | u8 spec_event; |
Hoang-Nam Nguyen | bbdd267 | 2008-01-17 15:05:45 +0100 | [diff] [blame] | 359 | struct ehca_sport *sport = &shca->sport[port - 1]; |
| 360 | unsigned long flags; |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 361 | |
| 362 | switch (ec) { |
| 363 | case 0x30: /* port availability change */ |
| 364 | if (EHCA_BMASK_GET(NEQE_PORT_AVAILABILITY, eqe)) { |
Hoang-Nam Nguyen | bbdd267 | 2008-01-17 15:05:45 +0100 | [diff] [blame] | 365 | int suppress_event; |
| 366 | /* replay modify_qp for sqps */ |
| 367 | spin_lock_irqsave(&sport->mod_sqp_lock, flags); |
| 368 | suppress_event = !sport->ibqp_sqp[IB_QPT_GSI]; |
| 369 | if (sport->ibqp_sqp[IB_QPT_SMI]) |
| 370 | ehca_recover_sqp(sport->ibqp_sqp[IB_QPT_SMI]); |
| 371 | if (!suppress_event) |
| 372 | ehca_recover_sqp(sport->ibqp_sqp[IB_QPT_GSI]); |
| 373 | spin_unlock_irqrestore(&sport->mod_sqp_lock, flags); |
| 374 | |
| 375 | /* AQP1 was destroyed, ignore this event */ |
| 376 | if (suppress_event) |
| 377 | break; |
| 378 | |
| 379 | sport->port_state = IB_PORT_ACTIVE; |
Joachim Fenkes | 8705ce5 | 2007-07-09 15:32:22 +0200 | [diff] [blame] | 380 | dispatch_port_event(shca, port, IB_EVENT_PORT_ACTIVE, |
| 381 | "is active"); |
| 382 | ehca_query_sma_attr(shca, port, |
Hoang-Nam Nguyen | bbdd267 | 2008-01-17 15:05:45 +0100 | [diff] [blame] | 383 | &sport->saved_attr); |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 384 | } else { |
Hoang-Nam Nguyen | bbdd267 | 2008-01-17 15:05:45 +0100 | [diff] [blame] | 385 | sport->port_state = IB_PORT_DOWN; |
Joachim Fenkes | 8705ce5 | 2007-07-09 15:32:22 +0200 | [diff] [blame] | 386 | dispatch_port_event(shca, port, IB_EVENT_PORT_ERR, |
| 387 | "is inactive"); |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 388 | } |
| 389 | break; |
| 390 | case 0x31: |
| 391 | /* port configuration change |
| 392 | * disruptive change is caused by |
| 393 | * LID, PKEY or SM change |
| 394 | */ |
Joachim Fenkes | 8705ce5 | 2007-07-09 15:32:22 +0200 | [diff] [blame] | 395 | if (EHCA_BMASK_GET(NEQE_DISRUPTIVE, eqe)) { |
| 396 | ehca_warn(&shca->ib_device, "disruptive port " |
| 397 | "%d configuration change", port); |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 398 | |
Hoang-Nam Nguyen | bbdd267 | 2008-01-17 15:05:45 +0100 | [diff] [blame] | 399 | sport->port_state = IB_PORT_DOWN; |
Joachim Fenkes | 8705ce5 | 2007-07-09 15:32:22 +0200 | [diff] [blame] | 400 | dispatch_port_event(shca, port, IB_EVENT_PORT_ERR, |
| 401 | "is inactive"); |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 402 | |
Hoang-Nam Nguyen | bbdd267 | 2008-01-17 15:05:45 +0100 | [diff] [blame] | 403 | sport->port_state = IB_PORT_ACTIVE; |
Joachim Fenkes | 8705ce5 | 2007-07-09 15:32:22 +0200 | [diff] [blame] | 404 | dispatch_port_event(shca, port, IB_EVENT_PORT_ACTIVE, |
| 405 | "is active"); |
Joachim Fenkes | 528b03f7 | 2008-01-25 21:12:39 +0100 | [diff] [blame] | 406 | ehca_query_sma_attr(shca, port, |
| 407 | &sport->saved_attr); |
Joachim Fenkes | 8705ce5 | 2007-07-09 15:32:22 +0200 | [diff] [blame] | 408 | } else |
| 409 | notify_port_conf_change(shca, port); |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 410 | break; |
| 411 | case 0x32: /* adapter malfunction */ |
| 412 | ehca_err(&shca->ib_device, "Adapter malfunction."); |
| 413 | break; |
| 414 | case 0x33: /* trace stopped */ |
| 415 | ehca_err(&shca->ib_device, "Traced stopped."); |
| 416 | break; |
Hoang-Nam Nguyen | e57d62a | 2007-12-20 15:06:33 +0100 | [diff] [blame] | 417 | case 0x34: /* util async event */ |
| 418 | spec_event = EHCA_BMASK_GET(NEQE_SPECIFIC_EVENT, eqe); |
| 419 | if (spec_event == 0x80) /* client reregister required */ |
| 420 | dispatch_port_event(shca, port, |
| 421 | IB_EVENT_CLIENT_REREGISTER, |
| 422 | "client reregister req."); |
| 423 | else |
| 424 | ehca_warn(&shca->ib_device, "Unknown util async " |
| 425 | "event %x on port %x", spec_event, port); |
| 426 | break; |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 427 | default: |
| 428 | ehca_err(&shca->ib_device, "Unknown event code: %x on %s.", |
| 429 | ec, shca->ib_device.name); |
| 430 | break; |
| 431 | } |
| 432 | |
| 433 | return; |
| 434 | } |
| 435 | |
| 436 | static inline void reset_eq_pending(struct ehca_cq *cq) |
| 437 | { |
| 438 | u64 CQx_EP; |
| 439 | struct h_galpa gal = cq->galpas.kernel; |
| 440 | |
| 441 | hipz_galpa_store_cq(gal, cqx_ep, 0x0); |
| 442 | CQx_EP = hipz_galpa_load(gal, CQTEMM_OFFSET(cqx_ep)); |
| 443 | |
| 444 | return; |
| 445 | } |
| 446 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 447 | irqreturn_t ehca_interrupt_neq(int irq, void *dev_id) |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 448 | { |
| 449 | struct ehca_shca *shca = (struct ehca_shca*)dev_id; |
| 450 | |
| 451 | tasklet_hi_schedule(&shca->neq.interrupt_task); |
| 452 | |
| 453 | return IRQ_HANDLED; |
| 454 | } |
| 455 | |
| 456 | void ehca_tasklet_neq(unsigned long data) |
| 457 | { |
| 458 | struct ehca_shca *shca = (struct ehca_shca*)data; |
| 459 | struct ehca_eqe *eqe; |
| 460 | u64 ret; |
| 461 | |
| 462 | eqe = (struct ehca_eqe *)ehca_poll_eq(shca, &shca->neq); |
| 463 | |
| 464 | while (eqe) { |
| 465 | if (!EHCA_BMASK_GET(NEQE_COMPLETION_EVENT, eqe->entry)) |
| 466 | parse_ec(shca, eqe->entry); |
| 467 | |
| 468 | eqe = (struct ehca_eqe *)ehca_poll_eq(shca, &shca->neq); |
| 469 | } |
| 470 | |
| 471 | ret = hipz_h_reset_event(shca->ipz_hca_handle, |
| 472 | shca->neq.ipz_eq_handle, 0xFFFFFFFFFFFFFFFFL); |
| 473 | |
| 474 | if (ret != H_SUCCESS) |
| 475 | ehca_err(&shca->ib_device, "Can't clear notification events."); |
| 476 | |
| 477 | return; |
| 478 | } |
| 479 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 480 | irqreturn_t ehca_interrupt_eq(int irq, void *dev_id) |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 481 | { |
| 482 | struct ehca_shca *shca = (struct ehca_shca*)dev_id; |
| 483 | |
| 484 | tasklet_hi_schedule(&shca->eq.interrupt_task); |
| 485 | |
| 486 | return IRQ_HANDLED; |
| 487 | } |
| 488 | |
Hoang-Nam Nguyen | 78d8d5f | 2007-02-15 17:06:33 +0100 | [diff] [blame] | 489 | |
| 490 | static inline void process_eqe(struct ehca_shca *shca, struct ehca_eqe *eqe) |
| 491 | { |
| 492 | u64 eqe_value; |
| 493 | u32 token; |
Hoang-Nam Nguyen | 78d8d5f | 2007-02-15 17:06:33 +0100 | [diff] [blame] | 494 | struct ehca_cq *cq; |
Hoang-Nam Nguyen | 3172679 | 2007-02-28 18:01:02 +0100 | [diff] [blame] | 495 | |
Hoang-Nam Nguyen | 78d8d5f | 2007-02-15 17:06:33 +0100 | [diff] [blame] | 496 | eqe_value = eqe->entry; |
| 497 | ehca_dbg(&shca->ib_device, "eqe_value=%lx", eqe_value); |
| 498 | if (EHCA_BMASK_GET(EQE_COMPLETION_EVENT, eqe_value)) { |
Hoang-Nam Nguyen | 3172679 | 2007-02-28 18:01:02 +0100 | [diff] [blame] | 499 | ehca_dbg(&shca->ib_device, "Got completion event"); |
Hoang-Nam Nguyen | 78d8d5f | 2007-02-15 17:06:33 +0100 | [diff] [blame] | 500 | token = EHCA_BMASK_GET(EQE_CQ_TOKEN, eqe_value); |
Joachim Fenkes | 26ed687 | 2007-07-09 15:31:10 +0200 | [diff] [blame] | 501 | read_lock(&ehca_cq_idr_lock); |
Hoang-Nam Nguyen | 78d8d5f | 2007-02-15 17:06:33 +0100 | [diff] [blame] | 502 | cq = idr_find(&ehca_cq_idr, token); |
Joachim Fenkes | 28db6be | 2007-07-09 15:30:39 +0200 | [diff] [blame] | 503 | if (cq) |
| 504 | atomic_inc(&cq->nr_events); |
Joachim Fenkes | 26ed687 | 2007-07-09 15:31:10 +0200 | [diff] [blame] | 505 | read_unlock(&ehca_cq_idr_lock); |
Hoang-Nam Nguyen | 78d8d5f | 2007-02-15 17:06:33 +0100 | [diff] [blame] | 506 | if (cq == NULL) { |
Hoang-Nam Nguyen | 78d8d5f | 2007-02-15 17:06:33 +0100 | [diff] [blame] | 507 | ehca_err(&shca->ib_device, |
| 508 | "Invalid eqe for non-existing cq token=%x", |
| 509 | token); |
| 510 | return; |
| 511 | } |
| 512 | reset_eq_pending(cq); |
Hoang-Nam Nguyen | 3172679 | 2007-02-28 18:01:02 +0100 | [diff] [blame] | 513 | if (ehca_scaling_code) |
Hoang-Nam Nguyen | 4fd3006 | 2007-02-15 17:08:33 +0100 | [diff] [blame] | 514 | queue_comp_task(cq); |
Hoang-Nam Nguyen | 3172679 | 2007-02-28 18:01:02 +0100 | [diff] [blame] | 515 | else { |
Hoang-Nam Nguyen | 4fd3006 | 2007-02-15 17:08:33 +0100 | [diff] [blame] | 516 | comp_event_callback(cq); |
Joachim Fenkes | 28db6be | 2007-07-09 15:30:39 +0200 | [diff] [blame] | 517 | if (atomic_dec_and_test(&cq->nr_events)) |
Hoang-Nam Nguyen | 3172679 | 2007-02-28 18:01:02 +0100 | [diff] [blame] | 518 | wake_up(&cq->wait_completion); |
Hoang-Nam Nguyen | 4fd3006 | 2007-02-15 17:08:33 +0100 | [diff] [blame] | 519 | } |
Hoang-Nam Nguyen | 78d8d5f | 2007-02-15 17:06:33 +0100 | [diff] [blame] | 520 | } else { |
Hoang-Nam Nguyen | 3172679 | 2007-02-28 18:01:02 +0100 | [diff] [blame] | 521 | ehca_dbg(&shca->ib_device, "Got non completion event"); |
Hoang-Nam Nguyen | 78d8d5f | 2007-02-15 17:06:33 +0100 | [diff] [blame] | 522 | parse_identifier(shca, eqe_value); |
| 523 | } |
| 524 | } |
| 525 | |
| 526 | void ehca_process_eq(struct ehca_shca *shca, int is_irq) |
| 527 | { |
| 528 | struct ehca_eq *eq = &shca->eq; |
| 529 | struct ehca_eqe_cache_entry *eqe_cache = eq->eqe_cache; |
| 530 | u64 eqe_value; |
| 531 | unsigned long flags; |
| 532 | int eqe_cnt, i; |
| 533 | int eq_empty = 0; |
| 534 | |
| 535 | spin_lock_irqsave(&eq->irq_spinlock, flags); |
| 536 | if (is_irq) { |
| 537 | const int max_query_cnt = 100; |
| 538 | int query_cnt = 0; |
| 539 | int int_state = 1; |
| 540 | do { |
| 541 | int_state = hipz_h_query_int_state( |
| 542 | shca->ipz_hca_handle, eq->ist); |
| 543 | query_cnt++; |
| 544 | iosync(); |
| 545 | } while (int_state && query_cnt < max_query_cnt); |
| 546 | if (unlikely((query_cnt == max_query_cnt))) |
| 547 | ehca_dbg(&shca->ib_device, "int_state=%x query_cnt=%x", |
| 548 | int_state, query_cnt); |
| 549 | } |
| 550 | |
| 551 | /* read out all eqes */ |
| 552 | eqe_cnt = 0; |
| 553 | do { |
| 554 | u32 token; |
| 555 | eqe_cache[eqe_cnt].eqe = |
| 556 | (struct ehca_eqe *)ehca_poll_eq(shca, eq); |
| 557 | if (!eqe_cache[eqe_cnt].eqe) |
| 558 | break; |
| 559 | eqe_value = eqe_cache[eqe_cnt].eqe->entry; |
| 560 | if (EHCA_BMASK_GET(EQE_COMPLETION_EVENT, eqe_value)) { |
| 561 | token = EHCA_BMASK_GET(EQE_CQ_TOKEN, eqe_value); |
Joachim Fenkes | 26ed687 | 2007-07-09 15:31:10 +0200 | [diff] [blame] | 562 | read_lock(&ehca_cq_idr_lock); |
Hoang-Nam Nguyen | 78d8d5f | 2007-02-15 17:06:33 +0100 | [diff] [blame] | 563 | eqe_cache[eqe_cnt].cq = idr_find(&ehca_cq_idr, token); |
Joachim Fenkes | 28db6be | 2007-07-09 15:30:39 +0200 | [diff] [blame] | 564 | if (eqe_cache[eqe_cnt].cq) |
| 565 | atomic_inc(&eqe_cache[eqe_cnt].cq->nr_events); |
Joachim Fenkes | 26ed687 | 2007-07-09 15:31:10 +0200 | [diff] [blame] | 566 | read_unlock(&ehca_cq_idr_lock); |
Hoang-Nam Nguyen | 78d8d5f | 2007-02-15 17:06:33 +0100 | [diff] [blame] | 567 | if (!eqe_cache[eqe_cnt].cq) { |
Hoang-Nam Nguyen | 78d8d5f | 2007-02-15 17:06:33 +0100 | [diff] [blame] | 568 | ehca_err(&shca->ib_device, |
| 569 | "Invalid eqe for non-existing cq " |
| 570 | "token=%x", token); |
| 571 | continue; |
| 572 | } |
Hoang-Nam Nguyen | 78d8d5f | 2007-02-15 17:06:33 +0100 | [diff] [blame] | 573 | } else |
| 574 | eqe_cache[eqe_cnt].cq = NULL; |
| 575 | eqe_cnt++; |
| 576 | } while (eqe_cnt < EHCA_EQE_CACHE_SIZE); |
| 577 | if (!eqe_cnt) { |
| 578 | if (is_irq) |
| 579 | ehca_dbg(&shca->ib_device, |
| 580 | "No eqe found for irq event"); |
| 581 | goto unlock_irq_spinlock; |
| 582 | } else if (!is_irq) |
| 583 | ehca_dbg(&shca->ib_device, "deadman found %x eqe", eqe_cnt); |
| 584 | if (unlikely(eqe_cnt == EHCA_EQE_CACHE_SIZE)) |
| 585 | ehca_dbg(&shca->ib_device, "too many eqes for one irq event"); |
| 586 | /* enable irq for new packets */ |
| 587 | for (i = 0; i < eqe_cnt; i++) { |
| 588 | if (eq->eqe_cache[i].cq) |
| 589 | reset_eq_pending(eq->eqe_cache[i].cq); |
| 590 | } |
| 591 | /* check eq */ |
| 592 | spin_lock(&eq->spinlock); |
| 593 | eq_empty = (!ipz_eqit_eq_peek_valid(&shca->eq.ipz_queue)); |
| 594 | spin_unlock(&eq->spinlock); |
| 595 | /* call completion handler for cached eqes */ |
| 596 | for (i = 0; i < eqe_cnt; i++) |
| 597 | if (eq->eqe_cache[i].cq) { |
Hoang-Nam Nguyen | 3172679 | 2007-02-28 18:01:02 +0100 | [diff] [blame] | 598 | if (ehca_scaling_code) |
Hoang-Nam Nguyen | 4fd3006 | 2007-02-15 17:08:33 +0100 | [diff] [blame] | 599 | queue_comp_task(eq->eqe_cache[i].cq); |
Hoang-Nam Nguyen | 3172679 | 2007-02-28 18:01:02 +0100 | [diff] [blame] | 600 | else { |
| 601 | struct ehca_cq *cq = eq->eqe_cache[i].cq; |
| 602 | comp_event_callback(cq); |
Joachim Fenkes | 28db6be | 2007-07-09 15:30:39 +0200 | [diff] [blame] | 603 | if (atomic_dec_and_test(&cq->nr_events)) |
Hoang-Nam Nguyen | 3172679 | 2007-02-28 18:01:02 +0100 | [diff] [blame] | 604 | wake_up(&cq->wait_completion); |
Hoang-Nam Nguyen | 3172679 | 2007-02-28 18:01:02 +0100 | [diff] [blame] | 605 | } |
Hoang-Nam Nguyen | 78d8d5f | 2007-02-15 17:06:33 +0100 | [diff] [blame] | 606 | } else { |
| 607 | ehca_dbg(&shca->ib_device, "Got non completion event"); |
| 608 | parse_identifier(shca, eq->eqe_cache[i].eqe->entry); |
| 609 | } |
| 610 | /* poll eq if not empty */ |
| 611 | if (eq_empty) |
| 612 | goto unlock_irq_spinlock; |
| 613 | do { |
| 614 | struct ehca_eqe *eqe; |
| 615 | eqe = (struct ehca_eqe *)ehca_poll_eq(shca, &shca->eq); |
| 616 | if (!eqe) |
| 617 | break; |
| 618 | process_eqe(shca, eqe); |
Hoang-Nam Nguyen | 78d8d5f | 2007-02-15 17:06:33 +0100 | [diff] [blame] | 619 | } while (1); |
| 620 | |
| 621 | unlock_irq_spinlock: |
| 622 | spin_unlock_irqrestore(&eq->irq_spinlock, flags); |
| 623 | } |
| 624 | |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 625 | void ehca_tasklet_eq(unsigned long data) |
| 626 | { |
Hoang-Nam Nguyen | 78d8d5f | 2007-02-15 17:06:33 +0100 | [diff] [blame] | 627 | ehca_process_eq((struct ehca_shca*)data, 1); |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 628 | } |
| 629 | |
Hoang-Nam Nguyen | 2b94397 | 2007-07-12 17:53:47 +0200 | [diff] [blame] | 630 | static inline int find_next_online_cpu(struct ehca_comp_pool *pool) |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 631 | { |
Hoang-Nam Nguyen | 8b16cef | 2007-02-15 17:07:30 +0100 | [diff] [blame] | 632 | int cpu; |
| 633 | unsigned long flags; |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 634 | |
Hoang-Nam Nguyen | 8b16cef | 2007-02-15 17:07:30 +0100 | [diff] [blame] | 635 | WARN_ON_ONCE(!in_interrupt()); |
Joachim Fenkes | 4da27d6 | 2008-04-23 11:55:45 -0700 | [diff] [blame^] | 636 | if (ehca_debug_level >= 3) |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 637 | ehca_dmp(&cpu_online_map, sizeof(cpumask_t), ""); |
| 638 | |
Hoang-Nam Nguyen | 8b16cef | 2007-02-15 17:07:30 +0100 | [diff] [blame] | 639 | spin_lock_irqsave(&pool->last_cpu_lock, flags); |
| 640 | cpu = next_cpu(pool->last_cpu, cpu_online_map); |
| 641 | if (cpu == NR_CPUS) |
| 642 | cpu = first_cpu(cpu_online_map); |
| 643 | pool->last_cpu = cpu; |
| 644 | spin_unlock_irqrestore(&pool->last_cpu_lock, flags); |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 645 | |
Hoang-Nam Nguyen | 8b16cef | 2007-02-15 17:07:30 +0100 | [diff] [blame] | 646 | return cpu; |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 647 | } |
| 648 | |
| 649 | static void __queue_comp_task(struct ehca_cq *__cq, |
| 650 | struct ehca_cpu_comp_task *cct) |
| 651 | { |
Hoang-Nam Nguyen | 8b16cef | 2007-02-15 17:07:30 +0100 | [diff] [blame] | 652 | unsigned long flags; |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 653 | |
Hoang-Nam Nguyen | 8b16cef | 2007-02-15 17:07:30 +0100 | [diff] [blame] | 654 | spin_lock_irqsave(&cct->task_lock, flags); |
| 655 | spin_lock(&__cq->task_lock); |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 656 | |
| 657 | if (__cq->nr_callbacks == 0) { |
| 658 | __cq->nr_callbacks++; |
| 659 | list_add_tail(&__cq->entry, &cct->cq_list); |
| 660 | cct->cq_jobs++; |
| 661 | wake_up(&cct->wait_queue); |
Hoang-Nam Nguyen | 3172679 | 2007-02-28 18:01:02 +0100 | [diff] [blame] | 662 | } else |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 663 | __cq->nr_callbacks++; |
| 664 | |
Hoang-Nam Nguyen | 8b16cef | 2007-02-15 17:07:30 +0100 | [diff] [blame] | 665 | spin_unlock(&__cq->task_lock); |
| 666 | spin_unlock_irqrestore(&cct->task_lock, flags); |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 667 | } |
| 668 | |
| 669 | static void queue_comp_task(struct ehca_cq *__cq) |
| 670 | { |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 671 | int cpu_id; |
| 672 | struct ehca_cpu_comp_task *cct; |
Hoang-Nam Nguyen | 3172679 | 2007-02-28 18:01:02 +0100 | [diff] [blame] | 673 | int cq_jobs; |
| 674 | unsigned long flags; |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 675 | |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 676 | cpu_id = find_next_online_cpu(pool); |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 677 | BUG_ON(!cpu_online(cpu_id)); |
| 678 | |
| 679 | cct = per_cpu_ptr(pool->cpu_comp_tasks, cpu_id); |
Hoang-Nam Nguyen | 8b16cef | 2007-02-15 17:07:30 +0100 | [diff] [blame] | 680 | BUG_ON(!cct); |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 681 | |
Hoang-Nam Nguyen | 3172679 | 2007-02-28 18:01:02 +0100 | [diff] [blame] | 682 | spin_lock_irqsave(&cct->task_lock, flags); |
| 683 | cq_jobs = cct->cq_jobs; |
| 684 | spin_unlock_irqrestore(&cct->task_lock, flags); |
| 685 | if (cq_jobs > 0) { |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 686 | cpu_id = find_next_online_cpu(pool); |
| 687 | cct = per_cpu_ptr(pool->cpu_comp_tasks, cpu_id); |
Hoang-Nam Nguyen | 8b16cef | 2007-02-15 17:07:30 +0100 | [diff] [blame] | 688 | BUG_ON(!cct); |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 689 | } |
| 690 | |
| 691 | __queue_comp_task(__cq, cct); |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 692 | } |
| 693 | |
Hoang-Nam Nguyen | 2b94397 | 2007-07-12 17:53:47 +0200 | [diff] [blame] | 694 | static void run_comp_task(struct ehca_cpu_comp_task *cct) |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 695 | { |
| 696 | struct ehca_cq *cq; |
Hoang-Nam Nguyen | 8b16cef | 2007-02-15 17:07:30 +0100 | [diff] [blame] | 697 | unsigned long flags; |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 698 | |
Hoang-Nam Nguyen | 8b16cef | 2007-02-15 17:07:30 +0100 | [diff] [blame] | 699 | spin_lock_irqsave(&cct->task_lock, flags); |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 700 | |
| 701 | while (!list_empty(&cct->cq_list)) { |
| 702 | cq = list_entry(cct->cq_list.next, struct ehca_cq, entry); |
Hoang-Nam Nguyen | 8b16cef | 2007-02-15 17:07:30 +0100 | [diff] [blame] | 703 | spin_unlock_irqrestore(&cct->task_lock, flags); |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 704 | |
Joachim Fenkes | 28db6be | 2007-07-09 15:30:39 +0200 | [diff] [blame] | 705 | comp_event_callback(cq); |
| 706 | if (atomic_dec_and_test(&cq->nr_events)) |
Hoang-Nam Nguyen | 3172679 | 2007-02-28 18:01:02 +0100 | [diff] [blame] | 707 | wake_up(&cq->wait_completion); |
Hoang-Nam Nguyen | 3172679 | 2007-02-28 18:01:02 +0100 | [diff] [blame] | 708 | |
| 709 | spin_lock_irqsave(&cct->task_lock, flags); |
Hoang-Nam Nguyen | 8b16cef | 2007-02-15 17:07:30 +0100 | [diff] [blame] | 710 | spin_lock(&cq->task_lock); |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 711 | cq->nr_callbacks--; |
Hoang-Nam Nguyen | 3172679 | 2007-02-28 18:01:02 +0100 | [diff] [blame] | 712 | if (!cq->nr_callbacks) { |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 713 | list_del_init(cct->cq_list.next); |
| 714 | cct->cq_jobs--; |
| 715 | } |
Hoang-Nam Nguyen | 8b16cef | 2007-02-15 17:07:30 +0100 | [diff] [blame] | 716 | spin_unlock(&cq->task_lock); |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 717 | } |
| 718 | |
Hoang-Nam Nguyen | 8b16cef | 2007-02-15 17:07:30 +0100 | [diff] [blame] | 719 | spin_unlock_irqrestore(&cct->task_lock, flags); |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 720 | } |
| 721 | |
| 722 | static int comp_task(void *__cct) |
| 723 | { |
Hoang-Nam Nguyen | 2b94397 | 2007-07-12 17:53:47 +0200 | [diff] [blame] | 724 | struct ehca_cpu_comp_task *cct = __cct; |
Hoang-Nam Nguyen | 8b16cef | 2007-02-15 17:07:30 +0100 | [diff] [blame] | 725 | int cql_empty; |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 726 | DECLARE_WAITQUEUE(wait, current); |
| 727 | |
| 728 | set_current_state(TASK_INTERRUPTIBLE); |
Hoang-Nam Nguyen | 2b94397 | 2007-07-12 17:53:47 +0200 | [diff] [blame] | 729 | while (!kthread_should_stop()) { |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 730 | add_wait_queue(&cct->wait_queue, &wait); |
| 731 | |
Hoang-Nam Nguyen | 8b16cef | 2007-02-15 17:07:30 +0100 | [diff] [blame] | 732 | spin_lock_irq(&cct->task_lock); |
| 733 | cql_empty = list_empty(&cct->cq_list); |
| 734 | spin_unlock_irq(&cct->task_lock); |
| 735 | if (cql_empty) |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 736 | schedule(); |
| 737 | else |
| 738 | __set_current_state(TASK_RUNNING); |
| 739 | |
| 740 | remove_wait_queue(&cct->wait_queue, &wait); |
| 741 | |
Hoang-Nam Nguyen | 8b16cef | 2007-02-15 17:07:30 +0100 | [diff] [blame] | 742 | spin_lock_irq(&cct->task_lock); |
| 743 | cql_empty = list_empty(&cct->cq_list); |
| 744 | spin_unlock_irq(&cct->task_lock); |
| 745 | if (!cql_empty) |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 746 | run_comp_task(__cct); |
| 747 | |
| 748 | set_current_state(TASK_INTERRUPTIBLE); |
| 749 | } |
| 750 | __set_current_state(TASK_RUNNING); |
| 751 | |
| 752 | return 0; |
| 753 | } |
| 754 | |
| 755 | static struct task_struct *create_comp_task(struct ehca_comp_pool *pool, |
| 756 | int cpu) |
| 757 | { |
| 758 | struct ehca_cpu_comp_task *cct; |
| 759 | |
| 760 | cct = per_cpu_ptr(pool->cpu_comp_tasks, cpu); |
| 761 | spin_lock_init(&cct->task_lock); |
| 762 | INIT_LIST_HEAD(&cct->cq_list); |
| 763 | init_waitqueue_head(&cct->wait_queue); |
| 764 | cct->task = kthread_create(comp_task, cct, "ehca_comp/%d", cpu); |
| 765 | |
| 766 | return cct->task; |
| 767 | } |
| 768 | |
| 769 | static void destroy_comp_task(struct ehca_comp_pool *pool, |
| 770 | int cpu) |
| 771 | { |
| 772 | struct ehca_cpu_comp_task *cct; |
| 773 | struct task_struct *task; |
| 774 | unsigned long flags_cct; |
| 775 | |
| 776 | cct = per_cpu_ptr(pool->cpu_comp_tasks, cpu); |
| 777 | |
| 778 | spin_lock_irqsave(&cct->task_lock, flags_cct); |
| 779 | |
| 780 | task = cct->task; |
| 781 | cct->task = NULL; |
| 782 | cct->cq_jobs = 0; |
| 783 | |
| 784 | spin_unlock_irqrestore(&cct->task_lock, flags_cct); |
| 785 | |
| 786 | if (task) |
| 787 | kthread_stop(task); |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 788 | } |
| 789 | |
Satyam Sharma | 9faa559 | 2007-08-23 04:58:30 +0530 | [diff] [blame] | 790 | static void __cpuinit take_over_work(struct ehca_comp_pool *pool, int cpu) |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 791 | { |
| 792 | struct ehca_cpu_comp_task *cct = per_cpu_ptr(pool->cpu_comp_tasks, cpu); |
| 793 | LIST_HEAD(list); |
| 794 | struct ehca_cq *cq; |
| 795 | unsigned long flags_cct; |
| 796 | |
| 797 | spin_lock_irqsave(&cct->task_lock, flags_cct); |
| 798 | |
| 799 | list_splice_init(&cct->cq_list, &list); |
| 800 | |
Hoang-Nam Nguyen | 2b94397 | 2007-07-12 17:53:47 +0200 | [diff] [blame] | 801 | while (!list_empty(&list)) { |
Hoang-Nam Nguyen | 78d8d5f | 2007-02-15 17:06:33 +0100 | [diff] [blame] | 802 | cq = list_entry(cct->cq_list.next, struct ehca_cq, entry); |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 803 | |
Hoang-Nam Nguyen | 78d8d5f | 2007-02-15 17:06:33 +0100 | [diff] [blame] | 804 | list_del(&cq->entry); |
| 805 | __queue_comp_task(cq, per_cpu_ptr(pool->cpu_comp_tasks, |
| 806 | smp_processor_id())); |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 807 | } |
| 808 | |
| 809 | spin_unlock_irqrestore(&cct->task_lock, flags_cct); |
| 810 | |
| 811 | } |
| 812 | |
Satyam Sharma | 9faa559 | 2007-08-23 04:58:30 +0530 | [diff] [blame] | 813 | static int __cpuinit comp_pool_callback(struct notifier_block *nfb, |
| 814 | unsigned long action, |
| 815 | void *hcpu) |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 816 | { |
| 817 | unsigned int cpu = (unsigned long)hcpu; |
| 818 | struct ehca_cpu_comp_task *cct; |
| 819 | |
| 820 | switch (action) { |
| 821 | case CPU_UP_PREPARE: |
Rafael J. Wysocki | 8bb7844 | 2007-05-09 02:35:10 -0700 | [diff] [blame] | 822 | case CPU_UP_PREPARE_FROZEN: |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 823 | ehca_gen_dbg("CPU: %x (CPU_PREPARE)", cpu); |
Hoang-Nam Nguyen | 2b94397 | 2007-07-12 17:53:47 +0200 | [diff] [blame] | 824 | if (!create_comp_task(pool, cpu)) { |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 825 | ehca_gen_err("Can't create comp_task for cpu: %x", cpu); |
| 826 | return NOTIFY_BAD; |
| 827 | } |
| 828 | break; |
| 829 | case CPU_UP_CANCELED: |
Rafael J. Wysocki | 8bb7844 | 2007-05-09 02:35:10 -0700 | [diff] [blame] | 830 | case CPU_UP_CANCELED_FROZEN: |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 831 | ehca_gen_dbg("CPU: %x (CPU_CANCELED)", cpu); |
| 832 | cct = per_cpu_ptr(pool->cpu_comp_tasks, cpu); |
| 833 | kthread_bind(cct->task, any_online_cpu(cpu_online_map)); |
| 834 | destroy_comp_task(pool, cpu); |
| 835 | break; |
| 836 | case CPU_ONLINE: |
Rafael J. Wysocki | 8bb7844 | 2007-05-09 02:35:10 -0700 | [diff] [blame] | 837 | case CPU_ONLINE_FROZEN: |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 838 | ehca_gen_dbg("CPU: %x (CPU_ONLINE)", cpu); |
| 839 | cct = per_cpu_ptr(pool->cpu_comp_tasks, cpu); |
| 840 | kthread_bind(cct->task, cpu); |
| 841 | wake_up_process(cct->task); |
| 842 | break; |
| 843 | case CPU_DOWN_PREPARE: |
Rafael J. Wysocki | 8bb7844 | 2007-05-09 02:35:10 -0700 | [diff] [blame] | 844 | case CPU_DOWN_PREPARE_FROZEN: |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 845 | ehca_gen_dbg("CPU: %x (CPU_DOWN_PREPARE)", cpu); |
| 846 | break; |
| 847 | case CPU_DOWN_FAILED: |
Rafael J. Wysocki | 8bb7844 | 2007-05-09 02:35:10 -0700 | [diff] [blame] | 848 | case CPU_DOWN_FAILED_FROZEN: |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 849 | ehca_gen_dbg("CPU: %x (CPU_DOWN_FAILED)", cpu); |
| 850 | break; |
| 851 | case CPU_DEAD: |
Rafael J. Wysocki | 8bb7844 | 2007-05-09 02:35:10 -0700 | [diff] [blame] | 852 | case CPU_DEAD_FROZEN: |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 853 | ehca_gen_dbg("CPU: %x (CPU_DEAD)", cpu); |
| 854 | destroy_comp_task(pool, cpu); |
| 855 | take_over_work(pool, cpu); |
| 856 | break; |
| 857 | } |
| 858 | |
| 859 | return NOTIFY_OK; |
| 860 | } |
Satyam Sharma | 9faa559 | 2007-08-23 04:58:30 +0530 | [diff] [blame] | 861 | |
| 862 | static struct notifier_block comp_pool_callback_nb __cpuinitdata = { |
| 863 | .notifier_call = comp_pool_callback, |
| 864 | .priority = 0, |
| 865 | }; |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 866 | |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 867 | int ehca_create_comp_pool(void) |
| 868 | { |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 869 | int cpu; |
| 870 | struct task_struct *task; |
| 871 | |
Hoang-Nam Nguyen | 4fd3006 | 2007-02-15 17:08:33 +0100 | [diff] [blame] | 872 | if (!ehca_scaling_code) |
| 873 | return 0; |
| 874 | |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 875 | pool = kzalloc(sizeof(struct ehca_comp_pool), GFP_KERNEL); |
| 876 | if (pool == NULL) |
| 877 | return -ENOMEM; |
| 878 | |
| 879 | spin_lock_init(&pool->last_cpu_lock); |
| 880 | pool->last_cpu = any_online_cpu(cpu_online_map); |
| 881 | |
| 882 | pool->cpu_comp_tasks = alloc_percpu(struct ehca_cpu_comp_task); |
| 883 | if (pool->cpu_comp_tasks == NULL) { |
| 884 | kfree(pool); |
| 885 | return -EINVAL; |
| 886 | } |
| 887 | |
| 888 | for_each_online_cpu(cpu) { |
| 889 | task = create_comp_task(pool, cpu); |
| 890 | if (task) { |
| 891 | kthread_bind(task, cpu); |
| 892 | wake_up_process(task); |
| 893 | } |
| 894 | } |
| 895 | |
Satyam Sharma | 9faa559 | 2007-08-23 04:58:30 +0530 | [diff] [blame] | 896 | register_hotcpu_notifier(&comp_pool_callback_nb); |
Hoang-Nam Nguyen | 4fd3006 | 2007-02-15 17:08:33 +0100 | [diff] [blame] | 897 | |
| 898 | printk(KERN_INFO "eHCA scaling code enabled\n"); |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 899 | |
| 900 | return 0; |
| 901 | } |
| 902 | |
| 903 | void ehca_destroy_comp_pool(void) |
| 904 | { |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 905 | int i; |
| 906 | |
Hoang-Nam Nguyen | 4fd3006 | 2007-02-15 17:08:33 +0100 | [diff] [blame] | 907 | if (!ehca_scaling_code) |
| 908 | return; |
| 909 | |
Satyam Sharma | 9faa559 | 2007-08-23 04:58:30 +0530 | [diff] [blame] | 910 | unregister_hotcpu_notifier(&comp_pool_callback_nb); |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 911 | |
| 912 | for (i = 0; i < NR_CPUS; i++) { |
| 913 | if (cpu_online(i)) |
| 914 | destroy_comp_task(pool, i); |
| 915 | } |
Akinobu Mita | 65e5c02 | 2007-02-05 16:21:09 -0800 | [diff] [blame] | 916 | free_percpu(pool->cpu_comp_tasks); |
| 917 | kfree(pool); |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 918 | } |