| 1 |
// SPDX-License-Identifier: GPL-2.0-only |
| 2 |
/* ds.c: Domain Services driver for Logical Domains |
| 3 |
* |
| 4 |
* Copyright (C) 2007, 2008 David S. Miller <[email protected]> |
| 5 |
*/ |
| 6 |
|
| 7 |
#include <linux/kernel.h> |
| 8 |
#include <linux/module.h> |
| 9 |
#include <linux/types.h> |
| 10 |
#include <linux/string.h> |
| 11 |
#include <linux/slab.h> |
| 12 |
#include <linux/sched.h> |
| 13 |
#include <linux/sched/clock.h> |
| 14 |
#include <linux/delay.h> |
| 15 |
#include <linux/mutex.h> |
| 16 |
#include <linux/kthread.h> |
| 17 |
#include <linux/reboot.h> |
| 18 |
#include <linux/cpu.h> |
| 19 |
|
| 20 |
#include <asm/hypervisor.h> |
| 21 |
#include <asm/ldc.h> |
| 22 |
#include <asm/vio.h> |
| 23 |
#include <asm/mdesc.h> |
| 24 |
#include <asm/head.h> |
| 25 |
#include <asm/irq.h> |
| 26 |
|
| 27 |
#include "kernel.h" |
| 28 |
|
| 29 |
#define DRV_MODULE_NAME "ds" |
| 30 |
#define PFX DRV_MODULE_NAME ": " |
| 31 |
#define DRV_MODULE_VERSION "1.0" |
| 32 |
#define DRV_MODULE_RELDATE "Jul 11, 2007" |
| 33 |
|
| 34 |
static char version[] = |
| 35 |
DRV_MODULE_NAME ".c:v" DRV_MODULE_VERSION " (" DRV_MODULE_RELDATE ")\n"; |
| 36 |
MODULE_AUTHOR("David S. Miller <[email protected]>"); |
| 37 |
MODULE_DESCRIPTION("Sun LDOM domain services driver"); |
| 38 |
MODULE_LICENSE("GPL"); |
| 39 |
MODULE_VERSION(DRV_MODULE_VERSION); |
| 40 |
|
| 41 |
struct ds_msg_tag { |
| 42 |
__u32 type; |
| 43 |
#define DS_INIT_REQ 0x00 |
| 44 |
#define DS_INIT_ACK 0x01 |
| 45 |
#define DS_INIT_NACK 0x02 |
| 46 |
#define DS_REG_REQ 0x03 |
| 47 |
#define DS_REG_ACK 0x04 |
| 48 |
#define DS_REG_NACK 0x05 |
| 49 |
#define DS_UNREG_REQ 0x06 |
| 50 |
#define DS_UNREG_ACK 0x07 |
| 51 |
#define DS_UNREG_NACK 0x08 |
| 52 |
#define DS_DATA 0x09 |
| 53 |
#define DS_NACK 0x0a |
| 54 |
|
| 55 |
__u32 len; |
| 56 |
}; |
| 57 |
|
| 58 |
/* Result codes */ |
| 59 |
#define DS_OK 0x00 |
| 60 |
#define DS_REG_VER_NACK 0x01 |
| 61 |
#define DS_REG_DUP 0x02 |
| 62 |
#define DS_INV_HDL 0x03 |
| 63 |
#define DS_TYPE_UNKNOWN 0x04 |
| 64 |
|
| 65 |
struct ds_version { |
| 66 |
__u16 major; |
| 67 |
__u16 minor; |
| 68 |
}; |
| 69 |
|
| 70 |
struct ds_ver_req { |
| 71 |
struct ds_msg_tag tag; |
| 72 |
struct ds_version ver; |
| 73 |
}; |
| 74 |
|
| 75 |
struct ds_ver_ack { |
| 76 |
struct ds_msg_tag tag; |
| 77 |
__u16 minor; |
| 78 |
}; |
| 79 |
|
| 80 |
struct ds_ver_nack { |
| 81 |
struct ds_msg_tag tag; |
| 82 |
__u16 major; |
| 83 |
}; |
| 84 |
|
| 85 |
struct ds_reg_req { |
| 86 |
struct ds_msg_tag tag; |
| 87 |
__u64 handle; |
| 88 |
__u16 major; |
| 89 |
__u16 minor; |
| 90 |
char svc_id[]; |
| 91 |
}; |
| 92 |
|
| 93 |
struct ds_reg_ack { |
| 94 |
struct ds_msg_tag tag; |
| 95 |
__u64 handle; |
| 96 |
__u16 minor; |
| 97 |
}; |
| 98 |
|
| 99 |
struct ds_reg_nack { |
| 100 |
struct ds_msg_tag tag; |
| 101 |
__u64 handle; |
| 102 |
__u16 major; |
| 103 |
}; |
| 104 |
|
| 105 |
struct ds_unreg_req { |
| 106 |
struct ds_msg_tag tag; |
| 107 |
__u64 handle; |
| 108 |
}; |
| 109 |
|
| 110 |
struct ds_unreg_ack { |
| 111 |
struct ds_msg_tag tag; |
| 112 |
__u64 handle; |
| 113 |
}; |
| 114 |
|
| 115 |
struct ds_unreg_nack { |
| 116 |
struct ds_msg_tag tag; |
| 117 |
__u64 handle; |
| 118 |
}; |
| 119 |
|
| 120 |
struct ds_data { |
| 121 |
struct ds_msg_tag tag; |
| 122 |
__u64 handle; |
| 123 |
}; |
| 124 |
|
| 125 |
struct ds_data_nack { |
| 126 |
struct ds_msg_tag tag; |
| 127 |
__u64 handle; |
| 128 |
__u64 result; |
| 129 |
}; |
| 130 |
|
| 131 |
struct ds_info; |
| 132 |
struct ds_cap_state { |
| 133 |
__u64 handle; |
| 134 |
|
| 135 |
void (*data)(struct ds_info *dp, |
| 136 |
struct ds_cap_state *cp, |
| 137 |
void *buf, int len); |
| 138 |
|
| 139 |
const char *service_id; |
| 140 |
|
| 141 |
u8 state; |
| 142 |
#define CAP_STATE_UNKNOWN 0x00 |
| 143 |
#define CAP_STATE_REG_SENT 0x01 |
| 144 |
#define CAP_STATE_REGISTERED 0x02 |
| 145 |
}; |
| 146 |
|
| 147 |
static void md_update_data(struct ds_info *dp, struct ds_cap_state *cp, |
| 148 |
void *buf, int len); |
| 149 |
static void domain_shutdown_data(struct ds_info *dp, |
| 150 |
struct ds_cap_state *cp, |
| 151 |
void *buf, int len); |
| 152 |
static void domain_panic_data(struct ds_info *dp, |
| 153 |
struct ds_cap_state *cp, |
| 154 |
void *buf, int len); |
| 155 |
#ifdef CONFIG_HOTPLUG_CPU |
| 156 |
static void dr_cpu_data(struct ds_info *dp, |
| 157 |
struct ds_cap_state *cp, |
| 158 |
void *buf, int len); |
| 159 |
#endif |
| 160 |
static void ds_pri_data(struct ds_info *dp, |
| 161 |
struct ds_cap_state *cp, |
| 162 |
void *buf, int len); |
| 163 |
static void ds_var_data(struct ds_info *dp, |
| 164 |
struct ds_cap_state *cp, |
| 165 |
void *buf, int len); |
| 166 |
|
| 167 |
static struct ds_cap_state ds_states_template[] = { |
| 168 |
{ |
| 169 |
.service_id = "md-update", |
| 170 |
.data = md_update_data, |
| 171 |
}, |
| 172 |
{ |
| 173 |
.service_id = "domain-shutdown", |
| 174 |
.data = domain_shutdown_data, |
| 175 |
}, |
| 176 |
{ |
| 177 |
.service_id = "domain-panic", |
| 178 |
.data = domain_panic_data, |
| 179 |
}, |
| 180 |
#ifdef CONFIG_HOTPLUG_CPU |
| 181 |
{ |
| 182 |
.service_id = "dr-cpu", |
| 183 |
.data = dr_cpu_data, |
| 184 |
}, |
| 185 |
#endif |
| 186 |
{ |
| 187 |
.service_id = "pri", |
| 188 |
.data = ds_pri_data, |
| 189 |
}, |
| 190 |
{ |
| 191 |
.service_id = "var-config", |
| 192 |
.data = ds_var_data, |
| 193 |
}, |
| 194 |
{ |
| 195 |
.service_id = "var-config-backup", |
| 196 |
.data = ds_var_data, |
| 197 |
}, |
| 198 |
}; |
| 199 |
|
| 200 |
static DEFINE_SPINLOCK(ds_lock); |
| 201 |
|
| 202 |
struct ds_info { |
| 203 |
struct ldc_channel *lp; |
| 204 |
u8 hs_state; |
| 205 |
#define DS_HS_START 0x01 |
| 206 |
#define DS_HS_DONE 0x02 |
| 207 |
|
| 208 |
u64 id; |
| 209 |
|
| 210 |
void *rcv_buf; |
| 211 |
int rcv_buf_len; |
| 212 |
|
| 213 |
struct ds_cap_state *ds_states; |
| 214 |
int num_ds_states; |
| 215 |
|
| 216 |
struct ds_info *next; |
| 217 |
}; |
| 218 |
|
| 219 |
static struct ds_info *ds_info_list; |
| 220 |
|
| 221 |
static struct ds_cap_state *find_cap(struct ds_info *dp, u64 handle) |
| 222 |
{ |
| 223 |
unsigned int index = handle >> 32; |
| 224 |
|
| 225 |
if (index >= dp->num_ds_states) |
| 226 |
return NULL; |
| 227 |
return &dp->ds_states[index]; |
| 228 |
} |
| 229 |
|
| 230 |
static struct ds_cap_state *find_cap_by_string(struct ds_info *dp, |
| 231 |
const char *name) |
| 232 |
{ |
| 233 |
int i; |
| 234 |
|
| 235 |
for (i = 0; i < dp->num_ds_states; i++) { |
| 236 |
if (strcmp(dp->ds_states[i].service_id, name)) |
| 237 |
continue; |
| 238 |
|
| 239 |
return &dp->ds_states[i]; |
| 240 |
} |
| 241 |
return NULL; |
| 242 |
} |
| 243 |
|
| 244 |
static int __ds_send(struct ldc_channel *lp, void *data, int len) |
| 245 |
{ |
| 246 |
int err, limit = 1000; |
| 247 |
|
| 248 |
err = -EINVAL; |
| 249 |
while (limit-- > 0) { |
| 250 |
err = ldc_write(lp, data, len); |
| 251 |
if (!err || (err != -EAGAIN)) |
| 252 |
break; |
| 253 |
udelay(1); |
| 254 |
} |
| 255 |
|
| 256 |
return err; |
| 257 |
} |
| 258 |
|
| 259 |
static int ds_send(struct ldc_channel *lp, void *data, int len) |
| 260 |
{ |
| 261 |
unsigned long flags; |
| 262 |
int err; |
| 263 |
|
| 264 |
spin_lock_irqsave(&ds_lock, flags); |
| 265 |
err = __ds_send(lp, data, len); |
| 266 |
spin_unlock_irqrestore(&ds_lock, flags); |
| 267 |
|
| 268 |
return err; |
| 269 |
} |
| 270 |
|
| 271 |
struct ds_md_update_req { |
| 272 |
__u64 req_num; |
| 273 |
}; |
| 274 |
|
| 275 |
struct ds_md_update_res { |
| 276 |
__u64 req_num; |
| 277 |
__u32 result; |
| 278 |
}; |
| 279 |
|
| 280 |
static void md_update_data(struct ds_info *dp, |
| 281 |
struct ds_cap_state *cp, |
| 282 |
void *buf, int len) |
| 283 |
{ |
| 284 |
struct ldc_channel *lp = dp->lp; |
| 285 |
struct ds_data *dpkt = buf; |
| 286 |
struct ds_md_update_req *rp; |
| 287 |
struct { |
| 288 |
struct ds_data data; |
| 289 |
struct ds_md_update_res res; |
| 290 |
} pkt; |
| 291 |
|
| 292 |
rp = (struct ds_md_update_req *) (dpkt + 1); |
| 293 |
|
| 294 |
printk(KERN_INFO "ds-%llu: Machine description update.\n", dp->id); |
| 295 |
|
| 296 |
mdesc_update(); |
| 297 |
|
| 298 |
memset(&pkt, 0, sizeof(pkt)); |
| 299 |
pkt.data.tag.type = DS_DATA; |
| 300 |
pkt.data.tag.len = sizeof(pkt) - sizeof(struct ds_msg_tag); |
| 301 |
pkt.data.handle = cp->handle; |
| 302 |
pkt.res.req_num = rp->req_num; |
| 303 |
pkt.res.result = DS_OK; |
| 304 |
|
| 305 |
ds_send(lp, &pkt, sizeof(pkt)); |
| 306 |
} |
| 307 |
|
| 308 |
struct ds_shutdown_req { |
| 309 |
__u64 req_num; |
| 310 |
__u32 ms_delay; |
| 311 |
}; |
| 312 |
|
| 313 |
struct ds_shutdown_res { |
| 314 |
__u64 req_num; |
| 315 |
__u32 result; |
| 316 |
char reason[1]; |
| 317 |
}; |
| 318 |
|
| 319 |
static void domain_shutdown_data(struct ds_info *dp, |
| 320 |
struct ds_cap_state *cp, |
| 321 |
void *buf, int len) |
| 322 |
{ |
| 323 |
struct ldc_channel *lp = dp->lp; |
| 324 |
struct ds_data *dpkt = buf; |
| 325 |
struct ds_shutdown_req *rp; |
| 326 |
struct { |
| 327 |
struct ds_data data; |
| 328 |
struct ds_shutdown_res res; |
| 329 |
} pkt; |
| 330 |
|
| 331 |
rp = (struct ds_shutdown_req *) (dpkt + 1); |
| 332 |
|
| 333 |
printk(KERN_ALERT "ds-%llu: Shutdown request from " |
| 334 |
"LDOM manager received.\n", dp->id); |
| 335 |
|
| 336 |
memset(&pkt, 0, sizeof(pkt)); |
| 337 |
pkt.data.tag.type = DS_DATA; |
| 338 |
pkt.data.tag.len = sizeof(pkt) - sizeof(struct ds_msg_tag); |
| 339 |
pkt.data.handle = cp->handle; |
| 340 |
pkt.res.req_num = rp->req_num; |
| 341 |
pkt.res.result = DS_OK; |
| 342 |
pkt.res.reason[0] = 0; |
| 343 |
|
| 344 |
ds_send(lp, &pkt, sizeof(pkt)); |
| 345 |
|
| 346 |
orderly_poweroff(true); |
| 347 |
} |
| 348 |
|
| 349 |
struct ds_panic_req { |
| 350 |
__u64 req_num; |
| 351 |
}; |
| 352 |
|
| 353 |
struct ds_panic_res { |
| 354 |
__u64 req_num; |
| 355 |
__u32 result; |
| 356 |
char reason[1]; |
| 357 |
}; |
| 358 |
|
| 359 |
static void domain_panic_data(struct ds_info *dp, |
| 360 |
struct ds_cap_state *cp, |
| 361 |
void *buf, int len) |
| 362 |
{ |
| 363 |
struct ldc_channel *lp = dp->lp; |
| 364 |
struct ds_data *dpkt = buf; |
| 365 |
struct ds_panic_req *rp; |
| 366 |
struct { |
| 367 |
struct ds_data data; |
| 368 |
struct ds_panic_res res; |
| 369 |
} pkt; |
| 370 |
|
| 371 |
rp = (struct ds_panic_req *) (dpkt + 1); |
| 372 |
|
| 373 |
printk(KERN_ALERT "ds-%llu: Panic request from " |
| 374 |
"LDOM manager received.\n", dp->id); |
| 375 |
|
| 376 |
memset(&pkt, 0, sizeof(pkt)); |
| 377 |
pkt.data.tag.type = DS_DATA; |
| 378 |
pkt.data.tag.len = sizeof(pkt) - sizeof(struct ds_msg_tag); |
| 379 |
pkt.data.handle = cp->handle; |
| 380 |
pkt.res.req_num = rp->req_num; |
| 381 |
pkt.res.result = DS_OK; |
| 382 |
pkt.res.reason[0] = 0; |
| 383 |
|
| 384 |
ds_send(lp, &pkt, sizeof(pkt)); |
| 385 |
|
| 386 |
panic("PANIC requested by LDOM manager."); |
| 387 |
} |
| 388 |
|
| 389 |
#ifdef CONFIG_HOTPLUG_CPU |
| 390 |
struct dr_cpu_tag { |
| 391 |
__u64 req_num; |
| 392 |
__u32 type; |
| 393 |
#define DR_CPU_CONFIGURE 0x43 |
| 394 |
#define DR_CPU_UNCONFIGURE 0x55 |
| 395 |
#define DR_CPU_FORCE_UNCONFIGURE 0x46 |
| 396 |
#define DR_CPU_STATUS 0x53 |
| 397 |
|
| 398 |
/* Responses */ |
| 399 |
#define DR_CPU_OK 0x6f |
| 400 |
#define DR_CPU_ERROR 0x65 |
| 401 |
|
| 402 |
__u32 num_records; |
| 403 |
}; |
| 404 |
|
| 405 |
struct dr_cpu_resp_entry { |
| 406 |
__u32 cpu; |
| 407 |
__u32 result; |
| 408 |
#define DR_CPU_RES_OK 0x00 |
| 409 |
#define DR_CPU_RES_FAILURE 0x01 |
| 410 |
#define DR_CPU_RES_BLOCKED 0x02 |
| 411 |
#define DR_CPU_RES_CPU_NOT_RESPONDING 0x03 |
| 412 |
#define DR_CPU_RES_NOT_IN_MD 0x04 |
| 413 |
|
| 414 |
__u32 stat; |
| 415 |
#define DR_CPU_STAT_NOT_PRESENT 0x00 |
| 416 |
#define DR_CPU_STAT_UNCONFIGURED 0x01 |
| 417 |
#define DR_CPU_STAT_CONFIGURED 0x02 |
| 418 |
|
| 419 |
__u32 str_off; |
| 420 |
}; |
| 421 |
|
| 422 |
static void __dr_cpu_send_error(struct ds_info *dp, |
| 423 |
struct ds_cap_state *cp, |
| 424 |
struct ds_data *data) |
| 425 |
{ |
| 426 |
struct dr_cpu_tag *tag = (struct dr_cpu_tag *) (data + 1); |
| 427 |
struct { |
| 428 |
struct ds_data data; |
| 429 |
struct dr_cpu_tag tag; |
| 430 |
} pkt; |
| 431 |
int msg_len; |
| 432 |
|
| 433 |
memset(&pkt, 0, sizeof(pkt)); |
| 434 |
pkt.data.tag.type = DS_DATA; |
| 435 |
pkt.data.handle = cp->handle; |
| 436 |
pkt.tag.req_num = tag->req_num; |
| 437 |
pkt.tag.type = DR_CPU_ERROR; |
| 438 |
pkt.tag.num_records = 0; |
| 439 |
|
| 440 |
msg_len = (sizeof(struct ds_data) + |
| 441 |
sizeof(struct dr_cpu_tag)); |
| 442 |
|
| 443 |
pkt.data.tag.len = msg_len - sizeof(struct ds_msg_tag); |
| 444 |
|
| 445 |
__ds_send(dp->lp, &pkt, msg_len); |
| 446 |
} |
| 447 |
|
| 448 |
static void dr_cpu_send_error(struct ds_info *dp, |
| 449 |
struct ds_cap_state *cp, |
| 450 |
struct ds_data *data) |
| 451 |
{ |
| 452 |
unsigned long flags; |
| 453 |
|
| 454 |
spin_lock_irqsave(&ds_lock, flags); |
| 455 |
__dr_cpu_send_error(dp, cp, data); |
| 456 |
spin_unlock_irqrestore(&ds_lock, flags); |
| 457 |
} |
| 458 |
|
| 459 |
#define CPU_SENTINEL 0xffffffff |
| 460 |
|
| 461 |
static void purge_dups(u32 *list, u32 num_ents) |
| 462 |
{ |
| 463 |
unsigned int i; |
| 464 |
|
| 465 |
for (i = 0; i < num_ents; i++) { |
| 466 |
u32 cpu = list[i]; |
| 467 |
unsigned int j; |
| 468 |
|
| 469 |
if (cpu == CPU_SENTINEL) |
| 470 |
continue; |
| 471 |
|
| 472 |
for (j = i + 1; j < num_ents; j++) { |
| 473 |
if (list[j] == cpu) |
| 474 |
list[j] = CPU_SENTINEL; |
| 475 |
} |
| 476 |
} |
| 477 |
} |
| 478 |
|
| 479 |
static int dr_cpu_size_response(int ncpus) |
| 480 |
{ |
| 481 |
return (sizeof(struct ds_data) + |
| 482 |
sizeof(struct dr_cpu_tag) + |
| 483 |
(sizeof(struct dr_cpu_resp_entry) * ncpus)); |
| 484 |
} |
| 485 |
|
| 486 |
static void dr_cpu_init_response(struct ds_data *resp, u64 req_num, |
| 487 |
u64 handle, int resp_len, int ncpus, |
| 488 |
cpumask_t *mask, u32 default_stat) |
| 489 |
{ |
| 490 |
struct dr_cpu_resp_entry *ent; |
| 491 |
struct dr_cpu_tag *tag; |
| 492 |
int i, cpu; |
| 493 |
|
| 494 |
tag = (struct dr_cpu_tag *) (resp + 1); |
| 495 |
ent = (struct dr_cpu_resp_entry *) (tag + 1); |
| 496 |
|
| 497 |
resp->tag.type = DS_DATA; |
| 498 |
resp->tag.len = resp_len - sizeof(struct ds_msg_tag); |
| 499 |
resp->handle = handle; |
| 500 |
tag->req_num = req_num; |
| 501 |
tag->type = DR_CPU_OK; |
| 502 |
tag->num_records = ncpus; |
| 503 |
|
| 504 |
i = 0; |
| 505 |
for_each_cpu(cpu, mask) { |
| 506 |
ent[i].cpu = cpu; |
| 507 |
ent[i].result = DR_CPU_RES_OK; |
| 508 |
ent[i].stat = default_stat; |
| 509 |
i++; |
| 510 |
} |
| 511 |
BUG_ON(i != ncpus); |
| 512 |
} |
| 513 |
|
| 514 |
static void dr_cpu_mark(struct ds_data *resp, int cpu, int ncpus, |
| 515 |
u32 res, u32 stat) |
| 516 |
{ |
| 517 |
struct dr_cpu_resp_entry *ent; |
| 518 |
struct dr_cpu_tag *tag; |
| 519 |
int i; |
| 520 |
|
| 521 |
tag = (struct dr_cpu_tag *) (resp + 1); |
| 522 |
ent = (struct dr_cpu_resp_entry *) (tag + 1); |
| 523 |
|
| 524 |
for (i = 0; i < ncpus; i++) { |
| 525 |
if (ent[i].cpu != cpu) |
| 526 |
continue; |
| 527 |
ent[i].result = res; |
| 528 |
ent[i].stat = stat; |
| 529 |
break; |
| 530 |
} |
| 531 |
} |
| 532 |
|
| 533 |
static int dr_cpu_configure(struct ds_info *dp, struct ds_cap_state *cp, |
| 534 |
u64 req_num, cpumask_t *mask) |
| 535 |
{ |
| 536 |
struct ds_data *resp; |
| 537 |
int resp_len, ncpus, cpu; |
| 538 |
unsigned long flags; |
| 539 |
|
| 540 |
ncpus = cpumask_weight(mask); |
| 541 |
resp_len = dr_cpu_size_response(ncpus); |
| 542 |
resp = kzalloc(resp_len, GFP_KERNEL); |
| 543 |
if (!resp) |
| 544 |
return -ENOMEM; |
| 545 |
|
| 546 |
dr_cpu_init_response(resp, req_num, cp->handle, |
| 547 |
resp_len, ncpus, mask, |
| 548 |
DR_CPU_STAT_CONFIGURED); |
| 549 |
|
| 550 |
mdesc_populate_present_mask(mask); |
| 551 |
mdesc_fill_in_cpu_data(mask); |
| 552 |
|
| 553 |
for_each_cpu(cpu, mask) { |
| 554 |
int err; |
| 555 |
|
| 556 |
printk(KERN_INFO "ds-%llu: Starting cpu %d...\n", |
| 557 |
dp->id, cpu); |
| 558 |
err = add_cpu(cpu); |
| 559 |
if (err) { |
| 560 |
__u32 res = DR_CPU_RES_FAILURE; |
| 561 |
__u32 stat = DR_CPU_STAT_UNCONFIGURED; |
| 562 |
|
| 563 |
if (!cpu_present(cpu)) { |
| 564 |
/* CPU not present in MD */ |
| 565 |
res = DR_CPU_RES_NOT_IN_MD; |
| 566 |
stat = DR_CPU_STAT_NOT_PRESENT; |
| 567 |
} else if (err == -ENODEV) { |
| 568 |
/* CPU did not call in successfully */ |
| 569 |
res = DR_CPU_RES_CPU_NOT_RESPONDING; |
| 570 |
} |
| 571 |
|
| 572 |
printk(KERN_INFO "ds-%llu: CPU startup failed err=%d\n", |
| 573 |
dp->id, err); |
| 574 |
dr_cpu_mark(resp, cpu, ncpus, res, stat); |
| 575 |
} |
| 576 |
} |
| 577 |
|
| 578 |
spin_lock_irqsave(&ds_lock, flags); |
| 579 |
__ds_send(dp->lp, resp, resp_len); |
| 580 |
spin_unlock_irqrestore(&ds_lock, flags); |
| 581 |
|
| 582 |
kfree(resp); |
| 583 |
|
| 584 |
/* Redistribute IRQs, taking into account the new cpus. */ |
| 585 |
fixup_irqs(); |
| 586 |
|
| 587 |
return 0; |
| 588 |
} |
| 589 |
|
| 590 |
static int dr_cpu_unconfigure(struct ds_info *dp, |
| 591 |
struct ds_cap_state *cp, |
| 592 |
u64 req_num, |
| 593 |
cpumask_t *mask) |
| 594 |
{ |
| 595 |
struct ds_data *resp; |
| 596 |
int resp_len, ncpus, cpu; |
| 597 |
unsigned long flags; |
| 598 |
|
| 599 |
ncpus = cpumask_weight(mask); |
| 600 |
resp_len = dr_cpu_size_response(ncpus); |
| 601 |
resp = kzalloc(resp_len, GFP_KERNEL); |
| 602 |
if (!resp) |
| 603 |
return -ENOMEM; |
| 604 |
|
| 605 |
dr_cpu_init_response(resp, req_num, cp->handle, |
| 606 |
resp_len, ncpus, mask, |
| 607 |
DR_CPU_STAT_UNCONFIGURED); |
| 608 |
|
| 609 |
for_each_cpu(cpu, mask) { |
| 610 |
int err; |
| 611 |
|
| 612 |
printk(KERN_INFO "ds-%llu: Shutting down cpu %d...\n", |
| 613 |
dp->id, cpu); |
| 614 |
err = remove_cpu(cpu); |
| 615 |
if (err) |
| 616 |
dr_cpu_mark(resp, cpu, ncpus, |
| 617 |
DR_CPU_RES_FAILURE, |
| 618 |
DR_CPU_STAT_CONFIGURED); |
| 619 |
} |
| 620 |
|
| 621 |
spin_lock_irqsave(&ds_lock, flags); |
| 622 |
__ds_send(dp->lp, resp, resp_len); |
| 623 |
spin_unlock_irqrestore(&ds_lock, flags); |
| 624 |
|
| 625 |
kfree(resp); |
| 626 |
|
| 627 |
return 0; |
| 628 |
} |
| 629 |
|
| 630 |
static void dr_cpu_data(struct ds_info *dp, struct ds_cap_state *cp, void *buf, |
| 631 |
int len) |
| 632 |
{ |
| 633 |
struct ds_data *data = buf; |
| 634 |
struct dr_cpu_tag *tag = (struct dr_cpu_tag *) (data + 1); |
| 635 |
u32 *cpu_list = (u32 *) (tag + 1); |
| 636 |
u64 req_num = tag->req_num; |
| 637 |
cpumask_t mask; |
| 638 |
unsigned int i; |
| 639 |
int err; |
| 640 |
|
| 641 |
switch (tag->type) { |
| 642 |
case DR_CPU_CONFIGURE: |
| 643 |
case DR_CPU_UNCONFIGURE: |
| 644 |
case DR_CPU_FORCE_UNCONFIGURE: |
| 645 |
break; |
| 646 |
|
| 647 |
default: |
| 648 |
dr_cpu_send_error(dp, cp, data); |
| 649 |
return; |
| 650 |
} |
| 651 |
|
| 652 |
purge_dups(cpu_list, tag->num_records); |
| 653 |
|
| 654 |
cpumask_clear(&mask); |
| 655 |
for (i = 0; i < tag->num_records; i++) { |
| 656 |
if (cpu_list[i] == CPU_SENTINEL) |
| 657 |
continue; |
| 658 |
|
| 659 |
if (cpu_list[i] < nr_cpu_ids) |
| 660 |
cpumask_set_cpu(cpu_list[i], &mask); |
| 661 |
} |
| 662 |
|
| 663 |
if (tag->type == DR_CPU_CONFIGURE) |
| 664 |
err = dr_cpu_configure(dp, cp, req_num, &mask); |
| 665 |
else |
| 666 |
err = dr_cpu_unconfigure(dp, cp, req_num, &mask); |
| 667 |
|
| 668 |
if (err) |
| 669 |
dr_cpu_send_error(dp, cp, data); |
| 670 |
} |
| 671 |
#endif /* CONFIG_HOTPLUG_CPU */ |
| 672 |
|
| 673 |
struct ds_pri_msg { |
| 674 |
__u64 req_num; |
| 675 |
__u64 type; |
| 676 |
#define DS_PRI_REQUEST 0x00 |
| 677 |
#define DS_PRI_DATA 0x01 |
| 678 |
#define DS_PRI_UPDATE 0x02 |
| 679 |
}; |
| 680 |
|
| 681 |
static void ds_pri_data(struct ds_info *dp, |
| 682 |
struct ds_cap_state *cp, |
| 683 |
void *buf, int len) |
| 684 |
{ |
| 685 |
struct ds_data *dpkt = buf; |
| 686 |
struct ds_pri_msg *rp; |
| 687 |
|
| 688 |
rp = (struct ds_pri_msg *) (dpkt + 1); |
| 689 |
|
| 690 |
printk(KERN_INFO "ds-%llu: PRI REQ [%llx:%llx], len=%d\n", |
| 691 |
dp->id, rp->req_num, rp->type, len); |
| 692 |
} |
| 693 |
|
| 694 |
struct ds_var_hdr { |
| 695 |
__u32 type; |
| 696 |
#define DS_VAR_SET_REQ 0x00 |
| 697 |
#define DS_VAR_DELETE_REQ 0x01 |
| 698 |
#define DS_VAR_SET_RESP 0x02 |
| 699 |
#define DS_VAR_DELETE_RESP 0x03 |
| 700 |
}; |
| 701 |
|
| 702 |
struct ds_var_set_msg { |
| 703 |
struct ds_var_hdr hdr; |
| 704 |
char name_and_value[]; |
| 705 |
}; |
| 706 |
|
| 707 |
struct ds_var_delete_msg { |
| 708 |
struct ds_var_hdr hdr; |
| 709 |
char name[]; |
| 710 |
}; |
| 711 |
|
| 712 |
struct ds_var_resp { |
| 713 |
struct ds_var_hdr hdr; |
| 714 |
__u32 result; |
| 715 |
#define DS_VAR_SUCCESS 0x00 |
| 716 |
#define DS_VAR_NO_SPACE 0x01 |
| 717 |
#define DS_VAR_INVALID_VAR 0x02 |
| 718 |
#define DS_VAR_INVALID_VAL 0x03 |
| 719 |
#define DS_VAR_NOT_PRESENT 0x04 |
| 720 |
}; |
| 721 |
|
| 722 |
static DEFINE_MUTEX(ds_var_mutex); |
| 723 |
static int ds_var_doorbell; |
| 724 |
static int ds_var_response; |
| 725 |
|
| 726 |
static void ds_var_data(struct ds_info *dp, |
| 727 |
struct ds_cap_state *cp, |
| 728 |
void *buf, int len) |
| 729 |
{ |
| 730 |
struct ds_data *dpkt = buf; |
| 731 |
struct ds_var_resp *rp; |
| 732 |
|
| 733 |
rp = (struct ds_var_resp *) (dpkt + 1); |
| 734 |
|
| 735 |
if (rp->hdr.type != DS_VAR_SET_RESP && |
| 736 |
rp->hdr.type != DS_VAR_DELETE_RESP) |
| 737 |
return; |
| 738 |
|
| 739 |
ds_var_response = rp->result; |
| 740 |
wmb(); |
| 741 |
ds_var_doorbell = 1; |
| 742 |
} |
| 743 |
|
| 744 |
void ldom_set_var(const char *var, const char *value) |
| 745 |
{ |
| 746 |
struct ds_cap_state *cp; |
| 747 |
struct ds_info *dp; |
| 748 |
unsigned long flags; |
| 749 |
|
| 750 |
spin_lock_irqsave(&ds_lock, flags); |
| 751 |
cp = NULL; |
| 752 |
for (dp = ds_info_list; dp; dp = dp->next) { |
| 753 |
struct ds_cap_state *tmp; |
| 754 |
|
| 755 |
tmp = find_cap_by_string(dp, "var-config"); |
| 756 |
if (tmp && tmp->state == CAP_STATE_REGISTERED) { |
| 757 |
cp = tmp; |
| 758 |
break; |
| 759 |
} |
| 760 |
} |
| 761 |
if (!cp) { |
| 762 |
for (dp = ds_info_list; dp; dp = dp->next) { |
| 763 |
struct ds_cap_state *tmp; |
| 764 |
|
| 765 |
tmp = find_cap_by_string(dp, "var-config-backup"); |
| 766 |
if (tmp && tmp->state == CAP_STATE_REGISTERED) { |
| 767 |
cp = tmp; |
| 768 |
break; |
| 769 |
} |
| 770 |
} |
| 771 |
} |
| 772 |
spin_unlock_irqrestore(&ds_lock, flags); |
| 773 |
|
| 774 |
if (cp) { |
| 775 |
union { |
| 776 |
struct { |
| 777 |
struct ds_data data; |
| 778 |
struct ds_var_set_msg msg; |
| 779 |
} header; |
| 780 |
char all[512]; |
| 781 |
} pkt; |
| 782 |
char *base, *p; |
| 783 |
int msg_len, loops; |
| 784 |
size_t var_len, value_len; |
| 785 |
|
| 786 |
var_len = strlen(var) + 1; |
| 787 |
value_len = strlen(value) + 1; |
| 788 |
|
| 789 |
if (var_len + value_len > sizeof(pkt) - sizeof(pkt.header)) { |
| 790 |
pr_err(PFX |
| 791 |
"contents length: %zu, which more than max: %lu," |
| 792 |
"so could not set (%s) variable to (%s).\n", |
| 793 |
var_len + value_len, |
| 794 |
sizeof(pkt) - sizeof(pkt.header), var, value); |
| 795 |
return; |
| 796 |
} |
| 797 |
|
| 798 |
memset(&pkt, 0, sizeof(pkt)); |
| 799 |
pkt.header.data.tag.type = DS_DATA; |
| 800 |
pkt.header.data.handle = cp->handle; |
| 801 |
pkt.header.msg.hdr.type = DS_VAR_SET_REQ; |
| 802 |
base = p = &pkt.header.msg.name_and_value[0]; |
| 803 |
strscpy(p, var, var_len); |
| 804 |
p += var_len; |
| 805 |
strscpy(p, value, value_len); |
| 806 |
p += value_len; |
| 807 |
|
| 808 |
msg_len = (sizeof(struct ds_data) + |
| 809 |
sizeof(struct ds_var_set_msg) + |
| 810 |
(p - base)); |
| 811 |
msg_len = (msg_len + 3) & ~3; |
| 812 |
pkt.header.data.tag.len = msg_len - sizeof(struct ds_msg_tag); |
| 813 |
|
| 814 |
mutex_lock(&ds_var_mutex); |
| 815 |
|
| 816 |
spin_lock_irqsave(&ds_lock, flags); |
| 817 |
ds_var_doorbell = 0; |
| 818 |
ds_var_response = -1; |
| 819 |
|
| 820 |
__ds_send(dp->lp, &pkt, msg_len); |
| 821 |
spin_unlock_irqrestore(&ds_lock, flags); |
| 822 |
|
| 823 |
loops = 1000; |
| 824 |
while (ds_var_doorbell == 0) { |
| 825 |
if (loops-- < 0) |
| 826 |
break; |
| 827 |
barrier(); |
| 828 |
udelay(100); |
| 829 |
} |
| 830 |
|
| 831 |
mutex_unlock(&ds_var_mutex); |
| 832 |
|
| 833 |
if (ds_var_doorbell == 0 || |
| 834 |
ds_var_response != DS_VAR_SUCCESS) |
| 835 |
printk(KERN_ERR "ds-%llu: var-config [%s:%s] " |
| 836 |
"failed, response(%d).\n", |
| 837 |
dp->id, var, value, |
| 838 |
ds_var_response); |
| 839 |
} else { |
| 840 |
printk(KERN_ERR PFX "var-config not registered so " |
| 841 |
"could not set (%s) variable to (%s).\n", |
| 842 |
var, value); |
| 843 |
} |
| 844 |
} |
| 845 |
|
| 846 |
static char full_boot_str[256] __attribute__((aligned(32))); |
| 847 |
static int reboot_data_supported; |
| 848 |
|
| 849 |
void ldom_reboot(const char *boot_command) |
| 850 |
{ |
| 851 |
/* Don't bother with any of this if the boot_command |
| 852 |
* is empty. |
| 853 |
*/ |
| 854 |
if (boot_command && strlen(boot_command)) { |
| 855 |
unsigned long len; |
| 856 |
|
| 857 |
snprintf(full_boot_str, sizeof(full_boot_str), "boot %s", |
| 858 |
boot_command); |
| 859 |
len = strlen(full_boot_str); |
| 860 |
|
| 861 |
if (reboot_data_supported) { |
| 862 |
unsigned long ra = kimage_addr_to_ra(full_boot_str); |
| 863 |
unsigned long hv_ret; |
| 864 |
|
| 865 |
hv_ret = sun4v_reboot_data_set(ra, len); |
| 866 |
if (hv_ret != HV_EOK) |
| 867 |
pr_err("SUN4V: Unable to set reboot data " |
| 868 |
"hv_ret=%lu\n", hv_ret); |
| 869 |
} else { |
| 870 |
ldom_set_var("reboot-command", full_boot_str); |
| 871 |
} |
| 872 |
} |
| 873 |
sun4v_mach_sir(); |
| 874 |
} |
| 875 |
|
| 876 |
void ldom_power_off(void) |
| 877 |
{ |
| 878 |
sun4v_mach_exit(0); |
| 879 |
} |
| 880 |
|
| 881 |
static void ds_conn_reset(struct ds_info *dp) |
| 882 |
{ |
| 883 |
printk(KERN_ERR "ds-%llu: ds_conn_reset() from %ps\n", |
| 884 |
dp->id, __builtin_return_address(0)); |
| 885 |
} |
| 886 |
|
| 887 |
static int register_services(struct ds_info *dp) |
| 888 |
{ |
| 889 |
struct ldc_channel *lp = dp->lp; |
| 890 |
int i; |
| 891 |
|
| 892 |
for (i = 0; i < dp->num_ds_states; i++) { |
| 893 |
struct { |
| 894 |
struct ds_reg_req req; |
| 895 |
u8 id_buf[256]; |
| 896 |
} pbuf; |
| 897 |
struct ds_cap_state *cp = &dp->ds_states[i]; |
| 898 |
int err, msg_len; |
| 899 |
u64 new_count; |
| 900 |
|
| 901 |
if (cp->state == CAP_STATE_REGISTERED) |
| 902 |
continue; |
| 903 |
|
| 904 |
new_count = sched_clock() & 0xffffffff; |
| 905 |
cp->handle = ((u64) i << 32) | new_count; |
| 906 |
|
| 907 |
msg_len = (sizeof(struct ds_reg_req) + |
| 908 |
strlen(cp->service_id)); |
| 909 |
|
| 910 |
memset(&pbuf, 0, sizeof(pbuf)); |
| 911 |
pbuf.req.tag.type = DS_REG_REQ; |
| 912 |
pbuf.req.tag.len = (msg_len - sizeof(struct ds_msg_tag)); |
| 913 |
pbuf.req.handle = cp->handle; |
| 914 |
pbuf.req.major = 1; |
| 915 |
pbuf.req.minor = 0; |
| 916 |
strscpy(pbuf.id_buf, cp->service_id); |
| 917 |
|
| 918 |
err = __ds_send(lp, &pbuf, msg_len); |
| 919 |
if (err > 0) |
| 920 |
cp->state = CAP_STATE_REG_SENT; |
| 921 |
} |
| 922 |
return 0; |
| 923 |
} |
| 924 |
|
| 925 |
static int ds_handshake(struct ds_info *dp, struct ds_msg_tag *pkt) |
| 926 |
{ |
| 927 |
|
| 928 |
if (dp->hs_state == DS_HS_START) { |
| 929 |
if (pkt->type != DS_INIT_ACK) |
| 930 |
goto conn_reset; |
| 931 |
|
| 932 |
dp->hs_state = DS_HS_DONE; |
| 933 |
|
| 934 |
return register_services(dp); |
| 935 |
} |
| 936 |
|
| 937 |
if (dp->hs_state != DS_HS_DONE) |
| 938 |
goto conn_reset; |
| 939 |
|
| 940 |
if (pkt->type == DS_REG_ACK) { |
| 941 |
struct ds_reg_ack *ap = (struct ds_reg_ack *) pkt; |
| 942 |
struct ds_cap_state *cp = find_cap(dp, ap->handle); |
| 943 |
|
| 944 |
if (!cp) { |
| 945 |
printk(KERN_ERR "ds-%llu: REG ACK for unknown " |
| 946 |
"handle %llx\n", dp->id, ap->handle); |
| 947 |
return 0; |
| 948 |
} |
| 949 |
printk(KERN_INFO "ds-%llu: Registered %s service.\n", |
| 950 |
dp->id, cp->service_id); |
| 951 |
cp->state = CAP_STATE_REGISTERED; |
| 952 |
} else if (pkt->type == DS_REG_NACK) { |
| 953 |
struct ds_reg_nack *np = (struct ds_reg_nack *) pkt; |
| 954 |
struct ds_cap_state *cp = find_cap(dp, np->handle); |
| 955 |
|
| 956 |
if (!cp) { |
| 957 |
printk(KERN_ERR "ds-%llu: REG NACK for " |
| 958 |
"unknown handle %llx\n", |
| 959 |
dp->id, np->handle); |
| 960 |
return 0; |
| 961 |
} |
| 962 |
cp->state = CAP_STATE_UNKNOWN; |
| 963 |
} |
| 964 |
|
| 965 |
return 0; |
| 966 |
|
| 967 |
conn_reset: |
| 968 |
ds_conn_reset(dp); |
| 969 |
return -ECONNRESET; |
| 970 |
} |
| 971 |
|
| 972 |
static void __send_ds_nack(struct ds_info *dp, u64 handle) |
| 973 |
{ |
| 974 |
struct ds_data_nack nack = { |
| 975 |
.tag = { |
| 976 |
.type = DS_NACK, |
| 977 |
.len = (sizeof(struct ds_data_nack) - |
| 978 |
sizeof(struct ds_msg_tag)), |
| 979 |
}, |
| 980 |
.handle = handle, |
| 981 |
.result = DS_INV_HDL, |
| 982 |
}; |
| 983 |
|
| 984 |
__ds_send(dp->lp, &nack, sizeof(nack)); |
| 985 |
} |
| 986 |
|
| 987 |
static LIST_HEAD(ds_work_list); |
| 988 |
static DECLARE_WAIT_QUEUE_HEAD(ds_wait); |
| 989 |
|
| 990 |
struct ds_queue_entry { |
| 991 |
struct list_head list; |
| 992 |
struct ds_info *dp; |
| 993 |
int req_len; |
| 994 |
int __pad; |
| 995 |
u64 req[]; |
| 996 |
}; |
| 997 |
|
| 998 |
static void process_ds_work(void) |
| 999 |
{ |
| 1000 |
struct ds_queue_entry *qp, *tmp; |
| 1001 |
unsigned long flags; |
| 1002 |
LIST_HEAD(todo); |
| 1003 |
|
| 1004 |
spin_lock_irqsave(&ds_lock, flags); |
| 1005 |
list_splice_init(&ds_work_list, &todo); |
| 1006 |
spin_unlock_irqrestore(&ds_lock, flags); |
| 1007 |
|
| 1008 |
list_for_each_entry_safe(qp, tmp, &todo, list) { |
| 1009 |
struct ds_data *dpkt = (struct ds_data *) qp->req; |
| 1010 |
struct ds_info *dp = qp->dp; |
| 1011 |
struct ds_cap_state *cp = find_cap(dp, dpkt->handle); |
| 1012 |
int req_len = qp->req_len; |
| 1013 |
|
| 1014 |
if (!cp) { |
| 1015 |
printk(KERN_ERR "ds-%llu: Data for unknown " |
| 1016 |
"handle %llu\n", |
| 1017 |
dp->id, dpkt->handle); |
| 1018 |
|
| 1019 |
spin_lock_irqsave(&ds_lock, flags); |
| 1020 |
__send_ds_nack(dp, dpkt->handle); |
| 1021 |
spin_unlock_irqrestore(&ds_lock, flags); |
| 1022 |
} else { |
| 1023 |
cp->data(dp, cp, dpkt, req_len); |
| 1024 |
} |
| 1025 |
|
| 1026 |
list_del(&qp->list); |
| 1027 |
kfree(qp); |
| 1028 |
} |
| 1029 |
} |
| 1030 |
|
| 1031 |
static int ds_thread(void *__unused) |
| 1032 |
{ |
| 1033 |
DEFINE_WAIT(wait); |
| 1034 |
|
| 1035 |
while (1) { |
| 1036 |
prepare_to_wait(&ds_wait, &wait, TASK_INTERRUPTIBLE); |
| 1037 |
if (list_empty(&ds_work_list)) |
| 1038 |
schedule(); |
| 1039 |
finish_wait(&ds_wait, &wait); |
| 1040 |
|
| 1041 |
if (kthread_should_stop()) |
| 1042 |
break; |
| 1043 |
|
| 1044 |
process_ds_work(); |
| 1045 |
} |
| 1046 |
|
| 1047 |
return 0; |
| 1048 |
} |
| 1049 |
|
| 1050 |
static int ds_data(struct ds_info *dp, struct ds_msg_tag *pkt, int len) |
| 1051 |
{ |
| 1052 |
struct ds_data *dpkt = (struct ds_data *) pkt; |
| 1053 |
struct ds_queue_entry *qp; |
| 1054 |
|
| 1055 |
qp = kmalloc(sizeof(struct ds_queue_entry) + len, GFP_ATOMIC); |
| 1056 |
if (!qp) { |
| 1057 |
__send_ds_nack(dp, dpkt->handle); |
| 1058 |
} else { |
| 1059 |
qp->dp = dp; |
| 1060 |
memcpy(&qp->req, pkt, len); |
| 1061 |
list_add_tail(&qp->list, &ds_work_list); |
| 1062 |
wake_up(&ds_wait); |
| 1063 |
} |
| 1064 |
return 0; |
| 1065 |
} |
| 1066 |
|
| 1067 |
static void ds_up(struct ds_info *dp) |
| 1068 |
{ |
| 1069 |
struct ldc_channel *lp = dp->lp; |
| 1070 |
struct ds_ver_req req; |
| 1071 |
int err; |
| 1072 |
|
| 1073 |
req.tag.type = DS_INIT_REQ; |
| 1074 |
req.tag.len = sizeof(req) - sizeof(struct ds_msg_tag); |
| 1075 |
req.ver.major = 1; |
| 1076 |
req.ver.minor = 0; |
| 1077 |
|
| 1078 |
err = __ds_send(lp, &req, sizeof(req)); |
| 1079 |
if (err > 0) |
| 1080 |
dp->hs_state = DS_HS_START; |
| 1081 |
} |
| 1082 |
|
| 1083 |
static void ds_reset(struct ds_info *dp) |
| 1084 |
{ |
| 1085 |
int i; |
| 1086 |
|
| 1087 |
dp->hs_state = 0; |
| 1088 |
|
| 1089 |
for (i = 0; i < dp->num_ds_states; i++) { |
| 1090 |
struct ds_cap_state *cp = &dp->ds_states[i]; |
| 1091 |
|
| 1092 |
cp->state = CAP_STATE_UNKNOWN; |
| 1093 |
} |
| 1094 |
} |
| 1095 |
|
| 1096 |
static void ds_event(void *arg, int event) |
| 1097 |
{ |
| 1098 |
struct ds_info *dp = arg; |
| 1099 |
struct ldc_channel *lp = dp->lp; |
| 1100 |
unsigned long flags; |
| 1101 |
int err; |
| 1102 |
|
| 1103 |
spin_lock_irqsave(&ds_lock, flags); |
| 1104 |
|
| 1105 |
if (event == LDC_EVENT_UP) { |
| 1106 |
ds_up(dp); |
| 1107 |
spin_unlock_irqrestore(&ds_lock, flags); |
| 1108 |
return; |
| 1109 |
} |
| 1110 |
|
| 1111 |
if (event == LDC_EVENT_RESET) { |
| 1112 |
ds_reset(dp); |
| 1113 |
spin_unlock_irqrestore(&ds_lock, flags); |
| 1114 |
return; |
| 1115 |
} |
| 1116 |
|
| 1117 |
if (event != LDC_EVENT_DATA_READY) { |
| 1118 |
printk(KERN_WARNING "ds-%llu: Unexpected LDC event %d\n", |
| 1119 |
dp->id, event); |
| 1120 |
spin_unlock_irqrestore(&ds_lock, flags); |
| 1121 |
return; |
| 1122 |
} |
| 1123 |
|
| 1124 |
err = 0; |
| 1125 |
while (1) { |
| 1126 |
struct ds_msg_tag *tag; |
| 1127 |
|
| 1128 |
err = ldc_read(lp, dp->rcv_buf, sizeof(*tag)); |
| 1129 |
|
| 1130 |
if (unlikely(err < 0)) { |
| 1131 |
if (err == -ECONNRESET) |
| 1132 |
ds_conn_reset(dp); |
| 1133 |
break; |
| 1134 |
} |
| 1135 |
if (err == 0) |
| 1136 |
break; |
| 1137 |
|
| 1138 |
tag = dp->rcv_buf; |
| 1139 |
err = ldc_read(lp, tag + 1, tag->len); |
| 1140 |
|
| 1141 |
if (unlikely(err < 0)) { |
| 1142 |
if (err == -ECONNRESET) |
| 1143 |
ds_conn_reset(dp); |
| 1144 |
break; |
| 1145 |
} |
| 1146 |
if (err < tag->len) |
| 1147 |
break; |
| 1148 |
|
| 1149 |
if (tag->type < DS_DATA) |
| 1150 |
err = ds_handshake(dp, dp->rcv_buf); |
| 1151 |
else |
| 1152 |
err = ds_data(dp, dp->rcv_buf, |
| 1153 |
sizeof(*tag) + err); |
| 1154 |
if (err == -ECONNRESET) |
| 1155 |
break; |
| 1156 |
} |
| 1157 |
|
| 1158 |
spin_unlock_irqrestore(&ds_lock, flags); |
| 1159 |
} |
| 1160 |
|
| 1161 |
static int ds_probe(struct vio_dev *vdev, const struct vio_device_id *id) |
| 1162 |
{ |
| 1163 |
static int ds_version_printed; |
| 1164 |
struct ldc_channel_config ds_cfg = { |
| 1165 |
.event = ds_event, |
| 1166 |
.mtu = 4096, |
| 1167 |
.mode = LDC_MODE_STREAM, |
| 1168 |
}; |
| 1169 |
struct mdesc_handle *hp; |
| 1170 |
struct ldc_channel *lp; |
| 1171 |
struct ds_info *dp; |
| 1172 |
const u64 *val; |
| 1173 |
int err, i; |
| 1174 |
|
| 1175 |
if (ds_version_printed++ == 0) |
| 1176 |
printk(KERN_INFO "%s", version); |
| 1177 |
|
| 1178 |
dp = kzalloc_obj(*dp); |
| 1179 |
err = -ENOMEM; |
| 1180 |
if (!dp) |
| 1181 |
goto out_err; |
| 1182 |
|
| 1183 |
hp = mdesc_grab(); |
| 1184 |
val = mdesc_get_property(hp, vdev->mp, "id", NULL); |
| 1185 |
if (val) |
| 1186 |
dp->id = *val; |
| 1187 |
mdesc_release(hp); |
| 1188 |
|
| 1189 |
dp->rcv_buf = kzalloc(4096, GFP_KERNEL); |
| 1190 |
if (!dp->rcv_buf) |
| 1191 |
goto out_free_dp; |
| 1192 |
|
| 1193 |
dp->rcv_buf_len = 4096; |
| 1194 |
|
| 1195 |
dp->ds_states = kmemdup(ds_states_template, |
| 1196 |
sizeof(ds_states_template), GFP_KERNEL); |
| 1197 |
if (!dp->ds_states) |
| 1198 |
goto out_free_rcv_buf; |
| 1199 |
|
| 1200 |
dp->num_ds_states = ARRAY_SIZE(ds_states_template); |
| 1201 |
|
| 1202 |
for (i = 0; i < dp->num_ds_states; i++) |
| 1203 |
dp->ds_states[i].handle = ((u64)i << 32); |
| 1204 |
|
| 1205 |
ds_cfg.tx_irq = vdev->tx_irq; |
| 1206 |
ds_cfg.rx_irq = vdev->rx_irq; |
| 1207 |
|
| 1208 |
lp = ldc_alloc(vdev->channel_id, &ds_cfg, dp, "DS"); |
| 1209 |
if (IS_ERR(lp)) { |
| 1210 |
err = PTR_ERR(lp); |
| 1211 |
goto out_free_ds_states; |
| 1212 |
} |
| 1213 |
dp->lp = lp; |
| 1214 |
|
| 1215 |
err = ldc_bind(lp); |
| 1216 |
if (err) |
| 1217 |
goto out_free_ldc; |
| 1218 |
|
| 1219 |
spin_lock_irq(&ds_lock); |
| 1220 |
dp->next = ds_info_list; |
| 1221 |
ds_info_list = dp; |
| 1222 |
spin_unlock_irq(&ds_lock); |
| 1223 |
|
| 1224 |
return err; |
| 1225 |
|
| 1226 |
out_free_ldc: |
| 1227 |
ldc_free(dp->lp); |
| 1228 |
|
| 1229 |
out_free_ds_states: |
| 1230 |
kfree(dp->ds_states); |
| 1231 |
|
| 1232 |
out_free_rcv_buf: |
| 1233 |
kfree(dp->rcv_buf); |
| 1234 |
|
| 1235 |
out_free_dp: |
| 1236 |
kfree(dp); |
| 1237 |
|
| 1238 |
out_err: |
| 1239 |
return err; |
| 1240 |
} |
| 1241 |
|
| 1242 |
static const struct vio_device_id ds_match[] = { |
| 1243 |
{ |
| 1244 |
.type = "domain-services-port", |
| 1245 |
}, |
| 1246 |
{}, |
| 1247 |
}; |
| 1248 |
|
| 1249 |
static struct vio_driver ds_driver = { |
| 1250 |
.id_table = ds_match, |
| 1251 |
.probe = ds_probe, |
| 1252 |
.name = "ds", |
| 1253 |
}; |
| 1254 |
|
| 1255 |
static int __init ds_init(void) |
| 1256 |
{ |
| 1257 |
unsigned long hv_ret, major, minor; |
| 1258 |
|
| 1259 |
if (tlb_type == hypervisor) { |
| 1260 |
hv_ret = sun4v_get_version(HV_GRP_REBOOT_DATA, &major, &minor); |
| 1261 |
if (hv_ret == HV_EOK) { |
| 1262 |
pr_info("SUN4V: Reboot data supported (maj=%lu,min=%lu).\n", |
| 1263 |
major, minor); |
| 1264 |
reboot_data_supported = 1; |
| 1265 |
} |
| 1266 |
} |
| 1267 |
kthread_run(ds_thread, NULL, "kldomd"); |
| 1268 |
|
| 1269 |
return vio_register_driver(&ds_driver); |
| 1270 |
} |
| 1271 |
|
| 1272 |
fs_initcall(ds_init); |