dasd_devmap.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841
  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. */
  15. #include <linux/config.h>
  16. #include <linux/ctype.h>
  17. #include <linux/init.h>
  18. #include <linux/module.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. module_param_array(dasd, charp, NULL, 0);
  65. /*
  66. * Single spinlock to protect devmap structures and lists.
  67. */
  68. static DEFINE_SPINLOCK(dasd_devmap_lock);
  69. /*
  70. * Hash lists for devmap structures.
  71. */
  72. static struct list_head dasd_hashlists[256];
  73. int dasd_max_devindex;
  74. static struct dasd_devmap *dasd_add_busid(char *, int);
  75. static inline int
  76. dasd_hash_busid(char *bus_id)
  77. {
  78. int hash, i;
  79. hash = 0;
  80. for (i = 0; (i < BUS_ID_SIZE) && *bus_id; i++, bus_id++)
  81. hash += *bus_id;
  82. return hash & 0xff;
  83. }
  84. #ifndef MODULE
  85. /*
  86. * The parameter parsing functions for builtin-drivers are called
  87. * before kmalloc works. Store the pointers to the parameters strings
  88. * into dasd[] for later processing.
  89. */
  90. static int __init
  91. dasd_call_setup(char *str)
  92. {
  93. static int count = 0;
  94. if (count < 256)
  95. dasd[count++] = str;
  96. return 1;
  97. }
  98. __setup ("dasd=", dasd_call_setup);
  99. #endif /* #ifndef MODULE */
  100. /*
  101. * Read a device busid/devno from a string.
  102. */
  103. static inline int
  104. dasd_busid(char **str, int *id0, int *id1, int *devno)
  105. {
  106. int val, old_style;
  107. /* check for leading '0x' */
  108. old_style = 0;
  109. if ((*str)[0] == '0' && (*str)[1] == 'x') {
  110. *str += 2;
  111. old_style = 1;
  112. }
  113. if (!isxdigit((*str)[0])) /* We require at least one hex digit */
  114. return -EINVAL;
  115. val = simple_strtoul(*str, str, 16);
  116. if (old_style || (*str)[0] != '.') {
  117. *id0 = *id1 = 0;
  118. if (val < 0 || val > 0xffff)
  119. return -EINVAL;
  120. *devno = val;
  121. return 0;
  122. }
  123. /* New style x.y.z busid */
  124. if (val < 0 || val > 0xff)
  125. return -EINVAL;
  126. *id0 = val;
  127. (*str)++;
  128. if (!isxdigit((*str)[0])) /* We require at least one hex digit */
  129. return -EINVAL;
  130. val = simple_strtoul(*str, str, 16);
  131. if (val < 0 || val > 0xff || (*str)++[0] != '.')
  132. return -EINVAL;
  133. *id1 = val;
  134. if (!isxdigit((*str)[0])) /* We require at least one hex digit */
  135. return -EINVAL;
  136. val = simple_strtoul(*str, str, 16);
  137. if (val < 0 || val > 0xffff)
  138. return -EINVAL;
  139. *devno = val;
  140. return 0;
  141. }
  142. /*
  143. * Read colon separated list of dasd features. Currently there is
  144. * only one: "ro" for read-only devices. The default feature set
  145. * is empty (value 0).
  146. */
  147. static inline int
  148. dasd_feature_list(char *str, char **endp)
  149. {
  150. int features, len, rc;
  151. rc = 0;
  152. if (*str != '(') {
  153. *endp = str;
  154. return DASD_FEATURE_DEFAULT;
  155. }
  156. str++;
  157. features = 0;
  158. while (1) {
  159. for (len = 0;
  160. str[len] && str[len] != ':' && str[len] != ')'; len++);
  161. if (len == 2 && !strncmp(str, "ro", 2))
  162. features |= DASD_FEATURE_READONLY;
  163. else if (len == 4 && !strncmp(str, "diag", 4))
  164. features |= DASD_FEATURE_USEDIAG;
  165. else {
  166. MESSAGE(KERN_WARNING,
  167. "unsupported feature: %*s, "
  168. "ignoring setting", len, str);
  169. rc = -EINVAL;
  170. }
  171. str += len;
  172. if (*str != ':')
  173. break;
  174. str++;
  175. }
  176. if (*str != ')') {
  177. MESSAGE(KERN_WARNING, "%s",
  178. "missing ')' in dasd parameter string\n");
  179. rc = -EINVAL;
  180. } else
  181. str++;
  182. *endp = str;
  183. if (rc != 0)
  184. return rc;
  185. return features;
  186. }
  187. /*
  188. * Try to match the first element on the comma separated parse string
  189. * with one of the known keywords. If a keyword is found, take the approprate
  190. * action and return a pointer to the residual string. If the first element
  191. * could not be matched to any keyword then return an error code.
  192. */
  193. static char *
  194. dasd_parse_keyword( char *parsestring ) {
  195. char *nextcomma, *residual_str;
  196. int length;
  197. nextcomma = strchr(parsestring,',');
  198. if (nextcomma) {
  199. length = nextcomma - parsestring;
  200. residual_str = nextcomma + 1;
  201. } else {
  202. length = strlen(parsestring);
  203. residual_str = parsestring + length;
  204. }
  205. if (strncmp ("autodetect", parsestring, length) == 0) {
  206. dasd_autodetect = 1;
  207. MESSAGE (KERN_INFO, "%s",
  208. "turning to autodetection mode");
  209. return residual_str;
  210. }
  211. if (strncmp ("probeonly", parsestring, length) == 0) {
  212. dasd_probeonly = 1;
  213. MESSAGE(KERN_INFO, "%s",
  214. "turning to probeonly mode");
  215. return residual_str;
  216. }
  217. if (strncmp ("fixedbuffers", parsestring, length) == 0) {
  218. if (dasd_page_cache)
  219. return residual_str;
  220. dasd_page_cache =
  221. kmem_cache_create("dasd_page_cache", PAGE_SIZE, 0,
  222. SLAB_CACHE_DMA, NULL, NULL );
  223. if (!dasd_page_cache)
  224. MESSAGE(KERN_WARNING, "%s", "Failed to create slab, "
  225. "fixed buffer mode disabled.");
  226. else
  227. MESSAGE (KERN_INFO, "%s",
  228. "turning on fixed buffer mode");
  229. return residual_str;
  230. }
  231. return ERR_PTR(-EINVAL);
  232. }
  233. /*
  234. * Try to interprete the first element on the comma separated parse string
  235. * as a device number or a range of devices. If the interpretation is
  236. * successfull, create the matching dasd_devmap entries and return a pointer
  237. * to the residual string.
  238. * If interpretation fails or in case of an error, return an error code.
  239. */
  240. static char *
  241. dasd_parse_range( char *parsestring ) {
  242. struct dasd_devmap *devmap;
  243. int from, from_id0, from_id1;
  244. int to, to_id0, to_id1;
  245. int features, rc;
  246. char bus_id[BUS_ID_SIZE+1], *str;
  247. str = parsestring;
  248. rc = dasd_busid(&str, &from_id0, &from_id1, &from);
  249. if (rc == 0) {
  250. to = from;
  251. to_id0 = from_id0;
  252. to_id1 = from_id1;
  253. if (*str == '-') {
  254. str++;
  255. rc = dasd_busid(&str, &to_id0, &to_id1, &to);
  256. }
  257. }
  258. if (rc == 0 &&
  259. (from_id0 != to_id0 || from_id1 != to_id1 || from > to))
  260. rc = -EINVAL;
  261. if (rc) {
  262. MESSAGE(KERN_ERR, "Invalid device range %s", parsestring);
  263. return ERR_PTR(rc);
  264. }
  265. features = dasd_feature_list(str, &str);
  266. if (features < 0)
  267. return ERR_PTR(-EINVAL);
  268. while (from <= to) {
  269. sprintf(bus_id, "%01x.%01x.%04x",
  270. from_id0, from_id1, from++);
  271. devmap = dasd_add_busid(bus_id, features);
  272. if (IS_ERR(devmap))
  273. return (char *)devmap;
  274. }
  275. if (*str == ',')
  276. return str + 1;
  277. if (*str == '\0')
  278. return str;
  279. MESSAGE(KERN_WARNING,
  280. "junk at end of dasd parameter string: %s\n", str);
  281. return ERR_PTR(-EINVAL);
  282. }
  283. static inline char *
  284. dasd_parse_next_element( char *parsestring ) {
  285. char * residual_str;
  286. residual_str = dasd_parse_keyword(parsestring);
  287. if (!IS_ERR(residual_str))
  288. return residual_str;
  289. residual_str = dasd_parse_range(parsestring);
  290. return residual_str;
  291. }
  292. /*
  293. * Parse parameters stored in dasd[]
  294. * The 'dasd=...' parameter allows to specify a comma separated list of
  295. * keywords and device ranges. When the dasd driver is build into the kernel,
  296. * the complete list will be stored as one element of the dasd[] array.
  297. * When the dasd driver is build as a module, then the list is broken into
  298. * it's elements and each dasd[] entry contains one element.
  299. */
  300. int
  301. dasd_parse(void)
  302. {
  303. int rc, i;
  304. char *parsestring;
  305. rc = 0;
  306. for (i = 0; i < 256; i++) {
  307. if (dasd[i] == NULL)
  308. break;
  309. parsestring = dasd[i];
  310. /* loop over the comma separated list in the parsestring */
  311. while (*parsestring) {
  312. parsestring = dasd_parse_next_element(parsestring);
  313. if(IS_ERR(parsestring)) {
  314. rc = PTR_ERR(parsestring);
  315. break;
  316. }
  317. }
  318. if (rc) {
  319. DBF_EVENT(DBF_ALERT, "%s", "invalid range found");
  320. break;
  321. }
  322. }
  323. return rc;
  324. }
  325. /*
  326. * Add a devmap for the device specified by busid. It is possible that
  327. * the devmap already exists (dasd= parameter). The order of the devices
  328. * added through this function will define the kdevs for the individual
  329. * devices.
  330. */
  331. static struct dasd_devmap *
  332. dasd_add_busid(char *bus_id, int features)
  333. {
  334. struct dasd_devmap *devmap, *new, *tmp;
  335. int hash;
  336. new = (struct dasd_devmap *)
  337. kmalloc(sizeof(struct dasd_devmap), GFP_KERNEL);
  338. if (!new)
  339. return ERR_PTR(-ENOMEM);
  340. spin_lock(&dasd_devmap_lock);
  341. devmap = 0;
  342. hash = dasd_hash_busid(bus_id);
  343. list_for_each_entry(tmp, &dasd_hashlists[hash], list)
  344. if (strncmp(tmp->bus_id, bus_id, BUS_ID_SIZE) == 0) {
  345. devmap = tmp;
  346. break;
  347. }
  348. if (!devmap) {
  349. /* This bus_id is new. */
  350. new->devindex = dasd_max_devindex++;
  351. strncpy(new->bus_id, bus_id, BUS_ID_SIZE);
  352. new->features = features;
  353. new->device = 0;
  354. list_add(&new->list, &dasd_hashlists[hash]);
  355. devmap = new;
  356. new = 0;
  357. }
  358. spin_unlock(&dasd_devmap_lock);
  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. BUG_ON(devmap->device != NULL);
  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. BUG_ON(IS_ERR(devmap));
  500. spin_lock(&dasd_devmap_lock);
  501. if (devmap->device != device) {
  502. spin_unlock(&dasd_devmap_lock);
  503. dasd_put_device(device);
  504. return;
  505. }
  506. devmap->device = NULL;
  507. spin_unlock(&dasd_devmap_lock);
  508. /* Drop ref_count by 2, one for the devmap reference and
  509. * one for the passed reference. */
  510. atomic_sub(2, &device->ref_count);
  511. /* Wait for reference counter to drop to zero. */
  512. wait_event(dasd_delete_wq, atomic_read(&device->ref_count) == 0);
  513. /* Disconnect dasd_device structure from ccw_device structure. */
  514. cdev = device->cdev;
  515. device->cdev = NULL;
  516. /* Disconnect dasd_devmap structure from ccw_device structure. */
  517. cdev->dev.driver_data = NULL;
  518. /* Put ccw_device structure. */
  519. put_device(&cdev->dev);
  520. /* Now the device structure can be freed. */
  521. dasd_free_device(device);
  522. }
  523. /*
  524. * Reference counter dropped to zero. Wake up waiter
  525. * in dasd_delete_device.
  526. */
  527. void
  528. dasd_put_device_wake(struct dasd_device *device)
  529. {
  530. wake_up(&dasd_delete_wq);
  531. }
  532. /*
  533. * Return dasd_device structure associated with cdev.
  534. */
  535. struct dasd_device *
  536. dasd_device_from_cdev(struct ccw_device *cdev)
  537. {
  538. struct dasd_devmap *devmap;
  539. struct dasd_device *device;
  540. device = ERR_PTR(-ENODEV);
  541. spin_lock(&dasd_devmap_lock);
  542. devmap = cdev->dev.driver_data;
  543. if (devmap && devmap->device) {
  544. device = devmap->device;
  545. dasd_get_device(device);
  546. }
  547. spin_unlock(&dasd_devmap_lock);
  548. return device;
  549. }
  550. /*
  551. * SECTION: files in sysfs
  552. */
  553. /*
  554. * readonly controls the readonly status of a dasd
  555. */
  556. static ssize_t
  557. dasd_ro_show(struct device *dev, struct device_attribute *attr, char *buf)
  558. {
  559. struct dasd_devmap *devmap;
  560. int ro_flag;
  561. devmap = dasd_find_busid(dev->bus_id);
  562. if (!IS_ERR(devmap))
  563. ro_flag = (devmap->features & DASD_FEATURE_READONLY) != 0;
  564. else
  565. ro_flag = (DASD_FEATURE_DEFAULT & DASD_FEATURE_READONLY) != 0;
  566. return snprintf(buf, PAGE_SIZE, ro_flag ? "1\n" : "0\n");
  567. }
  568. static ssize_t
  569. dasd_ro_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  570. {
  571. struct dasd_devmap *devmap;
  572. int ro_flag;
  573. devmap = dasd_devmap_from_cdev(to_ccwdev(dev));
  574. if (IS_ERR(devmap))
  575. return PTR_ERR(devmap);
  576. ro_flag = buf[0] == '1';
  577. spin_lock(&dasd_devmap_lock);
  578. if (ro_flag)
  579. devmap->features |= DASD_FEATURE_READONLY;
  580. else
  581. devmap->features &= ~DASD_FEATURE_READONLY;
  582. if (devmap->device)
  583. devmap->device->features = devmap->features;
  584. if (devmap->device && devmap->device->gdp)
  585. set_disk_ro(devmap->device->gdp, ro_flag);
  586. spin_unlock(&dasd_devmap_lock);
  587. return count;
  588. }
  589. static DEVICE_ATTR(readonly, 0644, dasd_ro_show, dasd_ro_store);
  590. /*
  591. * use_diag controls whether the driver should use diag rather than ssch
  592. * to talk to the device
  593. */
  594. static ssize_t
  595. dasd_use_diag_show(struct device *dev, struct device_attribute *attr, char *buf)
  596. {
  597. struct dasd_devmap *devmap;
  598. int use_diag;
  599. devmap = dasd_find_busid(dev->bus_id);
  600. if (!IS_ERR(devmap))
  601. use_diag = (devmap->features & DASD_FEATURE_USEDIAG) != 0;
  602. else
  603. use_diag = (DASD_FEATURE_DEFAULT & DASD_FEATURE_USEDIAG) != 0;
  604. return sprintf(buf, use_diag ? "1\n" : "0\n");
  605. }
  606. static ssize_t
  607. dasd_use_diag_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  608. {
  609. struct dasd_devmap *devmap;
  610. ssize_t rc;
  611. int use_diag;
  612. devmap = dasd_devmap_from_cdev(to_ccwdev(dev));
  613. if (IS_ERR(devmap))
  614. return PTR_ERR(devmap);
  615. use_diag = buf[0] == '1';
  616. spin_lock(&dasd_devmap_lock);
  617. /* Changing diag discipline flag is only allowed in offline state. */
  618. rc = count;
  619. if (!devmap->device) {
  620. if (use_diag)
  621. devmap->features |= DASD_FEATURE_USEDIAG;
  622. else
  623. devmap->features &= ~DASD_FEATURE_USEDIAG;
  624. } else
  625. rc = -EPERM;
  626. spin_unlock(&dasd_devmap_lock);
  627. return rc;
  628. }
  629. static
  630. DEVICE_ATTR(use_diag, 0644, dasd_use_diag_show, dasd_use_diag_store);
  631. static ssize_t
  632. dasd_discipline_show(struct device *dev, struct device_attribute *attr, char *buf)
  633. {
  634. struct dasd_devmap *devmap;
  635. char *dname;
  636. spin_lock(&dasd_devmap_lock);
  637. dname = "none";
  638. devmap = dev->driver_data;
  639. if (devmap && devmap->device && devmap->device->discipline)
  640. dname = devmap->device->discipline->name;
  641. spin_unlock(&dasd_devmap_lock);
  642. return snprintf(buf, PAGE_SIZE, "%s\n", dname);
  643. }
  644. static DEVICE_ATTR(discipline, 0444, dasd_discipline_show, NULL);
  645. /*
  646. * extended error-reporting
  647. */
  648. static ssize_t
  649. dasd_eer_show(struct device *dev, struct device_attribute *attr, char *buf)
  650. {
  651. struct dasd_devmap *devmap;
  652. int eer_flag;
  653. devmap = dasd_find_busid(dev->bus_id);
  654. if (!IS_ERR(devmap) && devmap->device)
  655. eer_flag = dasd_eer_enabled(devmap->device);
  656. else
  657. eer_flag = 0;
  658. return snprintf(buf, PAGE_SIZE, eer_flag ? "1\n" : "0\n");
  659. }
  660. static ssize_t
  661. dasd_eer_store(struct device *dev, struct device_attribute *attr,
  662. const char *buf, size_t count)
  663. {
  664. struct dasd_devmap *devmap;
  665. int rc;
  666. devmap = dasd_devmap_from_cdev(to_ccwdev(dev));
  667. if (IS_ERR(devmap))
  668. return PTR_ERR(devmap);
  669. if (!devmap->device)
  670. return count;
  671. if (buf[0] == '1') {
  672. rc = dasd_eer_enable(devmap->device);
  673. if (rc)
  674. return rc;
  675. } else
  676. dasd_eer_disable(devmap->device);
  677. return count;
  678. }
  679. static DEVICE_ATTR(eer_enabled, 0644, dasd_eer_show, dasd_eer_store);
  680. static struct attribute * dasd_attrs[] = {
  681. &dev_attr_readonly.attr,
  682. &dev_attr_discipline.attr,
  683. &dev_attr_use_diag.attr,
  684. &dev_attr_eer_enabled.attr,
  685. NULL,
  686. };
  687. static struct attribute_group dasd_attr_group = {
  688. .attrs = dasd_attrs,
  689. };
  690. /*
  691. * Return value of the specified feature.
  692. */
  693. int
  694. dasd_get_feature(struct ccw_device *cdev, int feature)
  695. {
  696. struct dasd_devmap *devmap;
  697. devmap = dasd_find_busid(cdev->dev.bus_id);
  698. if (IS_ERR(devmap))
  699. return (int) PTR_ERR(devmap);
  700. return ((devmap->features & feature) != 0);
  701. }
  702. /*
  703. * Set / reset given feature.
  704. * Flag indicates wether to set (!=0) or the reset (=0) the feature.
  705. */
  706. int
  707. dasd_set_feature(struct ccw_device *cdev, int feature, int flag)
  708. {
  709. struct dasd_devmap *devmap;
  710. devmap = dasd_find_busid(cdev->dev.bus_id);
  711. if (IS_ERR(devmap))
  712. return (int) PTR_ERR(devmap);
  713. spin_lock(&dasd_devmap_lock);
  714. if (flag)
  715. devmap->features |= feature;
  716. else
  717. devmap->features &= ~feature;
  718. if (devmap->device)
  719. devmap->device->features = devmap->features;
  720. spin_unlock(&dasd_devmap_lock);
  721. return 0;
  722. }
  723. int
  724. dasd_add_sysfs_files(struct ccw_device *cdev)
  725. {
  726. return sysfs_create_group(&cdev->dev.kobj, &dasd_attr_group);
  727. }
  728. void
  729. dasd_remove_sysfs_files(struct ccw_device *cdev)
  730. {
  731. sysfs_remove_group(&cdev->dev.kobj, &dasd_attr_group);
  732. }
  733. int
  734. dasd_devmap_init(void)
  735. {
  736. int i;
  737. /* Initialize devmap structures. */
  738. dasd_max_devindex = 0;
  739. for (i = 0; i < 256; i++)
  740. INIT_LIST_HEAD(&dasd_hashlists[i]);
  741. return 0;
  742. }
  743. void
  744. dasd_devmap_exit(void)
  745. {
  746. dasd_forget_ranges();
  747. }