qdio_main.c 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881
  1. /*
  2. * Linux for s390 qdio support, buffer handling, qdio API and module support.
  3. *
  4. * Copyright IBM Corp. 2000, 2008
  5. * Author(s): Utz Bacher <utz.bacher@de.ibm.com>
  6. * Jan Glauber <jang@linux.vnet.ibm.com>
  7. * 2.6 cio integration by Cornelia Huck <cornelia.huck@de.ibm.com>
  8. */
  9. #include <linux/module.h>
  10. #include <linux/init.h>
  11. #include <linux/kernel.h>
  12. #include <linux/timer.h>
  13. #include <linux/delay.h>
  14. #include <linux/gfp.h>
  15. #include <linux/io.h>
  16. #include <linux/atomic.h>
  17. #include <asm/debug.h>
  18. #include <asm/qdio.h>
  19. #include <asm/ipl.h>
  20. #include "cio.h"
  21. #include "css.h"
  22. #include "device.h"
  23. #include "qdio.h"
  24. #include "qdio_debug.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(unsigned long schid,
  30. unsigned int out_mask, unsigned int in_mask,
  31. unsigned int fc)
  32. {
  33. register unsigned long __fc asm ("0") = fc;
  34. register unsigned long __schid asm ("1") = schid;
  35. register unsigned long out asm ("2") = out_mask;
  36. register unsigned long in asm ("3") = in_mask;
  37. int cc;
  38. asm volatile(
  39. " siga 0\n"
  40. " ipm %0\n"
  41. " srl %0,28\n"
  42. : "=d" (cc)
  43. : "d" (__fc), "d" (__schid), "d" (out), "d" (in) : "cc");
  44. return cc;
  45. }
  46. static inline int do_siga_input(unsigned long schid, unsigned int mask,
  47. unsigned int fc)
  48. {
  49. register unsigned long __fc asm ("0") = fc;
  50. register unsigned long __schid asm ("1") = schid;
  51. register unsigned long __mask asm ("2") = mask;
  52. int cc;
  53. asm volatile(
  54. " siga 0\n"
  55. " ipm %0\n"
  56. " srl %0,28\n"
  57. : "=d" (cc)
  58. : "d" (__fc), "d" (__schid), "d" (__mask) : "cc");
  59. return cc;
  60. }
  61. /**
  62. * do_siga_output - perform SIGA-w/wt function
  63. * @schid: subchannel id or in case of QEBSM the subchannel token
  64. * @mask: which output queues to process
  65. * @bb: busy bit indicator, set only if SIGA-w/wt could not access a buffer
  66. * @fc: function code to perform
  67. *
  68. * Returns condition code.
  69. * Note: For IQDC unicast queues only the highest priority queue is processed.
  70. */
  71. static inline int do_siga_output(unsigned long schid, unsigned long mask,
  72. unsigned int *bb, unsigned int fc,
  73. unsigned long aob)
  74. {
  75. register unsigned long __fc asm("0") = fc;
  76. register unsigned long __schid asm("1") = schid;
  77. register unsigned long __mask asm("2") = mask;
  78. register unsigned long __aob asm("3") = aob;
  79. int cc;
  80. asm volatile(
  81. " siga 0\n"
  82. " ipm %0\n"
  83. " srl %0,28\n"
  84. : "=d" (cc), "+d" (__fc), "+d" (__aob)
  85. : "d" (__schid), "d" (__mask)
  86. : "cc");
  87. *bb = __fc >> 31;
  88. return cc;
  89. }
  90. static inline int qdio_check_ccq(struct qdio_q *q, unsigned int ccq)
  91. {
  92. /* all done or next buffer state different */
  93. if (ccq == 0 || ccq == 32)
  94. return 0;
  95. /* no buffer processed */
  96. if (ccq == 97)
  97. return 1;
  98. /* not all buffers processed */
  99. if (ccq == 96)
  100. return 2;
  101. /* notify devices immediately */
  102. DBF_ERROR("%4x ccq:%3d", SCH_NO(q), ccq);
  103. return -EIO;
  104. }
  105. /**
  106. * qdio_do_eqbs - extract buffer states for QEBSM
  107. * @q: queue to manipulate
  108. * @state: state of the extracted buffers
  109. * @start: buffer number to start at
  110. * @count: count of buffers to examine
  111. * @auto_ack: automatically acknowledge buffers
  112. *
  113. * Returns the number of successfully extracted equal buffer states.
  114. * Stops processing if a state is different from the last buffers state.
  115. */
  116. static int qdio_do_eqbs(struct qdio_q *q, unsigned char *state,
  117. int start, int count, int auto_ack)
  118. {
  119. int rc, tmp_count = count, tmp_start = start, nr = q->nr, retried = 0;
  120. unsigned int ccq = 0;
  121. qperf_inc(q, eqbs);
  122. if (!q->is_input_q)
  123. nr += q->irq_ptr->nr_input_qs;
  124. again:
  125. ccq = do_eqbs(q->irq_ptr->sch_token, state, nr, &tmp_start, &tmp_count,
  126. auto_ack);
  127. rc = qdio_check_ccq(q, ccq);
  128. if (!rc)
  129. return count - tmp_count;
  130. if (rc == 1) {
  131. DBF_DEV_EVENT(DBF_WARN, q->irq_ptr, "EQBS again:%2d", ccq);
  132. goto again;
  133. }
  134. if (rc == 2) {
  135. qperf_inc(q, eqbs_partial);
  136. DBF_DEV_EVENT(DBF_WARN, q->irq_ptr, "EQBS part:%02x",
  137. tmp_count);
  138. /*
  139. * Retry once, if that fails bail out and process the
  140. * extracted buffers before trying again.
  141. */
  142. if (!retried++)
  143. goto again;
  144. else
  145. return count - tmp_count;
  146. }
  147. DBF_ERROR("%4x EQBS ERROR", SCH_NO(q));
  148. DBF_ERROR("%3d%3d%2d", count, tmp_count, nr);
  149. q->handler(q->irq_ptr->cdev, QDIO_ERROR_GET_BUF_STATE,
  150. q->nr, q->first_to_kick, count, q->irq_ptr->int_parm);
  151. return 0;
  152. }
  153. /**
  154. * qdio_do_sqbs - set buffer states for QEBSM
  155. * @q: queue to manipulate
  156. * @state: new state of the buffers
  157. * @start: first buffer number to change
  158. * @count: how many buffers to change
  159. *
  160. * Returns the number of successfully changed buffers.
  161. * Does retrying until the specified count of buffer states is set or an
  162. * error occurs.
  163. */
  164. static int qdio_do_sqbs(struct qdio_q *q, unsigned char state, int start,
  165. int count)
  166. {
  167. unsigned int ccq = 0;
  168. int tmp_count = count, tmp_start = start;
  169. int nr = q->nr;
  170. int rc;
  171. if (!count)
  172. return 0;
  173. qperf_inc(q, sqbs);
  174. if (!q->is_input_q)
  175. nr += q->irq_ptr->nr_input_qs;
  176. again:
  177. ccq = do_sqbs(q->irq_ptr->sch_token, state, nr, &tmp_start, &tmp_count);
  178. rc = qdio_check_ccq(q, ccq);
  179. if (!rc) {
  180. WARN_ON_ONCE(tmp_count);
  181. return count - tmp_count;
  182. }
  183. if (rc == 1 || rc == 2) {
  184. DBF_DEV_EVENT(DBF_INFO, q->irq_ptr, "SQBS again:%2d", ccq);
  185. qperf_inc(q, sqbs_partial);
  186. goto again;
  187. }
  188. DBF_ERROR("%4x SQBS ERROR", SCH_NO(q));
  189. DBF_ERROR("%3d%3d%2d", count, tmp_count, nr);
  190. q->handler(q->irq_ptr->cdev, QDIO_ERROR_SET_BUF_STATE,
  191. q->nr, q->first_to_kick, count, q->irq_ptr->int_parm);
  192. return 0;
  193. }
  194. /* returns number of examined buffers and their common state in *state */
  195. static inline int get_buf_states(struct qdio_q *q, unsigned int bufnr,
  196. unsigned char *state, unsigned int count,
  197. int auto_ack, int merge_pending)
  198. {
  199. unsigned char __state = 0;
  200. int i;
  201. if (is_qebsm(q))
  202. return qdio_do_eqbs(q, state, bufnr, count, auto_ack);
  203. for (i = 0; i < count; i++) {
  204. if (!__state) {
  205. __state = q->slsb.val[bufnr];
  206. if (merge_pending && __state == SLSB_P_OUTPUT_PENDING)
  207. __state = SLSB_P_OUTPUT_EMPTY;
  208. } else if (merge_pending) {
  209. if ((q->slsb.val[bufnr] & __state) != __state)
  210. break;
  211. } else if (q->slsb.val[bufnr] != __state)
  212. break;
  213. bufnr = next_buf(bufnr);
  214. }
  215. *state = __state;
  216. return i;
  217. }
  218. static inline int get_buf_state(struct qdio_q *q, unsigned int bufnr,
  219. unsigned char *state, int auto_ack)
  220. {
  221. return get_buf_states(q, bufnr, state, 1, auto_ack, 0);
  222. }
  223. /* wrap-around safe setting of slsb states, returns number of changed buffers */
  224. static inline int set_buf_states(struct qdio_q *q, int bufnr,
  225. unsigned char state, int count)
  226. {
  227. int i;
  228. if (is_qebsm(q))
  229. return qdio_do_sqbs(q, state, bufnr, count);
  230. for (i = 0; i < count; i++) {
  231. xchg(&q->slsb.val[bufnr], state);
  232. bufnr = next_buf(bufnr);
  233. }
  234. return count;
  235. }
  236. static inline int set_buf_state(struct qdio_q *q, int bufnr,
  237. unsigned char state)
  238. {
  239. return set_buf_states(q, bufnr, state, 1);
  240. }
  241. /* set slsb states to initial state */
  242. static void qdio_init_buf_states(struct qdio_irq *irq_ptr)
  243. {
  244. struct qdio_q *q;
  245. int i;
  246. for_each_input_queue(irq_ptr, q, i)
  247. set_buf_states(q, 0, SLSB_P_INPUT_NOT_INIT,
  248. QDIO_MAX_BUFFERS_PER_Q);
  249. for_each_output_queue(irq_ptr, q, i)
  250. set_buf_states(q, 0, SLSB_P_OUTPUT_NOT_INIT,
  251. QDIO_MAX_BUFFERS_PER_Q);
  252. }
  253. static inline int qdio_siga_sync(struct qdio_q *q, unsigned int output,
  254. unsigned int input)
  255. {
  256. unsigned long schid = *((u32 *) &q->irq_ptr->schid);
  257. unsigned int fc = QDIO_SIGA_SYNC;
  258. int cc;
  259. DBF_DEV_EVENT(DBF_INFO, q->irq_ptr, "siga-s:%1d", q->nr);
  260. qperf_inc(q, siga_sync);
  261. if (is_qebsm(q)) {
  262. schid = q->irq_ptr->sch_token;
  263. fc |= QDIO_SIGA_QEBSM_FLAG;
  264. }
  265. cc = do_siga_sync(schid, output, input, fc);
  266. if (unlikely(cc))
  267. DBF_ERROR("%4x SIGA-S:%2d", SCH_NO(q), cc);
  268. return (cc) ? -EIO : 0;
  269. }
  270. static inline int qdio_siga_sync_q(struct qdio_q *q)
  271. {
  272. if (q->is_input_q)
  273. return qdio_siga_sync(q, 0, q->mask);
  274. else
  275. return qdio_siga_sync(q, q->mask, 0);
  276. }
  277. static int qdio_siga_output(struct qdio_q *q, unsigned int *busy_bit,
  278. unsigned long aob)
  279. {
  280. unsigned long schid = *((u32 *) &q->irq_ptr->schid);
  281. unsigned int fc = QDIO_SIGA_WRITE;
  282. u64 start_time = 0;
  283. int retries = 0, cc;
  284. unsigned long laob = 0;
  285. if (q->u.out.use_cq && aob != 0) {
  286. fc = QDIO_SIGA_WRITEQ;
  287. laob = aob;
  288. }
  289. if (is_qebsm(q)) {
  290. schid = q->irq_ptr->sch_token;
  291. fc |= QDIO_SIGA_QEBSM_FLAG;
  292. }
  293. again:
  294. WARN_ON_ONCE((aob && queue_type(q) != QDIO_IQDIO_QFMT) ||
  295. (aob && fc != QDIO_SIGA_WRITEQ));
  296. cc = do_siga_output(schid, q->mask, busy_bit, fc, laob);
  297. /* hipersocket busy condition */
  298. if (unlikely(*busy_bit)) {
  299. retries++;
  300. if (!start_time) {
  301. start_time = get_tod_clock_fast();
  302. goto again;
  303. }
  304. if (get_tod_clock_fast() - start_time < QDIO_BUSY_BIT_PATIENCE)
  305. goto again;
  306. }
  307. if (retries) {
  308. DBF_DEV_EVENT(DBF_WARN, q->irq_ptr,
  309. "%4x cc2 BB1:%1d", SCH_NO(q), q->nr);
  310. DBF_DEV_EVENT(DBF_WARN, q->irq_ptr, "count:%u", retries);
  311. }
  312. return cc;
  313. }
  314. static inline int qdio_siga_input(struct qdio_q *q)
  315. {
  316. unsigned long schid = *((u32 *) &q->irq_ptr->schid);
  317. unsigned int fc = QDIO_SIGA_READ;
  318. int cc;
  319. DBF_DEV_EVENT(DBF_INFO, q->irq_ptr, "siga-r:%1d", q->nr);
  320. qperf_inc(q, siga_read);
  321. if (is_qebsm(q)) {
  322. schid = q->irq_ptr->sch_token;
  323. fc |= QDIO_SIGA_QEBSM_FLAG;
  324. }
  325. cc = do_siga_input(schid, q->mask, fc);
  326. if (unlikely(cc))
  327. DBF_ERROR("%4x SIGA-R:%2d", SCH_NO(q), cc);
  328. return (cc) ? -EIO : 0;
  329. }
  330. #define qdio_siga_sync_out(q) qdio_siga_sync(q, ~0U, 0)
  331. #define qdio_siga_sync_all(q) qdio_siga_sync(q, ~0U, ~0U)
  332. static inline void qdio_sync_queues(struct qdio_q *q)
  333. {
  334. /* PCI capable outbound queues will also be scanned so sync them too */
  335. if (pci_out_supported(q))
  336. qdio_siga_sync_all(q);
  337. else
  338. qdio_siga_sync_q(q);
  339. }
  340. int debug_get_buf_state(struct qdio_q *q, unsigned int bufnr,
  341. unsigned char *state)
  342. {
  343. if (need_siga_sync(q))
  344. qdio_siga_sync_q(q);
  345. return get_buf_states(q, bufnr, state, 1, 0, 0);
  346. }
  347. static inline void qdio_stop_polling(struct qdio_q *q)
  348. {
  349. if (!q->u.in.polling)
  350. return;
  351. q->u.in.polling = 0;
  352. qperf_inc(q, stop_polling);
  353. /* show the card that we are not polling anymore */
  354. if (is_qebsm(q)) {
  355. set_buf_states(q, q->u.in.ack_start, SLSB_P_INPUT_NOT_INIT,
  356. q->u.in.ack_count);
  357. q->u.in.ack_count = 0;
  358. } else
  359. set_buf_state(q, q->u.in.ack_start, SLSB_P_INPUT_NOT_INIT);
  360. }
  361. static inline void account_sbals(struct qdio_q *q, unsigned int count)
  362. {
  363. int pos;
  364. q->q_stats.nr_sbal_total += count;
  365. if (count == QDIO_MAX_BUFFERS_MASK) {
  366. q->q_stats.nr_sbals[7]++;
  367. return;
  368. }
  369. pos = ilog2(count);
  370. q->q_stats.nr_sbals[pos]++;
  371. }
  372. static void process_buffer_error(struct qdio_q *q, int count)
  373. {
  374. unsigned char state = (q->is_input_q) ? SLSB_P_INPUT_NOT_INIT :
  375. SLSB_P_OUTPUT_NOT_INIT;
  376. q->qdio_error = QDIO_ERROR_SLSB_STATE;
  377. /* special handling for no target buffer empty */
  378. if ((!q->is_input_q &&
  379. (q->sbal[q->first_to_check]->element[15].sflags) == 0x10)) {
  380. qperf_inc(q, target_full);
  381. DBF_DEV_EVENT(DBF_INFO, q->irq_ptr, "OUTFULL FTC:%02x",
  382. q->first_to_check);
  383. goto set;
  384. }
  385. DBF_ERROR("%4x BUF ERROR", SCH_NO(q));
  386. DBF_ERROR((q->is_input_q) ? "IN:%2d" : "OUT:%2d", q->nr);
  387. DBF_ERROR("FTC:%3d C:%3d", q->first_to_check, count);
  388. DBF_ERROR("F14:%2x F15:%2x",
  389. q->sbal[q->first_to_check]->element[14].sflags,
  390. q->sbal[q->first_to_check]->element[15].sflags);
  391. set:
  392. /*
  393. * Interrupts may be avoided as long as the error is present
  394. * so change the buffer state immediately to avoid starvation.
  395. */
  396. set_buf_states(q, q->first_to_check, state, count);
  397. }
  398. static inline void inbound_primed(struct qdio_q *q, int count)
  399. {
  400. int new;
  401. DBF_DEV_EVENT(DBF_INFO, q->irq_ptr, "in prim: %02x", count);
  402. /* for QEBSM the ACK was already set by EQBS */
  403. if (is_qebsm(q)) {
  404. if (!q->u.in.polling) {
  405. q->u.in.polling = 1;
  406. q->u.in.ack_count = count;
  407. q->u.in.ack_start = q->first_to_check;
  408. return;
  409. }
  410. /* delete the previous ACK's */
  411. set_buf_states(q, q->u.in.ack_start, SLSB_P_INPUT_NOT_INIT,
  412. q->u.in.ack_count);
  413. q->u.in.ack_count = count;
  414. q->u.in.ack_start = q->first_to_check;
  415. return;
  416. }
  417. /*
  418. * ACK the newest buffer. The ACK will be removed in qdio_stop_polling
  419. * or by the next inbound run.
  420. */
  421. new = add_buf(q->first_to_check, count - 1);
  422. if (q->u.in.polling) {
  423. /* reset the previous ACK but first set the new one */
  424. set_buf_state(q, new, SLSB_P_INPUT_ACK);
  425. set_buf_state(q, q->u.in.ack_start, SLSB_P_INPUT_NOT_INIT);
  426. } else {
  427. q->u.in.polling = 1;
  428. set_buf_state(q, new, SLSB_P_INPUT_ACK);
  429. }
  430. q->u.in.ack_start = new;
  431. count--;
  432. if (!count)
  433. return;
  434. /* need to change ALL buffers to get more interrupts */
  435. set_buf_states(q, q->first_to_check, SLSB_P_INPUT_NOT_INIT, count);
  436. }
  437. static int get_inbound_buffer_frontier(struct qdio_q *q)
  438. {
  439. int count, stop;
  440. unsigned char state = 0;
  441. q->timestamp = get_tod_clock_fast();
  442. /*
  443. * Don't check 128 buffers, as otherwise qdio_inbound_q_moved
  444. * would return 0.
  445. */
  446. count = min(atomic_read(&q->nr_buf_used), QDIO_MAX_BUFFERS_MASK);
  447. stop = add_buf(q->first_to_check, count);
  448. if (q->first_to_check == stop)
  449. goto out;
  450. /*
  451. * No siga sync here, as a PCI or we after a thin interrupt
  452. * already sync'ed the queues.
  453. */
  454. count = get_buf_states(q, q->first_to_check, &state, count, 1, 0);
  455. if (!count)
  456. goto out;
  457. switch (state) {
  458. case SLSB_P_INPUT_PRIMED:
  459. inbound_primed(q, count);
  460. q->first_to_check = add_buf(q->first_to_check, count);
  461. if (atomic_sub_return(count, &q->nr_buf_used) == 0)
  462. qperf_inc(q, inbound_queue_full);
  463. if (q->irq_ptr->perf_stat_enabled)
  464. account_sbals(q, count);
  465. break;
  466. case SLSB_P_INPUT_ERROR:
  467. process_buffer_error(q, count);
  468. q->first_to_check = add_buf(q->first_to_check, count);
  469. atomic_sub(count, &q->nr_buf_used);
  470. if (q->irq_ptr->perf_stat_enabled)
  471. account_sbals_error(q, count);
  472. break;
  473. case SLSB_CU_INPUT_EMPTY:
  474. case SLSB_P_INPUT_NOT_INIT:
  475. case SLSB_P_INPUT_ACK:
  476. if (q->irq_ptr->perf_stat_enabled)
  477. q->q_stats.nr_sbal_nop++;
  478. DBF_DEV_EVENT(DBF_INFO, q->irq_ptr, "in nop");
  479. break;
  480. default:
  481. WARN_ON_ONCE(1);
  482. }
  483. out:
  484. return q->first_to_check;
  485. }
  486. static int qdio_inbound_q_moved(struct qdio_q *q)
  487. {
  488. int bufnr;
  489. bufnr = get_inbound_buffer_frontier(q);
  490. if (bufnr != q->last_move) {
  491. q->last_move = bufnr;
  492. if (!is_thinint_irq(q->irq_ptr) && MACHINE_IS_LPAR)
  493. q->u.in.timestamp = get_tod_clock();
  494. return 1;
  495. } else
  496. return 0;
  497. }
  498. static inline int qdio_inbound_q_done(struct qdio_q *q)
  499. {
  500. unsigned char state = 0;
  501. if (!atomic_read(&q->nr_buf_used))
  502. return 1;
  503. if (need_siga_sync(q))
  504. qdio_siga_sync_q(q);
  505. get_buf_state(q, q->first_to_check, &state, 0);
  506. if (state == SLSB_P_INPUT_PRIMED || state == SLSB_P_INPUT_ERROR)
  507. /* more work coming */
  508. return 0;
  509. if (is_thinint_irq(q->irq_ptr))
  510. return 1;
  511. /* don't poll under z/VM */
  512. if (MACHINE_IS_VM)
  513. return 1;
  514. /*
  515. * At this point we know, that inbound first_to_check
  516. * has (probably) not moved (see qdio_inbound_processing).
  517. */
  518. if (get_tod_clock_fast() > q->u.in.timestamp + QDIO_INPUT_THRESHOLD) {
  519. DBF_DEV_EVENT(DBF_INFO, q->irq_ptr, "in done:%02x",
  520. q->first_to_check);
  521. return 1;
  522. } else
  523. return 0;
  524. }
  525. static inline int contains_aobs(struct qdio_q *q)
  526. {
  527. return !q->is_input_q && q->u.out.use_cq;
  528. }
  529. static inline void qdio_handle_aobs(struct qdio_q *q, int start, int count)
  530. {
  531. unsigned char state = 0;
  532. int j, b = start;
  533. if (!contains_aobs(q))
  534. return;
  535. for (j = 0; j < count; ++j) {
  536. get_buf_state(q, b, &state, 0);
  537. if (state == SLSB_P_OUTPUT_PENDING) {
  538. struct qaob *aob = q->u.out.aobs[b];
  539. if (aob == NULL)
  540. continue;
  541. q->u.out.sbal_state[b].flags |=
  542. QDIO_OUTBUF_STATE_FLAG_PENDING;
  543. q->u.out.aobs[b] = NULL;
  544. } else if (state == SLSB_P_OUTPUT_EMPTY) {
  545. q->u.out.sbal_state[b].aob = NULL;
  546. }
  547. b = next_buf(b);
  548. }
  549. }
  550. static inline unsigned long qdio_aob_for_buffer(struct qdio_output_q *q,
  551. int bufnr)
  552. {
  553. unsigned long phys_aob = 0;
  554. if (!q->use_cq)
  555. goto out;
  556. if (!q->aobs[bufnr]) {
  557. struct qaob *aob = qdio_allocate_aob();
  558. q->aobs[bufnr] = aob;
  559. }
  560. if (q->aobs[bufnr]) {
  561. q->sbal_state[bufnr].flags = QDIO_OUTBUF_STATE_FLAG_NONE;
  562. q->sbal_state[bufnr].aob = q->aobs[bufnr];
  563. q->aobs[bufnr]->user1 = (u64) q->sbal_state[bufnr].user;
  564. phys_aob = virt_to_phys(q->aobs[bufnr]);
  565. WARN_ON_ONCE(phys_aob & 0xFF);
  566. }
  567. out:
  568. return phys_aob;
  569. }
  570. static void qdio_kick_handler(struct qdio_q *q)
  571. {
  572. int start = q->first_to_kick;
  573. int end = q->first_to_check;
  574. int count;
  575. if (unlikely(q->irq_ptr->state != QDIO_IRQ_STATE_ACTIVE))
  576. return;
  577. count = sub_buf(end, start);
  578. if (q->is_input_q) {
  579. qperf_inc(q, inbound_handler);
  580. DBF_DEV_EVENT(DBF_INFO, q->irq_ptr, "kih s:%02x c:%02x", start, count);
  581. } else {
  582. qperf_inc(q, outbound_handler);
  583. DBF_DEV_EVENT(DBF_INFO, q->irq_ptr, "koh: s:%02x c:%02x",
  584. start, count);
  585. }
  586. qdio_handle_aobs(q, start, count);
  587. q->handler(q->irq_ptr->cdev, q->qdio_error, q->nr, start, count,
  588. q->irq_ptr->int_parm);
  589. /* for the next time */
  590. q->first_to_kick = end;
  591. q->qdio_error = 0;
  592. }
  593. static void __qdio_inbound_processing(struct qdio_q *q)
  594. {
  595. qperf_inc(q, tasklet_inbound);
  596. if (!qdio_inbound_q_moved(q))
  597. return;
  598. qdio_kick_handler(q);
  599. if (!qdio_inbound_q_done(q)) {
  600. /* means poll time is not yet over */
  601. qperf_inc(q, tasklet_inbound_resched);
  602. if (likely(q->irq_ptr->state != QDIO_IRQ_STATE_STOPPED)) {
  603. tasklet_schedule(&q->tasklet);
  604. return;
  605. }
  606. }
  607. qdio_stop_polling(q);
  608. /*
  609. * We need to check again to not lose initiative after
  610. * resetting the ACK state.
  611. */
  612. if (!qdio_inbound_q_done(q)) {
  613. qperf_inc(q, tasklet_inbound_resched2);
  614. if (likely(q->irq_ptr->state != QDIO_IRQ_STATE_STOPPED))
  615. tasklet_schedule(&q->tasklet);
  616. }
  617. }
  618. void qdio_inbound_processing(unsigned long data)
  619. {
  620. struct qdio_q *q = (struct qdio_q *)data;
  621. __qdio_inbound_processing(q);
  622. }
  623. static int get_outbound_buffer_frontier(struct qdio_q *q)
  624. {
  625. int count, stop;
  626. unsigned char state = 0;
  627. q->timestamp = get_tod_clock_fast();
  628. if (need_siga_sync(q))
  629. if (((queue_type(q) != QDIO_IQDIO_QFMT) &&
  630. !pci_out_supported(q)) ||
  631. (queue_type(q) == QDIO_IQDIO_QFMT &&
  632. multicast_outbound(q)))
  633. qdio_siga_sync_q(q);
  634. /*
  635. * Don't check 128 buffers, as otherwise qdio_inbound_q_moved
  636. * would return 0.
  637. */
  638. count = min(atomic_read(&q->nr_buf_used), QDIO_MAX_BUFFERS_MASK);
  639. stop = add_buf(q->first_to_check, count);
  640. if (q->first_to_check == stop)
  641. goto out;
  642. count = get_buf_states(q, q->first_to_check, &state, count, 0, 1);
  643. if (!count)
  644. goto out;
  645. switch (state) {
  646. case SLSB_P_OUTPUT_EMPTY:
  647. /* the adapter got it */
  648. DBF_DEV_EVENT(DBF_INFO, q->irq_ptr,
  649. "out empty:%1d %02x", q->nr, count);
  650. atomic_sub(count, &q->nr_buf_used);
  651. q->first_to_check = add_buf(q->first_to_check, count);
  652. if (q->irq_ptr->perf_stat_enabled)
  653. account_sbals(q, count);
  654. break;
  655. case SLSB_P_OUTPUT_ERROR:
  656. process_buffer_error(q, count);
  657. q->first_to_check = add_buf(q->first_to_check, count);
  658. atomic_sub(count, &q->nr_buf_used);
  659. if (q->irq_ptr->perf_stat_enabled)
  660. account_sbals_error(q, count);
  661. break;
  662. case SLSB_CU_OUTPUT_PRIMED:
  663. /* the adapter has not fetched the output yet */
  664. if (q->irq_ptr->perf_stat_enabled)
  665. q->q_stats.nr_sbal_nop++;
  666. DBF_DEV_EVENT(DBF_INFO, q->irq_ptr, "out primed:%1d",
  667. q->nr);
  668. break;
  669. case SLSB_P_OUTPUT_NOT_INIT:
  670. case SLSB_P_OUTPUT_HALTED:
  671. break;
  672. default:
  673. WARN_ON_ONCE(1);
  674. }
  675. out:
  676. return q->first_to_check;
  677. }
  678. /* all buffers processed? */
  679. static inline int qdio_outbound_q_done(struct qdio_q *q)
  680. {
  681. return atomic_read(&q->nr_buf_used) == 0;
  682. }
  683. static inline int qdio_outbound_q_moved(struct qdio_q *q)
  684. {
  685. int bufnr;
  686. bufnr = get_outbound_buffer_frontier(q);
  687. if (bufnr != q->last_move) {
  688. q->last_move = bufnr;
  689. DBF_DEV_EVENT(DBF_INFO, q->irq_ptr, "out moved:%1d", q->nr);
  690. return 1;
  691. } else
  692. return 0;
  693. }
  694. static int qdio_kick_outbound_q(struct qdio_q *q, unsigned long aob)
  695. {
  696. int retries = 0, cc;
  697. unsigned int busy_bit;
  698. if (!need_siga_out(q))
  699. return 0;
  700. DBF_DEV_EVENT(DBF_INFO, q->irq_ptr, "siga-w:%1d", q->nr);
  701. retry:
  702. qperf_inc(q, siga_write);
  703. cc = qdio_siga_output(q, &busy_bit, aob);
  704. switch (cc) {
  705. case 0:
  706. break;
  707. case 2:
  708. if (busy_bit) {
  709. while (++retries < QDIO_BUSY_BIT_RETRIES) {
  710. mdelay(QDIO_BUSY_BIT_RETRY_DELAY);
  711. goto retry;
  712. }
  713. DBF_ERROR("%4x cc2 BBC:%1d", SCH_NO(q), q->nr);
  714. cc = -EBUSY;
  715. } else {
  716. DBF_DEV_EVENT(DBF_INFO, q->irq_ptr, "siga-w cc2:%1d", q->nr);
  717. cc = -ENOBUFS;
  718. }
  719. break;
  720. case 1:
  721. case 3:
  722. DBF_ERROR("%4x SIGA-W:%1d", SCH_NO(q), cc);
  723. cc = -EIO;
  724. break;
  725. }
  726. if (retries) {
  727. DBF_ERROR("%4x cc2 BB2:%1d", SCH_NO(q), q->nr);
  728. DBF_ERROR("count:%u", retries);
  729. }
  730. return cc;
  731. }
  732. static void __qdio_outbound_processing(struct qdio_q *q)
  733. {
  734. qperf_inc(q, tasklet_outbound);
  735. WARN_ON_ONCE(atomic_read(&q->nr_buf_used) < 0);
  736. if (qdio_outbound_q_moved(q))
  737. qdio_kick_handler(q);
  738. if (queue_type(q) == QDIO_ZFCP_QFMT)
  739. if (!pci_out_supported(q) && !qdio_outbound_q_done(q))
  740. goto sched;
  741. if (q->u.out.pci_out_enabled)
  742. return;
  743. /*
  744. * Now we know that queue type is either qeth without pci enabled
  745. * or HiperSockets. Make sure buffer switch from PRIMED to EMPTY
  746. * is noticed and outbound_handler is called after some time.
  747. */
  748. if (qdio_outbound_q_done(q))
  749. del_timer(&q->u.out.timer);
  750. else
  751. if (!timer_pending(&q->u.out.timer))
  752. mod_timer(&q->u.out.timer, jiffies + 10 * HZ);
  753. return;
  754. sched:
  755. if (unlikely(q->irq_ptr->state == QDIO_IRQ_STATE_STOPPED))
  756. return;
  757. tasklet_schedule(&q->tasklet);
  758. }
  759. /* outbound tasklet */
  760. void qdio_outbound_processing(unsigned long data)
  761. {
  762. struct qdio_q *q = (struct qdio_q *)data;
  763. __qdio_outbound_processing(q);
  764. }
  765. void qdio_outbound_timer(unsigned long data)
  766. {
  767. struct qdio_q *q = (struct qdio_q *)data;
  768. if (unlikely(q->irq_ptr->state == QDIO_IRQ_STATE_STOPPED))
  769. return;
  770. tasklet_schedule(&q->tasklet);
  771. }
  772. static inline void qdio_check_outbound_after_thinint(struct qdio_q *q)
  773. {
  774. struct qdio_q *out;
  775. int i;
  776. if (!pci_out_supported(q))
  777. return;
  778. for_each_output_queue(q->irq_ptr, out, i)
  779. if (!qdio_outbound_q_done(out))
  780. tasklet_schedule(&out->tasklet);
  781. }
  782. static void __tiqdio_inbound_processing(struct qdio_q *q)
  783. {
  784. qperf_inc(q, tasklet_inbound);
  785. if (need_siga_sync(q) && need_siga_sync_after_ai(q))
  786. qdio_sync_queues(q);
  787. /*
  788. * The interrupt could be caused by a PCI request. Check the
  789. * PCI capable outbound queues.
  790. */
  791. qdio_check_outbound_after_thinint(q);
  792. if (!qdio_inbound_q_moved(q))
  793. return;
  794. qdio_kick_handler(q);
  795. if (!qdio_inbound_q_done(q)) {
  796. qperf_inc(q, tasklet_inbound_resched);
  797. if (likely(q->irq_ptr->state != QDIO_IRQ_STATE_STOPPED)) {
  798. tasklet_schedule(&q->tasklet);
  799. return;
  800. }
  801. }
  802. qdio_stop_polling(q);
  803. /*
  804. * We need to check again to not lose initiative after
  805. * resetting the ACK state.
  806. */
  807. if (!qdio_inbound_q_done(q)) {
  808. qperf_inc(q, tasklet_inbound_resched2);
  809. if (likely(q->irq_ptr->state != QDIO_IRQ_STATE_STOPPED))
  810. tasklet_schedule(&q->tasklet);
  811. }
  812. }
  813. void tiqdio_inbound_processing(unsigned long data)
  814. {
  815. struct qdio_q *q = (struct qdio_q *)data;
  816. __tiqdio_inbound_processing(q);
  817. }
  818. static inline void qdio_set_state(struct qdio_irq *irq_ptr,
  819. enum qdio_irq_states state)
  820. {
  821. DBF_DEV_EVENT(DBF_INFO, irq_ptr, "newstate: %1d", state);
  822. irq_ptr->state = state;
  823. mb();
  824. }
  825. static void qdio_irq_check_sense(struct qdio_irq *irq_ptr, struct irb *irb)
  826. {
  827. if (irb->esw.esw0.erw.cons) {
  828. DBF_ERROR("%4x sense:", irq_ptr->schid.sch_no);
  829. DBF_ERROR_HEX(irb, 64);
  830. DBF_ERROR_HEX(irb->ecw, 64);
  831. }
  832. }
  833. /* PCI interrupt handler */
  834. static void qdio_int_handler_pci(struct qdio_irq *irq_ptr)
  835. {
  836. int i;
  837. struct qdio_q *q;
  838. if (unlikely(irq_ptr->state == QDIO_IRQ_STATE_STOPPED))
  839. return;
  840. for_each_input_queue(irq_ptr, q, i) {
  841. if (q->u.in.queue_start_poll) {
  842. /* skip if polling is enabled or already in work */
  843. if (test_and_set_bit(QDIO_QUEUE_IRQS_DISABLED,
  844. &q->u.in.queue_irq_state)) {
  845. qperf_inc(q, int_discarded);
  846. continue;
  847. }
  848. q->u.in.queue_start_poll(q->irq_ptr->cdev, q->nr,
  849. q->irq_ptr->int_parm);
  850. } else {
  851. tasklet_schedule(&q->tasklet);
  852. }
  853. }
  854. if (!(irq_ptr->qib.ac & QIB_AC_OUTBOUND_PCI_SUPPORTED))
  855. return;
  856. for_each_output_queue(irq_ptr, q, i) {
  857. if (qdio_outbound_q_done(q))
  858. continue;
  859. if (need_siga_sync(q) && need_siga_sync_out_after_pci(q))
  860. qdio_siga_sync_q(q);
  861. tasklet_schedule(&q->tasklet);
  862. }
  863. }
  864. static void qdio_handle_activate_check(struct ccw_device *cdev,
  865. unsigned long intparm, int cstat, int dstat)
  866. {
  867. struct qdio_irq *irq_ptr = cdev->private->qdio_data;
  868. struct qdio_q *q;
  869. int count;
  870. DBF_ERROR("%4x ACT CHECK", irq_ptr->schid.sch_no);
  871. DBF_ERROR("intp :%lx", intparm);
  872. DBF_ERROR("ds: %2x cs:%2x", dstat, cstat);
  873. if (irq_ptr->nr_input_qs) {
  874. q = irq_ptr->input_qs[0];
  875. } else if (irq_ptr->nr_output_qs) {
  876. q = irq_ptr->output_qs[0];
  877. } else {
  878. dump_stack();
  879. goto no_handler;
  880. }
  881. count = sub_buf(q->first_to_check, q->first_to_kick);
  882. q->handler(q->irq_ptr->cdev, QDIO_ERROR_ACTIVATE,
  883. q->nr, q->first_to_kick, count, irq_ptr->int_parm);
  884. no_handler:
  885. qdio_set_state(irq_ptr, QDIO_IRQ_STATE_STOPPED);
  886. /*
  887. * In case of z/VM LGR (Live Guest Migration) QDIO recovery will happen.
  888. * Therefore we call the LGR detection function here.
  889. */
  890. lgr_info_log();
  891. }
  892. static void qdio_establish_handle_irq(struct ccw_device *cdev, int cstat,
  893. int dstat)
  894. {
  895. struct qdio_irq *irq_ptr = cdev->private->qdio_data;
  896. DBF_DEV_EVENT(DBF_INFO, irq_ptr, "qest irq");
  897. if (cstat)
  898. goto error;
  899. if (dstat & ~(DEV_STAT_DEV_END | DEV_STAT_CHN_END))
  900. goto error;
  901. if (!(dstat & DEV_STAT_DEV_END))
  902. goto error;
  903. qdio_set_state(irq_ptr, QDIO_IRQ_STATE_ESTABLISHED);
  904. return;
  905. error:
  906. DBF_ERROR("%4x EQ:error", irq_ptr->schid.sch_no);
  907. DBF_ERROR("ds: %2x cs:%2x", dstat, cstat);
  908. qdio_set_state(irq_ptr, QDIO_IRQ_STATE_ERR);
  909. }
  910. /* qdio interrupt handler */
  911. void qdio_int_handler(struct ccw_device *cdev, unsigned long intparm,
  912. struct irb *irb)
  913. {
  914. struct qdio_irq *irq_ptr = cdev->private->qdio_data;
  915. int cstat, dstat;
  916. if (!intparm || !irq_ptr) {
  917. DBF_ERROR("qint:%4x", cdev->private->schid.sch_no);
  918. return;
  919. }
  920. if (irq_ptr->perf_stat_enabled)
  921. irq_ptr->perf_stat.qdio_int++;
  922. if (IS_ERR(irb)) {
  923. DBF_ERROR("%4x IO error", irq_ptr->schid.sch_no);
  924. qdio_set_state(irq_ptr, QDIO_IRQ_STATE_ERR);
  925. wake_up(&cdev->private->wait_q);
  926. return;
  927. }
  928. qdio_irq_check_sense(irq_ptr, irb);
  929. cstat = irb->scsw.cmd.cstat;
  930. dstat = irb->scsw.cmd.dstat;
  931. switch (irq_ptr->state) {
  932. case QDIO_IRQ_STATE_INACTIVE:
  933. qdio_establish_handle_irq(cdev, cstat, dstat);
  934. break;
  935. case QDIO_IRQ_STATE_CLEANUP:
  936. qdio_set_state(irq_ptr, QDIO_IRQ_STATE_INACTIVE);
  937. break;
  938. case QDIO_IRQ_STATE_ESTABLISHED:
  939. case QDIO_IRQ_STATE_ACTIVE:
  940. if (cstat & SCHN_STAT_PCI) {
  941. qdio_int_handler_pci(irq_ptr);
  942. return;
  943. }
  944. if (cstat || dstat)
  945. qdio_handle_activate_check(cdev, intparm, cstat,
  946. dstat);
  947. break;
  948. case QDIO_IRQ_STATE_STOPPED:
  949. break;
  950. default:
  951. WARN_ON_ONCE(1);
  952. }
  953. wake_up(&cdev->private->wait_q);
  954. }
  955. /**
  956. * qdio_get_ssqd_desc - get qdio subchannel description
  957. * @cdev: ccw device to get description for
  958. * @data: where to store the ssqd
  959. *
  960. * Returns 0 or an error code. The results of the chsc are stored in the
  961. * specified structure.
  962. */
  963. int qdio_get_ssqd_desc(struct ccw_device *cdev,
  964. struct qdio_ssqd_desc *data)
  965. {
  966. if (!cdev || !cdev->private)
  967. return -EINVAL;
  968. DBF_EVENT("get ssqd:%4x", cdev->private->schid.sch_no);
  969. return qdio_setup_get_ssqd(NULL, &cdev->private->schid, data);
  970. }
  971. EXPORT_SYMBOL_GPL(qdio_get_ssqd_desc);
  972. static void qdio_shutdown_queues(struct ccw_device *cdev)
  973. {
  974. struct qdio_irq *irq_ptr = cdev->private->qdio_data;
  975. struct qdio_q *q;
  976. int i;
  977. for_each_input_queue(irq_ptr, q, i)
  978. tasklet_kill(&q->tasklet);
  979. for_each_output_queue(irq_ptr, q, i) {
  980. del_timer(&q->u.out.timer);
  981. tasklet_kill(&q->tasklet);
  982. }
  983. }
  984. /**
  985. * qdio_shutdown - shut down a qdio subchannel
  986. * @cdev: associated ccw device
  987. * @how: use halt or clear to shutdown
  988. */
  989. int qdio_shutdown(struct ccw_device *cdev, int how)
  990. {
  991. struct qdio_irq *irq_ptr = cdev->private->qdio_data;
  992. int rc;
  993. unsigned long flags;
  994. if (!irq_ptr)
  995. return -ENODEV;
  996. WARN_ON_ONCE(irqs_disabled());
  997. DBF_EVENT("qshutdown:%4x", cdev->private->schid.sch_no);
  998. mutex_lock(&irq_ptr->setup_mutex);
  999. /*
  1000. * Subchannel was already shot down. We cannot prevent being called
  1001. * twice since cio may trigger a shutdown asynchronously.
  1002. */
  1003. if (irq_ptr->state == QDIO_IRQ_STATE_INACTIVE) {
  1004. mutex_unlock(&irq_ptr->setup_mutex);
  1005. return 0;
  1006. }
  1007. /*
  1008. * Indicate that the device is going down. Scheduling the queue
  1009. * tasklets is forbidden from here on.
  1010. */
  1011. qdio_set_state(irq_ptr, QDIO_IRQ_STATE_STOPPED);
  1012. tiqdio_remove_input_queues(irq_ptr);
  1013. qdio_shutdown_queues(cdev);
  1014. qdio_shutdown_debug_entries(irq_ptr);
  1015. /* cleanup subchannel */
  1016. spin_lock_irqsave(get_ccwdev_lock(cdev), flags);
  1017. if (how & QDIO_FLAG_CLEANUP_USING_CLEAR)
  1018. rc = ccw_device_clear(cdev, QDIO_DOING_CLEANUP);
  1019. else
  1020. /* default behaviour is halt */
  1021. rc = ccw_device_halt(cdev, QDIO_DOING_CLEANUP);
  1022. if (rc) {
  1023. DBF_ERROR("%4x SHUTD ERR", irq_ptr->schid.sch_no);
  1024. DBF_ERROR("rc:%4d", rc);
  1025. goto no_cleanup;
  1026. }
  1027. qdio_set_state(irq_ptr, QDIO_IRQ_STATE_CLEANUP);
  1028. spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags);
  1029. wait_event_interruptible_timeout(cdev->private->wait_q,
  1030. irq_ptr->state == QDIO_IRQ_STATE_INACTIVE ||
  1031. irq_ptr->state == QDIO_IRQ_STATE_ERR,
  1032. 10 * HZ);
  1033. spin_lock_irqsave(get_ccwdev_lock(cdev), flags);
  1034. no_cleanup:
  1035. qdio_shutdown_thinint(irq_ptr);
  1036. /* restore interrupt handler */
  1037. if ((void *)cdev->handler == (void *)qdio_int_handler)
  1038. cdev->handler = irq_ptr->orig_handler;
  1039. spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags);
  1040. qdio_set_state(irq_ptr, QDIO_IRQ_STATE_INACTIVE);
  1041. mutex_unlock(&irq_ptr->setup_mutex);
  1042. if (rc)
  1043. return rc;
  1044. return 0;
  1045. }
  1046. EXPORT_SYMBOL_GPL(qdio_shutdown);
  1047. /**
  1048. * qdio_free - free data structures for a qdio subchannel
  1049. * @cdev: associated ccw device
  1050. */
  1051. int qdio_free(struct ccw_device *cdev)
  1052. {
  1053. struct qdio_irq *irq_ptr = cdev->private->qdio_data;
  1054. if (!irq_ptr)
  1055. return -ENODEV;
  1056. DBF_EVENT("qfree:%4x", cdev->private->schid.sch_no);
  1057. DBF_DEV_EVENT(DBF_ERR, irq_ptr, "dbf abandoned");
  1058. mutex_lock(&irq_ptr->setup_mutex);
  1059. irq_ptr->debug_area = NULL;
  1060. cdev->private->qdio_data = NULL;
  1061. mutex_unlock(&irq_ptr->setup_mutex);
  1062. qdio_release_memory(irq_ptr);
  1063. return 0;
  1064. }
  1065. EXPORT_SYMBOL_GPL(qdio_free);
  1066. /**
  1067. * qdio_allocate - allocate qdio queues and associated data
  1068. * @init_data: initialization data
  1069. */
  1070. int qdio_allocate(struct qdio_initialize *init_data)
  1071. {
  1072. struct qdio_irq *irq_ptr;
  1073. DBF_EVENT("qallocate:%4x", init_data->cdev->private->schid.sch_no);
  1074. if ((init_data->no_input_qs && !init_data->input_handler) ||
  1075. (init_data->no_output_qs && !init_data->output_handler))
  1076. return -EINVAL;
  1077. if ((init_data->no_input_qs > QDIO_MAX_QUEUES_PER_IRQ) ||
  1078. (init_data->no_output_qs > QDIO_MAX_QUEUES_PER_IRQ))
  1079. return -EINVAL;
  1080. if ((!init_data->input_sbal_addr_array) ||
  1081. (!init_data->output_sbal_addr_array))
  1082. return -EINVAL;
  1083. /* irq_ptr must be in GFP_DMA since it contains ccw1.cda */
  1084. irq_ptr = (void *) get_zeroed_page(GFP_KERNEL | GFP_DMA);
  1085. if (!irq_ptr)
  1086. goto out_err;
  1087. mutex_init(&irq_ptr->setup_mutex);
  1088. if (qdio_allocate_dbf(init_data, irq_ptr))
  1089. goto out_rel;
  1090. /*
  1091. * Allocate a page for the chsc calls in qdio_establish.
  1092. * Must be pre-allocated since a zfcp recovery will call
  1093. * qdio_establish. In case of low memory and swap on a zfcp disk
  1094. * we may not be able to allocate memory otherwise.
  1095. */
  1096. irq_ptr->chsc_page = get_zeroed_page(GFP_KERNEL);
  1097. if (!irq_ptr->chsc_page)
  1098. goto out_rel;
  1099. /* qdr is used in ccw1.cda which is u32 */
  1100. irq_ptr->qdr = (struct qdr *) get_zeroed_page(GFP_KERNEL | GFP_DMA);
  1101. if (!irq_ptr->qdr)
  1102. goto out_rel;
  1103. if (qdio_allocate_qs(irq_ptr, init_data->no_input_qs,
  1104. init_data->no_output_qs))
  1105. goto out_rel;
  1106. init_data->cdev->private->qdio_data = irq_ptr;
  1107. qdio_set_state(irq_ptr, QDIO_IRQ_STATE_INACTIVE);
  1108. return 0;
  1109. out_rel:
  1110. qdio_release_memory(irq_ptr);
  1111. out_err:
  1112. return -ENOMEM;
  1113. }
  1114. EXPORT_SYMBOL_GPL(qdio_allocate);
  1115. static void qdio_detect_hsicq(struct qdio_irq *irq_ptr)
  1116. {
  1117. struct qdio_q *q = irq_ptr->input_qs[0];
  1118. int i, use_cq = 0;
  1119. if (irq_ptr->nr_input_qs > 1 && queue_type(q) == QDIO_IQDIO_QFMT)
  1120. use_cq = 1;
  1121. for_each_output_queue(irq_ptr, q, i) {
  1122. if (use_cq) {
  1123. if (qdio_enable_async_operation(&q->u.out) < 0) {
  1124. use_cq = 0;
  1125. continue;
  1126. }
  1127. } else
  1128. qdio_disable_async_operation(&q->u.out);
  1129. }
  1130. DBF_EVENT("use_cq:%d", use_cq);
  1131. }
  1132. /**
  1133. * qdio_establish - establish queues on a qdio subchannel
  1134. * @init_data: initialization data
  1135. */
  1136. int qdio_establish(struct qdio_initialize *init_data)
  1137. {
  1138. struct qdio_irq *irq_ptr;
  1139. struct ccw_device *cdev = init_data->cdev;
  1140. unsigned long saveflags;
  1141. int rc;
  1142. DBF_EVENT("qestablish:%4x", cdev->private->schid.sch_no);
  1143. irq_ptr = cdev->private->qdio_data;
  1144. if (!irq_ptr)
  1145. return -ENODEV;
  1146. if (cdev->private->state != DEV_STATE_ONLINE)
  1147. return -EINVAL;
  1148. mutex_lock(&irq_ptr->setup_mutex);
  1149. qdio_setup_irq(init_data);
  1150. rc = qdio_establish_thinint(irq_ptr);
  1151. if (rc) {
  1152. mutex_unlock(&irq_ptr->setup_mutex);
  1153. qdio_shutdown(cdev, QDIO_FLAG_CLEANUP_USING_CLEAR);
  1154. return rc;
  1155. }
  1156. /* establish q */
  1157. irq_ptr->ccw.cmd_code = irq_ptr->equeue.cmd;
  1158. irq_ptr->ccw.flags = CCW_FLAG_SLI;
  1159. irq_ptr->ccw.count = irq_ptr->equeue.count;
  1160. irq_ptr->ccw.cda = (u32)((addr_t)irq_ptr->qdr);
  1161. spin_lock_irqsave(get_ccwdev_lock(cdev), saveflags);
  1162. ccw_device_set_options_mask(cdev, 0);
  1163. rc = ccw_device_start(cdev, &irq_ptr->ccw, QDIO_DOING_ESTABLISH, 0, 0);
  1164. if (rc) {
  1165. DBF_ERROR("%4x est IO ERR", irq_ptr->schid.sch_no);
  1166. DBF_ERROR("rc:%4x", rc);
  1167. }
  1168. spin_unlock_irqrestore(get_ccwdev_lock(cdev), saveflags);
  1169. if (rc) {
  1170. mutex_unlock(&irq_ptr->setup_mutex);
  1171. qdio_shutdown(cdev, QDIO_FLAG_CLEANUP_USING_CLEAR);
  1172. return rc;
  1173. }
  1174. wait_event_interruptible_timeout(cdev->private->wait_q,
  1175. irq_ptr->state == QDIO_IRQ_STATE_ESTABLISHED ||
  1176. irq_ptr->state == QDIO_IRQ_STATE_ERR, HZ);
  1177. if (irq_ptr->state != QDIO_IRQ_STATE_ESTABLISHED) {
  1178. mutex_unlock(&irq_ptr->setup_mutex);
  1179. qdio_shutdown(cdev, QDIO_FLAG_CLEANUP_USING_CLEAR);
  1180. return -EIO;
  1181. }
  1182. qdio_setup_ssqd_info(irq_ptr);
  1183. qdio_detect_hsicq(irq_ptr);
  1184. /* qebsm is now setup if available, initialize buffer states */
  1185. qdio_init_buf_states(irq_ptr);
  1186. mutex_unlock(&irq_ptr->setup_mutex);
  1187. qdio_print_subchannel_info(irq_ptr, cdev);
  1188. qdio_setup_debug_entries(irq_ptr, cdev);
  1189. return 0;
  1190. }
  1191. EXPORT_SYMBOL_GPL(qdio_establish);
  1192. /**
  1193. * qdio_activate - activate queues on a qdio subchannel
  1194. * @cdev: associated cdev
  1195. */
  1196. int qdio_activate(struct ccw_device *cdev)
  1197. {
  1198. struct qdio_irq *irq_ptr;
  1199. int rc;
  1200. unsigned long saveflags;
  1201. DBF_EVENT("qactivate:%4x", cdev->private->schid.sch_no);
  1202. irq_ptr = cdev->private->qdio_data;
  1203. if (!irq_ptr)
  1204. return -ENODEV;
  1205. if (cdev->private->state != DEV_STATE_ONLINE)
  1206. return -EINVAL;
  1207. mutex_lock(&irq_ptr->setup_mutex);
  1208. if (irq_ptr->state == QDIO_IRQ_STATE_INACTIVE) {
  1209. rc = -EBUSY;
  1210. goto out;
  1211. }
  1212. irq_ptr->ccw.cmd_code = irq_ptr->aqueue.cmd;
  1213. irq_ptr->ccw.flags = CCW_FLAG_SLI;
  1214. irq_ptr->ccw.count = irq_ptr->aqueue.count;
  1215. irq_ptr->ccw.cda = 0;
  1216. spin_lock_irqsave(get_ccwdev_lock(cdev), saveflags);
  1217. ccw_device_set_options(cdev, CCWDEV_REPORT_ALL);
  1218. rc = ccw_device_start(cdev, &irq_ptr->ccw, QDIO_DOING_ACTIVATE,
  1219. 0, DOIO_DENY_PREFETCH);
  1220. if (rc) {
  1221. DBF_ERROR("%4x act IO ERR", irq_ptr->schid.sch_no);
  1222. DBF_ERROR("rc:%4x", rc);
  1223. }
  1224. spin_unlock_irqrestore(get_ccwdev_lock(cdev), saveflags);
  1225. if (rc)
  1226. goto out;
  1227. if (is_thinint_irq(irq_ptr))
  1228. tiqdio_add_input_queues(irq_ptr);
  1229. /* wait for subchannel to become active */
  1230. msleep(5);
  1231. switch (irq_ptr->state) {
  1232. case QDIO_IRQ_STATE_STOPPED:
  1233. case QDIO_IRQ_STATE_ERR:
  1234. rc = -EIO;
  1235. break;
  1236. default:
  1237. qdio_set_state(irq_ptr, QDIO_IRQ_STATE_ACTIVE);
  1238. rc = 0;
  1239. }
  1240. out:
  1241. mutex_unlock(&irq_ptr->setup_mutex);
  1242. return rc;
  1243. }
  1244. EXPORT_SYMBOL_GPL(qdio_activate);
  1245. static inline int buf_in_between(int bufnr, int start, int count)
  1246. {
  1247. int end = add_buf(start, count);
  1248. if (end > start) {
  1249. if (bufnr >= start && bufnr < end)
  1250. return 1;
  1251. else
  1252. return 0;
  1253. }
  1254. /* wrap-around case */
  1255. if ((bufnr >= start && bufnr <= QDIO_MAX_BUFFERS_PER_Q) ||
  1256. (bufnr < end))
  1257. return 1;
  1258. else
  1259. return 0;
  1260. }
  1261. /**
  1262. * handle_inbound - reset processed input buffers
  1263. * @q: queue containing the buffers
  1264. * @callflags: flags
  1265. * @bufnr: first buffer to process
  1266. * @count: how many buffers are emptied
  1267. */
  1268. static int handle_inbound(struct qdio_q *q, unsigned int callflags,
  1269. int bufnr, int count)
  1270. {
  1271. int diff;
  1272. qperf_inc(q, inbound_call);
  1273. if (!q->u.in.polling)
  1274. goto set;
  1275. /* protect against stop polling setting an ACK for an emptied slsb */
  1276. if (count == QDIO_MAX_BUFFERS_PER_Q) {
  1277. /* overwriting everything, just delete polling status */
  1278. q->u.in.polling = 0;
  1279. q->u.in.ack_count = 0;
  1280. goto set;
  1281. } else if (buf_in_between(q->u.in.ack_start, bufnr, count)) {
  1282. if (is_qebsm(q)) {
  1283. /* partial overwrite, just update ack_start */
  1284. diff = add_buf(bufnr, count);
  1285. diff = sub_buf(diff, q->u.in.ack_start);
  1286. q->u.in.ack_count -= diff;
  1287. if (q->u.in.ack_count <= 0) {
  1288. q->u.in.polling = 0;
  1289. q->u.in.ack_count = 0;
  1290. goto set;
  1291. }
  1292. q->u.in.ack_start = add_buf(q->u.in.ack_start, diff);
  1293. }
  1294. else
  1295. /* the only ACK will be deleted, so stop polling */
  1296. q->u.in.polling = 0;
  1297. }
  1298. set:
  1299. count = set_buf_states(q, bufnr, SLSB_CU_INPUT_EMPTY, count);
  1300. atomic_add(count, &q->nr_buf_used);
  1301. if (need_siga_in(q))
  1302. return qdio_siga_input(q);
  1303. return 0;
  1304. }
  1305. /**
  1306. * handle_outbound - process filled outbound buffers
  1307. * @q: queue containing the buffers
  1308. * @callflags: flags
  1309. * @bufnr: first buffer to process
  1310. * @count: how many buffers are filled
  1311. */
  1312. static int handle_outbound(struct qdio_q *q, unsigned int callflags,
  1313. int bufnr, int count)
  1314. {
  1315. unsigned char state = 0;
  1316. int used, rc = 0;
  1317. qperf_inc(q, outbound_call);
  1318. count = set_buf_states(q, bufnr, SLSB_CU_OUTPUT_PRIMED, count);
  1319. used = atomic_add_return(count, &q->nr_buf_used);
  1320. if (used == QDIO_MAX_BUFFERS_PER_Q)
  1321. qperf_inc(q, outbound_queue_full);
  1322. if (callflags & QDIO_FLAG_PCI_OUT) {
  1323. q->u.out.pci_out_enabled = 1;
  1324. qperf_inc(q, pci_request_int);
  1325. } else
  1326. q->u.out.pci_out_enabled = 0;
  1327. if (queue_type(q) == QDIO_IQDIO_QFMT) {
  1328. unsigned long phys_aob = 0;
  1329. /* One SIGA-W per buffer required for unicast HSI */
  1330. WARN_ON_ONCE(count > 1 && !multicast_outbound(q));
  1331. phys_aob = qdio_aob_for_buffer(&q->u.out, bufnr);
  1332. rc = qdio_kick_outbound_q(q, phys_aob);
  1333. } else if (need_siga_sync(q)) {
  1334. rc = qdio_siga_sync_q(q);
  1335. } else {
  1336. /* try to fast requeue buffers */
  1337. get_buf_state(q, prev_buf(bufnr), &state, 0);
  1338. if (state != SLSB_CU_OUTPUT_PRIMED)
  1339. rc = qdio_kick_outbound_q(q, 0);
  1340. else
  1341. qperf_inc(q, fast_requeue);
  1342. }
  1343. /* in case of SIGA errors we must process the error immediately */
  1344. if (used >= q->u.out.scan_threshold || rc)
  1345. tasklet_schedule(&q->tasklet);
  1346. else
  1347. /* free the SBALs in case of no further traffic */
  1348. if (!timer_pending(&q->u.out.timer))
  1349. mod_timer(&q->u.out.timer, jiffies + HZ);
  1350. return rc;
  1351. }
  1352. /**
  1353. * do_QDIO - process input or output buffers
  1354. * @cdev: associated ccw_device for the qdio subchannel
  1355. * @callflags: input or output and special flags from the program
  1356. * @q_nr: queue number
  1357. * @bufnr: buffer number
  1358. * @count: how many buffers to process
  1359. */
  1360. int do_QDIO(struct ccw_device *cdev, unsigned int callflags,
  1361. int q_nr, unsigned int bufnr, unsigned int count)
  1362. {
  1363. struct qdio_irq *irq_ptr;
  1364. if (bufnr >= QDIO_MAX_BUFFERS_PER_Q || count > QDIO_MAX_BUFFERS_PER_Q)
  1365. return -EINVAL;
  1366. irq_ptr = cdev->private->qdio_data;
  1367. if (!irq_ptr)
  1368. return -ENODEV;
  1369. DBF_DEV_EVENT(DBF_INFO, irq_ptr,
  1370. "do%02x b:%02x c:%02x", callflags, bufnr, count);
  1371. if (irq_ptr->state != QDIO_IRQ_STATE_ACTIVE)
  1372. return -EIO;
  1373. if (!count)
  1374. return 0;
  1375. if (callflags & QDIO_FLAG_SYNC_INPUT)
  1376. return handle_inbound(irq_ptr->input_qs[q_nr],
  1377. callflags, bufnr, count);
  1378. else if (callflags & QDIO_FLAG_SYNC_OUTPUT)
  1379. return handle_outbound(irq_ptr->output_qs[q_nr],
  1380. callflags, bufnr, count);
  1381. return -EINVAL;
  1382. }
  1383. EXPORT_SYMBOL_GPL(do_QDIO);
  1384. /**
  1385. * qdio_start_irq - process input buffers
  1386. * @cdev: associated ccw_device for the qdio subchannel
  1387. * @nr: input queue number
  1388. *
  1389. * Return codes
  1390. * 0 - success
  1391. * 1 - irqs not started since new data is available
  1392. */
  1393. int qdio_start_irq(struct ccw_device *cdev, int nr)
  1394. {
  1395. struct qdio_q *q;
  1396. struct qdio_irq *irq_ptr = cdev->private->qdio_data;
  1397. if (!irq_ptr)
  1398. return -ENODEV;
  1399. q = irq_ptr->input_qs[nr];
  1400. clear_nonshared_ind(irq_ptr);
  1401. qdio_stop_polling(q);
  1402. clear_bit(QDIO_QUEUE_IRQS_DISABLED, &q->u.in.queue_irq_state);
  1403. /*
  1404. * We need to check again to not lose initiative after
  1405. * resetting the ACK state.
  1406. */
  1407. if (test_nonshared_ind(irq_ptr))
  1408. goto rescan;
  1409. if (!qdio_inbound_q_done(q))
  1410. goto rescan;
  1411. return 0;
  1412. rescan:
  1413. if (test_and_set_bit(QDIO_QUEUE_IRQS_DISABLED,
  1414. &q->u.in.queue_irq_state))
  1415. return 0;
  1416. else
  1417. return 1;
  1418. }
  1419. EXPORT_SYMBOL(qdio_start_irq);
  1420. /**
  1421. * qdio_get_next_buffers - process input buffers
  1422. * @cdev: associated ccw_device for the qdio subchannel
  1423. * @nr: input queue number
  1424. * @bufnr: first filled buffer number
  1425. * @error: buffers are in error state
  1426. *
  1427. * Return codes
  1428. * < 0 - error
  1429. * = 0 - no new buffers found
  1430. * > 0 - number of processed buffers
  1431. */
  1432. int qdio_get_next_buffers(struct ccw_device *cdev, int nr, int *bufnr,
  1433. int *error)
  1434. {
  1435. struct qdio_q *q;
  1436. int start, end;
  1437. struct qdio_irq *irq_ptr = cdev->private->qdio_data;
  1438. if (!irq_ptr)
  1439. return -ENODEV;
  1440. q = irq_ptr->input_qs[nr];
  1441. /*
  1442. * Cannot rely on automatic sync after interrupt since queues may
  1443. * also be examined without interrupt.
  1444. */
  1445. if (need_siga_sync(q))
  1446. qdio_sync_queues(q);
  1447. /* check the PCI capable outbound queues. */
  1448. qdio_check_outbound_after_thinint(q);
  1449. if (!qdio_inbound_q_moved(q))
  1450. return 0;
  1451. /* Note: upper-layer MUST stop processing immediately here ... */
  1452. if (unlikely(q->irq_ptr->state != QDIO_IRQ_STATE_ACTIVE))
  1453. return -EIO;
  1454. start = q->first_to_kick;
  1455. end = q->first_to_check;
  1456. *bufnr = start;
  1457. *error = q->qdio_error;
  1458. /* for the next time */
  1459. q->first_to_kick = end;
  1460. q->qdio_error = 0;
  1461. return sub_buf(end, start);
  1462. }
  1463. EXPORT_SYMBOL(qdio_get_next_buffers);
  1464. /**
  1465. * qdio_stop_irq - disable interrupt processing for the device
  1466. * @cdev: associated ccw_device for the qdio subchannel
  1467. * @nr: input queue number
  1468. *
  1469. * Return codes
  1470. * 0 - interrupts were already disabled
  1471. * 1 - interrupts successfully disabled
  1472. */
  1473. int qdio_stop_irq(struct ccw_device *cdev, int nr)
  1474. {
  1475. struct qdio_q *q;
  1476. struct qdio_irq *irq_ptr = cdev->private->qdio_data;
  1477. if (!irq_ptr)
  1478. return -ENODEV;
  1479. q = irq_ptr->input_qs[nr];
  1480. if (test_and_set_bit(QDIO_QUEUE_IRQS_DISABLED,
  1481. &q->u.in.queue_irq_state))
  1482. return 0;
  1483. else
  1484. return 1;
  1485. }
  1486. EXPORT_SYMBOL(qdio_stop_irq);
  1487. /**
  1488. * qdio_pnso_brinfo() - perform network subchannel op #0 - bridge info.
  1489. * @schid: Subchannel ID.
  1490. * @cnc: Boolean Change-Notification Control
  1491. * @response: Response code will be stored at this address
  1492. * @cb: Callback function will be executed for each element
  1493. * of the address list
  1494. * @priv: Pointer passed from the caller to qdio_pnso_brinfo()
  1495. * @type: Type of the address entry passed to the callback
  1496. * @entry: Entry containg the address of the specified type
  1497. * @priv: Pointer to pass to the callback function.
  1498. *
  1499. * Performs "Store-network-bridging-information list" operation and calls
  1500. * the callback function for every entry in the list. If "change-
  1501. * notification-control" is set, further changes in the address list
  1502. * will be reported via the IPA command.
  1503. */
  1504. int qdio_pnso_brinfo(struct subchannel_id schid,
  1505. int cnc, u16 *response,
  1506. void (*cb)(void *priv, enum qdio_brinfo_entry_type type,
  1507. void *entry),
  1508. void *priv)
  1509. {
  1510. struct chsc_pnso_area *rr;
  1511. int rc;
  1512. u32 prev_instance = 0;
  1513. int isfirstblock = 1;
  1514. int i, size, elems;
  1515. rr = (struct chsc_pnso_area *)get_zeroed_page(GFP_KERNEL);
  1516. if (rr == NULL)
  1517. return -ENOMEM;
  1518. do {
  1519. /* on the first iteration, naihdr.resume_token will be zero */
  1520. rc = chsc_pnso_brinfo(schid, rr, rr->naihdr.resume_token, cnc);
  1521. if (rc != 0 && rc != -EBUSY)
  1522. goto out;
  1523. if (rr->response.code != 1) {
  1524. rc = -EIO;
  1525. continue;
  1526. } else
  1527. rc = 0;
  1528. if (cb == NULL)
  1529. continue;
  1530. size = rr->naihdr.naids;
  1531. elems = (rr->response.length -
  1532. sizeof(struct chsc_header) -
  1533. sizeof(struct chsc_brinfo_naihdr)) /
  1534. size;
  1535. if (!isfirstblock && (rr->naihdr.instance != prev_instance)) {
  1536. /* Inform the caller that they need to scrap */
  1537. /* the data that was already reported via cb */
  1538. rc = -EAGAIN;
  1539. break;
  1540. }
  1541. isfirstblock = 0;
  1542. prev_instance = rr->naihdr.instance;
  1543. for (i = 0; i < elems; i++)
  1544. switch (size) {
  1545. case sizeof(struct qdio_brinfo_entry_l3_ipv6):
  1546. (*cb)(priv, l3_ipv6_addr,
  1547. &rr->entries.l3_ipv6[i]);
  1548. break;
  1549. case sizeof(struct qdio_brinfo_entry_l3_ipv4):
  1550. (*cb)(priv, l3_ipv4_addr,
  1551. &rr->entries.l3_ipv4[i]);
  1552. break;
  1553. case sizeof(struct qdio_brinfo_entry_l2):
  1554. (*cb)(priv, l2_addr_lnid,
  1555. &rr->entries.l2[i]);
  1556. break;
  1557. default:
  1558. WARN_ON_ONCE(1);
  1559. rc = -EIO;
  1560. goto out;
  1561. }
  1562. } while (rr->response.code == 0x0107 || /* channel busy */
  1563. (rr->response.code == 1 && /* list stored */
  1564. /* resume token is non-zero => list incomplete */
  1565. (rr->naihdr.resume_token.t1 || rr->naihdr.resume_token.t2)));
  1566. (*response) = rr->response.code;
  1567. out:
  1568. free_page((unsigned long)rr);
  1569. return rc;
  1570. }
  1571. EXPORT_SYMBOL_GPL(qdio_pnso_brinfo);
  1572. static int __init init_QDIO(void)
  1573. {
  1574. int rc;
  1575. rc = qdio_debug_init();
  1576. if (rc)
  1577. return rc;
  1578. rc = qdio_setup_init();
  1579. if (rc)
  1580. goto out_debug;
  1581. rc = tiqdio_allocate_memory();
  1582. if (rc)
  1583. goto out_cache;
  1584. rc = tiqdio_register_thinints();
  1585. if (rc)
  1586. goto out_ti;
  1587. return 0;
  1588. out_ti:
  1589. tiqdio_free_memory();
  1590. out_cache:
  1591. qdio_setup_exit();
  1592. out_debug:
  1593. qdio_debug_exit();
  1594. return rc;
  1595. }
  1596. static void __exit exit_QDIO(void)
  1597. {
  1598. tiqdio_unregister_thinints();
  1599. tiqdio_free_memory();
  1600. qdio_setup_exit();
  1601. qdio_debug_exit();
  1602. }
  1603. module_init(init_QDIO);
  1604. module_exit(exit_QDIO);