ap_bus.c 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221
  1. /*
  2. * linux/drivers/s390/crypto/ap_bus.c
  3. *
  4. * Copyright (C) 2006 IBM Corporation
  5. * Author(s): Cornelia Huck <cornelia.huck@de.ibm.com>
  6. * Martin Schwidefsky <schwidefsky@de.ibm.com>
  7. * Ralph Wuerthner <rwuerthn@de.ibm.com>
  8. *
  9. * Adjunct processor bus.
  10. *
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License as published by
  13. * the Free Software Foundation; either version 2, or (at your option)
  14. * any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program; if not, write to the Free Software
  23. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  24. */
  25. #include <linux/module.h>
  26. #include <linux/init.h>
  27. #include <linux/delay.h>
  28. #include <linux/err.h>
  29. #include <linux/interrupt.h>
  30. #include <linux/workqueue.h>
  31. #include <linux/notifier.h>
  32. #include <linux/kthread.h>
  33. #include <linux/mutex.h>
  34. #include <asm/s390_rdev.h>
  35. #include "ap_bus.h"
  36. /* Some prototypes. */
  37. static void ap_scan_bus(void *);
  38. static void ap_poll_all(unsigned long);
  39. static void ap_poll_timeout(unsigned long);
  40. static int ap_poll_thread_start(void);
  41. static void ap_poll_thread_stop(void);
  42. /**
  43. * Module description.
  44. */
  45. MODULE_AUTHOR("IBM Corporation");
  46. MODULE_DESCRIPTION("Adjunct Processor Bus driver, "
  47. "Copyright 2006 IBM Corporation");
  48. MODULE_LICENSE("GPL");
  49. /**
  50. * Module parameter
  51. */
  52. int ap_domain_index = -1; /* Adjunct Processor Domain Index */
  53. module_param_named(domain, ap_domain_index, int, 0000);
  54. MODULE_PARM_DESC(domain, "domain index for ap devices");
  55. EXPORT_SYMBOL(ap_domain_index);
  56. static int ap_thread_flag = 1;
  57. module_param_named(poll_thread, ap_thread_flag, int, 0000);
  58. MODULE_PARM_DESC(poll_thread, "Turn on/off poll thread, default is 1 (on).");
  59. static struct device *ap_root_device = NULL;
  60. /**
  61. * Workqueue & timer for bus rescan.
  62. */
  63. static struct workqueue_struct *ap_work_queue;
  64. static struct timer_list ap_config_timer;
  65. static int ap_config_time = AP_CONFIG_TIME;
  66. static DECLARE_WORK(ap_config_work, ap_scan_bus, NULL);
  67. /**
  68. * Tasklet & timer for AP request polling.
  69. */
  70. static struct timer_list ap_poll_timer = TIMER_INITIALIZER(ap_poll_timeout,0,0);
  71. static DECLARE_TASKLET(ap_tasklet, ap_poll_all, 0);
  72. static atomic_t ap_poll_requests = ATOMIC_INIT(0);
  73. static DECLARE_WAIT_QUEUE_HEAD(ap_poll_wait);
  74. static struct task_struct *ap_poll_kthread = NULL;
  75. static DEFINE_MUTEX(ap_poll_thread_mutex);
  76. /**
  77. * Test if ap instructions are available.
  78. *
  79. * Returns 0 if the ap instructions are installed.
  80. */
  81. static inline int ap_instructions_available(void)
  82. {
  83. register unsigned long reg0 asm ("0") = AP_MKQID(0,0);
  84. register unsigned long reg1 asm ("1") = -ENODEV;
  85. register unsigned long reg2 asm ("2") = 0UL;
  86. asm volatile(
  87. " .long 0xb2af0000\n" /* PQAP(TAPQ) */
  88. "0: la %1,0\n"
  89. "1:\n"
  90. EX_TABLE(0b, 1b)
  91. : "+d" (reg0), "+d" (reg1), "+d" (reg2) : : "cc" );
  92. return reg1;
  93. }
  94. /**
  95. * Test adjunct processor queue.
  96. * @qid: the ap queue number
  97. * @queue_depth: pointer to queue depth value
  98. * @device_type: pointer to device type value
  99. *
  100. * Returns ap queue status structure.
  101. */
  102. static inline struct ap_queue_status
  103. ap_test_queue(ap_qid_t qid, int *queue_depth, int *device_type)
  104. {
  105. register unsigned long reg0 asm ("0") = qid;
  106. register struct ap_queue_status reg1 asm ("1");
  107. register unsigned long reg2 asm ("2") = 0UL;
  108. asm volatile(".long 0xb2af0000" /* PQAP(TAPQ) */
  109. : "+d" (reg0), "=d" (reg1), "+d" (reg2) : : "cc");
  110. *device_type = (int) (reg2 >> 24);
  111. *queue_depth = (int) (reg2 & 0xff);
  112. return reg1;
  113. }
  114. /**
  115. * Reset adjunct processor queue.
  116. * @qid: the ap queue number
  117. *
  118. * Returns ap queue status structure.
  119. */
  120. static inline struct ap_queue_status ap_reset_queue(ap_qid_t qid)
  121. {
  122. register unsigned long reg0 asm ("0") = qid | 0x01000000UL;
  123. register struct ap_queue_status reg1 asm ("1");
  124. register unsigned long reg2 asm ("2") = 0UL;
  125. asm volatile(
  126. ".long 0xb2af0000" /* PQAP(RAPQ) */
  127. : "+d" (reg0), "=d" (reg1), "+d" (reg2) : : "cc");
  128. return reg1;
  129. }
  130. /**
  131. * Send message to adjunct processor queue.
  132. * @qid: the ap queue number
  133. * @psmid: the program supplied message identifier
  134. * @msg: the message text
  135. * @length: the message length
  136. *
  137. * Returns ap queue status structure.
  138. *
  139. * Condition code 1 on NQAP can't happen because the L bit is 1.
  140. *
  141. * Condition code 2 on NQAP also means the send is incomplete,
  142. * because a segment boundary was reached. The NQAP is repeated.
  143. */
  144. static inline struct ap_queue_status
  145. __ap_send(ap_qid_t qid, unsigned long long psmid, void *msg, size_t length)
  146. {
  147. typedef struct { char _[length]; } msgblock;
  148. register unsigned long reg0 asm ("0") = qid | 0x40000000UL;
  149. register struct ap_queue_status reg1 asm ("1");
  150. register unsigned long reg2 asm ("2") = (unsigned long) msg;
  151. register unsigned long reg3 asm ("3") = (unsigned long) length;
  152. register unsigned long reg4 asm ("4") = (unsigned int) (psmid >> 32);
  153. register unsigned long reg5 asm ("5") = (unsigned int) psmid;
  154. asm volatile (
  155. "0: .long 0xb2ad0042\n" /* DQAP */
  156. " brc 2,0b"
  157. : "+d" (reg0), "=d" (reg1), "+d" (reg2), "+d" (reg3)
  158. : "d" (reg4), "d" (reg5), "m" (*(msgblock *) msg)
  159. : "cc" );
  160. return reg1;
  161. }
  162. int ap_send(ap_qid_t qid, unsigned long long psmid, void *msg, size_t length)
  163. {
  164. struct ap_queue_status status;
  165. status = __ap_send(qid, psmid, msg, length);
  166. switch (status.response_code) {
  167. case AP_RESPONSE_NORMAL:
  168. return 0;
  169. case AP_RESPONSE_Q_FULL:
  170. return -EBUSY;
  171. default: /* Device is gone. */
  172. return -ENODEV;
  173. }
  174. }
  175. EXPORT_SYMBOL(ap_send);
  176. /*
  177. * Receive message from adjunct processor queue.
  178. * @qid: the ap queue number
  179. * @psmid: pointer to program supplied message identifier
  180. * @msg: the message text
  181. * @length: the message length
  182. *
  183. * Returns ap queue status structure.
  184. *
  185. * Condition code 1 on DQAP means the receive has taken place
  186. * but only partially. The response is incomplete, hence the
  187. * DQAP is repeated.
  188. *
  189. * Condition code 2 on DQAP also means the receive is incomplete,
  190. * this time because a segment boundary was reached. Again, the
  191. * DQAP is repeated.
  192. *
  193. * Note that gpr2 is used by the DQAP instruction to keep track of
  194. * any 'residual' length, in case the instruction gets interrupted.
  195. * Hence it gets zeroed before the instruction.
  196. */
  197. static inline struct ap_queue_status
  198. __ap_recv(ap_qid_t qid, unsigned long long *psmid, void *msg, size_t length)
  199. {
  200. typedef struct { char _[length]; } msgblock;
  201. register unsigned long reg0 asm("0") = qid | 0x80000000UL;
  202. register struct ap_queue_status reg1 asm ("1");
  203. register unsigned long reg2 asm("2") = 0UL;
  204. register unsigned long reg4 asm("4") = (unsigned long) msg;
  205. register unsigned long reg5 asm("5") = (unsigned long) length;
  206. register unsigned long reg6 asm("6") = 0UL;
  207. register unsigned long reg7 asm("7") = 0UL;
  208. asm volatile(
  209. "0: .long 0xb2ae0064\n"
  210. " brc 6,0b\n"
  211. : "+d" (reg0), "=d" (reg1), "+d" (reg2),
  212. "+d" (reg4), "+d" (reg5), "+d" (reg6), "+d" (reg7),
  213. "=m" (*(msgblock *) msg) : : "cc" );
  214. *psmid = (((unsigned long long) reg6) << 32) + reg7;
  215. return reg1;
  216. }
  217. int ap_recv(ap_qid_t qid, unsigned long long *psmid, void *msg, size_t length)
  218. {
  219. struct ap_queue_status status;
  220. status = __ap_recv(qid, psmid, msg, length);
  221. switch (status.response_code) {
  222. case AP_RESPONSE_NORMAL:
  223. return 0;
  224. case AP_RESPONSE_NO_PENDING_REPLY:
  225. if (status.queue_empty)
  226. return -ENOENT;
  227. return -EBUSY;
  228. default:
  229. return -ENODEV;
  230. }
  231. }
  232. EXPORT_SYMBOL(ap_recv);
  233. /**
  234. * Check if an AP queue is available. The test is repeated for
  235. * AP_MAX_RESET times.
  236. * @qid: the ap queue number
  237. * @queue_depth: pointer to queue depth value
  238. * @device_type: pointer to device type value
  239. */
  240. static int ap_query_queue(ap_qid_t qid, int *queue_depth, int *device_type)
  241. {
  242. struct ap_queue_status status;
  243. int t_depth, t_device_type, rc, i;
  244. rc = -EBUSY;
  245. for (i = 0; i < AP_MAX_RESET; i++) {
  246. status = ap_test_queue(qid, &t_depth, &t_device_type);
  247. switch (status.response_code) {
  248. case AP_RESPONSE_NORMAL:
  249. *queue_depth = t_depth + 1;
  250. *device_type = t_device_type;
  251. rc = 0;
  252. break;
  253. case AP_RESPONSE_Q_NOT_AVAIL:
  254. rc = -ENODEV;
  255. break;
  256. case AP_RESPONSE_RESET_IN_PROGRESS:
  257. break;
  258. case AP_RESPONSE_DECONFIGURED:
  259. rc = -ENODEV;
  260. break;
  261. case AP_RESPONSE_CHECKSTOPPED:
  262. rc = -ENODEV;
  263. break;
  264. case AP_RESPONSE_BUSY:
  265. break;
  266. default:
  267. BUG();
  268. }
  269. if (rc != -EBUSY)
  270. break;
  271. if (i < AP_MAX_RESET - 1)
  272. udelay(5);
  273. }
  274. return rc;
  275. }
  276. /**
  277. * Reset an AP queue and wait for it to become available again.
  278. * @qid: the ap queue number
  279. */
  280. static int ap_init_queue(ap_qid_t qid)
  281. {
  282. struct ap_queue_status status;
  283. int rc, dummy, i;
  284. rc = -ENODEV;
  285. status = ap_reset_queue(qid);
  286. for (i = 0; i < AP_MAX_RESET; i++) {
  287. switch (status.response_code) {
  288. case AP_RESPONSE_NORMAL:
  289. if (status.queue_empty)
  290. rc = 0;
  291. break;
  292. case AP_RESPONSE_Q_NOT_AVAIL:
  293. case AP_RESPONSE_DECONFIGURED:
  294. case AP_RESPONSE_CHECKSTOPPED:
  295. i = AP_MAX_RESET; /* return with -ENODEV */
  296. break;
  297. case AP_RESPONSE_RESET_IN_PROGRESS:
  298. case AP_RESPONSE_BUSY:
  299. default:
  300. break;
  301. }
  302. if (rc != -ENODEV)
  303. break;
  304. if (i < AP_MAX_RESET - 1) {
  305. udelay(5);
  306. status = ap_test_queue(qid, &dummy, &dummy);
  307. }
  308. }
  309. return rc;
  310. }
  311. /**
  312. * AP device related attributes.
  313. */
  314. static ssize_t ap_hwtype_show(struct device *dev,
  315. struct device_attribute *attr, char *buf)
  316. {
  317. struct ap_device *ap_dev = to_ap_dev(dev);
  318. return snprintf(buf, PAGE_SIZE, "%d\n", ap_dev->device_type);
  319. }
  320. static DEVICE_ATTR(hwtype, 0444, ap_hwtype_show, NULL);
  321. static ssize_t ap_depth_show(struct device *dev, struct device_attribute *attr,
  322. char *buf)
  323. {
  324. struct ap_device *ap_dev = to_ap_dev(dev);
  325. return snprintf(buf, PAGE_SIZE, "%d\n", ap_dev->queue_depth);
  326. }
  327. static DEVICE_ATTR(depth, 0444, ap_depth_show, NULL);
  328. static ssize_t ap_request_count_show(struct device *dev,
  329. struct device_attribute *attr,
  330. char *buf)
  331. {
  332. struct ap_device *ap_dev = to_ap_dev(dev);
  333. int rc;
  334. spin_lock_bh(&ap_dev->lock);
  335. rc = snprintf(buf, PAGE_SIZE, "%d\n", ap_dev->total_request_count);
  336. spin_unlock_bh(&ap_dev->lock);
  337. return rc;
  338. }
  339. static DEVICE_ATTR(request_count, 0444, ap_request_count_show, NULL);
  340. static ssize_t ap_modalias_show(struct device *dev,
  341. struct device_attribute *attr, char *buf)
  342. {
  343. return sprintf(buf, "ap:t%02X", to_ap_dev(dev)->device_type);
  344. }
  345. static DEVICE_ATTR(modalias, 0444, ap_modalias_show, NULL);
  346. static struct attribute *ap_dev_attrs[] = {
  347. &dev_attr_hwtype.attr,
  348. &dev_attr_depth.attr,
  349. &dev_attr_request_count.attr,
  350. &dev_attr_modalias.attr,
  351. NULL
  352. };
  353. static struct attribute_group ap_dev_attr_group = {
  354. .attrs = ap_dev_attrs
  355. };
  356. /**
  357. * AP bus driver registration/unregistration.
  358. */
  359. static int ap_bus_match(struct device *dev, struct device_driver *drv)
  360. {
  361. struct ap_device *ap_dev = to_ap_dev(dev);
  362. struct ap_driver *ap_drv = to_ap_drv(drv);
  363. struct ap_device_id *id;
  364. /**
  365. * Compare device type of the device with the list of
  366. * supported types of the device_driver.
  367. */
  368. for (id = ap_drv->ids; id->match_flags; id++) {
  369. if ((id->match_flags & AP_DEVICE_ID_MATCH_DEVICE_TYPE) &&
  370. (id->dev_type != ap_dev->device_type))
  371. continue;
  372. return 1;
  373. }
  374. return 0;
  375. }
  376. /**
  377. * uevent function for AP devices. It sets up a single environment
  378. * variable DEV_TYPE which contains the hardware device type.
  379. */
  380. static int ap_uevent (struct device *dev, char **envp, int num_envp,
  381. char *buffer, int buffer_size)
  382. {
  383. struct ap_device *ap_dev = to_ap_dev(dev);
  384. int length;
  385. if (!ap_dev)
  386. return -ENODEV;
  387. /* Set up DEV_TYPE environment variable. */
  388. envp[0] = buffer;
  389. length = scnprintf(buffer, buffer_size, "DEV_TYPE=%04X",
  390. ap_dev->device_type);
  391. if (buffer_size - length <= 0)
  392. return -ENOMEM;
  393. envp[1] = 0;
  394. return 0;
  395. }
  396. static struct bus_type ap_bus_type = {
  397. .name = "ap",
  398. .match = &ap_bus_match,
  399. .uevent = &ap_uevent,
  400. };
  401. static int ap_device_probe(struct device *dev)
  402. {
  403. struct ap_device *ap_dev = to_ap_dev(dev);
  404. struct ap_driver *ap_drv = to_ap_drv(dev->driver);
  405. int rc;
  406. ap_dev->drv = ap_drv;
  407. rc = ap_drv->probe ? ap_drv->probe(ap_dev) : -ENODEV;
  408. if (rc)
  409. ap_dev->unregistered = 1;
  410. return rc;
  411. }
  412. /**
  413. * Flush all requests from the request/pending queue of an AP device.
  414. * @ap_dev: pointer to the AP device.
  415. */
  416. static inline void __ap_flush_queue(struct ap_device *ap_dev)
  417. {
  418. struct ap_message *ap_msg, *next;
  419. list_for_each_entry_safe(ap_msg, next, &ap_dev->pendingq, list) {
  420. list_del_init(&ap_msg->list);
  421. ap_dev->pendingq_count--;
  422. ap_dev->drv->receive(ap_dev, ap_msg, ERR_PTR(-ENODEV));
  423. }
  424. list_for_each_entry_safe(ap_msg, next, &ap_dev->requestq, list) {
  425. list_del_init(&ap_msg->list);
  426. ap_dev->requestq_count--;
  427. ap_dev->drv->receive(ap_dev, ap_msg, ERR_PTR(-ENODEV));
  428. }
  429. }
  430. void ap_flush_queue(struct ap_device *ap_dev)
  431. {
  432. spin_lock_bh(&ap_dev->lock);
  433. __ap_flush_queue(ap_dev);
  434. spin_unlock_bh(&ap_dev->lock);
  435. }
  436. EXPORT_SYMBOL(ap_flush_queue);
  437. static int ap_device_remove(struct device *dev)
  438. {
  439. struct ap_device *ap_dev = to_ap_dev(dev);
  440. struct ap_driver *ap_drv = ap_dev->drv;
  441. spin_lock_bh(&ap_dev->lock);
  442. __ap_flush_queue(ap_dev);
  443. /**
  444. * set ->unregistered to 1 while holding the lock. This prevents
  445. * new messages to be put on the queue from now on.
  446. */
  447. ap_dev->unregistered = 1;
  448. spin_unlock_bh(&ap_dev->lock);
  449. if (ap_drv->remove)
  450. ap_drv->remove(ap_dev);
  451. return 0;
  452. }
  453. int ap_driver_register(struct ap_driver *ap_drv, struct module *owner,
  454. char *name)
  455. {
  456. struct device_driver *drv = &ap_drv->driver;
  457. drv->bus = &ap_bus_type;
  458. drv->probe = ap_device_probe;
  459. drv->remove = ap_device_remove;
  460. drv->owner = owner;
  461. drv->name = name;
  462. return driver_register(drv);
  463. }
  464. EXPORT_SYMBOL(ap_driver_register);
  465. void ap_driver_unregister(struct ap_driver *ap_drv)
  466. {
  467. driver_unregister(&ap_drv->driver);
  468. }
  469. EXPORT_SYMBOL(ap_driver_unregister);
  470. /**
  471. * AP bus attributes.
  472. */
  473. static ssize_t ap_domain_show(struct bus_type *bus, char *buf)
  474. {
  475. return snprintf(buf, PAGE_SIZE, "%d\n", ap_domain_index);
  476. }
  477. static BUS_ATTR(ap_domain, 0444, ap_domain_show, NULL);
  478. static ssize_t ap_config_time_show(struct bus_type *bus, char *buf)
  479. {
  480. return snprintf(buf, PAGE_SIZE, "%d\n", ap_config_time);
  481. }
  482. static ssize_t ap_config_time_store(struct bus_type *bus,
  483. const char *buf, size_t count)
  484. {
  485. int time;
  486. if (sscanf(buf, "%d\n", &time) != 1 || time < 5 || time > 120)
  487. return -EINVAL;
  488. ap_config_time = time;
  489. if (!timer_pending(&ap_config_timer) ||
  490. !mod_timer(&ap_config_timer, jiffies + ap_config_time * HZ)) {
  491. ap_config_timer.expires = jiffies + ap_config_time * HZ;
  492. add_timer(&ap_config_timer);
  493. }
  494. return count;
  495. }
  496. static BUS_ATTR(config_time, 0644, ap_config_time_show, ap_config_time_store);
  497. static ssize_t ap_poll_thread_show(struct bus_type *bus, char *buf)
  498. {
  499. return snprintf(buf, PAGE_SIZE, "%d\n", ap_poll_kthread ? 1 : 0);
  500. }
  501. static ssize_t ap_poll_thread_store(struct bus_type *bus,
  502. const char *buf, size_t count)
  503. {
  504. int flag, rc;
  505. if (sscanf(buf, "%d\n", &flag) != 1)
  506. return -EINVAL;
  507. if (flag) {
  508. rc = ap_poll_thread_start();
  509. if (rc)
  510. return rc;
  511. }
  512. else
  513. ap_poll_thread_stop();
  514. return count;
  515. }
  516. static BUS_ATTR(poll_thread, 0644, ap_poll_thread_show, ap_poll_thread_store);
  517. static struct bus_attribute *const ap_bus_attrs[] = {
  518. &bus_attr_ap_domain,
  519. &bus_attr_config_time,
  520. &bus_attr_poll_thread,
  521. NULL
  522. };
  523. /**
  524. * Pick one of the 16 ap domains.
  525. */
  526. static inline int ap_select_domain(void)
  527. {
  528. int queue_depth, device_type, count, max_count, best_domain;
  529. int rc, i, j;
  530. /**
  531. * We want to use a single domain. Either the one specified with
  532. * the "domain=" parameter or the domain with the maximum number
  533. * of devices.
  534. */
  535. if (ap_domain_index >= 0 && ap_domain_index < AP_DOMAINS)
  536. /* Domain has already been selected. */
  537. return 0;
  538. best_domain = -1;
  539. max_count = 0;
  540. for (i = 0; i < AP_DOMAINS; i++) {
  541. count = 0;
  542. for (j = 0; j < AP_DEVICES; j++) {
  543. ap_qid_t qid = AP_MKQID(j, i);
  544. rc = ap_query_queue(qid, &queue_depth, &device_type);
  545. if (rc)
  546. continue;
  547. count++;
  548. }
  549. if (count > max_count) {
  550. max_count = count;
  551. best_domain = i;
  552. }
  553. }
  554. if (best_domain >= 0){
  555. ap_domain_index = best_domain;
  556. return 0;
  557. }
  558. return -ENODEV;
  559. }
  560. /**
  561. * Find the device type if query queue returned a device type of 0.
  562. * @ap_dev: pointer to the AP device.
  563. */
  564. static int ap_probe_device_type(struct ap_device *ap_dev)
  565. {
  566. static unsigned char msg[] = {
  567. 0x00,0x06,0x00,0x00,0x00,0x00,0x00,0x00,
  568. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  569. 0x00,0x00,0x00,0x58,0x00,0x00,0x00,0x00,
  570. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  571. 0x01,0x00,0x43,0x43,0x41,0x2d,0x41,0x50,
  572. 0x50,0x4c,0x20,0x20,0x20,0x01,0x01,0x01,
  573. 0x00,0x00,0x00,0x00,0x50,0x4b,0x00,0x00,
  574. 0x00,0x00,0x01,0x1c,0x00,0x00,0x00,0x00,
  575. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  576. 0x00,0x00,0x05,0xb8,0x00,0x00,0x00,0x00,
  577. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  578. 0x70,0x00,0x41,0x00,0x00,0x00,0x00,0x00,
  579. 0x00,0x00,0x54,0x32,0x01,0x00,0xa0,0x00,
  580. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  581. 0x00,0x00,0x00,0x00,0xb8,0x05,0x00,0x00,
  582. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  583. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  584. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  585. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  586. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  587. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  588. 0x00,0x00,0x0a,0x00,0x00,0x00,0x00,0x00,
  589. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  590. 0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x00,
  591. 0x49,0x43,0x53,0x46,0x20,0x20,0x20,0x20,
  592. 0x50,0x4b,0x0a,0x00,0x50,0x4b,0x43,0x53,
  593. 0x2d,0x31,0x2e,0x32,0x37,0x00,0x11,0x22,
  594. 0x33,0x44,0x55,0x66,0x77,0x88,0x99,0x00,
  595. 0x11,0x22,0x33,0x44,0x55,0x66,0x77,0x88,
  596. 0x99,0x00,0x11,0x22,0x33,0x44,0x55,0x66,
  597. 0x77,0x88,0x99,0x00,0x11,0x22,0x33,0x44,
  598. 0x55,0x66,0x77,0x88,0x99,0x00,0x11,0x22,
  599. 0x33,0x44,0x55,0x66,0x77,0x88,0x99,0x00,
  600. 0x11,0x22,0x33,0x5d,0x00,0x5b,0x00,0x77,
  601. 0x88,0x1e,0x00,0x00,0x57,0x00,0x00,0x00,
  602. 0x00,0x04,0x00,0x00,0x4f,0x00,0x00,0x00,
  603. 0x03,0x02,0x00,0x00,0x40,0x01,0x00,0x01,
  604. 0xce,0x02,0x68,0x2d,0x5f,0xa9,0xde,0x0c,
  605. 0xf6,0xd2,0x7b,0x58,0x4b,0xf9,0x28,0x68,
  606. 0x3d,0xb4,0xf4,0xef,0x78,0xd5,0xbe,0x66,
  607. 0x63,0x42,0xef,0xf8,0xfd,0xa4,0xf8,0xb0,
  608. 0x8e,0x29,0xc2,0xc9,0x2e,0xd8,0x45,0xb8,
  609. 0x53,0x8c,0x6f,0x4e,0x72,0x8f,0x6c,0x04,
  610. 0x9c,0x88,0xfc,0x1e,0xc5,0x83,0x55,0x57,
  611. 0xf7,0xdd,0xfd,0x4f,0x11,0x36,0x95,0x5d,
  612. };
  613. struct ap_queue_status status;
  614. unsigned long long psmid;
  615. char *reply;
  616. int rc, i;
  617. reply = (void *) get_zeroed_page(GFP_KERNEL);
  618. if (!reply) {
  619. rc = -ENOMEM;
  620. goto out;
  621. }
  622. status = __ap_send(ap_dev->qid, 0x0102030405060708ULL,
  623. msg, sizeof(msg));
  624. if (status.response_code != AP_RESPONSE_NORMAL) {
  625. rc = -ENODEV;
  626. goto out_free;
  627. }
  628. /* Wait for the test message to complete. */
  629. for (i = 0; i < 6; i++) {
  630. mdelay(300);
  631. status = __ap_recv(ap_dev->qid, &psmid, reply, 4096);
  632. if (status.response_code == AP_RESPONSE_NORMAL &&
  633. psmid == 0x0102030405060708ULL)
  634. break;
  635. }
  636. if (i < 6) {
  637. /* Got an answer. */
  638. if (reply[0] == 0x00 && reply[1] == 0x86)
  639. ap_dev->device_type = AP_DEVICE_TYPE_PCICC;
  640. else
  641. ap_dev->device_type = AP_DEVICE_TYPE_PCICA;
  642. rc = 0;
  643. } else
  644. rc = -ENODEV;
  645. out_free:
  646. free_page((unsigned long) reply);
  647. out:
  648. return rc;
  649. }
  650. /**
  651. * Scan the ap bus for new devices.
  652. */
  653. static int __ap_scan_bus(struct device *dev, void *data)
  654. {
  655. return to_ap_dev(dev)->qid == (ap_qid_t)(unsigned long) data;
  656. }
  657. static void ap_device_release(struct device *dev)
  658. {
  659. struct ap_device *ap_dev = to_ap_dev(dev);
  660. kfree(ap_dev);
  661. }
  662. static void ap_scan_bus(void *data)
  663. {
  664. struct ap_device *ap_dev;
  665. struct device *dev;
  666. ap_qid_t qid;
  667. int queue_depth, device_type;
  668. int rc, i;
  669. if (ap_select_domain() != 0)
  670. return;
  671. for (i = 0; i < AP_DEVICES; i++) {
  672. qid = AP_MKQID(i, ap_domain_index);
  673. dev = bus_find_device(&ap_bus_type, NULL,
  674. (void *)(unsigned long)qid,
  675. __ap_scan_bus);
  676. if (dev) {
  677. put_device(dev);
  678. continue;
  679. }
  680. rc = ap_query_queue(qid, &queue_depth, &device_type);
  681. if (rc)
  682. continue;
  683. rc = ap_init_queue(qid);
  684. if (rc)
  685. continue;
  686. ap_dev = kzalloc(sizeof(*ap_dev), GFP_KERNEL);
  687. if (!ap_dev)
  688. break;
  689. ap_dev->qid = qid;
  690. ap_dev->queue_depth = queue_depth;
  691. spin_lock_init(&ap_dev->lock);
  692. INIT_LIST_HEAD(&ap_dev->pendingq);
  693. INIT_LIST_HEAD(&ap_dev->requestq);
  694. if (device_type == 0)
  695. ap_probe_device_type(ap_dev);
  696. else
  697. ap_dev->device_type = device_type;
  698. ap_dev->device.bus = &ap_bus_type;
  699. ap_dev->device.parent = ap_root_device;
  700. snprintf(ap_dev->device.bus_id, BUS_ID_SIZE, "card%02x",
  701. AP_QID_DEVICE(ap_dev->qid));
  702. ap_dev->device.release = ap_device_release;
  703. rc = device_register(&ap_dev->device);
  704. if (rc) {
  705. kfree(ap_dev);
  706. continue;
  707. }
  708. /* Add device attributes. */
  709. rc = sysfs_create_group(&ap_dev->device.kobj,
  710. &ap_dev_attr_group);
  711. if (rc)
  712. device_unregister(&ap_dev->device);
  713. }
  714. }
  715. static void
  716. ap_config_timeout(unsigned long ptr)
  717. {
  718. queue_work(ap_work_queue, &ap_config_work);
  719. ap_config_timer.expires = jiffies + ap_config_time * HZ;
  720. add_timer(&ap_config_timer);
  721. }
  722. /**
  723. * Set up the timer to run the poll tasklet
  724. */
  725. static inline void ap_schedule_poll_timer(void)
  726. {
  727. if (timer_pending(&ap_poll_timer))
  728. return;
  729. mod_timer(&ap_poll_timer, jiffies + AP_POLL_TIME);
  730. }
  731. /**
  732. * Receive pending reply messages from an AP device.
  733. * @ap_dev: pointer to the AP device
  734. * @flags: pointer to control flags, bit 2^0 is set if another poll is
  735. * required, bit 2^1 is set if the poll timer needs to get armed
  736. * Returns 0 if the device is still present, -ENODEV if not.
  737. */
  738. static inline int ap_poll_read(struct ap_device *ap_dev, unsigned long *flags)
  739. {
  740. struct ap_queue_status status;
  741. struct ap_message *ap_msg;
  742. if (ap_dev->queue_count <= 0)
  743. return 0;
  744. status = __ap_recv(ap_dev->qid, &ap_dev->reply->psmid,
  745. ap_dev->reply->message, ap_dev->reply->length);
  746. switch (status.response_code) {
  747. case AP_RESPONSE_NORMAL:
  748. atomic_dec(&ap_poll_requests);
  749. ap_dev->queue_count--;
  750. list_for_each_entry(ap_msg, &ap_dev->pendingq, list) {
  751. if (ap_msg->psmid != ap_dev->reply->psmid)
  752. continue;
  753. list_del_init(&ap_msg->list);
  754. ap_dev->pendingq_count--;
  755. ap_dev->drv->receive(ap_dev, ap_msg, ap_dev->reply);
  756. break;
  757. }
  758. if (ap_dev->queue_count > 0)
  759. *flags |= 1;
  760. break;
  761. case AP_RESPONSE_NO_PENDING_REPLY:
  762. if (status.queue_empty) {
  763. /* The card shouldn't forget requests but who knows. */
  764. ap_dev->queue_count = 0;
  765. list_splice_init(&ap_dev->pendingq, &ap_dev->requestq);
  766. ap_dev->requestq_count += ap_dev->pendingq_count;
  767. ap_dev->pendingq_count = 0;
  768. } else
  769. *flags |= 2;
  770. break;
  771. default:
  772. return -ENODEV;
  773. }
  774. return 0;
  775. }
  776. /**
  777. * Send messages from the request queue to an AP device.
  778. * @ap_dev: pointer to the AP device
  779. * @flags: pointer to control flags, bit 2^0 is set if another poll is
  780. * required, bit 2^1 is set if the poll timer needs to get armed
  781. * Returns 0 if the device is still present, -ENODEV if not.
  782. */
  783. static inline int ap_poll_write(struct ap_device *ap_dev, unsigned long *flags)
  784. {
  785. struct ap_queue_status status;
  786. struct ap_message *ap_msg;
  787. if (ap_dev->requestq_count <= 0 ||
  788. ap_dev->queue_count >= ap_dev->queue_depth)
  789. return 0;
  790. /* Start the next request on the queue. */
  791. ap_msg = list_entry(ap_dev->requestq.next, struct ap_message, list);
  792. status = __ap_send(ap_dev->qid, ap_msg->psmid,
  793. ap_msg->message, ap_msg->length);
  794. switch (status.response_code) {
  795. case AP_RESPONSE_NORMAL:
  796. atomic_inc(&ap_poll_requests);
  797. ap_dev->queue_count++;
  798. list_move_tail(&ap_msg->list, &ap_dev->pendingq);
  799. ap_dev->requestq_count--;
  800. ap_dev->pendingq_count++;
  801. if (ap_dev->queue_count < ap_dev->queue_depth &&
  802. ap_dev->requestq_count > 0)
  803. *flags |= 1;
  804. *flags |= 2;
  805. break;
  806. case AP_RESPONSE_Q_FULL:
  807. *flags |= 2;
  808. break;
  809. case AP_RESPONSE_MESSAGE_TOO_BIG:
  810. return -EINVAL;
  811. default:
  812. return -ENODEV;
  813. }
  814. return 0;
  815. }
  816. /**
  817. * Poll AP device for pending replies and send new messages. If either
  818. * ap_poll_read or ap_poll_write returns -ENODEV unregister the device.
  819. * @ap_dev: pointer to the bus device
  820. * @flags: pointer to control flags, bit 2^0 is set if another poll is
  821. * required, bit 2^1 is set if the poll timer needs to get armed
  822. * Returns 0.
  823. */
  824. static inline int ap_poll_queue(struct ap_device *ap_dev, unsigned long *flags)
  825. {
  826. int rc;
  827. rc = ap_poll_read(ap_dev, flags);
  828. if (rc)
  829. return rc;
  830. return ap_poll_write(ap_dev, flags);
  831. }
  832. /**
  833. * Queue a message to a device.
  834. * @ap_dev: pointer to the AP device
  835. * @ap_msg: the message to be queued
  836. */
  837. static int __ap_queue_message(struct ap_device *ap_dev, struct ap_message *ap_msg)
  838. {
  839. struct ap_queue_status status;
  840. if (list_empty(&ap_dev->requestq) &&
  841. ap_dev->queue_count < ap_dev->queue_depth) {
  842. status = __ap_send(ap_dev->qid, ap_msg->psmid,
  843. ap_msg->message, ap_msg->length);
  844. switch (status.response_code) {
  845. case AP_RESPONSE_NORMAL:
  846. list_add_tail(&ap_msg->list, &ap_dev->pendingq);
  847. atomic_inc(&ap_poll_requests);
  848. ap_dev->pendingq_count++;
  849. ap_dev->queue_count++;
  850. ap_dev->total_request_count++;
  851. break;
  852. case AP_RESPONSE_Q_FULL:
  853. list_add_tail(&ap_msg->list, &ap_dev->requestq);
  854. ap_dev->requestq_count++;
  855. ap_dev->total_request_count++;
  856. return -EBUSY;
  857. case AP_RESPONSE_MESSAGE_TOO_BIG:
  858. ap_dev->drv->receive(ap_dev, ap_msg, ERR_PTR(-EINVAL));
  859. return -EINVAL;
  860. default: /* Device is gone. */
  861. ap_dev->drv->receive(ap_dev, ap_msg, ERR_PTR(-ENODEV));
  862. return -ENODEV;
  863. }
  864. } else {
  865. list_add_tail(&ap_msg->list, &ap_dev->requestq);
  866. ap_dev->requestq_count++;
  867. ap_dev->total_request_count++;
  868. return -EBUSY;
  869. }
  870. ap_schedule_poll_timer();
  871. return 0;
  872. }
  873. void ap_queue_message(struct ap_device *ap_dev, struct ap_message *ap_msg)
  874. {
  875. unsigned long flags;
  876. int rc;
  877. spin_lock_bh(&ap_dev->lock);
  878. if (!ap_dev->unregistered) {
  879. /* Make room on the queue by polling for finished requests. */
  880. rc = ap_poll_queue(ap_dev, &flags);
  881. if (!rc)
  882. rc = __ap_queue_message(ap_dev, ap_msg);
  883. if (!rc)
  884. wake_up(&ap_poll_wait);
  885. } else {
  886. ap_dev->drv->receive(ap_dev, ap_msg, ERR_PTR(-ENODEV));
  887. rc = 0;
  888. }
  889. spin_unlock_bh(&ap_dev->lock);
  890. if (rc == -ENODEV)
  891. device_unregister(&ap_dev->device);
  892. }
  893. EXPORT_SYMBOL(ap_queue_message);
  894. /**
  895. * Cancel a crypto request. This is done by removing the request
  896. * from the devive pendingq or requestq queue. Note that the
  897. * request stays on the AP queue. When it finishes the message
  898. * reply will be discarded because the psmid can't be found.
  899. * @ap_dev: AP device that has the message queued
  900. * @ap_msg: the message that is to be removed
  901. */
  902. void ap_cancel_message(struct ap_device *ap_dev, struct ap_message *ap_msg)
  903. {
  904. struct ap_message *tmp;
  905. spin_lock_bh(&ap_dev->lock);
  906. if (!list_empty(&ap_msg->list)) {
  907. list_for_each_entry(tmp, &ap_dev->pendingq, list)
  908. if (tmp->psmid == ap_msg->psmid) {
  909. ap_dev->pendingq_count--;
  910. goto found;
  911. }
  912. ap_dev->requestq_count--;
  913. found:
  914. list_del_init(&ap_msg->list);
  915. }
  916. spin_unlock_bh(&ap_dev->lock);
  917. }
  918. EXPORT_SYMBOL(ap_cancel_message);
  919. /**
  920. * AP receive polling for finished AP requests
  921. */
  922. static void ap_poll_timeout(unsigned long unused)
  923. {
  924. tasklet_schedule(&ap_tasklet);
  925. }
  926. /**
  927. * Poll all AP devices on the bus in a round robin fashion. Continue
  928. * polling until bit 2^0 of the control flags is not set. If bit 2^1
  929. * of the control flags has been set arm the poll timer.
  930. */
  931. static int __ap_poll_all(struct device *dev, void *data)
  932. {
  933. struct ap_device *ap_dev = to_ap_dev(dev);
  934. int rc;
  935. spin_lock(&ap_dev->lock);
  936. if (!ap_dev->unregistered) {
  937. rc = ap_poll_queue(to_ap_dev(dev), (unsigned long *) data);
  938. } else
  939. rc = 0;
  940. spin_unlock(&ap_dev->lock);
  941. if (rc)
  942. device_unregister(&ap_dev->device);
  943. return 0;
  944. }
  945. static void ap_poll_all(unsigned long dummy)
  946. {
  947. unsigned long flags;
  948. do {
  949. flags = 0;
  950. bus_for_each_dev(&ap_bus_type, NULL, &flags, __ap_poll_all);
  951. } while (flags & 1);
  952. if (flags & 2)
  953. ap_schedule_poll_timer();
  954. }
  955. /**
  956. * AP bus poll thread. The purpose of this thread is to poll for
  957. * finished requests in a loop if there is a "free" cpu - that is
  958. * a cpu that doesn't have anything better to do. The polling stops
  959. * as soon as there is another task or if all messages have been
  960. * delivered.
  961. */
  962. static int ap_poll_thread(void *data)
  963. {
  964. DECLARE_WAITQUEUE(wait, current);
  965. unsigned long flags;
  966. int requests;
  967. set_user_nice(current, -20);
  968. while (1) {
  969. if (need_resched()) {
  970. schedule();
  971. continue;
  972. }
  973. add_wait_queue(&ap_poll_wait, &wait);
  974. set_current_state(TASK_INTERRUPTIBLE);
  975. if (kthread_should_stop())
  976. break;
  977. requests = atomic_read(&ap_poll_requests);
  978. if (requests <= 0)
  979. schedule();
  980. set_current_state(TASK_RUNNING);
  981. remove_wait_queue(&ap_poll_wait, &wait);
  982. local_bh_disable();
  983. flags = 0;
  984. bus_for_each_dev(&ap_bus_type, NULL, &flags, __ap_poll_all);
  985. local_bh_enable();
  986. }
  987. set_current_state(TASK_RUNNING);
  988. remove_wait_queue(&ap_poll_wait, &wait);
  989. return 0;
  990. }
  991. static int ap_poll_thread_start(void)
  992. {
  993. int rc;
  994. mutex_lock(&ap_poll_thread_mutex);
  995. if (!ap_poll_kthread) {
  996. ap_poll_kthread = kthread_run(ap_poll_thread, NULL, "appoll");
  997. rc = IS_ERR(ap_poll_kthread) ? PTR_ERR(ap_poll_kthread) : 0;
  998. if (rc)
  999. ap_poll_kthread = NULL;
  1000. }
  1001. else
  1002. rc = 0;
  1003. mutex_unlock(&ap_poll_thread_mutex);
  1004. return rc;
  1005. }
  1006. static void ap_poll_thread_stop(void)
  1007. {
  1008. mutex_lock(&ap_poll_thread_mutex);
  1009. if (ap_poll_kthread) {
  1010. kthread_stop(ap_poll_kthread);
  1011. ap_poll_kthread = NULL;
  1012. }
  1013. mutex_unlock(&ap_poll_thread_mutex);
  1014. }
  1015. /**
  1016. * The module initialization code.
  1017. */
  1018. int __init ap_module_init(void)
  1019. {
  1020. int rc, i;
  1021. if (ap_domain_index < -1 || ap_domain_index >= AP_DOMAINS) {
  1022. printk(KERN_WARNING "Invalid param: domain = %d. "
  1023. " Not loading.\n", ap_domain_index);
  1024. return -EINVAL;
  1025. }
  1026. if (ap_instructions_available() != 0) {
  1027. printk(KERN_WARNING "AP instructions not installed.\n");
  1028. return -ENODEV;
  1029. }
  1030. /* Create /sys/bus/ap. */
  1031. rc = bus_register(&ap_bus_type);
  1032. if (rc)
  1033. goto out;
  1034. for (i = 0; ap_bus_attrs[i]; i++) {
  1035. rc = bus_create_file(&ap_bus_type, ap_bus_attrs[i]);
  1036. if (rc)
  1037. goto out_bus;
  1038. }
  1039. /* Create /sys/devices/ap. */
  1040. ap_root_device = s390_root_dev_register("ap");
  1041. rc = IS_ERR(ap_root_device) ? PTR_ERR(ap_root_device) : 0;
  1042. if (rc)
  1043. goto out_bus;
  1044. ap_work_queue = create_singlethread_workqueue("kapwork");
  1045. if (!ap_work_queue) {
  1046. rc = -ENOMEM;
  1047. goto out_root;
  1048. }
  1049. if (ap_select_domain() == 0)
  1050. ap_scan_bus(NULL);
  1051. /* Setup the ap bus rescan timer. */
  1052. init_timer(&ap_config_timer);
  1053. ap_config_timer.function = ap_config_timeout;
  1054. ap_config_timer.data = 0;
  1055. ap_config_timer.expires = jiffies + ap_config_time * HZ;
  1056. add_timer(&ap_config_timer);
  1057. /* Start the low priority AP bus poll thread. */
  1058. if (ap_thread_flag) {
  1059. rc = ap_poll_thread_start();
  1060. if (rc)
  1061. goto out_work;
  1062. }
  1063. return 0;
  1064. out_work:
  1065. del_timer_sync(&ap_config_timer);
  1066. del_timer_sync(&ap_poll_timer);
  1067. destroy_workqueue(ap_work_queue);
  1068. out_root:
  1069. s390_root_dev_unregister(ap_root_device);
  1070. out_bus:
  1071. while (i--)
  1072. bus_remove_file(&ap_bus_type, ap_bus_attrs[i]);
  1073. bus_unregister(&ap_bus_type);
  1074. out:
  1075. return rc;
  1076. }
  1077. static int __ap_match_all(struct device *dev, void *data)
  1078. {
  1079. return 1;
  1080. }
  1081. /**
  1082. * The module termination code
  1083. */
  1084. void ap_module_exit(void)
  1085. {
  1086. int i;
  1087. struct device *dev;
  1088. ap_poll_thread_stop();
  1089. del_timer_sync(&ap_config_timer);
  1090. del_timer_sync(&ap_poll_timer);
  1091. destroy_workqueue(ap_work_queue);
  1092. s390_root_dev_unregister(ap_root_device);
  1093. while ((dev = bus_find_device(&ap_bus_type, NULL, NULL,
  1094. __ap_match_all)))
  1095. {
  1096. device_unregister(dev);
  1097. put_device(dev);
  1098. }
  1099. for (i = 0; ap_bus_attrs[i]; i++)
  1100. bus_remove_file(&ap_bus_type, ap_bus_attrs[i]);
  1101. bus_unregister(&ap_bus_type);
  1102. }
  1103. #ifndef CONFIG_ZCRYPT_MONOLITHIC
  1104. module_init(ap_module_init);
  1105. module_exit(ap_module_exit);
  1106. #endif