ehca_irq.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762
  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. #include "ehca_classes.h"
  42. #include "ehca_irq.h"
  43. #include "ehca_iverbs.h"
  44. #include "ehca_tools.h"
  45. #include "hcp_if.h"
  46. #include "hipz_fns.h"
  47. #define EQE_COMPLETION_EVENT EHCA_BMASK_IBM(1,1)
  48. #define EQE_CQ_QP_NUMBER EHCA_BMASK_IBM(8,31)
  49. #define EQE_EE_IDENTIFIER EHCA_BMASK_IBM(2,7)
  50. #define EQE_CQ_NUMBER EHCA_BMASK_IBM(8,31)
  51. #define EQE_QP_NUMBER EHCA_BMASK_IBM(8,31)
  52. #define EQE_QP_TOKEN EHCA_BMASK_IBM(32,63)
  53. #define EQE_CQ_TOKEN EHCA_BMASK_IBM(32,63)
  54. #define NEQE_COMPLETION_EVENT EHCA_BMASK_IBM(1,1)
  55. #define NEQE_EVENT_CODE EHCA_BMASK_IBM(2,7)
  56. #define NEQE_PORT_NUMBER EHCA_BMASK_IBM(8,15)
  57. #define NEQE_PORT_AVAILABILITY EHCA_BMASK_IBM(16,16)
  58. #define ERROR_DATA_LENGTH EHCA_BMASK_IBM(52,63)
  59. #define ERROR_DATA_TYPE EHCA_BMASK_IBM(0,7)
  60. #ifdef CONFIG_INFINIBAND_EHCA_SCALING
  61. static void queue_comp_task(struct ehca_cq *__cq);
  62. static struct ehca_comp_pool* pool;
  63. static struct notifier_block comp_pool_callback_nb;
  64. #endif
  65. static inline void comp_event_callback(struct ehca_cq *cq)
  66. {
  67. if (!cq->ib_cq.comp_handler)
  68. return;
  69. spin_lock(&cq->cb_lock);
  70. cq->ib_cq.comp_handler(&cq->ib_cq, cq->ib_cq.cq_context);
  71. spin_unlock(&cq->cb_lock);
  72. return;
  73. }
  74. static void print_error_data(struct ehca_shca * shca, void* data,
  75. u64* rblock, int length)
  76. {
  77. u64 type = EHCA_BMASK_GET(ERROR_DATA_TYPE, rblock[2]);
  78. u64 resource = rblock[1];
  79. switch (type) {
  80. case 0x1: /* Queue Pair */
  81. {
  82. struct ehca_qp *qp = (struct ehca_qp*)data;
  83. /* only print error data if AER is set */
  84. if (rblock[6] == 0)
  85. return;
  86. ehca_err(&shca->ib_device,
  87. "QP 0x%x (resource=%lx) has errors.",
  88. qp->ib_qp.qp_num, resource);
  89. break;
  90. }
  91. case 0x4: /* Completion Queue */
  92. {
  93. struct ehca_cq *cq = (struct ehca_cq*)data;
  94. ehca_err(&shca->ib_device,
  95. "CQ 0x%x (resource=%lx) has errors.",
  96. cq->cq_number, resource);
  97. break;
  98. }
  99. default:
  100. ehca_err(&shca->ib_device,
  101. "Unknown errror type: %lx on %s.",
  102. type, shca->ib_device.name);
  103. break;
  104. }
  105. ehca_err(&shca->ib_device, "Error data is available: %lx.", resource);
  106. ehca_err(&shca->ib_device, "EHCA ----- error data begin "
  107. "---------------------------------------------------");
  108. ehca_dmp(rblock, length, "resource=%lx", resource);
  109. ehca_err(&shca->ib_device, "EHCA ----- error data end "
  110. "----------------------------------------------------");
  111. return;
  112. }
  113. int ehca_error_data(struct ehca_shca *shca, void *data,
  114. u64 resource)
  115. {
  116. unsigned long ret;
  117. u64 *rblock;
  118. unsigned long block_count;
  119. rblock = kzalloc(H_CB_ALIGNMENT, GFP_KERNEL);
  120. if (!rblock) {
  121. ehca_err(&shca->ib_device, "Cannot allocate rblock memory.");
  122. ret = -ENOMEM;
  123. goto error_data1;
  124. }
  125. ret = hipz_h_error_data(shca->ipz_hca_handle,
  126. resource,
  127. rblock,
  128. &block_count);
  129. if (ret == H_R_STATE) {
  130. ehca_err(&shca->ib_device,
  131. "No error data is available: %lx.", resource);
  132. }
  133. else if (ret == H_SUCCESS) {
  134. int length;
  135. length = EHCA_BMASK_GET(ERROR_DATA_LENGTH, rblock[0]);
  136. if (length > PAGE_SIZE)
  137. length = PAGE_SIZE;
  138. print_error_data(shca, data, rblock, length);
  139. }
  140. else {
  141. ehca_err(&shca->ib_device,
  142. "Error data could not be fetched: %lx", resource);
  143. }
  144. kfree(rblock);
  145. error_data1:
  146. return ret;
  147. }
  148. static void qp_event_callback(struct ehca_shca *shca,
  149. u64 eqe,
  150. enum ib_event_type event_type)
  151. {
  152. struct ib_event event;
  153. struct ehca_qp *qp;
  154. unsigned long flags;
  155. u32 token = EHCA_BMASK_GET(EQE_QP_TOKEN, eqe);
  156. spin_lock_irqsave(&ehca_qp_idr_lock, flags);
  157. qp = idr_find(&ehca_qp_idr, token);
  158. spin_unlock_irqrestore(&ehca_qp_idr_lock, flags);
  159. if (!qp)
  160. return;
  161. ehca_error_data(shca, qp, qp->ipz_qp_handle.handle);
  162. if (!qp->ib_qp.event_handler)
  163. return;
  164. event.device = &shca->ib_device;
  165. event.event = event_type;
  166. event.element.qp = &qp->ib_qp;
  167. qp->ib_qp.event_handler(&event, qp->ib_qp.qp_context);
  168. return;
  169. }
  170. static void cq_event_callback(struct ehca_shca *shca,
  171. u64 eqe)
  172. {
  173. struct ehca_cq *cq;
  174. unsigned long flags;
  175. u32 token = EHCA_BMASK_GET(EQE_CQ_TOKEN, eqe);
  176. spin_lock_irqsave(&ehca_cq_idr_lock, flags);
  177. cq = idr_find(&ehca_cq_idr, token);
  178. spin_unlock_irqrestore(&ehca_cq_idr_lock, flags);
  179. if (!cq)
  180. return;
  181. ehca_error_data(shca, cq, cq->ipz_cq_handle.handle);
  182. return;
  183. }
  184. static void parse_identifier(struct ehca_shca *shca, u64 eqe)
  185. {
  186. u8 identifier = EHCA_BMASK_GET(EQE_EE_IDENTIFIER, eqe);
  187. switch (identifier) {
  188. case 0x02: /* path migrated */
  189. qp_event_callback(shca, eqe, IB_EVENT_PATH_MIG);
  190. break;
  191. case 0x03: /* communication established */
  192. qp_event_callback(shca, eqe, IB_EVENT_COMM_EST);
  193. break;
  194. case 0x04: /* send queue drained */
  195. qp_event_callback(shca, eqe, IB_EVENT_SQ_DRAINED);
  196. break;
  197. case 0x05: /* QP error */
  198. case 0x06: /* QP error */
  199. qp_event_callback(shca, eqe, IB_EVENT_QP_FATAL);
  200. break;
  201. case 0x07: /* CQ error */
  202. case 0x08: /* CQ error */
  203. cq_event_callback(shca, eqe);
  204. break;
  205. case 0x09: /* MRMWPTE error */
  206. ehca_err(&shca->ib_device, "MRMWPTE error.");
  207. break;
  208. case 0x0A: /* port event */
  209. ehca_err(&shca->ib_device, "Port event.");
  210. break;
  211. case 0x0B: /* MR access error */
  212. ehca_err(&shca->ib_device, "MR access error.");
  213. break;
  214. case 0x0C: /* EQ error */
  215. ehca_err(&shca->ib_device, "EQ error.");
  216. break;
  217. case 0x0D: /* P/Q_Key mismatch */
  218. ehca_err(&shca->ib_device, "P/Q_Key mismatch.");
  219. break;
  220. case 0x10: /* sampling complete */
  221. ehca_err(&shca->ib_device, "Sampling complete.");
  222. break;
  223. case 0x11: /* unaffiliated access error */
  224. ehca_err(&shca->ib_device, "Unaffiliated access error.");
  225. break;
  226. case 0x12: /* path migrating error */
  227. ehca_err(&shca->ib_device, "Path migration error.");
  228. break;
  229. case 0x13: /* interface trace stopped */
  230. ehca_err(&shca->ib_device, "Interface trace stopped.");
  231. break;
  232. case 0x14: /* first error capture info available */
  233. default:
  234. ehca_err(&shca->ib_device, "Unknown identifier: %x on %s.",
  235. identifier, shca->ib_device.name);
  236. break;
  237. }
  238. return;
  239. }
  240. static void parse_ec(struct ehca_shca *shca, u64 eqe)
  241. {
  242. struct ib_event event;
  243. u8 ec = EHCA_BMASK_GET(NEQE_EVENT_CODE, eqe);
  244. u8 port = EHCA_BMASK_GET(NEQE_PORT_NUMBER, eqe);
  245. switch (ec) {
  246. case 0x30: /* port availability change */
  247. if (EHCA_BMASK_GET(NEQE_PORT_AVAILABILITY, eqe)) {
  248. ehca_info(&shca->ib_device,
  249. "port %x is active.", port);
  250. event.device = &shca->ib_device;
  251. event.event = IB_EVENT_PORT_ACTIVE;
  252. event.element.port_num = port;
  253. shca->sport[port - 1].port_state = IB_PORT_ACTIVE;
  254. ib_dispatch_event(&event);
  255. } else {
  256. ehca_info(&shca->ib_device,
  257. "port %x is inactive.", port);
  258. event.device = &shca->ib_device;
  259. event.event = IB_EVENT_PORT_ERR;
  260. event.element.port_num = port;
  261. shca->sport[port - 1].port_state = IB_PORT_DOWN;
  262. ib_dispatch_event(&event);
  263. }
  264. break;
  265. case 0x31:
  266. /* port configuration change
  267. * disruptive change is caused by
  268. * LID, PKEY or SM change
  269. */
  270. ehca_warn(&shca->ib_device,
  271. "disruptive port %x configuration change", port);
  272. ehca_info(&shca->ib_device,
  273. "port %x is inactive.", port);
  274. event.device = &shca->ib_device;
  275. event.event = IB_EVENT_PORT_ERR;
  276. event.element.port_num = port;
  277. shca->sport[port - 1].port_state = IB_PORT_DOWN;
  278. ib_dispatch_event(&event);
  279. ehca_info(&shca->ib_device,
  280. "port %x is active.", port);
  281. event.device = &shca->ib_device;
  282. event.event = IB_EVENT_PORT_ACTIVE;
  283. event.element.port_num = port;
  284. shca->sport[port - 1].port_state = IB_PORT_ACTIVE;
  285. ib_dispatch_event(&event);
  286. break;
  287. case 0x32: /* adapter malfunction */
  288. ehca_err(&shca->ib_device, "Adapter malfunction.");
  289. break;
  290. case 0x33: /* trace stopped */
  291. ehca_err(&shca->ib_device, "Traced stopped.");
  292. break;
  293. default:
  294. ehca_err(&shca->ib_device, "Unknown event code: %x on %s.",
  295. ec, shca->ib_device.name);
  296. break;
  297. }
  298. return;
  299. }
  300. static inline void reset_eq_pending(struct ehca_cq *cq)
  301. {
  302. u64 CQx_EP;
  303. struct h_galpa gal = cq->galpas.kernel;
  304. hipz_galpa_store_cq(gal, cqx_ep, 0x0);
  305. CQx_EP = hipz_galpa_load(gal, CQTEMM_OFFSET(cqx_ep));
  306. return;
  307. }
  308. irqreturn_t ehca_interrupt_neq(int irq, void *dev_id)
  309. {
  310. struct ehca_shca *shca = (struct ehca_shca*)dev_id;
  311. tasklet_hi_schedule(&shca->neq.interrupt_task);
  312. return IRQ_HANDLED;
  313. }
  314. void ehca_tasklet_neq(unsigned long data)
  315. {
  316. struct ehca_shca *shca = (struct ehca_shca*)data;
  317. struct ehca_eqe *eqe;
  318. u64 ret;
  319. eqe = (struct ehca_eqe *)ehca_poll_eq(shca, &shca->neq);
  320. while (eqe) {
  321. if (!EHCA_BMASK_GET(NEQE_COMPLETION_EVENT, eqe->entry))
  322. parse_ec(shca, eqe->entry);
  323. eqe = (struct ehca_eqe *)ehca_poll_eq(shca, &shca->neq);
  324. }
  325. ret = hipz_h_reset_event(shca->ipz_hca_handle,
  326. shca->neq.ipz_eq_handle, 0xFFFFFFFFFFFFFFFFL);
  327. if (ret != H_SUCCESS)
  328. ehca_err(&shca->ib_device, "Can't clear notification events.");
  329. return;
  330. }
  331. irqreturn_t ehca_interrupt_eq(int irq, void *dev_id)
  332. {
  333. struct ehca_shca *shca = (struct ehca_shca*)dev_id;
  334. tasklet_hi_schedule(&shca->eq.interrupt_task);
  335. return IRQ_HANDLED;
  336. }
  337. void ehca_tasklet_eq(unsigned long data)
  338. {
  339. struct ehca_shca *shca = (struct ehca_shca*)data;
  340. struct ehca_eqe *eqe;
  341. int int_state;
  342. int query_cnt = 0;
  343. do {
  344. eqe = (struct ehca_eqe *)ehca_poll_eq(shca, &shca->eq);
  345. if ((shca->hw_level >= 2) && eqe)
  346. int_state = 1;
  347. else
  348. int_state = 0;
  349. while ((int_state == 1) || eqe) {
  350. while (eqe) {
  351. u64 eqe_value = eqe->entry;
  352. ehca_dbg(&shca->ib_device,
  353. "eqe_value=%lx", eqe_value);
  354. /* TODO: better structure */
  355. if (EHCA_BMASK_GET(EQE_COMPLETION_EVENT,
  356. eqe_value)) {
  357. unsigned long flags;
  358. u32 token;
  359. struct ehca_cq *cq;
  360. ehca_dbg(&shca->ib_device,
  361. "... completion event");
  362. token =
  363. EHCA_BMASK_GET(EQE_CQ_TOKEN,
  364. eqe_value);
  365. spin_lock_irqsave(&ehca_cq_idr_lock,
  366. flags);
  367. cq = idr_find(&ehca_cq_idr, token);
  368. if (cq == NULL) {
  369. spin_unlock(&ehca_cq_idr_lock);
  370. break;
  371. }
  372. reset_eq_pending(cq);
  373. #ifdef CONFIG_INFINIBAND_EHCA_SCALING
  374. queue_comp_task(cq);
  375. spin_unlock_irqrestore(&ehca_cq_idr_lock,
  376. flags);
  377. #else
  378. spin_unlock_irqrestore(&ehca_cq_idr_lock,
  379. flags);
  380. comp_event_callback(cq);
  381. #endif
  382. } else {
  383. ehca_dbg(&shca->ib_device,
  384. "... non completion event");
  385. parse_identifier(shca, eqe_value);
  386. }
  387. eqe =
  388. (struct ehca_eqe *)ehca_poll_eq(shca,
  389. &shca->eq);
  390. }
  391. if (shca->hw_level >= 2) {
  392. int_state =
  393. hipz_h_query_int_state(shca->ipz_hca_handle,
  394. shca->eq.ist);
  395. query_cnt++;
  396. iosync();
  397. if (query_cnt >= 100) {
  398. query_cnt = 0;
  399. int_state = 0;
  400. }
  401. }
  402. eqe = (struct ehca_eqe *)ehca_poll_eq(shca, &shca->eq);
  403. }
  404. } while (int_state != 0);
  405. return;
  406. }
  407. #ifdef CONFIG_INFINIBAND_EHCA_SCALING
  408. static inline int find_next_online_cpu(struct ehca_comp_pool* pool)
  409. {
  410. unsigned long flags_last_cpu;
  411. if (ehca_debug_level)
  412. ehca_dmp(&cpu_online_map, sizeof(cpumask_t), "");
  413. spin_lock_irqsave(&pool->last_cpu_lock, flags_last_cpu);
  414. pool->last_cpu = next_cpu(pool->last_cpu, cpu_online_map);
  415. if (pool->last_cpu == NR_CPUS)
  416. pool->last_cpu = first_cpu(cpu_online_map);
  417. spin_unlock_irqrestore(&pool->last_cpu_lock, flags_last_cpu);
  418. return pool->last_cpu;
  419. }
  420. static void __queue_comp_task(struct ehca_cq *__cq,
  421. struct ehca_cpu_comp_task *cct)
  422. {
  423. unsigned long flags_cct;
  424. unsigned long flags_cq;
  425. spin_lock_irqsave(&cct->task_lock, flags_cct);
  426. spin_lock_irqsave(&__cq->task_lock, flags_cq);
  427. if (__cq->nr_callbacks == 0) {
  428. __cq->nr_callbacks++;
  429. list_add_tail(&__cq->entry, &cct->cq_list);
  430. cct->cq_jobs++;
  431. wake_up(&cct->wait_queue);
  432. }
  433. else
  434. __cq->nr_callbacks++;
  435. spin_unlock_irqrestore(&__cq->task_lock, flags_cq);
  436. spin_unlock_irqrestore(&cct->task_lock, flags_cct);
  437. }
  438. static void queue_comp_task(struct ehca_cq *__cq)
  439. {
  440. int cpu;
  441. int cpu_id;
  442. struct ehca_cpu_comp_task *cct;
  443. cpu = get_cpu();
  444. cpu_id = find_next_online_cpu(pool);
  445. BUG_ON(!cpu_online(cpu_id));
  446. cct = per_cpu_ptr(pool->cpu_comp_tasks, cpu_id);
  447. if (cct->cq_jobs > 0) {
  448. cpu_id = find_next_online_cpu(pool);
  449. cct = per_cpu_ptr(pool->cpu_comp_tasks, cpu_id);
  450. }
  451. __queue_comp_task(__cq, cct);
  452. put_cpu();
  453. return;
  454. }
  455. static void run_comp_task(struct ehca_cpu_comp_task* cct)
  456. {
  457. struct ehca_cq *cq;
  458. unsigned long flags_cct;
  459. unsigned long flags_cq;
  460. spin_lock_irqsave(&cct->task_lock, flags_cct);
  461. while (!list_empty(&cct->cq_list)) {
  462. cq = list_entry(cct->cq_list.next, struct ehca_cq, entry);
  463. spin_unlock_irqrestore(&cct->task_lock, flags_cct);
  464. comp_event_callback(cq);
  465. spin_lock_irqsave(&cct->task_lock, flags_cct);
  466. spin_lock_irqsave(&cq->task_lock, flags_cq);
  467. cq->nr_callbacks--;
  468. if (cq->nr_callbacks == 0) {
  469. list_del_init(cct->cq_list.next);
  470. cct->cq_jobs--;
  471. }
  472. spin_unlock_irqrestore(&cq->task_lock, flags_cq);
  473. }
  474. spin_unlock_irqrestore(&cct->task_lock, flags_cct);
  475. return;
  476. }
  477. static int comp_task(void *__cct)
  478. {
  479. struct ehca_cpu_comp_task* cct = __cct;
  480. DECLARE_WAITQUEUE(wait, current);
  481. set_current_state(TASK_INTERRUPTIBLE);
  482. while(!kthread_should_stop()) {
  483. add_wait_queue(&cct->wait_queue, &wait);
  484. if (list_empty(&cct->cq_list))
  485. schedule();
  486. else
  487. __set_current_state(TASK_RUNNING);
  488. remove_wait_queue(&cct->wait_queue, &wait);
  489. if (!list_empty(&cct->cq_list))
  490. run_comp_task(__cct);
  491. set_current_state(TASK_INTERRUPTIBLE);
  492. }
  493. __set_current_state(TASK_RUNNING);
  494. return 0;
  495. }
  496. static struct task_struct *create_comp_task(struct ehca_comp_pool *pool,
  497. int cpu)
  498. {
  499. struct ehca_cpu_comp_task *cct;
  500. cct = per_cpu_ptr(pool->cpu_comp_tasks, cpu);
  501. spin_lock_init(&cct->task_lock);
  502. INIT_LIST_HEAD(&cct->cq_list);
  503. init_waitqueue_head(&cct->wait_queue);
  504. cct->task = kthread_create(comp_task, cct, "ehca_comp/%d", cpu);
  505. return cct->task;
  506. }
  507. static void destroy_comp_task(struct ehca_comp_pool *pool,
  508. int cpu)
  509. {
  510. struct ehca_cpu_comp_task *cct;
  511. struct task_struct *task;
  512. unsigned long flags_cct;
  513. cct = per_cpu_ptr(pool->cpu_comp_tasks, cpu);
  514. spin_lock_irqsave(&cct->task_lock, flags_cct);
  515. task = cct->task;
  516. cct->task = NULL;
  517. cct->cq_jobs = 0;
  518. spin_unlock_irqrestore(&cct->task_lock, flags_cct);
  519. if (task)
  520. kthread_stop(task);
  521. return;
  522. }
  523. static void take_over_work(struct ehca_comp_pool *pool,
  524. int cpu)
  525. {
  526. struct ehca_cpu_comp_task *cct = per_cpu_ptr(pool->cpu_comp_tasks, cpu);
  527. LIST_HEAD(list);
  528. struct ehca_cq *cq;
  529. unsigned long flags_cct;
  530. spin_lock_irqsave(&cct->task_lock, flags_cct);
  531. list_splice_init(&cct->cq_list, &list);
  532. while(!list_empty(&list)) {
  533. cq = list_entry(cct->cq_list.next, struct ehca_cq, entry);
  534. list_del(&cq->entry);
  535. __queue_comp_task(cq, per_cpu_ptr(pool->cpu_comp_tasks,
  536. smp_processor_id()));
  537. }
  538. spin_unlock_irqrestore(&cct->task_lock, flags_cct);
  539. }
  540. static int comp_pool_callback(struct notifier_block *nfb,
  541. unsigned long action,
  542. void *hcpu)
  543. {
  544. unsigned int cpu = (unsigned long)hcpu;
  545. struct ehca_cpu_comp_task *cct;
  546. switch (action) {
  547. case CPU_UP_PREPARE:
  548. ehca_gen_dbg("CPU: %x (CPU_PREPARE)", cpu);
  549. if(!create_comp_task(pool, cpu)) {
  550. ehca_gen_err("Can't create comp_task for cpu: %x", cpu);
  551. return NOTIFY_BAD;
  552. }
  553. break;
  554. case CPU_UP_CANCELED:
  555. ehca_gen_dbg("CPU: %x (CPU_CANCELED)", cpu);
  556. cct = per_cpu_ptr(pool->cpu_comp_tasks, cpu);
  557. kthread_bind(cct->task, any_online_cpu(cpu_online_map));
  558. destroy_comp_task(pool, cpu);
  559. break;
  560. case CPU_ONLINE:
  561. ehca_gen_dbg("CPU: %x (CPU_ONLINE)", cpu);
  562. cct = per_cpu_ptr(pool->cpu_comp_tasks, cpu);
  563. kthread_bind(cct->task, cpu);
  564. wake_up_process(cct->task);
  565. break;
  566. case CPU_DOWN_PREPARE:
  567. ehca_gen_dbg("CPU: %x (CPU_DOWN_PREPARE)", cpu);
  568. break;
  569. case CPU_DOWN_FAILED:
  570. ehca_gen_dbg("CPU: %x (CPU_DOWN_FAILED)", cpu);
  571. break;
  572. case CPU_DEAD:
  573. ehca_gen_dbg("CPU: %x (CPU_DEAD)", cpu);
  574. destroy_comp_task(pool, cpu);
  575. take_over_work(pool, cpu);
  576. break;
  577. }
  578. return NOTIFY_OK;
  579. }
  580. #endif
  581. int ehca_create_comp_pool(void)
  582. {
  583. #ifdef CONFIG_INFINIBAND_EHCA_SCALING
  584. int cpu;
  585. struct task_struct *task;
  586. pool = kzalloc(sizeof(struct ehca_comp_pool), GFP_KERNEL);
  587. if (pool == NULL)
  588. return -ENOMEM;
  589. spin_lock_init(&pool->last_cpu_lock);
  590. pool->last_cpu = any_online_cpu(cpu_online_map);
  591. pool->cpu_comp_tasks = alloc_percpu(struct ehca_cpu_comp_task);
  592. if (pool->cpu_comp_tasks == NULL) {
  593. kfree(pool);
  594. return -EINVAL;
  595. }
  596. for_each_online_cpu(cpu) {
  597. task = create_comp_task(pool, cpu);
  598. if (task) {
  599. kthread_bind(task, cpu);
  600. wake_up_process(task);
  601. }
  602. }
  603. comp_pool_callback_nb.notifier_call = comp_pool_callback;
  604. comp_pool_callback_nb.priority =0;
  605. register_cpu_notifier(&comp_pool_callback_nb);
  606. #endif
  607. return 0;
  608. }
  609. void ehca_destroy_comp_pool(void)
  610. {
  611. #ifdef CONFIG_INFINIBAND_EHCA_SCALING
  612. int i;
  613. unregister_cpu_notifier(&comp_pool_callback_nb);
  614. for (i = 0; i < NR_CPUS; i++) {
  615. if (cpu_online(i))
  616. destroy_comp_task(pool, i);
  617. }
  618. #endif
  619. return;
  620. }