ap_bus.c 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227
  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. rc = ap_query_queue(qid, &queue_depth, &device_type);
  668. if (dev && rc) {
  669. put_device(dev);
  670. device_unregister(dev);
  671. continue;
  672. }
  673. if (dev) {
  674. put_device(dev);
  675. continue;
  676. }
  677. if (rc)
  678. continue;
  679. rc = ap_init_queue(qid);
  680. if (rc)
  681. continue;
  682. ap_dev = kzalloc(sizeof(*ap_dev), GFP_KERNEL);
  683. if (!ap_dev)
  684. break;
  685. ap_dev->qid = qid;
  686. ap_dev->queue_depth = queue_depth;
  687. ap_dev->unregistered = 1;
  688. spin_lock_init(&ap_dev->lock);
  689. INIT_LIST_HEAD(&ap_dev->pendingq);
  690. INIT_LIST_HEAD(&ap_dev->requestq);
  691. if (device_type == 0)
  692. ap_probe_device_type(ap_dev);
  693. else
  694. ap_dev->device_type = device_type;
  695. ap_dev->device.bus = &ap_bus_type;
  696. ap_dev->device.parent = ap_root_device;
  697. snprintf(ap_dev->device.bus_id, BUS_ID_SIZE, "card%02x",
  698. AP_QID_DEVICE(ap_dev->qid));
  699. ap_dev->device.release = ap_device_release;
  700. rc = device_register(&ap_dev->device);
  701. if (rc) {
  702. kfree(ap_dev);
  703. continue;
  704. }
  705. /* Add device attributes. */
  706. rc = sysfs_create_group(&ap_dev->device.kobj,
  707. &ap_dev_attr_group);
  708. if (!rc) {
  709. spin_lock_bh(&ap_dev->lock);
  710. ap_dev->unregistered = 0;
  711. spin_unlock_bh(&ap_dev->lock);
  712. }
  713. else
  714. device_unregister(&ap_dev->device);
  715. }
  716. }
  717. static void
  718. ap_config_timeout(unsigned long ptr)
  719. {
  720. queue_work(ap_work_queue, &ap_config_work);
  721. ap_config_timer.expires = jiffies + ap_config_time * HZ;
  722. add_timer(&ap_config_timer);
  723. }
  724. /**
  725. * Set up the timer to run the poll tasklet
  726. */
  727. static inline void ap_schedule_poll_timer(void)
  728. {
  729. if (timer_pending(&ap_poll_timer))
  730. return;
  731. mod_timer(&ap_poll_timer, jiffies + AP_POLL_TIME);
  732. }
  733. /**
  734. * Receive pending reply messages from an AP device.
  735. * @ap_dev: pointer to the AP device
  736. * @flags: pointer to control flags, bit 2^0 is set if another poll is
  737. * required, bit 2^1 is set if the poll timer needs to get armed
  738. * Returns 0 if the device is still present, -ENODEV if not.
  739. */
  740. static inline int ap_poll_read(struct ap_device *ap_dev, unsigned long *flags)
  741. {
  742. struct ap_queue_status status;
  743. struct ap_message *ap_msg;
  744. if (ap_dev->queue_count <= 0)
  745. return 0;
  746. status = __ap_recv(ap_dev->qid, &ap_dev->reply->psmid,
  747. ap_dev->reply->message, ap_dev->reply->length);
  748. switch (status.response_code) {
  749. case AP_RESPONSE_NORMAL:
  750. atomic_dec(&ap_poll_requests);
  751. ap_dev->queue_count--;
  752. list_for_each_entry(ap_msg, &ap_dev->pendingq, list) {
  753. if (ap_msg->psmid != ap_dev->reply->psmid)
  754. continue;
  755. list_del_init(&ap_msg->list);
  756. ap_dev->pendingq_count--;
  757. ap_dev->drv->receive(ap_dev, ap_msg, ap_dev->reply);
  758. break;
  759. }
  760. if (ap_dev->queue_count > 0)
  761. *flags |= 1;
  762. break;
  763. case AP_RESPONSE_NO_PENDING_REPLY:
  764. if (status.queue_empty) {
  765. /* The card shouldn't forget requests but who knows. */
  766. ap_dev->queue_count = 0;
  767. list_splice_init(&ap_dev->pendingq, &ap_dev->requestq);
  768. ap_dev->requestq_count += ap_dev->pendingq_count;
  769. ap_dev->pendingq_count = 0;
  770. } else
  771. *flags |= 2;
  772. break;
  773. default:
  774. return -ENODEV;
  775. }
  776. return 0;
  777. }
  778. /**
  779. * Send messages from the request queue to an AP device.
  780. * @ap_dev: pointer to the AP device
  781. * @flags: pointer to control flags, bit 2^0 is set if another poll is
  782. * required, bit 2^1 is set if the poll timer needs to get armed
  783. * Returns 0 if the device is still present, -ENODEV if not.
  784. */
  785. static inline int ap_poll_write(struct ap_device *ap_dev, unsigned long *flags)
  786. {
  787. struct ap_queue_status status;
  788. struct ap_message *ap_msg;
  789. if (ap_dev->requestq_count <= 0 ||
  790. ap_dev->queue_count >= ap_dev->queue_depth)
  791. return 0;
  792. /* Start the next request on the queue. */
  793. ap_msg = list_entry(ap_dev->requestq.next, struct ap_message, list);
  794. status = __ap_send(ap_dev->qid, ap_msg->psmid,
  795. ap_msg->message, ap_msg->length);
  796. switch (status.response_code) {
  797. case AP_RESPONSE_NORMAL:
  798. atomic_inc(&ap_poll_requests);
  799. ap_dev->queue_count++;
  800. list_move_tail(&ap_msg->list, &ap_dev->pendingq);
  801. ap_dev->requestq_count--;
  802. ap_dev->pendingq_count++;
  803. if (ap_dev->queue_count < ap_dev->queue_depth &&
  804. ap_dev->requestq_count > 0)
  805. *flags |= 1;
  806. *flags |= 2;
  807. break;
  808. case AP_RESPONSE_Q_FULL:
  809. *flags |= 2;
  810. break;
  811. case AP_RESPONSE_MESSAGE_TOO_BIG:
  812. return -EINVAL;
  813. default:
  814. return -ENODEV;
  815. }
  816. return 0;
  817. }
  818. /**
  819. * Poll AP device for pending replies and send new messages. If either
  820. * ap_poll_read or ap_poll_write returns -ENODEV unregister the device.
  821. * @ap_dev: pointer to the bus device
  822. * @flags: pointer to control flags, bit 2^0 is set if another poll is
  823. * required, bit 2^1 is set if the poll timer needs to get armed
  824. * Returns 0.
  825. */
  826. static inline int ap_poll_queue(struct ap_device *ap_dev, unsigned long *flags)
  827. {
  828. int rc;
  829. rc = ap_poll_read(ap_dev, flags);
  830. if (rc)
  831. return rc;
  832. return ap_poll_write(ap_dev, flags);
  833. }
  834. /**
  835. * Queue a message to a device.
  836. * @ap_dev: pointer to the AP device
  837. * @ap_msg: the message to be queued
  838. */
  839. static int __ap_queue_message(struct ap_device *ap_dev, struct ap_message *ap_msg)
  840. {
  841. struct ap_queue_status status;
  842. if (list_empty(&ap_dev->requestq) &&
  843. ap_dev->queue_count < ap_dev->queue_depth) {
  844. status = __ap_send(ap_dev->qid, ap_msg->psmid,
  845. ap_msg->message, ap_msg->length);
  846. switch (status.response_code) {
  847. case AP_RESPONSE_NORMAL:
  848. list_add_tail(&ap_msg->list, &ap_dev->pendingq);
  849. atomic_inc(&ap_poll_requests);
  850. ap_dev->pendingq_count++;
  851. ap_dev->queue_count++;
  852. ap_dev->total_request_count++;
  853. break;
  854. case AP_RESPONSE_Q_FULL:
  855. list_add_tail(&ap_msg->list, &ap_dev->requestq);
  856. ap_dev->requestq_count++;
  857. ap_dev->total_request_count++;
  858. return -EBUSY;
  859. case AP_RESPONSE_MESSAGE_TOO_BIG:
  860. ap_dev->drv->receive(ap_dev, ap_msg, ERR_PTR(-EINVAL));
  861. return -EINVAL;
  862. default: /* Device is gone. */
  863. ap_dev->drv->receive(ap_dev, ap_msg, ERR_PTR(-ENODEV));
  864. return -ENODEV;
  865. }
  866. } else {
  867. list_add_tail(&ap_msg->list, &ap_dev->requestq);
  868. ap_dev->requestq_count++;
  869. ap_dev->total_request_count++;
  870. return -EBUSY;
  871. }
  872. ap_schedule_poll_timer();
  873. return 0;
  874. }
  875. void ap_queue_message(struct ap_device *ap_dev, struct ap_message *ap_msg)
  876. {
  877. unsigned long flags;
  878. int rc;
  879. spin_lock_bh(&ap_dev->lock);
  880. if (!ap_dev->unregistered) {
  881. /* Make room on the queue by polling for finished requests. */
  882. rc = ap_poll_queue(ap_dev, &flags);
  883. if (!rc)
  884. rc = __ap_queue_message(ap_dev, ap_msg);
  885. if (!rc)
  886. wake_up(&ap_poll_wait);
  887. if (rc == -ENODEV)
  888. ap_dev->unregistered = 1;
  889. } else {
  890. ap_dev->drv->receive(ap_dev, ap_msg, ERR_PTR(-ENODEV));
  891. rc = 0;
  892. }
  893. spin_unlock_bh(&ap_dev->lock);
  894. if (rc == -ENODEV)
  895. device_unregister(&ap_dev->device);
  896. }
  897. EXPORT_SYMBOL(ap_queue_message);
  898. /**
  899. * Cancel a crypto request. This is done by removing the request
  900. * from the devive pendingq or requestq queue. Note that the
  901. * request stays on the AP queue. When it finishes the message
  902. * reply will be discarded because the psmid can't be found.
  903. * @ap_dev: AP device that has the message queued
  904. * @ap_msg: the message that is to be removed
  905. */
  906. void ap_cancel_message(struct ap_device *ap_dev, struct ap_message *ap_msg)
  907. {
  908. struct ap_message *tmp;
  909. spin_lock_bh(&ap_dev->lock);
  910. if (!list_empty(&ap_msg->list)) {
  911. list_for_each_entry(tmp, &ap_dev->pendingq, list)
  912. if (tmp->psmid == ap_msg->psmid) {
  913. ap_dev->pendingq_count--;
  914. goto found;
  915. }
  916. ap_dev->requestq_count--;
  917. found:
  918. list_del_init(&ap_msg->list);
  919. }
  920. spin_unlock_bh(&ap_dev->lock);
  921. }
  922. EXPORT_SYMBOL(ap_cancel_message);
  923. /**
  924. * AP receive polling for finished AP requests
  925. */
  926. static void ap_poll_timeout(unsigned long unused)
  927. {
  928. tasklet_schedule(&ap_tasklet);
  929. }
  930. /**
  931. * Poll all AP devices on the bus in a round robin fashion. Continue
  932. * polling until bit 2^0 of the control flags is not set. If bit 2^1
  933. * of the control flags has been set arm the poll timer.
  934. */
  935. static int __ap_poll_all(struct device *dev, void *data)
  936. {
  937. struct ap_device *ap_dev = to_ap_dev(dev);
  938. int rc;
  939. spin_lock(&ap_dev->lock);
  940. if (!ap_dev->unregistered) {
  941. rc = ap_poll_queue(to_ap_dev(dev), (unsigned long *) data);
  942. if (rc)
  943. ap_dev->unregistered = 1;
  944. } else
  945. rc = 0;
  946. spin_unlock(&ap_dev->lock);
  947. if (rc)
  948. device_unregister(&ap_dev->device);
  949. return 0;
  950. }
  951. static void ap_poll_all(unsigned long dummy)
  952. {
  953. unsigned long flags;
  954. do {
  955. flags = 0;
  956. bus_for_each_dev(&ap_bus_type, NULL, &flags, __ap_poll_all);
  957. } while (flags & 1);
  958. if (flags & 2)
  959. ap_schedule_poll_timer();
  960. }
  961. /**
  962. * AP bus poll thread. The purpose of this thread is to poll for
  963. * finished requests in a loop if there is a "free" cpu - that is
  964. * a cpu that doesn't have anything better to do. The polling stops
  965. * as soon as there is another task or if all messages have been
  966. * delivered.
  967. */
  968. static int ap_poll_thread(void *data)
  969. {
  970. DECLARE_WAITQUEUE(wait, current);
  971. unsigned long flags;
  972. int requests;
  973. set_user_nice(current, 19);
  974. while (1) {
  975. if (need_resched()) {
  976. schedule();
  977. continue;
  978. }
  979. add_wait_queue(&ap_poll_wait, &wait);
  980. set_current_state(TASK_INTERRUPTIBLE);
  981. if (kthread_should_stop())
  982. break;
  983. requests = atomic_read(&ap_poll_requests);
  984. if (requests <= 0)
  985. schedule();
  986. set_current_state(TASK_RUNNING);
  987. remove_wait_queue(&ap_poll_wait, &wait);
  988. local_bh_disable();
  989. flags = 0;
  990. bus_for_each_dev(&ap_bus_type, NULL, &flags, __ap_poll_all);
  991. local_bh_enable();
  992. }
  993. set_current_state(TASK_RUNNING);
  994. remove_wait_queue(&ap_poll_wait, &wait);
  995. return 0;
  996. }
  997. static int ap_poll_thread_start(void)
  998. {
  999. int rc;
  1000. mutex_lock(&ap_poll_thread_mutex);
  1001. if (!ap_poll_kthread) {
  1002. ap_poll_kthread = kthread_run(ap_poll_thread, NULL, "appoll");
  1003. rc = IS_ERR(ap_poll_kthread) ? PTR_ERR(ap_poll_kthread) : 0;
  1004. if (rc)
  1005. ap_poll_kthread = NULL;
  1006. }
  1007. else
  1008. rc = 0;
  1009. mutex_unlock(&ap_poll_thread_mutex);
  1010. return rc;
  1011. }
  1012. static void ap_poll_thread_stop(void)
  1013. {
  1014. mutex_lock(&ap_poll_thread_mutex);
  1015. if (ap_poll_kthread) {
  1016. kthread_stop(ap_poll_kthread);
  1017. ap_poll_kthread = NULL;
  1018. }
  1019. mutex_unlock(&ap_poll_thread_mutex);
  1020. }
  1021. /**
  1022. * The module initialization code.
  1023. */
  1024. int __init ap_module_init(void)
  1025. {
  1026. int rc, i;
  1027. if (ap_domain_index < -1 || ap_domain_index >= AP_DOMAINS) {
  1028. printk(KERN_WARNING "Invalid param: domain = %d. "
  1029. " Not loading.\n", ap_domain_index);
  1030. return -EINVAL;
  1031. }
  1032. if (ap_instructions_available() != 0) {
  1033. printk(KERN_WARNING "AP instructions not installed.\n");
  1034. return -ENODEV;
  1035. }
  1036. /* Create /sys/bus/ap. */
  1037. rc = bus_register(&ap_bus_type);
  1038. if (rc)
  1039. goto out;
  1040. for (i = 0; ap_bus_attrs[i]; i++) {
  1041. rc = bus_create_file(&ap_bus_type, ap_bus_attrs[i]);
  1042. if (rc)
  1043. goto out_bus;
  1044. }
  1045. /* Create /sys/devices/ap. */
  1046. ap_root_device = s390_root_dev_register("ap");
  1047. rc = IS_ERR(ap_root_device) ? PTR_ERR(ap_root_device) : 0;
  1048. if (rc)
  1049. goto out_bus;
  1050. ap_work_queue = create_singlethread_workqueue("kapwork");
  1051. if (!ap_work_queue) {
  1052. rc = -ENOMEM;
  1053. goto out_root;
  1054. }
  1055. if (ap_select_domain() == 0)
  1056. ap_scan_bus(NULL);
  1057. /* Setup the ap bus rescan timer. */
  1058. init_timer(&ap_config_timer);
  1059. ap_config_timer.function = ap_config_timeout;
  1060. ap_config_timer.data = 0;
  1061. ap_config_timer.expires = jiffies + ap_config_time * HZ;
  1062. add_timer(&ap_config_timer);
  1063. /* Start the low priority AP bus poll thread. */
  1064. if (ap_thread_flag) {
  1065. rc = ap_poll_thread_start();
  1066. if (rc)
  1067. goto out_work;
  1068. }
  1069. return 0;
  1070. out_work:
  1071. del_timer_sync(&ap_config_timer);
  1072. del_timer_sync(&ap_poll_timer);
  1073. destroy_workqueue(ap_work_queue);
  1074. out_root:
  1075. s390_root_dev_unregister(ap_root_device);
  1076. out_bus:
  1077. while (i--)
  1078. bus_remove_file(&ap_bus_type, ap_bus_attrs[i]);
  1079. bus_unregister(&ap_bus_type);
  1080. out:
  1081. return rc;
  1082. }
  1083. static int __ap_match_all(struct device *dev, void *data)
  1084. {
  1085. return 1;
  1086. }
  1087. /**
  1088. * The module termination code
  1089. */
  1090. void ap_module_exit(void)
  1091. {
  1092. int i;
  1093. struct device *dev;
  1094. ap_poll_thread_stop();
  1095. del_timer_sync(&ap_config_timer);
  1096. del_timer_sync(&ap_poll_timer);
  1097. destroy_workqueue(ap_work_queue);
  1098. s390_root_dev_unregister(ap_root_device);
  1099. while ((dev = bus_find_device(&ap_bus_type, NULL, NULL,
  1100. __ap_match_all)))
  1101. {
  1102. device_unregister(dev);
  1103. put_device(dev);
  1104. }
  1105. for (i = 0; ap_bus_attrs[i]; i++)
  1106. bus_remove_file(&ap_bus_type, ap_bus_attrs[i]);
  1107. bus_unregister(&ap_bus_type);
  1108. }
  1109. #ifndef CONFIG_ZCRYPT_MONOLITHIC
  1110. module_init(ap_module_init);
  1111. module_exit(ap_module_exit);
  1112. #endif