| 1 |
// SPDX-License-Identifier: GPL-2.0 |
| 2 |
/* |
| 3 |
* tape device discipline for 3490 tapes. |
| 4 |
* |
| 5 |
* Copyright IBM Corp. 2001, 2009 |
| 6 |
* Author(s): Carsten Otte <[email protected]> |
| 7 |
* Tuan Ngo-Anh <[email protected]> |
| 8 |
* Martin Schwidefsky <[email protected]> |
| 9 |
*/ |
| 10 |
|
| 11 |
#define pr_fmt(fmt) "tape_3490: " fmt |
| 12 |
|
| 13 |
#include <linux/export.h> |
| 14 |
#include <linux/module.h> |
| 15 |
#include <linux/init.h> |
| 16 |
#include <linux/bio.h> |
| 17 |
#include <linux/workqueue.h> |
| 18 |
#include <linux/slab.h> |
| 19 |
|
| 20 |
#define TAPE_DBF_AREA tape_3490_dbf |
| 21 |
|
| 22 |
#include "tape.h" |
| 23 |
#include "tape_std.h" |
| 24 |
|
| 25 |
/* |
| 26 |
* Pointer to debug area. |
| 27 |
*/ |
| 28 |
debug_info_t *TAPE_DBF_AREA = NULL; |
| 29 |
EXPORT_SYMBOL(TAPE_DBF_AREA); |
| 30 |
|
| 31 |
struct tape_3490_block_id { |
| 32 |
unsigned int unused : 10; |
| 33 |
unsigned int block : 22; |
| 34 |
}; |
| 35 |
|
| 36 |
/* |
| 37 |
* Medium sense for 3490 tapes. There is no 'real' medium sense call. |
| 38 |
* So we just do a normal sense. |
| 39 |
*/ |
| 40 |
static void __tape_3490_medium_sense(struct tape_request *request) |
| 41 |
{ |
| 42 |
struct tape_device *device = request->device; |
| 43 |
unsigned char *sense; |
| 44 |
|
| 45 |
if (request->rc == 0) { |
| 46 |
sense = request->cpdata; |
| 47 |
|
| 48 |
/* |
| 49 |
* This isn't quite correct. But since INTERVENTION_REQUIRED |
| 50 |
* means that the drive is 'neither ready nor on-line' it is |
| 51 |
* only slightly inaccurate to say there is no tape loaded if |
| 52 |
* the drive isn't online... |
| 53 |
*/ |
| 54 |
if (sense[0] & SENSE_INTERVENTION_REQUIRED) |
| 55 |
tape_med_state_set(device, MS_UNLOADED); |
| 56 |
else |
| 57 |
tape_med_state_set(device, MS_LOADED); |
| 58 |
|
| 59 |
if (sense[1] & SENSE_WRITE_PROTECT) |
| 60 |
device->tape_generic_status |= GMT_WR_PROT(~0); |
| 61 |
else |
| 62 |
device->tape_generic_status &= ~GMT_WR_PROT(~0); |
| 63 |
} else |
| 64 |
DBF_EVENT(4, "tape_3490: medium sense failed with rc=%d\n", |
| 65 |
request->rc); |
| 66 |
tape_free_request(request); |
| 67 |
} |
| 68 |
|
| 69 |
static int tape_3490_medium_sense(struct tape_device *device) |
| 70 |
{ |
| 71 |
struct tape_request *request; |
| 72 |
int rc; |
| 73 |
|
| 74 |
request = tape_alloc_request(1, 32); |
| 75 |
if (IS_ERR(request)) { |
| 76 |
DBF_EXCEPTION(6, "MSEN fail\n"); |
| 77 |
return PTR_ERR(request); |
| 78 |
} |
| 79 |
|
| 80 |
request->op = TO_MSEN; |
| 81 |
tape_ccw_end(request->cpaddr, SENSE, 32, request->cpdata); |
| 82 |
rc = tape_do_io_interruptible(device, request); |
| 83 |
__tape_3490_medium_sense(request); |
| 84 |
return rc; |
| 85 |
} |
| 86 |
|
| 87 |
static void tape_3490_medium_sense_async(struct tape_device *device) |
| 88 |
{ |
| 89 |
struct tape_request *request; |
| 90 |
|
| 91 |
request = tape_alloc_request(1, 32); |
| 92 |
if (IS_ERR(request)) { |
| 93 |
DBF_EXCEPTION(6, "MSEN fail\n"); |
| 94 |
return; |
| 95 |
} |
| 96 |
|
| 97 |
request->op = TO_MSEN; |
| 98 |
tape_ccw_end(request->cpaddr, SENSE, 32, request->cpdata); |
| 99 |
request->callback = (void *) __tape_3490_medium_sense; |
| 100 |
request->callback_data = NULL; |
| 101 |
tape_do_io_async(device, request); |
| 102 |
} |
| 103 |
|
| 104 |
struct tape_3490_work { |
| 105 |
struct tape_device *device; |
| 106 |
enum tape_op op; |
| 107 |
struct work_struct work; |
| 108 |
}; |
| 109 |
|
| 110 |
/* |
| 111 |
* These functions are currently used only to schedule a medium_sense for |
| 112 |
* later execution. This is because we get an interrupt whenever a medium |
| 113 |
* is inserted but cannot call tape_do_io* from an interrupt context. |
| 114 |
* Maybe that's useful for other actions we want to start from the |
| 115 |
* interrupt handler. |
| 116 |
* Note: the work handler is called by the system work queue. The tape |
| 117 |
* commands started by the handler need to be asynchrounous, otherwise |
| 118 |
* a deadlock can occur e.g. in case of a deferred cc=1 (see __tape_do_irq). |
| 119 |
*/ |
| 120 |
static void |
| 121 |
tape_3490_work_handler(struct work_struct *work) |
| 122 |
{ |
| 123 |
struct tape_3490_work *p = |
| 124 |
container_of(work, struct tape_3490_work, work); |
| 125 |
struct tape_device *device = p->device; |
| 126 |
|
| 127 |
switch(p->op) { |
| 128 |
case TO_MSEN: |
| 129 |
tape_3490_medium_sense_async(device); |
| 130 |
break; |
| 131 |
default: |
| 132 |
DBF_EVENT(3, "T3490: internal error: unknown work\n"); |
| 133 |
} |
| 134 |
tape_put_device(device); |
| 135 |
kfree(p); |
| 136 |
} |
| 137 |
|
| 138 |
static int |
| 139 |
tape_3490_schedule_work(struct tape_device *device, enum tape_op op) |
| 140 |
{ |
| 141 |
struct tape_3490_work *p; |
| 142 |
|
| 143 |
if ((p = kzalloc_obj(*p, GFP_ATOMIC)) == NULL) |
| 144 |
return -ENOMEM; |
| 145 |
|
| 146 |
INIT_WORK(&p->work, tape_3490_work_handler); |
| 147 |
|
| 148 |
p->device = tape_get_device(device); |
| 149 |
p->op = op; |
| 150 |
|
| 151 |
schedule_work(&p->work); |
| 152 |
return 0; |
| 153 |
} |
| 154 |
|
| 155 |
/* |
| 156 |
* Done Handler is called when dev stat = DEVICE-END (successful operation) |
| 157 |
*/ |
| 158 |
static inline int |
| 159 |
tape_3490_done(struct tape_request *request) |
| 160 |
{ |
| 161 |
DBF_EVENT(6, "%s done\n", tape_op_verbose[request->op]); |
| 162 |
return TAPE_IO_SUCCESS; |
| 163 |
} |
| 164 |
|
| 165 |
static inline int |
| 166 |
tape_3490_erp_failed(struct tape_request *request, int rc) |
| 167 |
{ |
| 168 |
DBF_EVENT(3, "Error recovery failed for %s (RC=%d)\n", |
| 169 |
tape_op_verbose[request->op], rc); |
| 170 |
return rc; |
| 171 |
} |
| 172 |
|
| 173 |
static inline int |
| 174 |
tape_3490_erp_succeeded(struct tape_request *request) |
| 175 |
{ |
| 176 |
DBF_EVENT(3, "Error Recovery successful for %s\n", |
| 177 |
tape_op_verbose[request->op]); |
| 178 |
return tape_3490_done(request); |
| 179 |
} |
| 180 |
|
| 181 |
static inline int |
| 182 |
tape_3490_erp_retry(struct tape_request *request) |
| 183 |
{ |
| 184 |
DBF_EVENT(3, "xerp retr %s\n", tape_op_verbose[request->op]); |
| 185 |
return TAPE_IO_RETRY; |
| 186 |
} |
| 187 |
|
| 188 |
/* |
| 189 |
* This function is called, when no request is outstanding and we get an |
| 190 |
* interrupt |
| 191 |
*/ |
| 192 |
static int |
| 193 |
tape_3490_unsolicited_irq(struct tape_device *device, struct irb *irb) |
| 194 |
{ |
| 195 |
if (irb->scsw.cmd.dstat == 0x85) { /* READY */ |
| 196 |
/* A medium was inserted in the drive. */ |
| 197 |
DBF_EVENT(6, "xuud med\n"); |
| 198 |
tape_3490_schedule_work(device, TO_MSEN); |
| 199 |
} else { |
| 200 |
DBF_EVENT(3, "unsol.irq! dev end: %08x\n", device->cdev_id); |
| 201 |
tape_dump_sense_dbf(device, NULL, irb); |
| 202 |
} |
| 203 |
return TAPE_IO_SUCCESS; |
| 204 |
} |
| 205 |
|
| 206 |
static int |
| 207 |
tape_3490_erp_bug(struct tape_device *device, struct tape_request *request, |
| 208 |
struct irb *irb, int no) |
| 209 |
{ |
| 210 |
if (request->op != TO_ASSIGN) { |
| 211 |
dev_err(&device->cdev->dev, "An unexpected condition %d " |
| 212 |
"occurred in tape error recovery\n", no); |
| 213 |
tape_dump_sense_dbf(device, request, irb); |
| 214 |
} |
| 215 |
return tape_3490_erp_failed(request, -EIO); |
| 216 |
} |
| 217 |
|
| 218 |
/* |
| 219 |
* Handle data overrun between cu and drive. The channel speed might |
| 220 |
* be too slow. |
| 221 |
*/ |
| 222 |
static int |
| 223 |
tape_3490_erp_overrun(struct tape_device *device, struct tape_request *request, |
| 224 |
struct irb *irb) |
| 225 |
{ |
| 226 |
if (irb->ecw[3] == 0x40) { |
| 227 |
dev_warn (&device->cdev->dev, "A data overrun occurred between" |
| 228 |
" the control unit and tape unit\n"); |
| 229 |
return tape_3490_erp_failed(request, -EIO); |
| 230 |
} |
| 231 |
return tape_3490_erp_bug(device, request, irb, -1); |
| 232 |
} |
| 233 |
|
| 234 |
/* |
| 235 |
* Handle record sequence error. |
| 236 |
*/ |
| 237 |
static int |
| 238 |
tape_3490_erp_sequence(struct tape_device *device, |
| 239 |
struct tape_request *request, struct irb *irb) |
| 240 |
{ |
| 241 |
if (irb->ecw[3] == 0x41) { |
| 242 |
/* |
| 243 |
* cu detected incorrect block-id sequence on tape. |
| 244 |
*/ |
| 245 |
dev_warn (&device->cdev->dev, "The block ID sequence on the " |
| 246 |
"tape is incorrect\n"); |
| 247 |
return tape_3490_erp_failed(request, -EIO); |
| 248 |
} |
| 249 |
/* |
| 250 |
* Record sequence error bit is set, but erpa does not |
| 251 |
* show record sequence error. |
| 252 |
*/ |
| 253 |
return tape_3490_erp_bug(device, request, irb, -2); |
| 254 |
} |
| 255 |
|
| 256 |
/* |
| 257 |
* This function analyses the tape's sense-data in case of a unit-check. |
| 258 |
* If possible, it tries to recover from the error. Else the user is |
| 259 |
* informed about the problem. |
| 260 |
*/ |
| 261 |
static int |
| 262 |
tape_3490_unit_check(struct tape_device *device, struct tape_request *request, |
| 263 |
struct irb *irb) |
| 264 |
{ |
| 265 |
int inhibit_cu_recovery; |
| 266 |
__u8* sense; |
| 267 |
|
| 268 |
inhibit_cu_recovery = (*device->modeset_byte & 0x80) ? 1 : 0; |
| 269 |
sense = irb->ecw; |
| 270 |
|
| 271 |
if ( |
| 272 |
sense[0] & SENSE_COMMAND_REJECT && |
| 273 |
sense[1] & SENSE_WRITE_PROTECT |
| 274 |
) { |
| 275 |
if ( |
| 276 |
request->op == TO_DSE || |
| 277 |
request->op == TO_WRI || |
| 278 |
request->op == TO_WTM |
| 279 |
) { |
| 280 |
/* medium is write protected */ |
| 281 |
return tape_3490_erp_failed(request, -EACCES); |
| 282 |
} else { |
| 283 |
return tape_3490_erp_bug(device, request, irb, -3); |
| 284 |
} |
| 285 |
} |
| 286 |
|
| 287 |
/* |
| 288 |
* Special cases for various tape-states when reaching |
| 289 |
* end of recorded area |
| 290 |
* |
| 291 |
* FIXME: Maybe a special case of the special case: |
| 292 |
* sense[0] == SENSE_EQUIPMENT_CHECK && |
| 293 |
* sense[1] == SENSE_DRIVE_ONLINE && |
| 294 |
* sense[3] == 0x47 (Volume Fenced) |
| 295 |
* |
| 296 |
* This was caused by continued FSF or FSR after an |
| 297 |
* 'End Of Data'. |
| 298 |
*/ |
| 299 |
if (( |
| 300 |
sense[0] == SENSE_DATA_CHECK || |
| 301 |
sense[0] == SENSE_EQUIPMENT_CHECK || |
| 302 |
sense[0] == (SENSE_EQUIPMENT_CHECK | SENSE_DEFERRED_UNIT_CHECK) |
| 303 |
) && ( |
| 304 |
sense[1] == SENSE_DRIVE_ONLINE || |
| 305 |
sense[1] == (SENSE_BEGINNING_OF_TAPE | SENSE_WRITE_MODE) |
| 306 |
)) { |
| 307 |
switch (request->op) { |
| 308 |
/* |
| 309 |
* sense[0] == SENSE_DATA_CHECK && |
| 310 |
* sense[1] == SENSE_DRIVE_ONLINE |
| 311 |
* sense[3] == 0x36 (End Of Data) |
| 312 |
* |
| 313 |
* Further seeks might return a 'Volume Fenced'. |
| 314 |
*/ |
| 315 |
case TO_FSF: |
| 316 |
case TO_FSB: |
| 317 |
/* Trying to seek beyond end of recorded area */ |
| 318 |
return tape_3490_erp_failed(request, -ENOSPC); |
| 319 |
case TO_BSB: |
| 320 |
return tape_3490_erp_retry(request); |
| 321 |
|
| 322 |
/* |
| 323 |
* sense[0] == SENSE_DATA_CHECK && |
| 324 |
* sense[1] == SENSE_DRIVE_ONLINE && |
| 325 |
* sense[3] == 0x36 (End Of Data) |
| 326 |
*/ |
| 327 |
case TO_LBL: |
| 328 |
/* Block could not be located. */ |
| 329 |
return tape_3490_erp_failed(request, -EIO); |
| 330 |
|
| 331 |
case TO_RFO: |
| 332 |
/* Read beyond end of recorded area -> 0 bytes read */ |
| 333 |
return tape_3490_erp_failed(request, 0); |
| 334 |
|
| 335 |
/* |
| 336 |
* sense[0] == SENSE_EQUIPMENT_CHECK && |
| 337 |
* sense[1] == SENSE_DRIVE_ONLINE && |
| 338 |
* sense[3] == 0x38 (Physical End Of Volume) |
| 339 |
*/ |
| 340 |
case TO_WRI: |
| 341 |
/* Writing at physical end of volume */ |
| 342 |
return tape_3490_erp_failed(request, -ENOSPC); |
| 343 |
default: |
| 344 |
return tape_3490_erp_failed(request, 0); |
| 345 |
} |
| 346 |
} |
| 347 |
|
| 348 |
/* Sensing special bits */ |
| 349 |
if (sense[0] & SENSE_BUS_OUT_CHECK) |
| 350 |
return tape_3490_erp_retry(request); |
| 351 |
|
| 352 |
if (sense[0] & SENSE_DATA_CHECK) { |
| 353 |
/* |
| 354 |
* hardware failure, damaged tape or improper |
| 355 |
* operating conditions |
| 356 |
*/ |
| 357 |
switch (sense[3]) { |
| 358 |
case 0x23: |
| 359 |
/* a read data check occurred */ |
| 360 |
if ((sense[2] & SENSE_TAPE_SYNC_MODE) || |
| 361 |
inhibit_cu_recovery) |
| 362 |
// data check is not permanent, may be |
| 363 |
// recovered. We always use async-mode with |
| 364 |
// cu-recovery, so this should *never* happen. |
| 365 |
return tape_3490_erp_bug(device, request, |
| 366 |
irb, -4); |
| 367 |
|
| 368 |
/* data check is permanent, CU recovery has failed */ |
| 369 |
dev_warn (&device->cdev->dev, "A read error occurred " |
| 370 |
"that cannot be recovered\n"); |
| 371 |
return tape_3490_erp_failed(request, -EIO); |
| 372 |
case 0x25: |
| 373 |
// a write data check occurred |
| 374 |
if ((sense[2] & SENSE_TAPE_SYNC_MODE) || |
| 375 |
inhibit_cu_recovery) |
| 376 |
// data check is not permanent, may be |
| 377 |
// recovered. We always use async-mode with |
| 378 |
// cu-recovery, so this should *never* happen. |
| 379 |
return tape_3490_erp_bug(device, request, |
| 380 |
irb, -5); |
| 381 |
|
| 382 |
// data check is permanent, cu-recovery has failed |
| 383 |
dev_warn (&device->cdev->dev, "A write error on the " |
| 384 |
"tape cannot be recovered\n"); |
| 385 |
return tape_3490_erp_failed(request, -EIO); |
| 386 |
case 0x28: |
| 387 |
/* ID-Mark at tape start couldn't be written */ |
| 388 |
dev_warn (&device->cdev->dev, "Writing the ID-mark " |
| 389 |
"failed\n"); |
| 390 |
return tape_3490_erp_failed(request, -EIO); |
| 391 |
case 0x31: |
| 392 |
/* Tape void. Tried to read beyond end of device. */ |
| 393 |
dev_warn (&device->cdev->dev, "Reading the tape beyond" |
| 394 |
" the end of the recorded area failed\n"); |
| 395 |
return tape_3490_erp_failed(request, -ENOSPC); |
| 396 |
case 0x41: |
| 397 |
/* Record sequence error. */ |
| 398 |
dev_warn (&device->cdev->dev, "The tape contains an " |
| 399 |
"incorrect block ID sequence\n"); |
| 400 |
return tape_3490_erp_failed(request, -EIO); |
| 401 |
} |
| 402 |
} |
| 403 |
|
| 404 |
if (sense[0] & SENSE_OVERRUN) |
| 405 |
return tape_3490_erp_overrun(device, request, irb); |
| 406 |
|
| 407 |
if (sense[1] & SENSE_RECORD_SEQUENCE_ERR) |
| 408 |
return tape_3490_erp_sequence(device, request, irb); |
| 409 |
|
| 410 |
/* Sensing erpa codes */ |
| 411 |
switch (sense[3]) { |
| 412 |
case 0x00: |
| 413 |
/* Unit check with erpa code 0. Report and ignore. */ |
| 414 |
return TAPE_IO_SUCCESS; |
| 415 |
case 0x27: |
| 416 |
/* |
| 417 |
* Command reject. May indicate illegal channel program or |
| 418 |
* buffer over/underrun. Since all channel programs are |
| 419 |
* issued by this driver and ought be correct, we assume a |
| 420 |
* over/underrun situation and retry the channel program. |
| 421 |
*/ |
| 422 |
return tape_3490_erp_retry(request); |
| 423 |
case 0x29: |
| 424 |
/* |
| 425 |
* Function incompatible. Either the tape is idrc compressed |
| 426 |
* but the hardware isn't capable to do idrc, or a perform |
| 427 |
* subsystem func is issued and the CU is not on-line. |
| 428 |
*/ |
| 429 |
return tape_3490_erp_failed(request, -EIO); |
| 430 |
case 0x2b: |
| 431 |
/* |
| 432 |
* Environmental data present. Indicates either unload |
| 433 |
* completed ok or read buffered log command completed ok. |
| 434 |
*/ |
| 435 |
if (request->op == TO_RUN) { |
| 436 |
/* Rewind unload completed ok. */ |
| 437 |
tape_med_state_set(device, MS_UNLOADED); |
| 438 |
return tape_3490_erp_succeeded(request); |
| 439 |
} |
| 440 |
/* tape_3490 doesn't use read buffered log commands. */ |
| 441 |
return tape_3490_erp_bug(device, request, irb, sense[3]); |
| 442 |
case 0x2c: |
| 443 |
/* |
| 444 |
* Permanent equipment check. CU has tried recovery, but |
| 445 |
* did not succeed. |
| 446 |
*/ |
| 447 |
return tape_3490_erp_failed(request, -EIO); |
| 448 |
case 0x2d: |
| 449 |
/* Data security erase failure. */ |
| 450 |
if (request->op == TO_DSE) |
| 451 |
return tape_3490_erp_failed(request, -EIO); |
| 452 |
/* Data security erase failure, but no such command issued. */ |
| 453 |
return tape_3490_erp_bug(device, request, irb, sense[3]); |
| 454 |
case 0x2e: |
| 455 |
/* |
| 456 |
* Not capable. This indicates either that the drive fails |
| 457 |
* reading the format id mark or that format specified |
| 458 |
* is not supported by the drive. |
| 459 |
*/ |
| 460 |
dev_warn (&device->cdev->dev, "The tape unit cannot process " |
| 461 |
"the tape format\n"); |
| 462 |
return tape_3490_erp_failed(request, -EMEDIUMTYPE); |
| 463 |
case 0x30: |
| 464 |
/* The medium is write protected. */ |
| 465 |
dev_warn (&device->cdev->dev, "The tape medium is write-" |
| 466 |
"protected\n"); |
| 467 |
return tape_3490_erp_failed(request, -EACCES); |
| 468 |
case 0x35: |
| 469 |
/* |
| 470 |
* Drive equipment check. One of the following: |
| 471 |
* - cu cannot recover from a drive detected error |
| 472 |
* - a check code message is shown on drive display |
| 473 |
* - the cartridge loader does not respond correctly |
| 474 |
* - a failure occurs during an index, load, or unload cycle |
| 475 |
*/ |
| 476 |
dev_warn (&device->cdev->dev, "An equipment check has occurred" |
| 477 |
" on the tape unit\n"); |
| 478 |
return tape_3490_erp_failed(request, -EIO); |
| 479 |
case 0x36: |
| 480 |
/* End of data. */ |
| 481 |
return tape_3490_erp_failed(request, -EIO); |
| 482 |
case 0x38: |
| 483 |
/* |
| 484 |
* Physical end of tape. A read/write operation reached |
| 485 |
* the physical end of tape. |
| 486 |
*/ |
| 487 |
if (request->op==TO_WRI || |
| 488 |
request->op==TO_DSE || |
| 489 |
request->op==TO_WTM) |
| 490 |
return tape_3490_erp_failed(request, -ENOSPC); |
| 491 |
return tape_3490_erp_failed(request, -EIO); |
| 492 |
case 0x39: |
| 493 |
/* Backward at Beginning of tape. */ |
| 494 |
return tape_3490_erp_failed(request, -EIO); |
| 495 |
case 0x42: |
| 496 |
/* |
| 497 |
* Degraded mode. A condition that can cause degraded |
| 498 |
* performance is detected. |
| 499 |
*/ |
| 500 |
dev_warn (&device->cdev->dev, "The tape subsystem is running " |
| 501 |
"in degraded mode\n"); |
| 502 |
return tape_3490_erp_retry(request); |
| 503 |
case 0x43: |
| 504 |
/* Drive not ready. */ |
| 505 |
tape_med_state_set(device, MS_UNLOADED); |
| 506 |
/* Some commands commands are successful even in this case */ |
| 507 |
if (sense[1] & SENSE_DRIVE_ONLINE) { |
| 508 |
switch(request->op) { |
| 509 |
case TO_ASSIGN: |
| 510 |
case TO_UNASSIGN: |
| 511 |
case TO_DIS: |
| 512 |
case TO_NOP: |
| 513 |
return tape_3490_done(request); |
| 514 |
break; |
| 515 |
default: |
| 516 |
break; |
| 517 |
} |
| 518 |
} |
| 519 |
return tape_3490_erp_failed(request, -ENOMEDIUM); |
| 520 |
case 0x44: |
| 521 |
/* Locate Block unsuccessful. */ |
| 522 |
if (request->op != TO_BLOCK && request->op != TO_LBL) |
| 523 |
/* No locate block was issued. */ |
| 524 |
return tape_3490_erp_bug(device, request, |
| 525 |
irb, sense[3]); |
| 526 |
return tape_3490_erp_failed(request, -EIO); |
| 527 |
case 0x45: |
| 528 |
/* The drive is assigned to a different channel path. */ |
| 529 |
dev_warn (&device->cdev->dev, "The tape unit is already " |
| 530 |
"assigned\n"); |
| 531 |
return tape_3490_erp_failed(request, -EIO); |
| 532 |
case 0x47: |
| 533 |
/* Volume fenced. CU reports volume integrity is lost. */ |
| 534 |
dev_warn (&device->cdev->dev, "The control unit has fenced " |
| 535 |
"access to the tape volume\n"); |
| 536 |
return tape_3490_erp_failed(request, -EIO); |
| 537 |
case 0x48: |
| 538 |
/* Log sense data and retry request. */ |
| 539 |
return tape_3490_erp_retry(request); |
| 540 |
case 0x4d: |
| 541 |
/* |
| 542 |
* Resetting event received. Since the driver does |
| 543 |
* not support resetting event recovery (which has to |
| 544 |
* be handled by the I/O Layer), retry our command. |
| 545 |
*/ |
| 546 |
return tape_3490_erp_retry(request); |
| 547 |
case 0x4e: |
| 548 |
/* |
| 549 |
* Maximum block size exceeded. This indicates, that |
| 550 |
* the block to be written is larger than allowed for |
| 551 |
* buffered mode. |
| 552 |
*/ |
| 553 |
dev_warn (&device->cdev->dev, |
| 554 |
"The maximum block size for buffered mode is exceeded\n"); |
| 555 |
return tape_3490_erp_failed(request, -ENOBUFS); |
| 556 |
case 0x50: |
| 557 |
/* |
| 558 |
* Read buffered log (Overflow). CU is running in extended |
| 559 |
* buffered log mode, and a counter overflows. This should |
| 560 |
* never happen, since we're never running in extended |
| 561 |
* buffered log mode. |
| 562 |
*/ |
| 563 |
return tape_3490_erp_retry(request); |
| 564 |
case 0x51: |
| 565 |
/* |
| 566 |
* Read buffered log (EOV). EOF processing occurs while the |
| 567 |
* CU is in extended buffered log mode. This should never |
| 568 |
* happen, since we're never running in extended buffered |
| 569 |
* log mode. |
| 570 |
*/ |
| 571 |
return tape_3490_erp_retry(request); |
| 572 |
case 0x52: |
| 573 |
/* End of Volume complete. Rewind unload completed ok. */ |
| 574 |
if (request->op == TO_RUN) { |
| 575 |
tape_med_state_set(device, MS_UNLOADED); |
| 576 |
return tape_3490_erp_succeeded(request); |
| 577 |
} |
| 578 |
return tape_3490_erp_bug(device, request, irb, sense[3]); |
| 579 |
case 0x53: |
| 580 |
/* Global command intercept. */ |
| 581 |
return tape_3490_erp_retry(request); |
| 582 |
case 0x54: |
| 583 |
/* Channel interface recovery (temporary). */ |
| 584 |
return tape_3490_erp_retry(request); |
| 585 |
case 0x55: |
| 586 |
/* Channel interface recovery (permanent). */ |
| 587 |
dev_warn (&device->cdev->dev, "A channel interface error cannot be" |
| 588 |
" recovered\n"); |
| 589 |
return tape_3490_erp_failed(request, -EIO); |
| 590 |
case 0x56: |
| 591 |
/* Channel protocol error. */ |
| 592 |
dev_warn (&device->cdev->dev, "A channel protocol error " |
| 593 |
"occurred\n"); |
| 594 |
return tape_3490_erp_failed(request, -EIO); |
| 595 |
case 0x57: |
| 596 |
/* Global status intercept. */ |
| 597 |
return tape_3490_erp_retry(request); |
| 598 |
/* The following erpas should have been covered earlier. */ |
| 599 |
case 0x23: /* Read data check. */ |
| 600 |
case 0x25: /* Write data check. */ |
| 601 |
case 0x28: /* Write id mark check. */ |
| 602 |
case 0x31: /* Tape void. */ |
| 603 |
case 0x40: /* Overrun error. */ |
| 604 |
case 0x41: /* Record sequence error. */ |
| 605 |
/* All other erpas are reserved for future use. */ |
| 606 |
default: |
| 607 |
return tape_3490_erp_bug(device, request, irb, sense[3]); |
| 608 |
} |
| 609 |
} |
| 610 |
|
| 611 |
/* |
| 612 |
* 3490 interrupt handler |
| 613 |
*/ |
| 614 |
static int |
| 615 |
tape_3490_irq(struct tape_device *device, struct tape_request *request, |
| 616 |
struct irb *irb) |
| 617 |
{ |
| 618 |
if (request == NULL) |
| 619 |
return tape_3490_unsolicited_irq(device, irb); |
| 620 |
|
| 621 |
if ((irb->scsw.cmd.dstat & DEV_STAT_UNIT_EXCEP) && |
| 622 |
(irb->scsw.cmd.dstat & DEV_STAT_DEV_END) && |
| 623 |
(request->op == TO_WRI)) { |
| 624 |
/* Write at end of volume */ |
| 625 |
return tape_3490_erp_failed(request, -ENOSPC); |
| 626 |
} |
| 627 |
|
| 628 |
if (irb->scsw.cmd.dstat & DEV_STAT_UNIT_CHECK) |
| 629 |
return tape_3490_unit_check(device, request, irb); |
| 630 |
|
| 631 |
if (irb->scsw.cmd.dstat & DEV_STAT_DEV_END) { |
| 632 |
/* |
| 633 |
* A unit exception occurs on skipping over a tapemark block. |
| 634 |
*/ |
| 635 |
if (irb->scsw.cmd.dstat & DEV_STAT_UNIT_EXCEP) { |
| 636 |
if (request->op == TO_BSB || request->op == TO_FSB) |
| 637 |
request->rescnt++; |
| 638 |
else |
| 639 |
DBF_EVENT(5, "Unit Exception!\n"); |
| 640 |
} |
| 641 |
return tape_3490_done(request); |
| 642 |
} |
| 643 |
|
| 644 |
DBF_EVENT(6, "xunknownirq\n"); |
| 645 |
tape_dump_sense_dbf(device, request, irb); |
| 646 |
return TAPE_IO_STOP; |
| 647 |
} |
| 648 |
|
| 649 |
static int |
| 650 |
tape_3490_setup_device(struct tape_device * device) |
| 651 |
{ |
| 652 |
int rc; |
| 653 |
|
| 654 |
DBF_EVENT(6, "3490 device setup\n"); |
| 655 |
if ((rc = tape_std_assign(device)) == 0) { |
| 656 |
if ((rc = tape_3490_medium_sense(device)) != 0) { |
| 657 |
DBF_LH(3, "3490 medium sense returned %d\n", rc); |
| 658 |
} |
| 659 |
} |
| 660 |
return rc; |
| 661 |
} |
| 662 |
|
| 663 |
static void |
| 664 |
tape_3490_cleanup_device(struct tape_device *device) |
| 665 |
{ |
| 666 |
tape_std_unassign(device); |
| 667 |
} |
| 668 |
|
| 669 |
|
| 670 |
/* |
| 671 |
* MTTELL: Tell block. Return the number of block relative to current file. |
| 672 |
*/ |
| 673 |
static int |
| 674 |
tape_3490_mttell(struct tape_device *device, int mt_count) |
| 675 |
{ |
| 676 |
struct { |
| 677 |
struct tape_3490_block_id cbid; |
| 678 |
struct tape_3490_block_id dbid; |
| 679 |
} __attribute__ ((packed)) block_id; |
| 680 |
int rc; |
| 681 |
|
| 682 |
rc = tape_std_read_block_id(device, (__u64 *) &block_id); |
| 683 |
if (rc) |
| 684 |
return rc; |
| 685 |
|
| 686 |
return block_id.cbid.block; |
| 687 |
} |
| 688 |
|
| 689 |
/* |
| 690 |
* MTSEEK: seek to the specified block. |
| 691 |
*/ |
| 692 |
static int |
| 693 |
tape_3490_mtseek(struct tape_device *device, int mt_count) |
| 694 |
{ |
| 695 |
struct tape_request *request; |
| 696 |
struct tape_3490_block_id * bid; |
| 697 |
|
| 698 |
if (mt_count > 0x3fffff) { |
| 699 |
DBF_EXCEPTION(6, "xsee parm\n"); |
| 700 |
return -EINVAL; |
| 701 |
} |
| 702 |
request = tape_alloc_request(3, 4); |
| 703 |
if (IS_ERR(request)) |
| 704 |
return PTR_ERR(request); |
| 705 |
|
| 706 |
/* setup ccws */ |
| 707 |
request->op = TO_LBL; |
| 708 |
bid = (struct tape_3490_block_id *) request->cpdata; |
| 709 |
bid->block = mt_count; |
| 710 |
|
| 711 |
tape_ccw_cc(request->cpaddr, MODE_SET_DB, 1, device->modeset_byte); |
| 712 |
tape_ccw_cc(request->cpaddr + 1, LOCATE, 4, request->cpdata); |
| 713 |
tape_ccw_end(request->cpaddr + 2, NOP, 0, NULL); |
| 714 |
|
| 715 |
/* execute it */ |
| 716 |
return tape_do_io_free(device, request); |
| 717 |
} |
| 718 |
|
| 719 |
/* |
| 720 |
* List of 3490 tape commands. |
| 721 |
*/ |
| 722 |
static tape_mtop_fn tape_3490_mtop[TAPE_NR_MTOPS] = { |
| 723 |
[MTRESET] = tape_std_mtreset, |
| 724 |
[MTFSF] = tape_std_mtfsf, |
| 725 |
[MTBSF] = tape_std_mtbsf, |
| 726 |
[MTFSR] = tape_std_mtfsr, |
| 727 |
[MTBSR] = tape_std_mtbsr, |
| 728 |
[MTWEOF] = tape_std_mtweof, |
| 729 |
[MTREW] = tape_std_mtrew, |
| 730 |
[MTOFFL] = tape_std_mtoffl, |
| 731 |
[MTNOP] = tape_std_mtnop, |
| 732 |
[MTRETEN] = tape_std_mtreten, |
| 733 |
[MTBSFM] = tape_std_mtbsfm, |
| 734 |
[MTFSFM] = tape_std_mtfsfm, |
| 735 |
[MTEOM] = tape_std_mteom, |
| 736 |
[MTERASE] = tape_std_mterase, |
| 737 |
[MTRAS1] = NULL, |
| 738 |
[MTRAS2] = NULL, |
| 739 |
[MTRAS3] = NULL, |
| 740 |
[MTSETBLK] = tape_std_mtsetblk, |
| 741 |
[MTSETDENSITY] = NULL, |
| 742 |
[MTSEEK] = tape_3490_mtseek, |
| 743 |
[MTTELL] = tape_3490_mttell, |
| 744 |
[MTSETDRVBUFFER] = NULL, |
| 745 |
[MTFSS] = NULL, |
| 746 |
[MTBSS] = NULL, |
| 747 |
[MTWSM] = NULL, |
| 748 |
[MTLOCK] = NULL, |
| 749 |
[MTUNLOCK] = NULL, |
| 750 |
[MTLOAD] = tape_std_mtload, |
| 751 |
[MTUNLOAD] = tape_std_mtunload, |
| 752 |
[MTCOMPRESSION] = tape_std_mtcompression, |
| 753 |
[MTSETPART] = NULL, |
| 754 |
[MTMKPART] = NULL |
| 755 |
}; |
| 756 |
|
| 757 |
/* |
| 758 |
* Tape discipline structure for 3490. |
| 759 |
*/ |
| 760 |
static struct tape_discipline tape_discipline_3490 = { |
| 761 |
.owner = THIS_MODULE, |
| 762 |
.setup_device = tape_3490_setup_device, |
| 763 |
.cleanup_device = tape_3490_cleanup_device, |
| 764 |
.process_eov = tape_std_process_eov, |
| 765 |
.irq = tape_3490_irq, |
| 766 |
.read_block = tape_std_read_block, |
| 767 |
.write_block = tape_std_write_block, |
| 768 |
.mtop_array = tape_3490_mtop |
| 769 |
}; |
| 770 |
|
| 771 |
static struct ccw_device_id tape_3490_ids[] = { |
| 772 |
{ CCW_DEVICE_DEVTYPE(0x3490, 0, 0x3490, 0), .driver_info = tape_3490}, |
| 773 |
{ /* end of list */ }, |
| 774 |
}; |
| 775 |
|
| 776 |
static int |
| 777 |
tape_3490_online(struct ccw_device *cdev) |
| 778 |
{ |
| 779 |
return tape_generic_online( |
| 780 |
dev_get_drvdata(&cdev->dev), |
| 781 |
&tape_discipline_3490 |
| 782 |
); |
| 783 |
} |
| 784 |
|
| 785 |
static struct ccw_driver tape_3490_driver = { |
| 786 |
.driver = { |
| 787 |
.name = "tape_34xx", |
| 788 |
.owner = THIS_MODULE, |
| 789 |
}, |
| 790 |
.ids = tape_3490_ids, |
| 791 |
.probe = tape_generic_probe, |
| 792 |
.remove = tape_generic_remove, |
| 793 |
.set_online = tape_3490_online, |
| 794 |
.set_offline = tape_generic_offline, |
| 795 |
.int_class = IRQIO_TAP, |
| 796 |
}; |
| 797 |
|
| 798 |
int tape_3490_init(void) |
| 799 |
{ |
| 800 |
int rc; |
| 801 |
|
| 802 |
TAPE_DBF_AREA = debug_register ( "tape_3490", 2, 2, 4*sizeof(long)); |
| 803 |
debug_register_view(TAPE_DBF_AREA, &debug_sprintf_view); |
| 804 |
#ifdef DBF_LIKE_HELL |
| 805 |
debug_set_level(TAPE_DBF_AREA, 6); |
| 806 |
#endif |
| 807 |
|
| 808 |
DBF_EVENT(3, "3490 init\n"); |
| 809 |
/* Register driver for 3490 tapes. */ |
| 810 |
rc = ccw_driver_register(&tape_3490_driver); |
| 811 |
if (rc) |
| 812 |
DBF_EVENT(3, "3490 init failed\n"); |
| 813 |
else |
| 814 |
DBF_EVENT(3, "3490 registered\n"); |
| 815 |
return rc; |
| 816 |
} |
| 817 |
|
| 818 |
void tape_3490_exit(void) |
| 819 |
{ |
| 820 |
ccw_driver_unregister(&tape_3490_driver); |
| 821 |
|
| 822 |
debug_unregister(TAPE_DBF_AREA); |
| 823 |
} |
| 824 |
|
| 825 |
MODULE_DEVICE_TABLE(ccw, tape_3490_ids); |