dasd_devmap.c 40 KB

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