dasd_devmap.c 38 KB

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