monreader.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662
  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 = kmalloc(sizeof(struct mon_private), GFP_KERNEL);
  230. if (!monpriv) {
  231. P_ERROR("no memory for monpriv\n");
  232. return NULL;
  233. }
  234. memset(monpriv, 0, sizeof(struct mon_private));
  235. for (i = 0; i < MON_MSGLIM; i++) {
  236. monpriv->msg_array[i] = kmalloc(sizeof(struct mon_msg),
  237. GFP_KERNEL);
  238. if (!monpriv->msg_array[i]) {
  239. P_ERROR("open, no memory for msg_array\n");
  240. for (j = 0; j < i; j++)
  241. kfree(monpriv->msg_array[j]);
  242. return NULL;
  243. }
  244. memset(monpriv->msg_array[i], 0, sizeof(struct mon_msg));
  245. }
  246. return monpriv;
  247. }
  248. static inline void
  249. mon_read_debug(struct mon_msg *monmsg, struct mon_private *monpriv)
  250. {
  251. #ifdef MON_DEBUG
  252. u8 msg_type[2], mca_type;
  253. unsigned long records_len;
  254. records_len = mon_rec_end(monmsg) - mon_rec_start(monmsg) + 1;
  255. memcpy(msg_type, &monmsg->local_eib.iptrgcls, 2);
  256. EBCASC(msg_type, 2);
  257. mca_type = mon_mca_type(monmsg, 0);
  258. EBCASC(&mca_type, 1);
  259. P_DEBUG("read, mon_read_index = %i, mon_write_index = %i\n",
  260. monpriv->read_index, monpriv->write_index);
  261. P_DEBUG("read, pathid = 0x%04X, msgid = 0x%08X, trgcls = 0x%08X\n",
  262. monmsg->local_eib.ippathid, monmsg->local_eib.ipmsgid,
  263. monmsg->local_eib.iptrgcls);
  264. P_DEBUG("read, msg_type = '%c%c', mca_type = '%c' / 0x%X / 0x%X\n",
  265. msg_type[0], msg_type[1], mca_type ? mca_type : 'X',
  266. mon_mca_type(monmsg, 1), mon_mca_type(monmsg, 2));
  267. P_DEBUG("read, MCA: start = 0x%lX, end = 0x%lX\n",
  268. mon_mca_start(monmsg), mon_mca_end(monmsg));
  269. P_DEBUG("read, REC: start = 0x%X, end = 0x%X, len = %lu\n\n",
  270. mon_rec_start(monmsg), mon_rec_end(monmsg), records_len);
  271. if (mon_mca_size(monmsg) > 12)
  272. P_DEBUG("READ, MORE THAN ONE MCA\n\n");
  273. #endif
  274. }
  275. static inline void
  276. mon_next_mca(struct mon_msg *monmsg)
  277. {
  278. if (likely((mon_mca_size(monmsg) - monmsg->mca_offset) == 12))
  279. return;
  280. P_DEBUG("READ, NEXT MCA\n\n");
  281. monmsg->mca_offset += 12;
  282. monmsg->pos = 0;
  283. }
  284. static inline struct mon_msg *
  285. mon_next_message(struct mon_private *monpriv)
  286. {
  287. struct mon_msg *monmsg;
  288. if (!atomic_read(&monpriv->read_ready))
  289. return NULL;
  290. monmsg = monpriv->msg_array[monpriv->read_index];
  291. if (unlikely(monmsg->replied_msglim)) {
  292. monmsg->replied_msglim = 0;
  293. monmsg->msglim_reached = 0;
  294. monmsg->pos = 0;
  295. monmsg->mca_offset = 0;
  296. P_WARNING("read, message limit reached\n");
  297. monpriv->read_index = (monpriv->read_index + 1) %
  298. MON_MSGLIM;
  299. atomic_dec(&monpriv->read_ready);
  300. return ERR_PTR(-EOVERFLOW);
  301. }
  302. return monmsg;
  303. }
  304. /******************************************************************************
  305. * IUCV handler *
  306. *****************************************************************************/
  307. static void
  308. mon_iucv_ConnectionComplete(iucv_ConnectionComplete *eib, void *pgm_data)
  309. {
  310. struct mon_private *monpriv = (struct mon_private *) pgm_data;
  311. P_DEBUG("IUCV connection completed\n");
  312. P_DEBUG("IUCV ACCEPT (from *MONITOR): Version = 0x%02X, Event = "
  313. "0x%02X, Sample = 0x%02X\n",
  314. eib->ipuser[0], eib->ipuser[1], eib->ipuser[2]);
  315. atomic_set(&monpriv->iucv_connected, 1);
  316. wake_up(&mon_conn_wait_queue);
  317. }
  318. static void
  319. mon_iucv_ConnectionSevered(iucv_ConnectionSevered *eib, void *pgm_data)
  320. {
  321. struct mon_private *monpriv = (struct mon_private *) pgm_data;
  322. P_ERROR("IUCV connection severed with rc = 0x%X\n",
  323. (u8) eib->ipuser[0]);
  324. atomic_set(&monpriv->iucv_severed, 1);
  325. wake_up(&mon_conn_wait_queue);
  326. wake_up_interruptible(&mon_read_wait_queue);
  327. }
  328. static void
  329. mon_iucv_MessagePending(iucv_MessagePending *eib, void *pgm_data)
  330. {
  331. struct mon_private *monpriv = (struct mon_private *) pgm_data;
  332. P_DEBUG("IUCV message pending\n");
  333. memcpy(&monpriv->msg_array[monpriv->write_index]->local_eib, eib,
  334. sizeof(iucv_MessagePending));
  335. if (atomic_inc_return(&monpriv->msglim_count) == MON_MSGLIM) {
  336. P_WARNING("IUCV message pending, message limit (%i) reached\n",
  337. MON_MSGLIM);
  338. monpriv->msg_array[monpriv->write_index]->msglim_reached = 1;
  339. }
  340. monpriv->write_index = (monpriv->write_index + 1) % MON_MSGLIM;
  341. atomic_inc(&monpriv->read_ready);
  342. wake_up_interruptible(&mon_read_wait_queue);
  343. }
  344. static iucv_interrupt_ops_t mon_iucvops = {
  345. .ConnectionComplete = mon_iucv_ConnectionComplete,
  346. .ConnectionSevered = mon_iucv_ConnectionSevered,
  347. .MessagePending = mon_iucv_MessagePending,
  348. };
  349. /******************************************************************************
  350. * file operations *
  351. *****************************************************************************/
  352. static int
  353. mon_open(struct inode *inode, struct file *filp)
  354. {
  355. int rc, i;
  356. struct mon_private *monpriv;
  357. /*
  358. * only one user allowed
  359. */
  360. if (test_and_set_bit(MON_IN_USE, &mon_in_use))
  361. return -EBUSY;
  362. monpriv = mon_alloc_mem();
  363. if (!monpriv)
  364. return -ENOMEM;
  365. /*
  366. * Register with IUCV and connect to *MONITOR service
  367. */
  368. monpriv->iucv_handle = iucv_register_program("my_monreader ",
  369. MON_SERVICE,
  370. NULL,
  371. &mon_iucvops,
  372. monpriv);
  373. if (!monpriv->iucv_handle) {
  374. P_ERROR("failed to register with iucv driver\n");
  375. rc = -EIO;
  376. goto out_error;
  377. }
  378. P_INFO("open, registered with IUCV\n");
  379. rc = iucv_connect(&monpriv->pathid, MON_MSGLIM, user_data_connect,
  380. MON_SERVICE, iucv_host, IPRMDATA, NULL, NULL,
  381. monpriv->iucv_handle, NULL);
  382. if (rc) {
  383. P_ERROR("iucv connection to *MONITOR failed with "
  384. "IPUSER SEVER code = %i\n", rc);
  385. rc = -EIO;
  386. goto out_unregister;
  387. }
  388. /*
  389. * Wait for connection confirmation
  390. */
  391. wait_event(mon_conn_wait_queue,
  392. atomic_read(&monpriv->iucv_connected) ||
  393. atomic_read(&monpriv->iucv_severed));
  394. if (atomic_read(&monpriv->iucv_severed)) {
  395. atomic_set(&monpriv->iucv_severed, 0);
  396. atomic_set(&monpriv->iucv_connected, 0);
  397. rc = -EIO;
  398. goto out_unregister;
  399. }
  400. P_INFO("open, established connection to *MONITOR service\n\n");
  401. filp->private_data = monpriv;
  402. return nonseekable_open(inode, filp);
  403. out_unregister:
  404. iucv_unregister_program(monpriv->iucv_handle);
  405. out_error:
  406. for (i = 0; i < MON_MSGLIM; i++)
  407. kfree(monpriv->msg_array[i]);
  408. kfree(monpriv);
  409. clear_bit(MON_IN_USE, &mon_in_use);
  410. return rc;
  411. }
  412. static int
  413. mon_close(struct inode *inode, struct file *filp)
  414. {
  415. int rc, i;
  416. struct mon_private *monpriv = filp->private_data;
  417. /*
  418. * Close IUCV connection and unregister
  419. */
  420. rc = iucv_sever(monpriv->pathid, user_data_sever);
  421. if (rc)
  422. P_ERROR("close, iucv_sever failed with rc = %i\n", rc);
  423. else
  424. P_INFO("close, terminated connection to *MONITOR service\n");
  425. rc = iucv_unregister_program(monpriv->iucv_handle);
  426. if (rc)
  427. P_ERROR("close, iucv_unregister failed with rc = %i\n", rc);
  428. else
  429. P_INFO("close, unregistered with IUCV\n");
  430. atomic_set(&monpriv->iucv_severed, 0);
  431. atomic_set(&monpriv->iucv_connected, 0);
  432. atomic_set(&monpriv->read_ready, 0);
  433. atomic_set(&monpriv->msglim_count, 0);
  434. monpriv->write_index = 0;
  435. monpriv->read_index = 0;
  436. for (i = 0; i < MON_MSGLIM; i++)
  437. kfree(monpriv->msg_array[i]);
  438. kfree(monpriv);
  439. clear_bit(MON_IN_USE, &mon_in_use);
  440. return 0;
  441. }
  442. static ssize_t
  443. mon_read(struct file *filp, char __user *data, size_t count, loff_t *ppos)
  444. {
  445. struct mon_private *monpriv = filp->private_data;
  446. struct mon_msg *monmsg;
  447. int ret;
  448. u32 mce_start;
  449. monmsg = mon_next_message(monpriv);
  450. if (IS_ERR(monmsg))
  451. return PTR_ERR(monmsg);
  452. if (!monmsg) {
  453. if (filp->f_flags & O_NONBLOCK)
  454. return -EAGAIN;
  455. ret = wait_event_interruptible(mon_read_wait_queue,
  456. atomic_read(&monpriv->read_ready) ||
  457. atomic_read(&monpriv->iucv_severed));
  458. if (ret)
  459. return ret;
  460. if (unlikely(atomic_read(&monpriv->iucv_severed)))
  461. return -EIO;
  462. monmsg = monpriv->msg_array[monpriv->read_index];
  463. }
  464. if (!monmsg->pos) {
  465. monmsg->pos = mon_mca_start(monmsg) + monmsg->mca_offset;
  466. mon_read_debug(monmsg, monpriv);
  467. }
  468. if (mon_check_mca(monmsg))
  469. goto reply;
  470. /* read monitor control element (12 bytes) first */
  471. mce_start = mon_mca_start(monmsg) + monmsg->mca_offset;
  472. if ((monmsg->pos >= mce_start) && (monmsg->pos < mce_start + 12)) {
  473. count = min(count, (size_t) mce_start + 12 - monmsg->pos);
  474. ret = copy_to_user(data, (void *) (unsigned long) monmsg->pos,
  475. count);
  476. if (ret)
  477. return -EFAULT;
  478. monmsg->pos += count;
  479. if (monmsg->pos == mce_start + 12)
  480. monmsg->pos = mon_rec_start(monmsg);
  481. goto out_copy;
  482. }
  483. /* read records */
  484. if (monmsg->pos <= mon_rec_end(monmsg)) {
  485. count = min(count, (size_t) mon_rec_end(monmsg) - monmsg->pos
  486. + 1);
  487. ret = copy_to_user(data, (void *) (unsigned long) monmsg->pos,
  488. count);
  489. if (ret)
  490. return -EFAULT;
  491. monmsg->pos += count;
  492. if (monmsg->pos > mon_rec_end(monmsg))
  493. mon_next_mca(monmsg);
  494. goto out_copy;
  495. }
  496. reply:
  497. ret = mon_send_reply(monmsg, monpriv);
  498. return ret;
  499. out_copy:
  500. *ppos += count;
  501. return count;
  502. }
  503. static unsigned int
  504. mon_poll(struct file *filp, struct poll_table_struct *p)
  505. {
  506. struct mon_private *monpriv = filp->private_data;
  507. poll_wait(filp, &mon_read_wait_queue, p);
  508. if (unlikely(atomic_read(&monpriv->iucv_severed)))
  509. return POLLERR;
  510. if (atomic_read(&monpriv->read_ready))
  511. return POLLIN | POLLRDNORM;
  512. return 0;
  513. }
  514. static struct file_operations mon_fops = {
  515. .owner = THIS_MODULE,
  516. .open = &mon_open,
  517. .release = &mon_close,
  518. .read = &mon_read,
  519. .poll = &mon_poll,
  520. };
  521. static struct miscdevice mon_dev = {
  522. .name = "monreader",
  523. .devfs_name = "monreader",
  524. .fops = &mon_fops,
  525. .minor = MISC_DYNAMIC_MINOR,
  526. };
  527. /******************************************************************************
  528. * module init/exit *
  529. *****************************************************************************/
  530. static int __init
  531. mon_init(void)
  532. {
  533. int rc;
  534. if (!MACHINE_IS_VM) {
  535. P_ERROR("not running under z/VM, driver not loaded\n");
  536. return -ENODEV;
  537. }
  538. rc = segment_type(mon_dcss_name);
  539. if (rc < 0) {
  540. mon_segment_warn(rc, mon_dcss_name);
  541. return rc;
  542. }
  543. if (rc != SEG_TYPE_SC) {
  544. P_ERROR("segment %s has unsupported type, should be SC\n",
  545. mon_dcss_name);
  546. return -EINVAL;
  547. }
  548. rc = segment_load(mon_dcss_name, SEGMENT_SHARED,
  549. &mon_dcss_start, &mon_dcss_end);
  550. if (rc < 0) {
  551. mon_segment_warn(rc, mon_dcss_name);
  552. return -EINVAL;
  553. }
  554. dcss_mkname(mon_dcss_name, &user_data_connect[8]);
  555. rc = misc_register(&mon_dev);
  556. if (rc < 0 ) {
  557. P_ERROR("misc_register failed, rc = %i\n", rc);
  558. goto out;
  559. }
  560. P_INFO("Loaded segment %s from %p to %p, size = %lu Byte\n",
  561. mon_dcss_name, (void *) mon_dcss_start, (void *) mon_dcss_end,
  562. mon_dcss_end - mon_dcss_start + 1);
  563. return 0;
  564. out:
  565. segment_unload(mon_dcss_name);
  566. return rc;
  567. }
  568. static void __exit
  569. mon_exit(void)
  570. {
  571. segment_unload(mon_dcss_name);
  572. WARN_ON(misc_deregister(&mon_dev) != 0);
  573. return;
  574. }
  575. module_init(mon_init);
  576. module_exit(mon_exit);
  577. module_param_string(mondcss, mon_dcss_name, 9, 0444);
  578. MODULE_PARM_DESC(mondcss, "Name of DCSS segment to be used for *MONITOR "
  579. "service, max. 8 chars. Default is MONDCSS");
  580. MODULE_AUTHOR("Gerald Schaefer <geraldsc@de.ibm.com>");
  581. MODULE_DESCRIPTION("Character device driver for reading z/VM "
  582. "monitor service records.");
  583. MODULE_LICENSE("GPL");