chp.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738
  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 const struct attribute_group *chp_attr_groups[] = {
  311. &chp_attr_group,
  312. NULL,
  313. };
  314. static void chp_release(struct device *dev)
  315. {
  316. struct channel_path *cp;
  317. cp = to_channelpath(dev);
  318. kfree(cp);
  319. }
  320. /**
  321. * chp_new - register a new channel-path
  322. * @chpid - channel-path ID
  323. *
  324. * Create and register data structure representing new channel-path. Return
  325. * zero on success, non-zero otherwise.
  326. */
  327. int chp_new(struct chp_id chpid)
  328. {
  329. struct channel_path *chp;
  330. int ret;
  331. if (chp_is_registered(chpid))
  332. return 0;
  333. chp = kzalloc(sizeof(struct channel_path), GFP_KERNEL);
  334. if (!chp)
  335. return -ENOMEM;
  336. /* fill in status, etc. */
  337. chp->chpid = chpid;
  338. chp->state = 1;
  339. chp->dev.parent = &channel_subsystems[chpid.cssid]->device;
  340. chp->dev.groups = chp_attr_groups;
  341. chp->dev.release = chp_release;
  342. mutex_init(&chp->lock);
  343. /* Obtain channel path description and fill it in. */
  344. ret = chsc_determine_base_channel_path_desc(chpid, &chp->desc);
  345. if (ret)
  346. goto out_free;
  347. if ((chp->desc.flags & 0x80) == 0) {
  348. ret = -ENODEV;
  349. goto out_free;
  350. }
  351. /* Get channel-measurement characteristics. */
  352. if (css_chsc_characteristics.scmc && css_chsc_characteristics.secm) {
  353. ret = chsc_get_channel_measurement_chars(chp);
  354. if (ret)
  355. goto out_free;
  356. } else {
  357. chp->cmg = -1;
  358. }
  359. dev_set_name(&chp->dev, "chp%x.%02x", chpid.cssid, chpid.id);
  360. /* make it known to the system */
  361. ret = device_register(&chp->dev);
  362. if (ret) {
  363. CIO_MSG_EVENT(0, "Could not register chp%x.%02x: %d\n",
  364. chpid.cssid, chpid.id, ret);
  365. put_device(&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. device_unregister(&chp->dev);
  373. mutex_unlock(&channel_subsystems[chpid.cssid]->mutex);
  374. goto out;
  375. }
  376. }
  377. channel_subsystems[chpid.cssid]->chps[chpid.id] = chp;
  378. mutex_unlock(&channel_subsystems[chpid.cssid]->mutex);
  379. goto out;
  380. out_free:
  381. kfree(chp);
  382. out:
  383. return ret;
  384. }
  385. /**
  386. * chp_get_chp_desc - return newly allocated channel-path description
  387. * @chpid: channel-path ID
  388. *
  389. * On success return a newly allocated copy of the channel-path description
  390. * data associated with the given channel-path ID. Return %NULL on error.
  391. */
  392. void *chp_get_chp_desc(struct chp_id chpid)
  393. {
  394. struct channel_path *chp;
  395. struct channel_path_desc *desc;
  396. chp = chpid_to_chp(chpid);
  397. if (!chp)
  398. return NULL;
  399. desc = kmalloc(sizeof(struct channel_path_desc), GFP_KERNEL);
  400. if (!desc)
  401. return NULL;
  402. mutex_lock(&chp->lock);
  403. memcpy(desc, &chp->desc, sizeof(struct channel_path_desc));
  404. mutex_unlock(&chp->lock);
  405. return desc;
  406. }
  407. /**
  408. * chp_process_crw - process channel-path status change
  409. * @crw0: channel report-word to handler
  410. * @crw1: second channel-report word (always NULL)
  411. * @overflow: crw overflow indication
  412. *
  413. * Handle channel-report-words indicating that the status of a channel-path
  414. * has changed.
  415. */
  416. static void chp_process_crw(struct crw *crw0, struct crw *crw1,
  417. int overflow)
  418. {
  419. struct chp_id chpid;
  420. if (overflow) {
  421. css_schedule_eval_all();
  422. return;
  423. }
  424. CIO_CRW_EVENT(2, "CRW reports slct=%d, oflw=%d, "
  425. "chn=%d, rsc=%X, anc=%d, erc=%X, rsid=%X\n",
  426. crw0->slct, crw0->oflw, crw0->chn, crw0->rsc, crw0->anc,
  427. crw0->erc, crw0->rsid);
  428. /*
  429. * Check for solicited machine checks. These are
  430. * created by reset channel path and need not be
  431. * handled here.
  432. */
  433. if (crw0->slct) {
  434. CIO_CRW_EVENT(2, "solicited machine check for "
  435. "channel path %02X\n", crw0->rsid);
  436. return;
  437. }
  438. chp_id_init(&chpid);
  439. chpid.id = crw0->rsid;
  440. switch (crw0->erc) {
  441. case CRW_ERC_IPARM: /* Path has come. */
  442. if (!chp_is_registered(chpid))
  443. chp_new(chpid);
  444. chsc_chp_online(chpid);
  445. break;
  446. case CRW_ERC_PERRI: /* Path has gone. */
  447. case CRW_ERC_PERRN:
  448. chsc_chp_offline(chpid);
  449. break;
  450. default:
  451. CIO_CRW_EVENT(2, "Don't know how to handle erc=%x\n",
  452. crw0->erc);
  453. }
  454. }
  455. int chp_ssd_get_mask(struct chsc_ssd_info *ssd, struct chp_link *link)
  456. {
  457. int i;
  458. int mask;
  459. for (i = 0; i < 8; i++) {
  460. mask = 0x80 >> i;
  461. if (!(ssd->path_mask & mask))
  462. continue;
  463. if (!chp_id_is_equal(&ssd->chpid[i], &link->chpid))
  464. continue;
  465. if ((ssd->fla_valid_mask & mask) &&
  466. ((ssd->fla[i] & link->fla_mask) != link->fla))
  467. continue;
  468. return mask;
  469. }
  470. return 0;
  471. }
  472. EXPORT_SYMBOL_GPL(chp_ssd_get_mask);
  473. static inline int info_bit_num(struct chp_id id)
  474. {
  475. return id.id + id.cssid * (__MAX_CHPID + 1);
  476. }
  477. /* Force chp_info refresh on next call to info_validate(). */
  478. static void info_expire(void)
  479. {
  480. mutex_lock(&info_lock);
  481. chp_info_expires = jiffies - 1;
  482. mutex_unlock(&info_lock);
  483. }
  484. /* Ensure that chp_info is up-to-date. */
  485. static int info_update(void)
  486. {
  487. int rc;
  488. mutex_lock(&info_lock);
  489. rc = 0;
  490. if (time_after(jiffies, chp_info_expires)) {
  491. /* Data is too old, update. */
  492. rc = sclp_chp_read_info(&chp_info);
  493. chp_info_expires = jiffies + CHP_INFO_UPDATE_INTERVAL ;
  494. }
  495. mutex_unlock(&info_lock);
  496. return rc;
  497. }
  498. /**
  499. * chp_info_get_status - retrieve configure status of a channel-path
  500. * @chpid: channel-path ID
  501. *
  502. * On success, return 0 for standby, 1 for configured, 2 for reserved,
  503. * 3 for not recognized. Return negative error code on error.
  504. */
  505. int chp_info_get_status(struct chp_id chpid)
  506. {
  507. int rc;
  508. int bit;
  509. rc = info_update();
  510. if (rc)
  511. return rc;
  512. bit = info_bit_num(chpid);
  513. mutex_lock(&info_lock);
  514. if (!chp_test_bit(chp_info.recognized, bit))
  515. rc = CHP_STATUS_NOT_RECOGNIZED;
  516. else if (chp_test_bit(chp_info.configured, bit))
  517. rc = CHP_STATUS_CONFIGURED;
  518. else if (chp_test_bit(chp_info.standby, bit))
  519. rc = CHP_STATUS_STANDBY;
  520. else
  521. rc = CHP_STATUS_RESERVED;
  522. mutex_unlock(&info_lock);
  523. return rc;
  524. }
  525. /* Return configure task for chpid. */
  526. static enum cfg_task_t cfg_get_task(struct chp_id chpid)
  527. {
  528. return chp_cfg_task[chpid.cssid][chpid.id];
  529. }
  530. /* Set configure task for chpid. */
  531. static void cfg_set_task(struct chp_id chpid, enum cfg_task_t cfg)
  532. {
  533. chp_cfg_task[chpid.cssid][chpid.id] = cfg;
  534. }
  535. /* Perform one configure/deconfigure request. Reschedule work function until
  536. * last request. */
  537. static void cfg_func(struct work_struct *work)
  538. {
  539. struct chp_id chpid;
  540. enum cfg_task_t t;
  541. int rc;
  542. mutex_lock(&cfg_lock);
  543. t = cfg_none;
  544. chp_id_for_each(&chpid) {
  545. t = cfg_get_task(chpid);
  546. if (t != cfg_none) {
  547. cfg_set_task(chpid, cfg_none);
  548. break;
  549. }
  550. }
  551. mutex_unlock(&cfg_lock);
  552. switch (t) {
  553. case cfg_configure:
  554. rc = sclp_chp_configure(chpid);
  555. if (rc)
  556. CIO_MSG_EVENT(2, "chp: sclp_chp_configure(%x.%02x)="
  557. "%d\n", chpid.cssid, chpid.id, rc);
  558. else {
  559. info_expire();
  560. chsc_chp_online(chpid);
  561. }
  562. break;
  563. case cfg_deconfigure:
  564. rc = sclp_chp_deconfigure(chpid);
  565. if (rc)
  566. CIO_MSG_EVENT(2, "chp: sclp_chp_deconfigure(%x.%02x)="
  567. "%d\n", chpid.cssid, chpid.id, rc);
  568. else {
  569. info_expire();
  570. chsc_chp_offline(chpid);
  571. }
  572. break;
  573. case cfg_none:
  574. /* Get updated information after last change. */
  575. info_update();
  576. mutex_lock(&cfg_lock);
  577. cfg_busy = 0;
  578. mutex_unlock(&cfg_lock);
  579. wake_up_interruptible(&cfg_wait_queue);
  580. return;
  581. }
  582. queue_work(chp_wq, &cfg_work);
  583. }
  584. /**
  585. * chp_cfg_schedule - schedule chpid configuration request
  586. * @chpid - channel-path ID
  587. * @configure - Non-zero for configure, zero for deconfigure
  588. *
  589. * Schedule a channel-path configuration/deconfiguration request.
  590. */
  591. void chp_cfg_schedule(struct chp_id chpid, int configure)
  592. {
  593. CIO_MSG_EVENT(2, "chp_cfg_sched%x.%02x=%d\n", chpid.cssid, chpid.id,
  594. configure);
  595. mutex_lock(&cfg_lock);
  596. cfg_set_task(chpid, configure ? cfg_configure : cfg_deconfigure);
  597. cfg_busy = 1;
  598. mutex_unlock(&cfg_lock);
  599. queue_work(chp_wq, &cfg_work);
  600. }
  601. /**
  602. * chp_cfg_cancel_deconfigure - cancel chpid deconfiguration request
  603. * @chpid - channel-path ID
  604. *
  605. * Cancel an active channel-path deconfiguration request if it has not yet
  606. * been performed.
  607. */
  608. void chp_cfg_cancel_deconfigure(struct chp_id chpid)
  609. {
  610. CIO_MSG_EVENT(2, "chp_cfg_cancel:%x.%02x\n", chpid.cssid, chpid.id);
  611. mutex_lock(&cfg_lock);
  612. if (cfg_get_task(chpid) == cfg_deconfigure)
  613. cfg_set_task(chpid, cfg_none);
  614. mutex_unlock(&cfg_lock);
  615. }
  616. static int cfg_wait_idle(void)
  617. {
  618. if (wait_event_interruptible(cfg_wait_queue, !cfg_busy))
  619. return -ERESTARTSYS;
  620. return 0;
  621. }
  622. static int __init chp_init(void)
  623. {
  624. struct chp_id chpid;
  625. int ret;
  626. ret = crw_register_handler(CRW_RSC_CPATH, chp_process_crw);
  627. if (ret)
  628. return ret;
  629. chp_wq = create_singlethread_workqueue("cio_chp");
  630. if (!chp_wq) {
  631. crw_unregister_handler(CRW_RSC_CPATH);
  632. return -ENOMEM;
  633. }
  634. INIT_WORK(&cfg_work, cfg_func);
  635. init_waitqueue_head(&cfg_wait_queue);
  636. if (info_update())
  637. return 0;
  638. /* Register available channel-paths. */
  639. chp_id_for_each(&chpid) {
  640. if (chp_info_get_status(chpid) != CHP_STATUS_NOT_RECOGNIZED)
  641. chp_new(chpid);
  642. }
  643. return 0;
  644. }
  645. subsys_initcall(chp_init);