tape_core.c 34 KB

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