tape_std.c 19 KB

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