dasd_devmap.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801
  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. if (new)
  359. kfree(new);
  360. return devmap;
  361. }
  362. /*
  363. * Find devmap for device with given bus_id.
  364. */
  365. static struct dasd_devmap *
  366. dasd_find_busid(char *bus_id)
  367. {
  368. struct dasd_devmap *devmap, *tmp;
  369. int hash;
  370. spin_lock(&dasd_devmap_lock);
  371. devmap = ERR_PTR(-ENODEV);
  372. hash = dasd_hash_busid(bus_id);
  373. list_for_each_entry(tmp, &dasd_hashlists[hash], list) {
  374. if (strncmp(tmp->bus_id, bus_id, BUS_ID_SIZE) == 0) {
  375. devmap = tmp;
  376. break;
  377. }
  378. }
  379. spin_unlock(&dasd_devmap_lock);
  380. return devmap;
  381. }
  382. /*
  383. * Check if busid has been added to the list of dasd ranges.
  384. */
  385. int
  386. dasd_busid_known(char *bus_id)
  387. {
  388. return IS_ERR(dasd_find_busid(bus_id)) ? -ENOENT : 0;
  389. }
  390. /*
  391. * Forget all about the device numbers added so far.
  392. * This may only be called at module unload or system shutdown.
  393. */
  394. static void
  395. dasd_forget_ranges(void)
  396. {
  397. struct dasd_devmap *devmap, *n;
  398. int i;
  399. spin_lock(&dasd_devmap_lock);
  400. for (i = 0; i < 256; i++) {
  401. list_for_each_entry_safe(devmap, n, &dasd_hashlists[i], list) {
  402. if (devmap->device != NULL)
  403. BUG();
  404. list_del(&devmap->list);
  405. kfree(devmap);
  406. }
  407. }
  408. spin_unlock(&dasd_devmap_lock);
  409. }
  410. /*
  411. * Find the device struct by its device index.
  412. */
  413. struct dasd_device *
  414. dasd_device_from_devindex(int devindex)
  415. {
  416. struct dasd_devmap *devmap, *tmp;
  417. struct dasd_device *device;
  418. int i;
  419. spin_lock(&dasd_devmap_lock);
  420. devmap = 0;
  421. for (i = 0; (i < 256) && !devmap; i++)
  422. list_for_each_entry(tmp, &dasd_hashlists[i], list)
  423. if (tmp->devindex == devindex) {
  424. /* Found the devmap for the device. */
  425. devmap = tmp;
  426. break;
  427. }
  428. if (devmap && devmap->device) {
  429. device = devmap->device;
  430. dasd_get_device(device);
  431. } else
  432. device = ERR_PTR(-ENODEV);
  433. spin_unlock(&dasd_devmap_lock);
  434. return device;
  435. }
  436. /*
  437. * Return devmap for cdev. If no devmap exists yet, create one and
  438. * connect it to the cdev.
  439. */
  440. static struct dasd_devmap *
  441. dasd_devmap_from_cdev(struct ccw_device *cdev)
  442. {
  443. struct dasd_devmap *devmap;
  444. devmap = dasd_find_busid(cdev->dev.bus_id);
  445. if (IS_ERR(devmap))
  446. devmap = dasd_add_busid(cdev->dev.bus_id,
  447. DASD_FEATURE_DEFAULT);
  448. return devmap;
  449. }
  450. /*
  451. * Create a dasd device structure for cdev.
  452. */
  453. struct dasd_device *
  454. dasd_create_device(struct ccw_device *cdev)
  455. {
  456. struct dasd_devmap *devmap;
  457. struct dasd_device *device;
  458. int rc;
  459. devmap = dasd_devmap_from_cdev(cdev);
  460. if (IS_ERR(devmap))
  461. return (void *) devmap;
  462. cdev->dev.driver_data = devmap;
  463. device = dasd_alloc_device();
  464. if (IS_ERR(device))
  465. return device;
  466. atomic_set(&device->ref_count, 2);
  467. spin_lock(&dasd_devmap_lock);
  468. if (!devmap->device) {
  469. devmap->device = device;
  470. device->devindex = devmap->devindex;
  471. device->features = devmap->features;
  472. get_device(&cdev->dev);
  473. device->cdev = cdev;
  474. rc = 0;
  475. } else
  476. /* Someone else was faster. */
  477. rc = -EBUSY;
  478. spin_unlock(&dasd_devmap_lock);
  479. if (rc) {
  480. dasd_free_device(device);
  481. return ERR_PTR(rc);
  482. }
  483. return device;
  484. }
  485. /*
  486. * Wait queue for dasd_delete_device waits.
  487. */
  488. static DECLARE_WAIT_QUEUE_HEAD(dasd_delete_wq);
  489. /*
  490. * Remove a dasd device structure. The passed referenced
  491. * is destroyed.
  492. */
  493. void
  494. dasd_delete_device(struct dasd_device *device)
  495. {
  496. struct ccw_device *cdev;
  497. struct dasd_devmap *devmap;
  498. /* First remove device pointer from devmap. */
  499. devmap = dasd_find_busid(device->cdev->dev.bus_id);
  500. if (IS_ERR(devmap))
  501. BUG();
  502. spin_lock(&dasd_devmap_lock);
  503. if (devmap->device != device) {
  504. spin_unlock(&dasd_devmap_lock);
  505. dasd_put_device(device);
  506. return;
  507. }
  508. devmap->device = NULL;
  509. spin_unlock(&dasd_devmap_lock);
  510. /* Drop ref_count by 2, one for the devmap reference and
  511. * one for the passed reference. */
  512. atomic_sub(2, &device->ref_count);
  513. /* Wait for reference counter to drop to zero. */
  514. wait_event(dasd_delete_wq, atomic_read(&device->ref_count) == 0);
  515. /* Disconnect dasd_device structure from ccw_device structure. */
  516. cdev = device->cdev;
  517. device->cdev = NULL;
  518. /* Disconnect dasd_devmap structure from ccw_device structure. */
  519. cdev->dev.driver_data = NULL;
  520. /* Put ccw_device structure. */
  521. put_device(&cdev->dev);
  522. /* Now the device structure can be freed. */
  523. dasd_free_device(device);
  524. }
  525. /*
  526. * Reference counter dropped to zero. Wake up waiter
  527. * in dasd_delete_device.
  528. */
  529. void
  530. dasd_put_device_wake(struct dasd_device *device)
  531. {
  532. wake_up(&dasd_delete_wq);
  533. }
  534. /*
  535. * Return dasd_device structure associated with cdev.
  536. */
  537. struct dasd_device *
  538. dasd_device_from_cdev(struct ccw_device *cdev)
  539. {
  540. struct dasd_devmap *devmap;
  541. struct dasd_device *device;
  542. device = ERR_PTR(-ENODEV);
  543. spin_lock(&dasd_devmap_lock);
  544. devmap = cdev->dev.driver_data;
  545. if (devmap && devmap->device) {
  546. device = devmap->device;
  547. dasd_get_device(device);
  548. }
  549. spin_unlock(&dasd_devmap_lock);
  550. return device;
  551. }
  552. /*
  553. * SECTION: files in sysfs
  554. */
  555. /*
  556. * readonly controls the readonly status of a dasd
  557. */
  558. static ssize_t
  559. dasd_ro_show(struct device *dev, struct device_attribute *attr, char *buf)
  560. {
  561. struct dasd_devmap *devmap;
  562. int ro_flag;
  563. devmap = dasd_find_busid(dev->bus_id);
  564. if (!IS_ERR(devmap))
  565. ro_flag = (devmap->features & DASD_FEATURE_READONLY) != 0;
  566. else
  567. ro_flag = (DASD_FEATURE_DEFAULT & DASD_FEATURE_READONLY) != 0;
  568. return snprintf(buf, PAGE_SIZE, ro_flag ? "1\n" : "0\n");
  569. }
  570. static ssize_t
  571. dasd_ro_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  572. {
  573. struct dasd_devmap *devmap;
  574. int ro_flag;
  575. devmap = dasd_devmap_from_cdev(to_ccwdev(dev));
  576. if (IS_ERR(devmap))
  577. return PTR_ERR(devmap);
  578. ro_flag = buf[0] == '1';
  579. spin_lock(&dasd_devmap_lock);
  580. if (ro_flag)
  581. devmap->features |= DASD_FEATURE_READONLY;
  582. else
  583. devmap->features &= ~DASD_FEATURE_READONLY;
  584. if (devmap->device)
  585. devmap->device->features = devmap->features;
  586. if (devmap->device && devmap->device->gdp)
  587. set_disk_ro(devmap->device->gdp, ro_flag);
  588. spin_unlock(&dasd_devmap_lock);
  589. return count;
  590. }
  591. static DEVICE_ATTR(readonly, 0644, dasd_ro_show, dasd_ro_store);
  592. /*
  593. * use_diag controls whether the driver should use diag rather than ssch
  594. * to talk to the device
  595. */
  596. static ssize_t
  597. dasd_use_diag_show(struct device *dev, struct device_attribute *attr, char *buf)
  598. {
  599. struct dasd_devmap *devmap;
  600. int use_diag;
  601. devmap = dasd_find_busid(dev->bus_id);
  602. if (!IS_ERR(devmap))
  603. use_diag = (devmap->features & DASD_FEATURE_USEDIAG) != 0;
  604. else
  605. use_diag = (DASD_FEATURE_DEFAULT & DASD_FEATURE_USEDIAG) != 0;
  606. return sprintf(buf, use_diag ? "1\n" : "0\n");
  607. }
  608. static ssize_t
  609. dasd_use_diag_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  610. {
  611. struct dasd_devmap *devmap;
  612. ssize_t rc;
  613. int use_diag;
  614. devmap = dasd_devmap_from_cdev(to_ccwdev(dev));
  615. if (IS_ERR(devmap))
  616. return PTR_ERR(devmap);
  617. use_diag = buf[0] == '1';
  618. spin_lock(&dasd_devmap_lock);
  619. /* Changing diag discipline flag is only allowed in offline state. */
  620. rc = count;
  621. if (!devmap->device) {
  622. if (use_diag)
  623. devmap->features |= DASD_FEATURE_USEDIAG;
  624. else
  625. devmap->features &= ~DASD_FEATURE_USEDIAG;
  626. } else
  627. rc = -EPERM;
  628. spin_unlock(&dasd_devmap_lock);
  629. return rc;
  630. }
  631. static
  632. DEVICE_ATTR(use_diag, 0644, dasd_use_diag_show, dasd_use_diag_store);
  633. static ssize_t
  634. dasd_discipline_show(struct device *dev, struct device_attribute *attr, char *buf)
  635. {
  636. struct dasd_devmap *devmap;
  637. char *dname;
  638. spin_lock(&dasd_devmap_lock);
  639. dname = "none";
  640. devmap = dev->driver_data;
  641. if (devmap && devmap->device && devmap->device->discipline)
  642. dname = devmap->device->discipline->name;
  643. spin_unlock(&dasd_devmap_lock);
  644. return snprintf(buf, PAGE_SIZE, "%s\n", dname);
  645. }
  646. static DEVICE_ATTR(discipline, 0444, dasd_discipline_show, NULL);
  647. static struct attribute * dasd_attrs[] = {
  648. &dev_attr_readonly.attr,
  649. &dev_attr_discipline.attr,
  650. &dev_attr_use_diag.attr,
  651. NULL,
  652. };
  653. static struct attribute_group dasd_attr_group = {
  654. .attrs = dasd_attrs,
  655. };
  656. /*
  657. * Return value of the specified feature.
  658. */
  659. int
  660. dasd_get_feature(struct ccw_device *cdev, int feature)
  661. {
  662. struct dasd_devmap *devmap;
  663. devmap = dasd_find_busid(cdev->dev.bus_id);
  664. if (IS_ERR(devmap))
  665. return (int) PTR_ERR(devmap);
  666. return ((devmap->features & feature) != 0);
  667. }
  668. /*
  669. * Set / reset given feature.
  670. * Flag indicates wether to set (!=0) or the reset (=0) the feature.
  671. */
  672. int
  673. dasd_set_feature(struct ccw_device *cdev, int feature, int flag)
  674. {
  675. struct dasd_devmap *devmap;
  676. devmap = dasd_find_busid(cdev->dev.bus_id);
  677. if (IS_ERR(devmap))
  678. return (int) PTR_ERR(devmap);
  679. spin_lock(&dasd_devmap_lock);
  680. if (flag)
  681. devmap->features |= feature;
  682. else
  683. devmap->features &= ~feature;
  684. if (devmap->device)
  685. devmap->device->features = devmap->features;
  686. spin_unlock(&dasd_devmap_lock);
  687. return 0;
  688. }
  689. int
  690. dasd_add_sysfs_files(struct ccw_device *cdev)
  691. {
  692. return sysfs_create_group(&cdev->dev.kobj, &dasd_attr_group);
  693. }
  694. void
  695. dasd_remove_sysfs_files(struct ccw_device *cdev)
  696. {
  697. sysfs_remove_group(&cdev->dev.kobj, &dasd_attr_group);
  698. }
  699. int
  700. dasd_devmap_init(void)
  701. {
  702. int i;
  703. /* Initialize devmap structures. */
  704. dasd_max_devindex = 0;
  705. for (i = 0; i < 256; i++)
  706. INIT_LIST_HEAD(&dasd_hashlists[i]);
  707. return 0;
  708. }
  709. void
  710. dasd_devmap_exit(void)
  711. {
  712. dasd_forget_ranges();
  713. }