Chris Kelly | 1619cb6 | 2012-02-20 21:11:28 +0000 | [diff] [blame] | 1 | /* ----------------------------------------------------------------------------- |
| 2 | * Copyright (c) 2011 Ozmo Inc |
| 3 | * Released under the GNU General Public License Version 2 (GPLv2). |
| 4 | * ----------------------------------------------------------------------------- |
| 5 | */ |
Joe Perches | 05f608f | 2013-07-23 13:45:01 +0100 | [diff] [blame] | 6 | |
Chris Kelly | 1619cb6 | 2012-02-20 21:11:28 +0000 | [diff] [blame] | 7 | #include <linux/init.h> |
| 8 | #include <linux/module.h> |
| 9 | #include <linux/timer.h> |
| 10 | #include <linux/sched.h> |
| 11 | #include <linux/netdevice.h> |
| 12 | #include <linux/errno.h> |
| 13 | #include <linux/ieee80211.h> |
Joe Perches | f724b58 | 2013-07-23 13:45:00 +0100 | [diff] [blame] | 14 | #include "ozdbg.h" |
Chris Kelly | 1619cb6 | 2012-02-20 21:11:28 +0000 | [diff] [blame] | 15 | #include "ozprotocol.h" |
| 16 | #include "ozeltbuf.h" |
| 17 | #include "ozpd.h" |
| 18 | #include "ozproto.h" |
| 19 | #include "ozusbsvc.h" |
Joe Perches | 05f608f | 2013-07-23 13:45:01 +0100 | [diff] [blame] | 20 | |
Chris Kelly | 1619cb6 | 2012-02-20 21:11:28 +0000 | [diff] [blame] | 21 | #include "ozappif.h" |
Chris Kelly | 1619cb6 | 2012-02-20 21:11:28 +0000 | [diff] [blame] | 22 | #include <asm/unaligned.h> |
| 23 | #include <linux/uaccess.h> |
| 24 | #include <net/psnap.h> |
| 25 | /*------------------------------------------------------------------------------ |
| 26 | */ |
| 27 | #define OZ_CF_CONN_SUCCESS 1 |
| 28 | #define OZ_CF_CONN_FAILURE 2 |
| 29 | |
| 30 | #define OZ_DO_STOP 1 |
| 31 | #define OZ_DO_SLEEP 2 |
| 32 | |
Chris Kelly | 1619cb6 | 2012-02-20 21:11:28 +0000 | [diff] [blame] | 33 | #define OZ_MAX_TIMER_POOL_SIZE 16 |
| 34 | |
| 35 | /*------------------------------------------------------------------------------ |
| 36 | */ |
| 37 | struct oz_binding { |
| 38 | struct packet_type ptype; |
| 39 | char name[OZ_MAX_BINDING_LEN]; |
Rupesh Gujare | 8a3cac6 | 2013-08-01 18:40:00 +0100 | [diff] [blame^] | 40 | struct list_head link; |
Chris Kelly | 1619cb6 | 2012-02-20 21:11:28 +0000 | [diff] [blame] | 41 | }; |
| 42 | |
Chris Kelly | 1619cb6 | 2012-02-20 21:11:28 +0000 | [diff] [blame] | 43 | /*------------------------------------------------------------------------------ |
| 44 | * Static external variables. |
| 45 | */ |
| 46 | static DEFINE_SPINLOCK(g_polling_lock); |
| 47 | static LIST_HEAD(g_pd_list); |
Rupesh Gujare | 8a3cac6 | 2013-08-01 18:40:00 +0100 | [diff] [blame^] | 48 | static LIST_HEAD(g_binding); |
Chris Kelly | 1619cb6 | 2012-02-20 21:11:28 +0000 | [diff] [blame] | 49 | static DEFINE_SPINLOCK(g_binding_lock); |
| 50 | static struct sk_buff_head g_rx_queue; |
| 51 | static u8 g_session_id; |
| 52 | static u16 g_apps = 0x1; |
| 53 | static int g_processing_rx; |
Chris Kelly | 1619cb6 | 2012-02-20 21:11:28 +0000 | [diff] [blame] | 54 | /*------------------------------------------------------------------------------ |
| 55 | * Context: softirq-serialized |
| 56 | */ |
| 57 | static u8 oz_get_new_session_id(u8 exclude) |
| 58 | { |
| 59 | if (++g_session_id == 0) |
| 60 | g_session_id = 1; |
| 61 | if (g_session_id == exclude) { |
| 62 | if (++g_session_id == 0) |
| 63 | g_session_id = 1; |
| 64 | } |
| 65 | return g_session_id; |
| 66 | } |
| 67 | /*------------------------------------------------------------------------------ |
| 68 | * Context: softirq-serialized |
| 69 | */ |
| 70 | static void oz_send_conn_rsp(struct oz_pd *pd, u8 status) |
| 71 | { |
| 72 | struct sk_buff *skb; |
| 73 | struct net_device *dev = pd->net_dev; |
| 74 | struct oz_hdr *oz_hdr; |
| 75 | struct oz_elt *elt; |
| 76 | struct oz_elt_connect_rsp *body; |
| 77 | int sz = sizeof(struct oz_hdr) + sizeof(struct oz_elt) + |
| 78 | sizeof(struct oz_elt_connect_rsp); |
Greg Kroah-Hartman | 6b790d0 | 2013-06-04 16:02:46 -0700 | [diff] [blame] | 79 | skb = alloc_skb(sz + OZ_ALLOCATED_SPACE(dev), GFP_ATOMIC); |
Peter Huewe | 41ebb8a | 2013-02-15 15:22:25 +0100 | [diff] [blame] | 80 | if (skb == NULL) |
Chris Kelly | 1619cb6 | 2012-02-20 21:11:28 +0000 | [diff] [blame] | 81 | return; |
| 82 | skb_reserve(skb, LL_RESERVED_SPACE(dev)); |
| 83 | skb_reset_network_header(skb); |
| 84 | oz_hdr = (struct oz_hdr *)skb_put(skb, sz); |
| 85 | elt = (struct oz_elt *)(oz_hdr+1); |
| 86 | body = (struct oz_elt_connect_rsp *)(elt+1); |
| 87 | skb->dev = dev; |
| 88 | skb->protocol = htons(OZ_ETHERTYPE); |
| 89 | /* Fill in device header */ |
| 90 | if (dev_hard_header(skb, dev, OZ_ETHERTYPE, pd->mac_addr, |
| 91 | dev->dev_addr, skb->len) < 0) { |
Greg Kroah-Hartman | e79f864 | 2013-06-04 16:01:33 -0700 | [diff] [blame] | 92 | kfree_skb(skb); |
Chris Kelly | 1619cb6 | 2012-02-20 21:11:28 +0000 | [diff] [blame] | 93 | return; |
| 94 | } |
| 95 | oz_hdr->control = (OZ_PROTOCOL_VERSION<<OZ_VERSION_SHIFT); |
| 96 | oz_hdr->last_pkt_num = 0; |
| 97 | put_unaligned(0, &oz_hdr->pkt_num); |
Chris Kelly | 1619cb6 | 2012-02-20 21:11:28 +0000 | [diff] [blame] | 98 | elt->type = OZ_ELT_CONNECT_RSP; |
| 99 | elt->length = sizeof(struct oz_elt_connect_rsp); |
| 100 | memset(body, 0, sizeof(struct oz_elt_connect_rsp)); |
| 101 | body->status = status; |
| 102 | if (status == 0) { |
| 103 | body->mode = pd->mode; |
| 104 | body->session_id = pd->session_id; |
| 105 | put_unaligned(cpu_to_le16(pd->total_apps), &body->apps); |
| 106 | } |
Joe Perches | f724b58 | 2013-07-23 13:45:00 +0100 | [diff] [blame] | 107 | oz_dbg(ON, "TX: OZ_ELT_CONNECT_RSP %d", status); |
Chris Kelly | 1619cb6 | 2012-02-20 21:11:28 +0000 | [diff] [blame] | 108 | dev_queue_xmit(skb); |
| 109 | return; |
| 110 | } |
| 111 | /*------------------------------------------------------------------------------ |
| 112 | * Context: softirq-serialized |
| 113 | */ |
| 114 | static void pd_set_keepalive(struct oz_pd *pd, u8 kalive) |
| 115 | { |
| 116 | unsigned long keep_alive = kalive & OZ_KALIVE_VALUE_MASK; |
| 117 | |
| 118 | switch (kalive & OZ_KALIVE_TYPE_MASK) { |
| 119 | case OZ_KALIVE_SPECIAL: |
Rupesh Gujare | 8fd0700 | 2013-07-30 13:31:50 +0100 | [diff] [blame] | 120 | pd->keep_alive = keep_alive * 1000*60*60*24*20; |
Chris Kelly | 1619cb6 | 2012-02-20 21:11:28 +0000 | [diff] [blame] | 121 | break; |
| 122 | case OZ_KALIVE_SECS: |
Rupesh Gujare | 8fd0700 | 2013-07-30 13:31:50 +0100 | [diff] [blame] | 123 | pd->keep_alive = keep_alive*1000; |
Chris Kelly | 1619cb6 | 2012-02-20 21:11:28 +0000 | [diff] [blame] | 124 | break; |
| 125 | case OZ_KALIVE_MINS: |
Rupesh Gujare | 8fd0700 | 2013-07-30 13:31:50 +0100 | [diff] [blame] | 126 | pd->keep_alive = keep_alive*1000*60; |
Chris Kelly | 1619cb6 | 2012-02-20 21:11:28 +0000 | [diff] [blame] | 127 | break; |
| 128 | case OZ_KALIVE_HOURS: |
Rupesh Gujare | 8fd0700 | 2013-07-30 13:31:50 +0100 | [diff] [blame] | 129 | pd->keep_alive = keep_alive*1000*60*60; |
Chris Kelly | 1619cb6 | 2012-02-20 21:11:28 +0000 | [diff] [blame] | 130 | break; |
| 131 | default: |
Rupesh Gujare | 8fd0700 | 2013-07-30 13:31:50 +0100 | [diff] [blame] | 132 | pd->keep_alive = 0; |
Chris Kelly | 1619cb6 | 2012-02-20 21:11:28 +0000 | [diff] [blame] | 133 | } |
Rupesh Gujare | 8fd0700 | 2013-07-30 13:31:50 +0100 | [diff] [blame] | 134 | oz_dbg(ON, "Keepalive = %lu mSec\n", pd->keep_alive); |
Chris Kelly | 1619cb6 | 2012-02-20 21:11:28 +0000 | [diff] [blame] | 135 | } |
| 136 | /*------------------------------------------------------------------------------ |
| 137 | * Context: softirq-serialized |
| 138 | */ |
Rupesh Gujare | 8fd0700 | 2013-07-30 13:31:50 +0100 | [diff] [blame] | 139 | static void pd_set_presleep(struct oz_pd *pd, u8 presleep, u8 start_timer) |
Chris Kelly | 1619cb6 | 2012-02-20 21:11:28 +0000 | [diff] [blame] | 140 | { |
| 141 | if (presleep) |
Rupesh Gujare | 8fd0700 | 2013-07-30 13:31:50 +0100 | [diff] [blame] | 142 | pd->presleep = presleep*100; |
Chris Kelly | 1619cb6 | 2012-02-20 21:11:28 +0000 | [diff] [blame] | 143 | else |
Rupesh Gujare | 8fd0700 | 2013-07-30 13:31:50 +0100 | [diff] [blame] | 144 | pd->presleep = OZ_PRESLEEP_TOUT; |
| 145 | if (start_timer) { |
| 146 | spin_unlock(&g_polling_lock); |
| 147 | oz_timer_add(pd, OZ_TIMER_TOUT, pd->presleep); |
| 148 | spin_lock(&g_polling_lock); |
| 149 | } |
| 150 | oz_dbg(ON, "Presleep time = %lu mSec\n", pd->presleep); |
Chris Kelly | 1619cb6 | 2012-02-20 21:11:28 +0000 | [diff] [blame] | 151 | } |
| 152 | /*------------------------------------------------------------------------------ |
| 153 | * Context: softirq-serialized |
| 154 | */ |
| 155 | static struct oz_pd *oz_connect_req(struct oz_pd *cur_pd, struct oz_elt *elt, |
Peter Huewe | dc7f5b3 | 2013-02-15 21:17:24 +0100 | [diff] [blame] | 156 | const u8 *pd_addr, struct net_device *net_dev) |
Chris Kelly | 1619cb6 | 2012-02-20 21:11:28 +0000 | [diff] [blame] | 157 | { |
| 158 | struct oz_pd *pd; |
| 159 | struct oz_elt_connect_req *body = |
| 160 | (struct oz_elt_connect_req *)(elt+1); |
| 161 | u8 rsp_status = OZ_STATUS_SUCCESS; |
| 162 | u8 stop_needed = 0; |
| 163 | u16 new_apps = g_apps; |
Peter Huewe | 41ebb8a | 2013-02-15 15:22:25 +0100 | [diff] [blame] | 164 | struct net_device *old_net_dev = NULL; |
| 165 | struct oz_pd *free_pd = NULL; |
Chris Kelly | 1619cb6 | 2012-02-20 21:11:28 +0000 | [diff] [blame] | 166 | if (cur_pd) { |
| 167 | pd = cur_pd; |
| 168 | spin_lock_bh(&g_polling_lock); |
| 169 | } else { |
Peter Huewe | 41ebb8a | 2013-02-15 15:22:25 +0100 | [diff] [blame] | 170 | struct oz_pd *pd2 = NULL; |
Chris Kelly | 1619cb6 | 2012-02-20 21:11:28 +0000 | [diff] [blame] | 171 | struct list_head *e; |
| 172 | pd = oz_pd_alloc(pd_addr); |
Peter Huewe | 41ebb8a | 2013-02-15 15:22:25 +0100 | [diff] [blame] | 173 | if (pd == NULL) |
| 174 | return NULL; |
Rupesh Gujare | 8fd0700 | 2013-07-30 13:31:50 +0100 | [diff] [blame] | 175 | getnstimeofday(&pd->last_rx_timestamp); |
Chris Kelly | 1619cb6 | 2012-02-20 21:11:28 +0000 | [diff] [blame] | 176 | spin_lock_bh(&g_polling_lock); |
| 177 | list_for_each(e, &g_pd_list) { |
| 178 | pd2 = container_of(e, struct oz_pd, link); |
| 179 | if (memcmp(pd2->mac_addr, pd_addr, ETH_ALEN) == 0) { |
| 180 | free_pd = pd; |
| 181 | pd = pd2; |
| 182 | break; |
| 183 | } |
| 184 | } |
| 185 | if (pd != pd2) |
| 186 | list_add_tail(&pd->link, &g_pd_list); |
| 187 | } |
Peter Huewe | 41ebb8a | 2013-02-15 15:22:25 +0100 | [diff] [blame] | 188 | if (pd == NULL) { |
Chris Kelly | 1619cb6 | 2012-02-20 21:11:28 +0000 | [diff] [blame] | 189 | spin_unlock_bh(&g_polling_lock); |
Peter Huewe | 41ebb8a | 2013-02-15 15:22:25 +0100 | [diff] [blame] | 190 | return NULL; |
Chris Kelly | 1619cb6 | 2012-02-20 21:11:28 +0000 | [diff] [blame] | 191 | } |
| 192 | if (pd->net_dev != net_dev) { |
| 193 | old_net_dev = pd->net_dev; |
| 194 | dev_hold(net_dev); |
| 195 | pd->net_dev = net_dev; |
| 196 | } |
Joe Perches | f724b58 | 2013-07-23 13:45:00 +0100 | [diff] [blame] | 197 | oz_dbg(ON, "Host vendor: %d\n", body->host_vendor); |
Chris Kelly | 1619cb6 | 2012-02-20 21:11:28 +0000 | [diff] [blame] | 198 | pd->max_tx_size = OZ_MAX_TX_SIZE; |
| 199 | pd->mode = body->mode; |
| 200 | pd->pd_info = body->pd_info; |
| 201 | if (pd->mode & OZ_F_ISOC_NO_ELTS) { |
Chris Kelly | 1619cb6 | 2012-02-20 21:11:28 +0000 | [diff] [blame] | 202 | pd->ms_per_isoc = body->ms_per_isoc; |
| 203 | if (!pd->ms_per_isoc) |
| 204 | pd->ms_per_isoc = 4; |
Rupesh Gujare | 86d03a0 | 2012-07-23 18:49:46 +0100 | [diff] [blame] | 205 | |
| 206 | switch (body->ms_isoc_latency & OZ_LATENCY_MASK) { |
| 207 | case OZ_ONE_MS_LATENCY: |
| 208 | pd->isoc_latency = (body->ms_isoc_latency & |
| 209 | ~OZ_LATENCY_MASK) / pd->ms_per_isoc; |
| 210 | break; |
| 211 | case OZ_TEN_MS_LATENCY: |
| 212 | pd->isoc_latency = ((body->ms_isoc_latency & |
| 213 | ~OZ_LATENCY_MASK) * 10) / pd->ms_per_isoc; |
| 214 | break; |
| 215 | default: |
| 216 | pd->isoc_latency = OZ_MAX_TX_QUEUE_ISOC; |
| 217 | } |
Chris Kelly | 1619cb6 | 2012-02-20 21:11:28 +0000 | [diff] [blame] | 218 | } |
| 219 | if (body->max_len_div16) |
| 220 | pd->max_tx_size = ((u16)body->max_len_div16)<<4; |
Joe Perches | f724b58 | 2013-07-23 13:45:00 +0100 | [diff] [blame] | 221 | oz_dbg(ON, "Max frame:%u Ms per isoc:%u\n", |
| 222 | pd->max_tx_size, pd->ms_per_isoc); |
Chris Kelly | 1619cb6 | 2012-02-20 21:11:28 +0000 | [diff] [blame] | 223 | pd->max_stream_buffering = 3*1024; |
Rupesh Gujare | 8fd0700 | 2013-07-30 13:31:50 +0100 | [diff] [blame] | 224 | pd->pulse_period = OZ_QUANTUM; |
| 225 | pd_set_presleep(pd, body->presleep, 0); |
Chris Kelly | 1619cb6 | 2012-02-20 21:11:28 +0000 | [diff] [blame] | 226 | pd_set_keepalive(pd, body->keep_alive); |
| 227 | |
| 228 | new_apps &= le16_to_cpu(get_unaligned(&body->apps)); |
| 229 | if ((new_apps & 0x1) && (body->session_id)) { |
| 230 | if (pd->session_id) { |
| 231 | if (pd->session_id != body->session_id) { |
| 232 | rsp_status = OZ_STATUS_SESSION_MISMATCH; |
| 233 | goto done; |
| 234 | } |
| 235 | } else { |
| 236 | new_apps &= ~0x1; /* Resume not permitted */ |
| 237 | pd->session_id = |
| 238 | oz_get_new_session_id(body->session_id); |
| 239 | } |
| 240 | } else { |
| 241 | if (pd->session_id && !body->session_id) { |
| 242 | rsp_status = OZ_STATUS_SESSION_TEARDOWN; |
| 243 | stop_needed = 1; |
| 244 | } else { |
| 245 | new_apps &= ~0x1; /* Resume not permitted */ |
| 246 | pd->session_id = |
| 247 | oz_get_new_session_id(body->session_id); |
| 248 | } |
| 249 | } |
| 250 | done: |
| 251 | if (rsp_status == OZ_STATUS_SUCCESS) { |
| 252 | u16 start_apps = new_apps & ~pd->total_apps & ~0x1; |
| 253 | u16 stop_apps = pd->total_apps & ~new_apps & ~0x1; |
| 254 | u16 resume_apps = new_apps & pd->paused_apps & ~0x1; |
| 255 | spin_unlock_bh(&g_polling_lock); |
| 256 | oz_pd_set_state(pd, OZ_PD_S_CONNECTED); |
Joe Perches | f724b58 | 2013-07-23 13:45:00 +0100 | [diff] [blame] | 257 | oz_dbg(ON, "new_apps=0x%x total_apps=0x%x paused_apps=0x%x\n", |
| 258 | new_apps, pd->total_apps, pd->paused_apps); |
Chris Kelly | 1619cb6 | 2012-02-20 21:11:28 +0000 | [diff] [blame] | 259 | if (start_apps) { |
| 260 | if (oz_services_start(pd, start_apps, 0)) |
| 261 | rsp_status = OZ_STATUS_TOO_MANY_PDS; |
| 262 | } |
| 263 | if (resume_apps) |
| 264 | if (oz_services_start(pd, resume_apps, 1)) |
| 265 | rsp_status = OZ_STATUS_TOO_MANY_PDS; |
| 266 | if (stop_apps) |
| 267 | oz_services_stop(pd, stop_apps, 0); |
| 268 | oz_pd_request_heartbeat(pd); |
| 269 | } else { |
| 270 | spin_unlock_bh(&g_polling_lock); |
| 271 | } |
| 272 | oz_send_conn_rsp(pd, rsp_status); |
| 273 | if (rsp_status != OZ_STATUS_SUCCESS) { |
| 274 | if (stop_needed) |
| 275 | oz_pd_stop(pd); |
| 276 | oz_pd_put(pd); |
Peter Huewe | 41ebb8a | 2013-02-15 15:22:25 +0100 | [diff] [blame] | 277 | pd = NULL; |
Chris Kelly | 1619cb6 | 2012-02-20 21:11:28 +0000 | [diff] [blame] | 278 | } |
| 279 | if (old_net_dev) |
| 280 | dev_put(old_net_dev); |
| 281 | if (free_pd) |
| 282 | oz_pd_destroy(free_pd); |
| 283 | return pd; |
| 284 | } |
| 285 | /*------------------------------------------------------------------------------ |
| 286 | * Context: softirq-serialized |
| 287 | */ |
| 288 | static void oz_add_farewell(struct oz_pd *pd, u8 ep_num, u8 index, |
Peter Huewe | dc7f5b3 | 2013-02-15 21:17:24 +0100 | [diff] [blame] | 289 | const u8 *report, u8 len) |
Chris Kelly | 1619cb6 | 2012-02-20 21:11:28 +0000 | [diff] [blame] | 290 | { |
| 291 | struct oz_farewell *f; |
| 292 | struct oz_farewell *f2; |
| 293 | int found = 0; |
Greg Kroah-Hartman | 1ec41a3 | 2012-03-02 16:51:09 -0800 | [diff] [blame] | 294 | f = kmalloc(sizeof(struct oz_farewell) + len - 1, GFP_ATOMIC); |
Chris Kelly | 1619cb6 | 2012-02-20 21:11:28 +0000 | [diff] [blame] | 295 | if (!f) |
| 296 | return; |
| 297 | f->ep_num = ep_num; |
| 298 | f->index = index; |
| 299 | memcpy(f->report, report, len); |
Joe Perches | f724b58 | 2013-07-23 13:45:00 +0100 | [diff] [blame] | 300 | oz_dbg(ON, "RX: Adding farewell report\n"); |
Chris Kelly | 1619cb6 | 2012-02-20 21:11:28 +0000 | [diff] [blame] | 301 | spin_lock(&g_polling_lock); |
| 302 | list_for_each_entry(f2, &pd->farewell_list, link) { |
| 303 | if ((f2->ep_num == ep_num) && (f2->index == index)) { |
| 304 | found = 1; |
| 305 | list_del(&f2->link); |
| 306 | break; |
| 307 | } |
| 308 | } |
| 309 | list_add_tail(&f->link, &pd->farewell_list); |
| 310 | spin_unlock(&g_polling_lock); |
| 311 | if (found) |
Greg Kroah-Hartman | 1ec41a3 | 2012-03-02 16:51:09 -0800 | [diff] [blame] | 312 | kfree(f2); |
Chris Kelly | 1619cb6 | 2012-02-20 21:11:28 +0000 | [diff] [blame] | 313 | } |
| 314 | /*------------------------------------------------------------------------------ |
| 315 | * Context: softirq-serialized |
| 316 | */ |
| 317 | static void oz_rx_frame(struct sk_buff *skb) |
| 318 | { |
| 319 | u8 *mac_hdr; |
| 320 | u8 *src_addr; |
| 321 | struct oz_elt *elt; |
| 322 | int length; |
Peter Huewe | 41ebb8a | 2013-02-15 15:22:25 +0100 | [diff] [blame] | 323 | struct oz_pd *pd = NULL; |
Chris Kelly | 1619cb6 | 2012-02-20 21:11:28 +0000 | [diff] [blame] | 324 | struct oz_hdr *oz_hdr = (struct oz_hdr *)skb_network_header(skb); |
Rupesh Gujare | 8fd0700 | 2013-07-30 13:31:50 +0100 | [diff] [blame] | 325 | struct timespec current_time; |
Chris Kelly | 1619cb6 | 2012-02-20 21:11:28 +0000 | [diff] [blame] | 326 | int dup = 0; |
| 327 | u32 pkt_num; |
| 328 | |
Joe Perches | f724b58 | 2013-07-23 13:45:00 +0100 | [diff] [blame] | 329 | oz_dbg(RX_FRAMES, "RX frame PN=0x%x LPN=0x%x control=0x%x\n", |
| 330 | oz_hdr->pkt_num, oz_hdr->last_pkt_num, oz_hdr->control); |
Chris Kelly | 1619cb6 | 2012-02-20 21:11:28 +0000 | [diff] [blame] | 331 | mac_hdr = skb_mac_header(skb); |
| 332 | src_addr = &mac_hdr[ETH_ALEN] ; |
| 333 | length = skb->len; |
| 334 | |
| 335 | /* Check the version field */ |
| 336 | if (oz_get_prot_ver(oz_hdr->control) != OZ_PROTOCOL_VERSION) { |
Joe Perches | f724b58 | 2013-07-23 13:45:00 +0100 | [diff] [blame] | 337 | oz_dbg(ON, "Incorrect protocol version: %d\n", |
| 338 | oz_get_prot_ver(oz_hdr->control)); |
Chris Kelly | 1619cb6 | 2012-02-20 21:11:28 +0000 | [diff] [blame] | 339 | goto done; |
| 340 | } |
| 341 | |
| 342 | pkt_num = le32_to_cpu(get_unaligned(&oz_hdr->pkt_num)); |
| 343 | |
| 344 | pd = oz_pd_find(src_addr); |
| 345 | if (pd) { |
Rupesh Gujare | 8fd0700 | 2013-07-30 13:31:50 +0100 | [diff] [blame] | 346 | if (!(pd->state & OZ_PD_S_CONNECTED)) |
| 347 | oz_pd_set_state(pd, OZ_PD_S_CONNECTED); |
| 348 | getnstimeofday(¤t_time); |
| 349 | if ((current_time.tv_sec != pd->last_rx_timestamp.tv_sec) || |
| 350 | (pd->presleep < MSEC_PER_SEC)) { |
| 351 | oz_timer_add(pd, OZ_TIMER_TOUT, pd->presleep); |
| 352 | pd->last_rx_timestamp = current_time; |
| 353 | } |
Chris Kelly | 1619cb6 | 2012-02-20 21:11:28 +0000 | [diff] [blame] | 354 | if (pkt_num != pd->last_rx_pkt_num) { |
| 355 | pd->last_rx_pkt_num = pkt_num; |
| 356 | } else { |
| 357 | dup = 1; |
Joe Perches | f724b58 | 2013-07-23 13:45:00 +0100 | [diff] [blame] | 358 | oz_dbg(ON, "Duplicate frame\n"); |
Chris Kelly | 1619cb6 | 2012-02-20 21:11:28 +0000 | [diff] [blame] | 359 | } |
| 360 | } |
| 361 | |
| 362 | if (pd && !dup && ((pd->mode & OZ_MODE_MASK) == OZ_MODE_TRIGGERED)) { |
Joe Perches | f724b58 | 2013-07-23 13:45:00 +0100 | [diff] [blame] | 363 | oz_dbg(RX_FRAMES, "Received TRIGGER Frame\n"); |
Chris Kelly | 1619cb6 | 2012-02-20 21:11:28 +0000 | [diff] [blame] | 364 | pd->last_sent_frame = &pd->tx_queue; |
| 365 | if (oz_hdr->control & OZ_F_ACK) { |
| 366 | /* Retire completed frames */ |
| 367 | oz_retire_tx_frames(pd, oz_hdr->last_pkt_num); |
| 368 | } |
| 369 | if ((oz_hdr->control & OZ_F_ACK_REQUESTED) && |
| 370 | (pd->state == OZ_PD_S_CONNECTED)) { |
| 371 | int backlog = pd->nb_queued_frames; |
| 372 | pd->trigger_pkt_num = pkt_num; |
| 373 | /* Send queued frames */ |
Chris Kelly | 1619cb6 | 2012-02-20 21:11:28 +0000 | [diff] [blame] | 374 | oz_send_queued_frames(pd, backlog); |
| 375 | } |
| 376 | } |
| 377 | |
| 378 | length -= sizeof(struct oz_hdr); |
| 379 | elt = (struct oz_elt *)((u8 *)oz_hdr + sizeof(struct oz_hdr)); |
| 380 | |
| 381 | while (length >= sizeof(struct oz_elt)) { |
| 382 | length -= sizeof(struct oz_elt) + elt->length; |
| 383 | if (length < 0) |
| 384 | break; |
| 385 | switch (elt->type) { |
| 386 | case OZ_ELT_CONNECT_REQ: |
Joe Perches | f724b58 | 2013-07-23 13:45:00 +0100 | [diff] [blame] | 387 | oz_dbg(ON, "RX: OZ_ELT_CONNECT_REQ\n"); |
Chris Kelly | 1619cb6 | 2012-02-20 21:11:28 +0000 | [diff] [blame] | 388 | pd = oz_connect_req(pd, elt, src_addr, skb->dev); |
| 389 | break; |
| 390 | case OZ_ELT_DISCONNECT: |
Joe Perches | f724b58 | 2013-07-23 13:45:00 +0100 | [diff] [blame] | 391 | oz_dbg(ON, "RX: OZ_ELT_DISCONNECT\n"); |
Chris Kelly | 1619cb6 | 2012-02-20 21:11:28 +0000 | [diff] [blame] | 392 | if (pd) |
| 393 | oz_pd_sleep(pd); |
| 394 | break; |
| 395 | case OZ_ELT_UPDATE_PARAM_REQ: { |
| 396 | struct oz_elt_update_param *body = |
| 397 | (struct oz_elt_update_param *)(elt + 1); |
Joe Perches | f724b58 | 2013-07-23 13:45:00 +0100 | [diff] [blame] | 398 | oz_dbg(ON, "RX: OZ_ELT_UPDATE_PARAM_REQ\n"); |
Chris Kelly | 1619cb6 | 2012-02-20 21:11:28 +0000 | [diff] [blame] | 399 | if (pd && (pd->state & OZ_PD_S_CONNECTED)) { |
| 400 | spin_lock(&g_polling_lock); |
| 401 | pd_set_keepalive(pd, body->keepalive); |
Rupesh Gujare | 8fd0700 | 2013-07-30 13:31:50 +0100 | [diff] [blame] | 402 | pd_set_presleep(pd, body->presleep, 1); |
Chris Kelly | 1619cb6 | 2012-02-20 21:11:28 +0000 | [diff] [blame] | 403 | spin_unlock(&g_polling_lock); |
| 404 | } |
| 405 | } |
| 406 | break; |
| 407 | case OZ_ELT_FAREWELL_REQ: { |
| 408 | struct oz_elt_farewell *body = |
| 409 | (struct oz_elt_farewell *)(elt + 1); |
Joe Perches | f724b58 | 2013-07-23 13:45:00 +0100 | [diff] [blame] | 410 | oz_dbg(ON, "RX: OZ_ELT_FAREWELL_REQ\n"); |
Chris Kelly | 1619cb6 | 2012-02-20 21:11:28 +0000 | [diff] [blame] | 411 | oz_add_farewell(pd, body->ep_num, |
| 412 | body->index, body->report, |
| 413 | elt->length + 1 - sizeof(*body)); |
| 414 | } |
| 415 | break; |
| 416 | case OZ_ELT_APP_DATA: |
| 417 | if (pd && (pd->state & OZ_PD_S_CONNECTED)) { |
| 418 | struct oz_app_hdr *app_hdr = |
| 419 | (struct oz_app_hdr *)(elt+1); |
| 420 | if (dup) |
| 421 | break; |
| 422 | oz_handle_app_elt(pd, app_hdr->app_id, elt); |
| 423 | } |
| 424 | break; |
| 425 | default: |
Joe Perches | f724b58 | 2013-07-23 13:45:00 +0100 | [diff] [blame] | 426 | oz_dbg(ON, "RX: Unknown elt %02x\n", elt->type); |
Chris Kelly | 1619cb6 | 2012-02-20 21:11:28 +0000 | [diff] [blame] | 427 | } |
| 428 | elt = oz_next_elt(elt); |
| 429 | } |
| 430 | done: |
| 431 | if (pd) |
| 432 | oz_pd_put(pd); |
| 433 | consume_skb(skb); |
| 434 | } |
| 435 | /*------------------------------------------------------------------------------ |
| 436 | * Context: process |
| 437 | */ |
| 438 | void oz_protocol_term(void) |
| 439 | { |
Rupesh Gujare | 8a3cac6 | 2013-08-01 18:40:00 +0100 | [diff] [blame^] | 440 | struct oz_binding *b, *t; |
| 441 | |
Chris Kelly | 1619cb6 | 2012-02-20 21:11:28 +0000 | [diff] [blame] | 442 | /* Walk the list of bindings and remove each one. |
| 443 | */ |
| 444 | spin_lock_bh(&g_binding_lock); |
Rupesh Gujare | 8a3cac6 | 2013-08-01 18:40:00 +0100 | [diff] [blame^] | 445 | list_for_each_entry_safe(b, t, &g_binding, link) { |
| 446 | list_del(&b->link); |
Chris Kelly | 1619cb6 | 2012-02-20 21:11:28 +0000 | [diff] [blame] | 447 | spin_unlock_bh(&g_binding_lock); |
| 448 | dev_remove_pack(&b->ptype); |
| 449 | if (b->ptype.dev) |
| 450 | dev_put(b->ptype.dev); |
Greg Kroah-Hartman | 1ec41a3 | 2012-03-02 16:51:09 -0800 | [diff] [blame] | 451 | kfree(b); |
Chris Kelly | 1619cb6 | 2012-02-20 21:11:28 +0000 | [diff] [blame] | 452 | spin_lock_bh(&g_binding_lock); |
| 453 | } |
| 454 | spin_unlock_bh(&g_binding_lock); |
| 455 | /* Walk the list of PDs and stop each one. This causes the PD to be |
| 456 | * removed from the list so we can just pull each one from the head |
| 457 | * of the list. |
| 458 | */ |
| 459 | spin_lock_bh(&g_polling_lock); |
| 460 | while (!list_empty(&g_pd_list)) { |
| 461 | struct oz_pd *pd = |
| 462 | list_first_entry(&g_pd_list, struct oz_pd, link); |
| 463 | oz_pd_get(pd); |
| 464 | spin_unlock_bh(&g_polling_lock); |
| 465 | oz_pd_stop(pd); |
| 466 | oz_pd_put(pd); |
| 467 | spin_lock_bh(&g_polling_lock); |
| 468 | } |
Chris Kelly | 1619cb6 | 2012-02-20 21:11:28 +0000 | [diff] [blame] | 469 | spin_unlock_bh(&g_polling_lock); |
Joe Perches | f724b58 | 2013-07-23 13:45:00 +0100 | [diff] [blame] | 470 | oz_dbg(ON, "Protocol stopped\n"); |
Chris Kelly | 1619cb6 | 2012-02-20 21:11:28 +0000 | [diff] [blame] | 471 | } |
| 472 | /*------------------------------------------------------------------------------ |
| 473 | * Context: softirq |
| 474 | */ |
Rupesh Gujare | 8fd0700 | 2013-07-30 13:31:50 +0100 | [diff] [blame] | 475 | void oz_pd_heartbeat_handler(unsigned long data) |
Chris Kelly | 1619cb6 | 2012-02-20 21:11:28 +0000 | [diff] [blame] | 476 | { |
Rupesh Gujare | 8fd0700 | 2013-07-30 13:31:50 +0100 | [diff] [blame] | 477 | struct oz_pd *pd = (struct oz_pd *)data; |
| 478 | u16 apps = 0; |
| 479 | spin_lock_bh(&g_polling_lock); |
| 480 | if (pd->state & OZ_PD_S_CONNECTED) |
| 481 | apps = pd->total_apps; |
| 482 | spin_unlock_bh(&g_polling_lock); |
| 483 | if (apps) |
| 484 | oz_pd_heartbeat(pd, apps); |
| 485 | |
| 486 | } |
| 487 | /*------------------------------------------------------------------------------ |
| 488 | * Context: softirq |
| 489 | */ |
| 490 | void oz_pd_timeout_handler(unsigned long data) |
| 491 | { |
| 492 | int type; |
| 493 | struct oz_pd *pd = (struct oz_pd *)data; |
| 494 | |
| 495 | spin_lock_bh(&g_polling_lock); |
| 496 | type = pd->timeout_type; |
| 497 | spin_unlock_bh(&g_polling_lock); |
Chris Kelly | 1619cb6 | 2012-02-20 21:11:28 +0000 | [diff] [blame] | 498 | switch (type) { |
| 499 | case OZ_TIMER_TOUT: |
| 500 | oz_pd_sleep(pd); |
| 501 | break; |
| 502 | case OZ_TIMER_STOP: |
| 503 | oz_pd_stop(pd); |
| 504 | break; |
Rupesh Gujare | 8fd0700 | 2013-07-30 13:31:50 +0100 | [diff] [blame] | 505 | } |
| 506 | } |
| 507 | /*------------------------------------------------------------------------------ |
| 508 | * Context: Interrupt |
| 509 | */ |
| 510 | enum hrtimer_restart oz_pd_heartbeat_event(struct hrtimer *timer) |
| 511 | { |
| 512 | struct oz_pd *pd; |
| 513 | |
| 514 | pd = container_of(timer, struct oz_pd, heartbeat); |
| 515 | hrtimer_forward_now(timer, ktime_set(pd->pulse_period / |
| 516 | MSEC_PER_SEC, (pd->pulse_period % MSEC_PER_SEC) * NSEC_PER_MSEC)); |
| 517 | tasklet_schedule(&pd->heartbeat_tasklet); |
| 518 | return HRTIMER_RESTART; |
| 519 | } |
| 520 | /*------------------------------------------------------------------------------ |
| 521 | * Context: Interrupt |
| 522 | */ |
| 523 | enum hrtimer_restart oz_pd_timeout_event(struct hrtimer *timer) |
| 524 | { |
| 525 | struct oz_pd *pd; |
| 526 | |
| 527 | pd = container_of(timer, struct oz_pd, timeout); |
| 528 | tasklet_schedule(&pd->timeout_tasklet); |
| 529 | return HRTIMER_NORESTART; |
| 530 | } |
| 531 | /*------------------------------------------------------------------------------ |
| 532 | * Context: softirq or process |
| 533 | */ |
| 534 | void oz_timer_add(struct oz_pd *pd, int type, unsigned long due_time) |
| 535 | { |
| 536 | spin_lock_bh(&g_polling_lock); |
| 537 | switch (type) { |
| 538 | case OZ_TIMER_TOUT: |
| 539 | case OZ_TIMER_STOP: |
| 540 | if (hrtimer_active(&pd->timeout)) { |
| 541 | hrtimer_set_expires(&pd->timeout, ktime_set(due_time / |
| 542 | MSEC_PER_SEC, (due_time % MSEC_PER_SEC) * |
| 543 | NSEC_PER_MSEC)); |
| 544 | hrtimer_start_expires(&pd->timeout, HRTIMER_MODE_REL); |
| 545 | } else { |
| 546 | hrtimer_start(&pd->timeout, ktime_set(due_time / |
| 547 | MSEC_PER_SEC, (due_time % MSEC_PER_SEC) * |
| 548 | NSEC_PER_MSEC), HRTIMER_MODE_REL); |
Chris Kelly | 1619cb6 | 2012-02-20 21:11:28 +0000 | [diff] [blame] | 549 | } |
Rupesh Gujare | 8fd0700 | 2013-07-30 13:31:50 +0100 | [diff] [blame] | 550 | pd->timeout_type = type; |
| 551 | break; |
| 552 | case OZ_TIMER_HEARTBEAT: |
| 553 | if (!hrtimer_active(&pd->heartbeat)) |
| 554 | hrtimer_start(&pd->heartbeat, ktime_set(due_time / |
| 555 | MSEC_PER_SEC, (due_time % MSEC_PER_SEC) * |
| 556 | NSEC_PER_MSEC), HRTIMER_MODE_REL); |
Chris Kelly | 1619cb6 | 2012-02-20 21:11:28 +0000 | [diff] [blame] | 557 | break; |
| 558 | } |
Chris Kelly | 1619cb6 | 2012-02-20 21:11:28 +0000 | [diff] [blame] | 559 | spin_unlock_bh(&g_polling_lock); |
Chris Kelly | 1619cb6 | 2012-02-20 21:11:28 +0000 | [diff] [blame] | 560 | } |
| 561 | /*------------------------------------------------------------------------------ |
| 562 | * Context: softirq or process |
| 563 | */ |
| 564 | void oz_pd_request_heartbeat(struct oz_pd *pd) |
| 565 | { |
Rupesh Gujare | 8fd0700 | 2013-07-30 13:31:50 +0100 | [diff] [blame] | 566 | oz_timer_add(pd, OZ_TIMER_HEARTBEAT, pd->pulse_period > 0 ? |
| 567 | pd->pulse_period : OZ_QUANTUM); |
Chris Kelly | 1619cb6 | 2012-02-20 21:11:28 +0000 | [diff] [blame] | 568 | } |
| 569 | /*------------------------------------------------------------------------------ |
| 570 | * Context: softirq or process |
| 571 | */ |
Peter Huewe | dc7f5b3 | 2013-02-15 21:17:24 +0100 | [diff] [blame] | 572 | struct oz_pd *oz_pd_find(const u8 *mac_addr) |
Chris Kelly | 1619cb6 | 2012-02-20 21:11:28 +0000 | [diff] [blame] | 573 | { |
| 574 | struct oz_pd *pd; |
| 575 | struct list_head *e; |
| 576 | spin_lock_bh(&g_polling_lock); |
| 577 | list_for_each(e, &g_pd_list) { |
| 578 | pd = container_of(e, struct oz_pd, link); |
| 579 | if (memcmp(pd->mac_addr, mac_addr, ETH_ALEN) == 0) { |
| 580 | atomic_inc(&pd->ref_count); |
| 581 | spin_unlock_bh(&g_polling_lock); |
| 582 | return pd; |
| 583 | } |
| 584 | } |
| 585 | spin_unlock_bh(&g_polling_lock); |
Peter Huewe | 41ebb8a | 2013-02-15 15:22:25 +0100 | [diff] [blame] | 586 | return NULL; |
Chris Kelly | 1619cb6 | 2012-02-20 21:11:28 +0000 | [diff] [blame] | 587 | } |
| 588 | /*------------------------------------------------------------------------------ |
| 589 | * Context: process |
| 590 | */ |
| 591 | void oz_app_enable(int app_id, int enable) |
| 592 | { |
| 593 | if (app_id <= OZ_APPID_MAX) { |
| 594 | spin_lock_bh(&g_polling_lock); |
| 595 | if (enable) |
| 596 | g_apps |= (1<<app_id); |
| 597 | else |
| 598 | g_apps &= ~(1<<app_id); |
| 599 | spin_unlock_bh(&g_polling_lock); |
| 600 | } |
| 601 | } |
| 602 | /*------------------------------------------------------------------------------ |
| 603 | * Context: softirq |
| 604 | */ |
| 605 | static int oz_pkt_recv(struct sk_buff *skb, struct net_device *dev, |
| 606 | struct packet_type *pt, struct net_device *orig_dev) |
| 607 | { |
Chris Kelly | 1619cb6 | 2012-02-20 21:11:28 +0000 | [diff] [blame] | 608 | skb = skb_share_check(skb, GFP_ATOMIC); |
Peter Huewe | 41ebb8a | 2013-02-15 15:22:25 +0100 | [diff] [blame] | 609 | if (skb == NULL) |
Chris Kelly | 1619cb6 | 2012-02-20 21:11:28 +0000 | [diff] [blame] | 610 | return 0; |
| 611 | spin_lock_bh(&g_rx_queue.lock); |
| 612 | if (g_processing_rx) { |
| 613 | /* We already hold the lock so use __ variant. |
| 614 | */ |
| 615 | __skb_queue_head(&g_rx_queue, skb); |
| 616 | spin_unlock_bh(&g_rx_queue.lock); |
| 617 | } else { |
| 618 | g_processing_rx = 1; |
| 619 | do { |
| 620 | |
| 621 | spin_unlock_bh(&g_rx_queue.lock); |
| 622 | oz_rx_frame(skb); |
| 623 | spin_lock_bh(&g_rx_queue.lock); |
| 624 | if (skb_queue_empty(&g_rx_queue)) { |
| 625 | g_processing_rx = 0; |
| 626 | spin_unlock_bh(&g_rx_queue.lock); |
| 627 | break; |
| 628 | } |
| 629 | /* We already hold the lock so use __ variant. |
| 630 | */ |
| 631 | skb = __skb_dequeue(&g_rx_queue); |
| 632 | } while (1); |
| 633 | } |
| 634 | return 0; |
| 635 | } |
| 636 | /*------------------------------------------------------------------------------ |
| 637 | * Context: process |
| 638 | */ |
| 639 | void oz_binding_add(char *net_dev) |
| 640 | { |
| 641 | struct oz_binding *binding; |
Greg Kroah-Hartman | 1ec41a3 | 2012-03-02 16:51:09 -0800 | [diff] [blame] | 642 | |
Rupesh Gujare | fec9f24b | 2012-06-20 13:36:08 +0100 | [diff] [blame] | 643 | binding = kmalloc(sizeof(struct oz_binding), GFP_KERNEL); |
Chris Kelly | 1619cb6 | 2012-02-20 21:11:28 +0000 | [diff] [blame] | 644 | if (binding) { |
| 645 | binding->ptype.type = __constant_htons(OZ_ETHERTYPE); |
| 646 | binding->ptype.func = oz_pkt_recv; |
| 647 | memcpy(binding->name, net_dev, OZ_MAX_BINDING_LEN); |
| 648 | if (net_dev && *net_dev) { |
Joe Perches | f724b58 | 2013-07-23 13:45:00 +0100 | [diff] [blame] | 649 | oz_dbg(ON, "Adding binding: %s\n", net_dev); |
Chris Kelly | 1619cb6 | 2012-02-20 21:11:28 +0000 | [diff] [blame] | 650 | binding->ptype.dev = |
| 651 | dev_get_by_name(&init_net, net_dev); |
Peter Huewe | 41ebb8a | 2013-02-15 15:22:25 +0100 | [diff] [blame] | 652 | if (binding->ptype.dev == NULL) { |
Joe Perches | f724b58 | 2013-07-23 13:45:00 +0100 | [diff] [blame] | 653 | oz_dbg(ON, "Netdev %s not found\n", net_dev); |
Greg Kroah-Hartman | 1ec41a3 | 2012-03-02 16:51:09 -0800 | [diff] [blame] | 654 | kfree(binding); |
Peter Huewe | 41ebb8a | 2013-02-15 15:22:25 +0100 | [diff] [blame] | 655 | binding = NULL; |
Chris Kelly | 1619cb6 | 2012-02-20 21:11:28 +0000 | [diff] [blame] | 656 | } |
| 657 | } else { |
Joe Perches | f724b58 | 2013-07-23 13:45:00 +0100 | [diff] [blame] | 658 | oz_dbg(ON, "Binding to all netcards\n"); |
Peter Huewe | 41ebb8a | 2013-02-15 15:22:25 +0100 | [diff] [blame] | 659 | binding->ptype.dev = NULL; |
Chris Kelly | 1619cb6 | 2012-02-20 21:11:28 +0000 | [diff] [blame] | 660 | } |
| 661 | if (binding) { |
| 662 | dev_add_pack(&binding->ptype); |
| 663 | spin_lock_bh(&g_binding_lock); |
Rupesh Gujare | 8a3cac6 | 2013-08-01 18:40:00 +0100 | [diff] [blame^] | 664 | list_add_tail(&binding->link, &g_binding); |
Chris Kelly | 1619cb6 | 2012-02-20 21:11:28 +0000 | [diff] [blame] | 665 | spin_unlock_bh(&g_binding_lock); |
| 666 | } |
| 667 | } |
| 668 | } |
| 669 | /*------------------------------------------------------------------------------ |
| 670 | * Context: process |
| 671 | */ |
| 672 | static int compare_binding_name(char *s1, char *s2) |
| 673 | { |
| 674 | int i; |
| 675 | for (i = 0; i < OZ_MAX_BINDING_LEN; i++) { |
| 676 | if (*s1 != *s2) |
| 677 | return 0; |
| 678 | if (!*s1++) |
| 679 | return 1; |
| 680 | s2++; |
| 681 | } |
| 682 | return 1; |
| 683 | } |
| 684 | /*------------------------------------------------------------------------------ |
| 685 | * Context: process |
| 686 | */ |
| 687 | static void pd_stop_all_for_device(struct net_device *net_dev) |
| 688 | { |
| 689 | struct list_head h; |
| 690 | struct oz_pd *pd; |
| 691 | struct oz_pd *n; |
| 692 | INIT_LIST_HEAD(&h); |
| 693 | spin_lock_bh(&g_polling_lock); |
| 694 | list_for_each_entry_safe(pd, n, &g_pd_list, link) { |
| 695 | if (pd->net_dev == net_dev) { |
| 696 | list_move(&pd->link, &h); |
| 697 | oz_pd_get(pd); |
| 698 | } |
| 699 | } |
| 700 | spin_unlock_bh(&g_polling_lock); |
| 701 | while (!list_empty(&h)) { |
| 702 | pd = list_first_entry(&h, struct oz_pd, link); |
| 703 | oz_pd_stop(pd); |
| 704 | oz_pd_put(pd); |
| 705 | } |
| 706 | } |
| 707 | /*------------------------------------------------------------------------------ |
| 708 | * Context: process |
| 709 | */ |
| 710 | void oz_binding_remove(char *net_dev) |
| 711 | { |
Peter Huewe | 41ebb8a | 2013-02-15 15:22:25 +0100 | [diff] [blame] | 712 | struct oz_binding *binding; |
Rupesh Gujare | 8a3cac6 | 2013-08-01 18:40:00 +0100 | [diff] [blame^] | 713 | int found = 0; |
| 714 | |
Joe Perches | f724b58 | 2013-07-23 13:45:00 +0100 | [diff] [blame] | 715 | oz_dbg(ON, "Removing binding: %s\n", net_dev); |
Chris Kelly | 1619cb6 | 2012-02-20 21:11:28 +0000 | [diff] [blame] | 716 | spin_lock_bh(&g_binding_lock); |
Rupesh Gujare | 8a3cac6 | 2013-08-01 18:40:00 +0100 | [diff] [blame^] | 717 | list_for_each_entry(binding, &g_binding, link) { |
Chris Kelly | 1619cb6 | 2012-02-20 21:11:28 +0000 | [diff] [blame] | 718 | if (compare_binding_name(binding->name, net_dev)) { |
Joe Perches | f724b58 | 2013-07-23 13:45:00 +0100 | [diff] [blame] | 719 | oz_dbg(ON, "Binding '%s' found\n", net_dev); |
Rupesh Gujare | 8a3cac6 | 2013-08-01 18:40:00 +0100 | [diff] [blame^] | 720 | found = 1; |
Chris Kelly | 1619cb6 | 2012-02-20 21:11:28 +0000 | [diff] [blame] | 721 | break; |
Chris Kelly | 1619cb6 | 2012-02-20 21:11:28 +0000 | [diff] [blame] | 722 | } |
| 723 | } |
| 724 | spin_unlock_bh(&g_binding_lock); |
Rupesh Gujare | 8a3cac6 | 2013-08-01 18:40:00 +0100 | [diff] [blame^] | 725 | if (found) { |
Chris Kelly | 1619cb6 | 2012-02-20 21:11:28 +0000 | [diff] [blame] | 726 | dev_remove_pack(&binding->ptype); |
| 727 | if (binding->ptype.dev) { |
| 728 | dev_put(binding->ptype.dev); |
| 729 | pd_stop_all_for_device(binding->ptype.dev); |
| 730 | } |
Rupesh Gujare | 8a3cac6 | 2013-08-01 18:40:00 +0100 | [diff] [blame^] | 731 | list_del(&binding->link); |
Greg Kroah-Hartman | 1ec41a3 | 2012-03-02 16:51:09 -0800 | [diff] [blame] | 732 | kfree(binding); |
Chris Kelly | 1619cb6 | 2012-02-20 21:11:28 +0000 | [diff] [blame] | 733 | } |
| 734 | } |
| 735 | /*------------------------------------------------------------------------------ |
| 736 | * Context: process |
| 737 | */ |
| 738 | static char *oz_get_next_device_name(char *s, char *dname, int max_size) |
| 739 | { |
| 740 | while (*s == ',') |
| 741 | s++; |
| 742 | while (*s && (*s != ',') && max_size > 1) { |
| 743 | *dname++ = *s++; |
| 744 | max_size--; |
| 745 | } |
| 746 | *dname = 0; |
| 747 | return s; |
| 748 | } |
| 749 | /*------------------------------------------------------------------------------ |
| 750 | * Context: process |
| 751 | */ |
| 752 | int oz_protocol_init(char *devs) |
| 753 | { |
| 754 | skb_queue_head_init(&g_rx_queue); |
| 755 | if (devs && (devs[0] == '*')) { |
Peter Huewe | 41ebb8a | 2013-02-15 15:22:25 +0100 | [diff] [blame] | 756 | oz_binding_add(NULL); |
Chris Kelly | 1619cb6 | 2012-02-20 21:11:28 +0000 | [diff] [blame] | 757 | } else { |
| 758 | char d[32]; |
| 759 | while (*devs) { |
| 760 | devs = oz_get_next_device_name(devs, d, sizeof(d)); |
| 761 | if (d[0]) |
| 762 | oz_binding_add(d); |
| 763 | } |
| 764 | } |
Chris Kelly | 1619cb6 | 2012-02-20 21:11:28 +0000 | [diff] [blame] | 765 | return 0; |
| 766 | } |
| 767 | /*------------------------------------------------------------------------------ |
| 768 | * Context: process |
| 769 | */ |
| 770 | int oz_get_pd_list(struct oz_mac_addr *addr, int max_count) |
| 771 | { |
| 772 | struct oz_pd *pd; |
| 773 | struct list_head *e; |
| 774 | int count = 0; |
| 775 | spin_lock_bh(&g_polling_lock); |
| 776 | list_for_each(e, &g_pd_list) { |
| 777 | if (count >= max_count) |
| 778 | break; |
| 779 | pd = container_of(e, struct oz_pd, link); |
| 780 | memcpy(&addr[count++], pd->mac_addr, ETH_ALEN); |
| 781 | } |
| 782 | spin_unlock_bh(&g_polling_lock); |
| 783 | return count; |
| 784 | } |
| 785 | /*------------------------------------------------------------------------------ |
| 786 | */ |
| 787 | void oz_polling_lock_bh(void) |
| 788 | { |
| 789 | spin_lock_bh(&g_polling_lock); |
| 790 | } |
| 791 | /*------------------------------------------------------------------------------ |
| 792 | */ |
| 793 | void oz_polling_unlock_bh(void) |
| 794 | { |
| 795 | spin_unlock_bh(&g_polling_lock); |
| 796 | } |