dasd_devmap.c 40 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706
  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 > 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. int rc = 0;
  277. char *tmp;
  278. tmp = kstrdup(range, GFP_KERNEL);
  279. if (!tmp)
  280. return -ENOMEM;
  281. if (dasd_evaluate_range_param(tmp, &from_str, &to_str, &features_str)) {
  282. rc = -EINVAL;
  283. goto out;
  284. }
  285. if (dasd_busid(from_str, &from_id0, &from_id1, &from)) {
  286. rc = -EINVAL;
  287. goto out;
  288. }
  289. to = from;
  290. to_id0 = from_id0;
  291. to_id1 = from_id1;
  292. if (to_str) {
  293. if (dasd_busid(to_str, &to_id0, &to_id1, &to)) {
  294. rc = -EINVAL;
  295. goto out;
  296. }
  297. if (from_id0 != to_id0 || from_id1 != to_id1 || from > to) {
  298. pr_err("%s is not a valid device range\n", range);
  299. rc = -EINVAL;
  300. goto out;
  301. }
  302. }
  303. features = dasd_feature_list(features_str);
  304. if (features < 0) {
  305. rc = -EINVAL;
  306. goto out;
  307. }
  308. /* each device in dasd= parameter should be set initially online */
  309. features |= DASD_FEATURE_INITIAL_ONLINE;
  310. while (from <= to) {
  311. sprintf(bus_id, "%01x.%01x.%04x", from_id0, from_id1, from++);
  312. devmap = dasd_add_busid(bus_id, features);
  313. if (IS_ERR(devmap)) {
  314. rc = PTR_ERR(devmap);
  315. goto out;
  316. }
  317. }
  318. out:
  319. kfree(tmp);
  320. return rc;
  321. }
  322. /*
  323. * Parse parameters stored in dasd[]
  324. * The 'dasd=...' parameter allows to specify a comma separated list of
  325. * keywords and device ranges. The parameters in that list will be stored as
  326. * separate elementes in dasd[].
  327. */
  328. int __init dasd_parse(void)
  329. {
  330. int rc, i;
  331. char *cur;
  332. rc = 0;
  333. for (i = 0; i < DASD_MAX_PARAMS; i++) {
  334. cur = dasd[i];
  335. if (!cur)
  336. break;
  337. if (*cur == '\0')
  338. continue;
  339. rc = dasd_parse_keyword(cur);
  340. if (rc)
  341. rc = dasd_parse_range(cur);
  342. if (rc)
  343. break;
  344. }
  345. return rc;
  346. }
  347. /*
  348. * Add a devmap for the device specified by busid. It is possible that
  349. * the devmap already exists (dasd= parameter). The order of the devices
  350. * added through this function will define the kdevs for the individual
  351. * devices.
  352. */
  353. static struct dasd_devmap *
  354. dasd_add_busid(const char *bus_id, int features)
  355. {
  356. struct dasd_devmap *devmap, *new, *tmp;
  357. int hash;
  358. new = kzalloc(sizeof(struct dasd_devmap), GFP_KERNEL);
  359. if (!new)
  360. return ERR_PTR(-ENOMEM);
  361. spin_lock(&dasd_devmap_lock);
  362. devmap = NULL;
  363. hash = dasd_hash_busid(bus_id);
  364. list_for_each_entry(tmp, &dasd_hashlists[hash], list)
  365. if (strncmp(tmp->bus_id, bus_id, DASD_BUS_ID_SIZE) == 0) {
  366. devmap = tmp;
  367. break;
  368. }
  369. if (!devmap) {
  370. /* This bus_id is new. */
  371. new->devindex = dasd_max_devindex++;
  372. strncpy(new->bus_id, bus_id, DASD_BUS_ID_SIZE);
  373. new->features = features;
  374. new->device = NULL;
  375. list_add(&new->list, &dasd_hashlists[hash]);
  376. devmap = new;
  377. new = NULL;
  378. }
  379. spin_unlock(&dasd_devmap_lock);
  380. kfree(new);
  381. return devmap;
  382. }
  383. /*
  384. * Find devmap for device with given bus_id.
  385. */
  386. static struct dasd_devmap *
  387. dasd_find_busid(const char *bus_id)
  388. {
  389. struct dasd_devmap *devmap, *tmp;
  390. int hash;
  391. spin_lock(&dasd_devmap_lock);
  392. devmap = ERR_PTR(-ENODEV);
  393. hash = dasd_hash_busid(bus_id);
  394. list_for_each_entry(tmp, &dasd_hashlists[hash], list) {
  395. if (strncmp(tmp->bus_id, bus_id, DASD_BUS_ID_SIZE) == 0) {
  396. devmap = tmp;
  397. break;
  398. }
  399. }
  400. spin_unlock(&dasd_devmap_lock);
  401. return devmap;
  402. }
  403. /*
  404. * Check if busid has been added to the list of dasd ranges.
  405. */
  406. int
  407. dasd_busid_known(const char *bus_id)
  408. {
  409. return IS_ERR(dasd_find_busid(bus_id)) ? -ENOENT : 0;
  410. }
  411. /*
  412. * Forget all about the device numbers added so far.
  413. * This may only be called at module unload or system shutdown.
  414. */
  415. static void
  416. dasd_forget_ranges(void)
  417. {
  418. struct dasd_devmap *devmap, *n;
  419. int i;
  420. spin_lock(&dasd_devmap_lock);
  421. for (i = 0; i < 256; i++) {
  422. list_for_each_entry_safe(devmap, n, &dasd_hashlists[i], list) {
  423. BUG_ON(devmap->device != NULL);
  424. list_del(&devmap->list);
  425. kfree(devmap);
  426. }
  427. }
  428. spin_unlock(&dasd_devmap_lock);
  429. }
  430. /*
  431. * Find the device struct by its device index.
  432. */
  433. struct dasd_device *
  434. dasd_device_from_devindex(int devindex)
  435. {
  436. struct dasd_devmap *devmap, *tmp;
  437. struct dasd_device *device;
  438. int i;
  439. spin_lock(&dasd_devmap_lock);
  440. devmap = NULL;
  441. for (i = 0; (i < 256) && !devmap; i++)
  442. list_for_each_entry(tmp, &dasd_hashlists[i], list)
  443. if (tmp->devindex == devindex) {
  444. /* Found the devmap for the device. */
  445. devmap = tmp;
  446. break;
  447. }
  448. if (devmap && devmap->device) {
  449. device = devmap->device;
  450. dasd_get_device(device);
  451. } else
  452. device = ERR_PTR(-ENODEV);
  453. spin_unlock(&dasd_devmap_lock);
  454. return device;
  455. }
  456. /*
  457. * Return devmap for cdev. If no devmap exists yet, create one and
  458. * connect it to the cdev.
  459. */
  460. static struct dasd_devmap *
  461. dasd_devmap_from_cdev(struct ccw_device *cdev)
  462. {
  463. struct dasd_devmap *devmap;
  464. devmap = dasd_find_busid(dev_name(&cdev->dev));
  465. if (IS_ERR(devmap))
  466. devmap = dasd_add_busid(dev_name(&cdev->dev),
  467. DASD_FEATURE_DEFAULT);
  468. return devmap;
  469. }
  470. /*
  471. * Create a dasd device structure for cdev.
  472. */
  473. struct dasd_device *
  474. dasd_create_device(struct ccw_device *cdev)
  475. {
  476. struct dasd_devmap *devmap;
  477. struct dasd_device *device;
  478. unsigned long flags;
  479. int rc;
  480. devmap = dasd_devmap_from_cdev(cdev);
  481. if (IS_ERR(devmap))
  482. return (void *) devmap;
  483. device = dasd_alloc_device();
  484. if (IS_ERR(device))
  485. return device;
  486. atomic_set(&device->ref_count, 3);
  487. spin_lock(&dasd_devmap_lock);
  488. if (!devmap->device) {
  489. devmap->device = device;
  490. device->devindex = devmap->devindex;
  491. device->features = devmap->features;
  492. get_device(&cdev->dev);
  493. device->cdev = cdev;
  494. rc = 0;
  495. } else
  496. /* Someone else was faster. */
  497. rc = -EBUSY;
  498. spin_unlock(&dasd_devmap_lock);
  499. if (rc) {
  500. dasd_free_device(device);
  501. return ERR_PTR(rc);
  502. }
  503. spin_lock_irqsave(get_ccwdev_lock(cdev), flags);
  504. dev_set_drvdata(&cdev->dev, device);
  505. spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags);
  506. return device;
  507. }
  508. /*
  509. * Wait queue for dasd_delete_device waits.
  510. */
  511. static DECLARE_WAIT_QUEUE_HEAD(dasd_delete_wq);
  512. /*
  513. * Remove a dasd device structure. The passed referenced
  514. * is destroyed.
  515. */
  516. void
  517. dasd_delete_device(struct dasd_device *device)
  518. {
  519. struct ccw_device *cdev;
  520. struct dasd_devmap *devmap;
  521. unsigned long flags;
  522. /* First remove device pointer from devmap. */
  523. devmap = dasd_find_busid(dev_name(&device->cdev->dev));
  524. BUG_ON(IS_ERR(devmap));
  525. spin_lock(&dasd_devmap_lock);
  526. if (devmap->device != device) {
  527. spin_unlock(&dasd_devmap_lock);
  528. dasd_put_device(device);
  529. return;
  530. }
  531. devmap->device = NULL;
  532. spin_unlock(&dasd_devmap_lock);
  533. /* Disconnect dasd_device structure from ccw_device structure. */
  534. spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
  535. dev_set_drvdata(&device->cdev->dev, NULL);
  536. spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
  537. /*
  538. * Drop ref_count by 3, one for the devmap reference, one for
  539. * the cdev reference and one for the passed reference.
  540. */
  541. atomic_sub(3, &device->ref_count);
  542. /* Wait for reference counter to drop to zero. */
  543. wait_event(dasd_delete_wq, atomic_read(&device->ref_count) == 0);
  544. dasd_generic_free_discipline(device);
  545. /* Disconnect dasd_device structure from ccw_device structure. */
  546. cdev = device->cdev;
  547. device->cdev = NULL;
  548. /* Put ccw_device structure. */
  549. put_device(&cdev->dev);
  550. /* Now the device structure can be freed. */
  551. dasd_free_device(device);
  552. }
  553. /*
  554. * Reference counter dropped to zero. Wake up waiter
  555. * in dasd_delete_device.
  556. */
  557. void
  558. dasd_put_device_wake(struct dasd_device *device)
  559. {
  560. wake_up(&dasd_delete_wq);
  561. }
  562. EXPORT_SYMBOL_GPL(dasd_put_device_wake);
  563. /*
  564. * Return dasd_device structure associated with cdev.
  565. * This function needs to be called with the ccw device
  566. * lock held. It can be used from interrupt context.
  567. */
  568. struct dasd_device *
  569. dasd_device_from_cdev_locked(struct ccw_device *cdev)
  570. {
  571. struct dasd_device *device = dev_get_drvdata(&cdev->dev);
  572. if (!device)
  573. return ERR_PTR(-ENODEV);
  574. dasd_get_device(device);
  575. return device;
  576. }
  577. /*
  578. * Return dasd_device structure associated with cdev.
  579. */
  580. struct dasd_device *
  581. dasd_device_from_cdev(struct ccw_device *cdev)
  582. {
  583. struct dasd_device *device;
  584. unsigned long flags;
  585. spin_lock_irqsave(get_ccwdev_lock(cdev), flags);
  586. device = dasd_device_from_cdev_locked(cdev);
  587. spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags);
  588. return device;
  589. }
  590. void dasd_add_link_to_gendisk(struct gendisk *gdp, struct dasd_device *device)
  591. {
  592. struct dasd_devmap *devmap;
  593. devmap = dasd_find_busid(dev_name(&device->cdev->dev));
  594. if (IS_ERR(devmap))
  595. return;
  596. spin_lock(&dasd_devmap_lock);
  597. gdp->private_data = devmap;
  598. spin_unlock(&dasd_devmap_lock);
  599. }
  600. struct dasd_device *dasd_device_from_gendisk(struct gendisk *gdp)
  601. {
  602. struct dasd_device *device;
  603. struct dasd_devmap *devmap;
  604. if (!gdp->private_data)
  605. return NULL;
  606. device = NULL;
  607. spin_lock(&dasd_devmap_lock);
  608. devmap = gdp->private_data;
  609. if (devmap && devmap->device) {
  610. device = devmap->device;
  611. dasd_get_device(device);
  612. }
  613. spin_unlock(&dasd_devmap_lock);
  614. return device;
  615. }
  616. /*
  617. * SECTION: files in sysfs
  618. */
  619. /*
  620. * failfast controls the behaviour, if no path is available
  621. */
  622. static ssize_t dasd_ff_show(struct device *dev, struct device_attribute *attr,
  623. char *buf)
  624. {
  625. struct dasd_devmap *devmap;
  626. int ff_flag;
  627. devmap = dasd_find_busid(dev_name(dev));
  628. if (!IS_ERR(devmap))
  629. ff_flag = (devmap->features & DASD_FEATURE_FAILFAST) != 0;
  630. else
  631. ff_flag = (DASD_FEATURE_DEFAULT & DASD_FEATURE_FAILFAST) != 0;
  632. return snprintf(buf, PAGE_SIZE, ff_flag ? "1\n" : "0\n");
  633. }
  634. static ssize_t dasd_ff_store(struct device *dev, struct device_attribute *attr,
  635. const char *buf, size_t count)
  636. {
  637. unsigned int val;
  638. int rc;
  639. if (kstrtouint(buf, 0, &val) || val > 1)
  640. return -EINVAL;
  641. rc = dasd_set_feature(to_ccwdev(dev), DASD_FEATURE_FAILFAST, val);
  642. return rc ? : count;
  643. }
  644. static DEVICE_ATTR(failfast, 0644, dasd_ff_show, dasd_ff_store);
  645. /*
  646. * readonly controls the readonly status of a dasd
  647. */
  648. static ssize_t
  649. dasd_ro_show(struct device *dev, struct device_attribute *attr, char *buf)
  650. {
  651. struct dasd_devmap *devmap;
  652. struct dasd_device *device;
  653. int ro_flag = 0;
  654. devmap = dasd_find_busid(dev_name(dev));
  655. if (IS_ERR(devmap))
  656. goto out;
  657. ro_flag = !!(devmap->features & DASD_FEATURE_READONLY);
  658. spin_lock(&dasd_devmap_lock);
  659. device = devmap->device;
  660. if (device)
  661. ro_flag |= test_bit(DASD_FLAG_DEVICE_RO, &device->flags);
  662. spin_unlock(&dasd_devmap_lock);
  663. out:
  664. return snprintf(buf, PAGE_SIZE, ro_flag ? "1\n" : "0\n");
  665. }
  666. static ssize_t
  667. dasd_ro_store(struct device *dev, struct device_attribute *attr,
  668. const char *buf, size_t count)
  669. {
  670. struct ccw_device *cdev = to_ccwdev(dev);
  671. struct dasd_device *device;
  672. unsigned long flags;
  673. unsigned int val;
  674. int rc;
  675. if (kstrtouint(buf, 0, &val) || val > 1)
  676. return -EINVAL;
  677. rc = dasd_set_feature(cdev, DASD_FEATURE_READONLY, val);
  678. if (rc)
  679. return rc;
  680. device = dasd_device_from_cdev(cdev);
  681. if (IS_ERR(device))
  682. return count;
  683. spin_lock_irqsave(get_ccwdev_lock(cdev), flags);
  684. val = val || test_bit(DASD_FLAG_DEVICE_RO, &device->flags);
  685. if (!device->block || !device->block->gdp ||
  686. test_bit(DASD_FLAG_OFFLINE, &device->flags)) {
  687. spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags);
  688. goto out;
  689. }
  690. /* Increase open_count to avoid losing the block device */
  691. atomic_inc(&device->block->open_count);
  692. spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags);
  693. set_disk_ro(device->block->gdp, val);
  694. atomic_dec(&device->block->open_count);
  695. out:
  696. dasd_put_device(device);
  697. return count;
  698. }
  699. static DEVICE_ATTR(readonly, 0644, dasd_ro_show, dasd_ro_store);
  700. /*
  701. * erplog controls the logging of ERP related data
  702. * (e.g. failing channel programs).
  703. */
  704. static ssize_t
  705. dasd_erplog_show(struct device *dev, struct device_attribute *attr, char *buf)
  706. {
  707. struct dasd_devmap *devmap;
  708. int erplog;
  709. devmap = dasd_find_busid(dev_name(dev));
  710. if (!IS_ERR(devmap))
  711. erplog = (devmap->features & DASD_FEATURE_ERPLOG) != 0;
  712. else
  713. erplog = (DASD_FEATURE_DEFAULT & DASD_FEATURE_ERPLOG) != 0;
  714. return snprintf(buf, PAGE_SIZE, erplog ? "1\n" : "0\n");
  715. }
  716. static ssize_t
  717. dasd_erplog_store(struct device *dev, struct device_attribute *attr,
  718. const char *buf, size_t count)
  719. {
  720. unsigned int val;
  721. int rc;
  722. if (kstrtouint(buf, 0, &val) || val > 1)
  723. return -EINVAL;
  724. rc = dasd_set_feature(to_ccwdev(dev), DASD_FEATURE_ERPLOG, val);
  725. return rc ? : count;
  726. }
  727. static DEVICE_ATTR(erplog, 0644, dasd_erplog_show, dasd_erplog_store);
  728. /*
  729. * use_diag controls whether the driver should use diag rather than ssch
  730. * to talk to the device
  731. */
  732. static ssize_t
  733. dasd_use_diag_show(struct device *dev, struct device_attribute *attr, char *buf)
  734. {
  735. struct dasd_devmap *devmap;
  736. int use_diag;
  737. devmap = dasd_find_busid(dev_name(dev));
  738. if (!IS_ERR(devmap))
  739. use_diag = (devmap->features & DASD_FEATURE_USEDIAG) != 0;
  740. else
  741. use_diag = (DASD_FEATURE_DEFAULT & DASD_FEATURE_USEDIAG) != 0;
  742. return sprintf(buf, use_diag ? "1\n" : "0\n");
  743. }
  744. static ssize_t
  745. dasd_use_diag_store(struct device *dev, struct device_attribute *attr,
  746. const char *buf, size_t count)
  747. {
  748. struct dasd_devmap *devmap;
  749. unsigned int val;
  750. ssize_t rc;
  751. devmap = dasd_devmap_from_cdev(to_ccwdev(dev));
  752. if (IS_ERR(devmap))
  753. return PTR_ERR(devmap);
  754. if (kstrtouint(buf, 0, &val) || val > 1)
  755. return -EINVAL;
  756. spin_lock(&dasd_devmap_lock);
  757. /* Changing diag discipline flag is only allowed in offline state. */
  758. rc = count;
  759. if (!devmap->device && !(devmap->features & DASD_FEATURE_USERAW)) {
  760. if (val)
  761. devmap->features |= DASD_FEATURE_USEDIAG;
  762. else
  763. devmap->features &= ~DASD_FEATURE_USEDIAG;
  764. } else
  765. rc = -EPERM;
  766. spin_unlock(&dasd_devmap_lock);
  767. return rc;
  768. }
  769. static DEVICE_ATTR(use_diag, 0644, dasd_use_diag_show, dasd_use_diag_store);
  770. /*
  771. * use_raw controls whether the driver should give access to raw eckd data or
  772. * operate in standard mode
  773. */
  774. static ssize_t
  775. dasd_use_raw_show(struct device *dev, struct device_attribute *attr, char *buf)
  776. {
  777. struct dasd_devmap *devmap;
  778. int use_raw;
  779. devmap = dasd_find_busid(dev_name(dev));
  780. if (!IS_ERR(devmap))
  781. use_raw = (devmap->features & DASD_FEATURE_USERAW) != 0;
  782. else
  783. use_raw = (DASD_FEATURE_DEFAULT & DASD_FEATURE_USERAW) != 0;
  784. return sprintf(buf, use_raw ? "1\n" : "0\n");
  785. }
  786. static ssize_t
  787. dasd_use_raw_store(struct device *dev, struct device_attribute *attr,
  788. const char *buf, size_t count)
  789. {
  790. struct dasd_devmap *devmap;
  791. ssize_t rc;
  792. unsigned long val;
  793. devmap = dasd_devmap_from_cdev(to_ccwdev(dev));
  794. if (IS_ERR(devmap))
  795. return PTR_ERR(devmap);
  796. if ((kstrtoul(buf, 10, &val) != 0) || val > 1)
  797. return -EINVAL;
  798. spin_lock(&dasd_devmap_lock);
  799. /* Changing diag discipline flag is only allowed in offline state. */
  800. rc = count;
  801. if (!devmap->device && !(devmap->features & DASD_FEATURE_USEDIAG)) {
  802. if (val)
  803. devmap->features |= DASD_FEATURE_USERAW;
  804. else
  805. devmap->features &= ~DASD_FEATURE_USERAW;
  806. } else
  807. rc = -EPERM;
  808. spin_unlock(&dasd_devmap_lock);
  809. return rc;
  810. }
  811. static DEVICE_ATTR(raw_track_access, 0644, dasd_use_raw_show,
  812. dasd_use_raw_store);
  813. static ssize_t
  814. dasd_safe_offline_store(struct device *dev, struct device_attribute *attr,
  815. const char *buf, size_t count)
  816. {
  817. struct ccw_device *cdev = to_ccwdev(dev);
  818. struct dasd_device *device;
  819. unsigned long flags;
  820. int rc;
  821. spin_lock_irqsave(get_ccwdev_lock(cdev), flags);
  822. device = dasd_device_from_cdev_locked(cdev);
  823. if (IS_ERR(device)) {
  824. rc = PTR_ERR(device);
  825. spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags);
  826. goto out;
  827. }
  828. if (test_bit(DASD_FLAG_OFFLINE, &device->flags) ||
  829. test_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING, &device->flags)) {
  830. /* Already doing offline processing */
  831. dasd_put_device(device);
  832. spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags);
  833. rc = -EBUSY;
  834. goto out;
  835. }
  836. set_bit(DASD_FLAG_SAFE_OFFLINE, &device->flags);
  837. dasd_put_device(device);
  838. spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags);
  839. rc = ccw_device_set_offline(cdev);
  840. out:
  841. return rc ? rc : count;
  842. }
  843. static DEVICE_ATTR(safe_offline, 0200, NULL, dasd_safe_offline_store);
  844. static ssize_t
  845. dasd_access_show(struct device *dev, struct device_attribute *attr,
  846. char *buf)
  847. {
  848. struct ccw_device *cdev = to_ccwdev(dev);
  849. struct dasd_device *device;
  850. int count;
  851. device = dasd_device_from_cdev(cdev);
  852. if (IS_ERR(device))
  853. return PTR_ERR(device);
  854. if (!device->discipline)
  855. count = -ENODEV;
  856. else if (!device->discipline->host_access_count)
  857. count = -EOPNOTSUPP;
  858. else
  859. count = device->discipline->host_access_count(device);
  860. dasd_put_device(device);
  861. if (count < 0)
  862. return count;
  863. return sprintf(buf, "%d\n", count);
  864. }
  865. static DEVICE_ATTR(host_access_count, 0444, dasd_access_show, NULL);
  866. static ssize_t
  867. dasd_discipline_show(struct device *dev, struct device_attribute *attr,
  868. char *buf)
  869. {
  870. struct dasd_device *device;
  871. ssize_t len;
  872. device = dasd_device_from_cdev(to_ccwdev(dev));
  873. if (IS_ERR(device))
  874. goto out;
  875. else if (!device->discipline) {
  876. dasd_put_device(device);
  877. goto out;
  878. } else {
  879. len = snprintf(buf, PAGE_SIZE, "%s\n",
  880. device->discipline->name);
  881. dasd_put_device(device);
  882. return len;
  883. }
  884. out:
  885. len = snprintf(buf, PAGE_SIZE, "none\n");
  886. return len;
  887. }
  888. static DEVICE_ATTR(discipline, 0444, dasd_discipline_show, NULL);
  889. static ssize_t
  890. dasd_device_status_show(struct device *dev, struct device_attribute *attr,
  891. char *buf)
  892. {
  893. struct dasd_device *device;
  894. ssize_t len;
  895. device = dasd_device_from_cdev(to_ccwdev(dev));
  896. if (!IS_ERR(device)) {
  897. switch (device->state) {
  898. case DASD_STATE_NEW:
  899. len = snprintf(buf, PAGE_SIZE, "new\n");
  900. break;
  901. case DASD_STATE_KNOWN:
  902. len = snprintf(buf, PAGE_SIZE, "detected\n");
  903. break;
  904. case DASD_STATE_BASIC:
  905. len = snprintf(buf, PAGE_SIZE, "basic\n");
  906. break;
  907. case DASD_STATE_UNFMT:
  908. len = snprintf(buf, PAGE_SIZE, "unformatted\n");
  909. break;
  910. case DASD_STATE_READY:
  911. len = snprintf(buf, PAGE_SIZE, "ready\n");
  912. break;
  913. case DASD_STATE_ONLINE:
  914. len = snprintf(buf, PAGE_SIZE, "online\n");
  915. break;
  916. default:
  917. len = snprintf(buf, PAGE_SIZE, "no stat\n");
  918. break;
  919. }
  920. dasd_put_device(device);
  921. } else
  922. len = snprintf(buf, PAGE_SIZE, "unknown\n");
  923. return len;
  924. }
  925. static DEVICE_ATTR(status, 0444, dasd_device_status_show, NULL);
  926. static ssize_t dasd_alias_show(struct device *dev,
  927. struct device_attribute *attr, char *buf)
  928. {
  929. struct dasd_device *device;
  930. struct dasd_uid uid;
  931. device = dasd_device_from_cdev(to_ccwdev(dev));
  932. if (IS_ERR(device))
  933. return sprintf(buf, "0\n");
  934. if (device->discipline && device->discipline->get_uid &&
  935. !device->discipline->get_uid(device, &uid)) {
  936. if (uid.type == UA_BASE_PAV_ALIAS ||
  937. uid.type == UA_HYPER_PAV_ALIAS) {
  938. dasd_put_device(device);
  939. return sprintf(buf, "1\n");
  940. }
  941. }
  942. dasd_put_device(device);
  943. return sprintf(buf, "0\n");
  944. }
  945. static DEVICE_ATTR(alias, 0444, dasd_alias_show, NULL);
  946. static ssize_t dasd_vendor_show(struct device *dev,
  947. struct device_attribute *attr, char *buf)
  948. {
  949. struct dasd_device *device;
  950. struct dasd_uid uid;
  951. char *vendor;
  952. device = dasd_device_from_cdev(to_ccwdev(dev));
  953. vendor = "";
  954. if (IS_ERR(device))
  955. return snprintf(buf, PAGE_SIZE, "%s\n", vendor);
  956. if (device->discipline && device->discipline->get_uid &&
  957. !device->discipline->get_uid(device, &uid))
  958. vendor = uid.vendor;
  959. dasd_put_device(device);
  960. return snprintf(buf, PAGE_SIZE, "%s\n", vendor);
  961. }
  962. static DEVICE_ATTR(vendor, 0444, dasd_vendor_show, NULL);
  963. #define UID_STRLEN ( /* vendor */ 3 + 1 + /* serial */ 14 + 1 +\
  964. /* SSID */ 4 + 1 + /* unit addr */ 2 + 1 +\
  965. /* vduit */ 32 + 1)
  966. static ssize_t
  967. dasd_uid_show(struct device *dev, struct device_attribute *attr, char *buf)
  968. {
  969. struct dasd_device *device;
  970. struct dasd_uid uid;
  971. char uid_string[UID_STRLEN];
  972. char ua_string[3];
  973. device = dasd_device_from_cdev(to_ccwdev(dev));
  974. uid_string[0] = 0;
  975. if (IS_ERR(device))
  976. return snprintf(buf, PAGE_SIZE, "%s\n", uid_string);
  977. if (device->discipline && device->discipline->get_uid &&
  978. !device->discipline->get_uid(device, &uid)) {
  979. switch (uid.type) {
  980. case UA_BASE_DEVICE:
  981. snprintf(ua_string, sizeof(ua_string), "%02x",
  982. uid.real_unit_addr);
  983. break;
  984. case UA_BASE_PAV_ALIAS:
  985. snprintf(ua_string, sizeof(ua_string), "%02x",
  986. uid.base_unit_addr);
  987. break;
  988. case UA_HYPER_PAV_ALIAS:
  989. snprintf(ua_string, sizeof(ua_string), "xx");
  990. break;
  991. default:
  992. /* should not happen, treat like base device */
  993. snprintf(ua_string, sizeof(ua_string), "%02x",
  994. uid.real_unit_addr);
  995. break;
  996. }
  997. if (strlen(uid.vduit) > 0)
  998. snprintf(uid_string, sizeof(uid_string),
  999. "%s.%s.%04x.%s.%s",
  1000. uid.vendor, uid.serial, uid.ssid, ua_string,
  1001. uid.vduit);
  1002. else
  1003. snprintf(uid_string, sizeof(uid_string),
  1004. "%s.%s.%04x.%s",
  1005. uid.vendor, uid.serial, uid.ssid, ua_string);
  1006. }
  1007. dasd_put_device(device);
  1008. return snprintf(buf, PAGE_SIZE, "%s\n", uid_string);
  1009. }
  1010. static DEVICE_ATTR(uid, 0444, dasd_uid_show, NULL);
  1011. /*
  1012. * extended error-reporting
  1013. */
  1014. static ssize_t
  1015. dasd_eer_show(struct device *dev, struct device_attribute *attr, char *buf)
  1016. {
  1017. struct dasd_devmap *devmap;
  1018. int eer_flag;
  1019. devmap = dasd_find_busid(dev_name(dev));
  1020. if (!IS_ERR(devmap) && devmap->device)
  1021. eer_flag = dasd_eer_enabled(devmap->device);
  1022. else
  1023. eer_flag = 0;
  1024. return snprintf(buf, PAGE_SIZE, eer_flag ? "1\n" : "0\n");
  1025. }
  1026. static ssize_t
  1027. dasd_eer_store(struct device *dev, struct device_attribute *attr,
  1028. const char *buf, size_t count)
  1029. {
  1030. struct dasd_device *device;
  1031. unsigned int val;
  1032. int rc = 0;
  1033. device = dasd_device_from_cdev(to_ccwdev(dev));
  1034. if (IS_ERR(device))
  1035. return PTR_ERR(device);
  1036. if (kstrtouint(buf, 0, &val) || val > 1)
  1037. return -EINVAL;
  1038. if (val)
  1039. rc = dasd_eer_enable(device);
  1040. else
  1041. dasd_eer_disable(device);
  1042. dasd_put_device(device);
  1043. return rc ? : count;
  1044. }
  1045. static DEVICE_ATTR(eer_enabled, 0644, dasd_eer_show, dasd_eer_store);
  1046. /*
  1047. * expiration time for default requests
  1048. */
  1049. static ssize_t
  1050. dasd_expires_show(struct device *dev, struct device_attribute *attr, char *buf)
  1051. {
  1052. struct dasd_device *device;
  1053. int len;
  1054. device = dasd_device_from_cdev(to_ccwdev(dev));
  1055. if (IS_ERR(device))
  1056. return -ENODEV;
  1057. len = snprintf(buf, PAGE_SIZE, "%lu\n", device->default_expires);
  1058. dasd_put_device(device);
  1059. return len;
  1060. }
  1061. static ssize_t
  1062. dasd_expires_store(struct device *dev, struct device_attribute *attr,
  1063. const char *buf, size_t count)
  1064. {
  1065. struct dasd_device *device;
  1066. unsigned long val;
  1067. device = dasd_device_from_cdev(to_ccwdev(dev));
  1068. if (IS_ERR(device))
  1069. return -ENODEV;
  1070. if ((kstrtoul(buf, 10, &val) != 0) ||
  1071. (val > DASD_EXPIRES_MAX) || val == 0) {
  1072. dasd_put_device(device);
  1073. return -EINVAL;
  1074. }
  1075. if (val)
  1076. device->default_expires = val;
  1077. dasd_put_device(device);
  1078. return count;
  1079. }
  1080. static DEVICE_ATTR(expires, 0644, dasd_expires_show, dasd_expires_store);
  1081. static ssize_t
  1082. dasd_retries_show(struct device *dev, struct device_attribute *attr, char *buf)
  1083. {
  1084. struct dasd_device *device;
  1085. int len;
  1086. device = dasd_device_from_cdev(to_ccwdev(dev));
  1087. if (IS_ERR(device))
  1088. return -ENODEV;
  1089. len = snprintf(buf, PAGE_SIZE, "%lu\n", device->default_retries);
  1090. dasd_put_device(device);
  1091. return len;
  1092. }
  1093. static ssize_t
  1094. dasd_retries_store(struct device *dev, struct device_attribute *attr,
  1095. const char *buf, size_t count)
  1096. {
  1097. struct dasd_device *device;
  1098. unsigned long val;
  1099. device = dasd_device_from_cdev(to_ccwdev(dev));
  1100. if (IS_ERR(device))
  1101. return -ENODEV;
  1102. if ((kstrtoul(buf, 10, &val) != 0) ||
  1103. (val > DASD_RETRIES_MAX)) {
  1104. dasd_put_device(device);
  1105. return -EINVAL;
  1106. }
  1107. if (val)
  1108. device->default_retries = val;
  1109. dasd_put_device(device);
  1110. return count;
  1111. }
  1112. static DEVICE_ATTR(retries, 0644, dasd_retries_show, dasd_retries_store);
  1113. static ssize_t
  1114. dasd_timeout_show(struct device *dev, struct device_attribute *attr,
  1115. char *buf)
  1116. {
  1117. struct dasd_device *device;
  1118. int len;
  1119. device = dasd_device_from_cdev(to_ccwdev(dev));
  1120. if (IS_ERR(device))
  1121. return -ENODEV;
  1122. len = snprintf(buf, PAGE_SIZE, "%lu\n", device->blk_timeout);
  1123. dasd_put_device(device);
  1124. return len;
  1125. }
  1126. static ssize_t
  1127. dasd_timeout_store(struct device *dev, struct device_attribute *attr,
  1128. const char *buf, size_t count)
  1129. {
  1130. struct dasd_device *device;
  1131. struct request_queue *q;
  1132. unsigned long val;
  1133. device = dasd_device_from_cdev(to_ccwdev(dev));
  1134. if (IS_ERR(device) || !device->block)
  1135. return -ENODEV;
  1136. if ((kstrtoul(buf, 10, &val) != 0) ||
  1137. val > UINT_MAX / HZ) {
  1138. dasd_put_device(device);
  1139. return -EINVAL;
  1140. }
  1141. q = device->block->request_queue;
  1142. if (!q) {
  1143. dasd_put_device(device);
  1144. return -ENODEV;
  1145. }
  1146. device->blk_timeout = val;
  1147. blk_queue_rq_timeout(q, device->blk_timeout * HZ);
  1148. dasd_put_device(device);
  1149. return count;
  1150. }
  1151. static DEVICE_ATTR(timeout, 0644,
  1152. dasd_timeout_show, dasd_timeout_store);
  1153. static ssize_t
  1154. dasd_path_reset_store(struct device *dev, struct device_attribute *attr,
  1155. const char *buf, size_t count)
  1156. {
  1157. struct dasd_device *device;
  1158. unsigned int val;
  1159. device = dasd_device_from_cdev(to_ccwdev(dev));
  1160. if (IS_ERR(device))
  1161. return -ENODEV;
  1162. if ((kstrtouint(buf, 16, &val) != 0) || val > 0xff)
  1163. val = 0;
  1164. if (device->discipline && device->discipline->reset_path)
  1165. device->discipline->reset_path(device, (__u8) val);
  1166. dasd_put_device(device);
  1167. return count;
  1168. }
  1169. static DEVICE_ATTR(path_reset, 0200, NULL, dasd_path_reset_store);
  1170. static ssize_t dasd_hpf_show(struct device *dev, struct device_attribute *attr,
  1171. char *buf)
  1172. {
  1173. struct dasd_device *device;
  1174. int hpf;
  1175. device = dasd_device_from_cdev(to_ccwdev(dev));
  1176. if (IS_ERR(device))
  1177. return -ENODEV;
  1178. if (!device->discipline || !device->discipline->hpf_enabled) {
  1179. dasd_put_device(device);
  1180. return snprintf(buf, PAGE_SIZE, "%d\n", dasd_nofcx);
  1181. }
  1182. hpf = device->discipline->hpf_enabled(device);
  1183. dasd_put_device(device);
  1184. return snprintf(buf, PAGE_SIZE, "%d\n", hpf);
  1185. }
  1186. static DEVICE_ATTR(hpf, 0444, dasd_hpf_show, NULL);
  1187. static ssize_t dasd_reservation_policy_show(struct device *dev,
  1188. struct device_attribute *attr,
  1189. char *buf)
  1190. {
  1191. struct dasd_devmap *devmap;
  1192. int rc = 0;
  1193. devmap = dasd_find_busid(dev_name(dev));
  1194. if (IS_ERR(devmap)) {
  1195. rc = snprintf(buf, PAGE_SIZE, "ignore\n");
  1196. } else {
  1197. spin_lock(&dasd_devmap_lock);
  1198. if (devmap->features & DASD_FEATURE_FAILONSLCK)
  1199. rc = snprintf(buf, PAGE_SIZE, "fail\n");
  1200. else
  1201. rc = snprintf(buf, PAGE_SIZE, "ignore\n");
  1202. spin_unlock(&dasd_devmap_lock);
  1203. }
  1204. return rc;
  1205. }
  1206. static ssize_t dasd_reservation_policy_store(struct device *dev,
  1207. struct device_attribute *attr,
  1208. const char *buf, size_t count)
  1209. {
  1210. struct ccw_device *cdev = to_ccwdev(dev);
  1211. int rc;
  1212. if (sysfs_streq("ignore", buf))
  1213. rc = dasd_set_feature(cdev, DASD_FEATURE_FAILONSLCK, 0);
  1214. else if (sysfs_streq("fail", buf))
  1215. rc = dasd_set_feature(cdev, DASD_FEATURE_FAILONSLCK, 1);
  1216. else
  1217. rc = -EINVAL;
  1218. return rc ? : count;
  1219. }
  1220. static DEVICE_ATTR(reservation_policy, 0644,
  1221. dasd_reservation_policy_show, dasd_reservation_policy_store);
  1222. static ssize_t dasd_reservation_state_show(struct device *dev,
  1223. struct device_attribute *attr,
  1224. char *buf)
  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 snprintf(buf, PAGE_SIZE, "none\n");
  1231. if (test_bit(DASD_FLAG_IS_RESERVED, &device->flags))
  1232. rc = snprintf(buf, PAGE_SIZE, "reserved\n");
  1233. else if (test_bit(DASD_FLAG_LOCK_STOLEN, &device->flags))
  1234. rc = snprintf(buf, PAGE_SIZE, "lost\n");
  1235. else
  1236. rc = snprintf(buf, PAGE_SIZE, "none\n");
  1237. dasd_put_device(device);
  1238. return rc;
  1239. }
  1240. static ssize_t dasd_reservation_state_store(struct device *dev,
  1241. struct device_attribute *attr,
  1242. const char *buf, size_t count)
  1243. {
  1244. struct dasd_device *device;
  1245. int rc = 0;
  1246. device = dasd_device_from_cdev(to_ccwdev(dev));
  1247. if (IS_ERR(device))
  1248. return -ENODEV;
  1249. if (sysfs_streq("reset", buf))
  1250. clear_bit(DASD_FLAG_LOCK_STOLEN, &device->flags);
  1251. else
  1252. rc = -EINVAL;
  1253. dasd_put_device(device);
  1254. if (rc)
  1255. return rc;
  1256. else
  1257. return count;
  1258. }
  1259. static DEVICE_ATTR(last_known_reservation_state, 0644,
  1260. dasd_reservation_state_show, dasd_reservation_state_store);
  1261. static ssize_t dasd_pm_show(struct device *dev,
  1262. struct device_attribute *attr, char *buf)
  1263. {
  1264. struct dasd_device *device;
  1265. u8 opm, nppm, cablepm, cuirpm, hpfpm, ifccpm;
  1266. device = dasd_device_from_cdev(to_ccwdev(dev));
  1267. if (IS_ERR(device))
  1268. return sprintf(buf, "0\n");
  1269. opm = dasd_path_get_opm(device);
  1270. nppm = dasd_path_get_nppm(device);
  1271. cablepm = dasd_path_get_cablepm(device);
  1272. cuirpm = dasd_path_get_cuirpm(device);
  1273. hpfpm = dasd_path_get_hpfpm(device);
  1274. ifccpm = dasd_path_get_ifccpm(device);
  1275. dasd_put_device(device);
  1276. return sprintf(buf, "%02x %02x %02x %02x %02x %02x\n", opm, nppm,
  1277. cablepm, cuirpm, hpfpm, ifccpm);
  1278. }
  1279. static DEVICE_ATTR(path_masks, 0444, dasd_pm_show, NULL);
  1280. /*
  1281. * threshold value for IFCC/CCC errors
  1282. */
  1283. static ssize_t
  1284. dasd_path_threshold_show(struct device *dev,
  1285. struct device_attribute *attr, char *buf)
  1286. {
  1287. struct dasd_device *device;
  1288. int len;
  1289. device = dasd_device_from_cdev(to_ccwdev(dev));
  1290. if (IS_ERR(device))
  1291. return -ENODEV;
  1292. len = snprintf(buf, PAGE_SIZE, "%lu\n", device->path_thrhld);
  1293. dasd_put_device(device);
  1294. return len;
  1295. }
  1296. static ssize_t
  1297. dasd_path_threshold_store(struct device *dev, struct device_attribute *attr,
  1298. const char *buf, size_t count)
  1299. {
  1300. struct dasd_device *device;
  1301. unsigned long flags;
  1302. unsigned long val;
  1303. device = dasd_device_from_cdev(to_ccwdev(dev));
  1304. if (IS_ERR(device))
  1305. return -ENODEV;
  1306. if (kstrtoul(buf, 10, &val) != 0 || val > DASD_THRHLD_MAX) {
  1307. dasd_put_device(device);
  1308. return -EINVAL;
  1309. }
  1310. spin_lock_irqsave(get_ccwdev_lock(to_ccwdev(dev)), flags);
  1311. device->path_thrhld = val;
  1312. spin_unlock_irqrestore(get_ccwdev_lock(to_ccwdev(dev)), flags);
  1313. dasd_put_device(device);
  1314. return count;
  1315. }
  1316. static DEVICE_ATTR(path_threshold, 0644, dasd_path_threshold_show,
  1317. dasd_path_threshold_store);
  1318. /*
  1319. * interval for IFCC/CCC checks
  1320. * meaning time with no IFCC/CCC error before the error counter
  1321. * gets reset
  1322. */
  1323. static ssize_t
  1324. dasd_path_interval_show(struct device *dev,
  1325. struct device_attribute *attr, char *buf)
  1326. {
  1327. struct dasd_device *device;
  1328. int len;
  1329. device = dasd_device_from_cdev(to_ccwdev(dev));
  1330. if (IS_ERR(device))
  1331. return -ENODEV;
  1332. len = snprintf(buf, PAGE_SIZE, "%lu\n", device->path_interval);
  1333. dasd_put_device(device);
  1334. return len;
  1335. }
  1336. static ssize_t
  1337. dasd_path_interval_store(struct device *dev, struct device_attribute *attr,
  1338. const char *buf, size_t count)
  1339. {
  1340. struct dasd_device *device;
  1341. unsigned long flags;
  1342. unsigned long val;
  1343. device = dasd_device_from_cdev(to_ccwdev(dev));
  1344. if (IS_ERR(device))
  1345. return -ENODEV;
  1346. if ((kstrtoul(buf, 10, &val) != 0) ||
  1347. (val > DASD_INTERVAL_MAX) || val == 0) {
  1348. dasd_put_device(device);
  1349. return -EINVAL;
  1350. }
  1351. spin_lock_irqsave(get_ccwdev_lock(to_ccwdev(dev)), flags);
  1352. if (val)
  1353. device->path_interval = val;
  1354. spin_unlock_irqrestore(get_ccwdev_lock(to_ccwdev(dev)), flags);
  1355. dasd_put_device(device);
  1356. return count;
  1357. }
  1358. static DEVICE_ATTR(path_interval, 0644, dasd_path_interval_show,
  1359. dasd_path_interval_store);
  1360. static struct attribute * dasd_attrs[] = {
  1361. &dev_attr_readonly.attr,
  1362. &dev_attr_discipline.attr,
  1363. &dev_attr_status.attr,
  1364. &dev_attr_alias.attr,
  1365. &dev_attr_vendor.attr,
  1366. &dev_attr_uid.attr,
  1367. &dev_attr_use_diag.attr,
  1368. &dev_attr_raw_track_access.attr,
  1369. &dev_attr_eer_enabled.attr,
  1370. &dev_attr_erplog.attr,
  1371. &dev_attr_failfast.attr,
  1372. &dev_attr_expires.attr,
  1373. &dev_attr_retries.attr,
  1374. &dev_attr_timeout.attr,
  1375. &dev_attr_reservation_policy.attr,
  1376. &dev_attr_last_known_reservation_state.attr,
  1377. &dev_attr_safe_offline.attr,
  1378. &dev_attr_host_access_count.attr,
  1379. &dev_attr_path_masks.attr,
  1380. &dev_attr_path_threshold.attr,
  1381. &dev_attr_path_interval.attr,
  1382. &dev_attr_path_reset.attr,
  1383. &dev_attr_hpf.attr,
  1384. NULL,
  1385. };
  1386. static const struct attribute_group dasd_attr_group = {
  1387. .attrs = dasd_attrs,
  1388. };
  1389. /*
  1390. * Return value of the specified feature.
  1391. */
  1392. int
  1393. dasd_get_feature(struct ccw_device *cdev, int feature)
  1394. {
  1395. struct dasd_devmap *devmap;
  1396. devmap = dasd_find_busid(dev_name(&cdev->dev));
  1397. if (IS_ERR(devmap))
  1398. return PTR_ERR(devmap);
  1399. return ((devmap->features & feature) != 0);
  1400. }
  1401. /*
  1402. * Set / reset given feature.
  1403. * Flag indicates whether to set (!=0) or the reset (=0) the feature.
  1404. */
  1405. int
  1406. dasd_set_feature(struct ccw_device *cdev, int feature, int flag)
  1407. {
  1408. struct dasd_devmap *devmap;
  1409. devmap = dasd_devmap_from_cdev(cdev);
  1410. if (IS_ERR(devmap))
  1411. return PTR_ERR(devmap);
  1412. spin_lock(&dasd_devmap_lock);
  1413. if (flag)
  1414. devmap->features |= feature;
  1415. else
  1416. devmap->features &= ~feature;
  1417. if (devmap->device)
  1418. devmap->device->features = devmap->features;
  1419. spin_unlock(&dasd_devmap_lock);
  1420. return 0;
  1421. }
  1422. EXPORT_SYMBOL(dasd_set_feature);
  1423. int
  1424. dasd_add_sysfs_files(struct ccw_device *cdev)
  1425. {
  1426. return sysfs_create_group(&cdev->dev.kobj, &dasd_attr_group);
  1427. }
  1428. void
  1429. dasd_remove_sysfs_files(struct ccw_device *cdev)
  1430. {
  1431. sysfs_remove_group(&cdev->dev.kobj, &dasd_attr_group);
  1432. }
  1433. int
  1434. dasd_devmap_init(void)
  1435. {
  1436. int i;
  1437. /* Initialize devmap structures. */
  1438. dasd_max_devindex = 0;
  1439. for (i = 0; i < 256; i++)
  1440. INIT_LIST_HEAD(&dasd_hashlists[i]);
  1441. return 0;
  1442. }
  1443. void
  1444. dasd_devmap_exit(void)
  1445. {
  1446. dasd_forget_ranges();
  1447. }