i2o.h 29 KB

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