dasd_devmap.c 35 KB

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