10 #define KMSG_COMPONENT "tape_3590"
11 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
13 #include <linux/module.h>
14 #include <linux/slab.h>
19 #define TAPE_DBF_AREA tape_3590_dbf
47 [0x10] =
"Lost Sense",
48 [0x11] =
"Assigned Elsewhere",
49 [0x12] =
"Allegiance Reset",
50 [0x13] =
"Shared Access Violation",
51 [0x20] =
"Command Reject",
52 [0x21] =
"Configuration Error",
53 [0x22] =
"Protection Exception",
54 [0x23] =
"Write Protect",
55 [0x24] =
"Write Length",
56 [0x25] =
"Read-Only Format",
57 [0x31] =
"Beginning of Partition",
58 [0x33] =
"End of Partition",
59 [0x34] =
"End of Data",
60 [0x35] =
"Block not found",
61 [0x40] =
"Device Intervention",
62 [0x41] =
"Loader Intervention",
63 [0x42] =
"Library Intervention",
64 [0x50] =
"Write Error",
65 [0x51] =
"Erase Error",
66 [0x52] =
"Formatting Error",
67 [0x53] =
"Read Error",
68 [0x54] =
"Unsupported Format",
69 [0x55] =
"No Formatting",
70 [0x56] =
"Positioning lost",
71 [0x57] =
"Read Length",
72 [0x60] =
"Unsupported Medium",
73 [0x61] =
"Medium Length Error",
74 [0x62] =
"Medium removed",
75 [0x64] =
"Load Check",
76 [0x65] =
"Unload Check",
77 [0x70] =
"Equipment Check",
78 [0x71] =
"Bus out Check",
79 [0x72] =
"Protocol Error",
80 [0x73] =
"Interface Error",
82 [0x75] =
"Halt Signal",
83 [0x90] =
"Device fenced",
84 [0x91] =
"Device Path fenced",
85 [0xa0] =
"Volume misplaced",
86 [0xa1] =
"Volume inaccessible",
87 [0xa2] =
"Volume in input",
88 [0xa3] =
"Volume ejected",
89 [0xa4] =
"All categories reserved",
90 [0xa5] =
"Duplicate Volume",
91 [0xa6] =
"Library Manager Offline",
92 [0xa7] =
"Library Output Station full",
93 [0xa8] =
"Vision System non-operational",
94 [0xa9] =
"Library Manager Equipment Check",
95 [0xaa] =
"Library Equipment Check",
96 [0xab] =
"All Library Cells full",
97 [0xac] =
"No Cleaner Volumes in Library",
98 [0xad] =
"I/O Station door open",
99 [0xae] =
"Subsystem environmental alert",
107 static int crypt_enabled(
struct tape_device *device)
117 memset(out, 0,
sizeof(*out));
131 memset(out, 0,
sizeof(*out));
148 if (in->
count == 0) {
153 }
else if (in->
count == 1) {
154 int_to_ext_kekl(&in->
kekl[0], &out->
kekl[0]);
157 }
else if (in->
count == 2) {
158 int_to_ext_kekl(&in->
kekl[0], &out->
kekl[0]);
159 int_to_ext_kekl(&in->
kekl[1], &out->
kekl[1]);
187 if (check_ext_kekl(&kekls->
kekl[0]))
189 if (check_ext_kekl(&kekls->
kekl[1]))
200 static int tape_3592_kekl_query(
struct tape_device *device,
213 if (IS_ERR(request)) {
214 rc = PTR_ERR(request);
218 memset(order,0,
sizeof(*order));
228 int_to_ext_kekl_pair(&int_kekls->
kekls, ext_kekls);
241 static int tape_3592_ioctl_kekl_query(
struct tape_device *device,
247 DBF_EVENT(6,
"tape_3592_ioctl_kekl_query\n");
248 if (!crypt_supported(device))
250 if (!crypt_enabled(device))
255 rc = tape_3592_kekl_query(device, ext_kekls);
258 if (
copy_to_user((
char __user *) arg, ext_kekls,
sizeof(*ext_kekls))) {
268 static int tape_3590_mttell(
struct tape_device *device,
int mt_count);
273 static int tape_3592_kekl_set(
struct tape_device *device,
280 if (check_ext_kekl_pair(ext_kekls)) {
284 if (tape_3590_mttell(device, 0) != 0)
288 return PTR_ERR(request);
290 memset(order, 0,
sizeof(*order));
292 order->
kekls.count = 2;
293 ext_to_int_kekl(&ext_kekls->
kekl[0], &order->
kekls.kekl[0]);
294 ext_to_int_kekl(&ext_kekls->
kekl[1], &order->
kekls.kekl[1]);
298 return tape_do_io_free(device, request);
304 static int tape_3592_ioctl_kekl_set(
struct tape_device *device,
310 DBF_EVENT(6,
"tape_3592_ioctl_kekl_set\n");
311 if (!crypt_supported(device))
313 if (!crypt_enabled(device))
318 if (
copy_from_user(ext_kekls, (
char __user *)arg,
sizeof(*ext_kekls))) {
322 rc = tape_3592_kekl_set(device, ext_kekls);
336 DBF_EVENT(6,
"tape_3592_enable_crypt\n");
337 if (!crypt_supported(device))
350 data[36 + 14] = 0x2f;
351 data[36 + 18] = 0xc3;
352 data[36 + 35] = 0x72;
359 static int tape_3592_enable_crypt(
struct tape_device *device)
363 request = __tape_3592_enable_crypt(device);
365 return PTR_ERR(request);
366 return tape_do_io_free(device, request);
369 static void tape_3592_enable_crypt_async(
struct tape_device *device)
373 request = __tape_3592_enable_crypt(device);
374 if (!IS_ERR(request))
375 tape_do_io_async_free(device, request);
386 DBF_EVENT(6,
"tape_3592_disable_crypt\n");
387 if (!crypt_supported(device))
398 data[36 + 35] = 0x32;
407 static int tape_3592_disable_crypt(
struct tape_device *device)
411 request = __tape_3592_disable_crypt(device);
413 return PTR_ERR(request);
414 return tape_do_io_free(device, request);
417 static void tape_3592_disable_crypt_async(
struct tape_device *device)
421 request = __tape_3592_disable_crypt(device);
422 if (!IS_ERR(request))
423 tape_do_io_async_free(device, request);
429 static int tape_3592_ioctl_crypt_set(
struct tape_device *device,
434 DBF_EVENT(6,
"tape_3592_ioctl_crypt_set\n");
435 if (!crypt_supported(device))
442 return tape_3592_enable_crypt(device);
444 return tape_3592_disable_crypt(device);
447 static int tape_3590_sense_medium(
struct tape_device *device);
452 static int tape_3592_ioctl_crypt_query(
struct tape_device *device,
455 DBF_EVENT(6,
"tape_3592_ioctl_crypt_query\n");
456 if (!crypt_supported(device))
458 tape_3590_sense_medium(device);
470 tape_3590_ioctl(
struct tape_device *device,
unsigned int cmd,
unsigned long arg)
482 return tape_3592_ioctl_kekl_set(device, arg);
484 return tape_3592_ioctl_kekl_query(device, arg);
486 return tape_3592_ioctl_crypt_set(device, arg);
488 return tape_3592_ioctl_crypt_query(device, arg);
497 static int tape_3590_sense_medium(
struct tape_device *device)
503 return PTR_ERR(request);
506 return tape_do_io_free(device, request);
509 static void tape_3590_sense_medium_async(
struct tape_device *device)
518 tape_do_io_async_free(device, request);
525 tape_3590_mttell(
struct tape_device *device,
int mt_count)
533 return block_id >> 32;
547 return PTR_ERR(request);
553 return tape_do_io_free(device, request);
561 tape_3590_read_opposite(
struct tape_device *device,
597 static void tape_3590_read_attmsg_async(
struct tape_device *device)
612 tape_do_io_async_free(device, request);
636 tape_3590_sense_medium_async(p->
device);
639 tape_3590_read_attmsg_async(p->
device);
642 tape_3592_enable_crypt_async(p->
device);
645 tape_3592_disable_crypt_async(p->
device);
648 DBF_EVENT(3,
"T3590: work handler undefined for "
649 "operation 0x%02x\n", p->
op);
672 static void tape_3590_med_state_set(
struct tape_device *device,
680 switch (sense->
macst) {
715 switch (request->
op) {
736 tape_3590_med_state_set(device, request->
cpdata);
770 DBF_EVENT(3,
"Error Recovery successful for %s\n",
772 return tape_3590_done(device, request);
782 DBF_EVENT(3,
"Error Recovery failed for %s\n",
809 else if (irb->
scsw.
cmd.dstat == 0x85)
819 tape_3590_schedule_work(device,
TO_MSEN);
828 struct irb *irb,
int rc)
834 switch (sense->
bra) {
836 return tape_3590_erp_failed(device, request, irb, rc);
838 return tape_3590_erp_succeded(device, request);
840 return tape_3590_erp_retry(device, request, irb);
842 return tape_3590_erp_failed(device, request, irb, rc);
853 tape_3590_erp_read_buf_log(
struct tape_device *device,
860 return tape_3590_erp_basic(device, request, irb, -
EIO);
876 dev_warn (&device->
cdev->dev,
"The tape medium must be loaded into a "
877 "different tape unit\n");
878 return tape_3590_erp_basic(device, request, irb, -
EIO);
885 tape_3590_erp_long_busy(
struct tape_device *device,
896 tape_3590_erp_special_interrupt(
struct tape_device *device,
899 return tape_3590_erp_basic(device, request, irb, -
EIO);
906 tape_3590_erp_read_alternate(
struct tape_device *device,
920 DBF_EVENT(2,
"(%08x): No support for READ_PREVIOUS command\n",
924 DBF_EVENT(2,
"(%08x): No support for READ_BACKWARD command\n",
928 tape_3590_read_opposite(device, request);
929 return tape_3590_erp_retry(device, request, irb);
936 tape_3590_erp_read_opposite(
struct tape_device *device,
939 switch (request->
op) {
945 tape_3590_read_opposite(device, request);
946 return tape_3590_erp_retry(device, request, irb);
949 return tape_3590_erp_failed(device, request, irb, -
EIO);
952 return tape_3590_erp_failed(device, request, irb, -
EIO);
960 tape_3590_print_mim_msg_f0(
struct tape_device *device,
struct irb *irb)
968 if (!exception || !service)
973 switch (sense->
fmt.
f70.emc) {
1001 switch (sense->
fmt.
f70.smc) {
1004 "procedure %i", sense->
fmt.
f70.md);
1012 dev_warn (&device->
cdev->dev,
"Tape media information: exception %s, "
1013 "service %s\n", exception, service);
1024 tape_3590_print_io_sim_msg_f1(
struct tape_device *device,
struct irb *irb)
1032 if (!exception || !service)
1037 switch (sense->
fmt.
f71.emc) {
1047 "interface 0x%02x", sense->
fmt.
f71.md[0]);
1051 "0x%02x", sense->
fmt.
f71.md[0]);
1055 "0x%02x", sense->
fmt.
f71.md[0]);
1063 "0x%02x", sense->
fmt.
f71.md[0]);
1070 switch (sense->
fmt.
f71.smc) {
1079 if (sense->
fmt.
f71.mdf == 0)
1081 "0x%x on CU", sense->
fmt.
f71.md[1]);
1084 "nodes (0x%x-0x%x) on CU", sense->
fmt.
f71.md[1],
1088 if (sense->
fmt.
f71.mdf == 0)
1090 "channel path 0x%x on CU",
1094 " paths (0x%x-0x%x) on CU",
1098 if (sense->
fmt.
f71.mdf == 0)
1100 " path 0x%x on CU", sense->
fmt.
f71.md[1]);
1103 " paths (0x%x-0x%x) on CU",
1107 if (sense->
fmt.
f71.mdf == 0)
1109 "library path 0x%x on CU",
1113 "library paths (0x%x-0x%x) on CU",
1124 dev_warn (&device->
cdev->dev,
"I/O subsystem information: exception"
1125 " %s, service %s\n", exception, service);
1135 tape_3590_print_dev_sim_msg_f2(
struct tape_device *device,
struct irb *irb)
1143 if (!exception || !service)
1148 switch (sense->
fmt.
f71.emc) {
1158 "interface 0x%02x", sense->
fmt.
f71.md[0]);
1166 " 0x%02x", sense->
fmt.
f71.md[0]);
1179 switch (sense->
fmt.
f71.smc) {
1188 if (sense->
fmt.
f71.mdf == 0)
1190 "channel path 0x%x on DV",
1194 "channel path (0x%x-0x%x) on DV",
1198 if (sense->
fmt.
f71.mdf == 0)
1200 "interface 0x%x on DV", sense->
fmt.
f71.md[1]);
1203 "interfaces (0x%x-0x%x) on DV",
1207 if (sense->
fmt.
f71.mdf == 0)
1209 " 0x%x on DV", sense->
fmt.
f71.md[1]);
1212 " (0x%x-0x%x) on DV",
1219 if (sense->
fmt.
f71.mdf == 0)
1221 "message display 0x%x on DV",
1225 "message displays (0x%x-0x%x) on DV",
1236 dev_warn (&device->
cdev->dev,
"Device subsystem information: exception"
1237 " %s, service %s\n", exception, service);
1247 tape_3590_print_era_msg(
struct tape_device *device,
struct irb *irb)
1255 if (tape_3590_msg[sense->
mc] !=
NULL)
1257 "issued sense message %s\n",
1258 tape_3590_msg[sense->
mc]);
1261 "issued an unknown sense message code 0x%x\n",
1265 if (sense->
mc == 0xf0) {
1267 dev_warn (&device->
cdev->dev,
"MIM SEV=%i, MC=%02x, ES=%x/%x, "
1268 "RC=%02x-%04x-%02x\n", sense->
fmt.
f70.sev, sense->
mc,
1272 tape_3590_print_mim_msg_f0(device, irb);
1275 if (sense->
mc == 0xf1) {
1277 dev_warn (&device->
cdev->dev,
"IOSIM SEV=%i, DEVTYPE=3590/%02x,"
1278 " MC=%02x, ES=%x/%x, REF=0x%04x-0x%04x-0x%04x\n",
1279 sense->
fmt.
f71.sev, device->
cdev->id.dev_model,
1282 sense->
fmt.
f71.refcode3);
1283 tape_3590_print_io_sim_msg_f1(device, irb);
1286 if (sense->
mc == 0xf2) {
1288 dev_warn (&device->
cdev->dev,
"DEVSIM SEV=%i, DEVTYPE=3590/%02x"
1289 ", MC=%02x, ES=%x/%x, REF=0x%04x-0x%04x-0x%04x\n",
1290 sense->
fmt.
f71.sev, device->
cdev->id.dev_model,
1293 sense->
fmt.
f71.refcode3);
1294 tape_3590_print_dev_sim_msg_f2(device, irb);
1297 if (sense->
mc == 0xf3) {
1301 dev_warn (&device->
cdev->dev,
"The tape unit has issued an unknown "
1302 "sense message code %x\n", sense->
mc);
1305 static int tape_3590_crypt_error(
struct tape_device *device,
1314 ekm_rc2 = *((
u16*) &sense[10]);
1315 if ((cu_rc == 0) && (ekm_rc2 == 0xee31))
1317 return tape_3590_erp_basic(device, request, irb, -
EKEYREJECTED);
1318 if ((cu_rc == 1) || (cu_rc == 2))
1320 return tape_3590_erp_basic(device, request, irb, -
ENOTCONN);
1322 dev_err (&device->
cdev->dev,
"The tape unit failed to obtain the "
1323 "encryption key from EKM\n");
1325 return tape_3590_erp_basic(device, request, irb, -
ENOKEY);
1351 tape_3590_print_era_msg(device, irb);
1352 return tape_3590_erp_read_buf_log(device, request, irb);
1355 tape_3590_print_era_msg(device, irb);
1356 return tape_3590_erp_read_alternate(device, request, irb);
1360 tape_3590_print_era_msg(device, irb);
1361 return tape_3590_erp_special_interrupt(device, request, irb);
1363 return tape_3590_crypt_error(device, request, irb);
1366 DBF_EVENT(2,
"(%08x): Backward at Beginning of Partition\n",
1368 return tape_3590_erp_basic(device, request, irb, -
ENOSPC);
1370 DBF_EVENT(2,
"(%08x): Forward at End of Partition\n",
1372 return tape_3590_erp_basic(device, request, irb, -
ENOSPC);
1375 return tape_3590_erp_basic(device, request, irb, -
ENOSPC);
1378 DBF_EVENT(2,
"(%08x): Rewind Unload initiated\n",
1380 return tape_3590_erp_basic(device, request, irb, -
EIO);
1382 DBF_EVENT(2,
"(%08x): Rewind Unload complete\n",
1386 return tape_3590_erp_basic(device, request, irb, 0);
1395 return tape_3590_erp_basic(device, request, irb, -
ENOMEDIUM);
1399 tape_3590_print_era_msg(device, irb);
1400 return tape_3590_erp_basic(device, request, irb, -
EBUSY);
1403 return tape_3590_erp_long_busy(device, request, irb);
1406 if (sense->
rac == 0xd0) {
1408 tape_3590_print_era_msg(device, irb);
1409 return tape_3590_erp_swap(device, request, irb);
1411 if (sense->
rac == 0x26) {
1413 tape_3590_print_era_msg(device, irb);
1414 return tape_3590_erp_read_opposite(device, request,
1417 return tape_3590_erp_basic(device, request, irb, -
EIO);
1424 tape_3590_print_era_msg(device, irb);
1425 return tape_3590_erp_swap(device, request, irb);
1429 return tape_3590_erp_basic(device, request, irb, -
EMEDIUMTYPE);
1435 return tape_3590_erp_basic(device, request, irb, -
ENOMEDIUM);
1438 return tape_3590_erp_basic(device, request, irb, -
EMEDIUMTYPE);
1441 return tape_3590_erp_basic(device, request, irb, -
EPERM);
1443 dev_warn (&device->
cdev->dev,
"A different host has privileged"
1444 " access to the tape unit\n");
1445 return tape_3590_erp_basic(device, request, irb, -
EPERM);
1447 return tape_3590_erp_basic(device, request, irb, -
EIO);
1458 if (request ==
NULL)
1459 return tape_3590_unsolicited_irq(device, irb);
1466 return tape_3590_erp_failed(device, request, irb, -
ENOSPC);
1470 return tape_3590_unit_check(device, request, irb);
1480 return tape_3590_done(device, request);
1489 DBF_EVENT(2,
"Unit Attention when busy..\n");
1499 static int tape_3590_read_dev_chars(
struct tape_device *device,
1506 if (IS_ERR(request))
1507 return PTR_ERR(request);
1522 tape_3590_setup_device(
struct tape_device *device)
1540 rc = tape_3590_read_dev_chars(device, rdc_data);
1542 DBF_LH(3,
"Read device characteristics failed!\n");
1548 if (rdc_data->
data[31] == 0x13) {
1550 tape_3592_disable_crypt(device);
1552 DBF_EVENT(6,
"Device has NO crypto support\n");
1555 rc = tape_3590_sense_medium(device);
1557 DBF_LH(3,
"3590 medium sense returned %d\n", rc);
1573 tape_3590_cleanup_device(
struct tape_device *device)
1605 [
MTSEEK] = tape_3590_mtseek,
1606 [
MTTELL] = tape_3590_mttell,
1625 .setup_device = tape_3590_setup_device,
1626 .cleanup_device = tape_3590_cleanup_device,
1628 .irq = tape_3590_irq,
1631 .ioctl_fn = tape_3590_ioctl,
1632 .mtop_array = tape_3590_mtop
1645 &tape_discipline_3590);
1648 static struct ccw_driver tape_3590_driver = {
1650 .name =
"tape_3590",
1653 .ids = tape_3590_ids,
1657 .set_online = tape_3590_online,
1666 tape_3590_init(
void)
1670 TAPE_DBF_AREA =
debug_register(
"tape_3590", 2, 2, 4 *
sizeof(
long));
1672 #ifdef DBF_LIKE_HELL
1693 tape_3590_exit(
void)