dasd_devmap.c 34 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399
  1. /*
  2. * Author(s)......: Holger Smolinski <Holger.Smolinski@de.ibm.com>
  3. * Horst Hummel <Horst.Hummel@de.ibm.com>
  4. * Carsten Otte <Cotte@de.ibm.com>
  5. * Martin Schwidefsky <schwidefsky@de.ibm.com>
  6. * Bugreports.to..: <Linux390@de.ibm.com>
  7. * Copyright IBM Corp. 1999,2001
  8. *
  9. * Device mapping and dasd= parameter parsing functions. All devmap
  10. * functions may not be called from interrupt context. In particular
  11. * dasd_get_device is a no-no from interrupt context.
  12. *
  13. */
  14. #define KMSG_COMPONENT "dasd"
  15. #include <linux/ctype.h>
  16. #include <linux/init.h>
  17. #include <linux/module.h>
  18. #include <linux/slab.h>
  19. #include <asm/debug.h>
  20. #include <asm/uaccess.h>
  21. #include <asm/ipl.h>
  22. /* This is ugly... */
  23. #define PRINTK_HEADER "dasd_devmap:"
  24. #define DASD_BUS_ID_SIZE 20
  25. #include "dasd_int.h"
  26. struct kmem_cache *dasd_page_cache;
  27. EXPORT_SYMBOL_GPL(dasd_page_cache);
  28. /*
  29. * dasd_devmap_t is used to store the features and the relation
  30. * between device number and device index. To find a dasd_devmap_t
  31. * that corresponds to a device number of a device index each
  32. * dasd_devmap_t is added to two linked lists, one to search by
  33. * the device number and one to search by the device index. As
  34. * soon as big minor numbers are available the device index list
  35. * can be removed since the device number will then be identical
  36. * to the device index.
  37. */
  38. struct dasd_devmap {
  39. struct list_head list;
  40. char bus_id[DASD_BUS_ID_SIZE];
  41. unsigned int devindex;
  42. unsigned short features;
  43. struct dasd_device *device;
  44. };
  45. /*
  46. * Parameter parsing functions for dasd= parameter. The syntax is:
  47. * <devno> : (0x)?[0-9a-fA-F]+
  48. * <busid> : [0-0a-f]\.[0-9a-f]\.(0x)?[0-9a-fA-F]+
  49. * <feature> : ro
  50. * <feature_list> : \(<feature>(:<feature>)*\)
  51. * <devno-range> : <devno>(-<devno>)?<feature_list>?
  52. * <busid-range> : <busid>(-<busid>)?<feature_list>?
  53. * <devices> : <devno-range>|<busid-range>
  54. * <dasd_module> : dasd_diag_mod|dasd_eckd_mod|dasd_fba_mod
  55. *
  56. * <dasd> : autodetect|probeonly|<devices>(,<devices>)*
  57. */
  58. int dasd_probeonly = 0; /* is true, when probeonly mode is active */
  59. int dasd_autodetect = 0; /* is true, when autodetection is active */
  60. int dasd_nopav = 0; /* is true, when PAV is disabled */
  61. EXPORT_SYMBOL_GPL(dasd_nopav);
  62. int dasd_nofcx; /* disable High Performance Ficon */
  63. EXPORT_SYMBOL_GPL(dasd_nofcx);
  64. /*
  65. * char *dasd[] is intended to hold the ranges supplied by the dasd= statement
  66. * it is named 'dasd' to directly be filled by insmod with the comma separated
  67. * strings when running as a module.
  68. */
  69. static char *dasd[256];
  70. module_param_array(dasd, charp, NULL, 0);
  71. /*
  72. * Single spinlock to protect devmap and servermap structures and lists.
  73. */
  74. static DEFINE_SPINLOCK(dasd_devmap_lock);
  75. /*
  76. * Hash lists for devmap structures.
  77. */
  78. static struct list_head dasd_hashlists[256];
  79. int dasd_max_devindex;
  80. static struct dasd_devmap *dasd_add_busid(const char *, int);
  81. static inline int
  82. dasd_hash_busid(const char *bus_id)
  83. {
  84. int hash, i;
  85. hash = 0;
  86. for (i = 0; (i < DASD_BUS_ID_SIZE) && *bus_id; i++, bus_id++)
  87. hash += *bus_id;
  88. return hash & 0xff;
  89. }
  90. #ifndef MODULE
  91. /*
  92. * The parameter parsing functions for builtin-drivers are called
  93. * before kmalloc works. Store the pointers to the parameters strings
  94. * into dasd[] for later processing.
  95. */
  96. static int __init
  97. dasd_call_setup(char *str)
  98. {
  99. static int count = 0;
  100. if (count < 256)
  101. dasd[count++] = str;
  102. return 1;
  103. }
  104. __setup ("dasd=", dasd_call_setup);
  105. #endif /* #ifndef MODULE */
  106. #define DASD_IPLDEV "ipldev"
  107. /*
  108. * Read a device busid/devno from a string.
  109. */
  110. static int
  111. dasd_busid(char **str, int *id0, int *id1, int *devno)
  112. {
  113. int val, old_style;
  114. /* Interpret ipldev busid */
  115. if (strncmp(DASD_IPLDEV, *str, strlen(DASD_IPLDEV)) == 0) {
  116. if (ipl_info.type != IPL_TYPE_CCW) {
  117. pr_err("The IPL device is not a CCW device\n");
  118. return -EINVAL;
  119. }
  120. *id0 = 0;
  121. *id1 = ipl_info.data.ccw.dev_id.ssid;
  122. *devno = ipl_info.data.ccw.dev_id.devno;
  123. *str += strlen(DASD_IPLDEV);
  124. return 0;
  125. }
  126. /* check for leading '0x' */
  127. old_style = 0;
  128. if ((*str)[0] == '0' && (*str)[1] == 'x') {
  129. *str += 2;
  130. old_style = 1;
  131. }
  132. if (!isxdigit((*str)[0])) /* We require at least one hex digit */
  133. return -EINVAL;
  134. val = simple_strtoul(*str, str, 16);
  135. if (old_style || (*str)[0] != '.') {
  136. *id0 = *id1 = 0;
  137. if (val < 0 || val > 0xffff)
  138. return -EINVAL;
  139. *devno = val;
  140. return 0;
  141. }
  142. /* New style x.y.z busid */
  143. if (val < 0 || val > 0xff)
  144. return -EINVAL;
  145. *id0 = val;
  146. (*str)++;
  147. if (!isxdigit((*str)[0])) /* We require at least one hex digit */
  148. return -EINVAL;
  149. val = simple_strtoul(*str, str, 16);
  150. if (val < 0 || val > 0xff || (*str)++[0] != '.')
  151. return -EINVAL;
  152. *id1 = val;
  153. if (!isxdigit((*str)[0])) /* We require at least one hex digit */
  154. return -EINVAL;
  155. val = simple_strtoul(*str, str, 16);
  156. if (val < 0 || val > 0xffff)
  157. return -EINVAL;
  158. *devno = val;
  159. return 0;
  160. }
  161. /*
  162. * Read colon separated list of dasd features. Currently there is
  163. * only one: "ro" for read-only devices. The default feature set
  164. * is empty (value 0).
  165. */
  166. static int
  167. dasd_feature_list(char *str, char **endp)
  168. {
  169. int features, len, rc;
  170. rc = 0;
  171. if (*str != '(') {
  172. *endp = str;
  173. return DASD_FEATURE_DEFAULT;
  174. }
  175. str++;
  176. features = 0;
  177. while (1) {
  178. for (len = 0;
  179. str[len] && str[len] != ':' && str[len] != ')'; len++);
  180. if (len == 2 && !strncmp(str, "ro", 2))
  181. features |= DASD_FEATURE_READONLY;
  182. else if (len == 4 && !strncmp(str, "diag", 4))
  183. features |= DASD_FEATURE_USEDIAG;
  184. else if (len == 3 && !strncmp(str, "raw", 3))
  185. features |= DASD_FEATURE_USERAW;
  186. else if (len == 6 && !strncmp(str, "erplog", 6))
  187. features |= DASD_FEATURE_ERPLOG;
  188. else if (len == 8 && !strncmp(str, "failfast", 8))
  189. features |= DASD_FEATURE_FAILFAST;
  190. else {
  191. pr_warning("%*s is not a supported device option\n",
  192. len, str);
  193. rc = -EINVAL;
  194. }
  195. str += len;
  196. if (*str != ':')
  197. break;
  198. str++;
  199. }
  200. if (*str != ')') {
  201. pr_warning("A closing parenthesis ')' is missing in the "
  202. "dasd= parameter\n");
  203. rc = -EINVAL;
  204. } else
  205. str++;
  206. *endp = str;
  207. if (rc != 0)
  208. return rc;
  209. return features;
  210. }
  211. /*
  212. * Try to match the first element on the comma separated parse string
  213. * with one of the known keywords. If a keyword is found, take the approprate
  214. * action and return a pointer to the residual string. If the first element
  215. * could not be matched to any keyword then return an error code.
  216. */
  217. static char *
  218. dasd_parse_keyword( char *parsestring ) {
  219. char *nextcomma, *residual_str;
  220. int length;
  221. nextcomma = strchr(parsestring,',');
  222. if (nextcomma) {
  223. length = nextcomma - parsestring;
  224. residual_str = nextcomma + 1;
  225. } else {
  226. length = strlen(parsestring);
  227. residual_str = parsestring + length;
  228. }
  229. if (strncmp("autodetect", parsestring, length) == 0) {
  230. dasd_autodetect = 1;
  231. pr_info("The autodetection mode has been activated\n");
  232. return residual_str;
  233. }
  234. if (strncmp("probeonly", parsestring, length) == 0) {
  235. dasd_probeonly = 1;
  236. pr_info("The probeonly mode has been activated\n");
  237. return residual_str;
  238. }
  239. if (strncmp("nopav", parsestring, length) == 0) {
  240. if (MACHINE_IS_VM)
  241. pr_info("'nopav' is not supported on z/VM\n");
  242. else {
  243. dasd_nopav = 1;
  244. pr_info("PAV support has be deactivated\n");
  245. }
  246. return residual_str;
  247. }
  248. if (strncmp("nofcx", parsestring, length) == 0) {
  249. dasd_nofcx = 1;
  250. pr_info("High Performance FICON support has been "
  251. "deactivated\n");
  252. return residual_str;
  253. }
  254. if (strncmp("fixedbuffers", parsestring, length) == 0) {
  255. if (dasd_page_cache)
  256. return residual_str;
  257. dasd_page_cache =
  258. kmem_cache_create("dasd_page_cache", PAGE_SIZE,
  259. PAGE_SIZE, SLAB_CACHE_DMA,
  260. NULL);
  261. if (!dasd_page_cache)
  262. DBF_EVENT(DBF_WARNING, "%s", "Failed to create slab, "
  263. "fixed buffer mode disabled.");
  264. else
  265. DBF_EVENT(DBF_INFO, "%s",
  266. "turning on fixed buffer mode");
  267. return residual_str;
  268. }
  269. return ERR_PTR(-EINVAL);
  270. }
  271. /*
  272. * Try to interprete the first element on the comma separated parse string
  273. * as a device number or a range of devices. If the interpretation is
  274. * successful, create the matching dasd_devmap entries and return a pointer
  275. * to the residual string.
  276. * If interpretation fails or in case of an error, return an error code.
  277. */
  278. static char *
  279. dasd_parse_range( char *parsestring ) {
  280. struct dasd_devmap *devmap;
  281. int from, from_id0, from_id1;
  282. int to, to_id0, to_id1;
  283. int features, rc;
  284. char bus_id[DASD_BUS_ID_SIZE+1], *str;
  285. str = parsestring;
  286. rc = dasd_busid(&str, &from_id0, &from_id1, &from);
  287. if (rc == 0) {
  288. to = from;
  289. to_id0 = from_id0;
  290. to_id1 = from_id1;
  291. if (*str == '-') {
  292. str++;
  293. rc = dasd_busid(&str, &to_id0, &to_id1, &to);
  294. }
  295. }
  296. if (rc == 0 &&
  297. (from_id0 != to_id0 || from_id1 != to_id1 || from > to))
  298. rc = -EINVAL;
  299. if (rc) {
  300. pr_err("%s is not a valid device range\n", parsestring);
  301. return ERR_PTR(rc);
  302. }
  303. features = dasd_feature_list(str, &str);
  304. if (features < 0)
  305. return ERR_PTR(-EINVAL);
  306. /* each device in dasd= parameter should be set initially online */
  307. features |= DASD_FEATURE_INITIAL_ONLINE;
  308. while (from <= to) {
  309. sprintf(bus_id, "%01x.%01x.%04x",
  310. from_id0, from_id1, from++);
  311. devmap = dasd_add_busid(bus_id, features);
  312. if (IS_ERR(devmap))
  313. return (char *)devmap;
  314. }
  315. if (*str == ',')
  316. return str + 1;
  317. if (*str == '\0')
  318. return str;
  319. pr_warning("The dasd= parameter value %s has an invalid ending\n",
  320. str);
  321. return ERR_PTR(-EINVAL);
  322. }
  323. static char *
  324. dasd_parse_next_element( char *parsestring ) {
  325. char * residual_str;
  326. residual_str = dasd_parse_keyword(parsestring);
  327. if (!IS_ERR(residual_str))
  328. return residual_str;
  329. residual_str = dasd_parse_range(parsestring);
  330. return residual_str;
  331. }
  332. /*
  333. * Parse parameters stored in dasd[]
  334. * The 'dasd=...' parameter allows to specify a comma separated list of
  335. * keywords and device ranges. When the dasd driver is build into the kernel,
  336. * the complete list will be stored as one element of the dasd[] array.
  337. * When the dasd driver is build as a module, then the list is broken into
  338. * it's elements and each dasd[] entry contains one element.
  339. */
  340. int
  341. dasd_parse(void)
  342. {
  343. int rc, i;
  344. char *parsestring;
  345. rc = 0;
  346. for (i = 0; i < 256; i++) {
  347. if (dasd[i] == NULL)
  348. break;
  349. parsestring = dasd[i];
  350. /* loop over the comma separated list in the parsestring */
  351. while (*parsestring) {
  352. parsestring = dasd_parse_next_element(parsestring);
  353. if(IS_ERR(parsestring)) {
  354. rc = PTR_ERR(parsestring);
  355. break;
  356. }
  357. }
  358. if (rc) {
  359. DBF_EVENT(DBF_ALERT, "%s", "invalid range found");
  360. break;
  361. }
  362. }
  363. return rc;
  364. }
  365. /*
  366. * Add a devmap for the device specified by busid. It is possible that
  367. * the devmap already exists (dasd= parameter). The order of the devices
  368. * added through this function will define the kdevs for the individual
  369. * devices.
  370. */
  371. static struct dasd_devmap *
  372. dasd_add_busid(const char *bus_id, int features)
  373. {
  374. struct dasd_devmap *devmap, *new, *tmp;
  375. int hash;
  376. new = (struct dasd_devmap *)
  377. kzalloc(sizeof(struct dasd_devmap), GFP_KERNEL);
  378. if (!new)
  379. return ERR_PTR(-ENOMEM);
  380. spin_lock(&dasd_devmap_lock);
  381. devmap = NULL;
  382. hash = dasd_hash_busid(bus_id);
  383. list_for_each_entry(tmp, &dasd_hashlists[hash], list)
  384. if (strncmp(tmp->bus_id, bus_id, DASD_BUS_ID_SIZE) == 0) {
  385. devmap = tmp;
  386. break;
  387. }
  388. if (!devmap) {
  389. /* This bus_id is new. */
  390. new->devindex = dasd_max_devindex++;
  391. strncpy(new->bus_id, bus_id, DASD_BUS_ID_SIZE);
  392. new->features = features;
  393. new->device = NULL;
  394. list_add(&new->list, &dasd_hashlists[hash]);
  395. devmap = new;
  396. new = NULL;
  397. }
  398. spin_unlock(&dasd_devmap_lock);
  399. kfree(new);
  400. return devmap;
  401. }
  402. /*
  403. * Find devmap for device with given bus_id.
  404. */
  405. static struct dasd_devmap *
  406. dasd_find_busid(const char *bus_id)
  407. {
  408. struct dasd_devmap *devmap, *tmp;
  409. int hash;
  410. spin_lock(&dasd_devmap_lock);
  411. devmap = ERR_PTR(-ENODEV);
  412. hash = dasd_hash_busid(bus_id);
  413. list_for_each_entry(tmp, &dasd_hashlists[hash], list) {
  414. if (strncmp(tmp->bus_id, bus_id, DASD_BUS_ID_SIZE) == 0) {
  415. devmap = tmp;
  416. break;
  417. }
  418. }
  419. spin_unlock(&dasd_devmap_lock);
  420. return devmap;
  421. }
  422. /*
  423. * Check if busid has been added to the list of dasd ranges.
  424. */
  425. int
  426. dasd_busid_known(const char *bus_id)
  427. {
  428. return IS_ERR(dasd_find_busid(bus_id)) ? -ENOENT : 0;
  429. }
  430. /*
  431. * Forget all about the device numbers added so far.
  432. * This may only be called at module unload or system shutdown.
  433. */
  434. static void
  435. dasd_forget_ranges(void)
  436. {
  437. struct dasd_devmap *devmap, *n;
  438. int i;
  439. spin_lock(&dasd_devmap_lock);
  440. for (i = 0; i < 256; i++) {
  441. list_for_each_entry_safe(devmap, n, &dasd_hashlists[i], list) {
  442. BUG_ON(devmap->device != NULL);
  443. list_del(&devmap->list);
  444. kfree(devmap);
  445. }
  446. }
  447. spin_unlock(&dasd_devmap_lock);
  448. }
  449. /*
  450. * Find the device struct by its device index.
  451. */
  452. struct dasd_device *
  453. dasd_device_from_devindex(int devindex)
  454. {
  455. struct dasd_devmap *devmap, *tmp;
  456. struct dasd_device *device;
  457. int i;
  458. spin_lock(&dasd_devmap_lock);
  459. devmap = NULL;
  460. for (i = 0; (i < 256) && !devmap; i++)
  461. list_for_each_entry(tmp, &dasd_hashlists[i], list)
  462. if (tmp->devindex == devindex) {
  463. /* Found the devmap for the device. */
  464. devmap = tmp;
  465. break;
  466. }
  467. if (devmap && devmap->device) {
  468. device = devmap->device;
  469. dasd_get_device(device);
  470. } else
  471. device = ERR_PTR(-ENODEV);
  472. spin_unlock(&dasd_devmap_lock);
  473. return device;
  474. }
  475. /*
  476. * Return devmap for cdev. If no devmap exists yet, create one and
  477. * connect it to the cdev.
  478. */
  479. static struct dasd_devmap *
  480. dasd_devmap_from_cdev(struct ccw_device *cdev)
  481. {
  482. struct dasd_devmap *devmap;
  483. devmap = dasd_find_busid(dev_name(&cdev->dev));
  484. if (IS_ERR(devmap))
  485. devmap = dasd_add_busid(dev_name(&cdev->dev),
  486. DASD_FEATURE_DEFAULT);
  487. return devmap;
  488. }
  489. /*
  490. * Create a dasd device structure for cdev.
  491. */
  492. struct dasd_device *
  493. dasd_create_device(struct ccw_device *cdev)
  494. {
  495. struct dasd_devmap *devmap;
  496. struct dasd_device *device;
  497. unsigned long flags;
  498. int rc;
  499. devmap = dasd_devmap_from_cdev(cdev);
  500. if (IS_ERR(devmap))
  501. return (void *) devmap;
  502. device = dasd_alloc_device();
  503. if (IS_ERR(device))
  504. return device;
  505. atomic_set(&device->ref_count, 3);
  506. spin_lock(&dasd_devmap_lock);
  507. if (!devmap->device) {
  508. devmap->device = device;
  509. device->devindex = devmap->devindex;
  510. device->features = devmap->features;
  511. get_device(&cdev->dev);
  512. device->cdev = cdev;
  513. rc = 0;
  514. } else
  515. /* Someone else was faster. */
  516. rc = -EBUSY;
  517. spin_unlock(&dasd_devmap_lock);
  518. if (rc) {
  519. dasd_free_device(device);
  520. return ERR_PTR(rc);
  521. }
  522. spin_lock_irqsave(get_ccwdev_lock(cdev), flags);
  523. dev_set_drvdata(&cdev->dev, device);
  524. spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags);
  525. return device;
  526. }
  527. /*
  528. * Wait queue for dasd_delete_device waits.
  529. */
  530. static DECLARE_WAIT_QUEUE_HEAD(dasd_delete_wq);
  531. /*
  532. * Remove a dasd device structure. The passed referenced
  533. * is destroyed.
  534. */
  535. void
  536. dasd_delete_device(struct dasd_device *device)
  537. {
  538. struct ccw_device *cdev;
  539. struct dasd_devmap *devmap;
  540. unsigned long flags;
  541. /* First remove device pointer from devmap. */
  542. devmap = dasd_find_busid(dev_name(&device->cdev->dev));
  543. BUG_ON(IS_ERR(devmap));
  544. spin_lock(&dasd_devmap_lock);
  545. if (devmap->device != device) {
  546. spin_unlock(&dasd_devmap_lock);
  547. dasd_put_device(device);
  548. return;
  549. }
  550. devmap->device = NULL;
  551. spin_unlock(&dasd_devmap_lock);
  552. /* Disconnect dasd_device structure from ccw_device structure. */
  553. spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
  554. dev_set_drvdata(&device->cdev->dev, NULL);
  555. spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
  556. /*
  557. * Drop ref_count by 3, one for the devmap reference, one for
  558. * the cdev reference and one for the passed reference.
  559. */
  560. atomic_sub(3, &device->ref_count);
  561. /* Wait for reference counter to drop to zero. */
  562. wait_event(dasd_delete_wq, atomic_read(&device->ref_count) == 0);
  563. /* Disconnect dasd_device structure from ccw_device structure. */
  564. cdev = device->cdev;
  565. device->cdev = NULL;
  566. /* Put ccw_device structure. */
  567. put_device(&cdev->dev);
  568. /* Now the device structure can be freed. */
  569. dasd_free_device(device);
  570. }
  571. /*
  572. * Reference counter dropped to zero. Wake up waiter
  573. * in dasd_delete_device.
  574. */
  575. void
  576. dasd_put_device_wake(struct dasd_device *device)
  577. {
  578. wake_up(&dasd_delete_wq);
  579. }
  580. EXPORT_SYMBOL_GPL(dasd_put_device_wake);
  581. /*
  582. * Return dasd_device structure associated with cdev.
  583. * This function needs to be called with the ccw device
  584. * lock held. It can be used from interrupt context.
  585. */
  586. struct dasd_device *
  587. dasd_device_from_cdev_locked(struct ccw_device *cdev)
  588. {
  589. struct dasd_device *device = dev_get_drvdata(&cdev->dev);
  590. if (!device)
  591. return ERR_PTR(-ENODEV);
  592. dasd_get_device(device);
  593. return device;
  594. }
  595. /*
  596. * Return dasd_device structure associated with cdev.
  597. */
  598. struct dasd_device *
  599. dasd_device_from_cdev(struct ccw_device *cdev)
  600. {
  601. struct dasd_device *device;
  602. unsigned long flags;
  603. spin_lock_irqsave(get_ccwdev_lock(cdev), flags);
  604. device = dasd_device_from_cdev_locked(cdev);
  605. spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags);
  606. return device;
  607. }
  608. void dasd_add_link_to_gendisk(struct gendisk *gdp, struct dasd_device *device)
  609. {
  610. struct dasd_devmap *devmap;
  611. devmap = dasd_find_busid(dev_name(&device->cdev->dev));
  612. if (IS_ERR(devmap))
  613. return;
  614. spin_lock(&dasd_devmap_lock);
  615. gdp->private_data = devmap;
  616. spin_unlock(&dasd_devmap_lock);
  617. }
  618. struct dasd_device *dasd_device_from_gendisk(struct gendisk *gdp)
  619. {
  620. struct dasd_device *device;
  621. struct dasd_devmap *devmap;
  622. if (!gdp->private_data)
  623. return NULL;
  624. device = NULL;
  625. spin_lock(&dasd_devmap_lock);
  626. devmap = gdp->private_data;
  627. if (devmap && devmap->device) {
  628. device = devmap->device;
  629. dasd_get_device(device);
  630. }
  631. spin_unlock(&dasd_devmap_lock);
  632. return device;
  633. }
  634. /*
  635. * SECTION: files in sysfs
  636. */
  637. /*
  638. * failfast controls the behaviour, if no path is available
  639. */
  640. static ssize_t dasd_ff_show(struct device *dev, struct device_attribute *attr,
  641. char *buf)
  642. {
  643. struct dasd_devmap *devmap;
  644. int ff_flag;
  645. devmap = dasd_find_busid(dev_name(dev));
  646. if (!IS_ERR(devmap))
  647. ff_flag = (devmap->features & DASD_FEATURE_FAILFAST) != 0;
  648. else
  649. ff_flag = (DASD_FEATURE_DEFAULT & DASD_FEATURE_FAILFAST) != 0;
  650. return snprintf(buf, PAGE_SIZE, ff_flag ? "1\n" : "0\n");
  651. }
  652. static ssize_t dasd_ff_store(struct device *dev, struct device_attribute *attr,
  653. const char *buf, size_t count)
  654. {
  655. struct dasd_devmap *devmap;
  656. int val;
  657. char *endp;
  658. devmap = dasd_devmap_from_cdev(to_ccwdev(dev));
  659. if (IS_ERR(devmap))
  660. return PTR_ERR(devmap);
  661. val = simple_strtoul(buf, &endp, 0);
  662. if (((endp + 1) < (buf + count)) || (val > 1))
  663. return -EINVAL;
  664. spin_lock(&dasd_devmap_lock);
  665. if (val)
  666. devmap->features |= DASD_FEATURE_FAILFAST;
  667. else
  668. devmap->features &= ~DASD_FEATURE_FAILFAST;
  669. if (devmap->device)
  670. devmap->device->features = devmap->features;
  671. spin_unlock(&dasd_devmap_lock);
  672. return count;
  673. }
  674. static DEVICE_ATTR(failfast, 0644, dasd_ff_show, dasd_ff_store);
  675. /*
  676. * readonly controls the readonly status of a dasd
  677. */
  678. static ssize_t
  679. dasd_ro_show(struct device *dev, struct device_attribute *attr, char *buf)
  680. {
  681. struct dasd_devmap *devmap;
  682. int ro_flag;
  683. devmap = dasd_find_busid(dev_name(dev));
  684. if (!IS_ERR(devmap))
  685. ro_flag = (devmap->features & DASD_FEATURE_READONLY) != 0;
  686. else
  687. ro_flag = (DASD_FEATURE_DEFAULT & DASD_FEATURE_READONLY) != 0;
  688. return snprintf(buf, PAGE_SIZE, ro_flag ? "1\n" : "0\n");
  689. }
  690. static ssize_t
  691. dasd_ro_store(struct device *dev, struct device_attribute *attr,
  692. const char *buf, size_t count)
  693. {
  694. struct dasd_devmap *devmap;
  695. struct dasd_device *device;
  696. int val;
  697. char *endp;
  698. devmap = dasd_devmap_from_cdev(to_ccwdev(dev));
  699. if (IS_ERR(devmap))
  700. return PTR_ERR(devmap);
  701. val = simple_strtoul(buf, &endp, 0);
  702. if (((endp + 1) < (buf + count)) || (val > 1))
  703. return -EINVAL;
  704. spin_lock(&dasd_devmap_lock);
  705. if (val)
  706. devmap->features |= DASD_FEATURE_READONLY;
  707. else
  708. devmap->features &= ~DASD_FEATURE_READONLY;
  709. device = devmap->device;
  710. if (device) {
  711. device->features = devmap->features;
  712. val = val || test_bit(DASD_FLAG_DEVICE_RO, &device->flags);
  713. }
  714. spin_unlock(&dasd_devmap_lock);
  715. if (device && device->block && device->block->gdp)
  716. set_disk_ro(device->block->gdp, val);
  717. return count;
  718. }
  719. static DEVICE_ATTR(readonly, 0644, dasd_ro_show, dasd_ro_store);
  720. /*
  721. * erplog controls the logging of ERP related data
  722. * (e.g. failing channel programs).
  723. */
  724. static ssize_t
  725. dasd_erplog_show(struct device *dev, struct device_attribute *attr, char *buf)
  726. {
  727. struct dasd_devmap *devmap;
  728. int erplog;
  729. devmap = dasd_find_busid(dev_name(dev));
  730. if (!IS_ERR(devmap))
  731. erplog = (devmap->features & DASD_FEATURE_ERPLOG) != 0;
  732. else
  733. erplog = (DASD_FEATURE_DEFAULT & DASD_FEATURE_ERPLOG) != 0;
  734. return snprintf(buf, PAGE_SIZE, erplog ? "1\n" : "0\n");
  735. }
  736. static ssize_t
  737. dasd_erplog_store(struct device *dev, struct device_attribute *attr,
  738. const char *buf, size_t count)
  739. {
  740. struct dasd_devmap *devmap;
  741. int val;
  742. char *endp;
  743. devmap = dasd_devmap_from_cdev(to_ccwdev(dev));
  744. if (IS_ERR(devmap))
  745. return PTR_ERR(devmap);
  746. val = simple_strtoul(buf, &endp, 0);
  747. if (((endp + 1) < (buf + count)) || (val > 1))
  748. return -EINVAL;
  749. spin_lock(&dasd_devmap_lock);
  750. if (val)
  751. devmap->features |= DASD_FEATURE_ERPLOG;
  752. else
  753. devmap->features &= ~DASD_FEATURE_ERPLOG;
  754. if (devmap->device)
  755. devmap->device->features = devmap->features;
  756. spin_unlock(&dasd_devmap_lock);
  757. return count;
  758. }
  759. static DEVICE_ATTR(erplog, 0644, dasd_erplog_show, dasd_erplog_store);
  760. /*
  761. * use_diag controls whether the driver should use diag rather than ssch
  762. * to talk to the device
  763. */
  764. static ssize_t
  765. dasd_use_diag_show(struct device *dev, struct device_attribute *attr, char *buf)
  766. {
  767. struct dasd_devmap *devmap;
  768. int use_diag;
  769. devmap = dasd_find_busid(dev_name(dev));
  770. if (!IS_ERR(devmap))
  771. use_diag = (devmap->features & DASD_FEATURE_USEDIAG) != 0;
  772. else
  773. use_diag = (DASD_FEATURE_DEFAULT & DASD_FEATURE_USEDIAG) != 0;
  774. return sprintf(buf, use_diag ? "1\n" : "0\n");
  775. }
  776. static ssize_t
  777. dasd_use_diag_store(struct device *dev, struct device_attribute *attr,
  778. const char *buf, size_t count)
  779. {
  780. struct dasd_devmap *devmap;
  781. ssize_t rc;
  782. int val;
  783. char *endp;
  784. devmap = dasd_devmap_from_cdev(to_ccwdev(dev));
  785. if (IS_ERR(devmap))
  786. return PTR_ERR(devmap);
  787. val = simple_strtoul(buf, &endp, 0);
  788. if (((endp + 1) < (buf + count)) || (val > 1))
  789. return -EINVAL;
  790. spin_lock(&dasd_devmap_lock);
  791. /* Changing diag discipline flag is only allowed in offline state. */
  792. rc = count;
  793. if (!devmap->device && !(devmap->features & DASD_FEATURE_USERAW)) {
  794. if (val)
  795. devmap->features |= DASD_FEATURE_USEDIAG;
  796. else
  797. devmap->features &= ~DASD_FEATURE_USEDIAG;
  798. } else
  799. rc = -EPERM;
  800. spin_unlock(&dasd_devmap_lock);
  801. return rc;
  802. }
  803. static DEVICE_ATTR(use_diag, 0644, dasd_use_diag_show, dasd_use_diag_store);
  804. /*
  805. * use_raw controls whether the driver should give access to raw eckd data or
  806. * operate in standard mode
  807. */
  808. static ssize_t
  809. dasd_use_raw_show(struct device *dev, struct device_attribute *attr, char *buf)
  810. {
  811. struct dasd_devmap *devmap;
  812. int use_raw;
  813. devmap = dasd_find_busid(dev_name(dev));
  814. if (!IS_ERR(devmap))
  815. use_raw = (devmap->features & DASD_FEATURE_USERAW) != 0;
  816. else
  817. use_raw = (DASD_FEATURE_DEFAULT & DASD_FEATURE_USERAW) != 0;
  818. return sprintf(buf, use_raw ? "1\n" : "0\n");
  819. }
  820. static ssize_t
  821. dasd_use_raw_store(struct device *dev, struct device_attribute *attr,
  822. const char *buf, size_t count)
  823. {
  824. struct dasd_devmap *devmap;
  825. ssize_t rc;
  826. unsigned long val;
  827. devmap = dasd_devmap_from_cdev(to_ccwdev(dev));
  828. if (IS_ERR(devmap))
  829. return PTR_ERR(devmap);
  830. if ((strict_strtoul(buf, 10, &val) != 0) || val > 1)
  831. return -EINVAL;
  832. spin_lock(&dasd_devmap_lock);
  833. /* Changing diag discipline flag is only allowed in offline state. */
  834. rc = count;
  835. if (!devmap->device && !(devmap->features & DASD_FEATURE_USEDIAG)) {
  836. if (val)
  837. devmap->features |= DASD_FEATURE_USERAW;
  838. else
  839. devmap->features &= ~DASD_FEATURE_USERAW;
  840. } else
  841. rc = -EPERM;
  842. spin_unlock(&dasd_devmap_lock);
  843. return rc;
  844. }
  845. static DEVICE_ATTR(raw_track_access, 0644, dasd_use_raw_show,
  846. dasd_use_raw_store);
  847. static ssize_t
  848. dasd_discipline_show(struct device *dev, struct device_attribute *attr,
  849. char *buf)
  850. {
  851. struct dasd_device *device;
  852. ssize_t len;
  853. device = dasd_device_from_cdev(to_ccwdev(dev));
  854. if (IS_ERR(device))
  855. goto out;
  856. else if (!device->discipline) {
  857. dasd_put_device(device);
  858. goto out;
  859. } else {
  860. len = snprintf(buf, PAGE_SIZE, "%s\n",
  861. device->discipline->name);
  862. dasd_put_device(device);
  863. return len;
  864. }
  865. out:
  866. len = snprintf(buf, PAGE_SIZE, "none\n");
  867. return len;
  868. }
  869. static DEVICE_ATTR(discipline, 0444, dasd_discipline_show, NULL);
  870. static ssize_t
  871. dasd_device_status_show(struct device *dev, struct device_attribute *attr,
  872. char *buf)
  873. {
  874. struct dasd_device *device;
  875. ssize_t len;
  876. device = dasd_device_from_cdev(to_ccwdev(dev));
  877. if (!IS_ERR(device)) {
  878. switch (device->state) {
  879. case DASD_STATE_NEW:
  880. len = snprintf(buf, PAGE_SIZE, "new\n");
  881. break;
  882. case DASD_STATE_KNOWN:
  883. len = snprintf(buf, PAGE_SIZE, "detected\n");
  884. break;
  885. case DASD_STATE_BASIC:
  886. len = snprintf(buf, PAGE_SIZE, "basic\n");
  887. break;
  888. case DASD_STATE_UNFMT:
  889. len = snprintf(buf, PAGE_SIZE, "unformatted\n");
  890. break;
  891. case DASD_STATE_READY:
  892. len = snprintf(buf, PAGE_SIZE, "ready\n");
  893. break;
  894. case DASD_STATE_ONLINE:
  895. len = snprintf(buf, PAGE_SIZE, "online\n");
  896. break;
  897. default:
  898. len = snprintf(buf, PAGE_SIZE, "no stat\n");
  899. break;
  900. }
  901. dasd_put_device(device);
  902. } else
  903. len = snprintf(buf, PAGE_SIZE, "unknown\n");
  904. return len;
  905. }
  906. static DEVICE_ATTR(status, 0444, dasd_device_status_show, NULL);
  907. static ssize_t dasd_alias_show(struct device *dev,
  908. struct device_attribute *attr, char *buf)
  909. {
  910. struct dasd_device *device;
  911. struct dasd_uid uid;
  912. device = dasd_device_from_cdev(to_ccwdev(dev));
  913. if (IS_ERR(device))
  914. return sprintf(buf, "0\n");
  915. if (device->discipline && device->discipline->get_uid &&
  916. !device->discipline->get_uid(device, &uid)) {
  917. if (uid.type == UA_BASE_PAV_ALIAS ||
  918. uid.type == UA_HYPER_PAV_ALIAS) {
  919. dasd_put_device(device);
  920. return sprintf(buf, "1\n");
  921. }
  922. }
  923. dasd_put_device(device);
  924. return sprintf(buf, "0\n");
  925. }
  926. static DEVICE_ATTR(alias, 0444, dasd_alias_show, NULL);
  927. static ssize_t dasd_vendor_show(struct device *dev,
  928. struct device_attribute *attr, char *buf)
  929. {
  930. struct dasd_device *device;
  931. struct dasd_uid uid;
  932. char *vendor;
  933. device = dasd_device_from_cdev(to_ccwdev(dev));
  934. vendor = "";
  935. if (IS_ERR(device))
  936. return snprintf(buf, PAGE_SIZE, "%s\n", vendor);
  937. if (device->discipline && device->discipline->get_uid &&
  938. !device->discipline->get_uid(device, &uid))
  939. vendor = uid.vendor;
  940. dasd_put_device(device);
  941. return snprintf(buf, PAGE_SIZE, "%s\n", vendor);
  942. }
  943. static DEVICE_ATTR(vendor, 0444, dasd_vendor_show, NULL);
  944. #define UID_STRLEN ( /* vendor */ 3 + 1 + /* serial */ 14 + 1 +\
  945. /* SSID */ 4 + 1 + /* unit addr */ 2 + 1 +\
  946. /* vduit */ 32 + 1)
  947. static ssize_t
  948. dasd_uid_show(struct device *dev, struct device_attribute *attr, char *buf)
  949. {
  950. struct dasd_device *device;
  951. struct dasd_uid uid;
  952. char uid_string[UID_STRLEN];
  953. char ua_string[3];
  954. device = dasd_device_from_cdev(to_ccwdev(dev));
  955. uid_string[0] = 0;
  956. if (IS_ERR(device))
  957. return snprintf(buf, PAGE_SIZE, "%s\n", uid_string);
  958. if (device->discipline && device->discipline->get_uid &&
  959. !device->discipline->get_uid(device, &uid)) {
  960. switch (uid.type) {
  961. case UA_BASE_DEVICE:
  962. snprintf(ua_string, sizeof(ua_string), "%02x",
  963. uid.real_unit_addr);
  964. break;
  965. case UA_BASE_PAV_ALIAS:
  966. snprintf(ua_string, sizeof(ua_string), "%02x",
  967. uid.base_unit_addr);
  968. break;
  969. case UA_HYPER_PAV_ALIAS:
  970. snprintf(ua_string, sizeof(ua_string), "xx");
  971. break;
  972. default:
  973. /* should not happen, treat like base device */
  974. snprintf(ua_string, sizeof(ua_string), "%02x",
  975. uid.real_unit_addr);
  976. break;
  977. }
  978. if (strlen(uid.vduit) > 0)
  979. snprintf(uid_string, sizeof(uid_string),
  980. "%s.%s.%04x.%s.%s",
  981. uid.vendor, uid.serial, uid.ssid, ua_string,
  982. uid.vduit);
  983. else
  984. snprintf(uid_string, sizeof(uid_string),
  985. "%s.%s.%04x.%s",
  986. uid.vendor, uid.serial, uid.ssid, ua_string);
  987. }
  988. dasd_put_device(device);
  989. return snprintf(buf, PAGE_SIZE, "%s\n", uid_string);
  990. }
  991. static DEVICE_ATTR(uid, 0444, dasd_uid_show, NULL);
  992. /*
  993. * extended error-reporting
  994. */
  995. static ssize_t
  996. dasd_eer_show(struct device *dev, struct device_attribute *attr, char *buf)
  997. {
  998. struct dasd_devmap *devmap;
  999. int eer_flag;
  1000. devmap = dasd_find_busid(dev_name(dev));
  1001. if (!IS_ERR(devmap) && devmap->device)
  1002. eer_flag = dasd_eer_enabled(devmap->device);
  1003. else
  1004. eer_flag = 0;
  1005. return snprintf(buf, PAGE_SIZE, eer_flag ? "1\n" : "0\n");
  1006. }
  1007. static ssize_t
  1008. dasd_eer_store(struct device *dev, struct device_attribute *attr,
  1009. const char *buf, size_t count)
  1010. {
  1011. struct dasd_devmap *devmap;
  1012. int val, rc;
  1013. char *endp;
  1014. devmap = dasd_devmap_from_cdev(to_ccwdev(dev));
  1015. if (IS_ERR(devmap))
  1016. return PTR_ERR(devmap);
  1017. if (!devmap->device)
  1018. return -ENODEV;
  1019. val = simple_strtoul(buf, &endp, 0);
  1020. if (((endp + 1) < (buf + count)) || (val > 1))
  1021. return -EINVAL;
  1022. if (val) {
  1023. rc = dasd_eer_enable(devmap->device);
  1024. if (rc)
  1025. return rc;
  1026. } else
  1027. dasd_eer_disable(devmap->device);
  1028. return count;
  1029. }
  1030. static DEVICE_ATTR(eer_enabled, 0644, dasd_eer_show, dasd_eer_store);
  1031. /*
  1032. * expiration time for default requests
  1033. */
  1034. static ssize_t
  1035. dasd_expires_show(struct device *dev, struct device_attribute *attr, char *buf)
  1036. {
  1037. struct dasd_device *device;
  1038. int len;
  1039. device = dasd_device_from_cdev(to_ccwdev(dev));
  1040. if (IS_ERR(device))
  1041. return -ENODEV;
  1042. len = snprintf(buf, PAGE_SIZE, "%lu\n", device->default_expires);
  1043. dasd_put_device(device);
  1044. return len;
  1045. }
  1046. static ssize_t
  1047. dasd_expires_store(struct device *dev, struct device_attribute *attr,
  1048. const char *buf, size_t count)
  1049. {
  1050. struct dasd_device *device;
  1051. unsigned long val;
  1052. device = dasd_device_from_cdev(to_ccwdev(dev));
  1053. if (IS_ERR(device))
  1054. return -ENODEV;
  1055. if ((strict_strtoul(buf, 10, &val) != 0) ||
  1056. (val > DASD_EXPIRES_MAX) || val == 0) {
  1057. dasd_put_device(device);
  1058. return -EINVAL;
  1059. }
  1060. if (val)
  1061. device->default_expires = val;
  1062. dasd_put_device(device);
  1063. return count;
  1064. }
  1065. static DEVICE_ATTR(expires, 0644, dasd_expires_show, dasd_expires_store);
  1066. static ssize_t dasd_reservation_policy_show(struct device *dev,
  1067. struct device_attribute *attr,
  1068. char *buf)
  1069. {
  1070. struct dasd_devmap *devmap;
  1071. int rc = 0;
  1072. devmap = dasd_find_busid(dev_name(dev));
  1073. if (IS_ERR(devmap)) {
  1074. rc = snprintf(buf, PAGE_SIZE, "ignore\n");
  1075. } else {
  1076. spin_lock(&dasd_devmap_lock);
  1077. if (devmap->features & DASD_FEATURE_FAILONSLCK)
  1078. rc = snprintf(buf, PAGE_SIZE, "fail\n");
  1079. else
  1080. rc = snprintf(buf, PAGE_SIZE, "ignore\n");
  1081. spin_unlock(&dasd_devmap_lock);
  1082. }
  1083. return rc;
  1084. }
  1085. static ssize_t dasd_reservation_policy_store(struct device *dev,
  1086. struct device_attribute *attr,
  1087. const char *buf, size_t count)
  1088. {
  1089. struct dasd_devmap *devmap;
  1090. int rc;
  1091. devmap = dasd_devmap_from_cdev(to_ccwdev(dev));
  1092. if (IS_ERR(devmap))
  1093. return PTR_ERR(devmap);
  1094. rc = 0;
  1095. spin_lock(&dasd_devmap_lock);
  1096. if (sysfs_streq("ignore", buf))
  1097. devmap->features &= ~DASD_FEATURE_FAILONSLCK;
  1098. else if (sysfs_streq("fail", buf))
  1099. devmap->features |= DASD_FEATURE_FAILONSLCK;
  1100. else
  1101. rc = -EINVAL;
  1102. if (devmap->device)
  1103. devmap->device->features = devmap->features;
  1104. spin_unlock(&dasd_devmap_lock);
  1105. if (rc)
  1106. return rc;
  1107. else
  1108. return count;
  1109. }
  1110. static DEVICE_ATTR(reservation_policy, 0644,
  1111. dasd_reservation_policy_show, dasd_reservation_policy_store);
  1112. static ssize_t dasd_reservation_state_show(struct device *dev,
  1113. struct device_attribute *attr,
  1114. char *buf)
  1115. {
  1116. struct dasd_device *device;
  1117. int rc = 0;
  1118. device = dasd_device_from_cdev(to_ccwdev(dev));
  1119. if (IS_ERR(device))
  1120. return snprintf(buf, PAGE_SIZE, "none\n");
  1121. if (test_bit(DASD_FLAG_IS_RESERVED, &device->flags))
  1122. rc = snprintf(buf, PAGE_SIZE, "reserved\n");
  1123. else if (test_bit(DASD_FLAG_LOCK_STOLEN, &device->flags))
  1124. rc = snprintf(buf, PAGE_SIZE, "lost\n");
  1125. else
  1126. rc = snprintf(buf, PAGE_SIZE, "none\n");
  1127. dasd_put_device(device);
  1128. return rc;
  1129. }
  1130. static ssize_t dasd_reservation_state_store(struct device *dev,
  1131. struct device_attribute *attr,
  1132. const char *buf, size_t count)
  1133. {
  1134. struct dasd_device *device;
  1135. int rc = 0;
  1136. device = dasd_device_from_cdev(to_ccwdev(dev));
  1137. if (IS_ERR(device))
  1138. return -ENODEV;
  1139. if (sysfs_streq("reset", buf))
  1140. clear_bit(DASD_FLAG_LOCK_STOLEN, &device->flags);
  1141. else
  1142. rc = -EINVAL;
  1143. dasd_put_device(device);
  1144. if (rc)
  1145. return rc;
  1146. else
  1147. return count;
  1148. }
  1149. static DEVICE_ATTR(last_known_reservation_state, 0644,
  1150. dasd_reservation_state_show, dasd_reservation_state_store);
  1151. static struct attribute * dasd_attrs[] = {
  1152. &dev_attr_readonly.attr,
  1153. &dev_attr_discipline.attr,
  1154. &dev_attr_status.attr,
  1155. &dev_attr_alias.attr,
  1156. &dev_attr_vendor.attr,
  1157. &dev_attr_uid.attr,
  1158. &dev_attr_use_diag.attr,
  1159. &dev_attr_raw_track_access.attr,
  1160. &dev_attr_eer_enabled.attr,
  1161. &dev_attr_erplog.attr,
  1162. &dev_attr_failfast.attr,
  1163. &dev_attr_expires.attr,
  1164. &dev_attr_reservation_policy.attr,
  1165. &dev_attr_last_known_reservation_state.attr,
  1166. NULL,
  1167. };
  1168. static struct attribute_group dasd_attr_group = {
  1169. .attrs = dasd_attrs,
  1170. };
  1171. /*
  1172. * Return value of the specified feature.
  1173. */
  1174. int
  1175. dasd_get_feature(struct ccw_device *cdev, int feature)
  1176. {
  1177. struct dasd_devmap *devmap;
  1178. devmap = dasd_find_busid(dev_name(&cdev->dev));
  1179. if (IS_ERR(devmap))
  1180. return PTR_ERR(devmap);
  1181. return ((devmap->features & feature) != 0);
  1182. }
  1183. /*
  1184. * Set / reset given feature.
  1185. * Flag indicates wether to set (!=0) or the reset (=0) the feature.
  1186. */
  1187. int
  1188. dasd_set_feature(struct ccw_device *cdev, int feature, int flag)
  1189. {
  1190. struct dasd_devmap *devmap;
  1191. devmap = dasd_find_busid(dev_name(&cdev->dev));
  1192. if (IS_ERR(devmap))
  1193. return PTR_ERR(devmap);
  1194. spin_lock(&dasd_devmap_lock);
  1195. if (flag)
  1196. devmap->features |= feature;
  1197. else
  1198. devmap->features &= ~feature;
  1199. if (devmap->device)
  1200. devmap->device->features = devmap->features;
  1201. spin_unlock(&dasd_devmap_lock);
  1202. return 0;
  1203. }
  1204. int
  1205. dasd_add_sysfs_files(struct ccw_device *cdev)
  1206. {
  1207. return sysfs_create_group(&cdev->dev.kobj, &dasd_attr_group);
  1208. }
  1209. void
  1210. dasd_remove_sysfs_files(struct ccw_device *cdev)
  1211. {
  1212. sysfs_remove_group(&cdev->dev.kobj, &dasd_attr_group);
  1213. }
  1214. int
  1215. dasd_devmap_init(void)
  1216. {
  1217. int i;
  1218. /* Initialize devmap structures. */
  1219. dasd_max_devindex = 0;
  1220. for (i = 0; i < 256; i++)
  1221. INIT_LIST_HEAD(&dasd_hashlists[i]);
  1222. return 0;
  1223. }
  1224. void
  1225. dasd_devmap_exit(void)
  1226. {
  1227. dasd_forget_ranges();
  1228. }