tape_34xx.c 37 KB

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