chp.c 17 KB

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