dasd_devmap.c 41 KB

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