tape_3590.c 47 KB

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