i2o.h 30 KB

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