i2o.h 29 KB

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