tape_std.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749
  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(&timeout);
  68. if (rc != 0) {
  69. DBF_EVENT(3, "%08x: assign failed - device might be busy\n",
  70. device->cdev_id);
  71. } else {
  72. DBF_EVENT(3, "%08x: Tape assigned\n", device->cdev_id);
  73. }
  74. tape_free_request(request);
  75. return rc;
  76. }
  77. /*
  78. * tape_std_unassign
  79. */
  80. int
  81. tape_std_unassign (struct tape_device *device)
  82. {
  83. int rc;
  84. struct tape_request *request;
  85. if (device->tape_state == TS_NOT_OPER) {
  86. DBF_EVENT(3, "(%08x): Can't unassign device\n",
  87. device->cdev_id);
  88. return -EIO;
  89. }
  90. request = tape_alloc_request(2, 11);
  91. if (IS_ERR(request))
  92. return PTR_ERR(request);
  93. request->op = TO_UNASSIGN;
  94. tape_ccw_cc(request->cpaddr, UNASSIGN, 11, request->cpdata);
  95. tape_ccw_end(request->cpaddr + 1, NOP, 0, NULL);
  96. if ((rc = tape_do_io(device, request)) != 0) {
  97. DBF_EVENT(3, "%08x: Unassign failed\n", device->cdev_id);
  98. } else {
  99. DBF_EVENT(3, "%08x: Tape unassigned\n", device->cdev_id);
  100. }
  101. tape_free_request(request);
  102. return rc;
  103. }
  104. /*
  105. * TAPE390_DISPLAY: Show a string on the tape display.
  106. */
  107. int
  108. tape_std_display(struct tape_device *device, struct display_struct *disp)
  109. {
  110. struct tape_request *request;
  111. int rc;
  112. request = tape_alloc_request(2, 17);
  113. if (IS_ERR(request)) {
  114. DBF_EVENT(3, "TAPE: load display failed\n");
  115. return PTR_ERR(request);
  116. }
  117. request->op = TO_DIS;
  118. *(unsigned char *) request->cpdata = disp->cntrl;
  119. DBF_EVENT(5, "TAPE: display cntrl=%04x\n", disp->cntrl);
  120. memcpy(((unsigned char *) request->cpdata) + 1, disp->message1, 8);
  121. memcpy(((unsigned char *) request->cpdata) + 9, disp->message2, 8);
  122. ASCEBC(((unsigned char*) request->cpdata) + 1, 16);
  123. tape_ccw_cc(request->cpaddr, LOAD_DISPLAY, 17, request->cpdata);
  124. tape_ccw_end(request->cpaddr + 1, NOP, 0, NULL);
  125. rc = tape_do_io_interruptible(device, request);
  126. tape_free_request(request);
  127. return rc;
  128. }
  129. /*
  130. * Read block id.
  131. */
  132. int
  133. tape_std_read_block_id(struct tape_device *device, __u64 *id)
  134. {
  135. struct tape_request *request;
  136. int rc;
  137. request = tape_alloc_request(3, 8);
  138. if (IS_ERR(request))
  139. return PTR_ERR(request);
  140. request->op = TO_RBI;
  141. /* setup ccws */
  142. tape_ccw_cc(request->cpaddr, MODE_SET_DB, 1, device->modeset_byte);
  143. tape_ccw_cc(request->cpaddr + 1, READ_BLOCK_ID, 8, request->cpdata);
  144. tape_ccw_end(request->cpaddr + 2, NOP, 0, NULL);
  145. /* execute it */
  146. rc = tape_do_io(device, request);
  147. if (rc == 0)
  148. /* Get result from read buffer. */
  149. *id = *(__u64 *) request->cpdata;
  150. tape_free_request(request);
  151. return rc;
  152. }
  153. int
  154. tape_std_terminate_write(struct tape_device *device)
  155. {
  156. int rc;
  157. if(device->required_tapemarks == 0)
  158. return 0;
  159. DBF_LH(5, "tape%d: terminate write %dxEOF\n", device->first_minor,
  160. device->required_tapemarks);
  161. rc = tape_mtop(device, MTWEOF, device->required_tapemarks);
  162. if (rc)
  163. return rc;
  164. device->required_tapemarks = 0;
  165. return tape_mtop(device, MTBSR, 1);
  166. }
  167. /*
  168. * MTLOAD: Loads the tape.
  169. * The default implementation just wait until the tape medium state changes
  170. * to MS_LOADED.
  171. */
  172. int
  173. tape_std_mtload(struct tape_device *device, int count)
  174. {
  175. return wait_event_interruptible(device->state_change_wq,
  176. (device->medium_state == MS_LOADED));
  177. }
  178. /*
  179. * MTSETBLK: Set block size.
  180. */
  181. int
  182. tape_std_mtsetblk(struct tape_device *device, int count)
  183. {
  184. struct idal_buffer *new;
  185. DBF_LH(6, "tape_std_mtsetblk(%d)\n", count);
  186. if (count <= 0) {
  187. /*
  188. * Just set block_size to 0. tapechar_read/tapechar_write
  189. * will realloc the idal buffer if a bigger one than the
  190. * current is needed.
  191. */
  192. device->char_data.block_size = 0;
  193. return 0;
  194. }
  195. if (device->char_data.idal_buf != NULL &&
  196. device->char_data.idal_buf->size == count)
  197. /* We already have a idal buffer of that size. */
  198. return 0;
  199. if (count > MAX_BLOCKSIZE) {
  200. DBF_EVENT(3, "Invalid block size (%d > %d) given.\n",
  201. count, MAX_BLOCKSIZE);
  202. return -EINVAL;
  203. }
  204. /* Allocate a new idal buffer. */
  205. new = idal_buffer_alloc(count, 0);
  206. if (IS_ERR(new))
  207. return -ENOMEM;
  208. if (device->char_data.idal_buf != NULL)
  209. idal_buffer_free(device->char_data.idal_buf);
  210. device->char_data.idal_buf = new;
  211. device->char_data.block_size = count;
  212. DBF_LH(6, "new blocksize is %d\n", device->char_data.block_size);
  213. return 0;
  214. }
  215. /*
  216. * MTRESET: Set block size to 0.
  217. */
  218. int
  219. tape_std_mtreset(struct tape_device *device, int count)
  220. {
  221. DBF_EVENT(6, "TCHAR:devreset:\n");
  222. device->char_data.block_size = 0;
  223. return 0;
  224. }
  225. /*
  226. * MTFSF: Forward space over 'count' file marks. The tape is positioned
  227. * at the EOT (End of Tape) side of the file mark.
  228. */
  229. int
  230. tape_std_mtfsf(struct tape_device *device, int mt_count)
  231. {
  232. struct tape_request *request;
  233. struct ccw1 *ccw;
  234. request = tape_alloc_request(mt_count + 2, 0);
  235. if (IS_ERR(request))
  236. return PTR_ERR(request);
  237. request->op = TO_FSF;
  238. /* setup ccws */
  239. ccw = tape_ccw_cc(request->cpaddr, MODE_SET_DB, 1,
  240. device->modeset_byte);
  241. ccw = tape_ccw_repeat(ccw, FORSPACEFILE, mt_count);
  242. ccw = tape_ccw_end(ccw, NOP, 0, NULL);
  243. /* execute it */
  244. return tape_do_io_free(device, request);
  245. }
  246. /*
  247. * MTFSR: Forward space over 'count' tape blocks (blocksize is set
  248. * via MTSETBLK.
  249. */
  250. int
  251. tape_std_mtfsr(struct tape_device *device, int mt_count)
  252. {
  253. struct tape_request *request;
  254. struct ccw1 *ccw;
  255. int rc;
  256. request = tape_alloc_request(mt_count + 2, 0);
  257. if (IS_ERR(request))
  258. return PTR_ERR(request);
  259. request->op = TO_FSB;
  260. /* setup ccws */
  261. ccw = tape_ccw_cc(request->cpaddr, MODE_SET_DB, 1,
  262. device->modeset_byte);
  263. ccw = tape_ccw_repeat(ccw, FORSPACEBLOCK, mt_count);
  264. ccw = tape_ccw_end(ccw, NOP, 0, NULL);
  265. /* execute it */
  266. rc = tape_do_io(device, request);
  267. if (rc == 0 && request->rescnt > 0) {
  268. DBF_LH(3, "FSR over tapemark\n");
  269. rc = 1;
  270. }
  271. tape_free_request(request);
  272. return rc;
  273. }
  274. /*
  275. * MTBSR: Backward space over 'count' tape blocks.
  276. * (blocksize is set via MTSETBLK.
  277. */
  278. int
  279. tape_std_mtbsr(struct tape_device *device, int mt_count)
  280. {
  281. struct tape_request *request;
  282. struct ccw1 *ccw;
  283. int rc;
  284. request = tape_alloc_request(mt_count + 2, 0);
  285. if (IS_ERR(request))
  286. return PTR_ERR(request);
  287. request->op = TO_BSB;
  288. /* setup ccws */
  289. ccw = tape_ccw_cc(request->cpaddr, MODE_SET_DB, 1,
  290. device->modeset_byte);
  291. ccw = tape_ccw_repeat(ccw, BACKSPACEBLOCK, mt_count);
  292. ccw = tape_ccw_end(ccw, NOP, 0, NULL);
  293. /* execute it */
  294. rc = tape_do_io(device, request);
  295. if (rc == 0 && request->rescnt > 0) {
  296. DBF_LH(3, "BSR over tapemark\n");
  297. rc = 1;
  298. }
  299. tape_free_request(request);
  300. return rc;
  301. }
  302. /*
  303. * MTWEOF: Write 'count' file marks at the current position.
  304. */
  305. int
  306. tape_std_mtweof(struct tape_device *device, int mt_count)
  307. {
  308. struct tape_request *request;
  309. struct ccw1 *ccw;
  310. request = tape_alloc_request(mt_count + 2, 0);
  311. if (IS_ERR(request))
  312. return PTR_ERR(request);
  313. request->op = TO_WTM;
  314. /* setup ccws */
  315. ccw = tape_ccw_cc(request->cpaddr, MODE_SET_DB, 1,
  316. device->modeset_byte);
  317. ccw = tape_ccw_repeat(ccw, WRITETAPEMARK, mt_count);
  318. ccw = tape_ccw_end(ccw, NOP, 0, NULL);
  319. /* execute it */
  320. return tape_do_io_free(device, request);
  321. }
  322. /*
  323. * MTBSFM: Backward space over 'count' file marks.
  324. * The tape is positioned at the BOT (Begin Of Tape) side of the
  325. * last skipped file mark.
  326. */
  327. int
  328. tape_std_mtbsfm(struct tape_device *device, int mt_count)
  329. {
  330. struct tape_request *request;
  331. struct ccw1 *ccw;
  332. request = tape_alloc_request(mt_count + 2, 0);
  333. if (IS_ERR(request))
  334. return PTR_ERR(request);
  335. request->op = TO_BSF;
  336. /* setup ccws */
  337. ccw = tape_ccw_cc(request->cpaddr, MODE_SET_DB, 1,
  338. device->modeset_byte);
  339. ccw = tape_ccw_repeat(ccw, BACKSPACEFILE, mt_count);
  340. ccw = tape_ccw_end(ccw, NOP, 0, NULL);
  341. /* execute it */
  342. return tape_do_io_free(device, request);
  343. }
  344. /*
  345. * MTBSF: Backward space over 'count' file marks. The tape is positioned at
  346. * the EOT (End of Tape) side of the last skipped file mark.
  347. */
  348. int
  349. tape_std_mtbsf(struct tape_device *device, int mt_count)
  350. {
  351. struct tape_request *request;
  352. struct ccw1 *ccw;
  353. int rc;
  354. request = tape_alloc_request(mt_count + 2, 0);
  355. if (IS_ERR(request))
  356. return PTR_ERR(request);
  357. request->op = TO_BSF;
  358. /* setup ccws */
  359. ccw = tape_ccw_cc(request->cpaddr, MODE_SET_DB, 1,
  360. device->modeset_byte);
  361. ccw = tape_ccw_repeat(ccw, BACKSPACEFILE, mt_count);
  362. ccw = tape_ccw_end(ccw, NOP, 0, NULL);
  363. /* execute it */
  364. rc = tape_do_io_free(device, request);
  365. if (rc == 0) {
  366. rc = tape_mtop(device, MTFSR, 1);
  367. if (rc > 0)
  368. rc = 0;
  369. }
  370. return rc;
  371. }
  372. /*
  373. * MTFSFM: Forward space over 'count' file marks.
  374. * The tape is positioned at the BOT (Begin Of Tape) side
  375. * of the last skipped file mark.
  376. */
  377. int
  378. tape_std_mtfsfm(struct tape_device *device, int mt_count)
  379. {
  380. struct tape_request *request;
  381. struct ccw1 *ccw;
  382. int rc;
  383. request = tape_alloc_request(mt_count + 2, 0);
  384. if (IS_ERR(request))
  385. return PTR_ERR(request);
  386. request->op = TO_FSF;
  387. /* setup ccws */
  388. ccw = tape_ccw_cc(request->cpaddr, MODE_SET_DB, 1,
  389. device->modeset_byte);
  390. ccw = tape_ccw_repeat(ccw, FORSPACEFILE, mt_count);
  391. ccw = tape_ccw_end(ccw, NOP, 0, NULL);
  392. /* execute it */
  393. rc = tape_do_io_free(device, request);
  394. if (rc == 0) {
  395. rc = tape_mtop(device, MTBSR, 1);
  396. if (rc > 0)
  397. rc = 0;
  398. }
  399. return rc;
  400. }
  401. /*
  402. * MTREW: Rewind the tape.
  403. */
  404. int
  405. tape_std_mtrew(struct tape_device *device, int mt_count)
  406. {
  407. struct tape_request *request;
  408. request = tape_alloc_request(3, 0);
  409. if (IS_ERR(request))
  410. return PTR_ERR(request);
  411. request->op = TO_REW;
  412. /* setup ccws */
  413. tape_ccw_cc(request->cpaddr, MODE_SET_DB, 1,
  414. device->modeset_byte);
  415. tape_ccw_cc(request->cpaddr + 1, REWIND, 0, NULL);
  416. tape_ccw_end(request->cpaddr + 2, NOP, 0, NULL);
  417. /* execute it */
  418. return tape_do_io_free(device, request);
  419. }
  420. /*
  421. * MTOFFL: Rewind the tape and put the drive off-line.
  422. * Implement 'rewind unload'
  423. */
  424. int
  425. tape_std_mtoffl(struct tape_device *device, int mt_count)
  426. {
  427. struct tape_request *request;
  428. request = tape_alloc_request(3, 0);
  429. if (IS_ERR(request))
  430. return PTR_ERR(request);
  431. request->op = TO_RUN;
  432. /* setup ccws */
  433. tape_ccw_cc(request->cpaddr, MODE_SET_DB, 1, device->modeset_byte);
  434. tape_ccw_cc(request->cpaddr + 1, REWIND_UNLOAD, 0, NULL);
  435. tape_ccw_end(request->cpaddr + 2, NOP, 0, NULL);
  436. /* execute it */
  437. return tape_do_io_free(device, request);
  438. }
  439. /*
  440. * MTNOP: 'No operation'.
  441. */
  442. int
  443. tape_std_mtnop(struct tape_device *device, int mt_count)
  444. {
  445. struct tape_request *request;
  446. request = tape_alloc_request(2, 0);
  447. if (IS_ERR(request))
  448. return PTR_ERR(request);
  449. request->op = TO_NOP;
  450. /* setup ccws */
  451. tape_ccw_cc(request->cpaddr, MODE_SET_DB, 1, device->modeset_byte);
  452. tape_ccw_end(request->cpaddr + 1, NOP, 0, NULL);
  453. /* execute it */
  454. return tape_do_io_free(device, request);
  455. }
  456. /*
  457. * MTEOM: positions at the end of the portion of the tape already used
  458. * for recordind data. MTEOM positions after the last file mark, ready for
  459. * appending another file.
  460. */
  461. int
  462. tape_std_mteom(struct tape_device *device, int mt_count)
  463. {
  464. int rc;
  465. /*
  466. * Seek from the beginning of tape (rewind).
  467. */
  468. if ((rc = tape_mtop(device, MTREW, 1)) < 0)
  469. return rc;
  470. /*
  471. * The logical end of volume is given by two sewuential tapemarks.
  472. * Look for this by skipping to the next file (over one tapemark)
  473. * and then test for another one (fsr returns 1 if a tapemark was
  474. * encountered).
  475. */
  476. do {
  477. if ((rc = tape_mtop(device, MTFSF, 1)) < 0)
  478. return rc;
  479. if ((rc = tape_mtop(device, MTFSR, 1)) < 0)
  480. return rc;
  481. } while (rc == 0);
  482. return tape_mtop(device, MTBSR, 1);
  483. }
  484. /*
  485. * MTRETEN: Retension the tape, i.e. forward space to end of tape and rewind.
  486. */
  487. int
  488. tape_std_mtreten(struct tape_device *device, int mt_count)
  489. {
  490. struct tape_request *request;
  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. 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);