dasd_devmap.c 37 KB

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