]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blob - drivers/infiniband/hw/ehca/ehca_irq.c
IB/ehca: Use proper GFP_ flags for get_zeroed_page()
[linux-2.6-omap-h63xx.git] / drivers / infiniband / hw / ehca / ehca_irq.c
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>
8  *
9  *  Copyright (c) 2005 IBM Corporation
10  *
11  *  All rights reserved.
12  *
13  *  This source code is distributed under a dual license of GPL v2.0 and OpenIB
14  *  BSD.
15  *
16  * OpenIB BSD License
17  *
18  * Redistribution and use in source and binary forms, with or without
19  * modification, are permitted provided that the following conditions are met:
20  *
21  * Redistributions of source code must retain the above copyright notice, this
22  * list of conditions and the following disclaimer.
23  *
24  * Redistributions in binary form must reproduce the above copyright notice,
25  * this list of conditions and the following disclaimer in the documentation
26  * and/or other materials
27  * provided with the distribution.
28  *
29  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
30  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
31  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
32  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
33  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
34  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
35  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
36  * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
37  * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
38  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
39  * POSSIBILITY OF SUCH DAMAGE.
40  */
41
42 #include "ehca_classes.h"
43 #include "ehca_irq.h"
44 #include "ehca_iverbs.h"
45 #include "ehca_tools.h"
46 #include "hcp_if.h"
47 #include "hipz_fns.h"
48 #include "ipz_pt_fn.h"
49
50 #define EQE_COMPLETION_EVENT   EHCA_BMASK_IBM(1,1)
51 #define EQE_CQ_QP_NUMBER       EHCA_BMASK_IBM(8,31)
52 #define EQE_EE_IDENTIFIER      EHCA_BMASK_IBM(2,7)
53 #define EQE_CQ_NUMBER          EHCA_BMASK_IBM(8,31)
54 #define EQE_QP_NUMBER          EHCA_BMASK_IBM(8,31)
55 #define EQE_QP_TOKEN           EHCA_BMASK_IBM(32,63)
56 #define EQE_CQ_TOKEN           EHCA_BMASK_IBM(32,63)
57
58 #define NEQE_COMPLETION_EVENT  EHCA_BMASK_IBM(1,1)
59 #define NEQE_EVENT_CODE        EHCA_BMASK_IBM(2,7)
60 #define NEQE_PORT_NUMBER       EHCA_BMASK_IBM(8,15)
61 #define NEQE_PORT_AVAILABILITY EHCA_BMASK_IBM(16,16)
62
63 #define ERROR_DATA_LENGTH      EHCA_BMASK_IBM(52,63)
64 #define ERROR_DATA_TYPE        EHCA_BMASK_IBM(0,7)
65
66 #ifdef CONFIG_INFINIBAND_EHCA_SCALING
67
68 static void queue_comp_task(struct ehca_cq *__cq);
69
70 static struct ehca_comp_pool* pool;
71 static struct notifier_block comp_pool_callback_nb;
72
73 #endif
74
75 static inline void comp_event_callback(struct ehca_cq *cq)
76 {
77         if (!cq->ib_cq.comp_handler)
78                 return;
79
80         spin_lock(&cq->cb_lock);
81         cq->ib_cq.comp_handler(&cq->ib_cq, cq->ib_cq.cq_context);
82         spin_unlock(&cq->cb_lock);
83
84         return;
85 }
86
87 static void print_error_data(struct ehca_shca * shca, void* data,
88                              u64* rblock, int length)
89 {
90         u64 type = EHCA_BMASK_GET(ERROR_DATA_TYPE, rblock[2]);
91         u64 resource = rblock[1];
92
93         switch (type) {
94         case 0x1: /* Queue Pair */
95         {
96                 struct ehca_qp *qp = (struct ehca_qp*)data;
97
98                 /* only print error data if AER is set */
99                 if (rblock[6] == 0)
100                         return;
101
102                 ehca_err(&shca->ib_device,
103                          "QP 0x%x (resource=%lx) has errors.",
104                          qp->ib_qp.qp_num, resource);
105                 break;
106         }
107         case 0x4: /* Completion Queue */
108         {
109                 struct ehca_cq *cq = (struct ehca_cq*)data;
110
111                 ehca_err(&shca->ib_device,
112                          "CQ 0x%x (resource=%lx) has errors.",
113                          cq->cq_number, resource);
114                 break;
115         }
116         default:
117                 ehca_err(&shca->ib_device,
118                          "Unknown errror type: %lx on %s.",
119                          type, shca->ib_device.name);
120                 break;
121         }
122
123         ehca_err(&shca->ib_device, "Error data is available: %lx.", resource);
124         ehca_err(&shca->ib_device, "EHCA ----- error data begin "
125                  "---------------------------------------------------");
126         ehca_dmp(rblock, length, "resource=%lx", resource);
127         ehca_err(&shca->ib_device, "EHCA ----- error data end "
128                  "----------------------------------------------------");
129
130         return;
131 }
132
133 int ehca_error_data(struct ehca_shca *shca, void *data,
134                     u64 resource)
135 {
136
137         unsigned long ret;
138         u64 *rblock;
139         unsigned long block_count;
140
141         rblock = ehca_alloc_fw_ctrlblock(GFP_ATOMIC);
142         if (!rblock) {
143                 ehca_err(&shca->ib_device, "Cannot allocate rblock memory.");
144                 ret = -ENOMEM;
145                 goto error_data1;
146         }
147
148         /* rblock must be 4K aligned and should be 4K large */
149         ret = hipz_h_error_data(shca->ipz_hca_handle,
150                                 resource,
151                                 rblock,
152                                 &block_count);
153
154         if (ret == H_R_STATE)
155                 ehca_err(&shca->ib_device,
156                          "No error data is available: %lx.", resource);
157         else if (ret == H_SUCCESS) {
158                 int length;
159
160                 length = EHCA_BMASK_GET(ERROR_DATA_LENGTH, rblock[0]);
161
162                 if (length > EHCA_PAGESIZE)
163                         length = EHCA_PAGESIZE;
164
165                 print_error_data(shca, data, rblock, length);
166         } else
167                 ehca_err(&shca->ib_device,
168                          "Error data could not be fetched: %lx", resource);
169
170         ehca_free_fw_ctrlblock(rblock);
171
172 error_data1:
173         return ret;
174
175 }
176
177 static void qp_event_callback(struct ehca_shca *shca,
178                               u64 eqe,
179                               enum ib_event_type event_type)
180 {
181         struct ib_event event;
182         struct ehca_qp *qp;
183         unsigned long flags;
184         u32 token = EHCA_BMASK_GET(EQE_QP_TOKEN, eqe);
185
186         spin_lock_irqsave(&ehca_qp_idr_lock, flags);
187         qp = idr_find(&ehca_qp_idr, token);
188         spin_unlock_irqrestore(&ehca_qp_idr_lock, flags);
189
190
191         if (!qp)
192                 return;
193
194         ehca_error_data(shca, qp, qp->ipz_qp_handle.handle);
195
196         if (!qp->ib_qp.event_handler)
197                 return;
198
199         event.device     = &shca->ib_device;
200         event.event      = event_type;
201         event.element.qp = &qp->ib_qp;
202
203         qp->ib_qp.event_handler(&event, qp->ib_qp.qp_context);
204
205         return;
206 }
207
208 static void cq_event_callback(struct ehca_shca *shca,
209                                           u64 eqe)
210 {
211         struct ehca_cq *cq;
212         unsigned long flags;
213         u32 token = EHCA_BMASK_GET(EQE_CQ_TOKEN, eqe);
214
215         spin_lock_irqsave(&ehca_cq_idr_lock, flags);
216         cq = idr_find(&ehca_cq_idr, token);
217         spin_unlock_irqrestore(&ehca_cq_idr_lock, flags);
218
219         if (!cq)
220                 return;
221
222         ehca_error_data(shca, cq, cq->ipz_cq_handle.handle);
223
224         return;
225 }
226
227 static void parse_identifier(struct ehca_shca *shca, u64 eqe)
228 {
229         u8 identifier = EHCA_BMASK_GET(EQE_EE_IDENTIFIER, eqe);
230
231         switch (identifier) {
232         case 0x02: /* path migrated */
233                 qp_event_callback(shca, eqe, IB_EVENT_PATH_MIG);
234                 break;
235         case 0x03: /* communication established */
236                 qp_event_callback(shca, eqe, IB_EVENT_COMM_EST);
237                 break;
238         case 0x04: /* send queue drained */
239                 qp_event_callback(shca, eqe, IB_EVENT_SQ_DRAINED);
240                 break;
241         case 0x05: /* QP error */
242         case 0x06: /* QP error */
243                 qp_event_callback(shca, eqe, IB_EVENT_QP_FATAL);
244                 break;
245         case 0x07: /* CQ error */
246         case 0x08: /* CQ error */
247                 cq_event_callback(shca, eqe);
248                 break;
249         case 0x09: /* MRMWPTE error */
250                 ehca_err(&shca->ib_device, "MRMWPTE error.");
251                 break;
252         case 0x0A: /* port event */
253                 ehca_err(&shca->ib_device, "Port event.");
254                 break;
255         case 0x0B: /* MR access error */
256                 ehca_err(&shca->ib_device, "MR access error.");
257                 break;
258         case 0x0C: /* EQ error */
259                 ehca_err(&shca->ib_device, "EQ error.");
260                 break;
261         case 0x0D: /* P/Q_Key mismatch */
262                 ehca_err(&shca->ib_device, "P/Q_Key mismatch.");
263                 break;
264         case 0x10: /* sampling complete */
265                 ehca_err(&shca->ib_device, "Sampling complete.");
266                 break;
267         case 0x11: /* unaffiliated access error */
268                 ehca_err(&shca->ib_device, "Unaffiliated access error.");
269                 break;
270         case 0x12: /* path migrating error */
271                 ehca_err(&shca->ib_device, "Path migration error.");
272                 break;
273         case 0x13: /* interface trace stopped */
274                 ehca_err(&shca->ib_device, "Interface trace stopped.");
275                 break;
276         case 0x14: /* first error capture info available */
277         default:
278                 ehca_err(&shca->ib_device, "Unknown identifier: %x on %s.",
279                          identifier, shca->ib_device.name);
280                 break;
281         }
282
283         return;
284 }
285
286 static void parse_ec(struct ehca_shca *shca, u64 eqe)
287 {
288         struct ib_event event;
289         u8 ec   = EHCA_BMASK_GET(NEQE_EVENT_CODE, eqe);
290         u8 port = EHCA_BMASK_GET(NEQE_PORT_NUMBER, eqe);
291
292         switch (ec) {
293         case 0x30: /* port availability change */
294                 if (EHCA_BMASK_GET(NEQE_PORT_AVAILABILITY, eqe)) {
295                         ehca_info(&shca->ib_device,
296                                   "port %x is active.", port);
297                         event.device = &shca->ib_device;
298                         event.event = IB_EVENT_PORT_ACTIVE;
299                         event.element.port_num = port;
300                         shca->sport[port - 1].port_state = IB_PORT_ACTIVE;
301                         ib_dispatch_event(&event);
302                 } else {
303                         ehca_info(&shca->ib_device,
304                                   "port %x is inactive.", port);
305                         event.device = &shca->ib_device;
306                         event.event = IB_EVENT_PORT_ERR;
307                         event.element.port_num = port;
308                         shca->sport[port - 1].port_state = IB_PORT_DOWN;
309                         ib_dispatch_event(&event);
310                 }
311                 break;
312         case 0x31:
313                 /* port configuration change
314                  * disruptive change is caused by
315                  * LID, PKEY or SM change
316                  */
317                 ehca_warn(&shca->ib_device,
318                           "disruptive port %x configuration change", port);
319
320                 ehca_info(&shca->ib_device,
321                          "port %x is inactive.", port);
322                 event.device = &shca->ib_device;
323                 event.event = IB_EVENT_PORT_ERR;
324                 event.element.port_num = port;
325                 shca->sport[port - 1].port_state = IB_PORT_DOWN;
326                 ib_dispatch_event(&event);
327
328                 ehca_info(&shca->ib_device,
329                          "port %x is active.", port);
330                 event.device = &shca->ib_device;
331                 event.event = IB_EVENT_PORT_ACTIVE;
332                 event.element.port_num = port;
333                 shca->sport[port - 1].port_state = IB_PORT_ACTIVE;
334                 ib_dispatch_event(&event);
335                 break;
336         case 0x32: /* adapter malfunction */
337                 ehca_err(&shca->ib_device, "Adapter malfunction.");
338                 break;
339         case 0x33:  /* trace stopped */
340                 ehca_err(&shca->ib_device, "Traced stopped.");
341                 break;
342         default:
343                 ehca_err(&shca->ib_device, "Unknown event code: %x on %s.",
344                          ec, shca->ib_device.name);
345                 break;
346         }
347
348         return;
349 }
350
351 static inline void reset_eq_pending(struct ehca_cq *cq)
352 {
353         u64 CQx_EP;
354         struct h_galpa gal = cq->galpas.kernel;
355
356         hipz_galpa_store_cq(gal, cqx_ep, 0x0);
357         CQx_EP = hipz_galpa_load(gal, CQTEMM_OFFSET(cqx_ep));
358
359         return;
360 }
361
362 irqreturn_t ehca_interrupt_neq(int irq, void *dev_id)
363 {
364         struct ehca_shca *shca = (struct ehca_shca*)dev_id;
365
366         tasklet_hi_schedule(&shca->neq.interrupt_task);
367
368         return IRQ_HANDLED;
369 }
370
371 void ehca_tasklet_neq(unsigned long data)
372 {
373         struct ehca_shca *shca = (struct ehca_shca*)data;
374         struct ehca_eqe *eqe;
375         u64 ret;
376
377         eqe = (struct ehca_eqe *)ehca_poll_eq(shca, &shca->neq);
378
379         while (eqe) {
380                 if (!EHCA_BMASK_GET(NEQE_COMPLETION_EVENT, eqe->entry))
381                         parse_ec(shca, eqe->entry);
382
383                 eqe = (struct ehca_eqe *)ehca_poll_eq(shca, &shca->neq);
384         }
385
386         ret = hipz_h_reset_event(shca->ipz_hca_handle,
387                                  shca->neq.ipz_eq_handle, 0xFFFFFFFFFFFFFFFFL);
388
389         if (ret != H_SUCCESS)
390                 ehca_err(&shca->ib_device, "Can't clear notification events.");
391
392         return;
393 }
394
395 irqreturn_t ehca_interrupt_eq(int irq, void *dev_id)
396 {
397         struct ehca_shca *shca = (struct ehca_shca*)dev_id;
398
399         tasklet_hi_schedule(&shca->eq.interrupt_task);
400
401         return IRQ_HANDLED;
402 }
403
404 void ehca_tasklet_eq(unsigned long data)
405 {
406         struct ehca_shca *shca = (struct ehca_shca*)data;
407         struct ehca_eqe *eqe;
408         int int_state;
409         int query_cnt = 0;
410
411         do {
412                 eqe = (struct ehca_eqe *)ehca_poll_eq(shca, &shca->eq);
413
414                 if ((shca->hw_level >= 2) && eqe)
415                         int_state = 1;
416                 else
417                         int_state = 0;
418
419                 while ((int_state == 1) || eqe) {
420                         while (eqe) {
421                                 u64 eqe_value = eqe->entry;
422
423                                 ehca_dbg(&shca->ib_device,
424                                          "eqe_value=%lx", eqe_value);
425
426                                 /* TODO: better structure */
427                                 if (EHCA_BMASK_GET(EQE_COMPLETION_EVENT,
428                                                    eqe_value)) {
429                                         unsigned long flags;
430                                         u32 token;
431                                         struct ehca_cq *cq;
432
433                                         ehca_dbg(&shca->ib_device,
434                                                  "... completion event");
435                                         token =
436                                                 EHCA_BMASK_GET(EQE_CQ_TOKEN,
437                                                                eqe_value);
438                                         spin_lock_irqsave(&ehca_cq_idr_lock,
439                                                           flags);
440                                         cq = idr_find(&ehca_cq_idr, token);
441
442                                         if (cq == NULL) {
443                                                 spin_unlock(&ehca_cq_idr_lock);
444                                                 break;
445                                         }
446
447                                         reset_eq_pending(cq);
448 #ifdef CONFIG_INFINIBAND_EHCA_SCALING
449                                         queue_comp_task(cq);
450                                         spin_unlock_irqrestore(&ehca_cq_idr_lock,
451                                                                flags);
452 #else
453                                         spin_unlock_irqrestore(&ehca_cq_idr_lock,
454                                                                flags);
455                                         comp_event_callback(cq);
456 #endif
457                                 } else {
458                                         ehca_dbg(&shca->ib_device,
459                                                  "... non completion event");
460                                         parse_identifier(shca, eqe_value);
461                                 }
462                                 eqe =
463                                         (struct ehca_eqe *)ehca_poll_eq(shca,
464                                                                     &shca->eq);
465                         }
466
467                         if (shca->hw_level >= 2) {
468                                 int_state =
469                                     hipz_h_query_int_state(shca->ipz_hca_handle,
470                                                            shca->eq.ist);
471                                 query_cnt++;
472                                 iosync();
473                                 if (query_cnt >= 100) {
474                                         query_cnt = 0;
475                                         int_state = 0;
476                                 }
477                         }
478                         eqe = (struct ehca_eqe *)ehca_poll_eq(shca, &shca->eq);
479
480                 }
481         } while (int_state != 0);
482
483         return;
484 }
485
486 #ifdef CONFIG_INFINIBAND_EHCA_SCALING
487
488 static inline int find_next_online_cpu(struct ehca_comp_pool* pool)
489 {
490         unsigned long flags_last_cpu;
491
492         if (ehca_debug_level)
493                 ehca_dmp(&cpu_online_map, sizeof(cpumask_t), "");
494
495         spin_lock_irqsave(&pool->last_cpu_lock, flags_last_cpu);
496         pool->last_cpu = next_cpu(pool->last_cpu, cpu_online_map);
497         if (pool->last_cpu == NR_CPUS)
498                 pool->last_cpu = first_cpu(cpu_online_map);
499         spin_unlock_irqrestore(&pool->last_cpu_lock, flags_last_cpu);
500
501         return pool->last_cpu;
502 }
503
504 static void __queue_comp_task(struct ehca_cq *__cq,
505                               struct ehca_cpu_comp_task *cct)
506 {
507         unsigned long flags_cct;
508         unsigned long flags_cq;
509
510         spin_lock_irqsave(&cct->task_lock, flags_cct);
511         spin_lock_irqsave(&__cq->task_lock, flags_cq);
512
513         if (__cq->nr_callbacks == 0) {
514                 __cq->nr_callbacks++;
515                 list_add_tail(&__cq->entry, &cct->cq_list);
516                 cct->cq_jobs++;
517                 wake_up(&cct->wait_queue);
518         }
519         else
520                 __cq->nr_callbacks++;
521
522         spin_unlock_irqrestore(&__cq->task_lock, flags_cq);
523         spin_unlock_irqrestore(&cct->task_lock, flags_cct);
524 }
525
526 static void queue_comp_task(struct ehca_cq *__cq)
527 {
528         int cpu;
529         int cpu_id;
530         struct ehca_cpu_comp_task *cct;
531
532         cpu = get_cpu();
533         cpu_id = find_next_online_cpu(pool);
534
535         BUG_ON(!cpu_online(cpu_id));
536
537         cct = per_cpu_ptr(pool->cpu_comp_tasks, cpu_id);
538
539         if (cct->cq_jobs > 0) {
540                 cpu_id = find_next_online_cpu(pool);
541                 cct = per_cpu_ptr(pool->cpu_comp_tasks, cpu_id);
542         }
543
544         __queue_comp_task(__cq, cct);
545
546         put_cpu();
547
548         return;
549 }
550
551 static void run_comp_task(struct ehca_cpu_comp_task* cct)
552 {
553         struct ehca_cq *cq;
554         unsigned long flags_cct;
555         unsigned long flags_cq;
556
557         spin_lock_irqsave(&cct->task_lock, flags_cct);
558
559         while (!list_empty(&cct->cq_list)) {
560                 cq = list_entry(cct->cq_list.next, struct ehca_cq, entry);
561                 spin_unlock_irqrestore(&cct->task_lock, flags_cct);
562                 comp_event_callback(cq);
563                 spin_lock_irqsave(&cct->task_lock, flags_cct);
564
565                 spin_lock_irqsave(&cq->task_lock, flags_cq);
566                 cq->nr_callbacks--;
567                 if (cq->nr_callbacks == 0) {
568                         list_del_init(cct->cq_list.next);
569                         cct->cq_jobs--;
570                 }
571                 spin_unlock_irqrestore(&cq->task_lock, flags_cq);
572
573         }
574
575         spin_unlock_irqrestore(&cct->task_lock, flags_cct);
576
577         return;
578 }
579
580 static int comp_task(void *__cct)
581 {
582         struct ehca_cpu_comp_task* cct = __cct;
583         DECLARE_WAITQUEUE(wait, current);
584
585         set_current_state(TASK_INTERRUPTIBLE);
586         while(!kthread_should_stop()) {
587                 add_wait_queue(&cct->wait_queue, &wait);
588
589                 if (list_empty(&cct->cq_list))
590                         schedule();
591                 else
592                         __set_current_state(TASK_RUNNING);
593
594                 remove_wait_queue(&cct->wait_queue, &wait);
595
596                 if (!list_empty(&cct->cq_list))
597                         run_comp_task(__cct);
598
599                 set_current_state(TASK_INTERRUPTIBLE);
600         }
601         __set_current_state(TASK_RUNNING);
602
603         return 0;
604 }
605
606 static struct task_struct *create_comp_task(struct ehca_comp_pool *pool,
607                                             int cpu)
608 {
609         struct ehca_cpu_comp_task *cct;
610
611         cct = per_cpu_ptr(pool->cpu_comp_tasks, cpu);
612         spin_lock_init(&cct->task_lock);
613         INIT_LIST_HEAD(&cct->cq_list);
614         init_waitqueue_head(&cct->wait_queue);
615         cct->task = kthread_create(comp_task, cct, "ehca_comp/%d", cpu);
616
617         return cct->task;
618 }
619
620 static void destroy_comp_task(struct ehca_comp_pool *pool,
621                               int cpu)
622 {
623         struct ehca_cpu_comp_task *cct;
624         struct task_struct *task;
625         unsigned long flags_cct;
626
627         cct = per_cpu_ptr(pool->cpu_comp_tasks, cpu);
628
629         spin_lock_irqsave(&cct->task_lock, flags_cct);
630
631         task = cct->task;
632         cct->task = NULL;
633         cct->cq_jobs = 0;
634
635         spin_unlock_irqrestore(&cct->task_lock, flags_cct);
636
637         if (task)
638                 kthread_stop(task);
639
640         return;
641 }
642
643 static void take_over_work(struct ehca_comp_pool *pool,
644                            int cpu)
645 {
646         struct ehca_cpu_comp_task *cct = per_cpu_ptr(pool->cpu_comp_tasks, cpu);
647         LIST_HEAD(list);
648         struct ehca_cq *cq;
649         unsigned long flags_cct;
650
651         spin_lock_irqsave(&cct->task_lock, flags_cct);
652
653         list_splice_init(&cct->cq_list, &list);
654
655         while(!list_empty(&list)) {
656                cq = list_entry(cct->cq_list.next, struct ehca_cq, entry);
657
658                list_del(&cq->entry);
659                __queue_comp_task(cq, per_cpu_ptr(pool->cpu_comp_tasks,
660                                                  smp_processor_id()));
661         }
662
663         spin_unlock_irqrestore(&cct->task_lock, flags_cct);
664
665 }
666
667 static int comp_pool_callback(struct notifier_block *nfb,
668                               unsigned long action,
669                               void *hcpu)
670 {
671         unsigned int cpu = (unsigned long)hcpu;
672         struct ehca_cpu_comp_task *cct;
673
674         switch (action) {
675         case CPU_UP_PREPARE:
676                 ehca_gen_dbg("CPU: %x (CPU_PREPARE)", cpu);
677                 if(!create_comp_task(pool, cpu)) {
678                         ehca_gen_err("Can't create comp_task for cpu: %x", cpu);
679                         return NOTIFY_BAD;
680                 }
681                 break;
682         case CPU_UP_CANCELED:
683                 ehca_gen_dbg("CPU: %x (CPU_CANCELED)", cpu);
684                 cct = per_cpu_ptr(pool->cpu_comp_tasks, cpu);
685                 kthread_bind(cct->task, any_online_cpu(cpu_online_map));
686                 destroy_comp_task(pool, cpu);
687                 break;
688         case CPU_ONLINE:
689                 ehca_gen_dbg("CPU: %x (CPU_ONLINE)", cpu);
690                 cct = per_cpu_ptr(pool->cpu_comp_tasks, cpu);
691                 kthread_bind(cct->task, cpu);
692                 wake_up_process(cct->task);
693                 break;
694         case CPU_DOWN_PREPARE:
695                 ehca_gen_dbg("CPU: %x (CPU_DOWN_PREPARE)", cpu);
696                 break;
697         case CPU_DOWN_FAILED:
698                 ehca_gen_dbg("CPU: %x (CPU_DOWN_FAILED)", cpu);
699                 break;
700         case CPU_DEAD:
701                 ehca_gen_dbg("CPU: %x (CPU_DEAD)", cpu);
702                 destroy_comp_task(pool, cpu);
703                 take_over_work(pool, cpu);
704                 break;
705         }
706
707         return NOTIFY_OK;
708 }
709
710 #endif
711
712 int ehca_create_comp_pool(void)
713 {
714 #ifdef CONFIG_INFINIBAND_EHCA_SCALING
715         int cpu;
716         struct task_struct *task;
717
718         pool = kzalloc(sizeof(struct ehca_comp_pool), GFP_KERNEL);
719         if (pool == NULL)
720                 return -ENOMEM;
721
722         spin_lock_init(&pool->last_cpu_lock);
723         pool->last_cpu = any_online_cpu(cpu_online_map);
724
725         pool->cpu_comp_tasks = alloc_percpu(struct ehca_cpu_comp_task);
726         if (pool->cpu_comp_tasks == NULL) {
727                 kfree(pool);
728                 return -EINVAL;
729         }
730
731         for_each_online_cpu(cpu) {
732                 task = create_comp_task(pool, cpu);
733                 if (task) {
734                         kthread_bind(task, cpu);
735                         wake_up_process(task);
736                 }
737         }
738
739         comp_pool_callback_nb.notifier_call = comp_pool_callback;
740         comp_pool_callback_nb.priority =0;
741         register_cpu_notifier(&comp_pool_callback_nb);
742 #endif
743
744         return 0;
745 }
746
747 void ehca_destroy_comp_pool(void)
748 {
749 #ifdef CONFIG_INFINIBAND_EHCA_SCALING
750         int i;
751
752         unregister_cpu_notifier(&comp_pool_callback_nb);
753
754         for (i = 0; i < NR_CPUS; i++) {
755                 if (cpu_online(i))
756                         destroy_comp_task(pool, i);
757         }
758 #endif
759
760         return;
761 }