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
|
/*
* IEEE 1394 for Linux
*
* Low level (host adapter) management.
*
* Copyright (C) 1999 Andreas E. Bombe
* Copyright (C) 1999 Emanuel Pirker
*
* 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/types.h>
#include <linux/init.h>
#include <linux/vmalloc.h>
#include <linux/wait.h>
#include "ieee1394_types.h"
#include "hosts.h"
#include "ieee1394_core.h"
#include "highlevel.h"
static LIST_HEAD(templates);
static spinlock_t templates_lock = SPIN_LOCK_UNLOCKED;
/*
* This function calls the add_host/remove_host hooks for every host currently
* registered. Init == TRUE means add_host.
*/
void hl_all_hosts(struct hpsb_highlevel *hl, int init)
{
struct list_head *tlh, *hlh;
struct hpsb_host_template *tmpl;
struct hpsb_host *host;
spin_lock(&templates_lock);
list_for_each(tlh, &templates) {
tmpl = list_entry(tlh, struct hpsb_host_template, list);
list_for_each(hlh, &tmpl->hosts) {
host = list_entry(hlh, struct hpsb_host, list);
if (host->initialized) {
if (init) {
if (hl->op->add_host) {
hl->op->add_host(host);
}
} else {
if (hl->op->remove_host) {
hl->op->remove_host(host);
}
}
}
}
}
spin_unlock(&templates_lock);
}
int hpsb_inc_host_usage(struct hpsb_host *host)
{
struct list_head *tlh, *hlh;
struct hpsb_host_template *tmpl;
int retval = 0;
unsigned long flags;
spin_lock_irqsave(&templates_lock, flags);
list_for_each(tlh, &templates) {
tmpl = list_entry(tlh, struct hpsb_host_template, list);
list_for_each(hlh, &tmpl->hosts) {
if (host == list_entry(hlh, struct hpsb_host, list)) {
tmpl->devctl(host, MODIFY_USAGE, 1);
retval = 1;
break;
}
}
if (retval)
break;
}
spin_unlock_irqrestore(&templates_lock, flags);
return retval;
}
void hpsb_dec_host_usage(struct hpsb_host *host)
{
host->template->devctl(host, MODIFY_USAGE, 0);
}
/*
* The following function is exported for module usage. It will be called from
* the detect function of a adapter driver.
*/
struct hpsb_host *hpsb_get_host(struct hpsb_host_template *tmpl,
size_t hd_size)
{
struct hpsb_host *h;
h = vmalloc(sizeof(struct hpsb_host) + hd_size);
if (!h) return NULL;
memset(h, 0, sizeof(struct hpsb_host) + hd_size);
atomic_set(&h->generation, 0);
INIT_LIST_HEAD(&h->pending_packets);
spin_lock_init(&h->pending_pkt_lock);
sema_init(&h->tlabel_count, 64);
spin_lock_init(&h->tlabel_lock);
INIT_TQUEUE(&h->timeout_tq, (void (*)(void*))abort_timedouts, h);
h->topology_map = h->csr.topology_map + 3;
h->speed_map = (u8 *)(h->csr.speed_map + 2);
h->template = tmpl;
if (hd_size)
h->hostdata = &h->embedded_hostdata[0];
list_add_tail(&h->list, &tmpl->hosts);
return h;
}
static void free_all_hosts(struct hpsb_host_template *tmpl)
{
struct list_head *hlh, *next;
struct hpsb_host *host;
list_for_each_safe(hlh, next, &tmpl->hosts) {
host = list_entry(hlh, struct hpsb_host, list);
vfree(host);
}
}
static void init_hosts(struct hpsb_host_template *tmpl)
{
int count;
struct list_head *hlh;
struct hpsb_host *host;
count = tmpl->detect_hosts(tmpl);
list_for_each(hlh, &tmpl->hosts) {
host = list_entry(hlh, struct hpsb_host, list);
if (tmpl->initialize_host(host)) {
host->initialized = 1;
highlevel_add_host(host);
hpsb_reset_bus(host, LONG_RESET);
}
}
tmpl->number_of_hosts = count;
HPSB_INFO("detected %d %s adapter%s", count, tmpl->name,
(count != 1 ? "s" : ""));
}
static void shutdown_hosts(struct hpsb_host_template *tmpl)
{
struct list_head *hlh;
struct hpsb_host *host;
list_for_each(hlh, &tmpl->hosts) {
host = list_entry(hlh, struct hpsb_host, list);
if (host->initialized) {
highlevel_remove_host(host);
host->initialized = 0;
abort_requests(host);
tmpl->release_host(host);
while (test_bit(0, &host->timeout_tq.sync)) {
schedule();
}
}
}
free_all_hosts(tmpl);
tmpl->release_host(NULL);
tmpl->number_of_hosts = 0;
}
/*
* The following two functions are exported symbols for module usage.
*/
int hpsb_register_lowlevel(struct hpsb_host_template *tmpl)
{
INIT_LIST_HEAD(&tmpl->hosts);
tmpl->number_of_hosts = 0;
spin_lock(&templates_lock);
list_add_tail(&tmpl->list, &templates);
spin_unlock(&templates_lock);
/* PCI cards should be smart and use the PCI detection layer, and
* not this one shot deal. detect_hosts() will be obsoleted soon. */
if (tmpl->detect_hosts != NULL) {
HPSB_DEBUG("Registered %s driver, initializing now", tmpl->name);
init_hosts(tmpl);
}
return 0;
}
void hpsb_unregister_lowlevel(struct hpsb_host_template *tmpl)
{
shutdown_hosts(tmpl);
if (tmpl->number_of_hosts)
HPSB_PANIC("attempted to remove busy host template "
"of %s at address 0x%p", tmpl->name, tmpl);
else {
spin_lock(&templates_lock);
list_del(&tmpl->list);
spin_unlock(&templates_lock);
}
}
|