dasd_devmap.c 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002
  1. /*
  2. * File...........: linux/drivers/s390/block/dasd_devmap.c
  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. * (C) IBM Corporation, IBM Deutschland Entwicklung GmbH, 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 <asm/debug.h>
  19. #include <asm/uaccess.h>
  20. /* This is ugly... */
  21. #define PRINTK_HEADER "dasd_devmap:"
  22. #include "dasd_int.h"
  23. kmem_cache_t *dasd_page_cache;
  24. EXPORT_SYMBOL_GPL(dasd_page_cache);
  25. /*
  26. * dasd_devmap_t is used to store the features and the relation
  27. * between device number and device index. To find a dasd_devmap_t
  28. * that corresponds to a device number of a device index each
  29. * dasd_devmap_t is added to two linked lists, one to search by
  30. * the device number and one to search by the device index. As
  31. * soon as big minor numbers are available the device index list
  32. * can be removed since the device number will then be identical
  33. * to the device index.
  34. */
  35. struct dasd_devmap {
  36. struct list_head list;
  37. char bus_id[BUS_ID_SIZE];
  38. unsigned int devindex;
  39. unsigned short features;
  40. struct dasd_device *device;
  41. struct dasd_uid uid;
  42. };
  43. /*
  44. * dasd_server_ssid_map contains a globally unique storage server subsystem ID.
  45. * dasd_server_ssid_list contains the list of all subsystem IDs accessed by
  46. * the DASD device driver.
  47. */
  48. struct dasd_server_ssid_map {
  49. struct list_head list;
  50. struct server_id {
  51. char vendor[4];
  52. char serial[15];
  53. } sid;
  54. __u16 ssid;
  55. };
  56. static struct list_head dasd_server_ssid_list;
  57. /*
  58. * Parameter parsing functions for dasd= parameter. The syntax is:
  59. * <devno> : (0x)?[0-9a-fA-F]+
  60. * <busid> : [0-0a-f]\.[0-9a-f]\.(0x)?[0-9a-fA-F]+
  61. * <feature> : ro
  62. * <feature_list> : \(<feature>(:<feature>)*\)
  63. * <devno-range> : <devno>(-<devno>)?<feature_list>?
  64. * <busid-range> : <busid>(-<busid>)?<feature_list>?
  65. * <devices> : <devno-range>|<busid-range>
  66. * <dasd_module> : dasd_diag_mod|dasd_eckd_mod|dasd_fba_mod
  67. *
  68. * <dasd> : autodetect|probeonly|<devices>(,<devices>)*
  69. */
  70. int dasd_probeonly = 0; /* is true, when probeonly mode is active */
  71. int dasd_autodetect = 0; /* is true, when autodetection is active */
  72. int dasd_nopav = 0; /* is true, when PAV is disabled */
  73. EXPORT_SYMBOL_GPL(dasd_nopav);
  74. /*
  75. * char *dasd[] is intended to hold the ranges supplied by the dasd= statement
  76. * it is named 'dasd' to directly be filled by insmod with the comma separated
  77. * strings when running as a module.
  78. */
  79. static char *dasd[256];
  80. module_param_array(dasd, charp, NULL, 0);
  81. /*
  82. * Single spinlock to protect devmap and servermap structures and lists.
  83. */
  84. static DEFINE_SPINLOCK(dasd_devmap_lock);
  85. /*
  86. * Hash lists for devmap structures.
  87. */
  88. static struct list_head dasd_hashlists[256];
  89. int dasd_max_devindex;
  90. static struct dasd_devmap *dasd_add_busid(char *, int);
  91. static inline int
  92. dasd_hash_busid(char *bus_id)
  93. {
  94. int hash, i;
  95. hash = 0;
  96. for (i = 0; (i < BUS_ID_SIZE) && *bus_id; i++, bus_id++)
  97. hash += *bus_id;
  98. return hash & 0xff;
  99. }
  100. #ifndef MODULE
  101. /*
  102. * The parameter parsing functions for builtin-drivers are called
  103. * before kmalloc works. Store the pointers to the parameters strings
  104. * into dasd[] for later processing.
  105. */
  106. static int __init
  107. dasd_call_setup(char *str)
  108. {
  109. static int count = 0;
  110. if (count < 256)
  111. dasd[count++] = str;
  112. return 1;
  113. }
  114. __setup ("dasd=", dasd_call_setup);
  115. #endif /* #ifndef MODULE */
  116. /*
  117. * Read a device busid/devno from a string.
  118. */
  119. static inline int
  120. dasd_busid(char **str, int *id0, int *id1, int *devno)
  121. {
  122. int val, old_style;
  123. /* check for leading '0x' */
  124. old_style = 0;
  125. if ((*str)[0] == '0' && (*str)[1] == 'x') {
  126. *str += 2;
  127. old_style = 1;
  128. }
  129. if (!isxdigit((*str)[0])) /* We require at least one hex digit */
  130. return -EINVAL;
  131. val = simple_strtoul(*str, str, 16);
  132. if (old_style || (*str)[0] != '.') {
  133. *id0 = *id1 = 0;
  134. if (val < 0 || val > 0xffff)
  135. return -EINVAL;
  136. *devno = val;
  137. return 0;
  138. }
  139. /* New style x.y.z busid */
  140. if (val < 0 || val > 0xff)
  141. return -EINVAL;
  142. *id0 = val;
  143. (*str)++;
  144. if (!isxdigit((*str)[0])) /* We require at least one hex digit */
  145. return -EINVAL;
  146. val = simple_strtoul(*str, str, 16);
  147. if (val < 0 || val > 0xff || (*str)++[0] != '.')
  148. return -EINVAL;
  149. *id1 = val;
  150. if (!isxdigit((*str)[0])) /* We require at least one hex digit */
  151. return -EINVAL;
  152. val = simple_strtoul(*str, str, 16);
  153. if (val < 0 || val > 0xffff)
  154. return -EINVAL;
  155. *devno = val;
  156. return 0;
  157. }
  158. /*
  159. * Read colon separated list of dasd features. Currently there is
  160. * only one: "ro" for read-only devices. The default feature set
  161. * is empty (value 0).
  162. */
  163. static inline int
  164. dasd_feature_list(char *str, char **endp)
  165. {
  166. int features, len, rc;
  167. rc = 0;
  168. if (*str != '(') {
  169. *endp = str;
  170. return DASD_FEATURE_DEFAULT;
  171. }
  172. str++;
  173. features = 0;
  174. while (1) {
  175. for (len = 0;
  176. str[len] && str[len] != ':' && str[len] != ')'; len++);
  177. if (len == 2 && !strncmp(str, "ro", 2))
  178. features |= DASD_FEATURE_READONLY;
  179. else if (len == 4 && !strncmp(str, "diag", 4))
  180. features |= DASD_FEATURE_USEDIAG;
  181. else {
  182. MESSAGE(KERN_WARNING,
  183. "unsupported feature: %*s, "
  184. "ignoring setting", len, str);
  185. rc = -EINVAL;
  186. }
  187. str += len;
  188. if (*str != ':')
  189. break;
  190. str++;
  191. }
  192. if (*str != ')') {
  193. MESSAGE(KERN_WARNING, "%s",
  194. "missing ')' in dasd parameter string\n");
  195. rc = -EINVAL;
  196. } else
  197. str++;
  198. *endp = str;
  199. if (rc != 0)
  200. return rc;
  201. return features;
  202. }
  203. /*
  204. * Try to match the first element on the comma separated parse string
  205. * with one of the known keywords. If a keyword is found, take the approprate
  206. * action and return a pointer to the residual string. If the first element
  207. * could not be matched to any keyword then return an error code.
  208. */
  209. static char *
  210. dasd_parse_keyword( char *parsestring ) {
  211. char *nextcomma, *residual_str;
  212. int length;
  213. nextcomma = strchr(parsestring,',');
  214. if (nextcomma) {
  215. length = nextcomma - parsestring;
  216. residual_str = nextcomma + 1;
  217. } else {
  218. length = strlen(parsestring);
  219. residual_str = parsestring + length;
  220. }
  221. if (strncmp("autodetect", parsestring, length) == 0) {
  222. dasd_autodetect = 1;
  223. MESSAGE (KERN_INFO, "%s",
  224. "turning to autodetection mode");
  225. return residual_str;
  226. }
  227. if (strncmp("probeonly", parsestring, length) == 0) {
  228. dasd_probeonly = 1;
  229. MESSAGE(KERN_INFO, "%s",
  230. "turning to probeonly mode");
  231. return residual_str;
  232. }
  233. if (strncmp("nopav", parsestring, length) == 0) {
  234. dasd_nopav = 1;
  235. MESSAGE(KERN_INFO, "%s", "disable PAV mode");
  236. return residual_str;
  237. }
  238. if (strncmp("fixedbuffers", parsestring, length) == 0) {
  239. if (dasd_page_cache)
  240. return residual_str;
  241. dasd_page_cache =
  242. kmem_cache_create("dasd_page_cache", PAGE_SIZE,
  243. PAGE_SIZE, SLAB_CACHE_DMA,
  244. NULL, NULL );
  245. if (!dasd_page_cache)
  246. MESSAGE(KERN_WARNING, "%s", "Failed to create slab, "
  247. "fixed buffer mode disabled.");
  248. else
  249. MESSAGE (KERN_INFO, "%s",
  250. "turning on fixed buffer mode");
  251. return residual_str;
  252. }
  253. return ERR_PTR(-EINVAL);
  254. }
  255. /*
  256. * Try to interprete the first element on the comma separated parse string
  257. * as a device number or a range of devices. If the interpretation is
  258. * successfull, create the matching dasd_devmap entries and return a pointer
  259. * to the residual string.
  260. * If interpretation fails or in case of an error, return an error code.
  261. */
  262. static char *
  263. dasd_parse_range( char *parsestring ) {
  264. struct dasd_devmap *devmap;
  265. int from, from_id0, from_id1;
  266. int to, to_id0, to_id1;
  267. int features, rc;
  268. char bus_id[BUS_ID_SIZE+1], *str;
  269. str = parsestring;
  270. rc = dasd_busid(&str, &from_id0, &from_id1, &from);
  271. if (rc == 0) {
  272. to = from;
  273. to_id0 = from_id0;
  274. to_id1 = from_id1;
  275. if (*str == '-') {
  276. str++;
  277. rc = dasd_busid(&str, &to_id0, &to_id1, &to);
  278. }
  279. }
  280. if (rc == 0 &&
  281. (from_id0 != to_id0 || from_id1 != to_id1 || from > to))
  282. rc = -EINVAL;
  283. if (rc) {
  284. MESSAGE(KERN_ERR, "Invalid device range %s", parsestring);
  285. return ERR_PTR(rc);
  286. }
  287. features = dasd_feature_list(str, &str);
  288. if (features < 0)
  289. return ERR_PTR(-EINVAL);
  290. /* each device in dasd= parameter should be set initially online */
  291. features |= DASD_FEATURE_INITIAL_ONLINE;
  292. while (from <= to) {
  293. sprintf(bus_id, "%01x.%01x.%04x",
  294. from_id0, from_id1, from++);
  295. devmap = dasd_add_busid(bus_id, features);
  296. if (IS_ERR(devmap))
  297. return (char *)devmap;
  298. }
  299. if (*str == ',')
  300. return str + 1;
  301. if (*str == '\0')
  302. return str;
  303. MESSAGE(KERN_WARNING,
  304. "junk at end of dasd parameter string: %s\n", str);
  305. return ERR_PTR(-EINVAL);
  306. }
  307. static inline char *
  308. dasd_parse_next_element( char *parsestring ) {
  309. char * residual_str;
  310. residual_str = dasd_parse_keyword(parsestring);
  311. if (!IS_ERR(residual_str))
  312. return residual_str;
  313. residual_str = dasd_parse_range(parsestring);
  314. return residual_str;
  315. }
  316. /*
  317. * Parse parameters stored in dasd[]
  318. * The 'dasd=...' parameter allows to specify a comma separated list of
  319. * keywords and device ranges. When the dasd driver is build into the kernel,
  320. * the complete list will be stored as one element of the dasd[] array.
  321. * When the dasd driver is build as a module, then the list is broken into
  322. * it's elements and each dasd[] entry contains one element.
  323. */
  324. int
  325. dasd_parse(void)
  326. {
  327. int rc, i;
  328. char *parsestring;
  329. rc = 0;
  330. for (i = 0; i < 256; i++) {
  331. if (dasd[i] == NULL)
  332. break;
  333. parsestring = dasd[i];
  334. /* loop over the comma separated list in the parsestring */
  335. while (*parsestring) {
  336. parsestring = dasd_parse_next_element(parsestring);
  337. if(IS_ERR(parsestring)) {
  338. rc = PTR_ERR(parsestring);
  339. break;
  340. }
  341. }
  342. if (rc) {
  343. DBF_EVENT(DBF_ALERT, "%s", "invalid range found");
  344. break;
  345. }
  346. }
  347. return rc;
  348. }
  349. /*
  350. * Add a devmap for the device specified by busid. It is possible that
  351. * the devmap already exists (dasd= parameter). The order of the devices
  352. * added through this function will define the kdevs for the individual
  353. * devices.
  354. */
  355. static struct dasd_devmap *
  356. dasd_add_busid(char *bus_id, int features)
  357. {
  358. struct dasd_devmap *devmap, *new, *tmp;
  359. int hash;
  360. new = (struct dasd_devmap *)
  361. kzalloc(sizeof(struct dasd_devmap), GFP_KERNEL);
  362. if (!new)
  363. return ERR_PTR(-ENOMEM);
  364. spin_lock(&dasd_devmap_lock);
  365. devmap = NULL;
  366. hash = dasd_hash_busid(bus_id);
  367. list_for_each_entry(tmp, &dasd_hashlists[hash], list)
  368. if (strncmp(tmp->bus_id, bus_id, BUS_ID_SIZE) == 0) {
  369. devmap = tmp;
  370. break;
  371. }
  372. if (!devmap) {
  373. /* This bus_id is new. */
  374. new->devindex = dasd_max_devindex++;
  375. strncpy(new->bus_id, bus_id, BUS_ID_SIZE);
  376. new->features = features;
  377. new->device = NULL;
  378. list_add(&new->list, &dasd_hashlists[hash]);
  379. devmap = new;
  380. new = NULL;
  381. }
  382. spin_unlock(&dasd_devmap_lock);
  383. kfree(new);
  384. return devmap;
  385. }
  386. /*
  387. * Find devmap for device with given bus_id.
  388. */
  389. static struct dasd_devmap *
  390. dasd_find_busid(char *bus_id)
  391. {
  392. struct dasd_devmap *devmap, *tmp;
  393. int hash;
  394. spin_lock(&dasd_devmap_lock);
  395. devmap = ERR_PTR(-ENODEV);
  396. hash = dasd_hash_busid(bus_id);
  397. list_for_each_entry(tmp, &dasd_hashlists[hash], list) {
  398. if (strncmp(tmp->bus_id, bus_id, BUS_ID_SIZE) == 0) {
  399. devmap = tmp;
  400. break;
  401. }
  402. }
  403. spin_unlock(&dasd_devmap_lock);
  404. return devmap;
  405. }
  406. /*
  407. * Check if busid has been added to the list of dasd ranges.
  408. */
  409. int
  410. dasd_busid_known(char *bus_id)
  411. {
  412. return IS_ERR(dasd_find_busid(bus_id)) ? -ENOENT : 0;
  413. }
  414. /*
  415. * Forget all about the device numbers added so far.
  416. * This may only be called at module unload or system shutdown.
  417. */
  418. static void
  419. dasd_forget_ranges(void)
  420. {
  421. struct dasd_devmap *devmap, *n;
  422. int i;
  423. spin_lock(&dasd_devmap_lock);
  424. for (i = 0; i < 256; i++) {
  425. list_for_each_entry_safe(devmap, n, &dasd_hashlists[i], list) {
  426. BUG_ON(devmap->device != NULL);
  427. list_del(&devmap->list);
  428. kfree(devmap);
  429. }
  430. }
  431. spin_unlock(&dasd_devmap_lock);
  432. }
  433. /*
  434. * Find the device struct by its device index.
  435. */
  436. struct dasd_device *
  437. dasd_device_from_devindex(int devindex)
  438. {
  439. struct dasd_devmap *devmap, *tmp;
  440. struct dasd_device *device;
  441. int i;
  442. spin_lock(&dasd_devmap_lock);
  443. devmap = NULL;
  444. for (i = 0; (i < 256) && !devmap; i++)
  445. list_for_each_entry(tmp, &dasd_hashlists[i], list)
  446. if (tmp->devindex == devindex) {
  447. /* Found the devmap for the device. */
  448. devmap = tmp;
  449. break;
  450. }
  451. if (devmap && devmap->device) {
  452. device = devmap->device;
  453. dasd_get_device(device);
  454. } else
  455. device = ERR_PTR(-ENODEV);
  456. spin_unlock(&dasd_devmap_lock);
  457. return device;
  458. }
  459. /*
  460. * Return devmap for cdev. If no devmap exists yet, create one and
  461. * connect it to the cdev.
  462. */
  463. static struct dasd_devmap *
  464. dasd_devmap_from_cdev(struct ccw_device *cdev)
  465. {
  466. struct dasd_devmap *devmap;
  467. devmap = dasd_find_busid(cdev->dev.bus_id);
  468. if (IS_ERR(devmap))
  469. devmap = dasd_add_busid(cdev->dev.bus_id,
  470. DASD_FEATURE_DEFAULT);
  471. return devmap;
  472. }
  473. /*
  474. * Create a dasd device structure for cdev.
  475. */
  476. struct dasd_device *
  477. dasd_create_device(struct ccw_device *cdev)
  478. {
  479. struct dasd_devmap *devmap;
  480. struct dasd_device *device;
  481. int rc;
  482. devmap = dasd_devmap_from_cdev(cdev);
  483. if (IS_ERR(devmap))
  484. return (void *) devmap;
  485. cdev->dev.driver_data = devmap;
  486. device = dasd_alloc_device();
  487. if (IS_ERR(device))
  488. return device;
  489. atomic_set(&device->ref_count, 2);
  490. spin_lock(&dasd_devmap_lock);
  491. if (!devmap->device) {
  492. devmap->device = device;
  493. device->devindex = devmap->devindex;
  494. device->features = devmap->features;
  495. get_device(&cdev->dev);
  496. device->cdev = cdev;
  497. rc = 0;
  498. } else
  499. /* Someone else was faster. */
  500. rc = -EBUSY;
  501. spin_unlock(&dasd_devmap_lock);
  502. if (rc) {
  503. dasd_free_device(device);
  504. return ERR_PTR(rc);
  505. }
  506. return device;
  507. }
  508. /*
  509. * Wait queue for dasd_delete_device waits.
  510. */
  511. static DECLARE_WAIT_QUEUE_HEAD(dasd_delete_wq);
  512. /*
  513. * Remove a dasd device structure. The passed referenced
  514. * is destroyed.
  515. */
  516. void
  517. dasd_delete_device(struct dasd_device *device)
  518. {
  519. struct ccw_device *cdev;
  520. struct dasd_devmap *devmap;
  521. /* First remove device pointer from devmap. */
  522. devmap = dasd_find_busid(device->cdev->dev.bus_id);
  523. BUG_ON(IS_ERR(devmap));
  524. spin_lock(&dasd_devmap_lock);
  525. if (devmap->device != device) {
  526. spin_unlock(&dasd_devmap_lock);
  527. dasd_put_device(device);
  528. return;
  529. }
  530. devmap->device = NULL;
  531. spin_unlock(&dasd_devmap_lock);
  532. /* Drop ref_count by 2, one for the devmap reference and
  533. * one for the passed reference. */
  534. atomic_sub(2, &device->ref_count);
  535. /* Wait for reference counter to drop to zero. */
  536. wait_event(dasd_delete_wq, atomic_read(&device->ref_count) == 0);
  537. /* Disconnect dasd_device structure from ccw_device structure. */
  538. cdev = device->cdev;
  539. device->cdev = NULL;
  540. /* Disconnect dasd_devmap structure from ccw_device structure. */
  541. cdev->dev.driver_data = NULL;
  542. /* Put ccw_device structure. */
  543. put_device(&cdev->dev);
  544. /* Now the device structure can be freed. */
  545. dasd_free_device(device);
  546. }
  547. /*
  548. * Reference counter dropped to zero. Wake up waiter
  549. * in dasd_delete_device.
  550. */
  551. void
  552. dasd_put_device_wake(struct dasd_device *device)
  553. {
  554. wake_up(&dasd_delete_wq);
  555. }
  556. /*
  557. * Return dasd_device structure associated with cdev.
  558. */
  559. struct dasd_device *
  560. dasd_device_from_cdev(struct ccw_device *cdev)
  561. {
  562. struct dasd_devmap *devmap;
  563. struct dasd_device *device;
  564. device = ERR_PTR(-ENODEV);
  565. spin_lock(&dasd_devmap_lock);
  566. devmap = cdev->dev.driver_data;
  567. if (devmap && devmap->device) {
  568. device = devmap->device;
  569. dasd_get_device(device);
  570. }
  571. spin_unlock(&dasd_devmap_lock);
  572. return device;
  573. }
  574. /*
  575. * SECTION: files in sysfs
  576. */
  577. /*
  578. * readonly controls the readonly status of a dasd
  579. */
  580. static ssize_t
  581. dasd_ro_show(struct device *dev, struct device_attribute *attr, char *buf)
  582. {
  583. struct dasd_devmap *devmap;
  584. int ro_flag;
  585. devmap = dasd_find_busid(dev->bus_id);
  586. if (!IS_ERR(devmap))
  587. ro_flag = (devmap->features & DASD_FEATURE_READONLY) != 0;
  588. else
  589. ro_flag = (DASD_FEATURE_DEFAULT & DASD_FEATURE_READONLY) != 0;
  590. return snprintf(buf, PAGE_SIZE, ro_flag ? "1\n" : "0\n");
  591. }
  592. static ssize_t
  593. dasd_ro_store(struct device *dev, struct device_attribute *attr,
  594. const char *buf, size_t count)
  595. {
  596. struct dasd_devmap *devmap;
  597. int ro_flag;
  598. devmap = dasd_devmap_from_cdev(to_ccwdev(dev));
  599. if (IS_ERR(devmap))
  600. return PTR_ERR(devmap);
  601. ro_flag = buf[0] == '1';
  602. spin_lock(&dasd_devmap_lock);
  603. if (ro_flag)
  604. devmap->features |= DASD_FEATURE_READONLY;
  605. else
  606. devmap->features &= ~DASD_FEATURE_READONLY;
  607. if (devmap->device)
  608. devmap->device->features = devmap->features;
  609. if (devmap->device && devmap->device->gdp)
  610. set_disk_ro(devmap->device->gdp, ro_flag);
  611. spin_unlock(&dasd_devmap_lock);
  612. return count;
  613. }
  614. static DEVICE_ATTR(readonly, 0644, dasd_ro_show, dasd_ro_store);
  615. /*
  616. * use_diag controls whether the driver should use diag rather than ssch
  617. * to talk to the device
  618. */
  619. static ssize_t
  620. dasd_use_diag_show(struct device *dev, struct device_attribute *attr, char *buf)
  621. {
  622. struct dasd_devmap *devmap;
  623. int use_diag;
  624. devmap = dasd_find_busid(dev->bus_id);
  625. if (!IS_ERR(devmap))
  626. use_diag = (devmap->features & DASD_FEATURE_USEDIAG) != 0;
  627. else
  628. use_diag = (DASD_FEATURE_DEFAULT & DASD_FEATURE_USEDIAG) != 0;
  629. return sprintf(buf, use_diag ? "1\n" : "0\n");
  630. }
  631. static ssize_t
  632. dasd_use_diag_store(struct device *dev, struct device_attribute *attr,
  633. const char *buf, size_t count)
  634. {
  635. struct dasd_devmap *devmap;
  636. ssize_t rc;
  637. int use_diag;
  638. devmap = dasd_devmap_from_cdev(to_ccwdev(dev));
  639. if (IS_ERR(devmap))
  640. return PTR_ERR(devmap);
  641. use_diag = buf[0] == '1';
  642. spin_lock(&dasd_devmap_lock);
  643. /* Changing diag discipline flag is only allowed in offline state. */
  644. rc = count;
  645. if (!devmap->device) {
  646. if (use_diag)
  647. devmap->features |= DASD_FEATURE_USEDIAG;
  648. else
  649. devmap->features &= ~DASD_FEATURE_USEDIAG;
  650. } else
  651. rc = -EPERM;
  652. spin_unlock(&dasd_devmap_lock);
  653. return rc;
  654. }
  655. static DEVICE_ATTR(use_diag, 0644, dasd_use_diag_show, dasd_use_diag_store);
  656. static ssize_t
  657. dasd_discipline_show(struct device *dev, struct device_attribute *attr,
  658. char *buf)
  659. {
  660. struct dasd_devmap *devmap;
  661. char *dname;
  662. spin_lock(&dasd_devmap_lock);
  663. dname = "none";
  664. devmap = dev->driver_data;
  665. if (devmap && devmap->device && devmap->device->discipline)
  666. dname = devmap->device->discipline->name;
  667. spin_unlock(&dasd_devmap_lock);
  668. return snprintf(buf, PAGE_SIZE, "%s\n", dname);
  669. }
  670. static DEVICE_ATTR(discipline, 0444, dasd_discipline_show, NULL);
  671. static ssize_t
  672. dasd_alias_show(struct device *dev, struct device_attribute *attr, char *buf)
  673. {
  674. struct dasd_devmap *devmap;
  675. int alias;
  676. devmap = dasd_find_busid(dev->bus_id);
  677. spin_lock(&dasd_devmap_lock);
  678. if (!IS_ERR(devmap))
  679. alias = devmap->uid.alias;
  680. else
  681. alias = 0;
  682. spin_unlock(&dasd_devmap_lock);
  683. return sprintf(buf, alias ? "1\n" : "0\n");
  684. }
  685. static DEVICE_ATTR(alias, 0444, dasd_alias_show, NULL);
  686. static ssize_t
  687. dasd_vendor_show(struct device *dev, struct device_attribute *attr, char *buf)
  688. {
  689. struct dasd_devmap *devmap;
  690. char *vendor;
  691. devmap = dasd_find_busid(dev->bus_id);
  692. spin_lock(&dasd_devmap_lock);
  693. if (!IS_ERR(devmap) && strlen(devmap->uid.vendor) > 0)
  694. vendor = devmap->uid.vendor;
  695. else
  696. vendor = "";
  697. spin_unlock(&dasd_devmap_lock);
  698. return snprintf(buf, PAGE_SIZE, "%s\n", vendor);
  699. }
  700. static DEVICE_ATTR(vendor, 0444, dasd_vendor_show, NULL);
  701. #define UID_STRLEN ( /* vendor */ 3 + 1 + /* serial */ 14 + 1 +\
  702. /* SSID */ 4 + 1 + /* unit addr */ 2 + 1)
  703. static ssize_t
  704. dasd_uid_show(struct device *dev, struct device_attribute *attr, char *buf)
  705. {
  706. struct dasd_devmap *devmap;
  707. char uid[UID_STRLEN];
  708. devmap = dasd_find_busid(dev->bus_id);
  709. spin_lock(&dasd_devmap_lock);
  710. if (!IS_ERR(devmap) && strlen(devmap->uid.vendor) > 0)
  711. snprintf(uid, sizeof(uid), "%s.%s.%04x.%02x",
  712. devmap->uid.vendor, devmap->uid.serial,
  713. devmap->uid.ssid, devmap->uid.unit_addr);
  714. else
  715. uid[0] = 0;
  716. spin_unlock(&dasd_devmap_lock);
  717. return snprintf(buf, PAGE_SIZE, "%s\n", uid);
  718. }
  719. static DEVICE_ATTR(uid, 0444, dasd_uid_show, NULL);
  720. /*
  721. * extended error-reporting
  722. */
  723. static ssize_t
  724. dasd_eer_show(struct device *dev, struct device_attribute *attr, char *buf)
  725. {
  726. struct dasd_devmap *devmap;
  727. int eer_flag;
  728. devmap = dasd_find_busid(dev->bus_id);
  729. if (!IS_ERR(devmap) && devmap->device)
  730. eer_flag = dasd_eer_enabled(devmap->device);
  731. else
  732. eer_flag = 0;
  733. return snprintf(buf, PAGE_SIZE, eer_flag ? "1\n" : "0\n");
  734. }
  735. static ssize_t
  736. dasd_eer_store(struct device *dev, struct device_attribute *attr,
  737. const char *buf, size_t count)
  738. {
  739. struct dasd_devmap *devmap;
  740. int rc;
  741. devmap = dasd_devmap_from_cdev(to_ccwdev(dev));
  742. if (IS_ERR(devmap))
  743. return PTR_ERR(devmap);
  744. if (!devmap->device)
  745. return count;
  746. if (buf[0] == '1') {
  747. rc = dasd_eer_enable(devmap->device);
  748. if (rc)
  749. return rc;
  750. } else
  751. dasd_eer_disable(devmap->device);
  752. return count;
  753. }
  754. static DEVICE_ATTR(eer_enabled, 0644, dasd_eer_show, dasd_eer_store);
  755. static struct attribute * dasd_attrs[] = {
  756. &dev_attr_readonly.attr,
  757. &dev_attr_discipline.attr,
  758. &dev_attr_alias.attr,
  759. &dev_attr_vendor.attr,
  760. &dev_attr_uid.attr,
  761. &dev_attr_use_diag.attr,
  762. &dev_attr_eer_enabled.attr,
  763. NULL,
  764. };
  765. static struct attribute_group dasd_attr_group = {
  766. .attrs = dasd_attrs,
  767. };
  768. /*
  769. * Return copy of the device unique identifier.
  770. */
  771. int
  772. dasd_get_uid(struct ccw_device *cdev, struct dasd_uid *uid)
  773. {
  774. struct dasd_devmap *devmap;
  775. devmap = dasd_find_busid(cdev->dev.bus_id);
  776. if (IS_ERR(devmap))
  777. return PTR_ERR(devmap);
  778. spin_lock(&dasd_devmap_lock);
  779. *uid = devmap->uid;
  780. spin_unlock(&dasd_devmap_lock);
  781. return 0;
  782. }
  783. /*
  784. * Register the given device unique identifier into devmap struct.
  785. * In addition check if the related storage server subsystem ID is already
  786. * contained in the dasd_server_ssid_list. If subsystem ID is not contained,
  787. * create new entry.
  788. * Return 0 if server was already in serverlist,
  789. * 1 if the server was added successful
  790. * <0 in case of error.
  791. */
  792. int
  793. dasd_set_uid(struct ccw_device *cdev, struct dasd_uid *uid)
  794. {
  795. struct dasd_devmap *devmap;
  796. struct dasd_server_ssid_map *srv, *tmp;
  797. devmap = dasd_find_busid(cdev->dev.bus_id);
  798. if (IS_ERR(devmap))
  799. return PTR_ERR(devmap);
  800. /* generate entry for server_ssid_map */
  801. srv = (struct dasd_server_ssid_map *)
  802. kzalloc(sizeof(struct dasd_server_ssid_map), GFP_KERNEL);
  803. if (!srv)
  804. return -ENOMEM;
  805. strncpy(srv->sid.vendor, uid->vendor, sizeof(srv->sid.vendor) - 1);
  806. strncpy(srv->sid.serial, uid->serial, sizeof(srv->sid.serial) - 1);
  807. srv->ssid = uid->ssid;
  808. /* server is already contained ? */
  809. spin_lock(&dasd_devmap_lock);
  810. devmap->uid = *uid;
  811. list_for_each_entry(tmp, &dasd_server_ssid_list, list) {
  812. if (!memcmp(&srv->sid, &tmp->sid,
  813. sizeof(struct dasd_server_ssid_map))) {
  814. kfree(srv);
  815. srv = NULL;
  816. break;
  817. }
  818. }
  819. /* add servermap to serverlist */
  820. if (srv)
  821. list_add(&srv->list, &dasd_server_ssid_list);
  822. spin_unlock(&dasd_devmap_lock);
  823. return (srv ? 1 : 0);
  824. }
  825. EXPORT_SYMBOL_GPL(dasd_set_uid);
  826. /*
  827. * Return value of the specified feature.
  828. */
  829. int
  830. dasd_get_feature(struct ccw_device *cdev, int feature)
  831. {
  832. struct dasd_devmap *devmap;
  833. devmap = dasd_find_busid(cdev->dev.bus_id);
  834. if (IS_ERR(devmap))
  835. return PTR_ERR(devmap);
  836. return ((devmap->features & feature) != 0);
  837. }
  838. /*
  839. * Set / reset given feature.
  840. * Flag indicates wether to set (!=0) or the reset (=0) the feature.
  841. */
  842. int
  843. dasd_set_feature(struct ccw_device *cdev, int feature, int flag)
  844. {
  845. struct dasd_devmap *devmap;
  846. devmap = dasd_find_busid(cdev->dev.bus_id);
  847. if (IS_ERR(devmap))
  848. return PTR_ERR(devmap);
  849. spin_lock(&dasd_devmap_lock);
  850. if (flag)
  851. devmap->features |= feature;
  852. else
  853. devmap->features &= ~feature;
  854. if (devmap->device)
  855. devmap->device->features = devmap->features;
  856. spin_unlock(&dasd_devmap_lock);
  857. return 0;
  858. }
  859. int
  860. dasd_add_sysfs_files(struct ccw_device *cdev)
  861. {
  862. return sysfs_create_group(&cdev->dev.kobj, &dasd_attr_group);
  863. }
  864. void
  865. dasd_remove_sysfs_files(struct ccw_device *cdev)
  866. {
  867. sysfs_remove_group(&cdev->dev.kobj, &dasd_attr_group);
  868. }
  869. int
  870. dasd_devmap_init(void)
  871. {
  872. int i;
  873. /* Initialize devmap structures. */
  874. dasd_max_devindex = 0;
  875. for (i = 0; i < 256; i++)
  876. INIT_LIST_HEAD(&dasd_hashlists[i]);
  877. /* Initialize servermap structure. */
  878. INIT_LIST_HEAD(&dasd_server_ssid_list);
  879. return 0;
  880. }
  881. void
  882. dasd_devmap_exit(void)
  883. {
  884. dasd_forget_ranges();
  885. }