Commit 2c4b69bd authored by Ben Collins's avatar Ben Collins

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: default avatarStefan Richter <stefanr@s5r6.in-berlin.de>
Signed-off-by: default avatarBen Collins <bcollins@ubuntu.com>
parent 44515193
......@@ -68,24 +68,18 @@ static struct hl_host_info *hl_get_hostinfo(struct hpsb_highlevel *hl,
}
}
read_unlock(&hl->host_info_lock);
return NULL;
}
/* Returns a per host/driver data structure that was previously stored by
* hpsb_create_hostinfo. */
void *hpsb_get_hostinfo(struct hpsb_highlevel *hl, struct hpsb_host *host)
{
struct hl_host_info *hi = hl_get_hostinfo(hl, host);
if (hi)
return hi->data;
return NULL;
return hi ? hi->data : NULL;
}
/* 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,
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);
if (hi) {
HPSB_ERR("%s called hpsb_create_hostinfo when hostinfo already exists",
hl->name);
HPSB_ERR("%s called hpsb_create_hostinfo when hostinfo already"
" exists", hl->name);
return NULL;
}
......@@ -120,7 +114,6 @@ void *hpsb_create_hostinfo(struct hpsb_highlevel *hl, struct hpsb_host *host,
return data;
}
int hpsb_set_hostinfo(struct hpsb_highlevel *hl, struct hpsb_host *host,
void *data)
{
......@@ -132,16 +125,14 @@ int hpsb_set_hostinfo(struct hpsb_highlevel *hl, struct hpsb_host *host,
hi->data = data;
return 0;
} else
HPSB_ERR("%s called hpsb_set_hostinfo when hostinfo already has data",
hl->name);
HPSB_ERR("%s called hpsb_set_hostinfo when hostinfo "
"already has data", hl->name);
} else
HPSB_ERR("%s called hpsb_set_hostinfo when no hostinfo exists",
hl->name);
return -EINVAL;
}
void hpsb_destroy_hostinfo(struct hpsb_highlevel *hl, struct hpsb_host *host)
{
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);
kfree(hi);
}
return;
}
void hpsb_set_hostinfo_key(struct hpsb_highlevel *hl, struct hpsb_host *host, unsigned long key)
void hpsb_set_hostinfo_key(struct hpsb_highlevel *hl, struct hpsb_host *host,
unsigned long key)
{
struct hl_host_info *hi;
hi = hl_get_hostinfo(hl, host);
if (hi)
hi->key = key;
return;
}
void *hpsb_get_hostinfo_bykey(struct hpsb_highlevel *hl, unsigned long key)
{
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);
return data;
}
static int highlevel_for_each_host_reg(struct hpsb_host *host, void *__data)
{
struct hpsb_highlevel *hl = __data;
hl->add_host(host);
if (host->update_config_rom) {
if (hpsb_update_config_rom_image(host) < 0) {
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);
}
}
return 0;
}
......@@ -227,7 +209,6 @@ void hpsb_register_highlevel(struct hpsb_highlevel *hl)
if (hl->add_host)
nodemgr_for_each_host(hl, highlevel_for_each_host_reg);
return;
}
......@@ -238,7 +219,8 @@ static void __delete_addr(struct hpsb_address_serve *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;
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);
list_for_each_safe (lh, next, &hl->addr_list) {
as = list_entry(lh, struct hpsb_address_serve, hl_list);
if (as->host == host)
__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
* highlevel driver. */
if (update_cr && host->update_config_rom) {
if (hpsb_update_config_rom_image(host) < 0) {
if (update_cr && 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);
}
}
/* And finally, remove all the host info associated between these
* two. */
/* Finally remove all the host info associated between these two. */
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;
__unregister_host(hl, host, 1);
return 0;
}
......@@ -324,9 +301,11 @@ u64 hpsb_allocate_and_register_addrspace(struct hpsb_highlevel *hl,
end = CSR1212_ALL_SPACE_END;
}
if (((start|end) & ~align_mask) || (start >= end) || (end > 0x1000000000000ULL)) {
HPSB_ERR("%s called with invalid addresses (start = %012Lx end = %012Lx)",
__FUNCTION__, (unsigned long long)start, (unsigned long long)end);
if (((start|end) & ~align_mask) || (start >= end) ||
(end > CSR1212_ALL_SPACE_END)) {
HPSB_ERR("%s called with invalid addresses "
"(start = %012Lx end = %012Lx)", __FUNCTION__,
(unsigned long long)start,(unsigned long long)end);
return retval;
}
......@@ -340,20 +319,21 @@ u64 hpsb_allocate_and_register_addrspace(struct hpsb_highlevel *hl,
as->host = host;
write_lock_irqsave(&addr_space_lock, flags);
list_for_each(entry, &host->addr_space) {
u64 a1sa, a1ea;
u64 a2sa, a2ea;
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;
a1ea = (a1->end + alignment -1) & align_mask;
a2sa = a2->start & 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->end = as->start + size;
list_add(&as->host_list, entry);
......@@ -362,13 +342,10 @@ u64 hpsb_allocate_and_register_addrspace(struct hpsb_highlevel *hl,
break;
}
}
write_unlock_irqrestore(&addr_space_lock, flags);
if (retval == CSR1212_INVALID_ADDR_SPACE) {
if (retval == CSR1212_INVALID_ADDR_SPACE)
kfree(as);
}
return retval;
}
......@@ -380,7 +357,8 @@ int hpsb_register_addrspace(struct hpsb_highlevel *hl, struct hpsb_host *host,
int retval = 0;
unsigned long flags;
if (((start|end) & 3) || (start >= end) || (end > 0x1000000000000ULL)) {
if (((start|end) & 3) || (start >= end) ||
(end > CSR1212_ALL_SPACE_END)) {
HPSB_ERR("%s called with invalid addresses", __FUNCTION__);
return 0;
}
......@@ -397,12 +375,12 @@ int hpsb_register_addrspace(struct hpsb_highlevel *hl, struct hpsb_host *host,
as->host = host;
write_lock_irqsave(&addr_space_lock, flags);
list_for_each(lh, &host->addr_space) {
struct hpsb_address_serve *as_this =
list_entry(lh, struct hpsb_address_serve, host_list);
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)
break;
......@@ -418,7 +396,6 @@ int hpsb_register_addrspace(struct hpsb_highlevel *hl, struct hpsb_host *host,
if (retval == 0)
kfree(as);
return retval;
}
......@@ -431,7 +408,6 @@ int hpsb_unregister_addrspace(struct hpsb_highlevel *hl, struct hpsb_host *host,
unsigned long flags;
write_lock_irqsave(&addr_space_lock, flags);
list_for_each_safe (lh, next, &hl->addr_list) {
as = list_entry(lh, struct hpsb_address_serve, hl_list);
if (as->start == start && as->host == host) {
......@@ -440,9 +416,7 @@ int hpsb_unregister_addrspace(struct hpsb_highlevel *hl, struct hpsb_host *host,
break;
}
}
write_unlock_irqrestore(&addr_space_lock, flags);
return retval;
}
......@@ -453,11 +427,8 @@ int hpsb_listen_channel(struct hpsb_highlevel *hl, struct hpsb_host *host,
HPSB_ERR("%s called with invalid channel", __FUNCTION__);
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 0;
}
......@@ -468,10 +439,8 @@ void hpsb_unlisten_channel(struct hpsb_highlevel *hl, struct hpsb_host *host,
HPSB_ERR("%s called with invalid channel", __FUNCTION__);
return;
}
if (--host->iso_listen_count[channel] == 0) {
if (--host->iso_listen_count[channel] == 0)
host->driver->devctl(host, ISO_UNLISTEN_CHANNEL, channel);
}
}
static void init_hpsb_highlevel(struct hpsb_host *host)
......@@ -502,11 +471,9 @@ void highlevel_add_host(struct hpsb_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);
}
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)
......@@ -562,15 +529,14 @@ void highlevel_fcp_request(struct hpsb_host *host, int nodeid, int direction,
read_unlock_irqrestore(&hl_irqs_lock, flags);
}
int highlevel_read(struct hpsb_host *host, int nodeid, void *data,
u64 addr, unsigned int length, u16 flags)
int highlevel_read(struct hpsb_host *host, int nodeid, void *data, u64 addr,
unsigned int length, u16 flags)
{
struct hpsb_address_serve *as;
unsigned int partlength;
int rcode = RCODE_ADDRESS_ERROR;
read_lock(&addr_space_lock);
list_for_each_entry(as, &host->addr_space, host_list) {
if (as->start > addr)
break;
......@@ -578,41 +544,35 @@ int highlevel_read(struct hpsb_host *host, int nodeid, void *data,
if (as->end > addr) {
partlength = min(as->end - addr, (u64) length);
if (as->op->read) {
if (as->op->read)
rcode = as->op->read(host, nodeid, data,
addr, partlength, flags);
} else {
else
rcode = RCODE_TYPE_ERROR;
}
data += partlength;
length -= partlength;
addr += partlength;
if ((rcode != RCODE_COMPLETE) || !length) {
if ((rcode != RCODE_COMPLETE) || !length)
break;
}
}
}
read_unlock(&addr_space_lock);
if (length && (rcode == RCODE_COMPLETE)) {
if (length && (rcode == RCODE_COMPLETE))
rcode = RCODE_ADDRESS_ERROR;
}
return rcode;
}
int highlevel_write(struct hpsb_host *host, int nodeid, int destid,
void *data, u64 addr, unsigned int length, u16 flags)
int highlevel_write(struct hpsb_host *host, int nodeid, int destid, void *data,
u64 addr, unsigned int length, u16 flags)
{
struct hpsb_address_serve *as;
unsigned int partlength;
int rcode = RCODE_ADDRESS_ERROR;
read_lock(&addr_space_lock);
list_for_each_entry(as, &host->addr_space, host_list) {
if (as->start > addr)
break;
......@@ -620,64 +580,57 @@ int highlevel_write(struct hpsb_host *host, int nodeid, int destid,
if (as->end > addr) {
partlength = min(as->end - addr, (u64) length);
if (as->op->write) {
if (as->op->write)
rcode = as->op->write(host, nodeid, destid,
data, addr, partlength, flags);
} else {
data, addr, partlength,
flags);
else
rcode = RCODE_TYPE_ERROR;
}
data += partlength;
length -= partlength;
addr += partlength;
if ((rcode != RCODE_COMPLETE) || !length) {
if ((rcode != RCODE_COMPLETE) || !length)
break;
}
}
}
read_unlock(&addr_space_lock);
if (length && (rcode == RCODE_COMPLETE)) {
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, u16 flags)
u64 addr, quadlet_t data, quadlet_t arg, int ext_tcode,
u16 flags)
{
struct hpsb_address_serve *as;
int rcode = RCODE_ADDRESS_ERROR;
read_lock(&addr_space_lock);
list_for_each_entry(as, &host->addr_space, host_list) {
if (as->start > addr)
break;
if (as->end > addr) {
if (as->op->lock) {
if (as->op->lock)
rcode = as->op->lock(host, nodeid, store, addr,
data, arg, ext_tcode, flags);
} else {
data, arg, ext_tcode,
flags);
else
rcode = RCODE_TYPE_ERROR;
}
break;
}
}
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, u16 flags)
u64 addr, octlet_t data, octlet_t arg, int ext_tcode,
u16 flags)
{
struct hpsb_address_serve *as;
int rcode = RCODE_ADDRESS_ERROR;
......@@ -689,19 +642,15 @@ int highlevel_lock64(struct hpsb_host *host, int nodeid, octlet_t *store,
break;
if (as->end > addr) {
if (as->op->lock64) {
if (as->op->lock64)
rcode = as->op->lock64(host, nodeid, store,
addr, data, arg,
ext_tcode, flags);
} else {
else
rcode = RCODE_TYPE_ERROR;
}
break;
}
}
read_unlock(&addr_space_lock);
return rcode;
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment