ap_bus.c 45 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744
  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. * Felix Beck <felix.beck@de.ibm.com>
  9. *
  10. * Adjunct processor bus.
  11. *
  12. * This program is free software; you can redistribute it and/or modify
  13. * it under the terms of the GNU General Public License as published by
  14. * the Free Software Foundation; either version 2, or (at your option)
  15. * any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU General Public License
  23. * along with this program; if not, write to the Free Software
  24. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  25. */
  26. #define KMSG_COMPONENT "ap"
  27. #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
  28. #include <linux/kernel_stat.h>
  29. #include <linux/module.h>
  30. #include <linux/init.h>
  31. #include <linux/delay.h>
  32. #include <linux/err.h>
  33. #include <linux/interrupt.h>
  34. #include <linux/workqueue.h>
  35. #include <linux/slab.h>
  36. #include <linux/notifier.h>
  37. #include <linux/kthread.h>
  38. #include <linux/mutex.h>
  39. #include <asm/reset.h>
  40. #include <asm/airq.h>
  41. #include <asm/atomic.h>
  42. #include <asm/system.h>
  43. #include <asm/isc.h>
  44. #include <linux/hrtimer.h>
  45. #include <linux/ktime.h>
  46. #include "ap_bus.h"
  47. /* Some prototypes. */
  48. static void ap_scan_bus(struct work_struct *);
  49. static void ap_poll_all(unsigned long);
  50. static enum hrtimer_restart ap_poll_timeout(struct hrtimer *);
  51. static int ap_poll_thread_start(void);
  52. static void ap_poll_thread_stop(void);
  53. static void ap_request_timeout(unsigned long);
  54. static inline void ap_schedule_poll_timer(void);
  55. static int __ap_poll_device(struct ap_device *ap_dev, unsigned long *flags);
  56. static int ap_device_remove(struct device *dev);
  57. static int ap_device_probe(struct device *dev);
  58. static void ap_interrupt_handler(void *unused1, void *unused2);
  59. static void ap_reset(struct ap_device *ap_dev);
  60. static void ap_config_timeout(unsigned long ptr);
  61. static int ap_select_domain(void);
  62. /*
  63. * Module description.
  64. */
  65. MODULE_AUTHOR("IBM Corporation");
  66. MODULE_DESCRIPTION("Adjunct Processor Bus driver, "
  67. "Copyright 2006 IBM Corporation");
  68. MODULE_LICENSE("GPL");
  69. /*
  70. * Module parameter
  71. */
  72. int ap_domain_index = -1; /* Adjunct Processor Domain Index */
  73. module_param_named(domain, ap_domain_index, int, 0000);
  74. MODULE_PARM_DESC(domain, "domain index for ap devices");
  75. EXPORT_SYMBOL(ap_domain_index);
  76. static int ap_thread_flag = 0;
  77. module_param_named(poll_thread, ap_thread_flag, int, 0000);
  78. MODULE_PARM_DESC(poll_thread, "Turn on/off poll thread, default is 0 (off).");
  79. static struct device *ap_root_device = NULL;
  80. static DEFINE_SPINLOCK(ap_device_list_lock);
  81. static LIST_HEAD(ap_device_list);
  82. /*
  83. * Workqueue & timer for bus rescan.
  84. */
  85. static struct workqueue_struct *ap_work_queue;
  86. static struct timer_list ap_config_timer;
  87. static int ap_config_time = AP_CONFIG_TIME;
  88. static DECLARE_WORK(ap_config_work, ap_scan_bus);
  89. /*
  90. * Tasklet & timer for AP request polling and interrupts
  91. */
  92. static DECLARE_TASKLET(ap_tasklet, ap_poll_all, 0);
  93. static atomic_t ap_poll_requests = ATOMIC_INIT(0);
  94. static DECLARE_WAIT_QUEUE_HEAD(ap_poll_wait);
  95. static struct task_struct *ap_poll_kthread = NULL;
  96. static DEFINE_MUTEX(ap_poll_thread_mutex);
  97. static DEFINE_SPINLOCK(ap_poll_timer_lock);
  98. static void *ap_interrupt_indicator;
  99. static struct hrtimer ap_poll_timer;
  100. /* In LPAR poll with 4kHz frequency. Poll every 250000 nanoseconds.
  101. * If z/VM change to 1500000 nanoseconds to adjust to z/VM polling.*/
  102. static unsigned long long poll_timeout = 250000;
  103. /* Suspend flag */
  104. static int ap_suspend_flag;
  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. /**
  111. * ap_using_interrupts() - Returns non-zero if interrupt support is
  112. * available.
  113. */
  114. static inline int ap_using_interrupts(void)
  115. {
  116. return ap_interrupt_indicator != NULL;
  117. }
  118. /**
  119. * ap_intructions_available() - Test if AP instructions are available.
  120. *
  121. * Returns 0 if the AP instructions are installed.
  122. */
  123. static inline int ap_instructions_available(void)
  124. {
  125. register unsigned long reg0 asm ("0") = AP_MKQID(0,0);
  126. register unsigned long reg1 asm ("1") = -ENODEV;
  127. register unsigned long reg2 asm ("2") = 0UL;
  128. asm volatile(
  129. " .long 0xb2af0000\n" /* PQAP(TAPQ) */
  130. "0: la %1,0\n"
  131. "1:\n"
  132. EX_TABLE(0b, 1b)
  133. : "+d" (reg0), "+d" (reg1), "+d" (reg2) : : "cc" );
  134. return reg1;
  135. }
  136. /**
  137. * ap_interrupts_available(): Test if AP interrupts are available.
  138. *
  139. * Returns 1 if AP interrupts are available.
  140. */
  141. static int ap_interrupts_available(void)
  142. {
  143. return test_facility(2) && test_facility(65);
  144. }
  145. /**
  146. * ap_test_queue(): Test adjunct processor queue.
  147. * @qid: The AP queue number
  148. * @queue_depth: Pointer to queue depth value
  149. * @device_type: Pointer to device type value
  150. *
  151. * Returns AP queue status structure.
  152. */
  153. static inline struct ap_queue_status
  154. ap_test_queue(ap_qid_t qid, int *queue_depth, int *device_type)
  155. {
  156. register unsigned long reg0 asm ("0") = qid;
  157. register struct ap_queue_status reg1 asm ("1");
  158. register unsigned long reg2 asm ("2") = 0UL;
  159. asm volatile(".long 0xb2af0000" /* PQAP(TAPQ) */
  160. : "+d" (reg0), "=d" (reg1), "+d" (reg2) : : "cc");
  161. *device_type = (int) (reg2 >> 24);
  162. *queue_depth = (int) (reg2 & 0xff);
  163. return reg1;
  164. }
  165. /**
  166. * ap_reset_queue(): Reset adjunct processor queue.
  167. * @qid: The AP queue number
  168. *
  169. * Returns AP queue status structure.
  170. */
  171. static inline struct ap_queue_status ap_reset_queue(ap_qid_t qid)
  172. {
  173. register unsigned long reg0 asm ("0") = qid | 0x01000000UL;
  174. register struct ap_queue_status reg1 asm ("1");
  175. register unsigned long reg2 asm ("2") = 0UL;
  176. asm volatile(
  177. ".long 0xb2af0000" /* PQAP(RAPQ) */
  178. : "+d" (reg0), "=d" (reg1), "+d" (reg2) : : "cc");
  179. return reg1;
  180. }
  181. #ifdef CONFIG_64BIT
  182. /**
  183. * ap_queue_interruption_control(): Enable interruption for a specific AP.
  184. * @qid: The AP queue number
  185. * @ind: The notification indicator byte
  186. *
  187. * Returns AP queue status.
  188. */
  189. static inline struct ap_queue_status
  190. ap_queue_interruption_control(ap_qid_t qid, void *ind)
  191. {
  192. register unsigned long reg0 asm ("0") = qid | 0x03000000UL;
  193. register unsigned long reg1_in asm ("1") = 0x0000800000000000UL | AP_ISC;
  194. register struct ap_queue_status reg1_out asm ("1");
  195. register void *reg2 asm ("2") = ind;
  196. asm volatile(
  197. ".long 0xb2af0000" /* PQAP(RAPQ) */
  198. : "+d" (reg0), "+d" (reg1_in), "=d" (reg1_out), "+d" (reg2)
  199. :
  200. : "cc" );
  201. return reg1_out;
  202. }
  203. #endif
  204. /**
  205. * ap_queue_enable_interruption(): Enable interruption on an AP.
  206. * @qid: The AP queue number
  207. * @ind: the notification indicator byte
  208. *
  209. * Enables interruption on AP queue via ap_queue_interruption_control(). Based
  210. * on the return value it waits a while and tests the AP queue if interrupts
  211. * have been switched on using ap_test_queue().
  212. */
  213. static int ap_queue_enable_interruption(ap_qid_t qid, void *ind)
  214. {
  215. #ifdef CONFIG_64BIT
  216. struct ap_queue_status status;
  217. int t_depth, t_device_type, rc, i;
  218. rc = -EBUSY;
  219. status = ap_queue_interruption_control(qid, ind);
  220. for (i = 0; i < AP_MAX_RESET; i++) {
  221. switch (status.response_code) {
  222. case AP_RESPONSE_NORMAL:
  223. if (status.int_enabled)
  224. return 0;
  225. break;
  226. case AP_RESPONSE_RESET_IN_PROGRESS:
  227. case AP_RESPONSE_BUSY:
  228. break;
  229. case AP_RESPONSE_Q_NOT_AVAIL:
  230. case AP_RESPONSE_DECONFIGURED:
  231. case AP_RESPONSE_CHECKSTOPPED:
  232. case AP_RESPONSE_INVALID_ADDRESS:
  233. return -ENODEV;
  234. case AP_RESPONSE_OTHERWISE_CHANGED:
  235. if (status.int_enabled)
  236. return 0;
  237. break;
  238. default:
  239. break;
  240. }
  241. if (i < AP_MAX_RESET - 1) {
  242. udelay(5);
  243. status = ap_test_queue(qid, &t_depth, &t_device_type);
  244. }
  245. }
  246. return rc;
  247. #else
  248. return -EINVAL;
  249. #endif
  250. }
  251. /**
  252. * __ap_send(): Send message to adjunct processor queue.
  253. * @qid: The AP queue number
  254. * @psmid: The program supplied message identifier
  255. * @msg: The message text
  256. * @length: The message length
  257. * @special: Special Bit
  258. *
  259. * Returns AP queue status structure.
  260. * Condition code 1 on NQAP can't happen because the L bit is 1.
  261. * Condition code 2 on NQAP also means the send is incomplete,
  262. * because a segment boundary was reached. The NQAP is repeated.
  263. */
  264. static inline struct ap_queue_status
  265. __ap_send(ap_qid_t qid, unsigned long long psmid, void *msg, size_t length,
  266. unsigned int special)
  267. {
  268. typedef struct { char _[length]; } msgblock;
  269. register unsigned long reg0 asm ("0") = qid | 0x40000000UL;
  270. register struct ap_queue_status reg1 asm ("1");
  271. register unsigned long reg2 asm ("2") = (unsigned long) msg;
  272. register unsigned long reg3 asm ("3") = (unsigned long) length;
  273. register unsigned long reg4 asm ("4") = (unsigned int) (psmid >> 32);
  274. register unsigned long reg5 asm ("5") = (unsigned int) psmid;
  275. if (special == 1)
  276. reg0 |= 0x400000UL;
  277. asm volatile (
  278. "0: .long 0xb2ad0042\n" /* DQAP */
  279. " brc 2,0b"
  280. : "+d" (reg0), "=d" (reg1), "+d" (reg2), "+d" (reg3)
  281. : "d" (reg4), "d" (reg5), "m" (*(msgblock *) msg)
  282. : "cc" );
  283. return reg1;
  284. }
  285. int ap_send(ap_qid_t qid, unsigned long long psmid, void *msg, size_t length)
  286. {
  287. struct ap_queue_status status;
  288. status = __ap_send(qid, psmid, msg, length, 0);
  289. switch (status.response_code) {
  290. case AP_RESPONSE_NORMAL:
  291. return 0;
  292. case AP_RESPONSE_Q_FULL:
  293. case AP_RESPONSE_RESET_IN_PROGRESS:
  294. return -EBUSY;
  295. case AP_RESPONSE_REQ_FAC_NOT_INST:
  296. return -EINVAL;
  297. default: /* Device is gone. */
  298. return -ENODEV;
  299. }
  300. }
  301. EXPORT_SYMBOL(ap_send);
  302. /**
  303. * __ap_recv(): Receive message from adjunct processor queue.
  304. * @qid: The AP queue number
  305. * @psmid: Pointer to program supplied message identifier
  306. * @msg: The message text
  307. * @length: The message length
  308. *
  309. * Returns AP queue status structure.
  310. * Condition code 1 on DQAP means the receive has taken place
  311. * but only partially. The response is incomplete, hence the
  312. * DQAP is repeated.
  313. * Condition code 2 on DQAP also means the receive is incomplete,
  314. * this time because a segment boundary was reached. Again, the
  315. * DQAP is repeated.
  316. * Note that gpr2 is used by the DQAP instruction to keep track of
  317. * any 'residual' length, in case the instruction gets interrupted.
  318. * Hence it gets zeroed before the instruction.
  319. */
  320. static inline struct ap_queue_status
  321. __ap_recv(ap_qid_t qid, unsigned long long *psmid, void *msg, size_t length)
  322. {
  323. typedef struct { char _[length]; } msgblock;
  324. register unsigned long reg0 asm("0") = qid | 0x80000000UL;
  325. register struct ap_queue_status reg1 asm ("1");
  326. register unsigned long reg2 asm("2") = 0UL;
  327. register unsigned long reg4 asm("4") = (unsigned long) msg;
  328. register unsigned long reg5 asm("5") = (unsigned long) length;
  329. register unsigned long reg6 asm("6") = 0UL;
  330. register unsigned long reg7 asm("7") = 0UL;
  331. asm volatile(
  332. "0: .long 0xb2ae0064\n"
  333. " brc 6,0b\n"
  334. : "+d" (reg0), "=d" (reg1), "+d" (reg2),
  335. "+d" (reg4), "+d" (reg5), "+d" (reg6), "+d" (reg7),
  336. "=m" (*(msgblock *) msg) : : "cc" );
  337. *psmid = (((unsigned long long) reg6) << 32) + reg7;
  338. return reg1;
  339. }
  340. int ap_recv(ap_qid_t qid, unsigned long long *psmid, void *msg, size_t length)
  341. {
  342. struct ap_queue_status status;
  343. status = __ap_recv(qid, psmid, msg, length);
  344. switch (status.response_code) {
  345. case AP_RESPONSE_NORMAL:
  346. return 0;
  347. case AP_RESPONSE_NO_PENDING_REPLY:
  348. if (status.queue_empty)
  349. return -ENOENT;
  350. return -EBUSY;
  351. case AP_RESPONSE_RESET_IN_PROGRESS:
  352. return -EBUSY;
  353. default:
  354. return -ENODEV;
  355. }
  356. }
  357. EXPORT_SYMBOL(ap_recv);
  358. /**
  359. * ap_query_queue(): Check if an AP queue is available.
  360. * @qid: The AP queue number
  361. * @queue_depth: Pointer to queue depth value
  362. * @device_type: Pointer to device type value
  363. *
  364. * The test is repeated for AP_MAX_RESET times.
  365. */
  366. static int ap_query_queue(ap_qid_t qid, int *queue_depth, int *device_type)
  367. {
  368. struct ap_queue_status status;
  369. int t_depth, t_device_type, rc, i;
  370. rc = -EBUSY;
  371. for (i = 0; i < AP_MAX_RESET; i++) {
  372. status = ap_test_queue(qid, &t_depth, &t_device_type);
  373. switch (status.response_code) {
  374. case AP_RESPONSE_NORMAL:
  375. *queue_depth = t_depth + 1;
  376. *device_type = t_device_type;
  377. rc = 0;
  378. break;
  379. case AP_RESPONSE_Q_NOT_AVAIL:
  380. rc = -ENODEV;
  381. break;
  382. case AP_RESPONSE_RESET_IN_PROGRESS:
  383. break;
  384. case AP_RESPONSE_DECONFIGURED:
  385. rc = -ENODEV;
  386. break;
  387. case AP_RESPONSE_CHECKSTOPPED:
  388. rc = -ENODEV;
  389. break;
  390. case AP_RESPONSE_INVALID_ADDRESS:
  391. rc = -ENODEV;
  392. break;
  393. case AP_RESPONSE_OTHERWISE_CHANGED:
  394. break;
  395. case AP_RESPONSE_BUSY:
  396. break;
  397. default:
  398. BUG();
  399. }
  400. if (rc != -EBUSY)
  401. break;
  402. if (i < AP_MAX_RESET - 1)
  403. udelay(5);
  404. }
  405. return rc;
  406. }
  407. /**
  408. * ap_init_queue(): Reset an AP queue.
  409. * @qid: The AP queue number
  410. *
  411. * Reset an AP queue and wait for it to become available again.
  412. */
  413. static int ap_init_queue(ap_qid_t qid)
  414. {
  415. struct ap_queue_status status;
  416. int rc, dummy, i;
  417. rc = -ENODEV;
  418. status = ap_reset_queue(qid);
  419. for (i = 0; i < AP_MAX_RESET; i++) {
  420. switch (status.response_code) {
  421. case AP_RESPONSE_NORMAL:
  422. if (status.queue_empty)
  423. rc = 0;
  424. break;
  425. case AP_RESPONSE_Q_NOT_AVAIL:
  426. case AP_RESPONSE_DECONFIGURED:
  427. case AP_RESPONSE_CHECKSTOPPED:
  428. i = AP_MAX_RESET; /* return with -ENODEV */
  429. break;
  430. case AP_RESPONSE_RESET_IN_PROGRESS:
  431. rc = -EBUSY;
  432. case AP_RESPONSE_BUSY:
  433. default:
  434. break;
  435. }
  436. if (rc != -ENODEV && rc != -EBUSY)
  437. break;
  438. if (i < AP_MAX_RESET - 1) {
  439. udelay(5);
  440. status = ap_test_queue(qid, &dummy, &dummy);
  441. }
  442. }
  443. if (rc == 0 && ap_using_interrupts()) {
  444. rc = ap_queue_enable_interruption(qid, ap_interrupt_indicator);
  445. /* If interruption mode is supported by the machine,
  446. * but an AP can not be enabled for interruption then
  447. * the AP will be discarded. */
  448. if (rc)
  449. pr_err("Registering adapter interrupts for "
  450. "AP %d failed\n", AP_QID_DEVICE(qid));
  451. }
  452. return rc;
  453. }
  454. /**
  455. * ap_increase_queue_count(): Arm request timeout.
  456. * @ap_dev: Pointer to an AP device.
  457. *
  458. * Arm request timeout if an AP device was idle and a new request is submitted.
  459. */
  460. static void ap_increase_queue_count(struct ap_device *ap_dev)
  461. {
  462. int timeout = ap_dev->drv->request_timeout;
  463. ap_dev->queue_count++;
  464. if (ap_dev->queue_count == 1) {
  465. mod_timer(&ap_dev->timeout, jiffies + timeout);
  466. ap_dev->reset = AP_RESET_ARMED;
  467. }
  468. }
  469. /**
  470. * ap_decrease_queue_count(): Decrease queue count.
  471. * @ap_dev: Pointer to an AP device.
  472. *
  473. * If AP device is still alive, re-schedule request timeout if there are still
  474. * pending requests.
  475. */
  476. static void ap_decrease_queue_count(struct ap_device *ap_dev)
  477. {
  478. int timeout = ap_dev->drv->request_timeout;
  479. ap_dev->queue_count--;
  480. if (ap_dev->queue_count > 0)
  481. mod_timer(&ap_dev->timeout, jiffies + timeout);
  482. else
  483. /*
  484. * The timeout timer should to be disabled now - since
  485. * del_timer_sync() is very expensive, we just tell via the
  486. * reset flag to ignore the pending timeout timer.
  487. */
  488. ap_dev->reset = AP_RESET_IGNORE;
  489. }
  490. /*
  491. * AP device related attributes.
  492. */
  493. static ssize_t ap_hwtype_show(struct device *dev,
  494. struct device_attribute *attr, char *buf)
  495. {
  496. struct ap_device *ap_dev = to_ap_dev(dev);
  497. return snprintf(buf, PAGE_SIZE, "%d\n", ap_dev->device_type);
  498. }
  499. static DEVICE_ATTR(hwtype, 0444, ap_hwtype_show, NULL);
  500. static ssize_t ap_depth_show(struct device *dev, struct device_attribute *attr,
  501. char *buf)
  502. {
  503. struct ap_device *ap_dev = to_ap_dev(dev);
  504. return snprintf(buf, PAGE_SIZE, "%d\n", ap_dev->queue_depth);
  505. }
  506. static DEVICE_ATTR(depth, 0444, ap_depth_show, NULL);
  507. static ssize_t ap_request_count_show(struct device *dev,
  508. struct device_attribute *attr,
  509. char *buf)
  510. {
  511. struct ap_device *ap_dev = to_ap_dev(dev);
  512. int rc;
  513. spin_lock_bh(&ap_dev->lock);
  514. rc = snprintf(buf, PAGE_SIZE, "%d\n", ap_dev->total_request_count);
  515. spin_unlock_bh(&ap_dev->lock);
  516. return rc;
  517. }
  518. static DEVICE_ATTR(request_count, 0444, ap_request_count_show, NULL);
  519. static ssize_t ap_modalias_show(struct device *dev,
  520. struct device_attribute *attr, char *buf)
  521. {
  522. return sprintf(buf, "ap:t%02X", to_ap_dev(dev)->device_type);
  523. }
  524. static DEVICE_ATTR(modalias, 0444, ap_modalias_show, NULL);
  525. static struct attribute *ap_dev_attrs[] = {
  526. &dev_attr_hwtype.attr,
  527. &dev_attr_depth.attr,
  528. &dev_attr_request_count.attr,
  529. &dev_attr_modalias.attr,
  530. NULL
  531. };
  532. static struct attribute_group ap_dev_attr_group = {
  533. .attrs = ap_dev_attrs
  534. };
  535. /**
  536. * ap_bus_match()
  537. * @dev: Pointer to device
  538. * @drv: Pointer to device_driver
  539. *
  540. * AP bus driver registration/unregistration.
  541. */
  542. static int ap_bus_match(struct device *dev, struct device_driver *drv)
  543. {
  544. struct ap_device *ap_dev = to_ap_dev(dev);
  545. struct ap_driver *ap_drv = to_ap_drv(drv);
  546. struct ap_device_id *id;
  547. /*
  548. * Compare device type of the device with the list of
  549. * supported types of the device_driver.
  550. */
  551. for (id = ap_drv->ids; id->match_flags; id++) {
  552. if ((id->match_flags & AP_DEVICE_ID_MATCH_DEVICE_TYPE) &&
  553. (id->dev_type != ap_dev->device_type))
  554. continue;
  555. return 1;
  556. }
  557. return 0;
  558. }
  559. /**
  560. * ap_uevent(): Uevent function for AP devices.
  561. * @dev: Pointer to device
  562. * @env: Pointer to kobj_uevent_env
  563. *
  564. * It sets up a single environment variable DEV_TYPE which contains the
  565. * hardware device type.
  566. */
  567. static int ap_uevent (struct device *dev, struct kobj_uevent_env *env)
  568. {
  569. struct ap_device *ap_dev = to_ap_dev(dev);
  570. int retval = 0;
  571. if (!ap_dev)
  572. return -ENODEV;
  573. /* Set up DEV_TYPE environment variable. */
  574. retval = add_uevent_var(env, "DEV_TYPE=%04X", ap_dev->device_type);
  575. if (retval)
  576. return retval;
  577. /* Add MODALIAS= */
  578. retval = add_uevent_var(env, "MODALIAS=ap:t%02X", ap_dev->device_type);
  579. return retval;
  580. }
  581. static int ap_bus_suspend(struct device *dev, pm_message_t state)
  582. {
  583. struct ap_device *ap_dev = to_ap_dev(dev);
  584. unsigned long flags;
  585. if (!ap_suspend_flag) {
  586. ap_suspend_flag = 1;
  587. /* Disable scanning for devices, thus we do not want to scan
  588. * for them after removing.
  589. */
  590. del_timer_sync(&ap_config_timer);
  591. if (ap_work_queue != NULL) {
  592. destroy_workqueue(ap_work_queue);
  593. ap_work_queue = NULL;
  594. }
  595. tasklet_disable(&ap_tasklet);
  596. }
  597. /* Poll on the device until all requests are finished. */
  598. do {
  599. flags = 0;
  600. spin_lock_bh(&ap_dev->lock);
  601. __ap_poll_device(ap_dev, &flags);
  602. spin_unlock_bh(&ap_dev->lock);
  603. } while ((flags & 1) || (flags & 2));
  604. spin_lock_bh(&ap_dev->lock);
  605. ap_dev->unregistered = 1;
  606. spin_unlock_bh(&ap_dev->lock);
  607. return 0;
  608. }
  609. static int ap_bus_resume(struct device *dev)
  610. {
  611. int rc = 0;
  612. struct ap_device *ap_dev = to_ap_dev(dev);
  613. if (ap_suspend_flag) {
  614. ap_suspend_flag = 0;
  615. if (!ap_interrupts_available())
  616. ap_interrupt_indicator = NULL;
  617. if (!user_set_domain) {
  618. ap_domain_index = -1;
  619. ap_select_domain();
  620. }
  621. init_timer(&ap_config_timer);
  622. ap_config_timer.function = ap_config_timeout;
  623. ap_config_timer.data = 0;
  624. ap_config_timer.expires = jiffies + ap_config_time * HZ;
  625. add_timer(&ap_config_timer);
  626. ap_work_queue = create_singlethread_workqueue("kapwork");
  627. if (!ap_work_queue)
  628. return -ENOMEM;
  629. tasklet_enable(&ap_tasklet);
  630. if (!ap_using_interrupts())
  631. ap_schedule_poll_timer();
  632. else
  633. tasklet_schedule(&ap_tasklet);
  634. if (ap_thread_flag)
  635. rc = ap_poll_thread_start();
  636. }
  637. if (AP_QID_QUEUE(ap_dev->qid) != ap_domain_index) {
  638. spin_lock_bh(&ap_dev->lock);
  639. ap_dev->qid = AP_MKQID(AP_QID_DEVICE(ap_dev->qid),
  640. ap_domain_index);
  641. spin_unlock_bh(&ap_dev->lock);
  642. }
  643. queue_work(ap_work_queue, &ap_config_work);
  644. return rc;
  645. }
  646. static struct bus_type ap_bus_type = {
  647. .name = "ap",
  648. .match = &ap_bus_match,
  649. .uevent = &ap_uevent,
  650. .suspend = ap_bus_suspend,
  651. .resume = ap_bus_resume
  652. };
  653. static int ap_device_probe(struct device *dev)
  654. {
  655. struct ap_device *ap_dev = to_ap_dev(dev);
  656. struct ap_driver *ap_drv = to_ap_drv(dev->driver);
  657. int rc;
  658. ap_dev->drv = ap_drv;
  659. rc = ap_drv->probe ? ap_drv->probe(ap_dev) : -ENODEV;
  660. if (!rc) {
  661. spin_lock_bh(&ap_device_list_lock);
  662. list_add(&ap_dev->list, &ap_device_list);
  663. spin_unlock_bh(&ap_device_list_lock);
  664. }
  665. return rc;
  666. }
  667. /**
  668. * __ap_flush_queue(): Flush requests.
  669. * @ap_dev: Pointer to the AP device
  670. *
  671. * Flush all requests from the request/pending queue of an AP device.
  672. */
  673. static void __ap_flush_queue(struct ap_device *ap_dev)
  674. {
  675. struct ap_message *ap_msg, *next;
  676. list_for_each_entry_safe(ap_msg, next, &ap_dev->pendingq, list) {
  677. list_del_init(&ap_msg->list);
  678. ap_dev->pendingq_count--;
  679. ap_dev->drv->receive(ap_dev, ap_msg, ERR_PTR(-ENODEV));
  680. }
  681. list_for_each_entry_safe(ap_msg, next, &ap_dev->requestq, list) {
  682. list_del_init(&ap_msg->list);
  683. ap_dev->requestq_count--;
  684. ap_dev->drv->receive(ap_dev, ap_msg, ERR_PTR(-ENODEV));
  685. }
  686. }
  687. void ap_flush_queue(struct ap_device *ap_dev)
  688. {
  689. spin_lock_bh(&ap_dev->lock);
  690. __ap_flush_queue(ap_dev);
  691. spin_unlock_bh(&ap_dev->lock);
  692. }
  693. EXPORT_SYMBOL(ap_flush_queue);
  694. static int ap_device_remove(struct device *dev)
  695. {
  696. struct ap_device *ap_dev = to_ap_dev(dev);
  697. struct ap_driver *ap_drv = ap_dev->drv;
  698. ap_flush_queue(ap_dev);
  699. del_timer_sync(&ap_dev->timeout);
  700. spin_lock_bh(&ap_device_list_lock);
  701. list_del_init(&ap_dev->list);
  702. spin_unlock_bh(&ap_device_list_lock);
  703. if (ap_drv->remove)
  704. ap_drv->remove(ap_dev);
  705. spin_lock_bh(&ap_dev->lock);
  706. atomic_sub(ap_dev->queue_count, &ap_poll_requests);
  707. spin_unlock_bh(&ap_dev->lock);
  708. return 0;
  709. }
  710. int ap_driver_register(struct ap_driver *ap_drv, struct module *owner,
  711. char *name)
  712. {
  713. struct device_driver *drv = &ap_drv->driver;
  714. drv->bus = &ap_bus_type;
  715. drv->probe = ap_device_probe;
  716. drv->remove = ap_device_remove;
  717. drv->owner = owner;
  718. drv->name = name;
  719. return driver_register(drv);
  720. }
  721. EXPORT_SYMBOL(ap_driver_register);
  722. void ap_driver_unregister(struct ap_driver *ap_drv)
  723. {
  724. driver_unregister(&ap_drv->driver);
  725. }
  726. EXPORT_SYMBOL(ap_driver_unregister);
  727. /*
  728. * AP bus attributes.
  729. */
  730. static ssize_t ap_domain_show(struct bus_type *bus, char *buf)
  731. {
  732. return snprintf(buf, PAGE_SIZE, "%d\n", ap_domain_index);
  733. }
  734. static BUS_ATTR(ap_domain, 0444, ap_domain_show, NULL);
  735. static ssize_t ap_config_time_show(struct bus_type *bus, char *buf)
  736. {
  737. return snprintf(buf, PAGE_SIZE, "%d\n", ap_config_time);
  738. }
  739. static ssize_t ap_interrupts_show(struct bus_type *bus, char *buf)
  740. {
  741. return snprintf(buf, PAGE_SIZE, "%d\n",
  742. ap_using_interrupts() ? 1 : 0);
  743. }
  744. static BUS_ATTR(ap_interrupts, 0444, ap_interrupts_show, NULL);
  745. static ssize_t ap_config_time_store(struct bus_type *bus,
  746. const char *buf, size_t count)
  747. {
  748. int time;
  749. if (sscanf(buf, "%d\n", &time) != 1 || time < 5 || time > 120)
  750. return -EINVAL;
  751. ap_config_time = time;
  752. if (!timer_pending(&ap_config_timer) ||
  753. !mod_timer(&ap_config_timer, jiffies + ap_config_time * HZ)) {
  754. ap_config_timer.expires = jiffies + ap_config_time * HZ;
  755. add_timer(&ap_config_timer);
  756. }
  757. return count;
  758. }
  759. static BUS_ATTR(config_time, 0644, ap_config_time_show, ap_config_time_store);
  760. static ssize_t ap_poll_thread_show(struct bus_type *bus, char *buf)
  761. {
  762. return snprintf(buf, PAGE_SIZE, "%d\n", ap_poll_kthread ? 1 : 0);
  763. }
  764. static ssize_t ap_poll_thread_store(struct bus_type *bus,
  765. const char *buf, size_t count)
  766. {
  767. int flag, rc;
  768. if (sscanf(buf, "%d\n", &flag) != 1)
  769. return -EINVAL;
  770. if (flag) {
  771. rc = ap_poll_thread_start();
  772. if (rc)
  773. return rc;
  774. }
  775. else
  776. ap_poll_thread_stop();
  777. return count;
  778. }
  779. static BUS_ATTR(poll_thread, 0644, ap_poll_thread_show, ap_poll_thread_store);
  780. static ssize_t poll_timeout_show(struct bus_type *bus, char *buf)
  781. {
  782. return snprintf(buf, PAGE_SIZE, "%llu\n", poll_timeout);
  783. }
  784. static ssize_t poll_timeout_store(struct bus_type *bus, const char *buf,
  785. size_t count)
  786. {
  787. unsigned long long time;
  788. ktime_t hr_time;
  789. /* 120 seconds = maximum poll interval */
  790. if (sscanf(buf, "%llu\n", &time) != 1 || time < 1 ||
  791. time > 120000000000ULL)
  792. return -EINVAL;
  793. poll_timeout = time;
  794. hr_time = ktime_set(0, poll_timeout);
  795. if (!hrtimer_is_queued(&ap_poll_timer) ||
  796. !hrtimer_forward(&ap_poll_timer, hrtimer_get_expires(&ap_poll_timer), hr_time)) {
  797. hrtimer_set_expires(&ap_poll_timer, hr_time);
  798. hrtimer_start_expires(&ap_poll_timer, HRTIMER_MODE_ABS);
  799. }
  800. return count;
  801. }
  802. static BUS_ATTR(poll_timeout, 0644, poll_timeout_show, poll_timeout_store);
  803. static struct bus_attribute *const ap_bus_attrs[] = {
  804. &bus_attr_ap_domain,
  805. &bus_attr_config_time,
  806. &bus_attr_poll_thread,
  807. &bus_attr_ap_interrupts,
  808. &bus_attr_poll_timeout,
  809. NULL,
  810. };
  811. /**
  812. * ap_select_domain(): Select an AP domain.
  813. *
  814. * Pick one of the 16 AP domains.
  815. */
  816. static int ap_select_domain(void)
  817. {
  818. int queue_depth, device_type, count, max_count, best_domain;
  819. int rc, i, j;
  820. /*
  821. * We want to use a single domain. Either the one specified with
  822. * the "domain=" parameter or the domain with the maximum number
  823. * of devices.
  824. */
  825. if (ap_domain_index >= 0 && ap_domain_index < AP_DOMAINS)
  826. /* Domain has already been selected. */
  827. return 0;
  828. best_domain = -1;
  829. max_count = 0;
  830. for (i = 0; i < AP_DOMAINS; i++) {
  831. count = 0;
  832. for (j = 0; j < AP_DEVICES; j++) {
  833. ap_qid_t qid = AP_MKQID(j, i);
  834. rc = ap_query_queue(qid, &queue_depth, &device_type);
  835. if (rc)
  836. continue;
  837. count++;
  838. }
  839. if (count > max_count) {
  840. max_count = count;
  841. best_domain = i;
  842. }
  843. }
  844. if (best_domain >= 0){
  845. ap_domain_index = best_domain;
  846. return 0;
  847. }
  848. return -ENODEV;
  849. }
  850. /**
  851. * ap_probe_device_type(): Find the device type of an AP.
  852. * @ap_dev: pointer to the AP device.
  853. *
  854. * Find the device type if query queue returned a device type of 0.
  855. */
  856. static int ap_probe_device_type(struct ap_device *ap_dev)
  857. {
  858. static unsigned char msg[] = {
  859. 0x00,0x06,0x00,0x00,0x00,0x00,0x00,0x00,
  860. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  861. 0x00,0x00,0x00,0x58,0x00,0x00,0x00,0x00,
  862. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  863. 0x01,0x00,0x43,0x43,0x41,0x2d,0x41,0x50,
  864. 0x50,0x4c,0x20,0x20,0x20,0x01,0x01,0x01,
  865. 0x00,0x00,0x00,0x00,0x50,0x4b,0x00,0x00,
  866. 0x00,0x00,0x01,0x1c,0x00,0x00,0x00,0x00,
  867. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  868. 0x00,0x00,0x05,0xb8,0x00,0x00,0x00,0x00,
  869. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  870. 0x70,0x00,0x41,0x00,0x00,0x00,0x00,0x00,
  871. 0x00,0x00,0x54,0x32,0x01,0x00,0xa0,0x00,
  872. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  873. 0x00,0x00,0x00,0x00,0xb8,0x05,0x00,0x00,
  874. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  875. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  876. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  877. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  878. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  879. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  880. 0x00,0x00,0x0a,0x00,0x00,0x00,0x00,0x00,
  881. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  882. 0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x00,
  883. 0x49,0x43,0x53,0x46,0x20,0x20,0x20,0x20,
  884. 0x50,0x4b,0x0a,0x00,0x50,0x4b,0x43,0x53,
  885. 0x2d,0x31,0x2e,0x32,0x37,0x00,0x11,0x22,
  886. 0x33,0x44,0x55,0x66,0x77,0x88,0x99,0x00,
  887. 0x11,0x22,0x33,0x44,0x55,0x66,0x77,0x88,
  888. 0x99,0x00,0x11,0x22,0x33,0x44,0x55,0x66,
  889. 0x77,0x88,0x99,0x00,0x11,0x22,0x33,0x44,
  890. 0x55,0x66,0x77,0x88,0x99,0x00,0x11,0x22,
  891. 0x33,0x44,0x55,0x66,0x77,0x88,0x99,0x00,
  892. 0x11,0x22,0x33,0x5d,0x00,0x5b,0x00,0x77,
  893. 0x88,0x1e,0x00,0x00,0x57,0x00,0x00,0x00,
  894. 0x00,0x04,0x00,0x00,0x4f,0x00,0x00,0x00,
  895. 0x03,0x02,0x00,0x00,0x40,0x01,0x00,0x01,
  896. 0xce,0x02,0x68,0x2d,0x5f,0xa9,0xde,0x0c,
  897. 0xf6,0xd2,0x7b,0x58,0x4b,0xf9,0x28,0x68,
  898. 0x3d,0xb4,0xf4,0xef,0x78,0xd5,0xbe,0x66,
  899. 0x63,0x42,0xef,0xf8,0xfd,0xa4,0xf8,0xb0,
  900. 0x8e,0x29,0xc2,0xc9,0x2e,0xd8,0x45,0xb8,
  901. 0x53,0x8c,0x6f,0x4e,0x72,0x8f,0x6c,0x04,
  902. 0x9c,0x88,0xfc,0x1e,0xc5,0x83,0x55,0x57,
  903. 0xf7,0xdd,0xfd,0x4f,0x11,0x36,0x95,0x5d,
  904. };
  905. struct ap_queue_status status;
  906. unsigned long long psmid;
  907. char *reply;
  908. int rc, i;
  909. reply = (void *) get_zeroed_page(GFP_KERNEL);
  910. if (!reply) {
  911. rc = -ENOMEM;
  912. goto out;
  913. }
  914. status = __ap_send(ap_dev->qid, 0x0102030405060708ULL,
  915. msg, sizeof(msg), 0);
  916. if (status.response_code != AP_RESPONSE_NORMAL) {
  917. rc = -ENODEV;
  918. goto out_free;
  919. }
  920. /* Wait for the test message to complete. */
  921. for (i = 0; i < 6; i++) {
  922. mdelay(300);
  923. status = __ap_recv(ap_dev->qid, &psmid, reply, 4096);
  924. if (status.response_code == AP_RESPONSE_NORMAL &&
  925. psmid == 0x0102030405060708ULL)
  926. break;
  927. }
  928. if (i < 6) {
  929. /* Got an answer. */
  930. if (reply[0] == 0x00 && reply[1] == 0x86)
  931. ap_dev->device_type = AP_DEVICE_TYPE_PCICC;
  932. else
  933. ap_dev->device_type = AP_DEVICE_TYPE_PCICA;
  934. rc = 0;
  935. } else
  936. rc = -ENODEV;
  937. out_free:
  938. free_page((unsigned long) reply);
  939. out:
  940. return rc;
  941. }
  942. static void ap_interrupt_handler(void *unused1, void *unused2)
  943. {
  944. kstat_cpu(smp_processor_id()).irqs[IOINT_APB]++;
  945. tasklet_schedule(&ap_tasklet);
  946. }
  947. /**
  948. * __ap_scan_bus(): Scan the AP bus.
  949. * @dev: Pointer to device
  950. * @data: Pointer to data
  951. *
  952. * Scan the AP bus for new devices.
  953. */
  954. static int __ap_scan_bus(struct device *dev, void *data)
  955. {
  956. return to_ap_dev(dev)->qid == (ap_qid_t)(unsigned long) data;
  957. }
  958. static void ap_device_release(struct device *dev)
  959. {
  960. struct ap_device *ap_dev = to_ap_dev(dev);
  961. kfree(ap_dev);
  962. }
  963. static void ap_scan_bus(struct work_struct *unused)
  964. {
  965. struct ap_device *ap_dev;
  966. struct device *dev;
  967. ap_qid_t qid;
  968. int queue_depth, device_type;
  969. int rc, i;
  970. if (ap_select_domain() != 0)
  971. return;
  972. for (i = 0; i < AP_DEVICES; i++) {
  973. qid = AP_MKQID(i, ap_domain_index);
  974. dev = bus_find_device(&ap_bus_type, NULL,
  975. (void *)(unsigned long)qid,
  976. __ap_scan_bus);
  977. rc = ap_query_queue(qid, &queue_depth, &device_type);
  978. if (dev) {
  979. if (rc == -EBUSY) {
  980. set_current_state(TASK_UNINTERRUPTIBLE);
  981. schedule_timeout(AP_RESET_TIMEOUT);
  982. rc = ap_query_queue(qid, &queue_depth,
  983. &device_type);
  984. }
  985. ap_dev = to_ap_dev(dev);
  986. spin_lock_bh(&ap_dev->lock);
  987. if (rc || ap_dev->unregistered) {
  988. spin_unlock_bh(&ap_dev->lock);
  989. if (ap_dev->unregistered)
  990. i--;
  991. device_unregister(dev);
  992. put_device(dev);
  993. continue;
  994. }
  995. spin_unlock_bh(&ap_dev->lock);
  996. put_device(dev);
  997. continue;
  998. }
  999. if (rc)
  1000. continue;
  1001. rc = ap_init_queue(qid);
  1002. if (rc)
  1003. continue;
  1004. ap_dev = kzalloc(sizeof(*ap_dev), GFP_KERNEL);
  1005. if (!ap_dev)
  1006. break;
  1007. ap_dev->qid = qid;
  1008. ap_dev->queue_depth = queue_depth;
  1009. ap_dev->unregistered = 1;
  1010. spin_lock_init(&ap_dev->lock);
  1011. INIT_LIST_HEAD(&ap_dev->pendingq);
  1012. INIT_LIST_HEAD(&ap_dev->requestq);
  1013. INIT_LIST_HEAD(&ap_dev->list);
  1014. setup_timer(&ap_dev->timeout, ap_request_timeout,
  1015. (unsigned long) ap_dev);
  1016. if (device_type == 0)
  1017. ap_probe_device_type(ap_dev);
  1018. else
  1019. ap_dev->device_type = device_type;
  1020. ap_dev->device.bus = &ap_bus_type;
  1021. ap_dev->device.parent = ap_root_device;
  1022. if (dev_set_name(&ap_dev->device, "card%02x",
  1023. AP_QID_DEVICE(ap_dev->qid))) {
  1024. kfree(ap_dev);
  1025. continue;
  1026. }
  1027. ap_dev->device.release = ap_device_release;
  1028. rc = device_register(&ap_dev->device);
  1029. if (rc) {
  1030. put_device(&ap_dev->device);
  1031. continue;
  1032. }
  1033. /* Add device attributes. */
  1034. rc = sysfs_create_group(&ap_dev->device.kobj,
  1035. &ap_dev_attr_group);
  1036. if (!rc) {
  1037. spin_lock_bh(&ap_dev->lock);
  1038. ap_dev->unregistered = 0;
  1039. spin_unlock_bh(&ap_dev->lock);
  1040. }
  1041. else
  1042. device_unregister(&ap_dev->device);
  1043. }
  1044. }
  1045. static void
  1046. ap_config_timeout(unsigned long ptr)
  1047. {
  1048. queue_work(ap_work_queue, &ap_config_work);
  1049. ap_config_timer.expires = jiffies + ap_config_time * HZ;
  1050. add_timer(&ap_config_timer);
  1051. }
  1052. /**
  1053. * ap_schedule_poll_timer(): Schedule poll timer.
  1054. *
  1055. * Set up the timer to run the poll tasklet
  1056. */
  1057. static inline void ap_schedule_poll_timer(void)
  1058. {
  1059. ktime_t hr_time;
  1060. spin_lock_bh(&ap_poll_timer_lock);
  1061. if (ap_using_interrupts() || ap_suspend_flag)
  1062. goto out;
  1063. if (hrtimer_is_queued(&ap_poll_timer))
  1064. goto out;
  1065. if (ktime_to_ns(hrtimer_expires_remaining(&ap_poll_timer)) <= 0) {
  1066. hr_time = ktime_set(0, poll_timeout);
  1067. hrtimer_forward_now(&ap_poll_timer, hr_time);
  1068. hrtimer_restart(&ap_poll_timer);
  1069. }
  1070. out:
  1071. spin_unlock_bh(&ap_poll_timer_lock);
  1072. }
  1073. /**
  1074. * ap_poll_read(): Receive pending reply messages from an AP device.
  1075. * @ap_dev: pointer to the AP device
  1076. * @flags: pointer to control flags, bit 2^0 is set if another poll is
  1077. * required, bit 2^1 is set if the poll timer needs to get armed
  1078. *
  1079. * Returns 0 if the device is still present, -ENODEV if not.
  1080. */
  1081. static int ap_poll_read(struct ap_device *ap_dev, unsigned long *flags)
  1082. {
  1083. struct ap_queue_status status;
  1084. struct ap_message *ap_msg;
  1085. if (ap_dev->queue_count <= 0)
  1086. return 0;
  1087. status = __ap_recv(ap_dev->qid, &ap_dev->reply->psmid,
  1088. ap_dev->reply->message, ap_dev->reply->length);
  1089. switch (status.response_code) {
  1090. case AP_RESPONSE_NORMAL:
  1091. atomic_dec(&ap_poll_requests);
  1092. ap_decrease_queue_count(ap_dev);
  1093. list_for_each_entry(ap_msg, &ap_dev->pendingq, list) {
  1094. if (ap_msg->psmid != ap_dev->reply->psmid)
  1095. continue;
  1096. list_del_init(&ap_msg->list);
  1097. ap_dev->pendingq_count--;
  1098. ap_dev->drv->receive(ap_dev, ap_msg, ap_dev->reply);
  1099. break;
  1100. }
  1101. if (ap_dev->queue_count > 0)
  1102. *flags |= 1;
  1103. break;
  1104. case AP_RESPONSE_NO_PENDING_REPLY:
  1105. if (status.queue_empty) {
  1106. /* The card shouldn't forget requests but who knows. */
  1107. atomic_sub(ap_dev->queue_count, &ap_poll_requests);
  1108. ap_dev->queue_count = 0;
  1109. list_splice_init(&ap_dev->pendingq, &ap_dev->requestq);
  1110. ap_dev->requestq_count += ap_dev->pendingq_count;
  1111. ap_dev->pendingq_count = 0;
  1112. } else
  1113. *flags |= 2;
  1114. break;
  1115. default:
  1116. return -ENODEV;
  1117. }
  1118. return 0;
  1119. }
  1120. /**
  1121. * ap_poll_write(): Send messages from the request queue to an AP device.
  1122. * @ap_dev: pointer to the AP device
  1123. * @flags: pointer to control flags, bit 2^0 is set if another poll is
  1124. * required, bit 2^1 is set if the poll timer needs to get armed
  1125. *
  1126. * Returns 0 if the device is still present, -ENODEV if not.
  1127. */
  1128. static int ap_poll_write(struct ap_device *ap_dev, unsigned long *flags)
  1129. {
  1130. struct ap_queue_status status;
  1131. struct ap_message *ap_msg;
  1132. if (ap_dev->requestq_count <= 0 ||
  1133. ap_dev->queue_count >= ap_dev->queue_depth)
  1134. return 0;
  1135. /* Start the next request on the queue. */
  1136. ap_msg = list_entry(ap_dev->requestq.next, struct ap_message, list);
  1137. status = __ap_send(ap_dev->qid, ap_msg->psmid,
  1138. ap_msg->message, ap_msg->length, ap_msg->special);
  1139. switch (status.response_code) {
  1140. case AP_RESPONSE_NORMAL:
  1141. atomic_inc(&ap_poll_requests);
  1142. ap_increase_queue_count(ap_dev);
  1143. list_move_tail(&ap_msg->list, &ap_dev->pendingq);
  1144. ap_dev->requestq_count--;
  1145. ap_dev->pendingq_count++;
  1146. if (ap_dev->queue_count < ap_dev->queue_depth &&
  1147. ap_dev->requestq_count > 0)
  1148. *flags |= 1;
  1149. *flags |= 2;
  1150. break;
  1151. case AP_RESPONSE_Q_FULL:
  1152. case AP_RESPONSE_RESET_IN_PROGRESS:
  1153. *flags |= 2;
  1154. break;
  1155. case AP_RESPONSE_MESSAGE_TOO_BIG:
  1156. case AP_RESPONSE_REQ_FAC_NOT_INST:
  1157. return -EINVAL;
  1158. default:
  1159. return -ENODEV;
  1160. }
  1161. return 0;
  1162. }
  1163. /**
  1164. * ap_poll_queue(): Poll AP device for pending replies and send new messages.
  1165. * @ap_dev: pointer to the bus device
  1166. * @flags: pointer to control flags, bit 2^0 is set if another poll is
  1167. * required, bit 2^1 is set if the poll timer needs to get armed
  1168. *
  1169. * Poll AP device for pending replies and send new messages. If either
  1170. * ap_poll_read or ap_poll_write returns -ENODEV unregister the device.
  1171. * Returns 0.
  1172. */
  1173. static inline int ap_poll_queue(struct ap_device *ap_dev, unsigned long *flags)
  1174. {
  1175. int rc;
  1176. rc = ap_poll_read(ap_dev, flags);
  1177. if (rc)
  1178. return rc;
  1179. return ap_poll_write(ap_dev, flags);
  1180. }
  1181. /**
  1182. * __ap_queue_message(): Queue a message to a device.
  1183. * @ap_dev: pointer to the AP device
  1184. * @ap_msg: the message to be queued
  1185. *
  1186. * Queue a message to a device. Returns 0 if successful.
  1187. */
  1188. static int __ap_queue_message(struct ap_device *ap_dev, struct ap_message *ap_msg)
  1189. {
  1190. struct ap_queue_status status;
  1191. if (list_empty(&ap_dev->requestq) &&
  1192. ap_dev->queue_count < ap_dev->queue_depth) {
  1193. status = __ap_send(ap_dev->qid, ap_msg->psmid,
  1194. ap_msg->message, ap_msg->length,
  1195. ap_msg->special);
  1196. switch (status.response_code) {
  1197. case AP_RESPONSE_NORMAL:
  1198. list_add_tail(&ap_msg->list, &ap_dev->pendingq);
  1199. atomic_inc(&ap_poll_requests);
  1200. ap_dev->pendingq_count++;
  1201. ap_increase_queue_count(ap_dev);
  1202. ap_dev->total_request_count++;
  1203. break;
  1204. case AP_RESPONSE_Q_FULL:
  1205. case AP_RESPONSE_RESET_IN_PROGRESS:
  1206. list_add_tail(&ap_msg->list, &ap_dev->requestq);
  1207. ap_dev->requestq_count++;
  1208. ap_dev->total_request_count++;
  1209. return -EBUSY;
  1210. case AP_RESPONSE_REQ_FAC_NOT_INST:
  1211. case AP_RESPONSE_MESSAGE_TOO_BIG:
  1212. ap_dev->drv->receive(ap_dev, ap_msg, ERR_PTR(-EINVAL));
  1213. return -EINVAL;
  1214. default: /* Device is gone. */
  1215. ap_dev->drv->receive(ap_dev, ap_msg, ERR_PTR(-ENODEV));
  1216. return -ENODEV;
  1217. }
  1218. } else {
  1219. list_add_tail(&ap_msg->list, &ap_dev->requestq);
  1220. ap_dev->requestq_count++;
  1221. ap_dev->total_request_count++;
  1222. return -EBUSY;
  1223. }
  1224. ap_schedule_poll_timer();
  1225. return 0;
  1226. }
  1227. void ap_queue_message(struct ap_device *ap_dev, struct ap_message *ap_msg)
  1228. {
  1229. unsigned long flags;
  1230. int rc;
  1231. spin_lock_bh(&ap_dev->lock);
  1232. if (!ap_dev->unregistered) {
  1233. /* Make room on the queue by polling for finished requests. */
  1234. rc = ap_poll_queue(ap_dev, &flags);
  1235. if (!rc)
  1236. rc = __ap_queue_message(ap_dev, ap_msg);
  1237. if (!rc)
  1238. wake_up(&ap_poll_wait);
  1239. if (rc == -ENODEV)
  1240. ap_dev->unregistered = 1;
  1241. } else {
  1242. ap_dev->drv->receive(ap_dev, ap_msg, ERR_PTR(-ENODEV));
  1243. rc = -ENODEV;
  1244. }
  1245. spin_unlock_bh(&ap_dev->lock);
  1246. if (rc == -ENODEV)
  1247. device_unregister(&ap_dev->device);
  1248. }
  1249. EXPORT_SYMBOL(ap_queue_message);
  1250. /**
  1251. * ap_cancel_message(): Cancel a crypto request.
  1252. * @ap_dev: The AP device that has the message queued
  1253. * @ap_msg: The message that is to be removed
  1254. *
  1255. * Cancel a crypto request. This is done by removing the request
  1256. * from the device pending or request queue. Note that the
  1257. * request stays on the AP queue. When it finishes the message
  1258. * reply will be discarded because the psmid can't be found.
  1259. */
  1260. void ap_cancel_message(struct ap_device *ap_dev, struct ap_message *ap_msg)
  1261. {
  1262. struct ap_message *tmp;
  1263. spin_lock_bh(&ap_dev->lock);
  1264. if (!list_empty(&ap_msg->list)) {
  1265. list_for_each_entry(tmp, &ap_dev->pendingq, list)
  1266. if (tmp->psmid == ap_msg->psmid) {
  1267. ap_dev->pendingq_count--;
  1268. goto found;
  1269. }
  1270. ap_dev->requestq_count--;
  1271. found:
  1272. list_del_init(&ap_msg->list);
  1273. }
  1274. spin_unlock_bh(&ap_dev->lock);
  1275. }
  1276. EXPORT_SYMBOL(ap_cancel_message);
  1277. /**
  1278. * ap_poll_timeout(): AP receive polling for finished AP requests.
  1279. * @unused: Unused pointer.
  1280. *
  1281. * Schedules the AP tasklet using a high resolution timer.
  1282. */
  1283. static enum hrtimer_restart ap_poll_timeout(struct hrtimer *unused)
  1284. {
  1285. tasklet_schedule(&ap_tasklet);
  1286. return HRTIMER_NORESTART;
  1287. }
  1288. /**
  1289. * ap_reset(): Reset a not responding AP device.
  1290. * @ap_dev: Pointer to the AP device
  1291. *
  1292. * Reset a not responding AP device and move all requests from the
  1293. * pending queue to the request queue.
  1294. */
  1295. static void ap_reset(struct ap_device *ap_dev)
  1296. {
  1297. int rc;
  1298. ap_dev->reset = AP_RESET_IGNORE;
  1299. atomic_sub(ap_dev->queue_count, &ap_poll_requests);
  1300. ap_dev->queue_count = 0;
  1301. list_splice_init(&ap_dev->pendingq, &ap_dev->requestq);
  1302. ap_dev->requestq_count += ap_dev->pendingq_count;
  1303. ap_dev->pendingq_count = 0;
  1304. rc = ap_init_queue(ap_dev->qid);
  1305. if (rc == -ENODEV)
  1306. ap_dev->unregistered = 1;
  1307. }
  1308. static int __ap_poll_device(struct ap_device *ap_dev, unsigned long *flags)
  1309. {
  1310. if (!ap_dev->unregistered) {
  1311. if (ap_poll_queue(ap_dev, flags))
  1312. ap_dev->unregistered = 1;
  1313. if (ap_dev->reset == AP_RESET_DO)
  1314. ap_reset(ap_dev);
  1315. }
  1316. return 0;
  1317. }
  1318. /**
  1319. * ap_poll_all(): Poll all AP devices.
  1320. * @dummy: Unused variable
  1321. *
  1322. * Poll all AP devices on the bus in a round robin fashion. Continue
  1323. * polling until bit 2^0 of the control flags is not set. If bit 2^1
  1324. * of the control flags has been set arm the poll timer.
  1325. */
  1326. static void ap_poll_all(unsigned long dummy)
  1327. {
  1328. unsigned long flags;
  1329. struct ap_device *ap_dev;
  1330. /* Reset the indicator if interrupts are used. Thus new interrupts can
  1331. * be received. Doing it in the beginning of the tasklet is therefor
  1332. * important that no requests on any AP get lost.
  1333. */
  1334. if (ap_using_interrupts())
  1335. xchg((u8 *)ap_interrupt_indicator, 0);
  1336. do {
  1337. flags = 0;
  1338. spin_lock(&ap_device_list_lock);
  1339. list_for_each_entry(ap_dev, &ap_device_list, list) {
  1340. spin_lock(&ap_dev->lock);
  1341. __ap_poll_device(ap_dev, &flags);
  1342. spin_unlock(&ap_dev->lock);
  1343. }
  1344. spin_unlock(&ap_device_list_lock);
  1345. } while (flags & 1);
  1346. if (flags & 2)
  1347. ap_schedule_poll_timer();
  1348. }
  1349. /**
  1350. * ap_poll_thread(): Thread that polls for finished requests.
  1351. * @data: Unused pointer
  1352. *
  1353. * AP bus poll thread. The purpose of this thread is to poll for
  1354. * finished requests in a loop if there is a "free" cpu - that is
  1355. * a cpu that doesn't have anything better to do. The polling stops
  1356. * as soon as there is another task or if all messages have been
  1357. * delivered.
  1358. */
  1359. static int ap_poll_thread(void *data)
  1360. {
  1361. DECLARE_WAITQUEUE(wait, current);
  1362. unsigned long flags;
  1363. int requests;
  1364. struct ap_device *ap_dev;
  1365. set_user_nice(current, 19);
  1366. while (1) {
  1367. if (ap_suspend_flag)
  1368. return 0;
  1369. if (need_resched()) {
  1370. schedule();
  1371. continue;
  1372. }
  1373. add_wait_queue(&ap_poll_wait, &wait);
  1374. set_current_state(TASK_INTERRUPTIBLE);
  1375. if (kthread_should_stop())
  1376. break;
  1377. requests = atomic_read(&ap_poll_requests);
  1378. if (requests <= 0)
  1379. schedule();
  1380. set_current_state(TASK_RUNNING);
  1381. remove_wait_queue(&ap_poll_wait, &wait);
  1382. flags = 0;
  1383. spin_lock_bh(&ap_device_list_lock);
  1384. list_for_each_entry(ap_dev, &ap_device_list, list) {
  1385. spin_lock(&ap_dev->lock);
  1386. __ap_poll_device(ap_dev, &flags);
  1387. spin_unlock(&ap_dev->lock);
  1388. }
  1389. spin_unlock_bh(&ap_device_list_lock);
  1390. }
  1391. set_current_state(TASK_RUNNING);
  1392. remove_wait_queue(&ap_poll_wait, &wait);
  1393. return 0;
  1394. }
  1395. static int ap_poll_thread_start(void)
  1396. {
  1397. int rc;
  1398. if (ap_using_interrupts() || ap_suspend_flag)
  1399. return 0;
  1400. mutex_lock(&ap_poll_thread_mutex);
  1401. if (!ap_poll_kthread) {
  1402. ap_poll_kthread = kthread_run(ap_poll_thread, NULL, "appoll");
  1403. rc = IS_ERR(ap_poll_kthread) ? PTR_ERR(ap_poll_kthread) : 0;
  1404. if (rc)
  1405. ap_poll_kthread = NULL;
  1406. }
  1407. else
  1408. rc = 0;
  1409. mutex_unlock(&ap_poll_thread_mutex);
  1410. return rc;
  1411. }
  1412. static void ap_poll_thread_stop(void)
  1413. {
  1414. mutex_lock(&ap_poll_thread_mutex);
  1415. if (ap_poll_kthread) {
  1416. kthread_stop(ap_poll_kthread);
  1417. ap_poll_kthread = NULL;
  1418. }
  1419. mutex_unlock(&ap_poll_thread_mutex);
  1420. }
  1421. /**
  1422. * ap_request_timeout(): Handling of request timeouts
  1423. * @data: Holds the AP device.
  1424. *
  1425. * Handles request timeouts.
  1426. */
  1427. static void ap_request_timeout(unsigned long data)
  1428. {
  1429. struct ap_device *ap_dev = (struct ap_device *) data;
  1430. if (ap_dev->reset == AP_RESET_ARMED) {
  1431. ap_dev->reset = AP_RESET_DO;
  1432. if (ap_using_interrupts())
  1433. tasklet_schedule(&ap_tasklet);
  1434. }
  1435. }
  1436. static void ap_reset_domain(void)
  1437. {
  1438. int i;
  1439. if (ap_domain_index != -1)
  1440. for (i = 0; i < AP_DEVICES; i++)
  1441. ap_reset_queue(AP_MKQID(i, ap_domain_index));
  1442. }
  1443. static void ap_reset_all(void)
  1444. {
  1445. int i, j;
  1446. for (i = 0; i < AP_DOMAINS; i++)
  1447. for (j = 0; j < AP_DEVICES; j++)
  1448. ap_reset_queue(AP_MKQID(j, i));
  1449. }
  1450. static struct reset_call ap_reset_call = {
  1451. .fn = ap_reset_all,
  1452. };
  1453. /**
  1454. * ap_module_init(): The module initialization code.
  1455. *
  1456. * Initializes the module.
  1457. */
  1458. int __init ap_module_init(void)
  1459. {
  1460. int rc, i;
  1461. if (ap_domain_index < -1 || ap_domain_index >= AP_DOMAINS) {
  1462. pr_warning("%d is not a valid cryptographic domain\n",
  1463. ap_domain_index);
  1464. return -EINVAL;
  1465. }
  1466. /* In resume callback we need to know if the user had set the domain.
  1467. * If so, we can not just reset it.
  1468. */
  1469. if (ap_domain_index >= 0)
  1470. user_set_domain = 1;
  1471. if (ap_instructions_available() != 0) {
  1472. pr_warning("The hardware system does not support "
  1473. "AP instructions\n");
  1474. return -ENODEV;
  1475. }
  1476. if (ap_interrupts_available()) {
  1477. isc_register(AP_ISC);
  1478. ap_interrupt_indicator = s390_register_adapter_interrupt(
  1479. &ap_interrupt_handler, NULL, AP_ISC);
  1480. if (IS_ERR(ap_interrupt_indicator)) {
  1481. ap_interrupt_indicator = NULL;
  1482. isc_unregister(AP_ISC);
  1483. }
  1484. }
  1485. register_reset_call(&ap_reset_call);
  1486. /* Create /sys/bus/ap. */
  1487. rc = bus_register(&ap_bus_type);
  1488. if (rc)
  1489. goto out;
  1490. for (i = 0; ap_bus_attrs[i]; i++) {
  1491. rc = bus_create_file(&ap_bus_type, ap_bus_attrs[i]);
  1492. if (rc)
  1493. goto out_bus;
  1494. }
  1495. /* Create /sys/devices/ap. */
  1496. ap_root_device = root_device_register("ap");
  1497. rc = IS_ERR(ap_root_device) ? PTR_ERR(ap_root_device) : 0;
  1498. if (rc)
  1499. goto out_bus;
  1500. ap_work_queue = create_singlethread_workqueue("kapwork");
  1501. if (!ap_work_queue) {
  1502. rc = -ENOMEM;
  1503. goto out_root;
  1504. }
  1505. if (ap_select_domain() == 0)
  1506. ap_scan_bus(NULL);
  1507. /* Setup the AP bus rescan timer. */
  1508. init_timer(&ap_config_timer);
  1509. ap_config_timer.function = ap_config_timeout;
  1510. ap_config_timer.data = 0;
  1511. ap_config_timer.expires = jiffies + ap_config_time * HZ;
  1512. add_timer(&ap_config_timer);
  1513. /* Setup the high resultion poll timer.
  1514. * If we are running under z/VM adjust polling to z/VM polling rate.
  1515. */
  1516. if (MACHINE_IS_VM)
  1517. poll_timeout = 1500000;
  1518. spin_lock_init(&ap_poll_timer_lock);
  1519. hrtimer_init(&ap_poll_timer, CLOCK_MONOTONIC, HRTIMER_MODE_ABS);
  1520. ap_poll_timer.function = ap_poll_timeout;
  1521. /* Start the low priority AP bus poll thread. */
  1522. if (ap_thread_flag) {
  1523. rc = ap_poll_thread_start();
  1524. if (rc)
  1525. goto out_work;
  1526. }
  1527. return 0;
  1528. out_work:
  1529. del_timer_sync(&ap_config_timer);
  1530. hrtimer_cancel(&ap_poll_timer);
  1531. destroy_workqueue(ap_work_queue);
  1532. out_root:
  1533. root_device_unregister(ap_root_device);
  1534. out_bus:
  1535. while (i--)
  1536. bus_remove_file(&ap_bus_type, ap_bus_attrs[i]);
  1537. bus_unregister(&ap_bus_type);
  1538. out:
  1539. unregister_reset_call(&ap_reset_call);
  1540. if (ap_using_interrupts()) {
  1541. s390_unregister_adapter_interrupt(ap_interrupt_indicator, AP_ISC);
  1542. isc_unregister(AP_ISC);
  1543. }
  1544. return rc;
  1545. }
  1546. static int __ap_match_all(struct device *dev, void *data)
  1547. {
  1548. return 1;
  1549. }
  1550. /**
  1551. * ap_modules_exit(): The module termination code
  1552. *
  1553. * Terminates the module.
  1554. */
  1555. void ap_module_exit(void)
  1556. {
  1557. int i;
  1558. struct device *dev;
  1559. ap_reset_domain();
  1560. ap_poll_thread_stop();
  1561. del_timer_sync(&ap_config_timer);
  1562. hrtimer_cancel(&ap_poll_timer);
  1563. destroy_workqueue(ap_work_queue);
  1564. tasklet_kill(&ap_tasklet);
  1565. root_device_unregister(ap_root_device);
  1566. while ((dev = bus_find_device(&ap_bus_type, NULL, NULL,
  1567. __ap_match_all)))
  1568. {
  1569. device_unregister(dev);
  1570. put_device(dev);
  1571. }
  1572. for (i = 0; ap_bus_attrs[i]; i++)
  1573. bus_remove_file(&ap_bus_type, ap_bus_attrs[i]);
  1574. bus_unregister(&ap_bus_type);
  1575. unregister_reset_call(&ap_reset_call);
  1576. if (ap_using_interrupts()) {
  1577. s390_unregister_adapter_interrupt(ap_interrupt_indicator, AP_ISC);
  1578. isc_unregister(AP_ISC);
  1579. }
  1580. }
  1581. #ifndef CONFIG_ZCRYPT_MONOLITHIC
  1582. module_init(ap_module_init);
  1583. module_exit(ap_module_exit);
  1584. #endif