dasd_devmap.c 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809
  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. #define DASD_DEFINE_ATTR(_name, _func) \
  1396. static ssize_t dasd_##_name##_show(struct device *dev, \
  1397. struct device_attribute *attr, \
  1398. char *buf) \
  1399. { \
  1400. struct ccw_device *cdev = to_ccwdev(dev); \
  1401. struct dasd_device *device = dasd_device_from_cdev(cdev); \
  1402. int val = 0; \
  1403. \
  1404. if (IS_ERR(device)) \
  1405. return -ENODEV; \
  1406. if (device->discipline && _func) \
  1407. val = _func(device); \
  1408. dasd_put_device(device); \
  1409. \
  1410. return snprintf(buf, PAGE_SIZE, "%d\n", val); \
  1411. } \
  1412. static DEVICE_ATTR(_name, 0444, dasd_##_name##_show, NULL); \
  1413. DASD_DEFINE_ATTR(ese, device->discipline->is_ese);
  1414. DASD_DEFINE_ATTR(extent_size, device->discipline->ext_size);
  1415. DASD_DEFINE_ATTR(pool_id, device->discipline->ext_pool_id);
  1416. DASD_DEFINE_ATTR(space_configured, device->discipline->space_configured);
  1417. DASD_DEFINE_ATTR(space_allocated, device->discipline->space_allocated);
  1418. DASD_DEFINE_ATTR(logical_capacity, device->discipline->logical_capacity);
  1419. DASD_DEFINE_ATTR(warn_threshold, device->discipline->ext_pool_warn_thrshld);
  1420. DASD_DEFINE_ATTR(cap_at_warnlevel, device->discipline->ext_pool_cap_at_warnlevel);
  1421. DASD_DEFINE_ATTR(pool_oos, device->discipline->ext_pool_oos);
  1422. static struct attribute * dasd_attrs[] = {
  1423. &dev_attr_readonly.attr,
  1424. &dev_attr_discipline.attr,
  1425. &dev_attr_status.attr,
  1426. &dev_attr_alias.attr,
  1427. &dev_attr_vendor.attr,
  1428. &dev_attr_uid.attr,
  1429. &dev_attr_use_diag.attr,
  1430. &dev_attr_raw_track_access.attr,
  1431. &dev_attr_eer_enabled.attr,
  1432. &dev_attr_erplog.attr,
  1433. &dev_attr_failfast.attr,
  1434. &dev_attr_expires.attr,
  1435. &dev_attr_retries.attr,
  1436. &dev_attr_timeout.attr,
  1437. &dev_attr_reservation_policy.attr,
  1438. &dev_attr_last_known_reservation_state.attr,
  1439. &dev_attr_safe_offline.attr,
  1440. &dev_attr_host_access_count.attr,
  1441. &dev_attr_path_masks.attr,
  1442. &dev_attr_path_threshold.attr,
  1443. &dev_attr_path_autodisable.attr,
  1444. &dev_attr_path_interval.attr,
  1445. &dev_attr_path_reset.attr,
  1446. &dev_attr_hpf.attr,
  1447. &dev_attr_ese.attr,
  1448. NULL,
  1449. };
  1450. static const struct attribute_group dasd_attr_group = {
  1451. .attrs = dasd_attrs,
  1452. };
  1453. static struct attribute *capacity_attrs[] = {
  1454. &dev_attr_space_configured.attr,
  1455. &dev_attr_space_allocated.attr,
  1456. &dev_attr_logical_capacity.attr,
  1457. NULL,
  1458. };
  1459. static const struct attribute_group capacity_attr_group = {
  1460. .name = "capacity",
  1461. .attrs = capacity_attrs,
  1462. };
  1463. static struct attribute *ext_pool_attrs[] = {
  1464. &dev_attr_pool_id.attr,
  1465. &dev_attr_extent_size.attr,
  1466. &dev_attr_warn_threshold.attr,
  1467. &dev_attr_cap_at_warnlevel.attr,
  1468. &dev_attr_pool_oos.attr,
  1469. NULL,
  1470. };
  1471. static const struct attribute_group ext_pool_attr_group = {
  1472. .name = "extent_pool",
  1473. .attrs = ext_pool_attrs,
  1474. };
  1475. static const struct attribute_group *dasd_attr_groups[] = {
  1476. &dasd_attr_group,
  1477. &capacity_attr_group,
  1478. &ext_pool_attr_group,
  1479. NULL,
  1480. };
  1481. /*
  1482. * Return value of the specified feature.
  1483. */
  1484. int
  1485. dasd_get_feature(struct ccw_device *cdev, int feature)
  1486. {
  1487. struct dasd_devmap *devmap;
  1488. devmap = dasd_find_busid(dev_name(&cdev->dev));
  1489. if (IS_ERR(devmap))
  1490. return PTR_ERR(devmap);
  1491. return ((devmap->features & feature) != 0);
  1492. }
  1493. /*
  1494. * Set / reset given feature.
  1495. * Flag indicates whether to set (!=0) or the reset (=0) the feature.
  1496. */
  1497. int
  1498. dasd_set_feature(struct ccw_device *cdev, int feature, int flag)
  1499. {
  1500. struct dasd_devmap *devmap;
  1501. devmap = dasd_devmap_from_cdev(cdev);
  1502. if (IS_ERR(devmap))
  1503. return PTR_ERR(devmap);
  1504. spin_lock(&dasd_devmap_lock);
  1505. if (flag)
  1506. devmap->features |= feature;
  1507. else
  1508. devmap->features &= ~feature;
  1509. if (devmap->device)
  1510. devmap->device->features = devmap->features;
  1511. spin_unlock(&dasd_devmap_lock);
  1512. return 0;
  1513. }
  1514. EXPORT_SYMBOL(dasd_set_feature);
  1515. int dasd_add_sysfs_files(struct ccw_device *cdev)
  1516. {
  1517. return sysfs_create_groups(&cdev->dev.kobj, dasd_attr_groups);
  1518. }
  1519. void
  1520. dasd_remove_sysfs_files(struct ccw_device *cdev)
  1521. {
  1522. sysfs_remove_groups(&cdev->dev.kobj, dasd_attr_groups);
  1523. }
  1524. int
  1525. dasd_devmap_init(void)
  1526. {
  1527. int i;
  1528. /* Initialize devmap structures. */
  1529. dasd_max_devindex = 0;
  1530. for (i = 0; i < 256; i++)
  1531. INIT_LIST_HEAD(&dasd_hashlists[i]);
  1532. return 0;
  1533. }
  1534. void
  1535. dasd_devmap_exit(void)
  1536. {
  1537. dasd_forget_ranges();
  1538. }