chp.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740
  1. /*
  2. * drivers/s390/cio/chp.c
  3. *
  4. * Copyright IBM Corp. 1999,2007
  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 <asm/chpid.h>
  18. #include <asm/sclp.h>
  19. #include "../s390mach.h"
  20. #include "cio.h"
  21. #include "css.h"
  22. #include "ioasm.h"
  23. #include "cio_debug.h"
  24. #include "chp.h"
  25. #define to_channelpath(device) container_of(device, struct channel_path, dev)
  26. #define CHP_INFO_UPDATE_INTERVAL 1*HZ
  27. enum cfg_task_t {
  28. cfg_none,
  29. cfg_configure,
  30. cfg_deconfigure
  31. };
  32. /* Map for pending configure tasks. */
  33. static enum cfg_task_t chp_cfg_task[__MAX_CSSID + 1][__MAX_CHPID + 1];
  34. static DEFINE_MUTEX(cfg_lock);
  35. static int cfg_busy;
  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. /* Workqueue to perform pending configure tasks. */
  42. static struct workqueue_struct *chp_wq;
  43. static struct work_struct cfg_work;
  44. /* Wait queue for configure completion events. */
  45. static wait_queue_head_t cfg_wait_queue;
  46. /* Return channel_path struct for given chpid. */
  47. static inline struct channel_path *chpid_to_chp(struct chp_id chpid)
  48. {
  49. return channel_subsystems[chpid.cssid]->chps[chpid.id];
  50. }
  51. /* Set vary state for given chpid. */
  52. static void set_chp_logically_online(struct chp_id chpid, int onoff)
  53. {
  54. chpid_to_chp(chpid)->state = onoff;
  55. }
  56. /* On succes return 0 if channel-path is varied offline, 1 if it is varied
  57. * online. Return -ENODEV if channel-path is not registered. */
  58. int chp_get_status(struct chp_id chpid)
  59. {
  60. return (chpid_to_chp(chpid) ? chpid_to_chp(chpid)->state : -ENODEV);
  61. }
  62. /**
  63. * chp_get_sch_opm - return opm for subchannel
  64. * @sch: subchannel
  65. *
  66. * Calculate and return the operational path mask (opm) based on the chpids
  67. * used by the subchannel and the status of the associated channel-paths.
  68. */
  69. u8 chp_get_sch_opm(struct subchannel *sch)
  70. {
  71. struct chp_id chpid;
  72. int opm;
  73. int i;
  74. opm = 0;
  75. chp_id_init(&chpid);
  76. for (i = 0; i < 8; i++) {
  77. opm <<= 1;
  78. chpid.id = sch->schib.pmcw.chpid[i];
  79. if (chp_get_status(chpid) != 0)
  80. opm |= 1;
  81. }
  82. return opm;
  83. }
  84. EXPORT_SYMBOL_GPL(chp_get_sch_opm);
  85. /**
  86. * chp_is_registered - check if a channel-path is registered
  87. * @chpid: channel-path ID
  88. *
  89. * Return non-zero if a channel-path with the given chpid is registered,
  90. * zero otherwise.
  91. */
  92. int chp_is_registered(struct chp_id chpid)
  93. {
  94. return chpid_to_chp(chpid) != NULL;
  95. }
  96. /*
  97. * Function: s390_vary_chpid
  98. * Varies the specified chpid online or offline
  99. */
  100. static int s390_vary_chpid(struct chp_id chpid, int on)
  101. {
  102. char dbf_text[15];
  103. int status;
  104. sprintf(dbf_text, on?"varyon%x.%02x":"varyoff%x.%02x", chpid.cssid,
  105. chpid.id);
  106. CIO_TRACE_EVENT(2, dbf_text);
  107. status = chp_get_status(chpid);
  108. if (!on && !status) {
  109. printk(KERN_ERR "cio: chpid %x.%02x is already offline\n",
  110. chpid.cssid, chpid.id);
  111. return -EINVAL;
  112. }
  113. set_chp_logically_online(chpid, on);
  114. chsc_chp_vary(chpid, on);
  115. return 0;
  116. }
  117. /*
  118. * Channel measurement related functions
  119. */
  120. static ssize_t chp_measurement_chars_read(struct kobject *kobj,
  121. struct bin_attribute *bin_attr,
  122. char *buf, loff_t off, size_t count)
  123. {
  124. struct channel_path *chp;
  125. struct device *device;
  126. unsigned int size;
  127. device = container_of(kobj, struct device, kobj);
  128. chp = to_channelpath(device);
  129. if (!chp->cmg_chars)
  130. return 0;
  131. size = sizeof(struct cmg_chars);
  132. if (off > size)
  133. return 0;
  134. if (off + count > size)
  135. count = size - off;
  136. memcpy(buf, chp->cmg_chars + off, count);
  137. return count;
  138. }
  139. static struct bin_attribute chp_measurement_chars_attr = {
  140. .attr = {
  141. .name = "measurement_chars",
  142. .mode = S_IRUSR,
  143. },
  144. .size = sizeof(struct cmg_chars),
  145. .read = chp_measurement_chars_read,
  146. };
  147. static void chp_measurement_copy_block(struct cmg_entry *buf,
  148. struct channel_subsystem *css,
  149. struct chp_id chpid)
  150. {
  151. void *area;
  152. struct cmg_entry *entry, reference_buf;
  153. int idx;
  154. if (chpid.id < 128) {
  155. area = css->cub_addr1;
  156. idx = chpid.id;
  157. } else {
  158. area = css->cub_addr2;
  159. idx = chpid.id - 128;
  160. }
  161. entry = area + (idx * sizeof(struct cmg_entry));
  162. do {
  163. memcpy(buf, entry, sizeof(*entry));
  164. memcpy(&reference_buf, entry, sizeof(*entry));
  165. } while (reference_buf.values[0] != buf->values[0]);
  166. }
  167. static ssize_t chp_measurement_read(struct kobject *kobj,
  168. struct bin_attribute *bin_attr,
  169. char *buf, loff_t off, size_t count)
  170. {
  171. struct channel_path *chp;
  172. struct channel_subsystem *css;
  173. struct device *device;
  174. unsigned int size;
  175. device = container_of(kobj, struct device, kobj);
  176. chp = to_channelpath(device);
  177. css = to_css(chp->dev.parent);
  178. size = sizeof(struct cmg_entry);
  179. /* Only allow single reads. */
  180. if (off || count < size)
  181. return 0;
  182. chp_measurement_copy_block((struct cmg_entry *)buf, css, chp->chpid);
  183. count = size;
  184. return count;
  185. }
  186. static struct bin_attribute chp_measurement_attr = {
  187. .attr = {
  188. .name = "measurement",
  189. .mode = S_IRUSR,
  190. },
  191. .size = sizeof(struct cmg_entry),
  192. .read = chp_measurement_read,
  193. };
  194. void chp_remove_cmg_attr(struct channel_path *chp)
  195. {
  196. device_remove_bin_file(&chp->dev, &chp_measurement_chars_attr);
  197. device_remove_bin_file(&chp->dev, &chp_measurement_attr);
  198. }
  199. int chp_add_cmg_attr(struct channel_path *chp)
  200. {
  201. int ret;
  202. ret = device_create_bin_file(&chp->dev, &chp_measurement_chars_attr);
  203. if (ret)
  204. return ret;
  205. ret = device_create_bin_file(&chp->dev, &chp_measurement_attr);
  206. if (ret)
  207. device_remove_bin_file(&chp->dev, &chp_measurement_chars_attr);
  208. return ret;
  209. }
  210. /*
  211. * Files for the channel path entries.
  212. */
  213. static ssize_t chp_status_show(struct device *dev,
  214. struct device_attribute *attr, char *buf)
  215. {
  216. struct channel_path *chp = to_channelpath(dev);
  217. if (!chp)
  218. return 0;
  219. return (chp_get_status(chp->chpid) ? sprintf(buf, "online\n") :
  220. sprintf(buf, "offline\n"));
  221. }
  222. static ssize_t chp_status_write(struct device *dev,
  223. struct device_attribute *attr,
  224. const char *buf, size_t count)
  225. {
  226. struct channel_path *cp = to_channelpath(dev);
  227. char cmd[10];
  228. int num_args;
  229. int error;
  230. num_args = sscanf(buf, "%5s", cmd);
  231. if (!num_args)
  232. return count;
  233. if (!strnicmp(cmd, "on", 2) || !strcmp(cmd, "1"))
  234. error = s390_vary_chpid(cp->chpid, 1);
  235. else if (!strnicmp(cmd, "off", 3) || !strcmp(cmd, "0"))
  236. error = s390_vary_chpid(cp->chpid, 0);
  237. else
  238. error = -EINVAL;
  239. return error < 0 ? error : count;
  240. }
  241. static DEVICE_ATTR(status, 0644, chp_status_show, chp_status_write);
  242. static ssize_t chp_configure_show(struct device *dev,
  243. struct device_attribute *attr, char *buf)
  244. {
  245. struct channel_path *cp;
  246. int status;
  247. cp = to_channelpath(dev);
  248. status = chp_info_get_status(cp->chpid);
  249. if (status < 0)
  250. return status;
  251. return snprintf(buf, PAGE_SIZE, "%d\n", status);
  252. }
  253. static int cfg_wait_idle(void);
  254. static ssize_t chp_configure_write(struct device *dev,
  255. struct device_attribute *attr,
  256. const char *buf, size_t count)
  257. {
  258. struct channel_path *cp;
  259. int val;
  260. char delim;
  261. if (sscanf(buf, "%d %c", &val, &delim) != 1)
  262. return -EINVAL;
  263. if (val != 0 && val != 1)
  264. return -EINVAL;
  265. cp = to_channelpath(dev);
  266. chp_cfg_schedule(cp->chpid, val);
  267. cfg_wait_idle();
  268. return count;
  269. }
  270. static DEVICE_ATTR(configure, 0644, chp_configure_show, chp_configure_write);
  271. static ssize_t chp_type_show(struct device *dev, struct device_attribute *attr,
  272. char *buf)
  273. {
  274. struct channel_path *chp = to_channelpath(dev);
  275. if (!chp)
  276. return 0;
  277. return sprintf(buf, "%x\n", chp->desc.desc);
  278. }
  279. static DEVICE_ATTR(type, 0444, chp_type_show, NULL);
  280. static ssize_t chp_cmg_show(struct device *dev, struct device_attribute *attr,
  281. char *buf)
  282. {
  283. struct channel_path *chp = to_channelpath(dev);
  284. if (!chp)
  285. return 0;
  286. if (chp->cmg == -1) /* channel measurements not available */
  287. return sprintf(buf, "unknown\n");
  288. return sprintf(buf, "%x\n", chp->cmg);
  289. }
  290. static DEVICE_ATTR(cmg, 0444, chp_cmg_show, NULL);
  291. static ssize_t chp_shared_show(struct device *dev,
  292. struct device_attribute *attr, char *buf)
  293. {
  294. struct channel_path *chp = to_channelpath(dev);
  295. if (!chp)
  296. return 0;
  297. if (chp->shared == -1) /* channel measurements not available */
  298. return sprintf(buf, "unknown\n");
  299. return sprintf(buf, "%x\n", chp->shared);
  300. }
  301. static DEVICE_ATTR(shared, 0444, chp_shared_show, NULL);
  302. static struct attribute *chp_attrs[] = {
  303. &dev_attr_status.attr,
  304. &dev_attr_configure.attr,
  305. &dev_attr_type.attr,
  306. &dev_attr_cmg.attr,
  307. &dev_attr_shared.attr,
  308. NULL,
  309. };
  310. static struct attribute_group chp_attr_group = {
  311. .attrs = chp_attrs,
  312. };
  313. static void chp_release(struct device *dev)
  314. {
  315. struct channel_path *cp;
  316. cp = to_channelpath(dev);
  317. kfree(cp);
  318. }
  319. /**
  320. * chp_new - register a new channel-path
  321. * @chpid - channel-path ID
  322. *
  323. * Create and register data structure representing new channel-path. Return
  324. * zero on success, non-zero otherwise.
  325. */
  326. int chp_new(struct chp_id chpid)
  327. {
  328. struct channel_path *chp;
  329. int ret;
  330. if (chp_is_registered(chpid))
  331. return 0;
  332. chp = kzalloc(sizeof(struct channel_path), GFP_KERNEL);
  333. if (!chp)
  334. return -ENOMEM;
  335. /* fill in status, etc. */
  336. chp->chpid = chpid;
  337. chp->state = 1;
  338. chp->dev.parent = &channel_subsystems[chpid.cssid]->device;
  339. chp->dev.release = chp_release;
  340. snprintf(chp->dev.bus_id, BUS_ID_SIZE, "chp%x.%02x", chpid.cssid,
  341. chpid.id);
  342. /* Obtain channel path description and fill it in. */
  343. ret = chsc_determine_channel_path_description(chpid, &chp->desc);
  344. if (ret)
  345. goto out_free;
  346. if ((chp->desc.flags & 0x80) == 0) {
  347. ret = -ENODEV;
  348. goto out_free;
  349. }
  350. /* Get channel-measurement characteristics. */
  351. if (css_chsc_characteristics.scmc && css_chsc_characteristics.secm) {
  352. ret = chsc_get_channel_measurement_chars(chp);
  353. if (ret)
  354. goto out_free;
  355. } else {
  356. chp->cmg = -1;
  357. }
  358. /* make it known to the system */
  359. ret = device_register(&chp->dev);
  360. if (ret) {
  361. CIO_MSG_EVENT(0, "Could not register chp%x.%02x: %d\n",
  362. chpid.cssid, chpid.id, ret);
  363. goto out_free;
  364. }
  365. ret = sysfs_create_group(&chp->dev.kobj, &chp_attr_group);
  366. if (ret) {
  367. device_unregister(&chp->dev);
  368. goto out_free;
  369. }
  370. mutex_lock(&channel_subsystems[chpid.cssid]->mutex);
  371. if (channel_subsystems[chpid.cssid]->cm_enabled) {
  372. ret = chp_add_cmg_attr(chp);
  373. if (ret) {
  374. sysfs_remove_group(&chp->dev.kobj, &chp_attr_group);
  375. device_unregister(&chp->dev);
  376. mutex_unlock(&channel_subsystems[chpid.cssid]->mutex);
  377. goto out_free;
  378. }
  379. }
  380. channel_subsystems[chpid.cssid]->chps[chpid.id] = chp;
  381. mutex_unlock(&channel_subsystems[chpid.cssid]->mutex);
  382. return ret;
  383. out_free:
  384. kfree(chp);
  385. return ret;
  386. }
  387. /**
  388. * chp_get_chp_desc - return newly allocated channel-path description
  389. * @chpid: channel-path ID
  390. *
  391. * On success return a newly allocated copy of the channel-path description
  392. * data associated with the given channel-path ID. Return %NULL on error.
  393. */
  394. void *chp_get_chp_desc(struct chp_id chpid)
  395. {
  396. struct channel_path *chp;
  397. struct channel_path_desc *desc;
  398. chp = chpid_to_chp(chpid);
  399. if (!chp)
  400. return NULL;
  401. desc = kmalloc(sizeof(struct channel_path_desc), GFP_KERNEL);
  402. if (!desc)
  403. return NULL;
  404. memcpy(desc, &chp->desc, sizeof(struct channel_path_desc));
  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 = s390_register_crw_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. s390_unregister_crw_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);