ap_bus.c 46 KB

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