chp.c 17 KB

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