1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404
|
/*
* IEEE 1394 for Linux
*
* Copyright (C) 1999 Andreas E. Bombe
*
* This code is licensed under the GPL. See the file COPYING in the root
* directory of the kernel sources for details.
*/
#include <linux/config.h>
#include <linux/slab.h>
#include "ieee1394.h"
#include "ieee1394_types.h"
#include "hosts.h"
#include "ieee1394_core.h"
#include "highlevel.h"
LIST_HEAD(hl_drivers);
rwlock_t hl_drivers_lock = RW_LOCK_UNLOCKED;
LIST_HEAD(addr_space);
rwlock_t addr_space_lock = RW_LOCK_UNLOCKED;
/* addr_space list will have zero and max already included as bounds */
static struct hpsb_address_ops dummy_ops = { NULL, NULL, NULL, NULL };
static struct hpsb_address_serve dummy_zero_addr, dummy_max_addr;
struct hpsb_highlevel *hpsb_register_highlevel(const char *name,
struct hpsb_highlevel_ops *ops)
{
struct hpsb_highlevel *hl;
hl = (struct hpsb_highlevel *)kmalloc(sizeof(struct hpsb_highlevel),
GFP_KERNEL);
if (hl == NULL) {
return NULL;
}
INIT_LIST_HEAD(&hl->hl_list);
INIT_LIST_HEAD(&hl->addr_list);
hl->name = name;
hl->op = ops;
write_lock_irq(&hl_drivers_lock);
hl_all_hosts(hl, 1);
list_add_tail(&hl->hl_list, &hl_drivers);
write_unlock_irq(&hl_drivers_lock);
return hl;
}
void hpsb_unregister_highlevel(struct hpsb_highlevel *hl)
{
struct list_head *entry;
struct hpsb_address_serve *as;
if (hl == NULL) {
return;
}
write_lock_irq(&addr_space_lock);
entry = hl->addr_list.next;
while (entry != &hl->addr_list) {
as = list_entry(entry, struct hpsb_address_serve, addr_list);
list_del(&as->as_list);
entry = entry->next;
kfree(as);
}
write_unlock_irq(&addr_space_lock);
write_lock_irq(&hl_drivers_lock);
list_del(&hl->hl_list);
hl_all_hosts(hl, 0);
write_unlock_irq(&hl_drivers_lock);
kfree(hl);
}
int hpsb_register_addrspace(struct hpsb_highlevel *hl,
struct hpsb_address_ops *ops, u64 start, u64 end)
{
struct hpsb_address_serve *as;
struct list_head *entry;
int retval = 0;
if (((start|end) & 3) || (start >= end) || (end > 0x1000000000000ULL)) {
HPSB_ERR(__FUNCTION__ " called with invalid addresses");
return 0;
}
as = (struct hpsb_address_serve *)
kmalloc(sizeof(struct hpsb_address_serve), GFP_KERNEL);
if (as == NULL) {
return 0;
}
INIT_LIST_HEAD(&as->as_list);
INIT_LIST_HEAD(&as->addr_list);
as->op = ops;
as->start = start;
as->end = end;
write_lock_irq(&addr_space_lock);
entry = addr_space.next;
while (list_entry(entry, struct hpsb_address_serve, as_list)->end
<= start) {
if (list_entry(entry->next, struct hpsb_address_serve, as_list)
->start >= end) {
list_add(&as->as_list, entry);
list_add_tail(&as->addr_list, &hl->addr_list);
retval = 1;
break;
}
entry = entry->next;
}
write_unlock_irq(&addr_space_lock);
if (retval == 0) {
kfree(as);
}
return retval;
}
void hpsb_listen_channel(struct hpsb_highlevel *hl, struct hpsb_host *host,
unsigned int channel)
{
if (channel > 63) {
HPSB_ERR(__FUNCTION__ " called with invalid channel");
return;
}
if (host->iso_listen_count[channel]++ == 0) {
host->template->devctl(host, ISO_LISTEN_CHANNEL, channel);
}
}
void hpsb_unlisten_channel(struct hpsb_highlevel *hl, struct hpsb_host *host,
unsigned int channel)
{
if (channel > 63) {
HPSB_ERR(__FUNCTION__ " called with invalid channel");
return;
}
if (--host->iso_listen_count[channel] == 0) {
host->template->devctl(host, ISO_UNLISTEN_CHANNEL, channel);
}
}
#define DEFINE_MULTIPLEXER(Function) \
void highlevel_##Function(struct hpsb_host *host) \
{ \
struct list_head *lh; \
void (*funcptr)(struct hpsb_host*); \
read_lock(&hl_drivers_lock); \
list_for_each(lh, &hl_drivers) { \
funcptr = list_entry(lh, struct hpsb_highlevel, hl_list) \
->op->Function; \
if (funcptr) funcptr(host); \
} \
read_unlock(&hl_drivers_lock); \
}
DEFINE_MULTIPLEXER(add_host)
DEFINE_MULTIPLEXER(remove_host)
DEFINE_MULTIPLEXER(host_reset)
#undef DEFINE_MULTIPLEXER
/* Add one host to our list */
void highlevel_add_one_host (struct hpsb_host *host)
{
if (host->template->initialize_host)
if (!host->template->initialize_host(host))
goto fail;
host->initialized = 1;
highlevel_add_host (host);
hpsb_reset_bus (host, LONG_RESET);
fail:
host->template->number_of_hosts++;
}
void highlevel_iso_receive(struct hpsb_host *host, quadlet_t *data,
unsigned int length)
{
struct list_head *entry;
struct hpsb_highlevel *hl;
int channel = (data[0] >> 8) & 0x3f;
read_lock(&hl_drivers_lock);
entry = hl_drivers.next;
while (entry != &hl_drivers) {
hl = list_entry(entry, struct hpsb_highlevel, hl_list);
if (hl->op->iso_receive) {
hl->op->iso_receive(host, channel, data, length);
}
entry = entry->next;
}
read_unlock(&hl_drivers_lock);
}
void highlevel_fcp_request(struct hpsb_host *host, int nodeid, int direction,
u8 *data, unsigned int length)
{
struct list_head *entry;
struct hpsb_highlevel *hl;
int cts = data[0] >> 4;
read_lock(&hl_drivers_lock);
entry = hl_drivers.next;
while (entry != &hl_drivers) {
hl = list_entry(entry, struct hpsb_highlevel, hl_list);
if (hl->op->fcp_request) {
hl->op->fcp_request(host, nodeid, direction, cts, data,
length);
}
entry = entry->next;
}
read_unlock(&hl_drivers_lock);
}
int highlevel_read(struct hpsb_host *host, int nodeid, quadlet_t *buffer,
u64 addr, unsigned int length)
{
struct hpsb_address_serve *as;
struct list_head *entry;
unsigned int partlength;
int rcode = RCODE_ADDRESS_ERROR;
read_lock(&addr_space_lock);
entry = addr_space.next;
as = list_entry(entry, struct hpsb_address_serve, as_list);
while (as->start <= addr) {
if (as->end > addr) {
partlength = MIN((unsigned int)(as->end - addr),
length);
if (as->op->read != NULL) {
rcode = as->op->read(host, nodeid, buffer, addr,
partlength);
} else {
rcode = RCODE_TYPE_ERROR;
}
length -= partlength;
addr += partlength;
if ((rcode != RCODE_COMPLETE) || !length) {
break;
}
}
entry = entry->next;
as = list_entry(entry, struct hpsb_address_serve, as_list);
}
read_unlock(&addr_space_lock);
if (length && (rcode == RCODE_COMPLETE)) {
rcode = RCODE_ADDRESS_ERROR;
}
return rcode;
}
int highlevel_write(struct hpsb_host *host, int nodeid, int destid,
quadlet_t *data, u64 addr, unsigned int length)
{
struct hpsb_address_serve *as;
struct list_head *entry;
unsigned int partlength;
int rcode = RCODE_ADDRESS_ERROR;
read_lock(&addr_space_lock);
entry = addr_space.next;
as = list_entry(entry, struct hpsb_address_serve, as_list);
while (as->start <= addr) {
if (as->end > addr) {
partlength = MIN((unsigned int)(as->end - addr),
length);
if (as->op->write != NULL) {
rcode = as->op->write(host, nodeid, destid, data,
addr, partlength);
} else {
rcode = RCODE_TYPE_ERROR;
}
length -= partlength;
addr += partlength;
if ((rcode != RCODE_COMPLETE) || !length) {
break;
}
}
entry = entry->next;
as = list_entry(entry, struct hpsb_address_serve, as_list);
}
read_unlock(&addr_space_lock);
if (length && (rcode == RCODE_COMPLETE)) {
rcode = RCODE_ADDRESS_ERROR;
}
return rcode;
}
int highlevel_lock(struct hpsb_host *host, int nodeid, quadlet_t *store,
u64 addr, quadlet_t data, quadlet_t arg, int ext_tcode)
{
struct hpsb_address_serve *as;
struct list_head *entry;
int rcode = RCODE_ADDRESS_ERROR;
read_lock(&addr_space_lock);
entry = addr_space.next;
as = list_entry(entry, struct hpsb_address_serve, as_list);
while (as->start <= addr) {
if (as->end > addr) {
if (as->op->lock != NULL) {
rcode = as->op->lock(host, nodeid, store, addr,
data, arg, ext_tcode);
} else {
rcode = RCODE_TYPE_ERROR;
}
break;
}
entry = entry->next;
as = list_entry(entry, struct hpsb_address_serve, as_list);
}
read_unlock(&addr_space_lock);
return rcode;
}
int highlevel_lock64(struct hpsb_host *host, int nodeid, octlet_t *store,
u64 addr, octlet_t data, octlet_t arg, int ext_tcode)
{
struct hpsb_address_serve *as;
struct list_head *entry;
int rcode = RCODE_ADDRESS_ERROR;
read_lock(&addr_space_lock);
entry = addr_space.next;
as = list_entry(entry, struct hpsb_address_serve, as_list);
while (as->start <= addr) {
if (as->end > addr) {
if (as->op->lock64 != NULL) {
rcode = as->op->lock64(host, nodeid, store,
addr, data, arg,
ext_tcode);
} else {
rcode = RCODE_TYPE_ERROR;
}
break;
}
entry = entry->next;
as = list_entry(entry, struct hpsb_address_serve, as_list);
}
read_unlock(&addr_space_lock);
return rcode;
}
void init_hpsb_highlevel(void)
{
INIT_LIST_HEAD(&dummy_zero_addr.as_list);
INIT_LIST_HEAD(&dummy_zero_addr.addr_list);
INIT_LIST_HEAD(&dummy_max_addr.as_list);
INIT_LIST_HEAD(&dummy_max_addr.addr_list);
dummy_zero_addr.op = dummy_max_addr.op = &dummy_ops;
dummy_zero_addr.start = dummy_zero_addr.end = 0;
dummy_max_addr.start = dummy_max_addr.end = ((u64) 1) << 48;
list_add_tail(&dummy_zero_addr.as_list, &addr_space);
list_add_tail(&dummy_max_addr.as_list, &addr_space);
}
|