dasd_devmap.c 33 KB

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