chp.c 17 KB

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