Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 <linux/device.h> |
Stefan Richter | b33fdd6 | 2008-08-27 13:40:02 +0200 | [diff] [blame] | 24 | #include <asm/system.h> |
Stefan Richter | de4394f | 2006-07-03 12:02:29 -0400 | [diff] [blame] | 25 | #include <asm/types.h> |
| 26 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | #include "ieee1394_core.h" |
Stefan Richter | b33fdd6 | 2008-08-27 13:40:02 +0200 | [diff] [blame] | 28 | #include "ieee1394_transactions.h" |
Stefan Richter | de4394f | 2006-07-03 12:02:29 -0400 | [diff] [blame] | 29 | #include "ieee1394_types.h" |
| 30 | |
| 31 | struct csr1212_csr; |
| 32 | struct csr1212_keyval; |
| 33 | struct hpsb_host; |
| 34 | struct ieee1394_device_id; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | /* This is the start of a Node entry structure. It should be a stable API |
| 37 | * for which to gather info from the Node Manager about devices attached |
| 38 | * to the bus. */ |
| 39 | struct bus_options { |
| 40 | u8 irmc; /* Iso Resource Manager Capable */ |
| 41 | u8 cmc; /* Cycle Master Capable */ |
| 42 | u8 isc; /* Iso Capable */ |
| 43 | u8 bmc; /* Bus Master Capable */ |
| 44 | u8 pmc; /* Power Manager Capable (PNP spec) */ |
| 45 | u8 cyc_clk_acc; /* Cycle clock accuracy */ |
| 46 | u8 max_rom; /* Maximum block read supported in the CSR */ |
| 47 | u8 generation; /* Incremented when configrom changes */ |
| 48 | u8 lnkspd; /* Link speed */ |
| 49 | u16 max_rec; /* Maximum packet size node can receive */ |
| 50 | }; |
| 51 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | #define UNIT_DIRECTORY_VENDOR_ID 0x01 |
| 53 | #define UNIT_DIRECTORY_MODEL_ID 0x02 |
| 54 | #define UNIT_DIRECTORY_SPECIFIER_ID 0x04 |
| 55 | #define UNIT_DIRECTORY_VERSION 0x08 |
| 56 | #define UNIT_DIRECTORY_HAS_LUN_DIRECTORY 0x10 |
| 57 | #define UNIT_DIRECTORY_LUN_DIRECTORY 0x20 |
| 58 | #define UNIT_DIRECTORY_HAS_LUN 0x40 |
| 59 | |
| 60 | /* |
| 61 | * A unit directory corresponds to a protocol supported by the |
| 62 | * node. If a node supports eg. IP/1394 and AV/C, its config rom has a |
| 63 | * unit directory for each of these protocols. |
| 64 | */ |
| 65 | struct unit_directory { |
Stefan Richter | e1d118f | 2006-07-03 12:02:28 -0400 | [diff] [blame] | 66 | struct node_entry *ne; /* The node which this directory belongs to */ |
| 67 | octlet_t address; /* Address of the unit directory on the node */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | u8 flags; /* Indicates which entries were read */ |
| 69 | |
| 70 | quadlet_t vendor_id; |
| 71 | struct csr1212_keyval *vendor_name_kv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | |
| 73 | quadlet_t model_id; |
| 74 | struct csr1212_keyval *model_name_kv; |
| 75 | quadlet_t specifier_id; |
| 76 | quadlet_t version; |
Stefan Richter | d7794c8 | 2007-05-27 13:17:15 +0200 | [diff] [blame] | 77 | quadlet_t directory_id; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | |
| 79 | unsigned int id; |
| 80 | |
| 81 | int ignore_driver; |
| 82 | |
| 83 | int length; /* Number of quadlets */ |
| 84 | |
| 85 | struct device device; |
Kay Sievers | dd7f292 | 2007-05-25 11:50:53 +0200 | [diff] [blame] | 86 | struct device unit_dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | |
| 88 | struct csr1212_keyval *ud_kv; |
Stefan Richter | e1d118f | 2006-07-03 12:02:28 -0400 | [diff] [blame] | 89 | u32 lun; /* logical unit number immediate value */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | }; |
| 91 | |
| 92 | struct node_entry { |
| 93 | u64 guid; /* GUID of this node */ |
| 94 | u32 guid_vendor_id; /* Top 24bits of guid */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | |
| 96 | struct hpsb_host *host; /* Host this node is attached to */ |
| 97 | nodeid_t nodeid; /* NodeID */ |
| 98 | struct bus_options busopt; /* Bus Options */ |
Stefan Richter | 6848408 | 2008-08-16 13:36:47 +0200 | [diff] [blame] | 99 | bool needs_probe; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | unsigned int generation; /* Synced with hpsb generation */ |
| 101 | |
| 102 | /* The following is read from the config rom */ |
| 103 | u32 vendor_id; |
| 104 | struct csr1212_keyval *vendor_name_kv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | |
| 106 | u32 capabilities; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | |
| 108 | struct device device; |
Kay Sievers | dd7f292 | 2007-05-25 11:50:53 +0200 | [diff] [blame] | 109 | struct device node_dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | |
| 111 | /* Means this node is not attached anymore */ |
Stefan Richter | fc392fe | 2008-08-19 21:30:17 +0200 | [diff] [blame] | 112 | bool in_limbo; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | |
| 114 | struct csr1212_csr *csr; |
| 115 | }; |
| 116 | |
| 117 | struct hpsb_protocol_driver { |
| 118 | /* The name of the driver, e.g. SBP2 or IP1394 */ |
| 119 | const char *name; |
| 120 | |
| 121 | /* |
| 122 | * The device id table describing the protocols and/or devices |
| 123 | * supported by this driver. This is used by the nodemgr to |
| 124 | * decide if a driver could support a given node, but the |
| 125 | * probe function below can implement further protocol |
| 126 | * dependent or vendor dependent checking. |
| 127 | */ |
Stefan Richter | c640946 | 2009-02-15 23:11:38 +0100 | [diff] [blame] | 128 | const struct ieee1394_device_id *id_table; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | |
| 130 | /* |
| 131 | * The update function is called when the node has just |
| 132 | * survived a bus reset, i.e. it is still present on the bus. |
| 133 | * However, it may be necessary to reestablish the connection |
| 134 | * or login into the node again, depending on the protocol. If the |
| 135 | * probe fails (returns non-zero), we unbind the driver from this |
| 136 | * device. |
| 137 | */ |
| 138 | int (*update)(struct unit_directory *ud); |
| 139 | |
| 140 | /* Our LDM structure */ |
| 141 | struct device_driver driver; |
| 142 | }; |
| 143 | |
Ben Collins | ed30c26 | 2006-11-23 13:59:48 -0500 | [diff] [blame] | 144 | int __hpsb_register_protocol(struct hpsb_protocol_driver *, struct module *); |
| 145 | static inline int hpsb_register_protocol(struct hpsb_protocol_driver *driver) |
| 146 | { |
| 147 | return __hpsb_register_protocol(driver, THIS_MODULE); |
| 148 | } |
| 149 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 150 | void hpsb_unregister_protocol(struct hpsb_protocol_driver *driver); |
| 151 | |
| 152 | static inline int hpsb_node_entry_valid(struct node_entry *ne) |
| 153 | { |
| 154 | return ne->generation == get_hpsb_generation(ne->host); |
| 155 | } |
Stefan Richter | afd6546 | 2007-03-05 03:06:23 +0100 | [diff] [blame] | 156 | void hpsb_node_fill_packet(struct node_entry *ne, struct hpsb_packet *packet); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | int hpsb_node_write(struct node_entry *ne, u64 addr, |
| 158 | quadlet_t *buffer, size_t length); |
Stefan Richter | b33fdd6 | 2008-08-27 13:40:02 +0200 | [diff] [blame] | 159 | static inline int hpsb_node_read(struct node_entry *ne, u64 addr, |
| 160 | quadlet_t *buffer, size_t length) |
| 161 | { |
| 162 | unsigned int g = ne->generation; |
| 163 | |
| 164 | smp_rmb(); |
| 165 | return hpsb_read(ne->host, ne->nodeid, g, addr, buffer, length); |
| 166 | } |
| 167 | static inline int hpsb_node_lock(struct node_entry *ne, u64 addr, int extcode, |
| 168 | quadlet_t *buffer, quadlet_t arg) |
| 169 | { |
| 170 | unsigned int g = ne->generation; |
| 171 | |
| 172 | smp_rmb(); |
| 173 | return hpsb_lock(ne->host, ne->nodeid, g, addr, extcode, buffer, arg); |
| 174 | } |
Stefan Richter | afd6546 | 2007-03-05 03:06:23 +0100 | [diff] [blame] | 175 | int nodemgr_for_each_host(void *data, int (*cb)(struct hpsb_host *, void *)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 176 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | int init_ieee1394_nodemgr(void); |
| 178 | void cleanup_ieee1394_nodemgr(void); |
| 179 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 180 | /* The template for a host device */ |
| 181 | extern struct device nodemgr_dev_template_host; |
| 182 | |
| 183 | /* Bus attributes we export */ |
| 184 | extern struct bus_attribute *const fw_bus_attrs[]; |
| 185 | |
| 186 | #endif /* _IEEE1394_NODEMGR_H */ |