tape_core.c 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302
  1. /*
  2. * drivers/s390/char/tape_core.c
  3. * basic function of the tape device driver
  4. *
  5. * S390 and zSeries version
  6. * Copyright (C) 2001,2005 IBM Deutschland Entwicklung GmbH, IBM Corporation
  7. * Author(s): Carsten Otte <cotte@de.ibm.com>
  8. * Michael Holzheu <holzheu@de.ibm.com>
  9. * Tuan Ngo-Anh <ngoanh@de.ibm.com>
  10. * Martin Schwidefsky <schwidefsky@de.ibm.com>
  11. * Stefan Bader <shbader@de.ibm.com>
  12. */
  13. #include <linux/config.h>
  14. #include <linux/module.h>
  15. #include <linux/init.h> // for kernel parameters
  16. #include <linux/kmod.h> // for requesting modules
  17. #include <linux/spinlock.h> // for locks
  18. #include <linux/vmalloc.h>
  19. #include <linux/list.h>
  20. #include <asm/types.h> // for variable types
  21. #define TAPE_DBF_AREA tape_core_dbf
  22. #include "tape.h"
  23. #include "tape_std.h"
  24. #define PRINTK_HEADER "TAPE_CORE: "
  25. static void __tape_do_irq (struct ccw_device *, unsigned long, struct irb *);
  26. static void tape_delayed_next_request(void * data);
  27. /*
  28. * One list to contain all tape devices of all disciplines, so
  29. * we can assign the devices to minor numbers of the same major
  30. * The list is protected by the rwlock
  31. */
  32. static struct list_head tape_device_list = LIST_HEAD_INIT(tape_device_list);
  33. static DEFINE_RWLOCK(tape_device_lock);
  34. /*
  35. * Pointer to debug area.
  36. */
  37. debug_info_t *TAPE_DBF_AREA = NULL;
  38. EXPORT_SYMBOL(TAPE_DBF_AREA);
  39. /*
  40. * Printable strings for tape enumerations.
  41. */
  42. const char *tape_state_verbose[TS_SIZE] =
  43. {
  44. [TS_UNUSED] = "UNUSED",
  45. [TS_IN_USE] = "IN_USE",
  46. [TS_BLKUSE] = "BLKUSE",
  47. [TS_INIT] = "INIT ",
  48. [TS_NOT_OPER] = "NOT_OP"
  49. };
  50. const char *tape_op_verbose[TO_SIZE] =
  51. {
  52. [TO_BLOCK] = "BLK", [TO_BSB] = "BSB",
  53. [TO_BSF] = "BSF", [TO_DSE] = "DSE",
  54. [TO_FSB] = "FSB", [TO_FSF] = "FSF",
  55. [TO_LBL] = "LBL", [TO_NOP] = "NOP",
  56. [TO_RBA] = "RBA", [TO_RBI] = "RBI",
  57. [TO_RFO] = "RFO", [TO_REW] = "REW",
  58. [TO_RUN] = "RUN", [TO_WRI] = "WRI",
  59. [TO_WTM] = "WTM", [TO_MSEN] = "MSN",
  60. [TO_LOAD] = "LOA", [TO_READ_CONFIG] = "RCF",
  61. [TO_READ_ATTMSG] = "RAT",
  62. [TO_DIS] = "DIS", [TO_ASSIGN] = "ASS",
  63. [TO_UNASSIGN] = "UAS"
  64. };
  65. static inline int
  66. busid_to_int(char *bus_id)
  67. {
  68. int dec;
  69. int d;
  70. char * s;
  71. for(s = bus_id, d = 0; *s != '\0' && *s != '.'; s++)
  72. d = (d * 10) + (*s - '0');
  73. dec = d;
  74. for(s++, d = 0; *s != '\0' && *s != '.'; s++)
  75. d = (d * 10) + (*s - '0');
  76. dec = (dec << 8) + d;
  77. for(s++; *s != '\0'; s++) {
  78. if (*s >= '0' && *s <= '9') {
  79. d = *s - '0';
  80. } else if (*s >= 'a' && *s <= 'f') {
  81. d = *s - 'a' + 10;
  82. } else {
  83. d = *s - 'A' + 10;
  84. }
  85. dec = (dec << 4) + d;
  86. }
  87. return dec;
  88. }
  89. /*
  90. * Some channel attached tape specific attributes.
  91. *
  92. * FIXME: In the future the first_minor and blocksize attribute should be
  93. * replaced by a link to the cdev tree.
  94. */
  95. static ssize_t
  96. tape_medium_state_show(struct device *dev, struct device_attribute *attr, char *buf)
  97. {
  98. struct tape_device *tdev;
  99. tdev = (struct tape_device *) dev->driver_data;
  100. return scnprintf(buf, PAGE_SIZE, "%i\n", tdev->medium_state);
  101. }
  102. static
  103. DEVICE_ATTR(medium_state, 0444, tape_medium_state_show, NULL);
  104. static ssize_t
  105. tape_first_minor_show(struct device *dev, struct device_attribute *attr, char *buf)
  106. {
  107. struct tape_device *tdev;
  108. tdev = (struct tape_device *) dev->driver_data;
  109. return scnprintf(buf, PAGE_SIZE, "%i\n", tdev->first_minor);
  110. }
  111. static
  112. DEVICE_ATTR(first_minor, 0444, tape_first_minor_show, NULL);
  113. static ssize_t
  114. tape_state_show(struct device *dev, struct device_attribute *attr, char *buf)
  115. {
  116. struct tape_device *tdev;
  117. tdev = (struct tape_device *) dev->driver_data;
  118. return scnprintf(buf, PAGE_SIZE, "%s\n", (tdev->first_minor < 0) ?
  119. "OFFLINE" : tape_state_verbose[tdev->tape_state]);
  120. }
  121. static
  122. DEVICE_ATTR(state, 0444, tape_state_show, NULL);
  123. static ssize_t
  124. tape_operation_show(struct device *dev, struct device_attribute *attr, char *buf)
  125. {
  126. struct tape_device *tdev;
  127. ssize_t rc;
  128. tdev = (struct tape_device *) dev->driver_data;
  129. if (tdev->first_minor < 0)
  130. return scnprintf(buf, PAGE_SIZE, "N/A\n");
  131. spin_lock_irq(get_ccwdev_lock(tdev->cdev));
  132. if (list_empty(&tdev->req_queue))
  133. rc = scnprintf(buf, PAGE_SIZE, "---\n");
  134. else {
  135. struct tape_request *req;
  136. req = list_entry(tdev->req_queue.next, struct tape_request,
  137. list);
  138. rc = scnprintf(buf,PAGE_SIZE, "%s\n", tape_op_verbose[req->op]);
  139. }
  140. spin_unlock_irq(get_ccwdev_lock(tdev->cdev));
  141. return rc;
  142. }
  143. static
  144. DEVICE_ATTR(operation, 0444, tape_operation_show, NULL);
  145. static ssize_t
  146. tape_blocksize_show(struct device *dev, struct device_attribute *attr, char *buf)
  147. {
  148. struct tape_device *tdev;
  149. tdev = (struct tape_device *) dev->driver_data;
  150. return scnprintf(buf, PAGE_SIZE, "%i\n", tdev->char_data.block_size);
  151. }
  152. static
  153. DEVICE_ATTR(blocksize, 0444, tape_blocksize_show, NULL);
  154. static struct attribute *tape_attrs[] = {
  155. &dev_attr_medium_state.attr,
  156. &dev_attr_first_minor.attr,
  157. &dev_attr_state.attr,
  158. &dev_attr_operation.attr,
  159. &dev_attr_blocksize.attr,
  160. NULL
  161. };
  162. static struct attribute_group tape_attr_group = {
  163. .attrs = tape_attrs,
  164. };
  165. /*
  166. * Tape state functions
  167. */
  168. void
  169. tape_state_set(struct tape_device *device, enum tape_state newstate)
  170. {
  171. const char *str;
  172. if (device->tape_state == TS_NOT_OPER) {
  173. DBF_EVENT(3, "ts_set err: not oper\n");
  174. return;
  175. }
  176. DBF_EVENT(4, "ts. dev: %x\n", device->first_minor);
  177. DBF_EVENT(4, "old ts:\t\n");
  178. if (device->tape_state < TS_SIZE && device->tape_state >=0 )
  179. str = tape_state_verbose[device->tape_state];
  180. else
  181. str = "UNKNOWN TS";
  182. DBF_EVENT(4, "%s\n", str);
  183. DBF_EVENT(4, "new ts:\t\n");
  184. if (newstate < TS_SIZE && newstate >= 0)
  185. str = tape_state_verbose[newstate];
  186. else
  187. str = "UNKNOWN TS";
  188. DBF_EVENT(4, "%s\n", str);
  189. device->tape_state = newstate;
  190. wake_up(&device->state_change_wq);
  191. }
  192. void
  193. tape_med_state_set(struct tape_device *device, enum tape_medium_state newstate)
  194. {
  195. if (device->medium_state == newstate)
  196. return;
  197. switch(newstate){
  198. case MS_UNLOADED:
  199. device->tape_generic_status |= GMT_DR_OPEN(~0);
  200. PRINT_INFO("(%s): Tape is unloaded\n",
  201. device->cdev->dev.bus_id);
  202. break;
  203. case MS_LOADED:
  204. device->tape_generic_status &= ~GMT_DR_OPEN(~0);
  205. PRINT_INFO("(%s): Tape has been mounted\n",
  206. device->cdev->dev.bus_id);
  207. break;
  208. default:
  209. // print nothing
  210. break;
  211. }
  212. device->medium_state = newstate;
  213. wake_up(&device->state_change_wq);
  214. }
  215. /*
  216. * Stop running ccw. Has to be called with the device lock held.
  217. */
  218. static inline int
  219. __tape_cancel_io(struct tape_device *device, struct tape_request *request)
  220. {
  221. int retries;
  222. int rc;
  223. /* Check if interrupt has already been processed */
  224. if (request->callback == NULL)
  225. return 0;
  226. rc = 0;
  227. for (retries = 0; retries < 5; retries++) {
  228. rc = ccw_device_clear(device->cdev, (long) request);
  229. switch (rc) {
  230. case 0:
  231. request->status = TAPE_REQUEST_DONE;
  232. return 0;
  233. case -EBUSY:
  234. request->status = TAPE_REQUEST_CANCEL;
  235. schedule_work(&device->tape_dnr);
  236. return 0;
  237. case -ENODEV:
  238. DBF_EXCEPTION(2, "device gone, retry\n");
  239. break;
  240. case -EIO:
  241. DBF_EXCEPTION(2, "I/O error, retry\n");
  242. break;
  243. default:
  244. BUG();
  245. }
  246. }
  247. return rc;
  248. }
  249. /*
  250. * Add device into the sorted list, giving it the first
  251. * available minor number.
  252. */
  253. static int
  254. tape_assign_minor(struct tape_device *device)
  255. {
  256. struct tape_device *tmp;
  257. int minor;
  258. minor = 0;
  259. write_lock(&tape_device_lock);
  260. list_for_each_entry(tmp, &tape_device_list, node) {
  261. if (minor < tmp->first_minor)
  262. break;
  263. minor += TAPE_MINORS_PER_DEV;
  264. }
  265. if (minor >= 256) {
  266. write_unlock(&tape_device_lock);
  267. return -ENODEV;
  268. }
  269. device->first_minor = minor;
  270. list_add_tail(&device->node, &tmp->node);
  271. write_unlock(&tape_device_lock);
  272. return 0;
  273. }
  274. /* remove device from the list */
  275. static void
  276. tape_remove_minor(struct tape_device *device)
  277. {
  278. write_lock(&tape_device_lock);
  279. list_del_init(&device->node);
  280. device->first_minor = -1;
  281. write_unlock(&tape_device_lock);
  282. }
  283. /*
  284. * Set a device online.
  285. *
  286. * This function is called by the common I/O layer to move a device from the
  287. * detected but offline into the online state.
  288. * If we return an error (RC < 0) the device remains in the offline state. This
  289. * can happen if the device is assigned somewhere else, for example.
  290. */
  291. int
  292. tape_generic_online(struct tape_device *device,
  293. struct tape_discipline *discipline)
  294. {
  295. int rc;
  296. DBF_LH(6, "tape_enable_device(%p, %p)\n", device, discipline);
  297. if (device->tape_state != TS_INIT) {
  298. DBF_LH(3, "Tapestate not INIT (%d)\n", device->tape_state);
  299. return -EINVAL;
  300. }
  301. /* Let the discipline have a go at the device. */
  302. device->discipline = discipline;
  303. if (!try_module_get(discipline->owner)) {
  304. PRINT_ERR("Cannot get module. Module gone.\n");
  305. return -EINVAL;
  306. }
  307. rc = discipline->setup_device(device);
  308. if (rc)
  309. goto out;
  310. rc = tape_assign_minor(device);
  311. if (rc)
  312. goto out_discipline;
  313. rc = tapechar_setup_device(device);
  314. if (rc)
  315. goto out_minor;
  316. rc = tapeblock_setup_device(device);
  317. if (rc)
  318. goto out_char;
  319. tape_state_set(device, TS_UNUSED);
  320. DBF_LH(3, "(%08x): Drive set online\n", device->cdev_id);
  321. return 0;
  322. out_char:
  323. tapechar_cleanup_device(device);
  324. out_discipline:
  325. device->discipline->cleanup_device(device);
  326. device->discipline = NULL;
  327. out_minor:
  328. tape_remove_minor(device);
  329. out:
  330. module_put(discipline->owner);
  331. return rc;
  332. }
  333. static inline void
  334. tape_cleanup_device(struct tape_device *device)
  335. {
  336. tapeblock_cleanup_device(device);
  337. tapechar_cleanup_device(device);
  338. device->discipline->cleanup_device(device);
  339. module_put(device->discipline->owner);
  340. tape_remove_minor(device);
  341. tape_med_state_set(device, MS_UNKNOWN);
  342. }
  343. /*
  344. * Set device offline.
  345. *
  346. * Called by the common I/O layer if the drive should set offline on user
  347. * request. We may prevent this by returning an error.
  348. * Manual offline is only allowed while the drive is not in use.
  349. */
  350. int
  351. tape_generic_offline(struct tape_device *device)
  352. {
  353. if (!device) {
  354. PRINT_ERR("tape_generic_offline: no such device\n");
  355. return -ENODEV;
  356. }
  357. DBF_LH(3, "(%08x): tape_generic_offline(%p)\n",
  358. device->cdev_id, device);
  359. spin_lock_irq(get_ccwdev_lock(device->cdev));
  360. switch (device->tape_state) {
  361. case TS_INIT:
  362. case TS_NOT_OPER:
  363. spin_unlock_irq(get_ccwdev_lock(device->cdev));
  364. break;
  365. case TS_UNUSED:
  366. tape_state_set(device, TS_INIT);
  367. spin_unlock_irq(get_ccwdev_lock(device->cdev));
  368. tape_cleanup_device(device);
  369. break;
  370. default:
  371. DBF_EVENT(3, "(%08x): Set offline failed "
  372. "- drive in use.\n",
  373. device->cdev_id);
  374. PRINT_WARN("(%s): Set offline failed "
  375. "- drive in use.\n",
  376. device->cdev->dev.bus_id);
  377. spin_unlock_irq(get_ccwdev_lock(device->cdev));
  378. return -EBUSY;
  379. }
  380. DBF_LH(3, "(%08x): Drive set offline.\n", device->cdev_id);
  381. return 0;
  382. }
  383. /*
  384. * Allocate memory for a new device structure.
  385. */
  386. static struct tape_device *
  387. tape_alloc_device(void)
  388. {
  389. struct tape_device *device;
  390. device = kzalloc(sizeof(struct tape_device), GFP_KERNEL);
  391. if (device == NULL) {
  392. DBF_EXCEPTION(2, "ti:no mem\n");
  393. PRINT_INFO ("can't allocate memory for "
  394. "tape info structure\n");
  395. return ERR_PTR(-ENOMEM);
  396. }
  397. device->modeset_byte = kmalloc(1, GFP_KERNEL | GFP_DMA);
  398. if (device->modeset_byte == NULL) {
  399. DBF_EXCEPTION(2, "ti:no mem\n");
  400. PRINT_INFO("can't allocate memory for modeset byte\n");
  401. kfree(device);
  402. return ERR_PTR(-ENOMEM);
  403. }
  404. INIT_LIST_HEAD(&device->req_queue);
  405. INIT_LIST_HEAD(&device->node);
  406. init_waitqueue_head(&device->state_change_wq);
  407. device->tape_state = TS_INIT;
  408. device->medium_state = MS_UNKNOWN;
  409. *device->modeset_byte = 0;
  410. device->first_minor = -1;
  411. atomic_set(&device->ref_count, 1);
  412. INIT_WORK(&device->tape_dnr, tape_delayed_next_request, device);
  413. return device;
  414. }
  415. /*
  416. * Get a reference to an existing device structure. This will automatically
  417. * increment the reference count.
  418. */
  419. struct tape_device *
  420. tape_get_device_reference(struct tape_device *device)
  421. {
  422. DBF_EVENT(4, "tape_get_device_reference(%p) = %i\n", device,
  423. atomic_inc_return(&device->ref_count));
  424. return device;
  425. }
  426. /*
  427. * Decrease the reference counter of a devices structure. If the
  428. * reference counter reaches zero free the device structure.
  429. * The function returns a NULL pointer to be used by the caller
  430. * for clearing reference pointers.
  431. */
  432. struct tape_device *
  433. tape_put_device(struct tape_device *device)
  434. {
  435. int remain;
  436. remain = atomic_dec_return(&device->ref_count);
  437. if (remain > 0) {
  438. DBF_EVENT(4, "tape_put_device(%p) -> %i\n", device, remain);
  439. } else {
  440. if (remain < 0) {
  441. DBF_EVENT(4, "put device without reference\n");
  442. PRINT_ERR("put device without reference\n");
  443. } else {
  444. DBF_EVENT(4, "tape_free_device(%p)\n", device);
  445. kfree(device->modeset_byte);
  446. kfree(device);
  447. }
  448. }
  449. return NULL;
  450. }
  451. /*
  452. * Find tape device by a device index.
  453. */
  454. struct tape_device *
  455. tape_get_device(int devindex)
  456. {
  457. struct tape_device *device, *tmp;
  458. device = ERR_PTR(-ENODEV);
  459. read_lock(&tape_device_lock);
  460. list_for_each_entry(tmp, &tape_device_list, node) {
  461. if (tmp->first_minor / TAPE_MINORS_PER_DEV == devindex) {
  462. device = tape_get_device_reference(tmp);
  463. break;
  464. }
  465. }
  466. read_unlock(&tape_device_lock);
  467. return device;
  468. }
  469. /*
  470. * Driverfs tape probe function.
  471. */
  472. int
  473. tape_generic_probe(struct ccw_device *cdev)
  474. {
  475. struct tape_device *device;
  476. device = tape_alloc_device();
  477. if (IS_ERR(device))
  478. return -ENODEV;
  479. PRINT_INFO("tape device %s found\n", cdev->dev.bus_id);
  480. cdev->dev.driver_data = device;
  481. device->cdev = cdev;
  482. device->cdev_id = busid_to_int(cdev->dev.bus_id);
  483. cdev->handler = __tape_do_irq;
  484. ccw_device_set_options(cdev, CCWDEV_DO_PATHGROUP);
  485. sysfs_create_group(&cdev->dev.kobj, &tape_attr_group);
  486. return 0;
  487. }
  488. static inline void
  489. __tape_discard_requests(struct tape_device *device)
  490. {
  491. struct tape_request * request;
  492. struct list_head * l, *n;
  493. list_for_each_safe(l, n, &device->req_queue) {
  494. request = list_entry(l, struct tape_request, list);
  495. if (request->status == TAPE_REQUEST_IN_IO)
  496. request->status = TAPE_REQUEST_DONE;
  497. list_del(&request->list);
  498. /* Decrease ref_count for removed request. */
  499. request->device = tape_put_device(device);
  500. request->rc = -EIO;
  501. if (request->callback != NULL)
  502. request->callback(request, request->callback_data);
  503. }
  504. }
  505. /*
  506. * Driverfs tape remove function.
  507. *
  508. * This function is called whenever the common I/O layer detects the device
  509. * gone. This can happen at any time and we cannot refuse.
  510. */
  511. void
  512. tape_generic_remove(struct ccw_device *cdev)
  513. {
  514. struct tape_device * device;
  515. device = cdev->dev.driver_data;
  516. if (!device) {
  517. PRINT_ERR("No device pointer in tape_generic_remove!\n");
  518. return;
  519. }
  520. DBF_LH(3, "(%08x): tape_generic_remove(%p)\n", device->cdev_id, cdev);
  521. spin_lock_irq(get_ccwdev_lock(device->cdev));
  522. switch (device->tape_state) {
  523. case TS_INIT:
  524. tape_state_set(device, TS_NOT_OPER);
  525. case TS_NOT_OPER:
  526. /*
  527. * Nothing to do.
  528. */
  529. spin_unlock_irq(get_ccwdev_lock(device->cdev));
  530. break;
  531. case TS_UNUSED:
  532. /*
  533. * Need only to release the device.
  534. */
  535. tape_state_set(device, TS_NOT_OPER);
  536. spin_unlock_irq(get_ccwdev_lock(device->cdev));
  537. tape_cleanup_device(device);
  538. break;
  539. default:
  540. /*
  541. * There may be requests on the queue. We will not get
  542. * an interrupt for a request that was running. So we
  543. * just post them all as I/O errors.
  544. */
  545. DBF_EVENT(3, "(%08x): Drive in use vanished!\n",
  546. device->cdev_id);
  547. PRINT_WARN("(%s): Drive in use vanished - "
  548. "expect trouble!\n",
  549. device->cdev->dev.bus_id);
  550. PRINT_WARN("State was %i\n", device->tape_state);
  551. tape_state_set(device, TS_NOT_OPER);
  552. __tape_discard_requests(device);
  553. spin_unlock_irq(get_ccwdev_lock(device->cdev));
  554. tape_cleanup_device(device);
  555. }
  556. if (cdev->dev.driver_data != NULL) {
  557. sysfs_remove_group(&cdev->dev.kobj, &tape_attr_group);
  558. cdev->dev.driver_data = tape_put_device(cdev->dev.driver_data);
  559. }
  560. }
  561. /*
  562. * Allocate a new tape ccw request
  563. */
  564. struct tape_request *
  565. tape_alloc_request(int cplength, int datasize)
  566. {
  567. struct tape_request *request;
  568. if (datasize > PAGE_SIZE || (cplength*sizeof(struct ccw1)) > PAGE_SIZE)
  569. BUG();
  570. DBF_LH(6, "tape_alloc_request(%d, %d)\n", cplength, datasize);
  571. request = kzalloc(sizeof(struct tape_request), GFP_KERNEL);
  572. if (request == NULL) {
  573. DBF_EXCEPTION(1, "cqra nomem\n");
  574. return ERR_PTR(-ENOMEM);
  575. }
  576. /* allocate channel program */
  577. if (cplength > 0) {
  578. request->cpaddr = kcalloc(cplength, sizeof(struct ccw1),
  579. GFP_ATOMIC | GFP_DMA);
  580. if (request->cpaddr == NULL) {
  581. DBF_EXCEPTION(1, "cqra nomem\n");
  582. kfree(request);
  583. return ERR_PTR(-ENOMEM);
  584. }
  585. }
  586. /* alloc small kernel buffer */
  587. if (datasize > 0) {
  588. request->cpdata = kzalloc(datasize, GFP_KERNEL | GFP_DMA);
  589. if (request->cpdata == NULL) {
  590. DBF_EXCEPTION(1, "cqra nomem\n");
  591. kfree(request->cpaddr);
  592. kfree(request);
  593. return ERR_PTR(-ENOMEM);
  594. }
  595. }
  596. DBF_LH(6, "New request %p(%p/%p)\n", request, request->cpaddr,
  597. request->cpdata);
  598. return request;
  599. }
  600. /*
  601. * Free tape ccw request
  602. */
  603. void
  604. tape_free_request (struct tape_request * request)
  605. {
  606. DBF_LH(6, "Free request %p\n", request);
  607. if (request->device != NULL) {
  608. request->device = tape_put_device(request->device);
  609. }
  610. kfree(request->cpdata);
  611. kfree(request->cpaddr);
  612. kfree(request);
  613. }
  614. static inline int
  615. __tape_start_io(struct tape_device *device, struct tape_request *request)
  616. {
  617. int rc;
  618. #ifdef CONFIG_S390_TAPE_BLOCK
  619. if (request->op == TO_BLOCK)
  620. device->discipline->check_locate(device, request);
  621. #endif
  622. rc = ccw_device_start(
  623. device->cdev,
  624. request->cpaddr,
  625. (unsigned long) request,
  626. 0x00,
  627. request->options
  628. );
  629. if (rc == 0) {
  630. request->status = TAPE_REQUEST_IN_IO;
  631. } else if (rc == -EBUSY) {
  632. /* The common I/O subsystem is currently busy. Retry later. */
  633. request->status = TAPE_REQUEST_QUEUED;
  634. schedule_work(&device->tape_dnr);
  635. rc = 0;
  636. } else {
  637. /* Start failed. Remove request and indicate failure. */
  638. DBF_EVENT(1, "tape: start request failed with RC = %i\n", rc);
  639. }
  640. return rc;
  641. }
  642. static inline void
  643. __tape_start_next_request(struct tape_device *device)
  644. {
  645. struct list_head *l, *n;
  646. struct tape_request *request;
  647. int rc;
  648. DBF_LH(6, "__tape_start_next_request(%p)\n", device);
  649. /*
  650. * Try to start each request on request queue until one is
  651. * started successful.
  652. */
  653. list_for_each_safe(l, n, &device->req_queue) {
  654. request = list_entry(l, struct tape_request, list);
  655. /*
  656. * Avoid race condition if bottom-half was triggered more than
  657. * once.
  658. */
  659. if (request->status == TAPE_REQUEST_IN_IO)
  660. return;
  661. /*
  662. * Request has already been stopped. We have to wait until
  663. * the request is removed from the queue in the interrupt
  664. * handling.
  665. */
  666. if (request->status == TAPE_REQUEST_DONE)
  667. return;
  668. /*
  669. * We wanted to cancel the request but the common I/O layer
  670. * was busy at that time. This can only happen if this
  671. * function is called by delayed_next_request.
  672. * Otherwise we start the next request on the queue.
  673. */
  674. if (request->status == TAPE_REQUEST_CANCEL) {
  675. rc = __tape_cancel_io(device, request);
  676. } else {
  677. rc = __tape_start_io(device, request);
  678. }
  679. if (rc == 0)
  680. return;
  681. /* Set ending status. */
  682. request->rc = rc;
  683. request->status = TAPE_REQUEST_DONE;
  684. /* Remove from request queue. */
  685. list_del(&request->list);
  686. /* Do callback. */
  687. if (request->callback != NULL)
  688. request->callback(request, request->callback_data);
  689. }
  690. }
  691. static void
  692. tape_delayed_next_request(void *data)
  693. {
  694. struct tape_device * device;
  695. device = (struct tape_device *) data;
  696. DBF_LH(6, "tape_delayed_next_request(%p)\n", device);
  697. spin_lock_irq(get_ccwdev_lock(device->cdev));
  698. __tape_start_next_request(device);
  699. spin_unlock_irq(get_ccwdev_lock(device->cdev));
  700. }
  701. static inline void
  702. __tape_end_request(
  703. struct tape_device * device,
  704. struct tape_request * request,
  705. int rc)
  706. {
  707. DBF_LH(6, "__tape_end_request(%p, %p, %i)\n", device, request, rc);
  708. if (request) {
  709. request->rc = rc;
  710. request->status = TAPE_REQUEST_DONE;
  711. /* Remove from request queue. */
  712. list_del(&request->list);
  713. /* Do callback. */
  714. if (request->callback != NULL)
  715. request->callback(request, request->callback_data);
  716. }
  717. /* Start next request. */
  718. if (!list_empty(&device->req_queue))
  719. __tape_start_next_request(device);
  720. }
  721. /*
  722. * Write sense data to console/dbf
  723. */
  724. void
  725. tape_dump_sense(struct tape_device* device, struct tape_request *request,
  726. struct irb *irb)
  727. {
  728. unsigned int *sptr;
  729. PRINT_INFO("-------------------------------------------------\n");
  730. PRINT_INFO("DSTAT : %02x CSTAT: %02x CPA: %04x\n",
  731. irb->scsw.dstat, irb->scsw.cstat, irb->scsw.cpa);
  732. PRINT_INFO("DEVICE: %s\n", device->cdev->dev.bus_id);
  733. if (request != NULL)
  734. PRINT_INFO("OP : %s\n", tape_op_verbose[request->op]);
  735. sptr = (unsigned int *) irb->ecw;
  736. PRINT_INFO("Sense data: %08X %08X %08X %08X \n",
  737. sptr[0], sptr[1], sptr[2], sptr[3]);
  738. PRINT_INFO("Sense data: %08X %08X %08X %08X \n",
  739. sptr[4], sptr[5], sptr[6], sptr[7]);
  740. PRINT_INFO("--------------------------------------------------\n");
  741. }
  742. /*
  743. * Write sense data to dbf
  744. */
  745. void
  746. tape_dump_sense_dbf(struct tape_device *device, struct tape_request *request,
  747. struct irb *irb)
  748. {
  749. unsigned int *sptr;
  750. const char* op;
  751. if (request != NULL)
  752. op = tape_op_verbose[request->op];
  753. else
  754. op = "---";
  755. DBF_EVENT(3, "DSTAT : %02x CSTAT: %02x\n",
  756. irb->scsw.dstat,irb->scsw.cstat);
  757. DBF_EVENT(3, "DEVICE: %08x OP\t: %s\n", device->cdev_id, op);
  758. sptr = (unsigned int *) irb->ecw;
  759. DBF_EVENT(3, "%08x %08x\n", sptr[0], sptr[1]);
  760. DBF_EVENT(3, "%08x %08x\n", sptr[2], sptr[3]);
  761. DBF_EVENT(3, "%08x %08x\n", sptr[4], sptr[5]);
  762. DBF_EVENT(3, "%08x %08x\n", sptr[6], sptr[7]);
  763. }
  764. /*
  765. * I/O helper function. Adds the request to the request queue
  766. * and starts it if the tape is idle. Has to be called with
  767. * the device lock held.
  768. */
  769. static inline int
  770. __tape_start_request(struct tape_device *device, struct tape_request *request)
  771. {
  772. int rc;
  773. switch (request->op) {
  774. case TO_MSEN:
  775. case TO_ASSIGN:
  776. case TO_UNASSIGN:
  777. case TO_READ_ATTMSG:
  778. if (device->tape_state == TS_INIT)
  779. break;
  780. if (device->tape_state == TS_UNUSED)
  781. break;
  782. default:
  783. if (device->tape_state == TS_BLKUSE)
  784. break;
  785. if (device->tape_state != TS_IN_USE)
  786. return -ENODEV;
  787. }
  788. /* Increase use count of device for the added request. */
  789. request->device = tape_get_device_reference(device);
  790. if (list_empty(&device->req_queue)) {
  791. /* No other requests are on the queue. Start this one. */
  792. rc = __tape_start_io(device, request);
  793. if (rc)
  794. return rc;
  795. DBF_LH(5, "Request %p added for execution.\n", request);
  796. list_add(&request->list, &device->req_queue);
  797. } else {
  798. DBF_LH(5, "Request %p add to queue.\n", request);
  799. request->status = TAPE_REQUEST_QUEUED;
  800. list_add_tail(&request->list, &device->req_queue);
  801. }
  802. return 0;
  803. }
  804. /*
  805. * Add the request to the request queue, try to start it if the
  806. * tape is idle. Return without waiting for end of i/o.
  807. */
  808. int
  809. tape_do_io_async(struct tape_device *device, struct tape_request *request)
  810. {
  811. int rc;
  812. DBF_LH(6, "tape_do_io_async(%p, %p)\n", device, request);
  813. spin_lock_irq(get_ccwdev_lock(device->cdev));
  814. /* Add request to request queue and try to start it. */
  815. rc = __tape_start_request(device, request);
  816. spin_unlock_irq(get_ccwdev_lock(device->cdev));
  817. return rc;
  818. }
  819. /*
  820. * tape_do_io/__tape_wake_up
  821. * Add the request to the request queue, try to start it if the
  822. * tape is idle and wait uninterruptible for its completion.
  823. */
  824. static void
  825. __tape_wake_up(struct tape_request *request, void *data)
  826. {
  827. request->callback = NULL;
  828. wake_up((wait_queue_head_t *) data);
  829. }
  830. int
  831. tape_do_io(struct tape_device *device, struct tape_request *request)
  832. {
  833. wait_queue_head_t wq;
  834. int rc;
  835. init_waitqueue_head(&wq);
  836. spin_lock_irq(get_ccwdev_lock(device->cdev));
  837. /* Setup callback */
  838. request->callback = __tape_wake_up;
  839. request->callback_data = &wq;
  840. /* Add request to request queue and try to start it. */
  841. rc = __tape_start_request(device, request);
  842. spin_unlock_irq(get_ccwdev_lock(device->cdev));
  843. if (rc)
  844. return rc;
  845. /* Request added to the queue. Wait for its completion. */
  846. wait_event(wq, (request->callback == NULL));
  847. /* Get rc from request */
  848. return request->rc;
  849. }
  850. /*
  851. * tape_do_io_interruptible/__tape_wake_up_interruptible
  852. * Add the request to the request queue, try to start it if the
  853. * tape is idle and wait uninterruptible for its completion.
  854. */
  855. static void
  856. __tape_wake_up_interruptible(struct tape_request *request, void *data)
  857. {
  858. request->callback = NULL;
  859. wake_up_interruptible((wait_queue_head_t *) data);
  860. }
  861. int
  862. tape_do_io_interruptible(struct tape_device *device,
  863. struct tape_request *request)
  864. {
  865. wait_queue_head_t wq;
  866. int rc;
  867. init_waitqueue_head(&wq);
  868. spin_lock_irq(get_ccwdev_lock(device->cdev));
  869. /* Setup callback */
  870. request->callback = __tape_wake_up_interruptible;
  871. request->callback_data = &wq;
  872. rc = __tape_start_request(device, request);
  873. spin_unlock_irq(get_ccwdev_lock(device->cdev));
  874. if (rc)
  875. return rc;
  876. /* Request added to the queue. Wait for its completion. */
  877. rc = wait_event_interruptible(wq, (request->callback == NULL));
  878. if (rc != -ERESTARTSYS)
  879. /* Request finished normally. */
  880. return request->rc;
  881. /* Interrupted by a signal. We have to stop the current request. */
  882. spin_lock_irq(get_ccwdev_lock(device->cdev));
  883. rc = __tape_cancel_io(device, request);
  884. spin_unlock_irq(get_ccwdev_lock(device->cdev));
  885. if (rc == 0) {
  886. /* Wait for the interrupt that acknowledges the halt. */
  887. do {
  888. rc = wait_event_interruptible(
  889. wq,
  890. (request->callback == NULL)
  891. );
  892. } while (rc == -ERESTARTSYS);
  893. DBF_EVENT(3, "IO stopped on %08x\n", device->cdev_id);
  894. rc = -ERESTARTSYS;
  895. }
  896. return rc;
  897. }
  898. /*
  899. * Stop running ccw.
  900. */
  901. int
  902. tape_cancel_io(struct tape_device *device, struct tape_request *request)
  903. {
  904. int rc;
  905. spin_lock_irq(get_ccwdev_lock(device->cdev));
  906. rc = __tape_cancel_io(device, request);
  907. spin_unlock_irq(get_ccwdev_lock(device->cdev));
  908. return rc;
  909. }
  910. /*
  911. * Tape interrupt routine, called from the ccw_device layer
  912. */
  913. static void
  914. __tape_do_irq (struct ccw_device *cdev, unsigned long intparm, struct irb *irb)
  915. {
  916. struct tape_device *device;
  917. struct tape_request *request;
  918. int rc;
  919. device = (struct tape_device *) cdev->dev.driver_data;
  920. if (device == NULL) {
  921. PRINT_ERR("could not get device structure for %s "
  922. "in interrupt\n", cdev->dev.bus_id);
  923. return;
  924. }
  925. request = (struct tape_request *) intparm;
  926. DBF_LH(6, "__tape_do_irq(device=%p, request=%p)\n", device, request);
  927. /* On special conditions irb is an error pointer */
  928. if (IS_ERR(irb)) {
  929. /* FIXME: What to do with the request? */
  930. switch (PTR_ERR(irb)) {
  931. case -ETIMEDOUT:
  932. PRINT_WARN("(%s): Request timed out\n",
  933. cdev->dev.bus_id);
  934. case -EIO:
  935. __tape_end_request(device, request, -EIO);
  936. break;
  937. default:
  938. PRINT_ERR("(%s): Unexpected i/o error %li\n",
  939. cdev->dev.bus_id,
  940. PTR_ERR(irb));
  941. }
  942. return;
  943. }
  944. /*
  945. * If the condition code is not zero and the start function bit is
  946. * still set, this is an deferred error and the last start I/O did
  947. * not succeed. At this point the condition that caused the deferred
  948. * error might still apply. So we just schedule the request to be
  949. * started later.
  950. */
  951. if (irb->scsw.cc != 0 && (irb->scsw.fctl & SCSW_FCTL_START_FUNC) &&
  952. (request->status == TAPE_REQUEST_IN_IO)) {
  953. DBF_EVENT(3,"(%08x): deferred cc=%i, fctl=%i. restarting\n",
  954. device->cdev_id, irb->scsw.cc, irb->scsw.fctl);
  955. request->status = TAPE_REQUEST_QUEUED;
  956. schedule_delayed_work(&device->tape_dnr, HZ);
  957. return;
  958. }
  959. /* May be an unsolicited irq */
  960. if(request != NULL)
  961. request->rescnt = irb->scsw.count;
  962. if (irb->scsw.dstat != 0x0c) {
  963. /* Set the 'ONLINE' flag depending on sense byte 1 */
  964. if(*(((__u8 *) irb->ecw) + 1) & SENSE_DRIVE_ONLINE)
  965. device->tape_generic_status |= GMT_ONLINE(~0);
  966. else
  967. device->tape_generic_status &= ~GMT_ONLINE(~0);
  968. /*
  969. * Any request that does not come back with channel end
  970. * and device end is unusual. Log the sense data.
  971. */
  972. DBF_EVENT(3,"-- Tape Interrupthandler --\n");
  973. tape_dump_sense_dbf(device, request, irb);
  974. } else {
  975. /* Upon normal completion the device _is_ online */
  976. device->tape_generic_status |= GMT_ONLINE(~0);
  977. }
  978. if (device->tape_state == TS_NOT_OPER) {
  979. DBF_EVENT(6, "tape:device is not operational\n");
  980. return;
  981. }
  982. /*
  983. * Request that were canceled still come back with an interrupt.
  984. * To detect these request the state will be set to TAPE_REQUEST_DONE.
  985. */
  986. if(request != NULL && request->status == TAPE_REQUEST_DONE) {
  987. __tape_end_request(device, request, -EIO);
  988. return;
  989. }
  990. rc = device->discipline->irq(device, request, irb);
  991. /*
  992. * rc < 0 : request finished unsuccessfully.
  993. * rc == TAPE_IO_SUCCESS: request finished successfully.
  994. * rc == TAPE_IO_PENDING: request is still running. Ignore rc.
  995. * rc == TAPE_IO_RETRY: request finished but needs another go.
  996. * rc == TAPE_IO_STOP: request needs to get terminated.
  997. */
  998. switch (rc) {
  999. case TAPE_IO_SUCCESS:
  1000. /* Upon normal completion the device _is_ online */
  1001. device->tape_generic_status |= GMT_ONLINE(~0);
  1002. __tape_end_request(device, request, rc);
  1003. break;
  1004. case TAPE_IO_PENDING:
  1005. break;
  1006. case TAPE_IO_RETRY:
  1007. rc = __tape_start_io(device, request);
  1008. if (rc)
  1009. __tape_end_request(device, request, rc);
  1010. break;
  1011. case TAPE_IO_STOP:
  1012. rc = __tape_cancel_io(device, request);
  1013. if (rc)
  1014. __tape_end_request(device, request, rc);
  1015. break;
  1016. default:
  1017. if (rc > 0) {
  1018. DBF_EVENT(6, "xunknownrc\n");
  1019. PRINT_ERR("Invalid return code from discipline "
  1020. "interrupt function.\n");
  1021. __tape_end_request(device, request, -EIO);
  1022. } else {
  1023. __tape_end_request(device, request, rc);
  1024. }
  1025. break;
  1026. }
  1027. }
  1028. /*
  1029. * Tape device open function used by tape_char & tape_block frontends.
  1030. */
  1031. int
  1032. tape_open(struct tape_device *device)
  1033. {
  1034. int rc;
  1035. spin_lock(get_ccwdev_lock(device->cdev));
  1036. if (device->tape_state == TS_NOT_OPER) {
  1037. DBF_EVENT(6, "TAPE:nodev\n");
  1038. rc = -ENODEV;
  1039. } else if (device->tape_state == TS_IN_USE) {
  1040. DBF_EVENT(6, "TAPE:dbusy\n");
  1041. rc = -EBUSY;
  1042. } else if (device->tape_state == TS_BLKUSE) {
  1043. DBF_EVENT(6, "TAPE:dbusy\n");
  1044. rc = -EBUSY;
  1045. } else if (device->discipline != NULL &&
  1046. !try_module_get(device->discipline->owner)) {
  1047. DBF_EVENT(6, "TAPE:nodisc\n");
  1048. rc = -ENODEV;
  1049. } else {
  1050. tape_state_set(device, TS_IN_USE);
  1051. rc = 0;
  1052. }
  1053. spin_unlock(get_ccwdev_lock(device->cdev));
  1054. return rc;
  1055. }
  1056. /*
  1057. * Tape device release function used by tape_char & tape_block frontends.
  1058. */
  1059. int
  1060. tape_release(struct tape_device *device)
  1061. {
  1062. spin_lock(get_ccwdev_lock(device->cdev));
  1063. if (device->tape_state == TS_IN_USE)
  1064. tape_state_set(device, TS_UNUSED);
  1065. module_put(device->discipline->owner);
  1066. spin_unlock(get_ccwdev_lock(device->cdev));
  1067. return 0;
  1068. }
  1069. /*
  1070. * Execute a magnetic tape command a number of times.
  1071. */
  1072. int
  1073. tape_mtop(struct tape_device *device, int mt_op, int mt_count)
  1074. {
  1075. tape_mtop_fn fn;
  1076. int rc;
  1077. DBF_EVENT(6, "TAPE:mtio\n");
  1078. DBF_EVENT(6, "TAPE:ioop: %x\n", mt_op);
  1079. DBF_EVENT(6, "TAPE:arg: %x\n", mt_count);
  1080. if (mt_op < 0 || mt_op >= TAPE_NR_MTOPS)
  1081. return -EINVAL;
  1082. fn = device->discipline->mtop_array[mt_op];
  1083. if (fn == NULL)
  1084. return -EINVAL;
  1085. /* We assume that the backends can handle count up to 500. */
  1086. if (mt_op == MTBSR || mt_op == MTFSR || mt_op == MTFSF ||
  1087. mt_op == MTBSF || mt_op == MTFSFM || mt_op == MTBSFM) {
  1088. rc = 0;
  1089. for (; mt_count > 500; mt_count -= 500)
  1090. if ((rc = fn(device, 500)) != 0)
  1091. break;
  1092. if (rc == 0)
  1093. rc = fn(device, mt_count);
  1094. } else
  1095. rc = fn(device, mt_count);
  1096. return rc;
  1097. }
  1098. /*
  1099. * Tape init function.
  1100. */
  1101. static int
  1102. tape_init (void)
  1103. {
  1104. TAPE_DBF_AREA = debug_register ( "tape", 2, 2, 4*sizeof(long));
  1105. debug_register_view(TAPE_DBF_AREA, &debug_sprintf_view);
  1106. #ifdef DBF_LIKE_HELL
  1107. debug_set_level(TAPE_DBF_AREA, 6);
  1108. #endif
  1109. DBF_EVENT(3, "tape init\n");
  1110. tape_proc_init();
  1111. tapechar_init ();
  1112. tapeblock_init ();
  1113. return 0;
  1114. }
  1115. /*
  1116. * Tape exit function.
  1117. */
  1118. static void
  1119. tape_exit(void)
  1120. {
  1121. DBF_EVENT(6, "tape exit\n");
  1122. /* Get rid of the frontends */
  1123. tapechar_exit();
  1124. tapeblock_exit();
  1125. tape_proc_cleanup();
  1126. debug_unregister (TAPE_DBF_AREA);
  1127. }
  1128. MODULE_AUTHOR("(C) 2001 IBM Deutschland Entwicklung GmbH by Carsten Otte and "
  1129. "Michael Holzheu (cotte@de.ibm.com,holzheu@de.ibm.com)");
  1130. MODULE_DESCRIPTION("Linux on zSeries channel attached tape device driver");
  1131. MODULE_LICENSE("GPL");
  1132. module_init(tape_init);
  1133. module_exit(tape_exit);
  1134. EXPORT_SYMBOL(tape_generic_remove);
  1135. EXPORT_SYMBOL(tape_generic_probe);
  1136. EXPORT_SYMBOL(tape_generic_online);
  1137. EXPORT_SYMBOL(tape_generic_offline);
  1138. EXPORT_SYMBOL(tape_put_device);
  1139. EXPORT_SYMBOL(tape_get_device_reference);
  1140. EXPORT_SYMBOL(tape_state_verbose);
  1141. EXPORT_SYMBOL(tape_op_verbose);
  1142. EXPORT_SYMBOL(tape_state_set);
  1143. EXPORT_SYMBOL(tape_med_state_set);
  1144. EXPORT_SYMBOL(tape_alloc_request);
  1145. EXPORT_SYMBOL(tape_free_request);
  1146. EXPORT_SYMBOL(tape_dump_sense);
  1147. EXPORT_SYMBOL(tape_dump_sense_dbf);
  1148. EXPORT_SYMBOL(tape_do_io);
  1149. EXPORT_SYMBOL(tape_do_io_async);
  1150. EXPORT_SYMBOL(tape_do_io_interruptible);
  1151. EXPORT_SYMBOL(tape_cancel_io);
  1152. EXPORT_SYMBOL(tape_mtop);