cmf.c 34 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379
  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 (scsw_fctl(&sch->schib.scsw) & SCSW_FCTL_START_FUNC) {
  306. /* Don't copy if a start function is in progress. */
  307. if ((!(scsw_actl(&sch->schib.scsw) & SCSW_ACTL_SUSPENDED)) &&
  308. (scsw_actl(&sch->schib.scsw) &
  309. (SCSW_ACTL_DEVACT | SCSW_ACTL_SCHACT)) &&
  310. (!(scsw_stctl(&sch->schib.scsw) & 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. ret = -ENOMEM;
  548. goto out;
  549. } else {
  550. /* everything ok */
  551. memset(mem, 0, size);
  552. cmb_area.mem = mem;
  553. cmf_activate(cmb_area.mem, 1);
  554. }
  555. }
  556. /* do the actual allocation */
  557. ret = alloc_cmb_single(cdev, cmb_data);
  558. out:
  559. spin_unlock(&cmb_area.lock);
  560. if (ret) {
  561. kfree(cmb_data->last_block);
  562. kfree(cmb_data);
  563. }
  564. return ret;
  565. }
  566. static void free_cmb(struct ccw_device *cdev)
  567. {
  568. struct ccw_device_private *priv;
  569. struct cmb_data *cmb_data;
  570. spin_lock(&cmb_area.lock);
  571. spin_lock_irq(cdev->ccwlock);
  572. priv = cdev->private;
  573. if (list_empty(&priv->cmb_list)) {
  574. /* already freed */
  575. goto out;
  576. }
  577. cmb_data = priv->cmb;
  578. priv->cmb = NULL;
  579. if (cmb_data)
  580. kfree(cmb_data->last_block);
  581. kfree(cmb_data);
  582. list_del_init(&priv->cmb_list);
  583. if (list_empty(&cmb_area.list)) {
  584. ssize_t size;
  585. size = sizeof(struct cmb) * cmb_area.num_channels;
  586. cmf_activate(NULL, 0);
  587. free_pages((unsigned long)cmb_area.mem, get_order(size));
  588. cmb_area.mem = NULL;
  589. }
  590. out:
  591. spin_unlock_irq(cdev->ccwlock);
  592. spin_unlock(&cmb_area.lock);
  593. }
  594. static int set_cmb(struct ccw_device *cdev, u32 mme)
  595. {
  596. u16 offset;
  597. struct cmb_data *cmb_data;
  598. unsigned long flags;
  599. spin_lock_irqsave(cdev->ccwlock, flags);
  600. if (!cdev->private->cmb) {
  601. spin_unlock_irqrestore(cdev->ccwlock, flags);
  602. return -EINVAL;
  603. }
  604. cmb_data = cdev->private->cmb;
  605. offset = mme ? (struct cmb *)cmb_data->hw_block - cmb_area.mem : 0;
  606. spin_unlock_irqrestore(cdev->ccwlock, flags);
  607. return set_schib_wait(cdev, mme, 0, offset);
  608. }
  609. static u64 read_cmb(struct ccw_device *cdev, int index)
  610. {
  611. struct cmb *cmb;
  612. u32 val;
  613. int ret;
  614. unsigned long flags;
  615. ret = cmf_cmb_copy_wait(cdev);
  616. if (ret < 0)
  617. return 0;
  618. spin_lock_irqsave(cdev->ccwlock, flags);
  619. if (!cdev->private->cmb) {
  620. ret = 0;
  621. goto out;
  622. }
  623. cmb = ((struct cmb_data *)cdev->private->cmb)->last_block;
  624. switch (index) {
  625. case cmb_ssch_rsch_count:
  626. ret = cmb->ssch_rsch_count;
  627. goto out;
  628. case cmb_sample_count:
  629. ret = cmb->sample_count;
  630. goto out;
  631. case cmb_device_connect_time:
  632. val = cmb->device_connect_time;
  633. break;
  634. case cmb_function_pending_time:
  635. val = cmb->function_pending_time;
  636. break;
  637. case cmb_device_disconnect_time:
  638. val = cmb->device_disconnect_time;
  639. break;
  640. case cmb_control_unit_queuing_time:
  641. val = cmb->control_unit_queuing_time;
  642. break;
  643. case cmb_device_active_only_time:
  644. val = cmb->device_active_only_time;
  645. break;
  646. default:
  647. ret = 0;
  648. goto out;
  649. }
  650. ret = time_to_avg_nsec(val, cmb->sample_count);
  651. out:
  652. spin_unlock_irqrestore(cdev->ccwlock, flags);
  653. return ret;
  654. }
  655. static int readall_cmb(struct ccw_device *cdev, struct cmbdata *data)
  656. {
  657. struct cmb *cmb;
  658. struct cmb_data *cmb_data;
  659. u64 time;
  660. unsigned long flags;
  661. int ret;
  662. ret = cmf_cmb_copy_wait(cdev);
  663. if (ret < 0)
  664. return ret;
  665. spin_lock_irqsave(cdev->ccwlock, flags);
  666. cmb_data = cdev->private->cmb;
  667. if (!cmb_data) {
  668. ret = -ENODEV;
  669. goto out;
  670. }
  671. if (cmb_data->last_update == 0) {
  672. ret = -EAGAIN;
  673. goto out;
  674. }
  675. cmb = cmb_data->last_block;
  676. time = cmb_data->last_update - cdev->private->cmb_start_time;
  677. memset(data, 0, sizeof(struct cmbdata));
  678. /* we only know values before device_busy_time */
  679. data->size = offsetof(struct cmbdata, device_busy_time);
  680. /* convert to nanoseconds */
  681. data->elapsed_time = (time * 1000) >> 12;
  682. /* copy data to new structure */
  683. data->ssch_rsch_count = cmb->ssch_rsch_count;
  684. data->sample_count = cmb->sample_count;
  685. /* time fields are converted to nanoseconds while copying */
  686. data->device_connect_time = time_to_nsec(cmb->device_connect_time);
  687. data->function_pending_time = time_to_nsec(cmb->function_pending_time);
  688. data->device_disconnect_time =
  689. time_to_nsec(cmb->device_disconnect_time);
  690. data->control_unit_queuing_time
  691. = time_to_nsec(cmb->control_unit_queuing_time);
  692. data->device_active_only_time
  693. = time_to_nsec(cmb->device_active_only_time);
  694. ret = 0;
  695. out:
  696. spin_unlock_irqrestore(cdev->ccwlock, flags);
  697. return ret;
  698. }
  699. static void reset_cmb(struct ccw_device *cdev)
  700. {
  701. cmf_generic_reset(cdev);
  702. }
  703. static void * align_cmb(void *area)
  704. {
  705. return area;
  706. }
  707. static struct attribute_group cmf_attr_group;
  708. static struct cmb_operations cmbops_basic = {
  709. .alloc = alloc_cmb,
  710. .free = free_cmb,
  711. .set = set_cmb,
  712. .read = read_cmb,
  713. .readall = readall_cmb,
  714. .reset = reset_cmb,
  715. .align = align_cmb,
  716. .attr_group = &cmf_attr_group,
  717. };
  718. /* ******** extended cmb handling ********/
  719. /**
  720. * struct cmbe - extended channel measurement block
  721. * @ssch_rsch_count: number of ssch and rsch
  722. * @sample_count: number of samples
  723. * @device_connect_time: time of device connect
  724. * @function_pending_time: time of function pending
  725. * @device_disconnect_time: time of device disconnect
  726. * @control_unit_queuing_time: time of control unit queuing
  727. * @device_active_only_time: time of device active only
  728. * @device_busy_time: time of device busy
  729. * @initial_command_response_time: initial command response time
  730. * @reserved: unused
  731. *
  732. * The measurement block as used by the hardware. May be in any 64 bit physical
  733. * location.
  734. * The fields are described further in z/Architecture Principles of Operation,
  735. * third edition, chapter 17.
  736. */
  737. struct cmbe {
  738. u32 ssch_rsch_count;
  739. u32 sample_count;
  740. u32 device_connect_time;
  741. u32 function_pending_time;
  742. u32 device_disconnect_time;
  743. u32 control_unit_queuing_time;
  744. u32 device_active_only_time;
  745. u32 device_busy_time;
  746. u32 initial_command_response_time;
  747. u32 reserved[7];
  748. };
  749. /*
  750. * kmalloc only guarantees 8 byte alignment, but we need cmbe
  751. * pointers to be naturally aligned. Make sure to allocate
  752. * enough space for two cmbes.
  753. */
  754. static inline struct cmbe *cmbe_align(struct cmbe *c)
  755. {
  756. unsigned long addr;
  757. addr = ((unsigned long)c + sizeof (struct cmbe) - sizeof(long)) &
  758. ~(sizeof (struct cmbe) - sizeof(long));
  759. return (struct cmbe*)addr;
  760. }
  761. static int alloc_cmbe(struct ccw_device *cdev)
  762. {
  763. struct cmbe *cmbe;
  764. struct cmb_data *cmb_data;
  765. int ret;
  766. cmbe = kzalloc (sizeof (*cmbe) * 2, GFP_KERNEL);
  767. if (!cmbe)
  768. return -ENOMEM;
  769. cmb_data = kzalloc(sizeof(struct cmb_data), GFP_KERNEL);
  770. if (!cmb_data) {
  771. ret = -ENOMEM;
  772. goto out_free;
  773. }
  774. cmb_data->last_block = kzalloc(sizeof(struct cmbe), GFP_KERNEL);
  775. if (!cmb_data->last_block) {
  776. ret = -ENOMEM;
  777. goto out_free;
  778. }
  779. cmb_data->size = sizeof(struct cmbe);
  780. spin_lock_irq(cdev->ccwlock);
  781. if (cdev->private->cmb) {
  782. spin_unlock_irq(cdev->ccwlock);
  783. ret = -EBUSY;
  784. goto out_free;
  785. }
  786. cmb_data->hw_block = cmbe;
  787. cdev->private->cmb = cmb_data;
  788. spin_unlock_irq(cdev->ccwlock);
  789. /* activate global measurement if this is the first channel */
  790. spin_lock(&cmb_area.lock);
  791. if (list_empty(&cmb_area.list))
  792. cmf_activate(NULL, 1);
  793. list_add_tail(&cdev->private->cmb_list, &cmb_area.list);
  794. spin_unlock(&cmb_area.lock);
  795. return 0;
  796. out_free:
  797. if (cmb_data)
  798. kfree(cmb_data->last_block);
  799. kfree(cmb_data);
  800. kfree(cmbe);
  801. return ret;
  802. }
  803. static void free_cmbe(struct ccw_device *cdev)
  804. {
  805. struct cmb_data *cmb_data;
  806. spin_lock_irq(cdev->ccwlock);
  807. cmb_data = cdev->private->cmb;
  808. cdev->private->cmb = NULL;
  809. if (cmb_data)
  810. kfree(cmb_data->last_block);
  811. kfree(cmb_data);
  812. spin_unlock_irq(cdev->ccwlock);
  813. /* deactivate global measurement if this is the last channel */
  814. spin_lock(&cmb_area.lock);
  815. list_del_init(&cdev->private->cmb_list);
  816. if (list_empty(&cmb_area.list))
  817. cmf_activate(NULL, 0);
  818. spin_unlock(&cmb_area.lock);
  819. }
  820. static int set_cmbe(struct ccw_device *cdev, u32 mme)
  821. {
  822. unsigned long mba;
  823. struct cmb_data *cmb_data;
  824. unsigned long flags;
  825. spin_lock_irqsave(cdev->ccwlock, flags);
  826. if (!cdev->private->cmb) {
  827. spin_unlock_irqrestore(cdev->ccwlock, flags);
  828. return -EINVAL;
  829. }
  830. cmb_data = cdev->private->cmb;
  831. mba = mme ? (unsigned long) cmbe_align(cmb_data->hw_block) : 0;
  832. spin_unlock_irqrestore(cdev->ccwlock, flags);
  833. return set_schib_wait(cdev, mme, 1, mba);
  834. }
  835. static u64 read_cmbe(struct ccw_device *cdev, int index)
  836. {
  837. struct cmbe *cmb;
  838. struct cmb_data *cmb_data;
  839. u32 val;
  840. int ret;
  841. unsigned long flags;
  842. ret = cmf_cmb_copy_wait(cdev);
  843. if (ret < 0)
  844. return 0;
  845. spin_lock_irqsave(cdev->ccwlock, flags);
  846. cmb_data = cdev->private->cmb;
  847. if (!cmb_data) {
  848. ret = 0;
  849. goto out;
  850. }
  851. cmb = cmb_data->last_block;
  852. switch (index) {
  853. case cmb_ssch_rsch_count:
  854. ret = cmb->ssch_rsch_count;
  855. goto out;
  856. case cmb_sample_count:
  857. ret = cmb->sample_count;
  858. goto out;
  859. case cmb_device_connect_time:
  860. val = cmb->device_connect_time;
  861. break;
  862. case cmb_function_pending_time:
  863. val = cmb->function_pending_time;
  864. break;
  865. case cmb_device_disconnect_time:
  866. val = cmb->device_disconnect_time;
  867. break;
  868. case cmb_control_unit_queuing_time:
  869. val = cmb->control_unit_queuing_time;
  870. break;
  871. case cmb_device_active_only_time:
  872. val = cmb->device_active_only_time;
  873. break;
  874. case cmb_device_busy_time:
  875. val = cmb->device_busy_time;
  876. break;
  877. case cmb_initial_command_response_time:
  878. val = cmb->initial_command_response_time;
  879. break;
  880. default:
  881. ret = 0;
  882. goto out;
  883. }
  884. ret = time_to_avg_nsec(val, cmb->sample_count);
  885. out:
  886. spin_unlock_irqrestore(cdev->ccwlock, flags);
  887. return ret;
  888. }
  889. static int readall_cmbe(struct ccw_device *cdev, struct cmbdata *data)
  890. {
  891. struct cmbe *cmb;
  892. struct cmb_data *cmb_data;
  893. u64 time;
  894. unsigned long flags;
  895. int ret;
  896. ret = cmf_cmb_copy_wait(cdev);
  897. if (ret < 0)
  898. return ret;
  899. spin_lock_irqsave(cdev->ccwlock, flags);
  900. cmb_data = cdev->private->cmb;
  901. if (!cmb_data) {
  902. ret = -ENODEV;
  903. goto out;
  904. }
  905. if (cmb_data->last_update == 0) {
  906. ret = -EAGAIN;
  907. goto out;
  908. }
  909. time = cmb_data->last_update - cdev->private->cmb_start_time;
  910. memset (data, 0, sizeof(struct cmbdata));
  911. /* we only know values before device_busy_time */
  912. data->size = offsetof(struct cmbdata, device_busy_time);
  913. /* conver to nanoseconds */
  914. data->elapsed_time = (time * 1000) >> 12;
  915. cmb = cmb_data->last_block;
  916. /* copy data to new structure */
  917. data->ssch_rsch_count = cmb->ssch_rsch_count;
  918. data->sample_count = cmb->sample_count;
  919. /* time fields are converted to nanoseconds while copying */
  920. data->device_connect_time = time_to_nsec(cmb->device_connect_time);
  921. data->function_pending_time = time_to_nsec(cmb->function_pending_time);
  922. data->device_disconnect_time =
  923. time_to_nsec(cmb->device_disconnect_time);
  924. data->control_unit_queuing_time
  925. = time_to_nsec(cmb->control_unit_queuing_time);
  926. data->device_active_only_time
  927. = time_to_nsec(cmb->device_active_only_time);
  928. data->device_busy_time = time_to_nsec(cmb->device_busy_time);
  929. data->initial_command_response_time
  930. = time_to_nsec(cmb->initial_command_response_time);
  931. ret = 0;
  932. out:
  933. spin_unlock_irqrestore(cdev->ccwlock, flags);
  934. return ret;
  935. }
  936. static void reset_cmbe(struct ccw_device *cdev)
  937. {
  938. cmf_generic_reset(cdev);
  939. }
  940. static void * align_cmbe(void *area)
  941. {
  942. return cmbe_align(area);
  943. }
  944. static struct attribute_group cmf_attr_group_ext;
  945. static struct cmb_operations cmbops_extended = {
  946. .alloc = alloc_cmbe,
  947. .free = free_cmbe,
  948. .set = set_cmbe,
  949. .read = read_cmbe,
  950. .readall = readall_cmbe,
  951. .reset = reset_cmbe,
  952. .align = align_cmbe,
  953. .attr_group = &cmf_attr_group_ext,
  954. };
  955. static ssize_t cmb_show_attr(struct device *dev, char *buf, enum cmb_index idx)
  956. {
  957. return sprintf(buf, "%lld\n",
  958. (unsigned long long) cmf_read(to_ccwdev(dev), idx));
  959. }
  960. static ssize_t cmb_show_avg_sample_interval(struct device *dev,
  961. struct device_attribute *attr,
  962. char *buf)
  963. {
  964. struct ccw_device *cdev;
  965. long interval;
  966. unsigned long count;
  967. struct cmb_data *cmb_data;
  968. cdev = to_ccwdev(dev);
  969. count = cmf_read(cdev, cmb_sample_count);
  970. spin_lock_irq(cdev->ccwlock);
  971. cmb_data = cdev->private->cmb;
  972. if (count) {
  973. interval = cmb_data->last_update -
  974. cdev->private->cmb_start_time;
  975. interval = (interval * 1000) >> 12;
  976. interval /= count;
  977. } else
  978. interval = -1;
  979. spin_unlock_irq(cdev->ccwlock);
  980. return sprintf(buf, "%ld\n", interval);
  981. }
  982. static ssize_t cmb_show_avg_utilization(struct device *dev,
  983. struct device_attribute *attr,
  984. char *buf)
  985. {
  986. struct cmbdata data;
  987. u64 utilization;
  988. unsigned long t, u;
  989. int ret;
  990. ret = cmf_readall(to_ccwdev(dev), &data);
  991. if (ret == -EAGAIN || ret == -ENODEV)
  992. /* No data (yet/currently) available to use for calculation. */
  993. return sprintf(buf, "n/a\n");
  994. else if (ret)
  995. return ret;
  996. utilization = data.device_connect_time +
  997. data.function_pending_time +
  998. data.device_disconnect_time;
  999. /* shift to avoid long long division */
  1000. while (-1ul < (data.elapsed_time | utilization)) {
  1001. utilization >>= 8;
  1002. data.elapsed_time >>= 8;
  1003. }
  1004. /* calculate value in 0.1 percent units */
  1005. t = (unsigned long) data.elapsed_time / 1000;
  1006. u = (unsigned long) utilization / t;
  1007. return sprintf(buf, "%02ld.%01ld%%\n", u/ 10, u - (u/ 10) * 10);
  1008. }
  1009. #define cmf_attr(name) \
  1010. static ssize_t show_##name(struct device *dev, \
  1011. struct device_attribute *attr, char *buf) \
  1012. { return cmb_show_attr((dev), buf, cmb_##name); } \
  1013. static DEVICE_ATTR(name, 0444, show_##name, NULL);
  1014. #define cmf_attr_avg(name) \
  1015. static ssize_t show_avg_##name(struct device *dev, \
  1016. struct device_attribute *attr, char *buf) \
  1017. { return cmb_show_attr((dev), buf, cmb_##name); } \
  1018. static DEVICE_ATTR(avg_##name, 0444, show_avg_##name, NULL);
  1019. cmf_attr(ssch_rsch_count);
  1020. cmf_attr(sample_count);
  1021. cmf_attr_avg(device_connect_time);
  1022. cmf_attr_avg(function_pending_time);
  1023. cmf_attr_avg(device_disconnect_time);
  1024. cmf_attr_avg(control_unit_queuing_time);
  1025. cmf_attr_avg(device_active_only_time);
  1026. cmf_attr_avg(device_busy_time);
  1027. cmf_attr_avg(initial_command_response_time);
  1028. static DEVICE_ATTR(avg_sample_interval, 0444, cmb_show_avg_sample_interval,
  1029. NULL);
  1030. static DEVICE_ATTR(avg_utilization, 0444, cmb_show_avg_utilization, NULL);
  1031. static struct attribute *cmf_attributes[] = {
  1032. &dev_attr_avg_sample_interval.attr,
  1033. &dev_attr_avg_utilization.attr,
  1034. &dev_attr_ssch_rsch_count.attr,
  1035. &dev_attr_sample_count.attr,
  1036. &dev_attr_avg_device_connect_time.attr,
  1037. &dev_attr_avg_function_pending_time.attr,
  1038. &dev_attr_avg_device_disconnect_time.attr,
  1039. &dev_attr_avg_control_unit_queuing_time.attr,
  1040. &dev_attr_avg_device_active_only_time.attr,
  1041. NULL,
  1042. };
  1043. static struct attribute_group cmf_attr_group = {
  1044. .name = "cmf",
  1045. .attrs = cmf_attributes,
  1046. };
  1047. static struct attribute *cmf_attributes_ext[] = {
  1048. &dev_attr_avg_sample_interval.attr,
  1049. &dev_attr_avg_utilization.attr,
  1050. &dev_attr_ssch_rsch_count.attr,
  1051. &dev_attr_sample_count.attr,
  1052. &dev_attr_avg_device_connect_time.attr,
  1053. &dev_attr_avg_function_pending_time.attr,
  1054. &dev_attr_avg_device_disconnect_time.attr,
  1055. &dev_attr_avg_control_unit_queuing_time.attr,
  1056. &dev_attr_avg_device_active_only_time.attr,
  1057. &dev_attr_avg_device_busy_time.attr,
  1058. &dev_attr_avg_initial_command_response_time.attr,
  1059. NULL,
  1060. };
  1061. static struct attribute_group cmf_attr_group_ext = {
  1062. .name = "cmf",
  1063. .attrs = cmf_attributes_ext,
  1064. };
  1065. static ssize_t cmb_enable_show(struct device *dev,
  1066. struct device_attribute *attr,
  1067. char *buf)
  1068. {
  1069. return sprintf(buf, "%d\n", to_ccwdev(dev)->private->cmb ? 1 : 0);
  1070. }
  1071. static ssize_t cmb_enable_store(struct device *dev,
  1072. struct device_attribute *attr, const char *buf,
  1073. size_t c)
  1074. {
  1075. struct ccw_device *cdev;
  1076. int ret;
  1077. unsigned long val;
  1078. ret = strict_strtoul(buf, 16, &val);
  1079. if (ret)
  1080. return ret;
  1081. cdev = to_ccwdev(dev);
  1082. switch (val) {
  1083. case 0:
  1084. ret = disable_cmf(cdev);
  1085. break;
  1086. case 1:
  1087. ret = enable_cmf(cdev);
  1088. break;
  1089. }
  1090. return c;
  1091. }
  1092. DEVICE_ATTR(cmb_enable, 0644, cmb_enable_show, cmb_enable_store);
  1093. /**
  1094. * enable_cmf() - switch on the channel measurement for a specific device
  1095. * @cdev: The ccw device to be enabled
  1096. *
  1097. * Returns %0 for success or a negative error value.
  1098. *
  1099. * Context:
  1100. * non-atomic
  1101. */
  1102. int enable_cmf(struct ccw_device *cdev)
  1103. {
  1104. int ret;
  1105. ret = cmbops->alloc(cdev);
  1106. cmbops->reset(cdev);
  1107. if (ret)
  1108. return ret;
  1109. ret = cmbops->set(cdev, 2);
  1110. if (ret) {
  1111. cmbops->free(cdev);
  1112. return ret;
  1113. }
  1114. ret = sysfs_create_group(&cdev->dev.kobj, cmbops->attr_group);
  1115. if (!ret)
  1116. return 0;
  1117. cmbops->set(cdev, 0); //FIXME: this can fail
  1118. cmbops->free(cdev);
  1119. return ret;
  1120. }
  1121. /**
  1122. * disable_cmf() - switch off the channel measurement for a specific device
  1123. * @cdev: The ccw device to be disabled
  1124. *
  1125. * Returns %0 for success or a negative error value.
  1126. *
  1127. * Context:
  1128. * non-atomic
  1129. */
  1130. int disable_cmf(struct ccw_device *cdev)
  1131. {
  1132. int ret;
  1133. ret = cmbops->set(cdev, 0);
  1134. if (ret)
  1135. return ret;
  1136. cmbops->free(cdev);
  1137. sysfs_remove_group(&cdev->dev.kobj, cmbops->attr_group);
  1138. return ret;
  1139. }
  1140. /**
  1141. * cmf_read() - read one value from the current channel measurement block
  1142. * @cdev: the channel to be read
  1143. * @index: the index of the value to be read
  1144. *
  1145. * Returns the value read or %0 if the value cannot be read.
  1146. *
  1147. * Context:
  1148. * any
  1149. */
  1150. u64 cmf_read(struct ccw_device *cdev, int index)
  1151. {
  1152. return cmbops->read(cdev, index);
  1153. }
  1154. /**
  1155. * cmf_readall() - read the current channel measurement block
  1156. * @cdev: the channel to be read
  1157. * @data: a pointer to a data block that will be filled
  1158. *
  1159. * Returns %0 on success, a negative error value otherwise.
  1160. *
  1161. * Context:
  1162. * any
  1163. */
  1164. int cmf_readall(struct ccw_device *cdev, struct cmbdata *data)
  1165. {
  1166. return cmbops->readall(cdev, data);
  1167. }
  1168. /* Reenable cmf when a disconnected device becomes available again. */
  1169. int cmf_reenable(struct ccw_device *cdev)
  1170. {
  1171. cmbops->reset(cdev);
  1172. return cmbops->set(cdev, 2);
  1173. }
  1174. static int __init init_cmf(void)
  1175. {
  1176. char *format_string;
  1177. char *detect_string = "parameter";
  1178. /*
  1179. * If the user did not give a parameter, see if we are running on a
  1180. * machine supporting extended measurement blocks, otherwise fall back
  1181. * to basic mode.
  1182. */
  1183. if (format == CMF_AUTODETECT) {
  1184. if (!css_general_characteristics.ext_mb) {
  1185. format = CMF_BASIC;
  1186. } else {
  1187. format = CMF_EXTENDED;
  1188. }
  1189. detect_string = "autodetected";
  1190. } else {
  1191. detect_string = "parameter";
  1192. }
  1193. switch (format) {
  1194. case CMF_BASIC:
  1195. format_string = "basic";
  1196. cmbops = &cmbops_basic;
  1197. break;
  1198. case CMF_EXTENDED:
  1199. format_string = "extended";
  1200. cmbops = &cmbops_extended;
  1201. break;
  1202. default:
  1203. return 1;
  1204. }
  1205. printk(KERN_INFO "cio: Channel measurement facility using %s "
  1206. "format (%s)\n", format_string, detect_string);
  1207. return 0;
  1208. }
  1209. module_init(init_cmf);
  1210. MODULE_AUTHOR("Arnd Bergmann <arndb@de.ibm.com>");
  1211. MODULE_LICENSE("GPL");
  1212. MODULE_DESCRIPTION("channel measurement facility base driver\n"
  1213. "Copyright 2003 IBM Corporation\n");
  1214. EXPORT_SYMBOL_GPL(enable_cmf);
  1215. EXPORT_SYMBOL_GPL(disable_cmf);
  1216. EXPORT_SYMBOL_GPL(cmf_read);
  1217. EXPORT_SYMBOL_GPL(cmf_readall);