import of ftp.dlink.com/GPL/DSMG-600_reB/ppclinux.tar.gz
[linux-2.4.21-pre4.git] / drivers / ieee1394 / nodemgr.h
1 /*
2  * Copyright (C) 2000   Andreas E. Bombe
3  *               2001   Ben Collins <bcollins@debian.org>
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software Foundation,
17  * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18  */
19
20 #ifndef _IEEE1394_NODEMGR_H
21 #define _IEEE1394_NODEMGR_H
22
23 #define CONFIG_ROM_BUS_INFO_LENGTH(q)           ((q) >> 24)
24 #define CONFIG_ROM_BUS_CRC_LENGTH(q)            (((q) >> 16) & 0xff)
25 #define CONFIG_ROM_BUS_CRC(q)                   ((q) & 0xffff)
26
27 #define CONFIG_ROM_ROOT_LENGTH(q)               ((q) >> 16)
28 #define CONFIG_ROM_ROOT_CRC(q)                  ((q) & 0xffff)
29
30 #define CONFIG_ROM_DIRECTORY_LENGTH(q)          ((q) >> 16)
31 #define CONFIG_ROM_DIRECTORY_CRC(q)             ((q) & 0xffff)
32
33 #define CONFIG_ROM_LEAF_LENGTH(q)               ((q) >> 16)
34 #define CONFIG_ROM_LEAF_CRC(q)                  ((q) & 0xffff)
35
36 #define CONFIG_ROM_DESCRIPTOR_TYPE(q)           ((q) >> 24)
37 #define CONFIG_ROM_DESCRIPTOR_SPECIFIER_ID(q)   ((q) & 0xffffff)
38 #define CONFIG_ROM_DESCRIPTOR_WIDTH(q)          ((q) >> 28)
39 #define CONFIG_ROM_DESCRIPTOR_CHAR_SET(q)       (((q) >> 16) & 0xfff)
40 #define CONFIG_ROM_DESCRIPTOR_LANG(q)           ((q) & 0xffff)
41
42 #define CONFIG_ROM_KEY_ID_MASK                  0x3f
43 #define CONFIG_ROM_KEY_TYPE_MASK                0xc0
44 #define CONFIG_ROM_KEY_TYPE_IMMEDIATE           0x00
45 #define CONFIG_ROM_KEY_TYPE_OFFSET              0x40
46 #define CONFIG_ROM_KEY_TYPE_LEAF                0x80
47 #define CONFIG_ROM_KEY_TYPE_DIRECTORY           0xc0
48
49 #define CONFIG_ROM_KEY(q)                       ((q) >> 24)
50 #define CONFIG_ROM_VALUE(q)                     ((q) & 0xffffff)
51
52 #define CONFIG_ROM_VENDOR_ID                    0x03
53 #define CONFIG_ROM_MODEL_ID                     0x17
54 #define CONFIG_ROM_NODE_CAPABILITES             0x0C
55 #define CONFIG_ROM_UNIT_DIRECTORY               0xd1
56 #define CONFIG_ROM_SPECIFIER_ID                 0x12 
57 #define CONFIG_ROM_UNIT_SW_VERSION              0x13
58 #define CONFIG_ROM_DESCRIPTOR_LEAF              0x81
59 #define CONFIG_ROM_DESCRIPTOR_DIRECTORY         0xc1
60
61 /* '1' '3' '9' '4' in ASCII */
62 #define IEEE1394_BUSID_MAGIC    0x31333934
63
64 /* This is the start of a Node entry structure. It should be a stable API
65  * for which to gather info from the Node Manager about devices attached
66  * to the bus.  */
67 struct bus_options {
68         u8      irmc;           /* Iso Resource Manager Capable */
69         u8      cmc;            /* Cycle Master Capable */
70         u8      isc;            /* Iso Capable */
71         u8      bmc;            /* Bus Master Capable */
72         u8      pmc;            /* Power Manager Capable (PNP spec) */
73         u8      cyc_clk_acc;    /* Cycle clock accuracy */
74         u8      generation;     /* Incremented when configrom changes */
75         u8      lnkspd;         /* Link speed */
76         u16     max_rec;        /* Maximum packet size node can receive */
77 };
78
79 #define UNIT_DIRECTORY_VENDOR_ID        0x01
80 #define UNIT_DIRECTORY_MODEL_ID         0x02
81 #define UNIT_DIRECTORY_SPECIFIER_ID     0x04
82 #define UNIT_DIRECTORY_VERSION          0x08
83 #define UNIT_DIRECTORY_VENDOR_TEXT      0x10
84 #define UNIT_DIRECTORY_MODEL_TEXT       0x20
85
86 /*
87  * A unit directory corresponds to a protocol supported by the
88  * node. If a node supports eg. IP/1394 and AV/C, its config rom has a
89  * unit directory for each of these protocols.
90  * 
91  * Unit directories appear on two types of lists: for each node we
92  * maintain a list of the unit directories found in its config rom and
93  * for each driver we maintain a list of the unit directories
94  * (ie. devices) the driver manages.
95  */
96 struct unit_directory {
97         struct node_entry *ne;  /* The node which this directory belongs to */
98         octlet_t address;       /* Address of the unit directory on the node */
99         u8 flags;               /* Indicates which entries were read */
100         quadlet_t vendor_id;
101         const char *vendor_name;
102         int vendor_name_size;
103         quadlet_t model_id;
104         const char *model_name;
105         int model_name_size;
106         quadlet_t specifier_id;
107         quadlet_t version;
108
109         struct hpsb_protocol_driver *driver;
110         void *driver_data;
111
112         /* For linking the nodes managed by the driver, or unmanaged nodes */
113         struct list_head driver_list;
114
115         /* For linking directories belonging to a node */
116         struct list_head node_list;
117
118         int count;              /* Number of quadlets */
119         quadlet_t quadlets[0];
120 };
121
122 struct node_entry {
123         struct list_head list;
124         u64 guid;                       /* GUID of this node */
125         struct hpsb_host *host;         /* Host this node is attached to */
126         nodeid_t nodeid;                /* NodeID */
127         struct bus_options busopt;      /* Bus Options */
128         unsigned int generation;        /* Synced with hpsb generation */
129
130         /* The following is read from the config rom */
131         u32 vendor_id;
132         u32 capabilities;       
133         struct list_head unit_directories;
134
135         const char *vendor_name;
136         quadlet_t quadlets[0];
137 };
138
139 static inline int hpsb_node_entry_valid(struct node_entry *ne)
140 {
141         return ne->generation == get_hpsb_generation(ne->host);
142 }
143
144 /*
145  * Returns a node entry (which has its reference count incremented) or NULL if
146  * the GUID in question is not known.  Getting a valid entry does not mean that
147  * the node with this GUID is currently accessible (might be powered down).
148  */
149 struct node_entry *hpsb_guid_get_entry(u64 guid);
150
151 /* Same as above, but use the nodeid to get an node entry. This is not
152  * fool-proof by itself, since the nodeid can change.  */
153 struct node_entry *hpsb_nodeid_get_entry(nodeid_t nodeid);
154
155 /*
156  * If the entry refers to a local host, this function will return the pointer
157  * to the hpsb_host structure.  It will return NULL otherwise.  Once you have
158  * established it is a local host, you can use that knowledge from then on (the
159  * GUID won't wander to an external node).  */
160 struct hpsb_host *hpsb_get_host_by_ne(struct node_entry *ne);
161
162 /*
163  * This will fill in the given, pre-initialised hpsb_packet with the current
164  * information from the node entry (host, node ID, generation number).  It will
165  * return false if the node owning the GUID is not accessible (and not modify the 
166  * hpsb_packet) and return true otherwise.
167  *
168  * Note that packet sending may still fail in hpsb_send_packet if a bus reset
169  * happens while you are trying to set up the packet (due to obsolete generation
170  * number).  It will at least reliably fail so that you don't accidentally and
171  * unknowingly send your packet to the wrong node.
172  */
173 void hpsb_node_fill_packet(struct node_entry *ne, struct hpsb_packet *pkt);
174
175 int hpsb_node_read(struct node_entry *ne, u64 addr,
176                    quadlet_t *buffer, size_t length);
177 int hpsb_node_write(struct node_entry *ne, u64 addr, 
178                     quadlet_t *buffer, size_t length);
179 int hpsb_node_lock(struct node_entry *ne, u64 addr, 
180                    int extcode, quadlet_t *data, quadlet_t arg);
181
182
183 void init_ieee1394_nodemgr(int disable_hotplug);
184 void cleanup_ieee1394_nodemgr(void);
185
186 #endif /* _IEEE1394_NODEMGR_H */