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