tape_core.c 34 KB

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