tape_std.c 19 KB

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