chp.c 17 KB

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