tape_core.c 32 KB

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