tape_core.c 34 KB

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