tape_std.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748
  1. /*
  2. * drivers/s390/char/tape_std.c
  3. * standard tape device functions for ibm tapes.
  4. *
  5. * S390 and zSeries version
  6. * Copyright (C) 2001,2002 IBM Deutschland Entwicklung GmbH, IBM Corporation
  7. * Author(s): Carsten Otte <cotte@de.ibm.com>
  8. * Michael Holzheu <holzheu@de.ibm.com>
  9. * Tuan Ngo-Anh <ngoanh@de.ibm.com>
  10. * Martin Schwidefsky <schwidefsky@de.ibm.com>
  11. * Stefan Bader <shbader@de.ibm.com>
  12. */
  13. #include <linux/stddef.h>
  14. #include <linux/kernel.h>
  15. #include <linux/bio.h>
  16. #include <linux/timer.h>
  17. #include <asm/types.h>
  18. #include <asm/idals.h>
  19. #include <asm/ebcdic.h>
  20. #include <asm/tape390.h>
  21. #define TAPE_DBF_AREA tape_core_dbf
  22. #include "tape.h"
  23. #include "tape_std.h"
  24. /*
  25. * tape_std_assign
  26. */
  27. static void
  28. tape_std_assign_timeout(unsigned long data)
  29. {
  30. struct tape_request * request;
  31. struct tape_device * device;
  32. int rc;
  33. request = (struct tape_request *) data;
  34. device = request->device;
  35. BUG_ON(!device);
  36. DBF_EVENT(3, "%08x: Assignment timeout. Device busy.\n",
  37. device->cdev_id);
  38. rc = tape_cancel_io(device, request);
  39. if(rc)
  40. DBF_EVENT(3, "(%s): Assign timeout: Cancel failed with rc = %i\n",
  41. dev_name(&device->cdev->dev), rc);
  42. }
  43. int
  44. tape_std_assign(struct tape_device *device)
  45. {
  46. int rc;
  47. struct timer_list timeout;
  48. struct tape_request *request;
  49. request = tape_alloc_request(2, 11);
  50. if (IS_ERR(request))
  51. return PTR_ERR(request);
  52. request->op = TO_ASSIGN;
  53. tape_ccw_cc(request->cpaddr, ASSIGN, 11, request->cpdata);
  54. tape_ccw_end(request->cpaddr + 1, NOP, 0, NULL);
  55. /*
  56. * The assign command sometimes blocks if the device is assigned
  57. * to another host (actually this shouldn't happen but it does).
  58. * So we set up a timeout for this call.
  59. */
  60. init_timer(&timeout);
  61. timeout.function = tape_std_assign_timeout;
  62. timeout.data = (unsigned long) request;
  63. timeout.expires = jiffies + 2 * HZ;
  64. add_timer(&timeout);
  65. rc = tape_do_io_interruptible(device, request);
  66. del_timer(&timeout);
  67. if (rc != 0) {
  68. DBF_EVENT(3, "%08x: assign failed - device might be busy\n",
  69. device->cdev_id);
  70. } else {
  71. DBF_EVENT(3, "%08x: Tape assigned\n", device->cdev_id);
  72. }
  73. tape_free_request(request);
  74. return rc;
  75. }
  76. /*
  77. * tape_std_unassign
  78. */
  79. int
  80. tape_std_unassign (struct tape_device *device)
  81. {
  82. int rc;
  83. struct tape_request *request;
  84. if (device->tape_state == TS_NOT_OPER) {
  85. DBF_EVENT(3, "(%08x): Can't unassign device\n",
  86. device->cdev_id);
  87. return -EIO;
  88. }
  89. request = tape_alloc_request(2, 11);
  90. if (IS_ERR(request))
  91. return PTR_ERR(request);
  92. request->op = TO_UNASSIGN;
  93. tape_ccw_cc(request->cpaddr, UNASSIGN, 11, request->cpdata);
  94. tape_ccw_end(request->cpaddr + 1, NOP, 0, NULL);
  95. if ((rc = tape_do_io(device, request)) != 0) {
  96. DBF_EVENT(3, "%08x: Unassign failed\n", device->cdev_id);
  97. } else {
  98. DBF_EVENT(3, "%08x: Tape unassigned\n", device->cdev_id);
  99. }
  100. tape_free_request(request);
  101. return rc;
  102. }
  103. /*
  104. * TAPE390_DISPLAY: Show a string on the tape display.
  105. */
  106. int
  107. tape_std_display(struct tape_device *device, struct display_struct *disp)
  108. {
  109. struct tape_request *request;
  110. int rc;
  111. request = tape_alloc_request(2, 17);
  112. if (IS_ERR(request)) {
  113. DBF_EVENT(3, "TAPE: load display failed\n");
  114. return PTR_ERR(request);
  115. }
  116. request->op = TO_DIS;
  117. *(unsigned char *) request->cpdata = disp->cntrl;
  118. DBF_EVENT(5, "TAPE: display cntrl=%04x\n", disp->cntrl);
  119. memcpy(((unsigned char *) request->cpdata) + 1, disp->message1, 8);
  120. memcpy(((unsigned char *) request->cpdata) + 9, disp->message2, 8);
  121. ASCEBC(((unsigned char*) request->cpdata) + 1, 16);
  122. tape_ccw_cc(request->cpaddr, LOAD_DISPLAY, 17, request->cpdata);
  123. tape_ccw_end(request->cpaddr + 1, NOP, 0, NULL);
  124. rc = tape_do_io_interruptible(device, request);
  125. tape_free_request(request);
  126. return rc;
  127. }
  128. /*
  129. * Read block id.
  130. */
  131. int
  132. tape_std_read_block_id(struct tape_device *device, __u64 *id)
  133. {
  134. struct tape_request *request;
  135. int rc;
  136. request = tape_alloc_request(3, 8);
  137. if (IS_ERR(request))
  138. return PTR_ERR(request);
  139. request->op = TO_RBI;
  140. /* setup ccws */
  141. tape_ccw_cc(request->cpaddr, MODE_SET_DB, 1, device->modeset_byte);
  142. tape_ccw_cc(request->cpaddr + 1, READ_BLOCK_ID, 8, request->cpdata);
  143. tape_ccw_end(request->cpaddr + 2, NOP, 0, NULL);
  144. /* execute it */
  145. rc = tape_do_io(device, request);
  146. if (rc == 0)
  147. /* Get result from read buffer. */
  148. *id = *(__u64 *) request->cpdata;
  149. tape_free_request(request);
  150. return rc;
  151. }
  152. int
  153. tape_std_terminate_write(struct tape_device *device)
  154. {
  155. int rc;
  156. if(device->required_tapemarks == 0)
  157. return 0;
  158. DBF_LH(5, "tape%d: terminate write %dxEOF\n", device->first_minor,
  159. device->required_tapemarks);
  160. rc = tape_mtop(device, MTWEOF, device->required_tapemarks);
  161. if (rc)
  162. return rc;
  163. device->required_tapemarks = 0;
  164. return tape_mtop(device, MTBSR, 1);
  165. }
  166. /*
  167. * MTLOAD: Loads the tape.
  168. * The default implementation just wait until the tape medium state changes
  169. * to MS_LOADED.
  170. */
  171. int
  172. tape_std_mtload(struct tape_device *device, int count)
  173. {
  174. return wait_event_interruptible(device->state_change_wq,
  175. (device->medium_state == MS_LOADED));
  176. }
  177. /*
  178. * MTSETBLK: Set block size.
  179. */
  180. int
  181. tape_std_mtsetblk(struct tape_device *device, int count)
  182. {
  183. struct idal_buffer *new;
  184. DBF_LH(6, "tape_std_mtsetblk(%d)\n", count);
  185. if (count <= 0) {
  186. /*
  187. * Just set block_size to 0. tapechar_read/tapechar_write
  188. * will realloc the idal buffer if a bigger one than the
  189. * current is needed.
  190. */
  191. device->char_data.block_size = 0;
  192. return 0;
  193. }
  194. if (device->char_data.idal_buf != NULL &&
  195. device->char_data.idal_buf->size == count)
  196. /* We already have a idal buffer of that size. */
  197. return 0;
  198. if (count > MAX_BLOCKSIZE) {
  199. DBF_EVENT(3, "Invalid block size (%d > %d) given.\n",
  200. count, MAX_BLOCKSIZE);
  201. return -EINVAL;
  202. }
  203. /* Allocate a new idal buffer. */
  204. new = idal_buffer_alloc(count, 0);
  205. if (IS_ERR(new))
  206. return -ENOMEM;
  207. if (device->char_data.idal_buf != NULL)
  208. idal_buffer_free(device->char_data.idal_buf);
  209. device->char_data.idal_buf = new;
  210. device->char_data.block_size = count;
  211. DBF_LH(6, "new blocksize is %d\n", device->char_data.block_size);
  212. return 0;
  213. }
  214. /*
  215. * MTRESET: Set block size to 0.
  216. */
  217. int
  218. tape_std_mtreset(struct tape_device *device, int count)
  219. {
  220. DBF_EVENT(6, "TCHAR:devreset:\n");
  221. device->char_data.block_size = 0;
  222. return 0;
  223. }
  224. /*
  225. * MTFSF: Forward space over 'count' file marks. The tape is positioned
  226. * at the EOT (End of Tape) side of the file mark.
  227. */
  228. int
  229. tape_std_mtfsf(struct tape_device *device, int mt_count)
  230. {
  231. struct tape_request *request;
  232. struct ccw1 *ccw;
  233. request = tape_alloc_request(mt_count + 2, 0);
  234. if (IS_ERR(request))
  235. return PTR_ERR(request);
  236. request->op = TO_FSF;
  237. /* setup ccws */
  238. ccw = tape_ccw_cc(request->cpaddr, MODE_SET_DB, 1,
  239. device->modeset_byte);
  240. ccw = tape_ccw_repeat(ccw, FORSPACEFILE, mt_count);
  241. ccw = tape_ccw_end(ccw, NOP, 0, NULL);
  242. /* execute it */
  243. return tape_do_io_free(device, request);
  244. }
  245. /*
  246. * MTFSR: Forward space over 'count' tape blocks (blocksize is set
  247. * via MTSETBLK.
  248. */
  249. int
  250. tape_std_mtfsr(struct tape_device *device, int mt_count)
  251. {
  252. struct tape_request *request;
  253. struct ccw1 *ccw;
  254. int rc;
  255. request = tape_alloc_request(mt_count + 2, 0);
  256. if (IS_ERR(request))
  257. return PTR_ERR(request);
  258. request->op = TO_FSB;
  259. /* setup ccws */
  260. ccw = tape_ccw_cc(request->cpaddr, MODE_SET_DB, 1,
  261. device->modeset_byte);
  262. ccw = tape_ccw_repeat(ccw, FORSPACEBLOCK, mt_count);
  263. ccw = tape_ccw_end(ccw, NOP, 0, NULL);
  264. /* execute it */
  265. rc = tape_do_io(device, request);
  266. if (rc == 0 && request->rescnt > 0) {
  267. DBF_LH(3, "FSR over tapemark\n");
  268. rc = 1;
  269. }
  270. tape_free_request(request);
  271. return rc;
  272. }
  273. /*
  274. * MTBSR: Backward space over 'count' tape blocks.
  275. * (blocksize is set via MTSETBLK.
  276. */
  277. int
  278. tape_std_mtbsr(struct tape_device *device, int mt_count)
  279. {
  280. struct tape_request *request;
  281. struct ccw1 *ccw;
  282. int rc;
  283. request = tape_alloc_request(mt_count + 2, 0);
  284. if (IS_ERR(request))
  285. return PTR_ERR(request);
  286. request->op = TO_BSB;
  287. /* setup ccws */
  288. ccw = tape_ccw_cc(request->cpaddr, MODE_SET_DB, 1,
  289. device->modeset_byte);
  290. ccw = tape_ccw_repeat(ccw, BACKSPACEBLOCK, mt_count);
  291. ccw = tape_ccw_end(ccw, NOP, 0, NULL);
  292. /* execute it */
  293. rc = tape_do_io(device, request);
  294. if (rc == 0 && request->rescnt > 0) {
  295. DBF_LH(3, "BSR over tapemark\n");
  296. rc = 1;
  297. }
  298. tape_free_request(request);
  299. return rc;
  300. }
  301. /*
  302. * MTWEOF: Write 'count' file marks at the current position.
  303. */
  304. int
  305. tape_std_mtweof(struct tape_device *device, int mt_count)
  306. {
  307. struct tape_request *request;
  308. struct ccw1 *ccw;
  309. request = tape_alloc_request(mt_count + 2, 0);
  310. if (IS_ERR(request))
  311. return PTR_ERR(request);
  312. request->op = TO_WTM;
  313. /* setup ccws */
  314. ccw = tape_ccw_cc(request->cpaddr, MODE_SET_DB, 1,
  315. device->modeset_byte);
  316. ccw = tape_ccw_repeat(ccw, WRITETAPEMARK, mt_count);
  317. ccw = tape_ccw_end(ccw, NOP, 0, NULL);
  318. /* execute it */
  319. return tape_do_io_free(device, request);
  320. }
  321. /*
  322. * MTBSFM: Backward space over 'count' file marks.
  323. * The tape is positioned at the BOT (Begin Of Tape) side of the
  324. * last skipped file mark.
  325. */
  326. int
  327. tape_std_mtbsfm(struct tape_device *device, int mt_count)
  328. {
  329. struct tape_request *request;
  330. struct ccw1 *ccw;
  331. request = tape_alloc_request(mt_count + 2, 0);
  332. if (IS_ERR(request))
  333. return PTR_ERR(request);
  334. request->op = TO_BSF;
  335. /* setup ccws */
  336. ccw = tape_ccw_cc(request->cpaddr, MODE_SET_DB, 1,
  337. device->modeset_byte);
  338. ccw = tape_ccw_repeat(ccw, BACKSPACEFILE, mt_count);
  339. ccw = tape_ccw_end(ccw, NOP, 0, NULL);
  340. /* execute it */
  341. return tape_do_io_free(device, request);
  342. }
  343. /*
  344. * MTBSF: Backward space over 'count' file marks. The tape is positioned at
  345. * the EOT (End of Tape) side of the last skipped file mark.
  346. */
  347. int
  348. tape_std_mtbsf(struct tape_device *device, int mt_count)
  349. {
  350. struct tape_request *request;
  351. struct ccw1 *ccw;
  352. int rc;
  353. request = tape_alloc_request(mt_count + 2, 0);
  354. if (IS_ERR(request))
  355. return PTR_ERR(request);
  356. request->op = TO_BSF;
  357. /* setup ccws */
  358. ccw = tape_ccw_cc(request->cpaddr, MODE_SET_DB, 1,
  359. device->modeset_byte);
  360. ccw = tape_ccw_repeat(ccw, BACKSPACEFILE, mt_count);
  361. ccw = tape_ccw_end(ccw, NOP, 0, NULL);
  362. /* execute it */
  363. rc = tape_do_io_free(device, request);
  364. if (rc == 0) {
  365. rc = tape_mtop(device, MTFSR, 1);
  366. if (rc > 0)
  367. rc = 0;
  368. }
  369. return rc;
  370. }
  371. /*
  372. * MTFSFM: Forward space over 'count' file marks.
  373. * The tape is positioned at the BOT (Begin Of Tape) side
  374. * of the last skipped file mark.
  375. */
  376. int
  377. tape_std_mtfsfm(struct tape_device *device, int mt_count)
  378. {
  379. struct tape_request *request;
  380. struct ccw1 *ccw;
  381. int rc;
  382. request = tape_alloc_request(mt_count + 2, 0);
  383. if (IS_ERR(request))
  384. return PTR_ERR(request);
  385. request->op = TO_FSF;
  386. /* setup ccws */
  387. ccw = tape_ccw_cc(request->cpaddr, MODE_SET_DB, 1,
  388. device->modeset_byte);
  389. ccw = tape_ccw_repeat(ccw, FORSPACEFILE, mt_count);
  390. ccw = tape_ccw_end(ccw, NOP, 0, NULL);
  391. /* execute it */
  392. rc = tape_do_io_free(device, request);
  393. if (rc == 0) {
  394. rc = tape_mtop(device, MTBSR, 1);
  395. if (rc > 0)
  396. rc = 0;
  397. }
  398. return rc;
  399. }
  400. /*
  401. * MTREW: Rewind the tape.
  402. */
  403. int
  404. tape_std_mtrew(struct tape_device *device, int mt_count)
  405. {
  406. struct tape_request *request;
  407. request = tape_alloc_request(3, 0);
  408. if (IS_ERR(request))
  409. return PTR_ERR(request);
  410. request->op = TO_REW;
  411. /* setup ccws */
  412. tape_ccw_cc(request->cpaddr, MODE_SET_DB, 1,
  413. device->modeset_byte);
  414. tape_ccw_cc(request->cpaddr + 1, REWIND, 0, NULL);
  415. tape_ccw_end(request->cpaddr + 2, NOP, 0, NULL);
  416. /* execute it */
  417. return tape_do_io_free(device, request);
  418. }
  419. /*
  420. * MTOFFL: Rewind the tape and put the drive off-line.
  421. * Implement 'rewind unload'
  422. */
  423. int
  424. tape_std_mtoffl(struct tape_device *device, int mt_count)
  425. {
  426. struct tape_request *request;
  427. request = tape_alloc_request(3, 0);
  428. if (IS_ERR(request))
  429. return PTR_ERR(request);
  430. request->op = TO_RUN;
  431. /* setup ccws */
  432. tape_ccw_cc(request->cpaddr, MODE_SET_DB, 1, device->modeset_byte);
  433. tape_ccw_cc(request->cpaddr + 1, REWIND_UNLOAD, 0, NULL);
  434. tape_ccw_end(request->cpaddr + 2, NOP, 0, NULL);
  435. /* execute it */
  436. return tape_do_io_free(device, request);
  437. }
  438. /*
  439. * MTNOP: 'No operation'.
  440. */
  441. int
  442. tape_std_mtnop(struct tape_device *device, int mt_count)
  443. {
  444. struct tape_request *request;
  445. request = tape_alloc_request(2, 0);
  446. if (IS_ERR(request))
  447. return PTR_ERR(request);
  448. request->op = TO_NOP;
  449. /* setup ccws */
  450. tape_ccw_cc(request->cpaddr, MODE_SET_DB, 1, device->modeset_byte);
  451. tape_ccw_end(request->cpaddr + 1, NOP, 0, NULL);
  452. /* execute it */
  453. return tape_do_io_free(device, request);
  454. }
  455. /*
  456. * MTEOM: positions at the end of the portion of the tape already used
  457. * for recordind data. MTEOM positions after the last file mark, ready for
  458. * appending another file.
  459. */
  460. int
  461. tape_std_mteom(struct tape_device *device, int mt_count)
  462. {
  463. int rc;
  464. /*
  465. * Seek from the beginning of tape (rewind).
  466. */
  467. if ((rc = tape_mtop(device, MTREW, 1)) < 0)
  468. return rc;
  469. /*
  470. * The logical end of volume is given by two sewuential tapemarks.
  471. * Look for this by skipping to the next file (over one tapemark)
  472. * and then test for another one (fsr returns 1 if a tapemark was
  473. * encountered).
  474. */
  475. do {
  476. if ((rc = tape_mtop(device, MTFSF, 1)) < 0)
  477. return rc;
  478. if ((rc = tape_mtop(device, MTFSR, 1)) < 0)
  479. return rc;
  480. } while (rc == 0);
  481. return tape_mtop(device, MTBSR, 1);
  482. }
  483. /*
  484. * MTRETEN: Retension the tape, i.e. forward space to end of tape and rewind.
  485. */
  486. int
  487. tape_std_mtreten(struct tape_device *device, int mt_count)
  488. {
  489. struct tape_request *request;
  490. int rc;
  491. request = tape_alloc_request(4, 0);
  492. if (IS_ERR(request))
  493. return PTR_ERR(request);
  494. request->op = TO_FSF;
  495. /* setup ccws */
  496. tape_ccw_cc(request->cpaddr, MODE_SET_DB, 1, device->modeset_byte);
  497. tape_ccw_cc(request->cpaddr + 1,FORSPACEFILE, 0, NULL);
  498. tape_ccw_cc(request->cpaddr + 2, NOP, 0, NULL);
  499. tape_ccw_end(request->cpaddr + 3, CCW_CMD_TIC, 0, request->cpaddr);
  500. /* execute it, MTRETEN rc gets ignored */
  501. rc = tape_do_io_interruptible(device, request);
  502. tape_free_request(request);
  503. return tape_mtop(device, MTREW, 1);
  504. }
  505. /*
  506. * MTERASE: erases the tape.
  507. */
  508. int
  509. tape_std_mterase(struct tape_device *device, int mt_count)
  510. {
  511. struct tape_request *request;
  512. request = tape_alloc_request(6, 0);
  513. if (IS_ERR(request))
  514. return PTR_ERR(request);
  515. request->op = TO_DSE;
  516. /* setup ccws */
  517. tape_ccw_cc(request->cpaddr, MODE_SET_DB, 1, device->modeset_byte);
  518. tape_ccw_cc(request->cpaddr + 1, REWIND, 0, NULL);
  519. tape_ccw_cc(request->cpaddr + 2, ERASE_GAP, 0, NULL);
  520. tape_ccw_cc(request->cpaddr + 3, DATA_SEC_ERASE, 0, NULL);
  521. tape_ccw_cc(request->cpaddr + 4, REWIND, 0, NULL);
  522. tape_ccw_end(request->cpaddr + 5, NOP, 0, NULL);
  523. /* execute it */
  524. return tape_do_io_free(device, request);
  525. }
  526. /*
  527. * MTUNLOAD: Rewind the tape and unload it.
  528. */
  529. int
  530. tape_std_mtunload(struct tape_device *device, int mt_count)
  531. {
  532. return tape_mtop(device, MTOFFL, mt_count);
  533. }
  534. /*
  535. * MTCOMPRESSION: used to enable compression.
  536. * Sets the IDRC on/off.
  537. */
  538. int
  539. tape_std_mtcompression(struct tape_device *device, int mt_count)
  540. {
  541. struct tape_request *request;
  542. if (mt_count < 0 || mt_count > 1) {
  543. DBF_EXCEPTION(6, "xcom parm\n");
  544. return -EINVAL;
  545. }
  546. request = tape_alloc_request(2, 0);
  547. if (IS_ERR(request))
  548. return PTR_ERR(request);
  549. request->op = TO_NOP;
  550. /* setup ccws */
  551. if (mt_count == 0)
  552. *device->modeset_byte &= ~0x08;
  553. else
  554. *device->modeset_byte |= 0x08;
  555. tape_ccw_cc(request->cpaddr, MODE_SET_DB, 1, device->modeset_byte);
  556. tape_ccw_end(request->cpaddr + 1, NOP, 0, NULL);
  557. /* execute it */
  558. return tape_do_io_free(device, request);
  559. }
  560. /*
  561. * Read Block
  562. */
  563. struct tape_request *
  564. tape_std_read_block(struct tape_device *device, size_t count)
  565. {
  566. struct tape_request *request;
  567. /*
  568. * We have to alloc 4 ccws in order to be able to transform request
  569. * into a read backward request in error case.
  570. */
  571. request = tape_alloc_request(4, 0);
  572. if (IS_ERR(request)) {
  573. DBF_EXCEPTION(6, "xrbl fail");
  574. return request;
  575. }
  576. request->op = TO_RFO;
  577. tape_ccw_cc(request->cpaddr, MODE_SET_DB, 1, device->modeset_byte);
  578. tape_ccw_end_idal(request->cpaddr + 1, READ_FORWARD,
  579. device->char_data.idal_buf);
  580. DBF_EVENT(6, "xrbl ccwg\n");
  581. return request;
  582. }
  583. /*
  584. * Read Block backward transformation function.
  585. */
  586. void
  587. tape_std_read_backward(struct tape_device *device, struct tape_request *request)
  588. {
  589. /*
  590. * We have allocated 4 ccws in tape_std_read, so we can now
  591. * transform the request to a read backward, followed by a
  592. * forward space block.
  593. */
  594. request->op = TO_RBA;
  595. tape_ccw_cc(request->cpaddr, MODE_SET_DB, 1, device->modeset_byte);
  596. tape_ccw_cc_idal(request->cpaddr + 1, READ_BACKWARD,
  597. device->char_data.idal_buf);
  598. tape_ccw_cc(request->cpaddr + 2, FORSPACEBLOCK, 0, NULL);
  599. tape_ccw_end(request->cpaddr + 3, NOP, 0, NULL);
  600. DBF_EVENT(6, "xrop ccwg");}
  601. /*
  602. * Write Block
  603. */
  604. struct tape_request *
  605. tape_std_write_block(struct tape_device *device, size_t count)
  606. {
  607. struct tape_request *request;
  608. request = tape_alloc_request(2, 0);
  609. if (IS_ERR(request)) {
  610. DBF_EXCEPTION(6, "xwbl fail\n");
  611. return request;
  612. }
  613. request->op = TO_WRI;
  614. tape_ccw_cc(request->cpaddr, MODE_SET_DB, 1, device->modeset_byte);
  615. tape_ccw_end_idal(request->cpaddr + 1, WRITE_CMD,
  616. device->char_data.idal_buf);
  617. DBF_EVENT(6, "xwbl ccwg\n");
  618. return request;
  619. }
  620. /*
  621. * This routine is called by frontend after an ENOSP on write
  622. */
  623. void
  624. tape_std_process_eov(struct tape_device *device)
  625. {
  626. /*
  627. * End of volume: We have to backspace the last written record, then
  628. * we TRY to write a tapemark and then backspace over the written TM
  629. */
  630. if (tape_mtop(device, MTBSR, 1) == 0 &&
  631. tape_mtop(device, MTWEOF, 1) == 0) {
  632. tape_mtop(device, MTBSR, 1);
  633. }
  634. }
  635. EXPORT_SYMBOL(tape_std_assign);
  636. EXPORT_SYMBOL(tape_std_unassign);
  637. EXPORT_SYMBOL(tape_std_display);
  638. EXPORT_SYMBOL(tape_std_read_block_id);
  639. EXPORT_SYMBOL(tape_std_mtload);
  640. EXPORT_SYMBOL(tape_std_mtsetblk);
  641. EXPORT_SYMBOL(tape_std_mtreset);
  642. EXPORT_SYMBOL(tape_std_mtfsf);
  643. EXPORT_SYMBOL(tape_std_mtfsr);
  644. EXPORT_SYMBOL(tape_std_mtbsr);
  645. EXPORT_SYMBOL(tape_std_mtweof);
  646. EXPORT_SYMBOL(tape_std_mtbsfm);
  647. EXPORT_SYMBOL(tape_std_mtbsf);
  648. EXPORT_SYMBOL(tape_std_mtfsfm);
  649. EXPORT_SYMBOL(tape_std_mtrew);
  650. EXPORT_SYMBOL(tape_std_mtoffl);
  651. EXPORT_SYMBOL(tape_std_mtnop);
  652. EXPORT_SYMBOL(tape_std_mteom);
  653. EXPORT_SYMBOL(tape_std_mtreten);
  654. EXPORT_SYMBOL(tape_std_mterase);
  655. EXPORT_SYMBOL(tape_std_mtunload);
  656. EXPORT_SYMBOL(tape_std_mtcompression);
  657. EXPORT_SYMBOL(tape_std_read_block);
  658. EXPORT_SYMBOL(tape_std_read_backward);
  659. EXPORT_SYMBOL(tape_std_write_block);
  660. EXPORT_SYMBOL(tape_std_process_eov);