cmf.c 34 KB

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