tape_34xx.c 37 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348
  1. /*
  2. * drivers/s390/char/tape_34xx.c
  3. * tape device discipline for 3480/3490 tapes.
  4. *
  5. * Copyright (C) IBM Corp. 2001,2006
  6. * Author(s): Carsten Otte <cotte@de.ibm.com>
  7. * Tuan Ngo-Anh <ngoanh@de.ibm.com>
  8. * Martin Schwidefsky <schwidefsky@de.ibm.com>
  9. */
  10. #define KMSG_COMPONENT "tape"
  11. #include <linux/module.h>
  12. #include <linux/init.h>
  13. #include <linux/bio.h>
  14. #include <linux/workqueue.h>
  15. #define TAPE_DBF_AREA tape_34xx_dbf
  16. #include "tape.h"
  17. #include "tape_std.h"
  18. /*
  19. * Pointer to debug area.
  20. */
  21. debug_info_t *TAPE_DBF_AREA = NULL;
  22. EXPORT_SYMBOL(TAPE_DBF_AREA);
  23. #define TAPE34XX_FMT_3480 0
  24. #define TAPE34XX_FMT_3480_2_XF 1
  25. #define TAPE34XX_FMT_3480_XF 2
  26. struct tape_34xx_block_id {
  27. unsigned int wrap : 1;
  28. unsigned int segment : 7;
  29. unsigned int format : 2;
  30. unsigned int block : 22;
  31. };
  32. /*
  33. * A list of block ID's is used to faster seek blocks.
  34. */
  35. struct tape_34xx_sbid {
  36. struct list_head list;
  37. struct tape_34xx_block_id bid;
  38. };
  39. static void tape_34xx_delete_sbid_from(struct tape_device *, int);
  40. /*
  41. * Medium sense for 34xx tapes. There is no 'real' medium sense call.
  42. * So we just do a normal sense.
  43. */
  44. static int
  45. tape_34xx_medium_sense(struct tape_device *device)
  46. {
  47. struct tape_request *request;
  48. unsigned char *sense;
  49. int rc;
  50. request = tape_alloc_request(1, 32);
  51. if (IS_ERR(request)) {
  52. DBF_EXCEPTION(6, "MSEN fail\n");
  53. return PTR_ERR(request);
  54. }
  55. request->op = TO_MSEN;
  56. tape_ccw_end(request->cpaddr, SENSE, 32, request->cpdata);
  57. rc = tape_do_io_interruptible(device, request);
  58. if (request->rc == 0) {
  59. sense = request->cpdata;
  60. /*
  61. * This isn't quite correct. But since INTERVENTION_REQUIRED
  62. * means that the drive is 'neither ready nor on-line' it is
  63. * only slightly inaccurate to say there is no tape loaded if
  64. * the drive isn't online...
  65. */
  66. if (sense[0] & SENSE_INTERVENTION_REQUIRED)
  67. tape_med_state_set(device, MS_UNLOADED);
  68. else
  69. tape_med_state_set(device, MS_LOADED);
  70. if (sense[1] & SENSE_WRITE_PROTECT)
  71. device->tape_generic_status |= GMT_WR_PROT(~0);
  72. else
  73. device->tape_generic_status &= ~GMT_WR_PROT(~0);
  74. } else {
  75. DBF_EVENT(4, "tape_34xx: medium sense failed with rc=%d\n",
  76. request->rc);
  77. }
  78. tape_free_request(request);
  79. return rc;
  80. }
  81. struct tape_34xx_work {
  82. struct tape_device *device;
  83. enum tape_op op;
  84. struct work_struct work;
  85. };
  86. /*
  87. * These functions are currently used only to schedule a medium_sense for
  88. * later execution. This is because we get an interrupt whenever a medium
  89. * is inserted but cannot call tape_do_io* from an interrupt context.
  90. * Maybe that's useful for other actions we want to start from the
  91. * interrupt handler.
  92. */
  93. static void
  94. tape_34xx_work_handler(struct work_struct *work)
  95. {
  96. struct tape_34xx_work *p =
  97. container_of(work, struct tape_34xx_work, work);
  98. switch(p->op) {
  99. case TO_MSEN:
  100. tape_34xx_medium_sense(p->device);
  101. break;
  102. default:
  103. DBF_EVENT(3, "T34XX: internal error: unknown work\n");
  104. }
  105. p->device = tape_put_device(p->device);
  106. kfree(p);
  107. }
  108. static int
  109. tape_34xx_schedule_work(struct tape_device *device, enum tape_op op)
  110. {
  111. struct tape_34xx_work *p;
  112. if ((p = kzalloc(sizeof(*p), GFP_ATOMIC)) == NULL)
  113. return -ENOMEM;
  114. INIT_WORK(&p->work, tape_34xx_work_handler);
  115. p->device = tape_get_device_reference(device);
  116. p->op = op;
  117. schedule_work(&p->work);
  118. return 0;
  119. }
  120. /*
  121. * Done Handler is called when dev stat = DEVICE-END (successful operation)
  122. */
  123. static inline int
  124. tape_34xx_done(struct tape_request *request)
  125. {
  126. DBF_EVENT(6, "%s done\n", tape_op_verbose[request->op]);
  127. switch (request->op) {
  128. case TO_DSE:
  129. case TO_RUN:
  130. case TO_WRI:
  131. case TO_WTM:
  132. case TO_ASSIGN:
  133. case TO_UNASSIGN:
  134. tape_34xx_delete_sbid_from(request->device, 0);
  135. break;
  136. default:
  137. ;
  138. }
  139. return TAPE_IO_SUCCESS;
  140. }
  141. static inline int
  142. tape_34xx_erp_failed(struct tape_request *request, int rc)
  143. {
  144. DBF_EVENT(3, "Error recovery failed for %s (RC=%d)\n",
  145. tape_op_verbose[request->op], rc);
  146. return rc;
  147. }
  148. static inline int
  149. tape_34xx_erp_succeeded(struct tape_request *request)
  150. {
  151. DBF_EVENT(3, "Error Recovery successful for %s\n",
  152. tape_op_verbose[request->op]);
  153. return tape_34xx_done(request);
  154. }
  155. static inline int
  156. tape_34xx_erp_retry(struct tape_request *request)
  157. {
  158. DBF_EVENT(3, "xerp retr %s\n", tape_op_verbose[request->op]);
  159. return TAPE_IO_RETRY;
  160. }
  161. /*
  162. * This function is called, when no request is outstanding and we get an
  163. * interrupt
  164. */
  165. static int
  166. tape_34xx_unsolicited_irq(struct tape_device *device, struct irb *irb)
  167. {
  168. if (irb->scsw.cmd.dstat == 0x85) { /* READY */
  169. /* A medium was inserted in the drive. */
  170. DBF_EVENT(6, "xuud med\n");
  171. tape_34xx_delete_sbid_from(device, 0);
  172. tape_34xx_schedule_work(device, TO_MSEN);
  173. } else {
  174. DBF_EVENT(3, "unsol.irq! dev end: %08x\n", device->cdev_id);
  175. tape_dump_sense_dbf(device, NULL, irb);
  176. }
  177. return TAPE_IO_SUCCESS;
  178. }
  179. /*
  180. * Read Opposite Error Recovery Function:
  181. * Used, when Read Forward does not work
  182. */
  183. static int
  184. tape_34xx_erp_read_opposite(struct tape_device *device,
  185. struct tape_request *request)
  186. {
  187. if (request->op == TO_RFO) {
  188. /*
  189. * We did read forward, but the data could not be read
  190. * *correctly*. We transform the request to a read backward
  191. * and try again.
  192. */
  193. tape_std_read_backward(device, request);
  194. return tape_34xx_erp_retry(request);
  195. }
  196. /*
  197. * We tried to read forward and backward, but hat no
  198. * success -> failed.
  199. */
  200. return tape_34xx_erp_failed(request, -EIO);
  201. }
  202. static int
  203. tape_34xx_erp_bug(struct tape_device *device, struct tape_request *request,
  204. struct irb *irb, int no)
  205. {
  206. if (request->op != TO_ASSIGN) {
  207. dev_err(&device->cdev->dev, "An unexpected condition %d "
  208. "occurred in tape error recovery\n", no);
  209. tape_dump_sense_dbf(device, request, irb);
  210. }
  211. return tape_34xx_erp_failed(request, -EIO);
  212. }
  213. /*
  214. * Handle data overrun between cu and drive. The channel speed might
  215. * be too slow.
  216. */
  217. static int
  218. tape_34xx_erp_overrun(struct tape_device *device, struct tape_request *request,
  219. struct irb *irb)
  220. {
  221. if (irb->ecw[3] == 0x40) {
  222. dev_warn (&device->cdev->dev, "A data overrun occurred between"
  223. " the control unit and tape unit\n");
  224. return tape_34xx_erp_failed(request, -EIO);
  225. }
  226. return tape_34xx_erp_bug(device, request, irb, -1);
  227. }
  228. /*
  229. * Handle record sequence error.
  230. */
  231. static int
  232. tape_34xx_erp_sequence(struct tape_device *device,
  233. struct tape_request *request, struct irb *irb)
  234. {
  235. if (irb->ecw[3] == 0x41) {
  236. /*
  237. * cu detected incorrect block-id sequence on tape.
  238. */
  239. dev_warn (&device->cdev->dev, "The block ID sequence on the "
  240. "tape is incorrect\n");
  241. return tape_34xx_erp_failed(request, -EIO);
  242. }
  243. /*
  244. * Record sequence error bit is set, but erpa does not
  245. * show record sequence error.
  246. */
  247. return tape_34xx_erp_bug(device, request, irb, -2);
  248. }
  249. /*
  250. * This function analyses the tape's sense-data in case of a unit-check.
  251. * If possible, it tries to recover from the error. Else the user is
  252. * informed about the problem.
  253. */
  254. static int
  255. tape_34xx_unit_check(struct tape_device *device, struct tape_request *request,
  256. struct irb *irb)
  257. {
  258. int inhibit_cu_recovery;
  259. __u8* sense;
  260. inhibit_cu_recovery = (*device->modeset_byte & 0x80) ? 1 : 0;
  261. sense = irb->ecw;
  262. #ifdef CONFIG_S390_TAPE_BLOCK
  263. if (request->op == TO_BLOCK) {
  264. /*
  265. * Recovery for block device requests. Set the block_position
  266. * to something invalid and retry.
  267. */
  268. device->blk_data.block_position = -1;
  269. if (request->retries-- <= 0)
  270. return tape_34xx_erp_failed(request, -EIO);
  271. else
  272. return tape_34xx_erp_retry(request);
  273. }
  274. #endif
  275. if (
  276. sense[0] & SENSE_COMMAND_REJECT &&
  277. sense[1] & SENSE_WRITE_PROTECT
  278. ) {
  279. if (
  280. request->op == TO_DSE ||
  281. request->op == TO_WRI ||
  282. request->op == TO_WTM
  283. ) {
  284. /* medium is write protected */
  285. return tape_34xx_erp_failed(request, -EACCES);
  286. } else {
  287. return tape_34xx_erp_bug(device, request, irb, -3);
  288. }
  289. }
  290. /*
  291. * Special cases for various tape-states when reaching
  292. * end of recorded area
  293. *
  294. * FIXME: Maybe a special case of the special case:
  295. * sense[0] == SENSE_EQUIPMENT_CHECK &&
  296. * sense[1] == SENSE_DRIVE_ONLINE &&
  297. * sense[3] == 0x47 (Volume Fenced)
  298. *
  299. * This was caused by continued FSF or FSR after an
  300. * 'End Of Data'.
  301. */
  302. if ((
  303. sense[0] == SENSE_DATA_CHECK ||
  304. sense[0] == SENSE_EQUIPMENT_CHECK ||
  305. sense[0] == SENSE_EQUIPMENT_CHECK + SENSE_DEFERRED_UNIT_CHECK
  306. ) && (
  307. sense[1] == SENSE_DRIVE_ONLINE ||
  308. sense[1] == SENSE_BEGINNING_OF_TAPE + SENSE_WRITE_MODE
  309. )) {
  310. switch (request->op) {
  311. /*
  312. * sense[0] == SENSE_DATA_CHECK &&
  313. * sense[1] == SENSE_DRIVE_ONLINE
  314. * sense[3] == 0x36 (End Of Data)
  315. *
  316. * Further seeks might return a 'Volume Fenced'.
  317. */
  318. case TO_FSF:
  319. case TO_FSB:
  320. /* Trying to seek beyond end of recorded area */
  321. return tape_34xx_erp_failed(request, -ENOSPC);
  322. case TO_BSB:
  323. return tape_34xx_erp_retry(request);
  324. /*
  325. * sense[0] == SENSE_DATA_CHECK &&
  326. * sense[1] == SENSE_DRIVE_ONLINE &&
  327. * sense[3] == 0x36 (End Of Data)
  328. */
  329. case TO_LBL:
  330. /* Block could not be located. */
  331. tape_34xx_delete_sbid_from(device, 0);
  332. return tape_34xx_erp_failed(request, -EIO);
  333. case TO_RFO:
  334. /* Read beyond end of recorded area -> 0 bytes read */
  335. return tape_34xx_erp_failed(request, 0);
  336. /*
  337. * sense[0] == SENSE_EQUIPMENT_CHECK &&
  338. * sense[1] == SENSE_DRIVE_ONLINE &&
  339. * sense[3] == 0x38 (Physical End Of Volume)
  340. */
  341. case TO_WRI:
  342. /* Writing at physical end of volume */
  343. return tape_34xx_erp_failed(request, -ENOSPC);
  344. default:
  345. return tape_34xx_erp_failed(request, 0);
  346. }
  347. }
  348. /* Sensing special bits */
  349. if (sense[0] & SENSE_BUS_OUT_CHECK)
  350. return tape_34xx_erp_retry(request);
  351. if (sense[0] & SENSE_DATA_CHECK) {
  352. /*
  353. * hardware failure, damaged tape or improper
  354. * operating conditions
  355. */
  356. switch (sense[3]) {
  357. case 0x23:
  358. /* a read data check occurred */
  359. if ((sense[2] & SENSE_TAPE_SYNC_MODE) ||
  360. inhibit_cu_recovery)
  361. // data check is not permanent, may be
  362. // recovered. We always use async-mode with
  363. // cu-recovery, so this should *never* happen.
  364. return tape_34xx_erp_bug(device, request,
  365. irb, -4);
  366. /* data check is permanent, CU recovery has failed */
  367. dev_warn (&device->cdev->dev, "A read error occurred "
  368. "that cannot be recovered\n");
  369. return tape_34xx_erp_failed(request, -EIO);
  370. case 0x25:
  371. // a write data check occurred
  372. if ((sense[2] & SENSE_TAPE_SYNC_MODE) ||
  373. inhibit_cu_recovery)
  374. // data check is not permanent, may be
  375. // recovered. We always use async-mode with
  376. // cu-recovery, so this should *never* happen.
  377. return tape_34xx_erp_bug(device, request,
  378. irb, -5);
  379. // data check is permanent, cu-recovery has failed
  380. dev_warn (&device->cdev->dev, "A write error on the "
  381. "tape cannot be recovered\n");
  382. return tape_34xx_erp_failed(request, -EIO);
  383. case 0x26:
  384. /* Data Check (read opposite) occurred. */
  385. return tape_34xx_erp_read_opposite(device, request);
  386. case 0x28:
  387. /* ID-Mark at tape start couldn't be written */
  388. dev_warn (&device->cdev->dev, "Writing the ID-mark "
  389. "failed\n");
  390. return tape_34xx_erp_failed(request, -EIO);
  391. case 0x31:
  392. /* Tape void. Tried to read beyond end of device. */
  393. dev_warn (&device->cdev->dev, "Reading the tape beyond"
  394. " the end of the recorded area failed\n");
  395. return tape_34xx_erp_failed(request, -ENOSPC);
  396. case 0x41:
  397. /* Record sequence error. */
  398. dev_warn (&device->cdev->dev, "The tape contains an "
  399. "incorrect block ID sequence\n");
  400. return tape_34xx_erp_failed(request, -EIO);
  401. default:
  402. /* all data checks for 3480 should result in one of
  403. * the above erpa-codes. For 3490, other data-check
  404. * conditions do exist. */
  405. if (device->cdev->id.driver_info == tape_3480)
  406. return tape_34xx_erp_bug(device, request,
  407. irb, -6);
  408. }
  409. }
  410. if (sense[0] & SENSE_OVERRUN)
  411. return tape_34xx_erp_overrun(device, request, irb);
  412. if (sense[1] & SENSE_RECORD_SEQUENCE_ERR)
  413. return tape_34xx_erp_sequence(device, request, irb);
  414. /* Sensing erpa codes */
  415. switch (sense[3]) {
  416. case 0x00:
  417. /* Unit check with erpa code 0. Report and ignore. */
  418. return TAPE_IO_SUCCESS;
  419. case 0x21:
  420. /*
  421. * Data streaming not operational. CU will switch to
  422. * interlock mode. Reissue the command.
  423. */
  424. return tape_34xx_erp_retry(request);
  425. case 0x22:
  426. /*
  427. * Path equipment check. Might be drive adapter error, buffer
  428. * error on the lower interface, internal path not usable,
  429. * or error during cartridge load.
  430. */
  431. dev_warn (&device->cdev->dev, "A path equipment check occurred"
  432. " for the tape device\n");
  433. return tape_34xx_erp_failed(request, -EIO);
  434. case 0x24:
  435. /*
  436. * Load display check. Load display was command was issued,
  437. * but the drive is displaying a drive check message. Can
  438. * be threated as "device end".
  439. */
  440. return tape_34xx_erp_succeeded(request);
  441. case 0x27:
  442. /*
  443. * Command reject. May indicate illegal channel program or
  444. * buffer over/underrun. Since all channel programs are
  445. * issued by this driver and ought be correct, we assume a
  446. * over/underrun situation and retry the channel program.
  447. */
  448. return tape_34xx_erp_retry(request);
  449. case 0x29:
  450. /*
  451. * Function incompatible. Either the tape is idrc compressed
  452. * but the hardware isn't capable to do idrc, or a perform
  453. * subsystem func is issued and the CU is not on-line.
  454. */
  455. return tape_34xx_erp_failed(request, -EIO);
  456. case 0x2a:
  457. /*
  458. * Unsolicited environmental data. An internal counter
  459. * overflows, we can ignore this and reissue the cmd.
  460. */
  461. return tape_34xx_erp_retry(request);
  462. case 0x2b:
  463. /*
  464. * Environmental data present. Indicates either unload
  465. * completed ok or read buffered log command completed ok.
  466. */
  467. if (request->op == TO_RUN) {
  468. /* Rewind unload completed ok. */
  469. tape_med_state_set(device, MS_UNLOADED);
  470. return tape_34xx_erp_succeeded(request);
  471. }
  472. /* tape_34xx doesn't use read buffered log commands. */
  473. return tape_34xx_erp_bug(device, request, irb, sense[3]);
  474. case 0x2c:
  475. /*
  476. * Permanent equipment check. CU has tried recovery, but
  477. * did not succeed.
  478. */
  479. return tape_34xx_erp_failed(request, -EIO);
  480. case 0x2d:
  481. /* Data security erase failure. */
  482. if (request->op == TO_DSE)
  483. return tape_34xx_erp_failed(request, -EIO);
  484. /* Data security erase failure, but no such command issued. */
  485. return tape_34xx_erp_bug(device, request, irb, sense[3]);
  486. case 0x2e:
  487. /*
  488. * Not capable. This indicates either that the drive fails
  489. * reading the format id mark or that that format specified
  490. * is not supported by the drive.
  491. */
  492. dev_warn (&device->cdev->dev, "The tape unit cannot process "
  493. "the tape format\n");
  494. return tape_34xx_erp_failed(request, -EMEDIUMTYPE);
  495. case 0x30:
  496. /* The medium is write protected. */
  497. dev_warn (&device->cdev->dev, "The tape medium is write-"
  498. "protected\n");
  499. return tape_34xx_erp_failed(request, -EACCES);
  500. case 0x32:
  501. // Tension loss. We cannot recover this, it's an I/O error.
  502. dev_warn (&device->cdev->dev, "The tape does not have the "
  503. "required tape tension\n");
  504. return tape_34xx_erp_failed(request, -EIO);
  505. case 0x33:
  506. /*
  507. * Load Failure. The cartridge was not inserted correctly or
  508. * the tape is not threaded correctly.
  509. */
  510. dev_warn (&device->cdev->dev, "The tape unit failed to load"
  511. " the cartridge\n");
  512. tape_34xx_delete_sbid_from(device, 0);
  513. return tape_34xx_erp_failed(request, -EIO);
  514. case 0x34:
  515. /*
  516. * Unload failure. The drive cannot maintain tape tension
  517. * and control tape movement during an unload operation.
  518. */
  519. dev_warn (&device->cdev->dev, "Automatic unloading of the tape"
  520. " cartridge failed\n");
  521. if (request->op == TO_RUN)
  522. return tape_34xx_erp_failed(request, -EIO);
  523. return tape_34xx_erp_bug(device, request, irb, sense[3]);
  524. case 0x35:
  525. /*
  526. * Drive equipment check. One of the following:
  527. * - cu cannot recover from a drive detected error
  528. * - a check code message is shown on drive display
  529. * - the cartridge loader does not respond correctly
  530. * - a failure occurs during an index, load, or unload cycle
  531. */
  532. dev_warn (&device->cdev->dev, "An equipment check has occurred"
  533. " on the tape unit\n");
  534. return tape_34xx_erp_failed(request, -EIO);
  535. case 0x36:
  536. if (device->cdev->id.driver_info == tape_3490)
  537. /* End of data. */
  538. return tape_34xx_erp_failed(request, -EIO);
  539. /* This erpa is reserved for 3480 */
  540. return tape_34xx_erp_bug(device, request, irb, sense[3]);
  541. case 0x37:
  542. /*
  543. * Tape length error. The tape is shorter than reported in
  544. * the beginning-of-tape data.
  545. */
  546. dev_warn (&device->cdev->dev, "The tape information states an"
  547. " incorrect length\n");
  548. return tape_34xx_erp_failed(request, -EIO);
  549. case 0x38:
  550. /*
  551. * Physical end of tape. A read/write operation reached
  552. * the physical end of tape.
  553. */
  554. if (request->op==TO_WRI ||
  555. request->op==TO_DSE ||
  556. request->op==TO_WTM)
  557. return tape_34xx_erp_failed(request, -ENOSPC);
  558. return tape_34xx_erp_failed(request, -EIO);
  559. case 0x39:
  560. /* Backward at Beginning of tape. */
  561. return tape_34xx_erp_failed(request, -EIO);
  562. case 0x3a:
  563. /* Drive switched to not ready. */
  564. dev_warn (&device->cdev->dev, "The tape unit is not ready\n");
  565. return tape_34xx_erp_failed(request, -EIO);
  566. case 0x3b:
  567. /* Manual rewind or unload. This causes an I/O error. */
  568. dev_warn (&device->cdev->dev, "The tape medium has been "
  569. "rewound or unloaded manually\n");
  570. tape_34xx_delete_sbid_from(device, 0);
  571. return tape_34xx_erp_failed(request, -EIO);
  572. case 0x42:
  573. /*
  574. * Degraded mode. A condition that can cause degraded
  575. * performance is detected.
  576. */
  577. dev_warn (&device->cdev->dev, "The tape subsystem is running "
  578. "in degraded mode\n");
  579. return tape_34xx_erp_retry(request);
  580. case 0x43:
  581. /* Drive not ready. */
  582. tape_34xx_delete_sbid_from(device, 0);
  583. tape_med_state_set(device, MS_UNLOADED);
  584. /* Some commands commands are successful even in this case */
  585. if (sense[1] & SENSE_DRIVE_ONLINE) {
  586. switch(request->op) {
  587. case TO_ASSIGN:
  588. case TO_UNASSIGN:
  589. case TO_DIS:
  590. case TO_NOP:
  591. return tape_34xx_done(request);
  592. break;
  593. default:
  594. break;
  595. }
  596. }
  597. return tape_34xx_erp_failed(request, -ENOMEDIUM);
  598. case 0x44:
  599. /* Locate Block unsuccessful. */
  600. if (request->op != TO_BLOCK && request->op != TO_LBL)
  601. /* No locate block was issued. */
  602. return tape_34xx_erp_bug(device, request,
  603. irb, sense[3]);
  604. return tape_34xx_erp_failed(request, -EIO);
  605. case 0x45:
  606. /* The drive is assigned to a different channel path. */
  607. dev_warn (&device->cdev->dev, "The tape unit is already "
  608. "assigned\n");
  609. return tape_34xx_erp_failed(request, -EIO);
  610. case 0x46:
  611. /*
  612. * Drive not on-line. Drive may be switched offline,
  613. * the power supply may be switched off or
  614. * the drive address may not be set correctly.
  615. */
  616. dev_warn (&device->cdev->dev, "The tape unit is not online\n");
  617. return tape_34xx_erp_failed(request, -EIO);
  618. case 0x47:
  619. /* Volume fenced. CU reports volume integrity is lost. */
  620. dev_warn (&device->cdev->dev, "The control unit has fenced "
  621. "access to the tape volume\n");
  622. tape_34xx_delete_sbid_from(device, 0);
  623. return tape_34xx_erp_failed(request, -EIO);
  624. case 0x48:
  625. /* Log sense data and retry request. */
  626. return tape_34xx_erp_retry(request);
  627. case 0x49:
  628. /* Bus out check. A parity check error on the bus was found. */
  629. dev_warn (&device->cdev->dev, "A parity error occurred on the "
  630. "tape bus\n");
  631. return tape_34xx_erp_failed(request, -EIO);
  632. case 0x4a:
  633. /* Control unit erp failed. */
  634. dev_warn (&device->cdev->dev, "I/O error recovery failed on "
  635. "the tape control unit\n");
  636. return tape_34xx_erp_failed(request, -EIO);
  637. case 0x4b:
  638. /*
  639. * CU and drive incompatible. The drive requests micro-program
  640. * patches, which are not available on the CU.
  641. */
  642. dev_warn (&device->cdev->dev, "The tape unit requires a "
  643. "firmware update\n");
  644. return tape_34xx_erp_failed(request, -EIO);
  645. case 0x4c:
  646. /*
  647. * Recovered Check-One failure. Cu develops a hardware error,
  648. * but is able to recover.
  649. */
  650. return tape_34xx_erp_retry(request);
  651. case 0x4d:
  652. if (device->cdev->id.driver_info == tape_3490)
  653. /*
  654. * Resetting event received. Since the driver does
  655. * not support resetting event recovery (which has to
  656. * be handled by the I/O Layer), retry our command.
  657. */
  658. return tape_34xx_erp_retry(request);
  659. /* This erpa is reserved for 3480. */
  660. return tape_34xx_erp_bug(device, request, irb, sense[3]);
  661. case 0x4e:
  662. if (device->cdev->id.driver_info == tape_3490) {
  663. /*
  664. * Maximum block size exceeded. This indicates, that
  665. * the block to be written is larger than allowed for
  666. * buffered mode.
  667. */
  668. dev_warn (&device->cdev->dev, "The maximum block size"
  669. " for buffered mode is exceeded\n");
  670. return tape_34xx_erp_failed(request, -ENOBUFS);
  671. }
  672. /* This erpa is reserved for 3480. */
  673. return tape_34xx_erp_bug(device, request, irb, sense[3]);
  674. case 0x50:
  675. /*
  676. * Read buffered log (Overflow). CU is running in extended
  677. * buffered log mode, and a counter overflows. This should
  678. * never happen, since we're never running in extended
  679. * buffered log mode.
  680. */
  681. return tape_34xx_erp_retry(request);
  682. case 0x51:
  683. /*
  684. * Read buffered log (EOV). EOF processing occurs while the
  685. * CU is in extended buffered log mode. This should never
  686. * happen, since we're never running in extended buffered
  687. * log mode.
  688. */
  689. return tape_34xx_erp_retry(request);
  690. case 0x52:
  691. /* End of Volume complete. Rewind unload completed ok. */
  692. if (request->op == TO_RUN) {
  693. tape_med_state_set(device, MS_UNLOADED);
  694. tape_34xx_delete_sbid_from(device, 0);
  695. return tape_34xx_erp_succeeded(request);
  696. }
  697. return tape_34xx_erp_bug(device, request, irb, sense[3]);
  698. case 0x53:
  699. /* Global command intercept. */
  700. return tape_34xx_erp_retry(request);
  701. case 0x54:
  702. /* Channel interface recovery (temporary). */
  703. return tape_34xx_erp_retry(request);
  704. case 0x55:
  705. /* Channel interface recovery (permanent). */
  706. dev_warn (&device->cdev->dev, "A channel interface error cannot be"
  707. " recovered\n");
  708. return tape_34xx_erp_failed(request, -EIO);
  709. case 0x56:
  710. /* Channel protocol error. */
  711. dev_warn (&device->cdev->dev, "A channel protocol error "
  712. "occurred\n");
  713. return tape_34xx_erp_failed(request, -EIO);
  714. case 0x57:
  715. if (device->cdev->id.driver_info == tape_3480) {
  716. /* Attention intercept. */
  717. return tape_34xx_erp_retry(request);
  718. } else {
  719. /* Global status intercept. */
  720. return tape_34xx_erp_retry(request);
  721. }
  722. case 0x5a:
  723. /*
  724. * Tape length incompatible. The tape inserted is too long,
  725. * which could cause damage to the tape or the drive.
  726. */
  727. dev_warn (&device->cdev->dev, "The tape unit does not support "
  728. "the tape length\n");
  729. return tape_34xx_erp_failed(request, -EIO);
  730. case 0x5b:
  731. /* Format 3480 XF incompatible */
  732. if (sense[1] & SENSE_BEGINNING_OF_TAPE)
  733. /* The tape will get overwritten. */
  734. return tape_34xx_erp_retry(request);
  735. dev_warn (&device->cdev->dev, "The tape unit does not support"
  736. " format 3480 XF\n");
  737. return tape_34xx_erp_failed(request, -EIO);
  738. case 0x5c:
  739. /* Format 3480-2 XF incompatible */
  740. dev_warn (&device->cdev->dev, "The tape unit does not support tape "
  741. "format 3480-2 XF\n");
  742. return tape_34xx_erp_failed(request, -EIO);
  743. case 0x5d:
  744. /* Tape length violation. */
  745. dev_warn (&device->cdev->dev, "The tape unit does not support"
  746. " the current tape length\n");
  747. return tape_34xx_erp_failed(request, -EMEDIUMTYPE);
  748. case 0x5e:
  749. /* Compaction algorithm incompatible. */
  750. dev_warn (&device->cdev->dev, "The tape unit does not support"
  751. " the compaction algorithm\n");
  752. return tape_34xx_erp_failed(request, -EMEDIUMTYPE);
  753. /* The following erpas should have been covered earlier. */
  754. case 0x23: /* Read data check. */
  755. case 0x25: /* Write data check. */
  756. case 0x26: /* Data check (read opposite). */
  757. case 0x28: /* Write id mark check. */
  758. case 0x31: /* Tape void. */
  759. case 0x40: /* Overrun error. */
  760. case 0x41: /* Record sequence error. */
  761. /* All other erpas are reserved for future use. */
  762. default:
  763. return tape_34xx_erp_bug(device, request, irb, sense[3]);
  764. }
  765. }
  766. /*
  767. * 3480/3490 interrupt handler
  768. */
  769. static int
  770. tape_34xx_irq(struct tape_device *device, struct tape_request *request,
  771. struct irb *irb)
  772. {
  773. if (request == NULL)
  774. return tape_34xx_unsolicited_irq(device, irb);
  775. if ((irb->scsw.cmd.dstat & DEV_STAT_UNIT_EXCEP) &&
  776. (irb->scsw.cmd.dstat & DEV_STAT_DEV_END) &&
  777. (request->op == TO_WRI)) {
  778. /* Write at end of volume */
  779. return tape_34xx_erp_failed(request, -ENOSPC);
  780. }
  781. if (irb->scsw.cmd.dstat & DEV_STAT_UNIT_CHECK)
  782. return tape_34xx_unit_check(device, request, irb);
  783. if (irb->scsw.cmd.dstat & DEV_STAT_DEV_END) {
  784. /*
  785. * A unit exception occurs on skipping over a tapemark block.
  786. */
  787. if (irb->scsw.cmd.dstat & DEV_STAT_UNIT_EXCEP) {
  788. if (request->op == TO_BSB || request->op == TO_FSB)
  789. request->rescnt++;
  790. else
  791. DBF_EVENT(5, "Unit Exception!\n");
  792. }
  793. return tape_34xx_done(request);
  794. }
  795. DBF_EVENT(6, "xunknownirq\n");
  796. tape_dump_sense_dbf(device, request, irb);
  797. return TAPE_IO_STOP;
  798. }
  799. /*
  800. * ioctl_overload
  801. */
  802. static int
  803. tape_34xx_ioctl(struct tape_device *device, unsigned int cmd, unsigned long arg)
  804. {
  805. if (cmd == TAPE390_DISPLAY) {
  806. struct display_struct disp;
  807. if (copy_from_user(&disp, (char __user *) arg, sizeof(disp)) != 0)
  808. return -EFAULT;
  809. return tape_std_display(device, &disp);
  810. } else
  811. return -EINVAL;
  812. }
  813. static inline void
  814. tape_34xx_append_new_sbid(struct tape_34xx_block_id bid, struct list_head *l)
  815. {
  816. struct tape_34xx_sbid * new_sbid;
  817. new_sbid = kmalloc(sizeof(*new_sbid), GFP_ATOMIC);
  818. if (!new_sbid)
  819. return;
  820. new_sbid->bid = bid;
  821. list_add(&new_sbid->list, l);
  822. }
  823. /*
  824. * Build up the search block ID list. The block ID consists of a logical
  825. * block number and a hardware specific part. The hardware specific part
  826. * helps the tape drive to speed up searching for a specific block.
  827. */
  828. static void
  829. tape_34xx_add_sbid(struct tape_device *device, struct tape_34xx_block_id bid)
  830. {
  831. struct list_head * sbid_list;
  832. struct tape_34xx_sbid * sbid;
  833. struct list_head * l;
  834. /*
  835. * immediately return if there is no list at all or the block to add
  836. * is located in segment 1 of wrap 0 because this position is used
  837. * if no hardware position data is supplied.
  838. */
  839. sbid_list = (struct list_head *) device->discdata;
  840. if (!sbid_list || (bid.segment < 2 && bid.wrap == 0))
  841. return;
  842. /*
  843. * Search the position where to insert the new entry. Hardware
  844. * acceleration uses only the segment and wrap number. So we
  845. * need only one entry for a specific wrap/segment combination.
  846. * If there is a block with a lower number but the same hard-
  847. * ware position data we just update the block number in the
  848. * existing entry.
  849. */
  850. list_for_each(l, sbid_list) {
  851. sbid = list_entry(l, struct tape_34xx_sbid, list);
  852. if (
  853. (sbid->bid.segment == bid.segment) &&
  854. (sbid->bid.wrap == bid.wrap)
  855. ) {
  856. if (bid.block < sbid->bid.block)
  857. sbid->bid = bid;
  858. else return;
  859. break;
  860. }
  861. /* Sort in according to logical block number. */
  862. if (bid.block < sbid->bid.block) {
  863. tape_34xx_append_new_sbid(bid, l->prev);
  864. break;
  865. }
  866. }
  867. /* List empty or new block bigger than last entry. */
  868. if (l == sbid_list)
  869. tape_34xx_append_new_sbid(bid, l->prev);
  870. DBF_LH(4, "Current list is:\n");
  871. list_for_each(l, sbid_list) {
  872. sbid = list_entry(l, struct tape_34xx_sbid, list);
  873. DBF_LH(4, "%d:%03d@%05d\n",
  874. sbid->bid.wrap,
  875. sbid->bid.segment,
  876. sbid->bid.block
  877. );
  878. }
  879. }
  880. /*
  881. * Delete all entries from the search block ID list that belong to tape blocks
  882. * equal or higher than the given number.
  883. */
  884. static void
  885. tape_34xx_delete_sbid_from(struct tape_device *device, int from)
  886. {
  887. struct list_head * sbid_list;
  888. struct tape_34xx_sbid * sbid;
  889. struct list_head * l;
  890. struct list_head * n;
  891. sbid_list = (struct list_head *) device->discdata;
  892. if (!sbid_list)
  893. return;
  894. list_for_each_safe(l, n, sbid_list) {
  895. sbid = list_entry(l, struct tape_34xx_sbid, list);
  896. if (sbid->bid.block >= from) {
  897. DBF_LH(4, "Delete sbid %d:%03d@%05d\n",
  898. sbid->bid.wrap,
  899. sbid->bid.segment,
  900. sbid->bid.block
  901. );
  902. list_del(l);
  903. kfree(sbid);
  904. }
  905. }
  906. }
  907. /*
  908. * Merge hardware position data into a block id.
  909. */
  910. static void
  911. tape_34xx_merge_sbid(
  912. struct tape_device * device,
  913. struct tape_34xx_block_id * bid
  914. ) {
  915. struct tape_34xx_sbid * sbid;
  916. struct tape_34xx_sbid * sbid_to_use;
  917. struct list_head * sbid_list;
  918. struct list_head * l;
  919. sbid_list = (struct list_head *) device->discdata;
  920. bid->wrap = 0;
  921. bid->segment = 1;
  922. if (!sbid_list || list_empty(sbid_list))
  923. return;
  924. sbid_to_use = NULL;
  925. list_for_each(l, sbid_list) {
  926. sbid = list_entry(l, struct tape_34xx_sbid, list);
  927. if (sbid->bid.block >= bid->block)
  928. break;
  929. sbid_to_use = sbid;
  930. }
  931. if (sbid_to_use) {
  932. bid->wrap = sbid_to_use->bid.wrap;
  933. bid->segment = sbid_to_use->bid.segment;
  934. DBF_LH(4, "Use %d:%03d@%05d for %05d\n",
  935. sbid_to_use->bid.wrap,
  936. sbid_to_use->bid.segment,
  937. sbid_to_use->bid.block,
  938. bid->block
  939. );
  940. }
  941. }
  942. static int
  943. tape_34xx_setup_device(struct tape_device * device)
  944. {
  945. int rc;
  946. struct list_head * discdata;
  947. DBF_EVENT(6, "34xx device setup\n");
  948. if ((rc = tape_std_assign(device)) == 0) {
  949. if ((rc = tape_34xx_medium_sense(device)) != 0) {
  950. DBF_LH(3, "34xx medium sense returned %d\n", rc);
  951. }
  952. }
  953. discdata = kmalloc(sizeof(struct list_head), GFP_KERNEL);
  954. if (discdata) {
  955. INIT_LIST_HEAD(discdata);
  956. device->discdata = discdata;
  957. }
  958. return rc;
  959. }
  960. static void
  961. tape_34xx_cleanup_device(struct tape_device *device)
  962. {
  963. tape_std_unassign(device);
  964. if (device->discdata) {
  965. tape_34xx_delete_sbid_from(device, 0);
  966. kfree(device->discdata);
  967. device->discdata = NULL;
  968. }
  969. }
  970. /*
  971. * MTTELL: Tell block. Return the number of block relative to current file.
  972. */
  973. static int
  974. tape_34xx_mttell(struct tape_device *device, int mt_count)
  975. {
  976. struct {
  977. struct tape_34xx_block_id cbid;
  978. struct tape_34xx_block_id dbid;
  979. } __attribute__ ((packed)) block_id;
  980. int rc;
  981. rc = tape_std_read_block_id(device, (__u64 *) &block_id);
  982. if (rc)
  983. return rc;
  984. tape_34xx_add_sbid(device, block_id.cbid);
  985. return block_id.cbid.block;
  986. }
  987. /*
  988. * MTSEEK: seek to the specified block.
  989. */
  990. static int
  991. tape_34xx_mtseek(struct tape_device *device, int mt_count)
  992. {
  993. struct tape_request *request;
  994. struct tape_34xx_block_id * bid;
  995. if (mt_count > 0x3fffff) {
  996. DBF_EXCEPTION(6, "xsee parm\n");
  997. return -EINVAL;
  998. }
  999. request = tape_alloc_request(3, 4);
  1000. if (IS_ERR(request))
  1001. return PTR_ERR(request);
  1002. /* setup ccws */
  1003. request->op = TO_LBL;
  1004. bid = (struct tape_34xx_block_id *) request->cpdata;
  1005. bid->format = (*device->modeset_byte & 0x08) ?
  1006. TAPE34XX_FMT_3480_XF : TAPE34XX_FMT_3480;
  1007. bid->block = mt_count;
  1008. tape_34xx_merge_sbid(device, bid);
  1009. tape_ccw_cc(request->cpaddr, MODE_SET_DB, 1, device->modeset_byte);
  1010. tape_ccw_cc(request->cpaddr + 1, LOCATE, 4, request->cpdata);
  1011. tape_ccw_end(request->cpaddr + 2, NOP, 0, NULL);
  1012. /* execute it */
  1013. return tape_do_io_free(device, request);
  1014. }
  1015. #ifdef CONFIG_S390_TAPE_BLOCK
  1016. /*
  1017. * Tape block read for 34xx.
  1018. */
  1019. static struct tape_request *
  1020. tape_34xx_bread(struct tape_device *device, struct request *req)
  1021. {
  1022. struct tape_request *request;
  1023. struct ccw1 *ccw;
  1024. int count = 0;
  1025. unsigned off;
  1026. char *dst;
  1027. struct bio_vec *bv;
  1028. struct req_iterator iter;
  1029. struct tape_34xx_block_id * start_block;
  1030. DBF_EVENT(6, "xBREDid:");
  1031. /* Count the number of blocks for the request. */
  1032. rq_for_each_segment(bv, req, iter)
  1033. count += bv->bv_len >> (TAPEBLOCK_HSEC_S2B + 9);
  1034. /* Allocate the ccw request. */
  1035. request = tape_alloc_request(3+count+1, 8);
  1036. if (IS_ERR(request))
  1037. return request;
  1038. /* Setup ccws. */
  1039. request->op = TO_BLOCK;
  1040. start_block = (struct tape_34xx_block_id *) request->cpdata;
  1041. start_block->block = req->sector >> TAPEBLOCK_HSEC_S2B;
  1042. DBF_EVENT(6, "start_block = %i\n", start_block->block);
  1043. ccw = request->cpaddr;
  1044. ccw = tape_ccw_cc(ccw, MODE_SET_DB, 1, device->modeset_byte);
  1045. /*
  1046. * We always setup a nop after the mode set ccw. This slot is
  1047. * used in tape_std_check_locate to insert a locate ccw if the
  1048. * current tape position doesn't match the start block to be read.
  1049. * The second nop will be filled with a read block id which is in
  1050. * turn used by tape_34xx_free_bread to populate the segment bid
  1051. * table.
  1052. */
  1053. ccw = tape_ccw_cc(ccw, NOP, 0, NULL);
  1054. ccw = tape_ccw_cc(ccw, NOP, 0, NULL);
  1055. rq_for_each_segment(bv, req, iter) {
  1056. dst = kmap(bv->bv_page) + bv->bv_offset;
  1057. for (off = 0; off < bv->bv_len; off += TAPEBLOCK_HSEC_SIZE) {
  1058. ccw->flags = CCW_FLAG_CC;
  1059. ccw->cmd_code = READ_FORWARD;
  1060. ccw->count = TAPEBLOCK_HSEC_SIZE;
  1061. set_normalized_cda(ccw, (void*) __pa(dst));
  1062. ccw++;
  1063. dst += TAPEBLOCK_HSEC_SIZE;
  1064. }
  1065. }
  1066. ccw = tape_ccw_end(ccw, NOP, 0, NULL);
  1067. DBF_EVENT(6, "xBREDccwg\n");
  1068. return request;
  1069. }
  1070. static void
  1071. tape_34xx_free_bread (struct tape_request *request)
  1072. {
  1073. struct ccw1* ccw;
  1074. ccw = request->cpaddr;
  1075. if ((ccw + 2)->cmd_code == READ_BLOCK_ID) {
  1076. struct {
  1077. struct tape_34xx_block_id cbid;
  1078. struct tape_34xx_block_id dbid;
  1079. } __attribute__ ((packed)) *rbi_data;
  1080. rbi_data = request->cpdata;
  1081. if (request->device)
  1082. tape_34xx_add_sbid(request->device, rbi_data->cbid);
  1083. }
  1084. /* Last ccw is a nop and doesn't need clear_normalized_cda */
  1085. for (; ccw->flags & CCW_FLAG_CC; ccw++)
  1086. if (ccw->cmd_code == READ_FORWARD)
  1087. clear_normalized_cda(ccw);
  1088. tape_free_request(request);
  1089. }
  1090. /*
  1091. * check_locate is called just before the tape request is passed to
  1092. * the common io layer for execution. It has to check the current
  1093. * tape position and insert a locate ccw if it doesn't match the
  1094. * start block for the request.
  1095. */
  1096. static void
  1097. tape_34xx_check_locate(struct tape_device *device, struct tape_request *request)
  1098. {
  1099. struct tape_34xx_block_id * start_block;
  1100. start_block = (struct tape_34xx_block_id *) request->cpdata;
  1101. if (start_block->block == device->blk_data.block_position)
  1102. return;
  1103. DBF_LH(4, "Block seek(%06d+%06d)\n", start_block->block, device->bof);
  1104. start_block->wrap = 0;
  1105. start_block->segment = 1;
  1106. start_block->format = (*device->modeset_byte & 0x08) ?
  1107. TAPE34XX_FMT_3480_XF :
  1108. TAPE34XX_FMT_3480;
  1109. start_block->block = start_block->block + device->bof;
  1110. tape_34xx_merge_sbid(device, start_block);
  1111. tape_ccw_cc(request->cpaddr + 1, LOCATE, 4, request->cpdata);
  1112. tape_ccw_cc(request->cpaddr + 2, READ_BLOCK_ID, 8, request->cpdata);
  1113. }
  1114. #endif
  1115. /*
  1116. * List of 3480/3490 magnetic tape commands.
  1117. */
  1118. static tape_mtop_fn tape_34xx_mtop[TAPE_NR_MTOPS] = {
  1119. [MTRESET] = tape_std_mtreset,
  1120. [MTFSF] = tape_std_mtfsf,
  1121. [MTBSF] = tape_std_mtbsf,
  1122. [MTFSR] = tape_std_mtfsr,
  1123. [MTBSR] = tape_std_mtbsr,
  1124. [MTWEOF] = tape_std_mtweof,
  1125. [MTREW] = tape_std_mtrew,
  1126. [MTOFFL] = tape_std_mtoffl,
  1127. [MTNOP] = tape_std_mtnop,
  1128. [MTRETEN] = tape_std_mtreten,
  1129. [MTBSFM] = tape_std_mtbsfm,
  1130. [MTFSFM] = tape_std_mtfsfm,
  1131. [MTEOM] = tape_std_mteom,
  1132. [MTERASE] = tape_std_mterase,
  1133. [MTRAS1] = NULL,
  1134. [MTRAS2] = NULL,
  1135. [MTRAS3] = NULL,
  1136. [MTSETBLK] = tape_std_mtsetblk,
  1137. [MTSETDENSITY] = NULL,
  1138. [MTSEEK] = tape_34xx_mtseek,
  1139. [MTTELL] = tape_34xx_mttell,
  1140. [MTSETDRVBUFFER] = NULL,
  1141. [MTFSS] = NULL,
  1142. [MTBSS] = NULL,
  1143. [MTWSM] = NULL,
  1144. [MTLOCK] = NULL,
  1145. [MTUNLOCK] = NULL,
  1146. [MTLOAD] = tape_std_mtload,
  1147. [MTUNLOAD] = tape_std_mtunload,
  1148. [MTCOMPRESSION] = tape_std_mtcompression,
  1149. [MTSETPART] = NULL,
  1150. [MTMKPART] = NULL
  1151. };
  1152. /*
  1153. * Tape discipline structure for 3480 and 3490.
  1154. */
  1155. static struct tape_discipline tape_discipline_34xx = {
  1156. .owner = THIS_MODULE,
  1157. .setup_device = tape_34xx_setup_device,
  1158. .cleanup_device = tape_34xx_cleanup_device,
  1159. .process_eov = tape_std_process_eov,
  1160. .irq = tape_34xx_irq,
  1161. .read_block = tape_std_read_block,
  1162. .write_block = tape_std_write_block,
  1163. #ifdef CONFIG_S390_TAPE_BLOCK
  1164. .bread = tape_34xx_bread,
  1165. .free_bread = tape_34xx_free_bread,
  1166. .check_locate = tape_34xx_check_locate,
  1167. #endif
  1168. .ioctl_fn = tape_34xx_ioctl,
  1169. .mtop_array = tape_34xx_mtop
  1170. };
  1171. static struct ccw_device_id tape_34xx_ids[] = {
  1172. { CCW_DEVICE_DEVTYPE(0x3480, 0, 0x3480, 0), .driver_info = tape_3480},
  1173. { CCW_DEVICE_DEVTYPE(0x3490, 0, 0x3490, 0), .driver_info = tape_3490},
  1174. { /* end of list */ },
  1175. };
  1176. static int
  1177. tape_34xx_online(struct ccw_device *cdev)
  1178. {
  1179. return tape_generic_online(
  1180. cdev->dev.driver_data,
  1181. &tape_discipline_34xx
  1182. );
  1183. }
  1184. static int
  1185. tape_34xx_offline(struct ccw_device *cdev)
  1186. {
  1187. return tape_generic_offline(cdev->dev.driver_data);
  1188. }
  1189. static struct ccw_driver tape_34xx_driver = {
  1190. .name = "tape_34xx",
  1191. .owner = THIS_MODULE,
  1192. .ids = tape_34xx_ids,
  1193. .probe = tape_generic_probe,
  1194. .remove = tape_generic_remove,
  1195. .set_online = tape_34xx_online,
  1196. .set_offline = tape_34xx_offline,
  1197. };
  1198. static int
  1199. tape_34xx_init (void)
  1200. {
  1201. int rc;
  1202. TAPE_DBF_AREA = debug_register ( "tape_34xx", 2, 2, 4*sizeof(long));
  1203. debug_register_view(TAPE_DBF_AREA, &debug_sprintf_view);
  1204. #ifdef DBF_LIKE_HELL
  1205. debug_set_level(TAPE_DBF_AREA, 6);
  1206. #endif
  1207. DBF_EVENT(3, "34xx init\n");
  1208. /* Register driver for 3480/3490 tapes. */
  1209. rc = ccw_driver_register(&tape_34xx_driver);
  1210. if (rc)
  1211. DBF_EVENT(3, "34xx init failed\n");
  1212. else
  1213. DBF_EVENT(3, "34xx registered\n");
  1214. return rc;
  1215. }
  1216. static void
  1217. tape_34xx_exit(void)
  1218. {
  1219. ccw_driver_unregister(&tape_34xx_driver);
  1220. debug_unregister(TAPE_DBF_AREA);
  1221. }
  1222. MODULE_DEVICE_TABLE(ccw, tape_34xx_ids);
  1223. MODULE_AUTHOR("(C) 2001-2002 IBM Deutschland Entwicklung GmbH");
  1224. MODULE_DESCRIPTION("Linux on zSeries channel attached 3480 tape device driver");
  1225. MODULE_LICENSE("GPL");
  1226. module_init(tape_34xx_init);
  1227. module_exit(tape_34xx_exit);