dasd_devmap.c 62 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Author(s)......: Holger Smolinski <Holger.Smolinski@de.ibm.com>
  4. * Horst Hummel <Horst.Hummel@de.ibm.com>
  5. * Carsten Otte <Cotte@de.ibm.com>
  6. * Martin Schwidefsky <schwidefsky@de.ibm.com>
  7. * Bugreports.to..: <Linux390@de.ibm.com>
  8. * Copyright IBM Corp. 1999,2001
  9. *
  10. * Device mapping and dasd= parameter parsing functions. All devmap
  11. * functions may not be called from interrupt context. In particular
  12. * dasd_get_device is a no-no from interrupt context.
  13. *
  14. */
  15. #include <linux/export.h>
  16. #include <linux/ctype.h>
  17. #include <linux/init.h>
  18. #include <linux/module.h>
  19. #include <linux/slab.h>
  20. #include <asm/machine.h>
  21. #include <asm/debug.h>
  22. #include <linux/uaccess.h>
  23. #include <asm/ipl.h>
  24. #define DASD_MAX_PARAMS 256
  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. struct dasd_copy_relation *copy;
  45. unsigned int aq_mask;
  46. };
  47. /*
  48. * Parameter parsing functions for dasd= parameter. The syntax is:
  49. * <devno> : (0x)?[0-9a-fA-F]+
  50. * <busid> : [0-0a-f]\.[0-9a-f]\.(0x)?[0-9a-fA-F]+
  51. * <feature> : ro
  52. * <feature_list> : \(<feature>(:<feature>)*\)
  53. * <devno-range> : <devno>(-<devno>)?<feature_list>?
  54. * <busid-range> : <busid>(-<busid>)?<feature_list>?
  55. * <devices> : <devno-range>|<busid-range>
  56. * <dasd_module> : dasd_diag_mod|dasd_eckd_mod|dasd_fba_mod
  57. *
  58. * <dasd> : autodetect|probeonly|<devices>(,<devices>)*
  59. */
  60. int dasd_probeonly = 0; /* is true, when probeonly mode is active */
  61. int dasd_autodetect = 0; /* is true, when autodetection is active */
  62. int dasd_nopav = 0; /* is true, when PAV is disabled */
  63. EXPORT_SYMBOL_GPL(dasd_nopav);
  64. int dasd_nofcx; /* disable High Performance Ficon */
  65. EXPORT_SYMBOL_GPL(dasd_nofcx);
  66. /*
  67. * char *dasd[] is intended to hold the ranges supplied by the dasd= statement
  68. * it is named 'dasd' to directly be filled by insmod with the comma separated
  69. * strings when running as a module.
  70. */
  71. static char *dasd[DASD_MAX_PARAMS];
  72. module_param_array(dasd, charp, NULL, S_IRUGO);
  73. /*
  74. * Single spinlock to protect devmap and servermap structures and lists.
  75. */
  76. static DEFINE_SPINLOCK(dasd_devmap_lock);
  77. /*
  78. * Hash lists for devmap structures.
  79. */
  80. static struct list_head dasd_hashlists[256];
  81. int dasd_max_devindex;
  82. static struct dasd_devmap *dasd_add_busid(const char *, int);
  83. static inline int
  84. dasd_hash_busid(const char *bus_id)
  85. {
  86. int hash, i;
  87. hash = 0;
  88. for (i = 0; (i < DASD_BUS_ID_SIZE) && *bus_id; i++, bus_id++)
  89. hash += *bus_id;
  90. return hash & 0xff;
  91. }
  92. #ifndef MODULE
  93. static int __init dasd_call_setup(char *opt)
  94. {
  95. static int i __initdata;
  96. char *tmp;
  97. while (i < DASD_MAX_PARAMS) {
  98. tmp = strsep(&opt, ",");
  99. if (!tmp)
  100. break;
  101. dasd[i++] = tmp;
  102. }
  103. return 1;
  104. }
  105. __setup ("dasd=", dasd_call_setup);
  106. #endif /* #ifndef MODULE */
  107. #define DASD_IPLDEV "ipldev"
  108. /*
  109. * Read a device busid/devno from a string.
  110. */
  111. static int dasd_busid(char *str, int *id0, int *id1, int *devno)
  112. {
  113. unsigned int val;
  114. char *tok;
  115. /* Interpret ipldev busid */
  116. if (strncmp(DASD_IPLDEV, str, strlen(DASD_IPLDEV)) == 0) {
  117. if (ipl_info.type != IPL_TYPE_CCW) {
  118. pr_err("The IPL device is not a CCW device\n");
  119. return -EINVAL;
  120. }
  121. *id0 = 0;
  122. *id1 = ipl_info.data.ccw.dev_id.ssid;
  123. *devno = ipl_info.data.ccw.dev_id.devno;
  124. return 0;
  125. }
  126. /* Old style 0xXXXX or XXXX */
  127. if (!kstrtouint(str, 16, &val)) {
  128. *id0 = *id1 = 0;
  129. if (val > 0xffff)
  130. return -EINVAL;
  131. *devno = val;
  132. return 0;
  133. }
  134. /* New style x.y.z busid */
  135. tok = strsep(&str, ".");
  136. if (kstrtouint(tok, 16, &val) || val > 0xff)
  137. return -EINVAL;
  138. *id0 = val;
  139. tok = strsep(&str, ".");
  140. if (kstrtouint(tok, 16, &val) || val > 0xff)
  141. return -EINVAL;
  142. *id1 = val;
  143. tok = strsep(&str, ".");
  144. if (kstrtouint(tok, 16, &val) || val > 0xffff)
  145. return -EINVAL;
  146. *devno = val;
  147. return 0;
  148. }
  149. /*
  150. * Read colon separated list of dasd features.
  151. */
  152. static int __init dasd_feature_list(char *str)
  153. {
  154. int features, len, rc;
  155. features = 0;
  156. rc = 0;
  157. if (!str)
  158. return DASD_FEATURE_DEFAULT;
  159. while (1) {
  160. for (len = 0;
  161. str[len] && str[len] != ':' && str[len] != ')'; len++);
  162. if (len == 2 && !strncmp(str, "ro", 2))
  163. features |= DASD_FEATURE_READONLY;
  164. else if (len == 4 && !strncmp(str, "diag", 4))
  165. features |= DASD_FEATURE_USEDIAG;
  166. else if (len == 3 && !strncmp(str, "raw", 3))
  167. features |= DASD_FEATURE_USERAW;
  168. else if (len == 6 && !strncmp(str, "erplog", 6))
  169. features |= DASD_FEATURE_ERPLOG;
  170. else if (len == 8 && !strncmp(str, "failfast", 8))
  171. features |= DASD_FEATURE_FAILFAST;
  172. else {
  173. pr_warn("%.*s is not a supported device option\n",
  174. len, str);
  175. rc = -EINVAL;
  176. }
  177. str += len;
  178. if (*str != ':')
  179. break;
  180. str++;
  181. }
  182. return rc ? : features;
  183. }
  184. /*
  185. * Try to match the first element on the comma separated parse string
  186. * with one of the known keywords. If a keyword is found, take the approprate
  187. * action and return a pointer to the residual string. If the first element
  188. * could not be matched to any keyword then return an error code.
  189. */
  190. static int __init dasd_parse_keyword(char *keyword)
  191. {
  192. int length = strlen(keyword);
  193. if (strncmp("autodetect", keyword, length) == 0) {
  194. dasd_autodetect = 1;
  195. pr_info("The autodetection mode has been activated\n");
  196. return 0;
  197. }
  198. if (strncmp("probeonly", keyword, length) == 0) {
  199. dasd_probeonly = 1;
  200. pr_info("The probeonly mode has been activated\n");
  201. return 0;
  202. }
  203. if (strncmp("nopav", keyword, length) == 0) {
  204. if (machine_is_vm())
  205. pr_info("'nopav' is not supported on z/VM\n");
  206. else {
  207. dasd_nopav = 1;
  208. pr_info("PAV support has be deactivated\n");
  209. }
  210. return 0;
  211. }
  212. if (strncmp("nofcx", keyword, length) == 0) {
  213. dasd_nofcx = 1;
  214. pr_info("High Performance FICON support has been "
  215. "deactivated\n");
  216. return 0;
  217. }
  218. if (strncmp("fixedbuffers", keyword, length) == 0) {
  219. if (dasd_page_cache)
  220. return 0;
  221. dasd_page_cache =
  222. kmem_cache_create("dasd_page_cache", PAGE_SIZE,
  223. PAGE_SIZE, SLAB_CACHE_DMA,
  224. NULL);
  225. if (!dasd_page_cache)
  226. DBF_EVENT(DBF_WARNING, "%s", "Failed to create slab, "
  227. "fixed buffer mode disabled.");
  228. else
  229. DBF_EVENT(DBF_INFO, "%s",
  230. "turning on fixed buffer mode");
  231. return 0;
  232. }
  233. return -EINVAL;
  234. }
  235. /*
  236. * Split a string of a device range into its pieces and return the from, to, and
  237. * feature parts separately.
  238. * e.g.:
  239. * 0.0.1234-0.0.5678(ro:erplog) -> from: 0.0.1234 to: 0.0.5678 features: ro:erplog
  240. * 0.0.8765(raw) -> from: 0.0.8765 to: null features: raw
  241. * 0x4321 -> from: 0x4321 to: null features: null
  242. */
  243. static int __init dasd_evaluate_range_param(char *range, char **from_str,
  244. char **to_str, char **features_str)
  245. {
  246. int rc = 0;
  247. /* Do we have a range or a single device? */
  248. if (strchr(range, '-')) {
  249. *from_str = strsep(&range, "-");
  250. *to_str = strsep(&range, "(");
  251. *features_str = strsep(&range, ")");
  252. } else {
  253. *from_str = strsep(&range, "(");
  254. *features_str = strsep(&range, ")");
  255. }
  256. if (*features_str && !range) {
  257. pr_warn("A closing parenthesis ')' is missing in the dasd= parameter\n");
  258. rc = -EINVAL;
  259. }
  260. return rc;
  261. }
  262. /*
  263. * Try to interprete the range string as a device number or a range of devices.
  264. * If the interpretation is successful, create the matching dasd_devmap entries.
  265. * If interpretation fails or in case of an error, return an error code.
  266. */
  267. static int __init dasd_parse_range(const char *range)
  268. {
  269. struct dasd_devmap *devmap;
  270. int from, from_id0, from_id1;
  271. int to, to_id0, to_id1;
  272. int features;
  273. char bus_id[DASD_BUS_ID_SIZE + 1];
  274. char *features_str = NULL;
  275. char *from_str = NULL;
  276. char *to_str = NULL;
  277. int rc = 0;
  278. char *tmp;
  279. tmp = kstrdup(range, GFP_KERNEL);
  280. if (!tmp)
  281. return -ENOMEM;
  282. if (dasd_evaluate_range_param(tmp, &from_str, &to_str, &features_str)) {
  283. rc = -EINVAL;
  284. goto out;
  285. }
  286. if (dasd_busid(from_str, &from_id0, &from_id1, &from)) {
  287. rc = -EINVAL;
  288. goto out;
  289. }
  290. to = from;
  291. to_id0 = from_id0;
  292. to_id1 = from_id1;
  293. if (to_str) {
  294. if (dasd_busid(to_str, &to_id0, &to_id1, &to)) {
  295. rc = -EINVAL;
  296. goto out;
  297. }
  298. if (from_id0 != to_id0 || from_id1 != to_id1 || from > to) {
  299. pr_err("%s is not a valid device range\n", range);
  300. rc = -EINVAL;
  301. goto out;
  302. }
  303. }
  304. features = dasd_feature_list(features_str);
  305. if (features < 0) {
  306. rc = -EINVAL;
  307. goto out;
  308. }
  309. /* each device in dasd= parameter should be set initially online */
  310. features |= DASD_FEATURE_INITIAL_ONLINE;
  311. while (from <= to) {
  312. scnprintf(bus_id, sizeof(bus_id),
  313. "%01x.%01x.%04x", from_id0, from_id1, from++);
  314. devmap = dasd_add_busid(bus_id, features);
  315. if (IS_ERR(devmap)) {
  316. rc = PTR_ERR(devmap);
  317. goto out;
  318. }
  319. }
  320. out:
  321. kfree(tmp);
  322. return rc;
  323. }
  324. /*
  325. * Parse parameters stored in dasd[]
  326. * The 'dasd=...' parameter allows to specify a comma separated list of
  327. * keywords and device ranges. The parameters in that list will be stored as
  328. * separate elementes in dasd[].
  329. */
  330. int __init dasd_parse(void)
  331. {
  332. int rc, i;
  333. char *cur;
  334. rc = 0;
  335. for (i = 0; i < DASD_MAX_PARAMS; i++) {
  336. cur = dasd[i];
  337. if (!cur)
  338. break;
  339. if (*cur == '\0')
  340. continue;
  341. rc = dasd_parse_keyword(cur);
  342. if (rc)
  343. rc = dasd_parse_range(cur);
  344. if (rc)
  345. break;
  346. }
  347. return rc;
  348. }
  349. /*
  350. * Add a devmap for the device specified by busid. It is possible that
  351. * the devmap already exists (dasd= parameter). The order of the devices
  352. * added through this function will define the kdevs for the individual
  353. * devices.
  354. */
  355. static struct dasd_devmap *
  356. dasd_add_busid(const char *bus_id, int features)
  357. {
  358. struct dasd_devmap *devmap, *new, *tmp;
  359. int hash;
  360. new = kzalloc_obj(struct dasd_devmap);
  361. if (!new)
  362. return ERR_PTR(-ENOMEM);
  363. spin_lock(&dasd_devmap_lock);
  364. devmap = NULL;
  365. hash = dasd_hash_busid(bus_id);
  366. list_for_each_entry(tmp, &dasd_hashlists[hash], list)
  367. if (strncmp(tmp->bus_id, bus_id, DASD_BUS_ID_SIZE) == 0) {
  368. devmap = tmp;
  369. break;
  370. }
  371. if (!devmap) {
  372. /* This bus_id is new. */
  373. new->devindex = dasd_max_devindex++;
  374. strscpy(new->bus_id, bus_id, DASD_BUS_ID_SIZE);
  375. new->features = features;
  376. new->device = NULL;
  377. list_add(&new->list, &dasd_hashlists[hash]);
  378. devmap = new;
  379. new = NULL;
  380. }
  381. spin_unlock(&dasd_devmap_lock);
  382. kfree(new);
  383. return devmap;
  384. }
  385. static struct dasd_devmap *
  386. dasd_find_busid_locked(const char *bus_id)
  387. {
  388. struct dasd_devmap *devmap, *tmp;
  389. int hash;
  390. devmap = ERR_PTR(-ENODEV);
  391. hash = dasd_hash_busid(bus_id);
  392. list_for_each_entry(tmp, &dasd_hashlists[hash], list) {
  393. if (strncmp(tmp->bus_id, bus_id, DASD_BUS_ID_SIZE) == 0) {
  394. devmap = tmp;
  395. break;
  396. }
  397. }
  398. return devmap;
  399. }
  400. /*
  401. * Find devmap for device with given bus_id.
  402. */
  403. static struct dasd_devmap *
  404. dasd_find_busid(const char *bus_id)
  405. {
  406. struct dasd_devmap *devmap;
  407. spin_lock(&dasd_devmap_lock);
  408. devmap = dasd_find_busid_locked(bus_id);
  409. spin_unlock(&dasd_devmap_lock);
  410. return devmap;
  411. }
  412. /*
  413. * Check if busid has been added to the list of dasd ranges.
  414. */
  415. int
  416. dasd_busid_known(const char *bus_id)
  417. {
  418. return IS_ERR(dasd_find_busid(bus_id)) ? -ENOENT : 0;
  419. }
  420. /*
  421. * Forget all about the device numbers added so far.
  422. * This may only be called at module unload or system shutdown.
  423. */
  424. static void
  425. dasd_forget_ranges(void)
  426. {
  427. struct dasd_devmap *devmap, *n;
  428. int i;
  429. spin_lock(&dasd_devmap_lock);
  430. for (i = 0; i < 256; i++) {
  431. list_for_each_entry_safe(devmap, n, &dasd_hashlists[i], list) {
  432. BUG_ON(devmap->device != NULL);
  433. list_del(&devmap->list);
  434. kfree(devmap);
  435. }
  436. }
  437. spin_unlock(&dasd_devmap_lock);
  438. }
  439. /*
  440. * Find the device struct by its device index.
  441. */
  442. struct dasd_device *
  443. dasd_device_from_devindex(int devindex)
  444. {
  445. struct dasd_devmap *devmap, *tmp;
  446. struct dasd_device *device;
  447. int i;
  448. spin_lock(&dasd_devmap_lock);
  449. devmap = NULL;
  450. for (i = 0; (i < 256) && !devmap; i++)
  451. list_for_each_entry(tmp, &dasd_hashlists[i], list)
  452. if (tmp->devindex == devindex) {
  453. /* Found the devmap for the device. */
  454. devmap = tmp;
  455. break;
  456. }
  457. if (devmap && devmap->device) {
  458. device = devmap->device;
  459. dasd_get_device(device);
  460. } else
  461. device = ERR_PTR(-ENODEV);
  462. spin_unlock(&dasd_devmap_lock);
  463. return device;
  464. }
  465. /*
  466. * Return devmap for cdev. If no devmap exists yet, create one and
  467. * connect it to the cdev.
  468. */
  469. static struct dasd_devmap *
  470. dasd_devmap_from_cdev(struct ccw_device *cdev)
  471. {
  472. struct dasd_devmap *devmap;
  473. devmap = dasd_find_busid(dev_name(&cdev->dev));
  474. if (IS_ERR(devmap))
  475. devmap = dasd_add_busid(dev_name(&cdev->dev),
  476. DASD_FEATURE_DEFAULT);
  477. return devmap;
  478. }
  479. /*
  480. * Create a dasd device structure for cdev.
  481. */
  482. struct dasd_device *
  483. dasd_create_device(struct ccw_device *cdev)
  484. {
  485. struct dasd_devmap *devmap;
  486. struct dasd_device *device;
  487. unsigned long flags;
  488. int rc;
  489. devmap = dasd_devmap_from_cdev(cdev);
  490. if (IS_ERR(devmap))
  491. return (void *) devmap;
  492. device = dasd_alloc_device();
  493. if (IS_ERR(device))
  494. return device;
  495. atomic_set(&device->ref_count, 3);
  496. spin_lock(&dasd_devmap_lock);
  497. if (!devmap->device) {
  498. devmap->device = device;
  499. device->devindex = devmap->devindex;
  500. device->features = devmap->features;
  501. get_device(&cdev->dev);
  502. device->cdev = cdev;
  503. rc = 0;
  504. } else
  505. /* Someone else was faster. */
  506. rc = -EBUSY;
  507. spin_unlock(&dasd_devmap_lock);
  508. if (rc) {
  509. dasd_free_device(device);
  510. return ERR_PTR(rc);
  511. }
  512. spin_lock_irqsave(get_ccwdev_lock(cdev), flags);
  513. dev_set_drvdata(&cdev->dev, device);
  514. spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags);
  515. device->paths_info = kset_create_and_add("paths_info", NULL,
  516. &device->cdev->dev.kobj);
  517. if (!device->paths_info)
  518. dev_warn(&cdev->dev, "Could not create paths_info kset\n");
  519. return device;
  520. }
  521. /*
  522. * allocate a PPRC data structure and call the discipline function to fill
  523. */
  524. static int dasd_devmap_get_pprc_status(struct dasd_device *device,
  525. struct dasd_pprc_data_sc4 **data)
  526. {
  527. struct dasd_pprc_data_sc4 *temp;
  528. if (!device->discipline || !device->discipline->pprc_status) {
  529. dev_warn(&device->cdev->dev, "Unable to query copy relation status\n");
  530. return -EOPNOTSUPP;
  531. }
  532. temp = kzalloc_obj(*temp);
  533. if (!temp)
  534. return -ENOMEM;
  535. /* get PPRC information from storage */
  536. if (device->discipline->pprc_status(device, temp)) {
  537. dev_warn(&device->cdev->dev, "Error during copy relation status query\n");
  538. kfree(temp);
  539. return -EINVAL;
  540. }
  541. *data = temp;
  542. return 0;
  543. }
  544. /*
  545. * find an entry in a PPRC device_info array by a given UID
  546. * depending on the primary/secondary state of the device it has to be
  547. * matched with the respective fields
  548. */
  549. static int dasd_devmap_entry_from_pprc_data(struct dasd_pprc_data_sc4 *data,
  550. struct dasd_uid uid,
  551. bool primary)
  552. {
  553. int i;
  554. for (i = 0; i < DASD_CP_ENTRIES; i++) {
  555. if (primary) {
  556. if (data->dev_info[i].prim_cu_ssid == uid.ssid &&
  557. data->dev_info[i].primary == uid.real_unit_addr)
  558. return i;
  559. } else {
  560. if (data->dev_info[i].sec_cu_ssid == uid.ssid &&
  561. data->dev_info[i].secondary == uid.real_unit_addr)
  562. return i;
  563. }
  564. }
  565. return -1;
  566. }
  567. /*
  568. * check the consistency of a specified copy relation by checking
  569. * the following things:
  570. *
  571. * - is the given device part of a copy pair setup
  572. * - does the state of the device match the state in the PPRC status data
  573. * - does the device UID match with the UID in the PPRC status data
  574. * - to prevent misrouted IO check if the given device is present in all
  575. * related PPRC status data
  576. */
  577. static int dasd_devmap_check_copy_relation(struct dasd_device *device,
  578. struct dasd_copy_entry *entry,
  579. struct dasd_pprc_data_sc4 *data,
  580. struct dasd_copy_relation *copy)
  581. {
  582. struct dasd_pprc_data_sc4 *tmp_dat;
  583. struct dasd_device *tmp_dev;
  584. struct dasd_uid uid;
  585. int i, j;
  586. if (!device->discipline || !device->discipline->get_uid ||
  587. device->discipline->get_uid(device, &uid))
  588. return 1;
  589. i = dasd_devmap_entry_from_pprc_data(data, uid, entry->primary);
  590. if (i < 0) {
  591. dev_warn(&device->cdev->dev, "Device not part of a copy relation\n");
  592. return 1;
  593. }
  594. /* double check which role the current device has */
  595. if (entry->primary) {
  596. if (data->dev_info[i].flags & 0x80) {
  597. dev_warn(&device->cdev->dev, "Copy pair secondary is setup as primary\n");
  598. return 1;
  599. }
  600. if (data->dev_info[i].prim_cu_ssid != uid.ssid ||
  601. data->dev_info[i].primary != uid.real_unit_addr) {
  602. dev_warn(&device->cdev->dev,
  603. "Primary device %s does not match copy pair status primary device %04x\n",
  604. dev_name(&device->cdev->dev),
  605. data->dev_info[i].prim_cu_ssid |
  606. data->dev_info[i].primary);
  607. return 1;
  608. }
  609. } else {
  610. if (!(data->dev_info[i].flags & 0x80)) {
  611. dev_warn(&device->cdev->dev, "Copy pair primary is setup as secondary\n");
  612. return 1;
  613. }
  614. if (data->dev_info[i].sec_cu_ssid != uid.ssid ||
  615. data->dev_info[i].secondary != uid.real_unit_addr) {
  616. dev_warn(&device->cdev->dev,
  617. "Secondary device %s does not match copy pair status secondary device %04x\n",
  618. dev_name(&device->cdev->dev),
  619. data->dev_info[i].sec_cu_ssid |
  620. data->dev_info[i].secondary);
  621. return 1;
  622. }
  623. }
  624. /*
  625. * the current device has to be part of the copy relation of all
  626. * entries to prevent misrouted IO to another copy pair
  627. */
  628. for (j = 0; j < DASD_CP_ENTRIES; j++) {
  629. if (entry == &copy->entry[j])
  630. tmp_dev = device;
  631. else
  632. tmp_dev = copy->entry[j].device;
  633. if (!tmp_dev)
  634. continue;
  635. if (dasd_devmap_get_pprc_status(tmp_dev, &tmp_dat))
  636. return 1;
  637. if (dasd_devmap_entry_from_pprc_data(tmp_dat, uid, entry->primary) < 0) {
  638. dev_warn(&tmp_dev->cdev->dev,
  639. "Copy pair relation does not contain device: %s\n",
  640. dev_name(&device->cdev->dev));
  641. kfree(tmp_dat);
  642. return 1;
  643. }
  644. kfree(tmp_dat);
  645. }
  646. return 0;
  647. }
  648. /* delete device from copy relation entry */
  649. static void dasd_devmap_delete_copy_relation_device(struct dasd_device *device)
  650. {
  651. struct dasd_copy_relation *copy;
  652. int i;
  653. if (!device->copy)
  654. return;
  655. copy = device->copy;
  656. for (i = 0; i < DASD_CP_ENTRIES; i++) {
  657. if (copy->entry[i].device == device)
  658. copy->entry[i].device = NULL;
  659. }
  660. dasd_put_device(device);
  661. device->copy = NULL;
  662. }
  663. /*
  664. * read all required information for a copy relation setup and setup the device
  665. * accordingly
  666. */
  667. int dasd_devmap_set_device_copy_relation(struct ccw_device *cdev,
  668. bool pprc_enabled)
  669. {
  670. struct dasd_pprc_data_sc4 *data = NULL;
  671. struct dasd_copy_entry *entry = NULL;
  672. struct dasd_copy_relation *copy;
  673. struct dasd_devmap *devmap;
  674. struct dasd_device *device;
  675. int i, rc = 0;
  676. devmap = dasd_devmap_from_cdev(cdev);
  677. if (IS_ERR(devmap))
  678. return PTR_ERR(devmap);
  679. device = devmap->device;
  680. if (!device)
  681. return -ENODEV;
  682. copy = devmap->copy;
  683. /* no copy pair setup for this device */
  684. if (!copy)
  685. goto out;
  686. rc = dasd_devmap_get_pprc_status(device, &data);
  687. if (rc)
  688. return rc;
  689. /* print error if PPRC is requested but not enabled on storage server */
  690. if (!pprc_enabled) {
  691. dev_err(&cdev->dev, "Copy relation not enabled on storage server\n");
  692. rc = -EINVAL;
  693. goto out;
  694. }
  695. if (!data->dev_info[0].state) {
  696. dev_warn(&device->cdev->dev, "Copy pair setup requested for device not in copy relation\n");
  697. rc = -EINVAL;
  698. goto out;
  699. }
  700. /* find entry */
  701. for (i = 0; i < DASD_CP_ENTRIES; i++) {
  702. if (copy->entry[i].configured &&
  703. strncmp(dev_name(&cdev->dev),
  704. copy->entry[i].busid, DASD_BUS_ID_SIZE) == 0) {
  705. entry = &copy->entry[i];
  706. break;
  707. }
  708. }
  709. if (!entry) {
  710. dev_warn(&device->cdev->dev, "Copy relation entry not found\n");
  711. rc = -EINVAL;
  712. goto out;
  713. }
  714. /* check if the copy relation is valid */
  715. if (dasd_devmap_check_copy_relation(device, entry, data, copy)) {
  716. dev_warn(&device->cdev->dev, "Copy relation faulty\n");
  717. rc = -EINVAL;
  718. goto out;
  719. }
  720. dasd_get_device(device);
  721. copy->entry[i].device = device;
  722. device->copy = copy;
  723. out:
  724. kfree(data);
  725. return rc;
  726. }
  727. EXPORT_SYMBOL_GPL(dasd_devmap_set_device_copy_relation);
  728. /*
  729. * Wait queue for dasd_delete_device waits.
  730. */
  731. static DECLARE_WAIT_QUEUE_HEAD(dasd_delete_wq);
  732. /*
  733. * Remove a dasd device structure. The passed referenced
  734. * is destroyed.
  735. */
  736. void
  737. dasd_delete_device(struct dasd_device *device)
  738. {
  739. struct ccw_device *cdev;
  740. struct dasd_devmap *devmap;
  741. unsigned long flags;
  742. /* First remove device pointer from devmap. */
  743. devmap = dasd_find_busid(dev_name(&device->cdev->dev));
  744. BUG_ON(IS_ERR(devmap));
  745. spin_lock(&dasd_devmap_lock);
  746. if (devmap->device != device) {
  747. spin_unlock(&dasd_devmap_lock);
  748. dasd_put_device(device);
  749. return;
  750. }
  751. devmap->device = NULL;
  752. spin_unlock(&dasd_devmap_lock);
  753. /* Disconnect dasd_device structure from ccw_device structure. */
  754. spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
  755. dev_set_drvdata(&device->cdev->dev, NULL);
  756. spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
  757. /* Remove copy relation */
  758. dasd_devmap_delete_copy_relation_device(device);
  759. /*
  760. * Drop ref_count by 3, one for the devmap reference, one for
  761. * the cdev reference and one for the passed reference.
  762. */
  763. atomic_sub(3, &device->ref_count);
  764. /* Wait for reference counter to drop to zero. */
  765. wait_event(dasd_delete_wq, atomic_read(&device->ref_count) == 0);
  766. dasd_generic_free_discipline(device);
  767. kset_unregister(device->paths_info);
  768. /* Disconnect dasd_device structure from ccw_device structure. */
  769. cdev = device->cdev;
  770. device->cdev = NULL;
  771. /* Put ccw_device structure. */
  772. put_device(&cdev->dev);
  773. /* Now the device structure can be freed. */
  774. dasd_free_device(device);
  775. }
  776. /*
  777. * Reference counter dropped to zero. Wake up waiter
  778. * in dasd_delete_device.
  779. */
  780. void
  781. dasd_put_device_wake(struct dasd_device *device)
  782. {
  783. wake_up(&dasd_delete_wq);
  784. }
  785. EXPORT_SYMBOL_GPL(dasd_put_device_wake);
  786. /*
  787. * Return dasd_device structure associated with cdev.
  788. * This function needs to be called with the ccw device
  789. * lock held. It can be used from interrupt context.
  790. */
  791. struct dasd_device *
  792. dasd_device_from_cdev_locked(struct ccw_device *cdev)
  793. {
  794. struct dasd_device *device = dev_get_drvdata(&cdev->dev);
  795. if (!device)
  796. return ERR_PTR(-ENODEV);
  797. dasd_get_device(device);
  798. return device;
  799. }
  800. /*
  801. * Return dasd_device structure associated with cdev.
  802. */
  803. struct dasd_device *
  804. dasd_device_from_cdev(struct ccw_device *cdev)
  805. {
  806. struct dasd_device *device;
  807. unsigned long flags;
  808. spin_lock_irqsave(get_ccwdev_lock(cdev), flags);
  809. device = dasd_device_from_cdev_locked(cdev);
  810. spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags);
  811. return device;
  812. }
  813. void dasd_add_link_to_gendisk(struct gendisk *gdp, struct dasd_device *device)
  814. {
  815. struct dasd_devmap *devmap;
  816. devmap = dasd_find_busid(dev_name(&device->cdev->dev));
  817. if (IS_ERR(devmap))
  818. return;
  819. spin_lock(&dasd_devmap_lock);
  820. gdp->private_data = devmap;
  821. spin_unlock(&dasd_devmap_lock);
  822. }
  823. EXPORT_SYMBOL(dasd_add_link_to_gendisk);
  824. struct dasd_device *dasd_device_from_gendisk(struct gendisk *gdp)
  825. {
  826. struct dasd_device *device;
  827. struct dasd_devmap *devmap;
  828. if (!gdp->private_data)
  829. return NULL;
  830. device = NULL;
  831. spin_lock(&dasd_devmap_lock);
  832. devmap = gdp->private_data;
  833. if (devmap && devmap->device) {
  834. device = devmap->device;
  835. dasd_get_device(device);
  836. }
  837. spin_unlock(&dasd_devmap_lock);
  838. return device;
  839. }
  840. /*
  841. * SECTION: files in sysfs
  842. */
  843. /*
  844. * failfast controls the behaviour, if no path is available
  845. */
  846. static ssize_t dasd_ff_show(struct device *dev, struct device_attribute *attr,
  847. char *buf)
  848. {
  849. struct dasd_devmap *devmap;
  850. int ff_flag;
  851. devmap = dasd_find_busid(dev_name(dev));
  852. if (!IS_ERR(devmap))
  853. ff_flag = (devmap->features & DASD_FEATURE_FAILFAST) != 0;
  854. else
  855. ff_flag = (DASD_FEATURE_DEFAULT & DASD_FEATURE_FAILFAST) != 0;
  856. return sysfs_emit(buf, ff_flag ? "1\n" : "0\n");
  857. }
  858. static ssize_t dasd_ff_store(struct device *dev, struct device_attribute *attr,
  859. const char *buf, size_t count)
  860. {
  861. unsigned int val;
  862. int rc;
  863. if (kstrtouint(buf, 0, &val) || val > 1)
  864. return -EINVAL;
  865. rc = dasd_set_feature(to_ccwdev(dev), DASD_FEATURE_FAILFAST, val);
  866. return rc ? : count;
  867. }
  868. static DEVICE_ATTR(failfast, 0644, dasd_ff_show, dasd_ff_store);
  869. /*
  870. * readonly controls the readonly status of a dasd
  871. */
  872. static ssize_t
  873. dasd_ro_show(struct device *dev, struct device_attribute *attr, char *buf)
  874. {
  875. struct dasd_devmap *devmap;
  876. struct dasd_device *device;
  877. int ro_flag = 0;
  878. devmap = dasd_find_busid(dev_name(dev));
  879. if (IS_ERR(devmap))
  880. goto out;
  881. ro_flag = !!(devmap->features & DASD_FEATURE_READONLY);
  882. spin_lock(&dasd_devmap_lock);
  883. device = devmap->device;
  884. if (device)
  885. ro_flag |= test_bit(DASD_FLAG_DEVICE_RO, &device->flags);
  886. spin_unlock(&dasd_devmap_lock);
  887. out:
  888. return sysfs_emit(buf, ro_flag ? "1\n" : "0\n");
  889. }
  890. static ssize_t
  891. dasd_ro_store(struct device *dev, struct device_attribute *attr,
  892. const char *buf, size_t count)
  893. {
  894. struct ccw_device *cdev = to_ccwdev(dev);
  895. struct dasd_device *device;
  896. unsigned long flags;
  897. unsigned int val;
  898. int rc;
  899. if (kstrtouint(buf, 0, &val) || val > 1)
  900. return -EINVAL;
  901. rc = dasd_set_feature(cdev, DASD_FEATURE_READONLY, val);
  902. if (rc)
  903. return rc;
  904. device = dasd_device_from_cdev(cdev);
  905. if (IS_ERR(device))
  906. return count;
  907. spin_lock_irqsave(get_ccwdev_lock(cdev), flags);
  908. val = val || test_bit(DASD_FLAG_DEVICE_RO, &device->flags);
  909. if (!device->block || !device->block->gdp ||
  910. test_bit(DASD_FLAG_OFFLINE, &device->flags)) {
  911. spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags);
  912. goto out;
  913. }
  914. /* Increase open_count to avoid losing the block device */
  915. atomic_inc(&device->block->open_count);
  916. spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags);
  917. set_disk_ro(device->block->gdp, val);
  918. atomic_dec(&device->block->open_count);
  919. out:
  920. dasd_put_device(device);
  921. return count;
  922. }
  923. static DEVICE_ATTR(readonly, 0644, dasd_ro_show, dasd_ro_store);
  924. /*
  925. * erplog controls the logging of ERP related data
  926. * (e.g. failing channel programs).
  927. */
  928. static ssize_t
  929. dasd_erplog_show(struct device *dev, struct device_attribute *attr, char *buf)
  930. {
  931. struct dasd_devmap *devmap;
  932. int erplog;
  933. devmap = dasd_find_busid(dev_name(dev));
  934. if (!IS_ERR(devmap))
  935. erplog = (devmap->features & DASD_FEATURE_ERPLOG) != 0;
  936. else
  937. erplog = (DASD_FEATURE_DEFAULT & DASD_FEATURE_ERPLOG) != 0;
  938. return sysfs_emit(buf, erplog ? "1\n" : "0\n");
  939. }
  940. static ssize_t
  941. dasd_erplog_store(struct device *dev, struct device_attribute *attr,
  942. const char *buf, size_t count)
  943. {
  944. unsigned int val;
  945. int rc;
  946. if (kstrtouint(buf, 0, &val) || val > 1)
  947. return -EINVAL;
  948. rc = dasd_set_feature(to_ccwdev(dev), DASD_FEATURE_ERPLOG, val);
  949. return rc ? : count;
  950. }
  951. static DEVICE_ATTR(erplog, 0644, dasd_erplog_show, dasd_erplog_store);
  952. /*
  953. * use_diag controls whether the driver should use diag rather than ssch
  954. * to talk to the device
  955. */
  956. static ssize_t
  957. dasd_use_diag_show(struct device *dev, struct device_attribute *attr, char *buf)
  958. {
  959. struct dasd_devmap *devmap;
  960. int use_diag;
  961. devmap = dasd_find_busid(dev_name(dev));
  962. if (!IS_ERR(devmap))
  963. use_diag = (devmap->features & DASD_FEATURE_USEDIAG) != 0;
  964. else
  965. use_diag = (DASD_FEATURE_DEFAULT & DASD_FEATURE_USEDIAG) != 0;
  966. return sysfs_emit(buf, use_diag ? "1\n" : "0\n");
  967. }
  968. static ssize_t
  969. dasd_use_diag_store(struct device *dev, struct device_attribute *attr,
  970. const char *buf, size_t count)
  971. {
  972. struct dasd_devmap *devmap;
  973. unsigned int val;
  974. ssize_t rc;
  975. devmap = dasd_devmap_from_cdev(to_ccwdev(dev));
  976. if (IS_ERR(devmap))
  977. return PTR_ERR(devmap);
  978. if (kstrtouint(buf, 0, &val) || val > 1)
  979. return -EINVAL;
  980. spin_lock(&dasd_devmap_lock);
  981. /* Changing diag discipline flag is only allowed in offline state. */
  982. rc = count;
  983. if (!devmap->device && !(devmap->features & DASD_FEATURE_USERAW)) {
  984. if (val)
  985. devmap->features |= DASD_FEATURE_USEDIAG;
  986. else
  987. devmap->features &= ~DASD_FEATURE_USEDIAG;
  988. } else
  989. rc = -EPERM;
  990. spin_unlock(&dasd_devmap_lock);
  991. return rc;
  992. }
  993. static DEVICE_ATTR(use_diag, 0644, dasd_use_diag_show, dasd_use_diag_store);
  994. /*
  995. * use_raw controls whether the driver should give access to raw eckd data or
  996. * operate in standard mode
  997. */
  998. static ssize_t
  999. dasd_use_raw_show(struct device *dev, struct device_attribute *attr, char *buf)
  1000. {
  1001. struct dasd_devmap *devmap;
  1002. int use_raw;
  1003. devmap = dasd_find_busid(dev_name(dev));
  1004. if (!IS_ERR(devmap))
  1005. use_raw = (devmap->features & DASD_FEATURE_USERAW) != 0;
  1006. else
  1007. use_raw = (DASD_FEATURE_DEFAULT & DASD_FEATURE_USERAW) != 0;
  1008. return sysfs_emit(buf, use_raw ? "1\n" : "0\n");
  1009. }
  1010. static ssize_t
  1011. dasd_use_raw_store(struct device *dev, struct device_attribute *attr,
  1012. const char *buf, size_t count)
  1013. {
  1014. struct dasd_devmap *devmap;
  1015. ssize_t rc;
  1016. unsigned long val;
  1017. devmap = dasd_devmap_from_cdev(to_ccwdev(dev));
  1018. if (IS_ERR(devmap))
  1019. return PTR_ERR(devmap);
  1020. if ((kstrtoul(buf, 10, &val) != 0) || val > 1)
  1021. return -EINVAL;
  1022. spin_lock(&dasd_devmap_lock);
  1023. /* Changing diag discipline flag is only allowed in offline state. */
  1024. rc = count;
  1025. if (!devmap->device && !(devmap->features & DASD_FEATURE_USEDIAG)) {
  1026. if (val)
  1027. devmap->features |= DASD_FEATURE_USERAW;
  1028. else
  1029. devmap->features &= ~DASD_FEATURE_USERAW;
  1030. } else
  1031. rc = -EPERM;
  1032. spin_unlock(&dasd_devmap_lock);
  1033. return rc;
  1034. }
  1035. static DEVICE_ATTR(raw_track_access, 0644, dasd_use_raw_show,
  1036. dasd_use_raw_store);
  1037. static ssize_t
  1038. dasd_safe_offline_store(struct device *dev, struct device_attribute *attr,
  1039. const char *buf, size_t count)
  1040. {
  1041. struct ccw_device *cdev = to_ccwdev(dev);
  1042. struct dasd_device *device;
  1043. unsigned long flags;
  1044. int rc;
  1045. spin_lock_irqsave(get_ccwdev_lock(cdev), flags);
  1046. device = dasd_device_from_cdev_locked(cdev);
  1047. if (IS_ERR(device)) {
  1048. rc = PTR_ERR(device);
  1049. spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags);
  1050. goto out;
  1051. }
  1052. if (test_bit(DASD_FLAG_OFFLINE, &device->flags) ||
  1053. test_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING, &device->flags)) {
  1054. /* Already doing offline processing */
  1055. dasd_put_device(device);
  1056. spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags);
  1057. rc = -EBUSY;
  1058. goto out;
  1059. }
  1060. set_bit(DASD_FLAG_SAFE_OFFLINE, &device->flags);
  1061. dasd_put_device(device);
  1062. spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags);
  1063. rc = ccw_device_set_offline(cdev);
  1064. out:
  1065. return rc ? rc : count;
  1066. }
  1067. static DEVICE_ATTR(safe_offline, 0200, NULL, dasd_safe_offline_store);
  1068. static ssize_t
  1069. dasd_access_show(struct device *dev, struct device_attribute *attr,
  1070. char *buf)
  1071. {
  1072. struct ccw_device *cdev = to_ccwdev(dev);
  1073. struct dasd_device *device;
  1074. int count;
  1075. device = dasd_device_from_cdev(cdev);
  1076. if (IS_ERR(device))
  1077. return PTR_ERR(device);
  1078. if (!device->discipline)
  1079. count = -ENODEV;
  1080. else if (!device->discipline->host_access_count)
  1081. count = -EOPNOTSUPP;
  1082. else
  1083. count = device->discipline->host_access_count(device);
  1084. dasd_put_device(device);
  1085. if (count < 0)
  1086. return count;
  1087. return sysfs_emit(buf, "%d\n", count);
  1088. }
  1089. static DEVICE_ATTR(host_access_count, 0444, dasd_access_show, NULL);
  1090. static ssize_t
  1091. dasd_discipline_show(struct device *dev, struct device_attribute *attr,
  1092. char *buf)
  1093. {
  1094. struct dasd_device *device;
  1095. ssize_t len;
  1096. device = dasd_device_from_cdev(to_ccwdev(dev));
  1097. if (IS_ERR(device))
  1098. goto out;
  1099. else if (!device->discipline) {
  1100. dasd_put_device(device);
  1101. goto out;
  1102. } else {
  1103. len = sysfs_emit(buf, "%s\n",
  1104. device->discipline->name);
  1105. dasd_put_device(device);
  1106. return len;
  1107. }
  1108. out:
  1109. len = sysfs_emit(buf, "none\n");
  1110. return len;
  1111. }
  1112. static DEVICE_ATTR(discipline, 0444, dasd_discipline_show, NULL);
  1113. static ssize_t
  1114. dasd_device_status_show(struct device *dev, struct device_attribute *attr,
  1115. char *buf)
  1116. {
  1117. struct dasd_device *device;
  1118. ssize_t len;
  1119. device = dasd_device_from_cdev(to_ccwdev(dev));
  1120. if (!IS_ERR(device)) {
  1121. switch (device->state) {
  1122. case DASD_STATE_NEW:
  1123. len = sysfs_emit(buf, "new\n");
  1124. break;
  1125. case DASD_STATE_KNOWN:
  1126. len = sysfs_emit(buf, "detected\n");
  1127. break;
  1128. case DASD_STATE_BASIC:
  1129. len = sysfs_emit(buf, "basic\n");
  1130. break;
  1131. case DASD_STATE_UNFMT:
  1132. len = sysfs_emit(buf, "unformatted\n");
  1133. break;
  1134. case DASD_STATE_READY:
  1135. len = sysfs_emit(buf, "ready\n");
  1136. break;
  1137. case DASD_STATE_ONLINE:
  1138. len = sysfs_emit(buf, "online\n");
  1139. break;
  1140. default:
  1141. len = sysfs_emit(buf, "no stat\n");
  1142. break;
  1143. }
  1144. dasd_put_device(device);
  1145. } else
  1146. len = sysfs_emit(buf, "unknown\n");
  1147. return len;
  1148. }
  1149. static DEVICE_ATTR(status, 0444, dasd_device_status_show, NULL);
  1150. static ssize_t dasd_alias_show(struct device *dev,
  1151. struct device_attribute *attr, char *buf)
  1152. {
  1153. struct dasd_device *device;
  1154. struct dasd_uid uid;
  1155. device = dasd_device_from_cdev(to_ccwdev(dev));
  1156. if (IS_ERR(device))
  1157. return sysfs_emit(buf, "0\n");
  1158. if (device->discipline && device->discipline->get_uid &&
  1159. !device->discipline->get_uid(device, &uid)) {
  1160. if (uid.type == UA_BASE_PAV_ALIAS ||
  1161. uid.type == UA_HYPER_PAV_ALIAS) {
  1162. dasd_put_device(device);
  1163. return sysfs_emit(buf, "1\n");
  1164. }
  1165. }
  1166. dasd_put_device(device);
  1167. return sysfs_emit(buf, "0\n");
  1168. }
  1169. static DEVICE_ATTR(alias, 0444, dasd_alias_show, NULL);
  1170. static ssize_t dasd_vendor_show(struct device *dev,
  1171. struct device_attribute *attr, char *buf)
  1172. {
  1173. struct dasd_device *device;
  1174. struct dasd_uid uid;
  1175. char *vendor;
  1176. device = dasd_device_from_cdev(to_ccwdev(dev));
  1177. vendor = "";
  1178. if (IS_ERR(device))
  1179. return sysfs_emit(buf, "%s\n", vendor);
  1180. if (device->discipline && device->discipline->get_uid &&
  1181. !device->discipline->get_uid(device, &uid))
  1182. vendor = uid.vendor;
  1183. dasd_put_device(device);
  1184. return sysfs_emit(buf, "%s\n", vendor);
  1185. }
  1186. static DEVICE_ATTR(vendor, 0444, dasd_vendor_show, NULL);
  1187. static ssize_t
  1188. dasd_uid_show(struct device *dev, struct device_attribute *attr, char *buf)
  1189. {
  1190. char uid_string[DASD_UID_STRLEN];
  1191. struct dasd_device *device;
  1192. struct dasd_uid uid;
  1193. char ua_string[3];
  1194. device = dasd_device_from_cdev(to_ccwdev(dev));
  1195. uid_string[0] = 0;
  1196. if (IS_ERR(device))
  1197. return sysfs_emit(buf, "%s\n", uid_string);
  1198. if (device->discipline && device->discipline->get_uid &&
  1199. !device->discipline->get_uid(device, &uid)) {
  1200. switch (uid.type) {
  1201. case UA_BASE_DEVICE:
  1202. snprintf(ua_string, sizeof(ua_string), "%02x",
  1203. uid.real_unit_addr);
  1204. break;
  1205. case UA_BASE_PAV_ALIAS:
  1206. snprintf(ua_string, sizeof(ua_string), "%02x",
  1207. uid.base_unit_addr);
  1208. break;
  1209. case UA_HYPER_PAV_ALIAS:
  1210. snprintf(ua_string, sizeof(ua_string), "xx");
  1211. break;
  1212. default:
  1213. /* should not happen, treat like base device */
  1214. snprintf(ua_string, sizeof(ua_string), "%02x",
  1215. uid.real_unit_addr);
  1216. break;
  1217. }
  1218. snprintf(uid_string, sizeof(uid_string), "%s.%s.%04x.%s%s%s",
  1219. uid.vendor, uid.serial, uid.ssid, ua_string,
  1220. uid.vduit[0] ? "." : "", uid.vduit);
  1221. }
  1222. dasd_put_device(device);
  1223. return sysfs_emit(buf, "%s\n", uid_string);
  1224. }
  1225. static DEVICE_ATTR(uid, 0444, dasd_uid_show, NULL);
  1226. /*
  1227. * extended error-reporting
  1228. */
  1229. static ssize_t
  1230. dasd_eer_show(struct device *dev, struct device_attribute *attr, char *buf)
  1231. {
  1232. struct dasd_devmap *devmap;
  1233. int eer_flag;
  1234. devmap = dasd_find_busid(dev_name(dev));
  1235. if (!IS_ERR(devmap) && devmap->device)
  1236. eer_flag = dasd_eer_enabled(devmap->device);
  1237. else
  1238. eer_flag = 0;
  1239. return sysfs_emit(buf, eer_flag ? "1\n" : "0\n");
  1240. }
  1241. static ssize_t
  1242. dasd_eer_store(struct device *dev, struct device_attribute *attr,
  1243. const char *buf, size_t count)
  1244. {
  1245. struct dasd_device *device;
  1246. unsigned int val;
  1247. int rc = 0;
  1248. device = dasd_device_from_cdev(to_ccwdev(dev));
  1249. if (IS_ERR(device))
  1250. return PTR_ERR(device);
  1251. if (kstrtouint(buf, 0, &val) || val > 1)
  1252. return -EINVAL;
  1253. if (val)
  1254. rc = dasd_eer_enable(device);
  1255. else
  1256. dasd_eer_disable(device);
  1257. dasd_put_device(device);
  1258. return rc ? : count;
  1259. }
  1260. static DEVICE_ATTR(eer_enabled, 0644, dasd_eer_show, dasd_eer_store);
  1261. /*
  1262. * aq_mask controls if the DASD should be quiesced on certain triggers
  1263. * The aq_mask attribute is interpreted as bitmap of the DASD_EER_* triggers.
  1264. */
  1265. static ssize_t dasd_aq_mask_show(struct device *dev, struct device_attribute *attr,
  1266. char *buf)
  1267. {
  1268. struct dasd_devmap *devmap;
  1269. unsigned int aq_mask = 0;
  1270. devmap = dasd_find_busid(dev_name(dev));
  1271. if (!IS_ERR(devmap))
  1272. aq_mask = devmap->aq_mask;
  1273. return sysfs_emit(buf, "%d\n", aq_mask);
  1274. }
  1275. static ssize_t dasd_aq_mask_store(struct device *dev, struct device_attribute *attr,
  1276. const char *buf, size_t count)
  1277. {
  1278. struct dasd_devmap *devmap;
  1279. unsigned int val;
  1280. if (kstrtouint(buf, 0, &val) || val > DASD_EER_VALID)
  1281. return -EINVAL;
  1282. devmap = dasd_devmap_from_cdev(to_ccwdev(dev));
  1283. if (IS_ERR(devmap))
  1284. return PTR_ERR(devmap);
  1285. spin_lock(&dasd_devmap_lock);
  1286. devmap->aq_mask = val;
  1287. if (devmap->device)
  1288. devmap->device->aq_mask = devmap->aq_mask;
  1289. spin_unlock(&dasd_devmap_lock);
  1290. return count;
  1291. }
  1292. static DEVICE_ATTR(aq_mask, 0644, dasd_aq_mask_show, dasd_aq_mask_store);
  1293. /*
  1294. * aq_requeue controls if requests are returned to the blocklayer on quiesce
  1295. * or if requests are only not started
  1296. */
  1297. static ssize_t dasd_aqr_show(struct device *dev, struct device_attribute *attr,
  1298. char *buf)
  1299. {
  1300. struct dasd_devmap *devmap;
  1301. int flag;
  1302. devmap = dasd_find_busid(dev_name(dev));
  1303. if (!IS_ERR(devmap))
  1304. flag = (devmap->features & DASD_FEATURE_REQUEUEQUIESCE) != 0;
  1305. else
  1306. flag = (DASD_FEATURE_DEFAULT &
  1307. DASD_FEATURE_REQUEUEQUIESCE) != 0;
  1308. return sysfs_emit(buf, "%d\n", flag);
  1309. }
  1310. static ssize_t dasd_aqr_store(struct device *dev, struct device_attribute *attr,
  1311. const char *buf, size_t count)
  1312. {
  1313. bool val;
  1314. int rc;
  1315. if (kstrtobool(buf, &val))
  1316. return -EINVAL;
  1317. rc = dasd_set_feature(to_ccwdev(dev), DASD_FEATURE_REQUEUEQUIESCE, val);
  1318. return rc ? : count;
  1319. }
  1320. static DEVICE_ATTR(aq_requeue, 0644, dasd_aqr_show, dasd_aqr_store);
  1321. /*
  1322. * aq_timeouts controls how much retries have to time out until
  1323. * a device gets autoquiesced
  1324. */
  1325. static ssize_t
  1326. dasd_aq_timeouts_show(struct device *dev, struct device_attribute *attr,
  1327. char *buf)
  1328. {
  1329. struct dasd_device *device;
  1330. int len;
  1331. device = dasd_device_from_cdev(to_ccwdev(dev));
  1332. if (IS_ERR(device))
  1333. return -ENODEV;
  1334. len = sysfs_emit(buf, "%u\n", device->aq_timeouts);
  1335. dasd_put_device(device);
  1336. return len;
  1337. }
  1338. static ssize_t
  1339. dasd_aq_timeouts_store(struct device *dev, struct device_attribute *attr,
  1340. const char *buf, size_t count)
  1341. {
  1342. struct dasd_device *device;
  1343. unsigned int val;
  1344. device = dasd_device_from_cdev(to_ccwdev(dev));
  1345. if (IS_ERR(device))
  1346. return -ENODEV;
  1347. if ((kstrtouint(buf, 10, &val) != 0) ||
  1348. val > DASD_RETRIES_MAX || val == 0) {
  1349. dasd_put_device(device);
  1350. return -EINVAL;
  1351. }
  1352. if (val)
  1353. device->aq_timeouts = val;
  1354. dasd_put_device(device);
  1355. return count;
  1356. }
  1357. static DEVICE_ATTR(aq_timeouts, 0644, dasd_aq_timeouts_show,
  1358. dasd_aq_timeouts_store);
  1359. /*
  1360. * expiration time for default requests
  1361. */
  1362. static ssize_t
  1363. dasd_expires_show(struct device *dev, struct device_attribute *attr, char *buf)
  1364. {
  1365. struct dasd_device *device;
  1366. int len;
  1367. device = dasd_device_from_cdev(to_ccwdev(dev));
  1368. if (IS_ERR(device))
  1369. return -ENODEV;
  1370. len = sysfs_emit(buf, "%lu\n", device->default_expires);
  1371. dasd_put_device(device);
  1372. return len;
  1373. }
  1374. static ssize_t
  1375. dasd_expires_store(struct device *dev, struct device_attribute *attr,
  1376. const char *buf, size_t count)
  1377. {
  1378. struct dasd_device *device;
  1379. unsigned long val;
  1380. device = dasd_device_from_cdev(to_ccwdev(dev));
  1381. if (IS_ERR(device))
  1382. return -ENODEV;
  1383. if ((kstrtoul(buf, 10, &val) != 0) ||
  1384. (val > DASD_EXPIRES_MAX) || val == 0) {
  1385. dasd_put_device(device);
  1386. return -EINVAL;
  1387. }
  1388. if (val)
  1389. device->default_expires = val;
  1390. dasd_put_device(device);
  1391. return count;
  1392. }
  1393. static DEVICE_ATTR(expires, 0644, dasd_expires_show, dasd_expires_store);
  1394. static ssize_t
  1395. dasd_retries_show(struct device *dev, struct device_attribute *attr, char *buf)
  1396. {
  1397. struct dasd_device *device;
  1398. int len;
  1399. device = dasd_device_from_cdev(to_ccwdev(dev));
  1400. if (IS_ERR(device))
  1401. return -ENODEV;
  1402. len = sysfs_emit(buf, "%lu\n", device->default_retries);
  1403. dasd_put_device(device);
  1404. return len;
  1405. }
  1406. static ssize_t
  1407. dasd_retries_store(struct device *dev, struct device_attribute *attr,
  1408. const char *buf, size_t count)
  1409. {
  1410. struct dasd_device *device;
  1411. unsigned long val;
  1412. device = dasd_device_from_cdev(to_ccwdev(dev));
  1413. if (IS_ERR(device))
  1414. return -ENODEV;
  1415. if ((kstrtoul(buf, 10, &val) != 0) ||
  1416. (val > DASD_RETRIES_MAX)) {
  1417. dasd_put_device(device);
  1418. return -EINVAL;
  1419. }
  1420. if (val)
  1421. device->default_retries = val;
  1422. dasd_put_device(device);
  1423. return count;
  1424. }
  1425. static DEVICE_ATTR(retries, 0644, dasd_retries_show, dasd_retries_store);
  1426. static ssize_t
  1427. dasd_timeout_show(struct device *dev, struct device_attribute *attr,
  1428. char *buf)
  1429. {
  1430. struct dasd_device *device;
  1431. int len;
  1432. device = dasd_device_from_cdev(to_ccwdev(dev));
  1433. if (IS_ERR(device))
  1434. return -ENODEV;
  1435. len = sysfs_emit(buf, "%lu\n", device->blk_timeout);
  1436. dasd_put_device(device);
  1437. return len;
  1438. }
  1439. static ssize_t
  1440. dasd_timeout_store(struct device *dev, struct device_attribute *attr,
  1441. const char *buf, size_t count)
  1442. {
  1443. struct dasd_device *device;
  1444. unsigned long val;
  1445. device = dasd_device_from_cdev(to_ccwdev(dev));
  1446. if (IS_ERR(device) || !device->block)
  1447. return -ENODEV;
  1448. if ((kstrtoul(buf, 10, &val) != 0) ||
  1449. val > UINT_MAX / HZ) {
  1450. dasd_put_device(device);
  1451. return -EINVAL;
  1452. }
  1453. if (!device->block->gdp) {
  1454. dasd_put_device(device);
  1455. return -ENODEV;
  1456. }
  1457. device->blk_timeout = val;
  1458. blk_queue_rq_timeout(device->block->gdp->queue, val * HZ);
  1459. dasd_put_device(device);
  1460. return count;
  1461. }
  1462. static DEVICE_ATTR(timeout, 0644,
  1463. dasd_timeout_show, dasd_timeout_store);
  1464. static ssize_t
  1465. dasd_path_reset_store(struct device *dev, struct device_attribute *attr,
  1466. const char *buf, size_t count)
  1467. {
  1468. struct dasd_device *device;
  1469. unsigned int val;
  1470. device = dasd_device_from_cdev(to_ccwdev(dev));
  1471. if (IS_ERR(device))
  1472. return -ENODEV;
  1473. if ((kstrtouint(buf, 16, &val) != 0) || val > 0xff)
  1474. val = 0;
  1475. if (device->discipline && device->discipline->reset_path)
  1476. device->discipline->reset_path(device, (__u8) val);
  1477. dasd_put_device(device);
  1478. return count;
  1479. }
  1480. static DEVICE_ATTR(path_reset, 0200, NULL, dasd_path_reset_store);
  1481. static ssize_t dasd_hpf_show(struct device *dev, struct device_attribute *attr,
  1482. char *buf)
  1483. {
  1484. struct dasd_device *device;
  1485. int hpf;
  1486. device = dasd_device_from_cdev(to_ccwdev(dev));
  1487. if (IS_ERR(device))
  1488. return -ENODEV;
  1489. if (!device->discipline || !device->discipline->hpf_enabled) {
  1490. dasd_put_device(device);
  1491. return sysfs_emit(buf, "%d\n", dasd_nofcx);
  1492. }
  1493. hpf = device->discipline->hpf_enabled(device);
  1494. dasd_put_device(device);
  1495. return sysfs_emit(buf, "%d\n", hpf);
  1496. }
  1497. static DEVICE_ATTR(hpf, 0444, dasd_hpf_show, NULL);
  1498. static ssize_t dasd_reservation_policy_show(struct device *dev,
  1499. struct device_attribute *attr,
  1500. char *buf)
  1501. {
  1502. struct dasd_devmap *devmap;
  1503. int rc = 0;
  1504. devmap = dasd_find_busid(dev_name(dev));
  1505. if (IS_ERR(devmap)) {
  1506. rc = sysfs_emit(buf, "ignore\n");
  1507. } else {
  1508. spin_lock(&dasd_devmap_lock);
  1509. if (devmap->features & DASD_FEATURE_FAILONSLCK)
  1510. rc = sysfs_emit(buf, "fail\n");
  1511. else
  1512. rc = sysfs_emit(buf, "ignore\n");
  1513. spin_unlock(&dasd_devmap_lock);
  1514. }
  1515. return rc;
  1516. }
  1517. static ssize_t dasd_reservation_policy_store(struct device *dev,
  1518. struct device_attribute *attr,
  1519. const char *buf, size_t count)
  1520. {
  1521. struct ccw_device *cdev = to_ccwdev(dev);
  1522. int rc;
  1523. if (sysfs_streq("ignore", buf))
  1524. rc = dasd_set_feature(cdev, DASD_FEATURE_FAILONSLCK, 0);
  1525. else if (sysfs_streq("fail", buf))
  1526. rc = dasd_set_feature(cdev, DASD_FEATURE_FAILONSLCK, 1);
  1527. else
  1528. rc = -EINVAL;
  1529. return rc ? : count;
  1530. }
  1531. static DEVICE_ATTR(reservation_policy, 0644,
  1532. dasd_reservation_policy_show, dasd_reservation_policy_store);
  1533. static ssize_t dasd_reservation_state_show(struct device *dev,
  1534. struct device_attribute *attr,
  1535. char *buf)
  1536. {
  1537. struct dasd_device *device;
  1538. int rc = 0;
  1539. device = dasd_device_from_cdev(to_ccwdev(dev));
  1540. if (IS_ERR(device))
  1541. return sysfs_emit(buf, "none\n");
  1542. if (test_bit(DASD_FLAG_IS_RESERVED, &device->flags))
  1543. rc = sysfs_emit(buf, "reserved\n");
  1544. else if (test_bit(DASD_FLAG_LOCK_STOLEN, &device->flags))
  1545. rc = sysfs_emit(buf, "lost\n");
  1546. else
  1547. rc = sysfs_emit(buf, "none\n");
  1548. dasd_put_device(device);
  1549. return rc;
  1550. }
  1551. static ssize_t dasd_reservation_state_store(struct device *dev,
  1552. struct device_attribute *attr,
  1553. const char *buf, size_t count)
  1554. {
  1555. struct dasd_device *device;
  1556. int rc = 0;
  1557. device = dasd_device_from_cdev(to_ccwdev(dev));
  1558. if (IS_ERR(device))
  1559. return -ENODEV;
  1560. if (sysfs_streq("reset", buf))
  1561. clear_bit(DASD_FLAG_LOCK_STOLEN, &device->flags);
  1562. else
  1563. rc = -EINVAL;
  1564. dasd_put_device(device);
  1565. if (rc)
  1566. return rc;
  1567. else
  1568. return count;
  1569. }
  1570. static DEVICE_ATTR(last_known_reservation_state, 0644,
  1571. dasd_reservation_state_show, dasd_reservation_state_store);
  1572. static ssize_t dasd_pm_show(struct device *dev,
  1573. struct device_attribute *attr, char *buf)
  1574. {
  1575. struct dasd_device *device;
  1576. u8 opm, nppm, cablepm, cuirpm, hpfpm, ifccpm;
  1577. device = dasd_device_from_cdev(to_ccwdev(dev));
  1578. if (IS_ERR(device))
  1579. return sysfs_emit(buf, "0\n");
  1580. opm = dasd_path_get_opm(device);
  1581. nppm = dasd_path_get_nppm(device);
  1582. cablepm = dasd_path_get_cablepm(device);
  1583. cuirpm = dasd_path_get_cuirpm(device);
  1584. hpfpm = dasd_path_get_hpfpm(device);
  1585. ifccpm = dasd_path_get_ifccpm(device);
  1586. dasd_put_device(device);
  1587. return sysfs_emit(buf, "%02x %02x %02x %02x %02x %02x\n", opm, nppm,
  1588. cablepm, cuirpm, hpfpm, ifccpm);
  1589. }
  1590. static DEVICE_ATTR(path_masks, 0444, dasd_pm_show, NULL);
  1591. /*
  1592. * threshold value for IFCC/CCC errors
  1593. */
  1594. static ssize_t
  1595. dasd_path_threshold_show(struct device *dev,
  1596. struct device_attribute *attr, char *buf)
  1597. {
  1598. struct dasd_device *device;
  1599. int len;
  1600. device = dasd_device_from_cdev(to_ccwdev(dev));
  1601. if (IS_ERR(device))
  1602. return -ENODEV;
  1603. len = sysfs_emit(buf, "%lu\n", device->path_thrhld);
  1604. dasd_put_device(device);
  1605. return len;
  1606. }
  1607. static ssize_t
  1608. dasd_path_threshold_store(struct device *dev, struct device_attribute *attr,
  1609. const char *buf, size_t count)
  1610. {
  1611. struct dasd_device *device;
  1612. unsigned long flags;
  1613. unsigned long val;
  1614. device = dasd_device_from_cdev(to_ccwdev(dev));
  1615. if (IS_ERR(device))
  1616. return -ENODEV;
  1617. if (kstrtoul(buf, 10, &val) != 0 || val > DASD_THRHLD_MAX) {
  1618. dasd_put_device(device);
  1619. return -EINVAL;
  1620. }
  1621. spin_lock_irqsave(get_ccwdev_lock(to_ccwdev(dev)), flags);
  1622. device->path_thrhld = val;
  1623. spin_unlock_irqrestore(get_ccwdev_lock(to_ccwdev(dev)), flags);
  1624. dasd_put_device(device);
  1625. return count;
  1626. }
  1627. static DEVICE_ATTR(path_threshold, 0644, dasd_path_threshold_show,
  1628. dasd_path_threshold_store);
  1629. /*
  1630. * configure if path is disabled after IFCC/CCC error threshold is
  1631. * exceeded
  1632. */
  1633. static ssize_t
  1634. dasd_path_autodisable_show(struct device *dev,
  1635. struct device_attribute *attr, char *buf)
  1636. {
  1637. struct dasd_devmap *devmap;
  1638. int flag;
  1639. devmap = dasd_find_busid(dev_name(dev));
  1640. if (!IS_ERR(devmap))
  1641. flag = (devmap->features & DASD_FEATURE_PATH_AUTODISABLE) != 0;
  1642. else
  1643. flag = (DASD_FEATURE_DEFAULT &
  1644. DASD_FEATURE_PATH_AUTODISABLE) != 0;
  1645. return sysfs_emit(buf, flag ? "1\n" : "0\n");
  1646. }
  1647. static ssize_t
  1648. dasd_path_autodisable_store(struct device *dev,
  1649. struct device_attribute *attr,
  1650. const char *buf, size_t count)
  1651. {
  1652. unsigned int val;
  1653. int rc;
  1654. if (kstrtouint(buf, 0, &val) || val > 1)
  1655. return -EINVAL;
  1656. rc = dasd_set_feature(to_ccwdev(dev),
  1657. DASD_FEATURE_PATH_AUTODISABLE, val);
  1658. return rc ? : count;
  1659. }
  1660. static DEVICE_ATTR(path_autodisable, 0644,
  1661. dasd_path_autodisable_show,
  1662. dasd_path_autodisable_store);
  1663. /*
  1664. * interval for IFCC/CCC checks
  1665. * meaning time with no IFCC/CCC error before the error counter
  1666. * gets reset
  1667. */
  1668. static ssize_t
  1669. dasd_path_interval_show(struct device *dev,
  1670. struct device_attribute *attr, char *buf)
  1671. {
  1672. struct dasd_device *device;
  1673. int len;
  1674. device = dasd_device_from_cdev(to_ccwdev(dev));
  1675. if (IS_ERR(device))
  1676. return -ENODEV;
  1677. len = sysfs_emit(buf, "%lu\n", device->path_interval);
  1678. dasd_put_device(device);
  1679. return len;
  1680. }
  1681. static ssize_t
  1682. dasd_path_interval_store(struct device *dev, struct device_attribute *attr,
  1683. const char *buf, size_t count)
  1684. {
  1685. struct dasd_device *device;
  1686. unsigned long flags;
  1687. unsigned long val;
  1688. device = dasd_device_from_cdev(to_ccwdev(dev));
  1689. if (IS_ERR(device))
  1690. return -ENODEV;
  1691. if ((kstrtoul(buf, 10, &val) != 0) ||
  1692. (val > DASD_INTERVAL_MAX) || val == 0) {
  1693. dasd_put_device(device);
  1694. return -EINVAL;
  1695. }
  1696. spin_lock_irqsave(get_ccwdev_lock(to_ccwdev(dev)), flags);
  1697. if (val)
  1698. device->path_interval = val;
  1699. spin_unlock_irqrestore(get_ccwdev_lock(to_ccwdev(dev)), flags);
  1700. dasd_put_device(device);
  1701. return count;
  1702. }
  1703. static DEVICE_ATTR(path_interval, 0644, dasd_path_interval_show,
  1704. dasd_path_interval_store);
  1705. static ssize_t
  1706. dasd_device_fcs_show(struct device *dev, struct device_attribute *attr,
  1707. char *buf)
  1708. {
  1709. struct dasd_device *device;
  1710. int fc_sec;
  1711. int rc;
  1712. device = dasd_device_from_cdev(to_ccwdev(dev));
  1713. if (IS_ERR(device))
  1714. return -ENODEV;
  1715. fc_sec = dasd_path_get_fcs_device(device);
  1716. if (fc_sec == -EINVAL)
  1717. rc = sysfs_emit(buf, "Inconsistent\n");
  1718. else
  1719. rc = sysfs_emit(buf, "%s\n", dasd_path_get_fcs_str(fc_sec));
  1720. dasd_put_device(device);
  1721. return rc;
  1722. }
  1723. static DEVICE_ATTR(fc_security, 0444, dasd_device_fcs_show, NULL);
  1724. static ssize_t
  1725. dasd_path_fcs_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf)
  1726. {
  1727. struct dasd_path *path = to_dasd_path(kobj);
  1728. unsigned int fc_sec = path->fc_security;
  1729. return sysfs_emit(buf, "%s\n", dasd_path_get_fcs_str(fc_sec));
  1730. }
  1731. static struct kobj_attribute path_fcs_attribute =
  1732. __ATTR(fc_security, 0444, dasd_path_fcs_show, NULL);
  1733. /*
  1734. * print copy relation in the form
  1735. * primary,secondary[1] primary,secondary[2], ...
  1736. */
  1737. static ssize_t
  1738. dasd_copy_pair_show(struct device *dev,
  1739. struct device_attribute *attr, char *buf)
  1740. {
  1741. char prim_busid[DASD_BUS_ID_SIZE];
  1742. struct dasd_copy_relation *copy;
  1743. struct dasd_devmap *devmap;
  1744. int len = 0;
  1745. int i;
  1746. devmap = dasd_find_busid(dev_name(dev));
  1747. if (IS_ERR(devmap))
  1748. return -ENODEV;
  1749. if (!devmap->copy)
  1750. return -ENODEV;
  1751. copy = devmap->copy;
  1752. /* find primary */
  1753. for (i = 0; i < DASD_CP_ENTRIES; i++) {
  1754. if (copy->entry[i].configured && copy->entry[i].primary) {
  1755. strscpy(prim_busid, copy->entry[i].busid,
  1756. DASD_BUS_ID_SIZE);
  1757. break;
  1758. }
  1759. }
  1760. if (i == DASD_CP_ENTRIES)
  1761. goto out;
  1762. /* print all secondary */
  1763. for (i = 0; i < DASD_CP_ENTRIES; i++) {
  1764. if (copy->entry[i].configured && !copy->entry[i].primary)
  1765. len += sysfs_emit_at(buf, len, "%s,%s ", prim_busid,
  1766. copy->entry[i].busid);
  1767. }
  1768. len += sysfs_emit_at(buf, len, "\n");
  1769. out:
  1770. return len;
  1771. }
  1772. static int dasd_devmap_set_copy_relation(struct dasd_devmap *devmap,
  1773. struct dasd_copy_relation *copy,
  1774. char *busid, bool primary)
  1775. {
  1776. int i;
  1777. /* find free entry */
  1778. for (i = 0; i < DASD_CP_ENTRIES; i++) {
  1779. /* current bus_id already included, nothing to do */
  1780. if (copy->entry[i].configured &&
  1781. strncmp(copy->entry[i].busid, busid, DASD_BUS_ID_SIZE) == 0)
  1782. return 0;
  1783. if (!copy->entry[i].configured)
  1784. break;
  1785. }
  1786. if (i == DASD_CP_ENTRIES)
  1787. return -EINVAL;
  1788. copy->entry[i].configured = true;
  1789. strscpy(copy->entry[i].busid, busid, DASD_BUS_ID_SIZE);
  1790. if (primary) {
  1791. copy->active = &copy->entry[i];
  1792. copy->entry[i].primary = true;
  1793. }
  1794. if (!devmap->copy)
  1795. devmap->copy = copy;
  1796. return 0;
  1797. }
  1798. static void dasd_devmap_del_copy_relation(struct dasd_copy_relation *copy,
  1799. char *busid)
  1800. {
  1801. int i;
  1802. spin_lock(&dasd_devmap_lock);
  1803. /* find entry */
  1804. for (i = 0; i < DASD_CP_ENTRIES; i++) {
  1805. if (copy->entry[i].configured &&
  1806. strncmp(copy->entry[i].busid, busid, DASD_BUS_ID_SIZE) == 0)
  1807. break;
  1808. }
  1809. if (i == DASD_CP_ENTRIES || !copy->entry[i].configured) {
  1810. spin_unlock(&dasd_devmap_lock);
  1811. return;
  1812. }
  1813. copy->entry[i].configured = false;
  1814. memset(copy->entry[i].busid, 0, DASD_BUS_ID_SIZE);
  1815. if (copy->active == &copy->entry[i]) {
  1816. copy->active = NULL;
  1817. copy->entry[i].primary = false;
  1818. }
  1819. spin_unlock(&dasd_devmap_lock);
  1820. }
  1821. static int dasd_devmap_clear_copy_relation(struct device *dev)
  1822. {
  1823. struct dasd_copy_relation *copy;
  1824. struct dasd_devmap *devmap;
  1825. int i, rc = 1;
  1826. devmap = dasd_devmap_from_cdev(to_ccwdev(dev));
  1827. if (IS_ERR(devmap))
  1828. return 1;
  1829. spin_lock(&dasd_devmap_lock);
  1830. if (!devmap->copy)
  1831. goto out;
  1832. copy = devmap->copy;
  1833. /* first check if all secondary devices are offline*/
  1834. for (i = 0; i < DASD_CP_ENTRIES; i++) {
  1835. if (!copy->entry[i].configured)
  1836. continue;
  1837. if (copy->entry[i].device == copy->active->device)
  1838. continue;
  1839. if (copy->entry[i].device)
  1840. goto out;
  1841. }
  1842. /* clear all devmap entries */
  1843. for (i = 0; i < DASD_CP_ENTRIES; i++) {
  1844. if (strlen(copy->entry[i].busid) == 0)
  1845. continue;
  1846. if (copy->entry[i].device) {
  1847. dasd_put_device(copy->entry[i].device);
  1848. copy->entry[i].device->copy = NULL;
  1849. copy->entry[i].device = NULL;
  1850. }
  1851. devmap = dasd_find_busid_locked(copy->entry[i].busid);
  1852. devmap->copy = NULL;
  1853. memset(copy->entry[i].busid, 0, DASD_BUS_ID_SIZE);
  1854. }
  1855. kfree(copy);
  1856. rc = 0;
  1857. out:
  1858. spin_unlock(&dasd_devmap_lock);
  1859. return rc;
  1860. }
  1861. /*
  1862. * parse BUSIDs from a copy pair
  1863. */
  1864. static int dasd_devmap_parse_busid(const char *buf, char *prim_busid,
  1865. char *sec_busid)
  1866. {
  1867. char *primary, *secondary, *tmp, *pt;
  1868. int id0, id1, id2;
  1869. pt = kstrdup(buf, GFP_KERNEL);
  1870. tmp = pt;
  1871. if (!tmp)
  1872. return -ENOMEM;
  1873. primary = strsep(&tmp, ",");
  1874. if (!primary) {
  1875. kfree(pt);
  1876. return -EINVAL;
  1877. }
  1878. secondary = strsep(&tmp, ",");
  1879. if (!secondary) {
  1880. kfree(pt);
  1881. return -EINVAL;
  1882. }
  1883. if (dasd_busid(primary, &id0, &id1, &id2)) {
  1884. kfree(pt);
  1885. return -EINVAL;
  1886. }
  1887. sprintf(prim_busid, "%01x.%01x.%04x", id0, id1, id2);
  1888. if (dasd_busid(secondary, &id0, &id1, &id2)) {
  1889. kfree(pt);
  1890. return -EINVAL;
  1891. }
  1892. sprintf(sec_busid, "%01x.%01x.%04x", id0, id1, id2);
  1893. kfree(pt);
  1894. return 0;
  1895. }
  1896. static ssize_t dasd_copy_pair_store(struct device *dev,
  1897. struct device_attribute *attr,
  1898. const char *buf, size_t count)
  1899. {
  1900. struct dasd_devmap *prim_devmap, *sec_devmap;
  1901. char prim_busid[DASD_BUS_ID_SIZE];
  1902. char sec_busid[DASD_BUS_ID_SIZE];
  1903. struct dasd_copy_relation *copy;
  1904. struct dasd_device *device;
  1905. bool pprc_enabled;
  1906. int rc;
  1907. if (strncmp(buf, "clear", strlen("clear")) == 0) {
  1908. if (dasd_devmap_clear_copy_relation(dev))
  1909. return -EINVAL;
  1910. return count;
  1911. }
  1912. rc = dasd_devmap_parse_busid(buf, prim_busid, sec_busid);
  1913. if (rc)
  1914. return rc;
  1915. if (strncmp(dev_name(dev), prim_busid, DASD_BUS_ID_SIZE) != 0 &&
  1916. strncmp(dev_name(dev), sec_busid, DASD_BUS_ID_SIZE) != 0)
  1917. return -EINVAL;
  1918. /* allocate primary devmap if needed */
  1919. prim_devmap = dasd_find_busid(prim_busid);
  1920. if (IS_ERR(prim_devmap)) {
  1921. prim_devmap = dasd_add_busid(prim_busid, DASD_FEATURE_DEFAULT);
  1922. if (IS_ERR(prim_devmap))
  1923. return PTR_ERR(prim_devmap);
  1924. }
  1925. /* allocate secondary devmap if needed */
  1926. sec_devmap = dasd_find_busid(sec_busid);
  1927. if (IS_ERR(sec_devmap)) {
  1928. sec_devmap = dasd_add_busid(sec_busid, DASD_FEATURE_DEFAULT);
  1929. if (IS_ERR(sec_devmap))
  1930. return PTR_ERR(sec_devmap);
  1931. }
  1932. /* setting copy relation is only allowed for offline secondary */
  1933. if (sec_devmap->device)
  1934. return -EINVAL;
  1935. if (prim_devmap->copy) {
  1936. copy = prim_devmap->copy;
  1937. } else if (sec_devmap->copy) {
  1938. copy = sec_devmap->copy;
  1939. } else {
  1940. copy = kzalloc_obj(*copy);
  1941. if (!copy)
  1942. return -ENOMEM;
  1943. }
  1944. spin_lock(&dasd_devmap_lock);
  1945. rc = dasd_devmap_set_copy_relation(prim_devmap, copy, prim_busid, true);
  1946. if (rc) {
  1947. spin_unlock(&dasd_devmap_lock);
  1948. return rc;
  1949. }
  1950. rc = dasd_devmap_set_copy_relation(sec_devmap, copy, sec_busid, false);
  1951. if (rc) {
  1952. spin_unlock(&dasd_devmap_lock);
  1953. return rc;
  1954. }
  1955. spin_unlock(&dasd_devmap_lock);
  1956. /* if primary device is already online call device setup directly */
  1957. if (prim_devmap->device && !prim_devmap->device->copy) {
  1958. device = prim_devmap->device;
  1959. if (device->discipline->pprc_enabled) {
  1960. pprc_enabled = device->discipline->pprc_enabled(device);
  1961. rc = dasd_devmap_set_device_copy_relation(device->cdev,
  1962. pprc_enabled);
  1963. } else {
  1964. rc = -EOPNOTSUPP;
  1965. }
  1966. }
  1967. if (rc) {
  1968. dasd_devmap_del_copy_relation(copy, prim_busid);
  1969. dasd_devmap_del_copy_relation(copy, sec_busid);
  1970. count = rc;
  1971. }
  1972. return count;
  1973. }
  1974. static DEVICE_ATTR(copy_pair, 0644, dasd_copy_pair_show,
  1975. dasd_copy_pair_store);
  1976. static ssize_t
  1977. dasd_copy_role_show(struct device *dev,
  1978. struct device_attribute *attr, char *buf)
  1979. {
  1980. struct dasd_copy_relation *copy;
  1981. struct dasd_device *device;
  1982. int len, i;
  1983. device = dasd_device_from_cdev(to_ccwdev(dev));
  1984. if (IS_ERR(device))
  1985. return -ENODEV;
  1986. if (!device->copy) {
  1987. len = sysfs_emit(buf, "none\n");
  1988. goto out;
  1989. }
  1990. copy = device->copy;
  1991. /* only the active device is primary */
  1992. if (copy->active->device == device) {
  1993. len = sysfs_emit(buf, "primary\n");
  1994. goto out;
  1995. }
  1996. for (i = 0; i < DASD_CP_ENTRIES; i++) {
  1997. if (copy->entry[i].device == device) {
  1998. len = sysfs_emit(buf, "secondary\n");
  1999. goto out;
  2000. }
  2001. }
  2002. /* not in the list, no COPY role */
  2003. len = sysfs_emit(buf, "none\n");
  2004. out:
  2005. dasd_put_device(device);
  2006. return len;
  2007. }
  2008. static DEVICE_ATTR(copy_role, 0444, dasd_copy_role_show, NULL);
  2009. static ssize_t dasd_device_ping(struct device *dev,
  2010. struct device_attribute *attr,
  2011. const char *buf, size_t count)
  2012. {
  2013. struct dasd_device *device;
  2014. size_t rc;
  2015. device = dasd_device_from_cdev(to_ccwdev(dev));
  2016. if (IS_ERR(device))
  2017. return -ENODEV;
  2018. /*
  2019. * do not try during offline processing
  2020. * early check only
  2021. * the sleep_on function itself checks for offline
  2022. * processing again
  2023. */
  2024. if (test_bit(DASD_FLAG_OFFLINE, &device->flags)) {
  2025. rc = -EBUSY;
  2026. goto out;
  2027. }
  2028. if (!device->discipline || !device->discipline->device_ping) {
  2029. rc = -EOPNOTSUPP;
  2030. goto out;
  2031. }
  2032. rc = device->discipline->device_ping(device);
  2033. if (!rc)
  2034. rc = count;
  2035. out:
  2036. dasd_put_device(device);
  2037. return rc;
  2038. }
  2039. static DEVICE_ATTR(ping, 0200, NULL, dasd_device_ping);
  2040. #define DASD_DEFINE_ATTR(_name, _func) \
  2041. static ssize_t dasd_##_name##_show(struct device *dev, \
  2042. struct device_attribute *attr, \
  2043. char *buf) \
  2044. { \
  2045. struct ccw_device *cdev = to_ccwdev(dev); \
  2046. struct dasd_device *device = dasd_device_from_cdev(cdev); \
  2047. int val = 0; \
  2048. \
  2049. if (IS_ERR(device)) \
  2050. return -ENODEV; \
  2051. if (device->discipline && _func) \
  2052. val = _func(device); \
  2053. dasd_put_device(device); \
  2054. \
  2055. return sysfs_emit(buf, "%d\n", val); \
  2056. } \
  2057. static DEVICE_ATTR(_name, 0444, dasd_##_name##_show, NULL); \
  2058. DASD_DEFINE_ATTR(ese, device->discipline->is_ese);
  2059. DASD_DEFINE_ATTR(extent_size, device->discipline->ext_size);
  2060. DASD_DEFINE_ATTR(pool_id, device->discipline->ext_pool_id);
  2061. DASD_DEFINE_ATTR(space_configured, device->discipline->space_configured);
  2062. DASD_DEFINE_ATTR(space_allocated, device->discipline->space_allocated);
  2063. DASD_DEFINE_ATTR(logical_capacity, device->discipline->logical_capacity);
  2064. DASD_DEFINE_ATTR(warn_threshold, device->discipline->ext_pool_warn_thrshld);
  2065. DASD_DEFINE_ATTR(cap_at_warnlevel, device->discipline->ext_pool_cap_at_warnlevel);
  2066. DASD_DEFINE_ATTR(pool_oos, device->discipline->ext_pool_oos);
  2067. static struct attribute * dasd_attrs[] = {
  2068. &dev_attr_readonly.attr,
  2069. &dev_attr_discipline.attr,
  2070. &dev_attr_status.attr,
  2071. &dev_attr_alias.attr,
  2072. &dev_attr_vendor.attr,
  2073. &dev_attr_uid.attr,
  2074. &dev_attr_use_diag.attr,
  2075. &dev_attr_raw_track_access.attr,
  2076. &dev_attr_eer_enabled.attr,
  2077. &dev_attr_erplog.attr,
  2078. &dev_attr_failfast.attr,
  2079. &dev_attr_expires.attr,
  2080. &dev_attr_retries.attr,
  2081. &dev_attr_timeout.attr,
  2082. &dev_attr_reservation_policy.attr,
  2083. &dev_attr_last_known_reservation_state.attr,
  2084. &dev_attr_safe_offline.attr,
  2085. &dev_attr_host_access_count.attr,
  2086. &dev_attr_path_masks.attr,
  2087. &dev_attr_path_threshold.attr,
  2088. &dev_attr_path_autodisable.attr,
  2089. &dev_attr_path_interval.attr,
  2090. &dev_attr_path_reset.attr,
  2091. &dev_attr_hpf.attr,
  2092. &dev_attr_ese.attr,
  2093. &dev_attr_fc_security.attr,
  2094. &dev_attr_copy_pair.attr,
  2095. &dev_attr_copy_role.attr,
  2096. &dev_attr_ping.attr,
  2097. &dev_attr_aq_mask.attr,
  2098. &dev_attr_aq_requeue.attr,
  2099. &dev_attr_aq_timeouts.attr,
  2100. NULL,
  2101. };
  2102. static const struct attribute_group dasd_attr_group = {
  2103. .attrs = dasd_attrs,
  2104. };
  2105. static struct attribute *capacity_attrs[] = {
  2106. &dev_attr_space_configured.attr,
  2107. &dev_attr_space_allocated.attr,
  2108. &dev_attr_logical_capacity.attr,
  2109. NULL,
  2110. };
  2111. static const struct attribute_group capacity_attr_group = {
  2112. .name = "capacity",
  2113. .attrs = capacity_attrs,
  2114. };
  2115. static struct attribute *ext_pool_attrs[] = {
  2116. &dev_attr_pool_id.attr,
  2117. &dev_attr_extent_size.attr,
  2118. &dev_attr_warn_threshold.attr,
  2119. &dev_attr_cap_at_warnlevel.attr,
  2120. &dev_attr_pool_oos.attr,
  2121. NULL,
  2122. };
  2123. static const struct attribute_group ext_pool_attr_group = {
  2124. .name = "extent_pool",
  2125. .attrs = ext_pool_attrs,
  2126. };
  2127. const struct attribute_group *dasd_dev_groups[] = {
  2128. &dasd_attr_group,
  2129. &capacity_attr_group,
  2130. &ext_pool_attr_group,
  2131. NULL,
  2132. };
  2133. EXPORT_SYMBOL_GPL(dasd_dev_groups);
  2134. /*
  2135. * Return value of the specified feature.
  2136. */
  2137. int
  2138. dasd_get_feature(struct ccw_device *cdev, int feature)
  2139. {
  2140. struct dasd_devmap *devmap;
  2141. devmap = dasd_find_busid(dev_name(&cdev->dev));
  2142. if (IS_ERR(devmap))
  2143. return PTR_ERR(devmap);
  2144. return ((devmap->features & feature) != 0);
  2145. }
  2146. /*
  2147. * Set / reset given feature.
  2148. * Flag indicates whether to set (!=0) or the reset (=0) the feature.
  2149. */
  2150. int
  2151. dasd_set_feature(struct ccw_device *cdev, int feature, int flag)
  2152. {
  2153. struct dasd_devmap *devmap;
  2154. devmap = dasd_devmap_from_cdev(cdev);
  2155. if (IS_ERR(devmap))
  2156. return PTR_ERR(devmap);
  2157. spin_lock(&dasd_devmap_lock);
  2158. if (flag)
  2159. devmap->features |= feature;
  2160. else
  2161. devmap->features &= ~feature;
  2162. if (devmap->device)
  2163. devmap->device->features = devmap->features;
  2164. spin_unlock(&dasd_devmap_lock);
  2165. return 0;
  2166. }
  2167. EXPORT_SYMBOL(dasd_set_feature);
  2168. static struct attribute *paths_info_attrs[] = {
  2169. &path_fcs_attribute.attr,
  2170. NULL,
  2171. };
  2172. ATTRIBUTE_GROUPS(paths_info);
  2173. static struct kobj_type path_attr_type = {
  2174. .release = dasd_path_release,
  2175. .default_groups = paths_info_groups,
  2176. .sysfs_ops = &kobj_sysfs_ops,
  2177. };
  2178. static void dasd_path_init_kobj(struct dasd_device *device, int chp)
  2179. {
  2180. device->path[chp].kobj.kset = device->paths_info;
  2181. kobject_init(&device->path[chp].kobj, &path_attr_type);
  2182. }
  2183. void dasd_path_create_kobj(struct dasd_device *device, int chp)
  2184. {
  2185. int rc;
  2186. if (test_bit(DASD_FLAG_OFFLINE, &device->flags))
  2187. return;
  2188. if (!device->paths_info) {
  2189. dev_warn(&device->cdev->dev, "Unable to create paths objects\n");
  2190. return;
  2191. }
  2192. if (device->path[chp].in_sysfs)
  2193. return;
  2194. if (!device->path[chp].conf_data)
  2195. return;
  2196. dasd_path_init_kobj(device, chp);
  2197. rc = kobject_add(&device->path[chp].kobj, NULL, "%x.%02x",
  2198. device->path[chp].cssid, device->path[chp].chpid);
  2199. if (rc)
  2200. kobject_put(&device->path[chp].kobj);
  2201. device->path[chp].in_sysfs = true;
  2202. }
  2203. EXPORT_SYMBOL(dasd_path_create_kobj);
  2204. void dasd_path_create_kobjects(struct dasd_device *device)
  2205. {
  2206. u8 lpm, opm;
  2207. opm = dasd_path_get_opm(device);
  2208. for (lpm = 0x80; lpm; lpm >>= 1) {
  2209. if (!(lpm & opm))
  2210. continue;
  2211. dasd_path_create_kobj(device, pathmask_to_pos(lpm));
  2212. }
  2213. }
  2214. EXPORT_SYMBOL(dasd_path_create_kobjects);
  2215. static void dasd_path_remove_kobj(struct dasd_device *device, int chp)
  2216. {
  2217. if (device->path[chp].in_sysfs) {
  2218. kobject_put(&device->path[chp].kobj);
  2219. device->path[chp].in_sysfs = false;
  2220. }
  2221. }
  2222. /*
  2223. * As we keep kobjects for the lifetime of a device, this function must not be
  2224. * called anywhere but in the context of offlining a device.
  2225. */
  2226. void dasd_path_remove_kobjects(struct dasd_device *device)
  2227. {
  2228. int i;
  2229. for (i = 0; i < 8; i++)
  2230. dasd_path_remove_kobj(device, i);
  2231. }
  2232. EXPORT_SYMBOL(dasd_path_remove_kobjects);
  2233. int
  2234. dasd_devmap_init(void)
  2235. {
  2236. int i;
  2237. /* Initialize devmap structures. */
  2238. dasd_max_devindex = 0;
  2239. for (i = 0; i < 256; i++)
  2240. INIT_LIST_HEAD(&dasd_hashlists[i]);
  2241. return 0;
  2242. }
  2243. void
  2244. dasd_devmap_exit(void)
  2245. {
  2246. dasd_forget_ranges();
  2247. }