qdio_main.c 43 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768
  1. /*
  2. * linux/drivers/s390/cio/qdio_main.c
  3. *
  4. * Linux for s390 qdio support, buffer handling, qdio API and module support.
  5. *
  6. * Copyright 2000,2008 IBM Corp.
  7. * Author(s): Utz Bacher <utz.bacher@de.ibm.com>
  8. * Jan Glauber <jang@linux.vnet.ibm.com>
  9. * 2.6 cio integration by Cornelia Huck <cornelia.huck@de.ibm.com>
  10. */
  11. #include <linux/module.h>
  12. #include <linux/init.h>
  13. #include <linux/kernel.h>
  14. #include <linux/timer.h>
  15. #include <linux/delay.h>
  16. #include <asm/atomic.h>
  17. #include <asm/debug.h>
  18. #include <asm/qdio.h>
  19. #include "cio.h"
  20. #include "css.h"
  21. #include "device.h"
  22. #include "qdio.h"
  23. #include "qdio_debug.h"
  24. #include "qdio_perf.h"
  25. MODULE_AUTHOR("Utz Bacher <utz.bacher@de.ibm.com>,"\
  26. "Jan Glauber <jang@linux.vnet.ibm.com>");
  27. MODULE_DESCRIPTION("QDIO base support");
  28. MODULE_LICENSE("GPL");
  29. static inline int do_siga_sync(struct subchannel_id schid,
  30. unsigned int out_mask, unsigned int in_mask)
  31. {
  32. register unsigned long __fc asm ("0") = 2;
  33. register struct subchannel_id __schid asm ("1") = schid;
  34. register unsigned long out asm ("2") = out_mask;
  35. register unsigned long in asm ("3") = in_mask;
  36. int cc;
  37. asm volatile(
  38. " siga 0\n"
  39. " ipm %0\n"
  40. " srl %0,28\n"
  41. : "=d" (cc)
  42. : "d" (__fc), "d" (__schid), "d" (out), "d" (in) : "cc");
  43. return cc;
  44. }
  45. static inline int do_siga_input(struct subchannel_id schid, unsigned int mask)
  46. {
  47. register unsigned long __fc asm ("0") = 1;
  48. register struct subchannel_id __schid asm ("1") = schid;
  49. register unsigned long __mask asm ("2") = mask;
  50. int cc;
  51. asm volatile(
  52. " siga 0\n"
  53. " ipm %0\n"
  54. " srl %0,28\n"
  55. : "=d" (cc)
  56. : "d" (__fc), "d" (__schid), "d" (__mask) : "cc", "memory");
  57. return cc;
  58. }
  59. /**
  60. * do_siga_output - perform SIGA-w/wt function
  61. * @schid: subchannel id or in case of QEBSM the subchannel token
  62. * @mask: which output queues to process
  63. * @bb: busy bit indicator, set only if SIGA-w/wt could not access a buffer
  64. * @fc: function code to perform
  65. *
  66. * Returns cc or QDIO_ERROR_SIGA_ACCESS_EXCEPTION.
  67. * Note: For IQDC unicast queues only the highest priority queue is processed.
  68. */
  69. static inline int do_siga_output(unsigned long schid, unsigned long mask,
  70. u32 *bb, unsigned int fc)
  71. {
  72. register unsigned long __fc asm("0") = fc;
  73. register unsigned long __schid asm("1") = schid;
  74. register unsigned long __mask asm("2") = mask;
  75. int cc = QDIO_ERROR_SIGA_ACCESS_EXCEPTION;
  76. asm volatile(
  77. " siga 0\n"
  78. "0: ipm %0\n"
  79. " srl %0,28\n"
  80. "1:\n"
  81. EX_TABLE(0b, 1b)
  82. : "+d" (cc), "+d" (__fc), "+d" (__schid), "+d" (__mask)
  83. : : "cc", "memory");
  84. *bb = ((unsigned int) __fc) >> 31;
  85. return cc;
  86. }
  87. static inline int qdio_check_ccq(struct qdio_q *q, unsigned int ccq)
  88. {
  89. char dbf_text[15];
  90. /* all done or next buffer state different */
  91. if (ccq == 0 || ccq == 32)
  92. return 0;
  93. /* not all buffers processed */
  94. if (ccq == 96 || ccq == 97)
  95. return 1;
  96. /* notify devices immediately */
  97. sprintf(dbf_text, "%d", ccq);
  98. QDIO_DBF_TEXT2(1, trace, dbf_text);
  99. return -EIO;
  100. }
  101. /**
  102. * qdio_do_eqbs - extract buffer states for QEBSM
  103. * @q: queue to manipulate
  104. * @state: state of the extracted buffers
  105. * @start: buffer number to start at
  106. * @count: count of buffers to examine
  107. *
  108. * Returns the number of successfull extracted equal buffer states.
  109. * Stops processing if a state is different from the last buffers state.
  110. */
  111. static int qdio_do_eqbs(struct qdio_q *q, unsigned char *state,
  112. int start, int count)
  113. {
  114. unsigned int ccq = 0;
  115. int tmp_count = count, tmp_start = start;
  116. int nr = q->nr;
  117. int rc;
  118. char dbf_text[15];
  119. BUG_ON(!q->irq_ptr->sch_token);
  120. if (!q->is_input_q)
  121. nr += q->irq_ptr->nr_input_qs;
  122. again:
  123. ccq = do_eqbs(q->irq_ptr->sch_token, state, nr, &tmp_start, &tmp_count);
  124. rc = qdio_check_ccq(q, ccq);
  125. /* At least one buffer was processed, return and extract the remaining
  126. * buffers later.
  127. */
  128. if ((ccq == 96) && (count != tmp_count))
  129. return (count - tmp_count);
  130. if (rc == 1) {
  131. QDIO_DBF_TEXT5(1, trace, "eqAGAIN");
  132. goto again;
  133. }
  134. if (rc < 0) {
  135. QDIO_DBF_TEXT2(1, trace, "eqberr");
  136. sprintf(dbf_text, "%2x,%2x,%d,%d", count, tmp_count, ccq, nr);
  137. QDIO_DBF_TEXT2(1, trace, dbf_text);
  138. q->handler(q->irq_ptr->cdev,
  139. QDIO_ERROR_ACTIVATE_CHECK_CONDITION,
  140. 0, -1, -1, q->irq_ptr->int_parm);
  141. return 0;
  142. }
  143. return count - tmp_count;
  144. }
  145. /**
  146. * qdio_do_sqbs - set buffer states for QEBSM
  147. * @q: queue to manipulate
  148. * @state: new state of the buffers
  149. * @start: first buffer number to change
  150. * @count: how many buffers to change
  151. *
  152. * Returns the number of successfully changed buffers.
  153. * Does retrying until the specified count of buffer states is set or an
  154. * error occurs.
  155. */
  156. static int qdio_do_sqbs(struct qdio_q *q, unsigned char state, int start,
  157. int count)
  158. {
  159. unsigned int ccq = 0;
  160. int tmp_count = count, tmp_start = start;
  161. int nr = q->nr;
  162. int rc;
  163. char dbf_text[15];
  164. BUG_ON(!q->irq_ptr->sch_token);
  165. if (!q->is_input_q)
  166. nr += q->irq_ptr->nr_input_qs;
  167. again:
  168. ccq = do_sqbs(q->irq_ptr->sch_token, state, nr, &tmp_start, &tmp_count);
  169. rc = qdio_check_ccq(q, ccq);
  170. if (rc == 1) {
  171. QDIO_DBF_TEXT5(1, trace, "sqAGAIN");
  172. goto again;
  173. }
  174. if (rc < 0) {
  175. QDIO_DBF_TEXT3(1, trace, "sqberr");
  176. sprintf(dbf_text, "%2x,%2x", count, tmp_count);
  177. QDIO_DBF_TEXT3(1, trace, dbf_text);
  178. sprintf(dbf_text, "%d,%d", ccq, nr);
  179. QDIO_DBF_TEXT3(1, trace, dbf_text);
  180. q->handler(q->irq_ptr->cdev,
  181. QDIO_ERROR_ACTIVATE_CHECK_CONDITION,
  182. 0, -1, -1, q->irq_ptr->int_parm);
  183. return 0;
  184. }
  185. WARN_ON(tmp_count);
  186. return count - tmp_count;
  187. }
  188. /* returns number of examined buffers and their common state in *state */
  189. static inline int get_buf_states(struct qdio_q *q, unsigned int bufnr,
  190. unsigned char *state, unsigned int count)
  191. {
  192. unsigned char __state = 0;
  193. int i;
  194. BUG_ON(bufnr > QDIO_MAX_BUFFERS_MASK);
  195. BUG_ON(count > QDIO_MAX_BUFFERS_PER_Q);
  196. if (is_qebsm(q))
  197. return qdio_do_eqbs(q, state, bufnr, count);
  198. for (i = 0; i < count; i++) {
  199. if (!__state)
  200. __state = q->slsb.val[bufnr];
  201. else if (q->slsb.val[bufnr] != __state)
  202. break;
  203. bufnr = next_buf(bufnr);
  204. }
  205. *state = __state;
  206. return i;
  207. }
  208. inline int get_buf_state(struct qdio_q *q, unsigned int bufnr,
  209. unsigned char *state)
  210. {
  211. return get_buf_states(q, bufnr, state, 1);
  212. }
  213. /* wrap-around safe setting of slsb states, returns number of changed buffers */
  214. static inline int set_buf_states(struct qdio_q *q, int bufnr,
  215. unsigned char state, int count)
  216. {
  217. int i;
  218. BUG_ON(bufnr > QDIO_MAX_BUFFERS_MASK);
  219. BUG_ON(count > QDIO_MAX_BUFFERS_PER_Q);
  220. if (is_qebsm(q))
  221. return qdio_do_sqbs(q, state, bufnr, count);
  222. for (i = 0; i < count; i++) {
  223. xchg(&q->slsb.val[bufnr], state);
  224. bufnr = next_buf(bufnr);
  225. }
  226. return count;
  227. }
  228. static inline int set_buf_state(struct qdio_q *q, int bufnr,
  229. unsigned char state)
  230. {
  231. return set_buf_states(q, bufnr, state, 1);
  232. }
  233. /* set slsb states to initial state */
  234. void qdio_init_buf_states(struct qdio_irq *irq_ptr)
  235. {
  236. struct qdio_q *q;
  237. int i;
  238. for_each_input_queue(irq_ptr, q, i)
  239. set_buf_states(q, 0, SLSB_P_INPUT_NOT_INIT,
  240. QDIO_MAX_BUFFERS_PER_Q);
  241. for_each_output_queue(irq_ptr, q, i)
  242. set_buf_states(q, 0, SLSB_P_OUTPUT_NOT_INIT,
  243. QDIO_MAX_BUFFERS_PER_Q);
  244. }
  245. static int qdio_siga_sync(struct qdio_q *q, unsigned int output,
  246. unsigned int input)
  247. {
  248. int cc;
  249. if (!need_siga_sync(q))
  250. return 0;
  251. qdio_perf_stat_inc(&perf_stats.siga_sync);
  252. cc = do_siga_sync(q->irq_ptr->schid, output, input);
  253. if (cc) {
  254. QDIO_DBF_TEXT4(0, trace, "sigasync");
  255. QDIO_DBF_HEX4(0, trace, &q, sizeof(void *));
  256. QDIO_DBF_HEX3(0, trace, &cc, sizeof(int *));
  257. }
  258. return cc;
  259. }
  260. inline int qdio_siga_sync_q(struct qdio_q *q)
  261. {
  262. if (q->is_input_q)
  263. return qdio_siga_sync(q, 0, q->mask);
  264. else
  265. return qdio_siga_sync(q, q->mask, 0);
  266. }
  267. static inline int qdio_siga_sync_out(struct qdio_q *q)
  268. {
  269. return qdio_siga_sync(q, ~0U, 0);
  270. }
  271. static inline int qdio_siga_sync_all(struct qdio_q *q)
  272. {
  273. return qdio_siga_sync(q, ~0U, ~0U);
  274. }
  275. static inline int qdio_do_siga_output(struct qdio_q *q, unsigned int *busy_bit)
  276. {
  277. unsigned int fc = 0;
  278. unsigned long schid;
  279. if (q->u.out.use_enh_siga) {
  280. fc = 3;
  281. }
  282. if (!is_qebsm(q))
  283. schid = *((u32 *)&q->irq_ptr->schid);
  284. else {
  285. schid = q->irq_ptr->sch_token;
  286. fc |= 0x80;
  287. }
  288. return do_siga_output(schid, q->mask, busy_bit, fc);
  289. }
  290. static int qdio_siga_output(struct qdio_q *q)
  291. {
  292. int cc;
  293. u32 busy_bit;
  294. u64 start_time = 0;
  295. char dbf_text[15];
  296. QDIO_DBF_TEXT5(0, trace, "sigaout");
  297. QDIO_DBF_HEX5(0, trace, &q, sizeof(void *));
  298. qdio_perf_stat_inc(&perf_stats.siga_out);
  299. again:
  300. cc = qdio_do_siga_output(q, &busy_bit);
  301. if (queue_type(q) == QDIO_IQDIO_QFMT && cc == 2 && busy_bit) {
  302. sprintf(dbf_text, "bb%4x%2x", q->irq_ptr->schid.sch_no, q->nr);
  303. QDIO_DBF_TEXT3(0, trace, dbf_text);
  304. if (!start_time)
  305. start_time = get_usecs();
  306. else if ((get_usecs() - start_time) < QDIO_BUSY_BIT_PATIENCE)
  307. goto again;
  308. }
  309. if (cc == 2 && busy_bit)
  310. cc |= QDIO_ERROR_SIGA_BUSY;
  311. if (cc)
  312. QDIO_DBF_HEX3(0, trace, &cc, sizeof(int *));
  313. return cc;
  314. }
  315. static inline int qdio_siga_input(struct qdio_q *q)
  316. {
  317. int cc;
  318. QDIO_DBF_TEXT4(0, trace, "sigain");
  319. QDIO_DBF_HEX4(0, trace, &q, sizeof(void *));
  320. qdio_perf_stat_inc(&perf_stats.siga_in);
  321. cc = do_siga_input(q->irq_ptr->schid, q->mask);
  322. if (cc)
  323. QDIO_DBF_HEX3(0, trace, &cc, sizeof(int *));
  324. return cc;
  325. }
  326. /* called from thinint inbound handler */
  327. void qdio_sync_after_thinint(struct qdio_q *q)
  328. {
  329. if (pci_out_supported(q)) {
  330. if (need_siga_sync_thinint(q))
  331. qdio_siga_sync_all(q);
  332. else if (need_siga_sync_out_thinint(q))
  333. qdio_siga_sync_out(q);
  334. } else
  335. qdio_siga_sync_q(q);
  336. }
  337. inline void qdio_stop_polling(struct qdio_q *q)
  338. {
  339. spin_lock_bh(&q->u.in.lock);
  340. if (!q->u.in.polling) {
  341. spin_unlock_bh(&q->u.in.lock);
  342. return;
  343. }
  344. q->u.in.polling = 0;
  345. qdio_perf_stat_inc(&perf_stats.debug_stop_polling);
  346. /* show the card that we are not polling anymore */
  347. set_buf_state(q, q->last_move_ftc, SLSB_P_INPUT_NOT_INIT);
  348. spin_unlock_bh(&q->u.in.lock);
  349. }
  350. static void announce_buffer_error(struct qdio_q *q)
  351. {
  352. char dbf_text[15];
  353. if (q->is_input_q)
  354. QDIO_DBF_TEXT3(1, trace, "inperr");
  355. else
  356. QDIO_DBF_TEXT3(0, trace, "outperr");
  357. sprintf(dbf_text, "%x-%x-%x", q->first_to_check,
  358. q->sbal[q->first_to_check]->element[14].flags,
  359. q->sbal[q->first_to_check]->element[15].flags);
  360. QDIO_DBF_TEXT3(1, trace, dbf_text);
  361. QDIO_DBF_HEX2(1, trace, q->sbal[q->first_to_check], 256);
  362. q->qdio_error = QDIO_ERROR_SLSB_STATE;
  363. }
  364. static int get_inbound_buffer_frontier(struct qdio_q *q)
  365. {
  366. int count, stop;
  367. unsigned char state;
  368. /*
  369. * If we still poll don't update last_move_ftc, keep the
  370. * previously ACK buffer there.
  371. */
  372. if (!q->u.in.polling)
  373. q->last_move_ftc = q->first_to_check;
  374. /*
  375. * Don't check 128 buffers, as otherwise qdio_inbound_q_moved
  376. * would return 0.
  377. */
  378. count = min(atomic_read(&q->nr_buf_used), QDIO_MAX_BUFFERS_MASK);
  379. stop = add_buf(q->first_to_check, count);
  380. /*
  381. * No siga sync here, as a PCI or we after a thin interrupt
  382. * will sync the queues.
  383. */
  384. /* need to set count to 1 for non-qebsm */
  385. if (!is_qebsm(q))
  386. count = 1;
  387. check_next:
  388. if (q->first_to_check == stop)
  389. goto out;
  390. count = get_buf_states(q, q->first_to_check, &state, count);
  391. if (!count)
  392. goto out;
  393. switch (state) {
  394. case SLSB_P_INPUT_PRIMED:
  395. QDIO_DBF_TEXT5(0, trace, "inptprim");
  396. /*
  397. * Only ACK the first buffer. The ACK will be removed in
  398. * qdio_stop_polling.
  399. */
  400. if (q->u.in.polling)
  401. state = SLSB_P_INPUT_NOT_INIT;
  402. else {
  403. q->u.in.polling = 1;
  404. state = SLSB_P_INPUT_ACK;
  405. }
  406. set_buf_state(q, q->first_to_check, state);
  407. /*
  408. * Need to change all PRIMED buffers to NOT_INIT, otherwise
  409. * we're loosing initiative in the thinint code.
  410. */
  411. if (count > 1)
  412. set_buf_states(q, next_buf(q->first_to_check),
  413. SLSB_P_INPUT_NOT_INIT, count - 1);
  414. /*
  415. * No siga-sync needed for non-qebsm here, as the inbound queue
  416. * will be synced on the next siga-r, resp.
  417. * tiqdio_is_inbound_q_done will do the siga-sync.
  418. */
  419. q->first_to_check = add_buf(q->first_to_check, count);
  420. atomic_sub(count, &q->nr_buf_used);
  421. goto check_next;
  422. case SLSB_P_INPUT_ERROR:
  423. announce_buffer_error(q);
  424. /* process the buffer, the upper layer will take care of it */
  425. q->first_to_check = add_buf(q->first_to_check, count);
  426. atomic_sub(count, &q->nr_buf_used);
  427. break;
  428. case SLSB_CU_INPUT_EMPTY:
  429. case SLSB_P_INPUT_NOT_INIT:
  430. case SLSB_P_INPUT_ACK:
  431. QDIO_DBF_TEXT5(0, trace, "inpnipro");
  432. break;
  433. default:
  434. BUG();
  435. }
  436. out:
  437. QDIO_DBF_HEX4(0, trace, &q->first_to_check, sizeof(int));
  438. return q->first_to_check;
  439. }
  440. int qdio_inbound_q_moved(struct qdio_q *q)
  441. {
  442. int bufnr;
  443. bufnr = get_inbound_buffer_frontier(q);
  444. if ((bufnr != q->last_move_ftc) || q->qdio_error) {
  445. if (!need_siga_sync(q) && !pci_out_supported(q))
  446. q->u.in.timestamp = get_usecs();
  447. QDIO_DBF_TEXT4(0, trace, "inhasmvd");
  448. QDIO_DBF_HEX4(0, trace, &q, sizeof(void *));
  449. return 1;
  450. } else
  451. return 0;
  452. }
  453. static int qdio_inbound_q_done(struct qdio_q *q)
  454. {
  455. unsigned char state;
  456. #ifdef CONFIG_QDIO_DEBUG
  457. char dbf_text[15];
  458. #endif
  459. if (!atomic_read(&q->nr_buf_used))
  460. return 1;
  461. /*
  462. * We need that one for synchronization with the adapter, as it
  463. * does a kind of PCI avoidance.
  464. */
  465. qdio_siga_sync_q(q);
  466. get_buf_state(q, q->first_to_check, &state);
  467. if (state == SLSB_P_INPUT_PRIMED)
  468. /* we got something to do */
  469. return 0;
  470. /* on VM, we don't poll, so the q is always done here */
  471. if (need_siga_sync(q) || pci_out_supported(q))
  472. return 1;
  473. /*
  474. * At this point we know, that inbound first_to_check
  475. * has (probably) not moved (see qdio_inbound_processing).
  476. */
  477. if (get_usecs() > q->u.in.timestamp + QDIO_INPUT_THRESHOLD) {
  478. #ifdef CONFIG_QDIO_DEBUG
  479. QDIO_DBF_TEXT4(0, trace, "inqisdon");
  480. QDIO_DBF_HEX4(0, trace, &q, sizeof(void *));
  481. sprintf(dbf_text, "pf%02x", q->first_to_check);
  482. QDIO_DBF_TEXT4(0, trace, dbf_text);
  483. #endif /* CONFIG_QDIO_DEBUG */
  484. return 1;
  485. } else {
  486. #ifdef CONFIG_QDIO_DEBUG
  487. QDIO_DBF_TEXT4(0, trace, "inqisntd");
  488. QDIO_DBF_HEX4(0, trace, &q, sizeof(void *));
  489. sprintf(dbf_text, "pf%02x", q->first_to_check);
  490. QDIO_DBF_TEXT4(0, trace, dbf_text);
  491. #endif /* CONFIG_QDIO_DEBUG */
  492. return 0;
  493. }
  494. }
  495. void qdio_kick_inbound_handler(struct qdio_q *q)
  496. {
  497. int count, start, end;
  498. #ifdef CONFIG_QDIO_DEBUG
  499. char dbf_text[15];
  500. #endif
  501. qdio_perf_stat_inc(&perf_stats.inbound_handler);
  502. start = q->first_to_kick;
  503. end = q->first_to_check;
  504. if (end >= start)
  505. count = end - start;
  506. else
  507. count = end + QDIO_MAX_BUFFERS_PER_Q - start;
  508. #ifdef CONFIG_QDIO_DEBUG
  509. sprintf(dbf_text, "s=%2xc=%2x", start, count);
  510. QDIO_DBF_TEXT4(0, trace, dbf_text);
  511. #endif /* CONFIG_QDIO_DEBUG */
  512. if (unlikely(q->irq_ptr->state != QDIO_IRQ_STATE_ACTIVE))
  513. return;
  514. q->handler(q->irq_ptr->cdev, q->qdio_error, q->nr,
  515. start, count, q->irq_ptr->int_parm);
  516. /* for the next time */
  517. q->first_to_kick = q->first_to_check;
  518. q->qdio_error = 0;
  519. }
  520. static void __qdio_inbound_processing(struct qdio_q *q)
  521. {
  522. qdio_perf_stat_inc(&perf_stats.tasklet_inbound);
  523. again:
  524. if (!qdio_inbound_q_moved(q))
  525. return;
  526. qdio_kick_inbound_handler(q);
  527. if (!qdio_inbound_q_done(q))
  528. /* means poll time is not yet over */
  529. goto again;
  530. qdio_stop_polling(q);
  531. /*
  532. * We need to check again to not lose initiative after
  533. * resetting the ACK state.
  534. */
  535. if (!qdio_inbound_q_done(q))
  536. goto again;
  537. }
  538. /* inbound tasklet */
  539. void qdio_inbound_processing(unsigned long data)
  540. {
  541. struct qdio_q *q = (struct qdio_q *)data;
  542. __qdio_inbound_processing(q);
  543. }
  544. static int get_outbound_buffer_frontier(struct qdio_q *q)
  545. {
  546. int count, stop;
  547. unsigned char state;
  548. if (((queue_type(q) != QDIO_IQDIO_QFMT) && !pci_out_supported(q)) ||
  549. (queue_type(q) == QDIO_IQDIO_QFMT && multicast_outbound(q)))
  550. qdio_siga_sync_q(q);
  551. /*
  552. * Don't check 128 buffers, as otherwise qdio_inbound_q_moved
  553. * would return 0.
  554. */
  555. count = min(atomic_read(&q->nr_buf_used), QDIO_MAX_BUFFERS_MASK);
  556. stop = add_buf(q->first_to_check, count);
  557. /* need to set count to 1 for non-qebsm */
  558. if (!is_qebsm(q))
  559. count = 1;
  560. check_next:
  561. if (q->first_to_check == stop)
  562. return q->first_to_check;
  563. count = get_buf_states(q, q->first_to_check, &state, count);
  564. if (!count)
  565. return q->first_to_check;
  566. switch (state) {
  567. case SLSB_P_OUTPUT_EMPTY:
  568. /* the adapter got it */
  569. QDIO_DBF_TEXT5(0, trace, "outpempt");
  570. atomic_sub(count, &q->nr_buf_used);
  571. q->first_to_check = add_buf(q->first_to_check, count);
  572. /*
  573. * We fetch all buffer states at once. get_buf_states may
  574. * return count < stop. For QEBSM we do not loop.
  575. */
  576. if (is_qebsm(q))
  577. break;
  578. goto check_next;
  579. case SLSB_P_OUTPUT_ERROR:
  580. announce_buffer_error(q);
  581. /* process the buffer, the upper layer will take care of it */
  582. q->first_to_check = add_buf(q->first_to_check, count);
  583. atomic_sub(count, &q->nr_buf_used);
  584. break;
  585. case SLSB_CU_OUTPUT_PRIMED:
  586. /* the adapter has not fetched the output yet */
  587. QDIO_DBF_TEXT5(0, trace, "outpprim");
  588. break;
  589. case SLSB_P_OUTPUT_NOT_INIT:
  590. case SLSB_P_OUTPUT_HALTED:
  591. break;
  592. default:
  593. BUG();
  594. }
  595. return q->first_to_check;
  596. }
  597. /* all buffers processed? */
  598. static inline int qdio_outbound_q_done(struct qdio_q *q)
  599. {
  600. return atomic_read(&q->nr_buf_used) == 0;
  601. }
  602. static inline int qdio_outbound_q_moved(struct qdio_q *q)
  603. {
  604. int bufnr;
  605. bufnr = get_outbound_buffer_frontier(q);
  606. if ((bufnr != q->last_move_ftc) || q->qdio_error) {
  607. q->last_move_ftc = bufnr;
  608. QDIO_DBF_TEXT4(0, trace, "oqhasmvd");
  609. QDIO_DBF_HEX4(0, trace, &q, sizeof(void *));
  610. return 1;
  611. } else
  612. return 0;
  613. }
  614. /*
  615. * VM could present us cc=2 and busy bit set on SIGA-write
  616. * during reconfiguration of their Guest LAN (only in iqdio mode,
  617. * otherwise qdio is asynchronous and cc=2 and busy bit there will take
  618. * the queues down immediately).
  619. *
  620. * Therefore qdio_siga_output will try for a short time constantly,
  621. * if such a condition occurs. If it doesn't change, it will
  622. * increase the busy_siga_counter and save the timestamp, and
  623. * schedule the queue for later processing. qdio_outbound_processing
  624. * will check out the counter. If non-zero, it will call qdio_kick_outbound_q
  625. * as often as the value of the counter. This will attempt further SIGA
  626. * instructions. For each successful SIGA, the counter is
  627. * decreased, for failing SIGAs the counter remains the same, after
  628. * all. After some time of no movement, qdio_kick_outbound_q will
  629. * finally fail and reflect corresponding error codes to call
  630. * the upper layer module and have it take the queues down.
  631. *
  632. * Note that this is a change from the original HiperSockets design
  633. * (saying cc=2 and busy bit means take the queues down), but in
  634. * these days Guest LAN didn't exist... excessive cc=2 with busy bit
  635. * conditions will still take the queues down, but the threshold is
  636. * higher due to the Guest LAN environment.
  637. *
  638. * Called from outbound tasklet and do_QDIO handler.
  639. */
  640. static void qdio_kick_outbound_q(struct qdio_q *q)
  641. {
  642. int rc;
  643. #ifdef CONFIG_QDIO_DEBUG
  644. char dbf_text[15];
  645. QDIO_DBF_TEXT5(0, trace, "kickoutq");
  646. QDIO_DBF_HEX5(0, trace, &q, sizeof(void *));
  647. #endif /* CONFIG_QDIO_DEBUG */
  648. if (!need_siga_out(q))
  649. return;
  650. rc = qdio_siga_output(q);
  651. switch (rc) {
  652. case 0:
  653. /* TODO: improve error handling for CC=0 case */
  654. #ifdef CONFIG_QDIO_DEBUG
  655. if (q->u.out.timestamp) {
  656. QDIO_DBF_TEXT3(0, trace, "cc2reslv");
  657. sprintf(dbf_text, "%4x%2x%2x", q->irq_ptr->schid.sch_no,
  658. q->nr,
  659. atomic_read(&q->u.out.busy_siga_counter));
  660. QDIO_DBF_TEXT3(0, trace, dbf_text);
  661. }
  662. #endif /* CONFIG_QDIO_DEBUG */
  663. /* went smooth this time, reset timestamp */
  664. q->u.out.timestamp = 0;
  665. break;
  666. /* cc=2 and busy bit */
  667. case (2 | QDIO_ERROR_SIGA_BUSY):
  668. atomic_inc(&q->u.out.busy_siga_counter);
  669. /* if the last siga was successful, save timestamp here */
  670. if (!q->u.out.timestamp)
  671. q->u.out.timestamp = get_usecs();
  672. /* if we're in time, don't touch qdio_error */
  673. if (get_usecs() - q->u.out.timestamp < QDIO_BUSY_BIT_GIVE_UP) {
  674. tasklet_schedule(&q->tasklet);
  675. break;
  676. }
  677. QDIO_DBF_TEXT2(0, trace, "cc2REPRT");
  678. #ifdef CONFIG_QDIO_DEBUG
  679. sprintf(dbf_text, "%4x%2x%2x", q->irq_ptr->schid.sch_no, q->nr,
  680. atomic_read(&q->u.out.busy_siga_counter));
  681. QDIO_DBF_TEXT3(0, trace, dbf_text);
  682. #endif /* CONFIG_QDIO_DEBUG */
  683. default:
  684. /* for plain cc=1, 2 or 3 */
  685. q->qdio_error = rc;
  686. }
  687. }
  688. static void qdio_kick_outbound_handler(struct qdio_q *q)
  689. {
  690. int start, end, count;
  691. #ifdef CONFIG_QDIO_DEBUG
  692. char dbf_text[15];
  693. #endif
  694. start = q->first_to_kick;
  695. end = q->last_move_ftc;
  696. if (end >= start)
  697. count = end - start;
  698. else
  699. count = end + QDIO_MAX_BUFFERS_PER_Q - start;
  700. #ifdef CONFIG_QDIO_DEBUG
  701. QDIO_DBF_TEXT4(0, trace, "kickouth");
  702. QDIO_DBF_HEX4(0, trace, &q, sizeof(void *));
  703. sprintf(dbf_text, "s=%2xc=%2x", start, count);
  704. QDIO_DBF_TEXT4(0, trace, dbf_text);
  705. #endif /* CONFIG_QDIO_DEBUG */
  706. if (unlikely(q->irq_ptr->state != QDIO_IRQ_STATE_ACTIVE))
  707. return;
  708. q->handler(q->irq_ptr->cdev, q->qdio_error, q->nr, start, count,
  709. q->irq_ptr->int_parm);
  710. /* for the next time: */
  711. q->first_to_kick = q->last_move_ftc;
  712. q->qdio_error = 0;
  713. }
  714. static void __qdio_outbound_processing(struct qdio_q *q)
  715. {
  716. int siga_attempts;
  717. qdio_perf_stat_inc(&perf_stats.tasklet_outbound);
  718. /* see comment in qdio_kick_outbound_q */
  719. siga_attempts = atomic_read(&q->u.out.busy_siga_counter);
  720. while (siga_attempts--) {
  721. atomic_dec(&q->u.out.busy_siga_counter);
  722. qdio_kick_outbound_q(q);
  723. }
  724. BUG_ON(atomic_read(&q->nr_buf_used) < 0);
  725. if (qdio_outbound_q_moved(q))
  726. qdio_kick_outbound_handler(q);
  727. if (queue_type(q) == QDIO_ZFCP_QFMT) {
  728. if (!pci_out_supported(q) && !qdio_outbound_q_done(q))
  729. tasklet_schedule(&q->tasklet);
  730. return;
  731. }
  732. /* bail out for HiperSockets unicast queues */
  733. if (queue_type(q) == QDIO_IQDIO_QFMT && !multicast_outbound(q))
  734. return;
  735. if ((queue_type(q) == QDIO_IQDIO_QFMT) &&
  736. (atomic_read(&q->nr_buf_used)) > QDIO_IQDIO_POLL_LVL) {
  737. tasklet_schedule(&q->tasklet);
  738. return;
  739. }
  740. if (q->u.out.pci_out_enabled)
  741. return;
  742. /*
  743. * Now we know that queue type is either qeth without pci enabled
  744. * or HiperSockets multicast. Make sure buffer switch from PRIMED to
  745. * EMPTY is noticed and outbound_handler is called after some time.
  746. */
  747. if (qdio_outbound_q_done(q))
  748. del_timer(&q->u.out.timer);
  749. else {
  750. if (!timer_pending(&q->u.out.timer)) {
  751. mod_timer(&q->u.out.timer, jiffies + 10 * HZ);
  752. qdio_perf_stat_inc(&perf_stats.debug_tl_out_timer);
  753. }
  754. }
  755. }
  756. /* outbound tasklet */
  757. void qdio_outbound_processing(unsigned long data)
  758. {
  759. struct qdio_q *q = (struct qdio_q *)data;
  760. __qdio_outbound_processing(q);
  761. }
  762. void qdio_outbound_timer(unsigned long data)
  763. {
  764. struct qdio_q *q = (struct qdio_q *)data;
  765. tasklet_schedule(&q->tasklet);
  766. }
  767. /* called from thinint inbound tasklet */
  768. void qdio_check_outbound_after_thinint(struct qdio_q *q)
  769. {
  770. struct qdio_q *out;
  771. int i;
  772. if (!pci_out_supported(q))
  773. return;
  774. for_each_output_queue(q->irq_ptr, out, i)
  775. if (!qdio_outbound_q_done(out))
  776. tasklet_schedule(&out->tasklet);
  777. }
  778. static inline void qdio_set_state(struct qdio_irq *irq_ptr,
  779. enum qdio_irq_states state)
  780. {
  781. #ifdef CONFIG_QDIO_DEBUG
  782. char dbf_text[15];
  783. QDIO_DBF_TEXT5(0, trace, "newstate");
  784. sprintf(dbf_text, "%4x%4x", irq_ptr->schid.sch_no, state);
  785. QDIO_DBF_TEXT5(0, trace, dbf_text);
  786. #endif /* CONFIG_QDIO_DEBUG */
  787. irq_ptr->state = state;
  788. mb();
  789. }
  790. static void qdio_irq_check_sense(struct subchannel_id schid, struct irb *irb)
  791. {
  792. char dbf_text[15];
  793. if (irb->esw.esw0.erw.cons) {
  794. sprintf(dbf_text, "sens%4x", schid.sch_no);
  795. QDIO_DBF_TEXT2(1, trace, dbf_text);
  796. QDIO_DBF_HEX0(0, trace, irb, 64);
  797. QDIO_DBF_HEX0(0, trace, irb->ecw, 64);
  798. }
  799. }
  800. /* PCI interrupt handler */
  801. static void qdio_int_handler_pci(struct qdio_irq *irq_ptr)
  802. {
  803. int i;
  804. struct qdio_q *q;
  805. qdio_perf_stat_inc(&perf_stats.pci_int);
  806. for_each_input_queue(irq_ptr, q, i)
  807. tasklet_schedule(&q->tasklet);
  808. if (!(irq_ptr->qib.ac & QIB_AC_OUTBOUND_PCI_SUPPORTED))
  809. return;
  810. for_each_output_queue(irq_ptr, q, i) {
  811. if (qdio_outbound_q_done(q))
  812. continue;
  813. if (!siga_syncs_out_pci(q))
  814. qdio_siga_sync_q(q);
  815. tasklet_schedule(&q->tasklet);
  816. }
  817. }
  818. static void qdio_handle_activate_check(struct ccw_device *cdev,
  819. unsigned long intparm, int cstat, int dstat)
  820. {
  821. struct qdio_irq *irq_ptr = cdev->private->qdio_data;
  822. struct qdio_q *q;
  823. char dbf_text[15];
  824. QDIO_DBF_TEXT2(1, trace, "ick2");
  825. sprintf(dbf_text, "%s", dev_name(&cdev->dev));
  826. QDIO_DBF_TEXT2(1, trace, dbf_text);
  827. QDIO_DBF_HEX2(0, trace, &intparm, sizeof(int));
  828. QDIO_DBF_HEX2(0, trace, &dstat, sizeof(int));
  829. QDIO_DBF_HEX2(0, trace, &cstat, sizeof(int));
  830. if (irq_ptr->nr_input_qs) {
  831. q = irq_ptr->input_qs[0];
  832. } else if (irq_ptr->nr_output_qs) {
  833. q = irq_ptr->output_qs[0];
  834. } else {
  835. dump_stack();
  836. goto no_handler;
  837. }
  838. q->handler(q->irq_ptr->cdev, QDIO_ERROR_ACTIVATE_CHECK_CONDITION,
  839. 0, -1, -1, irq_ptr->int_parm);
  840. no_handler:
  841. qdio_set_state(irq_ptr, QDIO_IRQ_STATE_STOPPED);
  842. }
  843. static void qdio_call_shutdown(struct work_struct *work)
  844. {
  845. struct ccw_device_private *priv;
  846. struct ccw_device *cdev;
  847. priv = container_of(work, struct ccw_device_private, kick_work);
  848. cdev = priv->cdev;
  849. qdio_shutdown(cdev, QDIO_FLAG_CLEANUP_USING_CLEAR);
  850. put_device(&cdev->dev);
  851. }
  852. static void qdio_int_error(struct ccw_device *cdev)
  853. {
  854. struct qdio_irq *irq_ptr = cdev->private->qdio_data;
  855. switch (irq_ptr->state) {
  856. case QDIO_IRQ_STATE_INACTIVE:
  857. case QDIO_IRQ_STATE_CLEANUP:
  858. qdio_set_state(irq_ptr, QDIO_IRQ_STATE_ERR);
  859. break;
  860. case QDIO_IRQ_STATE_ESTABLISHED:
  861. case QDIO_IRQ_STATE_ACTIVE:
  862. qdio_set_state(irq_ptr, QDIO_IRQ_STATE_STOPPED);
  863. if (get_device(&cdev->dev)) {
  864. /* Can't call shutdown from interrupt context. */
  865. PREPARE_WORK(&cdev->private->kick_work,
  866. qdio_call_shutdown);
  867. queue_work(ccw_device_work, &cdev->private->kick_work);
  868. }
  869. break;
  870. default:
  871. WARN_ON(1);
  872. }
  873. wake_up(&cdev->private->wait_q);
  874. }
  875. static int qdio_establish_check_errors(struct ccw_device *cdev, int cstat,
  876. int dstat)
  877. {
  878. struct qdio_irq *irq_ptr = cdev->private->qdio_data;
  879. if (cstat || (dstat & ~(DEV_STAT_CHN_END | DEV_STAT_DEV_END))) {
  880. QDIO_DBF_TEXT2(1, setup, "eq:ckcon");
  881. goto error;
  882. }
  883. if (!(dstat & DEV_STAT_DEV_END)) {
  884. QDIO_DBF_TEXT2(1, setup, "eq:no de");
  885. goto error;
  886. }
  887. if (dstat & ~(DEV_STAT_CHN_END | DEV_STAT_DEV_END)) {
  888. QDIO_DBF_TEXT2(1, setup, "eq:badio");
  889. goto error;
  890. }
  891. return 0;
  892. error:
  893. QDIO_DBF_HEX2(0, trace, &cstat, sizeof(int));
  894. QDIO_DBF_HEX2(0, trace, &dstat, sizeof(int));
  895. qdio_set_state(irq_ptr, QDIO_IRQ_STATE_ERR);
  896. return 1;
  897. }
  898. static void qdio_establish_handle_irq(struct ccw_device *cdev, int cstat,
  899. int dstat)
  900. {
  901. struct qdio_irq *irq_ptr = cdev->private->qdio_data;
  902. char dbf_text[15];
  903. sprintf(dbf_text, "qehi%4x", cdev->private->schid.sch_no);
  904. QDIO_DBF_TEXT0(0, setup, dbf_text);
  905. QDIO_DBF_TEXT0(0, trace, dbf_text);
  906. if (!qdio_establish_check_errors(cdev, cstat, dstat))
  907. qdio_set_state(irq_ptr, QDIO_IRQ_STATE_ESTABLISHED);
  908. }
  909. /* qdio interrupt handler */
  910. void qdio_int_handler(struct ccw_device *cdev, unsigned long intparm,
  911. struct irb *irb)
  912. {
  913. struct qdio_irq *irq_ptr = cdev->private->qdio_data;
  914. int cstat, dstat;
  915. char dbf_text[15];
  916. qdio_perf_stat_inc(&perf_stats.qdio_int);
  917. if (!intparm || !irq_ptr) {
  918. sprintf(dbf_text, "qihd%4x", cdev->private->schid.sch_no);
  919. QDIO_DBF_TEXT2(1, setup, dbf_text);
  920. return;
  921. }
  922. if (IS_ERR(irb)) {
  923. switch (PTR_ERR(irb)) {
  924. case -EIO:
  925. sprintf(dbf_text, "ierr%4x", irq_ptr->schid.sch_no);
  926. QDIO_DBF_TEXT2(1, setup, dbf_text);
  927. return;
  928. case -ETIMEDOUT:
  929. sprintf(dbf_text, "qtoh%4x", irq_ptr->schid.sch_no);
  930. QDIO_DBF_TEXT2(1, setup, dbf_text);
  931. qdio_int_error(cdev);
  932. return;
  933. default:
  934. WARN_ON(1);
  935. return;
  936. }
  937. }
  938. qdio_irq_check_sense(irq_ptr->schid, irb);
  939. cstat = irb->scsw.cmd.cstat;
  940. dstat = irb->scsw.cmd.dstat;
  941. switch (irq_ptr->state) {
  942. case QDIO_IRQ_STATE_INACTIVE:
  943. qdio_establish_handle_irq(cdev, cstat, dstat);
  944. break;
  945. case QDIO_IRQ_STATE_CLEANUP:
  946. qdio_set_state(irq_ptr, QDIO_IRQ_STATE_INACTIVE);
  947. break;
  948. case QDIO_IRQ_STATE_ESTABLISHED:
  949. case QDIO_IRQ_STATE_ACTIVE:
  950. if (cstat & SCHN_STAT_PCI) {
  951. qdio_int_handler_pci(irq_ptr);
  952. /* no state change so no need to wake up wait_q */
  953. return;
  954. }
  955. if ((cstat & ~SCHN_STAT_PCI) || dstat) {
  956. qdio_handle_activate_check(cdev, intparm, cstat,
  957. dstat);
  958. break;
  959. }
  960. default:
  961. WARN_ON(1);
  962. }
  963. wake_up(&cdev->private->wait_q);
  964. }
  965. /**
  966. * qdio_get_ssqd_desc - get qdio subchannel description
  967. * @cdev: ccw device to get description for
  968. *
  969. * Returns a pointer to the saved qdio subchannel description,
  970. * or NULL for not setup qdio devices.
  971. */
  972. struct qdio_ssqd_desc *qdio_get_ssqd_desc(struct ccw_device *cdev)
  973. {
  974. struct qdio_irq *irq_ptr;
  975. char dbf_text[15];
  976. sprintf(dbf_text, "qssq%4x", cdev->private->schid.sch_no);
  977. QDIO_DBF_TEXT0(0, setup, dbf_text);
  978. irq_ptr = cdev->private->qdio_data;
  979. if (!irq_ptr)
  980. return NULL;
  981. return &irq_ptr->ssqd_desc;
  982. }
  983. EXPORT_SYMBOL_GPL(qdio_get_ssqd_desc);
  984. /**
  985. * qdio_cleanup - shutdown queues and free data structures
  986. * @cdev: associated ccw device
  987. * @how: use halt or clear to shutdown
  988. *
  989. * This function calls qdio_shutdown() for @cdev with method @how
  990. * and on success qdio_free() for @cdev.
  991. */
  992. int qdio_cleanup(struct ccw_device *cdev, int how)
  993. {
  994. struct qdio_irq *irq_ptr;
  995. char dbf_text[15];
  996. int rc;
  997. sprintf(dbf_text, "qcln%4x", cdev->private->schid.sch_no);
  998. QDIO_DBF_TEXT0(0, setup, dbf_text);
  999. irq_ptr = cdev->private->qdio_data;
  1000. if (!irq_ptr)
  1001. return -ENODEV;
  1002. rc = qdio_shutdown(cdev, how);
  1003. if (rc == 0)
  1004. rc = qdio_free(cdev);
  1005. return rc;
  1006. }
  1007. EXPORT_SYMBOL_GPL(qdio_cleanup);
  1008. static void qdio_shutdown_queues(struct ccw_device *cdev)
  1009. {
  1010. struct qdio_irq *irq_ptr = cdev->private->qdio_data;
  1011. struct qdio_q *q;
  1012. int i;
  1013. for_each_input_queue(irq_ptr, q, i)
  1014. tasklet_disable(&q->tasklet);
  1015. for_each_output_queue(irq_ptr, q, i) {
  1016. tasklet_disable(&q->tasklet);
  1017. del_timer(&q->u.out.timer);
  1018. }
  1019. }
  1020. /**
  1021. * qdio_shutdown - shut down a qdio subchannel
  1022. * @cdev: associated ccw device
  1023. * @how: use halt or clear to shutdown
  1024. */
  1025. int qdio_shutdown(struct ccw_device *cdev, int how)
  1026. {
  1027. struct qdio_irq *irq_ptr;
  1028. int rc;
  1029. unsigned long flags;
  1030. char dbf_text[15];
  1031. sprintf(dbf_text, "qshu%4x", cdev->private->schid.sch_no);
  1032. QDIO_DBF_TEXT0(0, setup, dbf_text);
  1033. irq_ptr = cdev->private->qdio_data;
  1034. if (!irq_ptr)
  1035. return -ENODEV;
  1036. mutex_lock(&irq_ptr->setup_mutex);
  1037. /*
  1038. * Subchannel was already shot down. We cannot prevent being called
  1039. * twice since cio may trigger a shutdown asynchronously.
  1040. */
  1041. if (irq_ptr->state == QDIO_IRQ_STATE_INACTIVE) {
  1042. mutex_unlock(&irq_ptr->setup_mutex);
  1043. return 0;
  1044. }
  1045. tiqdio_remove_input_queues(irq_ptr);
  1046. qdio_shutdown_queues(cdev);
  1047. qdio_shutdown_debug_entries(irq_ptr, cdev);
  1048. /* cleanup subchannel */
  1049. spin_lock_irqsave(get_ccwdev_lock(cdev), flags);
  1050. if (how & QDIO_FLAG_CLEANUP_USING_CLEAR)
  1051. rc = ccw_device_clear(cdev, QDIO_DOING_CLEANUP);
  1052. else
  1053. /* default behaviour is halt */
  1054. rc = ccw_device_halt(cdev, QDIO_DOING_CLEANUP);
  1055. if (rc) {
  1056. sprintf(dbf_text, "sher%4x", irq_ptr->schid.sch_no);
  1057. QDIO_DBF_TEXT0(0, setup, dbf_text);
  1058. sprintf(dbf_text, "rc=%d", rc);
  1059. QDIO_DBF_TEXT0(0, setup, dbf_text);
  1060. goto no_cleanup;
  1061. }
  1062. qdio_set_state(irq_ptr, QDIO_IRQ_STATE_CLEANUP);
  1063. spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags);
  1064. wait_event_interruptible_timeout(cdev->private->wait_q,
  1065. irq_ptr->state == QDIO_IRQ_STATE_INACTIVE ||
  1066. irq_ptr->state == QDIO_IRQ_STATE_ERR,
  1067. 10 * HZ);
  1068. spin_lock_irqsave(get_ccwdev_lock(cdev), flags);
  1069. no_cleanup:
  1070. qdio_shutdown_thinint(irq_ptr);
  1071. /* restore interrupt handler */
  1072. if ((void *)cdev->handler == (void *)qdio_int_handler)
  1073. cdev->handler = irq_ptr->orig_handler;
  1074. spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags);
  1075. qdio_set_state(irq_ptr, QDIO_IRQ_STATE_INACTIVE);
  1076. mutex_unlock(&irq_ptr->setup_mutex);
  1077. if (rc)
  1078. return rc;
  1079. return 0;
  1080. }
  1081. EXPORT_SYMBOL_GPL(qdio_shutdown);
  1082. /**
  1083. * qdio_free - free data structures for a qdio subchannel
  1084. * @cdev: associated ccw device
  1085. */
  1086. int qdio_free(struct ccw_device *cdev)
  1087. {
  1088. struct qdio_irq *irq_ptr;
  1089. char dbf_text[15];
  1090. sprintf(dbf_text, "qfre%4x", cdev->private->schid.sch_no);
  1091. QDIO_DBF_TEXT0(0, setup, dbf_text);
  1092. irq_ptr = cdev->private->qdio_data;
  1093. if (!irq_ptr)
  1094. return -ENODEV;
  1095. mutex_lock(&irq_ptr->setup_mutex);
  1096. cdev->private->qdio_data = NULL;
  1097. mutex_unlock(&irq_ptr->setup_mutex);
  1098. qdio_release_memory(irq_ptr);
  1099. return 0;
  1100. }
  1101. EXPORT_SYMBOL_GPL(qdio_free);
  1102. /**
  1103. * qdio_initialize - allocate and establish queues for a qdio subchannel
  1104. * @init_data: initialization data
  1105. *
  1106. * This function first allocates queues via qdio_allocate() and on success
  1107. * establishes them via qdio_establish().
  1108. */
  1109. int qdio_initialize(struct qdio_initialize *init_data)
  1110. {
  1111. int rc;
  1112. char dbf_text[15];
  1113. sprintf(dbf_text, "qini%4x", init_data->cdev->private->schid.sch_no);
  1114. QDIO_DBF_TEXT0(0, setup, dbf_text);
  1115. rc = qdio_allocate(init_data);
  1116. if (rc)
  1117. return rc;
  1118. rc = qdio_establish(init_data);
  1119. if (rc)
  1120. qdio_free(init_data->cdev);
  1121. return rc;
  1122. }
  1123. EXPORT_SYMBOL_GPL(qdio_initialize);
  1124. /**
  1125. * qdio_allocate - allocate qdio queues and associated data
  1126. * @init_data: initialization data
  1127. */
  1128. int qdio_allocate(struct qdio_initialize *init_data)
  1129. {
  1130. struct qdio_irq *irq_ptr;
  1131. char dbf_text[15];
  1132. sprintf(dbf_text, "qalc%4x", init_data->cdev->private->schid.sch_no);
  1133. QDIO_DBF_TEXT0(0, setup, dbf_text);
  1134. if ((init_data->no_input_qs && !init_data->input_handler) ||
  1135. (init_data->no_output_qs && !init_data->output_handler))
  1136. return -EINVAL;
  1137. if ((init_data->no_input_qs > QDIO_MAX_QUEUES_PER_IRQ) ||
  1138. (init_data->no_output_qs > QDIO_MAX_QUEUES_PER_IRQ))
  1139. return -EINVAL;
  1140. if ((!init_data->input_sbal_addr_array) ||
  1141. (!init_data->output_sbal_addr_array))
  1142. return -EINVAL;
  1143. qdio_allocate_do_dbf(init_data);
  1144. /* irq_ptr must be in GFP_DMA since it contains ccw1.cda */
  1145. irq_ptr = (void *) get_zeroed_page(GFP_KERNEL | GFP_DMA);
  1146. if (!irq_ptr)
  1147. goto out_err;
  1148. QDIO_DBF_TEXT0(0, setup, "irq_ptr:");
  1149. QDIO_DBF_HEX0(0, setup, &irq_ptr, sizeof(void *));
  1150. mutex_init(&irq_ptr->setup_mutex);
  1151. /*
  1152. * Allocate a page for the chsc calls in qdio_establish.
  1153. * Must be pre-allocated since a zfcp recovery will call
  1154. * qdio_establish. In case of low memory and swap on a zfcp disk
  1155. * we may not be able to allocate memory otherwise.
  1156. */
  1157. irq_ptr->chsc_page = get_zeroed_page(GFP_KERNEL);
  1158. if (!irq_ptr->chsc_page)
  1159. goto out_rel;
  1160. /* qdr is used in ccw1.cda which is u32 */
  1161. irq_ptr->qdr = (struct qdr *) get_zeroed_page(GFP_KERNEL | GFP_DMA);
  1162. if (!irq_ptr->qdr)
  1163. goto out_rel;
  1164. WARN_ON((unsigned long)irq_ptr->qdr & 0xfff);
  1165. QDIO_DBF_TEXT0(0, setup, "qdr:");
  1166. QDIO_DBF_HEX0(0, setup, &irq_ptr->qdr, sizeof(void *));
  1167. if (qdio_allocate_qs(irq_ptr, init_data->no_input_qs,
  1168. init_data->no_output_qs))
  1169. goto out_rel;
  1170. init_data->cdev->private->qdio_data = irq_ptr;
  1171. qdio_set_state(irq_ptr, QDIO_IRQ_STATE_INACTIVE);
  1172. return 0;
  1173. out_rel:
  1174. qdio_release_memory(irq_ptr);
  1175. out_err:
  1176. return -ENOMEM;
  1177. }
  1178. EXPORT_SYMBOL_GPL(qdio_allocate);
  1179. /**
  1180. * qdio_establish - establish queues on a qdio subchannel
  1181. * @init_data: initialization data
  1182. */
  1183. int qdio_establish(struct qdio_initialize *init_data)
  1184. {
  1185. char dbf_text[20];
  1186. struct qdio_irq *irq_ptr;
  1187. struct ccw_device *cdev = init_data->cdev;
  1188. unsigned long saveflags;
  1189. int rc;
  1190. sprintf(dbf_text, "qest%4x", cdev->private->schid.sch_no);
  1191. QDIO_DBF_TEXT0(0, setup, dbf_text);
  1192. irq_ptr = cdev->private->qdio_data;
  1193. if (!irq_ptr)
  1194. return -ENODEV;
  1195. if (cdev->private->state != DEV_STATE_ONLINE)
  1196. return -EINVAL;
  1197. mutex_lock(&irq_ptr->setup_mutex);
  1198. qdio_setup_irq(init_data);
  1199. rc = qdio_establish_thinint(irq_ptr);
  1200. if (rc) {
  1201. mutex_unlock(&irq_ptr->setup_mutex);
  1202. qdio_shutdown(cdev, QDIO_FLAG_CLEANUP_USING_CLEAR);
  1203. return rc;
  1204. }
  1205. /* establish q */
  1206. irq_ptr->ccw.cmd_code = irq_ptr->equeue.cmd;
  1207. irq_ptr->ccw.flags = CCW_FLAG_SLI;
  1208. irq_ptr->ccw.count = irq_ptr->equeue.count;
  1209. irq_ptr->ccw.cda = (u32)((addr_t)irq_ptr->qdr);
  1210. spin_lock_irqsave(get_ccwdev_lock(cdev), saveflags);
  1211. ccw_device_set_options_mask(cdev, 0);
  1212. rc = ccw_device_start(cdev, &irq_ptr->ccw, QDIO_DOING_ESTABLISH, 0, 0);
  1213. if (rc) {
  1214. sprintf(dbf_text, "eq:io%4x", irq_ptr->schid.sch_no);
  1215. QDIO_DBF_TEXT2(1, setup, dbf_text);
  1216. sprintf(dbf_text, "eq:rc%4x", rc);
  1217. QDIO_DBF_TEXT2(1, setup, dbf_text);
  1218. }
  1219. spin_unlock_irqrestore(get_ccwdev_lock(cdev), saveflags);
  1220. if (rc) {
  1221. mutex_unlock(&irq_ptr->setup_mutex);
  1222. qdio_shutdown(cdev, QDIO_FLAG_CLEANUP_USING_CLEAR);
  1223. return rc;
  1224. }
  1225. wait_event_interruptible_timeout(cdev->private->wait_q,
  1226. irq_ptr->state == QDIO_IRQ_STATE_ESTABLISHED ||
  1227. irq_ptr->state == QDIO_IRQ_STATE_ERR, HZ);
  1228. if (irq_ptr->state != QDIO_IRQ_STATE_ESTABLISHED) {
  1229. mutex_unlock(&irq_ptr->setup_mutex);
  1230. qdio_shutdown(cdev, QDIO_FLAG_CLEANUP_USING_CLEAR);
  1231. return -EIO;
  1232. }
  1233. qdio_setup_ssqd_info(irq_ptr);
  1234. sprintf(dbf_text, "qDmmwc%2x", irq_ptr->ssqd_desc.mmwc);
  1235. QDIO_DBF_TEXT2(0, setup, dbf_text);
  1236. sprintf(dbf_text, "qib ac%2x", irq_ptr->qib.ac);
  1237. QDIO_DBF_TEXT2(0, setup, dbf_text);
  1238. /* qebsm is now setup if available, initialize buffer states */
  1239. qdio_init_buf_states(irq_ptr);
  1240. mutex_unlock(&irq_ptr->setup_mutex);
  1241. qdio_print_subchannel_info(irq_ptr, cdev);
  1242. qdio_setup_debug_entries(irq_ptr, cdev);
  1243. return 0;
  1244. }
  1245. EXPORT_SYMBOL_GPL(qdio_establish);
  1246. /**
  1247. * qdio_activate - activate queues on a qdio subchannel
  1248. * @cdev: associated cdev
  1249. */
  1250. int qdio_activate(struct ccw_device *cdev)
  1251. {
  1252. struct qdio_irq *irq_ptr;
  1253. int rc;
  1254. unsigned long saveflags;
  1255. char dbf_text[20];
  1256. sprintf(dbf_text, "qact%4x", cdev->private->schid.sch_no);
  1257. QDIO_DBF_TEXT0(0, setup, dbf_text);
  1258. irq_ptr = cdev->private->qdio_data;
  1259. if (!irq_ptr)
  1260. return -ENODEV;
  1261. if (cdev->private->state != DEV_STATE_ONLINE)
  1262. return -EINVAL;
  1263. mutex_lock(&irq_ptr->setup_mutex);
  1264. if (irq_ptr->state == QDIO_IRQ_STATE_INACTIVE) {
  1265. rc = -EBUSY;
  1266. goto out;
  1267. }
  1268. irq_ptr->ccw.cmd_code = irq_ptr->aqueue.cmd;
  1269. irq_ptr->ccw.flags = CCW_FLAG_SLI;
  1270. irq_ptr->ccw.count = irq_ptr->aqueue.count;
  1271. irq_ptr->ccw.cda = 0;
  1272. spin_lock_irqsave(get_ccwdev_lock(cdev), saveflags);
  1273. ccw_device_set_options(cdev, CCWDEV_REPORT_ALL);
  1274. rc = ccw_device_start(cdev, &irq_ptr->ccw, QDIO_DOING_ACTIVATE,
  1275. 0, DOIO_DENY_PREFETCH);
  1276. if (rc) {
  1277. sprintf(dbf_text, "aq:io%4x", irq_ptr->schid.sch_no);
  1278. QDIO_DBF_TEXT2(1, setup, dbf_text);
  1279. sprintf(dbf_text, "aq:rc%4x", rc);
  1280. QDIO_DBF_TEXT2(1, setup, dbf_text);
  1281. }
  1282. spin_unlock_irqrestore(get_ccwdev_lock(cdev), saveflags);
  1283. if (rc)
  1284. goto out;
  1285. if (is_thinint_irq(irq_ptr))
  1286. tiqdio_add_input_queues(irq_ptr);
  1287. /* wait for subchannel to become active */
  1288. msleep(5);
  1289. switch (irq_ptr->state) {
  1290. case QDIO_IRQ_STATE_STOPPED:
  1291. case QDIO_IRQ_STATE_ERR:
  1292. mutex_unlock(&irq_ptr->setup_mutex);
  1293. qdio_shutdown(cdev, QDIO_FLAG_CLEANUP_USING_CLEAR);
  1294. return -EIO;
  1295. default:
  1296. qdio_set_state(irq_ptr, QDIO_IRQ_STATE_ACTIVE);
  1297. rc = 0;
  1298. }
  1299. out:
  1300. mutex_unlock(&irq_ptr->setup_mutex);
  1301. return rc;
  1302. }
  1303. EXPORT_SYMBOL_GPL(qdio_activate);
  1304. static inline int buf_in_between(int bufnr, int start, int count)
  1305. {
  1306. int end = add_buf(start, count);
  1307. if (end > start) {
  1308. if (bufnr >= start && bufnr < end)
  1309. return 1;
  1310. else
  1311. return 0;
  1312. }
  1313. /* wrap-around case */
  1314. if ((bufnr >= start && bufnr <= QDIO_MAX_BUFFERS_PER_Q) ||
  1315. (bufnr < end))
  1316. return 1;
  1317. else
  1318. return 0;
  1319. }
  1320. /**
  1321. * handle_inbound - reset processed input buffers
  1322. * @q: queue containing the buffers
  1323. * @callflags: flags
  1324. * @bufnr: first buffer to process
  1325. * @count: how many buffers are emptied
  1326. */
  1327. static void handle_inbound(struct qdio_q *q, unsigned int callflags,
  1328. int bufnr, int count)
  1329. {
  1330. unsigned long flags;
  1331. int used, rc;
  1332. /*
  1333. * do_QDIO could run in parallel with the queue tasklet so the
  1334. * upper-layer programm could empty the ACK'ed buffer here.
  1335. * If that happens we must clear the polling flag, otherwise
  1336. * qdio_stop_polling() could set the buffer to NOT_INIT after
  1337. * it was set to EMPTY which would kill us.
  1338. */
  1339. spin_lock_irqsave(&q->u.in.lock, flags);
  1340. if (q->u.in.polling)
  1341. if (buf_in_between(q->last_move_ftc, bufnr, count))
  1342. q->u.in.polling = 0;
  1343. count = set_buf_states(q, bufnr, SLSB_CU_INPUT_EMPTY, count);
  1344. spin_unlock_irqrestore(&q->u.in.lock, flags);
  1345. used = atomic_add_return(count, &q->nr_buf_used) - count;
  1346. BUG_ON(used + count > QDIO_MAX_BUFFERS_PER_Q);
  1347. /* no need to signal as long as the adapter had free buffers */
  1348. if (used)
  1349. return;
  1350. if (need_siga_in(q)) {
  1351. rc = qdio_siga_input(q);
  1352. if (rc)
  1353. q->qdio_error = rc;
  1354. }
  1355. }
  1356. /**
  1357. * handle_outbound - process filled outbound buffers
  1358. * @q: queue containing the buffers
  1359. * @callflags: flags
  1360. * @bufnr: first buffer to process
  1361. * @count: how many buffers are filled
  1362. */
  1363. static void handle_outbound(struct qdio_q *q, unsigned int callflags,
  1364. int bufnr, int count)
  1365. {
  1366. unsigned char state;
  1367. int used;
  1368. qdio_perf_stat_inc(&perf_stats.outbound_handler);
  1369. count = set_buf_states(q, bufnr, SLSB_CU_OUTPUT_PRIMED, count);
  1370. used = atomic_add_return(count, &q->nr_buf_used);
  1371. BUG_ON(used > QDIO_MAX_BUFFERS_PER_Q);
  1372. if (callflags & QDIO_FLAG_PCI_OUT)
  1373. q->u.out.pci_out_enabled = 1;
  1374. else
  1375. q->u.out.pci_out_enabled = 0;
  1376. if (queue_type(q) == QDIO_IQDIO_QFMT) {
  1377. if (multicast_outbound(q))
  1378. qdio_kick_outbound_q(q);
  1379. else
  1380. if ((q->irq_ptr->ssqd_desc.mmwc > 1) &&
  1381. (count > 1) &&
  1382. (count <= q->irq_ptr->ssqd_desc.mmwc)) {
  1383. /* exploit enhanced SIGA */
  1384. q->u.out.use_enh_siga = 1;
  1385. qdio_kick_outbound_q(q);
  1386. } else {
  1387. /*
  1388. * One siga-w per buffer required for unicast
  1389. * HiperSockets.
  1390. */
  1391. q->u.out.use_enh_siga = 0;
  1392. while (count--)
  1393. qdio_kick_outbound_q(q);
  1394. }
  1395. goto out;
  1396. }
  1397. if (need_siga_sync(q)) {
  1398. qdio_siga_sync_q(q);
  1399. goto out;
  1400. }
  1401. /* try to fast requeue buffers */
  1402. get_buf_state(q, prev_buf(bufnr), &state);
  1403. if (state != SLSB_CU_OUTPUT_PRIMED)
  1404. qdio_kick_outbound_q(q);
  1405. else {
  1406. QDIO_DBF_TEXT5(0, trace, "fast-req");
  1407. qdio_perf_stat_inc(&perf_stats.fast_requeue);
  1408. }
  1409. out:
  1410. /* Fixme: could wait forever if called from process context */
  1411. tasklet_schedule(&q->tasklet);
  1412. }
  1413. /**
  1414. * do_QDIO - process input or output buffers
  1415. * @cdev: associated ccw_device for the qdio subchannel
  1416. * @callflags: input or output and special flags from the program
  1417. * @q_nr: queue number
  1418. * @bufnr: buffer number
  1419. * @count: how many buffers to process
  1420. */
  1421. int do_QDIO(struct ccw_device *cdev, unsigned int callflags,
  1422. int q_nr, int bufnr, int count)
  1423. {
  1424. struct qdio_irq *irq_ptr;
  1425. #ifdef CONFIG_QDIO_DEBUG
  1426. char dbf_text[20];
  1427. sprintf(dbf_text, "doQD%4x", cdev->private->schid.sch_no);
  1428. QDIO_DBF_TEXT3(0, trace, dbf_text);
  1429. #endif /* CONFIG_QDIO_DEBUG */
  1430. if ((bufnr > QDIO_MAX_BUFFERS_PER_Q) ||
  1431. (count > QDIO_MAX_BUFFERS_PER_Q) ||
  1432. (q_nr > QDIO_MAX_QUEUES_PER_IRQ))
  1433. return -EINVAL;
  1434. if (!count)
  1435. return 0;
  1436. irq_ptr = cdev->private->qdio_data;
  1437. if (!irq_ptr)
  1438. return -ENODEV;
  1439. #ifdef CONFIG_QDIO_DEBUG
  1440. if (callflags & QDIO_FLAG_SYNC_INPUT)
  1441. QDIO_DBF_HEX3(0, trace, &irq_ptr->input_qs[q_nr],
  1442. sizeof(void *));
  1443. else
  1444. QDIO_DBF_HEX3(0, trace, &irq_ptr->output_qs[q_nr],
  1445. sizeof(void *));
  1446. sprintf(dbf_text, "flag%04x", callflags);
  1447. QDIO_DBF_TEXT3(0, trace, dbf_text);
  1448. sprintf(dbf_text, "qi%02xct%02x", bufnr, count);
  1449. QDIO_DBF_TEXT3(0, trace, dbf_text);
  1450. #endif /* CONFIG_QDIO_DEBUG */
  1451. if (irq_ptr->state != QDIO_IRQ_STATE_ACTIVE)
  1452. return -EBUSY;
  1453. if (callflags & QDIO_FLAG_SYNC_INPUT)
  1454. handle_inbound(irq_ptr->input_qs[q_nr],
  1455. callflags, bufnr, count);
  1456. else if (callflags & QDIO_FLAG_SYNC_OUTPUT)
  1457. handle_outbound(irq_ptr->output_qs[q_nr],
  1458. callflags, bufnr, count);
  1459. else {
  1460. QDIO_DBF_TEXT3(1, trace, "doQD:inv");
  1461. return -EINVAL;
  1462. }
  1463. return 0;
  1464. }
  1465. EXPORT_SYMBOL_GPL(do_QDIO);
  1466. static int __init init_QDIO(void)
  1467. {
  1468. int rc;
  1469. rc = qdio_setup_init();
  1470. if (rc)
  1471. return rc;
  1472. rc = tiqdio_allocate_memory();
  1473. if (rc)
  1474. goto out_cache;
  1475. rc = qdio_debug_init();
  1476. if (rc)
  1477. goto out_ti;
  1478. rc = qdio_setup_perf_stats();
  1479. if (rc)
  1480. goto out_debug;
  1481. rc = tiqdio_register_thinints();
  1482. if (rc)
  1483. goto out_perf;
  1484. return 0;
  1485. out_perf:
  1486. qdio_remove_perf_stats();
  1487. out_debug:
  1488. qdio_debug_exit();
  1489. out_ti:
  1490. tiqdio_free_memory();
  1491. out_cache:
  1492. qdio_setup_exit();
  1493. return rc;
  1494. }
  1495. static void __exit exit_QDIO(void)
  1496. {
  1497. tiqdio_unregister_thinints();
  1498. tiqdio_free_memory();
  1499. qdio_remove_perf_stats();
  1500. qdio_debug_exit();
  1501. qdio_setup_exit();
  1502. }
  1503. module_init(init_QDIO);
  1504. module_exit(exit_QDIO);