tape_34xx.c 38 KB

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