ap_bus.c 31 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222
  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. return rc;
  409. }
  410. /**
  411. * Flush all requests from the request/pending queue of an AP device.
  412. * @ap_dev: pointer to the AP device.
  413. */
  414. static inline void __ap_flush_queue(struct ap_device *ap_dev)
  415. {
  416. struct ap_message *ap_msg, *next;
  417. list_for_each_entry_safe(ap_msg, next, &ap_dev->pendingq, list) {
  418. list_del_init(&ap_msg->list);
  419. ap_dev->pendingq_count--;
  420. ap_dev->drv->receive(ap_dev, ap_msg, ERR_PTR(-ENODEV));
  421. }
  422. list_for_each_entry_safe(ap_msg, next, &ap_dev->requestq, list) {
  423. list_del_init(&ap_msg->list);
  424. ap_dev->requestq_count--;
  425. ap_dev->drv->receive(ap_dev, ap_msg, ERR_PTR(-ENODEV));
  426. }
  427. }
  428. void ap_flush_queue(struct ap_device *ap_dev)
  429. {
  430. spin_lock_bh(&ap_dev->lock);
  431. __ap_flush_queue(ap_dev);
  432. spin_unlock_bh(&ap_dev->lock);
  433. }
  434. EXPORT_SYMBOL(ap_flush_queue);
  435. static int ap_device_remove(struct device *dev)
  436. {
  437. struct ap_device *ap_dev = to_ap_dev(dev);
  438. struct ap_driver *ap_drv = ap_dev->drv;
  439. ap_flush_queue(ap_dev);
  440. if (ap_drv->remove)
  441. ap_drv->remove(ap_dev);
  442. return 0;
  443. }
  444. int ap_driver_register(struct ap_driver *ap_drv, struct module *owner,
  445. char *name)
  446. {
  447. struct device_driver *drv = &ap_drv->driver;
  448. drv->bus = &ap_bus_type;
  449. drv->probe = ap_device_probe;
  450. drv->remove = ap_device_remove;
  451. drv->owner = owner;
  452. drv->name = name;
  453. return driver_register(drv);
  454. }
  455. EXPORT_SYMBOL(ap_driver_register);
  456. void ap_driver_unregister(struct ap_driver *ap_drv)
  457. {
  458. driver_unregister(&ap_drv->driver);
  459. }
  460. EXPORT_SYMBOL(ap_driver_unregister);
  461. /**
  462. * AP bus attributes.
  463. */
  464. static ssize_t ap_domain_show(struct bus_type *bus, char *buf)
  465. {
  466. return snprintf(buf, PAGE_SIZE, "%d\n", ap_domain_index);
  467. }
  468. static BUS_ATTR(ap_domain, 0444, ap_domain_show, NULL);
  469. static ssize_t ap_config_time_show(struct bus_type *bus, char *buf)
  470. {
  471. return snprintf(buf, PAGE_SIZE, "%d\n", ap_config_time);
  472. }
  473. static ssize_t ap_config_time_store(struct bus_type *bus,
  474. const char *buf, size_t count)
  475. {
  476. int time;
  477. if (sscanf(buf, "%d\n", &time) != 1 || time < 5 || time > 120)
  478. return -EINVAL;
  479. ap_config_time = time;
  480. if (!timer_pending(&ap_config_timer) ||
  481. !mod_timer(&ap_config_timer, jiffies + ap_config_time * HZ)) {
  482. ap_config_timer.expires = jiffies + ap_config_time * HZ;
  483. add_timer(&ap_config_timer);
  484. }
  485. return count;
  486. }
  487. static BUS_ATTR(config_time, 0644, ap_config_time_show, ap_config_time_store);
  488. static ssize_t ap_poll_thread_show(struct bus_type *bus, char *buf)
  489. {
  490. return snprintf(buf, PAGE_SIZE, "%d\n", ap_poll_kthread ? 1 : 0);
  491. }
  492. static ssize_t ap_poll_thread_store(struct bus_type *bus,
  493. const char *buf, size_t count)
  494. {
  495. int flag, rc;
  496. if (sscanf(buf, "%d\n", &flag) != 1)
  497. return -EINVAL;
  498. if (flag) {
  499. rc = ap_poll_thread_start();
  500. if (rc)
  501. return rc;
  502. }
  503. else
  504. ap_poll_thread_stop();
  505. return count;
  506. }
  507. static BUS_ATTR(poll_thread, 0644, ap_poll_thread_show, ap_poll_thread_store);
  508. static struct bus_attribute *const ap_bus_attrs[] = {
  509. &bus_attr_ap_domain,
  510. &bus_attr_config_time,
  511. &bus_attr_poll_thread,
  512. NULL
  513. };
  514. /**
  515. * Pick one of the 16 ap domains.
  516. */
  517. static inline int ap_select_domain(void)
  518. {
  519. int queue_depth, device_type, count, max_count, best_domain;
  520. int rc, i, j;
  521. /**
  522. * We want to use a single domain. Either the one specified with
  523. * the "domain=" parameter or the domain with the maximum number
  524. * of devices.
  525. */
  526. if (ap_domain_index >= 0 && ap_domain_index < AP_DOMAINS)
  527. /* Domain has already been selected. */
  528. return 0;
  529. best_domain = -1;
  530. max_count = 0;
  531. for (i = 0; i < AP_DOMAINS; i++) {
  532. count = 0;
  533. for (j = 0; j < AP_DEVICES; j++) {
  534. ap_qid_t qid = AP_MKQID(j, i);
  535. rc = ap_query_queue(qid, &queue_depth, &device_type);
  536. if (rc)
  537. continue;
  538. count++;
  539. }
  540. if (count > max_count) {
  541. max_count = count;
  542. best_domain = i;
  543. }
  544. }
  545. if (best_domain >= 0){
  546. ap_domain_index = best_domain;
  547. return 0;
  548. }
  549. return -ENODEV;
  550. }
  551. /**
  552. * Find the device type if query queue returned a device type of 0.
  553. * @ap_dev: pointer to the AP device.
  554. */
  555. static int ap_probe_device_type(struct ap_device *ap_dev)
  556. {
  557. static unsigned char msg[] = {
  558. 0x00,0x06,0x00,0x00,0x00,0x00,0x00,0x00,
  559. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  560. 0x00,0x00,0x00,0x58,0x00,0x00,0x00,0x00,
  561. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  562. 0x01,0x00,0x43,0x43,0x41,0x2d,0x41,0x50,
  563. 0x50,0x4c,0x20,0x20,0x20,0x01,0x01,0x01,
  564. 0x00,0x00,0x00,0x00,0x50,0x4b,0x00,0x00,
  565. 0x00,0x00,0x01,0x1c,0x00,0x00,0x00,0x00,
  566. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  567. 0x00,0x00,0x05,0xb8,0x00,0x00,0x00,0x00,
  568. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  569. 0x70,0x00,0x41,0x00,0x00,0x00,0x00,0x00,
  570. 0x00,0x00,0x54,0x32,0x01,0x00,0xa0,0x00,
  571. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  572. 0x00,0x00,0x00,0x00,0xb8,0x05,0x00,0x00,
  573. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  574. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  575. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  576. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  577. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  578. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  579. 0x00,0x00,0x0a,0x00,0x00,0x00,0x00,0x00,
  580. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  581. 0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x00,
  582. 0x49,0x43,0x53,0x46,0x20,0x20,0x20,0x20,
  583. 0x50,0x4b,0x0a,0x00,0x50,0x4b,0x43,0x53,
  584. 0x2d,0x31,0x2e,0x32,0x37,0x00,0x11,0x22,
  585. 0x33,0x44,0x55,0x66,0x77,0x88,0x99,0x00,
  586. 0x11,0x22,0x33,0x44,0x55,0x66,0x77,0x88,
  587. 0x99,0x00,0x11,0x22,0x33,0x44,0x55,0x66,
  588. 0x77,0x88,0x99,0x00,0x11,0x22,0x33,0x44,
  589. 0x55,0x66,0x77,0x88,0x99,0x00,0x11,0x22,
  590. 0x33,0x44,0x55,0x66,0x77,0x88,0x99,0x00,
  591. 0x11,0x22,0x33,0x5d,0x00,0x5b,0x00,0x77,
  592. 0x88,0x1e,0x00,0x00,0x57,0x00,0x00,0x00,
  593. 0x00,0x04,0x00,0x00,0x4f,0x00,0x00,0x00,
  594. 0x03,0x02,0x00,0x00,0x40,0x01,0x00,0x01,
  595. 0xce,0x02,0x68,0x2d,0x5f,0xa9,0xde,0x0c,
  596. 0xf6,0xd2,0x7b,0x58,0x4b,0xf9,0x28,0x68,
  597. 0x3d,0xb4,0xf4,0xef,0x78,0xd5,0xbe,0x66,
  598. 0x63,0x42,0xef,0xf8,0xfd,0xa4,0xf8,0xb0,
  599. 0x8e,0x29,0xc2,0xc9,0x2e,0xd8,0x45,0xb8,
  600. 0x53,0x8c,0x6f,0x4e,0x72,0x8f,0x6c,0x04,
  601. 0x9c,0x88,0xfc,0x1e,0xc5,0x83,0x55,0x57,
  602. 0xf7,0xdd,0xfd,0x4f,0x11,0x36,0x95,0x5d,
  603. };
  604. struct ap_queue_status status;
  605. unsigned long long psmid;
  606. char *reply;
  607. int rc, i;
  608. reply = (void *) get_zeroed_page(GFP_KERNEL);
  609. if (!reply) {
  610. rc = -ENOMEM;
  611. goto out;
  612. }
  613. status = __ap_send(ap_dev->qid, 0x0102030405060708ULL,
  614. msg, sizeof(msg));
  615. if (status.response_code != AP_RESPONSE_NORMAL) {
  616. rc = -ENODEV;
  617. goto out_free;
  618. }
  619. /* Wait for the test message to complete. */
  620. for (i = 0; i < 6; i++) {
  621. mdelay(300);
  622. status = __ap_recv(ap_dev->qid, &psmid, reply, 4096);
  623. if (status.response_code == AP_RESPONSE_NORMAL &&
  624. psmid == 0x0102030405060708ULL)
  625. break;
  626. }
  627. if (i < 6) {
  628. /* Got an answer. */
  629. if (reply[0] == 0x00 && reply[1] == 0x86)
  630. ap_dev->device_type = AP_DEVICE_TYPE_PCICC;
  631. else
  632. ap_dev->device_type = AP_DEVICE_TYPE_PCICA;
  633. rc = 0;
  634. } else
  635. rc = -ENODEV;
  636. out_free:
  637. free_page((unsigned long) reply);
  638. out:
  639. return rc;
  640. }
  641. /**
  642. * Scan the ap bus for new devices.
  643. */
  644. static int __ap_scan_bus(struct device *dev, void *data)
  645. {
  646. return to_ap_dev(dev)->qid == (ap_qid_t)(unsigned long) data;
  647. }
  648. static void ap_device_release(struct device *dev)
  649. {
  650. struct ap_device *ap_dev = to_ap_dev(dev);
  651. kfree(ap_dev);
  652. }
  653. static void ap_scan_bus(void *data)
  654. {
  655. struct ap_device *ap_dev;
  656. struct device *dev;
  657. ap_qid_t qid;
  658. int queue_depth, device_type;
  659. int rc, i;
  660. if (ap_select_domain() != 0)
  661. return;
  662. for (i = 0; i < AP_DEVICES; i++) {
  663. qid = AP_MKQID(i, ap_domain_index);
  664. dev = bus_find_device(&ap_bus_type, NULL,
  665. (void *)(unsigned long)qid,
  666. __ap_scan_bus);
  667. if (dev) {
  668. put_device(dev);
  669. continue;
  670. }
  671. rc = ap_query_queue(qid, &queue_depth, &device_type);
  672. if (rc)
  673. continue;
  674. rc = ap_init_queue(qid);
  675. if (rc)
  676. continue;
  677. ap_dev = kzalloc(sizeof(*ap_dev), GFP_KERNEL);
  678. if (!ap_dev)
  679. break;
  680. ap_dev->qid = qid;
  681. ap_dev->queue_depth = queue_depth;
  682. ap_dev->unregistered = 1;
  683. spin_lock_init(&ap_dev->lock);
  684. INIT_LIST_HEAD(&ap_dev->pendingq);
  685. INIT_LIST_HEAD(&ap_dev->requestq);
  686. if (device_type == 0)
  687. ap_probe_device_type(ap_dev);
  688. else
  689. ap_dev->device_type = device_type;
  690. ap_dev->device.bus = &ap_bus_type;
  691. ap_dev->device.parent = ap_root_device;
  692. snprintf(ap_dev->device.bus_id, BUS_ID_SIZE, "card%02x",
  693. AP_QID_DEVICE(ap_dev->qid));
  694. ap_dev->device.release = ap_device_release;
  695. rc = device_register(&ap_dev->device);
  696. if (rc) {
  697. kfree(ap_dev);
  698. continue;
  699. }
  700. /* Add device attributes. */
  701. rc = sysfs_create_group(&ap_dev->device.kobj,
  702. &ap_dev_attr_group);
  703. if (!rc) {
  704. spin_lock_bh(&ap_dev->lock);
  705. ap_dev->unregistered = 0;
  706. spin_unlock_bh(&ap_dev->lock);
  707. }
  708. else
  709. device_unregister(&ap_dev->device);
  710. }
  711. }
  712. static void
  713. ap_config_timeout(unsigned long ptr)
  714. {
  715. queue_work(ap_work_queue, &ap_config_work);
  716. ap_config_timer.expires = jiffies + ap_config_time * HZ;
  717. add_timer(&ap_config_timer);
  718. }
  719. /**
  720. * Set up the timer to run the poll tasklet
  721. */
  722. static inline void ap_schedule_poll_timer(void)
  723. {
  724. if (timer_pending(&ap_poll_timer))
  725. return;
  726. mod_timer(&ap_poll_timer, jiffies + AP_POLL_TIME);
  727. }
  728. /**
  729. * Receive pending reply messages from an AP device.
  730. * @ap_dev: pointer to the AP device
  731. * @flags: pointer to control flags, bit 2^0 is set if another poll is
  732. * required, bit 2^1 is set if the poll timer needs to get armed
  733. * Returns 0 if the device is still present, -ENODEV if not.
  734. */
  735. static inline int ap_poll_read(struct ap_device *ap_dev, unsigned long *flags)
  736. {
  737. struct ap_queue_status status;
  738. struct ap_message *ap_msg;
  739. if (ap_dev->queue_count <= 0)
  740. return 0;
  741. status = __ap_recv(ap_dev->qid, &ap_dev->reply->psmid,
  742. ap_dev->reply->message, ap_dev->reply->length);
  743. switch (status.response_code) {
  744. case AP_RESPONSE_NORMAL:
  745. atomic_dec(&ap_poll_requests);
  746. ap_dev->queue_count--;
  747. list_for_each_entry(ap_msg, &ap_dev->pendingq, list) {
  748. if (ap_msg->psmid != ap_dev->reply->psmid)
  749. continue;
  750. list_del_init(&ap_msg->list);
  751. ap_dev->pendingq_count--;
  752. ap_dev->drv->receive(ap_dev, ap_msg, ap_dev->reply);
  753. break;
  754. }
  755. if (ap_dev->queue_count > 0)
  756. *flags |= 1;
  757. break;
  758. case AP_RESPONSE_NO_PENDING_REPLY:
  759. if (status.queue_empty) {
  760. /* The card shouldn't forget requests but who knows. */
  761. ap_dev->queue_count = 0;
  762. list_splice_init(&ap_dev->pendingq, &ap_dev->requestq);
  763. ap_dev->requestq_count += ap_dev->pendingq_count;
  764. ap_dev->pendingq_count = 0;
  765. } else
  766. *flags |= 2;
  767. break;
  768. default:
  769. return -ENODEV;
  770. }
  771. return 0;
  772. }
  773. /**
  774. * Send messages from the request queue to an AP device.
  775. * @ap_dev: pointer to the AP device
  776. * @flags: pointer to control flags, bit 2^0 is set if another poll is
  777. * required, bit 2^1 is set if the poll timer needs to get armed
  778. * Returns 0 if the device is still present, -ENODEV if not.
  779. */
  780. static inline int ap_poll_write(struct ap_device *ap_dev, unsigned long *flags)
  781. {
  782. struct ap_queue_status status;
  783. struct ap_message *ap_msg;
  784. if (ap_dev->requestq_count <= 0 ||
  785. ap_dev->queue_count >= ap_dev->queue_depth)
  786. return 0;
  787. /* Start the next request on the queue. */
  788. ap_msg = list_entry(ap_dev->requestq.next, struct ap_message, list);
  789. status = __ap_send(ap_dev->qid, ap_msg->psmid,
  790. ap_msg->message, ap_msg->length);
  791. switch (status.response_code) {
  792. case AP_RESPONSE_NORMAL:
  793. atomic_inc(&ap_poll_requests);
  794. ap_dev->queue_count++;
  795. list_move_tail(&ap_msg->list, &ap_dev->pendingq);
  796. ap_dev->requestq_count--;
  797. ap_dev->pendingq_count++;
  798. if (ap_dev->queue_count < ap_dev->queue_depth &&
  799. ap_dev->requestq_count > 0)
  800. *flags |= 1;
  801. *flags |= 2;
  802. break;
  803. case AP_RESPONSE_Q_FULL:
  804. *flags |= 2;
  805. break;
  806. case AP_RESPONSE_MESSAGE_TOO_BIG:
  807. return -EINVAL;
  808. default:
  809. return -ENODEV;
  810. }
  811. return 0;
  812. }
  813. /**
  814. * Poll AP device for pending replies and send new messages. If either
  815. * ap_poll_read or ap_poll_write returns -ENODEV unregister the device.
  816. * @ap_dev: pointer to the bus device
  817. * @flags: pointer to control flags, bit 2^0 is set if another poll is
  818. * required, bit 2^1 is set if the poll timer needs to get armed
  819. * Returns 0.
  820. */
  821. static inline int ap_poll_queue(struct ap_device *ap_dev, unsigned long *flags)
  822. {
  823. int rc;
  824. rc = ap_poll_read(ap_dev, flags);
  825. if (rc)
  826. return rc;
  827. return ap_poll_write(ap_dev, flags);
  828. }
  829. /**
  830. * Queue a message to a device.
  831. * @ap_dev: pointer to the AP device
  832. * @ap_msg: the message to be queued
  833. */
  834. static int __ap_queue_message(struct ap_device *ap_dev, struct ap_message *ap_msg)
  835. {
  836. struct ap_queue_status status;
  837. if (list_empty(&ap_dev->requestq) &&
  838. ap_dev->queue_count < ap_dev->queue_depth) {
  839. status = __ap_send(ap_dev->qid, ap_msg->psmid,
  840. ap_msg->message, ap_msg->length);
  841. switch (status.response_code) {
  842. case AP_RESPONSE_NORMAL:
  843. list_add_tail(&ap_msg->list, &ap_dev->pendingq);
  844. atomic_inc(&ap_poll_requests);
  845. ap_dev->pendingq_count++;
  846. ap_dev->queue_count++;
  847. ap_dev->total_request_count++;
  848. break;
  849. case AP_RESPONSE_Q_FULL:
  850. list_add_tail(&ap_msg->list, &ap_dev->requestq);
  851. ap_dev->requestq_count++;
  852. ap_dev->total_request_count++;
  853. return -EBUSY;
  854. case AP_RESPONSE_MESSAGE_TOO_BIG:
  855. ap_dev->drv->receive(ap_dev, ap_msg, ERR_PTR(-EINVAL));
  856. return -EINVAL;
  857. default: /* Device is gone. */
  858. ap_dev->drv->receive(ap_dev, ap_msg, ERR_PTR(-ENODEV));
  859. return -ENODEV;
  860. }
  861. } else {
  862. list_add_tail(&ap_msg->list, &ap_dev->requestq);
  863. ap_dev->requestq_count++;
  864. ap_dev->total_request_count++;
  865. return -EBUSY;
  866. }
  867. ap_schedule_poll_timer();
  868. return 0;
  869. }
  870. void ap_queue_message(struct ap_device *ap_dev, struct ap_message *ap_msg)
  871. {
  872. unsigned long flags;
  873. int rc;
  874. spin_lock_bh(&ap_dev->lock);
  875. if (!ap_dev->unregistered) {
  876. /* Make room on the queue by polling for finished requests. */
  877. rc = ap_poll_queue(ap_dev, &flags);
  878. if (!rc)
  879. rc = __ap_queue_message(ap_dev, ap_msg);
  880. if (!rc)
  881. wake_up(&ap_poll_wait);
  882. if (rc == -ENODEV)
  883. ap_dev->unregistered = 1;
  884. } else {
  885. ap_dev->drv->receive(ap_dev, ap_msg, ERR_PTR(-ENODEV));
  886. rc = 0;
  887. }
  888. spin_unlock_bh(&ap_dev->lock);
  889. if (rc == -ENODEV)
  890. device_unregister(&ap_dev->device);
  891. }
  892. EXPORT_SYMBOL(ap_queue_message);
  893. /**
  894. * Cancel a crypto request. This is done by removing the request
  895. * from the devive pendingq or requestq queue. Note that the
  896. * request stays on the AP queue. When it finishes the message
  897. * reply will be discarded because the psmid can't be found.
  898. * @ap_dev: AP device that has the message queued
  899. * @ap_msg: the message that is to be removed
  900. */
  901. void ap_cancel_message(struct ap_device *ap_dev, struct ap_message *ap_msg)
  902. {
  903. struct ap_message *tmp;
  904. spin_lock_bh(&ap_dev->lock);
  905. if (!list_empty(&ap_msg->list)) {
  906. list_for_each_entry(tmp, &ap_dev->pendingq, list)
  907. if (tmp->psmid == ap_msg->psmid) {
  908. ap_dev->pendingq_count--;
  909. goto found;
  910. }
  911. ap_dev->requestq_count--;
  912. found:
  913. list_del_init(&ap_msg->list);
  914. }
  915. spin_unlock_bh(&ap_dev->lock);
  916. }
  917. EXPORT_SYMBOL(ap_cancel_message);
  918. /**
  919. * AP receive polling for finished AP requests
  920. */
  921. static void ap_poll_timeout(unsigned long unused)
  922. {
  923. tasklet_schedule(&ap_tasklet);
  924. }
  925. /**
  926. * Poll all AP devices on the bus in a round robin fashion. Continue
  927. * polling until bit 2^0 of the control flags is not set. If bit 2^1
  928. * of the control flags has been set arm the poll timer.
  929. */
  930. static int __ap_poll_all(struct device *dev, void *data)
  931. {
  932. struct ap_device *ap_dev = to_ap_dev(dev);
  933. int rc;
  934. spin_lock(&ap_dev->lock);
  935. if (!ap_dev->unregistered) {
  936. rc = ap_poll_queue(to_ap_dev(dev), (unsigned long *) data);
  937. if (rc)
  938. ap_dev->unregistered = 1;
  939. } else
  940. rc = 0;
  941. spin_unlock(&ap_dev->lock);
  942. if (rc)
  943. device_unregister(&ap_dev->device);
  944. return 0;
  945. }
  946. static void ap_poll_all(unsigned long dummy)
  947. {
  948. unsigned long flags;
  949. do {
  950. flags = 0;
  951. bus_for_each_dev(&ap_bus_type, NULL, &flags, __ap_poll_all);
  952. } while (flags & 1);
  953. if (flags & 2)
  954. ap_schedule_poll_timer();
  955. }
  956. /**
  957. * AP bus poll thread. The purpose of this thread is to poll for
  958. * finished requests in a loop if there is a "free" cpu - that is
  959. * a cpu that doesn't have anything better to do. The polling stops
  960. * as soon as there is another task or if all messages have been
  961. * delivered.
  962. */
  963. static int ap_poll_thread(void *data)
  964. {
  965. DECLARE_WAITQUEUE(wait, current);
  966. unsigned long flags;
  967. int requests;
  968. set_user_nice(current, 19);
  969. while (1) {
  970. if (need_resched()) {
  971. schedule();
  972. continue;
  973. }
  974. add_wait_queue(&ap_poll_wait, &wait);
  975. set_current_state(TASK_INTERRUPTIBLE);
  976. if (kthread_should_stop())
  977. break;
  978. requests = atomic_read(&ap_poll_requests);
  979. if (requests <= 0)
  980. schedule();
  981. set_current_state(TASK_RUNNING);
  982. remove_wait_queue(&ap_poll_wait, &wait);
  983. local_bh_disable();
  984. flags = 0;
  985. bus_for_each_dev(&ap_bus_type, NULL, &flags, __ap_poll_all);
  986. local_bh_enable();
  987. }
  988. set_current_state(TASK_RUNNING);
  989. remove_wait_queue(&ap_poll_wait, &wait);
  990. return 0;
  991. }
  992. static int ap_poll_thread_start(void)
  993. {
  994. int rc;
  995. mutex_lock(&ap_poll_thread_mutex);
  996. if (!ap_poll_kthread) {
  997. ap_poll_kthread = kthread_run(ap_poll_thread, NULL, "appoll");
  998. rc = IS_ERR(ap_poll_kthread) ? PTR_ERR(ap_poll_kthread) : 0;
  999. if (rc)
  1000. ap_poll_kthread = NULL;
  1001. }
  1002. else
  1003. rc = 0;
  1004. mutex_unlock(&ap_poll_thread_mutex);
  1005. return rc;
  1006. }
  1007. static void ap_poll_thread_stop(void)
  1008. {
  1009. mutex_lock(&ap_poll_thread_mutex);
  1010. if (ap_poll_kthread) {
  1011. kthread_stop(ap_poll_kthread);
  1012. ap_poll_kthread = NULL;
  1013. }
  1014. mutex_unlock(&ap_poll_thread_mutex);
  1015. }
  1016. /**
  1017. * The module initialization code.
  1018. */
  1019. int __init ap_module_init(void)
  1020. {
  1021. int rc, i;
  1022. if (ap_domain_index < -1 || ap_domain_index >= AP_DOMAINS) {
  1023. printk(KERN_WARNING "Invalid param: domain = %d. "
  1024. " Not loading.\n", ap_domain_index);
  1025. return -EINVAL;
  1026. }
  1027. if (ap_instructions_available() != 0) {
  1028. printk(KERN_WARNING "AP instructions not installed.\n");
  1029. return -ENODEV;
  1030. }
  1031. /* Create /sys/bus/ap. */
  1032. rc = bus_register(&ap_bus_type);
  1033. if (rc)
  1034. goto out;
  1035. for (i = 0; ap_bus_attrs[i]; i++) {
  1036. rc = bus_create_file(&ap_bus_type, ap_bus_attrs[i]);
  1037. if (rc)
  1038. goto out_bus;
  1039. }
  1040. /* Create /sys/devices/ap. */
  1041. ap_root_device = s390_root_dev_register("ap");
  1042. rc = IS_ERR(ap_root_device) ? PTR_ERR(ap_root_device) : 0;
  1043. if (rc)
  1044. goto out_bus;
  1045. ap_work_queue = create_singlethread_workqueue("kapwork");
  1046. if (!ap_work_queue) {
  1047. rc = -ENOMEM;
  1048. goto out_root;
  1049. }
  1050. if (ap_select_domain() == 0)
  1051. ap_scan_bus(NULL);
  1052. /* Setup the ap bus rescan timer. */
  1053. init_timer(&ap_config_timer);
  1054. ap_config_timer.function = ap_config_timeout;
  1055. ap_config_timer.data = 0;
  1056. ap_config_timer.expires = jiffies + ap_config_time * HZ;
  1057. add_timer(&ap_config_timer);
  1058. /* Start the low priority AP bus poll thread. */
  1059. if (ap_thread_flag) {
  1060. rc = ap_poll_thread_start();
  1061. if (rc)
  1062. goto out_work;
  1063. }
  1064. return 0;
  1065. out_work:
  1066. del_timer_sync(&ap_config_timer);
  1067. del_timer_sync(&ap_poll_timer);
  1068. destroy_workqueue(ap_work_queue);
  1069. out_root:
  1070. s390_root_dev_unregister(ap_root_device);
  1071. out_bus:
  1072. while (i--)
  1073. bus_remove_file(&ap_bus_type, ap_bus_attrs[i]);
  1074. bus_unregister(&ap_bus_type);
  1075. out:
  1076. return rc;
  1077. }
  1078. static int __ap_match_all(struct device *dev, void *data)
  1079. {
  1080. return 1;
  1081. }
  1082. /**
  1083. * The module termination code
  1084. */
  1085. void ap_module_exit(void)
  1086. {
  1087. int i;
  1088. struct device *dev;
  1089. ap_poll_thread_stop();
  1090. del_timer_sync(&ap_config_timer);
  1091. del_timer_sync(&ap_poll_timer);
  1092. destroy_workqueue(ap_work_queue);
  1093. s390_root_dev_unregister(ap_root_device);
  1094. while ((dev = bus_find_device(&ap_bus_type, NULL, NULL,
  1095. __ap_match_all)))
  1096. {
  1097. device_unregister(dev);
  1098. put_device(dev);
  1099. }
  1100. for (i = 0; ap_bus_attrs[i]; i++)
  1101. bus_remove_file(&ap_bus_type, ap_bus_attrs[i]);
  1102. bus_unregister(&ap_bus_type);
  1103. }
  1104. #ifndef CONFIG_ZCRYPT_MONOLITHIC
  1105. module_init(ap_module_init);
  1106. module_exit(ap_module_exit);
  1107. #endif