ap_bus.c 46 KB

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