chp.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804
  1. /*
  2. * Copyright IBM Corp. 1999, 2010
  3. * Author(s): Cornelia Huck (cornelia.huck@de.ibm.com)
  4. * Arnd Bergmann (arndb@de.ibm.com)
  5. * Peter Oberparleiter <peter.oberparleiter@de.ibm.com>
  6. */
  7. #include <linux/bug.h>
  8. #include <linux/workqueue.h>
  9. #include <linux/spinlock.h>
  10. #include <linux/export.h>
  11. #include <linux/sched.h>
  12. #include <linux/init.h>
  13. #include <linux/jiffies.h>
  14. #include <linux/wait.h>
  15. #include <linux/mutex.h>
  16. #include <linux/errno.h>
  17. #include <linux/slab.h>
  18. #include <asm/chpid.h>
  19. #include <asm/sclp.h>
  20. #include <asm/crw.h>
  21. #include "cio.h"
  22. #include "css.h"
  23. #include "ioasm.h"
  24. #include "cio_debug.h"
  25. #include "chp.h"
  26. #define to_channelpath(device) container_of(device, struct channel_path, dev)
  27. #define CHP_INFO_UPDATE_INTERVAL 1*HZ
  28. enum cfg_task_t {
  29. cfg_none,
  30. cfg_configure,
  31. cfg_deconfigure
  32. };
  33. /* Map for pending configure tasks. */
  34. static enum cfg_task_t chp_cfg_task[__MAX_CSSID + 1][__MAX_CHPID + 1];
  35. static DEFINE_SPINLOCK(cfg_lock);
  36. /* Map for channel-path status. */
  37. static struct sclp_chp_info chp_info;
  38. static DEFINE_MUTEX(info_lock);
  39. /* Time after which channel-path status may be outdated. */
  40. static unsigned long chp_info_expires;
  41. static struct work_struct cfg_work;
  42. /* Wait queue for configure completion events. */
  43. static wait_queue_head_t cfg_wait_queue;
  44. /* Set vary state for given chpid. */
  45. static void set_chp_logically_online(struct chp_id chpid, int onoff)
  46. {
  47. chpid_to_chp(chpid)->state = onoff;
  48. }
  49. /* On success return 0 if channel-path is varied offline, 1 if it is varied
  50. * online. Return -ENODEV if channel-path is not registered. */
  51. int chp_get_status(struct chp_id chpid)
  52. {
  53. return (chpid_to_chp(chpid) ? chpid_to_chp(chpid)->state : -ENODEV);
  54. }
  55. /**
  56. * chp_get_sch_opm - return opm for subchannel
  57. * @sch: subchannel
  58. *
  59. * Calculate and return the operational path mask (opm) based on the chpids
  60. * used by the subchannel and the status of the associated channel-paths.
  61. */
  62. u8 chp_get_sch_opm(struct subchannel *sch)
  63. {
  64. struct chp_id chpid;
  65. int opm;
  66. int i;
  67. opm = 0;
  68. chp_id_init(&chpid);
  69. for (i = 0; i < 8; i++) {
  70. opm <<= 1;
  71. chpid.id = sch->schib.pmcw.chpid[i];
  72. if (chp_get_status(chpid) != 0)
  73. opm |= 1;
  74. }
  75. return opm;
  76. }
  77. EXPORT_SYMBOL_GPL(chp_get_sch_opm);
  78. /**
  79. * chp_is_registered - check if a channel-path is registered
  80. * @chpid: channel-path ID
  81. *
  82. * Return non-zero if a channel-path with the given chpid is registered,
  83. * zero otherwise.
  84. */
  85. int chp_is_registered(struct chp_id chpid)
  86. {
  87. return chpid_to_chp(chpid) != NULL;
  88. }
  89. /*
  90. * Function: s390_vary_chpid
  91. * Varies the specified chpid online or offline
  92. */
  93. static int s390_vary_chpid(struct chp_id chpid, int on)
  94. {
  95. char dbf_text[15];
  96. int status;
  97. sprintf(dbf_text, on?"varyon%x.%02x":"varyoff%x.%02x", chpid.cssid,
  98. chpid.id);
  99. CIO_TRACE_EVENT(2, dbf_text);
  100. status = chp_get_status(chpid);
  101. if (!on && !status)
  102. return 0;
  103. set_chp_logically_online(chpid, on);
  104. chsc_chp_vary(chpid, on);
  105. return 0;
  106. }
  107. /*
  108. * Channel measurement related functions
  109. */
  110. static ssize_t chp_measurement_chars_read(struct file *filp,
  111. struct kobject *kobj,
  112. struct bin_attribute *bin_attr,
  113. char *buf, loff_t off, size_t count)
  114. {
  115. struct channel_path *chp;
  116. struct device *device;
  117. device = container_of(kobj, struct device, kobj);
  118. chp = to_channelpath(device);
  119. if (chp->cmg == -1)
  120. return 0;
  121. return memory_read_from_buffer(buf, count, &off, &chp->cmg_chars,
  122. sizeof(chp->cmg_chars));
  123. }
  124. static struct bin_attribute chp_measurement_chars_attr = {
  125. .attr = {
  126. .name = "measurement_chars",
  127. .mode = S_IRUSR,
  128. },
  129. .size = sizeof(struct cmg_chars),
  130. .read = chp_measurement_chars_read,
  131. };
  132. static void chp_measurement_copy_block(struct cmg_entry *buf,
  133. struct channel_subsystem *css,
  134. struct chp_id chpid)
  135. {
  136. void *area;
  137. struct cmg_entry *entry, reference_buf;
  138. int idx;
  139. if (chpid.id < 128) {
  140. area = css->cub_addr1;
  141. idx = chpid.id;
  142. } else {
  143. area = css->cub_addr2;
  144. idx = chpid.id - 128;
  145. }
  146. entry = area + (idx * sizeof(struct cmg_entry));
  147. do {
  148. memcpy(buf, entry, sizeof(*entry));
  149. memcpy(&reference_buf, entry, sizeof(*entry));
  150. } while (reference_buf.values[0] != buf->values[0]);
  151. }
  152. static ssize_t chp_measurement_read(struct file *filp, struct kobject *kobj,
  153. struct bin_attribute *bin_attr,
  154. char *buf, loff_t off, size_t count)
  155. {
  156. struct channel_path *chp;
  157. struct channel_subsystem *css;
  158. struct device *device;
  159. unsigned int size;
  160. device = container_of(kobj, struct device, kobj);
  161. chp = to_channelpath(device);
  162. css = to_css(chp->dev.parent);
  163. size = sizeof(struct cmg_entry);
  164. /* Only allow single reads. */
  165. if (off || count < size)
  166. return 0;
  167. chp_measurement_copy_block((struct cmg_entry *)buf, css, chp->chpid);
  168. count = size;
  169. return count;
  170. }
  171. static struct bin_attribute chp_measurement_attr = {
  172. .attr = {
  173. .name = "measurement",
  174. .mode = S_IRUSR,
  175. },
  176. .size = sizeof(struct cmg_entry),
  177. .read = chp_measurement_read,
  178. };
  179. void chp_remove_cmg_attr(struct channel_path *chp)
  180. {
  181. device_remove_bin_file(&chp->dev, &chp_measurement_chars_attr);
  182. device_remove_bin_file(&chp->dev, &chp_measurement_attr);
  183. }
  184. int chp_add_cmg_attr(struct channel_path *chp)
  185. {
  186. int ret;
  187. ret = device_create_bin_file(&chp->dev, &chp_measurement_chars_attr);
  188. if (ret)
  189. return ret;
  190. ret = device_create_bin_file(&chp->dev, &chp_measurement_attr);
  191. if (ret)
  192. device_remove_bin_file(&chp->dev, &chp_measurement_chars_attr);
  193. return ret;
  194. }
  195. /*
  196. * Files for the channel path entries.
  197. */
  198. static ssize_t chp_status_show(struct device *dev,
  199. struct device_attribute *attr, char *buf)
  200. {
  201. struct channel_path *chp = to_channelpath(dev);
  202. int status;
  203. mutex_lock(&chp->lock);
  204. status = chp->state;
  205. mutex_unlock(&chp->lock);
  206. return status ? sprintf(buf, "online\n") : sprintf(buf, "offline\n");
  207. }
  208. static ssize_t chp_status_write(struct device *dev,
  209. struct device_attribute *attr,
  210. const char *buf, size_t count)
  211. {
  212. struct channel_path *cp = to_channelpath(dev);
  213. char cmd[10];
  214. int num_args;
  215. int error;
  216. num_args = sscanf(buf, "%5s", cmd);
  217. if (!num_args)
  218. return count;
  219. if (!strncasecmp(cmd, "on", 2) || !strcmp(cmd, "1")) {
  220. mutex_lock(&cp->lock);
  221. error = s390_vary_chpid(cp->chpid, 1);
  222. mutex_unlock(&cp->lock);
  223. } else if (!strncasecmp(cmd, "off", 3) || !strcmp(cmd, "0")) {
  224. mutex_lock(&cp->lock);
  225. error = s390_vary_chpid(cp->chpid, 0);
  226. mutex_unlock(&cp->lock);
  227. } else
  228. error = -EINVAL;
  229. return error < 0 ? error : count;
  230. }
  231. static DEVICE_ATTR(status, 0644, chp_status_show, chp_status_write);
  232. static ssize_t chp_configure_show(struct device *dev,
  233. struct device_attribute *attr, char *buf)
  234. {
  235. struct channel_path *cp;
  236. int status;
  237. cp = to_channelpath(dev);
  238. status = chp_info_get_status(cp->chpid);
  239. if (status < 0)
  240. return status;
  241. return snprintf(buf, PAGE_SIZE, "%d\n", status);
  242. }
  243. static int cfg_wait_idle(void);
  244. static ssize_t chp_configure_write(struct device *dev,
  245. struct device_attribute *attr,
  246. const char *buf, size_t count)
  247. {
  248. struct channel_path *cp;
  249. int val;
  250. char delim;
  251. if (sscanf(buf, "%d %c", &val, &delim) != 1)
  252. return -EINVAL;
  253. if (val != 0 && val != 1)
  254. return -EINVAL;
  255. cp = to_channelpath(dev);
  256. chp_cfg_schedule(cp->chpid, val);
  257. cfg_wait_idle();
  258. return count;
  259. }
  260. static DEVICE_ATTR(configure, 0644, chp_configure_show, chp_configure_write);
  261. static ssize_t chp_type_show(struct device *dev, struct device_attribute *attr,
  262. char *buf)
  263. {
  264. struct channel_path *chp = to_channelpath(dev);
  265. u8 type;
  266. mutex_lock(&chp->lock);
  267. type = chp->desc.desc;
  268. mutex_unlock(&chp->lock);
  269. return sprintf(buf, "%x\n", type);
  270. }
  271. static DEVICE_ATTR(type, 0444, chp_type_show, NULL);
  272. static ssize_t chp_cmg_show(struct device *dev, struct device_attribute *attr,
  273. char *buf)
  274. {
  275. struct channel_path *chp = to_channelpath(dev);
  276. if (!chp)
  277. return 0;
  278. if (chp->cmg == -1) /* channel measurements not available */
  279. return sprintf(buf, "unknown\n");
  280. return sprintf(buf, "%x\n", chp->cmg);
  281. }
  282. static DEVICE_ATTR(cmg, 0444, chp_cmg_show, NULL);
  283. static ssize_t chp_shared_show(struct device *dev,
  284. struct device_attribute *attr, char *buf)
  285. {
  286. struct channel_path *chp = to_channelpath(dev);
  287. if (!chp)
  288. return 0;
  289. if (chp->shared == -1) /* channel measurements not available */
  290. return sprintf(buf, "unknown\n");
  291. return sprintf(buf, "%x\n", chp->shared);
  292. }
  293. static DEVICE_ATTR(shared, 0444, chp_shared_show, NULL);
  294. static ssize_t chp_chid_show(struct device *dev, struct device_attribute *attr,
  295. char *buf)
  296. {
  297. struct channel_path *chp = to_channelpath(dev);
  298. ssize_t rc;
  299. mutex_lock(&chp->lock);
  300. if (chp->desc_fmt1.flags & 0x10)
  301. rc = sprintf(buf, "%04x\n", chp->desc_fmt1.chid);
  302. else
  303. rc = 0;
  304. mutex_unlock(&chp->lock);
  305. return rc;
  306. }
  307. static DEVICE_ATTR(chid, 0444, chp_chid_show, NULL);
  308. static ssize_t chp_chid_external_show(struct device *dev,
  309. struct device_attribute *attr, char *buf)
  310. {
  311. struct channel_path *chp = to_channelpath(dev);
  312. ssize_t rc;
  313. mutex_lock(&chp->lock);
  314. if (chp->desc_fmt1.flags & 0x10)
  315. rc = sprintf(buf, "%x\n", chp->desc_fmt1.flags & 0x8 ? 1 : 0);
  316. else
  317. rc = 0;
  318. mutex_unlock(&chp->lock);
  319. return rc;
  320. }
  321. static DEVICE_ATTR(chid_external, 0444, chp_chid_external_show, NULL);
  322. static struct attribute *chp_attrs[] = {
  323. &dev_attr_status.attr,
  324. &dev_attr_configure.attr,
  325. &dev_attr_type.attr,
  326. &dev_attr_cmg.attr,
  327. &dev_attr_shared.attr,
  328. &dev_attr_chid.attr,
  329. &dev_attr_chid_external.attr,
  330. NULL,
  331. };
  332. static struct attribute_group chp_attr_group = {
  333. .attrs = chp_attrs,
  334. };
  335. static const struct attribute_group *chp_attr_groups[] = {
  336. &chp_attr_group,
  337. NULL,
  338. };
  339. static void chp_release(struct device *dev)
  340. {
  341. struct channel_path *cp;
  342. cp = to_channelpath(dev);
  343. kfree(cp);
  344. }
  345. /**
  346. * chp_update_desc - update channel-path description
  347. * @chp - channel-path
  348. *
  349. * Update the channel-path description of the specified channel-path
  350. * including channel measurement related information.
  351. * Return zero on success, non-zero otherwise.
  352. */
  353. int chp_update_desc(struct channel_path *chp)
  354. {
  355. int rc;
  356. rc = chsc_determine_base_channel_path_desc(chp->chpid, &chp->desc);
  357. if (rc)
  358. return rc;
  359. /*
  360. * Fetching the following data is optional. Not all machines or
  361. * hypervisors implement the required chsc commands.
  362. */
  363. chsc_determine_fmt1_channel_path_desc(chp->chpid, &chp->desc_fmt1);
  364. chsc_get_channel_measurement_chars(chp);
  365. return 0;
  366. }
  367. /**
  368. * chp_new - register a new channel-path
  369. * @chpid - channel-path ID
  370. *
  371. * Create and register data structure representing new channel-path. Return
  372. * zero on success, non-zero otherwise.
  373. */
  374. int chp_new(struct chp_id chpid)
  375. {
  376. struct channel_path *chp;
  377. int ret;
  378. if (chp_is_registered(chpid))
  379. return 0;
  380. chp = kzalloc(sizeof(struct channel_path), GFP_KERNEL);
  381. if (!chp)
  382. return -ENOMEM;
  383. /* fill in status, etc. */
  384. chp->chpid = chpid;
  385. chp->state = 1;
  386. chp->dev.parent = &channel_subsystems[chpid.cssid]->device;
  387. chp->dev.groups = chp_attr_groups;
  388. chp->dev.release = chp_release;
  389. mutex_init(&chp->lock);
  390. /* Obtain channel path description and fill it in. */
  391. ret = chp_update_desc(chp);
  392. if (ret)
  393. goto out_free;
  394. if ((chp->desc.flags & 0x80) == 0) {
  395. ret = -ENODEV;
  396. goto out_free;
  397. }
  398. dev_set_name(&chp->dev, "chp%x.%02x", chpid.cssid, chpid.id);
  399. /* make it known to the system */
  400. ret = device_register(&chp->dev);
  401. if (ret) {
  402. CIO_MSG_EVENT(0, "Could not register chp%x.%02x: %d\n",
  403. chpid.cssid, chpid.id, ret);
  404. put_device(&chp->dev);
  405. goto out;
  406. }
  407. mutex_lock(&channel_subsystems[chpid.cssid]->mutex);
  408. if (channel_subsystems[chpid.cssid]->cm_enabled) {
  409. ret = chp_add_cmg_attr(chp);
  410. if (ret) {
  411. device_unregister(&chp->dev);
  412. mutex_unlock(&channel_subsystems[chpid.cssid]->mutex);
  413. goto out;
  414. }
  415. }
  416. channel_subsystems[chpid.cssid]->chps[chpid.id] = chp;
  417. mutex_unlock(&channel_subsystems[chpid.cssid]->mutex);
  418. goto out;
  419. out_free:
  420. kfree(chp);
  421. out:
  422. return ret;
  423. }
  424. /**
  425. * chp_get_chp_desc - return newly allocated channel-path description
  426. * @chpid: channel-path ID
  427. *
  428. * On success return a newly allocated copy of the channel-path description
  429. * data associated with the given channel-path ID. Return %NULL on error.
  430. */
  431. struct channel_path_desc *chp_get_chp_desc(struct chp_id chpid)
  432. {
  433. struct channel_path *chp;
  434. struct channel_path_desc *desc;
  435. chp = chpid_to_chp(chpid);
  436. if (!chp)
  437. return NULL;
  438. desc = kmalloc(sizeof(struct channel_path_desc), GFP_KERNEL);
  439. if (!desc)
  440. return NULL;
  441. mutex_lock(&chp->lock);
  442. memcpy(desc, &chp->desc, sizeof(struct channel_path_desc));
  443. mutex_unlock(&chp->lock);
  444. return desc;
  445. }
  446. /**
  447. * chp_process_crw - process channel-path status change
  448. * @crw0: channel report-word to handler
  449. * @crw1: second channel-report word (always NULL)
  450. * @overflow: crw overflow indication
  451. *
  452. * Handle channel-report-words indicating that the status of a channel-path
  453. * has changed.
  454. */
  455. static void chp_process_crw(struct crw *crw0, struct crw *crw1,
  456. int overflow)
  457. {
  458. struct chp_id chpid;
  459. if (overflow) {
  460. css_schedule_eval_all();
  461. return;
  462. }
  463. CIO_CRW_EVENT(2, "CRW reports slct=%d, oflw=%d, "
  464. "chn=%d, rsc=%X, anc=%d, erc=%X, rsid=%X\n",
  465. crw0->slct, crw0->oflw, crw0->chn, crw0->rsc, crw0->anc,
  466. crw0->erc, crw0->rsid);
  467. /*
  468. * Check for solicited machine checks. These are
  469. * created by reset channel path and need not be
  470. * handled here.
  471. */
  472. if (crw0->slct) {
  473. CIO_CRW_EVENT(2, "solicited machine check for "
  474. "channel path %02X\n", crw0->rsid);
  475. return;
  476. }
  477. chp_id_init(&chpid);
  478. chpid.id = crw0->rsid;
  479. switch (crw0->erc) {
  480. case CRW_ERC_IPARM: /* Path has come. */
  481. if (!chp_is_registered(chpid))
  482. chp_new(chpid);
  483. chsc_chp_online(chpid);
  484. break;
  485. case CRW_ERC_PERRI: /* Path has gone. */
  486. case CRW_ERC_PERRN:
  487. chsc_chp_offline(chpid);
  488. break;
  489. default:
  490. CIO_CRW_EVENT(2, "Don't know how to handle erc=%x\n",
  491. crw0->erc);
  492. }
  493. }
  494. int chp_ssd_get_mask(struct chsc_ssd_info *ssd, struct chp_link *link)
  495. {
  496. int i;
  497. int mask;
  498. for (i = 0; i < 8; i++) {
  499. mask = 0x80 >> i;
  500. if (!(ssd->path_mask & mask))
  501. continue;
  502. if (!chp_id_is_equal(&ssd->chpid[i], &link->chpid))
  503. continue;
  504. if ((ssd->fla_valid_mask & mask) &&
  505. ((ssd->fla[i] & link->fla_mask) != link->fla))
  506. continue;
  507. return mask;
  508. }
  509. return 0;
  510. }
  511. EXPORT_SYMBOL_GPL(chp_ssd_get_mask);
  512. static inline int info_bit_num(struct chp_id id)
  513. {
  514. return id.id + id.cssid * (__MAX_CHPID + 1);
  515. }
  516. /* Force chp_info refresh on next call to info_validate(). */
  517. static void info_expire(void)
  518. {
  519. mutex_lock(&info_lock);
  520. chp_info_expires = jiffies - 1;
  521. mutex_unlock(&info_lock);
  522. }
  523. /* Ensure that chp_info is up-to-date. */
  524. static int info_update(void)
  525. {
  526. int rc;
  527. mutex_lock(&info_lock);
  528. rc = 0;
  529. if (time_after(jiffies, chp_info_expires)) {
  530. /* Data is too old, update. */
  531. rc = sclp_chp_read_info(&chp_info);
  532. chp_info_expires = jiffies + CHP_INFO_UPDATE_INTERVAL ;
  533. }
  534. mutex_unlock(&info_lock);
  535. return rc;
  536. }
  537. /**
  538. * chp_info_get_status - retrieve configure status of a channel-path
  539. * @chpid: channel-path ID
  540. *
  541. * On success, return 0 for standby, 1 for configured, 2 for reserved,
  542. * 3 for not recognized. Return negative error code on error.
  543. */
  544. int chp_info_get_status(struct chp_id chpid)
  545. {
  546. int rc;
  547. int bit;
  548. rc = info_update();
  549. if (rc)
  550. return rc;
  551. bit = info_bit_num(chpid);
  552. mutex_lock(&info_lock);
  553. if (!chp_test_bit(chp_info.recognized, bit))
  554. rc = CHP_STATUS_NOT_RECOGNIZED;
  555. else if (chp_test_bit(chp_info.configured, bit))
  556. rc = CHP_STATUS_CONFIGURED;
  557. else if (chp_test_bit(chp_info.standby, bit))
  558. rc = CHP_STATUS_STANDBY;
  559. else
  560. rc = CHP_STATUS_RESERVED;
  561. mutex_unlock(&info_lock);
  562. return rc;
  563. }
  564. /* Return configure task for chpid. */
  565. static enum cfg_task_t cfg_get_task(struct chp_id chpid)
  566. {
  567. return chp_cfg_task[chpid.cssid][chpid.id];
  568. }
  569. /* Set configure task for chpid. */
  570. static void cfg_set_task(struct chp_id chpid, enum cfg_task_t cfg)
  571. {
  572. chp_cfg_task[chpid.cssid][chpid.id] = cfg;
  573. }
  574. /* Fetch the first configure task. Set chpid accordingly. */
  575. static enum cfg_task_t chp_cfg_fetch_task(struct chp_id *chpid)
  576. {
  577. enum cfg_task_t t = cfg_none;
  578. chp_id_for_each(chpid) {
  579. t = cfg_get_task(*chpid);
  580. if (t != cfg_none)
  581. break;
  582. }
  583. return t;
  584. }
  585. /* Perform one configure/deconfigure request. Reschedule work function until
  586. * last request. */
  587. static void cfg_func(struct work_struct *work)
  588. {
  589. struct chp_id chpid;
  590. enum cfg_task_t t;
  591. int rc;
  592. spin_lock(&cfg_lock);
  593. t = chp_cfg_fetch_task(&chpid);
  594. spin_unlock(&cfg_lock);
  595. switch (t) {
  596. case cfg_configure:
  597. rc = sclp_chp_configure(chpid);
  598. if (rc)
  599. CIO_MSG_EVENT(2, "chp: sclp_chp_configure(%x.%02x)="
  600. "%d\n", chpid.cssid, chpid.id, rc);
  601. else {
  602. info_expire();
  603. chsc_chp_online(chpid);
  604. }
  605. break;
  606. case cfg_deconfigure:
  607. rc = sclp_chp_deconfigure(chpid);
  608. if (rc)
  609. CIO_MSG_EVENT(2, "chp: sclp_chp_deconfigure(%x.%02x)="
  610. "%d\n", chpid.cssid, chpid.id, rc);
  611. else {
  612. info_expire();
  613. chsc_chp_offline(chpid);
  614. }
  615. break;
  616. case cfg_none:
  617. /* Get updated information after last change. */
  618. info_update();
  619. wake_up_interruptible(&cfg_wait_queue);
  620. return;
  621. }
  622. spin_lock(&cfg_lock);
  623. if (t == cfg_get_task(chpid))
  624. cfg_set_task(chpid, cfg_none);
  625. spin_unlock(&cfg_lock);
  626. schedule_work(&cfg_work);
  627. }
  628. /**
  629. * chp_cfg_schedule - schedule chpid configuration request
  630. * @chpid - channel-path ID
  631. * @configure - Non-zero for configure, zero for deconfigure
  632. *
  633. * Schedule a channel-path configuration/deconfiguration request.
  634. */
  635. void chp_cfg_schedule(struct chp_id chpid, int configure)
  636. {
  637. CIO_MSG_EVENT(2, "chp_cfg_sched%x.%02x=%d\n", chpid.cssid, chpid.id,
  638. configure);
  639. spin_lock(&cfg_lock);
  640. cfg_set_task(chpid, configure ? cfg_configure : cfg_deconfigure);
  641. spin_unlock(&cfg_lock);
  642. schedule_work(&cfg_work);
  643. }
  644. /**
  645. * chp_cfg_cancel_deconfigure - cancel chpid deconfiguration request
  646. * @chpid - channel-path ID
  647. *
  648. * Cancel an active channel-path deconfiguration request if it has not yet
  649. * been performed.
  650. */
  651. void chp_cfg_cancel_deconfigure(struct chp_id chpid)
  652. {
  653. CIO_MSG_EVENT(2, "chp_cfg_cancel:%x.%02x\n", chpid.cssid, chpid.id);
  654. spin_lock(&cfg_lock);
  655. if (cfg_get_task(chpid) == cfg_deconfigure)
  656. cfg_set_task(chpid, cfg_none);
  657. spin_unlock(&cfg_lock);
  658. }
  659. static bool cfg_idle(void)
  660. {
  661. struct chp_id chpid;
  662. enum cfg_task_t t;
  663. spin_lock(&cfg_lock);
  664. t = chp_cfg_fetch_task(&chpid);
  665. spin_unlock(&cfg_lock);
  666. return t == cfg_none;
  667. }
  668. static int cfg_wait_idle(void)
  669. {
  670. if (wait_event_interruptible(cfg_wait_queue, cfg_idle()))
  671. return -ERESTARTSYS;
  672. return 0;
  673. }
  674. static int __init chp_init(void)
  675. {
  676. struct chp_id chpid;
  677. int state, ret;
  678. ret = crw_register_handler(CRW_RSC_CPATH, chp_process_crw);
  679. if (ret)
  680. return ret;
  681. INIT_WORK(&cfg_work, cfg_func);
  682. init_waitqueue_head(&cfg_wait_queue);
  683. if (info_update())
  684. return 0;
  685. /* Register available channel-paths. */
  686. chp_id_for_each(&chpid) {
  687. state = chp_info_get_status(chpid);
  688. if (state == CHP_STATUS_CONFIGURED ||
  689. state == CHP_STATUS_STANDBY)
  690. chp_new(chpid);
  691. }
  692. return 0;
  693. }
  694. subsys_initcall(chp_init);