Stefan Bader | b6cba4e | 2006-03-24 03:15:29 -0800 | [diff] [blame] | 1 | /* |
| 2 | * drivers/s390/char/tape_3590.c |
| 3 | * tape device discipline for 3590 tapes. |
| 4 | * |
Michael Holzheu | cced1dd | 2007-02-05 21:18:26 +0100 | [diff] [blame] | 5 | * Copyright IBM Corp. 2001,2006 |
Stefan Bader | b6cba4e | 2006-03-24 03:15:29 -0800 | [diff] [blame] | 6 | * Author(s): Stefan Bader <shbader@de.ibm.com> |
| 7 | * Michael Holzheu <holzheu@de.ibm.com> |
| 8 | * Martin Schwidefsky <schwidefsky@de.ibm.com> |
| 9 | */ |
| 10 | |
Stefan Bader | b6cba4e | 2006-03-24 03:15:29 -0800 | [diff] [blame] | 11 | #include <linux/module.h> |
| 12 | #include <linux/init.h> |
| 13 | #include <linux/bio.h> |
Michael Holzheu | cced1dd | 2007-02-05 21:18:26 +0100 | [diff] [blame] | 14 | #include <asm/ebcdic.h> |
Stefan Bader | b6cba4e | 2006-03-24 03:15:29 -0800 | [diff] [blame] | 15 | |
| 16 | #define TAPE_DBF_AREA tape_3590_dbf |
| 17 | |
| 18 | #include "tape.h" |
| 19 | #include "tape_std.h" |
| 20 | #include "tape_3590.h" |
| 21 | |
| 22 | /* |
| 23 | * Pointer to debug area. |
| 24 | */ |
| 25 | debug_info_t *TAPE_DBF_AREA = NULL; |
| 26 | EXPORT_SYMBOL(TAPE_DBF_AREA); |
| 27 | |
| 28 | /******************************************************************* |
| 29 | * Error Recovery fuctions: |
| 30 | * - Read Opposite: implemented |
| 31 | * - Read Device (buffered) log: BRA |
| 32 | * - Read Library log: BRA |
| 33 | * - Swap Devices: BRA |
Michael Holzheu | cced1dd | 2007-02-05 21:18:26 +0100 | [diff] [blame] | 34 | * - Long Busy: implemented |
Stefan Bader | b6cba4e | 2006-03-24 03:15:29 -0800 | [diff] [blame] | 35 | * - Special Intercept: BRA |
| 36 | * - Read Alternate: implemented |
| 37 | *******************************************************************/ |
| 38 | |
| 39 | #define PRINTK_HEADER "TAPE_3590: " |
| 40 | |
| 41 | static const char *tape_3590_msg[TAPE_3590_MAX_MSG] = { |
| 42 | [0x00] = "", |
| 43 | [0x10] = "Lost Sense", |
| 44 | [0x11] = "Assigned Elsewhere", |
| 45 | [0x12] = "Allegiance Reset", |
| 46 | [0x13] = "Shared Access Violation", |
| 47 | [0x20] = "Command Reject", |
| 48 | [0x21] = "Configuration Error", |
| 49 | [0x22] = "Protection Exception", |
| 50 | [0x23] = "Write Protect", |
| 51 | [0x24] = "Write Length", |
| 52 | [0x25] = "Read-Only Format", |
| 53 | [0x31] = "Beginning of Partition", |
| 54 | [0x33] = "End of Partition", |
| 55 | [0x34] = "End of Data", |
| 56 | [0x35] = "Block not found", |
| 57 | [0x40] = "Device Intervention", |
| 58 | [0x41] = "Loader Intervention", |
| 59 | [0x42] = "Library Intervention", |
| 60 | [0x50] = "Write Error", |
| 61 | [0x51] = "Erase Error", |
| 62 | [0x52] = "Formatting Error", |
| 63 | [0x53] = "Read Error", |
| 64 | [0x54] = "Unsupported Format", |
| 65 | [0x55] = "No Formatting", |
| 66 | [0x56] = "Positioning lost", |
| 67 | [0x57] = "Read Length", |
| 68 | [0x60] = "Unsupported Medium", |
| 69 | [0x61] = "Medium Length Error", |
| 70 | [0x62] = "Medium removed", |
| 71 | [0x64] = "Load Check", |
| 72 | [0x65] = "Unload Check", |
| 73 | [0x70] = "Equipment Check", |
| 74 | [0x71] = "Bus out Check", |
| 75 | [0x72] = "Protocol Error", |
| 76 | [0x73] = "Interface Error", |
| 77 | [0x74] = "Overrun", |
| 78 | [0x75] = "Halt Signal", |
| 79 | [0x90] = "Device fenced", |
| 80 | [0x91] = "Device Path fenced", |
| 81 | [0xa0] = "Volume misplaced", |
| 82 | [0xa1] = "Volume inaccessible", |
| 83 | [0xa2] = "Volume in input", |
| 84 | [0xa3] = "Volume ejected", |
| 85 | [0xa4] = "All categories reserved", |
| 86 | [0xa5] = "Duplicate Volume", |
| 87 | [0xa6] = "Library Manager Offline", |
| 88 | [0xa7] = "Library Output Station full", |
| 89 | [0xa8] = "Vision System non-operational", |
| 90 | [0xa9] = "Library Manager Equipment Check", |
| 91 | [0xaa] = "Library Equipment Check", |
| 92 | [0xab] = "All Library Cells full", |
| 93 | [0xac] = "No Cleaner Volumes in Library", |
| 94 | [0xad] = "I/O Station door open", |
| 95 | [0xae] = "Subsystem environmental alert", |
| 96 | }; |
| 97 | |
Michael Holzheu | cced1dd | 2007-02-05 21:18:26 +0100 | [diff] [blame] | 98 | static int crypt_supported(struct tape_device *device) |
| 99 | { |
| 100 | return TAPE390_CRYPT_SUPPORTED(TAPE_3590_CRYPT_INFO(device)); |
| 101 | } |
| 102 | |
| 103 | static int crypt_enabled(struct tape_device *device) |
| 104 | { |
| 105 | return TAPE390_CRYPT_ON(TAPE_3590_CRYPT_INFO(device)); |
| 106 | } |
| 107 | |
| 108 | static void ext_to_int_kekl(struct tape390_kekl *in, |
| 109 | struct tape3592_kekl *out) |
| 110 | { |
| 111 | int i; |
| 112 | |
| 113 | memset(out, 0, sizeof(*out)); |
| 114 | if (in->type == TAPE390_KEKL_TYPE_HASH) |
| 115 | out->flags |= 0x40; |
| 116 | if (in->type_on_tape == TAPE390_KEKL_TYPE_HASH) |
| 117 | out->flags |= 0x80; |
| 118 | strncpy(out->label, in->label, 64); |
| 119 | for (i = strlen(in->label); i < sizeof(out->label); i++) |
| 120 | out->label[i] = ' '; |
| 121 | ASCEBC(out->label, sizeof(out->label)); |
| 122 | } |
| 123 | |
| 124 | static void int_to_ext_kekl(struct tape3592_kekl *in, |
| 125 | struct tape390_kekl *out) |
| 126 | { |
| 127 | memset(out, 0, sizeof(*out)); |
| 128 | if(in->flags & 0x40) |
| 129 | out->type = TAPE390_KEKL_TYPE_HASH; |
| 130 | else |
| 131 | out->type = TAPE390_KEKL_TYPE_LABEL; |
| 132 | if(in->flags & 0x80) |
| 133 | out->type_on_tape = TAPE390_KEKL_TYPE_HASH; |
| 134 | else |
| 135 | out->type_on_tape = TAPE390_KEKL_TYPE_LABEL; |
| 136 | memcpy(out->label, in->label, sizeof(in->label)); |
| 137 | EBCASC(out->label, sizeof(in->label)); |
| 138 | strstrip(out->label); |
| 139 | } |
| 140 | |
| 141 | static void int_to_ext_kekl_pair(struct tape3592_kekl_pair *in, |
| 142 | struct tape390_kekl_pair *out) |
| 143 | { |
| 144 | if (in->count == 0) { |
| 145 | out->kekl[0].type = TAPE390_KEKL_TYPE_NONE; |
| 146 | out->kekl[0].type_on_tape = TAPE390_KEKL_TYPE_NONE; |
| 147 | out->kekl[1].type = TAPE390_KEKL_TYPE_NONE; |
| 148 | out->kekl[1].type_on_tape = TAPE390_KEKL_TYPE_NONE; |
| 149 | } else if (in->count == 1) { |
| 150 | int_to_ext_kekl(&in->kekl[0], &out->kekl[0]); |
| 151 | out->kekl[1].type = TAPE390_KEKL_TYPE_NONE; |
| 152 | out->kekl[1].type_on_tape = TAPE390_KEKL_TYPE_NONE; |
| 153 | } else if (in->count == 2) { |
| 154 | int_to_ext_kekl(&in->kekl[0], &out->kekl[0]); |
| 155 | int_to_ext_kekl(&in->kekl[1], &out->kekl[1]); |
| 156 | } else { |
| 157 | printk("Invalid KEKL number: %d\n", in->count); |
| 158 | BUG(); |
| 159 | } |
| 160 | } |
| 161 | |
| 162 | static int check_ext_kekl(struct tape390_kekl *kekl) |
| 163 | { |
| 164 | if (kekl->type == TAPE390_KEKL_TYPE_NONE) |
| 165 | goto invalid; |
| 166 | if (kekl->type > TAPE390_KEKL_TYPE_HASH) |
| 167 | goto invalid; |
| 168 | if (kekl->type_on_tape == TAPE390_KEKL_TYPE_NONE) |
| 169 | goto invalid; |
| 170 | if (kekl->type_on_tape > TAPE390_KEKL_TYPE_HASH) |
| 171 | goto invalid; |
| 172 | if ((kekl->type == TAPE390_KEKL_TYPE_HASH) && |
| 173 | (kekl->type_on_tape == TAPE390_KEKL_TYPE_LABEL)) |
| 174 | goto invalid; |
| 175 | |
| 176 | return 0; |
| 177 | invalid: |
| 178 | return -EINVAL; |
| 179 | } |
| 180 | |
| 181 | static int check_ext_kekl_pair(struct tape390_kekl_pair *kekls) |
| 182 | { |
| 183 | if (check_ext_kekl(&kekls->kekl[0])) |
| 184 | goto invalid; |
| 185 | if (check_ext_kekl(&kekls->kekl[1])) |
| 186 | goto invalid; |
| 187 | |
| 188 | return 0; |
| 189 | invalid: |
| 190 | return -EINVAL; |
| 191 | } |
| 192 | |
| 193 | /* |
| 194 | * Query KEKLs |
| 195 | */ |
| 196 | static int tape_3592_kekl_query(struct tape_device *device, |
| 197 | struct tape390_kekl_pair *ext_kekls) |
| 198 | { |
| 199 | struct tape_request *request; |
| 200 | struct tape3592_kekl_query_order *order; |
| 201 | struct tape3592_kekl_query_data *int_kekls; |
| 202 | int rc; |
| 203 | |
| 204 | DBF_EVENT(6, "tape3592_kekl_query\n"); |
| 205 | int_kekls = kmalloc(sizeof(*int_kekls), GFP_KERNEL|GFP_DMA); |
| 206 | if (!int_kekls) |
| 207 | return -ENOMEM; |
| 208 | request = tape_alloc_request(2, sizeof(*order)); |
| 209 | if (IS_ERR(request)) { |
| 210 | rc = PTR_ERR(request); |
| 211 | goto fail_malloc; |
| 212 | } |
| 213 | order = request->cpdata; |
| 214 | memset(order,0,sizeof(*order)); |
| 215 | order->code = 0xe2; |
| 216 | order->max_count = 2; |
| 217 | request->op = TO_KEKL_QUERY; |
| 218 | tape_ccw_cc(request->cpaddr, PERF_SUBSYS_FUNC, sizeof(*order), order); |
| 219 | tape_ccw_end(request->cpaddr + 1, READ_SS_DATA, sizeof(*int_kekls), |
| 220 | int_kekls); |
| 221 | rc = tape_do_io(device, request); |
| 222 | if (rc) |
| 223 | goto fail_request; |
| 224 | int_to_ext_kekl_pair(&int_kekls->kekls, ext_kekls); |
| 225 | |
| 226 | rc = 0; |
| 227 | fail_request: |
| 228 | tape_free_request(request); |
| 229 | fail_malloc: |
| 230 | kfree(int_kekls); |
| 231 | return rc; |
| 232 | } |
| 233 | |
| 234 | /* |
| 235 | * IOCTL: Query KEKLs |
| 236 | */ |
| 237 | static int tape_3592_ioctl_kekl_query(struct tape_device *device, |
| 238 | unsigned long arg) |
| 239 | { |
| 240 | int rc; |
| 241 | struct tape390_kekl_pair *ext_kekls; |
| 242 | |
| 243 | DBF_EVENT(6, "tape_3592_ioctl_kekl_query\n"); |
| 244 | if (!crypt_supported(device)) |
| 245 | return -ENOSYS; |
| 246 | if (!crypt_enabled(device)) |
| 247 | return -EUNATCH; |
| 248 | ext_kekls = kmalloc(sizeof(*ext_kekls), GFP_KERNEL); |
| 249 | if (!ext_kekls) |
| 250 | return -ENOMEM; |
| 251 | rc = tape_3592_kekl_query(device, ext_kekls); |
| 252 | if (rc != 0) |
| 253 | goto fail; |
| 254 | if (copy_to_user((char __user *) arg, ext_kekls, sizeof(*ext_kekls))) { |
| 255 | rc = -EFAULT; |
| 256 | goto fail; |
| 257 | } |
| 258 | rc = 0; |
| 259 | fail: |
| 260 | kfree(ext_kekls); |
| 261 | return rc; |
| 262 | } |
| 263 | |
| 264 | static int tape_3590_mttell(struct tape_device *device, int mt_count); |
| 265 | |
| 266 | /* |
| 267 | * Set KEKLs |
| 268 | */ |
| 269 | static int tape_3592_kekl_set(struct tape_device *device, |
| 270 | struct tape390_kekl_pair *ext_kekls) |
| 271 | { |
| 272 | struct tape_request *request; |
| 273 | struct tape3592_kekl_set_order *order; |
| 274 | |
| 275 | DBF_EVENT(6, "tape3592_kekl_set\n"); |
| 276 | if (check_ext_kekl_pair(ext_kekls)) { |
| 277 | DBF_EVENT(6, "invalid kekls\n"); |
| 278 | return -EINVAL; |
| 279 | } |
| 280 | if (tape_3590_mttell(device, 0) != 0) |
| 281 | return -EBADSLT; |
| 282 | request = tape_alloc_request(1, sizeof(*order)); |
| 283 | if (IS_ERR(request)) |
| 284 | return PTR_ERR(request); |
| 285 | order = request->cpdata; |
| 286 | memset(order, 0, sizeof(*order)); |
| 287 | order->code = 0xe3; |
| 288 | order->kekls.count = 2; |
| 289 | ext_to_int_kekl(&ext_kekls->kekl[0], &order->kekls.kekl[0]); |
| 290 | ext_to_int_kekl(&ext_kekls->kekl[1], &order->kekls.kekl[1]); |
| 291 | request->op = TO_KEKL_SET; |
| 292 | tape_ccw_end(request->cpaddr, PERF_SUBSYS_FUNC, sizeof(*order), order); |
| 293 | |
| 294 | return tape_do_io_free(device, request); |
| 295 | } |
| 296 | |
| 297 | /* |
| 298 | * IOCTL: Set KEKLs |
| 299 | */ |
| 300 | static int tape_3592_ioctl_kekl_set(struct tape_device *device, |
| 301 | unsigned long arg) |
| 302 | { |
| 303 | int rc; |
| 304 | struct tape390_kekl_pair *ext_kekls; |
| 305 | |
| 306 | DBF_EVENT(6, "tape_3592_ioctl_kekl_set\n"); |
| 307 | if (!crypt_supported(device)) |
| 308 | return -ENOSYS; |
| 309 | if (!crypt_enabled(device)) |
| 310 | return -EUNATCH; |
| 311 | ext_kekls = kmalloc(sizeof(*ext_kekls), GFP_KERNEL); |
| 312 | if (!ext_kekls) |
| 313 | return -ENOMEM; |
| 314 | if (copy_from_user(ext_kekls, (char __user *)arg, sizeof(*ext_kekls))) { |
| 315 | rc = -EFAULT; |
| 316 | goto out; |
| 317 | } |
| 318 | rc = tape_3592_kekl_set(device, ext_kekls); |
| 319 | out: |
| 320 | kfree(ext_kekls); |
| 321 | return rc; |
| 322 | } |
| 323 | |
| 324 | /* |
| 325 | * Enable encryption |
| 326 | */ |
| 327 | static int tape_3592_enable_crypt(struct tape_device *device) |
| 328 | { |
| 329 | struct tape_request *request; |
| 330 | char *data; |
| 331 | |
| 332 | DBF_EVENT(6, "tape_3592_enable_crypt\n"); |
| 333 | if (!crypt_supported(device)) |
| 334 | return -ENOSYS; |
| 335 | request = tape_alloc_request(2, 72); |
| 336 | if (IS_ERR(request)) |
| 337 | return PTR_ERR(request); |
| 338 | data = request->cpdata; |
| 339 | memset(data,0,72); |
| 340 | |
| 341 | data[0] = 0x05; |
| 342 | data[36 + 0] = 0x03; |
| 343 | data[36 + 1] = 0x03; |
| 344 | data[36 + 4] = 0x40; |
| 345 | data[36 + 6] = 0x01; |
| 346 | data[36 + 14] = 0x2f; |
| 347 | data[36 + 18] = 0xc3; |
| 348 | data[36 + 35] = 0x72; |
| 349 | request->op = TO_CRYPT_ON; |
| 350 | tape_ccw_cc(request->cpaddr, MODE_SET_CB, 36, data); |
| 351 | tape_ccw_end(request->cpaddr + 1, MODE_SET_CB, 36, data + 36); |
| 352 | return tape_do_io_free(device, request); |
| 353 | } |
| 354 | |
| 355 | /* |
| 356 | * Disable encryption |
| 357 | */ |
| 358 | static int tape_3592_disable_crypt(struct tape_device *device) |
| 359 | { |
| 360 | struct tape_request *request; |
| 361 | char *data; |
| 362 | |
| 363 | DBF_EVENT(6, "tape_3592_disable_crypt\n"); |
| 364 | if (!crypt_supported(device)) |
| 365 | return -ENOSYS; |
| 366 | request = tape_alloc_request(2, 72); |
| 367 | if (IS_ERR(request)) |
| 368 | return PTR_ERR(request); |
| 369 | data = request->cpdata; |
| 370 | memset(data,0,72); |
| 371 | |
| 372 | data[0] = 0x05; |
| 373 | data[36 + 0] = 0x03; |
| 374 | data[36 + 1] = 0x03; |
| 375 | data[36 + 35] = 0x32; |
| 376 | |
| 377 | request->op = TO_CRYPT_OFF; |
| 378 | tape_ccw_cc(request->cpaddr, MODE_SET_CB, 36, data); |
| 379 | tape_ccw_end(request->cpaddr + 1, MODE_SET_CB, 36, data + 36); |
| 380 | |
| 381 | return tape_do_io_free(device, request); |
| 382 | } |
| 383 | |
| 384 | /* |
| 385 | * IOCTL: Set encryption status |
| 386 | */ |
| 387 | static int tape_3592_ioctl_crypt_set(struct tape_device *device, |
| 388 | unsigned long arg) |
| 389 | { |
| 390 | struct tape390_crypt_info info; |
| 391 | |
| 392 | DBF_EVENT(6, "tape_3592_ioctl_crypt_set\n"); |
| 393 | if (!crypt_supported(device)) |
| 394 | return -ENOSYS; |
| 395 | if (copy_from_user(&info, (char __user *)arg, sizeof(info))) |
| 396 | return -EFAULT; |
| 397 | if (info.status & ~TAPE390_CRYPT_ON_MASK) |
| 398 | return -EINVAL; |
| 399 | if (info.status & TAPE390_CRYPT_ON_MASK) |
| 400 | return tape_3592_enable_crypt(device); |
| 401 | else |
| 402 | return tape_3592_disable_crypt(device); |
| 403 | } |
| 404 | |
| 405 | static int tape_3590_sense_medium(struct tape_device *device); |
| 406 | |
| 407 | /* |
| 408 | * IOCTL: Query enryption status |
| 409 | */ |
| 410 | static int tape_3592_ioctl_crypt_query(struct tape_device *device, |
| 411 | unsigned long arg) |
| 412 | { |
| 413 | DBF_EVENT(6, "tape_3592_ioctl_crypt_query\n"); |
| 414 | if (!crypt_supported(device)) |
| 415 | return -ENOSYS; |
| 416 | tape_3590_sense_medium(device); |
| 417 | if (copy_to_user((char __user *) arg, &TAPE_3590_CRYPT_INFO(device), |
| 418 | sizeof(TAPE_3590_CRYPT_INFO(device)))) |
| 419 | return -EFAULT; |
| 420 | else |
| 421 | return 0; |
| 422 | } |
| 423 | |
Stefan Bader | b6cba4e | 2006-03-24 03:15:29 -0800 | [diff] [blame] | 424 | /* |
| 425 | * 3590 IOCTL Overload |
| 426 | */ |
| 427 | static int |
| 428 | tape_3590_ioctl(struct tape_device *device, unsigned int cmd, unsigned long arg) |
| 429 | { |
| 430 | switch (cmd) { |
| 431 | case TAPE390_DISPLAY: { |
| 432 | struct display_struct disp; |
| 433 | |
| 434 | if (copy_from_user(&disp, (char __user *) arg, sizeof(disp))) |
| 435 | return -EFAULT; |
| 436 | |
| 437 | return tape_std_display(device, &disp); |
| 438 | } |
Michael Holzheu | cced1dd | 2007-02-05 21:18:26 +0100 | [diff] [blame] | 439 | case TAPE390_KEKL_SET: |
| 440 | return tape_3592_ioctl_kekl_set(device, arg); |
| 441 | case TAPE390_KEKL_QUERY: |
| 442 | return tape_3592_ioctl_kekl_query(device, arg); |
| 443 | case TAPE390_CRYPT_SET: |
| 444 | return tape_3592_ioctl_crypt_set(device, arg); |
| 445 | case TAPE390_CRYPT_QUERY: |
| 446 | return tape_3592_ioctl_crypt_query(device, arg); |
Stefan Bader | b6cba4e | 2006-03-24 03:15:29 -0800 | [diff] [blame] | 447 | default: |
| 448 | return -EINVAL; /* no additional ioctls */ |
| 449 | } |
| 450 | } |
| 451 | |
| 452 | /* |
| 453 | * SENSE Medium: Get Sense data about medium state |
| 454 | */ |
| 455 | static int |
| 456 | tape_3590_sense_medium(struct tape_device *device) |
| 457 | { |
| 458 | struct tape_request *request; |
| 459 | |
| 460 | request = tape_alloc_request(1, 128); |
| 461 | if (IS_ERR(request)) |
| 462 | return PTR_ERR(request); |
| 463 | request->op = TO_MSEN; |
| 464 | tape_ccw_end(request->cpaddr, MEDIUM_SENSE, 128, request->cpdata); |
| 465 | return tape_do_io_free(device, request); |
| 466 | } |
| 467 | |
| 468 | /* |
| 469 | * MTTELL: Tell block. Return the number of block relative to current file. |
| 470 | */ |
| 471 | static int |
| 472 | tape_3590_mttell(struct tape_device *device, int mt_count) |
| 473 | { |
| 474 | __u64 block_id; |
| 475 | int rc; |
| 476 | |
| 477 | rc = tape_std_read_block_id(device, &block_id); |
| 478 | if (rc) |
| 479 | return rc; |
| 480 | return block_id >> 32; |
| 481 | } |
| 482 | |
| 483 | /* |
| 484 | * MTSEEK: seek to the specified block. |
| 485 | */ |
| 486 | static int |
| 487 | tape_3590_mtseek(struct tape_device *device, int count) |
| 488 | { |
| 489 | struct tape_request *request; |
| 490 | |
| 491 | DBF_EVENT(6, "xsee id: %x\n", count); |
| 492 | request = tape_alloc_request(3, 4); |
| 493 | if (IS_ERR(request)) |
| 494 | return PTR_ERR(request); |
| 495 | request->op = TO_LBL; |
| 496 | tape_ccw_cc(request->cpaddr, MODE_SET_DB, 1, device->modeset_byte); |
| 497 | *(__u32 *) request->cpdata = count; |
| 498 | tape_ccw_cc(request->cpaddr + 1, LOCATE, 4, request->cpdata); |
| 499 | tape_ccw_end(request->cpaddr + 2, NOP, 0, NULL); |
| 500 | return tape_do_io_free(device, request); |
| 501 | } |
| 502 | |
| 503 | /* |
| 504 | * Read Opposite Error Recovery Function: |
| 505 | * Used, when Read Forward does not work |
| 506 | */ |
| 507 | static void |
| 508 | tape_3590_read_opposite(struct tape_device *device, |
| 509 | struct tape_request *request) |
| 510 | { |
| 511 | struct tape_3590_disc_data *data; |
| 512 | |
| 513 | /* |
| 514 | * We have allocated 4 ccws in tape_std_read, so we can now |
| 515 | * transform the request to a read backward, followed by a |
| 516 | * forward space block. |
| 517 | */ |
| 518 | request->op = TO_RBA; |
| 519 | tape_ccw_cc(request->cpaddr, MODE_SET_DB, 1, device->modeset_byte); |
| 520 | data = device->discdata; |
| 521 | tape_ccw_cc_idal(request->cpaddr + 1, data->read_back_op, |
| 522 | device->char_data.idal_buf); |
| 523 | tape_ccw_cc(request->cpaddr + 2, FORSPACEBLOCK, 0, NULL); |
| 524 | tape_ccw_end(request->cpaddr + 3, NOP, 0, NULL); |
| 525 | DBF_EVENT(6, "xrop ccwg\n"); |
| 526 | } |
| 527 | |
| 528 | /* |
| 529 | * Read Attention Msg |
| 530 | * This should be done after an interrupt with attention bit (0x80) |
| 531 | * in device state. |
| 532 | * |
| 533 | * After a "read attention message" request there are two possible |
| 534 | * results: |
| 535 | * |
| 536 | * 1. A unit check is presented, when attention sense is present (e.g. when |
| 537 | * a medium has been unloaded). The attention sense comes then |
| 538 | * together with the unit check. The recovery action is either "retry" |
| 539 | * (in case there is an attention message pending) or "permanent error". |
| 540 | * |
| 541 | * 2. The attention msg is written to the "read subsystem data" buffer. |
| 542 | * In this case we probably should print it to the console. |
| 543 | */ |
| 544 | static int |
| 545 | tape_3590_read_attmsg(struct tape_device *device) |
| 546 | { |
| 547 | struct tape_request *request; |
| 548 | char *buf; |
| 549 | |
| 550 | request = tape_alloc_request(3, 4096); |
| 551 | if (IS_ERR(request)) |
| 552 | return PTR_ERR(request); |
| 553 | request->op = TO_READ_ATTMSG; |
| 554 | buf = request->cpdata; |
| 555 | buf[0] = PREP_RD_SS_DATA; |
| 556 | buf[6] = RD_ATTMSG; /* read att msg */ |
| 557 | tape_ccw_cc(request->cpaddr, PERFORM_SS_FUNC, 12, buf); |
| 558 | tape_ccw_cc(request->cpaddr + 1, READ_SS_DATA, 4096 - 12, buf + 12); |
| 559 | tape_ccw_end(request->cpaddr + 2, NOP, 0, NULL); |
| 560 | return tape_do_io_free(device, request); |
| 561 | } |
| 562 | |
| 563 | /* |
| 564 | * These functions are used to schedule follow-up actions from within an |
| 565 | * interrupt context (like unsolicited interrupts). |
| 566 | */ |
Stefan Bader | 2cc924b | 2006-04-27 18:40:16 -0700 | [diff] [blame] | 567 | struct work_handler_data { |
| 568 | struct tape_device *device; |
| 569 | enum tape_op op; |
| 570 | struct work_struct work; |
| 571 | }; |
| 572 | |
Stefan Bader | b6cba4e | 2006-03-24 03:15:29 -0800 | [diff] [blame] | 573 | static void |
Martin Schwidefsky | c163753 | 2006-12-08 15:53:57 +0100 | [diff] [blame] | 574 | tape_3590_work_handler(struct work_struct *work) |
Stefan Bader | b6cba4e | 2006-03-24 03:15:29 -0800 | [diff] [blame] | 575 | { |
Martin Schwidefsky | c163753 | 2006-12-08 15:53:57 +0100 | [diff] [blame] | 576 | struct work_handler_data *p = |
| 577 | container_of(work, struct work_handler_data, work); |
Stefan Bader | b6cba4e | 2006-03-24 03:15:29 -0800 | [diff] [blame] | 578 | |
| 579 | switch (p->op) { |
| 580 | case TO_MSEN: |
| 581 | tape_3590_sense_medium(p->device); |
| 582 | break; |
| 583 | case TO_READ_ATTMSG: |
| 584 | tape_3590_read_attmsg(p->device); |
| 585 | break; |
Michael Holzheu | cced1dd | 2007-02-05 21:18:26 +0100 | [diff] [blame] | 586 | case TO_CRYPT_ON: |
| 587 | tape_3592_enable_crypt(p->device); |
| 588 | break; |
| 589 | case TO_CRYPT_OFF: |
| 590 | tape_3592_disable_crypt(p->device); |
| 591 | break; |
Stefan Bader | b6cba4e | 2006-03-24 03:15:29 -0800 | [diff] [blame] | 592 | default: |
| 593 | DBF_EVENT(3, "T3590: work handler undefined for " |
| 594 | "operation 0x%02x\n", p->op); |
| 595 | } |
| 596 | tape_put_device(p->device); |
| 597 | kfree(p); |
| 598 | } |
| 599 | |
| 600 | static int |
| 601 | tape_3590_schedule_work(struct tape_device *device, enum tape_op op) |
| 602 | { |
Stefan Bader | 2cc924b | 2006-04-27 18:40:16 -0700 | [diff] [blame] | 603 | struct work_handler_data *p; |
Stefan Bader | b6cba4e | 2006-03-24 03:15:29 -0800 | [diff] [blame] | 604 | |
| 605 | if ((p = kzalloc(sizeof(*p), GFP_ATOMIC)) == NULL) |
| 606 | return -ENOMEM; |
| 607 | |
Martin Schwidefsky | c163753 | 2006-12-08 15:53:57 +0100 | [diff] [blame] | 608 | INIT_WORK(&p->work, tape_3590_work_handler); |
Stefan Bader | b6cba4e | 2006-03-24 03:15:29 -0800 | [diff] [blame] | 609 | |
| 610 | p->device = tape_get_device_reference(device); |
| 611 | p->op = op; |
| 612 | |
| 613 | schedule_work(&p->work); |
| 614 | return 0; |
| 615 | } |
| 616 | |
| 617 | #ifdef CONFIG_S390_TAPE_BLOCK |
| 618 | /* |
| 619 | * Tape Block READ |
| 620 | */ |
| 621 | static struct tape_request * |
| 622 | tape_3590_bread(struct tape_device *device, struct request *req) |
| 623 | { |
| 624 | struct tape_request *request; |
| 625 | struct ccw1 *ccw; |
NeilBrown | 5705f70 | 2007-09-25 12:35:59 +0200 | [diff] [blame] | 626 | int count = 0, start_block; |
Stefan Bader | b6cba4e | 2006-03-24 03:15:29 -0800 | [diff] [blame] | 627 | unsigned off; |
| 628 | char *dst; |
| 629 | struct bio_vec *bv; |
NeilBrown | 5705f70 | 2007-09-25 12:35:59 +0200 | [diff] [blame] | 630 | struct req_iterator iter; |
Stefan Bader | b6cba4e | 2006-03-24 03:15:29 -0800 | [diff] [blame] | 631 | |
| 632 | DBF_EVENT(6, "xBREDid:"); |
| 633 | start_block = req->sector >> TAPEBLOCK_HSEC_S2B; |
| 634 | DBF_EVENT(6, "start_block = %i\n", start_block); |
| 635 | |
NeilBrown | 5705f70 | 2007-09-25 12:35:59 +0200 | [diff] [blame] | 636 | rq_for_each_segment(bv, req, iter) |
| 637 | count += bv->bv_len >> (TAPEBLOCK_HSEC_S2B + 9); |
| 638 | |
Stefan Bader | b6cba4e | 2006-03-24 03:15:29 -0800 | [diff] [blame] | 639 | request = tape_alloc_request(2 + count + 1, 4); |
| 640 | if (IS_ERR(request)) |
| 641 | return request; |
| 642 | request->op = TO_BLOCK; |
| 643 | *(__u32 *) request->cpdata = start_block; |
| 644 | ccw = request->cpaddr; |
| 645 | ccw = tape_ccw_cc(ccw, MODE_SET_DB, 1, device->modeset_byte); |
| 646 | |
| 647 | /* |
| 648 | * We always setup a nop after the mode set ccw. This slot is |
| 649 | * used in tape_std_check_locate to insert a locate ccw if the |
| 650 | * current tape position doesn't match the start block to be read. |
| 651 | */ |
| 652 | ccw = tape_ccw_cc(ccw, NOP, 0, NULL); |
| 653 | |
NeilBrown | 5705f70 | 2007-09-25 12:35:59 +0200 | [diff] [blame] | 654 | rq_for_each_segment(bv, req, iter) { |
Jens Axboe | 6c92e69 | 2007-08-16 13:43:12 +0200 | [diff] [blame^] | 655 | dst = page_address(bv->bv_page) + bv->bv_offset; |
| 656 | for (off = 0; off < bv->bv_len; off += TAPEBLOCK_HSEC_SIZE) { |
| 657 | ccw->flags = CCW_FLAG_CC; |
| 658 | ccw->cmd_code = READ_FORWARD; |
| 659 | ccw->count = TAPEBLOCK_HSEC_SIZE; |
| 660 | set_normalized_cda(ccw, (void *) __pa(dst)); |
| 661 | ccw++; |
| 662 | dst += TAPEBLOCK_HSEC_SIZE; |
| 663 | } |
| 664 | if (off > bv->bv_len) |
| 665 | BUG(); |
Stefan Bader | b6cba4e | 2006-03-24 03:15:29 -0800 | [diff] [blame] | 666 | } |
| 667 | ccw = tape_ccw_end(ccw, NOP, 0, NULL); |
| 668 | DBF_EVENT(6, "xBREDccwg\n"); |
| 669 | return request; |
| 670 | } |
| 671 | |
| 672 | static void |
| 673 | tape_3590_free_bread(struct tape_request *request) |
| 674 | { |
| 675 | struct ccw1 *ccw; |
| 676 | |
| 677 | /* Last ccw is a nop and doesn't need clear_normalized_cda */ |
| 678 | for (ccw = request->cpaddr; ccw->flags & CCW_FLAG_CC; ccw++) |
| 679 | if (ccw->cmd_code == READ_FORWARD) |
| 680 | clear_normalized_cda(ccw); |
| 681 | tape_free_request(request); |
| 682 | } |
| 683 | |
| 684 | /* |
| 685 | * check_locate is called just before the tape request is passed to |
| 686 | * the common io layer for execution. It has to check the current |
| 687 | * tape position and insert a locate ccw if it doesn't match the |
| 688 | * start block for the request. |
| 689 | */ |
| 690 | static void |
| 691 | tape_3590_check_locate(struct tape_device *device, struct tape_request *request) |
| 692 | { |
| 693 | __u32 *start_block; |
| 694 | |
| 695 | start_block = (__u32 *) request->cpdata; |
| 696 | if (*start_block != device->blk_data.block_position) { |
| 697 | /* Add the start offset of the file to get the real block. */ |
| 698 | *start_block += device->bof; |
| 699 | tape_ccw_cc(request->cpaddr + 1, LOCATE, 4, request->cpdata); |
| 700 | } |
| 701 | } |
| 702 | #endif |
| 703 | |
Michael Holzheu | cced1dd | 2007-02-05 21:18:26 +0100 | [diff] [blame] | 704 | static void tape_3590_med_state_set(struct tape_device *device, |
| 705 | struct tape_3590_med_sense *sense) |
| 706 | { |
| 707 | struct tape390_crypt_info *c_info; |
| 708 | |
| 709 | c_info = &TAPE_3590_CRYPT_INFO(device); |
| 710 | |
| 711 | if (sense->masst == MSENSE_UNASSOCIATED) { |
| 712 | tape_med_state_set(device, MS_UNLOADED); |
| 713 | TAPE_3590_CRYPT_INFO(device).medium_status = 0; |
| 714 | return; |
| 715 | } |
| 716 | if (sense->masst != MSENSE_ASSOCIATED_MOUNT) { |
| 717 | PRINT_ERR("Unknown medium state: %x\n", sense->masst); |
| 718 | return; |
| 719 | } |
| 720 | tape_med_state_set(device, MS_LOADED); |
| 721 | c_info->medium_status |= TAPE390_MEDIUM_LOADED_MASK; |
| 722 | if (sense->flags & MSENSE_CRYPT_MASK) { |
| 723 | PRINT_INFO("Medium is encrypted (%04x)\n", sense->flags); |
| 724 | c_info->medium_status |= TAPE390_MEDIUM_ENCRYPTED_MASK; |
| 725 | } else { |
| 726 | DBF_EVENT(6, "Medium is not encrypted %04x\n", sense->flags); |
| 727 | c_info->medium_status &= ~TAPE390_MEDIUM_ENCRYPTED_MASK; |
| 728 | } |
| 729 | } |
| 730 | |
Stefan Bader | b6cba4e | 2006-03-24 03:15:29 -0800 | [diff] [blame] | 731 | /* |
| 732 | * The done handler is called at device/channel end and wakes up the sleeping |
| 733 | * process |
| 734 | */ |
| 735 | static int |
| 736 | tape_3590_done(struct tape_device *device, struct tape_request *request) |
| 737 | { |
Michael Holzheu | cced1dd | 2007-02-05 21:18:26 +0100 | [diff] [blame] | 738 | struct tape_3590_disc_data *disc_data; |
Stefan Bader | b6cba4e | 2006-03-24 03:15:29 -0800 | [diff] [blame] | 739 | |
| 740 | DBF_EVENT(6, "%s done\n", tape_op_verbose[request->op]); |
Michael Holzheu | cced1dd | 2007-02-05 21:18:26 +0100 | [diff] [blame] | 741 | disc_data = device->discdata; |
Stefan Bader | b6cba4e | 2006-03-24 03:15:29 -0800 | [diff] [blame] | 742 | |
| 743 | switch (request->op) { |
| 744 | case TO_BSB: |
| 745 | case TO_BSF: |
| 746 | case TO_DSE: |
| 747 | case TO_FSB: |
| 748 | case TO_FSF: |
| 749 | case TO_LBL: |
| 750 | case TO_RFO: |
| 751 | case TO_RBA: |
| 752 | case TO_REW: |
| 753 | case TO_WRI: |
| 754 | case TO_WTM: |
| 755 | case TO_BLOCK: |
| 756 | case TO_LOAD: |
| 757 | tape_med_state_set(device, MS_LOADED); |
| 758 | break; |
| 759 | case TO_RUN: |
| 760 | tape_med_state_set(device, MS_UNLOADED); |
Michael Holzheu | cced1dd | 2007-02-05 21:18:26 +0100 | [diff] [blame] | 761 | tape_3590_schedule_work(device, TO_CRYPT_OFF); |
Stefan Bader | b6cba4e | 2006-03-24 03:15:29 -0800 | [diff] [blame] | 762 | break; |
| 763 | case TO_MSEN: |
Michael Holzheu | cced1dd | 2007-02-05 21:18:26 +0100 | [diff] [blame] | 764 | tape_3590_med_state_set(device, request->cpdata); |
| 765 | break; |
| 766 | case TO_CRYPT_ON: |
| 767 | TAPE_3590_CRYPT_INFO(device).status |
| 768 | |= TAPE390_CRYPT_ON_MASK; |
| 769 | *(device->modeset_byte) |= 0x03; |
| 770 | break; |
| 771 | case TO_CRYPT_OFF: |
| 772 | TAPE_3590_CRYPT_INFO(device).status |
| 773 | &= ~TAPE390_CRYPT_ON_MASK; |
| 774 | *(device->modeset_byte) &= ~0x03; |
Stefan Bader | b6cba4e | 2006-03-24 03:15:29 -0800 | [diff] [blame] | 775 | break; |
| 776 | case TO_RBI: /* RBI seems to succeed even without medium loaded. */ |
| 777 | case TO_NOP: /* Same to NOP. */ |
| 778 | case TO_READ_CONFIG: |
| 779 | case TO_READ_ATTMSG: |
| 780 | case TO_DIS: |
| 781 | case TO_ASSIGN: |
| 782 | case TO_UNASSIGN: |
Stefan Bader | b6cba4e | 2006-03-24 03:15:29 -0800 | [diff] [blame] | 783 | case TO_SIZE: |
Michael Holzheu | cced1dd | 2007-02-05 21:18:26 +0100 | [diff] [blame] | 784 | case TO_KEKL_SET: |
| 785 | case TO_KEKL_QUERY: |
Michael Holzheu | e296306 | 2007-05-04 18:47:53 +0200 | [diff] [blame] | 786 | case TO_RDC: |
Stefan Bader | b6cba4e | 2006-03-24 03:15:29 -0800 | [diff] [blame] | 787 | break; |
| 788 | } |
| 789 | return TAPE_IO_SUCCESS; |
| 790 | } |
| 791 | |
| 792 | /* |
| 793 | * This fuction is called, when error recovery was successfull |
| 794 | */ |
| 795 | static inline int |
| 796 | tape_3590_erp_succeded(struct tape_device *device, struct tape_request *request) |
| 797 | { |
| 798 | DBF_EVENT(3, "Error Recovery successfull for %s\n", |
| 799 | tape_op_verbose[request->op]); |
| 800 | return tape_3590_done(device, request); |
| 801 | } |
| 802 | |
| 803 | /* |
| 804 | * This fuction is called, when error recovery was not successfull |
| 805 | */ |
| 806 | static inline int |
| 807 | tape_3590_erp_failed(struct tape_device *device, struct tape_request *request, |
| 808 | struct irb *irb, int rc) |
| 809 | { |
| 810 | DBF_EVENT(3, "Error Recovery failed for %s\n", |
| 811 | tape_op_verbose[request->op]); |
| 812 | tape_dump_sense_dbf(device, request, irb); |
| 813 | return rc; |
| 814 | } |
| 815 | |
| 816 | /* |
| 817 | * Error Recovery do retry |
| 818 | */ |
| 819 | static inline int |
| 820 | tape_3590_erp_retry(struct tape_device *device, struct tape_request *request, |
| 821 | struct irb *irb) |
| 822 | { |
| 823 | DBF_EVENT(2, "Retry: %s\n", tape_op_verbose[request->op]); |
| 824 | tape_dump_sense_dbf(device, request, irb); |
| 825 | return TAPE_IO_RETRY; |
| 826 | } |
| 827 | |
| 828 | /* |
| 829 | * Handle unsolicited interrupts |
| 830 | */ |
| 831 | static int |
| 832 | tape_3590_unsolicited_irq(struct tape_device *device, struct irb *irb) |
| 833 | { |
| 834 | if (irb->scsw.dstat == DEV_STAT_CHN_END) |
| 835 | /* Probably result of halt ssch */ |
| 836 | return TAPE_IO_PENDING; |
| 837 | else if (irb->scsw.dstat == 0x85) |
| 838 | /* Device Ready -> check medium state */ |
| 839 | tape_3590_schedule_work(device, TO_MSEN); |
| 840 | else if (irb->scsw.dstat & DEV_STAT_ATTENTION) |
| 841 | tape_3590_schedule_work(device, TO_READ_ATTMSG); |
| 842 | else { |
| 843 | DBF_EVENT(3, "unsol.irq! dev end: %08x\n", device->cdev_id); |
| 844 | PRINT_WARN("Unsolicited IRQ (Device End) caught.\n"); |
| 845 | tape_dump_sense(device, NULL, irb); |
| 846 | } |
| 847 | return TAPE_IO_SUCCESS; |
| 848 | } |
| 849 | |
| 850 | /* |
| 851 | * Basic Recovery routine |
| 852 | */ |
| 853 | static int |
| 854 | tape_3590_erp_basic(struct tape_device *device, struct tape_request *request, |
| 855 | struct irb *irb, int rc) |
| 856 | { |
| 857 | struct tape_3590_sense *sense; |
| 858 | |
| 859 | sense = (struct tape_3590_sense *) irb->ecw; |
| 860 | |
| 861 | switch (sense->bra) { |
| 862 | case SENSE_BRA_PER: |
| 863 | return tape_3590_erp_failed(device, request, irb, rc); |
| 864 | case SENSE_BRA_CONT: |
| 865 | return tape_3590_erp_succeded(device, request); |
| 866 | case SENSE_BRA_RE: |
| 867 | return tape_3590_erp_retry(device, request, irb); |
| 868 | case SENSE_BRA_DRE: |
| 869 | return tape_3590_erp_failed(device, request, irb, rc); |
| 870 | default: |
| 871 | PRINT_ERR("Unknown BRA %x - This should not happen!\n", |
| 872 | sense->bra); |
| 873 | BUG(); |
| 874 | return TAPE_IO_STOP; |
| 875 | } |
| 876 | } |
| 877 | |
| 878 | /* |
| 879 | * RDL: Read Device (buffered) log |
| 880 | */ |
| 881 | static int |
| 882 | tape_3590_erp_read_buf_log(struct tape_device *device, |
| 883 | struct tape_request *request, struct irb *irb) |
| 884 | { |
| 885 | /* |
| 886 | * We just do the basic error recovery at the moment (retry). |
| 887 | * Perhaps in the future, we read the log and dump it somewhere... |
| 888 | */ |
| 889 | return tape_3590_erp_basic(device, request, irb, -EIO); |
| 890 | } |
| 891 | |
| 892 | /* |
| 893 | * SWAP: Swap Devices |
| 894 | */ |
| 895 | static int |
| 896 | tape_3590_erp_swap(struct tape_device *device, struct tape_request *request, |
| 897 | struct irb *irb) |
| 898 | { |
| 899 | /* |
| 900 | * This error recovery should swap the tapes |
| 901 | * if the original has a problem. The operation |
| 902 | * should proceed with the new tape... this |
| 903 | * should probably be done in user space! |
| 904 | */ |
| 905 | PRINT_WARN("(%s): Swap Tape Device!\n", device->cdev->dev.bus_id); |
| 906 | return tape_3590_erp_basic(device, request, irb, -EIO); |
| 907 | } |
| 908 | |
| 909 | /* |
| 910 | * LBY: Long Busy |
| 911 | */ |
| 912 | static int |
| 913 | tape_3590_erp_long_busy(struct tape_device *device, |
| 914 | struct tape_request *request, struct irb *irb) |
| 915 | { |
Michael Holzheu | cced1dd | 2007-02-05 21:18:26 +0100 | [diff] [blame] | 916 | DBF_EVENT(6, "Device is busy\n"); |
| 917 | return TAPE_IO_LONG_BUSY; |
Stefan Bader | b6cba4e | 2006-03-24 03:15:29 -0800 | [diff] [blame] | 918 | } |
| 919 | |
| 920 | /* |
| 921 | * SPI: Special Intercept |
| 922 | */ |
| 923 | static int |
| 924 | tape_3590_erp_special_interrupt(struct tape_device *device, |
| 925 | struct tape_request *request, struct irb *irb) |
| 926 | { |
| 927 | return tape_3590_erp_basic(device, request, irb, -EIO); |
| 928 | } |
| 929 | |
| 930 | /* |
| 931 | * RDA: Read Alternate |
| 932 | */ |
| 933 | static int |
| 934 | tape_3590_erp_read_alternate(struct tape_device *device, |
| 935 | struct tape_request *request, struct irb *irb) |
| 936 | { |
| 937 | struct tape_3590_disc_data *data; |
| 938 | |
| 939 | /* |
| 940 | * The issued Read Backward or Read Previous command is not |
| 941 | * supported by the device |
| 942 | * The recovery action should be to issue another command: |
| 943 | * Read Revious: if Read Backward is not supported |
| 944 | * Read Backward: if Read Previous is not supported |
| 945 | */ |
| 946 | data = device->discdata; |
| 947 | if (data->read_back_op == READ_PREVIOUS) { |
| 948 | DBF_EVENT(2, "(%08x): No support for READ_PREVIOUS command\n", |
| 949 | device->cdev_id); |
| 950 | data->read_back_op = READ_BACKWARD; |
| 951 | } else { |
| 952 | DBF_EVENT(2, "(%08x): No support for READ_BACKWARD command\n", |
| 953 | device->cdev_id); |
| 954 | data->read_back_op = READ_PREVIOUS; |
| 955 | } |
| 956 | tape_3590_read_opposite(device, request); |
| 957 | return tape_3590_erp_retry(device, request, irb); |
| 958 | } |
| 959 | |
| 960 | /* |
| 961 | * Error Recovery read opposite |
| 962 | */ |
| 963 | static int |
| 964 | tape_3590_erp_read_opposite(struct tape_device *device, |
| 965 | struct tape_request *request, struct irb *irb) |
| 966 | { |
| 967 | switch (request->op) { |
| 968 | case TO_RFO: |
| 969 | /* |
| 970 | * We did read forward, but the data could not be read. |
| 971 | * We will read backward and then skip forward again. |
| 972 | */ |
| 973 | tape_3590_read_opposite(device, request); |
| 974 | return tape_3590_erp_retry(device, request, irb); |
| 975 | case TO_RBA: |
| 976 | /* We tried to read forward and backward, but hat no success */ |
| 977 | return tape_3590_erp_failed(device, request, irb, -EIO); |
| 978 | break; |
| 979 | default: |
| 980 | PRINT_WARN("read_opposite_recovery_called_with_op: %s\n", |
| 981 | tape_op_verbose[request->op]); |
| 982 | return tape_3590_erp_failed(device, request, irb, -EIO); |
| 983 | } |
| 984 | } |
| 985 | |
| 986 | /* |
| 987 | * Print an MIM (Media Information Message) (message code f0) |
| 988 | */ |
| 989 | static void |
| 990 | tape_3590_print_mim_msg_f0(struct tape_device *device, struct irb *irb) |
| 991 | { |
| 992 | struct tape_3590_sense *sense; |
| 993 | |
| 994 | sense = (struct tape_3590_sense *) irb->ecw; |
| 995 | /* Exception Message */ |
| 996 | switch (sense->fmt.f70.emc) { |
| 997 | case 0x02: |
| 998 | PRINT_WARN("(%s): Data degraded\n", device->cdev->dev.bus_id); |
| 999 | break; |
| 1000 | case 0x03: |
| 1001 | PRINT_WARN("(%s): Data degraded in partion %i\n", |
| 1002 | device->cdev->dev.bus_id, sense->fmt.f70.mp); |
| 1003 | break; |
| 1004 | case 0x04: |
| 1005 | PRINT_WARN("(%s): Medium degraded\n", device->cdev->dev.bus_id); |
| 1006 | break; |
| 1007 | case 0x05: |
| 1008 | PRINT_WARN("(%s): Medium degraded in partition %i\n", |
| 1009 | device->cdev->dev.bus_id, sense->fmt.f70.mp); |
| 1010 | break; |
| 1011 | case 0x06: |
| 1012 | PRINT_WARN("(%s): Block 0 Error\n", device->cdev->dev.bus_id); |
| 1013 | break; |
| 1014 | case 0x07: |
| 1015 | PRINT_WARN("(%s): Medium Exception 0x%02x\n", |
| 1016 | device->cdev->dev.bus_id, sense->fmt.f70.md); |
| 1017 | break; |
| 1018 | default: |
| 1019 | PRINT_WARN("(%s): MIM ExMsg: 0x%02x\n", |
| 1020 | device->cdev->dev.bus_id, sense->fmt.f70.emc); |
| 1021 | break; |
| 1022 | } |
| 1023 | /* Service Message */ |
| 1024 | switch (sense->fmt.f70.smc) { |
| 1025 | case 0x02: |
| 1026 | PRINT_WARN("(%s): Reference Media maintenance procedure %i\n", |
| 1027 | device->cdev->dev.bus_id, sense->fmt.f70.md); |
| 1028 | break; |
| 1029 | default: |
| 1030 | PRINT_WARN("(%s): MIM ServiceMsg: 0x%02x\n", |
| 1031 | device->cdev->dev.bus_id, sense->fmt.f70.smc); |
| 1032 | break; |
| 1033 | } |
| 1034 | } |
| 1035 | |
| 1036 | /* |
| 1037 | * Print an I/O Subsystem Service Information Message (message code f1) |
| 1038 | */ |
| 1039 | static void |
| 1040 | tape_3590_print_io_sim_msg_f1(struct tape_device *device, struct irb *irb) |
| 1041 | { |
| 1042 | struct tape_3590_sense *sense; |
| 1043 | |
| 1044 | sense = (struct tape_3590_sense *) irb->ecw; |
| 1045 | /* Exception Message */ |
| 1046 | switch (sense->fmt.f71.emc) { |
| 1047 | case 0x01: |
| 1048 | PRINT_WARN("(%s): Effect of failure is unknown\n", |
| 1049 | device->cdev->dev.bus_id); |
| 1050 | break; |
| 1051 | case 0x02: |
| 1052 | PRINT_WARN("(%s): CU Exception - no performance impact\n", |
| 1053 | device->cdev->dev.bus_id); |
| 1054 | break; |
| 1055 | case 0x03: |
| 1056 | PRINT_WARN("(%s): CU Exception on channel interface 0x%02x\n", |
| 1057 | device->cdev->dev.bus_id, sense->fmt.f71.md[0]); |
| 1058 | break; |
| 1059 | case 0x04: |
| 1060 | PRINT_WARN("(%s): CU Exception on device path 0x%02x\n", |
| 1061 | device->cdev->dev.bus_id, sense->fmt.f71.md[0]); |
| 1062 | break; |
| 1063 | case 0x05: |
| 1064 | PRINT_WARN("(%s): CU Exception on library path 0x%02x\n", |
| 1065 | device->cdev->dev.bus_id, sense->fmt.f71.md[0]); |
| 1066 | break; |
| 1067 | case 0x06: |
| 1068 | PRINT_WARN("(%s): CU Exception on node 0x%02x\n", |
| 1069 | device->cdev->dev.bus_id, sense->fmt.f71.md[0]); |
| 1070 | break; |
| 1071 | case 0x07: |
| 1072 | PRINT_WARN("(%s): CU Exception on partition 0x%02x\n", |
| 1073 | device->cdev->dev.bus_id, sense->fmt.f71.md[0]); |
| 1074 | break; |
| 1075 | default: |
| 1076 | PRINT_WARN("(%s): SIM ExMsg: 0x%02x\n", |
| 1077 | device->cdev->dev.bus_id, sense->fmt.f71.emc); |
| 1078 | } |
| 1079 | /* Service Message */ |
| 1080 | switch (sense->fmt.f71.smc) { |
| 1081 | case 0x01: |
| 1082 | PRINT_WARN("(%s): Repair impact is unknown\n", |
| 1083 | device->cdev->dev.bus_id); |
| 1084 | break; |
| 1085 | case 0x02: |
| 1086 | PRINT_WARN("(%s): Repair will not impact cu performance\n", |
| 1087 | device->cdev->dev.bus_id); |
| 1088 | break; |
| 1089 | case 0x03: |
| 1090 | if (sense->fmt.f71.mdf == 0) |
| 1091 | PRINT_WARN("(%s): Repair will disable node " |
| 1092 | "0x%x on CU\n", |
| 1093 | device->cdev->dev.bus_id, |
| 1094 | sense->fmt.f71.md[1]); |
| 1095 | else |
| 1096 | PRINT_WARN("(%s): Repair will disable nodes " |
| 1097 | "(0x%x-0x%x) on CU\n", |
| 1098 | device->cdev->dev.bus_id, |
| 1099 | sense->fmt.f71.md[1], sense->fmt.f71.md[2]); |
| 1100 | break; |
| 1101 | case 0x04: |
| 1102 | if (sense->fmt.f71.mdf == 0) |
| 1103 | PRINT_WARN("(%s): Repair will disable cannel path " |
| 1104 | "0x%x on CU\n", |
| 1105 | device->cdev->dev.bus_id, |
| 1106 | sense->fmt.f71.md[1]); |
| 1107 | else |
| 1108 | PRINT_WARN("(%s): Repair will disable cannel paths " |
| 1109 | "(0x%x-0x%x) on CU\n", |
| 1110 | device->cdev->dev.bus_id, |
| 1111 | sense->fmt.f71.md[1], sense->fmt.f71.md[2]); |
| 1112 | break; |
| 1113 | case 0x05: |
| 1114 | if (sense->fmt.f71.mdf == 0) |
| 1115 | PRINT_WARN("(%s): Repair will disable device path " |
| 1116 | "0x%x on CU\n", |
| 1117 | device->cdev->dev.bus_id, |
| 1118 | sense->fmt.f71.md[1]); |
| 1119 | else |
| 1120 | PRINT_WARN("(%s): Repair will disable device paths " |
| 1121 | "(0x%x-0x%x) on CU\n", |
| 1122 | device->cdev->dev.bus_id, |
| 1123 | sense->fmt.f71.md[1], sense->fmt.f71.md[2]); |
| 1124 | break; |
| 1125 | case 0x06: |
| 1126 | if (sense->fmt.f71.mdf == 0) |
| 1127 | PRINT_WARN("(%s): Repair will disable library path " |
| 1128 | "0x%x on CU\n", |
| 1129 | device->cdev->dev.bus_id, |
| 1130 | sense->fmt.f71.md[1]); |
| 1131 | else |
| 1132 | PRINT_WARN("(%s): Repair will disable library paths " |
| 1133 | "(0x%x-0x%x) on CU\n", |
| 1134 | device->cdev->dev.bus_id, |
| 1135 | sense->fmt.f71.md[1], sense->fmt.f71.md[2]); |
| 1136 | break; |
| 1137 | case 0x07: |
| 1138 | PRINT_WARN("(%s): Repair will disable access to CU\n", |
| 1139 | device->cdev->dev.bus_id); |
| 1140 | break; |
| 1141 | default: |
| 1142 | PRINT_WARN("(%s): SIM ServiceMsg: 0x%02x\n", |
| 1143 | device->cdev->dev.bus_id, sense->fmt.f71.smc); |
| 1144 | } |
| 1145 | } |
| 1146 | |
| 1147 | /* |
| 1148 | * Print an Device Subsystem Service Information Message (message code f2) |
| 1149 | */ |
| 1150 | static void |
| 1151 | tape_3590_print_dev_sim_msg_f2(struct tape_device *device, struct irb *irb) |
| 1152 | { |
| 1153 | struct tape_3590_sense *sense; |
| 1154 | |
| 1155 | sense = (struct tape_3590_sense *) irb->ecw; |
| 1156 | /* Exception Message */ |
| 1157 | switch (sense->fmt.f71.emc) { |
| 1158 | case 0x01: |
| 1159 | PRINT_WARN("(%s): Effect of failure is unknown\n", |
| 1160 | device->cdev->dev.bus_id); |
| 1161 | break; |
| 1162 | case 0x02: |
| 1163 | PRINT_WARN("(%s): DV Exception - no performance impact\n", |
| 1164 | device->cdev->dev.bus_id); |
| 1165 | break; |
| 1166 | case 0x03: |
| 1167 | PRINT_WARN("(%s): DV Exception on channel interface 0x%02x\n", |
| 1168 | device->cdev->dev.bus_id, sense->fmt.f71.md[0]); |
| 1169 | break; |
| 1170 | case 0x04: |
| 1171 | PRINT_WARN("(%s): DV Exception on loader 0x%02x\n", |
| 1172 | device->cdev->dev.bus_id, sense->fmt.f71.md[0]); |
| 1173 | break; |
| 1174 | case 0x05: |
| 1175 | PRINT_WARN("(%s): DV Exception on message display 0x%02x\n", |
| 1176 | device->cdev->dev.bus_id, sense->fmt.f71.md[0]); |
| 1177 | break; |
| 1178 | case 0x06: |
| 1179 | PRINT_WARN("(%s): DV Exception in tape path\n", |
| 1180 | device->cdev->dev.bus_id); |
| 1181 | break; |
| 1182 | case 0x07: |
| 1183 | PRINT_WARN("(%s): DV Exception in drive\n", |
| 1184 | device->cdev->dev.bus_id); |
| 1185 | break; |
| 1186 | default: |
| 1187 | PRINT_WARN("(%s): DSIM ExMsg: 0x%02x\n", |
| 1188 | device->cdev->dev.bus_id, sense->fmt.f71.emc); |
| 1189 | } |
| 1190 | /* Service Message */ |
| 1191 | switch (sense->fmt.f71.smc) { |
| 1192 | case 0x01: |
| 1193 | PRINT_WARN("(%s): Repair impact is unknown\n", |
| 1194 | device->cdev->dev.bus_id); |
| 1195 | break; |
| 1196 | case 0x02: |
| 1197 | PRINT_WARN("(%s): Repair will not impact device performance\n", |
| 1198 | device->cdev->dev.bus_id); |
| 1199 | break; |
| 1200 | case 0x03: |
| 1201 | if (sense->fmt.f71.mdf == 0) |
| 1202 | PRINT_WARN("(%s): Repair will disable channel path " |
| 1203 | "0x%x on DV\n", |
| 1204 | device->cdev->dev.bus_id, |
| 1205 | sense->fmt.f71.md[1]); |
| 1206 | else |
| 1207 | PRINT_WARN("(%s): Repair will disable channel path " |
| 1208 | "(0x%x-0x%x) on DV\n", |
| 1209 | device->cdev->dev.bus_id, |
| 1210 | sense->fmt.f71.md[1], sense->fmt.f71.md[2]); |
| 1211 | break; |
| 1212 | case 0x04: |
| 1213 | if (sense->fmt.f71.mdf == 0) |
| 1214 | PRINT_WARN("(%s): Repair will disable interface 0x%x " |
| 1215 | "on DV\n", |
| 1216 | device->cdev->dev.bus_id, |
| 1217 | sense->fmt.f71.md[1]); |
| 1218 | else |
| 1219 | PRINT_WARN("(%s): Repair will disable interfaces " |
| 1220 | "(0x%x-0x%x) on DV\n", |
| 1221 | device->cdev->dev.bus_id, |
| 1222 | sense->fmt.f71.md[1], sense->fmt.f71.md[2]); |
| 1223 | break; |
| 1224 | case 0x05: |
| 1225 | if (sense->fmt.f71.mdf == 0) |
| 1226 | PRINT_WARN("(%s): Repair will disable loader 0x%x " |
| 1227 | "on DV\n", |
| 1228 | device->cdev->dev.bus_id, |
| 1229 | sense->fmt.f71.md[1]); |
| 1230 | else |
| 1231 | PRINT_WARN("(%s): Repair will disable loader " |
| 1232 | "(0x%x-0x%x) on DV\n", |
| 1233 | device->cdev->dev.bus_id, |
| 1234 | sense->fmt.f71.md[1], sense->fmt.f71.md[2]); |
| 1235 | break; |
| 1236 | case 0x07: |
| 1237 | PRINT_WARN("(%s): Repair will disable access to DV\n", |
| 1238 | device->cdev->dev.bus_id); |
| 1239 | break; |
| 1240 | case 0x08: |
| 1241 | if (sense->fmt.f71.mdf == 0) |
| 1242 | PRINT_WARN("(%s): Repair will disable message " |
| 1243 | "display 0x%x on DV\n", |
| 1244 | device->cdev->dev.bus_id, |
| 1245 | sense->fmt.f71.md[1]); |
| 1246 | else |
| 1247 | PRINT_WARN("(%s): Repair will disable message " |
| 1248 | "displays (0x%x-0x%x) on DV\n", |
| 1249 | device->cdev->dev.bus_id, |
| 1250 | sense->fmt.f71.md[1], sense->fmt.f71.md[2]); |
| 1251 | break; |
| 1252 | case 0x09: |
| 1253 | PRINT_WARN("(%s): Clean DV\n", device->cdev->dev.bus_id); |
| 1254 | break; |
| 1255 | default: |
| 1256 | PRINT_WARN("(%s): DSIM ServiceMsg: 0x%02x\n", |
| 1257 | device->cdev->dev.bus_id, sense->fmt.f71.smc); |
| 1258 | } |
| 1259 | } |
| 1260 | |
| 1261 | /* |
| 1262 | * Print standard ERA Message |
| 1263 | */ |
| 1264 | static void |
| 1265 | tape_3590_print_era_msg(struct tape_device *device, struct irb *irb) |
| 1266 | { |
| 1267 | struct tape_3590_sense *sense; |
| 1268 | |
| 1269 | sense = (struct tape_3590_sense *) irb->ecw; |
| 1270 | if (sense->mc == 0) |
| 1271 | return; |
| 1272 | if ((sense->mc > 0) && (sense->mc < TAPE_3590_MAX_MSG)) { |
| 1273 | if (tape_3590_msg[sense->mc] != NULL) |
| 1274 | PRINT_WARN("(%s): %s\n", device->cdev->dev.bus_id, |
| 1275 | tape_3590_msg[sense->mc]); |
| 1276 | else { |
| 1277 | PRINT_WARN("(%s): Message Code 0x%x\n", |
| 1278 | device->cdev->dev.bus_id, sense->mc); |
| 1279 | } |
| 1280 | return; |
| 1281 | } |
| 1282 | if (sense->mc == 0xf0) { |
| 1283 | /* Standard Media Information Message */ |
| 1284 | PRINT_WARN("(%s): MIM SEV=%i, MC=%02x, ES=%x/%x, " |
| 1285 | "RC=%02x-%04x-%02x\n", device->cdev->dev.bus_id, |
| 1286 | sense->fmt.f70.sev, sense->mc, |
| 1287 | sense->fmt.f70.emc, sense->fmt.f70.smc, |
| 1288 | sense->fmt.f70.refcode, sense->fmt.f70.mid, |
| 1289 | sense->fmt.f70.fid); |
| 1290 | tape_3590_print_mim_msg_f0(device, irb); |
| 1291 | return; |
| 1292 | } |
| 1293 | if (sense->mc == 0xf1) { |
| 1294 | /* Standard I/O Subsystem Service Information Message */ |
| 1295 | PRINT_WARN("(%s): IOSIM SEV=%i, DEVTYPE=3590/%02x, " |
| 1296 | "MC=%02x, ES=%x/%x, REF=0x%04x-0x%04x-0x%04x\n", |
| 1297 | device->cdev->dev.bus_id, sense->fmt.f71.sev, |
| 1298 | device->cdev->id.dev_model, |
| 1299 | sense->mc, sense->fmt.f71.emc, |
| 1300 | sense->fmt.f71.smc, sense->fmt.f71.refcode1, |
| 1301 | sense->fmt.f71.refcode2, sense->fmt.f71.refcode3); |
| 1302 | tape_3590_print_io_sim_msg_f1(device, irb); |
| 1303 | return; |
| 1304 | } |
| 1305 | if (sense->mc == 0xf2) { |
| 1306 | /* Standard Device Service Information Message */ |
| 1307 | PRINT_WARN("(%s): DEVSIM SEV=%i, DEVTYPE=3590/%02x, " |
| 1308 | "MC=%02x, ES=%x/%x, REF=0x%04x-0x%04x-0x%04x\n", |
| 1309 | device->cdev->dev.bus_id, sense->fmt.f71.sev, |
| 1310 | device->cdev->id.dev_model, |
| 1311 | sense->mc, sense->fmt.f71.emc, |
| 1312 | sense->fmt.f71.smc, sense->fmt.f71.refcode1, |
| 1313 | sense->fmt.f71.refcode2, sense->fmt.f71.refcode3); |
| 1314 | tape_3590_print_dev_sim_msg_f2(device, irb); |
| 1315 | return; |
| 1316 | } |
| 1317 | if (sense->mc == 0xf3) { |
| 1318 | /* Standard Library Service Information Message */ |
| 1319 | return; |
| 1320 | } |
| 1321 | PRINT_WARN("(%s): Device Message(%x)\n", |
| 1322 | device->cdev->dev.bus_id, sense->mc); |
| 1323 | } |
| 1324 | |
Michael Holzheu | cced1dd | 2007-02-05 21:18:26 +0100 | [diff] [blame] | 1325 | static int tape_3590_crypt_error(struct tape_device *device, |
| 1326 | struct tape_request *request, struct irb *irb) |
| 1327 | { |
| 1328 | u8 cu_rc, ekm_rc1; |
| 1329 | u16 ekm_rc2; |
| 1330 | u32 drv_rc; |
| 1331 | char *bus_id, *sense; |
| 1332 | |
| 1333 | sense = ((struct tape_3590_sense *) irb->ecw)->fmt.data; |
| 1334 | bus_id = device->cdev->dev.bus_id; |
| 1335 | cu_rc = sense[0]; |
| 1336 | drv_rc = *((u32*) &sense[5]) & 0xffffff; |
| 1337 | ekm_rc1 = sense[9]; |
| 1338 | ekm_rc2 = *((u16*) &sense[10]); |
| 1339 | if ((cu_rc == 0) && (ekm_rc2 == 0xee31)) |
| 1340 | /* key not defined on EKM */ |
| 1341 | return tape_3590_erp_basic(device, request, irb, -EKEYREJECTED); |
| 1342 | if ((cu_rc == 1) || (cu_rc == 2)) |
| 1343 | /* No connection to EKM */ |
| 1344 | return tape_3590_erp_basic(device, request, irb, -ENOTCONN); |
| 1345 | |
| 1346 | PRINT_ERR("(%s): Unable to get encryption key from EKM\n", bus_id); |
| 1347 | PRINT_ERR("(%s): CU=%02X DRIVE=%06X EKM=%02X:%04X\n", bus_id, cu_rc, |
| 1348 | drv_rc, ekm_rc1, ekm_rc2); |
| 1349 | |
| 1350 | return tape_3590_erp_basic(device, request, irb, -ENOKEY); |
| 1351 | } |
| 1352 | |
Stefan Bader | b6cba4e | 2006-03-24 03:15:29 -0800 | [diff] [blame] | 1353 | /* |
| 1354 | * 3590 error Recovery routine: |
| 1355 | * If possible, it tries to recover from the error. If this is not possible, |
| 1356 | * inform the user about the problem. |
| 1357 | */ |
| 1358 | static int |
| 1359 | tape_3590_unit_check(struct tape_device *device, struct tape_request *request, |
| 1360 | struct irb *irb) |
| 1361 | { |
| 1362 | struct tape_3590_sense *sense; |
| 1363 | int rc; |
| 1364 | |
| 1365 | #ifdef CONFIG_S390_TAPE_BLOCK |
| 1366 | if (request->op == TO_BLOCK) { |
| 1367 | /* |
| 1368 | * Recovery for block device requests. Set the block_position |
| 1369 | * to something invalid and retry. |
| 1370 | */ |
| 1371 | device->blk_data.block_position = -1; |
| 1372 | if (request->retries-- <= 0) |
| 1373 | return tape_3590_erp_failed(device, request, irb, -EIO); |
| 1374 | else |
| 1375 | return tape_3590_erp_retry(device, request, irb); |
| 1376 | } |
| 1377 | #endif |
| 1378 | |
| 1379 | sense = (struct tape_3590_sense *) irb->ecw; |
| 1380 | |
Michael Holzheu | cced1dd | 2007-02-05 21:18:26 +0100 | [diff] [blame] | 1381 | DBF_EVENT(6, "Unit Check: RQC = %x\n", sense->rc_rqc); |
| 1382 | |
Stefan Bader | b6cba4e | 2006-03-24 03:15:29 -0800 | [diff] [blame] | 1383 | /* |
| 1384 | * First check all RC-QRCs where we want to do something special |
| 1385 | * - "break": basic error recovery is done |
| 1386 | * - "goto out:": just print error message if available |
| 1387 | */ |
| 1388 | rc = -EIO; |
| 1389 | switch (sense->rc_rqc) { |
| 1390 | |
| 1391 | case 0x1110: |
| 1392 | tape_3590_print_era_msg(device, irb); |
| 1393 | return tape_3590_erp_read_buf_log(device, request, irb); |
| 1394 | |
| 1395 | case 0x2011: |
| 1396 | tape_3590_print_era_msg(device, irb); |
| 1397 | return tape_3590_erp_read_alternate(device, request, irb); |
| 1398 | |
| 1399 | case 0x2230: |
| 1400 | case 0x2231: |
| 1401 | tape_3590_print_era_msg(device, irb); |
| 1402 | return tape_3590_erp_special_interrupt(device, request, irb); |
Michael Holzheu | cced1dd | 2007-02-05 21:18:26 +0100 | [diff] [blame] | 1403 | case 0x2240: |
| 1404 | return tape_3590_crypt_error(device, request, irb); |
Stefan Bader | b6cba4e | 2006-03-24 03:15:29 -0800 | [diff] [blame] | 1405 | |
| 1406 | case 0x3010: |
| 1407 | DBF_EVENT(2, "(%08x): Backward at Beginning of Partition\n", |
| 1408 | device->cdev_id); |
| 1409 | return tape_3590_erp_basic(device, request, irb, -ENOSPC); |
| 1410 | case 0x3012: |
| 1411 | DBF_EVENT(2, "(%08x): Forward at End of Partition\n", |
| 1412 | device->cdev_id); |
| 1413 | return tape_3590_erp_basic(device, request, irb, -ENOSPC); |
| 1414 | case 0x3020: |
| 1415 | DBF_EVENT(2, "(%08x): End of Data Mark\n", device->cdev_id); |
| 1416 | return tape_3590_erp_basic(device, request, irb, -ENOSPC); |
| 1417 | |
| 1418 | case 0x3122: |
| 1419 | DBF_EVENT(2, "(%08x): Rewind Unload initiated\n", |
| 1420 | device->cdev_id); |
| 1421 | return tape_3590_erp_basic(device, request, irb, -EIO); |
| 1422 | case 0x3123: |
| 1423 | DBF_EVENT(2, "(%08x): Rewind Unload complete\n", |
| 1424 | device->cdev_id); |
| 1425 | tape_med_state_set(device, MS_UNLOADED); |
Michael Holzheu | cced1dd | 2007-02-05 21:18:26 +0100 | [diff] [blame] | 1426 | tape_3590_schedule_work(device, TO_CRYPT_OFF); |
Stefan Bader | b6cba4e | 2006-03-24 03:15:29 -0800 | [diff] [blame] | 1427 | return tape_3590_erp_basic(device, request, irb, 0); |
| 1428 | |
| 1429 | case 0x4010: |
| 1430 | /* |
| 1431 | * print additional msg since default msg |
| 1432 | * "device intervention" is not very meaningfull |
| 1433 | */ |
| 1434 | PRINT_WARN("(%s): Tape operation when medium not loaded\n", |
| 1435 | device->cdev->dev.bus_id); |
| 1436 | tape_med_state_set(device, MS_UNLOADED); |
Michael Holzheu | cced1dd | 2007-02-05 21:18:26 +0100 | [diff] [blame] | 1437 | tape_3590_schedule_work(device, TO_CRYPT_OFF); |
Stefan Bader | b6cba4e | 2006-03-24 03:15:29 -0800 | [diff] [blame] | 1438 | return tape_3590_erp_basic(device, request, irb, -ENOMEDIUM); |
| 1439 | case 0x4012: /* Device Long Busy */ |
Michael Holzheu | cced1dd | 2007-02-05 21:18:26 +0100 | [diff] [blame] | 1440 | /* XXX: Also use long busy handling here? */ |
| 1441 | DBF_EVENT(6, "(%08x): LONG BUSY\n", device->cdev_id); |
Stefan Bader | b6cba4e | 2006-03-24 03:15:29 -0800 | [diff] [blame] | 1442 | tape_3590_print_era_msg(device, irb); |
Michael Holzheu | cced1dd | 2007-02-05 21:18:26 +0100 | [diff] [blame] | 1443 | return tape_3590_erp_basic(device, request, irb, -EBUSY); |
| 1444 | case 0x4014: |
| 1445 | DBF_EVENT(6, "(%08x): Crypto LONG BUSY\n", device->cdev_id); |
Stefan Bader | b6cba4e | 2006-03-24 03:15:29 -0800 | [diff] [blame] | 1446 | return tape_3590_erp_long_busy(device, request, irb); |
| 1447 | |
| 1448 | case 0x5010: |
| 1449 | if (sense->rac == 0xd0) { |
| 1450 | /* Swap */ |
| 1451 | tape_3590_print_era_msg(device, irb); |
| 1452 | return tape_3590_erp_swap(device, request, irb); |
| 1453 | } |
| 1454 | if (sense->rac == 0x26) { |
| 1455 | /* Read Opposite */ |
| 1456 | tape_3590_print_era_msg(device, irb); |
| 1457 | return tape_3590_erp_read_opposite(device, request, |
| 1458 | irb); |
| 1459 | } |
| 1460 | return tape_3590_erp_basic(device, request, irb, -EIO); |
| 1461 | case 0x5020: |
| 1462 | case 0x5021: |
| 1463 | case 0x5022: |
| 1464 | case 0x5040: |
| 1465 | case 0x5041: |
| 1466 | case 0x5042: |
| 1467 | tape_3590_print_era_msg(device, irb); |
| 1468 | return tape_3590_erp_swap(device, request, irb); |
| 1469 | |
| 1470 | case 0x5110: |
| 1471 | case 0x5111: |
| 1472 | return tape_3590_erp_basic(device, request, irb, -EMEDIUMTYPE); |
| 1473 | |
| 1474 | case 0x5120: |
| 1475 | case 0x1120: |
| 1476 | tape_med_state_set(device, MS_UNLOADED); |
Michael Holzheu | cced1dd | 2007-02-05 21:18:26 +0100 | [diff] [blame] | 1477 | tape_3590_schedule_work(device, TO_CRYPT_OFF); |
Stefan Bader | b6cba4e | 2006-03-24 03:15:29 -0800 | [diff] [blame] | 1478 | return tape_3590_erp_basic(device, request, irb, -ENOMEDIUM); |
| 1479 | |
| 1480 | case 0x6020: |
| 1481 | PRINT_WARN("(%s): Cartridge of wrong type ?\n", |
| 1482 | device->cdev->dev.bus_id); |
| 1483 | return tape_3590_erp_basic(device, request, irb, -EMEDIUMTYPE); |
| 1484 | |
| 1485 | case 0x8011: |
| 1486 | PRINT_WARN("(%s): Another host has reserved the tape device\n", |
| 1487 | device->cdev->dev.bus_id); |
| 1488 | return tape_3590_erp_basic(device, request, irb, -EPERM); |
| 1489 | case 0x8013: |
| 1490 | PRINT_WARN("(%s): Another host has priviliged access to the " |
| 1491 | "tape device\n", device->cdev->dev.bus_id); |
| 1492 | PRINT_WARN("(%s): To solve the problem unload the current " |
| 1493 | "cartridge!\n", device->cdev->dev.bus_id); |
| 1494 | return tape_3590_erp_basic(device, request, irb, -EPERM); |
| 1495 | default: |
| 1496 | return tape_3590_erp_basic(device, request, irb, -EIO); |
| 1497 | } |
| 1498 | } |
| 1499 | |
| 1500 | /* |
| 1501 | * 3590 interrupt handler: |
| 1502 | */ |
| 1503 | static int |
| 1504 | tape_3590_irq(struct tape_device *device, struct tape_request *request, |
| 1505 | struct irb *irb) |
| 1506 | { |
| 1507 | if (request == NULL) |
| 1508 | return tape_3590_unsolicited_irq(device, irb); |
| 1509 | |
| 1510 | if ((irb->scsw.dstat & DEV_STAT_UNIT_EXCEP) && |
| 1511 | (irb->scsw.dstat & DEV_STAT_DEV_END) && (request->op == TO_WRI)) { |
| 1512 | /* Write at end of volume */ |
| 1513 | DBF_EVENT(2, "End of volume\n"); |
| 1514 | return tape_3590_erp_failed(device, request, irb, -ENOSPC); |
| 1515 | } |
| 1516 | |
| 1517 | if (irb->scsw.dstat & DEV_STAT_UNIT_CHECK) |
| 1518 | return tape_3590_unit_check(device, request, irb); |
| 1519 | |
| 1520 | if (irb->scsw.dstat & DEV_STAT_DEV_END) { |
| 1521 | if (irb->scsw.dstat == DEV_STAT_UNIT_EXCEP) { |
| 1522 | if (request->op == TO_FSB || request->op == TO_BSB) |
| 1523 | request->rescnt++; |
| 1524 | else |
| 1525 | DBF_EVENT(5, "Unit Exception!\n"); |
| 1526 | } |
| 1527 | |
| 1528 | return tape_3590_done(device, request); |
| 1529 | } |
| 1530 | |
| 1531 | if (irb->scsw.dstat & DEV_STAT_CHN_END) { |
| 1532 | DBF_EVENT(2, "cannel end\n"); |
| 1533 | return TAPE_IO_PENDING; |
| 1534 | } |
| 1535 | |
| 1536 | if (irb->scsw.dstat & DEV_STAT_ATTENTION) { |
| 1537 | DBF_EVENT(2, "Unit Attention when busy..\n"); |
| 1538 | return TAPE_IO_PENDING; |
| 1539 | } |
| 1540 | |
| 1541 | DBF_EVENT(6, "xunknownirq\n"); |
| 1542 | PRINT_ERR("Unexpected interrupt.\n"); |
| 1543 | PRINT_ERR("Current op is: %s", tape_op_verbose[request->op]); |
| 1544 | tape_dump_sense(device, request, irb); |
| 1545 | return TAPE_IO_STOP; |
| 1546 | } |
| 1547 | |
Michael Holzheu | e296306 | 2007-05-04 18:47:53 +0200 | [diff] [blame] | 1548 | |
| 1549 | static int tape_3590_read_dev_chars(struct tape_device *device, |
| 1550 | struct tape_3590_rdc_data *rdc_data) |
| 1551 | { |
| 1552 | int rc; |
| 1553 | struct tape_request *request; |
| 1554 | |
| 1555 | request = tape_alloc_request(1, sizeof(*rdc_data)); |
| 1556 | if (IS_ERR(request)) |
| 1557 | return PTR_ERR(request); |
| 1558 | request->op = TO_RDC; |
| 1559 | tape_ccw_end(request->cpaddr, CCW_CMD_RDC, sizeof(*rdc_data), |
| 1560 | request->cpdata); |
| 1561 | rc = tape_do_io(device, request); |
| 1562 | if (rc == 0) |
| 1563 | memcpy(rdc_data, request->cpdata, sizeof(*rdc_data)); |
| 1564 | tape_free_request(request); |
| 1565 | return rc; |
| 1566 | } |
| 1567 | |
Stefan Bader | b6cba4e | 2006-03-24 03:15:29 -0800 | [diff] [blame] | 1568 | /* |
| 1569 | * Setup device function |
| 1570 | */ |
| 1571 | static int |
| 1572 | tape_3590_setup_device(struct tape_device *device) |
| 1573 | { |
| 1574 | int rc; |
| 1575 | struct tape_3590_disc_data *data; |
Michael Holzheu | e296306 | 2007-05-04 18:47:53 +0200 | [diff] [blame] | 1576 | struct tape_3590_rdc_data *rdc_data; |
Stefan Bader | b6cba4e | 2006-03-24 03:15:29 -0800 | [diff] [blame] | 1577 | |
| 1578 | DBF_EVENT(6, "3590 device setup\n"); |
Michael Holzheu | cced1dd | 2007-02-05 21:18:26 +0100 | [diff] [blame] | 1579 | data = kzalloc(sizeof(struct tape_3590_disc_data), GFP_KERNEL | GFP_DMA); |
Stefan Bader | b6cba4e | 2006-03-24 03:15:29 -0800 | [diff] [blame] | 1580 | if (data == NULL) |
| 1581 | return -ENOMEM; |
| 1582 | data->read_back_op = READ_PREVIOUS; |
| 1583 | device->discdata = data; |
| 1584 | |
Michael Holzheu | e296306 | 2007-05-04 18:47:53 +0200 | [diff] [blame] | 1585 | rdc_data = kmalloc(sizeof(*rdc_data), GFP_KERNEL | GFP_DMA); |
Michael Holzheu | cced1dd | 2007-02-05 21:18:26 +0100 | [diff] [blame] | 1586 | if (!rdc_data) { |
| 1587 | rc = -ENOMEM; |
| 1588 | goto fail_kmalloc; |
Stefan Bader | b6cba4e | 2006-03-24 03:15:29 -0800 | [diff] [blame] | 1589 | } |
Michael Holzheu | e296306 | 2007-05-04 18:47:53 +0200 | [diff] [blame] | 1590 | rc = tape_3590_read_dev_chars(device, rdc_data); |
Michael Holzheu | cced1dd | 2007-02-05 21:18:26 +0100 | [diff] [blame] | 1591 | if (rc) { |
| 1592 | DBF_LH(3, "Read device characteristics failed!\n"); |
| 1593 | goto fail_kmalloc; |
| 1594 | } |
| 1595 | rc = tape_std_assign(device); |
| 1596 | if (rc) |
| 1597 | goto fail_rdc_data; |
Michael Holzheu | e296306 | 2007-05-04 18:47:53 +0200 | [diff] [blame] | 1598 | if (rdc_data->data[31] == 0x13) { |
Michael Holzheu | cced1dd | 2007-02-05 21:18:26 +0100 | [diff] [blame] | 1599 | PRINT_INFO("Device has crypto support\n"); |
| 1600 | data->crypt_info.capability |= TAPE390_CRYPT_SUPPORTED_MASK; |
| 1601 | tape_3592_disable_crypt(device); |
| 1602 | } else { |
| 1603 | DBF_EVENT(6, "Device has NO crypto support\n"); |
| 1604 | } |
| 1605 | /* Try to find out if medium is loaded */ |
| 1606 | rc = tape_3590_sense_medium(device); |
| 1607 | if (rc) { |
| 1608 | DBF_LH(3, "3590 medium sense returned %d\n", rc); |
| 1609 | goto fail_rdc_data; |
| 1610 | } |
| 1611 | return 0; |
Stefan Bader | b6cba4e | 2006-03-24 03:15:29 -0800 | [diff] [blame] | 1612 | |
Michael Holzheu | cced1dd | 2007-02-05 21:18:26 +0100 | [diff] [blame] | 1613 | fail_rdc_data: |
| 1614 | kfree(rdc_data); |
| 1615 | fail_kmalloc: |
| 1616 | kfree(data); |
Stefan Bader | b6cba4e | 2006-03-24 03:15:29 -0800 | [diff] [blame] | 1617 | return rc; |
| 1618 | } |
| 1619 | |
| 1620 | /* |
| 1621 | * Cleanup device function |
| 1622 | */ |
| 1623 | static void |
| 1624 | tape_3590_cleanup_device(struct tape_device *device) |
| 1625 | { |
Stefan Bader | 2cc924b | 2006-04-27 18:40:16 -0700 | [diff] [blame] | 1626 | flush_scheduled_work(); |
Stefan Bader | b6cba4e | 2006-03-24 03:15:29 -0800 | [diff] [blame] | 1627 | tape_std_unassign(device); |
| 1628 | |
| 1629 | kfree(device->discdata); |
| 1630 | device->discdata = NULL; |
| 1631 | } |
| 1632 | |
| 1633 | /* |
| 1634 | * List of 3590 magnetic tape commands. |
| 1635 | */ |
| 1636 | static tape_mtop_fn tape_3590_mtop[TAPE_NR_MTOPS] = { |
| 1637 | [MTRESET] = tape_std_mtreset, |
| 1638 | [MTFSF] = tape_std_mtfsf, |
| 1639 | [MTBSF] = tape_std_mtbsf, |
| 1640 | [MTFSR] = tape_std_mtfsr, |
| 1641 | [MTBSR] = tape_std_mtbsr, |
| 1642 | [MTWEOF] = tape_std_mtweof, |
| 1643 | [MTREW] = tape_std_mtrew, |
| 1644 | [MTOFFL] = tape_std_mtoffl, |
| 1645 | [MTNOP] = tape_std_mtnop, |
| 1646 | [MTRETEN] = tape_std_mtreten, |
| 1647 | [MTBSFM] = tape_std_mtbsfm, |
| 1648 | [MTFSFM] = tape_std_mtfsfm, |
| 1649 | [MTEOM] = tape_std_mteom, |
| 1650 | [MTERASE] = tape_std_mterase, |
| 1651 | [MTRAS1] = NULL, |
| 1652 | [MTRAS2] = NULL, |
| 1653 | [MTRAS3] = NULL, |
| 1654 | [MTSETBLK] = tape_std_mtsetblk, |
| 1655 | [MTSETDENSITY] = NULL, |
| 1656 | [MTSEEK] = tape_3590_mtseek, |
| 1657 | [MTTELL] = tape_3590_mttell, |
| 1658 | [MTSETDRVBUFFER] = NULL, |
| 1659 | [MTFSS] = NULL, |
| 1660 | [MTBSS] = NULL, |
| 1661 | [MTWSM] = NULL, |
| 1662 | [MTLOCK] = NULL, |
| 1663 | [MTUNLOCK] = NULL, |
| 1664 | [MTLOAD] = tape_std_mtload, |
| 1665 | [MTUNLOAD] = tape_std_mtunload, |
| 1666 | [MTCOMPRESSION] = tape_std_mtcompression, |
| 1667 | [MTSETPART] = NULL, |
| 1668 | [MTMKPART] = NULL |
| 1669 | }; |
| 1670 | |
| 1671 | /* |
| 1672 | * Tape discipline structure for 3590. |
| 1673 | */ |
| 1674 | static struct tape_discipline tape_discipline_3590 = { |
| 1675 | .owner = THIS_MODULE, |
| 1676 | .setup_device = tape_3590_setup_device, |
| 1677 | .cleanup_device = tape_3590_cleanup_device, |
| 1678 | .process_eov = tape_std_process_eov, |
| 1679 | .irq = tape_3590_irq, |
| 1680 | .read_block = tape_std_read_block, |
| 1681 | .write_block = tape_std_write_block, |
| 1682 | #ifdef CONFIG_S390_TAPE_BLOCK |
| 1683 | .bread = tape_3590_bread, |
| 1684 | .free_bread = tape_3590_free_bread, |
| 1685 | .check_locate = tape_3590_check_locate, |
| 1686 | #endif |
| 1687 | .ioctl_fn = tape_3590_ioctl, |
| 1688 | .mtop_array = tape_3590_mtop |
| 1689 | }; |
| 1690 | |
| 1691 | static struct ccw_device_id tape_3590_ids[] = { |
| 1692 | {CCW_DEVICE_DEVTYPE(0x3590, 0, 0x3590, 0), .driver_info = tape_3590}, |
Stefan Bader | 2cc924b | 2006-04-27 18:40:16 -0700 | [diff] [blame] | 1693 | {CCW_DEVICE_DEVTYPE(0x3592, 0, 0x3592, 0), .driver_info = tape_3592}, |
Stefan Bader | b6cba4e | 2006-03-24 03:15:29 -0800 | [diff] [blame] | 1694 | { /* end of list */ } |
| 1695 | }; |
| 1696 | |
| 1697 | static int |
| 1698 | tape_3590_online(struct ccw_device *cdev) |
| 1699 | { |
| 1700 | return tape_generic_online(cdev->dev.driver_data, |
| 1701 | &tape_discipline_3590); |
| 1702 | } |
| 1703 | |
| 1704 | static int |
| 1705 | tape_3590_offline(struct ccw_device *cdev) |
| 1706 | { |
| 1707 | return tape_generic_offline(cdev->dev.driver_data); |
| 1708 | } |
| 1709 | |
| 1710 | static struct ccw_driver tape_3590_driver = { |
| 1711 | .name = "tape_3590", |
| 1712 | .owner = THIS_MODULE, |
| 1713 | .ids = tape_3590_ids, |
| 1714 | .probe = tape_generic_probe, |
| 1715 | .remove = tape_generic_remove, |
| 1716 | .set_offline = tape_3590_offline, |
| 1717 | .set_online = tape_3590_online, |
| 1718 | }; |
| 1719 | |
| 1720 | /* |
| 1721 | * Setup discipline structure. |
| 1722 | */ |
| 1723 | static int |
| 1724 | tape_3590_init(void) |
| 1725 | { |
| 1726 | int rc; |
| 1727 | |
| 1728 | TAPE_DBF_AREA = debug_register("tape_3590", 2, 2, 4 * sizeof(long)); |
| 1729 | debug_register_view(TAPE_DBF_AREA, &debug_sprintf_view); |
| 1730 | #ifdef DBF_LIKE_HELL |
| 1731 | debug_set_level(TAPE_DBF_AREA, 6); |
| 1732 | #endif |
| 1733 | |
| 1734 | DBF_EVENT(3, "3590 init\n"); |
| 1735 | /* Register driver for 3590 tapes. */ |
| 1736 | rc = ccw_driver_register(&tape_3590_driver); |
| 1737 | if (rc) |
| 1738 | DBF_EVENT(3, "3590 init failed\n"); |
| 1739 | else |
| 1740 | DBF_EVENT(3, "3590 registered\n"); |
| 1741 | return rc; |
| 1742 | } |
| 1743 | |
| 1744 | static void |
| 1745 | tape_3590_exit(void) |
| 1746 | { |
| 1747 | ccw_driver_unregister(&tape_3590_driver); |
| 1748 | |
| 1749 | debug_unregister(TAPE_DBF_AREA); |
| 1750 | } |
| 1751 | |
| 1752 | MODULE_DEVICE_TABLE(ccw, tape_3590_ids); |
| 1753 | MODULE_AUTHOR("(C) 2001,2006 IBM Corporation"); |
| 1754 | MODULE_DESCRIPTION("Linux on zSeries channel attached 3590 tape device driver"); |
| 1755 | MODULE_LICENSE("GPL"); |
| 1756 | |
| 1757 | module_init(tape_3590_init); |
| 1758 | module_exit(tape_3590_exit); |