monreader.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660
  1. /*
  2. * drivers/s390/char/monreader.c
  3. *
  4. * Character device driver for reading z/VM *MONITOR service records.
  5. *
  6. * Copyright (C) 2004 IBM Corporation, IBM Deutschland Entwicklung GmbH.
  7. *
  8. * Author: Gerald Schaefer <geraldsc@de.ibm.com>
  9. */
  10. #include <linux/module.h>
  11. #include <linux/moduleparam.h>
  12. #include <linux/init.h>
  13. #include <linux/errno.h>
  14. #include <linux/types.h>
  15. #include <linux/kernel.h>
  16. #include <linux/miscdevice.h>
  17. #include <linux/ctype.h>
  18. #include <linux/spinlock.h>
  19. #include <linux/interrupt.h>
  20. #include <asm/uaccess.h>
  21. #include <asm/ebcdic.h>
  22. #include <asm/extmem.h>
  23. #include <linux/poll.h>
  24. #include "../net/iucv.h"
  25. //#define MON_DEBUG /* Debug messages on/off */
  26. #define MON_NAME "monreader"
  27. #define P_INFO(x...) printk(KERN_INFO MON_NAME " info: " x)
  28. #define P_ERROR(x...) printk(KERN_ERR MON_NAME " error: " x)
  29. #define P_WARNING(x...) printk(KERN_WARNING MON_NAME " warning: " x)
  30. #ifdef MON_DEBUG
  31. #define P_DEBUG(x...) printk(KERN_DEBUG MON_NAME " debug: " x)
  32. #else
  33. #define P_DEBUG(x...) do {} while (0)
  34. #endif
  35. #define MON_COLLECT_SAMPLE 0x80
  36. #define MON_COLLECT_EVENT 0x40
  37. #define MON_SERVICE "*MONITOR"
  38. #define MON_IN_USE 0x01
  39. #define MON_MSGLIM 255
  40. static char mon_dcss_name[9] = "MONDCSS\0";
  41. struct mon_msg {
  42. u32 pos;
  43. u32 mca_offset;
  44. iucv_MessagePending local_eib;
  45. char msglim_reached;
  46. char replied_msglim;
  47. };
  48. struct mon_private {
  49. u16 pathid;
  50. iucv_handle_t iucv_handle;
  51. struct mon_msg *msg_array[MON_MSGLIM];
  52. unsigned int write_index;
  53. unsigned int read_index;
  54. atomic_t msglim_count;
  55. atomic_t read_ready;
  56. atomic_t iucv_connected;
  57. atomic_t iucv_severed;
  58. };
  59. static unsigned long mon_in_use = 0;
  60. static unsigned long mon_dcss_start;
  61. static unsigned long mon_dcss_end;
  62. static DECLARE_WAIT_QUEUE_HEAD(mon_read_wait_queue);
  63. static DECLARE_WAIT_QUEUE_HEAD(mon_conn_wait_queue);
  64. static u8 iucv_host[8] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
  65. static u8 user_data_connect[16] = {
  66. /* Version code, must be 0x01 for shared mode */
  67. 0x01,
  68. /* what to collect */
  69. MON_COLLECT_SAMPLE | MON_COLLECT_EVENT,
  70. /* DCSS name in EBCDIC, 8 bytes padded with blanks */
  71. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  72. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  73. };
  74. static u8 user_data_sever[16] = {
  75. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  76. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  77. };
  78. /******************************************************************************
  79. * helper functions *
  80. *****************************************************************************/
  81. /*
  82. * Create the 8 bytes EBCDIC DCSS segment name from
  83. * an ASCII name, incl. padding
  84. */
  85. static inline void
  86. dcss_mkname(char *ascii_name, char *ebcdic_name)
  87. {
  88. int i;
  89. for (i = 0; i < 8; i++) {
  90. if (ascii_name[i] == '\0')
  91. break;
  92. ebcdic_name[i] = toupper(ascii_name[i]);
  93. };
  94. for (; i < 8; i++)
  95. ebcdic_name[i] = ' ';
  96. ASCEBC(ebcdic_name, 8);
  97. }
  98. /*
  99. * print appropriate error message for segment_load()/segment_type()
  100. * return code
  101. */
  102. static void
  103. mon_segment_warn(int rc, char* seg_name)
  104. {
  105. switch (rc) {
  106. case -ENOENT:
  107. P_WARNING("cannot load/query segment %s, does not exist\n",
  108. seg_name);
  109. break;
  110. case -ENOSYS:
  111. P_WARNING("cannot load/query segment %s, not running on VM\n",
  112. seg_name);
  113. break;
  114. case -EIO:
  115. P_WARNING("cannot load/query segment %s, hardware error\n",
  116. seg_name);
  117. break;
  118. case -ENOTSUPP:
  119. P_WARNING("cannot load/query segment %s, is a multi-part "
  120. "segment\n", seg_name);
  121. break;
  122. case -ENOSPC:
  123. P_WARNING("cannot load/query segment %s, overlaps with "
  124. "storage\n", seg_name);
  125. break;
  126. case -EBUSY:
  127. P_WARNING("cannot load/query segment %s, overlaps with "
  128. "already loaded dcss\n", seg_name);
  129. break;
  130. case -EPERM:
  131. P_WARNING("cannot load/query segment %s, already loaded in "
  132. "incompatible mode\n", seg_name);
  133. break;
  134. case -ENOMEM:
  135. P_WARNING("cannot load/query segment %s, out of memory\n",
  136. seg_name);
  137. break;
  138. case -ERANGE:
  139. P_WARNING("cannot load/query segment %s, exceeds kernel "
  140. "mapping range\n", seg_name);
  141. break;
  142. default:
  143. P_WARNING("cannot load/query segment %s, return value %i\n",
  144. seg_name, rc);
  145. break;
  146. }
  147. }
  148. static inline unsigned long
  149. mon_mca_start(struct mon_msg *monmsg)
  150. {
  151. return monmsg->local_eib.ln1msg1.iprmmsg1_u32;
  152. }
  153. static inline unsigned long
  154. mon_mca_end(struct mon_msg *monmsg)
  155. {
  156. return monmsg->local_eib.ln1msg2.ipbfln1f;
  157. }
  158. static inline u8
  159. mon_mca_type(struct mon_msg *monmsg, u8 index)
  160. {
  161. return *((u8 *) mon_mca_start(monmsg) + monmsg->mca_offset + index);
  162. }
  163. static inline u32
  164. mon_mca_size(struct mon_msg *monmsg)
  165. {
  166. return mon_mca_end(monmsg) - mon_mca_start(monmsg) + 1;
  167. }
  168. static inline u32
  169. mon_rec_start(struct mon_msg *monmsg)
  170. {
  171. return *((u32 *) (mon_mca_start(monmsg) + monmsg->mca_offset + 4));
  172. }
  173. static inline u32
  174. mon_rec_end(struct mon_msg *monmsg)
  175. {
  176. return *((u32 *) (mon_mca_start(monmsg) + monmsg->mca_offset + 8));
  177. }
  178. static inline int
  179. mon_check_mca(struct mon_msg *monmsg)
  180. {
  181. if ((mon_rec_end(monmsg) <= mon_rec_start(monmsg)) ||
  182. (mon_rec_start(monmsg) < mon_dcss_start) ||
  183. (mon_rec_end(monmsg) > mon_dcss_end) ||
  184. (mon_mca_type(monmsg, 0) == 0) ||
  185. (mon_mca_size(monmsg) % 12 != 0) ||
  186. (mon_mca_end(monmsg) <= mon_mca_start(monmsg)) ||
  187. (mon_mca_end(monmsg) > mon_dcss_end) ||
  188. (mon_mca_start(monmsg) < mon_dcss_start) ||
  189. ((mon_mca_type(monmsg, 1) == 0) && (mon_mca_type(monmsg, 2) == 0)))
  190. {
  191. P_DEBUG("READ, IGNORED INVALID MCA\n\n");
  192. return -EINVAL;
  193. }
  194. return 0;
  195. }
  196. static inline int
  197. mon_send_reply(struct mon_msg *monmsg, struct mon_private *monpriv)
  198. {
  199. u8 prmmsg[8];
  200. int rc;
  201. P_DEBUG("read, REPLY: pathid = 0x%04X, msgid = 0x%08X, trgcls = "
  202. "0x%08X\n\n",
  203. monmsg->local_eib.ippathid, monmsg->local_eib.ipmsgid,
  204. monmsg->local_eib.iptrgcls);
  205. rc = iucv_reply_prmmsg(monmsg->local_eib.ippathid,
  206. monmsg->local_eib.ipmsgid,
  207. monmsg->local_eib.iptrgcls,
  208. 0, prmmsg);
  209. atomic_dec(&monpriv->msglim_count);
  210. if (likely(!monmsg->msglim_reached)) {
  211. monmsg->pos = 0;
  212. monmsg->mca_offset = 0;
  213. monpriv->read_index = (monpriv->read_index + 1) %
  214. MON_MSGLIM;
  215. atomic_dec(&monpriv->read_ready);
  216. } else
  217. monmsg->replied_msglim = 1;
  218. if (rc) {
  219. P_ERROR("read, IUCV reply failed with rc = %i\n\n", rc);
  220. return -EIO;
  221. }
  222. return 0;
  223. }
  224. static inline struct mon_private *
  225. mon_alloc_mem(void)
  226. {
  227. int i,j;
  228. struct mon_private *monpriv;
  229. monpriv = kzalloc(sizeof(struct mon_private), GFP_KERNEL);
  230. if (!monpriv) {
  231. P_ERROR("no memory for monpriv\n");
  232. return NULL;
  233. }
  234. for (i = 0; i < MON_MSGLIM; i++) {
  235. monpriv->msg_array[i] = kzalloc(sizeof(struct mon_msg),
  236. GFP_KERNEL);
  237. if (!monpriv->msg_array[i]) {
  238. P_ERROR("open, no memory for msg_array\n");
  239. for (j = 0; j < i; j++)
  240. kfree(monpriv->msg_array[j]);
  241. return NULL;
  242. }
  243. }
  244. return monpriv;
  245. }
  246. static inline void
  247. mon_read_debug(struct mon_msg *monmsg, struct mon_private *monpriv)
  248. {
  249. #ifdef MON_DEBUG
  250. u8 msg_type[2], mca_type;
  251. unsigned long records_len;
  252. records_len = mon_rec_end(monmsg) - mon_rec_start(monmsg) + 1;
  253. memcpy(msg_type, &monmsg->local_eib.iptrgcls, 2);
  254. EBCASC(msg_type, 2);
  255. mca_type = mon_mca_type(monmsg, 0);
  256. EBCASC(&mca_type, 1);
  257. P_DEBUG("read, mon_read_index = %i, mon_write_index = %i\n",
  258. monpriv->read_index, monpriv->write_index);
  259. P_DEBUG("read, pathid = 0x%04X, msgid = 0x%08X, trgcls = 0x%08X\n",
  260. monmsg->local_eib.ippathid, monmsg->local_eib.ipmsgid,
  261. monmsg->local_eib.iptrgcls);
  262. P_DEBUG("read, msg_type = '%c%c', mca_type = '%c' / 0x%X / 0x%X\n",
  263. msg_type[0], msg_type[1], mca_type ? mca_type : 'X',
  264. mon_mca_type(monmsg, 1), mon_mca_type(monmsg, 2));
  265. P_DEBUG("read, MCA: start = 0x%lX, end = 0x%lX\n",
  266. mon_mca_start(monmsg), mon_mca_end(monmsg));
  267. P_DEBUG("read, REC: start = 0x%X, end = 0x%X, len = %lu\n\n",
  268. mon_rec_start(monmsg), mon_rec_end(monmsg), records_len);
  269. if (mon_mca_size(monmsg) > 12)
  270. P_DEBUG("READ, MORE THAN ONE MCA\n\n");
  271. #endif
  272. }
  273. static inline void
  274. mon_next_mca(struct mon_msg *monmsg)
  275. {
  276. if (likely((mon_mca_size(monmsg) - monmsg->mca_offset) == 12))
  277. return;
  278. P_DEBUG("READ, NEXT MCA\n\n");
  279. monmsg->mca_offset += 12;
  280. monmsg->pos = 0;
  281. }
  282. static inline struct mon_msg *
  283. mon_next_message(struct mon_private *monpriv)
  284. {
  285. struct mon_msg *monmsg;
  286. if (!atomic_read(&monpriv->read_ready))
  287. return NULL;
  288. monmsg = monpriv->msg_array[monpriv->read_index];
  289. if (unlikely(monmsg->replied_msglim)) {
  290. monmsg->replied_msglim = 0;
  291. monmsg->msglim_reached = 0;
  292. monmsg->pos = 0;
  293. monmsg->mca_offset = 0;
  294. P_WARNING("read, message limit reached\n");
  295. monpriv->read_index = (monpriv->read_index + 1) %
  296. MON_MSGLIM;
  297. atomic_dec(&monpriv->read_ready);
  298. return ERR_PTR(-EOVERFLOW);
  299. }
  300. return monmsg;
  301. }
  302. /******************************************************************************
  303. * IUCV handler *
  304. *****************************************************************************/
  305. static void
  306. mon_iucv_ConnectionComplete(iucv_ConnectionComplete *eib, void *pgm_data)
  307. {
  308. struct mon_private *monpriv = (struct mon_private *) pgm_data;
  309. P_DEBUG("IUCV connection completed\n");
  310. P_DEBUG("IUCV ACCEPT (from *MONITOR): Version = 0x%02X, Event = "
  311. "0x%02X, Sample = 0x%02X\n",
  312. eib->ipuser[0], eib->ipuser[1], eib->ipuser[2]);
  313. atomic_set(&monpriv->iucv_connected, 1);
  314. wake_up(&mon_conn_wait_queue);
  315. }
  316. static void
  317. mon_iucv_ConnectionSevered(iucv_ConnectionSevered *eib, void *pgm_data)
  318. {
  319. struct mon_private *monpriv = (struct mon_private *) pgm_data;
  320. P_ERROR("IUCV connection severed with rc = 0x%X\n",
  321. (u8) eib->ipuser[0]);
  322. atomic_set(&monpriv->iucv_severed, 1);
  323. wake_up(&mon_conn_wait_queue);
  324. wake_up_interruptible(&mon_read_wait_queue);
  325. }
  326. static void
  327. mon_iucv_MessagePending(iucv_MessagePending *eib, void *pgm_data)
  328. {
  329. struct mon_private *monpriv = (struct mon_private *) pgm_data;
  330. P_DEBUG("IUCV message pending\n");
  331. memcpy(&monpriv->msg_array[monpriv->write_index]->local_eib, eib,
  332. sizeof(iucv_MessagePending));
  333. if (atomic_inc_return(&monpriv->msglim_count) == MON_MSGLIM) {
  334. P_WARNING("IUCV message pending, message limit (%i) reached\n",
  335. MON_MSGLIM);
  336. monpriv->msg_array[monpriv->write_index]->msglim_reached = 1;
  337. }
  338. monpriv->write_index = (monpriv->write_index + 1) % MON_MSGLIM;
  339. atomic_inc(&monpriv->read_ready);
  340. wake_up_interruptible(&mon_read_wait_queue);
  341. }
  342. static iucv_interrupt_ops_t mon_iucvops = {
  343. .ConnectionComplete = mon_iucv_ConnectionComplete,
  344. .ConnectionSevered = mon_iucv_ConnectionSevered,
  345. .MessagePending = mon_iucv_MessagePending,
  346. };
  347. /******************************************************************************
  348. * file operations *
  349. *****************************************************************************/
  350. static int
  351. mon_open(struct inode *inode, struct file *filp)
  352. {
  353. int rc, i;
  354. struct mon_private *monpriv;
  355. /*
  356. * only one user allowed
  357. */
  358. if (test_and_set_bit(MON_IN_USE, &mon_in_use))
  359. return -EBUSY;
  360. monpriv = mon_alloc_mem();
  361. if (!monpriv)
  362. return -ENOMEM;
  363. /*
  364. * Register with IUCV and connect to *MONITOR service
  365. */
  366. monpriv->iucv_handle = iucv_register_program("my_monreader ",
  367. MON_SERVICE,
  368. NULL,
  369. &mon_iucvops,
  370. monpriv);
  371. if (!monpriv->iucv_handle) {
  372. P_ERROR("failed to register with iucv driver\n");
  373. rc = -EIO;
  374. goto out_error;
  375. }
  376. P_INFO("open, registered with IUCV\n");
  377. rc = iucv_connect(&monpriv->pathid, MON_MSGLIM, user_data_connect,
  378. MON_SERVICE, iucv_host, IPRMDATA, NULL, NULL,
  379. monpriv->iucv_handle, NULL);
  380. if (rc) {
  381. P_ERROR("iucv connection to *MONITOR failed with "
  382. "IPUSER SEVER code = %i\n", rc);
  383. rc = -EIO;
  384. goto out_unregister;
  385. }
  386. /*
  387. * Wait for connection confirmation
  388. */
  389. wait_event(mon_conn_wait_queue,
  390. atomic_read(&monpriv->iucv_connected) ||
  391. atomic_read(&monpriv->iucv_severed));
  392. if (atomic_read(&monpriv->iucv_severed)) {
  393. atomic_set(&monpriv->iucv_severed, 0);
  394. atomic_set(&monpriv->iucv_connected, 0);
  395. rc = -EIO;
  396. goto out_unregister;
  397. }
  398. P_INFO("open, established connection to *MONITOR service\n\n");
  399. filp->private_data = monpriv;
  400. return nonseekable_open(inode, filp);
  401. out_unregister:
  402. iucv_unregister_program(monpriv->iucv_handle);
  403. out_error:
  404. for (i = 0; i < MON_MSGLIM; i++)
  405. kfree(monpriv->msg_array[i]);
  406. kfree(monpriv);
  407. clear_bit(MON_IN_USE, &mon_in_use);
  408. return rc;
  409. }
  410. static int
  411. mon_close(struct inode *inode, struct file *filp)
  412. {
  413. int rc, i;
  414. struct mon_private *monpriv = filp->private_data;
  415. /*
  416. * Close IUCV connection and unregister
  417. */
  418. rc = iucv_sever(monpriv->pathid, user_data_sever);
  419. if (rc)
  420. P_ERROR("close, iucv_sever failed with rc = %i\n", rc);
  421. else
  422. P_INFO("close, terminated connection to *MONITOR service\n");
  423. rc = iucv_unregister_program(monpriv->iucv_handle);
  424. if (rc)
  425. P_ERROR("close, iucv_unregister failed with rc = %i\n", rc);
  426. else
  427. P_INFO("close, unregistered with IUCV\n");
  428. atomic_set(&monpriv->iucv_severed, 0);
  429. atomic_set(&monpriv->iucv_connected, 0);
  430. atomic_set(&monpriv->read_ready, 0);
  431. atomic_set(&monpriv->msglim_count, 0);
  432. monpriv->write_index = 0;
  433. monpriv->read_index = 0;
  434. for (i = 0; i < MON_MSGLIM; i++)
  435. kfree(monpriv->msg_array[i]);
  436. kfree(monpriv);
  437. clear_bit(MON_IN_USE, &mon_in_use);
  438. return 0;
  439. }
  440. static ssize_t
  441. mon_read(struct file *filp, char __user *data, size_t count, loff_t *ppos)
  442. {
  443. struct mon_private *monpriv = filp->private_data;
  444. struct mon_msg *monmsg;
  445. int ret;
  446. u32 mce_start;
  447. monmsg = mon_next_message(monpriv);
  448. if (IS_ERR(monmsg))
  449. return PTR_ERR(monmsg);
  450. if (!monmsg) {
  451. if (filp->f_flags & O_NONBLOCK)
  452. return -EAGAIN;
  453. ret = wait_event_interruptible(mon_read_wait_queue,
  454. atomic_read(&monpriv->read_ready) ||
  455. atomic_read(&monpriv->iucv_severed));
  456. if (ret)
  457. return ret;
  458. if (unlikely(atomic_read(&monpriv->iucv_severed)))
  459. return -EIO;
  460. monmsg = monpriv->msg_array[monpriv->read_index];
  461. }
  462. if (!monmsg->pos) {
  463. monmsg->pos = mon_mca_start(monmsg) + monmsg->mca_offset;
  464. mon_read_debug(monmsg, monpriv);
  465. }
  466. if (mon_check_mca(monmsg))
  467. goto reply;
  468. /* read monitor control element (12 bytes) first */
  469. mce_start = mon_mca_start(monmsg) + monmsg->mca_offset;
  470. if ((monmsg->pos >= mce_start) && (monmsg->pos < mce_start + 12)) {
  471. count = min(count, (size_t) mce_start + 12 - monmsg->pos);
  472. ret = copy_to_user(data, (void *) (unsigned long) monmsg->pos,
  473. count);
  474. if (ret)
  475. return -EFAULT;
  476. monmsg->pos += count;
  477. if (monmsg->pos == mce_start + 12)
  478. monmsg->pos = mon_rec_start(monmsg);
  479. goto out_copy;
  480. }
  481. /* read records */
  482. if (monmsg->pos <= mon_rec_end(monmsg)) {
  483. count = min(count, (size_t) mon_rec_end(monmsg) - monmsg->pos
  484. + 1);
  485. ret = copy_to_user(data, (void *) (unsigned long) monmsg->pos,
  486. count);
  487. if (ret)
  488. return -EFAULT;
  489. monmsg->pos += count;
  490. if (monmsg->pos > mon_rec_end(monmsg))
  491. mon_next_mca(monmsg);
  492. goto out_copy;
  493. }
  494. reply:
  495. ret = mon_send_reply(monmsg, monpriv);
  496. return ret;
  497. out_copy:
  498. *ppos += count;
  499. return count;
  500. }
  501. static unsigned int
  502. mon_poll(struct file *filp, struct poll_table_struct *p)
  503. {
  504. struct mon_private *monpriv = filp->private_data;
  505. poll_wait(filp, &mon_read_wait_queue, p);
  506. if (unlikely(atomic_read(&monpriv->iucv_severed)))
  507. return POLLERR;
  508. if (atomic_read(&monpriv->read_ready))
  509. return POLLIN | POLLRDNORM;
  510. return 0;
  511. }
  512. static struct file_operations mon_fops = {
  513. .owner = THIS_MODULE,
  514. .open = &mon_open,
  515. .release = &mon_close,
  516. .read = &mon_read,
  517. .poll = &mon_poll,
  518. };
  519. static struct miscdevice mon_dev = {
  520. .name = "monreader",
  521. .devfs_name = "monreader",
  522. .fops = &mon_fops,
  523. .minor = MISC_DYNAMIC_MINOR,
  524. };
  525. /******************************************************************************
  526. * module init/exit *
  527. *****************************************************************************/
  528. static int __init
  529. mon_init(void)
  530. {
  531. int rc;
  532. if (!MACHINE_IS_VM) {
  533. P_ERROR("not running under z/VM, driver not loaded\n");
  534. return -ENODEV;
  535. }
  536. rc = segment_type(mon_dcss_name);
  537. if (rc < 0) {
  538. mon_segment_warn(rc, mon_dcss_name);
  539. return rc;
  540. }
  541. if (rc != SEG_TYPE_SC) {
  542. P_ERROR("segment %s has unsupported type, should be SC\n",
  543. mon_dcss_name);
  544. return -EINVAL;
  545. }
  546. rc = segment_load(mon_dcss_name, SEGMENT_SHARED,
  547. &mon_dcss_start, &mon_dcss_end);
  548. if (rc < 0) {
  549. mon_segment_warn(rc, mon_dcss_name);
  550. return -EINVAL;
  551. }
  552. dcss_mkname(mon_dcss_name, &user_data_connect[8]);
  553. rc = misc_register(&mon_dev);
  554. if (rc < 0 ) {
  555. P_ERROR("misc_register failed, rc = %i\n", rc);
  556. goto out;
  557. }
  558. P_INFO("Loaded segment %s from %p to %p, size = %lu Byte\n",
  559. mon_dcss_name, (void *) mon_dcss_start, (void *) mon_dcss_end,
  560. mon_dcss_end - mon_dcss_start + 1);
  561. return 0;
  562. out:
  563. segment_unload(mon_dcss_name);
  564. return rc;
  565. }
  566. static void __exit
  567. mon_exit(void)
  568. {
  569. segment_unload(mon_dcss_name);
  570. WARN_ON(misc_deregister(&mon_dev) != 0);
  571. return;
  572. }
  573. module_init(mon_init);
  574. module_exit(mon_exit);
  575. module_param_string(mondcss, mon_dcss_name, 9, 0444);
  576. MODULE_PARM_DESC(mondcss, "Name of DCSS segment to be used for *MONITOR "
  577. "service, max. 8 chars. Default is MONDCSS");
  578. MODULE_AUTHOR("Gerald Schaefer <geraldsc@de.ibm.com>");
  579. MODULE_DESCRIPTION("Character device driver for reading z/VM "
  580. "monitor service records.");
  581. MODULE_LICENSE("GPL");