tape_34xx.c 37 KB

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