tape_std.c 18 KB

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