i2o.h 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987
  1. /*
  2. * I2O kernel space accessible structures/APIs
  3. *
  4. * (c) Copyright 1999, 2000 Red Hat Software
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License
  8. * as published by the Free Software Foundation; either version
  9. * 2 of the License, or (at your option) any later version.
  10. *
  11. *************************************************************************
  12. *
  13. * This header file defined the I2O APIs/structures for use by
  14. * the I2O kernel modules.
  15. *
  16. */
  17. #ifndef _I2O_H
  18. #define _I2O_H
  19. #include <linux/i2o-dev.h>
  20. /* How many different OSM's are we allowing */
  21. #define I2O_MAX_DRIVERS 8
  22. #include <linux/pci.h>
  23. #include <linux/dma-mapping.h>
  24. #include <linux/string.h>
  25. #include <linux/slab.h>
  26. #include <linux/workqueue.h> /* work_struct */
  27. #include <linux/mempool.h>
  28. #include <linux/mutex.h>
  29. #include <linux/scatterlist.h>
  30. #include <linux/semaphore.h> /* Needed for MUTEX init macros */
  31. #include <asm/io.h>
  32. /* message queue empty */
  33. #define I2O_QUEUE_EMPTY 0xffffffff
  34. /*
  35. * Cache strategies
  36. */
  37. /* The NULL strategy leaves everything up to the controller. This tends to be a
  38. * pessimal but functional choice.
  39. */
  40. #define CACHE_NULL 0
  41. /* Prefetch data when reading. We continually attempt to load the next 32 sectors
  42. * into the controller cache.
  43. */
  44. #define CACHE_PREFETCH 1
  45. /* Prefetch data when reading. We sometimes attempt to load the next 32 sectors
  46. * into the controller cache. When an I/O is less <= 8K we assume its probably
  47. * not sequential and don't prefetch (default)
  48. */
  49. #define CACHE_SMARTFETCH 2
  50. /* Data is written to the cache and then out on to the disk. The I/O must be
  51. * physically on the medium before the write is acknowledged (default without
  52. * NVRAM)
  53. */
  54. #define CACHE_WRITETHROUGH 17
  55. /* Data is written to the cache and then out on to the disk. The controller
  56. * is permitted to write back the cache any way it wants. (default if battery
  57. * backed NVRAM is present). It can be useful to set this for swap regardless of
  58. * battery state.
  59. */
  60. #define CACHE_WRITEBACK 18
  61. /* Optimise for under powered controllers, especially on RAID1 and RAID0. We
  62. * write large I/O's directly to disk bypassing the cache to avoid the extra
  63. * memory copy hits. Small writes are writeback cached
  64. */
  65. #define CACHE_SMARTBACK 19
  66. /* Optimise for under powered controllers, especially on RAID1 and RAID0. We
  67. * write large I/O's directly to disk bypassing the cache to avoid the extra
  68. * memory copy hits. Small writes are writethrough cached. Suitable for devices
  69. * lacking battery backup
  70. */
  71. #define CACHE_SMARTTHROUGH 20
  72. /*
  73. * Ioctl structures
  74. */
  75. #define BLKI2OGRSTRAT _IOR('2', 1, int)
  76. #define BLKI2OGWSTRAT _IOR('2', 2, int)
  77. #define BLKI2OSRSTRAT _IOW('2', 3, int)
  78. #define BLKI2OSWSTRAT _IOW('2', 4, int)
  79. /*
  80. * I2O Function codes
  81. */
  82. /*
  83. * Executive Class
  84. */
  85. #define I2O_CMD_ADAPTER_ASSIGN 0xB3
  86. #define I2O_CMD_ADAPTER_READ 0xB2
  87. #define I2O_CMD_ADAPTER_RELEASE 0xB5
  88. #define I2O_CMD_BIOS_INFO_SET 0xA5
  89. #define I2O_CMD_BOOT_DEVICE_SET 0xA7
  90. #define I2O_CMD_CONFIG_VALIDATE 0xBB
  91. #define I2O_CMD_CONN_SETUP 0xCA
  92. #define I2O_CMD_DDM_DESTROY 0xB1
  93. #define I2O_CMD_DDM_ENABLE 0xD5
  94. #define I2O_CMD_DDM_QUIESCE 0xC7
  95. #define I2O_CMD_DDM_RESET 0xD9
  96. #define I2O_CMD_DDM_SUSPEND 0xAF
  97. #define I2O_CMD_DEVICE_ASSIGN 0xB7
  98. #define I2O_CMD_DEVICE_RELEASE 0xB9
  99. #define I2O_CMD_HRT_GET 0xA8
  100. #define I2O_CMD_ADAPTER_CLEAR 0xBE
  101. #define I2O_CMD_ADAPTER_CONNECT 0xC9
  102. #define I2O_CMD_ADAPTER_RESET 0xBD
  103. #define I2O_CMD_LCT_NOTIFY 0xA2
  104. #define I2O_CMD_OUTBOUND_INIT 0xA1
  105. #define I2O_CMD_PATH_ENABLE 0xD3
  106. #define I2O_CMD_PATH_QUIESCE 0xC5
  107. #define I2O_CMD_PATH_RESET 0xD7
  108. #define I2O_CMD_STATIC_MF_CREATE 0xDD
  109. #define I2O_CMD_STATIC_MF_RELEASE 0xDF
  110. #define I2O_CMD_STATUS_GET 0xA0
  111. #define I2O_CMD_SW_DOWNLOAD 0xA9
  112. #define I2O_CMD_SW_UPLOAD 0xAB
  113. #define I2O_CMD_SW_REMOVE 0xAD
  114. #define I2O_CMD_SYS_ENABLE 0xD1
  115. #define I2O_CMD_SYS_MODIFY 0xC1
  116. #define I2O_CMD_SYS_QUIESCE 0xC3
  117. #define I2O_CMD_SYS_TAB_SET 0xA3
  118. /*
  119. * Utility Class
  120. */
  121. #define I2O_CMD_UTIL_NOP 0x00
  122. #define I2O_CMD_UTIL_ABORT 0x01
  123. #define I2O_CMD_UTIL_CLAIM 0x09
  124. #define I2O_CMD_UTIL_RELEASE 0x0B
  125. #define I2O_CMD_UTIL_PARAMS_GET 0x06
  126. #define I2O_CMD_UTIL_PARAMS_SET 0x05
  127. #define I2O_CMD_UTIL_EVT_REGISTER 0x13
  128. #define I2O_CMD_UTIL_EVT_ACK 0x14
  129. #define I2O_CMD_UTIL_CONFIG_DIALOG 0x10
  130. #define I2O_CMD_UTIL_DEVICE_RESERVE 0x0D
  131. #define I2O_CMD_UTIL_DEVICE_RELEASE 0x0F
  132. #define I2O_CMD_UTIL_LOCK 0x17
  133. #define I2O_CMD_UTIL_LOCK_RELEASE 0x19
  134. #define I2O_CMD_UTIL_REPLY_FAULT_NOTIFY 0x15
  135. /*
  136. * SCSI Host Bus Adapter Class
  137. */
  138. #define I2O_CMD_SCSI_EXEC 0x81
  139. #define I2O_CMD_SCSI_ABORT 0x83
  140. #define I2O_CMD_SCSI_BUSRESET 0x27
  141. /*
  142. * Bus Adapter Class
  143. */
  144. #define I2O_CMD_BUS_ADAPTER_RESET 0x85
  145. #define I2O_CMD_BUS_RESET 0x87
  146. #define I2O_CMD_BUS_SCAN 0x89
  147. #define I2O_CMD_BUS_QUIESCE 0x8b
  148. /*
  149. * Random Block Storage Class
  150. */
  151. #define I2O_CMD_BLOCK_READ 0x30
  152. #define I2O_CMD_BLOCK_WRITE 0x31
  153. #define I2O_CMD_BLOCK_CFLUSH 0x37
  154. #define I2O_CMD_BLOCK_MLOCK 0x49
  155. #define I2O_CMD_BLOCK_MUNLOCK 0x4B
  156. #define I2O_CMD_BLOCK_MMOUNT 0x41
  157. #define I2O_CMD_BLOCK_MEJECT 0x43
  158. #define I2O_CMD_BLOCK_POWER 0x70
  159. #define I2O_CMD_PRIVATE 0xFF
  160. /* Command status values */
  161. #define I2O_CMD_IN_PROGRESS 0x01
  162. #define I2O_CMD_REJECTED 0x02
  163. #define I2O_CMD_FAILED 0x03
  164. #define I2O_CMD_COMPLETED 0x04
  165. /* I2O API function return values */
  166. #define I2O_RTN_NO_ERROR 0
  167. #define I2O_RTN_NOT_INIT 1
  168. #define I2O_RTN_FREE_Q_EMPTY 2
  169. #define I2O_RTN_TCB_ERROR 3
  170. #define I2O_RTN_TRANSACTION_ERROR 4
  171. #define I2O_RTN_ADAPTER_ALREADY_INIT 5
  172. #define I2O_RTN_MALLOC_ERROR 6
  173. #define I2O_RTN_ADPTR_NOT_REGISTERED 7
  174. #define I2O_RTN_MSG_REPLY_TIMEOUT 8
  175. #define I2O_RTN_NO_STATUS 9
  176. #define I2O_RTN_NO_FIRM_VER 10
  177. #define I2O_RTN_NO_LINK_SPEED 11
  178. /* Reply message status defines for all messages */
  179. #define I2O_REPLY_STATUS_SUCCESS 0x00
  180. #define I2O_REPLY_STATUS_ABORT_DIRTY 0x01
  181. #define I2O_REPLY_STATUS_ABORT_NO_DATA_TRANSFER 0x02
  182. #define I2O_REPLY_STATUS_ABORT_PARTIAL_TRANSFER 0x03
  183. #define I2O_REPLY_STATUS_ERROR_DIRTY 0x04
  184. #define I2O_REPLY_STATUS_ERROR_NO_DATA_TRANSFER 0x05
  185. #define I2O_REPLY_STATUS_ERROR_PARTIAL_TRANSFER 0x06
  186. #define I2O_REPLY_STATUS_PROCESS_ABORT_DIRTY 0x08
  187. #define I2O_REPLY_STATUS_PROCESS_ABORT_NO_DATA_TRANSFER 0x09
  188. #define I2O_REPLY_STATUS_PROCESS_ABORT_PARTIAL_TRANSFER 0x0A
  189. #define I2O_REPLY_STATUS_TRANSACTION_ERROR 0x0B
  190. #define I2O_REPLY_STATUS_PROGRESS_REPORT 0x80
  191. /* Status codes and Error Information for Parameter functions */
  192. #define I2O_PARAMS_STATUS_SUCCESS 0x00
  193. #define I2O_PARAMS_STATUS_BAD_KEY_ABORT 0x01
  194. #define I2O_PARAMS_STATUS_BAD_KEY_CONTINUE 0x02
  195. #define I2O_PARAMS_STATUS_BUFFER_FULL 0x03
  196. #define I2O_PARAMS_STATUS_BUFFER_TOO_SMALL 0x04
  197. #define I2O_PARAMS_STATUS_FIELD_UNREADABLE 0x05
  198. #define I2O_PARAMS_STATUS_FIELD_UNWRITEABLE 0x06
  199. #define I2O_PARAMS_STATUS_INSUFFICIENT_FIELDS 0x07
  200. #define I2O_PARAMS_STATUS_INVALID_GROUP_ID 0x08
  201. #define I2O_PARAMS_STATUS_INVALID_OPERATION 0x09
  202. #define I2O_PARAMS_STATUS_NO_KEY_FIELD 0x0A
  203. #define I2O_PARAMS_STATUS_NO_SUCH_FIELD 0x0B
  204. #define I2O_PARAMS_STATUS_NON_DYNAMIC_GROUP 0x0C
  205. #define I2O_PARAMS_STATUS_OPERATION_ERROR 0x0D
  206. #define I2O_PARAMS_STATUS_SCALAR_ERROR 0x0E
  207. #define I2O_PARAMS_STATUS_TABLE_ERROR 0x0F
  208. #define I2O_PARAMS_STATUS_WRONG_GROUP_TYPE 0x10
  209. /* DetailedStatusCode defines for Executive, DDM, Util and Transaction error
  210. * messages: Table 3-2 Detailed Status Codes.*/
  211. #define I2O_DSC_SUCCESS 0x0000
  212. #define I2O_DSC_BAD_KEY 0x0002
  213. #define I2O_DSC_TCL_ERROR 0x0003
  214. #define I2O_DSC_REPLY_BUFFER_FULL 0x0004
  215. #define I2O_DSC_NO_SUCH_PAGE 0x0005
  216. #define I2O_DSC_INSUFFICIENT_RESOURCE_SOFT 0x0006
  217. #define I2O_DSC_INSUFFICIENT_RESOURCE_HARD 0x0007
  218. #define I2O_DSC_CHAIN_BUFFER_TOO_LARGE 0x0009
  219. #define I2O_DSC_UNSUPPORTED_FUNCTION 0x000A
  220. #define I2O_DSC_DEVICE_LOCKED 0x000B
  221. #define I2O_DSC_DEVICE_RESET 0x000C
  222. #define I2O_DSC_INAPPROPRIATE_FUNCTION 0x000D
  223. #define I2O_DSC_INVALID_INITIATOR_ADDRESS 0x000E
  224. #define I2O_DSC_INVALID_MESSAGE_FLAGS 0x000F
  225. #define I2O_DSC_INVALID_OFFSET 0x0010
  226. #define I2O_DSC_INVALID_PARAMETER 0x0011
  227. #define I2O_DSC_INVALID_REQUEST 0x0012
  228. #define I2O_DSC_INVALID_TARGET_ADDRESS 0x0013
  229. #define I2O_DSC_MESSAGE_TOO_LARGE 0x0014
  230. #define I2O_DSC_MESSAGE_TOO_SMALL 0x0015
  231. #define I2O_DSC_MISSING_PARAMETER 0x0016
  232. #define I2O_DSC_TIMEOUT 0x0017
  233. #define I2O_DSC_UNKNOWN_ERROR 0x0018
  234. #define I2O_DSC_UNKNOWN_FUNCTION 0x0019
  235. #define I2O_DSC_UNSUPPORTED_VERSION 0x001A
  236. #define I2O_DSC_DEVICE_BUSY 0x001B
  237. #define I2O_DSC_DEVICE_NOT_AVAILABLE 0x001C
  238. /* DetailedStatusCode defines for Block Storage Operation: Table 6-7 Detailed
  239. Status Codes.*/
  240. #define I2O_BSA_DSC_SUCCESS 0x0000
  241. #define I2O_BSA_DSC_MEDIA_ERROR 0x0001
  242. #define I2O_BSA_DSC_ACCESS_ERROR 0x0002
  243. #define I2O_BSA_DSC_DEVICE_FAILURE 0x0003
  244. #define I2O_BSA_DSC_DEVICE_NOT_READY 0x0004
  245. #define I2O_BSA_DSC_MEDIA_NOT_PRESENT 0x0005
  246. #define I2O_BSA_DSC_MEDIA_LOCKED 0x0006
  247. #define I2O_BSA_DSC_MEDIA_FAILURE 0x0007
  248. #define I2O_BSA_DSC_PROTOCOL_FAILURE 0x0008
  249. #define I2O_BSA_DSC_BUS_FAILURE 0x0009
  250. #define I2O_BSA_DSC_ACCESS_VIOLATION 0x000A
  251. #define I2O_BSA_DSC_WRITE_PROTECTED 0x000B
  252. #define I2O_BSA_DSC_DEVICE_RESET 0x000C
  253. #define I2O_BSA_DSC_VOLUME_CHANGED 0x000D
  254. #define I2O_BSA_DSC_TIMEOUT 0x000E
  255. /* FailureStatusCodes, Table 3-3 Message Failure Codes */
  256. #define I2O_FSC_TRANSPORT_SERVICE_SUSPENDED 0x81
  257. #define I2O_FSC_TRANSPORT_SERVICE_TERMINATED 0x82
  258. #define I2O_FSC_TRANSPORT_CONGESTION 0x83
  259. #define I2O_FSC_TRANSPORT_FAILURE 0x84
  260. #define I2O_FSC_TRANSPORT_STATE_ERROR 0x85
  261. #define I2O_FSC_TRANSPORT_TIME_OUT 0x86
  262. #define I2O_FSC_TRANSPORT_ROUTING_FAILURE 0x87
  263. #define I2O_FSC_TRANSPORT_INVALID_VERSION 0x88
  264. #define I2O_FSC_TRANSPORT_INVALID_OFFSET 0x89
  265. #define I2O_FSC_TRANSPORT_INVALID_MSG_FLAGS 0x8A
  266. #define I2O_FSC_TRANSPORT_FRAME_TOO_SMALL 0x8B
  267. #define I2O_FSC_TRANSPORT_FRAME_TOO_LARGE 0x8C
  268. #define I2O_FSC_TRANSPORT_INVALID_TARGET_ID 0x8D
  269. #define I2O_FSC_TRANSPORT_INVALID_INITIATOR_ID 0x8E
  270. #define I2O_FSC_TRANSPORT_INVALID_INITIATOR_CONTEXT 0x8F
  271. #define I2O_FSC_TRANSPORT_UNKNOWN_FAILURE 0xFF
  272. /* Device Claim Types */
  273. #define I2O_CLAIM_PRIMARY 0x01000000
  274. #define I2O_CLAIM_MANAGEMENT 0x02000000
  275. #define I2O_CLAIM_AUTHORIZED 0x03000000
  276. #define I2O_CLAIM_SECONDARY 0x04000000
  277. /* Message header defines for VersionOffset */
  278. #define I2OVER15 0x0001
  279. #define I2OVER20 0x0002
  280. /* Default is 1.5 */
  281. #define I2OVERSION I2OVER15
  282. #define SGL_OFFSET_0 I2OVERSION
  283. #define SGL_OFFSET_4 (0x0040 | I2OVERSION)
  284. #define SGL_OFFSET_5 (0x0050 | I2OVERSION)
  285. #define SGL_OFFSET_6 (0x0060 | I2OVERSION)
  286. #define SGL_OFFSET_7 (0x0070 | I2OVERSION)
  287. #define SGL_OFFSET_8 (0x0080 | I2OVERSION)
  288. #define SGL_OFFSET_9 (0x0090 | I2OVERSION)
  289. #define SGL_OFFSET_10 (0x00A0 | I2OVERSION)
  290. #define SGL_OFFSET_11 (0x00B0 | I2OVERSION)
  291. #define SGL_OFFSET_12 (0x00C0 | I2OVERSION)
  292. #define SGL_OFFSET(x) (((x)<<4) | I2OVERSION)
  293. /* Transaction Reply Lists (TRL) Control Word structure */
  294. #define TRL_SINGLE_FIXED_LENGTH 0x00
  295. #define TRL_SINGLE_VARIABLE_LENGTH 0x40
  296. #define TRL_MULTIPLE_FIXED_LENGTH 0x80
  297. /* msg header defines for MsgFlags */
  298. #define MSG_STATIC 0x0100
  299. #define MSG_64BIT_CNTXT 0x0200
  300. #define MSG_MULTI_TRANS 0x1000
  301. #define MSG_FAIL 0x2000
  302. #define MSG_FINAL 0x4000
  303. #define MSG_REPLY 0x8000
  304. /* minimum size msg */
  305. #define THREE_WORD_MSG_SIZE 0x00030000
  306. #define FOUR_WORD_MSG_SIZE 0x00040000
  307. #define FIVE_WORD_MSG_SIZE 0x00050000
  308. #define SIX_WORD_MSG_SIZE 0x00060000
  309. #define SEVEN_WORD_MSG_SIZE 0x00070000
  310. #define EIGHT_WORD_MSG_SIZE 0x00080000
  311. #define NINE_WORD_MSG_SIZE 0x00090000
  312. #define TEN_WORD_MSG_SIZE 0x000A0000
  313. #define ELEVEN_WORD_MSG_SIZE 0x000B0000
  314. #define I2O_MESSAGE_SIZE(x) ((x)<<16)
  315. /* special TID assignments */
  316. #define ADAPTER_TID 0
  317. #define HOST_TID 1
  318. /* outbound queue defines */
  319. #define I2O_MAX_OUTBOUND_MSG_FRAMES 128
  320. #define I2O_OUTBOUND_MSG_FRAME_SIZE 128 /* in 32-bit words */
  321. /* inbound queue definitions */
  322. #define I2O_MSG_INPOOL_MIN 32
  323. #define I2O_INBOUND_MSG_FRAME_SIZE 128 /* in 32-bit words */
  324. #define I2O_POST_WAIT_OK 0
  325. #define I2O_POST_WAIT_TIMEOUT -ETIMEDOUT
  326. #define I2O_CONTEXT_LIST_MIN_LENGTH 15
  327. #define I2O_CONTEXT_LIST_USED 0x01
  328. #define I2O_CONTEXT_LIST_DELETED 0x02
  329. /* timeouts */
  330. #define I2O_TIMEOUT_INIT_OUTBOUND_QUEUE 15
  331. #define I2O_TIMEOUT_MESSAGE_GET 5
  332. #define I2O_TIMEOUT_RESET 30
  333. #define I2O_TIMEOUT_STATUS_GET 5
  334. #define I2O_TIMEOUT_LCT_GET 360
  335. #define I2O_TIMEOUT_SCSI_SCB_ABORT 240
  336. /* retries */
  337. #define I2O_HRT_GET_TRIES 3
  338. #define I2O_LCT_GET_TRIES 3
  339. /* defines for max_sectors and max_phys_segments */
  340. #define I2O_MAX_SECTORS 1024
  341. #define I2O_MAX_SECTORS_LIMITED 128
  342. #define I2O_MAX_PHYS_SEGMENTS BLK_MAX_SEGMENTS
  343. /*
  344. * Message structures
  345. */
  346. struct i2o_message {
  347. union {
  348. struct {
  349. u8 version_offset;
  350. u8 flags;
  351. u16 size;
  352. u32 target_tid:12;
  353. u32 init_tid:12;
  354. u32 function:8;
  355. u32 icntxt; /* initiator context */
  356. u32 tcntxt; /* transaction context */
  357. } s;
  358. u32 head[4];
  359. } u;
  360. /* List follows */
  361. u32 body[0];
  362. };
  363. /* MFA and I2O message used by mempool */
  364. struct i2o_msg_mfa {
  365. u32 mfa; /* MFA returned by the controller */
  366. struct i2o_message msg; /* I2O message */
  367. };
  368. /*
  369. * Each I2O device entity has one of these. There is one per device.
  370. */
  371. struct i2o_device {
  372. i2o_lct_entry lct_data; /* Device LCT information */
  373. struct i2o_controller *iop; /* Controlling IOP */
  374. struct list_head list; /* node in IOP devices list */
  375. struct device device;
  376. struct mutex lock; /* device lock */
  377. };
  378. /*
  379. * Event structure provided to the event handling function
  380. */
  381. struct i2o_event {
  382. struct work_struct work;
  383. struct i2o_device *i2o_dev; /* I2O device pointer from which the
  384. event reply was initiated */
  385. u16 size; /* Size of data in 32-bit words */
  386. u32 tcntxt; /* Transaction context used at
  387. registration */
  388. u32 event_indicator; /* Event indicator from reply */
  389. u32 data[0]; /* Event data from reply */
  390. };
  391. /*
  392. * I2O classes which could be handled by the OSM
  393. */
  394. struct i2o_class_id {
  395. u16 class_id:12;
  396. };
  397. /*
  398. * I2O driver structure for OSMs
  399. */
  400. struct i2o_driver {
  401. char *name; /* OSM name */
  402. int context; /* Low 8 bits of the transaction info */
  403. struct i2o_class_id *classes; /* I2O classes that this OSM handles */
  404. /* Message reply handler */
  405. int (*reply) (struct i2o_controller *, u32, struct i2o_message *);
  406. /* Event handler */
  407. work_func_t event;
  408. struct workqueue_struct *event_queue; /* Event queue */
  409. struct device_driver driver;
  410. /* notification of changes */
  411. void (*notify_controller_add) (struct i2o_controller *);
  412. void (*notify_controller_remove) (struct i2o_controller *);
  413. void (*notify_device_add) (struct i2o_device *);
  414. void (*notify_device_remove) (struct i2o_device *);
  415. struct semaphore lock;
  416. };
  417. /*
  418. * Contains DMA mapped address information
  419. */
  420. struct i2o_dma {
  421. void *virt;
  422. dma_addr_t phys;
  423. size_t len;
  424. };
  425. /*
  426. * Contains slab cache and mempool information
  427. */
  428. struct i2o_pool {
  429. char *name;
  430. struct kmem_cache *slab;
  431. mempool_t *mempool;
  432. };
  433. /*
  434. * Contains IO mapped address information
  435. */
  436. struct i2o_io {
  437. void __iomem *virt;
  438. unsigned long phys;
  439. unsigned long len;
  440. };
  441. /*
  442. * Context queue entry, used for 32-bit context on 64-bit systems
  443. */
  444. struct i2o_context_list_element {
  445. struct list_head list;
  446. u32 context;
  447. void *ptr;
  448. unsigned long timestamp;
  449. };
  450. /*
  451. * Each I2O controller has one of these objects
  452. */
  453. struct i2o_controller {
  454. char name[16];
  455. int unit;
  456. int type;
  457. struct pci_dev *pdev; /* PCI device */
  458. unsigned int promise:1; /* Promise controller */
  459. unsigned int adaptec:1; /* DPT / Adaptec controller */
  460. unsigned int raptor:1; /* split bar */
  461. unsigned int no_quiesce:1; /* dont quiesce before reset */
  462. unsigned int short_req:1; /* use small block sizes */
  463. unsigned int limit_sectors:1; /* limit number of sectors / request */
  464. unsigned int pae_support:1; /* controller has 64-bit SGL support */
  465. struct list_head devices; /* list of I2O devices */
  466. struct list_head list; /* Controller list */
  467. void __iomem *in_port; /* Inbout port address */
  468. void __iomem *out_port; /* Outbound port address */
  469. void __iomem *irq_status; /* Interrupt status register address */
  470. void __iomem *irq_mask; /* Interrupt mask register address */
  471. struct i2o_dma status; /* IOP status block */
  472. struct i2o_dma hrt; /* HW Resource Table */
  473. i2o_lct *lct; /* Logical Config Table */
  474. struct i2o_dma dlct; /* Temp LCT */
  475. struct mutex lct_lock; /* Lock for LCT updates */
  476. struct i2o_dma status_block; /* IOP status block */
  477. struct i2o_io base; /* controller messaging unit */
  478. struct i2o_io in_queue; /* inbound message queue Host->IOP */
  479. struct i2o_dma out_queue; /* outbound message queue IOP->Host */
  480. struct i2o_pool in_msg; /* mempool for inbound messages */
  481. unsigned int battery:1; /* Has a battery backup */
  482. unsigned int io_alloc:1; /* An I/O resource was allocated */
  483. unsigned int mem_alloc:1; /* A memory resource was allocated */
  484. struct resource io_resource; /* I/O resource allocated to the IOP */
  485. struct resource mem_resource; /* Mem resource allocated to the IOP */
  486. struct device device;
  487. struct i2o_device *exec; /* Executive */
  488. #if BITS_PER_LONG == 64
  489. spinlock_t context_list_lock; /* lock for context_list */
  490. atomic_t context_list_counter; /* needed for unique contexts */
  491. struct list_head context_list; /* list of context id's
  492. and pointers */
  493. #endif
  494. spinlock_t lock; /* lock for controller
  495. configuration */
  496. void *driver_data[I2O_MAX_DRIVERS]; /* storage for drivers */
  497. };
  498. /*
  499. * I2O System table entry
  500. *
  501. * The system table contains information about all the IOPs in the
  502. * system. It is sent to all IOPs so that they can create peer2peer
  503. * connections between them.
  504. */
  505. struct i2o_sys_tbl_entry {
  506. u16 org_id;
  507. u16 reserved1;
  508. u32 iop_id:12;
  509. u32 reserved2:20;
  510. u16 seg_num:12;
  511. u16 i2o_version:4;
  512. u8 iop_state;
  513. u8 msg_type;
  514. u16 frame_size;
  515. u16 reserved3;
  516. u32 last_changed;
  517. u32 iop_capabilities;
  518. u32 inbound_low;
  519. u32 inbound_high;
  520. };
  521. struct i2o_sys_tbl {
  522. u8 num_entries;
  523. u8 version;
  524. u16 reserved1;
  525. u32 change_ind;
  526. u32 reserved2;
  527. u32 reserved3;
  528. struct i2o_sys_tbl_entry iops[0];
  529. };
  530. extern struct list_head i2o_controllers;
  531. /* Message functions */
  532. extern struct i2o_message *i2o_msg_get_wait(struct i2o_controller *, int);
  533. extern int i2o_msg_post_wait_mem(struct i2o_controller *, struct i2o_message *,
  534. unsigned long, struct i2o_dma *);
  535. /* IOP functions */
  536. extern int i2o_status_get(struct i2o_controller *);
  537. extern int i2o_event_register(struct i2o_device *, struct i2o_driver *, int,
  538. u32);
  539. extern struct i2o_device *i2o_iop_find_device(struct i2o_controller *, u16);
  540. extern struct i2o_controller *i2o_find_iop(int);
  541. /* Functions needed for handling 64-bit pointers in 32-bit context */
  542. #if BITS_PER_LONG == 64
  543. extern u32 i2o_cntxt_list_add(struct i2o_controller *, void *);
  544. extern void *i2o_cntxt_list_get(struct i2o_controller *, u32);
  545. extern u32 i2o_cntxt_list_remove(struct i2o_controller *, void *);
  546. extern u32 i2o_cntxt_list_get_ptr(struct i2o_controller *, void *);
  547. static inline u32 i2o_ptr_low(void *ptr)
  548. {
  549. return (u32) (u64) ptr;
  550. };
  551. static inline u32 i2o_ptr_high(void *ptr)
  552. {
  553. return (u32) ((u64) ptr >> 32);
  554. };
  555. static inline u32 i2o_dma_low(dma_addr_t dma_addr)
  556. {
  557. return (u32) (u64) dma_addr;
  558. };
  559. static inline u32 i2o_dma_high(dma_addr_t dma_addr)
  560. {
  561. return (u32) ((u64) dma_addr >> 32);
  562. };
  563. #else
  564. static inline u32 i2o_cntxt_list_add(struct i2o_controller *c, void *ptr)
  565. {
  566. return (u32) ptr;
  567. };
  568. static inline void *i2o_cntxt_list_get(struct i2o_controller *c, u32 context)
  569. {
  570. return (void *)context;
  571. };
  572. static inline u32 i2o_cntxt_list_remove(struct i2o_controller *c, void *ptr)
  573. {
  574. return (u32) ptr;
  575. };
  576. static inline u32 i2o_cntxt_list_get_ptr(struct i2o_controller *c, void *ptr)
  577. {
  578. return (u32) ptr;
  579. };
  580. static inline u32 i2o_ptr_low(void *ptr)
  581. {
  582. return (u32) ptr;
  583. };
  584. static inline u32 i2o_ptr_high(void *ptr)
  585. {
  586. return 0;
  587. };
  588. static inline u32 i2o_dma_low(dma_addr_t dma_addr)
  589. {
  590. return (u32) dma_addr;
  591. };
  592. static inline u32 i2o_dma_high(dma_addr_t dma_addr)
  593. {
  594. return 0;
  595. };
  596. #endif
  597. extern u16 i2o_sg_tablesize(struct i2o_controller *c, u16 body_size);
  598. extern dma_addr_t i2o_dma_map_single(struct i2o_controller *c, void *ptr,
  599. size_t size,
  600. enum dma_data_direction direction,
  601. u32 ** sg_ptr);
  602. extern int i2o_dma_map_sg(struct i2o_controller *c,
  603. struct scatterlist *sg, int sg_count,
  604. enum dma_data_direction direction,
  605. u32 ** sg_ptr);
  606. extern int i2o_dma_alloc(struct device *dev, struct i2o_dma *addr, size_t len);
  607. extern void i2o_dma_free(struct device *dev, struct i2o_dma *addr);
  608. extern int i2o_dma_realloc(struct device *dev, struct i2o_dma *addr,
  609. size_t len);
  610. extern int i2o_pool_alloc(struct i2o_pool *pool, const char *name,
  611. size_t size, int min_nr);
  612. extern void i2o_pool_free(struct i2o_pool *pool);
  613. /* I2O driver (OSM) functions */
  614. extern int i2o_driver_register(struct i2o_driver *);
  615. extern void i2o_driver_unregister(struct i2o_driver *);
  616. /**
  617. * i2o_driver_notify_controller_add - Send notification of added controller
  618. * @drv: I2O driver
  619. * @c: I2O controller
  620. *
  621. * Send notification of added controller to a single registered driver.
  622. */
  623. static inline void i2o_driver_notify_controller_add(struct i2o_driver *drv,
  624. struct i2o_controller *c)
  625. {
  626. if (drv->notify_controller_add)
  627. drv->notify_controller_add(c);
  628. };
  629. /**
  630. * i2o_driver_notify_controller_remove - Send notification of removed controller
  631. * @drv: I2O driver
  632. * @c: I2O controller
  633. *
  634. * Send notification of removed controller to a single registered driver.
  635. */
  636. static inline void i2o_driver_notify_controller_remove(struct i2o_driver *drv,
  637. struct i2o_controller *c)
  638. {
  639. if (drv->notify_controller_remove)
  640. drv->notify_controller_remove(c);
  641. };
  642. /**
  643. * i2o_driver_notify_device_add - Send notification of added device
  644. * @drv: I2O driver
  645. * @i2o_dev: the added i2o_device
  646. *
  647. * Send notification of added device to a single registered driver.
  648. */
  649. static inline void i2o_driver_notify_device_add(struct i2o_driver *drv,
  650. struct i2o_device *i2o_dev)
  651. {
  652. if (drv->notify_device_add)
  653. drv->notify_device_add(i2o_dev);
  654. };
  655. /**
  656. * i2o_driver_notify_device_remove - Send notification of removed device
  657. * @drv: I2O driver
  658. * @i2o_dev: the added i2o_device
  659. *
  660. * Send notification of removed device to a single registered driver.
  661. */
  662. static inline void i2o_driver_notify_device_remove(struct i2o_driver *drv,
  663. struct i2o_device *i2o_dev)
  664. {
  665. if (drv->notify_device_remove)
  666. drv->notify_device_remove(i2o_dev);
  667. };
  668. extern void i2o_driver_notify_controller_add_all(struct i2o_controller *);
  669. extern void i2o_driver_notify_controller_remove_all(struct i2o_controller *);
  670. extern void i2o_driver_notify_device_add_all(struct i2o_device *);
  671. extern void i2o_driver_notify_device_remove_all(struct i2o_device *);
  672. /* I2O device functions */
  673. extern int i2o_device_claim(struct i2o_device *);
  674. extern int i2o_device_claim_release(struct i2o_device *);
  675. /* Exec OSM functions */
  676. extern int i2o_exec_lct_get(struct i2o_controller *);
  677. /* device / driver / kobject conversion functions */
  678. #define to_i2o_driver(drv) container_of(drv,struct i2o_driver, driver)
  679. #define to_i2o_device(dev) container_of(dev, struct i2o_device, device)
  680. #define to_i2o_controller(dev) container_of(dev, struct i2o_controller, device)
  681. /**
  682. * i2o_out_to_virt - Turn an I2O message to a virtual address
  683. * @c: controller
  684. * @m: message engine value
  685. *
  686. * Turn a receive message from an I2O controller bus address into
  687. * a Linux virtual address. The shared page frame is a linear block
  688. * so we simply have to shift the offset. This function does not
  689. * work for sender side messages as they are ioremap objects
  690. * provided by the I2O controller.
  691. */
  692. static inline struct i2o_message *i2o_msg_out_to_virt(struct i2o_controller *c,
  693. u32 m)
  694. {
  695. BUG_ON(m < c->out_queue.phys
  696. || m >= c->out_queue.phys + c->out_queue.len);
  697. return c->out_queue.virt + (m - c->out_queue.phys);
  698. };
  699. /**
  700. * i2o_msg_in_to_virt - Turn an I2O message to a virtual address
  701. * @c: controller
  702. * @m: message engine value
  703. *
  704. * Turn a send message from an I2O controller bus address into
  705. * a Linux virtual address. The shared page frame is a linear block
  706. * so we simply have to shift the offset. This function does not
  707. * work for receive side messages as they are kmalloc objects
  708. * in a different pool.
  709. */
  710. static inline struct i2o_message __iomem *i2o_msg_in_to_virt(struct
  711. i2o_controller *c,
  712. u32 m)
  713. {
  714. return c->in_queue.virt + m;
  715. };
  716. /**
  717. * i2o_msg_get - obtain an I2O message from the IOP
  718. * @c: I2O controller
  719. *
  720. * This function tries to get a message frame. If no message frame is
  721. * available do not wait until one is availabe (see also i2o_msg_get_wait).
  722. * The returned pointer to the message frame is not in I/O memory, it is
  723. * allocated from a mempool. But because a MFA is allocated from the
  724. * controller too it is guaranteed that i2o_msg_post() will never fail.
  725. *
  726. * On a success a pointer to the message frame is returned. If the message
  727. * queue is empty -EBUSY is returned and if no memory is available -ENOMEM
  728. * is returned.
  729. */
  730. static inline struct i2o_message *i2o_msg_get(struct i2o_controller *c)
  731. {
  732. struct i2o_msg_mfa *mmsg = mempool_alloc(c->in_msg.mempool, GFP_ATOMIC);
  733. if (!mmsg)
  734. return ERR_PTR(-ENOMEM);
  735. mmsg->mfa = readl(c->in_port);
  736. if (unlikely(mmsg->mfa >= c->in_queue.len)) {
  737. u32 mfa = mmsg->mfa;
  738. mempool_free(mmsg, c->in_msg.mempool);
  739. if (mfa == I2O_QUEUE_EMPTY)
  740. return ERR_PTR(-EBUSY);
  741. return ERR_PTR(-EFAULT);
  742. }
  743. return &mmsg->msg;
  744. };
  745. /**
  746. * i2o_msg_post - Post I2O message to I2O controller
  747. * @c: I2O controller to which the message should be send
  748. * @msg: message returned by i2o_msg_get()
  749. *
  750. * Post the message to the I2O controller and return immediately.
  751. */
  752. static inline void i2o_msg_post(struct i2o_controller *c,
  753. struct i2o_message *msg)
  754. {
  755. struct i2o_msg_mfa *mmsg;
  756. mmsg = container_of(msg, struct i2o_msg_mfa, msg);
  757. memcpy_toio(i2o_msg_in_to_virt(c, mmsg->mfa), msg,
  758. (le32_to_cpu(msg->u.head[0]) >> 16) << 2);
  759. writel(mmsg->mfa, c->in_port);
  760. mempool_free(mmsg, c->in_msg.mempool);
  761. };
  762. /**
  763. * i2o_msg_post_wait - Post and wait a message and wait until return
  764. * @c: controller
  765. * @msg: message to post
  766. * @timeout: time in seconds to wait
  767. *
  768. * This API allows an OSM to post a message and then be told whether or
  769. * not the system received a successful reply. If the message times out
  770. * then the value '-ETIMEDOUT' is returned.
  771. *
  772. * Returns 0 on success or negative error code on failure.
  773. */
  774. static inline int i2o_msg_post_wait(struct i2o_controller *c,
  775. struct i2o_message *msg,
  776. unsigned long timeout)
  777. {
  778. return i2o_msg_post_wait_mem(c, msg, timeout, NULL);
  779. };
  780. /**
  781. * i2o_msg_nop_mfa - Returns a fetched MFA back to the controller
  782. * @c: I2O controller from which the MFA was fetched
  783. * @mfa: MFA which should be returned
  784. *
  785. * This function must be used for preserved messages, because i2o_msg_nop()
  786. * also returns the allocated memory back to the msg_pool mempool.
  787. */
  788. static inline void i2o_msg_nop_mfa(struct i2o_controller *c, u32 mfa)
  789. {
  790. struct i2o_message __iomem *msg;
  791. u32 nop[3] = {
  792. THREE_WORD_MSG_SIZE | SGL_OFFSET_0,
  793. I2O_CMD_UTIL_NOP << 24 | HOST_TID << 12 | ADAPTER_TID,
  794. 0x00000000
  795. };
  796. msg = i2o_msg_in_to_virt(c, mfa);
  797. memcpy_toio(msg, nop, sizeof(nop));
  798. writel(mfa, c->in_port);
  799. };
  800. /**
  801. * i2o_msg_nop - Returns a message which is not used
  802. * @c: I2O controller from which the message was created
  803. * @msg: message which should be returned
  804. *
  805. * If you fetch a message via i2o_msg_get, and can't use it, you must
  806. * return the message with this function. Otherwise the MFA is lost as well
  807. * as the allocated memory from the mempool.
  808. */
  809. static inline void i2o_msg_nop(struct i2o_controller *c,
  810. struct i2o_message *msg)
  811. {
  812. struct i2o_msg_mfa *mmsg;
  813. mmsg = container_of(msg, struct i2o_msg_mfa, msg);
  814. i2o_msg_nop_mfa(c, mmsg->mfa);
  815. mempool_free(mmsg, c->in_msg.mempool);
  816. };
  817. /**
  818. * i2o_flush_reply - Flush reply from I2O controller
  819. * @c: I2O controller
  820. * @m: the message identifier
  821. *
  822. * The I2O controller must be informed that the reply message is not needed
  823. * anymore. If you forget to flush the reply, the message frame can't be
  824. * used by the controller anymore and is therefore lost.
  825. */
  826. static inline void i2o_flush_reply(struct i2o_controller *c, u32 m)
  827. {
  828. writel(m, c->out_port);
  829. };
  830. /*
  831. * Endian handling wrapped into the macro - keeps the core code
  832. * cleaner.
  833. */
  834. #define i2o_raw_writel(val, mem) __raw_writel(cpu_to_le32(val), mem)
  835. extern int i2o_parm_field_get(struct i2o_device *, int, int, void *, int);
  836. extern int i2o_parm_table_get(struct i2o_device *, int, int, int, void *, int,
  837. void *, int);
  838. /* debugging and troubleshooting/diagnostic helpers. */
  839. #define osm_printk(level, format, arg...) \
  840. printk(level "%s: " format, OSM_NAME , ## arg)
  841. #ifdef DEBUG
  842. #define osm_debug(format, arg...) \
  843. osm_printk(KERN_DEBUG, format , ## arg)
  844. #else
  845. #define osm_debug(format, arg...) \
  846. do { } while (0)
  847. #endif
  848. #define osm_err(format, arg...) \
  849. osm_printk(KERN_ERR, format , ## arg)
  850. #define osm_info(format, arg...) \
  851. osm_printk(KERN_INFO, format , ## arg)
  852. #define osm_warn(format, arg...) \
  853. osm_printk(KERN_WARNING, format , ## arg)
  854. /* debugging functions */
  855. extern void i2o_report_status(const char *, const char *, struct i2o_message *);
  856. extern void i2o_dump_message(struct i2o_message *);
  857. extern void i2o_dump_hrt(struct i2o_controller *c);
  858. extern void i2o_debug_state(struct i2o_controller *c);
  859. #endif /* _I2O_H */