dasd_devmap.c 62 KB

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