blob: f649c9d321b85c2a228162bca22d4bbfb0e97357 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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 <linux/device.h>
Stefan Richterde4394f2006-07-03 12:02:29 -040024#include <asm/types.h>
25
Linus Torvalds1da177e2005-04-16 15:20:36 -070026#include "ieee1394_core.h"
Stefan Richterde4394f2006-07-03 12:02:29 -040027#include "ieee1394_types.h"
28
29struct csr1212_csr;
30struct csr1212_keyval;
31struct hpsb_host;
32struct ieee1394_device_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -070033
34/* '1' '3' '9' '4' in ASCII */
35#define IEEE1394_BUSID_MAGIC __constant_cpu_to_be32(0x31333934)
36
37/* This is the start of a Node entry structure. It should be a stable API
38 * for which to gather info from the Node Manager about devices attached
39 * to the bus. */
40struct bus_options {
41 u8 irmc; /* Iso Resource Manager Capable */
42 u8 cmc; /* Cycle Master Capable */
43 u8 isc; /* Iso Capable */
44 u8 bmc; /* Bus Master Capable */
45 u8 pmc; /* Power Manager Capable (PNP spec) */
46 u8 cyc_clk_acc; /* Cycle clock accuracy */
47 u8 max_rom; /* Maximum block read supported in the CSR */
48 u8 generation; /* Incremented when configrom changes */
49 u8 lnkspd; /* Link speed */
50 u16 max_rec; /* Maximum packet size node can receive */
51};
52
Linus Torvalds1da177e2005-04-16 15:20:36 -070053#define UNIT_DIRECTORY_VENDOR_ID 0x01
54#define UNIT_DIRECTORY_MODEL_ID 0x02
55#define UNIT_DIRECTORY_SPECIFIER_ID 0x04
56#define UNIT_DIRECTORY_VERSION 0x08
57#define UNIT_DIRECTORY_HAS_LUN_DIRECTORY 0x10
58#define UNIT_DIRECTORY_LUN_DIRECTORY 0x20
59#define UNIT_DIRECTORY_HAS_LUN 0x40
60
61/*
62 * A unit directory corresponds to a protocol supported by the
63 * node. If a node supports eg. IP/1394 and AV/C, its config rom has a
64 * unit directory for each of these protocols.
65 */
66struct unit_directory {
Stefan Richtere1d118f2006-07-03 12:02:28 -040067 struct node_entry *ne; /* The node which this directory belongs to */
68 octlet_t address; /* Address of the unit directory on the node */
Linus Torvalds1da177e2005-04-16 15:20:36 -070069 u8 flags; /* Indicates which entries were read */
70
71 quadlet_t vendor_id;
72 struct csr1212_keyval *vendor_name_kv;
73 const char *vendor_oui;
74
75 quadlet_t model_id;
76 struct csr1212_keyval *model_name_kv;
77 quadlet_t specifier_id;
78 quadlet_t version;
79
80 unsigned int id;
81
82 int ignore_driver;
83
84 int length; /* Number of quadlets */
85
86 struct device device;
Linus Torvalds1da177e2005-04-16 15:20:36 -070087 struct class_device class_dev;
88
89 struct csr1212_keyval *ud_kv;
Stefan Richtere1d118f2006-07-03 12:02:28 -040090 u32 lun; /* logical unit number immediate value */
Linus Torvalds1da177e2005-04-16 15:20:36 -070091};
92
93struct node_entry {
94 u64 guid; /* GUID of this node */
95 u32 guid_vendor_id; /* Top 24bits of guid */
96 const char *guid_vendor_oui; /* OUI name of guid vendor id */
97
98 struct hpsb_host *host; /* Host this node is attached to */
99 nodeid_t nodeid; /* NodeID */
100 struct bus_options busopt; /* Bus Options */
101 int needs_probe;
102 unsigned int generation; /* Synced with hpsb generation */
103
104 /* The following is read from the config rom */
105 u32 vendor_id;
106 struct csr1212_keyval *vendor_name_kv;
107 const char *vendor_oui;
108
109 u32 capabilities;
110 struct hpsb_tlabel_pool *tpool;
111
112 struct device device;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113 struct class_device class_dev;
114
115 /* Means this node is not attached anymore */
116 int in_limbo;
117
118 struct csr1212_csr *csr;
119};
120
121struct hpsb_protocol_driver {
122 /* The name of the driver, e.g. SBP2 or IP1394 */
123 const char *name;
124
125 /*
126 * The device id table describing the protocols and/or devices
127 * supported by this driver. This is used by the nodemgr to
128 * decide if a driver could support a given node, but the
129 * probe function below can implement further protocol
130 * dependent or vendor dependent checking.
131 */
132 struct ieee1394_device_id *id_table;
133
134 /*
135 * The update function is called when the node has just
136 * survived a bus reset, i.e. it is still present on the bus.
137 * However, it may be necessary to reestablish the connection
138 * or login into the node again, depending on the protocol. If the
139 * probe fails (returns non-zero), we unbind the driver from this
140 * device.
141 */
142 int (*update)(struct unit_directory *ud);
143
144 /* Our LDM structure */
145 struct device_driver driver;
146};
147
148int hpsb_register_protocol(struct hpsb_protocol_driver *driver);
149void hpsb_unregister_protocol(struct hpsb_protocol_driver *driver);
150
151static inline int hpsb_node_entry_valid(struct node_entry *ne)
152{
153 return ne->generation == get_hpsb_generation(ne->host);
154}
155
156/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157 * This will fill in the given, pre-initialised hpsb_packet with the current
158 * information from the node entry (host, node ID, generation number). It will
Stefan Richtere1d118f2006-07-03 12:02:28 -0400159 * return false if the node owning the GUID is not accessible (and not modify
160 * the hpsb_packet) and return true otherwise.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161 *
162 * Note that packet sending may still fail in hpsb_send_packet if a bus reset
163 * happens while you are trying to set up the packet (due to obsolete generation
164 * number). It will at least reliably fail so that you don't accidentally and
165 * unknowingly send your packet to the wrong node.
166 */
167void hpsb_node_fill_packet(struct node_entry *ne, struct hpsb_packet *pkt);
168
169int hpsb_node_read(struct node_entry *ne, u64 addr,
170 quadlet_t *buffer, size_t length);
171int hpsb_node_write(struct node_entry *ne, u64 addr,
172 quadlet_t *buffer, size_t length);
173int hpsb_node_lock(struct node_entry *ne, u64 addr,
174 int extcode, quadlet_t *data, quadlet_t arg);
175
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176/* Iterate the hosts, calling a given function with supplied data for each
177 * host. */
178int nodemgr_for_each_host(void *__data, int (*cb)(struct hpsb_host *, void *));
179
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180int init_ieee1394_nodemgr(void);
181void cleanup_ieee1394_nodemgr(void);
182
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183/* The template for a host device */
184extern struct device nodemgr_dev_template_host;
185
186/* Bus attributes we export */
187extern struct bus_attribute *const fw_bus_attrs[];
188
189#endif /* _IEEE1394_NODEMGR_H */