qman_test_stash.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628
  1. /* Copyright 2009 - 2016 Freescale Semiconductor, Inc.
  2. *
  3. * Redistribution and use in source and binary forms, with or without
  4. * modification, are permitted provided that the following conditions are met:
  5. * * Redistributions of source code must retain the above copyright
  6. * notice, this list of conditions and the following disclaimer.
  7. * * Redistributions in binary form must reproduce the above copyright
  8. * notice, this list of conditions and the following disclaimer in the
  9. * documentation and/or other materials provided with the distribution.
  10. * * Neither the name of Freescale Semiconductor nor the
  11. * names of its contributors may be used to endorse or promote products
  12. * derived from this software without specific prior written permission.
  13. *
  14. * ALTERNATIVELY, this software may be distributed under the terms of the
  15. * GNU General Public License ("GPL") as published by the Free Software
  16. * Foundation, either version 2 of that License or (at your option) any
  17. * later version.
  18. *
  19. * THIS SOFTWARE IS PROVIDED BY Freescale Semiconductor ``AS IS'' AND ANY
  20. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  21. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  22. * DISCLAIMED. IN NO EVENT SHALL Freescale Semiconductor BE LIABLE FOR ANY
  23. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  24. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  25. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  26. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  27. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  28. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29. */
  30. #include "qman_test.h"
  31. #include <linux/dma-mapping.h>
  32. #include <linux/delay.h>
  33. /*
  34. * Algorithm:
  35. *
  36. * Each cpu will have HP_PER_CPU "handlers" set up, each of which incorporates
  37. * an rx/tx pair of FQ objects (both of which are stashed on dequeue). The
  38. * organisation of FQIDs is such that the HP_PER_CPU*NUM_CPUS handlers will
  39. * shuttle a "hot potato" frame around them such that every forwarding action
  40. * moves it from one cpu to another. (The use of more than one handler per cpu
  41. * is to allow enough handlers/FQs to truly test the significance of caching -
  42. * ie. when cache-expiries are occurring.)
  43. *
  44. * The "hot potato" frame content will be HP_NUM_WORDS*4 bytes in size, and the
  45. * first and last words of the frame data will undergo a transformation step on
  46. * each forwarding action. To achieve this, each handler will be assigned a
  47. * 32-bit "mixer", that is produced using a 32-bit LFSR. When a frame is
  48. * received by a handler, the mixer of the expected sender is XOR'd into all
  49. * words of the entire frame, which is then validated against the original
  50. * values. Then, before forwarding, the entire frame is XOR'd with the mixer of
  51. * the current handler. Apart from validating that the frame is taking the
  52. * expected path, this also provides some quasi-realistic overheads to each
  53. * forwarding action - dereferencing *all* the frame data, computation, and
  54. * conditional branching. There is a "special" handler designated to act as the
  55. * instigator of the test by creating an enqueuing the "hot potato" frame, and
  56. * to determine when the test has completed by counting HP_LOOPS iterations.
  57. *
  58. * Init phases:
  59. *
  60. * 1. prepare each cpu's 'hp_cpu' struct using on_each_cpu(,,1) and link them
  61. * into 'hp_cpu_list'. Specifically, set processor_id, allocate HP_PER_CPU
  62. * handlers and link-list them (but do no other handler setup).
  63. *
  64. * 2. scan over 'hp_cpu_list' HP_PER_CPU times, the first time sets each
  65. * hp_cpu's 'iterator' to point to its first handler. With each loop,
  66. * allocate rx/tx FQIDs and mixer values to the hp_cpu's iterator handler
  67. * and advance the iterator for the next loop. This includes a final fixup,
  68. * which connects the last handler to the first (and which is why phase 2
  69. * and 3 are separate).
  70. *
  71. * 3. scan over 'hp_cpu_list' HP_PER_CPU times, the first time sets each
  72. * hp_cpu's 'iterator' to point to its first handler. With each loop,
  73. * initialise FQ objects and advance the iterator for the next loop.
  74. * Moreover, do this initialisation on the cpu it applies to so that Rx FQ
  75. * initialisation targets the correct cpu.
  76. */
  77. /*
  78. * helper to run something on all cpus (can't use on_each_cpu(), as that invokes
  79. * the fn from irq context, which is too restrictive).
  80. */
  81. struct bstrap {
  82. int (*fn)(void);
  83. atomic_t started;
  84. };
  85. static int bstrap_fn(void *bs)
  86. {
  87. struct bstrap *bstrap = bs;
  88. int err;
  89. atomic_inc(&bstrap->started);
  90. err = bstrap->fn();
  91. if (err)
  92. return err;
  93. while (!kthread_should_stop())
  94. msleep(20);
  95. return 0;
  96. }
  97. static int on_all_cpus(int (*fn)(void))
  98. {
  99. int cpu;
  100. for_each_cpu(cpu, cpu_online_mask) {
  101. struct bstrap bstrap = {
  102. .fn = fn,
  103. .started = ATOMIC_INIT(0)
  104. };
  105. struct task_struct *k = kthread_create(bstrap_fn, &bstrap,
  106. "hotpotato%d", cpu);
  107. int ret;
  108. if (IS_ERR(k))
  109. return -ENOMEM;
  110. kthread_bind(k, cpu);
  111. wake_up_process(k);
  112. /*
  113. * If we call kthread_stop() before the "wake up" has had an
  114. * effect, then the thread may exit with -EINTR without ever
  115. * running the function. So poll until it's started before
  116. * requesting it to stop.
  117. */
  118. while (!atomic_read(&bstrap.started))
  119. msleep(20);
  120. ret = kthread_stop(k);
  121. if (ret)
  122. return ret;
  123. }
  124. return 0;
  125. }
  126. struct hp_handler {
  127. /* The following data is stashed when 'rx' is dequeued; */
  128. /* -------------- */
  129. /* The Rx FQ, dequeues of which will stash the entire hp_handler */
  130. struct qman_fq rx;
  131. /* The Tx FQ we should forward to */
  132. struct qman_fq tx;
  133. /* The value we XOR post-dequeue, prior to validating */
  134. u32 rx_mixer;
  135. /* The value we XOR pre-enqueue, after validating */
  136. u32 tx_mixer;
  137. /* what the hotpotato address should be on dequeue */
  138. dma_addr_t addr;
  139. u32 *frame_ptr;
  140. /* The following data isn't (necessarily) stashed on dequeue; */
  141. /* -------------- */
  142. u32 fqid_rx, fqid_tx;
  143. /* list node for linking us into 'hp_cpu' */
  144. struct list_head node;
  145. /* Just to check ... */
  146. unsigned int processor_id;
  147. } ____cacheline_aligned;
  148. struct hp_cpu {
  149. /* identify the cpu we run on; */
  150. unsigned int processor_id;
  151. /* root node for the per-cpu list of handlers */
  152. struct list_head handlers;
  153. /* list node for linking us into 'hp_cpu_list' */
  154. struct list_head node;
  155. /*
  156. * when repeatedly scanning 'hp_list', each time linking the n'th
  157. * handlers together, this is used as per-cpu iterator state
  158. */
  159. struct hp_handler *iterator;
  160. };
  161. /* Each cpu has one of these */
  162. static DEFINE_PER_CPU(struct hp_cpu, hp_cpus);
  163. /* links together the hp_cpu structs, in first-come first-serve order. */
  164. static LIST_HEAD(hp_cpu_list);
  165. static DEFINE_SPINLOCK(hp_lock);
  166. static unsigned int hp_cpu_list_length;
  167. /* the "special" handler, that starts and terminates the test. */
  168. static struct hp_handler *special_handler;
  169. static int loop_counter;
  170. /* handlers are allocated out of this, so they're properly aligned. */
  171. static struct kmem_cache *hp_handler_slab;
  172. /* this is the frame data */
  173. static void *__frame_ptr;
  174. static u32 *frame_ptr;
  175. static dma_addr_t frame_dma;
  176. /* needed for dma_map*() */
  177. static const struct qm_portal_config *pcfg;
  178. /* the main function waits on this */
  179. static DECLARE_WAIT_QUEUE_HEAD(queue);
  180. #define HP_PER_CPU 2
  181. #define HP_LOOPS 8
  182. /* 80 bytes, like a small ethernet frame, and bleeds into a second cacheline */
  183. #define HP_NUM_WORDS 80
  184. /* First word of the LFSR-based frame data */
  185. #define HP_FIRST_WORD 0xabbaf00d
  186. static inline u32 do_lfsr(u32 prev)
  187. {
  188. return (prev >> 1) ^ (-(prev & 1u) & 0xd0000001u);
  189. }
  190. static int allocate_frame_data(void)
  191. {
  192. u32 lfsr = HP_FIRST_WORD;
  193. int loop;
  194. if (!qman_dma_portal) {
  195. pr_crit("portal not available\n");
  196. return -EIO;
  197. }
  198. pcfg = qman_get_qm_portal_config(qman_dma_portal);
  199. __frame_ptr = kmalloc(4 * HP_NUM_WORDS, GFP_KERNEL);
  200. if (!__frame_ptr)
  201. return -ENOMEM;
  202. frame_ptr = PTR_ALIGN(__frame_ptr, 64);
  203. for (loop = 0; loop < HP_NUM_WORDS; loop++) {
  204. frame_ptr[loop] = lfsr;
  205. lfsr = do_lfsr(lfsr);
  206. }
  207. frame_dma = dma_map_single(pcfg->dev, frame_ptr, 4 * HP_NUM_WORDS,
  208. DMA_BIDIRECTIONAL);
  209. if (dma_mapping_error(pcfg->dev, frame_dma)) {
  210. pr_crit("dma mapping failure\n");
  211. kfree(__frame_ptr);
  212. return -EIO;
  213. }
  214. return 0;
  215. }
  216. static void deallocate_frame_data(void)
  217. {
  218. dma_unmap_single(pcfg->dev, frame_dma, 4 * HP_NUM_WORDS,
  219. DMA_BIDIRECTIONAL);
  220. kfree(__frame_ptr);
  221. }
  222. static inline int process_frame_data(struct hp_handler *handler,
  223. const struct qm_fd *fd)
  224. {
  225. u32 *p = handler->frame_ptr;
  226. u32 lfsr = HP_FIRST_WORD;
  227. int loop;
  228. if (qm_fd_addr_get64(fd) != handler->addr) {
  229. pr_crit("bad frame address, [%llX != %llX]\n",
  230. qm_fd_addr_get64(fd), handler->addr);
  231. return -EIO;
  232. }
  233. for (loop = 0; loop < HP_NUM_WORDS; loop++, p++) {
  234. *p ^= handler->rx_mixer;
  235. if (*p != lfsr) {
  236. pr_crit("corrupt frame data");
  237. return -EIO;
  238. }
  239. *p ^= handler->tx_mixer;
  240. lfsr = do_lfsr(lfsr);
  241. }
  242. return 0;
  243. }
  244. static enum qman_cb_dqrr_result normal_dqrr(struct qman_portal *portal,
  245. struct qman_fq *fq,
  246. const struct qm_dqrr_entry *dqrr)
  247. {
  248. struct hp_handler *handler = (struct hp_handler *)fq;
  249. if (process_frame_data(handler, &dqrr->fd)) {
  250. WARN_ON(1);
  251. goto skip;
  252. }
  253. if (qman_enqueue(&handler->tx, &dqrr->fd)) {
  254. pr_crit("qman_enqueue() failed");
  255. WARN_ON(1);
  256. }
  257. skip:
  258. return qman_cb_dqrr_consume;
  259. }
  260. static enum qman_cb_dqrr_result special_dqrr(struct qman_portal *portal,
  261. struct qman_fq *fq,
  262. const struct qm_dqrr_entry *dqrr)
  263. {
  264. struct hp_handler *handler = (struct hp_handler *)fq;
  265. process_frame_data(handler, &dqrr->fd);
  266. if (++loop_counter < HP_LOOPS) {
  267. if (qman_enqueue(&handler->tx, &dqrr->fd)) {
  268. pr_crit("qman_enqueue() failed");
  269. WARN_ON(1);
  270. goto skip;
  271. }
  272. } else {
  273. pr_info("Received final (%dth) frame\n", loop_counter);
  274. wake_up(&queue);
  275. }
  276. skip:
  277. return qman_cb_dqrr_consume;
  278. }
  279. static int create_per_cpu_handlers(void)
  280. {
  281. struct hp_handler *handler;
  282. int loop;
  283. struct hp_cpu *hp_cpu = this_cpu_ptr(&hp_cpus);
  284. hp_cpu->processor_id = smp_processor_id();
  285. spin_lock(&hp_lock);
  286. list_add_tail(&hp_cpu->node, &hp_cpu_list);
  287. hp_cpu_list_length++;
  288. spin_unlock(&hp_lock);
  289. INIT_LIST_HEAD(&hp_cpu->handlers);
  290. for (loop = 0; loop < HP_PER_CPU; loop++) {
  291. handler = kmem_cache_alloc(hp_handler_slab, GFP_KERNEL);
  292. if (!handler) {
  293. pr_crit("kmem_cache_alloc() failed");
  294. WARN_ON(1);
  295. return -EIO;
  296. }
  297. handler->processor_id = hp_cpu->processor_id;
  298. handler->addr = frame_dma;
  299. handler->frame_ptr = frame_ptr;
  300. list_add_tail(&handler->node, &hp_cpu->handlers);
  301. }
  302. return 0;
  303. }
  304. static int destroy_per_cpu_handlers(void)
  305. {
  306. struct list_head *loop, *tmp;
  307. struct hp_cpu *hp_cpu = this_cpu_ptr(&hp_cpus);
  308. spin_lock(&hp_lock);
  309. list_del(&hp_cpu->node);
  310. spin_unlock(&hp_lock);
  311. list_for_each_safe(loop, tmp, &hp_cpu->handlers) {
  312. u32 flags = 0;
  313. struct hp_handler *handler = list_entry(loop, struct hp_handler,
  314. node);
  315. if (qman_retire_fq(&handler->rx, &flags) ||
  316. (flags & QMAN_FQ_STATE_BLOCKOOS)) {
  317. pr_crit("qman_retire_fq(rx) failed, flags: %x", flags);
  318. WARN_ON(1);
  319. return -EIO;
  320. }
  321. if (qman_oos_fq(&handler->rx)) {
  322. pr_crit("qman_oos_fq(rx) failed");
  323. WARN_ON(1);
  324. return -EIO;
  325. }
  326. qman_destroy_fq(&handler->rx);
  327. qman_destroy_fq(&handler->tx);
  328. qman_release_fqid(handler->fqid_rx);
  329. list_del(&handler->node);
  330. kmem_cache_free(hp_handler_slab, handler);
  331. }
  332. return 0;
  333. }
  334. static inline u8 num_cachelines(u32 offset)
  335. {
  336. u8 res = (offset + (L1_CACHE_BYTES - 1))
  337. / (L1_CACHE_BYTES);
  338. if (res > 3)
  339. return 3;
  340. return res;
  341. }
  342. #define STASH_DATA_CL \
  343. num_cachelines(HP_NUM_WORDS * 4)
  344. #define STASH_CTX_CL \
  345. num_cachelines(offsetof(struct hp_handler, fqid_rx))
  346. static int init_handler(void *h)
  347. {
  348. struct qm_mcc_initfq opts;
  349. struct hp_handler *handler = h;
  350. int err;
  351. if (handler->processor_id != smp_processor_id()) {
  352. err = -EIO;
  353. goto failed;
  354. }
  355. /* Set up rx */
  356. memset(&handler->rx, 0, sizeof(handler->rx));
  357. if (handler == special_handler)
  358. handler->rx.cb.dqrr = special_dqrr;
  359. else
  360. handler->rx.cb.dqrr = normal_dqrr;
  361. err = qman_create_fq(handler->fqid_rx, 0, &handler->rx);
  362. if (err) {
  363. pr_crit("qman_create_fq(rx) failed");
  364. goto failed;
  365. }
  366. memset(&opts, 0, sizeof(opts));
  367. opts.we_mask = cpu_to_be16(QM_INITFQ_WE_FQCTRL |
  368. QM_INITFQ_WE_CONTEXTA);
  369. opts.fqd.fq_ctrl = cpu_to_be16(QM_FQCTRL_CTXASTASHING);
  370. qm_fqd_set_stashing(&opts.fqd, 0, STASH_DATA_CL, STASH_CTX_CL);
  371. err = qman_init_fq(&handler->rx, QMAN_INITFQ_FLAG_SCHED |
  372. QMAN_INITFQ_FLAG_LOCAL, &opts);
  373. if (err) {
  374. pr_crit("qman_init_fq(rx) failed");
  375. goto failed;
  376. }
  377. /* Set up tx */
  378. memset(&handler->tx, 0, sizeof(handler->tx));
  379. err = qman_create_fq(handler->fqid_tx, QMAN_FQ_FLAG_NO_MODIFY,
  380. &handler->tx);
  381. if (err) {
  382. pr_crit("qman_create_fq(tx) failed");
  383. goto failed;
  384. }
  385. return 0;
  386. failed:
  387. return err;
  388. }
  389. static void init_handler_cb(void *h)
  390. {
  391. if (init_handler(h))
  392. WARN_ON(1);
  393. }
  394. static int init_phase2(void)
  395. {
  396. int loop;
  397. u32 fqid = 0;
  398. u32 lfsr = 0xdeadbeef;
  399. struct hp_cpu *hp_cpu;
  400. struct hp_handler *handler;
  401. for (loop = 0; loop < HP_PER_CPU; loop++) {
  402. list_for_each_entry(hp_cpu, &hp_cpu_list, node) {
  403. int err;
  404. if (!loop)
  405. hp_cpu->iterator = list_first_entry(
  406. &hp_cpu->handlers,
  407. struct hp_handler, node);
  408. else
  409. hp_cpu->iterator = list_entry(
  410. hp_cpu->iterator->node.next,
  411. struct hp_handler, node);
  412. /* Rx FQID is the previous handler's Tx FQID */
  413. hp_cpu->iterator->fqid_rx = fqid;
  414. /* Allocate new FQID for Tx */
  415. err = qman_alloc_fqid(&fqid);
  416. if (err) {
  417. pr_crit("qman_alloc_fqid() failed");
  418. return err;
  419. }
  420. hp_cpu->iterator->fqid_tx = fqid;
  421. /* Rx mixer is the previous handler's Tx mixer */
  422. hp_cpu->iterator->rx_mixer = lfsr;
  423. /* Get new mixer for Tx */
  424. lfsr = do_lfsr(lfsr);
  425. hp_cpu->iterator->tx_mixer = lfsr;
  426. }
  427. }
  428. /* Fix up the first handler (fqid_rx==0, rx_mixer=0xdeadbeef) */
  429. hp_cpu = list_first_entry(&hp_cpu_list, struct hp_cpu, node);
  430. handler = list_first_entry(&hp_cpu->handlers, struct hp_handler, node);
  431. if (handler->fqid_rx != 0 || handler->rx_mixer != 0xdeadbeef)
  432. return 1;
  433. handler->fqid_rx = fqid;
  434. handler->rx_mixer = lfsr;
  435. /* and tag it as our "special" handler */
  436. special_handler = handler;
  437. return 0;
  438. }
  439. static int init_phase3(void)
  440. {
  441. int loop, err;
  442. struct hp_cpu *hp_cpu;
  443. for (loop = 0; loop < HP_PER_CPU; loop++) {
  444. list_for_each_entry(hp_cpu, &hp_cpu_list, node) {
  445. if (!loop)
  446. hp_cpu->iterator = list_first_entry(
  447. &hp_cpu->handlers,
  448. struct hp_handler, node);
  449. else
  450. hp_cpu->iterator = list_entry(
  451. hp_cpu->iterator->node.next,
  452. struct hp_handler, node);
  453. preempt_disable();
  454. if (hp_cpu->processor_id == smp_processor_id()) {
  455. err = init_handler(hp_cpu->iterator);
  456. if (err)
  457. return err;
  458. } else {
  459. smp_call_function_single(hp_cpu->processor_id,
  460. init_handler_cb, hp_cpu->iterator, 1);
  461. }
  462. preempt_enable();
  463. }
  464. }
  465. return 0;
  466. }
  467. static int send_first_frame(void *ignore)
  468. {
  469. u32 *p = special_handler->frame_ptr;
  470. u32 lfsr = HP_FIRST_WORD;
  471. int loop, err;
  472. struct qm_fd fd;
  473. if (special_handler->processor_id != smp_processor_id()) {
  474. err = -EIO;
  475. goto failed;
  476. }
  477. memset(&fd, 0, sizeof(fd));
  478. qm_fd_addr_set64(&fd, special_handler->addr);
  479. qm_fd_set_contig_big(&fd, HP_NUM_WORDS * 4);
  480. for (loop = 0; loop < HP_NUM_WORDS; loop++, p++) {
  481. if (*p != lfsr) {
  482. err = -EIO;
  483. pr_crit("corrupt frame data");
  484. goto failed;
  485. }
  486. *p ^= special_handler->tx_mixer;
  487. lfsr = do_lfsr(lfsr);
  488. }
  489. pr_info("Sending first frame\n");
  490. err = qman_enqueue(&special_handler->tx, &fd);
  491. if (err) {
  492. pr_crit("qman_enqueue() failed");
  493. goto failed;
  494. }
  495. return 0;
  496. failed:
  497. return err;
  498. }
  499. static void send_first_frame_cb(void *ignore)
  500. {
  501. if (send_first_frame(NULL))
  502. WARN_ON(1);
  503. }
  504. int qman_test_stash(void)
  505. {
  506. int err;
  507. if (cpumask_weight(cpu_online_mask) < 2) {
  508. pr_info("%s(): skip - only 1 CPU\n", __func__);
  509. return 0;
  510. }
  511. pr_info("%s(): Starting\n", __func__);
  512. hp_cpu_list_length = 0;
  513. loop_counter = 0;
  514. hp_handler_slab = kmem_cache_create("hp_handler_slab",
  515. sizeof(struct hp_handler), L1_CACHE_BYTES,
  516. SLAB_HWCACHE_ALIGN, NULL);
  517. if (!hp_handler_slab) {
  518. err = -EIO;
  519. pr_crit("kmem_cache_create() failed");
  520. goto failed;
  521. }
  522. err = allocate_frame_data();
  523. if (err)
  524. goto failed;
  525. /* Init phase 1 */
  526. pr_info("Creating %d handlers per cpu...\n", HP_PER_CPU);
  527. if (on_all_cpus(create_per_cpu_handlers)) {
  528. err = -EIO;
  529. pr_crit("on_each_cpu() failed");
  530. goto failed;
  531. }
  532. pr_info("Number of cpus: %d, total of %d handlers\n",
  533. hp_cpu_list_length, hp_cpu_list_length * HP_PER_CPU);
  534. err = init_phase2();
  535. if (err)
  536. goto failed;
  537. err = init_phase3();
  538. if (err)
  539. goto failed;
  540. preempt_disable();
  541. if (special_handler->processor_id == smp_processor_id()) {
  542. err = send_first_frame(NULL);
  543. if (err)
  544. goto failed;
  545. } else {
  546. smp_call_function_single(special_handler->processor_id,
  547. send_first_frame_cb, NULL, 1);
  548. }
  549. preempt_enable();
  550. wait_event(queue, loop_counter == HP_LOOPS);
  551. deallocate_frame_data();
  552. if (on_all_cpus(destroy_per_cpu_handlers)) {
  553. err = -EIO;
  554. pr_crit("on_each_cpu() failed");
  555. goto failed;
  556. }
  557. kmem_cache_destroy(hp_handler_slab);
  558. pr_info("%s(): Finished\n", __func__);
  559. return 0;
  560. failed:
  561. WARN_ON(1);
  562. return err;
  563. }