dasd_int.h 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839
  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. struct dasd_device *basedev; /* base device if no block->base */
  156. void *cpaddr; /* address of ccw or tcw */
  157. unsigned char cpmode; /* 0 = cmd mode, 1 = itcw */
  158. char status; /* status of this request */
  159. short retries; /* A retry counter */
  160. unsigned long flags; /* flags of this request */
  161. /* ... and how */
  162. unsigned long starttime; /* jiffies time of request start */
  163. unsigned long expires; /* expiration period in jiffies */
  164. char lpm; /* logical path mask */
  165. void *data; /* pointer to data area */
  166. /* these are important for recovering erroneous requests */
  167. int intrc; /* internal error, e.g. from start_IO */
  168. struct irb irb; /* device status in case of an error */
  169. struct dasd_ccw_req *refers; /* ERP-chain queueing. */
  170. void *function; /* originating ERP action */
  171. /* these are for statistics only */
  172. unsigned long long buildclk; /* TOD-clock of request generation */
  173. unsigned long long startclk; /* TOD-clock of request start */
  174. unsigned long long stopclk; /* TOD-clock of request interrupt */
  175. unsigned long long endclk; /* TOD-clock of request termination */
  176. /* Callback that is called after reaching final status. */
  177. void (*callback)(struct dasd_ccw_req *, void *data);
  178. void *callback_data;
  179. };
  180. /*
  181. * dasd_ccw_req -> status can be:
  182. */
  183. #define DASD_CQR_FILLED 0x00 /* request is ready to be processed */
  184. #define DASD_CQR_DONE 0x01 /* request is completed successfully */
  185. #define DASD_CQR_NEED_ERP 0x02 /* request needs recovery action */
  186. #define DASD_CQR_IN_ERP 0x03 /* request is in recovery */
  187. #define DASD_CQR_FAILED 0x04 /* request is finally failed */
  188. #define DASD_CQR_TERMINATED 0x05 /* request was stopped by driver */
  189. #define DASD_CQR_QUEUED 0x80 /* request is queued to be processed */
  190. #define DASD_CQR_IN_IO 0x81 /* request is currently in IO */
  191. #define DASD_CQR_ERROR 0x82 /* request is completed with error */
  192. #define DASD_CQR_CLEAR_PENDING 0x83 /* request is clear pending */
  193. #define DASD_CQR_CLEARED 0x84 /* request was cleared */
  194. #define DASD_CQR_SUCCESS 0x85 /* request was successful */
  195. /* default expiration time*/
  196. #define DASD_EXPIRES 300
  197. #define DASD_EXPIRES_MAX 40000000
  198. #define DASD_RETRIES 256
  199. #define DASD_RETRIES_MAX 32768
  200. /* per dasd_ccw_req flags */
  201. #define DASD_CQR_FLAGS_USE_ERP 0 /* use ERP for this request */
  202. #define DASD_CQR_FLAGS_FAILFAST 1 /* FAILFAST */
  203. #define DASD_CQR_VERIFY_PATH 2 /* path verification request */
  204. #define DASD_CQR_ALLOW_SLOCK 3 /* Try this request even when lock was
  205. * stolen. Should not be combined with
  206. * DASD_CQR_FLAGS_USE_ERP
  207. */
  208. /*
  209. * The following flags are used to suppress output of certain errors.
  210. * These flags should only be used for format checks!
  211. */
  212. #define DASD_CQR_SUPPRESS_NRF 4 /* Suppress 'No Record Found' error */
  213. #define DASD_CQR_SUPPRESS_FP 5 /* Suppress 'File Protected' error*/
  214. #define DASD_CQR_SUPPRESS_IL 6 /* Suppress 'Incorrect Length' error */
  215. /* Signature for error recovery functions. */
  216. typedef struct dasd_ccw_req *(*dasd_erp_fn_t) (struct dasd_ccw_req *);
  217. /*
  218. * A single CQR can only contain a maximum of 255 CCWs. It is limited by
  219. * the locate record and locate record extended count value which can only hold
  220. * 1 Byte max.
  221. */
  222. #define DASD_CQR_MAX_CCW 255
  223. /*
  224. * Unique identifier for dasd device.
  225. */
  226. #define UA_NOT_CONFIGURED 0x00
  227. #define UA_BASE_DEVICE 0x01
  228. #define UA_BASE_PAV_ALIAS 0x02
  229. #define UA_HYPER_PAV_ALIAS 0x03
  230. struct dasd_uid {
  231. __u8 type;
  232. char vendor[4];
  233. char serial[15];
  234. __u16 ssid;
  235. __u8 real_unit_addr;
  236. __u8 base_unit_addr;
  237. char vduit[33];
  238. };
  239. /*
  240. * the struct dasd_discipline is
  241. * sth like a table of virtual functions, if you think of dasd_eckd
  242. * inheriting dasd...
  243. * no, currently we are not planning to reimplement the driver in C++
  244. */
  245. struct dasd_discipline {
  246. struct module *owner;
  247. char ebcname[8]; /* a name used for tagging and printks */
  248. char name[8]; /* a name used for tagging and printks */
  249. int max_blocks; /* maximum number of blocks to be chained */
  250. struct list_head list; /* used for list of disciplines */
  251. /*
  252. * Device recognition functions. check_device is used to verify
  253. * the sense data and the information returned by read device
  254. * characteristics. It returns 0 if the discipline can be used
  255. * for the device in question. uncheck_device is called during
  256. * device shutdown to deregister a device from its discipline.
  257. */
  258. int (*check_device) (struct dasd_device *);
  259. void (*uncheck_device) (struct dasd_device *);
  260. /*
  261. * do_analysis is used in the step from device state "basic" to
  262. * state "accept". It returns 0 if the device can be made ready,
  263. * it returns -EMEDIUMTYPE if the device can't be made ready or
  264. * -EAGAIN if do_analysis started a ccw that needs to complete
  265. * before the analysis may be repeated.
  266. */
  267. int (*do_analysis) (struct dasd_block *);
  268. /*
  269. * This function is called, when new paths become available.
  270. * Disciplins may use this callback to do necessary setup work,
  271. * e.g. verify that new path is compatible with the current
  272. * configuration.
  273. */
  274. int (*verify_path)(struct dasd_device *, __u8);
  275. /*
  276. * Last things to do when a device is set online, and first things
  277. * when it is set offline.
  278. */
  279. int (*basic_to_ready) (struct dasd_device *);
  280. int (*online_to_ready) (struct dasd_device *);
  281. int (*basic_to_known)(struct dasd_device *);
  282. /* (struct dasd_device *);
  283. * Device operation functions. build_cp creates a ccw chain for
  284. * a block device request, start_io starts the request and
  285. * term_IO cancels it (e.g. in case of a timeout). format_device
  286. * formats the device and check_device_format compares the format of
  287. * a device with the expected format_data.
  288. * handle_terminated_request allows to examine a cqr and prepare
  289. * it for retry.
  290. */
  291. struct dasd_ccw_req *(*build_cp) (struct dasd_device *,
  292. struct dasd_block *,
  293. struct request *);
  294. int (*start_IO) (struct dasd_ccw_req *);
  295. int (*term_IO) (struct dasd_ccw_req *);
  296. void (*handle_terminated_request) (struct dasd_ccw_req *);
  297. int (*format_device) (struct dasd_device *,
  298. struct format_data_t *, int);
  299. int (*check_device_format)(struct dasd_device *,
  300. struct format_check_t *, int);
  301. int (*free_cp) (struct dasd_ccw_req *, struct request *);
  302. /*
  303. * Error recovery functions. examine_error() returns a value that
  304. * indicates what to do for an error condition. If examine_error()
  305. * returns 'dasd_era_recover' erp_action() is called to create a
  306. * special error recovery ccw. erp_postaction() is called after
  307. * an error recovery ccw has finished its execution. dump_sense
  308. * is called for every error condition to print the sense data
  309. * to the console.
  310. */
  311. dasd_erp_fn_t(*erp_action) (struct dasd_ccw_req *);
  312. dasd_erp_fn_t(*erp_postaction) (struct dasd_ccw_req *);
  313. void (*dump_sense) (struct dasd_device *, struct dasd_ccw_req *,
  314. struct irb *);
  315. void (*dump_sense_dbf) (struct dasd_device *, struct irb *, char *);
  316. void (*check_for_device_change) (struct dasd_device *,
  317. struct dasd_ccw_req *,
  318. struct irb *);
  319. /* i/o control functions. */
  320. int (*fill_geometry) (struct dasd_block *, struct hd_geometry *);
  321. int (*fill_info) (struct dasd_device *, struct dasd_information2_t *);
  322. int (*ioctl) (struct dasd_block *, unsigned int, void __user *);
  323. /* suspend/resume functions */
  324. int (*freeze) (struct dasd_device *);
  325. int (*restore) (struct dasd_device *);
  326. /* reload device after state change */
  327. int (*reload) (struct dasd_device *);
  328. int (*get_uid) (struct dasd_device *, struct dasd_uid *);
  329. void (*kick_validate) (struct dasd_device *);
  330. int (*check_attention)(struct dasd_device *, __u8);
  331. int (*host_access_count)(struct dasd_device *);
  332. int (*hosts_print)(struct dasd_device *, struct seq_file *);
  333. };
  334. extern struct dasd_discipline *dasd_diag_discipline_pointer;
  335. /*
  336. * Notification numbers for extended error reporting notifications:
  337. * The DASD_EER_DISABLE notification is sent before a dasd_device (and it's
  338. * eer pointer) is freed. The error reporting module needs to do all necessary
  339. * cleanup steps.
  340. * The DASD_EER_TRIGGER notification sends the actual error reports (triggers).
  341. */
  342. #define DASD_EER_DISABLE 0
  343. #define DASD_EER_TRIGGER 1
  344. /* Trigger IDs for extended error reporting DASD_EER_TRIGGER notification */
  345. #define DASD_EER_FATALERROR 1
  346. #define DASD_EER_NOPATH 2
  347. #define DASD_EER_STATECHANGE 3
  348. #define DASD_EER_PPRCSUSPEND 4
  349. struct dasd_path {
  350. __u8 opm;
  351. __u8 tbvpm;
  352. __u8 ppm;
  353. __u8 npm;
  354. /* paths that are not used because of a special condition */
  355. __u8 cablepm; /* miss-cabled */
  356. __u8 hpfpm; /* the HPF requirements of the other paths are not met */
  357. __u8 cuirpm; /* CUIR varied offline */
  358. };
  359. struct dasd_profile_info {
  360. /* legacy part of profile data, as in dasd_profile_info_t */
  361. unsigned int dasd_io_reqs; /* number of requests processed */
  362. unsigned int dasd_io_sects; /* number of sectors processed */
  363. unsigned int dasd_io_secs[32]; /* histogram of request's sizes */
  364. unsigned int dasd_io_times[32]; /* histogram of requests's times */
  365. unsigned int dasd_io_timps[32]; /* h. of requests's times per sector */
  366. unsigned int dasd_io_time1[32]; /* hist. of time from build to start */
  367. unsigned int dasd_io_time2[32]; /* hist. of time from start to irq */
  368. unsigned int dasd_io_time2ps[32]; /* hist. of time from start to irq */
  369. unsigned int dasd_io_time3[32]; /* hist. of time from irq to end */
  370. unsigned int dasd_io_nr_req[32]; /* hist. of # of requests in chanq */
  371. /* new data */
  372. struct timespec starttod; /* time of start or last reset */
  373. unsigned int dasd_io_alias; /* requests using an alias */
  374. unsigned int dasd_io_tpm; /* requests using transport mode */
  375. unsigned int dasd_read_reqs; /* total number of read requests */
  376. unsigned int dasd_read_sects; /* total number read sectors */
  377. unsigned int dasd_read_alias; /* read request using an alias */
  378. unsigned int dasd_read_tpm; /* read requests in transport mode */
  379. unsigned int dasd_read_secs[32]; /* histogram of request's sizes */
  380. unsigned int dasd_read_times[32]; /* histogram of requests's times */
  381. unsigned int dasd_read_time1[32]; /* hist. time from build to start */
  382. unsigned int dasd_read_time2[32]; /* hist. of time from start to irq */
  383. unsigned int dasd_read_time3[32]; /* hist. of time from irq to end */
  384. unsigned int dasd_read_nr_req[32]; /* hist. of # of requests in chanq */
  385. };
  386. struct dasd_profile {
  387. struct dentry *dentry;
  388. struct dasd_profile_info *data;
  389. spinlock_t lock;
  390. };
  391. struct dasd_device {
  392. /* Block device stuff. */
  393. struct dasd_block *block;
  394. unsigned int devindex;
  395. unsigned long flags; /* per device flags */
  396. unsigned short features; /* copy of devmap-features (read-only!) */
  397. /* extended error reporting stuff (eer) */
  398. struct dasd_ccw_req *eer_cqr;
  399. /* Device discipline stuff. */
  400. struct dasd_discipline *discipline;
  401. struct dasd_discipline *base_discipline;
  402. void *private;
  403. struct dasd_path path_data;
  404. /* Device state and target state. */
  405. int state, target;
  406. struct mutex state_mutex;
  407. int stopped; /* device (ccw_device_start) was stopped */
  408. /* reference count. */
  409. atomic_t ref_count;
  410. /* ccw queue and memory for static ccw/erp buffers. */
  411. struct list_head ccw_queue;
  412. spinlock_t mem_lock;
  413. void *ccw_mem;
  414. void *erp_mem;
  415. struct list_head ccw_chunks;
  416. struct list_head erp_chunks;
  417. atomic_t tasklet_scheduled;
  418. struct tasklet_struct tasklet;
  419. struct work_struct kick_work;
  420. struct work_struct restore_device;
  421. struct work_struct reload_device;
  422. struct work_struct kick_validate;
  423. struct work_struct suc_work;
  424. struct timer_list timer;
  425. debug_info_t *debug_area;
  426. struct ccw_device *cdev;
  427. /* hook for alias management */
  428. struct list_head alias_list;
  429. /* default expiration time in s */
  430. unsigned long default_expires;
  431. unsigned long default_retries;
  432. unsigned long blk_timeout;
  433. struct dentry *debugfs_dentry;
  434. struct dentry *hosts_dentry;
  435. struct dasd_profile profile;
  436. };
  437. struct dasd_block {
  438. /* Block device stuff. */
  439. struct gendisk *gdp;
  440. struct request_queue *request_queue;
  441. spinlock_t request_queue_lock;
  442. struct block_device *bdev;
  443. atomic_t open_count;
  444. unsigned long long blocks; /* size of volume in blocks */
  445. unsigned int bp_block; /* bytes per block */
  446. unsigned int s2b_shift; /* log2 (bp_block/512) */
  447. struct dasd_device *base;
  448. struct list_head ccw_queue;
  449. spinlock_t queue_lock;
  450. atomic_t tasklet_scheduled;
  451. struct tasklet_struct tasklet;
  452. struct timer_list timer;
  453. struct dentry *debugfs_dentry;
  454. struct dasd_profile profile;
  455. };
  456. struct dasd_attention_data {
  457. struct dasd_device *device;
  458. __u8 lpum;
  459. };
  460. /* reasons why device (ccw_device_start) was stopped */
  461. #define DASD_STOPPED_NOT_ACC 1 /* not accessible */
  462. #define DASD_STOPPED_QUIESCE 2 /* Quiesced */
  463. #define DASD_STOPPED_PENDING 4 /* long busy */
  464. #define DASD_STOPPED_DC_WAIT 8 /* disconnected, wait */
  465. #define DASD_STOPPED_SU 16 /* summary unit check handling */
  466. #define DASD_STOPPED_PM 32 /* pm state transition */
  467. #define DASD_UNRESUMED_PM 64 /* pm resume failed state */
  468. /* per device flags */
  469. #define DASD_FLAG_OFFLINE 3 /* device is in offline processing */
  470. #define DASD_FLAG_EER_SNSS 4 /* A SNSS is required */
  471. #define DASD_FLAG_EER_IN_USE 5 /* A SNSS request is running */
  472. #define DASD_FLAG_DEVICE_RO 6 /* The device itself is read-only. Don't
  473. * confuse this with the user specified
  474. * read-only feature.
  475. */
  476. #define DASD_FLAG_IS_RESERVED 7 /* The device is reserved */
  477. #define DASD_FLAG_LOCK_STOLEN 8 /* The device lock was stolen */
  478. #define DASD_FLAG_SUSPENDED 9 /* The device was suspended */
  479. #define DASD_FLAG_SAFE_OFFLINE 10 /* safe offline processing requested*/
  480. #define DASD_FLAG_SAFE_OFFLINE_RUNNING 11 /* safe offline running */
  481. #define DASD_FLAG_ABORTALL 12 /* Abort all noretry requests */
  482. #define DASD_FLAG_PATH_VERIFY 13 /* Path verification worker running */
  483. #define DASD_FLAG_SUC 14 /* unhandled summary unit check */
  484. #define DASD_SLEEPON_START_TAG ((void *) 1)
  485. #define DASD_SLEEPON_END_TAG ((void *) 2)
  486. void dasd_put_device_wake(struct dasd_device *);
  487. /*
  488. * Reference count inliners
  489. */
  490. static inline void
  491. dasd_get_device(struct dasd_device *device)
  492. {
  493. atomic_inc(&device->ref_count);
  494. }
  495. static inline void
  496. dasd_put_device(struct dasd_device *device)
  497. {
  498. if (atomic_dec_return(&device->ref_count) == 0)
  499. dasd_put_device_wake(device);
  500. }
  501. /*
  502. * The static memory in ccw_mem and erp_mem is managed by a sorted
  503. * list of free memory chunks.
  504. */
  505. struct dasd_mchunk
  506. {
  507. struct list_head list;
  508. unsigned long size;
  509. } __attribute__ ((aligned(8)));
  510. static inline void
  511. dasd_init_chunklist(struct list_head *chunk_list, void *mem,
  512. unsigned long size)
  513. {
  514. struct dasd_mchunk *chunk;
  515. INIT_LIST_HEAD(chunk_list);
  516. chunk = (struct dasd_mchunk *) mem;
  517. chunk->size = size - sizeof(struct dasd_mchunk);
  518. list_add(&chunk->list, chunk_list);
  519. }
  520. static inline void *
  521. dasd_alloc_chunk(struct list_head *chunk_list, unsigned long size)
  522. {
  523. struct dasd_mchunk *chunk, *tmp;
  524. size = (size + 7L) & -8L;
  525. list_for_each_entry(chunk, chunk_list, list) {
  526. if (chunk->size < size)
  527. continue;
  528. if (chunk->size > size + sizeof(struct dasd_mchunk)) {
  529. char *endaddr = (char *) (chunk + 1) + chunk->size;
  530. tmp = (struct dasd_mchunk *) (endaddr - size) - 1;
  531. tmp->size = size;
  532. chunk->size -= size + sizeof(struct dasd_mchunk);
  533. chunk = tmp;
  534. } else
  535. list_del(&chunk->list);
  536. return (void *) (chunk + 1);
  537. }
  538. return NULL;
  539. }
  540. static inline void
  541. dasd_free_chunk(struct list_head *chunk_list, void *mem)
  542. {
  543. struct dasd_mchunk *chunk, *tmp;
  544. struct list_head *p, *left;
  545. chunk = (struct dasd_mchunk *)
  546. ((char *) mem - sizeof(struct dasd_mchunk));
  547. /* Find out the left neighbour in chunk_list. */
  548. left = chunk_list;
  549. list_for_each(p, chunk_list) {
  550. if (list_entry(p, struct dasd_mchunk, list) > chunk)
  551. break;
  552. left = p;
  553. }
  554. /* Try to merge with right neighbour = next element from left. */
  555. if (left->next != chunk_list) {
  556. tmp = list_entry(left->next, struct dasd_mchunk, list);
  557. if ((char *) (chunk + 1) + chunk->size == (char *) tmp) {
  558. list_del(&tmp->list);
  559. chunk->size += tmp->size + sizeof(struct dasd_mchunk);
  560. }
  561. }
  562. /* Try to merge with left neighbour. */
  563. if (left != chunk_list) {
  564. tmp = list_entry(left, struct dasd_mchunk, list);
  565. if ((char *) (tmp + 1) + tmp->size == (char *) chunk) {
  566. tmp->size += chunk->size + sizeof(struct dasd_mchunk);
  567. return;
  568. }
  569. }
  570. __list_add(&chunk->list, left, left->next);
  571. }
  572. /*
  573. * Check if bsize is in { 512, 1024, 2048, 4096 }
  574. */
  575. static inline int
  576. dasd_check_blocksize(int bsize)
  577. {
  578. if (bsize < 512 || bsize > 4096 || !is_power_of_2(bsize))
  579. return -EMEDIUMTYPE;
  580. return 0;
  581. }
  582. /* externals in dasd.c */
  583. #define DASD_PROFILE_OFF 0
  584. #define DASD_PROFILE_ON 1
  585. #define DASD_PROFILE_GLOBAL_ONLY 2
  586. extern debug_info_t *dasd_debug_area;
  587. extern struct dasd_profile dasd_global_profile;
  588. extern unsigned int dasd_global_profile_level;
  589. extern const struct block_device_operations dasd_device_operations;
  590. extern struct kmem_cache *dasd_page_cache;
  591. struct dasd_ccw_req *
  592. dasd_kmalloc_request(int , int, int, struct dasd_device *);
  593. struct dasd_ccw_req *
  594. dasd_smalloc_request(int , int, int, struct dasd_device *);
  595. void dasd_kfree_request(struct dasd_ccw_req *, struct dasd_device *);
  596. void dasd_sfree_request(struct dasd_ccw_req *, struct dasd_device *);
  597. void dasd_wakeup_cb(struct dasd_ccw_req *, void *);
  598. static inline int
  599. dasd_kmalloc_set_cda(struct ccw1 *ccw, void *cda, struct dasd_device *device)
  600. {
  601. return set_normalized_cda(ccw, cda);
  602. }
  603. struct dasd_device *dasd_alloc_device(void);
  604. void dasd_free_device(struct dasd_device *);
  605. struct dasd_block *dasd_alloc_block(void);
  606. void dasd_free_block(struct dasd_block *);
  607. enum blk_eh_timer_return dasd_times_out(struct request *req);
  608. void dasd_enable_device(struct dasd_device *);
  609. void dasd_set_target_state(struct dasd_device *, int);
  610. void dasd_kick_device(struct dasd_device *);
  611. void dasd_restore_device(struct dasd_device *);
  612. void dasd_reload_device(struct dasd_device *);
  613. void dasd_add_request_head(struct dasd_ccw_req *);
  614. void dasd_add_request_tail(struct dasd_ccw_req *);
  615. int dasd_start_IO(struct dasd_ccw_req *);
  616. int dasd_term_IO(struct dasd_ccw_req *);
  617. void dasd_schedule_device_bh(struct dasd_device *);
  618. void dasd_schedule_block_bh(struct dasd_block *);
  619. int dasd_sleep_on(struct dasd_ccw_req *);
  620. int dasd_sleep_on_queue(struct list_head *);
  621. int dasd_sleep_on_immediatly(struct dasd_ccw_req *);
  622. int dasd_sleep_on_interruptible(struct dasd_ccw_req *);
  623. void dasd_device_set_timer(struct dasd_device *, int);
  624. void dasd_device_clear_timer(struct dasd_device *);
  625. void dasd_block_set_timer(struct dasd_block *, int);
  626. void dasd_block_clear_timer(struct dasd_block *);
  627. int dasd_cancel_req(struct dasd_ccw_req *);
  628. int dasd_flush_device_queue(struct dasd_device *);
  629. int dasd_generic_probe (struct ccw_device *, struct dasd_discipline *);
  630. void dasd_generic_free_discipline(struct dasd_device *);
  631. void dasd_generic_remove (struct ccw_device *cdev);
  632. int dasd_generic_set_online(struct ccw_device *, struct dasd_discipline *);
  633. int dasd_generic_set_offline (struct ccw_device *cdev);
  634. int dasd_generic_notify(struct ccw_device *, int);
  635. int dasd_generic_last_path_gone(struct dasd_device *);
  636. int dasd_generic_path_operational(struct dasd_device *);
  637. void dasd_generic_shutdown(struct ccw_device *);
  638. void dasd_generic_handle_state_change(struct dasd_device *);
  639. int dasd_generic_pm_freeze(struct ccw_device *);
  640. int dasd_generic_restore_device(struct ccw_device *);
  641. enum uc_todo dasd_generic_uc_handler(struct ccw_device *, struct irb *);
  642. void dasd_generic_path_event(struct ccw_device *, int *);
  643. int dasd_generic_verify_path(struct dasd_device *, __u8);
  644. int dasd_generic_read_dev_chars(struct dasd_device *, int, void *, int);
  645. char *dasd_get_sense(struct irb *);
  646. void dasd_device_set_stop_bits(struct dasd_device *, int);
  647. void dasd_device_remove_stop_bits(struct dasd_device *, int);
  648. int dasd_device_is_ro(struct dasd_device *);
  649. void dasd_profile_reset(struct dasd_profile *);
  650. int dasd_profile_on(struct dasd_profile *);
  651. void dasd_profile_off(struct dasd_profile *);
  652. char *dasd_get_user_string(const char __user *, size_t);
  653. /* externals in dasd_devmap.c */
  654. extern int dasd_max_devindex;
  655. extern int dasd_probeonly;
  656. extern int dasd_autodetect;
  657. extern int dasd_nopav;
  658. extern int dasd_nofcx;
  659. int dasd_devmap_init(void);
  660. void dasd_devmap_exit(void);
  661. struct dasd_device *dasd_create_device(struct ccw_device *);
  662. void dasd_delete_device(struct dasd_device *);
  663. int dasd_get_feature(struct ccw_device *, int);
  664. int dasd_set_feature(struct ccw_device *, int, int);
  665. int dasd_add_sysfs_files(struct ccw_device *);
  666. void dasd_remove_sysfs_files(struct ccw_device *);
  667. struct dasd_device *dasd_device_from_cdev(struct ccw_device *);
  668. struct dasd_device *dasd_device_from_cdev_locked(struct ccw_device *);
  669. struct dasd_device *dasd_device_from_devindex(int);
  670. void dasd_add_link_to_gendisk(struct gendisk *, struct dasd_device *);
  671. struct dasd_device *dasd_device_from_gendisk(struct gendisk *);
  672. int dasd_parse(void);
  673. int dasd_busid_known(const char *);
  674. /* externals in dasd_gendisk.c */
  675. int dasd_gendisk_init(void);
  676. void dasd_gendisk_exit(void);
  677. int dasd_gendisk_alloc(struct dasd_block *);
  678. void dasd_gendisk_free(struct dasd_block *);
  679. int dasd_scan_partitions(struct dasd_block *);
  680. void dasd_destroy_partitions(struct dasd_block *);
  681. /* externals in dasd_ioctl.c */
  682. int dasd_ioctl(struct block_device *, fmode_t, unsigned int, unsigned long);
  683. /* externals in dasd_proc.c */
  684. int dasd_proc_init(void);
  685. void dasd_proc_exit(void);
  686. /* externals in dasd_erp.c */
  687. struct dasd_ccw_req *dasd_default_erp_action(struct dasd_ccw_req *);
  688. struct dasd_ccw_req *dasd_default_erp_postaction(struct dasd_ccw_req *);
  689. struct dasd_ccw_req *dasd_alloc_erp_request(char *, int, int,
  690. struct dasd_device *);
  691. void dasd_free_erp_request(struct dasd_ccw_req *, struct dasd_device *);
  692. void dasd_log_sense(struct dasd_ccw_req *, struct irb *);
  693. void dasd_log_sense_dbf(struct dasd_ccw_req *cqr, struct irb *irb);
  694. /* externals in dasd_3990_erp.c */
  695. struct dasd_ccw_req *dasd_3990_erp_action(struct dasd_ccw_req *);
  696. void dasd_3990_erp_handle_sim(struct dasd_device *, char *);
  697. /* externals in dasd_eer.c */
  698. #ifdef CONFIG_DASD_EER
  699. int dasd_eer_init(void);
  700. void dasd_eer_exit(void);
  701. int dasd_eer_enable(struct dasd_device *);
  702. void dasd_eer_disable(struct dasd_device *);
  703. void dasd_eer_write(struct dasd_device *, struct dasd_ccw_req *cqr,
  704. unsigned int id);
  705. void dasd_eer_snss(struct dasd_device *);
  706. static inline int dasd_eer_enabled(struct dasd_device *device)
  707. {
  708. return device->eer_cqr != NULL;
  709. }
  710. #else
  711. #define dasd_eer_init() (0)
  712. #define dasd_eer_exit() do { } while (0)
  713. #define dasd_eer_enable(d) (0)
  714. #define dasd_eer_disable(d) do { } while (0)
  715. #define dasd_eer_write(d,c,i) do { } while (0)
  716. #define dasd_eer_snss(d) do { } while (0)
  717. #define dasd_eer_enabled(d) (0)
  718. #endif /* CONFIG_DASD_ERR */
  719. #endif /* DASD_H */