chp.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731
  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 <asm/crw.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 success 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. /* Obtain channel path description and fill it in. */
  332. ret = chsc_determine_base_channel_path_desc(chpid, &chp->desc);
  333. if (ret)
  334. goto out_free;
  335. if ((chp->desc.flags & 0x80) == 0) {
  336. ret = -ENODEV;
  337. goto out_free;
  338. }
  339. /* Get channel-measurement characteristics. */
  340. if (css_chsc_characteristics.scmc && css_chsc_characteristics.secm) {
  341. ret = chsc_get_channel_measurement_chars(chp);
  342. if (ret)
  343. goto out_free;
  344. } else {
  345. chp->cmg = -1;
  346. }
  347. dev_set_name(&chp->dev, "chp%x.%02x", chpid.cssid, chpid.id);
  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. put_device(&chp->dev);
  354. goto out;
  355. }
  356. ret = sysfs_create_group(&chp->dev.kobj, &chp_attr_group);
  357. if (ret) {
  358. device_unregister(&chp->dev);
  359. goto out;
  360. }
  361. mutex_lock(&channel_subsystems[chpid.cssid]->mutex);
  362. if (channel_subsystems[chpid.cssid]->cm_enabled) {
  363. ret = chp_add_cmg_attr(chp);
  364. if (ret) {
  365. sysfs_remove_group(&chp->dev.kobj, &chp_attr_group);
  366. device_unregister(&chp->dev);
  367. mutex_unlock(&channel_subsystems[chpid.cssid]->mutex);
  368. goto out;
  369. }
  370. }
  371. channel_subsystems[chpid.cssid]->chps[chpid.id] = chp;
  372. mutex_unlock(&channel_subsystems[chpid.cssid]->mutex);
  373. goto out;
  374. out_free:
  375. kfree(chp);
  376. out:
  377. return ret;
  378. }
  379. /**
  380. * chp_get_chp_desc - return newly allocated channel-path description
  381. * @chpid: channel-path ID
  382. *
  383. * On success return a newly allocated copy of the channel-path description
  384. * data associated with the given channel-path ID. Return %NULL on error.
  385. */
  386. void *chp_get_chp_desc(struct chp_id chpid)
  387. {
  388. struct channel_path *chp;
  389. struct channel_path_desc *desc;
  390. chp = chpid_to_chp(chpid);
  391. if (!chp)
  392. return NULL;
  393. desc = kmalloc(sizeof(struct channel_path_desc), GFP_KERNEL);
  394. if (!desc)
  395. return NULL;
  396. memcpy(desc, &chp->desc, sizeof(struct channel_path_desc));
  397. return desc;
  398. }
  399. /**
  400. * chp_process_crw - process channel-path status change
  401. * @crw0: channel report-word to handler
  402. * @crw1: second channel-report word (always NULL)
  403. * @overflow: crw overflow indication
  404. *
  405. * Handle channel-report-words indicating that the status of a channel-path
  406. * has changed.
  407. */
  408. static void chp_process_crw(struct crw *crw0, struct crw *crw1,
  409. int overflow)
  410. {
  411. struct chp_id chpid;
  412. if (overflow) {
  413. css_schedule_eval_all();
  414. return;
  415. }
  416. CIO_CRW_EVENT(2, "CRW reports slct=%d, oflw=%d, "
  417. "chn=%d, rsc=%X, anc=%d, erc=%X, rsid=%X\n",
  418. crw0->slct, crw0->oflw, crw0->chn, crw0->rsc, crw0->anc,
  419. crw0->erc, crw0->rsid);
  420. /*
  421. * Check for solicited machine checks. These are
  422. * created by reset channel path and need not be
  423. * handled here.
  424. */
  425. if (crw0->slct) {
  426. CIO_CRW_EVENT(2, "solicited machine check for "
  427. "channel path %02X\n", crw0->rsid);
  428. return;
  429. }
  430. chp_id_init(&chpid);
  431. chpid.id = crw0->rsid;
  432. switch (crw0->erc) {
  433. case CRW_ERC_IPARM: /* Path has come. */
  434. if (!chp_is_registered(chpid))
  435. chp_new(chpid);
  436. chsc_chp_online(chpid);
  437. break;
  438. case CRW_ERC_PERRI: /* Path has gone. */
  439. case CRW_ERC_PERRN:
  440. chsc_chp_offline(chpid);
  441. break;
  442. default:
  443. CIO_CRW_EVENT(2, "Don't know how to handle erc=%x\n",
  444. crw0->erc);
  445. }
  446. }
  447. int chp_ssd_get_mask(struct chsc_ssd_info *ssd, struct chp_link *link)
  448. {
  449. int i;
  450. int mask;
  451. for (i = 0; i < 8; i++) {
  452. mask = 0x80 >> i;
  453. if (!(ssd->path_mask & mask))
  454. continue;
  455. if (!chp_id_is_equal(&ssd->chpid[i], &link->chpid))
  456. continue;
  457. if ((ssd->fla_valid_mask & mask) &&
  458. ((ssd->fla[i] & link->fla_mask) != link->fla))
  459. continue;
  460. return mask;
  461. }
  462. return 0;
  463. }
  464. EXPORT_SYMBOL_GPL(chp_ssd_get_mask);
  465. static inline int info_bit_num(struct chp_id id)
  466. {
  467. return id.id + id.cssid * (__MAX_CHPID + 1);
  468. }
  469. /* Force chp_info refresh on next call to info_validate(). */
  470. static void info_expire(void)
  471. {
  472. mutex_lock(&info_lock);
  473. chp_info_expires = jiffies - 1;
  474. mutex_unlock(&info_lock);
  475. }
  476. /* Ensure that chp_info is up-to-date. */
  477. static int info_update(void)
  478. {
  479. int rc;
  480. mutex_lock(&info_lock);
  481. rc = 0;
  482. if (time_after(jiffies, chp_info_expires)) {
  483. /* Data is too old, update. */
  484. rc = sclp_chp_read_info(&chp_info);
  485. chp_info_expires = jiffies + CHP_INFO_UPDATE_INTERVAL ;
  486. }
  487. mutex_unlock(&info_lock);
  488. return rc;
  489. }
  490. /**
  491. * chp_info_get_status - retrieve configure status of a channel-path
  492. * @chpid: channel-path ID
  493. *
  494. * On success, return 0 for standby, 1 for configured, 2 for reserved,
  495. * 3 for not recognized. Return negative error code on error.
  496. */
  497. int chp_info_get_status(struct chp_id chpid)
  498. {
  499. int rc;
  500. int bit;
  501. rc = info_update();
  502. if (rc)
  503. return rc;
  504. bit = info_bit_num(chpid);
  505. mutex_lock(&info_lock);
  506. if (!chp_test_bit(chp_info.recognized, bit))
  507. rc = CHP_STATUS_NOT_RECOGNIZED;
  508. else if (chp_test_bit(chp_info.configured, bit))
  509. rc = CHP_STATUS_CONFIGURED;
  510. else if (chp_test_bit(chp_info.standby, bit))
  511. rc = CHP_STATUS_STANDBY;
  512. else
  513. rc = CHP_STATUS_RESERVED;
  514. mutex_unlock(&info_lock);
  515. return rc;
  516. }
  517. /* Return configure task for chpid. */
  518. static enum cfg_task_t cfg_get_task(struct chp_id chpid)
  519. {
  520. return chp_cfg_task[chpid.cssid][chpid.id];
  521. }
  522. /* Set configure task for chpid. */
  523. static void cfg_set_task(struct chp_id chpid, enum cfg_task_t cfg)
  524. {
  525. chp_cfg_task[chpid.cssid][chpid.id] = cfg;
  526. }
  527. /* Perform one configure/deconfigure request. Reschedule work function until
  528. * last request. */
  529. static void cfg_func(struct work_struct *work)
  530. {
  531. struct chp_id chpid;
  532. enum cfg_task_t t;
  533. int rc;
  534. mutex_lock(&cfg_lock);
  535. t = cfg_none;
  536. chp_id_for_each(&chpid) {
  537. t = cfg_get_task(chpid);
  538. if (t != cfg_none) {
  539. cfg_set_task(chpid, cfg_none);
  540. break;
  541. }
  542. }
  543. mutex_unlock(&cfg_lock);
  544. switch (t) {
  545. case cfg_configure:
  546. rc = sclp_chp_configure(chpid);
  547. if (rc)
  548. CIO_MSG_EVENT(2, "chp: sclp_chp_configure(%x.%02x)="
  549. "%d\n", chpid.cssid, chpid.id, rc);
  550. else {
  551. info_expire();
  552. chsc_chp_online(chpid);
  553. }
  554. break;
  555. case cfg_deconfigure:
  556. rc = sclp_chp_deconfigure(chpid);
  557. if (rc)
  558. CIO_MSG_EVENT(2, "chp: sclp_chp_deconfigure(%x.%02x)="
  559. "%d\n", chpid.cssid, chpid.id, rc);
  560. else {
  561. info_expire();
  562. chsc_chp_offline(chpid);
  563. }
  564. break;
  565. case cfg_none:
  566. /* Get updated information after last change. */
  567. info_update();
  568. mutex_lock(&cfg_lock);
  569. cfg_busy = 0;
  570. mutex_unlock(&cfg_lock);
  571. wake_up_interruptible(&cfg_wait_queue);
  572. return;
  573. }
  574. queue_work(chp_wq, &cfg_work);
  575. }
  576. /**
  577. * chp_cfg_schedule - schedule chpid configuration request
  578. * @chpid - channel-path ID
  579. * @configure - Non-zero for configure, zero for deconfigure
  580. *
  581. * Schedule a channel-path configuration/deconfiguration request.
  582. */
  583. void chp_cfg_schedule(struct chp_id chpid, int configure)
  584. {
  585. CIO_MSG_EVENT(2, "chp_cfg_sched%x.%02x=%d\n", chpid.cssid, chpid.id,
  586. configure);
  587. mutex_lock(&cfg_lock);
  588. cfg_set_task(chpid, configure ? cfg_configure : cfg_deconfigure);
  589. cfg_busy = 1;
  590. mutex_unlock(&cfg_lock);
  591. queue_work(chp_wq, &cfg_work);
  592. }
  593. /**
  594. * chp_cfg_cancel_deconfigure - cancel chpid deconfiguration request
  595. * @chpid - channel-path ID
  596. *
  597. * Cancel an active channel-path deconfiguration request if it has not yet
  598. * been performed.
  599. */
  600. void chp_cfg_cancel_deconfigure(struct chp_id chpid)
  601. {
  602. CIO_MSG_EVENT(2, "chp_cfg_cancel:%x.%02x\n", chpid.cssid, chpid.id);
  603. mutex_lock(&cfg_lock);
  604. if (cfg_get_task(chpid) == cfg_deconfigure)
  605. cfg_set_task(chpid, cfg_none);
  606. mutex_unlock(&cfg_lock);
  607. }
  608. static int cfg_wait_idle(void)
  609. {
  610. if (wait_event_interruptible(cfg_wait_queue, !cfg_busy))
  611. return -ERESTARTSYS;
  612. return 0;
  613. }
  614. static int __init chp_init(void)
  615. {
  616. struct chp_id chpid;
  617. int ret;
  618. ret = crw_register_handler(CRW_RSC_CPATH, chp_process_crw);
  619. if (ret)
  620. return ret;
  621. chp_wq = create_singlethread_workqueue("cio_chp");
  622. if (!chp_wq) {
  623. crw_unregister_handler(CRW_RSC_CPATH);
  624. return -ENOMEM;
  625. }
  626. INIT_WORK(&cfg_work, cfg_func);
  627. init_waitqueue_head(&cfg_wait_queue);
  628. if (info_update())
  629. return 0;
  630. /* Register available channel-paths. */
  631. chp_id_for_each(&chpid) {
  632. if (chp_info_get_status(chpid) != CHP_STATUS_NOT_RECOGNIZED)
  633. chp_new(chpid);
  634. }
  635. return 0;
  636. }
  637. subsys_initcall(chp_init);