dasd_devmap.c 35 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432
  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 = kzalloc(sizeof(struct dasd_devmap), GFP_KERNEL);
  377. if (!new)
  378. return ERR_PTR(-ENOMEM);
  379. spin_lock(&dasd_devmap_lock);
  380. devmap = NULL;
  381. hash = dasd_hash_busid(bus_id);
  382. list_for_each_entry(tmp, &dasd_hashlists[hash], list)
  383. if (strncmp(tmp->bus_id, bus_id, DASD_BUS_ID_SIZE) == 0) {
  384. devmap = tmp;
  385. break;
  386. }
  387. if (!devmap) {
  388. /* This bus_id is new. */
  389. new->devindex = dasd_max_devindex++;
  390. strncpy(new->bus_id, bus_id, DASD_BUS_ID_SIZE);
  391. new->features = features;
  392. new->device = NULL;
  393. list_add(&new->list, &dasd_hashlists[hash]);
  394. devmap = new;
  395. new = NULL;
  396. }
  397. spin_unlock(&dasd_devmap_lock);
  398. kfree(new);
  399. return devmap;
  400. }
  401. /*
  402. * Find devmap for device with given bus_id.
  403. */
  404. static struct dasd_devmap *
  405. dasd_find_busid(const char *bus_id)
  406. {
  407. struct dasd_devmap *devmap, *tmp;
  408. int hash;
  409. spin_lock(&dasd_devmap_lock);
  410. devmap = ERR_PTR(-ENODEV);
  411. hash = dasd_hash_busid(bus_id);
  412. list_for_each_entry(tmp, &dasd_hashlists[hash], list) {
  413. if (strncmp(tmp->bus_id, bus_id, DASD_BUS_ID_SIZE) == 0) {
  414. devmap = tmp;
  415. break;
  416. }
  417. }
  418. spin_unlock(&dasd_devmap_lock);
  419. return devmap;
  420. }
  421. /*
  422. * Check if busid has been added to the list of dasd ranges.
  423. */
  424. int
  425. dasd_busid_known(const char *bus_id)
  426. {
  427. return IS_ERR(dasd_find_busid(bus_id)) ? -ENOENT : 0;
  428. }
  429. /*
  430. * Forget all about the device numbers added so far.
  431. * This may only be called at module unload or system shutdown.
  432. */
  433. static void
  434. dasd_forget_ranges(void)
  435. {
  436. struct dasd_devmap *devmap, *n;
  437. int i;
  438. spin_lock(&dasd_devmap_lock);
  439. for (i = 0; i < 256; i++) {
  440. list_for_each_entry_safe(devmap, n, &dasd_hashlists[i], list) {
  441. BUG_ON(devmap->device != NULL);
  442. list_del(&devmap->list);
  443. kfree(devmap);
  444. }
  445. }
  446. spin_unlock(&dasd_devmap_lock);
  447. }
  448. /*
  449. * Find the device struct by its device index.
  450. */
  451. struct dasd_device *
  452. dasd_device_from_devindex(int devindex)
  453. {
  454. struct dasd_devmap *devmap, *tmp;
  455. struct dasd_device *device;
  456. int i;
  457. spin_lock(&dasd_devmap_lock);
  458. devmap = NULL;
  459. for (i = 0; (i < 256) && !devmap; i++)
  460. list_for_each_entry(tmp, &dasd_hashlists[i], list)
  461. if (tmp->devindex == devindex) {
  462. /* Found the devmap for the device. */
  463. devmap = tmp;
  464. break;
  465. }
  466. if (devmap && devmap->device) {
  467. device = devmap->device;
  468. dasd_get_device(device);
  469. } else
  470. device = ERR_PTR(-ENODEV);
  471. spin_unlock(&dasd_devmap_lock);
  472. return device;
  473. }
  474. /*
  475. * Return devmap for cdev. If no devmap exists yet, create one and
  476. * connect it to the cdev.
  477. */
  478. static struct dasd_devmap *
  479. dasd_devmap_from_cdev(struct ccw_device *cdev)
  480. {
  481. struct dasd_devmap *devmap;
  482. devmap = dasd_find_busid(dev_name(&cdev->dev));
  483. if (IS_ERR(devmap))
  484. devmap = dasd_add_busid(dev_name(&cdev->dev),
  485. DASD_FEATURE_DEFAULT);
  486. return devmap;
  487. }
  488. /*
  489. * Create a dasd device structure for cdev.
  490. */
  491. struct dasd_device *
  492. dasd_create_device(struct ccw_device *cdev)
  493. {
  494. struct dasd_devmap *devmap;
  495. struct dasd_device *device;
  496. unsigned long flags;
  497. int rc;
  498. devmap = dasd_devmap_from_cdev(cdev);
  499. if (IS_ERR(devmap))
  500. return (void *) devmap;
  501. device = dasd_alloc_device();
  502. if (IS_ERR(device))
  503. return device;
  504. atomic_set(&device->ref_count, 3);
  505. spin_lock(&dasd_devmap_lock);
  506. if (!devmap->device) {
  507. devmap->device = device;
  508. device->devindex = devmap->devindex;
  509. device->features = devmap->features;
  510. get_device(&cdev->dev);
  511. device->cdev = cdev;
  512. rc = 0;
  513. } else
  514. /* Someone else was faster. */
  515. rc = -EBUSY;
  516. spin_unlock(&dasd_devmap_lock);
  517. if (rc) {
  518. dasd_free_device(device);
  519. return ERR_PTR(rc);
  520. }
  521. spin_lock_irqsave(get_ccwdev_lock(cdev), flags);
  522. dev_set_drvdata(&cdev->dev, device);
  523. spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags);
  524. return device;
  525. }
  526. /*
  527. * Wait queue for dasd_delete_device waits.
  528. */
  529. static DECLARE_WAIT_QUEUE_HEAD(dasd_delete_wq);
  530. /*
  531. * Remove a dasd device structure. The passed referenced
  532. * is destroyed.
  533. */
  534. void
  535. dasd_delete_device(struct dasd_device *device)
  536. {
  537. struct ccw_device *cdev;
  538. struct dasd_devmap *devmap;
  539. unsigned long flags;
  540. /* First remove device pointer from devmap. */
  541. devmap = dasd_find_busid(dev_name(&device->cdev->dev));
  542. BUG_ON(IS_ERR(devmap));
  543. spin_lock(&dasd_devmap_lock);
  544. if (devmap->device != device) {
  545. spin_unlock(&dasd_devmap_lock);
  546. dasd_put_device(device);
  547. return;
  548. }
  549. devmap->device = NULL;
  550. spin_unlock(&dasd_devmap_lock);
  551. /* Disconnect dasd_device structure from ccw_device structure. */
  552. spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
  553. dev_set_drvdata(&device->cdev->dev, NULL);
  554. spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
  555. /*
  556. * Drop ref_count by 3, one for the devmap reference, one for
  557. * the cdev reference and one for the passed reference.
  558. */
  559. atomic_sub(3, &device->ref_count);
  560. /* Wait for reference counter to drop to zero. */
  561. wait_event(dasd_delete_wq, atomic_read(&device->ref_count) == 0);
  562. /* Disconnect dasd_device structure from ccw_device structure. */
  563. cdev = device->cdev;
  564. device->cdev = NULL;
  565. /* Put ccw_device structure. */
  566. put_device(&cdev->dev);
  567. /* Now the device structure can be freed. */
  568. dasd_free_device(device);
  569. }
  570. /*
  571. * Reference counter dropped to zero. Wake up waiter
  572. * in dasd_delete_device.
  573. */
  574. void
  575. dasd_put_device_wake(struct dasd_device *device)
  576. {
  577. wake_up(&dasd_delete_wq);
  578. }
  579. EXPORT_SYMBOL_GPL(dasd_put_device_wake);
  580. /*
  581. * Return dasd_device structure associated with cdev.
  582. * This function needs to be called with the ccw device
  583. * lock held. It can be used from interrupt context.
  584. */
  585. struct dasd_device *
  586. dasd_device_from_cdev_locked(struct ccw_device *cdev)
  587. {
  588. struct dasd_device *device = dev_get_drvdata(&cdev->dev);
  589. if (!device)
  590. return ERR_PTR(-ENODEV);
  591. dasd_get_device(device);
  592. return device;
  593. }
  594. /*
  595. * Return dasd_device structure associated with cdev.
  596. */
  597. struct dasd_device *
  598. dasd_device_from_cdev(struct ccw_device *cdev)
  599. {
  600. struct dasd_device *device;
  601. unsigned long flags;
  602. spin_lock_irqsave(get_ccwdev_lock(cdev), flags);
  603. device = dasd_device_from_cdev_locked(cdev);
  604. spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags);
  605. return device;
  606. }
  607. void dasd_add_link_to_gendisk(struct gendisk *gdp, struct dasd_device *device)
  608. {
  609. struct dasd_devmap *devmap;
  610. devmap = dasd_find_busid(dev_name(&device->cdev->dev));
  611. if (IS_ERR(devmap))
  612. return;
  613. spin_lock(&dasd_devmap_lock);
  614. gdp->private_data = devmap;
  615. spin_unlock(&dasd_devmap_lock);
  616. }
  617. struct dasd_device *dasd_device_from_gendisk(struct gendisk *gdp)
  618. {
  619. struct dasd_device *device;
  620. struct dasd_devmap *devmap;
  621. if (!gdp->private_data)
  622. return NULL;
  623. device = NULL;
  624. spin_lock(&dasd_devmap_lock);
  625. devmap = gdp->private_data;
  626. if (devmap && devmap->device) {
  627. device = devmap->device;
  628. dasd_get_device(device);
  629. }
  630. spin_unlock(&dasd_devmap_lock);
  631. return device;
  632. }
  633. /*
  634. * SECTION: files in sysfs
  635. */
  636. /*
  637. * failfast controls the behaviour, if no path is available
  638. */
  639. static ssize_t dasd_ff_show(struct device *dev, struct device_attribute *attr,
  640. char *buf)
  641. {
  642. struct dasd_devmap *devmap;
  643. int ff_flag;
  644. devmap = dasd_find_busid(dev_name(dev));
  645. if (!IS_ERR(devmap))
  646. ff_flag = (devmap->features & DASD_FEATURE_FAILFAST) != 0;
  647. else
  648. ff_flag = (DASD_FEATURE_DEFAULT & DASD_FEATURE_FAILFAST) != 0;
  649. return snprintf(buf, PAGE_SIZE, ff_flag ? "1\n" : "0\n");
  650. }
  651. static ssize_t dasd_ff_store(struct device *dev, struct device_attribute *attr,
  652. const char *buf, size_t count)
  653. {
  654. struct dasd_devmap *devmap;
  655. int val;
  656. char *endp;
  657. devmap = dasd_devmap_from_cdev(to_ccwdev(dev));
  658. if (IS_ERR(devmap))
  659. return PTR_ERR(devmap);
  660. val = simple_strtoul(buf, &endp, 0);
  661. if (((endp + 1) < (buf + count)) || (val > 1))
  662. return -EINVAL;
  663. spin_lock(&dasd_devmap_lock);
  664. if (val)
  665. devmap->features |= DASD_FEATURE_FAILFAST;
  666. else
  667. devmap->features &= ~DASD_FEATURE_FAILFAST;
  668. if (devmap->device)
  669. devmap->device->features = devmap->features;
  670. spin_unlock(&dasd_devmap_lock);
  671. return count;
  672. }
  673. static DEVICE_ATTR(failfast, 0644, dasd_ff_show, dasd_ff_store);
  674. /*
  675. * readonly controls the readonly status of a dasd
  676. */
  677. static ssize_t
  678. dasd_ro_show(struct device *dev, struct device_attribute *attr, char *buf)
  679. {
  680. struct dasd_devmap *devmap;
  681. int ro_flag;
  682. devmap = dasd_find_busid(dev_name(dev));
  683. if (!IS_ERR(devmap))
  684. ro_flag = (devmap->features & DASD_FEATURE_READONLY) != 0;
  685. else
  686. ro_flag = (DASD_FEATURE_DEFAULT & DASD_FEATURE_READONLY) != 0;
  687. return snprintf(buf, PAGE_SIZE, ro_flag ? "1\n" : "0\n");
  688. }
  689. static ssize_t
  690. dasd_ro_store(struct device *dev, struct device_attribute *attr,
  691. const char *buf, size_t count)
  692. {
  693. struct dasd_devmap *devmap;
  694. struct dasd_device *device;
  695. int val;
  696. char *endp;
  697. devmap = dasd_devmap_from_cdev(to_ccwdev(dev));
  698. if (IS_ERR(devmap))
  699. return PTR_ERR(devmap);
  700. val = simple_strtoul(buf, &endp, 0);
  701. if (((endp + 1) < (buf + count)) || (val > 1))
  702. return -EINVAL;
  703. spin_lock(&dasd_devmap_lock);
  704. if (val)
  705. devmap->features |= DASD_FEATURE_READONLY;
  706. else
  707. devmap->features &= ~DASD_FEATURE_READONLY;
  708. device = devmap->device;
  709. if (device) {
  710. device->features = devmap->features;
  711. val = val || test_bit(DASD_FLAG_DEVICE_RO, &device->flags);
  712. }
  713. spin_unlock(&dasd_devmap_lock);
  714. if (device && device->block && device->block->gdp)
  715. set_disk_ro(device->block->gdp, val);
  716. return count;
  717. }
  718. static DEVICE_ATTR(readonly, 0644, dasd_ro_show, dasd_ro_store);
  719. /*
  720. * erplog controls the logging of ERP related data
  721. * (e.g. failing channel programs).
  722. */
  723. static ssize_t
  724. dasd_erplog_show(struct device *dev, struct device_attribute *attr, char *buf)
  725. {
  726. struct dasd_devmap *devmap;
  727. int erplog;
  728. devmap = dasd_find_busid(dev_name(dev));
  729. if (!IS_ERR(devmap))
  730. erplog = (devmap->features & DASD_FEATURE_ERPLOG) != 0;
  731. else
  732. erplog = (DASD_FEATURE_DEFAULT & DASD_FEATURE_ERPLOG) != 0;
  733. return snprintf(buf, PAGE_SIZE, erplog ? "1\n" : "0\n");
  734. }
  735. static ssize_t
  736. dasd_erplog_store(struct device *dev, struct device_attribute *attr,
  737. const char *buf, size_t count)
  738. {
  739. struct dasd_devmap *devmap;
  740. int val;
  741. char *endp;
  742. devmap = dasd_devmap_from_cdev(to_ccwdev(dev));
  743. if (IS_ERR(devmap))
  744. return PTR_ERR(devmap);
  745. val = simple_strtoul(buf, &endp, 0);
  746. if (((endp + 1) < (buf + count)) || (val > 1))
  747. return -EINVAL;
  748. spin_lock(&dasd_devmap_lock);
  749. if (val)
  750. devmap->features |= DASD_FEATURE_ERPLOG;
  751. else
  752. devmap->features &= ~DASD_FEATURE_ERPLOG;
  753. if (devmap->device)
  754. devmap->device->features = devmap->features;
  755. spin_unlock(&dasd_devmap_lock);
  756. return count;
  757. }
  758. static DEVICE_ATTR(erplog, 0644, dasd_erplog_show, dasd_erplog_store);
  759. /*
  760. * use_diag controls whether the driver should use diag rather than ssch
  761. * to talk to the device
  762. */
  763. static ssize_t
  764. dasd_use_diag_show(struct device *dev, struct device_attribute *attr, char *buf)
  765. {
  766. struct dasd_devmap *devmap;
  767. int use_diag;
  768. devmap = dasd_find_busid(dev_name(dev));
  769. if (!IS_ERR(devmap))
  770. use_diag = (devmap->features & DASD_FEATURE_USEDIAG) != 0;
  771. else
  772. use_diag = (DASD_FEATURE_DEFAULT & DASD_FEATURE_USEDIAG) != 0;
  773. return sprintf(buf, use_diag ? "1\n" : "0\n");
  774. }
  775. static ssize_t
  776. dasd_use_diag_store(struct device *dev, struct device_attribute *attr,
  777. const char *buf, size_t count)
  778. {
  779. struct dasd_devmap *devmap;
  780. ssize_t rc;
  781. int val;
  782. char *endp;
  783. devmap = dasd_devmap_from_cdev(to_ccwdev(dev));
  784. if (IS_ERR(devmap))
  785. return PTR_ERR(devmap);
  786. val = simple_strtoul(buf, &endp, 0);
  787. if (((endp + 1) < (buf + count)) || (val > 1))
  788. return -EINVAL;
  789. spin_lock(&dasd_devmap_lock);
  790. /* Changing diag discipline flag is only allowed in offline state. */
  791. rc = count;
  792. if (!devmap->device && !(devmap->features & DASD_FEATURE_USERAW)) {
  793. if (val)
  794. devmap->features |= DASD_FEATURE_USEDIAG;
  795. else
  796. devmap->features &= ~DASD_FEATURE_USEDIAG;
  797. } else
  798. rc = -EPERM;
  799. spin_unlock(&dasd_devmap_lock);
  800. return rc;
  801. }
  802. static DEVICE_ATTR(use_diag, 0644, dasd_use_diag_show, dasd_use_diag_store);
  803. /*
  804. * use_raw controls whether the driver should give access to raw eckd data or
  805. * operate in standard mode
  806. */
  807. static ssize_t
  808. dasd_use_raw_show(struct device *dev, struct device_attribute *attr, char *buf)
  809. {
  810. struct dasd_devmap *devmap;
  811. int use_raw;
  812. devmap = dasd_find_busid(dev_name(dev));
  813. if (!IS_ERR(devmap))
  814. use_raw = (devmap->features & DASD_FEATURE_USERAW) != 0;
  815. else
  816. use_raw = (DASD_FEATURE_DEFAULT & DASD_FEATURE_USERAW) != 0;
  817. return sprintf(buf, use_raw ? "1\n" : "0\n");
  818. }
  819. static ssize_t
  820. dasd_use_raw_store(struct device *dev, struct device_attribute *attr,
  821. const char *buf, size_t count)
  822. {
  823. struct dasd_devmap *devmap;
  824. ssize_t rc;
  825. unsigned long val;
  826. devmap = dasd_devmap_from_cdev(to_ccwdev(dev));
  827. if (IS_ERR(devmap))
  828. return PTR_ERR(devmap);
  829. if ((strict_strtoul(buf, 10, &val) != 0) || val > 1)
  830. return -EINVAL;
  831. spin_lock(&dasd_devmap_lock);
  832. /* Changing diag discipline flag is only allowed in offline state. */
  833. rc = count;
  834. if (!devmap->device && !(devmap->features & DASD_FEATURE_USEDIAG)) {
  835. if (val)
  836. devmap->features |= DASD_FEATURE_USERAW;
  837. else
  838. devmap->features &= ~DASD_FEATURE_USERAW;
  839. } else
  840. rc = -EPERM;
  841. spin_unlock(&dasd_devmap_lock);
  842. return rc;
  843. }
  844. static DEVICE_ATTR(raw_track_access, 0644, dasd_use_raw_show,
  845. dasd_use_raw_store);
  846. static ssize_t
  847. dasd_safe_offline_store(struct device *dev, struct device_attribute *attr,
  848. const char *buf, size_t count)
  849. {
  850. struct ccw_device *cdev = to_ccwdev(dev);
  851. struct dasd_device *device;
  852. int rc;
  853. device = dasd_device_from_cdev(cdev);
  854. if (IS_ERR(device)) {
  855. rc = PTR_ERR(device);
  856. goto out;
  857. }
  858. if (test_bit(DASD_FLAG_OFFLINE, &device->flags) ||
  859. test_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING, &device->flags)) {
  860. /* Already doing offline processing */
  861. dasd_put_device(device);
  862. rc = -EBUSY;
  863. goto out;
  864. }
  865. set_bit(DASD_FLAG_SAFE_OFFLINE, &device->flags);
  866. dasd_put_device(device);
  867. rc = ccw_device_set_offline(cdev);
  868. out:
  869. return rc ? rc : count;
  870. }
  871. static DEVICE_ATTR(safe_offline, 0200, NULL, dasd_safe_offline_store);
  872. static ssize_t
  873. dasd_discipline_show(struct device *dev, struct device_attribute *attr,
  874. char *buf)
  875. {
  876. struct dasd_device *device;
  877. ssize_t len;
  878. device = dasd_device_from_cdev(to_ccwdev(dev));
  879. if (IS_ERR(device))
  880. goto out;
  881. else if (!device->discipline) {
  882. dasd_put_device(device);
  883. goto out;
  884. } else {
  885. len = snprintf(buf, PAGE_SIZE, "%s\n",
  886. device->discipline->name);
  887. dasd_put_device(device);
  888. return len;
  889. }
  890. out:
  891. len = snprintf(buf, PAGE_SIZE, "none\n");
  892. return len;
  893. }
  894. static DEVICE_ATTR(discipline, 0444, dasd_discipline_show, NULL);
  895. static ssize_t
  896. dasd_device_status_show(struct device *dev, struct device_attribute *attr,
  897. char *buf)
  898. {
  899. struct dasd_device *device;
  900. ssize_t len;
  901. device = dasd_device_from_cdev(to_ccwdev(dev));
  902. if (!IS_ERR(device)) {
  903. switch (device->state) {
  904. case DASD_STATE_NEW:
  905. len = snprintf(buf, PAGE_SIZE, "new\n");
  906. break;
  907. case DASD_STATE_KNOWN:
  908. len = snprintf(buf, PAGE_SIZE, "detected\n");
  909. break;
  910. case DASD_STATE_BASIC:
  911. len = snprintf(buf, PAGE_SIZE, "basic\n");
  912. break;
  913. case DASD_STATE_UNFMT:
  914. len = snprintf(buf, PAGE_SIZE, "unformatted\n");
  915. break;
  916. case DASD_STATE_READY:
  917. len = snprintf(buf, PAGE_SIZE, "ready\n");
  918. break;
  919. case DASD_STATE_ONLINE:
  920. len = snprintf(buf, PAGE_SIZE, "online\n");
  921. break;
  922. default:
  923. len = snprintf(buf, PAGE_SIZE, "no stat\n");
  924. break;
  925. }
  926. dasd_put_device(device);
  927. } else
  928. len = snprintf(buf, PAGE_SIZE, "unknown\n");
  929. return len;
  930. }
  931. static DEVICE_ATTR(status, 0444, dasd_device_status_show, NULL);
  932. static ssize_t dasd_alias_show(struct device *dev,
  933. struct device_attribute *attr, char *buf)
  934. {
  935. struct dasd_device *device;
  936. struct dasd_uid uid;
  937. device = dasd_device_from_cdev(to_ccwdev(dev));
  938. if (IS_ERR(device))
  939. return sprintf(buf, "0\n");
  940. if (device->discipline && device->discipline->get_uid &&
  941. !device->discipline->get_uid(device, &uid)) {
  942. if (uid.type == UA_BASE_PAV_ALIAS ||
  943. uid.type == UA_HYPER_PAV_ALIAS) {
  944. dasd_put_device(device);
  945. return sprintf(buf, "1\n");
  946. }
  947. }
  948. dasd_put_device(device);
  949. return sprintf(buf, "0\n");
  950. }
  951. static DEVICE_ATTR(alias, 0444, dasd_alias_show, NULL);
  952. static ssize_t dasd_vendor_show(struct device *dev,
  953. struct device_attribute *attr, char *buf)
  954. {
  955. struct dasd_device *device;
  956. struct dasd_uid uid;
  957. char *vendor;
  958. device = dasd_device_from_cdev(to_ccwdev(dev));
  959. vendor = "";
  960. if (IS_ERR(device))
  961. return snprintf(buf, PAGE_SIZE, "%s\n", vendor);
  962. if (device->discipline && device->discipline->get_uid &&
  963. !device->discipline->get_uid(device, &uid))
  964. vendor = uid.vendor;
  965. dasd_put_device(device);
  966. return snprintf(buf, PAGE_SIZE, "%s\n", vendor);
  967. }
  968. static DEVICE_ATTR(vendor, 0444, dasd_vendor_show, NULL);
  969. #define UID_STRLEN ( /* vendor */ 3 + 1 + /* serial */ 14 + 1 +\
  970. /* SSID */ 4 + 1 + /* unit addr */ 2 + 1 +\
  971. /* vduit */ 32 + 1)
  972. static ssize_t
  973. dasd_uid_show(struct device *dev, struct device_attribute *attr, char *buf)
  974. {
  975. struct dasd_device *device;
  976. struct dasd_uid uid;
  977. char uid_string[UID_STRLEN];
  978. char ua_string[3];
  979. device = dasd_device_from_cdev(to_ccwdev(dev));
  980. uid_string[0] = 0;
  981. if (IS_ERR(device))
  982. return snprintf(buf, PAGE_SIZE, "%s\n", uid_string);
  983. if (device->discipline && device->discipline->get_uid &&
  984. !device->discipline->get_uid(device, &uid)) {
  985. switch (uid.type) {
  986. case UA_BASE_DEVICE:
  987. snprintf(ua_string, sizeof(ua_string), "%02x",
  988. uid.real_unit_addr);
  989. break;
  990. case UA_BASE_PAV_ALIAS:
  991. snprintf(ua_string, sizeof(ua_string), "%02x",
  992. uid.base_unit_addr);
  993. break;
  994. case UA_HYPER_PAV_ALIAS:
  995. snprintf(ua_string, sizeof(ua_string), "xx");
  996. break;
  997. default:
  998. /* should not happen, treat like base device */
  999. snprintf(ua_string, sizeof(ua_string), "%02x",
  1000. uid.real_unit_addr);
  1001. break;
  1002. }
  1003. if (strlen(uid.vduit) > 0)
  1004. snprintf(uid_string, sizeof(uid_string),
  1005. "%s.%s.%04x.%s.%s",
  1006. uid.vendor, uid.serial, uid.ssid, ua_string,
  1007. uid.vduit);
  1008. else
  1009. snprintf(uid_string, sizeof(uid_string),
  1010. "%s.%s.%04x.%s",
  1011. uid.vendor, uid.serial, uid.ssid, ua_string);
  1012. }
  1013. dasd_put_device(device);
  1014. return snprintf(buf, PAGE_SIZE, "%s\n", uid_string);
  1015. }
  1016. static DEVICE_ATTR(uid, 0444, dasd_uid_show, NULL);
  1017. /*
  1018. * extended error-reporting
  1019. */
  1020. static ssize_t
  1021. dasd_eer_show(struct device *dev, struct device_attribute *attr, char *buf)
  1022. {
  1023. struct dasd_devmap *devmap;
  1024. int eer_flag;
  1025. devmap = dasd_find_busid(dev_name(dev));
  1026. if (!IS_ERR(devmap) && devmap->device)
  1027. eer_flag = dasd_eer_enabled(devmap->device);
  1028. else
  1029. eer_flag = 0;
  1030. return snprintf(buf, PAGE_SIZE, eer_flag ? "1\n" : "0\n");
  1031. }
  1032. static ssize_t
  1033. dasd_eer_store(struct device *dev, struct device_attribute *attr,
  1034. const char *buf, size_t count)
  1035. {
  1036. struct dasd_devmap *devmap;
  1037. int val, rc;
  1038. char *endp;
  1039. devmap = dasd_devmap_from_cdev(to_ccwdev(dev));
  1040. if (IS_ERR(devmap))
  1041. return PTR_ERR(devmap);
  1042. if (!devmap->device)
  1043. return -ENODEV;
  1044. val = simple_strtoul(buf, &endp, 0);
  1045. if (((endp + 1) < (buf + count)) || (val > 1))
  1046. return -EINVAL;
  1047. if (val) {
  1048. rc = dasd_eer_enable(devmap->device);
  1049. if (rc)
  1050. return rc;
  1051. } else
  1052. dasd_eer_disable(devmap->device);
  1053. return count;
  1054. }
  1055. static DEVICE_ATTR(eer_enabled, 0644, dasd_eer_show, dasd_eer_store);
  1056. /*
  1057. * expiration time for default requests
  1058. */
  1059. static ssize_t
  1060. dasd_expires_show(struct device *dev, struct device_attribute *attr, char *buf)
  1061. {
  1062. struct dasd_device *device;
  1063. int len;
  1064. device = dasd_device_from_cdev(to_ccwdev(dev));
  1065. if (IS_ERR(device))
  1066. return -ENODEV;
  1067. len = snprintf(buf, PAGE_SIZE, "%lu\n", device->default_expires);
  1068. dasd_put_device(device);
  1069. return len;
  1070. }
  1071. static ssize_t
  1072. dasd_expires_store(struct device *dev, struct device_attribute *attr,
  1073. const char *buf, size_t count)
  1074. {
  1075. struct dasd_device *device;
  1076. unsigned long val;
  1077. device = dasd_device_from_cdev(to_ccwdev(dev));
  1078. if (IS_ERR(device))
  1079. return -ENODEV;
  1080. if ((strict_strtoul(buf, 10, &val) != 0) ||
  1081. (val > DASD_EXPIRES_MAX) || val == 0) {
  1082. dasd_put_device(device);
  1083. return -EINVAL;
  1084. }
  1085. if (val)
  1086. device->default_expires = val;
  1087. dasd_put_device(device);
  1088. return count;
  1089. }
  1090. static DEVICE_ATTR(expires, 0644, dasd_expires_show, dasd_expires_store);
  1091. static ssize_t dasd_reservation_policy_show(struct device *dev,
  1092. struct device_attribute *attr,
  1093. char *buf)
  1094. {
  1095. struct dasd_devmap *devmap;
  1096. int rc = 0;
  1097. devmap = dasd_find_busid(dev_name(dev));
  1098. if (IS_ERR(devmap)) {
  1099. rc = snprintf(buf, PAGE_SIZE, "ignore\n");
  1100. } else {
  1101. spin_lock(&dasd_devmap_lock);
  1102. if (devmap->features & DASD_FEATURE_FAILONSLCK)
  1103. rc = snprintf(buf, PAGE_SIZE, "fail\n");
  1104. else
  1105. rc = snprintf(buf, PAGE_SIZE, "ignore\n");
  1106. spin_unlock(&dasd_devmap_lock);
  1107. }
  1108. return rc;
  1109. }
  1110. static ssize_t dasd_reservation_policy_store(struct device *dev,
  1111. struct device_attribute *attr,
  1112. const char *buf, size_t count)
  1113. {
  1114. struct dasd_devmap *devmap;
  1115. int rc;
  1116. devmap = dasd_devmap_from_cdev(to_ccwdev(dev));
  1117. if (IS_ERR(devmap))
  1118. return PTR_ERR(devmap);
  1119. rc = 0;
  1120. spin_lock(&dasd_devmap_lock);
  1121. if (sysfs_streq("ignore", buf))
  1122. devmap->features &= ~DASD_FEATURE_FAILONSLCK;
  1123. else if (sysfs_streq("fail", buf))
  1124. devmap->features |= DASD_FEATURE_FAILONSLCK;
  1125. else
  1126. rc = -EINVAL;
  1127. if (devmap->device)
  1128. devmap->device->features = devmap->features;
  1129. spin_unlock(&dasd_devmap_lock);
  1130. if (rc)
  1131. return rc;
  1132. else
  1133. return count;
  1134. }
  1135. static DEVICE_ATTR(reservation_policy, 0644,
  1136. dasd_reservation_policy_show, dasd_reservation_policy_store);
  1137. static ssize_t dasd_reservation_state_show(struct device *dev,
  1138. struct device_attribute *attr,
  1139. char *buf)
  1140. {
  1141. struct dasd_device *device;
  1142. int rc = 0;
  1143. device = dasd_device_from_cdev(to_ccwdev(dev));
  1144. if (IS_ERR(device))
  1145. return snprintf(buf, PAGE_SIZE, "none\n");
  1146. if (test_bit(DASD_FLAG_IS_RESERVED, &device->flags))
  1147. rc = snprintf(buf, PAGE_SIZE, "reserved\n");
  1148. else if (test_bit(DASD_FLAG_LOCK_STOLEN, &device->flags))
  1149. rc = snprintf(buf, PAGE_SIZE, "lost\n");
  1150. else
  1151. rc = snprintf(buf, PAGE_SIZE, "none\n");
  1152. dasd_put_device(device);
  1153. return rc;
  1154. }
  1155. static ssize_t dasd_reservation_state_store(struct device *dev,
  1156. struct device_attribute *attr,
  1157. const char *buf, size_t count)
  1158. {
  1159. struct dasd_device *device;
  1160. int rc = 0;
  1161. device = dasd_device_from_cdev(to_ccwdev(dev));
  1162. if (IS_ERR(device))
  1163. return -ENODEV;
  1164. if (sysfs_streq("reset", buf))
  1165. clear_bit(DASD_FLAG_LOCK_STOLEN, &device->flags);
  1166. else
  1167. rc = -EINVAL;
  1168. dasd_put_device(device);
  1169. if (rc)
  1170. return rc;
  1171. else
  1172. return count;
  1173. }
  1174. static DEVICE_ATTR(last_known_reservation_state, 0644,
  1175. dasd_reservation_state_show, dasd_reservation_state_store);
  1176. static struct attribute * dasd_attrs[] = {
  1177. &dev_attr_readonly.attr,
  1178. &dev_attr_discipline.attr,
  1179. &dev_attr_status.attr,
  1180. &dev_attr_alias.attr,
  1181. &dev_attr_vendor.attr,
  1182. &dev_attr_uid.attr,
  1183. &dev_attr_use_diag.attr,
  1184. &dev_attr_raw_track_access.attr,
  1185. &dev_attr_eer_enabled.attr,
  1186. &dev_attr_erplog.attr,
  1187. &dev_attr_failfast.attr,
  1188. &dev_attr_expires.attr,
  1189. &dev_attr_reservation_policy.attr,
  1190. &dev_attr_last_known_reservation_state.attr,
  1191. &dev_attr_safe_offline.attr,
  1192. NULL,
  1193. };
  1194. static struct attribute_group dasd_attr_group = {
  1195. .attrs = dasd_attrs,
  1196. };
  1197. /*
  1198. * Return value of the specified feature.
  1199. */
  1200. int
  1201. dasd_get_feature(struct ccw_device *cdev, int feature)
  1202. {
  1203. struct dasd_devmap *devmap;
  1204. devmap = dasd_find_busid(dev_name(&cdev->dev));
  1205. if (IS_ERR(devmap))
  1206. return PTR_ERR(devmap);
  1207. return ((devmap->features & feature) != 0);
  1208. }
  1209. /*
  1210. * Set / reset given feature.
  1211. * Flag indicates whether to set (!=0) or the reset (=0) the feature.
  1212. */
  1213. int
  1214. dasd_set_feature(struct ccw_device *cdev, int feature, int flag)
  1215. {
  1216. struct dasd_devmap *devmap;
  1217. devmap = dasd_find_busid(dev_name(&cdev->dev));
  1218. if (IS_ERR(devmap))
  1219. return PTR_ERR(devmap);
  1220. spin_lock(&dasd_devmap_lock);
  1221. if (flag)
  1222. devmap->features |= feature;
  1223. else
  1224. devmap->features &= ~feature;
  1225. if (devmap->device)
  1226. devmap->device->features = devmap->features;
  1227. spin_unlock(&dasd_devmap_lock);
  1228. return 0;
  1229. }
  1230. int
  1231. dasd_add_sysfs_files(struct ccw_device *cdev)
  1232. {
  1233. return sysfs_create_group(&cdev->dev.kobj, &dasd_attr_group);
  1234. }
  1235. void
  1236. dasd_remove_sysfs_files(struct ccw_device *cdev)
  1237. {
  1238. sysfs_remove_group(&cdev->dev.kobj, &dasd_attr_group);
  1239. }
  1240. int
  1241. dasd_devmap_init(void)
  1242. {
  1243. int i;
  1244. /* Initialize devmap structures. */
  1245. dasd_max_devindex = 0;
  1246. for (i = 0; i < 256; i++)
  1247. INIT_LIST_HEAD(&dasd_hashlists[i]);
  1248. return 0;
  1249. }
  1250. void
  1251. dasd_devmap_exit(void)
  1252. {
  1253. dasd_forget_ranges();
  1254. }