ap_bus.c 32 KB

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