dasd_int.h 43 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Author(s)......: Holger Smolinski <Holger.Smolinski@de.ibm.com>
  4. * Horst Hummel <Horst.Hummel@de.ibm.com>
  5. * Martin Schwidefsky <schwidefsky@de.ibm.com>
  6. * Bugreports.to..: <Linux390@de.ibm.com>
  7. * Copyright IBM Corp. 1999, 2009
  8. */
  9. #ifndef DASD_INT_H
  10. #define DASD_INT_H
  11. /* we keep old device allocation scheme; IOW, minors are still in 0..255 */
  12. #define DASD_PER_MAJOR (1U << (MINORBITS - DASD_PARTN_BITS))
  13. #define DASD_PARTN_MASK ((1 << DASD_PARTN_BITS) - 1)
  14. /*
  15. * States a dasd device can have:
  16. * new: the dasd_device structure is allocated.
  17. * known: the discipline for the device is identified.
  18. * basic: the device can do basic i/o.
  19. * unfmt: the device could not be analyzed (format is unknown).
  20. * ready: partition detection is done and the device is can do block io.
  21. * online: the device accepts requests from the block device queue.
  22. *
  23. * Things to do for startup state transitions:
  24. * new -> known: find discipline for the device and create devfs entries.
  25. * known -> basic: request irq line for the device.
  26. * basic -> ready: do the initial analysis, e.g. format detection,
  27. * do block device setup and detect partitions.
  28. * ready -> online: schedule the device tasklet.
  29. * Things to do for shutdown state transitions:
  30. * online -> ready: just set the new device state.
  31. * ready -> basic: flush requests from the block device layer, clear
  32. * partition information and reset format information.
  33. * basic -> known: terminate all requests and free irq.
  34. * known -> new: remove devfs entries and forget discipline.
  35. */
  36. #define DASD_STATE_NEW 0
  37. #define DASD_STATE_KNOWN 1
  38. #define DASD_STATE_BASIC 2
  39. #define DASD_STATE_UNFMT 3
  40. #define DASD_STATE_READY 4
  41. #define DASD_STATE_ONLINE 5
  42. #include <linux/module.h>
  43. #include <linux/wait.h>
  44. #include <linux/blkdev.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. #include <linux/bitops.h>
  54. #include <linux/blk-mq.h>
  55. /* DASD discipline magic */
  56. #define DASD_ECKD_MAGIC 0xC5C3D2C4
  57. #define DASD_DIAG_MAGIC 0xC4C9C1C7
  58. #define DASD_FBA_MAGIC 0xC6C2C140
  59. /*
  60. * SECTION: Type definitions
  61. */
  62. struct dasd_device;
  63. struct dasd_block;
  64. /* BIT DEFINITIONS FOR SENSE DATA */
  65. #define DASD_SENSE_BIT_0 0x80
  66. #define DASD_SENSE_BIT_1 0x40
  67. #define DASD_SENSE_BIT_2 0x20
  68. #define DASD_SENSE_BIT_3 0x10
  69. /* BIT DEFINITIONS FOR SIM SENSE */
  70. #define DASD_SIM_SENSE 0x0F
  71. #define DASD_SIM_MSG_TO_OP 0x03
  72. #define DASD_SIM_LOG 0x0C
  73. /* lock class for nested cdev lock */
  74. #define CDEV_NESTED_FIRST 1
  75. #define CDEV_NESTED_SECOND 2
  76. /*
  77. * SECTION: MACROs for klogd and s390 debug feature (dbf)
  78. */
  79. #define DBF_DEV_EVENT(d_level, d_device, d_str, d_data...) \
  80. do { \
  81. debug_sprintf_event(d_device->debug_area, \
  82. d_level, \
  83. d_str "\n", \
  84. d_data); \
  85. } while(0)
  86. #define DBF_EVENT(d_level, d_str, d_data...)\
  87. do { \
  88. debug_sprintf_event(dasd_debug_area, \
  89. d_level,\
  90. d_str "\n", \
  91. d_data); \
  92. } while(0)
  93. #define DBF_EVENT_DEVID(d_level, d_cdev, d_str, d_data...) \
  94. do { \
  95. struct ccw_dev_id __dev_id; \
  96. ccw_device_get_id(d_cdev, &__dev_id); \
  97. debug_sprintf_event(dasd_debug_area, \
  98. d_level, \
  99. "0.%x.%04x " d_str "\n", \
  100. __dev_id.ssid, __dev_id.devno, d_data); \
  101. } while (0)
  102. /* definition of dbf debug levels */
  103. #define DBF_EMERG 0 /* system is unusable */
  104. #define DBF_ALERT 1 /* action must be taken immediately */
  105. #define DBF_CRIT 2 /* critical conditions */
  106. #define DBF_ERR 3 /* error conditions */
  107. #define DBF_WARNING 4 /* warning conditions */
  108. #define DBF_NOTICE 5 /* normal but significant condition */
  109. #define DBF_INFO 6 /* informational */
  110. #define DBF_DEBUG 6 /* debug-level messages */
  111. /* Macro to calculate number of blocks per page */
  112. #define BLOCKS_PER_PAGE(blksize) (PAGE_SIZE / blksize)
  113. struct dasd_ccw_req {
  114. unsigned int magic; /* Eye catcher */
  115. int intrc; /* internal error, e.g. from start_IO */
  116. struct list_head devlist; /* for dasd_device request queue */
  117. struct list_head blocklist; /* for dasd_block request queue */
  118. struct dasd_block *block; /* the originating block device */
  119. struct dasd_device *memdev; /* the device used to allocate this */
  120. struct dasd_device *startdev; /* device the request is started on */
  121. struct dasd_device *basedev; /* base device if no block->base */
  122. void *cpaddr; /* address of ccw or tcw */
  123. short retries; /* A retry counter */
  124. unsigned char cpmode; /* 0 = cmd mode, 1 = itcw */
  125. char status; /* status of this request */
  126. char lpm; /* logical path mask */
  127. unsigned long flags; /* flags of this request */
  128. struct dasd_queue *dq;
  129. unsigned long starttime; /* jiffies time of request start */
  130. unsigned long expires; /* expiration period in jiffies */
  131. void *data; /* pointer to data area */
  132. struct irb irb; /* device status in case of an error */
  133. struct dasd_ccw_req *refers; /* ERP-chain queueing. */
  134. void *function; /* originating ERP action */
  135. void *mem_chunk;
  136. unsigned long buildclk; /* TOD-clock of request generation */
  137. unsigned long startclk; /* TOD-clock of request start */
  138. unsigned long stopclk; /* TOD-clock of request interrupt */
  139. unsigned long endclk; /* TOD-clock of request termination */
  140. void (*callback)(struct dasd_ccw_req *, void *data);
  141. void *callback_data;
  142. unsigned int proc_bytes; /* bytes for partial completion */
  143. unsigned int trkcount; /* count formatted tracks */
  144. };
  145. /*
  146. * dasd_ccw_req -> status can be:
  147. */
  148. #define DASD_CQR_FILLED 0x00 /* request is ready to be processed */
  149. #define DASD_CQR_DONE 0x01 /* request is completed successfully */
  150. #define DASD_CQR_NEED_ERP 0x02 /* request needs recovery action */
  151. #define DASD_CQR_IN_ERP 0x03 /* request is in recovery */
  152. #define DASD_CQR_FAILED 0x04 /* request is finally failed */
  153. #define DASD_CQR_TERMINATED 0x05 /* request was stopped by driver */
  154. #define DASD_CQR_QUEUED 0x80 /* request is queued to be processed */
  155. #define DASD_CQR_IN_IO 0x81 /* request is currently in IO */
  156. #define DASD_CQR_ERROR 0x82 /* request is completed with error */
  157. #define DASD_CQR_CLEAR_PENDING 0x83 /* request is clear pending */
  158. #define DASD_CQR_CLEARED 0x84 /* request was cleared */
  159. #define DASD_CQR_SUCCESS 0x85 /* request was successful */
  160. /* default expiration time*/
  161. #define DASD_EXPIRES 300
  162. #define DASD_EXPIRES_MAX 40000000
  163. #define DASD_RETRIES 256
  164. #define DASD_RETRIES_MAX 32768
  165. /* per dasd_ccw_req flags */
  166. #define DASD_CQR_FLAGS_USE_ERP 0 /* use ERP for this request */
  167. #define DASD_CQR_FLAGS_FAILFAST 1 /* FAILFAST */
  168. #define DASD_CQR_VERIFY_PATH 2 /* path verification request */
  169. #define DASD_CQR_ALLOW_SLOCK 3 /* Try this request even when lock was
  170. * stolen. Should not be combined with
  171. * DASD_CQR_FLAGS_USE_ERP
  172. */
  173. /*
  174. * The following flags are used to suppress output of certain errors.
  175. */
  176. #define DASD_CQR_SUPPRESS_NRF 4 /* Suppress 'No Record Found' error */
  177. #define DASD_CQR_SUPPRESS_IT 5 /* Suppress 'Invalid Track' error*/
  178. #define DASD_CQR_SUPPRESS_IL 6 /* Suppress 'Incorrect Length' error */
  179. #define DASD_CQR_SUPPRESS_CR 7 /* Suppress 'Command Reject' error */
  180. #define DASD_REQ_PER_DEV 4
  181. /* Signature for error recovery functions. */
  182. typedef struct dasd_ccw_req *(*dasd_erp_fn_t) (struct dasd_ccw_req *);
  183. /*
  184. * A single CQR can only contain a maximum of 255 CCWs. It is limited by
  185. * the locate record and locate record extended count value which can only hold
  186. * 1 Byte max.
  187. */
  188. #define DASD_CQR_MAX_CCW 255
  189. /*
  190. * Unique identifier for dasd device.
  191. */
  192. #define UA_NOT_CONFIGURED 0x00
  193. #define UA_BASE_DEVICE 0x01
  194. #define UA_BASE_PAV_ALIAS 0x02
  195. #define UA_HYPER_PAV_ALIAS 0x03
  196. struct dasd_uid {
  197. __u8 type;
  198. char vendor[4];
  199. char serial[15];
  200. __u16 ssid;
  201. __u8 real_unit_addr;
  202. __u8 base_unit_addr;
  203. char vduit[33];
  204. };
  205. #define DASD_UID_STRLEN ( /* vendor */ 3 + 1 + /* serial */ 14 + 1 + \
  206. /* SSID */ 4 + 1 + /* unit addr */ 2 + 1 + \
  207. /* vduit */ 32 + 1)
  208. /*
  209. * PPRC Status data
  210. */
  211. struct dasd_pprc_header {
  212. __u8 entries; /* 0 Number of device entries */
  213. __u8 unused; /* 1 unused */
  214. __u16 entry_length; /* 2-3 Length of device entry */
  215. __u32 unused2; /* 4-7 unused */
  216. } __packed;
  217. struct dasd_pprc_dev_info {
  218. __u8 state; /* 0 Copy State */
  219. __u8 flags; /* 1 Flags */
  220. __u8 reserved1[2]; /* 2-3 reserved */
  221. __u8 prim_lss; /* 4 Primary device LSS */
  222. __u8 primary; /* 5 Primary device address */
  223. __u8 sec_lss; /* 6 Secondary device LSS */
  224. __u8 secondary; /* 7 Secondary device address */
  225. __u16 pprc_id; /* 8-9 Peer-to-Peer Remote Copy ID */
  226. __u8 reserved2[12]; /* 10-21 reserved */
  227. __u16 prim_cu_ssid; /* 22-23 Primary Control Unit SSID */
  228. __u8 reserved3[12]; /* 24-35 reserved */
  229. __u16 sec_cu_ssid; /* 36-37 Secondary Control Unit SSID */
  230. __u8 reserved4[90]; /* 38-127 reserved */
  231. } __packed;
  232. struct dasd_pprc_data_sc4 {
  233. struct dasd_pprc_header header;
  234. struct dasd_pprc_dev_info dev_info[5];
  235. } __packed;
  236. #define DASD_BUS_ID_SIZE 20
  237. #define DASD_CP_ENTRIES 5
  238. struct dasd_copy_entry {
  239. char busid[DASD_BUS_ID_SIZE];
  240. struct dasd_device *device;
  241. bool primary;
  242. bool configured;
  243. };
  244. struct dasd_copy_relation {
  245. struct dasd_copy_entry entry[DASD_CP_ENTRIES];
  246. struct dasd_copy_entry *active;
  247. };
  248. int dasd_devmap_set_device_copy_relation(struct ccw_device *,
  249. bool pprc_enabled);
  250. /*
  251. * the struct dasd_discipline is
  252. * sth like a table of virtual functions, if you think of dasd_eckd
  253. * inheriting dasd...
  254. * no, currently we are not planning to reimplement the driver in C++
  255. */
  256. struct dasd_discipline {
  257. struct module *owner;
  258. char ebcname[8]; /* a name used for tagging and printks */
  259. char name[8]; /* a name used for tagging and printks */
  260. bool has_discard;
  261. struct list_head list; /* used for list of disciplines */
  262. /*
  263. * Device recognition functions. check_device is used to verify
  264. * the sense data and the information returned by read device
  265. * characteristics. It returns 0 if the discipline can be used
  266. * for the device in question. uncheck_device is called during
  267. * device shutdown to deregister a device from its discipline.
  268. */
  269. int (*check_device) (struct dasd_device *);
  270. void (*uncheck_device) (struct dasd_device *);
  271. /*
  272. * do_analysis is used in the step from device state "basic" to
  273. * state "accept". It returns 0 if the device can be made ready,
  274. * it returns -EMEDIUMTYPE if the device can't be made ready or
  275. * -EAGAIN if do_analysis started a ccw that needs to complete
  276. * before the analysis may be repeated.
  277. */
  278. int (*do_analysis) (struct dasd_block *);
  279. /*
  280. * This function is called, when new paths become available.
  281. * Disciplins may use this callback to do necessary setup work,
  282. * e.g. verify that new path is compatible with the current
  283. * configuration.
  284. */
  285. int (*pe_handler)(struct dasd_device *, __u8, __u8);
  286. /*
  287. * Last things to do when a device is set online, and first things
  288. * when it is set offline.
  289. */
  290. int (*basic_to_ready) (struct dasd_device *);
  291. int (*online_to_ready) (struct dasd_device *);
  292. int (*basic_to_known)(struct dasd_device *);
  293. unsigned int (*max_sectors)(struct dasd_block *);
  294. /* (struct dasd_device *);
  295. * Device operation functions. build_cp creates a ccw chain for
  296. * a block device request, start_io starts the request and
  297. * term_IO cancels it (e.g. in case of a timeout). format_device
  298. * formats the device and check_device_format compares the format of
  299. * a device with the expected format_data.
  300. * handle_terminated_request allows to examine a cqr and prepare
  301. * it for retry.
  302. */
  303. struct dasd_ccw_req *(*build_cp) (struct dasd_device *,
  304. struct dasd_block *,
  305. struct request *);
  306. int (*start_IO) (struct dasd_ccw_req *);
  307. int (*term_IO) (struct dasd_ccw_req *);
  308. void (*handle_terminated_request) (struct dasd_ccw_req *);
  309. int (*format_device) (struct dasd_device *,
  310. struct format_data_t *, int);
  311. int (*check_device_format)(struct dasd_device *,
  312. struct format_check_t *, int);
  313. int (*free_cp) (struct dasd_ccw_req *, struct request *);
  314. /*
  315. * Error recovery functions. examine_error() returns a value that
  316. * indicates what to do for an error condition. If examine_error()
  317. * returns 'dasd_era_recover' erp_action() is called to create a
  318. * special error recovery ccw. erp_postaction() is called after
  319. * an error recovery ccw has finished its execution. dump_sense
  320. * is called for every error condition to print the sense data
  321. * to the console.
  322. */
  323. dasd_erp_fn_t(*erp_action) (struct dasd_ccw_req *);
  324. dasd_erp_fn_t(*erp_postaction) (struct dasd_ccw_req *);
  325. void (*dump_sense) (struct dasd_device *, struct dasd_ccw_req *,
  326. struct irb *);
  327. void (*dump_sense_dbf) (struct dasd_device *, struct irb *, char *);
  328. void (*check_for_device_change) (struct dasd_device *,
  329. struct dasd_ccw_req *,
  330. struct irb *);
  331. /* i/o control functions. */
  332. int (*fill_geometry) (struct dasd_block *, struct hd_geometry *);
  333. int (*fill_info) (struct dasd_device *, struct dasd_information2_t *);
  334. int (*ioctl) (struct dasd_block *, unsigned int, void __user *);
  335. /* reload device after state change */
  336. int (*reload) (struct dasd_device *);
  337. int (*get_uid) (struct dasd_device *, struct dasd_uid *);
  338. void (*kick_validate) (struct dasd_device *);
  339. int (*check_attention)(struct dasd_device *, __u8);
  340. int (*host_access_count)(struct dasd_device *);
  341. int (*hosts_print)(struct dasd_device *, struct seq_file *);
  342. void (*handle_hpf_error)(struct dasd_device *, struct irb *);
  343. void (*disable_hpf)(struct dasd_device *);
  344. int (*hpf_enabled)(struct dasd_device *);
  345. void (*reset_path)(struct dasd_device *, __u8);
  346. /*
  347. * Extent Space Efficient (ESE) relevant functions
  348. */
  349. int (*is_ese)(struct dasd_device *);
  350. /* Capacity */
  351. int (*space_allocated)(struct dasd_device *);
  352. int (*space_configured)(struct dasd_device *);
  353. int (*logical_capacity)(struct dasd_device *);
  354. int (*release_space)(struct dasd_device *, struct format_data_t *);
  355. /* Extent Pool */
  356. int (*ext_pool_id)(struct dasd_device *);
  357. int (*ext_size)(struct dasd_device *);
  358. int (*ext_pool_cap_at_warnlevel)(struct dasd_device *);
  359. int (*ext_pool_warn_thrshld)(struct dasd_device *);
  360. int (*ext_pool_oos)(struct dasd_device *);
  361. int (*ext_pool_exhaust)(struct dasd_device *, struct dasd_ccw_req *);
  362. struct dasd_ccw_req *(*ese_format)(struct dasd_device *,
  363. struct dasd_ccw_req *, struct irb *);
  364. int (*ese_read)(struct dasd_ccw_req *, struct irb *);
  365. int (*pprc_status)(struct dasd_device *, struct dasd_pprc_data_sc4 *);
  366. bool (*pprc_enabled)(struct dasd_device *);
  367. int (*copy_pair_swap)(struct dasd_device *, char *, char *);
  368. int (*device_ping)(struct dasd_device *);
  369. };
  370. extern struct dasd_discipline *dasd_diag_discipline_pointer;
  371. /* Trigger IDs for extended error reporting DASD EER and autoquiesce */
  372. enum eer_trigger {
  373. DASD_EER_FATALERROR = 1,
  374. DASD_EER_NOPATH,
  375. DASD_EER_STATECHANGE,
  376. DASD_EER_PPRCSUSPEND,
  377. DASD_EER_NOSPC,
  378. DASD_EER_TIMEOUTS,
  379. DASD_EER_STARTIO,
  380. /* enum end marker, only add new trigger above */
  381. DASD_EER_MAX,
  382. DASD_EER_AUTOQUIESCE = 31, /* internal only */
  383. };
  384. #define DASD_EER_VALID ((1U << DASD_EER_MAX) - 1)
  385. /* DASD path handling */
  386. #define DASD_PATH_OPERATIONAL 1
  387. #define DASD_PATH_TBV 2
  388. #define DASD_PATH_PP 3
  389. #define DASD_PATH_NPP 4
  390. #define DASD_PATH_MISCABLED 5
  391. #define DASD_PATH_NOHPF 6
  392. #define DASD_PATH_CUIR 7
  393. #define DASD_PATH_IFCC 8
  394. #define DASD_PATH_FCSEC 9
  395. #define DASD_THRHLD_MAX 4294967295U
  396. #define DASD_INTERVAL_MAX 4294967295U
  397. /* FC Endpoint Security Capabilities */
  398. #define DASD_FC_SECURITY_UNSUP 0
  399. #define DASD_FC_SECURITY_AUTH 1
  400. #define DASD_FC_SECURITY_ENC_FCSP2 2
  401. #define DASD_FC_SECURITY_ENC_ERAS 3
  402. #define DASD_FC_SECURITY_ENC_STR "Encryption"
  403. static const struct {
  404. u8 value;
  405. char *name;
  406. } dasd_path_fcs_mnemonics[] = {
  407. { DASD_FC_SECURITY_UNSUP, "Unsupported" },
  408. { DASD_FC_SECURITY_AUTH, "Authentication" },
  409. { DASD_FC_SECURITY_ENC_FCSP2, DASD_FC_SECURITY_ENC_STR },
  410. { DASD_FC_SECURITY_ENC_ERAS, DASD_FC_SECURITY_ENC_STR },
  411. };
  412. static inline char *dasd_path_get_fcs_str(int val)
  413. {
  414. int i;
  415. for (i = 0; i < ARRAY_SIZE(dasd_path_fcs_mnemonics); i++) {
  416. if (dasd_path_fcs_mnemonics[i].value == val)
  417. return dasd_path_fcs_mnemonics[i].name;
  418. }
  419. return dasd_path_fcs_mnemonics[0].name;
  420. }
  421. struct dasd_path {
  422. unsigned long flags;
  423. u8 cssid;
  424. u8 ssid;
  425. u8 chpid;
  426. struct dasd_conf_data *conf_data;
  427. atomic_t error_count;
  428. unsigned long errorclk;
  429. u8 fc_security;
  430. struct kobject kobj;
  431. bool in_sysfs;
  432. };
  433. #define to_dasd_path(path) container_of(path, struct dasd_path, kobj)
  434. static inline void dasd_path_release(struct kobject *kobj)
  435. {
  436. /* Memory for the dasd_path kobject is freed when dasd_free_device() is called */
  437. }
  438. struct dasd_profile_info {
  439. /* legacy part of profile data, as in dasd_profile_info_t */
  440. unsigned int dasd_io_reqs; /* number of requests processed */
  441. unsigned int dasd_io_sects; /* number of sectors processed */
  442. unsigned int dasd_io_secs[32]; /* histogram of request's sizes */
  443. unsigned int dasd_io_times[32]; /* histogram of requests's times */
  444. unsigned int dasd_io_timps[32]; /* h. of requests's times per sector */
  445. unsigned int dasd_io_time1[32]; /* hist. of time from build to start */
  446. unsigned int dasd_io_time2[32]; /* hist. of time from start to irq */
  447. unsigned int dasd_io_time2ps[32]; /* hist. of time from start to irq */
  448. unsigned int dasd_io_time3[32]; /* hist. of time from irq to end */
  449. unsigned int dasd_io_nr_req[32]; /* hist. of # of requests in chanq */
  450. /* new data */
  451. struct timespec64 starttod; /* time of start or last reset */
  452. unsigned int dasd_io_alias; /* requests using an alias */
  453. unsigned int dasd_io_tpm; /* requests using transport mode */
  454. unsigned int dasd_read_reqs; /* total number of read requests */
  455. unsigned int dasd_read_sects; /* total number read sectors */
  456. unsigned int dasd_read_alias; /* read request using an alias */
  457. unsigned int dasd_read_tpm; /* read requests in transport mode */
  458. unsigned int dasd_read_secs[32]; /* histogram of request's sizes */
  459. unsigned int dasd_read_times[32]; /* histogram of requests's times */
  460. unsigned int dasd_read_time1[32]; /* hist. time from build to start */
  461. unsigned int dasd_read_time2[32]; /* hist. of time from start to irq */
  462. unsigned int dasd_read_time3[32]; /* hist. of time from irq to end */
  463. unsigned int dasd_read_nr_req[32]; /* hist. of # of requests in chanq */
  464. unsigned long dasd_sum_times; /* sum of request times */
  465. unsigned long dasd_sum_time_str; /* sum of time from build to start */
  466. unsigned long dasd_sum_time_irq; /* sum of time from start to irq */
  467. unsigned long dasd_sum_time_end; /* sum of time from irq to end */
  468. };
  469. struct dasd_profile {
  470. struct dentry *dentry;
  471. struct dasd_profile_info *data;
  472. spinlock_t lock;
  473. };
  474. struct dasd_format_entry {
  475. struct list_head list;
  476. sector_t track;
  477. };
  478. struct dasd_device {
  479. /* Block device stuff. */
  480. struct dasd_block *block;
  481. unsigned int devindex;
  482. unsigned long flags; /* per device flags */
  483. unsigned short features; /* copy of devmap-features (read-only!) */
  484. /* extended error reporting stuff (eer) */
  485. struct dasd_ccw_req *eer_cqr;
  486. /* Device discipline stuff. */
  487. struct dasd_discipline *discipline;
  488. struct dasd_discipline *base_discipline;
  489. void *private;
  490. struct dasd_path path[8];
  491. __u8 opm;
  492. /* Device state and target state. */
  493. int state, target;
  494. struct mutex state_mutex;
  495. int stopped; /* device (ccw_device_start) was stopped */
  496. /* reference count. */
  497. atomic_t ref_count;
  498. /* ccw queue and memory for static ccw/erp buffers. */
  499. struct list_head ccw_queue;
  500. spinlock_t mem_lock;
  501. void *ccw_mem;
  502. void *erp_mem;
  503. void *ese_mem;
  504. struct list_head ccw_chunks;
  505. struct list_head erp_chunks;
  506. struct list_head ese_chunks;
  507. atomic_t tasklet_scheduled;
  508. struct tasklet_struct tasklet;
  509. struct work_struct kick_work;
  510. struct work_struct reload_device;
  511. struct work_struct kick_validate;
  512. struct work_struct suc_work;
  513. struct work_struct requeue_requests;
  514. struct timer_list timer;
  515. debug_info_t *debug_area;
  516. struct ccw_device *cdev;
  517. /* hook for alias management */
  518. struct list_head alias_list;
  519. /* default expiration time in s */
  520. unsigned long default_expires;
  521. unsigned long default_retries;
  522. unsigned long blk_timeout;
  523. unsigned long path_thrhld;
  524. unsigned long path_interval;
  525. struct dentry *debugfs_dentry;
  526. struct dentry *hosts_dentry;
  527. struct dasd_profile profile;
  528. struct dasd_format_entry format_entry;
  529. struct kset *paths_info;
  530. struct dasd_copy_relation *copy;
  531. unsigned long aq_mask;
  532. unsigned int aq_timeouts;
  533. };
  534. struct dasd_block {
  535. /* Block device stuff. */
  536. struct gendisk *gdp;
  537. spinlock_t request_queue_lock;
  538. struct blk_mq_tag_set tag_set;
  539. struct file *bdev_file;
  540. atomic_t open_count;
  541. unsigned long blocks; /* size of volume in blocks */
  542. unsigned int bp_block; /* bytes per block */
  543. unsigned int s2b_shift; /* log2 (bp_block/512) */
  544. struct dasd_device *base;
  545. struct list_head ccw_queue;
  546. spinlock_t queue_lock;
  547. atomic_t tasklet_scheduled;
  548. struct tasklet_struct tasklet;
  549. struct timer_list timer;
  550. struct dentry *debugfs_dentry;
  551. struct dasd_profile profile;
  552. struct list_head format_list;
  553. spinlock_t format_lock;
  554. atomic_t trkcount;
  555. };
  556. struct dasd_attention_data {
  557. struct dasd_device *device;
  558. __u8 lpum;
  559. };
  560. struct dasd_queue {
  561. spinlock_t lock;
  562. };
  563. /* reasons why device (ccw_device_start) was stopped */
  564. #define DASD_STOPPED_NOT_ACC 1 /* not accessible */
  565. #define DASD_STOPPED_QUIESCE 2 /* Quiesced */
  566. #define DASD_STOPPED_PENDING 4 /* long busy */
  567. #define DASD_STOPPED_DC_WAIT 8 /* disconnected, wait */
  568. #define DASD_STOPPED_SU 16 /* summary unit check handling */
  569. #define DASD_STOPPED_PPRC 32 /* PPRC swap */
  570. #define DASD_STOPPED_NOSPC 128 /* no space left */
  571. /* per device flags */
  572. #define DASD_FLAG_OFFLINE 3 /* device is in offline processing */
  573. #define DASD_FLAG_EER_SNSS 4 /* A SNSS is required */
  574. #define DASD_FLAG_EER_IN_USE 5 /* A SNSS request is running */
  575. #define DASD_FLAG_DEVICE_RO 6 /* The device itself is read-only. Don't
  576. * confuse this with the user specified
  577. * read-only feature.
  578. */
  579. #define DASD_FLAG_IS_RESERVED 7 /* The device is reserved */
  580. #define DASD_FLAG_LOCK_STOLEN 8 /* The device lock was stolen */
  581. #define DASD_FLAG_SUSPENDED 9 /* The device was suspended */
  582. #define DASD_FLAG_SAFE_OFFLINE 10 /* safe offline processing requested*/
  583. #define DASD_FLAG_SAFE_OFFLINE_RUNNING 11 /* safe offline running */
  584. #define DASD_FLAG_ABORTALL 12 /* Abort all noretry requests */
  585. #define DASD_FLAG_PATH_VERIFY 13 /* Path verification worker running */
  586. #define DASD_FLAG_SUC 14 /* unhandled summary unit check */
  587. #define DASD_SLEEPON_START_TAG ((void *) 1)
  588. #define DASD_SLEEPON_END_TAG ((void *) 2)
  589. void dasd_put_device_wake(struct dasd_device *);
  590. /*
  591. * return values to be returned from the copy pair swap function
  592. * 0x00: swap successful
  593. * 0x01: swap data invalid
  594. * 0x02: no active device found
  595. * 0x03: wrong primary specified
  596. * 0x04: secondary device not found
  597. * 0x05: swap already running
  598. */
  599. #define DASD_COPYPAIRSWAP_SUCCESS 0
  600. #define DASD_COPYPAIRSWAP_INVALID 1
  601. #define DASD_COPYPAIRSWAP_NOACTIVE 2
  602. #define DASD_COPYPAIRSWAP_PRIMARY 3
  603. #define DASD_COPYPAIRSWAP_SECONDARY 4
  604. #define DASD_COPYPAIRSWAP_MULTIPLE 5
  605. /*
  606. * Reference count inliners
  607. */
  608. static inline void
  609. dasd_get_device(struct dasd_device *device)
  610. {
  611. atomic_inc(&device->ref_count);
  612. }
  613. static inline void
  614. dasd_put_device(struct dasd_device *device)
  615. {
  616. if (atomic_dec_return(&device->ref_count) == 0)
  617. dasd_put_device_wake(device);
  618. }
  619. /*
  620. * The static memory in ccw_mem and erp_mem is managed by a sorted
  621. * list of free memory chunks.
  622. */
  623. struct dasd_mchunk
  624. {
  625. struct list_head list;
  626. unsigned long size;
  627. } __attribute__ ((aligned(8)));
  628. static inline void
  629. dasd_init_chunklist(struct list_head *chunk_list, void *mem,
  630. unsigned long size)
  631. {
  632. struct dasd_mchunk *chunk;
  633. INIT_LIST_HEAD(chunk_list);
  634. chunk = (struct dasd_mchunk *) mem;
  635. chunk->size = size - sizeof(struct dasd_mchunk);
  636. list_add(&chunk->list, chunk_list);
  637. }
  638. static inline void *
  639. dasd_alloc_chunk(struct list_head *chunk_list, unsigned long size)
  640. {
  641. struct dasd_mchunk *chunk, *tmp;
  642. size = (size + 7L) & -8L;
  643. list_for_each_entry(chunk, chunk_list, list) {
  644. if (chunk->size < size)
  645. continue;
  646. if (chunk->size > size + sizeof(struct dasd_mchunk)) {
  647. char *endaddr = (char *) (chunk + 1) + chunk->size;
  648. tmp = (struct dasd_mchunk *) (endaddr - size) - 1;
  649. tmp->size = size;
  650. chunk->size -= size + sizeof(struct dasd_mchunk);
  651. chunk = tmp;
  652. } else
  653. list_del(&chunk->list);
  654. return (void *) (chunk + 1);
  655. }
  656. return NULL;
  657. }
  658. static inline void
  659. dasd_free_chunk(struct list_head *chunk_list, void *mem)
  660. {
  661. struct dasd_mchunk *chunk, *tmp;
  662. struct list_head *p, *left;
  663. chunk = (struct dasd_mchunk *)
  664. ((char *) mem - sizeof(struct dasd_mchunk));
  665. /* Find out the left neighbour in chunk_list. */
  666. left = chunk_list;
  667. list_for_each(p, chunk_list) {
  668. if (list_entry(p, struct dasd_mchunk, list) > chunk)
  669. break;
  670. left = p;
  671. }
  672. /* Try to merge with right neighbour = next element from left. */
  673. if (left->next != chunk_list) {
  674. tmp = list_entry(left->next, struct dasd_mchunk, list);
  675. if ((char *) (chunk + 1) + chunk->size == (char *) tmp) {
  676. list_del(&tmp->list);
  677. chunk->size += tmp->size + sizeof(struct dasd_mchunk);
  678. }
  679. }
  680. /* Try to merge with left neighbour. */
  681. if (left != chunk_list) {
  682. tmp = list_entry(left, struct dasd_mchunk, list);
  683. if ((char *) (tmp + 1) + tmp->size == (char *) chunk) {
  684. tmp->size += chunk->size + sizeof(struct dasd_mchunk);
  685. return;
  686. }
  687. }
  688. __list_add(&chunk->list, left, left->next);
  689. }
  690. /*
  691. * Check if bsize is in { 512, 1024, 2048, 4096 }
  692. */
  693. static inline int
  694. dasd_check_blocksize(int bsize)
  695. {
  696. if (bsize < 512 || bsize > 4096 || !is_power_of_2(bsize))
  697. return -EMEDIUMTYPE;
  698. return 0;
  699. }
  700. /*
  701. * return the callback data of the original request in case there are
  702. * ERP requests build on top of it
  703. */
  704. static inline void *dasd_get_callback_data(struct dasd_ccw_req *cqr)
  705. {
  706. while (cqr->refers)
  707. cqr = cqr->refers;
  708. return cqr->callback_data;
  709. }
  710. /* externals in dasd.c */
  711. #define DASD_PROFILE_OFF 0
  712. #define DASD_PROFILE_ON 1
  713. #define DASD_PROFILE_GLOBAL_ONLY 2
  714. extern debug_info_t *dasd_debug_area;
  715. extern struct dasd_profile dasd_global_profile;
  716. extern unsigned int dasd_global_profile_level;
  717. extern const struct block_device_operations dasd_device_operations;
  718. extern struct blk_mq_ops dasd_mq_ops;
  719. extern struct kmem_cache *dasd_page_cache;
  720. struct dasd_ccw_req *
  721. dasd_smalloc_request(int, int, int, struct dasd_device *, struct dasd_ccw_req *);
  722. struct dasd_ccw_req *dasd_fmalloc_request(int, int, int, struct dasd_device *);
  723. void dasd_sfree_request(struct dasd_ccw_req *, struct dasd_device *);
  724. void dasd_ffree_request(struct dasd_ccw_req *, struct dasd_device *);
  725. void dasd_wakeup_cb(struct dasd_ccw_req *, void *);
  726. struct dasd_device *dasd_alloc_device(void);
  727. void dasd_free_device(struct dasd_device *);
  728. struct dasd_block *dasd_alloc_block(void);
  729. void dasd_free_block(struct dasd_block *);
  730. enum blk_eh_timer_return dasd_times_out(struct request *req);
  731. void dasd_enable_device(struct dasd_device *);
  732. void dasd_set_target_state(struct dasd_device *, int);
  733. void dasd_kick_device(struct dasd_device *);
  734. void dasd_reload_device(struct dasd_device *);
  735. void dasd_schedule_requeue(struct dasd_device *);
  736. void dasd_add_request_head(struct dasd_ccw_req *);
  737. void dasd_add_request_tail(struct dasd_ccw_req *);
  738. int dasd_start_IO(struct dasd_ccw_req *);
  739. int dasd_term_IO(struct dasd_ccw_req *);
  740. void dasd_schedule_device_bh(struct dasd_device *);
  741. void dasd_schedule_block_bh(struct dasd_block *);
  742. int dasd_sleep_on(struct dasd_ccw_req *);
  743. int dasd_sleep_on_queue(struct list_head *);
  744. int dasd_sleep_on_immediatly(struct dasd_ccw_req *);
  745. int dasd_sleep_on_queue_interruptible(struct list_head *);
  746. int dasd_sleep_on_interruptible(struct dasd_ccw_req *);
  747. void dasd_device_set_timer(struct dasd_device *, int);
  748. void dasd_device_clear_timer(struct dasd_device *);
  749. void dasd_block_set_timer(struct dasd_block *, int);
  750. void dasd_block_clear_timer(struct dasd_block *);
  751. int dasd_cancel_req(struct dasd_ccw_req *);
  752. int dasd_flush_device_queue(struct dasd_device *);
  753. int dasd_generic_probe(struct ccw_device *);
  754. void dasd_generic_free_discipline(struct dasd_device *);
  755. void dasd_generic_remove (struct ccw_device *cdev);
  756. int dasd_generic_set_online(struct ccw_device *, struct dasd_discipline *);
  757. int dasd_generic_set_offline (struct ccw_device *cdev);
  758. int dasd_generic_notify(struct ccw_device *, int);
  759. int dasd_generic_last_path_gone(struct dasd_device *);
  760. int dasd_generic_path_operational(struct dasd_device *);
  761. void dasd_generic_shutdown(struct ccw_device *);
  762. void dasd_generic_handle_state_change(struct dasd_device *);
  763. enum uc_todo dasd_generic_uc_handler(struct ccw_device *, struct irb *);
  764. void dasd_generic_path_event(struct ccw_device *, int *);
  765. int dasd_generic_verify_path(struct dasd_device *, __u8);
  766. void dasd_generic_space_exhaust(struct dasd_device *, struct dasd_ccw_req *);
  767. void dasd_generic_space_avail(struct dasd_device *);
  768. int dasd_generic_requeue_all_requests(struct dasd_device *);
  769. int dasd_generic_read_dev_chars(struct dasd_device *, int, void *, int);
  770. char *dasd_get_sense(struct irb *);
  771. void dasd_device_set_stop_bits(struct dasd_device *, int);
  772. void dasd_device_remove_stop_bits(struct dasd_device *, int);
  773. int dasd_device_is_ro(struct dasd_device *);
  774. void dasd_profile_reset(struct dasd_profile *);
  775. int dasd_profile_on(struct dasd_profile *);
  776. void dasd_profile_off(struct dasd_profile *);
  777. char *dasd_get_user_string(const char __user *, size_t);
  778. /* externals in dasd_devmap.c */
  779. extern int dasd_max_devindex;
  780. extern int dasd_probeonly;
  781. extern int dasd_autodetect;
  782. extern int dasd_nopav;
  783. extern int dasd_nofcx;
  784. int dasd_devmap_init(void);
  785. void dasd_devmap_exit(void);
  786. struct dasd_device *dasd_create_device(struct ccw_device *);
  787. void dasd_delete_device(struct dasd_device *);
  788. int dasd_get_feature(struct ccw_device *, int);
  789. int dasd_set_feature(struct ccw_device *, int, int);
  790. extern const struct attribute_group *dasd_dev_groups[];
  791. void dasd_path_create_kobj(struct dasd_device *, int);
  792. void dasd_path_create_kobjects(struct dasd_device *);
  793. void dasd_path_remove_kobjects(struct dasd_device *);
  794. struct dasd_device *dasd_device_from_cdev(struct ccw_device *);
  795. struct dasd_device *dasd_device_from_cdev_locked(struct ccw_device *);
  796. struct dasd_device *dasd_device_from_devindex(int);
  797. void dasd_add_link_to_gendisk(struct gendisk *, struct dasd_device *);
  798. struct dasd_device *dasd_device_from_gendisk(struct gendisk *);
  799. int dasd_parse(void) __init;
  800. int dasd_busid_known(const char *);
  801. /* externals in dasd_gendisk.c */
  802. int dasd_gendisk_init(void);
  803. void dasd_gendisk_exit(void);
  804. int dasd_gendisk_alloc(struct dasd_block *);
  805. void dasd_gendisk_free(struct dasd_block *);
  806. int dasd_scan_partitions(struct dasd_block *);
  807. void dasd_destroy_partitions(struct dasd_block *);
  808. /* externals in dasd_ioctl.c */
  809. int dasd_ioctl(struct block_device *bdev, blk_mode_t mode, unsigned int cmd,
  810. unsigned long arg);
  811. int dasd_set_read_only(struct block_device *bdev, bool ro);
  812. /* externals in dasd_proc.c */
  813. int dasd_proc_init(void);
  814. void dasd_proc_exit(void);
  815. /* externals in dasd_erp.c */
  816. struct dasd_ccw_req *dasd_default_erp_action(struct dasd_ccw_req *);
  817. struct dasd_ccw_req *dasd_default_erp_postaction(struct dasd_ccw_req *);
  818. struct dasd_ccw_req *dasd_alloc_erp_request(unsigned int, int, int,
  819. struct dasd_device *);
  820. void dasd_free_erp_request(struct dasd_ccw_req *, struct dasd_device *);
  821. void dasd_log_sense(struct dasd_ccw_req *, struct irb *);
  822. void dasd_log_sense_dbf(struct dasd_ccw_req *cqr, struct irb *irb);
  823. /* externals in dasd_3990_erp.c */
  824. struct dasd_ccw_req *dasd_3990_erp_action(struct dasd_ccw_req *);
  825. void dasd_3990_erp_handle_sim(struct dasd_device *, char *);
  826. /* externals in dasd_eer.c */
  827. #ifdef CONFIG_DASD_EER
  828. int dasd_eer_init(void);
  829. void dasd_eer_exit(void);
  830. int dasd_eer_enable(struct dasd_device *);
  831. void dasd_eer_disable(struct dasd_device *);
  832. void dasd_eer_write(struct dasd_device *, struct dasd_ccw_req *cqr,
  833. unsigned int id);
  834. void dasd_eer_snss(struct dasd_device *);
  835. static inline int dasd_eer_enabled(struct dasd_device *device)
  836. {
  837. return device->eer_cqr != NULL;
  838. }
  839. #else
  840. #define dasd_eer_init() (0)
  841. #define dasd_eer_exit() do { } while (0)
  842. #define dasd_eer_enable(d) (0)
  843. #define dasd_eer_disable(d) do { } while (0)
  844. #define dasd_eer_write(d,c,i) do { } while (0)
  845. #define dasd_eer_snss(d) do { } while (0)
  846. #define dasd_eer_enabled(d) (0)
  847. #endif /* CONFIG_DASD_ERR */
  848. /* DASD path handling functions */
  849. /*
  850. * helper functions to modify bit masks for a given channel path for a device
  851. */
  852. static inline int dasd_path_is_operational(struct dasd_device *device, int chp)
  853. {
  854. return test_bit(DASD_PATH_OPERATIONAL, &device->path[chp].flags);
  855. }
  856. static inline int dasd_path_need_verify(struct dasd_device *device, int chp)
  857. {
  858. return test_bit(DASD_PATH_TBV, &device->path[chp].flags);
  859. }
  860. static inline void dasd_path_verify(struct dasd_device *device, int chp)
  861. {
  862. __set_bit(DASD_PATH_TBV, &device->path[chp].flags);
  863. }
  864. static inline void dasd_path_clear_verify(struct dasd_device *device, int chp)
  865. {
  866. __clear_bit(DASD_PATH_TBV, &device->path[chp].flags);
  867. }
  868. static inline void dasd_path_clear_all_verify(struct dasd_device *device)
  869. {
  870. int chp;
  871. for (chp = 0; chp < 8; chp++)
  872. dasd_path_clear_verify(device, chp);
  873. }
  874. static inline void dasd_path_fcsec(struct dasd_device *device, int chp)
  875. {
  876. __set_bit(DASD_PATH_FCSEC, &device->path[chp].flags);
  877. }
  878. static inline void dasd_path_clear_fcsec(struct dasd_device *device, int chp)
  879. {
  880. __clear_bit(DASD_PATH_FCSEC, &device->path[chp].flags);
  881. }
  882. static inline int dasd_path_need_fcsec(struct dasd_device *device, int chp)
  883. {
  884. return test_bit(DASD_PATH_FCSEC, &device->path[chp].flags);
  885. }
  886. static inline void dasd_path_clear_all_fcsec(struct dasd_device *device)
  887. {
  888. int chp;
  889. for (chp = 0; chp < 8; chp++)
  890. dasd_path_clear_fcsec(device, chp);
  891. }
  892. static inline void dasd_path_operational(struct dasd_device *device, int chp)
  893. {
  894. __set_bit(DASD_PATH_OPERATIONAL, &device->path[chp].flags);
  895. device->opm |= (0x80 >> chp);
  896. }
  897. static inline void dasd_path_nonpreferred(struct dasd_device *device, int chp)
  898. {
  899. __set_bit(DASD_PATH_NPP, &device->path[chp].flags);
  900. }
  901. static inline int dasd_path_is_nonpreferred(struct dasd_device *device, int chp)
  902. {
  903. return test_bit(DASD_PATH_NPP, &device->path[chp].flags);
  904. }
  905. static inline void dasd_path_clear_nonpreferred(struct dasd_device *device,
  906. int chp)
  907. {
  908. __clear_bit(DASD_PATH_NPP, &device->path[chp].flags);
  909. }
  910. static inline void dasd_path_preferred(struct dasd_device *device, int chp)
  911. {
  912. __set_bit(DASD_PATH_PP, &device->path[chp].flags);
  913. }
  914. static inline int dasd_path_is_preferred(struct dasd_device *device, int chp)
  915. {
  916. return test_bit(DASD_PATH_PP, &device->path[chp].flags);
  917. }
  918. static inline void dasd_path_clear_preferred(struct dasd_device *device,
  919. int chp)
  920. {
  921. __clear_bit(DASD_PATH_PP, &device->path[chp].flags);
  922. }
  923. static inline void dasd_path_clear_oper(struct dasd_device *device, int chp)
  924. {
  925. __clear_bit(DASD_PATH_OPERATIONAL, &device->path[chp].flags);
  926. device->opm &= ~(0x80 >> chp);
  927. }
  928. static inline void dasd_path_clear_cable(struct dasd_device *device, int chp)
  929. {
  930. __clear_bit(DASD_PATH_MISCABLED, &device->path[chp].flags);
  931. }
  932. static inline void dasd_path_cuir(struct dasd_device *device, int chp)
  933. {
  934. __set_bit(DASD_PATH_CUIR, &device->path[chp].flags);
  935. }
  936. static inline int dasd_path_is_cuir(struct dasd_device *device, int chp)
  937. {
  938. return test_bit(DASD_PATH_CUIR, &device->path[chp].flags);
  939. }
  940. static inline void dasd_path_clear_cuir(struct dasd_device *device, int chp)
  941. {
  942. __clear_bit(DASD_PATH_CUIR, &device->path[chp].flags);
  943. }
  944. static inline void dasd_path_ifcc(struct dasd_device *device, int chp)
  945. {
  946. set_bit(DASD_PATH_IFCC, &device->path[chp].flags);
  947. }
  948. static inline int dasd_path_is_ifcc(struct dasd_device *device, int chp)
  949. {
  950. return test_bit(DASD_PATH_IFCC, &device->path[chp].flags);
  951. }
  952. static inline void dasd_path_clear_ifcc(struct dasd_device *device, int chp)
  953. {
  954. clear_bit(DASD_PATH_IFCC, &device->path[chp].flags);
  955. }
  956. static inline void dasd_path_clear_nohpf(struct dasd_device *device, int chp)
  957. {
  958. __clear_bit(DASD_PATH_NOHPF, &device->path[chp].flags);
  959. }
  960. static inline void dasd_path_miscabled(struct dasd_device *device, int chp)
  961. {
  962. __set_bit(DASD_PATH_MISCABLED, &device->path[chp].flags);
  963. }
  964. static inline int dasd_path_is_miscabled(struct dasd_device *device, int chp)
  965. {
  966. return test_bit(DASD_PATH_MISCABLED, &device->path[chp].flags);
  967. }
  968. static inline void dasd_path_nohpf(struct dasd_device *device, int chp)
  969. {
  970. __set_bit(DASD_PATH_NOHPF, &device->path[chp].flags);
  971. }
  972. static inline int dasd_path_is_nohpf(struct dasd_device *device, int chp)
  973. {
  974. return test_bit(DASD_PATH_NOHPF, &device->path[chp].flags);
  975. }
  976. /*
  977. * get functions for path masks
  978. * will return a path masks for the given device
  979. */
  980. static inline __u8 dasd_path_get_opm(struct dasd_device *device)
  981. {
  982. return device->opm;
  983. }
  984. static inline __u8 dasd_path_get_tbvpm(struct dasd_device *device)
  985. {
  986. int chp;
  987. __u8 tbvpm = 0x00;
  988. for (chp = 0; chp < 8; chp++)
  989. if (dasd_path_need_verify(device, chp))
  990. tbvpm |= 0x80 >> chp;
  991. return tbvpm;
  992. }
  993. static inline int dasd_path_get_fcsecpm(struct dasd_device *device)
  994. {
  995. int chp;
  996. for (chp = 0; chp < 8; chp++)
  997. if (dasd_path_need_fcsec(device, chp))
  998. return 1;
  999. return 0;
  1000. }
  1001. static inline __u8 dasd_path_get_nppm(struct dasd_device *device)
  1002. {
  1003. int chp;
  1004. __u8 npm = 0x00;
  1005. for (chp = 0; chp < 8; chp++) {
  1006. if (dasd_path_is_nonpreferred(device, chp))
  1007. npm |= 0x80 >> chp;
  1008. }
  1009. return npm;
  1010. }
  1011. static inline __u8 dasd_path_get_ppm(struct dasd_device *device)
  1012. {
  1013. int chp;
  1014. __u8 ppm = 0x00;
  1015. for (chp = 0; chp < 8; chp++)
  1016. if (dasd_path_is_preferred(device, chp))
  1017. ppm |= 0x80 >> chp;
  1018. return ppm;
  1019. }
  1020. static inline __u8 dasd_path_get_cablepm(struct dasd_device *device)
  1021. {
  1022. int chp;
  1023. __u8 cablepm = 0x00;
  1024. for (chp = 0; chp < 8; chp++)
  1025. if (dasd_path_is_miscabled(device, chp))
  1026. cablepm |= 0x80 >> chp;
  1027. return cablepm;
  1028. }
  1029. static inline __u8 dasd_path_get_cuirpm(struct dasd_device *device)
  1030. {
  1031. int chp;
  1032. __u8 cuirpm = 0x00;
  1033. for (chp = 0; chp < 8; chp++)
  1034. if (dasd_path_is_cuir(device, chp))
  1035. cuirpm |= 0x80 >> chp;
  1036. return cuirpm;
  1037. }
  1038. static inline __u8 dasd_path_get_ifccpm(struct dasd_device *device)
  1039. {
  1040. int chp;
  1041. __u8 ifccpm = 0x00;
  1042. for (chp = 0; chp < 8; chp++)
  1043. if (dasd_path_is_ifcc(device, chp))
  1044. ifccpm |= 0x80 >> chp;
  1045. return ifccpm;
  1046. }
  1047. static inline __u8 dasd_path_get_hpfpm(struct dasd_device *device)
  1048. {
  1049. int chp;
  1050. __u8 hpfpm = 0x00;
  1051. for (chp = 0; chp < 8; chp++)
  1052. if (dasd_path_is_nohpf(device, chp))
  1053. hpfpm |= 0x80 >> chp;
  1054. return hpfpm;
  1055. }
  1056. static inline u8 dasd_path_get_fcs_path(struct dasd_device *device, int chp)
  1057. {
  1058. return device->path[chp].fc_security;
  1059. }
  1060. static inline int dasd_path_get_fcs_device(struct dasd_device *device)
  1061. {
  1062. u8 fc_sec = 0;
  1063. int chp;
  1064. for (chp = 0; chp < 8; chp++) {
  1065. if (device->opm & (0x80 >> chp)) {
  1066. fc_sec = device->path[chp].fc_security;
  1067. break;
  1068. }
  1069. }
  1070. for (; chp < 8; chp++) {
  1071. if (device->opm & (0x80 >> chp))
  1072. if (device->path[chp].fc_security != fc_sec)
  1073. return -EINVAL;
  1074. }
  1075. return fc_sec;
  1076. }
  1077. /*
  1078. * add functions for path masks
  1079. * the existing path mask will be extended by the given path mask
  1080. */
  1081. static inline void dasd_path_add_tbvpm(struct dasd_device *device, __u8 pm)
  1082. {
  1083. int chp;
  1084. for (chp = 0; chp < 8; chp++)
  1085. if (pm & (0x80 >> chp))
  1086. dasd_path_verify(device, chp);
  1087. }
  1088. static inline __u8 dasd_path_get_notoperpm(struct dasd_device *device)
  1089. {
  1090. int chp;
  1091. __u8 nopm = 0x00;
  1092. for (chp = 0; chp < 8; chp++)
  1093. if (dasd_path_is_nohpf(device, chp) ||
  1094. dasd_path_is_ifcc(device, chp) ||
  1095. dasd_path_is_cuir(device, chp) ||
  1096. dasd_path_is_miscabled(device, chp))
  1097. nopm |= 0x80 >> chp;
  1098. return nopm;
  1099. }
  1100. static inline void dasd_path_add_opm(struct dasd_device *device, __u8 pm)
  1101. {
  1102. int chp;
  1103. for (chp = 0; chp < 8; chp++)
  1104. if (pm & (0x80 >> chp)) {
  1105. dasd_path_operational(device, chp);
  1106. /*
  1107. * if the path is used
  1108. * it should not be in one of the negative lists
  1109. */
  1110. dasd_path_clear_nohpf(device, chp);
  1111. dasd_path_clear_cuir(device, chp);
  1112. dasd_path_clear_cable(device, chp);
  1113. dasd_path_clear_ifcc(device, chp);
  1114. }
  1115. }
  1116. static inline void dasd_path_add_cablepm(struct dasd_device *device, __u8 pm)
  1117. {
  1118. int chp;
  1119. for (chp = 0; chp < 8; chp++)
  1120. if (pm & (0x80 >> chp))
  1121. dasd_path_miscabled(device, chp);
  1122. }
  1123. static inline void dasd_path_add_cuirpm(struct dasd_device *device, __u8 pm)
  1124. {
  1125. int chp;
  1126. for (chp = 0; chp < 8; chp++)
  1127. if (pm & (0x80 >> chp))
  1128. dasd_path_cuir(device, chp);
  1129. }
  1130. static inline void dasd_path_add_ifccpm(struct dasd_device *device, __u8 pm)
  1131. {
  1132. int chp;
  1133. for (chp = 0; chp < 8; chp++)
  1134. if (pm & (0x80 >> chp))
  1135. dasd_path_ifcc(device, chp);
  1136. }
  1137. static inline void dasd_path_add_nppm(struct dasd_device *device, __u8 pm)
  1138. {
  1139. int chp;
  1140. for (chp = 0; chp < 8; chp++)
  1141. if (pm & (0x80 >> chp))
  1142. dasd_path_nonpreferred(device, chp);
  1143. }
  1144. static inline void dasd_path_add_nohpfpm(struct dasd_device *device, __u8 pm)
  1145. {
  1146. int chp;
  1147. for (chp = 0; chp < 8; chp++)
  1148. if (pm & (0x80 >> chp))
  1149. dasd_path_nohpf(device, chp);
  1150. }
  1151. static inline void dasd_path_add_ppm(struct dasd_device *device, __u8 pm)
  1152. {
  1153. int chp;
  1154. for (chp = 0; chp < 8; chp++)
  1155. if (pm & (0x80 >> chp))
  1156. dasd_path_preferred(device, chp);
  1157. }
  1158. static inline void dasd_path_add_fcsecpm(struct dasd_device *device, __u8 pm)
  1159. {
  1160. int chp;
  1161. for (chp = 0; chp < 8; chp++)
  1162. if (pm & (0x80 >> chp))
  1163. dasd_path_fcsec(device, chp);
  1164. }
  1165. /*
  1166. * set functions for path masks
  1167. * the existing path mask will be replaced by the given path mask
  1168. */
  1169. static inline void dasd_path_set_tbvpm(struct dasd_device *device, __u8 pm)
  1170. {
  1171. int chp;
  1172. for (chp = 0; chp < 8; chp++)
  1173. if (pm & (0x80 >> chp))
  1174. dasd_path_verify(device, chp);
  1175. else
  1176. dasd_path_clear_verify(device, chp);
  1177. }
  1178. static inline void dasd_path_set_opm(struct dasd_device *device, __u8 pm)
  1179. {
  1180. int chp;
  1181. for (chp = 0; chp < 8; chp++) {
  1182. dasd_path_clear_oper(device, chp);
  1183. if (pm & (0x80 >> chp)) {
  1184. dasd_path_operational(device, chp);
  1185. /*
  1186. * if the path is used
  1187. * it should not be in one of the negative lists
  1188. */
  1189. dasd_path_clear_nohpf(device, chp);
  1190. dasd_path_clear_cuir(device, chp);
  1191. dasd_path_clear_cable(device, chp);
  1192. dasd_path_clear_ifcc(device, chp);
  1193. }
  1194. }
  1195. }
  1196. /*
  1197. * remove functions for path masks
  1198. * the existing path mask will be cleared with the given path mask
  1199. */
  1200. static inline void dasd_path_remove_opm(struct dasd_device *device, __u8 pm)
  1201. {
  1202. int chp;
  1203. for (chp = 0; chp < 8; chp++) {
  1204. if (pm & (0x80 >> chp))
  1205. dasd_path_clear_oper(device, chp);
  1206. }
  1207. }
  1208. /*
  1209. * add the newly available path to the to be verified pm and remove it from
  1210. * normal operation until it is verified
  1211. */
  1212. static inline void dasd_path_available(struct dasd_device *device, int chp)
  1213. {
  1214. dasd_path_clear_oper(device, chp);
  1215. dasd_path_verify(device, chp);
  1216. }
  1217. static inline void dasd_path_notoper(struct dasd_device *device, int chp)
  1218. {
  1219. dasd_path_clear_oper(device, chp);
  1220. dasd_path_clear_preferred(device, chp);
  1221. dasd_path_clear_nonpreferred(device, chp);
  1222. }
  1223. static inline void dasd_path_fcsec_update(struct dasd_device *device, int chp)
  1224. {
  1225. dasd_path_fcsec(device, chp);
  1226. }
  1227. /*
  1228. * remove all paths from normal operation
  1229. */
  1230. static inline void dasd_path_no_path(struct dasd_device *device)
  1231. {
  1232. int chp;
  1233. for (chp = 0; chp < 8; chp++)
  1234. dasd_path_notoper(device, chp);
  1235. dasd_path_clear_all_verify(device);
  1236. }
  1237. /* end - path handling */
  1238. #endif /* DASD_H */