tape_std.c 18 KB

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