more debug output
[linux-2.4.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 #include "ieee1394_core.h"
24 #include "ieee1394_hotplug.h"
25
26 #define CONFIG_ROM_BUS_INFO_LENGTH(q)           ((q) >> 24)
27 #define CONFIG_ROM_BUS_CRC_LENGTH(q)            (((q) >> 16) & 0xff)
28 #define CONFIG_ROM_BUS_CRC(q)                   ((q) & 0xffff)
29
30 #define CONFIG_ROM_ROOT_LENGTH(q)               ((q) >> 16)
31 #define CONFIG_ROM_ROOT_CRC(q)                  ((q) & 0xffff)
32
33 #define CONFIG_ROM_DIRECTORY_LENGTH(q)          ((q) >> 16)
34 #define CONFIG_ROM_DIRECTORY_CRC(q)             ((q) & 0xffff)
35
36 #define CONFIG_ROM_LEAF_LENGTH(q)               ((q) >> 16)
37 #define CONFIG_ROM_LEAF_CRC(q)                  ((q) & 0xffff)
38
39 #define CONFIG_ROM_DESCRIPTOR_TYPE(q)           ((q) >> 24)
40 #define CONFIG_ROM_DESCRIPTOR_SPECIFIER_ID(q)   ((q) & 0xffffff)
41 #define CONFIG_ROM_DESCRIPTOR_WIDTH(q)          ((q) >> 28)
42 #define CONFIG_ROM_DESCRIPTOR_CHAR_SET(q)       (((q) >> 16) & 0xfff)
43 #define CONFIG_ROM_DESCRIPTOR_LANG(q)           ((q) & 0xffff)
44
45 #define CONFIG_ROM_KEY_ID_MASK                  0x3f
46 #define CONFIG_ROM_KEY_TYPE_MASK                0xc0
47 #define CONFIG_ROM_KEY_TYPE_IMMEDIATE           0x00
48 #define CONFIG_ROM_KEY_TYPE_OFFSET              0x40
49 #define CONFIG_ROM_KEY_TYPE_LEAF                0x80
50 #define CONFIG_ROM_KEY_TYPE_DIRECTORY           0xc0
51
52 #define CONFIG_ROM_KEY(q)                       ((q) >> 24)
53 #define CONFIG_ROM_VALUE(q)                     ((q) & 0xffffff)
54
55 #define CONFIG_ROM_VENDOR_ID                    0x03
56 #define CONFIG_ROM_MODEL_ID                     0x17
57 #define CONFIG_ROM_NODE_CAPABILITES             0x0C
58 #define CONFIG_ROM_UNIT_DIRECTORY               0xd1
59 #define CONFIG_ROM_LOGICAL_UNIT_DIRECTORY       0xd4
60 #define CONFIG_ROM_SPECIFIER_ID                 0x12 
61 #define CONFIG_ROM_UNIT_SW_VERSION              0x13
62 #define CONFIG_ROM_DESCRIPTOR_LEAF              0x81
63 #define CONFIG_ROM_DESCRIPTOR_DIRECTORY         0xc1
64
65 /* '1' '3' '9' '4' in ASCII */
66 #define IEEE1394_BUSID_MAGIC    0x31333934
67
68 /* This is the start of a Node entry structure. It should be a stable API
69  * for which to gather info from the Node Manager about devices attached
70  * to the bus.  */
71 struct bus_options {
72         u8      irmc;           /* Iso Resource Manager Capable */
73         u8      cmc;            /* Cycle Master Capable */
74         u8      isc;            /* Iso Capable */
75         u8      bmc;            /* Bus Master Capable */
76         u8      pmc;            /* Power Manager Capable (PNP spec) */
77         u8      cyc_clk_acc;    /* Cycle clock accuracy */
78         u8      generation;     /* Incremented when configrom changes */
79         u8      lnkspd;         /* Link speed */
80         u16     max_rec;        /* Maximum packet size node can receive */
81 };
82
83 #define UNIT_DIRECTORY_VENDOR_ID                0x01
84 #define UNIT_DIRECTORY_MODEL_ID                 0x02
85 #define UNIT_DIRECTORY_SPECIFIER_ID             0x04
86 #define UNIT_DIRECTORY_VERSION                  0x08
87 #define UNIT_DIRECTORY_VENDOR_TEXT              0x10
88 #define UNIT_DIRECTORY_MODEL_TEXT               0x20
89 #define UNIT_DIRECTORY_HAS_LUN_DIRECTORY        0x40
90 #define UNIT_DIRECTORY_LUN_DIRECTORY            0x80
91
92 /*
93  * A unit directory corresponds to a protocol supported by the
94  * node. If a node supports eg. IP/1394 and AV/C, its config rom has a
95  * unit directory for each of these protocols.
96  * 
97  * Unit directories appear on two types of lists: for each node we
98  * maintain a list of the unit directories found in its config rom and
99  * for each driver we maintain a list of the unit directories
100  * (ie. devices) the driver manages.
101  */
102 struct unit_directory {
103         struct node_entry *ne;  /* The node which this directory belongs to */
104         octlet_t address;       /* Address of the unit directory on the node */
105         u8 flags;               /* Indicates which entries were read */
106
107         quadlet_t vendor_id;
108         const char *vendor_name;
109         const char *vendor_oui;
110
111         int vendor_name_size;
112         quadlet_t model_id;
113         const char *model_name;
114         int model_name_size;
115         quadlet_t specifier_id;
116         quadlet_t version;
117
118         struct hpsb_protocol_driver *driver;
119         void *driver_data;
120
121         /* For linking the nodes managed by the driver, or unmanaged nodes */
122         struct list_head driver_list;
123
124         /* For linking directories belonging to a node */
125         struct list_head node_list;
126                 
127         /* for tracking unit versus logical unit */
128         struct unit_directory *parent;
129
130         int length;             /* Number of quadlets */
131
132         /* XXX Must be last in the struct! */
133         quadlet_t quadlets[0];
134 };
135
136 struct node_entry {
137         struct list_head list;
138         u64 guid;                       /* GUID of this node */
139         u32 guid_vendor_id;             /* Top 24bits of guid */
140         const char *guid_vendor_oui;    /* OUI name of guid vendor id */
141
142         struct hpsb_host *host;         /* Host this node is attached to */
143         nodeid_t nodeid;                /* NodeID */
144         struct bus_options busopt;      /* Bus Options */
145         unsigned int generation;        /* Synced with hpsb generation */
146
147         /* The following is read from the config rom */
148         u32 vendor_id;
149         const char *vendor_name;
150         const char *vendor_oui;
151
152         u32 capabilities;
153         struct hpsb_tlabel_pool *tpool;
154         struct list_head unit_directories;
155
156         /* XXX Must be last in the struct! */
157         quadlet_t quadlets[0];
158 };
159
160 struct hpsb_protocol_driver {
161         /* The name of the driver, e.g. SBP2 or IP1394 */
162         const char *name;
163
164         /*
165          * The device id table describing the protocols and/or devices
166          * supported by this driver.  This is used by the nodemgr to
167          * decide if a driver could support a given node, but the
168          * probe function below can implement further protocol
169          * dependent or vendor dependent checking.
170          */
171         struct ieee1394_device_id *id_table;
172
173         /*
174          * The probe function is called when a device is added to the
175          * bus and the nodemgr finds a matching entry in the drivers
176          * device id table or when registering this driver and a
177          * previously unhandled device can be handled.  The driver may
178          * decline to handle the device based on further investigation
179          * of the device (or whatever reason) in which case a negative
180          * error code should be returned, otherwise 0 should be
181          * returned. The driver may use the driver_data field in the
182          * unit directory to store per device driver specific data.
183          */
184         int (*probe)(struct unit_directory *ud);
185
186         /*
187          * The disconnect function is called when a device is removed
188          * from the bus or if it wasn't possible to read the guid
189          * after the last bus reset.
190          */
191         void (*disconnect)(struct unit_directory *ud);
192
193         /*
194          * The update function is called when the node has just
195          * survived a bus reset, i.e. it is still present on the bus.
196          * However, it may be necessary to reestablish the connection
197          * or login into the node again, depending on the protocol.
198          */
199         void (*update)(struct unit_directory *ud);
200
201         /* Driver in list of all registered drivers */
202         struct list_head list;
203
204         /* The list of unit directories managed by this driver */
205         struct list_head unit_directories;
206 };
207
208 int hpsb_register_protocol(struct hpsb_protocol_driver *driver);
209 void hpsb_unregister_protocol(struct hpsb_protocol_driver *driver);
210 void hpsb_release_unit_directory(struct unit_directory *ud);
211
212 static inline int hpsb_node_entry_valid(struct node_entry *ne)
213 {
214         return ne->generation == get_hpsb_generation(ne->host);
215 }
216
217 /*
218  * Returns a node entry (which has its reference count incremented) or NULL if
219  * the GUID in question is not known.  Getting a valid entry does not mean that
220  * the node with this GUID is currently accessible (might be powered down).
221  */
222 struct node_entry *hpsb_guid_get_entry(u64 guid);
223
224 /* Same as above, but use the nodeid to get an node entry. This is not
225  * fool-proof by itself, since the nodeid can change.  */
226 struct node_entry *hpsb_nodeid_get_entry(struct hpsb_host *host, nodeid_t nodeid);
227
228 /*
229  * If the entry refers to a local host, this function will return the pointer
230  * to the hpsb_host structure.  It will return NULL otherwise.  Once you have
231  * established it is a local host, you can use that knowledge from then on (the
232  * GUID won't wander to an external node).  */
233 struct hpsb_host *hpsb_get_host_by_ne(struct node_entry *ne);
234
235 /*
236  * This will fill in the given, pre-initialised hpsb_packet with the current
237  * information from the node entry (host, node ID, generation number).  It will
238  * return false if the node owning the GUID is not accessible (and not modify the 
239  * hpsb_packet) and return true otherwise.
240  *
241  * Note that packet sending may still fail in hpsb_send_packet if a bus reset
242  * happens while you are trying to set up the packet (due to obsolete generation
243  * number).  It will at least reliably fail so that you don't accidentally and
244  * unknowingly send your packet to the wrong node.
245  */
246 void hpsb_node_fill_packet(struct node_entry *ne, struct hpsb_packet *pkt);
247
248 int hpsb_node_read(struct node_entry *ne, u64 addr,
249                    quadlet_t *buffer, size_t length);
250 int hpsb_node_write(struct node_entry *ne, u64 addr, 
251                     quadlet_t *buffer, size_t length);
252 int hpsb_node_lock(struct node_entry *ne, u64 addr, 
253                    int extcode, quadlet_t *data, quadlet_t arg);
254
255
256 void init_ieee1394_nodemgr(void);
257 void cleanup_ieee1394_nodemgr(void);
258
259 #endif /* _IEEE1394_NODEMGR_H */