tape_34xx.c 38 KB

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