dasd_devmap.c 59 KB

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