tape_3590.c 47 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818
  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. struct tape_3590_disc_data *disc_data;
  714. DBF_EVENT(6, "%s done\n", tape_op_verbose[request->op]);
  715. disc_data = device->discdata;
  716. switch (request->op) {
  717. case TO_BSB:
  718. case TO_BSF:
  719. case TO_DSE:
  720. case TO_FSB:
  721. case TO_FSF:
  722. case TO_LBL:
  723. case TO_RFO:
  724. case TO_RBA:
  725. case TO_REW:
  726. case TO_WRI:
  727. case TO_WTM:
  728. case TO_BLOCK:
  729. case TO_LOAD:
  730. tape_med_state_set(device, MS_LOADED);
  731. break;
  732. case TO_RUN:
  733. tape_med_state_set(device, MS_UNLOADED);
  734. tape_3590_schedule_work(device, TO_CRYPT_OFF);
  735. break;
  736. case TO_MSEN:
  737. tape_3590_med_state_set(device, request->cpdata);
  738. break;
  739. case TO_CRYPT_ON:
  740. TAPE_3590_CRYPT_INFO(device).status
  741. |= TAPE390_CRYPT_ON_MASK;
  742. *(device->modeset_byte) |= 0x03;
  743. break;
  744. case TO_CRYPT_OFF:
  745. TAPE_3590_CRYPT_INFO(device).status
  746. &= ~TAPE390_CRYPT_ON_MASK;
  747. *(device->modeset_byte) &= ~0x03;
  748. break;
  749. case TO_RBI: /* RBI seems to succeed even without medium loaded. */
  750. case TO_NOP: /* Same to NOP. */
  751. case TO_READ_CONFIG:
  752. case TO_READ_ATTMSG:
  753. case TO_DIS:
  754. case TO_ASSIGN:
  755. case TO_UNASSIGN:
  756. case TO_SIZE:
  757. case TO_KEKL_SET:
  758. case TO_KEKL_QUERY:
  759. case TO_RDC:
  760. break;
  761. }
  762. return TAPE_IO_SUCCESS;
  763. }
  764. /*
  765. * This function is called, when error recovery was successful
  766. */
  767. static inline int
  768. tape_3590_erp_succeded(struct tape_device *device, struct tape_request *request)
  769. {
  770. DBF_EVENT(3, "Error Recovery successful for %s\n",
  771. tape_op_verbose[request->op]);
  772. return tape_3590_done(device, request);
  773. }
  774. /*
  775. * This function is called, when error recovery was not successful
  776. */
  777. static inline int
  778. tape_3590_erp_failed(struct tape_device *device, struct tape_request *request,
  779. struct irb *irb, int rc)
  780. {
  781. DBF_EVENT(3, "Error Recovery failed for %s\n",
  782. tape_op_verbose[request->op]);
  783. tape_dump_sense_dbf(device, request, irb);
  784. return rc;
  785. }
  786. /*
  787. * Error Recovery do retry
  788. */
  789. static inline int
  790. tape_3590_erp_retry(struct tape_device *device, struct tape_request *request,
  791. struct irb *irb)
  792. {
  793. DBF_EVENT(2, "Retry: %s\n", tape_op_verbose[request->op]);
  794. tape_dump_sense_dbf(device, request, irb);
  795. return TAPE_IO_RETRY;
  796. }
  797. /*
  798. * Handle unsolicited interrupts
  799. */
  800. static int
  801. tape_3590_unsolicited_irq(struct tape_device *device, struct irb *irb)
  802. {
  803. if (irb->scsw.cmd.dstat == DEV_STAT_CHN_END)
  804. /* Probably result of halt ssch */
  805. return TAPE_IO_PENDING;
  806. else if (irb->scsw.cmd.dstat == 0x85)
  807. /* Device Ready */
  808. DBF_EVENT(3, "unsol.irq! tape ready: %08x\n", device->cdev_id);
  809. else if (irb->scsw.cmd.dstat & DEV_STAT_ATTENTION) {
  810. tape_3590_schedule_work(device, TO_READ_ATTMSG);
  811. } else {
  812. DBF_EVENT(3, "unsol.irq! dev end: %08x\n", device->cdev_id);
  813. tape_dump_sense_dbf(device, NULL, irb);
  814. }
  815. /* check medium state */
  816. tape_3590_schedule_work(device, TO_MSEN);
  817. return TAPE_IO_SUCCESS;
  818. }
  819. /*
  820. * Basic Recovery routine
  821. */
  822. static int
  823. tape_3590_erp_basic(struct tape_device *device, struct tape_request *request,
  824. struct irb *irb, int rc)
  825. {
  826. struct tape_3590_sense *sense;
  827. sense = (struct tape_3590_sense *) irb->ecw;
  828. switch (sense->bra) {
  829. case SENSE_BRA_PER:
  830. return tape_3590_erp_failed(device, request, irb, rc);
  831. case SENSE_BRA_CONT:
  832. return tape_3590_erp_succeded(device, request);
  833. case SENSE_BRA_RE:
  834. return tape_3590_erp_retry(device, request, irb);
  835. case SENSE_BRA_DRE:
  836. return tape_3590_erp_failed(device, request, irb, rc);
  837. default:
  838. BUG();
  839. return TAPE_IO_STOP;
  840. }
  841. }
  842. /*
  843. * RDL: Read Device (buffered) log
  844. */
  845. static int
  846. tape_3590_erp_read_buf_log(struct tape_device *device,
  847. struct tape_request *request, struct irb *irb)
  848. {
  849. /*
  850. * We just do the basic error recovery at the moment (retry).
  851. * Perhaps in the future, we read the log and dump it somewhere...
  852. */
  853. return tape_3590_erp_basic(device, request, irb, -EIO);
  854. }
  855. /*
  856. * SWAP: Swap Devices
  857. */
  858. static int
  859. tape_3590_erp_swap(struct tape_device *device, struct tape_request *request,
  860. struct irb *irb)
  861. {
  862. /*
  863. * This error recovery should swap the tapes
  864. * if the original has a problem. The operation
  865. * should proceed with the new tape... this
  866. * should probably be done in user space!
  867. */
  868. dev_warn (&device->cdev->dev, "The tape medium must be loaded into a "
  869. "different tape unit\n");
  870. return tape_3590_erp_basic(device, request, irb, -EIO);
  871. }
  872. /*
  873. * LBY: Long Busy
  874. */
  875. static int
  876. tape_3590_erp_long_busy(struct tape_device *device,
  877. struct tape_request *request, struct irb *irb)
  878. {
  879. DBF_EVENT(6, "Device is busy\n");
  880. return TAPE_IO_LONG_BUSY;
  881. }
  882. /*
  883. * SPI: Special Intercept
  884. */
  885. static int
  886. tape_3590_erp_special_interrupt(struct tape_device *device,
  887. struct tape_request *request, struct irb *irb)
  888. {
  889. return tape_3590_erp_basic(device, request, irb, -EIO);
  890. }
  891. /*
  892. * RDA: Read Alternate
  893. */
  894. static int
  895. tape_3590_erp_read_alternate(struct tape_device *device,
  896. struct tape_request *request, struct irb *irb)
  897. {
  898. struct tape_3590_disc_data *data;
  899. /*
  900. * The issued Read Backward or Read Previous command is not
  901. * supported by the device
  902. * The recovery action should be to issue another command:
  903. * Read Revious: if Read Backward is not supported
  904. * Read Backward: if Read Previous is not supported
  905. */
  906. data = device->discdata;
  907. if (data->read_back_op == READ_PREVIOUS) {
  908. DBF_EVENT(2, "(%08x): No support for READ_PREVIOUS command\n",
  909. device->cdev_id);
  910. data->read_back_op = READ_BACKWARD;
  911. } else {
  912. DBF_EVENT(2, "(%08x): No support for READ_BACKWARD command\n",
  913. device->cdev_id);
  914. data->read_back_op = READ_PREVIOUS;
  915. }
  916. tape_3590_read_opposite(device, request);
  917. return tape_3590_erp_retry(device, request, irb);
  918. }
  919. /*
  920. * Error Recovery read opposite
  921. */
  922. static int
  923. tape_3590_erp_read_opposite(struct tape_device *device,
  924. struct tape_request *request, struct irb *irb)
  925. {
  926. switch (request->op) {
  927. case TO_RFO:
  928. /*
  929. * We did read forward, but the data could not be read.
  930. * We will read backward and then skip forward again.
  931. */
  932. tape_3590_read_opposite(device, request);
  933. return tape_3590_erp_retry(device, request, irb);
  934. case TO_RBA:
  935. /* We tried to read forward and backward, but hat no success */
  936. return tape_3590_erp_failed(device, request, irb, -EIO);
  937. break;
  938. default:
  939. return tape_3590_erp_failed(device, request, irb, -EIO);
  940. }
  941. }
  942. /*
  943. * Print an MIM (Media Information Message) (message code f0)
  944. */
  945. static void
  946. tape_3590_print_mim_msg_f0(struct tape_device *device, struct irb *irb)
  947. {
  948. struct tape_3590_sense *sense;
  949. char *exception, *service;
  950. exception = kmalloc(BUFSIZE, GFP_ATOMIC);
  951. service = kmalloc(BUFSIZE, GFP_ATOMIC);
  952. if (!exception || !service)
  953. goto out_nomem;
  954. sense = (struct tape_3590_sense *) irb->ecw;
  955. /* Exception Message */
  956. switch (sense->fmt.f70.emc) {
  957. case 0x02:
  958. snprintf(exception, BUFSIZE, "Data degraded");
  959. break;
  960. case 0x03:
  961. snprintf(exception, BUFSIZE, "Data degraded in partion %i",
  962. sense->fmt.f70.mp);
  963. break;
  964. case 0x04:
  965. snprintf(exception, BUFSIZE, "Medium degraded");
  966. break;
  967. case 0x05:
  968. snprintf(exception, BUFSIZE, "Medium degraded in partition %i",
  969. sense->fmt.f70.mp);
  970. break;
  971. case 0x06:
  972. snprintf(exception, BUFSIZE, "Block 0 Error");
  973. break;
  974. case 0x07:
  975. snprintf(exception, BUFSIZE, "Medium Exception 0x%02x",
  976. sense->fmt.f70.md);
  977. break;
  978. default:
  979. snprintf(exception, BUFSIZE, "0x%02x",
  980. sense->fmt.f70.emc);
  981. break;
  982. }
  983. /* Service Message */
  984. switch (sense->fmt.f70.smc) {
  985. case 0x02:
  986. snprintf(service, BUFSIZE, "Reference Media maintenance "
  987. "procedure %i", sense->fmt.f70.md);
  988. break;
  989. default:
  990. snprintf(service, BUFSIZE, "0x%02x",
  991. sense->fmt.f70.smc);
  992. break;
  993. }
  994. dev_warn (&device->cdev->dev, "Tape media information: exception %s, "
  995. "service %s\n", exception, service);
  996. out_nomem:
  997. kfree(exception);
  998. kfree(service);
  999. }
  1000. /*
  1001. * Print an I/O Subsystem Service Information Message (message code f1)
  1002. */
  1003. static void
  1004. tape_3590_print_io_sim_msg_f1(struct tape_device *device, struct irb *irb)
  1005. {
  1006. struct tape_3590_sense *sense;
  1007. char *exception, *service;
  1008. exception = kmalloc(BUFSIZE, GFP_ATOMIC);
  1009. service = kmalloc(BUFSIZE, GFP_ATOMIC);
  1010. if (!exception || !service)
  1011. goto out_nomem;
  1012. sense = (struct tape_3590_sense *) irb->ecw;
  1013. /* Exception Message */
  1014. switch (sense->fmt.f71.emc) {
  1015. case 0x01:
  1016. snprintf(exception, BUFSIZE, "Effect of failure is unknown");
  1017. break;
  1018. case 0x02:
  1019. snprintf(exception, BUFSIZE, "CU Exception - no performance "
  1020. "impact");
  1021. break;
  1022. case 0x03:
  1023. snprintf(exception, BUFSIZE, "CU Exception on channel "
  1024. "interface 0x%02x", sense->fmt.f71.md[0]);
  1025. break;
  1026. case 0x04:
  1027. snprintf(exception, BUFSIZE, "CU Exception on device path "
  1028. "0x%02x", sense->fmt.f71.md[0]);
  1029. break;
  1030. case 0x05:
  1031. snprintf(exception, BUFSIZE, "CU Exception on library path "
  1032. "0x%02x", sense->fmt.f71.md[0]);
  1033. break;
  1034. case 0x06:
  1035. snprintf(exception, BUFSIZE, "CU Exception on node 0x%02x",
  1036. sense->fmt.f71.md[0]);
  1037. break;
  1038. case 0x07:
  1039. snprintf(exception, BUFSIZE, "CU Exception on partition "
  1040. "0x%02x", sense->fmt.f71.md[0]);
  1041. break;
  1042. default:
  1043. snprintf(exception, BUFSIZE, "0x%02x",
  1044. sense->fmt.f71.emc);
  1045. }
  1046. /* Service Message */
  1047. switch (sense->fmt.f71.smc) {
  1048. case 0x01:
  1049. snprintf(service, BUFSIZE, "Repair impact is unknown");
  1050. break;
  1051. case 0x02:
  1052. snprintf(service, BUFSIZE, "Repair will not impact cu "
  1053. "performance");
  1054. break;
  1055. case 0x03:
  1056. if (sense->fmt.f71.mdf == 0)
  1057. snprintf(service, BUFSIZE, "Repair will disable node "
  1058. "0x%x on CU", sense->fmt.f71.md[1]);
  1059. else
  1060. snprintf(service, BUFSIZE, "Repair will disable "
  1061. "nodes (0x%x-0x%x) on CU", sense->fmt.f71.md[1],
  1062. sense->fmt.f71.md[2]);
  1063. break;
  1064. case 0x04:
  1065. if (sense->fmt.f71.mdf == 0)
  1066. snprintf(service, BUFSIZE, "Repair will disable "
  1067. "channel path 0x%x on CU",
  1068. sense->fmt.f71.md[1]);
  1069. else
  1070. snprintf(service, BUFSIZE, "Repair will disable cannel"
  1071. " paths (0x%x-0x%x) on CU",
  1072. sense->fmt.f71.md[1], sense->fmt.f71.md[2]);
  1073. break;
  1074. case 0x05:
  1075. if (sense->fmt.f71.mdf == 0)
  1076. snprintf(service, BUFSIZE, "Repair will disable device"
  1077. " path 0x%x on CU", sense->fmt.f71.md[1]);
  1078. else
  1079. snprintf(service, BUFSIZE, "Repair will disable device"
  1080. " paths (0x%x-0x%x) on CU",
  1081. sense->fmt.f71.md[1], sense->fmt.f71.md[2]);
  1082. break;
  1083. case 0x06:
  1084. if (sense->fmt.f71.mdf == 0)
  1085. snprintf(service, BUFSIZE, "Repair will disable "
  1086. "library path 0x%x on CU",
  1087. sense->fmt.f71.md[1]);
  1088. else
  1089. snprintf(service, BUFSIZE, "Repair will disable "
  1090. "library paths (0x%x-0x%x) on CU",
  1091. sense->fmt.f71.md[1], sense->fmt.f71.md[2]);
  1092. break;
  1093. case 0x07:
  1094. snprintf(service, BUFSIZE, "Repair will disable access to CU");
  1095. break;
  1096. default:
  1097. snprintf(service, BUFSIZE, "0x%02x",
  1098. sense->fmt.f71.smc);
  1099. }
  1100. dev_warn (&device->cdev->dev, "I/O subsystem information: exception"
  1101. " %s, service %s\n", exception, service);
  1102. out_nomem:
  1103. kfree(exception);
  1104. kfree(service);
  1105. }
  1106. /*
  1107. * Print an Device Subsystem Service Information Message (message code f2)
  1108. */
  1109. static void
  1110. tape_3590_print_dev_sim_msg_f2(struct tape_device *device, struct irb *irb)
  1111. {
  1112. struct tape_3590_sense *sense;
  1113. char *exception, *service;
  1114. exception = kmalloc(BUFSIZE, GFP_ATOMIC);
  1115. service = kmalloc(BUFSIZE, GFP_ATOMIC);
  1116. if (!exception || !service)
  1117. goto out_nomem;
  1118. sense = (struct tape_3590_sense *) irb->ecw;
  1119. /* Exception Message */
  1120. switch (sense->fmt.f71.emc) {
  1121. case 0x01:
  1122. snprintf(exception, BUFSIZE, "Effect of failure is unknown");
  1123. break;
  1124. case 0x02:
  1125. snprintf(exception, BUFSIZE, "DV Exception - no performance"
  1126. " impact");
  1127. break;
  1128. case 0x03:
  1129. snprintf(exception, BUFSIZE, "DV Exception on channel "
  1130. "interface 0x%02x", sense->fmt.f71.md[0]);
  1131. break;
  1132. case 0x04:
  1133. snprintf(exception, BUFSIZE, "DV Exception on loader 0x%02x",
  1134. sense->fmt.f71.md[0]);
  1135. break;
  1136. case 0x05:
  1137. snprintf(exception, BUFSIZE, "DV Exception on message display"
  1138. " 0x%02x", sense->fmt.f71.md[0]);
  1139. break;
  1140. case 0x06:
  1141. snprintf(exception, BUFSIZE, "DV Exception in tape path");
  1142. break;
  1143. case 0x07:
  1144. snprintf(exception, BUFSIZE, "DV Exception in drive");
  1145. break;
  1146. default:
  1147. snprintf(exception, BUFSIZE, "0x%02x",
  1148. sense->fmt.f71.emc);
  1149. }
  1150. /* Service Message */
  1151. switch (sense->fmt.f71.smc) {
  1152. case 0x01:
  1153. snprintf(service, BUFSIZE, "Repair impact is unknown");
  1154. break;
  1155. case 0x02:
  1156. snprintf(service, BUFSIZE, "Repair will not impact device "
  1157. "performance");
  1158. break;
  1159. case 0x03:
  1160. if (sense->fmt.f71.mdf == 0)
  1161. snprintf(service, BUFSIZE, "Repair will disable "
  1162. "channel path 0x%x on DV",
  1163. sense->fmt.f71.md[1]);
  1164. else
  1165. snprintf(service, BUFSIZE, "Repair will disable "
  1166. "channel path (0x%x-0x%x) on DV",
  1167. sense->fmt.f71.md[1], sense->fmt.f71.md[2]);
  1168. break;
  1169. case 0x04:
  1170. if (sense->fmt.f71.mdf == 0)
  1171. snprintf(service, BUFSIZE, "Repair will disable "
  1172. "interface 0x%x on DV", sense->fmt.f71.md[1]);
  1173. else
  1174. snprintf(service, BUFSIZE, "Repair will disable "
  1175. "interfaces (0x%x-0x%x) on DV",
  1176. sense->fmt.f71.md[1], sense->fmt.f71.md[2]);
  1177. break;
  1178. case 0x05:
  1179. if (sense->fmt.f71.mdf == 0)
  1180. snprintf(service, BUFSIZE, "Repair will disable loader"
  1181. " 0x%x on DV", sense->fmt.f71.md[1]);
  1182. else
  1183. snprintf(service, BUFSIZE, "Repair will disable loader"
  1184. " (0x%x-0x%x) on DV",
  1185. sense->fmt.f71.md[1], sense->fmt.f71.md[2]);
  1186. break;
  1187. case 0x07:
  1188. snprintf(service, BUFSIZE, "Repair will disable access to DV");
  1189. break;
  1190. case 0x08:
  1191. if (sense->fmt.f71.mdf == 0)
  1192. snprintf(service, BUFSIZE, "Repair will disable "
  1193. "message display 0x%x on DV",
  1194. sense->fmt.f71.md[1]);
  1195. else
  1196. snprintf(service, BUFSIZE, "Repair will disable "
  1197. "message displays (0x%x-0x%x) on DV",
  1198. sense->fmt.f71.md[1], sense->fmt.f71.md[2]);
  1199. break;
  1200. case 0x09:
  1201. snprintf(service, BUFSIZE, "Clean DV");
  1202. break;
  1203. default:
  1204. snprintf(service, BUFSIZE, "0x%02x",
  1205. sense->fmt.f71.smc);
  1206. }
  1207. dev_warn (&device->cdev->dev, "Device subsystem information: exception"
  1208. " %s, service %s\n", exception, service);
  1209. out_nomem:
  1210. kfree(exception);
  1211. kfree(service);
  1212. }
  1213. /*
  1214. * Print standard ERA Message
  1215. */
  1216. static void
  1217. tape_3590_print_era_msg(struct tape_device *device, struct irb *irb)
  1218. {
  1219. struct tape_3590_sense *sense;
  1220. sense = (struct tape_3590_sense *) irb->ecw;
  1221. if (sense->mc == 0)
  1222. return;
  1223. if ((sense->mc > 0) && (sense->mc < TAPE_3590_MAX_MSG)) {
  1224. if (tape_3590_msg[sense->mc] != NULL)
  1225. dev_warn (&device->cdev->dev, "The tape unit has "
  1226. "issued sense message %s\n",
  1227. tape_3590_msg[sense->mc]);
  1228. else
  1229. dev_warn (&device->cdev->dev, "The tape unit has "
  1230. "issued an unknown sense message code 0x%x\n",
  1231. sense->mc);
  1232. return;
  1233. }
  1234. if (sense->mc == 0xf0) {
  1235. /* Standard Media Information Message */
  1236. dev_warn (&device->cdev->dev, "MIM SEV=%i, MC=%02x, ES=%x/%x, "
  1237. "RC=%02x-%04x-%02x\n", sense->fmt.f70.sev, sense->mc,
  1238. sense->fmt.f70.emc, sense->fmt.f70.smc,
  1239. sense->fmt.f70.refcode, sense->fmt.f70.mid,
  1240. sense->fmt.f70.fid);
  1241. tape_3590_print_mim_msg_f0(device, irb);
  1242. return;
  1243. }
  1244. if (sense->mc == 0xf1) {
  1245. /* Standard I/O Subsystem Service Information Message */
  1246. dev_warn (&device->cdev->dev, "IOSIM SEV=%i, DEVTYPE=3590/%02x,"
  1247. " MC=%02x, ES=%x/%x, REF=0x%04x-0x%04x-0x%04x\n",
  1248. sense->fmt.f71.sev, device->cdev->id.dev_model,
  1249. sense->mc, sense->fmt.f71.emc, sense->fmt.f71.smc,
  1250. sense->fmt.f71.refcode1, sense->fmt.f71.refcode2,
  1251. sense->fmt.f71.refcode3);
  1252. tape_3590_print_io_sim_msg_f1(device, irb);
  1253. return;
  1254. }
  1255. if (sense->mc == 0xf2) {
  1256. /* Standard Device Service Information Message */
  1257. dev_warn (&device->cdev->dev, "DEVSIM SEV=%i, DEVTYPE=3590/%02x"
  1258. ", MC=%02x, ES=%x/%x, REF=0x%04x-0x%04x-0x%04x\n",
  1259. sense->fmt.f71.sev, device->cdev->id.dev_model,
  1260. sense->mc, sense->fmt.f71.emc, sense->fmt.f71.smc,
  1261. sense->fmt.f71.refcode1, sense->fmt.f71.refcode2,
  1262. sense->fmt.f71.refcode3);
  1263. tape_3590_print_dev_sim_msg_f2(device, irb);
  1264. return;
  1265. }
  1266. if (sense->mc == 0xf3) {
  1267. /* Standard Library Service Information Message */
  1268. return;
  1269. }
  1270. dev_warn (&device->cdev->dev, "The tape unit has issued an unknown "
  1271. "sense message code %x\n", sense->mc);
  1272. }
  1273. static int tape_3590_crypt_error(struct tape_device *device,
  1274. struct tape_request *request, struct irb *irb)
  1275. {
  1276. u8 cu_rc, ekm_rc1;
  1277. u16 ekm_rc2;
  1278. u32 drv_rc;
  1279. const char *bus_id;
  1280. char *sense;
  1281. sense = ((struct tape_3590_sense *) irb->ecw)->fmt.data;
  1282. bus_id = dev_name(&device->cdev->dev);
  1283. cu_rc = sense[0];
  1284. drv_rc = *((u32*) &sense[5]) & 0xffffff;
  1285. ekm_rc1 = sense[9];
  1286. ekm_rc2 = *((u16*) &sense[10]);
  1287. if ((cu_rc == 0) && (ekm_rc2 == 0xee31))
  1288. /* key not defined on EKM */
  1289. return tape_3590_erp_basic(device, request, irb, -EKEYREJECTED);
  1290. if ((cu_rc == 1) || (cu_rc == 2))
  1291. /* No connection to EKM */
  1292. return tape_3590_erp_basic(device, request, irb, -ENOTCONN);
  1293. dev_err (&device->cdev->dev, "The tape unit failed to obtain the "
  1294. "encryption key from EKM\n");
  1295. return tape_3590_erp_basic(device, request, irb, -ENOKEY);
  1296. }
  1297. /*
  1298. * 3590 error Recovery routine:
  1299. * If possible, it tries to recover from the error. If this is not possible,
  1300. * inform the user about the problem.
  1301. */
  1302. static int
  1303. tape_3590_unit_check(struct tape_device *device, struct tape_request *request,
  1304. struct irb *irb)
  1305. {
  1306. struct tape_3590_sense *sense;
  1307. int rc;
  1308. #ifdef CONFIG_S390_TAPE_BLOCK
  1309. if (request->op == TO_BLOCK) {
  1310. /*
  1311. * Recovery for block device requests. Set the block_position
  1312. * to something invalid and retry.
  1313. */
  1314. device->blk_data.block_position = -1;
  1315. if (request->retries-- <= 0)
  1316. return tape_3590_erp_failed(device, request, irb, -EIO);
  1317. else
  1318. return tape_3590_erp_retry(device, request, irb);
  1319. }
  1320. #endif
  1321. sense = (struct tape_3590_sense *) irb->ecw;
  1322. DBF_EVENT(6, "Unit Check: RQC = %x\n", sense->rc_rqc);
  1323. /*
  1324. * First check all RC-QRCs where we want to do something special
  1325. * - "break": basic error recovery is done
  1326. * - "goto out:": just print error message if available
  1327. */
  1328. rc = -EIO;
  1329. switch (sense->rc_rqc) {
  1330. case 0x1110:
  1331. tape_3590_print_era_msg(device, irb);
  1332. return tape_3590_erp_read_buf_log(device, request, irb);
  1333. case 0x2011:
  1334. tape_3590_print_era_msg(device, irb);
  1335. return tape_3590_erp_read_alternate(device, request, irb);
  1336. case 0x2230:
  1337. case 0x2231:
  1338. tape_3590_print_era_msg(device, irb);
  1339. return tape_3590_erp_special_interrupt(device, request, irb);
  1340. case 0x2240:
  1341. return tape_3590_crypt_error(device, request, irb);
  1342. case 0x3010:
  1343. DBF_EVENT(2, "(%08x): Backward at Beginning of Partition\n",
  1344. device->cdev_id);
  1345. return tape_3590_erp_basic(device, request, irb, -ENOSPC);
  1346. case 0x3012:
  1347. DBF_EVENT(2, "(%08x): Forward at End of Partition\n",
  1348. device->cdev_id);
  1349. return tape_3590_erp_basic(device, request, irb, -ENOSPC);
  1350. case 0x3020:
  1351. DBF_EVENT(2, "(%08x): End of Data Mark\n", device->cdev_id);
  1352. return tape_3590_erp_basic(device, request, irb, -ENOSPC);
  1353. case 0x3122:
  1354. DBF_EVENT(2, "(%08x): Rewind Unload initiated\n",
  1355. device->cdev_id);
  1356. return tape_3590_erp_basic(device, request, irb, -EIO);
  1357. case 0x3123:
  1358. DBF_EVENT(2, "(%08x): Rewind Unload complete\n",
  1359. device->cdev_id);
  1360. tape_med_state_set(device, MS_UNLOADED);
  1361. tape_3590_schedule_work(device, TO_CRYPT_OFF);
  1362. return tape_3590_erp_basic(device, request, irb, 0);
  1363. case 0x4010:
  1364. /*
  1365. * print additional msg since default msg
  1366. * "device intervention" is not very meaningfull
  1367. */
  1368. tape_med_state_set(device, MS_UNLOADED);
  1369. tape_3590_schedule_work(device, TO_CRYPT_OFF);
  1370. return tape_3590_erp_basic(device, request, irb, -ENOMEDIUM);
  1371. case 0x4012: /* Device Long Busy */
  1372. /* XXX: Also use long busy handling here? */
  1373. DBF_EVENT(6, "(%08x): LONG BUSY\n", device->cdev_id);
  1374. tape_3590_print_era_msg(device, irb);
  1375. return tape_3590_erp_basic(device, request, irb, -EBUSY);
  1376. case 0x4014:
  1377. DBF_EVENT(6, "(%08x): Crypto LONG BUSY\n", device->cdev_id);
  1378. return tape_3590_erp_long_busy(device, request, irb);
  1379. case 0x5010:
  1380. if (sense->rac == 0xd0) {
  1381. /* Swap */
  1382. tape_3590_print_era_msg(device, irb);
  1383. return tape_3590_erp_swap(device, request, irb);
  1384. }
  1385. if (sense->rac == 0x26) {
  1386. /* Read Opposite */
  1387. tape_3590_print_era_msg(device, irb);
  1388. return tape_3590_erp_read_opposite(device, request,
  1389. irb);
  1390. }
  1391. return tape_3590_erp_basic(device, request, irb, -EIO);
  1392. case 0x5020:
  1393. case 0x5021:
  1394. case 0x5022:
  1395. case 0x5040:
  1396. case 0x5041:
  1397. case 0x5042:
  1398. tape_3590_print_era_msg(device, irb);
  1399. return tape_3590_erp_swap(device, request, irb);
  1400. case 0x5110:
  1401. case 0x5111:
  1402. return tape_3590_erp_basic(device, request, irb, -EMEDIUMTYPE);
  1403. case 0x5120:
  1404. case 0x1120:
  1405. tape_med_state_set(device, MS_UNLOADED);
  1406. tape_3590_schedule_work(device, TO_CRYPT_OFF);
  1407. return tape_3590_erp_basic(device, request, irb, -ENOMEDIUM);
  1408. case 0x6020:
  1409. return tape_3590_erp_basic(device, request, irb, -EMEDIUMTYPE);
  1410. case 0x8011:
  1411. return tape_3590_erp_basic(device, request, irb, -EPERM);
  1412. case 0x8013:
  1413. dev_warn (&device->cdev->dev, "A different host has privileged"
  1414. " access to the tape unit\n");
  1415. return tape_3590_erp_basic(device, request, irb, -EPERM);
  1416. default:
  1417. return tape_3590_erp_basic(device, request, irb, -EIO);
  1418. }
  1419. }
  1420. /*
  1421. * 3590 interrupt handler:
  1422. */
  1423. static int
  1424. tape_3590_irq(struct tape_device *device, struct tape_request *request,
  1425. struct irb *irb)
  1426. {
  1427. if (request == NULL)
  1428. return tape_3590_unsolicited_irq(device, irb);
  1429. if ((irb->scsw.cmd.dstat & DEV_STAT_UNIT_EXCEP) &&
  1430. (irb->scsw.cmd.dstat & DEV_STAT_DEV_END) &&
  1431. (request->op == TO_WRI)) {
  1432. /* Write at end of volume */
  1433. DBF_EVENT(2, "End of volume\n");
  1434. return tape_3590_erp_failed(device, request, irb, -ENOSPC);
  1435. }
  1436. if (irb->scsw.cmd.dstat & DEV_STAT_UNIT_CHECK)
  1437. return tape_3590_unit_check(device, request, irb);
  1438. if (irb->scsw.cmd.dstat & DEV_STAT_DEV_END) {
  1439. if (irb->scsw.cmd.dstat == DEV_STAT_UNIT_EXCEP) {
  1440. if (request->op == TO_FSB || request->op == TO_BSB)
  1441. request->rescnt++;
  1442. else
  1443. DBF_EVENT(5, "Unit Exception!\n");
  1444. }
  1445. return tape_3590_done(device, request);
  1446. }
  1447. if (irb->scsw.cmd.dstat & DEV_STAT_CHN_END) {
  1448. DBF_EVENT(2, "cannel end\n");
  1449. return TAPE_IO_PENDING;
  1450. }
  1451. if (irb->scsw.cmd.dstat & DEV_STAT_ATTENTION) {
  1452. DBF_EVENT(2, "Unit Attention when busy..\n");
  1453. return TAPE_IO_PENDING;
  1454. }
  1455. DBF_EVENT(6, "xunknownirq\n");
  1456. tape_dump_sense_dbf(device, request, irb);
  1457. return TAPE_IO_STOP;
  1458. }
  1459. static int tape_3590_read_dev_chars(struct tape_device *device,
  1460. struct tape_3590_rdc_data *rdc_data)
  1461. {
  1462. int rc;
  1463. struct tape_request *request;
  1464. request = tape_alloc_request(1, sizeof(*rdc_data));
  1465. if (IS_ERR(request))
  1466. return PTR_ERR(request);
  1467. request->op = TO_RDC;
  1468. tape_ccw_end(request->cpaddr, CCW_CMD_RDC, sizeof(*rdc_data),
  1469. request->cpdata);
  1470. rc = tape_do_io(device, request);
  1471. if (rc == 0)
  1472. memcpy(rdc_data, request->cpdata, sizeof(*rdc_data));
  1473. tape_free_request(request);
  1474. return rc;
  1475. }
  1476. /*
  1477. * Setup device function
  1478. */
  1479. static int
  1480. tape_3590_setup_device(struct tape_device *device)
  1481. {
  1482. int rc;
  1483. struct tape_3590_disc_data *data;
  1484. struct tape_3590_rdc_data *rdc_data;
  1485. DBF_EVENT(6, "3590 device setup\n");
  1486. data = kzalloc(sizeof(struct tape_3590_disc_data), GFP_KERNEL | GFP_DMA);
  1487. if (data == NULL)
  1488. return -ENOMEM;
  1489. data->read_back_op = READ_PREVIOUS;
  1490. device->discdata = data;
  1491. rdc_data = kmalloc(sizeof(*rdc_data), GFP_KERNEL | GFP_DMA);
  1492. if (!rdc_data) {
  1493. rc = -ENOMEM;
  1494. goto fail_kmalloc;
  1495. }
  1496. rc = tape_3590_read_dev_chars(device, rdc_data);
  1497. if (rc) {
  1498. DBF_LH(3, "Read device characteristics failed!\n");
  1499. goto fail_rdc_data;
  1500. }
  1501. rc = tape_std_assign(device);
  1502. if (rc)
  1503. goto fail_rdc_data;
  1504. if (rdc_data->data[31] == 0x13) {
  1505. data->crypt_info.capability |= TAPE390_CRYPT_SUPPORTED_MASK;
  1506. tape_3592_disable_crypt(device);
  1507. } else {
  1508. DBF_EVENT(6, "Device has NO crypto support\n");
  1509. }
  1510. /* Try to find out if medium is loaded */
  1511. rc = tape_3590_sense_medium(device);
  1512. if (rc) {
  1513. DBF_LH(3, "3590 medium sense returned %d\n", rc);
  1514. goto fail_rdc_data;
  1515. }
  1516. return 0;
  1517. fail_rdc_data:
  1518. kfree(rdc_data);
  1519. fail_kmalloc:
  1520. kfree(data);
  1521. return rc;
  1522. }
  1523. /*
  1524. * Cleanup device function
  1525. */
  1526. static void
  1527. tape_3590_cleanup_device(struct tape_device *device)
  1528. {
  1529. flush_workqueue(tape_3590_wq);
  1530. tape_std_unassign(device);
  1531. kfree(device->discdata);
  1532. device->discdata = NULL;
  1533. }
  1534. /*
  1535. * List of 3590 magnetic tape commands.
  1536. */
  1537. static tape_mtop_fn tape_3590_mtop[TAPE_NR_MTOPS] = {
  1538. [MTRESET] = tape_std_mtreset,
  1539. [MTFSF] = tape_std_mtfsf,
  1540. [MTBSF] = tape_std_mtbsf,
  1541. [MTFSR] = tape_std_mtfsr,
  1542. [MTBSR] = tape_std_mtbsr,
  1543. [MTWEOF] = tape_std_mtweof,
  1544. [MTREW] = tape_std_mtrew,
  1545. [MTOFFL] = tape_std_mtoffl,
  1546. [MTNOP] = tape_std_mtnop,
  1547. [MTRETEN] = tape_std_mtreten,
  1548. [MTBSFM] = tape_std_mtbsfm,
  1549. [MTFSFM] = tape_std_mtfsfm,
  1550. [MTEOM] = tape_std_mteom,
  1551. [MTERASE] = tape_std_mterase,
  1552. [MTRAS1] = NULL,
  1553. [MTRAS2] = NULL,
  1554. [MTRAS3] = NULL,
  1555. [MTSETBLK] = tape_std_mtsetblk,
  1556. [MTSETDENSITY] = NULL,
  1557. [MTSEEK] = tape_3590_mtseek,
  1558. [MTTELL] = tape_3590_mttell,
  1559. [MTSETDRVBUFFER] = NULL,
  1560. [MTFSS] = NULL,
  1561. [MTBSS] = NULL,
  1562. [MTWSM] = NULL,
  1563. [MTLOCK] = NULL,
  1564. [MTUNLOCK] = NULL,
  1565. [MTLOAD] = tape_std_mtload,
  1566. [MTUNLOAD] = tape_std_mtunload,
  1567. [MTCOMPRESSION] = tape_std_mtcompression,
  1568. [MTSETPART] = NULL,
  1569. [MTMKPART] = NULL
  1570. };
  1571. /*
  1572. * Tape discipline structure for 3590.
  1573. */
  1574. static struct tape_discipline tape_discipline_3590 = {
  1575. .owner = THIS_MODULE,
  1576. .setup_device = tape_3590_setup_device,
  1577. .cleanup_device = tape_3590_cleanup_device,
  1578. .process_eov = tape_std_process_eov,
  1579. .irq = tape_3590_irq,
  1580. .read_block = tape_std_read_block,
  1581. .write_block = tape_std_write_block,
  1582. #ifdef CONFIG_S390_TAPE_BLOCK
  1583. .bread = tape_3590_bread,
  1584. .free_bread = tape_3590_free_bread,
  1585. .check_locate = tape_3590_check_locate,
  1586. #endif
  1587. .ioctl_fn = tape_3590_ioctl,
  1588. .mtop_array = tape_3590_mtop
  1589. };
  1590. static struct ccw_device_id tape_3590_ids[] = {
  1591. {CCW_DEVICE_DEVTYPE(0x3590, 0, 0x3590, 0), .driver_info = tape_3590},
  1592. {CCW_DEVICE_DEVTYPE(0x3592, 0, 0x3592, 0), .driver_info = tape_3592},
  1593. { /* end of list */ }
  1594. };
  1595. static int
  1596. tape_3590_online(struct ccw_device *cdev)
  1597. {
  1598. return tape_generic_online(dev_get_drvdata(&cdev->dev),
  1599. &tape_discipline_3590);
  1600. }
  1601. static struct ccw_driver tape_3590_driver = {
  1602. .name = "tape_3590",
  1603. .owner = THIS_MODULE,
  1604. .ids = tape_3590_ids,
  1605. .probe = tape_generic_probe,
  1606. .remove = tape_generic_remove,
  1607. .set_offline = tape_generic_offline,
  1608. .set_online = tape_3590_online,
  1609. .freeze = tape_generic_pm_suspend,
  1610. };
  1611. /*
  1612. * Setup discipline structure.
  1613. */
  1614. static int
  1615. tape_3590_init(void)
  1616. {
  1617. int rc;
  1618. TAPE_DBF_AREA = debug_register("tape_3590", 2, 2, 4 * sizeof(long));
  1619. debug_register_view(TAPE_DBF_AREA, &debug_sprintf_view);
  1620. #ifdef DBF_LIKE_HELL
  1621. debug_set_level(TAPE_DBF_AREA, 6);
  1622. #endif
  1623. DBF_EVENT(3, "3590 init\n");
  1624. tape_3590_wq = alloc_workqueue("tape_3590", 0, 0);
  1625. if (!tape_3590_wq)
  1626. return -ENOMEM;
  1627. /* Register driver for 3590 tapes. */
  1628. rc = ccw_driver_register(&tape_3590_driver);
  1629. if (rc) {
  1630. destroy_workqueue(tape_3590_wq);
  1631. DBF_EVENT(3, "3590 init failed\n");
  1632. } else
  1633. DBF_EVENT(3, "3590 registered\n");
  1634. return rc;
  1635. }
  1636. static void
  1637. tape_3590_exit(void)
  1638. {
  1639. ccw_driver_unregister(&tape_3590_driver);
  1640. destroy_workqueue(tape_3590_wq);
  1641. debug_unregister(TAPE_DBF_AREA);
  1642. }
  1643. MODULE_DEVICE_TABLE(ccw, tape_3590_ids);
  1644. MODULE_AUTHOR("(C) 2001,2006 IBM Corporation");
  1645. MODULE_DESCRIPTION("Linux on zSeries channel attached 3590 tape device driver");
  1646. MODULE_LICENSE("GPL");
  1647. module_init(tape_3590_init);
  1648. module_exit(tape_3590_exit);