tape_34xx.c 38 KB

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