cmf.c 34 KB

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