- Kai Germaschewski: ymfpci cleanups and resource leak fixes
[davej-history.git] / drivers / ieee1394 / ieee1394_core.h
blobd2505b9cb3bf24915d107d1b8cf33bc39964f2c3
2 #ifndef _IEEE1394_CORE_H
3 #define _IEEE1394_CORE_H
5 #include <linux/tqueue.h>
6 #include <asm/semaphore.h>
7 #include "hosts.h"
10 struct hpsb_packet {
11 /* This struct is basically read-only for hosts with the exception of
12 * the data buffer contents and xnext - see below. */
13 struct list_head list;
15 /* This can be used for host driver internal linking. */
16 struct hpsb_packet *xnext;
18 nodeid_t node_id;
20 /* Async and Iso types should be clear, raw means send-as-is, do not
21 * CRC! Byte swapping shall still be done in this case. */
22 enum { async, iso, raw } __attribute__((packed)) type;
24 /* Okay, this is core internal and a no care for hosts.
25 * queued = queued for sending
26 * pending = sent, waiting for response
27 * complete = processing completed, successful or not
28 * incoming = incoming packet
30 enum {
31 unused, queued, pending, complete, incoming
32 } __attribute__((packed)) state;
34 /* These are core internal. */
35 char tlabel;
36 char ack_code;
37 char tcode;
39 unsigned expect_response:1;
40 unsigned no_waiter:1;
42 /* Data big endianness flag - may vary from request to request. The
43 * header is always in machine byte order.
44 * Not really used currently. */
45 unsigned data_be:1;
47 /* Speed to transmit with: 0 = 100Mbps, 1 = 200Mbps, 2 = 400Mbps */
48 unsigned speed_code:2;
51 * *header and *data are guaranteed to be 32-bit DMAable and may be
52 * overwritten to allow in-place byte swapping. Neither of these is
53 * CRCed (the sizes also don't include CRC), but contain space for at
54 * least one additional quadlet to allow in-place CRCing. The memory is
55 * also guaranteed to be DMA mappable.
57 quadlet_t *header;
58 quadlet_t *data;
59 size_t header_size;
60 size_t data_size;
63 struct hpsb_host *host;
64 unsigned int generation;
66 /* Very core internal, don't care. */
67 struct semaphore state_change;
69 task_queue complete_tq;
71 /* Store jiffies for implementing bus timeouts. */
72 unsigned long sendtime;
76 void abort_timedouts(struct hpsb_host *host);
77 void abort_requests(struct hpsb_host *host);
79 struct hpsb_packet *alloc_hpsb_packet(size_t data_size);
80 void free_hpsb_packet(struct hpsb_packet *packet);
84 * Generation counter for the complete 1394 subsystem. Generation gets
85 * incremented on every change in the subsystem (e.g. bus reset).
87 * Use the functions, not the variable.
89 #include <asm/atomic.h>
90 extern atomic_t hpsb_generation;
92 inline static unsigned int get_hpsb_generation(void)
94 return atomic_read(&hpsb_generation);
97 inline static void inc_hpsb_generation(void)
99 atomic_inc(&hpsb_generation);
104 * Queue packet for transmitting, return 0 for failure.
106 int hpsb_send_packet(struct hpsb_packet *packet);
108 /* Initiate bus reset on the given host. Returns 1 if bus reset already in
109 * progress, 0 otherwise. */
110 int hpsb_reset_bus(struct hpsb_host *host);
113 * The following functions are exported for host driver module usage. All of
114 * them are safe to use in interrupt contexts, although some are quite
115 * complicated so you may want to run them in bottom halves instead of calling
116 * them directly.
119 /* Notify a bus reset to the core. Returns 1 if bus reset already in progress,
120 * 0 otherwise. */
121 int hpsb_bus_reset(struct hpsb_host *host);
124 * Hand over received selfid packet to the core. Complement check (second
125 * quadlet is complement of first) is expected to be done and succesful.
127 void hpsb_selfid_received(struct hpsb_host *host, quadlet_t sid);
130 * Notify completion of SelfID stage to the core and report new physical ID
131 * and whether host is root now.
133 void hpsb_selfid_complete(struct hpsb_host *host, int phyid, int isroot);
136 * Notify core of sending a packet. Ackcode is the ack code returned for async
137 * transmits or ACKX_SEND_ERROR if the transmission failed completely; ACKX_NONE
138 * for other cases (internal errors that don't justify a panic). Safe to call
139 * from within a transmit packet routine.
141 void hpsb_packet_sent(struct hpsb_host *host, struct hpsb_packet *packet,
142 int ackcode);
145 * Hand over received packet to the core. The contents of data are expected to
146 * be the full packet but with the CRCs left out (data block follows header
147 * immediately), with the header (i.e. the first four quadlets) in machine byte
148 * order and the data block in big endian. *data can be safely overwritten
149 * after this call.
151 * If the packet is a write request, write_acked is to be set to true if it was
152 * ack_complete'd already, false otherwise. This arg is ignored for any other
153 * packet type.
155 void hpsb_packet_received(struct hpsb_host *host, quadlet_t *data, size_t size,
156 int write_acked);
158 #endif /* _IEEE1394_CORE_H */