cmf.c 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347
  1. /*
  2. * Linux on zSeries Channel Measurement Facility support
  3. *
  4. * Copyright IBM Corp. 2000, 2006
  5. *
  6. * Authors: Arnd Bergmann <arndb@de.ibm.com>
  7. * Cornelia Huck <cornelia.huck@de.ibm.com>
  8. *
  9. * original idea from Natarajan Krishnaswami <nkrishna@us.ibm.com>
  10. *
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License as published by
  13. * the Free Software Foundation; either version 2, or (at your option)
  14. * any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program; if not, write to the Free Software
  23. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  24. */
  25. #define KMSG_COMPONENT "cio"
  26. #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
  27. #include <linux/bootmem.h>
  28. #include <linux/device.h>
  29. #include <linux/init.h>
  30. #include <linux/list.h>
  31. #include <linux/module.h>
  32. #include <linux/moduleparam.h>
  33. #include <linux/slab.h>
  34. #include <linux/timex.h> /* get_clock() */
  35. #include <asm/ccwdev.h>
  36. #include <asm/cio.h>
  37. #include <asm/cmb.h>
  38. #include <asm/div64.h>
  39. #include "cio.h"
  40. #include "css.h"
  41. #include "device.h"
  42. #include "ioasm.h"
  43. #include "chsc.h"
  44. /*
  45. * parameter to enable cmf during boot, possible uses are:
  46. * "s390cmf" -- enable cmf and allocate 2 MB of ram so measuring can be
  47. * used on any subchannel
  48. * "s390cmf=<num>" -- enable cmf and allocate enough memory to measure
  49. * <num> subchannel, where <num> is an integer
  50. * between 1 and 65535, default is 1024
  51. */
  52. #define ARGSTRING "s390cmf"
  53. /* indices for READCMB */
  54. enum cmb_index {
  55. /* basic and exended format: */
  56. cmb_ssch_rsch_count,
  57. cmb_sample_count,
  58. cmb_device_connect_time,
  59. cmb_function_pending_time,
  60. cmb_device_disconnect_time,
  61. cmb_control_unit_queuing_time,
  62. cmb_device_active_only_time,
  63. /* extended format only: */
  64. cmb_device_busy_time,
  65. cmb_initial_command_response_time,
  66. };
  67. /**
  68. * enum cmb_format - types of supported measurement block formats
  69. *
  70. * @CMF_BASIC: traditional channel measurement blocks supported
  71. * by all machines that we run on
  72. * @CMF_EXTENDED: improved format that was introduced with the z990
  73. * machine
  74. * @CMF_AUTODETECT: default: use extended format when running on a machine
  75. * supporting extended format, otherwise fall back to
  76. * basic format
  77. */
  78. enum cmb_format {
  79. CMF_BASIC,
  80. CMF_EXTENDED,
  81. CMF_AUTODETECT = -1,
  82. };
  83. /*
  84. * format - actual format for all measurement blocks
  85. *
  86. * The format module parameter can be set to a value of 0 (zero)
  87. * or 1, indicating basic or extended format as described for
  88. * enum cmb_format.
  89. */
  90. static int format = CMF_AUTODETECT;
  91. module_param(format, bint, 0444);
  92. /**
  93. * struct cmb_operations - functions to use depending on cmb_format
  94. *
  95. * Most of these functions operate on a struct ccw_device. There is only
  96. * one instance of struct cmb_operations because the format of the measurement
  97. * data is guaranteed to be the same for every ccw_device.
  98. *
  99. * @alloc: allocate memory for a channel measurement block,
  100. * either with the help of a special pool or with kmalloc
  101. * @free: free memory allocated with @alloc
  102. * @set: enable or disable measurement
  103. * @read: read a measurement entry at an index
  104. * @readall: read a measurement block in a common format
  105. * @reset: clear the data in the associated measurement block and
  106. * reset its time stamp
  107. * @align: align an allocated block so that the hardware can use it
  108. */
  109. struct cmb_operations {
  110. int (*alloc) (struct ccw_device *);
  111. void (*free) (struct ccw_device *);
  112. int (*set) (struct ccw_device *, u32);
  113. u64 (*read) (struct ccw_device *, int);
  114. int (*readall)(struct ccw_device *, struct cmbdata *);
  115. void (*reset) (struct ccw_device *);
  116. void *(*align) (void *);
  117. /* private: */
  118. struct attribute_group *attr_group;
  119. };
  120. static struct cmb_operations *cmbops;
  121. struct cmb_data {
  122. void *hw_block; /* Pointer to block updated by hardware */
  123. void *last_block; /* Last changed block copied from hardware block */
  124. int size; /* Size of hw_block and last_block */
  125. unsigned long long last_update; /* when last_block was updated */
  126. };
  127. /*
  128. * Our user interface is designed in terms of nanoseconds,
  129. * while the hardware measures total times in its own
  130. * unit.
  131. */
  132. static inline u64 time_to_nsec(u32 value)
  133. {
  134. return ((u64)value) * 128000ull;
  135. }
  136. /*
  137. * Users are usually interested in average times,
  138. * not accumulated time.
  139. * This also helps us with atomicity problems
  140. * when reading sinlge values.
  141. */
  142. static inline u64 time_to_avg_nsec(u32 value, u32 count)
  143. {
  144. u64 ret;
  145. /* no samples yet, avoid division by 0 */
  146. if (count == 0)
  147. return 0;
  148. /* value comes in units of 128 µsec */
  149. ret = time_to_nsec(value);
  150. do_div(ret, count);
  151. return ret;
  152. }
  153. /*
  154. * Activate or deactivate the channel monitor. When area is NULL,
  155. * the monitor is deactivated. The channel monitor needs to
  156. * be active in order to measure subchannels, which also need
  157. * to be enabled.
  158. */
  159. static inline void cmf_activate(void *area, unsigned int onoff)
  160. {
  161. register void * __gpr2 asm("2");
  162. register long __gpr1 asm("1");
  163. __gpr2 = area;
  164. __gpr1 = onoff ? 2 : 0;
  165. /* activate channel measurement */
  166. asm("schm" : : "d" (__gpr2), "d" (__gpr1) );
  167. }
  168. static int set_schib(struct ccw_device *cdev, u32 mme, int mbfc,
  169. unsigned long address)
  170. {
  171. struct subchannel *sch;
  172. sch = to_subchannel(cdev->dev.parent);
  173. sch->config.mme = mme;
  174. sch->config.mbfc = mbfc;
  175. /* address can be either a block address or a block index */
  176. if (mbfc)
  177. sch->config.mba = address;
  178. else
  179. sch->config.mbi = address;
  180. return cio_commit_config(sch);
  181. }
  182. struct set_schib_struct {
  183. u32 mme;
  184. int mbfc;
  185. unsigned long address;
  186. wait_queue_head_t wait;
  187. int ret;
  188. struct kref kref;
  189. };
  190. static void cmf_set_schib_release(struct kref *kref)
  191. {
  192. struct set_schib_struct *set_data;
  193. set_data = container_of(kref, struct set_schib_struct, kref);
  194. kfree(set_data);
  195. }
  196. #define CMF_PENDING 1
  197. static int set_schib_wait(struct ccw_device *cdev, u32 mme,
  198. int mbfc, unsigned long address)
  199. {
  200. struct set_schib_struct *set_data;
  201. int ret;
  202. spin_lock_irq(cdev->ccwlock);
  203. if (!cdev->private->cmb) {
  204. ret = -ENODEV;
  205. goto out;
  206. }
  207. set_data = kzalloc(sizeof(struct set_schib_struct), GFP_ATOMIC);
  208. if (!set_data) {
  209. ret = -ENOMEM;
  210. goto out;
  211. }
  212. init_waitqueue_head(&set_data->wait);
  213. kref_init(&set_data->kref);
  214. set_data->mme = mme;
  215. set_data->mbfc = mbfc;
  216. set_data->address = address;
  217. ret = set_schib(cdev, mme, mbfc, address);
  218. if (ret != -EBUSY)
  219. goto out_put;
  220. if (cdev->private->state != DEV_STATE_ONLINE) {
  221. /* if the device is not online, don't even try again */
  222. ret = -EBUSY;
  223. goto out_put;
  224. }
  225. cdev->private->state = DEV_STATE_CMFCHANGE;
  226. set_data->ret = CMF_PENDING;
  227. cdev->private->cmb_wait = set_data;
  228. spin_unlock_irq(cdev->ccwlock);
  229. if (wait_event_interruptible(set_data->wait,
  230. set_data->ret != CMF_PENDING)) {
  231. spin_lock_irq(cdev->ccwlock);
  232. if (set_data->ret == CMF_PENDING) {
  233. set_data->ret = -ERESTARTSYS;
  234. if (cdev->private->state == DEV_STATE_CMFCHANGE)
  235. cdev->private->state = DEV_STATE_ONLINE;
  236. }
  237. spin_unlock_irq(cdev->ccwlock);
  238. }
  239. spin_lock_irq(cdev->ccwlock);
  240. cdev->private->cmb_wait = NULL;
  241. ret = set_data->ret;
  242. out_put:
  243. kref_put(&set_data->kref, cmf_set_schib_release);
  244. out:
  245. spin_unlock_irq(cdev->ccwlock);
  246. return ret;
  247. }
  248. void retry_set_schib(struct ccw_device *cdev)
  249. {
  250. struct set_schib_struct *set_data;
  251. set_data = cdev->private->cmb_wait;
  252. if (!set_data) {
  253. WARN_ON(1);
  254. return;
  255. }
  256. kref_get(&set_data->kref);
  257. set_data->ret = set_schib(cdev, set_data->mme, set_data->mbfc,
  258. set_data->address);
  259. wake_up(&set_data->wait);
  260. kref_put(&set_data->kref, cmf_set_schib_release);
  261. }
  262. static int cmf_copy_block(struct ccw_device *cdev)
  263. {
  264. struct subchannel *sch;
  265. void *reference_buf;
  266. void *hw_block;
  267. struct cmb_data *cmb_data;
  268. sch = to_subchannel(cdev->dev.parent);
  269. if (cio_update_schib(sch))
  270. return -ENODEV;
  271. if (scsw_fctl(&sch->schib.scsw) & SCSW_FCTL_START_FUNC) {
  272. /* Don't copy if a start function is in progress. */
  273. if ((!(scsw_actl(&sch->schib.scsw) & SCSW_ACTL_SUSPENDED)) &&
  274. (scsw_actl(&sch->schib.scsw) &
  275. (SCSW_ACTL_DEVACT | SCSW_ACTL_SCHACT)) &&
  276. (!(scsw_stctl(&sch->schib.scsw) & SCSW_STCTL_SEC_STATUS)))
  277. return -EBUSY;
  278. }
  279. cmb_data = cdev->private->cmb;
  280. hw_block = cmbops->align(cmb_data->hw_block);
  281. if (!memcmp(cmb_data->last_block, hw_block, cmb_data->size))
  282. /* No need to copy. */
  283. return 0;
  284. reference_buf = kzalloc(cmb_data->size, GFP_ATOMIC);
  285. if (!reference_buf)
  286. return -ENOMEM;
  287. /* Ensure consistency of block copied from hardware. */
  288. do {
  289. memcpy(cmb_data->last_block, hw_block, cmb_data->size);
  290. memcpy(reference_buf, hw_block, cmb_data->size);
  291. } while (memcmp(cmb_data->last_block, reference_buf, cmb_data->size));
  292. cmb_data->last_update = get_clock();
  293. kfree(reference_buf);
  294. return 0;
  295. }
  296. struct copy_block_struct {
  297. wait_queue_head_t wait;
  298. int ret;
  299. struct kref kref;
  300. };
  301. static void cmf_copy_block_release(struct kref *kref)
  302. {
  303. struct copy_block_struct *copy_block;
  304. copy_block = container_of(kref, struct copy_block_struct, kref);
  305. kfree(copy_block);
  306. }
  307. static int cmf_cmb_copy_wait(struct ccw_device *cdev)
  308. {
  309. struct copy_block_struct *copy_block;
  310. int ret;
  311. unsigned long flags;
  312. spin_lock_irqsave(cdev->ccwlock, flags);
  313. if (!cdev->private->cmb) {
  314. ret = -ENODEV;
  315. goto out;
  316. }
  317. copy_block = kzalloc(sizeof(struct copy_block_struct), GFP_ATOMIC);
  318. if (!copy_block) {
  319. ret = -ENOMEM;
  320. goto out;
  321. }
  322. init_waitqueue_head(&copy_block->wait);
  323. kref_init(&copy_block->kref);
  324. ret = cmf_copy_block(cdev);
  325. if (ret != -EBUSY)
  326. goto out_put;
  327. if (cdev->private->state != DEV_STATE_ONLINE) {
  328. ret = -EBUSY;
  329. goto out_put;
  330. }
  331. cdev->private->state = DEV_STATE_CMFUPDATE;
  332. copy_block->ret = CMF_PENDING;
  333. cdev->private->cmb_wait = copy_block;
  334. spin_unlock_irqrestore(cdev->ccwlock, flags);
  335. if (wait_event_interruptible(copy_block->wait,
  336. copy_block->ret != CMF_PENDING)) {
  337. spin_lock_irqsave(cdev->ccwlock, flags);
  338. if (copy_block->ret == CMF_PENDING) {
  339. copy_block->ret = -ERESTARTSYS;
  340. if (cdev->private->state == DEV_STATE_CMFUPDATE)
  341. cdev->private->state = DEV_STATE_ONLINE;
  342. }
  343. spin_unlock_irqrestore(cdev->ccwlock, flags);
  344. }
  345. spin_lock_irqsave(cdev->ccwlock, flags);
  346. cdev->private->cmb_wait = NULL;
  347. ret = copy_block->ret;
  348. out_put:
  349. kref_put(&copy_block->kref, cmf_copy_block_release);
  350. out:
  351. spin_unlock_irqrestore(cdev->ccwlock, flags);
  352. return ret;
  353. }
  354. void cmf_retry_copy_block(struct ccw_device *cdev)
  355. {
  356. struct copy_block_struct *copy_block;
  357. copy_block = cdev->private->cmb_wait;
  358. if (!copy_block) {
  359. WARN_ON(1);
  360. return;
  361. }
  362. kref_get(&copy_block->kref);
  363. copy_block->ret = cmf_copy_block(cdev);
  364. wake_up(&copy_block->wait);
  365. kref_put(&copy_block->kref, cmf_copy_block_release);
  366. }
  367. static void cmf_generic_reset(struct ccw_device *cdev)
  368. {
  369. struct cmb_data *cmb_data;
  370. spin_lock_irq(cdev->ccwlock);
  371. cmb_data = cdev->private->cmb;
  372. if (cmb_data) {
  373. memset(cmb_data->last_block, 0, cmb_data->size);
  374. /*
  375. * Need to reset hw block as well to make the hardware start
  376. * from 0 again.
  377. */
  378. memset(cmbops->align(cmb_data->hw_block), 0, cmb_data->size);
  379. cmb_data->last_update = 0;
  380. }
  381. cdev->private->cmb_start_time = get_clock();
  382. spin_unlock_irq(cdev->ccwlock);
  383. }
  384. /**
  385. * struct cmb_area - container for global cmb data
  386. *
  387. * @mem: pointer to CMBs (only in basic measurement mode)
  388. * @list: contains a linked list of all subchannels
  389. * @num_channels: number of channels to be measured
  390. * @lock: protect concurrent access to @mem and @list
  391. */
  392. struct cmb_area {
  393. struct cmb *mem;
  394. struct list_head list;
  395. int num_channels;
  396. spinlock_t lock;
  397. };
  398. static struct cmb_area cmb_area = {
  399. .lock = __SPIN_LOCK_UNLOCKED(cmb_area.lock),
  400. .list = LIST_HEAD_INIT(cmb_area.list),
  401. .num_channels = 1024,
  402. };
  403. /* ****** old style CMB handling ********/
  404. /*
  405. * Basic channel measurement blocks are allocated in one contiguous
  406. * block of memory, which can not be moved as long as any channel
  407. * is active. Therefore, a maximum number of subchannels needs to
  408. * be defined somewhere. This is a module parameter, defaulting to
  409. * a reasonable value of 1024, or 32 kb of memory.
  410. * Current kernels don't allow kmalloc with more than 128kb, so the
  411. * maximum is 4096.
  412. */
  413. module_param_named(maxchannels, cmb_area.num_channels, uint, 0444);
  414. /**
  415. * struct cmb - basic channel measurement block
  416. * @ssch_rsch_count: number of ssch and rsch
  417. * @sample_count: number of samples
  418. * @device_connect_time: time of device connect
  419. * @function_pending_time: time of function pending
  420. * @device_disconnect_time: time of device disconnect
  421. * @control_unit_queuing_time: time of control unit queuing
  422. * @device_active_only_time: time of device active only
  423. * @reserved: unused in basic measurement mode
  424. *
  425. * The measurement block as used by the hardware. The fields are described
  426. * further in z/Architecture Principles of Operation, chapter 17.
  427. *
  428. * The cmb area made up from these blocks must be a contiguous array and may
  429. * not be reallocated or freed.
  430. * Only one cmb area can be present in the system.
  431. */
  432. struct cmb {
  433. u16 ssch_rsch_count;
  434. u16 sample_count;
  435. u32 device_connect_time;
  436. u32 function_pending_time;
  437. u32 device_disconnect_time;
  438. u32 control_unit_queuing_time;
  439. u32 device_active_only_time;
  440. u32 reserved[2];
  441. };
  442. /*
  443. * Insert a single device into the cmb_area list.
  444. * Called with cmb_area.lock held from alloc_cmb.
  445. */
  446. static int alloc_cmb_single(struct ccw_device *cdev,
  447. struct cmb_data *cmb_data)
  448. {
  449. struct cmb *cmb;
  450. struct ccw_device_private *node;
  451. int ret;
  452. spin_lock_irq(cdev->ccwlock);
  453. if (!list_empty(&cdev->private->cmb_list)) {
  454. ret = -EBUSY;
  455. goto out;
  456. }
  457. /*
  458. * Find first unused cmb in cmb_area.mem.
  459. * This is a little tricky: cmb_area.list
  460. * remains sorted by ->cmb->hw_data pointers.
  461. */
  462. cmb = cmb_area.mem;
  463. list_for_each_entry(node, &cmb_area.list, cmb_list) {
  464. struct cmb_data *data;
  465. data = node->cmb;
  466. if ((struct cmb*)data->hw_block > cmb)
  467. break;
  468. cmb++;
  469. }
  470. if (cmb - cmb_area.mem >= cmb_area.num_channels) {
  471. ret = -ENOMEM;
  472. goto out;
  473. }
  474. /* insert new cmb */
  475. list_add_tail(&cdev->private->cmb_list, &node->cmb_list);
  476. cmb_data->hw_block = cmb;
  477. cdev->private->cmb = cmb_data;
  478. ret = 0;
  479. out:
  480. spin_unlock_irq(cdev->ccwlock);
  481. return ret;
  482. }
  483. static int alloc_cmb(struct ccw_device *cdev)
  484. {
  485. int ret;
  486. struct cmb *mem;
  487. ssize_t size;
  488. struct cmb_data *cmb_data;
  489. /* Allocate private cmb_data. */
  490. cmb_data = kzalloc(sizeof(struct cmb_data), GFP_KERNEL);
  491. if (!cmb_data)
  492. return -ENOMEM;
  493. cmb_data->last_block = kzalloc(sizeof(struct cmb), GFP_KERNEL);
  494. if (!cmb_data->last_block) {
  495. kfree(cmb_data);
  496. return -ENOMEM;
  497. }
  498. cmb_data->size = sizeof(struct cmb);
  499. spin_lock(&cmb_area.lock);
  500. if (!cmb_area.mem) {
  501. /* there is no user yet, so we need a new area */
  502. size = sizeof(struct cmb) * cmb_area.num_channels;
  503. WARN_ON(!list_empty(&cmb_area.list));
  504. spin_unlock(&cmb_area.lock);
  505. mem = (void*)__get_free_pages(GFP_KERNEL | GFP_DMA,
  506. get_order(size));
  507. spin_lock(&cmb_area.lock);
  508. if (cmb_area.mem) {
  509. /* ok, another thread was faster */
  510. free_pages((unsigned long)mem, get_order(size));
  511. } else if (!mem) {
  512. /* no luck */
  513. ret = -ENOMEM;
  514. goto out;
  515. } else {
  516. /* everything ok */
  517. memset(mem, 0, size);
  518. cmb_area.mem = mem;
  519. cmf_activate(cmb_area.mem, 1);
  520. }
  521. }
  522. /* do the actual allocation */
  523. ret = alloc_cmb_single(cdev, cmb_data);
  524. out:
  525. spin_unlock(&cmb_area.lock);
  526. if (ret) {
  527. kfree(cmb_data->last_block);
  528. kfree(cmb_data);
  529. }
  530. return ret;
  531. }
  532. static void free_cmb(struct ccw_device *cdev)
  533. {
  534. struct ccw_device_private *priv;
  535. struct cmb_data *cmb_data;
  536. spin_lock(&cmb_area.lock);
  537. spin_lock_irq(cdev->ccwlock);
  538. priv = cdev->private;
  539. if (list_empty(&priv->cmb_list)) {
  540. /* already freed */
  541. goto out;
  542. }
  543. cmb_data = priv->cmb;
  544. priv->cmb = NULL;
  545. if (cmb_data)
  546. kfree(cmb_data->last_block);
  547. kfree(cmb_data);
  548. list_del_init(&priv->cmb_list);
  549. if (list_empty(&cmb_area.list)) {
  550. ssize_t size;
  551. size = sizeof(struct cmb) * cmb_area.num_channels;
  552. cmf_activate(NULL, 0);
  553. free_pages((unsigned long)cmb_area.mem, get_order(size));
  554. cmb_area.mem = NULL;
  555. }
  556. out:
  557. spin_unlock_irq(cdev->ccwlock);
  558. spin_unlock(&cmb_area.lock);
  559. }
  560. static int set_cmb(struct ccw_device *cdev, u32 mme)
  561. {
  562. u16 offset;
  563. struct cmb_data *cmb_data;
  564. unsigned long flags;
  565. spin_lock_irqsave(cdev->ccwlock, flags);
  566. if (!cdev->private->cmb) {
  567. spin_unlock_irqrestore(cdev->ccwlock, flags);
  568. return -EINVAL;
  569. }
  570. cmb_data = cdev->private->cmb;
  571. offset = mme ? (struct cmb *)cmb_data->hw_block - cmb_area.mem : 0;
  572. spin_unlock_irqrestore(cdev->ccwlock, flags);
  573. return set_schib_wait(cdev, mme, 0, offset);
  574. }
  575. static u64 read_cmb(struct ccw_device *cdev, int index)
  576. {
  577. struct cmb *cmb;
  578. u32 val;
  579. int ret;
  580. unsigned long flags;
  581. ret = cmf_cmb_copy_wait(cdev);
  582. if (ret < 0)
  583. return 0;
  584. spin_lock_irqsave(cdev->ccwlock, flags);
  585. if (!cdev->private->cmb) {
  586. ret = 0;
  587. goto out;
  588. }
  589. cmb = ((struct cmb_data *)cdev->private->cmb)->last_block;
  590. switch (index) {
  591. case cmb_ssch_rsch_count:
  592. ret = cmb->ssch_rsch_count;
  593. goto out;
  594. case cmb_sample_count:
  595. ret = cmb->sample_count;
  596. goto out;
  597. case cmb_device_connect_time:
  598. val = cmb->device_connect_time;
  599. break;
  600. case cmb_function_pending_time:
  601. val = cmb->function_pending_time;
  602. break;
  603. case cmb_device_disconnect_time:
  604. val = cmb->device_disconnect_time;
  605. break;
  606. case cmb_control_unit_queuing_time:
  607. val = cmb->control_unit_queuing_time;
  608. break;
  609. case cmb_device_active_only_time:
  610. val = cmb->device_active_only_time;
  611. break;
  612. default:
  613. ret = 0;
  614. goto out;
  615. }
  616. ret = time_to_avg_nsec(val, cmb->sample_count);
  617. out:
  618. spin_unlock_irqrestore(cdev->ccwlock, flags);
  619. return ret;
  620. }
  621. static int readall_cmb(struct ccw_device *cdev, struct cmbdata *data)
  622. {
  623. struct cmb *cmb;
  624. struct cmb_data *cmb_data;
  625. u64 time;
  626. unsigned long flags;
  627. int ret;
  628. ret = cmf_cmb_copy_wait(cdev);
  629. if (ret < 0)
  630. return ret;
  631. spin_lock_irqsave(cdev->ccwlock, flags);
  632. cmb_data = cdev->private->cmb;
  633. if (!cmb_data) {
  634. ret = -ENODEV;
  635. goto out;
  636. }
  637. if (cmb_data->last_update == 0) {
  638. ret = -EAGAIN;
  639. goto out;
  640. }
  641. cmb = cmb_data->last_block;
  642. time = cmb_data->last_update - cdev->private->cmb_start_time;
  643. memset(data, 0, sizeof(struct cmbdata));
  644. /* we only know values before device_busy_time */
  645. data->size = offsetof(struct cmbdata, device_busy_time);
  646. /* convert to nanoseconds */
  647. data->elapsed_time = (time * 1000) >> 12;
  648. /* copy data to new structure */
  649. data->ssch_rsch_count = cmb->ssch_rsch_count;
  650. data->sample_count = cmb->sample_count;
  651. /* time fields are converted to nanoseconds while copying */
  652. data->device_connect_time = time_to_nsec(cmb->device_connect_time);
  653. data->function_pending_time = time_to_nsec(cmb->function_pending_time);
  654. data->device_disconnect_time =
  655. time_to_nsec(cmb->device_disconnect_time);
  656. data->control_unit_queuing_time
  657. = time_to_nsec(cmb->control_unit_queuing_time);
  658. data->device_active_only_time
  659. = time_to_nsec(cmb->device_active_only_time);
  660. ret = 0;
  661. out:
  662. spin_unlock_irqrestore(cdev->ccwlock, flags);
  663. return ret;
  664. }
  665. static void reset_cmb(struct ccw_device *cdev)
  666. {
  667. cmf_generic_reset(cdev);
  668. }
  669. static void * align_cmb(void *area)
  670. {
  671. return area;
  672. }
  673. static struct attribute_group cmf_attr_group;
  674. static struct cmb_operations cmbops_basic = {
  675. .alloc = alloc_cmb,
  676. .free = free_cmb,
  677. .set = set_cmb,
  678. .read = read_cmb,
  679. .readall = readall_cmb,
  680. .reset = reset_cmb,
  681. .align = align_cmb,
  682. .attr_group = &cmf_attr_group,
  683. };
  684. /* ******** extended cmb handling ********/
  685. /**
  686. * struct cmbe - extended channel measurement block
  687. * @ssch_rsch_count: number of ssch and rsch
  688. * @sample_count: number of samples
  689. * @device_connect_time: time of device connect
  690. * @function_pending_time: time of function pending
  691. * @device_disconnect_time: time of device disconnect
  692. * @control_unit_queuing_time: time of control unit queuing
  693. * @device_active_only_time: time of device active only
  694. * @device_busy_time: time of device busy
  695. * @initial_command_response_time: initial command response time
  696. * @reserved: unused
  697. *
  698. * The measurement block as used by the hardware. May be in any 64 bit physical
  699. * location.
  700. * The fields are described further in z/Architecture Principles of Operation,
  701. * third edition, chapter 17.
  702. */
  703. struct cmbe {
  704. u32 ssch_rsch_count;
  705. u32 sample_count;
  706. u32 device_connect_time;
  707. u32 function_pending_time;
  708. u32 device_disconnect_time;
  709. u32 control_unit_queuing_time;
  710. u32 device_active_only_time;
  711. u32 device_busy_time;
  712. u32 initial_command_response_time;
  713. u32 reserved[7];
  714. };
  715. /*
  716. * kmalloc only guarantees 8 byte alignment, but we need cmbe
  717. * pointers to be naturally aligned. Make sure to allocate
  718. * enough space for two cmbes.
  719. */
  720. static inline struct cmbe *cmbe_align(struct cmbe *c)
  721. {
  722. unsigned long addr;
  723. addr = ((unsigned long)c + sizeof (struct cmbe) - sizeof(long)) &
  724. ~(sizeof (struct cmbe) - sizeof(long));
  725. return (struct cmbe*)addr;
  726. }
  727. static int alloc_cmbe(struct ccw_device *cdev)
  728. {
  729. struct cmbe *cmbe;
  730. struct cmb_data *cmb_data;
  731. int ret;
  732. cmbe = kzalloc (sizeof (*cmbe) * 2, GFP_KERNEL);
  733. if (!cmbe)
  734. return -ENOMEM;
  735. cmb_data = kzalloc(sizeof(struct cmb_data), GFP_KERNEL);
  736. if (!cmb_data) {
  737. ret = -ENOMEM;
  738. goto out_free;
  739. }
  740. cmb_data->last_block = kzalloc(sizeof(struct cmbe), GFP_KERNEL);
  741. if (!cmb_data->last_block) {
  742. ret = -ENOMEM;
  743. goto out_free;
  744. }
  745. cmb_data->size = sizeof(struct cmbe);
  746. spin_lock_irq(cdev->ccwlock);
  747. if (cdev->private->cmb) {
  748. spin_unlock_irq(cdev->ccwlock);
  749. ret = -EBUSY;
  750. goto out_free;
  751. }
  752. cmb_data->hw_block = cmbe;
  753. cdev->private->cmb = cmb_data;
  754. spin_unlock_irq(cdev->ccwlock);
  755. /* activate global measurement if this is the first channel */
  756. spin_lock(&cmb_area.lock);
  757. if (list_empty(&cmb_area.list))
  758. cmf_activate(NULL, 1);
  759. list_add_tail(&cdev->private->cmb_list, &cmb_area.list);
  760. spin_unlock(&cmb_area.lock);
  761. return 0;
  762. out_free:
  763. if (cmb_data)
  764. kfree(cmb_data->last_block);
  765. kfree(cmb_data);
  766. kfree(cmbe);
  767. return ret;
  768. }
  769. static void free_cmbe(struct ccw_device *cdev)
  770. {
  771. struct cmb_data *cmb_data;
  772. spin_lock_irq(cdev->ccwlock);
  773. cmb_data = cdev->private->cmb;
  774. cdev->private->cmb = NULL;
  775. if (cmb_data)
  776. kfree(cmb_data->last_block);
  777. kfree(cmb_data);
  778. spin_unlock_irq(cdev->ccwlock);
  779. /* deactivate global measurement if this is the last channel */
  780. spin_lock(&cmb_area.lock);
  781. list_del_init(&cdev->private->cmb_list);
  782. if (list_empty(&cmb_area.list))
  783. cmf_activate(NULL, 0);
  784. spin_unlock(&cmb_area.lock);
  785. }
  786. static int set_cmbe(struct ccw_device *cdev, u32 mme)
  787. {
  788. unsigned long mba;
  789. struct cmb_data *cmb_data;
  790. unsigned long flags;
  791. spin_lock_irqsave(cdev->ccwlock, flags);
  792. if (!cdev->private->cmb) {
  793. spin_unlock_irqrestore(cdev->ccwlock, flags);
  794. return -EINVAL;
  795. }
  796. cmb_data = cdev->private->cmb;
  797. mba = mme ? (unsigned long) cmbe_align(cmb_data->hw_block) : 0;
  798. spin_unlock_irqrestore(cdev->ccwlock, flags);
  799. return set_schib_wait(cdev, mme, 1, mba);
  800. }
  801. static u64 read_cmbe(struct ccw_device *cdev, int index)
  802. {
  803. struct cmbe *cmb;
  804. struct cmb_data *cmb_data;
  805. u32 val;
  806. int ret;
  807. unsigned long flags;
  808. ret = cmf_cmb_copy_wait(cdev);
  809. if (ret < 0)
  810. return 0;
  811. spin_lock_irqsave(cdev->ccwlock, flags);
  812. cmb_data = cdev->private->cmb;
  813. if (!cmb_data) {
  814. ret = 0;
  815. goto out;
  816. }
  817. cmb = cmb_data->last_block;
  818. switch (index) {
  819. case cmb_ssch_rsch_count:
  820. ret = cmb->ssch_rsch_count;
  821. goto out;
  822. case cmb_sample_count:
  823. ret = cmb->sample_count;
  824. goto out;
  825. case cmb_device_connect_time:
  826. val = cmb->device_connect_time;
  827. break;
  828. case cmb_function_pending_time:
  829. val = cmb->function_pending_time;
  830. break;
  831. case cmb_device_disconnect_time:
  832. val = cmb->device_disconnect_time;
  833. break;
  834. case cmb_control_unit_queuing_time:
  835. val = cmb->control_unit_queuing_time;
  836. break;
  837. case cmb_device_active_only_time:
  838. val = cmb->device_active_only_time;
  839. break;
  840. case cmb_device_busy_time:
  841. val = cmb->device_busy_time;
  842. break;
  843. case cmb_initial_command_response_time:
  844. val = cmb->initial_command_response_time;
  845. break;
  846. default:
  847. ret = 0;
  848. goto out;
  849. }
  850. ret = time_to_avg_nsec(val, cmb->sample_count);
  851. out:
  852. spin_unlock_irqrestore(cdev->ccwlock, flags);
  853. return ret;
  854. }
  855. static int readall_cmbe(struct ccw_device *cdev, struct cmbdata *data)
  856. {
  857. struct cmbe *cmb;
  858. struct cmb_data *cmb_data;
  859. u64 time;
  860. unsigned long flags;
  861. int ret;
  862. ret = cmf_cmb_copy_wait(cdev);
  863. if (ret < 0)
  864. return ret;
  865. spin_lock_irqsave(cdev->ccwlock, flags);
  866. cmb_data = cdev->private->cmb;
  867. if (!cmb_data) {
  868. ret = -ENODEV;
  869. goto out;
  870. }
  871. if (cmb_data->last_update == 0) {
  872. ret = -EAGAIN;
  873. goto out;
  874. }
  875. time = cmb_data->last_update - cdev->private->cmb_start_time;
  876. memset (data, 0, sizeof(struct cmbdata));
  877. /* we only know values before device_busy_time */
  878. data->size = offsetof(struct cmbdata, device_busy_time);
  879. /* conver to nanoseconds */
  880. data->elapsed_time = (time * 1000) >> 12;
  881. cmb = cmb_data->last_block;
  882. /* copy data to new structure */
  883. data->ssch_rsch_count = cmb->ssch_rsch_count;
  884. data->sample_count = cmb->sample_count;
  885. /* time fields are converted to nanoseconds while copying */
  886. data->device_connect_time = time_to_nsec(cmb->device_connect_time);
  887. data->function_pending_time = time_to_nsec(cmb->function_pending_time);
  888. data->device_disconnect_time =
  889. time_to_nsec(cmb->device_disconnect_time);
  890. data->control_unit_queuing_time
  891. = time_to_nsec(cmb->control_unit_queuing_time);
  892. data->device_active_only_time
  893. = time_to_nsec(cmb->device_active_only_time);
  894. data->device_busy_time = time_to_nsec(cmb->device_busy_time);
  895. data->initial_command_response_time
  896. = time_to_nsec(cmb->initial_command_response_time);
  897. ret = 0;
  898. out:
  899. spin_unlock_irqrestore(cdev->ccwlock, flags);
  900. return ret;
  901. }
  902. static void reset_cmbe(struct ccw_device *cdev)
  903. {
  904. cmf_generic_reset(cdev);
  905. }
  906. static void * align_cmbe(void *area)
  907. {
  908. return cmbe_align(area);
  909. }
  910. static struct attribute_group cmf_attr_group_ext;
  911. static struct cmb_operations cmbops_extended = {
  912. .alloc = alloc_cmbe,
  913. .free = free_cmbe,
  914. .set = set_cmbe,
  915. .read = read_cmbe,
  916. .readall = readall_cmbe,
  917. .reset = reset_cmbe,
  918. .align = align_cmbe,
  919. .attr_group = &cmf_attr_group_ext,
  920. };
  921. static ssize_t cmb_show_attr(struct device *dev, char *buf, enum cmb_index idx)
  922. {
  923. return sprintf(buf, "%lld\n",
  924. (unsigned long long) cmf_read(to_ccwdev(dev), idx));
  925. }
  926. static ssize_t cmb_show_avg_sample_interval(struct device *dev,
  927. struct device_attribute *attr,
  928. char *buf)
  929. {
  930. struct ccw_device *cdev;
  931. long interval;
  932. unsigned long count;
  933. struct cmb_data *cmb_data;
  934. cdev = to_ccwdev(dev);
  935. count = cmf_read(cdev, cmb_sample_count);
  936. spin_lock_irq(cdev->ccwlock);
  937. cmb_data = cdev->private->cmb;
  938. if (count) {
  939. interval = cmb_data->last_update -
  940. cdev->private->cmb_start_time;
  941. interval = (interval * 1000) >> 12;
  942. interval /= count;
  943. } else
  944. interval = -1;
  945. spin_unlock_irq(cdev->ccwlock);
  946. return sprintf(buf, "%ld\n", interval);
  947. }
  948. static ssize_t cmb_show_avg_utilization(struct device *dev,
  949. struct device_attribute *attr,
  950. char *buf)
  951. {
  952. struct cmbdata data;
  953. u64 utilization;
  954. unsigned long t, u;
  955. int ret;
  956. ret = cmf_readall(to_ccwdev(dev), &data);
  957. if (ret == -EAGAIN || ret == -ENODEV)
  958. /* No data (yet/currently) available to use for calculation. */
  959. return sprintf(buf, "n/a\n");
  960. else if (ret)
  961. return ret;
  962. utilization = data.device_connect_time +
  963. data.function_pending_time +
  964. data.device_disconnect_time;
  965. /* shift to avoid long long division */
  966. while (-1ul < (data.elapsed_time | utilization)) {
  967. utilization >>= 8;
  968. data.elapsed_time >>= 8;
  969. }
  970. /* calculate value in 0.1 percent units */
  971. t = (unsigned long) data.elapsed_time / 1000;
  972. u = (unsigned long) utilization / t;
  973. return sprintf(buf, "%02ld.%01ld%%\n", u/ 10, u - (u/ 10) * 10);
  974. }
  975. #define cmf_attr(name) \
  976. static ssize_t show_##name(struct device *dev, \
  977. struct device_attribute *attr, char *buf) \
  978. { return cmb_show_attr((dev), buf, cmb_##name); } \
  979. static DEVICE_ATTR(name, 0444, show_##name, NULL);
  980. #define cmf_attr_avg(name) \
  981. static ssize_t show_avg_##name(struct device *dev, \
  982. struct device_attribute *attr, char *buf) \
  983. { return cmb_show_attr((dev), buf, cmb_##name); } \
  984. static DEVICE_ATTR(avg_##name, 0444, show_avg_##name, NULL);
  985. cmf_attr(ssch_rsch_count);
  986. cmf_attr(sample_count);
  987. cmf_attr_avg(device_connect_time);
  988. cmf_attr_avg(function_pending_time);
  989. cmf_attr_avg(device_disconnect_time);
  990. cmf_attr_avg(control_unit_queuing_time);
  991. cmf_attr_avg(device_active_only_time);
  992. cmf_attr_avg(device_busy_time);
  993. cmf_attr_avg(initial_command_response_time);
  994. static DEVICE_ATTR(avg_sample_interval, 0444, cmb_show_avg_sample_interval,
  995. NULL);
  996. static DEVICE_ATTR(avg_utilization, 0444, cmb_show_avg_utilization, NULL);
  997. static struct attribute *cmf_attributes[] = {
  998. &dev_attr_avg_sample_interval.attr,
  999. &dev_attr_avg_utilization.attr,
  1000. &dev_attr_ssch_rsch_count.attr,
  1001. &dev_attr_sample_count.attr,
  1002. &dev_attr_avg_device_connect_time.attr,
  1003. &dev_attr_avg_function_pending_time.attr,
  1004. &dev_attr_avg_device_disconnect_time.attr,
  1005. &dev_attr_avg_control_unit_queuing_time.attr,
  1006. &dev_attr_avg_device_active_only_time.attr,
  1007. NULL,
  1008. };
  1009. static struct attribute_group cmf_attr_group = {
  1010. .name = "cmf",
  1011. .attrs = cmf_attributes,
  1012. };
  1013. static struct attribute *cmf_attributes_ext[] = {
  1014. &dev_attr_avg_sample_interval.attr,
  1015. &dev_attr_avg_utilization.attr,
  1016. &dev_attr_ssch_rsch_count.attr,
  1017. &dev_attr_sample_count.attr,
  1018. &dev_attr_avg_device_connect_time.attr,
  1019. &dev_attr_avg_function_pending_time.attr,
  1020. &dev_attr_avg_device_disconnect_time.attr,
  1021. &dev_attr_avg_control_unit_queuing_time.attr,
  1022. &dev_attr_avg_device_active_only_time.attr,
  1023. &dev_attr_avg_device_busy_time.attr,
  1024. &dev_attr_avg_initial_command_response_time.attr,
  1025. NULL,
  1026. };
  1027. static struct attribute_group cmf_attr_group_ext = {
  1028. .name = "cmf",
  1029. .attrs = cmf_attributes_ext,
  1030. };
  1031. static ssize_t cmb_enable_show(struct device *dev,
  1032. struct device_attribute *attr,
  1033. char *buf)
  1034. {
  1035. return sprintf(buf, "%d\n", to_ccwdev(dev)->private->cmb ? 1 : 0);
  1036. }
  1037. static ssize_t cmb_enable_store(struct device *dev,
  1038. struct device_attribute *attr, const char *buf,
  1039. size_t c)
  1040. {
  1041. struct ccw_device *cdev;
  1042. int ret;
  1043. unsigned long val;
  1044. ret = strict_strtoul(buf, 16, &val);
  1045. if (ret)
  1046. return ret;
  1047. cdev = to_ccwdev(dev);
  1048. switch (val) {
  1049. case 0:
  1050. ret = disable_cmf(cdev);
  1051. break;
  1052. case 1:
  1053. ret = enable_cmf(cdev);
  1054. break;
  1055. }
  1056. return c;
  1057. }
  1058. DEVICE_ATTR(cmb_enable, 0644, cmb_enable_show, cmb_enable_store);
  1059. int ccw_set_cmf(struct ccw_device *cdev, int enable)
  1060. {
  1061. return cmbops->set(cdev, enable ? 2 : 0);
  1062. }
  1063. /**
  1064. * enable_cmf() - switch on the channel measurement for a specific device
  1065. * @cdev: The ccw device to be enabled
  1066. *
  1067. * Returns %0 for success or a negative error value.
  1068. *
  1069. * Context:
  1070. * non-atomic
  1071. */
  1072. int enable_cmf(struct ccw_device *cdev)
  1073. {
  1074. int ret;
  1075. ret = cmbops->alloc(cdev);
  1076. cmbops->reset(cdev);
  1077. if (ret)
  1078. return ret;
  1079. ret = cmbops->set(cdev, 2);
  1080. if (ret) {
  1081. cmbops->free(cdev);
  1082. return ret;
  1083. }
  1084. ret = sysfs_create_group(&cdev->dev.kobj, cmbops->attr_group);
  1085. if (!ret)
  1086. return 0;
  1087. cmbops->set(cdev, 0); //FIXME: this can fail
  1088. cmbops->free(cdev);
  1089. return ret;
  1090. }
  1091. /**
  1092. * disable_cmf() - switch off the channel measurement for a specific device
  1093. * @cdev: The ccw device to be disabled
  1094. *
  1095. * Returns %0 for success or a negative error value.
  1096. *
  1097. * Context:
  1098. * non-atomic
  1099. */
  1100. int disable_cmf(struct ccw_device *cdev)
  1101. {
  1102. int ret;
  1103. ret = cmbops->set(cdev, 0);
  1104. if (ret)
  1105. return ret;
  1106. cmbops->free(cdev);
  1107. sysfs_remove_group(&cdev->dev.kobj, cmbops->attr_group);
  1108. return ret;
  1109. }
  1110. /**
  1111. * cmf_read() - read one value from the current channel measurement block
  1112. * @cdev: the channel to be read
  1113. * @index: the index of the value to be read
  1114. *
  1115. * Returns the value read or %0 if the value cannot be read.
  1116. *
  1117. * Context:
  1118. * any
  1119. */
  1120. u64 cmf_read(struct ccw_device *cdev, int index)
  1121. {
  1122. return cmbops->read(cdev, index);
  1123. }
  1124. /**
  1125. * cmf_readall() - read the current channel measurement block
  1126. * @cdev: the channel to be read
  1127. * @data: a pointer to a data block that will be filled
  1128. *
  1129. * Returns %0 on success, a negative error value otherwise.
  1130. *
  1131. * Context:
  1132. * any
  1133. */
  1134. int cmf_readall(struct ccw_device *cdev, struct cmbdata *data)
  1135. {
  1136. return cmbops->readall(cdev, data);
  1137. }
  1138. /* Reenable cmf when a disconnected device becomes available again. */
  1139. int cmf_reenable(struct ccw_device *cdev)
  1140. {
  1141. cmbops->reset(cdev);
  1142. return cmbops->set(cdev, 2);
  1143. }
  1144. static int __init init_cmf(void)
  1145. {
  1146. char *format_string;
  1147. char *detect_string = "parameter";
  1148. /*
  1149. * If the user did not give a parameter, see if we are running on a
  1150. * machine supporting extended measurement blocks, otherwise fall back
  1151. * to basic mode.
  1152. */
  1153. if (format == CMF_AUTODETECT) {
  1154. if (!css_general_characteristics.ext_mb) {
  1155. format = CMF_BASIC;
  1156. } else {
  1157. format = CMF_EXTENDED;
  1158. }
  1159. detect_string = "autodetected";
  1160. } else {
  1161. detect_string = "parameter";
  1162. }
  1163. switch (format) {
  1164. case CMF_BASIC:
  1165. format_string = "basic";
  1166. cmbops = &cmbops_basic;
  1167. break;
  1168. case CMF_EXTENDED:
  1169. format_string = "extended";
  1170. cmbops = &cmbops_extended;
  1171. break;
  1172. default:
  1173. return 1;
  1174. }
  1175. pr_info("Channel measurement facility initialized using format "
  1176. "%s (mode %s)\n", format_string, detect_string);
  1177. return 0;
  1178. }
  1179. module_init(init_cmf);
  1180. MODULE_AUTHOR("Arnd Bergmann <arndb@de.ibm.com>");
  1181. MODULE_LICENSE("GPL");
  1182. MODULE_DESCRIPTION("channel measurement facility base driver\n"
  1183. "Copyright IBM Corp. 2003\n");
  1184. EXPORT_SYMBOL_GPL(enable_cmf);
  1185. EXPORT_SYMBOL_GPL(disable_cmf);
  1186. EXPORT_SYMBOL_GPL(cmf_read);
  1187. EXPORT_SYMBOL_GPL(cmf_readall);