Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | #ifndef _IEEE1394_CORE_H |
| 2 | #define _IEEE1394_CORE_H |
| 3 | |
Stefan Richter | de4394f | 2006-07-03 12:02:29 -0400 | [diff] [blame] | 4 | #include <linux/device.h> |
| 5 | #include <linux/fs.h> |
| 6 | #include <linux/list.h> |
Stefan Richter | de4394f | 2006-07-03 12:02:29 -0400 | [diff] [blame] | 7 | #include <linux/types.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | #include <asm/atomic.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | |
Stefan Richter | de4394f | 2006-07-03 12:02:29 -0400 | [diff] [blame] | 10 | #include "hosts.h" |
| 11 | #include "ieee1394_types.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | |
| 13 | struct hpsb_packet { |
Stefan Richter | 741854e | 2005-12-01 18:52:03 -0500 | [diff] [blame] | 14 | /* This struct is basically read-only for hosts with the exception of |
Stefan Richter | 7542e0e | 2007-03-25 22:22:40 +0200 | [diff] [blame] | 15 | * the data buffer contents and driver_list. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | |
| 17 | /* This can be used for host driver internal linking. |
| 18 | * |
| 19 | * NOTE: This must be left in init state when the driver is done |
| 20 | * with it (e.g. by using list_del_init()), since the core does |
| 21 | * some sanity checks to make sure the packet is not on a |
| 22 | * driver_list when free'ing it. */ |
| 23 | struct list_head driver_list; |
| 24 | |
Stefan Richter | 741854e | 2005-12-01 18:52:03 -0500 | [diff] [blame] | 25 | nodeid_t node_id; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | |
Stefan Richter | 741854e | 2005-12-01 18:52:03 -0500 | [diff] [blame] | 27 | /* Async and Iso types should be clear, raw means send-as-is, do not |
| 28 | * CRC! Byte swapping shall still be done in this case. */ |
| 29 | enum { hpsb_async, hpsb_iso, hpsb_raw } __attribute__((packed)) type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | |
Stefan Richter | 741854e | 2005-12-01 18:52:03 -0500 | [diff] [blame] | 31 | /* Okay, this is core internal and a no care for hosts. |
| 32 | * queued = queued for sending |
| 33 | * pending = sent, waiting for response |
| 34 | * complete = processing completed, successful or not |
| 35 | */ |
| 36 | enum { |
| 37 | hpsb_unused, hpsb_queued, hpsb_pending, hpsb_complete |
| 38 | } __attribute__((packed)) state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | |
Stefan Richter | 741854e | 2005-12-01 18:52:03 -0500 | [diff] [blame] | 40 | /* These are core internal. */ |
| 41 | signed char tlabel; |
Linus Torvalds | 07bbeaf | 2005-07-06 13:05:50 -0700 | [diff] [blame] | 42 | signed char ack_code; |
| 43 | unsigned char tcode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | |
Stefan Richter | 741854e | 2005-12-01 18:52:03 -0500 | [diff] [blame] | 45 | unsigned expect_response:1; |
| 46 | unsigned no_waiter:1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | |
Stefan Richter | 741854e | 2005-12-01 18:52:03 -0500 | [diff] [blame] | 48 | /* Speed to transmit with: 0 = 100Mbps, 1 = 200Mbps, 2 = 400Mbps */ |
| 49 | unsigned speed_code:2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | |
Stefan Richter | 741854e | 2005-12-01 18:52:03 -0500 | [diff] [blame] | 51 | struct hpsb_host *host; |
| 52 | unsigned int generation; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | |
| 54 | atomic_t refcnt; |
Stefan Richter | 7542e0e | 2007-03-25 22:22:40 +0200 | [diff] [blame] | 55 | struct list_head queue; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | |
| 57 | /* Function (and possible data to pass to it) to call when this |
| 58 | * packet is completed. */ |
| 59 | void (*complete_routine)(void *); |
| 60 | void *complete_data; |
| 61 | |
Stefan Richter | 741854e | 2005-12-01 18:52:03 -0500 | [diff] [blame] | 62 | /* Store jiffies for implementing bus timeouts. */ |
| 63 | unsigned long sendtime; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | |
Stefan Richter | 7542e0e | 2007-03-25 22:22:40 +0200 | [diff] [blame] | 65 | /* Sizes are in bytes. *data can be DMA-mapped. */ |
| 66 | size_t allocated_data_size; /* as allocated */ |
| 67 | size_t data_size; /* as filled in */ |
| 68 | size_t header_size; /* as filled in, not counting the CRC */ |
| 69 | quadlet_t *data; |
| 70 | quadlet_t header[5]; |
| 71 | quadlet_t embedded_data[0]; /* keep as last member */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | }; |
| 73 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | void hpsb_set_packet_complete_task(struct hpsb_packet *packet, |
Stefan Richter | e1d118f | 2006-07-03 12:02:28 -0400 | [diff] [blame] | 75 | void (*routine)(void *), void *data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | static inline struct hpsb_packet *driver_packet(struct list_head *l) |
| 77 | { |
| 78 | return list_entry(l, struct hpsb_packet, driver_list); |
| 79 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | void abort_timedouts(unsigned long __opaque); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | struct hpsb_packet *hpsb_alloc_packet(size_t data_size); |
| 82 | void hpsb_free_packet(struct hpsb_packet *packet); |
| 83 | |
Stefan Richter | afd6546 | 2007-03-05 03:06:23 +0100 | [diff] [blame] | 84 | /** |
| 85 | * get_hpsb_generation - generation counter for the complete 1394 subsystem |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | * |
Stefan Richter | afd6546 | 2007-03-05 03:06:23 +0100 | [diff] [blame] | 87 | * Generation gets incremented on every change in the subsystem (notably on bus |
| 88 | * resets). Use the functions, not the variable. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | */ |
| 90 | static inline unsigned int get_hpsb_generation(struct hpsb_host *host) |
| 91 | { |
Stefan Richter | 741854e | 2005-12-01 18:52:03 -0500 | [diff] [blame] | 92 | return atomic_read(&host->generation); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | } |
| 94 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | int hpsb_send_phy_config(struct hpsb_host *host, int rootid, int gapcnt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | int hpsb_send_packet(struct hpsb_packet *packet); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | int hpsb_send_packet_and_wait(struct hpsb_packet *packet); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | int hpsb_reset_bus(struct hpsb_host *host, int type); |
Pieter Palmers | 3dc5ea9 | 2007-02-03 17:44:39 +0100 | [diff] [blame] | 99 | int hpsb_read_cycle_timer(struct hpsb_host *host, u32 *cycle_timer, |
| 100 | u64 *local_time); |
| 101 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | int hpsb_bus_reset(struct hpsb_host *host); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | void hpsb_selfid_received(struct hpsb_host *host, quadlet_t sid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | void hpsb_selfid_complete(struct hpsb_host *host, int phyid, int isroot); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | void hpsb_packet_sent(struct hpsb_host *host, struct hpsb_packet *packet, |
Stefan Richter | 741854e | 2005-12-01 18:52:03 -0500 | [diff] [blame] | 106 | int ackcode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | void hpsb_packet_received(struct hpsb_host *host, quadlet_t *data, size_t size, |
Stefan Richter | 741854e | 2005-12-01 18:52:03 -0500 | [diff] [blame] | 108 | int write_acked); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | /* |
| 111 | * CHARACTER DEVICE DISPATCHING |
| 112 | * |
| 113 | * All ieee1394 character device drivers share the same major number |
| 114 | * (major 171). The 256 minor numbers are allocated to the various |
| 115 | * task-specific interfaces (raw1394, video1394, dv1394, etc) in |
| 116 | * blocks of 16. |
| 117 | * |
| 118 | * The core ieee1394.o module allocates the device number region |
| 119 | * 171:0-255, the various drivers must then cdev_add() their cdev |
| 120 | * objects to handle their respective sub-regions. |
| 121 | * |
| 122 | * Minor device number block allocations: |
| 123 | * |
| 124 | * Block 0 ( 0- 15) raw1394 |
| 125 | * Block 1 ( 16- 31) video1394 |
| 126 | * Block 2 ( 32- 47) dv1394 |
| 127 | * |
| 128 | * Blocks 3-14 free for future allocation |
| 129 | * |
| 130 | * Block 15 (240-255) reserved for drivers under development, etc. |
| 131 | */ |
| 132 | |
Stefan Richter | 741854e | 2005-12-01 18:52:03 -0500 | [diff] [blame] | 133 | #define IEEE1394_MAJOR 171 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 | |
Stefan Richter | 741854e | 2005-12-01 18:52:03 -0500 | [diff] [blame] | 135 | #define IEEE1394_MINOR_BLOCK_RAW1394 0 |
| 136 | #define IEEE1394_MINOR_BLOCK_VIDEO1394 1 |
| 137 | #define IEEE1394_MINOR_BLOCK_DV1394 2 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | #define IEEE1394_MINOR_BLOCK_EXPERIMENTAL 15 |
| 139 | |
Stefan Richter | 741854e | 2005-12-01 18:52:03 -0500 | [diff] [blame] | 140 | #define IEEE1394_CORE_DEV MKDEV(IEEE1394_MAJOR, 0) |
Stefan Richter | e1d118f | 2006-07-03 12:02:28 -0400 | [diff] [blame] | 141 | #define IEEE1394_RAW1394_DEV MKDEV(IEEE1394_MAJOR, \ |
| 142 | IEEE1394_MINOR_BLOCK_RAW1394 * 16) |
| 143 | #define IEEE1394_VIDEO1394_DEV MKDEV(IEEE1394_MAJOR, \ |
| 144 | IEEE1394_MINOR_BLOCK_VIDEO1394 * 16) |
| 145 | #define IEEE1394_DV1394_DEV MKDEV(IEEE1394_MAJOR, \ |
| 146 | IEEE1394_MINOR_BLOCK_DV1394 * 16) |
| 147 | #define IEEE1394_EXPERIMENTAL_DEV MKDEV(IEEE1394_MAJOR, \ |
| 148 | IEEE1394_MINOR_BLOCK_EXPERIMENTAL * 16) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 149 | |
Stefan Richter | afd6546 | 2007-03-05 03:06:23 +0100 | [diff] [blame] | 150 | /** |
| 151 | * ieee1394_file_to_instance - get the index within a minor number block |
| 152 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 153 | static inline unsigned char ieee1394_file_to_instance(struct file *file) |
| 154 | { |
Josef Sipek | 4db6108 | 2006-12-08 02:37:10 -0800 | [diff] [blame] | 155 | return file->f_path.dentry->d_inode->i_cindex; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 156 | } |
| 157 | |
| 158 | extern int hpsb_disable_irm; |
| 159 | |
| 160 | /* Our sysfs bus entry */ |
| 161 | extern struct bus_type ieee1394_bus_type; |
| 162 | extern struct class hpsb_host_class; |
gregkh@suse.de | 7e25ab9 | 2005-03-23 09:53:36 -0800 | [diff] [blame] | 163 | extern struct class *hpsb_protocol_class; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 | |
| 165 | #endif /* _IEEE1394_CORE_H */ |