chp.c 17 KB

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