tape_34xx.c 38 KB

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