tape_34xx.c 38 KB

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