ieee1394: adjust code formatting in highlevel.c

Replace spaces by tabulators, wrap lines at 80 columns, delete some
blank lines and superfluous braces.  Collapse some if()-within-if()
constructs.  Replace a literal CSR address by its preprocessor constant.

Signed-off-by: Stefan Richter <stefanr@s5r6.in-berlin.de>
Signed-off-by: Ben Collins <bcollins@ubuntu.com>
This commit is contained in:
Ben Collins 2006-06-12 18:16:16 -04:00
parent 445151932e
commit 2c4b69bd7b
1 changed files with 182 additions and 233 deletions

View File

@ -53,7 +53,7 @@ static struct hpsb_address_serve dummy_zero_addr, dummy_max_addr;
static struct hl_host_info *hl_get_hostinfo(struct hpsb_highlevel *hl, static struct hl_host_info *hl_get_hostinfo(struct hpsb_highlevel *hl,
struct hpsb_host *host) struct hpsb_host *host)
{ {
struct hl_host_info *hi = NULL; struct hl_host_info *hi = NULL;
@ -68,24 +68,18 @@ static struct hl_host_info *hl_get_hostinfo(struct hpsb_highlevel *hl,
} }
} }
read_unlock(&hl->host_info_lock); read_unlock(&hl->host_info_lock);
return NULL; return NULL;
} }
/* Returns a per host/driver data structure that was previously stored by /* Returns a per host/driver data structure that was previously stored by
* hpsb_create_hostinfo. */ * hpsb_create_hostinfo. */
void *hpsb_get_hostinfo(struct hpsb_highlevel *hl, struct hpsb_host *host) void *hpsb_get_hostinfo(struct hpsb_highlevel *hl, struct hpsb_host *host)
{ {
struct hl_host_info *hi = hl_get_hostinfo(hl, host); struct hl_host_info *hi = hl_get_hostinfo(hl, host);
if (hi) return hi ? hi->data : NULL;
return hi->data;
return NULL;
} }
/* If size is zero, then the return here is only valid for error checking */ /* If size is zero, then the return here is only valid for error checking */
void *hpsb_create_hostinfo(struct hpsb_highlevel *hl, struct hpsb_host *host, void *hpsb_create_hostinfo(struct hpsb_highlevel *hl, struct hpsb_host *host,
size_t data_size) size_t data_size)
@ -96,8 +90,8 @@ void *hpsb_create_hostinfo(struct hpsb_highlevel *hl, struct hpsb_host *host,
hi = hl_get_hostinfo(hl, host); hi = hl_get_hostinfo(hl, host);
if (hi) { if (hi) {
HPSB_ERR("%s called hpsb_create_hostinfo when hostinfo already exists", HPSB_ERR("%s called hpsb_create_hostinfo when hostinfo already"
hl->name); " exists", hl->name);
return NULL; return NULL;
} }
@ -120,7 +114,6 @@ void *hpsb_create_hostinfo(struct hpsb_highlevel *hl, struct hpsb_host *host,
return data; return data;
} }
int hpsb_set_hostinfo(struct hpsb_highlevel *hl, struct hpsb_host *host, int hpsb_set_hostinfo(struct hpsb_highlevel *hl, struct hpsb_host *host,
void *data) void *data)
{ {
@ -132,16 +125,14 @@ int hpsb_set_hostinfo(struct hpsb_highlevel *hl, struct hpsb_host *host,
hi->data = data; hi->data = data;
return 0; return 0;
} else } else
HPSB_ERR("%s called hpsb_set_hostinfo when hostinfo already has data", HPSB_ERR("%s called hpsb_set_hostinfo when hostinfo "
hl->name); "already has data", hl->name);
} else } else
HPSB_ERR("%s called hpsb_set_hostinfo when no hostinfo exists", HPSB_ERR("%s called hpsb_set_hostinfo when no hostinfo exists",
hl->name); hl->name);
return -EINVAL; return -EINVAL;
} }
void hpsb_destroy_hostinfo(struct hpsb_highlevel *hl, struct hpsb_host *host) void hpsb_destroy_hostinfo(struct hpsb_highlevel *hl, struct hpsb_host *host)
{ {
struct hl_host_info *hi; struct hl_host_info *hi;
@ -154,23 +145,20 @@ void hpsb_destroy_hostinfo(struct hpsb_highlevel *hl, struct hpsb_host *host)
write_unlock_irqrestore(&hl->host_info_lock, flags); write_unlock_irqrestore(&hl->host_info_lock, flags);
kfree(hi); kfree(hi);
} }
return; return;
} }
void hpsb_set_hostinfo_key(struct hpsb_highlevel *hl, struct hpsb_host *host,
void hpsb_set_hostinfo_key(struct hpsb_highlevel *hl, struct hpsb_host *host, unsigned long key) unsigned long key)
{ {
struct hl_host_info *hi; struct hl_host_info *hi;
hi = hl_get_hostinfo(hl, host); hi = hl_get_hostinfo(hl, host);
if (hi) if (hi)
hi->key = key; hi->key = key;
return; return;
} }
void *hpsb_get_hostinfo_bykey(struct hpsb_highlevel *hl, unsigned long key) void *hpsb_get_hostinfo_bykey(struct hpsb_highlevel *hl, unsigned long key)
{ {
struct hl_host_info *hi; struct hl_host_info *hi;
@ -187,24 +175,18 @@ void *hpsb_get_hostinfo_bykey(struct hpsb_highlevel *hl, unsigned long key)
} }
} }
read_unlock(&hl->host_info_lock); read_unlock(&hl->host_info_lock);
return data; return data;
} }
static int highlevel_for_each_host_reg(struct hpsb_host *host, void *__data) static int highlevel_for_each_host_reg(struct hpsb_host *host, void *__data)
{ {
struct hpsb_highlevel *hl = __data; struct hpsb_highlevel *hl = __data;
hl->add_host(host); hl->add_host(host);
if (host->update_config_rom) { if (host->update_config_rom && hpsb_update_config_rom_image(host) < 0)
if (hpsb_update_config_rom_image(host) < 0) { HPSB_ERR("Failed to generate Configuration ROM image for host "
HPSB_ERR("Failed to generate Configuration ROM image for host " "%s-%d", hl->name, host->id);
"%s-%d", hl->name, host->id);
}
}
return 0; return 0;
} }
@ -212,13 +194,13 @@ void hpsb_register_highlevel(struct hpsb_highlevel *hl)
{ {
unsigned long flags; unsigned long flags;
INIT_LIST_HEAD(&hl->addr_list); INIT_LIST_HEAD(&hl->addr_list);
INIT_LIST_HEAD(&hl->host_info_list); INIT_LIST_HEAD(&hl->host_info_list);
rwlock_init(&hl->host_info_lock); rwlock_init(&hl->host_info_lock);
down_write(&hl_drivers_sem); down_write(&hl_drivers_sem);
list_add_tail(&hl->hl_list, &hl_drivers); list_add_tail(&hl->hl_list, &hl_drivers);
up_write(&hl_drivers_sem); up_write(&hl_drivers_sem);
write_lock_irqsave(&hl_irqs_lock, flags); write_lock_irqsave(&hl_irqs_lock, flags);
@ -227,8 +209,7 @@ void hpsb_register_highlevel(struct hpsb_highlevel *hl)
if (hl->add_host) if (hl->add_host)
nodemgr_for_each_host(hl, highlevel_for_each_host_reg); nodemgr_for_each_host(hl, highlevel_for_each_host_reg);
return;
return;
} }
static void __delete_addr(struct hpsb_address_serve *as) static void __delete_addr(struct hpsb_address_serve *as)
@ -238,7 +219,8 @@ static void __delete_addr(struct hpsb_address_serve *as)
kfree(as); kfree(as);
} }
static void __unregister_host(struct hpsb_highlevel *hl, struct hpsb_host *host, int update_cr) static void __unregister_host(struct hpsb_highlevel *hl, struct hpsb_host *host,
int update_cr)
{ {
unsigned long flags; unsigned long flags;
struct list_head *lh, *next; struct list_head *lh, *next;
@ -253,7 +235,6 @@ static void __unregister_host(struct hpsb_highlevel *hl, struct hpsb_host *host,
write_lock_irqsave(&addr_space_lock, flags); write_lock_irqsave(&addr_space_lock, flags);
list_for_each_safe (lh, next, &hl->addr_list) { list_for_each_safe (lh, next, &hl->addr_list) {
as = list_entry(lh, struct hpsb_address_serve, hl_list); as = list_entry(lh, struct hpsb_address_serve, hl_list);
if (as->host == host) if (as->host == host)
__delete_addr(as); __delete_addr(as);
} }
@ -261,15 +242,12 @@ static void __unregister_host(struct hpsb_highlevel *hl, struct hpsb_host *host,
/* Now update the config-rom to reflect anything removed by the /* Now update the config-rom to reflect anything removed by the
* highlevel driver. */ * highlevel driver. */
if (update_cr && host->update_config_rom) { if (update_cr && host->update_config_rom &&
if (hpsb_update_config_rom_image(host) < 0) { hpsb_update_config_rom_image(host) < 0)
HPSB_ERR("Failed to generate Configuration ROM image for host " HPSB_ERR("Failed to generate Configuration ROM image for host "
"%s-%d", hl->name, host->id); "%s-%d", hl->name, host->id);
}
}
/* And finally, remove all the host info associated between these /* Finally remove all the host info associated between these two. */
* two. */
hpsb_destroy_hostinfo(hl, host); hpsb_destroy_hostinfo(hl, host);
} }
@ -278,7 +256,6 @@ static int highlevel_for_each_host_unreg(struct hpsb_host *host, void *__data)
struct hpsb_highlevel *hl = __data; struct hpsb_highlevel *hl = __data;
__unregister_host(hl, host, 1); __unregister_host(hl, host, 1);
return 0; return 0;
} }
@ -291,7 +268,7 @@ void hpsb_unregister_highlevel(struct hpsb_highlevel *hl)
write_unlock_irqrestore(&hl_irqs_lock, flags); write_unlock_irqrestore(&hl_irqs_lock, flags);
down_write(&hl_drivers_sem); down_write(&hl_drivers_sem);
list_del(&hl->hl_list); list_del(&hl->hl_list);
up_write(&hl_drivers_sem); up_write(&hl_drivers_sem);
nodemgr_for_each_host(hl, highlevel_for_each_host_unreg); nodemgr_for_each_host(hl, highlevel_for_each_host_unreg);
@ -324,9 +301,11 @@ u64 hpsb_allocate_and_register_addrspace(struct hpsb_highlevel *hl,
end = CSR1212_ALL_SPACE_END; end = CSR1212_ALL_SPACE_END;
} }
if (((start|end) & ~align_mask) || (start >= end) || (end > 0x1000000000000ULL)) { if (((start|end) & ~align_mask) || (start >= end) ||
HPSB_ERR("%s called with invalid addresses (start = %012Lx end = %012Lx)", (end > CSR1212_ALL_SPACE_END)) {
__FUNCTION__, (unsigned long long)start, (unsigned long long)end); HPSB_ERR("%s called with invalid addresses "
"(start = %012Lx end = %012Lx)", __FUNCTION__,
(unsigned long long)start,(unsigned long long)end);
return retval; return retval;
} }
@ -340,20 +319,21 @@ u64 hpsb_allocate_and_register_addrspace(struct hpsb_highlevel *hl,
as->host = host; as->host = host;
write_lock_irqsave(&addr_space_lock, flags); write_lock_irqsave(&addr_space_lock, flags);
list_for_each(entry, &host->addr_space) { list_for_each(entry, &host->addr_space) {
u64 a1sa, a1ea; u64 a1sa, a1ea;
u64 a2sa, a2ea; u64 a2sa, a2ea;
a1 = list_entry(entry, struct hpsb_address_serve, host_list); a1 = list_entry(entry, struct hpsb_address_serve, host_list);
a2 = list_entry(entry->next, struct hpsb_address_serve, host_list); a2 = list_entry(entry->next, struct hpsb_address_serve,
host_list);
a1sa = a1->start & align_mask; a1sa = a1->start & align_mask;
a1ea = (a1->end + alignment -1) & align_mask; a1ea = (a1->end + alignment -1) & align_mask;
a2sa = a2->start & align_mask; a2sa = a2->start & align_mask;
a2ea = (a2->end + alignment -1) & align_mask; a2ea = (a2->end + alignment -1) & align_mask;
if ((a2sa - a1ea >= size) && (a2sa - start >= size) && (a2sa > start)) { if ((a2sa - a1ea >= size) && (a2sa - start >= size) &&
(a2sa > start)) {
as->start = max(start, a1ea); as->start = max(start, a1ea);
as->end = as->start + size; as->end = as->start + size;
list_add(&as->host_list, entry); list_add(&as->host_list, entry);
@ -362,47 +342,45 @@ u64 hpsb_allocate_and_register_addrspace(struct hpsb_highlevel *hl,
break; break;
} }
} }
write_unlock_irqrestore(&addr_space_lock, flags); write_unlock_irqrestore(&addr_space_lock, flags);
if (retval == CSR1212_INVALID_ADDR_SPACE) { if (retval == CSR1212_INVALID_ADDR_SPACE)
kfree(as); kfree(as);
}
return retval; return retval;
} }
int hpsb_register_addrspace(struct hpsb_highlevel *hl, struct hpsb_host *host, int hpsb_register_addrspace(struct hpsb_highlevel *hl, struct hpsb_host *host,
struct hpsb_address_ops *ops, u64 start, u64 end) struct hpsb_address_ops *ops, u64 start, u64 end)
{ {
struct hpsb_address_serve *as; struct hpsb_address_serve *as;
struct list_head *lh; struct list_head *lh;
int retval = 0; int retval = 0;
unsigned long flags; unsigned long flags;
if (((start|end) & 3) || (start >= end) || (end > 0x1000000000000ULL)) { if (((start|end) & 3) || (start >= end) ||
HPSB_ERR("%s called with invalid addresses", __FUNCTION__); (end > CSR1212_ALL_SPACE_END)) {
return 0; HPSB_ERR("%s called with invalid addresses", __FUNCTION__);
} return 0;
}
as = kmalloc(sizeof(*as), GFP_ATOMIC); as = kmalloc(sizeof(*as), GFP_ATOMIC);
if (!as) if (!as)
return 0; return 0;
INIT_LIST_HEAD(&as->host_list); INIT_LIST_HEAD(&as->host_list);
INIT_LIST_HEAD(&as->hl_list); INIT_LIST_HEAD(&as->hl_list);
as->op = ops; as->op = ops;
as->start = start; as->start = start;
as->end = end; as->end = end;
as->host = host; as->host = host;
write_lock_irqsave(&addr_space_lock, flags); write_lock_irqsave(&addr_space_lock, flags);
list_for_each(lh, &host->addr_space) { list_for_each(lh, &host->addr_space) {
struct hpsb_address_serve *as_this = struct hpsb_address_serve *as_this =
list_entry(lh, struct hpsb_address_serve, host_list); list_entry(lh, struct hpsb_address_serve, host_list);
struct hpsb_address_serve *as_next = struct hpsb_address_serve *as_next =
list_entry(lh->next, struct hpsb_address_serve, host_list); list_entry(lh->next, struct hpsb_address_serve,
host_list);
if (as_this->end > as->start) if (as_this->end > as->start)
break; break;
@ -418,60 +396,51 @@ int hpsb_register_addrspace(struct hpsb_highlevel *hl, struct hpsb_host *host,
if (retval == 0) if (retval == 0)
kfree(as); kfree(as);
return retval;
return retval;
} }
int hpsb_unregister_addrspace(struct hpsb_highlevel *hl, struct hpsb_host *host, int hpsb_unregister_addrspace(struct hpsb_highlevel *hl, struct hpsb_host *host,
u64 start) u64 start)
{ {
int retval = 0; int retval = 0;
struct hpsb_address_serve *as; struct hpsb_address_serve *as;
struct list_head *lh, *next; struct list_head *lh, *next;
unsigned long flags; unsigned long flags;
write_lock_irqsave(&addr_space_lock, flags);
write_lock_irqsave(&addr_space_lock, flags);
list_for_each_safe (lh, next, &hl->addr_list) { list_for_each_safe (lh, next, &hl->addr_list) {
as = list_entry(lh, struct hpsb_address_serve, hl_list); as = list_entry(lh, struct hpsb_address_serve, hl_list);
if (as->start == start && as->host == host) { if (as->start == start && as->host == host) {
__delete_addr(as); __delete_addr(as);
retval = 1; retval = 1;
break; break;
} }
} }
write_unlock_irqrestore(&addr_space_lock, flags);
write_unlock_irqrestore(&addr_space_lock, flags); return retval;
return retval;
} }
int hpsb_listen_channel(struct hpsb_highlevel *hl, struct hpsb_host *host, int hpsb_listen_channel(struct hpsb_highlevel *hl, struct hpsb_host *host,
unsigned int channel) unsigned int channel)
{ {
if (channel > 63) { if (channel > 63) {
HPSB_ERR("%s called with invalid channel", __FUNCTION__); HPSB_ERR("%s called with invalid channel", __FUNCTION__);
return -EINVAL; return -EINVAL;
} }
if (host->iso_listen_count[channel]++ == 0)
if (host->iso_listen_count[channel]++ == 0) { return host->driver->devctl(host, ISO_LISTEN_CHANNEL, channel);
return host->driver->devctl(host, ISO_LISTEN_CHANNEL, channel);
}
return 0; return 0;
} }
void hpsb_unlisten_channel(struct hpsb_highlevel *hl, struct hpsb_host *host, void hpsb_unlisten_channel(struct hpsb_highlevel *hl, struct hpsb_host *host,
unsigned int channel) unsigned int channel)
{ {
if (channel > 63) { if (channel > 63) {
HPSB_ERR("%s called with invalid channel", __FUNCTION__); HPSB_ERR("%s called with invalid channel", __FUNCTION__);
return; return;
} }
if (--host->iso_listen_count[channel] == 0)
if (--host->iso_listen_count[channel] == 0) { host->driver->devctl(host, ISO_UNLISTEN_CHANNEL, channel);
host->driver->devctl(host, ISO_UNLISTEN_CHANNEL, channel);
}
} }
static void init_hpsb_highlevel(struct hpsb_host *host) static void init_hpsb_highlevel(struct hpsb_host *host)
@ -492,26 +461,24 @@ static void init_hpsb_highlevel(struct hpsb_host *host)
void highlevel_add_host(struct hpsb_host *host) void highlevel_add_host(struct hpsb_host *host)
{ {
struct hpsb_highlevel *hl; struct hpsb_highlevel *hl;
init_hpsb_highlevel(host); init_hpsb_highlevel(host);
down_read(&hl_drivers_sem); down_read(&hl_drivers_sem);
list_for_each_entry(hl, &hl_drivers, hl_list) { list_for_each_entry(hl, &hl_drivers, hl_list) {
if (hl->add_host) if (hl->add_host)
hl->add_host(host); hl->add_host(host);
}
up_read(&hl_drivers_sem);
if (host->update_config_rom) {
if (hpsb_update_config_rom_image(host) < 0)
HPSB_ERR("Failed to generate Configuration ROM image for "
"host %s-%d", hl->name, host->id);
} }
up_read(&hl_drivers_sem);
if (host->update_config_rom && hpsb_update_config_rom_image(host) < 0)
HPSB_ERR("Failed to generate Configuration ROM image for host "
"%s-%d", hl->name, host->id);
} }
void highlevel_remove_host(struct hpsb_host *host) void highlevel_remove_host(struct hpsb_host *host)
{ {
struct hpsb_highlevel *hl; struct hpsb_highlevel *hl;
down_read(&hl_drivers_sem); down_read(&hl_drivers_sem);
list_for_each_entry(hl, &hl_drivers, hl_list) list_for_each_entry(hl, &hl_drivers, hl_list)
@ -522,186 +489,168 @@ void highlevel_remove_host(struct hpsb_host *host)
void highlevel_host_reset(struct hpsb_host *host) void highlevel_host_reset(struct hpsb_host *host)
{ {
unsigned long flags; unsigned long flags;
struct hpsb_highlevel *hl; struct hpsb_highlevel *hl;
read_lock_irqsave(&hl_irqs_lock, flags); read_lock_irqsave(&hl_irqs_lock, flags);
list_for_each_entry(hl, &hl_irqs, irq_list) { list_for_each_entry(hl, &hl_irqs, irq_list) {
if (hl->host_reset) if (hl->host_reset)
hl->host_reset(host); hl->host_reset(host);
} }
read_unlock_irqrestore(&hl_irqs_lock, flags); read_unlock_irqrestore(&hl_irqs_lock, flags);
} }
void highlevel_iso_receive(struct hpsb_host *host, void *data, size_t length) void highlevel_iso_receive(struct hpsb_host *host, void *data, size_t length)
{ {
unsigned long flags; unsigned long flags;
struct hpsb_highlevel *hl; struct hpsb_highlevel *hl;
int channel = (((quadlet_t *)data)[0] >> 8) & 0x3f; int channel = (((quadlet_t *)data)[0] >> 8) & 0x3f;
read_lock_irqsave(&hl_irqs_lock, flags); read_lock_irqsave(&hl_irqs_lock, flags);
list_for_each_entry(hl, &hl_irqs, irq_list) { list_for_each_entry(hl, &hl_irqs, irq_list) {
if (hl->iso_receive) if (hl->iso_receive)
hl->iso_receive(host, channel, data, length); hl->iso_receive(host, channel, data, length);
} }
read_unlock_irqrestore(&hl_irqs_lock, flags); read_unlock_irqrestore(&hl_irqs_lock, flags);
} }
void highlevel_fcp_request(struct hpsb_host *host, int nodeid, int direction, void highlevel_fcp_request(struct hpsb_host *host, int nodeid, int direction,
void *data, size_t length) void *data, size_t length)
{ {
unsigned long flags; unsigned long flags;
struct hpsb_highlevel *hl; struct hpsb_highlevel *hl;
int cts = ((quadlet_t *)data)[0] >> 4; int cts = ((quadlet_t *)data)[0] >> 4;
read_lock_irqsave(&hl_irqs_lock, flags); read_lock_irqsave(&hl_irqs_lock, flags);
list_for_each_entry(hl, &hl_irqs, irq_list) { list_for_each_entry(hl, &hl_irqs, irq_list) {
if (hl->fcp_request) if (hl->fcp_request)
hl->fcp_request(host, nodeid, direction, cts, data, hl->fcp_request(host, nodeid, direction, cts, data,
length); length);
} }
read_unlock_irqrestore(&hl_irqs_lock, flags); read_unlock_irqrestore(&hl_irqs_lock, flags);
} }
int highlevel_read(struct hpsb_host *host, int nodeid, void *data, int highlevel_read(struct hpsb_host *host, int nodeid, void *data, u64 addr,
u64 addr, unsigned int length, u16 flags) unsigned int length, u16 flags)
{ {
struct hpsb_address_serve *as; struct hpsb_address_serve *as;
unsigned int partlength; unsigned int partlength;
int rcode = RCODE_ADDRESS_ERROR; int rcode = RCODE_ADDRESS_ERROR;
read_lock(&addr_space_lock);
read_lock(&addr_space_lock);
list_for_each_entry(as, &host->addr_space, host_list) { list_for_each_entry(as, &host->addr_space, host_list) {
if (as->start > addr) if (as->start > addr)
break; break;
if (as->end > addr) { if (as->end > addr) {
partlength = min(as->end - addr, (u64) length); partlength = min(as->end - addr, (u64) length);
if (as->op->read) { if (as->op->read)
rcode = as->op->read(host, nodeid, data, rcode = as->op->read(host, nodeid, data,
addr, partlength, flags); addr, partlength, flags);
} else { else
rcode = RCODE_TYPE_ERROR; rcode = RCODE_TYPE_ERROR;
}
data += partlength; data += partlength;
length -= partlength; length -= partlength;
addr += partlength; addr += partlength;
if ((rcode != RCODE_COMPLETE) || !length) { if ((rcode != RCODE_COMPLETE) || !length)
break; break;
} }
} }
} read_unlock(&addr_space_lock);
read_unlock(&addr_space_lock); if (length && (rcode == RCODE_COMPLETE))
rcode = RCODE_ADDRESS_ERROR;
if (length && (rcode == RCODE_COMPLETE)) { return rcode;
rcode = RCODE_ADDRESS_ERROR;
}
return rcode;
} }
int highlevel_write(struct hpsb_host *host, int nodeid, int destid, int highlevel_write(struct hpsb_host *host, int nodeid, int destid, void *data,
void *data, u64 addr, unsigned int length, u16 flags) u64 addr, unsigned int length, u16 flags)
{ {
struct hpsb_address_serve *as; struct hpsb_address_serve *as;
unsigned int partlength; unsigned int partlength;
int rcode = RCODE_ADDRESS_ERROR; int rcode = RCODE_ADDRESS_ERROR;
read_lock(&addr_space_lock);
read_lock(&addr_space_lock);
list_for_each_entry(as, &host->addr_space, host_list) { list_for_each_entry(as, &host->addr_space, host_list) {
if (as->start > addr) if (as->start > addr)
break; break;
if (as->end > addr) { if (as->end > addr) {
partlength = min(as->end - addr, (u64) length); partlength = min(as->end - addr, (u64) length);
if (as->op->write) { if (as->op->write)
rcode = as->op->write(host, nodeid, destid, rcode = as->op->write(host, nodeid, destid,
data, addr, partlength, flags); data, addr, partlength,
} else { flags);
rcode = RCODE_TYPE_ERROR; else
} rcode = RCODE_TYPE_ERROR;
data += partlength; data += partlength;
length -= partlength; length -= partlength;
addr += partlength; addr += partlength;
if ((rcode != RCODE_COMPLETE) || !length) { if ((rcode != RCODE_COMPLETE) || !length)
break; break;
} }
} }
} read_unlock(&addr_space_lock);
read_unlock(&addr_space_lock); if (length && (rcode == RCODE_COMPLETE))
rcode = RCODE_ADDRESS_ERROR;
if (length && (rcode == RCODE_COMPLETE)) { return rcode;
rcode = RCODE_ADDRESS_ERROR;
}
return rcode;
} }
int highlevel_lock(struct hpsb_host *host, int nodeid, quadlet_t *store, int highlevel_lock(struct hpsb_host *host, int nodeid, quadlet_t *store,
u64 addr, quadlet_t data, quadlet_t arg, int ext_tcode, u16 flags) u64 addr, quadlet_t data, quadlet_t arg, int ext_tcode,
u16 flags)
{ {
struct hpsb_address_serve *as; struct hpsb_address_serve *as;
int rcode = RCODE_ADDRESS_ERROR; int rcode = RCODE_ADDRESS_ERROR;
read_lock(&addr_space_lock);
read_lock(&addr_space_lock);
list_for_each_entry(as, &host->addr_space, host_list) { list_for_each_entry(as, &host->addr_space, host_list) {
if (as->start > addr) if (as->start > addr)
break; break;
if (as->end > addr) { if (as->end > addr) {
if (as->op->lock) { if (as->op->lock)
rcode = as->op->lock(host, nodeid, store, addr, rcode = as->op->lock(host, nodeid, store, addr,
data, arg, ext_tcode, flags); data, arg, ext_tcode,
} else { flags);
rcode = RCODE_TYPE_ERROR; else
} rcode = RCODE_TYPE_ERROR;
break;
break; }
} }
} read_unlock(&addr_space_lock);
return rcode;
read_unlock(&addr_space_lock);
return rcode;
} }
int highlevel_lock64(struct hpsb_host *host, int nodeid, octlet_t *store, int highlevel_lock64(struct hpsb_host *host, int nodeid, octlet_t *store,
u64 addr, octlet_t data, octlet_t arg, int ext_tcode, u16 flags) u64 addr, octlet_t data, octlet_t arg, int ext_tcode,
u16 flags)
{ {
struct hpsb_address_serve *as; struct hpsb_address_serve *as;
int rcode = RCODE_ADDRESS_ERROR; int rcode = RCODE_ADDRESS_ERROR;
read_lock(&addr_space_lock); read_lock(&addr_space_lock);
list_for_each_entry(as, &host->addr_space, host_list) { list_for_each_entry(as, &host->addr_space, host_list) {
if (as->start > addr) if (as->start > addr)
break; break;
if (as->end > addr) { if (as->end > addr) {
if (as->op->lock64) { if (as->op->lock64)
rcode = as->op->lock64(host, nodeid, store, rcode = as->op->lock64(host, nodeid, store,
addr, data, arg, addr, data, arg,
ext_tcode, flags); ext_tcode, flags);
} else { else
rcode = RCODE_TYPE_ERROR; rcode = RCODE_TYPE_ERROR;
} break;
}
break; }
} read_unlock(&addr_space_lock);
} return rcode;
read_unlock(&addr_space_lock);
return rcode;
} }