ehca_irq.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895
  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. * Hoang-Nam Nguyen <hnguyen@de.ibm.com>
  9. * Joachim Fenkes <fenkes@de.ibm.com>
  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. #include "ehca_classes.h"
  44. #include "ehca_irq.h"
  45. #include "ehca_iverbs.h"
  46. #include "ehca_tools.h"
  47. #include "hcp_if.h"
  48. #include "hipz_fns.h"
  49. #include "ipz_pt_fn.h"
  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. #define NEQE_COMPLETION_EVENT EHCA_BMASK_IBM( 1, 1)
  58. #define NEQE_EVENT_CODE EHCA_BMASK_IBM( 2, 7)
  59. #define NEQE_PORT_NUMBER EHCA_BMASK_IBM( 8, 15)
  60. #define NEQE_PORT_AVAILABILITY EHCA_BMASK_IBM(16, 16)
  61. #define NEQE_DISRUPTIVE EHCA_BMASK_IBM(16, 16)
  62. #define ERROR_DATA_LENGTH EHCA_BMASK_IBM(52, 63)
  63. #define ERROR_DATA_TYPE EHCA_BMASK_IBM( 0, 7)
  64. static void queue_comp_task(struct ehca_cq *__cq);
  65. static struct ehca_comp_pool *pool;
  66. #ifdef CONFIG_HOTPLUG_CPU
  67. static struct notifier_block comp_pool_callback_nb;
  68. #endif
  69. static inline void comp_event_callback(struct ehca_cq *cq)
  70. {
  71. if (!cq->ib_cq.comp_handler)
  72. return;
  73. spin_lock(&cq->cb_lock);
  74. cq->ib_cq.comp_handler(&cq->ib_cq, cq->ib_cq.cq_context);
  75. spin_unlock(&cq->cb_lock);
  76. return;
  77. }
  78. static void print_error_data(struct ehca_shca *shca, void *data,
  79. u64 *rblock, int length)
  80. {
  81. u64 type = EHCA_BMASK_GET(ERROR_DATA_TYPE, rblock[2]);
  82. u64 resource = rblock[1];
  83. switch (type) {
  84. case 0x1: /* Queue Pair */
  85. {
  86. struct ehca_qp *qp = (struct ehca_qp *)data;
  87. /* only print error data if AER is set */
  88. if (rblock[6] == 0)
  89. return;
  90. ehca_err(&shca->ib_device,
  91. "QP 0x%x (resource=%lx) has errors.",
  92. qp->ib_qp.qp_num, resource);
  93. break;
  94. }
  95. case 0x4: /* Completion Queue */
  96. {
  97. struct ehca_cq *cq = (struct ehca_cq *)data;
  98. ehca_err(&shca->ib_device,
  99. "CQ 0x%x (resource=%lx) has errors.",
  100. cq->cq_number, resource);
  101. break;
  102. }
  103. default:
  104. ehca_err(&shca->ib_device,
  105. "Unknown error type: %lx on %s.",
  106. type, shca->ib_device.name);
  107. break;
  108. }
  109. ehca_err(&shca->ib_device, "Error data is available: %lx.", resource);
  110. ehca_err(&shca->ib_device, "EHCA ----- error data begin "
  111. "---------------------------------------------------");
  112. ehca_dmp(rblock, length, "resource=%lx", resource);
  113. ehca_err(&shca->ib_device, "EHCA ----- error data end "
  114. "----------------------------------------------------");
  115. return;
  116. }
  117. int ehca_error_data(struct ehca_shca *shca, void *data,
  118. u64 resource)
  119. {
  120. unsigned long ret;
  121. u64 *rblock;
  122. unsigned long block_count;
  123. rblock = ehca_alloc_fw_ctrlblock(GFP_ATOMIC);
  124. if (!rblock) {
  125. ehca_err(&shca->ib_device, "Cannot allocate rblock memory.");
  126. ret = -ENOMEM;
  127. goto error_data1;
  128. }
  129. /* rblock must be 4K aligned and should be 4K large */
  130. ret = hipz_h_error_data(shca->ipz_hca_handle,
  131. resource,
  132. rblock,
  133. &block_count);
  134. if (ret == H_R_STATE)
  135. ehca_err(&shca->ib_device,
  136. "No error data is available: %lx.", resource);
  137. else if (ret == H_SUCCESS) {
  138. int length;
  139. length = EHCA_BMASK_GET(ERROR_DATA_LENGTH, rblock[0]);
  140. if (length > EHCA_PAGESIZE)
  141. length = EHCA_PAGESIZE;
  142. print_error_data(shca, data, rblock, length);
  143. } else
  144. ehca_err(&shca->ib_device,
  145. "Error data could not be fetched: %lx", resource);
  146. ehca_free_fw_ctrlblock(rblock);
  147. error_data1:
  148. return ret;
  149. }
  150. static void dispatch_qp_event(struct ehca_shca *shca, struct ehca_qp *qp,
  151. enum ib_event_type event_type)
  152. {
  153. struct ib_event event;
  154. event.device = &shca->ib_device;
  155. event.event = event_type;
  156. if (qp->ext_type == EQPT_SRQ) {
  157. if (!qp->ib_srq.event_handler)
  158. return;
  159. event.element.srq = &qp->ib_srq;
  160. qp->ib_srq.event_handler(&event, qp->ib_srq.srq_context);
  161. } else {
  162. if (!qp->ib_qp.event_handler)
  163. return;
  164. event.element.qp = &qp->ib_qp;
  165. qp->ib_qp.event_handler(&event, qp->ib_qp.qp_context);
  166. }
  167. }
  168. static void qp_event_callback(struct ehca_shca *shca, u64 eqe,
  169. enum ib_event_type event_type, int fatal)
  170. {
  171. struct ehca_qp *qp;
  172. u32 token = EHCA_BMASK_GET(EQE_QP_TOKEN, eqe);
  173. read_lock(&ehca_qp_idr_lock);
  174. qp = idr_find(&ehca_qp_idr, token);
  175. read_unlock(&ehca_qp_idr_lock);
  176. if (!qp)
  177. return;
  178. if (fatal)
  179. ehca_error_data(shca, qp, qp->ipz_qp_handle.handle);
  180. dispatch_qp_event(shca, qp, fatal && qp->ext_type == EQPT_SRQ ?
  181. IB_EVENT_SRQ_ERR : event_type);
  182. /*
  183. * eHCA only processes one WQE at a time for SRQ base QPs,
  184. * so the last WQE has been processed as soon as the QP enters
  185. * error state.
  186. */
  187. if (fatal && qp->ext_type == EQPT_SRQBASE)
  188. dispatch_qp_event(shca, qp, IB_EVENT_QP_LAST_WQE_REACHED);
  189. return;
  190. }
  191. static void cq_event_callback(struct ehca_shca *shca,
  192. u64 eqe)
  193. {
  194. struct ehca_cq *cq;
  195. u32 token = EHCA_BMASK_GET(EQE_CQ_TOKEN, eqe);
  196. read_lock(&ehca_cq_idr_lock);
  197. cq = idr_find(&ehca_cq_idr, token);
  198. if (cq)
  199. atomic_inc(&cq->nr_events);
  200. read_unlock(&ehca_cq_idr_lock);
  201. if (!cq)
  202. return;
  203. ehca_error_data(shca, cq, cq->ipz_cq_handle.handle);
  204. if (atomic_dec_and_test(&cq->nr_events))
  205. wake_up(&cq->wait_completion);
  206. return;
  207. }
  208. static void parse_identifier(struct ehca_shca *shca, u64 eqe)
  209. {
  210. u8 identifier = EHCA_BMASK_GET(EQE_EE_IDENTIFIER, eqe);
  211. switch (identifier) {
  212. case 0x02: /* path migrated */
  213. qp_event_callback(shca, eqe, IB_EVENT_PATH_MIG, 0);
  214. break;
  215. case 0x03: /* communication established */
  216. qp_event_callback(shca, eqe, IB_EVENT_COMM_EST, 0);
  217. break;
  218. case 0x04: /* send queue drained */
  219. qp_event_callback(shca, eqe, IB_EVENT_SQ_DRAINED, 0);
  220. break;
  221. case 0x05: /* QP error */
  222. case 0x06: /* QP error */
  223. qp_event_callback(shca, eqe, IB_EVENT_QP_FATAL, 1);
  224. break;
  225. case 0x07: /* CQ error */
  226. case 0x08: /* CQ error */
  227. cq_event_callback(shca, eqe);
  228. break;
  229. case 0x09: /* MRMWPTE error */
  230. ehca_err(&shca->ib_device, "MRMWPTE error.");
  231. break;
  232. case 0x0A: /* port event */
  233. ehca_err(&shca->ib_device, "Port event.");
  234. break;
  235. case 0x0B: /* MR access error */
  236. ehca_err(&shca->ib_device, "MR access error.");
  237. break;
  238. case 0x0C: /* EQ error */
  239. ehca_err(&shca->ib_device, "EQ error.");
  240. break;
  241. case 0x0D: /* P/Q_Key mismatch */
  242. ehca_err(&shca->ib_device, "P/Q_Key mismatch.");
  243. break;
  244. case 0x10: /* sampling complete */
  245. ehca_err(&shca->ib_device, "Sampling complete.");
  246. break;
  247. case 0x11: /* unaffiliated access error */
  248. ehca_err(&shca->ib_device, "Unaffiliated access error.");
  249. break;
  250. case 0x12: /* path migrating error */
  251. ehca_err(&shca->ib_device, "Path migration error.");
  252. break;
  253. case 0x13: /* interface trace stopped */
  254. ehca_err(&shca->ib_device, "Interface trace stopped.");
  255. break;
  256. case 0x14: /* first error capture info available */
  257. ehca_info(&shca->ib_device, "First error capture available");
  258. break;
  259. case 0x15: /* SRQ limit reached */
  260. qp_event_callback(shca, eqe, IB_EVENT_SRQ_LIMIT_REACHED, 0);
  261. break;
  262. default:
  263. ehca_err(&shca->ib_device, "Unknown identifier: %x on %s.",
  264. identifier, shca->ib_device.name);
  265. break;
  266. }
  267. return;
  268. }
  269. static void dispatch_port_event(struct ehca_shca *shca, int port_num,
  270. enum ib_event_type type, const char *msg)
  271. {
  272. struct ib_event event;
  273. ehca_info(&shca->ib_device, "port %d %s.", port_num, msg);
  274. event.device = &shca->ib_device;
  275. event.event = type;
  276. event.element.port_num = port_num;
  277. ib_dispatch_event(&event);
  278. }
  279. static void notify_port_conf_change(struct ehca_shca *shca, int port_num)
  280. {
  281. struct ehca_sma_attr new_attr;
  282. struct ehca_sma_attr *old_attr = &shca->sport[port_num - 1].saved_attr;
  283. ehca_query_sma_attr(shca, port_num, &new_attr);
  284. if (new_attr.sm_sl != old_attr->sm_sl ||
  285. new_attr.sm_lid != old_attr->sm_lid)
  286. dispatch_port_event(shca, port_num, IB_EVENT_SM_CHANGE,
  287. "SM changed");
  288. if (new_attr.lid != old_attr->lid ||
  289. new_attr.lmc != old_attr->lmc)
  290. dispatch_port_event(shca, port_num, IB_EVENT_LID_CHANGE,
  291. "LID changed");
  292. if (new_attr.pkey_tbl_len != old_attr->pkey_tbl_len ||
  293. memcmp(new_attr.pkeys, old_attr->pkeys,
  294. sizeof(u16) * new_attr.pkey_tbl_len))
  295. dispatch_port_event(shca, port_num, IB_EVENT_PKEY_CHANGE,
  296. "P_Key changed");
  297. *old_attr = new_attr;
  298. }
  299. static void parse_ec(struct ehca_shca *shca, u64 eqe)
  300. {
  301. u8 ec = EHCA_BMASK_GET(NEQE_EVENT_CODE, eqe);
  302. u8 port = EHCA_BMASK_GET(NEQE_PORT_NUMBER, eqe);
  303. switch (ec) {
  304. case 0x30: /* port availability change */
  305. if (EHCA_BMASK_GET(NEQE_PORT_AVAILABILITY, eqe)) {
  306. shca->sport[port - 1].port_state = IB_PORT_ACTIVE;
  307. dispatch_port_event(shca, port, IB_EVENT_PORT_ACTIVE,
  308. "is active");
  309. ehca_query_sma_attr(shca, port,
  310. &shca->sport[port - 1].saved_attr);
  311. } else {
  312. shca->sport[port - 1].port_state = IB_PORT_DOWN;
  313. dispatch_port_event(shca, port, IB_EVENT_PORT_ERR,
  314. "is inactive");
  315. }
  316. break;
  317. case 0x31:
  318. /* port configuration change
  319. * disruptive change is caused by
  320. * LID, PKEY or SM change
  321. */
  322. if (EHCA_BMASK_GET(NEQE_DISRUPTIVE, eqe)) {
  323. ehca_warn(&shca->ib_device, "disruptive port "
  324. "%d configuration change", port);
  325. shca->sport[port - 1].port_state = IB_PORT_DOWN;
  326. dispatch_port_event(shca, port, IB_EVENT_PORT_ERR,
  327. "is inactive");
  328. shca->sport[port - 1].port_state = IB_PORT_ACTIVE;
  329. dispatch_port_event(shca, port, IB_EVENT_PORT_ACTIVE,
  330. "is active");
  331. } else
  332. notify_port_conf_change(shca, port);
  333. break;
  334. case 0x32: /* adapter malfunction */
  335. ehca_err(&shca->ib_device, "Adapter malfunction.");
  336. break;
  337. case 0x33: /* trace stopped */
  338. ehca_err(&shca->ib_device, "Traced stopped.");
  339. break;
  340. default:
  341. ehca_err(&shca->ib_device, "Unknown event code: %x on %s.",
  342. ec, shca->ib_device.name);
  343. break;
  344. }
  345. return;
  346. }
  347. static inline void reset_eq_pending(struct ehca_cq *cq)
  348. {
  349. u64 CQx_EP;
  350. struct h_galpa gal = cq->galpas.kernel;
  351. hipz_galpa_store_cq(gal, cqx_ep, 0x0);
  352. CQx_EP = hipz_galpa_load(gal, CQTEMM_OFFSET(cqx_ep));
  353. return;
  354. }
  355. irqreturn_t ehca_interrupt_neq(int irq, void *dev_id)
  356. {
  357. struct ehca_shca *shca = (struct ehca_shca*)dev_id;
  358. tasklet_hi_schedule(&shca->neq.interrupt_task);
  359. return IRQ_HANDLED;
  360. }
  361. void ehca_tasklet_neq(unsigned long data)
  362. {
  363. struct ehca_shca *shca = (struct ehca_shca*)data;
  364. struct ehca_eqe *eqe;
  365. u64 ret;
  366. eqe = (struct ehca_eqe *)ehca_poll_eq(shca, &shca->neq);
  367. while (eqe) {
  368. if (!EHCA_BMASK_GET(NEQE_COMPLETION_EVENT, eqe->entry))
  369. parse_ec(shca, eqe->entry);
  370. eqe = (struct ehca_eqe *)ehca_poll_eq(shca, &shca->neq);
  371. }
  372. ret = hipz_h_reset_event(shca->ipz_hca_handle,
  373. shca->neq.ipz_eq_handle, 0xFFFFFFFFFFFFFFFFL);
  374. if (ret != H_SUCCESS)
  375. ehca_err(&shca->ib_device, "Can't clear notification events.");
  376. return;
  377. }
  378. irqreturn_t ehca_interrupt_eq(int irq, void *dev_id)
  379. {
  380. struct ehca_shca *shca = (struct ehca_shca*)dev_id;
  381. tasklet_hi_schedule(&shca->eq.interrupt_task);
  382. return IRQ_HANDLED;
  383. }
  384. static inline void process_eqe(struct ehca_shca *shca, struct ehca_eqe *eqe)
  385. {
  386. u64 eqe_value;
  387. u32 token;
  388. struct ehca_cq *cq;
  389. eqe_value = eqe->entry;
  390. ehca_dbg(&shca->ib_device, "eqe_value=%lx", eqe_value);
  391. if (EHCA_BMASK_GET(EQE_COMPLETION_EVENT, eqe_value)) {
  392. ehca_dbg(&shca->ib_device, "Got completion event");
  393. token = EHCA_BMASK_GET(EQE_CQ_TOKEN, eqe_value);
  394. read_lock(&ehca_cq_idr_lock);
  395. cq = idr_find(&ehca_cq_idr, token);
  396. if (cq)
  397. atomic_inc(&cq->nr_events);
  398. read_unlock(&ehca_cq_idr_lock);
  399. if (cq == NULL) {
  400. ehca_err(&shca->ib_device,
  401. "Invalid eqe for non-existing cq token=%x",
  402. token);
  403. return;
  404. }
  405. reset_eq_pending(cq);
  406. if (ehca_scaling_code)
  407. queue_comp_task(cq);
  408. else {
  409. comp_event_callback(cq);
  410. if (atomic_dec_and_test(&cq->nr_events))
  411. wake_up(&cq->wait_completion);
  412. }
  413. } else {
  414. ehca_dbg(&shca->ib_device, "Got non completion event");
  415. parse_identifier(shca, eqe_value);
  416. }
  417. }
  418. void ehca_process_eq(struct ehca_shca *shca, int is_irq)
  419. {
  420. struct ehca_eq *eq = &shca->eq;
  421. struct ehca_eqe_cache_entry *eqe_cache = eq->eqe_cache;
  422. u64 eqe_value;
  423. unsigned long flags;
  424. int eqe_cnt, i;
  425. int eq_empty = 0;
  426. spin_lock_irqsave(&eq->irq_spinlock, flags);
  427. if (is_irq) {
  428. const int max_query_cnt = 100;
  429. int query_cnt = 0;
  430. int int_state = 1;
  431. do {
  432. int_state = hipz_h_query_int_state(
  433. shca->ipz_hca_handle, eq->ist);
  434. query_cnt++;
  435. iosync();
  436. } while (int_state && query_cnt < max_query_cnt);
  437. if (unlikely((query_cnt == max_query_cnt)))
  438. ehca_dbg(&shca->ib_device, "int_state=%x query_cnt=%x",
  439. int_state, query_cnt);
  440. }
  441. /* read out all eqes */
  442. eqe_cnt = 0;
  443. do {
  444. u32 token;
  445. eqe_cache[eqe_cnt].eqe =
  446. (struct ehca_eqe *)ehca_poll_eq(shca, eq);
  447. if (!eqe_cache[eqe_cnt].eqe)
  448. break;
  449. eqe_value = eqe_cache[eqe_cnt].eqe->entry;
  450. if (EHCA_BMASK_GET(EQE_COMPLETION_EVENT, eqe_value)) {
  451. token = EHCA_BMASK_GET(EQE_CQ_TOKEN, eqe_value);
  452. read_lock(&ehca_cq_idr_lock);
  453. eqe_cache[eqe_cnt].cq = idr_find(&ehca_cq_idr, token);
  454. if (eqe_cache[eqe_cnt].cq)
  455. atomic_inc(&eqe_cache[eqe_cnt].cq->nr_events);
  456. read_unlock(&ehca_cq_idr_lock);
  457. if (!eqe_cache[eqe_cnt].cq) {
  458. ehca_err(&shca->ib_device,
  459. "Invalid eqe for non-existing cq "
  460. "token=%x", token);
  461. continue;
  462. }
  463. } else
  464. eqe_cache[eqe_cnt].cq = NULL;
  465. eqe_cnt++;
  466. } while (eqe_cnt < EHCA_EQE_CACHE_SIZE);
  467. if (!eqe_cnt) {
  468. if (is_irq)
  469. ehca_dbg(&shca->ib_device,
  470. "No eqe found for irq event");
  471. goto unlock_irq_spinlock;
  472. } else if (!is_irq)
  473. ehca_dbg(&shca->ib_device, "deadman found %x eqe", eqe_cnt);
  474. if (unlikely(eqe_cnt == EHCA_EQE_CACHE_SIZE))
  475. ehca_dbg(&shca->ib_device, "too many eqes for one irq event");
  476. /* enable irq for new packets */
  477. for (i = 0; i < eqe_cnt; i++) {
  478. if (eq->eqe_cache[i].cq)
  479. reset_eq_pending(eq->eqe_cache[i].cq);
  480. }
  481. /* check eq */
  482. spin_lock(&eq->spinlock);
  483. eq_empty = (!ipz_eqit_eq_peek_valid(&shca->eq.ipz_queue));
  484. spin_unlock(&eq->spinlock);
  485. /* call completion handler for cached eqes */
  486. for (i = 0; i < eqe_cnt; i++)
  487. if (eq->eqe_cache[i].cq) {
  488. if (ehca_scaling_code)
  489. queue_comp_task(eq->eqe_cache[i].cq);
  490. else {
  491. struct ehca_cq *cq = eq->eqe_cache[i].cq;
  492. comp_event_callback(cq);
  493. if (atomic_dec_and_test(&cq->nr_events))
  494. wake_up(&cq->wait_completion);
  495. }
  496. } else {
  497. ehca_dbg(&shca->ib_device, "Got non completion event");
  498. parse_identifier(shca, eq->eqe_cache[i].eqe->entry);
  499. }
  500. /* poll eq if not empty */
  501. if (eq_empty)
  502. goto unlock_irq_spinlock;
  503. do {
  504. struct ehca_eqe *eqe;
  505. eqe = (struct ehca_eqe *)ehca_poll_eq(shca, &shca->eq);
  506. if (!eqe)
  507. break;
  508. process_eqe(shca, eqe);
  509. } while (1);
  510. unlock_irq_spinlock:
  511. spin_unlock_irqrestore(&eq->irq_spinlock, flags);
  512. }
  513. void ehca_tasklet_eq(unsigned long data)
  514. {
  515. ehca_process_eq((struct ehca_shca*)data, 1);
  516. }
  517. static inline int find_next_online_cpu(struct ehca_comp_pool *pool)
  518. {
  519. int cpu;
  520. unsigned long flags;
  521. WARN_ON_ONCE(!in_interrupt());
  522. if (ehca_debug_level)
  523. ehca_dmp(&cpu_online_map, sizeof(cpumask_t), "");
  524. spin_lock_irqsave(&pool->last_cpu_lock, flags);
  525. cpu = next_cpu(pool->last_cpu, cpu_online_map);
  526. if (cpu == NR_CPUS)
  527. cpu = first_cpu(cpu_online_map);
  528. pool->last_cpu = cpu;
  529. spin_unlock_irqrestore(&pool->last_cpu_lock, flags);
  530. return cpu;
  531. }
  532. static void __queue_comp_task(struct ehca_cq *__cq,
  533. struct ehca_cpu_comp_task *cct)
  534. {
  535. unsigned long flags;
  536. spin_lock_irqsave(&cct->task_lock, flags);
  537. spin_lock(&__cq->task_lock);
  538. if (__cq->nr_callbacks == 0) {
  539. __cq->nr_callbacks++;
  540. list_add_tail(&__cq->entry, &cct->cq_list);
  541. cct->cq_jobs++;
  542. wake_up(&cct->wait_queue);
  543. } else
  544. __cq->nr_callbacks++;
  545. spin_unlock(&__cq->task_lock);
  546. spin_unlock_irqrestore(&cct->task_lock, flags);
  547. }
  548. static void queue_comp_task(struct ehca_cq *__cq)
  549. {
  550. int cpu_id;
  551. struct ehca_cpu_comp_task *cct;
  552. int cq_jobs;
  553. unsigned long flags;
  554. cpu_id = find_next_online_cpu(pool);
  555. BUG_ON(!cpu_online(cpu_id));
  556. cct = per_cpu_ptr(pool->cpu_comp_tasks, cpu_id);
  557. BUG_ON(!cct);
  558. spin_lock_irqsave(&cct->task_lock, flags);
  559. cq_jobs = cct->cq_jobs;
  560. spin_unlock_irqrestore(&cct->task_lock, flags);
  561. if (cq_jobs > 0) {
  562. cpu_id = find_next_online_cpu(pool);
  563. cct = per_cpu_ptr(pool->cpu_comp_tasks, cpu_id);
  564. BUG_ON(!cct);
  565. }
  566. __queue_comp_task(__cq, cct);
  567. }
  568. static void run_comp_task(struct ehca_cpu_comp_task *cct)
  569. {
  570. struct ehca_cq *cq;
  571. unsigned long flags;
  572. spin_lock_irqsave(&cct->task_lock, flags);
  573. while (!list_empty(&cct->cq_list)) {
  574. cq = list_entry(cct->cq_list.next, struct ehca_cq, entry);
  575. spin_unlock_irqrestore(&cct->task_lock, flags);
  576. comp_event_callback(cq);
  577. if (atomic_dec_and_test(&cq->nr_events))
  578. wake_up(&cq->wait_completion);
  579. spin_lock_irqsave(&cct->task_lock, flags);
  580. spin_lock(&cq->task_lock);
  581. cq->nr_callbacks--;
  582. if (!cq->nr_callbacks) {
  583. list_del_init(cct->cq_list.next);
  584. cct->cq_jobs--;
  585. }
  586. spin_unlock(&cq->task_lock);
  587. }
  588. spin_unlock_irqrestore(&cct->task_lock, flags);
  589. }
  590. static int comp_task(void *__cct)
  591. {
  592. struct ehca_cpu_comp_task *cct = __cct;
  593. int cql_empty;
  594. DECLARE_WAITQUEUE(wait, current);
  595. set_current_state(TASK_INTERRUPTIBLE);
  596. while (!kthread_should_stop()) {
  597. add_wait_queue(&cct->wait_queue, &wait);
  598. spin_lock_irq(&cct->task_lock);
  599. cql_empty = list_empty(&cct->cq_list);
  600. spin_unlock_irq(&cct->task_lock);
  601. if (cql_empty)
  602. schedule();
  603. else
  604. __set_current_state(TASK_RUNNING);
  605. remove_wait_queue(&cct->wait_queue, &wait);
  606. spin_lock_irq(&cct->task_lock);
  607. cql_empty = list_empty(&cct->cq_list);
  608. spin_unlock_irq(&cct->task_lock);
  609. if (!cql_empty)
  610. run_comp_task(__cct);
  611. set_current_state(TASK_INTERRUPTIBLE);
  612. }
  613. __set_current_state(TASK_RUNNING);
  614. return 0;
  615. }
  616. static struct task_struct *create_comp_task(struct ehca_comp_pool *pool,
  617. int cpu)
  618. {
  619. struct ehca_cpu_comp_task *cct;
  620. cct = per_cpu_ptr(pool->cpu_comp_tasks, cpu);
  621. spin_lock_init(&cct->task_lock);
  622. INIT_LIST_HEAD(&cct->cq_list);
  623. init_waitqueue_head(&cct->wait_queue);
  624. cct->task = kthread_create(comp_task, cct, "ehca_comp/%d", cpu);
  625. return cct->task;
  626. }
  627. static void destroy_comp_task(struct ehca_comp_pool *pool,
  628. int cpu)
  629. {
  630. struct ehca_cpu_comp_task *cct;
  631. struct task_struct *task;
  632. unsigned long flags_cct;
  633. cct = per_cpu_ptr(pool->cpu_comp_tasks, cpu);
  634. spin_lock_irqsave(&cct->task_lock, flags_cct);
  635. task = cct->task;
  636. cct->task = NULL;
  637. cct->cq_jobs = 0;
  638. spin_unlock_irqrestore(&cct->task_lock, flags_cct);
  639. if (task)
  640. kthread_stop(task);
  641. }
  642. #ifdef CONFIG_HOTPLUG_CPU
  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. spin_lock_irqsave(&cct->task_lock, flags_cct);
  651. list_splice_init(&cct->cq_list, &list);
  652. while (!list_empty(&list)) {
  653. cq = list_entry(cct->cq_list.next, struct ehca_cq, entry);
  654. list_del(&cq->entry);
  655. __queue_comp_task(cq, per_cpu_ptr(pool->cpu_comp_tasks,
  656. smp_processor_id()));
  657. }
  658. spin_unlock_irqrestore(&cct->task_lock, flags_cct);
  659. }
  660. static int comp_pool_callback(struct notifier_block *nfb,
  661. unsigned long action,
  662. void *hcpu)
  663. {
  664. unsigned int cpu = (unsigned long)hcpu;
  665. struct ehca_cpu_comp_task *cct;
  666. switch (action) {
  667. case CPU_UP_PREPARE:
  668. case CPU_UP_PREPARE_FROZEN:
  669. ehca_gen_dbg("CPU: %x (CPU_PREPARE)", cpu);
  670. if (!create_comp_task(pool, cpu)) {
  671. ehca_gen_err("Can't create comp_task for cpu: %x", cpu);
  672. return NOTIFY_BAD;
  673. }
  674. break;
  675. case CPU_UP_CANCELED:
  676. case CPU_UP_CANCELED_FROZEN:
  677. ehca_gen_dbg("CPU: %x (CPU_CANCELED)", cpu);
  678. cct = per_cpu_ptr(pool->cpu_comp_tasks, cpu);
  679. kthread_bind(cct->task, any_online_cpu(cpu_online_map));
  680. destroy_comp_task(pool, cpu);
  681. break;
  682. case CPU_ONLINE:
  683. case CPU_ONLINE_FROZEN:
  684. ehca_gen_dbg("CPU: %x (CPU_ONLINE)", cpu);
  685. cct = per_cpu_ptr(pool->cpu_comp_tasks, cpu);
  686. kthread_bind(cct->task, cpu);
  687. wake_up_process(cct->task);
  688. break;
  689. case CPU_DOWN_PREPARE:
  690. case CPU_DOWN_PREPARE_FROZEN:
  691. ehca_gen_dbg("CPU: %x (CPU_DOWN_PREPARE)", cpu);
  692. break;
  693. case CPU_DOWN_FAILED:
  694. case CPU_DOWN_FAILED_FROZEN:
  695. ehca_gen_dbg("CPU: %x (CPU_DOWN_FAILED)", cpu);
  696. break;
  697. case CPU_DEAD:
  698. case CPU_DEAD_FROZEN:
  699. ehca_gen_dbg("CPU: %x (CPU_DEAD)", cpu);
  700. destroy_comp_task(pool, cpu);
  701. take_over_work(pool, cpu);
  702. break;
  703. }
  704. return NOTIFY_OK;
  705. }
  706. #endif
  707. int ehca_create_comp_pool(void)
  708. {
  709. int cpu;
  710. struct task_struct *task;
  711. if (!ehca_scaling_code)
  712. return 0;
  713. pool = kzalloc(sizeof(struct ehca_comp_pool), GFP_KERNEL);
  714. if (pool == NULL)
  715. return -ENOMEM;
  716. spin_lock_init(&pool->last_cpu_lock);
  717. pool->last_cpu = any_online_cpu(cpu_online_map);
  718. pool->cpu_comp_tasks = alloc_percpu(struct ehca_cpu_comp_task);
  719. if (pool->cpu_comp_tasks == NULL) {
  720. kfree(pool);
  721. return -EINVAL;
  722. }
  723. for_each_online_cpu(cpu) {
  724. task = create_comp_task(pool, cpu);
  725. if (task) {
  726. kthread_bind(task, cpu);
  727. wake_up_process(task);
  728. }
  729. }
  730. #ifdef CONFIG_HOTPLUG_CPU
  731. comp_pool_callback_nb.notifier_call = comp_pool_callback;
  732. comp_pool_callback_nb.priority = 0;
  733. register_cpu_notifier(&comp_pool_callback_nb);
  734. #endif
  735. printk(KERN_INFO "eHCA scaling code enabled\n");
  736. return 0;
  737. }
  738. void ehca_destroy_comp_pool(void)
  739. {
  740. int i;
  741. if (!ehca_scaling_code)
  742. return;
  743. #ifdef CONFIG_HOTPLUG_CPU
  744. unregister_cpu_notifier(&comp_pool_callback_nb);
  745. #endif
  746. for (i = 0; i < NR_CPUS; i++) {
  747. if (cpu_online(i))
  748. destroy_comp_task(pool, i);
  749. }
  750. free_percpu(pool->cpu_comp_tasks);
  751. kfree(pool);
  752. }