tape_34xx.c 38 KB

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