tape_core.c 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353
  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",[TO_RDC] = "RDC",
  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. case TO_RDC:
  804. if (device->tape_state == TS_INIT)
  805. break;
  806. if (device->tape_state == TS_UNUSED)
  807. break;
  808. default:
  809. if (device->tape_state == TS_BLKUSE)
  810. break;
  811. if (device->tape_state != TS_IN_USE)
  812. return -ENODEV;
  813. }
  814. /* Increase use count of device for the added request. */
  815. request->device = tape_get_device_reference(device);
  816. if (list_empty(&device->req_queue)) {
  817. /* No other requests are on the queue. Start this one. */
  818. rc = __tape_start_io(device, request);
  819. if (rc)
  820. return rc;
  821. DBF_LH(5, "Request %p added for execution.\n", request);
  822. list_add(&request->list, &device->req_queue);
  823. } else {
  824. DBF_LH(5, "Request %p add to queue.\n", request);
  825. request->status = TAPE_REQUEST_QUEUED;
  826. list_add_tail(&request->list, &device->req_queue);
  827. }
  828. return 0;
  829. }
  830. /*
  831. * Add the request to the request queue, try to start it if the
  832. * tape is idle. Return without waiting for end of i/o.
  833. */
  834. int
  835. tape_do_io_async(struct tape_device *device, struct tape_request *request)
  836. {
  837. int rc;
  838. DBF_LH(6, "tape_do_io_async(%p, %p)\n", device, request);
  839. spin_lock_irq(get_ccwdev_lock(device->cdev));
  840. /* Add request to request queue and try to start it. */
  841. rc = __tape_start_request(device, request);
  842. spin_unlock_irq(get_ccwdev_lock(device->cdev));
  843. return rc;
  844. }
  845. /*
  846. * tape_do_io/__tape_wake_up
  847. * Add the request to the request queue, try to start it if the
  848. * tape is idle and wait uninterruptible for its completion.
  849. */
  850. static void
  851. __tape_wake_up(struct tape_request *request, void *data)
  852. {
  853. request->callback = NULL;
  854. wake_up((wait_queue_head_t *) data);
  855. }
  856. int
  857. tape_do_io(struct tape_device *device, struct tape_request *request)
  858. {
  859. wait_queue_head_t wq;
  860. int rc;
  861. init_waitqueue_head(&wq);
  862. spin_lock_irq(get_ccwdev_lock(device->cdev));
  863. /* Setup callback */
  864. request->callback = __tape_wake_up;
  865. request->callback_data = &wq;
  866. /* Add request to request queue and try to start it. */
  867. rc = __tape_start_request(device, request);
  868. spin_unlock_irq(get_ccwdev_lock(device->cdev));
  869. if (rc)
  870. return rc;
  871. /* Request added to the queue. Wait for its completion. */
  872. wait_event(wq, (request->callback == NULL));
  873. /* Get rc from request */
  874. return request->rc;
  875. }
  876. /*
  877. * tape_do_io_interruptible/__tape_wake_up_interruptible
  878. * Add the request to the request queue, try to start it if the
  879. * tape is idle and wait uninterruptible for its completion.
  880. */
  881. static void
  882. __tape_wake_up_interruptible(struct tape_request *request, void *data)
  883. {
  884. request->callback = NULL;
  885. wake_up_interruptible((wait_queue_head_t *) data);
  886. }
  887. int
  888. tape_do_io_interruptible(struct tape_device *device,
  889. struct tape_request *request)
  890. {
  891. wait_queue_head_t wq;
  892. int rc;
  893. init_waitqueue_head(&wq);
  894. spin_lock_irq(get_ccwdev_lock(device->cdev));
  895. /* Setup callback */
  896. request->callback = __tape_wake_up_interruptible;
  897. request->callback_data = &wq;
  898. rc = __tape_start_request(device, request);
  899. spin_unlock_irq(get_ccwdev_lock(device->cdev));
  900. if (rc)
  901. return rc;
  902. /* Request added to the queue. Wait for its completion. */
  903. rc = wait_event_interruptible(wq, (request->callback == NULL));
  904. if (rc != -ERESTARTSYS)
  905. /* Request finished normally. */
  906. return request->rc;
  907. /* Interrupted by a signal. We have to stop the current request. */
  908. spin_lock_irq(get_ccwdev_lock(device->cdev));
  909. rc = __tape_cancel_io(device, request);
  910. spin_unlock_irq(get_ccwdev_lock(device->cdev));
  911. if (rc == 0) {
  912. /* Wait for the interrupt that acknowledges the halt. */
  913. do {
  914. rc = wait_event_interruptible(
  915. wq,
  916. (request->callback == NULL)
  917. );
  918. } while (rc == -ERESTARTSYS);
  919. DBF_EVENT(3, "IO stopped on %08x\n", device->cdev_id);
  920. rc = -ERESTARTSYS;
  921. }
  922. return rc;
  923. }
  924. /*
  925. * Stop running ccw.
  926. */
  927. int
  928. tape_cancel_io(struct tape_device *device, struct tape_request *request)
  929. {
  930. int rc;
  931. spin_lock_irq(get_ccwdev_lock(device->cdev));
  932. rc = __tape_cancel_io(device, request);
  933. spin_unlock_irq(get_ccwdev_lock(device->cdev));
  934. return rc;
  935. }
  936. /*
  937. * Tape interrupt routine, called from the ccw_device layer
  938. */
  939. static void
  940. __tape_do_irq (struct ccw_device *cdev, unsigned long intparm, struct irb *irb)
  941. {
  942. struct tape_device *device;
  943. struct tape_request *request;
  944. int rc;
  945. device = (struct tape_device *) cdev->dev.driver_data;
  946. if (device == NULL) {
  947. PRINT_ERR("could not get device structure for %s "
  948. "in interrupt\n", cdev->dev.bus_id);
  949. return;
  950. }
  951. request = (struct tape_request *) intparm;
  952. DBF_LH(6, "__tape_do_irq(device=%p, request=%p)\n", device, request);
  953. /* On special conditions irb is an error pointer */
  954. if (IS_ERR(irb)) {
  955. /* FIXME: What to do with the request? */
  956. switch (PTR_ERR(irb)) {
  957. case -ETIMEDOUT:
  958. PRINT_WARN("(%s): Request timed out\n",
  959. cdev->dev.bus_id);
  960. case -EIO:
  961. __tape_end_request(device, request, -EIO);
  962. break;
  963. default:
  964. PRINT_ERR("(%s): Unexpected i/o error %li\n",
  965. cdev->dev.bus_id,
  966. PTR_ERR(irb));
  967. }
  968. return;
  969. }
  970. /*
  971. * If the condition code is not zero and the start function bit is
  972. * still set, this is an deferred error and the last start I/O did
  973. * not succeed. At this point the condition that caused the deferred
  974. * error might still apply. So we just schedule the request to be
  975. * started later.
  976. */
  977. if (irb->scsw.cc != 0 && (irb->scsw.fctl & SCSW_FCTL_START_FUNC) &&
  978. (request->status == TAPE_REQUEST_IN_IO)) {
  979. DBF_EVENT(3,"(%08x): deferred cc=%i, fctl=%i. restarting\n",
  980. device->cdev_id, irb->scsw.cc, irb->scsw.fctl);
  981. request->status = TAPE_REQUEST_QUEUED;
  982. schedule_delayed_work(&device->tape_dnr, HZ);
  983. return;
  984. }
  985. /* May be an unsolicited irq */
  986. if(request != NULL)
  987. request->rescnt = irb->scsw.count;
  988. else if ((irb->scsw.dstat == 0x85 || irb->scsw.dstat == 0x80) &&
  989. !list_empty(&device->req_queue)) {
  990. /* Not Ready to Ready after long busy ? */
  991. struct tape_request *req;
  992. req = list_entry(device->req_queue.next,
  993. struct tape_request, list);
  994. if (req->status == TAPE_REQUEST_LONG_BUSY) {
  995. DBF_EVENT(3, "(%08x): del timer\n", device->cdev_id);
  996. if (del_timer(&device->lb_timeout)) {
  997. device->lb_timeout.data = (unsigned long)
  998. tape_put_device(device);
  999. __tape_start_next_request(device);
  1000. }
  1001. return;
  1002. }
  1003. }
  1004. if (irb->scsw.dstat != 0x0c) {
  1005. /* Set the 'ONLINE' flag depending on sense byte 1 */
  1006. if(*(((__u8 *) irb->ecw) + 1) & SENSE_DRIVE_ONLINE)
  1007. device->tape_generic_status |= GMT_ONLINE(~0);
  1008. else
  1009. device->tape_generic_status &= ~GMT_ONLINE(~0);
  1010. /*
  1011. * Any request that does not come back with channel end
  1012. * and device end is unusual. Log the sense data.
  1013. */
  1014. DBF_EVENT(3,"-- Tape Interrupthandler --\n");
  1015. tape_dump_sense_dbf(device, request, irb);
  1016. } else {
  1017. /* Upon normal completion the device _is_ online */
  1018. device->tape_generic_status |= GMT_ONLINE(~0);
  1019. }
  1020. if (device->tape_state == TS_NOT_OPER) {
  1021. DBF_EVENT(6, "tape:device is not operational\n");
  1022. return;
  1023. }
  1024. /*
  1025. * Request that were canceled still come back with an interrupt.
  1026. * To detect these request the state will be set to TAPE_REQUEST_DONE.
  1027. */
  1028. if(request != NULL && request->status == TAPE_REQUEST_DONE) {
  1029. __tape_end_request(device, request, -EIO);
  1030. return;
  1031. }
  1032. rc = device->discipline->irq(device, request, irb);
  1033. /*
  1034. * rc < 0 : request finished unsuccessfully.
  1035. * rc == TAPE_IO_SUCCESS: request finished successfully.
  1036. * rc == TAPE_IO_PENDING: request is still running. Ignore rc.
  1037. * rc == TAPE_IO_RETRY: request finished but needs another go.
  1038. * rc == TAPE_IO_STOP: request needs to get terminated.
  1039. */
  1040. switch (rc) {
  1041. case TAPE_IO_SUCCESS:
  1042. /* Upon normal completion the device _is_ online */
  1043. device->tape_generic_status |= GMT_ONLINE(~0);
  1044. __tape_end_request(device, request, rc);
  1045. break;
  1046. case TAPE_IO_PENDING:
  1047. break;
  1048. case TAPE_IO_LONG_BUSY:
  1049. device->lb_timeout.data =
  1050. (unsigned long)tape_get_device_reference(device);
  1051. device->lb_timeout.expires = jiffies +
  1052. LONG_BUSY_TIMEOUT * HZ;
  1053. DBF_EVENT(3, "(%08x): add timer\n", device->cdev_id);
  1054. add_timer(&device->lb_timeout);
  1055. request->status = TAPE_REQUEST_LONG_BUSY;
  1056. break;
  1057. case TAPE_IO_RETRY:
  1058. rc = __tape_start_io(device, request);
  1059. if (rc)
  1060. __tape_end_request(device, request, rc);
  1061. break;
  1062. case TAPE_IO_STOP:
  1063. rc = __tape_cancel_io(device, request);
  1064. if (rc)
  1065. __tape_end_request(device, request, rc);
  1066. break;
  1067. default:
  1068. if (rc > 0) {
  1069. DBF_EVENT(6, "xunknownrc\n");
  1070. PRINT_ERR("Invalid return code from discipline "
  1071. "interrupt function.\n");
  1072. __tape_end_request(device, request, -EIO);
  1073. } else {
  1074. __tape_end_request(device, request, rc);
  1075. }
  1076. break;
  1077. }
  1078. }
  1079. /*
  1080. * Tape device open function used by tape_char & tape_block frontends.
  1081. */
  1082. int
  1083. tape_open(struct tape_device *device)
  1084. {
  1085. int rc;
  1086. spin_lock(get_ccwdev_lock(device->cdev));
  1087. if (device->tape_state == TS_NOT_OPER) {
  1088. DBF_EVENT(6, "TAPE:nodev\n");
  1089. rc = -ENODEV;
  1090. } else if (device->tape_state == TS_IN_USE) {
  1091. DBF_EVENT(6, "TAPE:dbusy\n");
  1092. rc = -EBUSY;
  1093. } else if (device->tape_state == TS_BLKUSE) {
  1094. DBF_EVENT(6, "TAPE:dbusy\n");
  1095. rc = -EBUSY;
  1096. } else if (device->discipline != NULL &&
  1097. !try_module_get(device->discipline->owner)) {
  1098. DBF_EVENT(6, "TAPE:nodisc\n");
  1099. rc = -ENODEV;
  1100. } else {
  1101. tape_state_set(device, TS_IN_USE);
  1102. rc = 0;
  1103. }
  1104. spin_unlock(get_ccwdev_lock(device->cdev));
  1105. return rc;
  1106. }
  1107. /*
  1108. * Tape device release function used by tape_char & tape_block frontends.
  1109. */
  1110. int
  1111. tape_release(struct tape_device *device)
  1112. {
  1113. spin_lock(get_ccwdev_lock(device->cdev));
  1114. if (device->tape_state == TS_IN_USE)
  1115. tape_state_set(device, TS_UNUSED);
  1116. module_put(device->discipline->owner);
  1117. spin_unlock(get_ccwdev_lock(device->cdev));
  1118. return 0;
  1119. }
  1120. /*
  1121. * Execute a magnetic tape command a number of times.
  1122. */
  1123. int
  1124. tape_mtop(struct tape_device *device, int mt_op, int mt_count)
  1125. {
  1126. tape_mtop_fn fn;
  1127. int rc;
  1128. DBF_EVENT(6, "TAPE:mtio\n");
  1129. DBF_EVENT(6, "TAPE:ioop: %x\n", mt_op);
  1130. DBF_EVENT(6, "TAPE:arg: %x\n", mt_count);
  1131. if (mt_op < 0 || mt_op >= TAPE_NR_MTOPS)
  1132. return -EINVAL;
  1133. fn = device->discipline->mtop_array[mt_op];
  1134. if (fn == NULL)
  1135. return -EINVAL;
  1136. /* We assume that the backends can handle count up to 500. */
  1137. if (mt_op == MTBSR || mt_op == MTFSR || mt_op == MTFSF ||
  1138. mt_op == MTBSF || mt_op == MTFSFM || mt_op == MTBSFM) {
  1139. rc = 0;
  1140. for (; mt_count > 500; mt_count -= 500)
  1141. if ((rc = fn(device, 500)) != 0)
  1142. break;
  1143. if (rc == 0)
  1144. rc = fn(device, mt_count);
  1145. } else
  1146. rc = fn(device, mt_count);
  1147. return rc;
  1148. }
  1149. /*
  1150. * Tape init function.
  1151. */
  1152. static int
  1153. tape_init (void)
  1154. {
  1155. TAPE_DBF_AREA = debug_register ( "tape", 2, 2, 4*sizeof(long));
  1156. debug_register_view(TAPE_DBF_AREA, &debug_sprintf_view);
  1157. #ifdef DBF_LIKE_HELL
  1158. debug_set_level(TAPE_DBF_AREA, 6);
  1159. #endif
  1160. DBF_EVENT(3, "tape init\n");
  1161. tape_proc_init();
  1162. tapechar_init ();
  1163. tapeblock_init ();
  1164. return 0;
  1165. }
  1166. /*
  1167. * Tape exit function.
  1168. */
  1169. static void
  1170. tape_exit(void)
  1171. {
  1172. DBF_EVENT(6, "tape exit\n");
  1173. /* Get rid of the frontends */
  1174. tapechar_exit();
  1175. tapeblock_exit();
  1176. tape_proc_cleanup();
  1177. debug_unregister (TAPE_DBF_AREA);
  1178. }
  1179. MODULE_AUTHOR("(C) 2001 IBM Deutschland Entwicklung GmbH by Carsten Otte and "
  1180. "Michael Holzheu (cotte@de.ibm.com,holzheu@de.ibm.com)");
  1181. MODULE_DESCRIPTION("Linux on zSeries channel attached tape device driver");
  1182. MODULE_LICENSE("GPL");
  1183. module_init(tape_init);
  1184. module_exit(tape_exit);
  1185. EXPORT_SYMBOL(tape_generic_remove);
  1186. EXPORT_SYMBOL(tape_generic_probe);
  1187. EXPORT_SYMBOL(tape_generic_online);
  1188. EXPORT_SYMBOL(tape_generic_offline);
  1189. EXPORT_SYMBOL(tape_put_device);
  1190. EXPORT_SYMBOL(tape_get_device_reference);
  1191. EXPORT_SYMBOL(tape_state_verbose);
  1192. EXPORT_SYMBOL(tape_op_verbose);
  1193. EXPORT_SYMBOL(tape_state_set);
  1194. EXPORT_SYMBOL(tape_med_state_set);
  1195. EXPORT_SYMBOL(tape_alloc_request);
  1196. EXPORT_SYMBOL(tape_free_request);
  1197. EXPORT_SYMBOL(tape_dump_sense);
  1198. EXPORT_SYMBOL(tape_dump_sense_dbf);
  1199. EXPORT_SYMBOL(tape_do_io);
  1200. EXPORT_SYMBOL(tape_do_io_async);
  1201. EXPORT_SYMBOL(tape_do_io_interruptible);
  1202. EXPORT_SYMBOL(tape_cancel_io);
  1203. EXPORT_SYMBOL(tape_mtop);