ap_bus.c 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright IBM Corp. 2006, 2012
  4. * Author(s): Cornelia Huck <cornelia.huck@de.ibm.com>
  5. * Martin Schwidefsky <schwidefsky@de.ibm.com>
  6. * Ralph Wuerthner <rwuerthn@de.ibm.com>
  7. * Felix Beck <felix.beck@de.ibm.com>
  8. * Holger Dengler <hd@linux.vnet.ibm.com>
  9. *
  10. * Adjunct processor bus.
  11. */
  12. #define KMSG_COMPONENT "ap"
  13. #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
  14. #include <linux/kernel_stat.h>
  15. #include <linux/moduleparam.h>
  16. #include <linux/init.h>
  17. #include <linux/delay.h>
  18. #include <linux/err.h>
  19. #include <linux/interrupt.h>
  20. #include <linux/workqueue.h>
  21. #include <linux/slab.h>
  22. #include <linux/notifier.h>
  23. #include <linux/kthread.h>
  24. #include <linux/mutex.h>
  25. #include <linux/suspend.h>
  26. #include <asm/airq.h>
  27. #include <linux/atomic.h>
  28. #include <asm/isc.h>
  29. #include <linux/hrtimer.h>
  30. #include <linux/ktime.h>
  31. #include <asm/facility.h>
  32. #include <linux/crypto.h>
  33. #include <linux/mod_devicetable.h>
  34. #include <linux/debugfs.h>
  35. #include "ap_bus.h"
  36. #include "ap_asm.h"
  37. #include "ap_debug.h"
  38. /*
  39. * Module parameters; note though this file itself isn't modular.
  40. */
  41. int ap_domain_index = -1; /* Adjunct Processor Domain Index */
  42. static DEFINE_SPINLOCK(ap_domain_lock);
  43. module_param_named(domain, ap_domain_index, int, S_IRUSR|S_IRGRP);
  44. MODULE_PARM_DESC(domain, "domain index for ap devices");
  45. EXPORT_SYMBOL(ap_domain_index);
  46. static int ap_thread_flag = 0;
  47. module_param_named(poll_thread, ap_thread_flag, int, S_IRUSR|S_IRGRP);
  48. MODULE_PARM_DESC(poll_thread, "Turn on/off poll thread, default is 0 (off).");
  49. static struct device *ap_root_device;
  50. DEFINE_SPINLOCK(ap_list_lock);
  51. LIST_HEAD(ap_card_list);
  52. static struct ap_config_info *ap_configuration;
  53. static bool initialised;
  54. /*
  55. * AP bus related debug feature things.
  56. */
  57. debug_info_t *ap_dbf_info;
  58. /*
  59. * Workqueue timer for bus rescan.
  60. */
  61. static struct timer_list ap_config_timer;
  62. static int ap_config_time = AP_CONFIG_TIME;
  63. static void ap_scan_bus(struct work_struct *);
  64. static DECLARE_WORK(ap_scan_work, ap_scan_bus);
  65. /*
  66. * Tasklet & timer for AP request polling and interrupts
  67. */
  68. static void ap_tasklet_fn(unsigned long);
  69. static DECLARE_TASKLET(ap_tasklet, ap_tasklet_fn, 0);
  70. static DECLARE_WAIT_QUEUE_HEAD(ap_poll_wait);
  71. static struct task_struct *ap_poll_kthread = NULL;
  72. static DEFINE_MUTEX(ap_poll_thread_mutex);
  73. static DEFINE_SPINLOCK(ap_poll_timer_lock);
  74. static struct hrtimer ap_poll_timer;
  75. /* In LPAR poll with 4kHz frequency. Poll every 250000 nanoseconds.
  76. * If z/VM change to 1500000 nanoseconds to adjust to z/VM polling.*/
  77. static unsigned long long poll_timeout = 250000;
  78. /* Suspend flag */
  79. static int ap_suspend_flag;
  80. /* Maximum domain id */
  81. static int ap_max_domain_id;
  82. /* Flag to check if domain was set through module parameter domain=. This is
  83. * important when supsend and resume is done in a z/VM environment where the
  84. * domain might change. */
  85. static int user_set_domain = 0;
  86. static struct bus_type ap_bus_type;
  87. /* Adapter interrupt definitions */
  88. static void ap_interrupt_handler(struct airq_struct *airq);
  89. static int ap_airq_flag;
  90. static struct airq_struct ap_airq = {
  91. .handler = ap_interrupt_handler,
  92. .isc = AP_ISC,
  93. };
  94. /**
  95. * ap_using_interrupts() - Returns non-zero if interrupt support is
  96. * available.
  97. */
  98. static inline int ap_using_interrupts(void)
  99. {
  100. return ap_airq_flag;
  101. }
  102. /**
  103. * ap_airq_ptr() - Get the address of the adapter interrupt indicator
  104. *
  105. * Returns the address of the local-summary-indicator of the adapter
  106. * interrupt handler for AP, or NULL if adapter interrupts are not
  107. * available.
  108. */
  109. void *ap_airq_ptr(void)
  110. {
  111. if (ap_using_interrupts())
  112. return ap_airq.lsi_ptr;
  113. return NULL;
  114. }
  115. /**
  116. * ap_interrupts_available(): Test if AP interrupts are available.
  117. *
  118. * Returns 1 if AP interrupts are available.
  119. */
  120. static int ap_interrupts_available(void)
  121. {
  122. return test_facility(65);
  123. }
  124. /**
  125. * ap_configuration_available(): Test if AP configuration
  126. * information is available.
  127. *
  128. * Returns 1 if AP configuration information is available.
  129. */
  130. static int ap_configuration_available(void)
  131. {
  132. return test_facility(12);
  133. }
  134. /**
  135. * ap_apft_available(): Test if AP facilities test (APFT)
  136. * facility is available.
  137. *
  138. * Returns 1 if APFT is is available.
  139. */
  140. static int ap_apft_available(void)
  141. {
  142. return test_facility(15);
  143. }
  144. /*
  145. * ap_qact_available(): Test if the PQAP(QACT) subfunction is available.
  146. *
  147. * Returns 1 if the QACT subfunction is available.
  148. */
  149. static inline int ap_qact_available(void)
  150. {
  151. if (ap_configuration)
  152. return ap_configuration->qact;
  153. return 0;
  154. }
  155. /**
  156. * ap_test_queue(): Test adjunct processor queue.
  157. * @qid: The AP queue number
  158. * @tbit: Test facilities bit
  159. * @info: Pointer to queue descriptor
  160. *
  161. * Returns AP queue status structure.
  162. */
  163. struct ap_queue_status ap_test_queue(ap_qid_t qid,
  164. int tbit,
  165. unsigned long *info)
  166. {
  167. if (tbit)
  168. qid |= 1UL << 23; /* set T bit*/
  169. return ap_tapq(qid, info);
  170. }
  171. EXPORT_SYMBOL(ap_test_queue);
  172. /*
  173. * ap_query_configuration(): Fetch cryptographic config info
  174. *
  175. * Returns the ap configuration info fetched via PQAP(QCI).
  176. * On success 0 is returned, on failure a negative errno
  177. * is returned, e.g. if the PQAP(QCI) instruction is not
  178. * available, the return value will be -EOPNOTSUPP.
  179. */
  180. int ap_query_configuration(struct ap_config_info *info)
  181. {
  182. if (!ap_configuration_available())
  183. return -EOPNOTSUPP;
  184. if (!info)
  185. return -EINVAL;
  186. return ap_qci(info);
  187. }
  188. EXPORT_SYMBOL(ap_query_configuration);
  189. /**
  190. * ap_init_configuration(): Allocate and query configuration array.
  191. */
  192. static void ap_init_configuration(void)
  193. {
  194. if (!ap_configuration_available())
  195. return;
  196. ap_configuration = kzalloc(sizeof(*ap_configuration), GFP_KERNEL);
  197. if (!ap_configuration)
  198. return;
  199. if (ap_query_configuration(ap_configuration) != 0) {
  200. kfree(ap_configuration);
  201. ap_configuration = NULL;
  202. return;
  203. }
  204. }
  205. /*
  206. * ap_test_config(): helper function to extract the nrth bit
  207. * within the unsigned int array field.
  208. */
  209. static inline int ap_test_config(unsigned int *field, unsigned int nr)
  210. {
  211. return ap_test_bit((field + (nr >> 5)), (nr & 0x1f));
  212. }
  213. /*
  214. * ap_test_config_card_id(): Test, whether an AP card ID is configured.
  215. * @id AP card ID
  216. *
  217. * Returns 0 if the card is not configured
  218. * 1 if the card is configured or
  219. * if the configuration information is not available
  220. */
  221. static inline int ap_test_config_card_id(unsigned int id)
  222. {
  223. if (!ap_configuration) /* QCI not supported */
  224. return 1;
  225. return ap_test_config(ap_configuration->apm, id);
  226. }
  227. /*
  228. * ap_test_config_domain(): Test, whether an AP usage domain is configured.
  229. * @domain AP usage domain ID
  230. *
  231. * Returns 0 if the usage domain is not configured
  232. * 1 if the usage domain is configured or
  233. * if the configuration information is not available
  234. */
  235. static inline int ap_test_config_domain(unsigned int domain)
  236. {
  237. if (!ap_configuration) /* QCI not supported */
  238. return domain < 16;
  239. return ap_test_config(ap_configuration->aqm, domain);
  240. }
  241. /**
  242. * ap_query_queue(): Check if an AP queue is available.
  243. * @qid: The AP queue number
  244. * @queue_depth: Pointer to queue depth value
  245. * @device_type: Pointer to device type value
  246. * @facilities: Pointer to facility indicator
  247. */
  248. static int ap_query_queue(ap_qid_t qid, int *queue_depth, int *device_type,
  249. unsigned int *facilities)
  250. {
  251. struct ap_queue_status status;
  252. unsigned long info;
  253. int nd;
  254. if (!ap_test_config_card_id(AP_QID_CARD(qid)))
  255. return -ENODEV;
  256. status = ap_test_queue(qid, ap_apft_available(), &info);
  257. switch (status.response_code) {
  258. case AP_RESPONSE_NORMAL:
  259. *queue_depth = (int)(info & 0xff);
  260. *device_type = (int)((info >> 24) & 0xff);
  261. *facilities = (unsigned int)(info >> 32);
  262. /* Update maximum domain id */
  263. nd = (info >> 16) & 0xff;
  264. /* if N bit is available, z13 and newer */
  265. if ((info & (1UL << 57)) && nd > 0)
  266. ap_max_domain_id = nd;
  267. else /* older machine types */
  268. ap_max_domain_id = 15;
  269. switch (*device_type) {
  270. /* For CEX2 and CEX3 the available functions
  271. * are not refrected by the facilities bits.
  272. * Instead it is coded into the type. So here
  273. * modify the function bits based on the type.
  274. */
  275. case AP_DEVICE_TYPE_CEX2A:
  276. case AP_DEVICE_TYPE_CEX3A:
  277. *facilities |= 0x08000000;
  278. break;
  279. case AP_DEVICE_TYPE_CEX2C:
  280. case AP_DEVICE_TYPE_CEX3C:
  281. *facilities |= 0x10000000;
  282. break;
  283. default:
  284. break;
  285. }
  286. return 0;
  287. case AP_RESPONSE_Q_NOT_AVAIL:
  288. case AP_RESPONSE_DECONFIGURED:
  289. case AP_RESPONSE_CHECKSTOPPED:
  290. case AP_RESPONSE_INVALID_ADDRESS:
  291. return -ENODEV;
  292. case AP_RESPONSE_RESET_IN_PROGRESS:
  293. case AP_RESPONSE_OTHERWISE_CHANGED:
  294. case AP_RESPONSE_BUSY:
  295. return -EBUSY;
  296. default:
  297. BUG();
  298. }
  299. }
  300. void ap_wait(enum ap_wait wait)
  301. {
  302. ktime_t hr_time;
  303. switch (wait) {
  304. case AP_WAIT_AGAIN:
  305. case AP_WAIT_INTERRUPT:
  306. if (ap_using_interrupts())
  307. break;
  308. if (ap_poll_kthread) {
  309. wake_up(&ap_poll_wait);
  310. break;
  311. }
  312. /* Fall through */
  313. case AP_WAIT_TIMEOUT:
  314. spin_lock_bh(&ap_poll_timer_lock);
  315. if (!hrtimer_is_queued(&ap_poll_timer)) {
  316. hr_time = poll_timeout;
  317. hrtimer_forward_now(&ap_poll_timer, hr_time);
  318. hrtimer_restart(&ap_poll_timer);
  319. }
  320. spin_unlock_bh(&ap_poll_timer_lock);
  321. break;
  322. case AP_WAIT_NONE:
  323. default:
  324. break;
  325. }
  326. }
  327. /**
  328. * ap_request_timeout(): Handling of request timeouts
  329. * @t: timer making this callback
  330. *
  331. * Handles request timeouts.
  332. */
  333. void ap_request_timeout(struct timer_list *t)
  334. {
  335. struct ap_queue *aq = from_timer(aq, t, timeout);
  336. if (ap_suspend_flag)
  337. return;
  338. spin_lock_bh(&aq->lock);
  339. ap_wait(ap_sm_event(aq, AP_EVENT_TIMEOUT));
  340. spin_unlock_bh(&aq->lock);
  341. }
  342. /**
  343. * ap_poll_timeout(): AP receive polling for finished AP requests.
  344. * @unused: Unused pointer.
  345. *
  346. * Schedules the AP tasklet using a high resolution timer.
  347. */
  348. static enum hrtimer_restart ap_poll_timeout(struct hrtimer *unused)
  349. {
  350. if (!ap_suspend_flag)
  351. tasklet_schedule(&ap_tasklet);
  352. return HRTIMER_NORESTART;
  353. }
  354. /**
  355. * ap_interrupt_handler() - Schedule ap_tasklet on interrupt
  356. * @airq: pointer to adapter interrupt descriptor
  357. */
  358. static void ap_interrupt_handler(struct airq_struct *airq)
  359. {
  360. inc_irq_stat(IRQIO_APB);
  361. if (!ap_suspend_flag)
  362. tasklet_schedule(&ap_tasklet);
  363. }
  364. /**
  365. * ap_tasklet_fn(): Tasklet to poll all AP devices.
  366. * @dummy: Unused variable
  367. *
  368. * Poll all AP devices on the bus.
  369. */
  370. static void ap_tasklet_fn(unsigned long dummy)
  371. {
  372. struct ap_card *ac;
  373. struct ap_queue *aq;
  374. enum ap_wait wait = AP_WAIT_NONE;
  375. /* Reset the indicator if interrupts are used. Thus new interrupts can
  376. * be received. Doing it in the beginning of the tasklet is therefor
  377. * important that no requests on any AP get lost.
  378. */
  379. if (ap_using_interrupts())
  380. xchg(ap_airq.lsi_ptr, 0);
  381. spin_lock_bh(&ap_list_lock);
  382. for_each_ap_card(ac) {
  383. for_each_ap_queue(aq, ac) {
  384. spin_lock_bh(&aq->lock);
  385. wait = min(wait, ap_sm_event_loop(aq, AP_EVENT_POLL));
  386. spin_unlock_bh(&aq->lock);
  387. }
  388. }
  389. spin_unlock_bh(&ap_list_lock);
  390. ap_wait(wait);
  391. }
  392. static int ap_pending_requests(void)
  393. {
  394. struct ap_card *ac;
  395. struct ap_queue *aq;
  396. spin_lock_bh(&ap_list_lock);
  397. for_each_ap_card(ac) {
  398. for_each_ap_queue(aq, ac) {
  399. if (aq->queue_count == 0)
  400. continue;
  401. spin_unlock_bh(&ap_list_lock);
  402. return 1;
  403. }
  404. }
  405. spin_unlock_bh(&ap_list_lock);
  406. return 0;
  407. }
  408. /**
  409. * ap_poll_thread(): Thread that polls for finished requests.
  410. * @data: Unused pointer
  411. *
  412. * AP bus poll thread. The purpose of this thread is to poll for
  413. * finished requests in a loop if there is a "free" cpu - that is
  414. * a cpu that doesn't have anything better to do. The polling stops
  415. * as soon as there is another task or if all messages have been
  416. * delivered.
  417. */
  418. static int ap_poll_thread(void *data)
  419. {
  420. DECLARE_WAITQUEUE(wait, current);
  421. set_user_nice(current, MAX_NICE);
  422. set_freezable();
  423. while (!kthread_should_stop()) {
  424. add_wait_queue(&ap_poll_wait, &wait);
  425. set_current_state(TASK_INTERRUPTIBLE);
  426. if (ap_suspend_flag || !ap_pending_requests()) {
  427. schedule();
  428. try_to_freeze();
  429. }
  430. set_current_state(TASK_RUNNING);
  431. remove_wait_queue(&ap_poll_wait, &wait);
  432. if (need_resched()) {
  433. schedule();
  434. try_to_freeze();
  435. continue;
  436. }
  437. ap_tasklet_fn(0);
  438. }
  439. return 0;
  440. }
  441. static int ap_poll_thread_start(void)
  442. {
  443. int rc;
  444. if (ap_using_interrupts() || ap_poll_kthread)
  445. return 0;
  446. mutex_lock(&ap_poll_thread_mutex);
  447. ap_poll_kthread = kthread_run(ap_poll_thread, NULL, "appoll");
  448. rc = PTR_RET(ap_poll_kthread);
  449. if (rc)
  450. ap_poll_kthread = NULL;
  451. mutex_unlock(&ap_poll_thread_mutex);
  452. return rc;
  453. }
  454. static void ap_poll_thread_stop(void)
  455. {
  456. if (!ap_poll_kthread)
  457. return;
  458. mutex_lock(&ap_poll_thread_mutex);
  459. kthread_stop(ap_poll_kthread);
  460. ap_poll_kthread = NULL;
  461. mutex_unlock(&ap_poll_thread_mutex);
  462. }
  463. #define is_card_dev(x) ((x)->parent == ap_root_device)
  464. #define is_queue_dev(x) ((x)->parent != ap_root_device)
  465. /**
  466. * ap_bus_match()
  467. * @dev: Pointer to device
  468. * @drv: Pointer to device_driver
  469. *
  470. * AP bus driver registration/unregistration.
  471. */
  472. static int ap_bus_match(struct device *dev, struct device_driver *drv)
  473. {
  474. struct ap_driver *ap_drv = to_ap_drv(drv);
  475. struct ap_device_id *id;
  476. /*
  477. * Compare device type of the device with the list of
  478. * supported types of the device_driver.
  479. */
  480. for (id = ap_drv->ids; id->match_flags; id++) {
  481. if (is_card_dev(dev) &&
  482. id->match_flags & AP_DEVICE_ID_MATCH_CARD_TYPE &&
  483. id->dev_type == to_ap_dev(dev)->device_type)
  484. return 1;
  485. if (is_queue_dev(dev) &&
  486. id->match_flags & AP_DEVICE_ID_MATCH_QUEUE_TYPE &&
  487. id->dev_type == to_ap_dev(dev)->device_type)
  488. return 1;
  489. }
  490. return 0;
  491. }
  492. /**
  493. * ap_uevent(): Uevent function for AP devices.
  494. * @dev: Pointer to device
  495. * @env: Pointer to kobj_uevent_env
  496. *
  497. * It sets up a single environment variable DEV_TYPE which contains the
  498. * hardware device type.
  499. */
  500. static int ap_uevent (struct device *dev, struct kobj_uevent_env *env)
  501. {
  502. struct ap_device *ap_dev = to_ap_dev(dev);
  503. int retval = 0;
  504. if (!ap_dev)
  505. return -ENODEV;
  506. /* Set up DEV_TYPE environment variable. */
  507. retval = add_uevent_var(env, "DEV_TYPE=%04X", ap_dev->device_type);
  508. if (retval)
  509. return retval;
  510. /* Add MODALIAS= */
  511. retval = add_uevent_var(env, "MODALIAS=ap:t%02X", ap_dev->device_type);
  512. return retval;
  513. }
  514. static int ap_dev_suspend(struct device *dev)
  515. {
  516. struct ap_device *ap_dev = to_ap_dev(dev);
  517. if (ap_dev->drv && ap_dev->drv->suspend)
  518. ap_dev->drv->suspend(ap_dev);
  519. return 0;
  520. }
  521. static int ap_dev_resume(struct device *dev)
  522. {
  523. struct ap_device *ap_dev = to_ap_dev(dev);
  524. if (ap_dev->drv && ap_dev->drv->resume)
  525. ap_dev->drv->resume(ap_dev);
  526. return 0;
  527. }
  528. static void ap_bus_suspend(void)
  529. {
  530. AP_DBF(DBF_DEBUG, "ap_bus_suspend running\n");
  531. ap_suspend_flag = 1;
  532. /*
  533. * Disable scanning for devices, thus we do not want to scan
  534. * for them after removing.
  535. */
  536. flush_work(&ap_scan_work);
  537. tasklet_disable(&ap_tasklet);
  538. }
  539. static int __ap_card_devices_unregister(struct device *dev, void *dummy)
  540. {
  541. if (is_card_dev(dev))
  542. device_unregister(dev);
  543. return 0;
  544. }
  545. static int __ap_queue_devices_unregister(struct device *dev, void *dummy)
  546. {
  547. if (is_queue_dev(dev))
  548. device_unregister(dev);
  549. return 0;
  550. }
  551. static int __ap_queue_devices_with_id_unregister(struct device *dev, void *data)
  552. {
  553. if (is_queue_dev(dev) &&
  554. AP_QID_CARD(to_ap_queue(dev)->qid) == (int)(long) data)
  555. device_unregister(dev);
  556. return 0;
  557. }
  558. static void ap_bus_resume(void)
  559. {
  560. int rc;
  561. AP_DBF(DBF_DEBUG, "ap_bus_resume running\n");
  562. /* remove all queue devices */
  563. bus_for_each_dev(&ap_bus_type, NULL, NULL,
  564. __ap_queue_devices_unregister);
  565. /* remove all card devices */
  566. bus_for_each_dev(&ap_bus_type, NULL, NULL,
  567. __ap_card_devices_unregister);
  568. /* Reset thin interrupt setting */
  569. if (ap_interrupts_available() && !ap_using_interrupts()) {
  570. rc = register_adapter_interrupt(&ap_airq);
  571. ap_airq_flag = (rc == 0);
  572. }
  573. if (!ap_interrupts_available() && ap_using_interrupts()) {
  574. unregister_adapter_interrupt(&ap_airq);
  575. ap_airq_flag = 0;
  576. }
  577. /* Reset domain */
  578. if (!user_set_domain)
  579. ap_domain_index = -1;
  580. /* Get things going again */
  581. ap_suspend_flag = 0;
  582. if (ap_airq_flag)
  583. xchg(ap_airq.lsi_ptr, 0);
  584. tasklet_enable(&ap_tasklet);
  585. queue_work(system_long_wq, &ap_scan_work);
  586. }
  587. static int ap_power_event(struct notifier_block *this, unsigned long event,
  588. void *ptr)
  589. {
  590. switch (event) {
  591. case PM_HIBERNATION_PREPARE:
  592. case PM_SUSPEND_PREPARE:
  593. ap_bus_suspend();
  594. break;
  595. case PM_POST_HIBERNATION:
  596. case PM_POST_SUSPEND:
  597. ap_bus_resume();
  598. break;
  599. default:
  600. break;
  601. }
  602. return NOTIFY_DONE;
  603. }
  604. static struct notifier_block ap_power_notifier = {
  605. .notifier_call = ap_power_event,
  606. };
  607. static SIMPLE_DEV_PM_OPS(ap_bus_pm_ops, ap_dev_suspend, ap_dev_resume);
  608. static struct bus_type ap_bus_type = {
  609. .name = "ap",
  610. .match = &ap_bus_match,
  611. .uevent = &ap_uevent,
  612. .pm = &ap_bus_pm_ops,
  613. };
  614. static int ap_device_probe(struct device *dev)
  615. {
  616. struct ap_device *ap_dev = to_ap_dev(dev);
  617. struct ap_driver *ap_drv = to_ap_drv(dev->driver);
  618. int rc;
  619. /* Add queue/card to list of active queues/cards */
  620. spin_lock_bh(&ap_list_lock);
  621. if (is_card_dev(dev))
  622. list_add(&to_ap_card(dev)->list, &ap_card_list);
  623. else
  624. list_add(&to_ap_queue(dev)->list,
  625. &to_ap_queue(dev)->card->queues);
  626. spin_unlock_bh(&ap_list_lock);
  627. ap_dev->drv = ap_drv;
  628. rc = ap_drv->probe ? ap_drv->probe(ap_dev) : -ENODEV;
  629. if (rc) {
  630. spin_lock_bh(&ap_list_lock);
  631. if (is_card_dev(dev))
  632. list_del_init(&to_ap_card(dev)->list);
  633. else
  634. list_del_init(&to_ap_queue(dev)->list);
  635. spin_unlock_bh(&ap_list_lock);
  636. ap_dev->drv = NULL;
  637. }
  638. return rc;
  639. }
  640. static int ap_device_remove(struct device *dev)
  641. {
  642. struct ap_device *ap_dev = to_ap_dev(dev);
  643. struct ap_driver *ap_drv = ap_dev->drv;
  644. if (ap_drv->remove)
  645. ap_drv->remove(ap_dev);
  646. /* Remove queue/card from list of active queues/cards */
  647. spin_lock_bh(&ap_list_lock);
  648. if (is_card_dev(dev))
  649. list_del_init(&to_ap_card(dev)->list);
  650. else
  651. list_del_init(&to_ap_queue(dev)->list);
  652. spin_unlock_bh(&ap_list_lock);
  653. return 0;
  654. }
  655. int ap_driver_register(struct ap_driver *ap_drv, struct module *owner,
  656. char *name)
  657. {
  658. struct device_driver *drv = &ap_drv->driver;
  659. if (!initialised)
  660. return -ENODEV;
  661. drv->bus = &ap_bus_type;
  662. drv->probe = ap_device_probe;
  663. drv->remove = ap_device_remove;
  664. drv->owner = owner;
  665. drv->name = name;
  666. return driver_register(drv);
  667. }
  668. EXPORT_SYMBOL(ap_driver_register);
  669. void ap_driver_unregister(struct ap_driver *ap_drv)
  670. {
  671. driver_unregister(&ap_drv->driver);
  672. }
  673. EXPORT_SYMBOL(ap_driver_unregister);
  674. void ap_bus_force_rescan(void)
  675. {
  676. if (ap_suspend_flag)
  677. return;
  678. /* processing a asynchronous bus rescan */
  679. del_timer(&ap_config_timer);
  680. queue_work(system_long_wq, &ap_scan_work);
  681. flush_work(&ap_scan_work);
  682. }
  683. EXPORT_SYMBOL(ap_bus_force_rescan);
  684. /*
  685. * AP bus attributes.
  686. */
  687. static ssize_t ap_domain_show(struct bus_type *bus, char *buf)
  688. {
  689. return snprintf(buf, PAGE_SIZE, "%d\n", ap_domain_index);
  690. }
  691. static ssize_t ap_domain_store(struct bus_type *bus,
  692. const char *buf, size_t count)
  693. {
  694. int domain;
  695. if (sscanf(buf, "%i\n", &domain) != 1 ||
  696. domain < 0 || domain > ap_max_domain_id)
  697. return -EINVAL;
  698. spin_lock_bh(&ap_domain_lock);
  699. ap_domain_index = domain;
  700. spin_unlock_bh(&ap_domain_lock);
  701. AP_DBF(DBF_DEBUG, "stored new default domain=%d\n", domain);
  702. return count;
  703. }
  704. static BUS_ATTR(ap_domain, 0644, ap_domain_show, ap_domain_store);
  705. static ssize_t ap_control_domain_mask_show(struct bus_type *bus, char *buf)
  706. {
  707. if (!ap_configuration) /* QCI not supported */
  708. return snprintf(buf, PAGE_SIZE, "not supported\n");
  709. return snprintf(buf, PAGE_SIZE,
  710. "0x%08x%08x%08x%08x%08x%08x%08x%08x\n",
  711. ap_configuration->adm[0], ap_configuration->adm[1],
  712. ap_configuration->adm[2], ap_configuration->adm[3],
  713. ap_configuration->adm[4], ap_configuration->adm[5],
  714. ap_configuration->adm[6], ap_configuration->adm[7]);
  715. }
  716. static BUS_ATTR(ap_control_domain_mask, 0444,
  717. ap_control_domain_mask_show, NULL);
  718. static ssize_t ap_usage_domain_mask_show(struct bus_type *bus, char *buf)
  719. {
  720. if (!ap_configuration) /* QCI not supported */
  721. return snprintf(buf, PAGE_SIZE, "not supported\n");
  722. return snprintf(buf, PAGE_SIZE,
  723. "0x%08x%08x%08x%08x%08x%08x%08x%08x\n",
  724. ap_configuration->aqm[0], ap_configuration->aqm[1],
  725. ap_configuration->aqm[2], ap_configuration->aqm[3],
  726. ap_configuration->aqm[4], ap_configuration->aqm[5],
  727. ap_configuration->aqm[6], ap_configuration->aqm[7]);
  728. }
  729. static BUS_ATTR(ap_usage_domain_mask, 0444,
  730. ap_usage_domain_mask_show, NULL);
  731. static ssize_t ap_config_time_show(struct bus_type *bus, char *buf)
  732. {
  733. return snprintf(buf, PAGE_SIZE, "%d\n", ap_config_time);
  734. }
  735. static ssize_t ap_interrupts_show(struct bus_type *bus, char *buf)
  736. {
  737. return snprintf(buf, PAGE_SIZE, "%d\n",
  738. ap_using_interrupts() ? 1 : 0);
  739. }
  740. static BUS_ATTR(ap_interrupts, 0444, ap_interrupts_show, NULL);
  741. static ssize_t ap_config_time_store(struct bus_type *bus,
  742. const char *buf, size_t count)
  743. {
  744. int time;
  745. if (sscanf(buf, "%d\n", &time) != 1 || time < 5 || time > 120)
  746. return -EINVAL;
  747. ap_config_time = time;
  748. mod_timer(&ap_config_timer, jiffies + ap_config_time * HZ);
  749. return count;
  750. }
  751. static BUS_ATTR(config_time, 0644, ap_config_time_show, ap_config_time_store);
  752. static ssize_t ap_poll_thread_show(struct bus_type *bus, char *buf)
  753. {
  754. return snprintf(buf, PAGE_SIZE, "%d\n", ap_poll_kthread ? 1 : 0);
  755. }
  756. static ssize_t ap_poll_thread_store(struct bus_type *bus,
  757. const char *buf, size_t count)
  758. {
  759. int flag, rc;
  760. if (sscanf(buf, "%d\n", &flag) != 1)
  761. return -EINVAL;
  762. if (flag) {
  763. rc = ap_poll_thread_start();
  764. if (rc)
  765. count = rc;
  766. } else
  767. ap_poll_thread_stop();
  768. return count;
  769. }
  770. static BUS_ATTR(poll_thread, 0644, ap_poll_thread_show, ap_poll_thread_store);
  771. static ssize_t poll_timeout_show(struct bus_type *bus, char *buf)
  772. {
  773. return snprintf(buf, PAGE_SIZE, "%llu\n", poll_timeout);
  774. }
  775. static ssize_t poll_timeout_store(struct bus_type *bus, const char *buf,
  776. size_t count)
  777. {
  778. unsigned long long time;
  779. ktime_t hr_time;
  780. /* 120 seconds = maximum poll interval */
  781. if (sscanf(buf, "%llu\n", &time) != 1 || time < 1 ||
  782. time > 120000000000ULL)
  783. return -EINVAL;
  784. poll_timeout = time;
  785. hr_time = poll_timeout;
  786. spin_lock_bh(&ap_poll_timer_lock);
  787. hrtimer_cancel(&ap_poll_timer);
  788. hrtimer_set_expires(&ap_poll_timer, hr_time);
  789. hrtimer_start_expires(&ap_poll_timer, HRTIMER_MODE_ABS);
  790. spin_unlock_bh(&ap_poll_timer_lock);
  791. return count;
  792. }
  793. static BUS_ATTR(poll_timeout, 0644, poll_timeout_show, poll_timeout_store);
  794. static ssize_t ap_max_domain_id_show(struct bus_type *bus, char *buf)
  795. {
  796. int max_domain_id;
  797. if (ap_configuration)
  798. max_domain_id = ap_max_domain_id ? : -1;
  799. else
  800. max_domain_id = 15;
  801. return snprintf(buf, PAGE_SIZE, "%d\n", max_domain_id);
  802. }
  803. static BUS_ATTR(ap_max_domain_id, 0444, ap_max_domain_id_show, NULL);
  804. static struct bus_attribute *const ap_bus_attrs[] = {
  805. &bus_attr_ap_domain,
  806. &bus_attr_ap_control_domain_mask,
  807. &bus_attr_ap_usage_domain_mask,
  808. &bus_attr_config_time,
  809. &bus_attr_poll_thread,
  810. &bus_attr_ap_interrupts,
  811. &bus_attr_poll_timeout,
  812. &bus_attr_ap_max_domain_id,
  813. NULL,
  814. };
  815. /**
  816. * ap_select_domain(): Select an AP domain.
  817. *
  818. * Pick one of the 16 AP domains.
  819. */
  820. static int ap_select_domain(void)
  821. {
  822. int count, max_count, best_domain;
  823. struct ap_queue_status status;
  824. int i, j;
  825. /*
  826. * We want to use a single domain. Either the one specified with
  827. * the "domain=" parameter or the domain with the maximum number
  828. * of devices.
  829. */
  830. spin_lock_bh(&ap_domain_lock);
  831. if (ap_domain_index >= 0) {
  832. /* Domain has already been selected. */
  833. spin_unlock_bh(&ap_domain_lock);
  834. return 0;
  835. }
  836. best_domain = -1;
  837. max_count = 0;
  838. for (i = 0; i < AP_DOMAINS; i++) {
  839. if (!ap_test_config_domain(i))
  840. continue;
  841. count = 0;
  842. for (j = 0; j < AP_DEVICES; j++) {
  843. if (!ap_test_config_card_id(j))
  844. continue;
  845. status = ap_test_queue(AP_MKQID(j, i),
  846. ap_apft_available(),
  847. NULL);
  848. if (status.response_code != AP_RESPONSE_NORMAL)
  849. continue;
  850. count++;
  851. }
  852. if (count > max_count) {
  853. max_count = count;
  854. best_domain = i;
  855. }
  856. }
  857. if (best_domain >= 0){
  858. ap_domain_index = best_domain;
  859. AP_DBF(DBF_DEBUG, "new ap_domain_index=%d\n", ap_domain_index);
  860. spin_unlock_bh(&ap_domain_lock);
  861. return 0;
  862. }
  863. spin_unlock_bh(&ap_domain_lock);
  864. return -ENODEV;
  865. }
  866. /*
  867. * This function checks the type and returns either 0 for not
  868. * supported or the highest compatible type value (which may
  869. * include the input type value).
  870. */
  871. static int ap_get_compatible_type(ap_qid_t qid, int rawtype, unsigned int func)
  872. {
  873. int comp_type = 0;
  874. /* < CEX2A is not supported */
  875. if (rawtype < AP_DEVICE_TYPE_CEX2A)
  876. return 0;
  877. /* up to CEX6 known and fully supported */
  878. if (rawtype <= AP_DEVICE_TYPE_CEX6)
  879. return rawtype;
  880. /*
  881. * unknown new type > CEX6, check for compatibility
  882. * to the highest known and supported type which is
  883. * currently CEX6 with the help of the QACT function.
  884. */
  885. if (ap_qact_available()) {
  886. struct ap_queue_status status;
  887. union ap_qact_ap_info apinfo = {0};
  888. apinfo.mode = (func >> 26) & 0x07;
  889. apinfo.cat = AP_DEVICE_TYPE_CEX6;
  890. status = ap_qact(qid, 0, &apinfo);
  891. if (status.response_code == AP_RESPONSE_NORMAL
  892. && apinfo.cat >= AP_DEVICE_TYPE_CEX2A
  893. && apinfo.cat <= AP_DEVICE_TYPE_CEX6)
  894. comp_type = apinfo.cat;
  895. }
  896. if (!comp_type)
  897. AP_DBF(DBF_WARN, "queue=%02x.%04x unable to map type %d\n",
  898. AP_QID_CARD(qid), AP_QID_QUEUE(qid), rawtype);
  899. else if (comp_type != rawtype)
  900. AP_DBF(DBF_INFO, "queue=%02x.%04x map type %d to %d\n",
  901. AP_QID_CARD(qid), AP_QID_QUEUE(qid), rawtype, comp_type);
  902. return comp_type;
  903. }
  904. /*
  905. * helper function to be used with bus_find_dev
  906. * matches for the card device with the given id
  907. */
  908. static int __match_card_device_with_id(struct device *dev, void *data)
  909. {
  910. return is_card_dev(dev) && to_ap_card(dev)->id == (int)(long) data;
  911. }
  912. /* helper function to be used with bus_find_dev
  913. * matches for the queue device with a given qid
  914. */
  915. static int __match_queue_device_with_qid(struct device *dev, void *data)
  916. {
  917. return is_queue_dev(dev) && to_ap_queue(dev)->qid == (int)(long) data;
  918. }
  919. /**
  920. * ap_scan_bus(): Scan the AP bus for new devices
  921. * Runs periodically, workqueue timer (ap_config_time)
  922. */
  923. static void ap_scan_bus(struct work_struct *unused)
  924. {
  925. struct ap_queue *aq;
  926. struct ap_card *ac;
  927. struct device *dev;
  928. ap_qid_t qid;
  929. int comp_type, depth = 0, type = 0;
  930. unsigned int func = 0;
  931. int rc, id, dom, borked, domains, defdomdevs = 0;
  932. AP_DBF(DBF_DEBUG, "ap_scan_bus running\n");
  933. ap_query_configuration(ap_configuration);
  934. if (ap_select_domain() != 0)
  935. goto out;
  936. for (id = 0; id < AP_DEVICES; id++) {
  937. /* check if device is registered */
  938. dev = bus_find_device(&ap_bus_type, NULL,
  939. (void *)(long) id,
  940. __match_card_device_with_id);
  941. ac = dev ? to_ap_card(dev) : NULL;
  942. if (!ap_test_config_card_id(id)) {
  943. if (dev) {
  944. /* Card device has been removed from
  945. * configuration, remove the belonging
  946. * queue devices.
  947. */
  948. bus_for_each_dev(&ap_bus_type, NULL,
  949. (void *)(long) id,
  950. __ap_queue_devices_with_id_unregister);
  951. /* now remove the card device */
  952. device_unregister(dev);
  953. put_device(dev);
  954. }
  955. continue;
  956. }
  957. /* According to the configuration there should be a card
  958. * device, so check if there is at least one valid queue
  959. * and maybe create queue devices and the card device.
  960. */
  961. domains = 0;
  962. for (dom = 0; dom < AP_DOMAINS; dom++) {
  963. qid = AP_MKQID(id, dom);
  964. dev = bus_find_device(&ap_bus_type, NULL,
  965. (void *)(long) qid,
  966. __match_queue_device_with_qid);
  967. aq = dev ? to_ap_queue(dev) : NULL;
  968. if (!ap_test_config_domain(dom)) {
  969. if (dev) {
  970. /* Queue device exists but has been
  971. * removed from configuration.
  972. */
  973. device_unregister(dev);
  974. put_device(dev);
  975. }
  976. continue;
  977. }
  978. rc = ap_query_queue(qid, &depth, &type, &func);
  979. if (dev) {
  980. spin_lock_bh(&aq->lock);
  981. if (rc == -ENODEV ||
  982. /* adapter reconfiguration */
  983. (ac && ac->functions != func))
  984. aq->state = AP_STATE_BORKED;
  985. borked = aq->state == AP_STATE_BORKED;
  986. spin_unlock_bh(&aq->lock);
  987. if (borked) /* Remove broken device */
  988. device_unregister(dev);
  989. put_device(dev);
  990. if (!borked) {
  991. domains++;
  992. if (dom == ap_domain_index)
  993. defdomdevs++;
  994. continue;
  995. }
  996. }
  997. if (rc)
  998. continue;
  999. /* a new queue device is needed, check out comp type */
  1000. comp_type = ap_get_compatible_type(qid, type, func);
  1001. if (!comp_type)
  1002. continue;
  1003. /* maybe a card device needs to be created first */
  1004. if (!ac) {
  1005. ac = ap_card_create(id, depth, type,
  1006. comp_type, func);
  1007. if (!ac)
  1008. continue;
  1009. ac->ap_dev.device.bus = &ap_bus_type;
  1010. ac->ap_dev.device.parent = ap_root_device;
  1011. dev_set_name(&ac->ap_dev.device,
  1012. "card%02x", id);
  1013. /* Register card with AP bus */
  1014. rc = device_register(&ac->ap_dev.device);
  1015. if (rc) {
  1016. put_device(&ac->ap_dev.device);
  1017. ac = NULL;
  1018. break;
  1019. }
  1020. /* get it and thus adjust reference counter */
  1021. get_device(&ac->ap_dev.device);
  1022. }
  1023. /* now create the new queue device */
  1024. aq = ap_queue_create(qid, comp_type);
  1025. if (!aq)
  1026. continue;
  1027. aq->card = ac;
  1028. aq->ap_dev.device.bus = &ap_bus_type;
  1029. aq->ap_dev.device.parent = &ac->ap_dev.device;
  1030. dev_set_name(&aq->ap_dev.device,
  1031. "%02x.%04x", id, dom);
  1032. /* Start with a device reset */
  1033. spin_lock_bh(&aq->lock);
  1034. ap_wait(ap_sm_event(aq, AP_EVENT_POLL));
  1035. spin_unlock_bh(&aq->lock);
  1036. /* Register device */
  1037. rc = device_register(&aq->ap_dev.device);
  1038. if (rc) {
  1039. put_device(&aq->ap_dev.device);
  1040. continue;
  1041. }
  1042. domains++;
  1043. if (dom == ap_domain_index)
  1044. defdomdevs++;
  1045. } /* end domain loop */
  1046. if (ac) {
  1047. /* remove card dev if there are no queue devices */
  1048. if (!domains)
  1049. device_unregister(&ac->ap_dev.device);
  1050. put_device(&ac->ap_dev.device);
  1051. }
  1052. } /* end device loop */
  1053. if (defdomdevs < 1)
  1054. AP_DBF(DBF_INFO, "no queue device with default domain %d available\n",
  1055. ap_domain_index);
  1056. out:
  1057. mod_timer(&ap_config_timer, jiffies + ap_config_time * HZ);
  1058. }
  1059. static void ap_config_timeout(struct timer_list *unused)
  1060. {
  1061. if (ap_suspend_flag)
  1062. return;
  1063. queue_work(system_long_wq, &ap_scan_work);
  1064. }
  1065. static int __init ap_debug_init(void)
  1066. {
  1067. ap_dbf_info = debug_register("ap", 1, 1,
  1068. DBF_MAX_SPRINTF_ARGS * sizeof(long));
  1069. debug_register_view(ap_dbf_info, &debug_sprintf_view);
  1070. debug_set_level(ap_dbf_info, DBF_ERR);
  1071. return 0;
  1072. }
  1073. /**
  1074. * ap_module_init(): The module initialization code.
  1075. *
  1076. * Initializes the module.
  1077. */
  1078. static int __init ap_module_init(void)
  1079. {
  1080. int max_domain_id;
  1081. int rc, i;
  1082. rc = ap_debug_init();
  1083. if (rc)
  1084. return rc;
  1085. if (ap_instructions_available() != 0) {
  1086. pr_warn("The hardware system does not support AP instructions\n");
  1087. return -ENODEV;
  1088. }
  1089. /* Get AP configuration data if available */
  1090. ap_init_configuration();
  1091. if (ap_configuration)
  1092. max_domain_id =
  1093. ap_max_domain_id ? ap_max_domain_id : AP_DOMAINS - 1;
  1094. else
  1095. max_domain_id = 15;
  1096. if (ap_domain_index < -1 || ap_domain_index > max_domain_id) {
  1097. pr_warn("%d is not a valid cryptographic domain\n",
  1098. ap_domain_index);
  1099. ap_domain_index = -1;
  1100. }
  1101. /* In resume callback we need to know if the user had set the domain.
  1102. * If so, we can not just reset it.
  1103. */
  1104. if (ap_domain_index >= 0)
  1105. user_set_domain = 1;
  1106. if (ap_interrupts_available()) {
  1107. rc = register_adapter_interrupt(&ap_airq);
  1108. ap_airq_flag = (rc == 0);
  1109. }
  1110. /* Create /sys/bus/ap. */
  1111. rc = bus_register(&ap_bus_type);
  1112. if (rc)
  1113. goto out;
  1114. for (i = 0; ap_bus_attrs[i]; i++) {
  1115. rc = bus_create_file(&ap_bus_type, ap_bus_attrs[i]);
  1116. if (rc)
  1117. goto out_bus;
  1118. }
  1119. /* Create /sys/devices/ap. */
  1120. ap_root_device = root_device_register("ap");
  1121. rc = PTR_RET(ap_root_device);
  1122. if (rc)
  1123. goto out_bus;
  1124. /* Setup the AP bus rescan timer. */
  1125. timer_setup(&ap_config_timer, ap_config_timeout, 0);
  1126. /*
  1127. * Setup the high resultion poll timer.
  1128. * If we are running under z/VM adjust polling to z/VM polling rate.
  1129. */
  1130. if (MACHINE_IS_VM)
  1131. poll_timeout = 1500000;
  1132. spin_lock_init(&ap_poll_timer_lock);
  1133. hrtimer_init(&ap_poll_timer, CLOCK_MONOTONIC, HRTIMER_MODE_ABS);
  1134. ap_poll_timer.function = ap_poll_timeout;
  1135. /* Start the low priority AP bus poll thread. */
  1136. if (ap_thread_flag) {
  1137. rc = ap_poll_thread_start();
  1138. if (rc)
  1139. goto out_work;
  1140. }
  1141. rc = register_pm_notifier(&ap_power_notifier);
  1142. if (rc)
  1143. goto out_pm;
  1144. queue_work(system_long_wq, &ap_scan_work);
  1145. initialised = true;
  1146. return 0;
  1147. out_pm:
  1148. ap_poll_thread_stop();
  1149. out_work:
  1150. hrtimer_cancel(&ap_poll_timer);
  1151. root_device_unregister(ap_root_device);
  1152. out_bus:
  1153. while (i--)
  1154. bus_remove_file(&ap_bus_type, ap_bus_attrs[i]);
  1155. bus_unregister(&ap_bus_type);
  1156. out:
  1157. if (ap_using_interrupts())
  1158. unregister_adapter_interrupt(&ap_airq);
  1159. kfree(ap_configuration);
  1160. return rc;
  1161. }
  1162. device_initcall(ap_module_init);