1 #ifndef _IEEE1394_HOSTS_H 2 #define _IEEE1394_HOSTS_H 3 4 #include <linux/wait.h> 5 #include <linux/list.h> 6 #include <linux/timer.h> 7 #include <asm/semaphore.h> 8 9 #include "ieee1394_types.h" 10 #include "csr.h" 11 12 /* size of the array used to store config rom (in quadlets) 13 maximum is 0x100. About 0x40 is needed for the default 14 entries. So 0x80 should provide enough space for additional 15 directories etc. 16 Note: All lowlevel drivers are required to allocate at least 17 this amount of memory for the configuration rom! 18 */ 19 #define CSR_CONFIG_ROM_SIZE 0x100 20 21 struct hpsb_packet; 22 struct hpsb_iso; 23 24 struct hpsb_host { 25 struct list_head host_list; 26 27 void *hostdata; 28 29 atomic_t generation; 30 31 int refcount; 32 33 struct list_head pending_packets; 34 spinlock_t pending_pkt_lock; 35 struct timer_list timeout; 36 unsigned long timeout_interval; 37 38 unsigned char iso_listen_count[64]; 39 40 int node_count; /* number of identified nodes on this bus */ 41 int selfid_count; /* total number of SelfIDs received */ 42 int nodes_active; /* number of nodes that are actually active */ 43 44 nodeid_t node_id; /* node ID of this host */ 45 nodeid_t irm_id; /* ID of this bus' isochronous resource manager */ 46 nodeid_t busmgr_id; /* ID of this bus' bus manager */ 47 48 /* this nodes state */ 49 unsigned in_bus_reset:1; 50 unsigned is_shutdown:1; 51 52 /* this nodes' duties on the bus */ 53 unsigned is_root:1; 54 unsigned is_cycmst:1; 55 unsigned is_irm:1; 56 unsigned is_busmgr:1; 57 58 int reset_retries; 59 quadlet_t *topology_map; 60 u8 *speed_map; 61 struct csr_control csr; 62 63 /* Per node tlabel pool allocation */ 64 struct hpsb_tlabel_pool tpool[64]; 65 66 struct hpsb_host_driver *driver; 67 68 struct pci_dev *pdev; 69 70 int id; 71 }; 72 73 74 75 enum devctl_cmd { 76 /* Host is requested to reset its bus and cancel all outstanding async 77 * requests. If arg == 1, it shall also attempt to become root on the 78 * bus. Return void. */ 79 RESET_BUS, 80 81 /* Arg is void, return value is the hardware cycle counter value. */ 82 GET_CYCLE_COUNTER, 83 84 /* Set the hardware cycle counter to the value in arg, return void. 85 * FIXME - setting is probably not required. */ 86 SET_CYCLE_COUNTER, 87 88 /* Configure hardware for new bus ID in arg, return void. */ 89 SET_BUS_ID, 90 91 /* If arg true, start sending cycle start packets, stop if arg == 0. 92 * Return void. */ 93 ACT_CYCLE_MASTER, 94 95 /* Cancel all outstanding async requests without resetting the bus. 96 * Return void. */ 97 CANCEL_REQUESTS, 98 99 /* Decrease host usage count if arg == 0, increase otherwise. Return 100 * 1 for success, 0 for failure. Increase usage may fail if the driver 101 * is in the process of shutting itself down. Decrease usage can not 102 * fail. */ 103 MODIFY_USAGE, 104 105 /* Start or stop receiving isochronous channel in arg. Return void. 106 * This acts as an optimization hint, hosts are not required not to 107 * listen on unrequested channels. */ 108 ISO_LISTEN_CHANNEL, 109 ISO_UNLISTEN_CHANNEL 110 }; 111 112 enum isoctl_cmd { 113 /* rawiso API - see iso.h for the meanings of these commands 114 (they correspond exactly to the hpsb_iso_* API functions) 115 * INIT = allocate resources 116 * START = begin transmission/reception 117 * STOP = halt transmission/reception 118 * QUEUE/RELEASE = produce/consume packets 119 * SHUTDOWN = deallocate resources 120 */ 121 122 XMIT_INIT, 123 XMIT_START, 124 XMIT_STOP, 125 XMIT_QUEUE, 126 XMIT_SHUTDOWN, 127 128 RECV_INIT, 129 RECV_LISTEN_CHANNEL, /* multi-channel only */ 130 RECV_UNLISTEN_CHANNEL, /* multi-channel only */ 131 RECV_SET_CHANNEL_MASK, /* multi-channel only; arg is a *u64 */ 132 RECV_START, 133 RECV_STOP, 134 RECV_RELEASE, 135 RECV_SHUTDOWN, 136 RECV_FLUSH 137 }; 138 139 enum reset_types { 140 /* 166 microsecond reset -- only type of reset available on 141 non-1394a capable IEEE 1394 controllers */ 142 LONG_RESET, 143 144 /* Short (arbitrated) reset -- only available on 1394a capable 145 IEEE 1394 capable controllers */ 146 SHORT_RESET, 147 148 /* Variants, that set force_root before issueing the bus reset */ 149 LONG_RESET_FORCE_ROOT, SHORT_RESET_FORCE_ROOT, 150 151 /* Variants, that clear force_root before issueing the bus reset */ 152 LONG_RESET_NO_FORCE_ROOT, SHORT_RESET_NO_FORCE_ROOT 153 }; 154 155 struct hpsb_host_driver { 156 const char *name; 157 158 /* This function must store a pointer to the configuration ROM into the 159 * location referenced to by pointer and return the size of the ROM. It 160 * may not fail. If any allocation is required, it must be done 161 * earlier. 162 */ 163 size_t (*get_rom) (struct hpsb_host *host, quadlet_t **pointer); 164 165 /* This function shall implement packet transmission based on 166 * packet->type. It shall CRC both parts of the packet (unless 167 * packet->type == raw) and do byte-swapping as necessary or instruct 168 * the hardware to do so. It can return immediately after the packet 169 * was queued for sending. After sending, hpsb_sent_packet() has to be 170 * called. Return 0 for failure. 171 * NOTE: The function must be callable in interrupt context. 172 */ 173 int (*transmit_packet) (struct hpsb_host *host, 174 struct hpsb_packet *packet); 175 176 /* This function requests miscellanous services from the driver, see 177 * above for command codes and expected actions. Return -1 for unknown 178 * command, though that should never happen. 179 */ 180 int (*devctl) (struct hpsb_host *host, enum devctl_cmd command, int arg); 181 182 /* ISO transmission/reception functions. Return 0 on success, -1 183 * (or -EXXX errno code) on failure. If the low-level driver does not 184 * support the new ISO API, set isoctl to NULL. 185 */ 186 int (*isoctl) (struct hpsb_iso *iso, enum isoctl_cmd command, unsigned long arg); 187 188 /* This function is mainly to redirect local CSR reads/locks to the iso 189 * management registers (bus manager id, bandwidth available, channels 190 * available) to the hardware registers in OHCI. reg is 0,1,2,3 for bus 191 * mgr, bwdth avail, ch avail hi, ch avail lo respectively (the same ids 192 * as OHCI uses). data and compare are the new data and expected data 193 * respectively, return value is the old value. 194 */ 195 quadlet_t (*hw_csr_reg) (struct hpsb_host *host, int reg, 196 quadlet_t data, quadlet_t compare); 197 }; 198 199 200 extern struct list_head hpsb_hosts; 201 extern struct semaphore hpsb_hosts_lock; 202 203 204 /* 205 * In order to prevent hosts from unloading, use hpsb_ref_host(). This prevents 206 * the host from going away (e.g. makes module unloading of the driver 207 * impossible), but still can not guarantee it (e.g. PC-Card being pulled by the 208 * user). hpsb_ref_host() returns false if host could not be locked. If it is 209 * successful, host is valid as a pointer until hpsb_unref_host() (not just 210 * until after remove_host). 211 */ 212 int hpsb_ref_host(struct hpsb_host *host); 213 void hpsb_unref_host(struct hpsb_host *host); 214 215 struct hpsb_host *hpsb_alloc_host(struct hpsb_host_driver *drv, size_t extra); 216 void hpsb_add_host(struct hpsb_host *host); 217 void hpsb_remove_host(struct hpsb_host *h); 218 219 /* updates the configuration rom of a host. 220 * rom_version must be the current version, 221 * otherwise it will fail with return value -1. 222 * Return value -2 indicates that the new 223 * rom version is too big. 224 * Return value 0 indicates success 225 */ 226 int hpsb_update_config_rom(struct hpsb_host *host, 227 const quadlet_t *new_rom, size_t size, unsigned char rom_version); 228 229 /* reads the current version of the configuration rom of a host. 230 * buffersize is the size of the buffer, rom_size 231 * returns the size of the current rom image. 232 * rom_version is the version number of the fetched rom. 233 * return value -1 indicates, that the buffer was 234 * too small, 0 indicates success. 235 */ 236 int hpsb_get_config_rom(struct hpsb_host *host, quadlet_t *buffer, 237 size_t buffersize, size_t *rom_size, unsigned char *rom_version); 238 239 #endif /* _IEEE1394_HOSTS_H */ 240