dasd_devmap.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800
  1. /*
  2. * File...........: linux/drivers/s390/block/dasd_devmap.c
  3. * Author(s)......: Holger Smolinski <Holger.Smolinski@de.ibm.com>
  4. * Horst Hummel <Horst.Hummel@de.ibm.com>
  5. * Carsten Otte <Cotte@de.ibm.com>
  6. * Martin Schwidefsky <schwidefsky@de.ibm.com>
  7. * Bugreports.to..: <Linux390@de.ibm.com>
  8. * (C) IBM Corporation, IBM Deutschland Entwicklung GmbH, 1999-2001
  9. *
  10. * Device mapping and dasd= parameter parsing functions. All devmap
  11. * functions may not be called from interrupt context. In particular
  12. * dasd_get_device is a no-no from interrupt context.
  13. *
  14. * $Revision: 1.43 $
  15. */
  16. #include <linux/config.h>
  17. #include <linux/ctype.h>
  18. #include <linux/init.h>
  19. #include <asm/debug.h>
  20. #include <asm/uaccess.h>
  21. /* This is ugly... */
  22. #define PRINTK_HEADER "dasd_devmap:"
  23. #include "dasd_int.h"
  24. kmem_cache_t *dasd_page_cache;
  25. EXPORT_SYMBOL(dasd_page_cache);
  26. /*
  27. * dasd_devmap_t is used to store the features and the relation
  28. * between device number and device index. To find a dasd_devmap_t
  29. * that corresponds to a device number of a device index each
  30. * dasd_devmap_t is added to two linked lists, one to search by
  31. * the device number and one to search by the device index. As
  32. * soon as big minor numbers are available the device index list
  33. * can be removed since the device number will then be identical
  34. * to the device index.
  35. */
  36. struct dasd_devmap {
  37. struct list_head list;
  38. char bus_id[BUS_ID_SIZE];
  39. unsigned int devindex;
  40. unsigned short features;
  41. struct dasd_device *device;
  42. };
  43. /*
  44. * Parameter parsing functions for dasd= parameter. The syntax is:
  45. * <devno> : (0x)?[0-9a-fA-F]+
  46. * <busid> : [0-0a-f]\.[0-9a-f]\.(0x)?[0-9a-fA-F]+
  47. * <feature> : ro
  48. * <feature_list> : \(<feature>(:<feature>)*\)
  49. * <devno-range> : <devno>(-<devno>)?<feature_list>?
  50. * <busid-range> : <busid>(-<busid>)?<feature_list>?
  51. * <devices> : <devno-range>|<busid-range>
  52. * <dasd_module> : dasd_diag_mod|dasd_eckd_mod|dasd_fba_mod
  53. *
  54. * <dasd> : autodetect|probeonly|<devices>(,<devices>)*
  55. */
  56. int dasd_probeonly = 0; /* is true, when probeonly mode is active */
  57. int dasd_autodetect = 0; /* is true, when autodetection is active */
  58. /*
  59. * char *dasd[] is intended to hold the ranges supplied by the dasd= statement
  60. * it is named 'dasd' to directly be filled by insmod with the comma separated
  61. * strings when running as a module.
  62. */
  63. static char *dasd[256];
  64. /*
  65. * Single spinlock to protect devmap structures and lists.
  66. */
  67. static DEFINE_SPINLOCK(dasd_devmap_lock);
  68. /*
  69. * Hash lists for devmap structures.
  70. */
  71. static struct list_head dasd_hashlists[256];
  72. int dasd_max_devindex;
  73. static struct dasd_devmap *dasd_add_busid(char *, int);
  74. static inline int
  75. dasd_hash_busid(char *bus_id)
  76. {
  77. int hash, i;
  78. hash = 0;
  79. for (i = 0; (i < BUS_ID_SIZE) && *bus_id; i++, bus_id++)
  80. hash += *bus_id;
  81. return hash & 0xff;
  82. }
  83. #ifndef MODULE
  84. /*
  85. * The parameter parsing functions for builtin-drivers are called
  86. * before kmalloc works. Store the pointers to the parameters strings
  87. * into dasd[] for later processing.
  88. */
  89. static int __init
  90. dasd_call_setup(char *str)
  91. {
  92. static int count = 0;
  93. if (count < 256)
  94. dasd[count++] = str;
  95. return 1;
  96. }
  97. __setup ("dasd=", dasd_call_setup);
  98. #endif /* #ifndef MODULE */
  99. /*
  100. * Read a device busid/devno from a string.
  101. */
  102. static inline int
  103. dasd_busid(char **str, int *id0, int *id1, int *devno)
  104. {
  105. int val, old_style;
  106. /* check for leading '0x' */
  107. old_style = 0;
  108. if ((*str)[0] == '0' && (*str)[1] == 'x') {
  109. *str += 2;
  110. old_style = 1;
  111. }
  112. if (!isxdigit((*str)[0])) /* We require at least one hex digit */
  113. return -EINVAL;
  114. val = simple_strtoul(*str, str, 16);
  115. if (old_style || (*str)[0] != '.') {
  116. *id0 = *id1 = 0;
  117. if (val < 0 || val > 0xffff)
  118. return -EINVAL;
  119. *devno = val;
  120. return 0;
  121. }
  122. /* New style x.y.z busid */
  123. if (val < 0 || val > 0xff)
  124. return -EINVAL;
  125. *id0 = val;
  126. (*str)++;
  127. if (!isxdigit((*str)[0])) /* We require at least one hex digit */
  128. return -EINVAL;
  129. val = simple_strtoul(*str, str, 16);
  130. if (val < 0 || val > 0xff || (*str)++[0] != '.')
  131. return -EINVAL;
  132. *id1 = val;
  133. if (!isxdigit((*str)[0])) /* We require at least one hex digit */
  134. return -EINVAL;
  135. val = simple_strtoul(*str, str, 16);
  136. if (val < 0 || val > 0xffff)
  137. return -EINVAL;
  138. *devno = val;
  139. return 0;
  140. }
  141. /*
  142. * Read colon separated list of dasd features. Currently there is
  143. * only one: "ro" for read-only devices. The default feature set
  144. * is empty (value 0).
  145. */
  146. static inline int
  147. dasd_feature_list(char *str, char **endp)
  148. {
  149. int features, len, rc;
  150. rc = 0;
  151. if (*str != '(') {
  152. *endp = str;
  153. return DASD_FEATURE_DEFAULT;
  154. }
  155. str++;
  156. features = 0;
  157. while (1) {
  158. for (len = 0;
  159. str[len] && str[len] != ':' && str[len] != ')'; len++);
  160. if (len == 2 && !strncmp(str, "ro", 2))
  161. features |= DASD_FEATURE_READONLY;
  162. else if (len == 4 && !strncmp(str, "diag", 4))
  163. features |= DASD_FEATURE_USEDIAG;
  164. else {
  165. MESSAGE(KERN_WARNING,
  166. "unsupported feature: %*s, "
  167. "ignoring setting", len, str);
  168. rc = -EINVAL;
  169. }
  170. str += len;
  171. if (*str != ':')
  172. break;
  173. str++;
  174. }
  175. if (*str != ')') {
  176. MESSAGE(KERN_WARNING, "%s",
  177. "missing ')' in dasd parameter string\n");
  178. rc = -EINVAL;
  179. } else
  180. str++;
  181. *endp = str;
  182. if (rc != 0)
  183. return rc;
  184. return features;
  185. }
  186. /*
  187. * Try to match the first element on the comma separated parse string
  188. * with one of the known keywords. If a keyword is found, take the approprate
  189. * action and return a pointer to the residual string. If the first element
  190. * could not be matched to any keyword then return an error code.
  191. */
  192. static char *
  193. dasd_parse_keyword( char *parsestring ) {
  194. char *nextcomma, *residual_str;
  195. int length;
  196. nextcomma = strchr(parsestring,',');
  197. if (nextcomma) {
  198. length = nextcomma - parsestring;
  199. residual_str = nextcomma + 1;
  200. } else {
  201. length = strlen(parsestring);
  202. residual_str = parsestring + length;
  203. }
  204. if (strncmp ("autodetect", parsestring, length) == 0) {
  205. dasd_autodetect = 1;
  206. MESSAGE (KERN_INFO, "%s",
  207. "turning to autodetection mode");
  208. return residual_str;
  209. }
  210. if (strncmp ("probeonly", parsestring, length) == 0) {
  211. dasd_probeonly = 1;
  212. MESSAGE(KERN_INFO, "%s",
  213. "turning to probeonly mode");
  214. return residual_str;
  215. }
  216. if (strncmp ("fixedbuffers", parsestring, length) == 0) {
  217. if (dasd_page_cache)
  218. return residual_str;
  219. dasd_page_cache =
  220. kmem_cache_create("dasd_page_cache", PAGE_SIZE, 0,
  221. SLAB_CACHE_DMA, NULL, NULL );
  222. if (!dasd_page_cache)
  223. MESSAGE(KERN_WARNING, "%s", "Failed to create slab, "
  224. "fixed buffer mode disabled.");
  225. else
  226. MESSAGE (KERN_INFO, "%s",
  227. "turning on fixed buffer mode");
  228. return residual_str;
  229. }
  230. return ERR_PTR(-EINVAL);
  231. }
  232. /*
  233. * Try to interprete the first element on the comma separated parse string
  234. * as a device number or a range of devices. If the interpretation is
  235. * successfull, create the matching dasd_devmap entries and return a pointer
  236. * to the residual string.
  237. * If interpretation fails or in case of an error, return an error code.
  238. */
  239. static char *
  240. dasd_parse_range( char *parsestring ) {
  241. struct dasd_devmap *devmap;
  242. int from, from_id0, from_id1;
  243. int to, to_id0, to_id1;
  244. int features, rc;
  245. char bus_id[BUS_ID_SIZE+1], *str;
  246. str = parsestring;
  247. rc = dasd_busid(&str, &from_id0, &from_id1, &from);
  248. if (rc == 0) {
  249. to = from;
  250. to_id0 = from_id0;
  251. to_id1 = from_id1;
  252. if (*str == '-') {
  253. str++;
  254. rc = dasd_busid(&str, &to_id0, &to_id1, &to);
  255. }
  256. }
  257. if (rc == 0 &&
  258. (from_id0 != to_id0 || from_id1 != to_id1 || from > to))
  259. rc = -EINVAL;
  260. if (rc) {
  261. MESSAGE(KERN_ERR, "Invalid device range %s", parsestring);
  262. return ERR_PTR(rc);
  263. }
  264. features = dasd_feature_list(str, &str);
  265. if (features < 0)
  266. return ERR_PTR(-EINVAL);
  267. while (from <= to) {
  268. sprintf(bus_id, "%01x.%01x.%04x",
  269. from_id0, from_id1, from++);
  270. devmap = dasd_add_busid(bus_id, features);
  271. if (IS_ERR(devmap))
  272. return (char *)devmap;
  273. }
  274. if (*str == ',')
  275. return str + 1;
  276. if (*str == '\0')
  277. return str;
  278. MESSAGE(KERN_WARNING,
  279. "junk at end of dasd parameter string: %s\n", str);
  280. return ERR_PTR(-EINVAL);
  281. }
  282. static inline char *
  283. dasd_parse_next_element( char *parsestring ) {
  284. char * residual_str;
  285. residual_str = dasd_parse_keyword(parsestring);
  286. if (!IS_ERR(residual_str))
  287. return residual_str;
  288. residual_str = dasd_parse_range(parsestring);
  289. return residual_str;
  290. }
  291. /*
  292. * Parse parameters stored in dasd[]
  293. * The 'dasd=...' parameter allows to specify a comma separated list of
  294. * keywords and device ranges. When the dasd driver is build into the kernel,
  295. * the complete list will be stored as one element of the dasd[] array.
  296. * When the dasd driver is build as a module, then the list is broken into
  297. * it's elements and each dasd[] entry contains one element.
  298. */
  299. int
  300. dasd_parse(void)
  301. {
  302. int rc, i;
  303. char *parsestring;
  304. rc = 0;
  305. for (i = 0; i < 256; i++) {
  306. if (dasd[i] == NULL)
  307. break;
  308. parsestring = dasd[i];
  309. /* loop over the comma separated list in the parsestring */
  310. while (*parsestring) {
  311. parsestring = dasd_parse_next_element(parsestring);
  312. if(IS_ERR(parsestring)) {
  313. rc = PTR_ERR(parsestring);
  314. break;
  315. }
  316. }
  317. if (rc) {
  318. DBF_EVENT(DBF_ALERT, "%s", "invalid range found");
  319. break;
  320. }
  321. }
  322. return rc;
  323. }
  324. /*
  325. * Add a devmap for the device specified by busid. It is possible that
  326. * the devmap already exists (dasd= parameter). The order of the devices
  327. * added through this function will define the kdevs for the individual
  328. * devices.
  329. */
  330. static struct dasd_devmap *
  331. dasd_add_busid(char *bus_id, int features)
  332. {
  333. struct dasd_devmap *devmap, *new, *tmp;
  334. int hash;
  335. new = (struct dasd_devmap *)
  336. kmalloc(sizeof(struct dasd_devmap), GFP_KERNEL);
  337. if (!new)
  338. return ERR_PTR(-ENOMEM);
  339. spin_lock(&dasd_devmap_lock);
  340. devmap = 0;
  341. hash = dasd_hash_busid(bus_id);
  342. list_for_each_entry(tmp, &dasd_hashlists[hash], list)
  343. if (strncmp(tmp->bus_id, bus_id, BUS_ID_SIZE) == 0) {
  344. devmap = tmp;
  345. break;
  346. }
  347. if (!devmap) {
  348. /* This bus_id is new. */
  349. new->devindex = dasd_max_devindex++;
  350. strncpy(new->bus_id, bus_id, BUS_ID_SIZE);
  351. new->features = features;
  352. new->device = 0;
  353. list_add(&new->list, &dasd_hashlists[hash]);
  354. devmap = new;
  355. new = 0;
  356. }
  357. spin_unlock(&dasd_devmap_lock);
  358. kfree(new);
  359. return devmap;
  360. }
  361. /*
  362. * Find devmap for device with given bus_id.
  363. */
  364. static struct dasd_devmap *
  365. dasd_find_busid(char *bus_id)
  366. {
  367. struct dasd_devmap *devmap, *tmp;
  368. int hash;
  369. spin_lock(&dasd_devmap_lock);
  370. devmap = ERR_PTR(-ENODEV);
  371. hash = dasd_hash_busid(bus_id);
  372. list_for_each_entry(tmp, &dasd_hashlists[hash], list) {
  373. if (strncmp(tmp->bus_id, bus_id, BUS_ID_SIZE) == 0) {
  374. devmap = tmp;
  375. break;
  376. }
  377. }
  378. spin_unlock(&dasd_devmap_lock);
  379. return devmap;
  380. }
  381. /*
  382. * Check if busid has been added to the list of dasd ranges.
  383. */
  384. int
  385. dasd_busid_known(char *bus_id)
  386. {
  387. return IS_ERR(dasd_find_busid(bus_id)) ? -ENOENT : 0;
  388. }
  389. /*
  390. * Forget all about the device numbers added so far.
  391. * This may only be called at module unload or system shutdown.
  392. */
  393. static void
  394. dasd_forget_ranges(void)
  395. {
  396. struct dasd_devmap *devmap, *n;
  397. int i;
  398. spin_lock(&dasd_devmap_lock);
  399. for (i = 0; i < 256; i++) {
  400. list_for_each_entry_safe(devmap, n, &dasd_hashlists[i], list) {
  401. if (devmap->device != NULL)
  402. BUG();
  403. list_del(&devmap->list);
  404. kfree(devmap);
  405. }
  406. }
  407. spin_unlock(&dasd_devmap_lock);
  408. }
  409. /*
  410. * Find the device struct by its device index.
  411. */
  412. struct dasd_device *
  413. dasd_device_from_devindex(int devindex)
  414. {
  415. struct dasd_devmap *devmap, *tmp;
  416. struct dasd_device *device;
  417. int i;
  418. spin_lock(&dasd_devmap_lock);
  419. devmap = 0;
  420. for (i = 0; (i < 256) && !devmap; i++)
  421. list_for_each_entry(tmp, &dasd_hashlists[i], list)
  422. if (tmp->devindex == devindex) {
  423. /* Found the devmap for the device. */
  424. devmap = tmp;
  425. break;
  426. }
  427. if (devmap && devmap->device) {
  428. device = devmap->device;
  429. dasd_get_device(device);
  430. } else
  431. device = ERR_PTR(-ENODEV);
  432. spin_unlock(&dasd_devmap_lock);
  433. return device;
  434. }
  435. /*
  436. * Return devmap for cdev. If no devmap exists yet, create one and
  437. * connect it to the cdev.
  438. */
  439. static struct dasd_devmap *
  440. dasd_devmap_from_cdev(struct ccw_device *cdev)
  441. {
  442. struct dasd_devmap *devmap;
  443. devmap = dasd_find_busid(cdev->dev.bus_id);
  444. if (IS_ERR(devmap))
  445. devmap = dasd_add_busid(cdev->dev.bus_id,
  446. DASD_FEATURE_DEFAULT);
  447. return devmap;
  448. }
  449. /*
  450. * Create a dasd device structure for cdev.
  451. */
  452. struct dasd_device *
  453. dasd_create_device(struct ccw_device *cdev)
  454. {
  455. struct dasd_devmap *devmap;
  456. struct dasd_device *device;
  457. int rc;
  458. devmap = dasd_devmap_from_cdev(cdev);
  459. if (IS_ERR(devmap))
  460. return (void *) devmap;
  461. cdev->dev.driver_data = devmap;
  462. device = dasd_alloc_device();
  463. if (IS_ERR(device))
  464. return device;
  465. atomic_set(&device->ref_count, 2);
  466. spin_lock(&dasd_devmap_lock);
  467. if (!devmap->device) {
  468. devmap->device = device;
  469. device->devindex = devmap->devindex;
  470. device->features = devmap->features;
  471. get_device(&cdev->dev);
  472. device->cdev = cdev;
  473. rc = 0;
  474. } else
  475. /* Someone else was faster. */
  476. rc = -EBUSY;
  477. spin_unlock(&dasd_devmap_lock);
  478. if (rc) {
  479. dasd_free_device(device);
  480. return ERR_PTR(rc);
  481. }
  482. return device;
  483. }
  484. /*
  485. * Wait queue for dasd_delete_device waits.
  486. */
  487. static DECLARE_WAIT_QUEUE_HEAD(dasd_delete_wq);
  488. /*
  489. * Remove a dasd device structure. The passed referenced
  490. * is destroyed.
  491. */
  492. void
  493. dasd_delete_device(struct dasd_device *device)
  494. {
  495. struct ccw_device *cdev;
  496. struct dasd_devmap *devmap;
  497. /* First remove device pointer from devmap. */
  498. devmap = dasd_find_busid(device->cdev->dev.bus_id);
  499. if (IS_ERR(devmap))
  500. BUG();
  501. spin_lock(&dasd_devmap_lock);
  502. if (devmap->device != device) {
  503. spin_unlock(&dasd_devmap_lock);
  504. dasd_put_device(device);
  505. return;
  506. }
  507. devmap->device = NULL;
  508. spin_unlock(&dasd_devmap_lock);
  509. /* Drop ref_count by 2, one for the devmap reference and
  510. * one for the passed reference. */
  511. atomic_sub(2, &device->ref_count);
  512. /* Wait for reference counter to drop to zero. */
  513. wait_event(dasd_delete_wq, atomic_read(&device->ref_count) == 0);
  514. /* Disconnect dasd_device structure from ccw_device structure. */
  515. cdev = device->cdev;
  516. device->cdev = NULL;
  517. /* Disconnect dasd_devmap structure from ccw_device structure. */
  518. cdev->dev.driver_data = NULL;
  519. /* Put ccw_device structure. */
  520. put_device(&cdev->dev);
  521. /* Now the device structure can be freed. */
  522. dasd_free_device(device);
  523. }
  524. /*
  525. * Reference counter dropped to zero. Wake up waiter
  526. * in dasd_delete_device.
  527. */
  528. void
  529. dasd_put_device_wake(struct dasd_device *device)
  530. {
  531. wake_up(&dasd_delete_wq);
  532. }
  533. /*
  534. * Return dasd_device structure associated with cdev.
  535. */
  536. struct dasd_device *
  537. dasd_device_from_cdev(struct ccw_device *cdev)
  538. {
  539. struct dasd_devmap *devmap;
  540. struct dasd_device *device;
  541. device = ERR_PTR(-ENODEV);
  542. spin_lock(&dasd_devmap_lock);
  543. devmap = cdev->dev.driver_data;
  544. if (devmap && devmap->device) {
  545. device = devmap->device;
  546. dasd_get_device(device);
  547. }
  548. spin_unlock(&dasd_devmap_lock);
  549. return device;
  550. }
  551. /*
  552. * SECTION: files in sysfs
  553. */
  554. /*
  555. * readonly controls the readonly status of a dasd
  556. */
  557. static ssize_t
  558. dasd_ro_show(struct device *dev, struct device_attribute *attr, char *buf)
  559. {
  560. struct dasd_devmap *devmap;
  561. int ro_flag;
  562. devmap = dasd_find_busid(dev->bus_id);
  563. if (!IS_ERR(devmap))
  564. ro_flag = (devmap->features & DASD_FEATURE_READONLY) != 0;
  565. else
  566. ro_flag = (DASD_FEATURE_DEFAULT & DASD_FEATURE_READONLY) != 0;
  567. return snprintf(buf, PAGE_SIZE, ro_flag ? "1\n" : "0\n");
  568. }
  569. static ssize_t
  570. dasd_ro_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  571. {
  572. struct dasd_devmap *devmap;
  573. int ro_flag;
  574. devmap = dasd_devmap_from_cdev(to_ccwdev(dev));
  575. if (IS_ERR(devmap))
  576. return PTR_ERR(devmap);
  577. ro_flag = buf[0] == '1';
  578. spin_lock(&dasd_devmap_lock);
  579. if (ro_flag)
  580. devmap->features |= DASD_FEATURE_READONLY;
  581. else
  582. devmap->features &= ~DASD_FEATURE_READONLY;
  583. if (devmap->device)
  584. devmap->device->features = devmap->features;
  585. if (devmap->device && devmap->device->gdp)
  586. set_disk_ro(devmap->device->gdp, ro_flag);
  587. spin_unlock(&dasd_devmap_lock);
  588. return count;
  589. }
  590. static DEVICE_ATTR(readonly, 0644, dasd_ro_show, dasd_ro_store);
  591. /*
  592. * use_diag controls whether the driver should use diag rather than ssch
  593. * to talk to the device
  594. */
  595. static ssize_t
  596. dasd_use_diag_show(struct device *dev, struct device_attribute *attr, char *buf)
  597. {
  598. struct dasd_devmap *devmap;
  599. int use_diag;
  600. devmap = dasd_find_busid(dev->bus_id);
  601. if (!IS_ERR(devmap))
  602. use_diag = (devmap->features & DASD_FEATURE_USEDIAG) != 0;
  603. else
  604. use_diag = (DASD_FEATURE_DEFAULT & DASD_FEATURE_USEDIAG) != 0;
  605. return sprintf(buf, use_diag ? "1\n" : "0\n");
  606. }
  607. static ssize_t
  608. dasd_use_diag_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  609. {
  610. struct dasd_devmap *devmap;
  611. ssize_t rc;
  612. int use_diag;
  613. devmap = dasd_devmap_from_cdev(to_ccwdev(dev));
  614. if (IS_ERR(devmap))
  615. return PTR_ERR(devmap);
  616. use_diag = buf[0] == '1';
  617. spin_lock(&dasd_devmap_lock);
  618. /* Changing diag discipline flag is only allowed in offline state. */
  619. rc = count;
  620. if (!devmap->device) {
  621. if (use_diag)
  622. devmap->features |= DASD_FEATURE_USEDIAG;
  623. else
  624. devmap->features &= ~DASD_FEATURE_USEDIAG;
  625. } else
  626. rc = -EPERM;
  627. spin_unlock(&dasd_devmap_lock);
  628. return rc;
  629. }
  630. static
  631. DEVICE_ATTR(use_diag, 0644, dasd_use_diag_show, dasd_use_diag_store);
  632. static ssize_t
  633. dasd_discipline_show(struct device *dev, struct device_attribute *attr, char *buf)
  634. {
  635. struct dasd_devmap *devmap;
  636. char *dname;
  637. spin_lock(&dasd_devmap_lock);
  638. dname = "none";
  639. devmap = dev->driver_data;
  640. if (devmap && devmap->device && devmap->device->discipline)
  641. dname = devmap->device->discipline->name;
  642. spin_unlock(&dasd_devmap_lock);
  643. return snprintf(buf, PAGE_SIZE, "%s\n", dname);
  644. }
  645. static DEVICE_ATTR(discipline, 0444, dasd_discipline_show, NULL);
  646. static struct attribute * dasd_attrs[] = {
  647. &dev_attr_readonly.attr,
  648. &dev_attr_discipline.attr,
  649. &dev_attr_use_diag.attr,
  650. NULL,
  651. };
  652. static struct attribute_group dasd_attr_group = {
  653. .attrs = dasd_attrs,
  654. };
  655. /*
  656. * Return value of the specified feature.
  657. */
  658. int
  659. dasd_get_feature(struct ccw_device *cdev, int feature)
  660. {
  661. struct dasd_devmap *devmap;
  662. devmap = dasd_find_busid(cdev->dev.bus_id);
  663. if (IS_ERR(devmap))
  664. return (int) PTR_ERR(devmap);
  665. return ((devmap->features & feature) != 0);
  666. }
  667. /*
  668. * Set / reset given feature.
  669. * Flag indicates wether to set (!=0) or the reset (=0) the feature.
  670. */
  671. int
  672. dasd_set_feature(struct ccw_device *cdev, int feature, int flag)
  673. {
  674. struct dasd_devmap *devmap;
  675. devmap = dasd_find_busid(cdev->dev.bus_id);
  676. if (IS_ERR(devmap))
  677. return (int) PTR_ERR(devmap);
  678. spin_lock(&dasd_devmap_lock);
  679. if (flag)
  680. devmap->features |= feature;
  681. else
  682. devmap->features &= ~feature;
  683. if (devmap->device)
  684. devmap->device->features = devmap->features;
  685. spin_unlock(&dasd_devmap_lock);
  686. return 0;
  687. }
  688. int
  689. dasd_add_sysfs_files(struct ccw_device *cdev)
  690. {
  691. return sysfs_create_group(&cdev->dev.kobj, &dasd_attr_group);
  692. }
  693. void
  694. dasd_remove_sysfs_files(struct ccw_device *cdev)
  695. {
  696. sysfs_remove_group(&cdev->dev.kobj, &dasd_attr_group);
  697. }
  698. int
  699. dasd_devmap_init(void)
  700. {
  701. int i;
  702. /* Initialize devmap structures. */
  703. dasd_max_devindex = 0;
  704. for (i = 0; i < 256; i++)
  705. INIT_LIST_HEAD(&dasd_hashlists[i]);
  706. return 0;
  707. }
  708. void
  709. dasd_devmap_exit(void)
  710. {
  711. dasd_forget_ranges();
  712. }