dasd_devmap.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797
  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.40 $
  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. 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 && devmap->device->gdp)
  584. set_disk_ro(devmap->device->gdp, ro_flag);
  585. spin_unlock(&dasd_devmap_lock);
  586. return count;
  587. }
  588. static DEVICE_ATTR(readonly, 0644, dasd_ro_show, dasd_ro_store);
  589. /*
  590. * use_diag controls whether the driver should use diag rather than ssch
  591. * to talk to the device
  592. */
  593. static ssize_t
  594. dasd_use_diag_show(struct device *dev, struct device_attribute *attr, char *buf)
  595. {
  596. struct dasd_devmap *devmap;
  597. int use_diag;
  598. devmap = dasd_find_busid(dev->bus_id);
  599. if (!IS_ERR(devmap))
  600. use_diag = (devmap->features & DASD_FEATURE_USEDIAG) != 0;
  601. else
  602. use_diag = (DASD_FEATURE_DEFAULT & DASD_FEATURE_USEDIAG) != 0;
  603. return sprintf(buf, use_diag ? "1\n" : "0\n");
  604. }
  605. static ssize_t
  606. dasd_use_diag_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  607. {
  608. struct dasd_devmap *devmap;
  609. ssize_t rc;
  610. int use_diag;
  611. devmap = dasd_devmap_from_cdev(to_ccwdev(dev));
  612. if (IS_ERR(devmap))
  613. return PTR_ERR(devmap);
  614. use_diag = buf[0] == '1';
  615. spin_lock(&dasd_devmap_lock);
  616. /* Changing diag discipline flag is only allowed in offline state. */
  617. rc = count;
  618. if (!devmap->device) {
  619. if (use_diag)
  620. devmap->features |= DASD_FEATURE_USEDIAG;
  621. else
  622. devmap->features &= ~DASD_FEATURE_USEDIAG;
  623. } else
  624. rc = -EPERM;
  625. spin_unlock(&dasd_devmap_lock);
  626. return rc;
  627. }
  628. static
  629. DEVICE_ATTR(use_diag, 0644, dasd_use_diag_show, dasd_use_diag_store);
  630. static ssize_t
  631. dasd_discipline_show(struct device *dev, struct device_attribute *attr, char *buf)
  632. {
  633. struct dasd_devmap *devmap;
  634. char *dname;
  635. spin_lock(&dasd_devmap_lock);
  636. dname = "none";
  637. devmap = dev->driver_data;
  638. if (devmap && devmap->device && devmap->device->discipline)
  639. dname = devmap->device->discipline->name;
  640. spin_unlock(&dasd_devmap_lock);
  641. return snprintf(buf, PAGE_SIZE, "%s\n", dname);
  642. }
  643. static DEVICE_ATTR(discipline, 0444, dasd_discipline_show, NULL);
  644. static struct attribute * dasd_attrs[] = {
  645. &dev_attr_readonly.attr,
  646. &dev_attr_discipline.attr,
  647. &dev_attr_use_diag.attr,
  648. NULL,
  649. };
  650. static struct attribute_group dasd_attr_group = {
  651. .attrs = dasd_attrs,
  652. };
  653. /*
  654. * Return value of the specified feature.
  655. */
  656. int
  657. dasd_get_feature(struct ccw_device *cdev, int feature)
  658. {
  659. struct dasd_devmap *devmap;
  660. devmap = dasd_find_busid(cdev->dev.bus_id);
  661. if (IS_ERR(devmap))
  662. return (int) PTR_ERR(devmap);
  663. return ((devmap->features & feature) != 0);
  664. }
  665. /*
  666. * Set / reset given feature.
  667. * Flag indicates wether to set (!=0) or the reset (=0) the feature.
  668. */
  669. int
  670. dasd_set_feature(struct ccw_device *cdev, int feature, int flag)
  671. {
  672. struct dasd_devmap *devmap;
  673. devmap = dasd_find_busid(cdev->dev.bus_id);
  674. if (IS_ERR(devmap))
  675. return (int) PTR_ERR(devmap);
  676. spin_lock(&dasd_devmap_lock);
  677. if (flag)
  678. devmap->features |= feature;
  679. else
  680. devmap->features &= ~feature;
  681. spin_unlock(&dasd_devmap_lock);
  682. return 0;
  683. }
  684. int
  685. dasd_add_sysfs_files(struct ccw_device *cdev)
  686. {
  687. return sysfs_create_group(&cdev->dev.kobj, &dasd_attr_group);
  688. }
  689. void
  690. dasd_remove_sysfs_files(struct ccw_device *cdev)
  691. {
  692. sysfs_remove_group(&cdev->dev.kobj, &dasd_attr_group);
  693. }
  694. int
  695. dasd_devmap_init(void)
  696. {
  697. int i;
  698. /* Initialize devmap structures. */
  699. dasd_max_devindex = 0;
  700. for (i = 0; i < 256; i++)
  701. INIT_LIST_HEAD(&dasd_hashlists[i]);
  702. return 0;
  703. }
  704. void
  705. dasd_devmap_exit(void)
  706. {
  707. dasd_forget_ranges();
  708. }