dasd_int.h 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794
  1. /*
  2. * Author(s)......: Holger Smolinski <Holger.Smolinski@de.ibm.com>
  3. * Horst Hummel <Horst.Hummel@de.ibm.com>
  4. * Martin Schwidefsky <schwidefsky@de.ibm.com>
  5. * Bugreports.to..: <Linux390@de.ibm.com>
  6. * Copyright IBM Corp. 1999, 2009
  7. */
  8. #ifndef DASD_INT_H
  9. #define DASD_INT_H
  10. /* we keep old device allocation scheme; IOW, minors are still in 0..255 */
  11. #define DASD_PER_MAJOR (1U << (MINORBITS - DASD_PARTN_BITS))
  12. #define DASD_PARTN_MASK ((1 << DASD_PARTN_BITS) - 1)
  13. /*
  14. * States a dasd device can have:
  15. * new: the dasd_device structure is allocated.
  16. * known: the discipline for the device is identified.
  17. * basic: the device can do basic i/o.
  18. * unfmt: the device could not be analyzed (format is unknown).
  19. * ready: partition detection is done and the device is can do block io.
  20. * online: the device accepts requests from the block device queue.
  21. *
  22. * Things to do for startup state transitions:
  23. * new -> known: find discipline for the device and create devfs entries.
  24. * known -> basic: request irq line for the device.
  25. * basic -> ready: do the initial analysis, e.g. format detection,
  26. * do block device setup and detect partitions.
  27. * ready -> online: schedule the device tasklet.
  28. * Things to do for shutdown state transitions:
  29. * online -> ready: just set the new device state.
  30. * ready -> basic: flush requests from the block device layer, clear
  31. * partition information and reset format information.
  32. * basic -> known: terminate all requests and free irq.
  33. * known -> new: remove devfs entries and forget discipline.
  34. */
  35. #define DASD_STATE_NEW 0
  36. #define DASD_STATE_KNOWN 1
  37. #define DASD_STATE_BASIC 2
  38. #define DASD_STATE_UNFMT 3
  39. #define DASD_STATE_READY 4
  40. #define DASD_STATE_ONLINE 5
  41. #include <linux/module.h>
  42. #include <linux/wait.h>
  43. #include <linux/blkdev.h>
  44. #include <linux/genhd.h>
  45. #include <linux/hdreg.h>
  46. #include <linux/interrupt.h>
  47. #include <linux/log2.h>
  48. #include <asm/ccwdev.h>
  49. #include <linux/workqueue.h>
  50. #include <asm/debug.h>
  51. #include <asm/dasd.h>
  52. #include <asm/idals.h>
  53. /* DASD discipline magic */
  54. #define DASD_ECKD_MAGIC 0xC5C3D2C4
  55. #define DASD_DIAG_MAGIC 0xC4C9C1C7
  56. #define DASD_FBA_MAGIC 0xC6C2C140
  57. /*
  58. * SECTION: Type definitions
  59. */
  60. struct dasd_device;
  61. struct dasd_block;
  62. /* BIT DEFINITIONS FOR SENSE DATA */
  63. #define DASD_SENSE_BIT_0 0x80
  64. #define DASD_SENSE_BIT_1 0x40
  65. #define DASD_SENSE_BIT_2 0x20
  66. #define DASD_SENSE_BIT_3 0x10
  67. /* BIT DEFINITIONS FOR SIM SENSE */
  68. #define DASD_SIM_SENSE 0x0F
  69. #define DASD_SIM_MSG_TO_OP 0x03
  70. #define DASD_SIM_LOG 0x0C
  71. /* lock class for nested cdev lock */
  72. #define CDEV_NESTED_FIRST 1
  73. #define CDEV_NESTED_SECOND 2
  74. /*
  75. * SECTION: MACROs for klogd and s390 debug feature (dbf)
  76. */
  77. #define DBF_DEV_EVENT(d_level, d_device, d_str, d_data...) \
  78. do { \
  79. debug_sprintf_event(d_device->debug_area, \
  80. d_level, \
  81. d_str "\n", \
  82. d_data); \
  83. } while(0)
  84. #define DBF_DEV_EXC(d_level, d_device, d_str, d_data...) \
  85. do { \
  86. debug_sprintf_exception(d_device->debug_area, \
  87. d_level, \
  88. d_str "\n", \
  89. d_data); \
  90. } while(0)
  91. #define DBF_EVENT(d_level, d_str, d_data...)\
  92. do { \
  93. debug_sprintf_event(dasd_debug_area, \
  94. d_level,\
  95. d_str "\n", \
  96. d_data); \
  97. } while(0)
  98. #define DBF_EVENT_DEVID(d_level, d_cdev, d_str, d_data...) \
  99. do { \
  100. struct ccw_dev_id __dev_id; \
  101. ccw_device_get_id(d_cdev, &__dev_id); \
  102. debug_sprintf_event(dasd_debug_area, \
  103. d_level, \
  104. "0.%x.%04x " d_str "\n", \
  105. __dev_id.ssid, __dev_id.devno, d_data); \
  106. } while (0)
  107. #define DBF_EXC(d_level, d_str, d_data...)\
  108. do { \
  109. debug_sprintf_exception(dasd_debug_area, \
  110. d_level,\
  111. d_str "\n", \
  112. d_data); \
  113. } while(0)
  114. /* limit size for an errorstring */
  115. #define ERRORLENGTH 30
  116. /* definition of dbf debug levels */
  117. #define DBF_EMERG 0 /* system is unusable */
  118. #define DBF_ALERT 1 /* action must be taken immediately */
  119. #define DBF_CRIT 2 /* critical conditions */
  120. #define DBF_ERR 3 /* error conditions */
  121. #define DBF_WARNING 4 /* warning conditions */
  122. #define DBF_NOTICE 5 /* normal but significant condition */
  123. #define DBF_INFO 6 /* informational */
  124. #define DBF_DEBUG 6 /* debug-level messages */
  125. /* messages to be written via klogd and dbf */
  126. #define DEV_MESSAGE(d_loglevel,d_device,d_string,d_args...)\
  127. do { \
  128. printk(d_loglevel PRINTK_HEADER " %s: " d_string "\n", \
  129. dev_name(&d_device->cdev->dev), d_args); \
  130. DBF_DEV_EVENT(DBF_ALERT, d_device, d_string, d_args); \
  131. } while(0)
  132. #define MESSAGE(d_loglevel,d_string,d_args...)\
  133. do { \
  134. printk(d_loglevel PRINTK_HEADER " " d_string "\n", d_args); \
  135. DBF_EVENT(DBF_ALERT, d_string, d_args); \
  136. } while(0)
  137. /* messages to be written via klogd only */
  138. #define DEV_MESSAGE_LOG(d_loglevel,d_device,d_string,d_args...)\
  139. do { \
  140. printk(d_loglevel PRINTK_HEADER " %s: " d_string "\n", \
  141. dev_name(&d_device->cdev->dev), d_args); \
  142. } while(0)
  143. #define MESSAGE_LOG(d_loglevel,d_string,d_args...)\
  144. do { \
  145. printk(d_loglevel PRINTK_HEADER " " d_string "\n", d_args); \
  146. } while(0)
  147. struct dasd_ccw_req {
  148. unsigned int magic; /* Eye catcher */
  149. struct list_head devlist; /* for dasd_device request queue */
  150. struct list_head blocklist; /* for dasd_block request queue */
  151. /* Where to execute what... */
  152. struct dasd_block *block; /* the originating block device */
  153. struct dasd_device *memdev; /* the device used to allocate this */
  154. struct dasd_device *startdev; /* device the request is started on */
  155. void *cpaddr; /* address of ccw or tcw */
  156. unsigned char cpmode; /* 0 = cmd mode, 1 = itcw */
  157. char status; /* status of this request */
  158. short retries; /* A retry counter */
  159. unsigned long flags; /* flags of this request */
  160. /* ... and how */
  161. unsigned long starttime; /* jiffies time of request start */
  162. unsigned long expires; /* expiration period in jiffies */
  163. char lpm; /* logical path mask */
  164. void *data; /* pointer to data area */
  165. /* these are important for recovering erroneous requests */
  166. int intrc; /* internal error, e.g. from start_IO */
  167. struct irb irb; /* device status in case of an error */
  168. struct dasd_ccw_req *refers; /* ERP-chain queueing. */
  169. void *function; /* originating ERP action */
  170. /* these are for statistics only */
  171. unsigned long long buildclk; /* TOD-clock of request generation */
  172. unsigned long long startclk; /* TOD-clock of request start */
  173. unsigned long long stopclk; /* TOD-clock of request interrupt */
  174. unsigned long long endclk; /* TOD-clock of request termination */
  175. /* Callback that is called after reaching final status. */
  176. void (*callback)(struct dasd_ccw_req *, void *data);
  177. void *callback_data;
  178. };
  179. /*
  180. * dasd_ccw_req -> status can be:
  181. */
  182. #define DASD_CQR_FILLED 0x00 /* request is ready to be processed */
  183. #define DASD_CQR_DONE 0x01 /* request is completed successfully */
  184. #define DASD_CQR_NEED_ERP 0x02 /* request needs recovery action */
  185. #define DASD_CQR_IN_ERP 0x03 /* request is in recovery */
  186. #define DASD_CQR_FAILED 0x04 /* request is finally failed */
  187. #define DASD_CQR_TERMINATED 0x05 /* request was stopped by driver */
  188. #define DASD_CQR_QUEUED 0x80 /* request is queued to be processed */
  189. #define DASD_CQR_IN_IO 0x81 /* request is currently in IO */
  190. #define DASD_CQR_ERROR 0x82 /* request is completed with error */
  191. #define DASD_CQR_CLEAR_PENDING 0x83 /* request is clear pending */
  192. #define DASD_CQR_CLEARED 0x84 /* request was cleared */
  193. #define DASD_CQR_SUCCESS 0x85 /* request was successful */
  194. /* default expiration time*/
  195. #define DASD_EXPIRES 300
  196. #define DASD_EXPIRES_MAX 40000000
  197. /* per dasd_ccw_req flags */
  198. #define DASD_CQR_FLAGS_USE_ERP 0 /* use ERP for this request */
  199. #define DASD_CQR_FLAGS_FAILFAST 1 /* FAILFAST */
  200. #define DASD_CQR_VERIFY_PATH 2 /* path verification request */
  201. #define DASD_CQR_ALLOW_SLOCK 3 /* Try this request even when lock was
  202. * stolen. Should not be combined with
  203. * DASD_CQR_FLAGS_USE_ERP
  204. */
  205. /* Signature for error recovery functions. */
  206. typedef struct dasd_ccw_req *(*dasd_erp_fn_t) (struct dasd_ccw_req *);
  207. /*
  208. * Unique identifier for dasd device.
  209. */
  210. #define UA_NOT_CONFIGURED 0x00
  211. #define UA_BASE_DEVICE 0x01
  212. #define UA_BASE_PAV_ALIAS 0x02
  213. #define UA_HYPER_PAV_ALIAS 0x03
  214. struct dasd_uid {
  215. __u8 type;
  216. char vendor[4];
  217. char serial[15];
  218. __u16 ssid;
  219. __u8 real_unit_addr;
  220. __u8 base_unit_addr;
  221. char vduit[33];
  222. };
  223. /*
  224. * the struct dasd_discipline is
  225. * sth like a table of virtual functions, if you think of dasd_eckd
  226. * inheriting dasd...
  227. * no, currently we are not planning to reimplement the driver in C++
  228. */
  229. struct dasd_discipline {
  230. struct module *owner;
  231. char ebcname[8]; /* a name used for tagging and printks */
  232. char name[8]; /* a name used for tagging and printks */
  233. int max_blocks; /* maximum number of blocks to be chained */
  234. struct list_head list; /* used for list of disciplines */
  235. /*
  236. * Device recognition functions. check_device is used to verify
  237. * the sense data and the information returned by read device
  238. * characteristics. It returns 0 if the discipline can be used
  239. * for the device in question. uncheck_device is called during
  240. * device shutdown to deregister a device from its discipline.
  241. */
  242. int (*check_device) (struct dasd_device *);
  243. void (*uncheck_device) (struct dasd_device *);
  244. /*
  245. * do_analysis is used in the step from device state "basic" to
  246. * state "accept". It returns 0 if the device can be made ready,
  247. * it returns -EMEDIUMTYPE if the device can't be made ready or
  248. * -EAGAIN if do_analysis started a ccw that needs to complete
  249. * before the analysis may be repeated.
  250. */
  251. int (*do_analysis) (struct dasd_block *);
  252. /*
  253. * This function is called, when new paths become available.
  254. * Disciplins may use this callback to do necessary setup work,
  255. * e.g. verify that new path is compatible with the current
  256. * configuration.
  257. */
  258. int (*verify_path)(struct dasd_device *, __u8);
  259. /*
  260. * Last things to do when a device is set online, and first things
  261. * when it is set offline.
  262. */
  263. int (*ready_to_online) (struct dasd_device *);
  264. int (*online_to_ready) (struct dasd_device *);
  265. /*
  266. * Device operation functions. build_cp creates a ccw chain for
  267. * a block device request, start_io starts the request and
  268. * term_IO cancels it (e.g. in case of a timeout). format_device
  269. * returns a ccw chain to be used to format the device.
  270. * handle_terminated_request allows to examine a cqr and prepare
  271. * it for retry.
  272. */
  273. struct dasd_ccw_req *(*build_cp) (struct dasd_device *,
  274. struct dasd_block *,
  275. struct request *);
  276. int (*start_IO) (struct dasd_ccw_req *);
  277. int (*term_IO) (struct dasd_ccw_req *);
  278. void (*handle_terminated_request) (struct dasd_ccw_req *);
  279. struct dasd_ccw_req *(*format_device) (struct dasd_device *,
  280. struct format_data_t *);
  281. int (*free_cp) (struct dasd_ccw_req *, struct request *);
  282. /*
  283. * Error recovery functions. examine_error() returns a value that
  284. * indicates what to do for an error condition. If examine_error()
  285. * returns 'dasd_era_recover' erp_action() is called to create a
  286. * special error recovery ccw. erp_postaction() is called after
  287. * an error recovery ccw has finished its execution. dump_sense
  288. * is called for every error condition to print the sense data
  289. * to the console.
  290. */
  291. dasd_erp_fn_t(*erp_action) (struct dasd_ccw_req *);
  292. dasd_erp_fn_t(*erp_postaction) (struct dasd_ccw_req *);
  293. void (*dump_sense) (struct dasd_device *, struct dasd_ccw_req *,
  294. struct irb *);
  295. void (*dump_sense_dbf) (struct dasd_device *, struct irb *, char *);
  296. void (*check_for_device_change) (struct dasd_device *,
  297. struct dasd_ccw_req *,
  298. struct irb *);
  299. /* i/o control functions. */
  300. int (*fill_geometry) (struct dasd_block *, struct hd_geometry *);
  301. int (*fill_info) (struct dasd_device *, struct dasd_information2_t *);
  302. int (*ioctl) (struct dasd_block *, unsigned int, void __user *);
  303. /* suspend/resume functions */
  304. int (*freeze) (struct dasd_device *);
  305. int (*restore) (struct dasd_device *);
  306. /* reload device after state change */
  307. int (*reload) (struct dasd_device *);
  308. int (*get_uid) (struct dasd_device *, struct dasd_uid *);
  309. void (*kick_validate) (struct dasd_device *);
  310. };
  311. extern struct dasd_discipline *dasd_diag_discipline_pointer;
  312. /*
  313. * Notification numbers for extended error reporting notifications:
  314. * The DASD_EER_DISABLE notification is sent before a dasd_device (and it's
  315. * eer pointer) is freed. The error reporting module needs to do all necessary
  316. * cleanup steps.
  317. * The DASD_EER_TRIGGER notification sends the actual error reports (triggers).
  318. */
  319. #define DASD_EER_DISABLE 0
  320. #define DASD_EER_TRIGGER 1
  321. /* Trigger IDs for extended error reporting DASD_EER_TRIGGER notification */
  322. #define DASD_EER_FATALERROR 1
  323. #define DASD_EER_NOPATH 2
  324. #define DASD_EER_STATECHANGE 3
  325. #define DASD_EER_PPRCSUSPEND 4
  326. struct dasd_path {
  327. __u8 opm;
  328. __u8 tbvpm;
  329. __u8 ppm;
  330. __u8 npm;
  331. };
  332. struct dasd_profile_info {
  333. /* legacy part of profile data, as in dasd_profile_info_t */
  334. unsigned int dasd_io_reqs; /* number of requests processed */
  335. unsigned int dasd_io_sects; /* number of sectors processed */
  336. unsigned int dasd_io_secs[32]; /* histogram of request's sizes */
  337. unsigned int dasd_io_times[32]; /* histogram of requests's times */
  338. unsigned int dasd_io_timps[32]; /* h. of requests's times per sector */
  339. unsigned int dasd_io_time1[32]; /* hist. of time from build to start */
  340. unsigned int dasd_io_time2[32]; /* hist. of time from start to irq */
  341. unsigned int dasd_io_time2ps[32]; /* hist. of time from start to irq */
  342. unsigned int dasd_io_time3[32]; /* hist. of time from irq to end */
  343. unsigned int dasd_io_nr_req[32]; /* hist. of # of requests in chanq */
  344. /* new data */
  345. struct timespec starttod; /* time of start or last reset */
  346. unsigned int dasd_io_alias; /* requests using an alias */
  347. unsigned int dasd_io_tpm; /* requests using transport mode */
  348. unsigned int dasd_read_reqs; /* total number of read requests */
  349. unsigned int dasd_read_sects; /* total number read sectors */
  350. unsigned int dasd_read_alias; /* read request using an alias */
  351. unsigned int dasd_read_tpm; /* read requests in transport mode */
  352. unsigned int dasd_read_secs[32]; /* histogram of request's sizes */
  353. unsigned int dasd_read_times[32]; /* histogram of requests's times */
  354. unsigned int dasd_read_time1[32]; /* hist. time from build to start */
  355. unsigned int dasd_read_time2[32]; /* hist. of time from start to irq */
  356. unsigned int dasd_read_time3[32]; /* hist. of time from irq to end */
  357. unsigned int dasd_read_nr_req[32]; /* hist. of # of requests in chanq */
  358. };
  359. struct dasd_profile {
  360. struct dentry *dentry;
  361. struct dasd_profile_info *data;
  362. spinlock_t lock;
  363. };
  364. struct dasd_device {
  365. /* Block device stuff. */
  366. struct dasd_block *block;
  367. unsigned int devindex;
  368. unsigned long flags; /* per device flags */
  369. unsigned short features; /* copy of devmap-features (read-only!) */
  370. /* extended error reporting stuff (eer) */
  371. struct dasd_ccw_req *eer_cqr;
  372. /* Device discipline stuff. */
  373. struct dasd_discipline *discipline;
  374. struct dasd_discipline *base_discipline;
  375. char *private;
  376. struct dasd_path path_data;
  377. /* Device state and target state. */
  378. int state, target;
  379. struct mutex state_mutex;
  380. int stopped; /* device (ccw_device_start) was stopped */
  381. /* reference count. */
  382. atomic_t ref_count;
  383. /* ccw queue and memory for static ccw/erp buffers. */
  384. struct list_head ccw_queue;
  385. spinlock_t mem_lock;
  386. void *ccw_mem;
  387. void *erp_mem;
  388. struct list_head ccw_chunks;
  389. struct list_head erp_chunks;
  390. atomic_t tasklet_scheduled;
  391. struct tasklet_struct tasklet;
  392. struct work_struct kick_work;
  393. struct work_struct restore_device;
  394. struct work_struct reload_device;
  395. struct work_struct kick_validate;
  396. struct timer_list timer;
  397. debug_info_t *debug_area;
  398. struct ccw_device *cdev;
  399. /* hook for alias management */
  400. struct list_head alias_list;
  401. /* default expiration time in s */
  402. unsigned long default_expires;
  403. struct dentry *debugfs_dentry;
  404. struct dasd_profile profile;
  405. };
  406. struct dasd_block {
  407. /* Block device stuff. */
  408. struct gendisk *gdp;
  409. struct request_queue *request_queue;
  410. spinlock_t request_queue_lock;
  411. struct block_device *bdev;
  412. atomic_t open_count;
  413. unsigned long long blocks; /* size of volume in blocks */
  414. unsigned int bp_block; /* bytes per block */
  415. unsigned int s2b_shift; /* log2 (bp_block/512) */
  416. struct dasd_device *base;
  417. struct list_head ccw_queue;
  418. spinlock_t queue_lock;
  419. atomic_t tasklet_scheduled;
  420. struct tasklet_struct tasklet;
  421. struct timer_list timer;
  422. struct dentry *debugfs_dentry;
  423. struct dasd_profile profile;
  424. };
  425. /* reasons why device (ccw_device_start) was stopped */
  426. #define DASD_STOPPED_NOT_ACC 1 /* not accessible */
  427. #define DASD_STOPPED_QUIESCE 2 /* Quiesced */
  428. #define DASD_STOPPED_PENDING 4 /* long busy */
  429. #define DASD_STOPPED_DC_WAIT 8 /* disconnected, wait */
  430. #define DASD_STOPPED_SU 16 /* summary unit check handling */
  431. #define DASD_STOPPED_PM 32 /* pm state transition */
  432. #define DASD_UNRESUMED_PM 64 /* pm resume failed state */
  433. /* per device flags */
  434. #define DASD_FLAG_OFFLINE 3 /* device is in offline processing */
  435. #define DASD_FLAG_EER_SNSS 4 /* A SNSS is required */
  436. #define DASD_FLAG_EER_IN_USE 5 /* A SNSS request is running */
  437. #define DASD_FLAG_DEVICE_RO 6 /* The device itself is read-only. Don't
  438. * confuse this with the user specified
  439. * read-only feature.
  440. */
  441. #define DASD_FLAG_IS_RESERVED 7 /* The device is reserved */
  442. #define DASD_FLAG_LOCK_STOLEN 8 /* The device lock was stolen */
  443. #define DASD_FLAG_SUSPENDED 9 /* The device was suspended */
  444. #define DASD_FLAG_SAFE_OFFLINE 10 /* safe offline processing requested*/
  445. #define DASD_FLAG_SAFE_OFFLINE_RUNNING 11 /* safe offline running */
  446. void dasd_put_device_wake(struct dasd_device *);
  447. /*
  448. * Reference count inliners
  449. */
  450. static inline void
  451. dasd_get_device(struct dasd_device *device)
  452. {
  453. atomic_inc(&device->ref_count);
  454. }
  455. static inline void
  456. dasd_put_device(struct dasd_device *device)
  457. {
  458. if (atomic_dec_return(&device->ref_count) == 0)
  459. dasd_put_device_wake(device);
  460. }
  461. /*
  462. * The static memory in ccw_mem and erp_mem is managed by a sorted
  463. * list of free memory chunks.
  464. */
  465. struct dasd_mchunk
  466. {
  467. struct list_head list;
  468. unsigned long size;
  469. } __attribute__ ((aligned(8)));
  470. static inline void
  471. dasd_init_chunklist(struct list_head *chunk_list, void *mem,
  472. unsigned long size)
  473. {
  474. struct dasd_mchunk *chunk;
  475. INIT_LIST_HEAD(chunk_list);
  476. chunk = (struct dasd_mchunk *) mem;
  477. chunk->size = size - sizeof(struct dasd_mchunk);
  478. list_add(&chunk->list, chunk_list);
  479. }
  480. static inline void *
  481. dasd_alloc_chunk(struct list_head *chunk_list, unsigned long size)
  482. {
  483. struct dasd_mchunk *chunk, *tmp;
  484. size = (size + 7L) & -8L;
  485. list_for_each_entry(chunk, chunk_list, list) {
  486. if (chunk->size < size)
  487. continue;
  488. if (chunk->size > size + sizeof(struct dasd_mchunk)) {
  489. char *endaddr = (char *) (chunk + 1) + chunk->size;
  490. tmp = (struct dasd_mchunk *) (endaddr - size) - 1;
  491. tmp->size = size;
  492. chunk->size -= size + sizeof(struct dasd_mchunk);
  493. chunk = tmp;
  494. } else
  495. list_del(&chunk->list);
  496. return (void *) (chunk + 1);
  497. }
  498. return NULL;
  499. }
  500. static inline void
  501. dasd_free_chunk(struct list_head *chunk_list, void *mem)
  502. {
  503. struct dasd_mchunk *chunk, *tmp;
  504. struct list_head *p, *left;
  505. chunk = (struct dasd_mchunk *)
  506. ((char *) mem - sizeof(struct dasd_mchunk));
  507. /* Find out the left neighbour in chunk_list. */
  508. left = chunk_list;
  509. list_for_each(p, chunk_list) {
  510. if (list_entry(p, struct dasd_mchunk, list) > chunk)
  511. break;
  512. left = p;
  513. }
  514. /* Try to merge with right neighbour = next element from left. */
  515. if (left->next != chunk_list) {
  516. tmp = list_entry(left->next, struct dasd_mchunk, list);
  517. if ((char *) (chunk + 1) + chunk->size == (char *) tmp) {
  518. list_del(&tmp->list);
  519. chunk->size += tmp->size + sizeof(struct dasd_mchunk);
  520. }
  521. }
  522. /* Try to merge with left neighbour. */
  523. if (left != chunk_list) {
  524. tmp = list_entry(left, struct dasd_mchunk, list);
  525. if ((char *) (tmp + 1) + tmp->size == (char *) chunk) {
  526. tmp->size += chunk->size + sizeof(struct dasd_mchunk);
  527. return;
  528. }
  529. }
  530. __list_add(&chunk->list, left, left->next);
  531. }
  532. /*
  533. * Check if bsize is in { 512, 1024, 2048, 4096 }
  534. */
  535. static inline int
  536. dasd_check_blocksize(int bsize)
  537. {
  538. if (bsize < 512 || bsize > 4096 || !is_power_of_2(bsize))
  539. return -EMEDIUMTYPE;
  540. return 0;
  541. }
  542. /* externals in dasd.c */
  543. #define DASD_PROFILE_OFF 0
  544. #define DASD_PROFILE_ON 1
  545. #define DASD_PROFILE_GLOBAL_ONLY 2
  546. extern debug_info_t *dasd_debug_area;
  547. extern struct dasd_profile_info dasd_global_profile_data;
  548. extern unsigned int dasd_global_profile_level;
  549. extern const struct block_device_operations dasd_device_operations;
  550. extern struct kmem_cache *dasd_page_cache;
  551. struct dasd_ccw_req *
  552. dasd_kmalloc_request(int , int, int, struct dasd_device *);
  553. struct dasd_ccw_req *
  554. dasd_smalloc_request(int , int, int, struct dasd_device *);
  555. void dasd_kfree_request(struct dasd_ccw_req *, struct dasd_device *);
  556. void dasd_sfree_request(struct dasd_ccw_req *, struct dasd_device *);
  557. void dasd_wakeup_cb(struct dasd_ccw_req *, void *);
  558. static inline int
  559. dasd_kmalloc_set_cda(struct ccw1 *ccw, void *cda, struct dasd_device *device)
  560. {
  561. return set_normalized_cda(ccw, cda);
  562. }
  563. struct dasd_device *dasd_alloc_device(void);
  564. void dasd_free_device(struct dasd_device *);
  565. struct dasd_block *dasd_alloc_block(void);
  566. void dasd_free_block(struct dasd_block *);
  567. void dasd_enable_device(struct dasd_device *);
  568. void dasd_set_target_state(struct dasd_device *, int);
  569. void dasd_kick_device(struct dasd_device *);
  570. void dasd_restore_device(struct dasd_device *);
  571. void dasd_reload_device(struct dasd_device *);
  572. void dasd_add_request_head(struct dasd_ccw_req *);
  573. void dasd_add_request_tail(struct dasd_ccw_req *);
  574. int dasd_start_IO(struct dasd_ccw_req *);
  575. int dasd_term_IO(struct dasd_ccw_req *);
  576. void dasd_schedule_device_bh(struct dasd_device *);
  577. void dasd_schedule_block_bh(struct dasd_block *);
  578. int dasd_sleep_on(struct dasd_ccw_req *);
  579. int dasd_sleep_on_immediatly(struct dasd_ccw_req *);
  580. int dasd_sleep_on_interruptible(struct dasd_ccw_req *);
  581. void dasd_device_set_timer(struct dasd_device *, int);
  582. void dasd_device_clear_timer(struct dasd_device *);
  583. void dasd_block_set_timer(struct dasd_block *, int);
  584. void dasd_block_clear_timer(struct dasd_block *);
  585. int dasd_cancel_req(struct dasd_ccw_req *);
  586. int dasd_flush_device_queue(struct dasd_device *);
  587. int dasd_generic_probe (struct ccw_device *, struct dasd_discipline *);
  588. void dasd_generic_remove (struct ccw_device *cdev);
  589. int dasd_generic_set_online(struct ccw_device *, struct dasd_discipline *);
  590. int dasd_generic_set_offline (struct ccw_device *cdev);
  591. int dasd_generic_notify(struct ccw_device *, int);
  592. int dasd_generic_last_path_gone(struct dasd_device *);
  593. int dasd_generic_path_operational(struct dasd_device *);
  594. void dasd_generic_shutdown(struct ccw_device *);
  595. void dasd_generic_handle_state_change(struct dasd_device *);
  596. int dasd_generic_pm_freeze(struct ccw_device *);
  597. int dasd_generic_restore_device(struct ccw_device *);
  598. enum uc_todo dasd_generic_uc_handler(struct ccw_device *, struct irb *);
  599. void dasd_generic_path_event(struct ccw_device *, int *);
  600. int dasd_generic_verify_path(struct dasd_device *, __u8);
  601. int dasd_generic_read_dev_chars(struct dasd_device *, int, void *, int);
  602. char *dasd_get_sense(struct irb *);
  603. void dasd_device_set_stop_bits(struct dasd_device *, int);
  604. void dasd_device_remove_stop_bits(struct dasd_device *, int);
  605. int dasd_device_is_ro(struct dasd_device *);
  606. void dasd_profile_reset(struct dasd_profile *);
  607. int dasd_profile_on(struct dasd_profile *);
  608. void dasd_profile_off(struct dasd_profile *);
  609. void dasd_global_profile_reset(void);
  610. char *dasd_get_user_string(const char __user *, size_t);
  611. /* externals in dasd_devmap.c */
  612. extern int dasd_max_devindex;
  613. extern int dasd_probeonly;
  614. extern int dasd_autodetect;
  615. extern int dasd_nopav;
  616. extern int dasd_nofcx;
  617. int dasd_devmap_init(void);
  618. void dasd_devmap_exit(void);
  619. struct dasd_device *dasd_create_device(struct ccw_device *);
  620. void dasd_delete_device(struct dasd_device *);
  621. int dasd_get_feature(struct ccw_device *, int);
  622. int dasd_set_feature(struct ccw_device *, int, int);
  623. int dasd_add_sysfs_files(struct ccw_device *);
  624. void dasd_remove_sysfs_files(struct ccw_device *);
  625. struct dasd_device *dasd_device_from_cdev(struct ccw_device *);
  626. struct dasd_device *dasd_device_from_cdev_locked(struct ccw_device *);
  627. struct dasd_device *dasd_device_from_devindex(int);
  628. void dasd_add_link_to_gendisk(struct gendisk *, struct dasd_device *);
  629. struct dasd_device *dasd_device_from_gendisk(struct gendisk *);
  630. int dasd_parse(void);
  631. int dasd_busid_known(const char *);
  632. /* externals in dasd_gendisk.c */
  633. int dasd_gendisk_init(void);
  634. void dasd_gendisk_exit(void);
  635. int dasd_gendisk_alloc(struct dasd_block *);
  636. void dasd_gendisk_free(struct dasd_block *);
  637. int dasd_scan_partitions(struct dasd_block *);
  638. void dasd_destroy_partitions(struct dasd_block *);
  639. /* externals in dasd_ioctl.c */
  640. int dasd_ioctl(struct block_device *, fmode_t, unsigned int, unsigned long);
  641. /* externals in dasd_proc.c */
  642. int dasd_proc_init(void);
  643. void dasd_proc_exit(void);
  644. /* externals in dasd_erp.c */
  645. struct dasd_ccw_req *dasd_default_erp_action(struct dasd_ccw_req *);
  646. struct dasd_ccw_req *dasd_default_erp_postaction(struct dasd_ccw_req *);
  647. struct dasd_ccw_req *dasd_alloc_erp_request(char *, int, int,
  648. struct dasd_device *);
  649. void dasd_free_erp_request(struct dasd_ccw_req *, struct dasd_device *);
  650. void dasd_log_sense(struct dasd_ccw_req *, struct irb *);
  651. void dasd_log_sense_dbf(struct dasd_ccw_req *cqr, struct irb *irb);
  652. /* externals in dasd_3990_erp.c */
  653. struct dasd_ccw_req *dasd_3990_erp_action(struct dasd_ccw_req *);
  654. void dasd_3990_erp_handle_sim(struct dasd_device *, char *);
  655. /* externals in dasd_eer.c */
  656. #ifdef CONFIG_DASD_EER
  657. int dasd_eer_init(void);
  658. void dasd_eer_exit(void);
  659. int dasd_eer_enable(struct dasd_device *);
  660. void dasd_eer_disable(struct dasd_device *);
  661. void dasd_eer_write(struct dasd_device *, struct dasd_ccw_req *cqr,
  662. unsigned int id);
  663. void dasd_eer_snss(struct dasd_device *);
  664. static inline int dasd_eer_enabled(struct dasd_device *device)
  665. {
  666. return device->eer_cqr != NULL;
  667. }
  668. #else
  669. #define dasd_eer_init() (0)
  670. #define dasd_eer_exit() do { } while (0)
  671. #define dasd_eer_enable(d) (0)
  672. #define dasd_eer_disable(d) do { } while (0)
  673. #define dasd_eer_write(d,c,i) do { } while (0)
  674. #define dasd_eer_snss(d) do { } while (0)
  675. #define dasd_eer_enabled(d) (0)
  676. #endif /* CONFIG_DASD_ERR */
  677. #endif /* DASD_H */