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