7 #include <linux/module.h>
9 #include <linux/sched.h>
10 #include <linux/netdevice.h>
11 #include <linux/errno.h>
22 #include <asm/unaligned.h>
27 #define OZ_CF_CONN_SUCCESS 1
28 #define OZ_CF_CONN_FAILURE 2
35 #define OZ_TIMER_IDLE 0
36 #define OZ_TIMER_SET 1
37 #define OZ_TIMER_IN_HANDLER 2
39 #define OZ_MAX_TIMER_POOL_SIZE 16
63 static u8 g_session_id;
64 static u16 g_apps = 0x1;
65 static int g_processing_rx;
69 static int g_timer_pool_count;
74 static void oz_protocol_timer_start(
void);
78 static u8 oz_get_new_session_id(
u8 exclude)
80 if (++g_session_id == 0)
82 if (g_session_id == exclude) {
83 if (++g_session_id == 0)
104 skb_reset_network_header(skb);
105 oz_hdr = (
struct oz_hdr *)
skb_put(skb, sz);
106 elt = (
struct oz_elt *)(oz_hdr+1);
129 oz_trace(
"TX: OZ_ELT_CONNECT_RSP %d", status);
136 static void pd_set_keepalive(
struct oz_pd *pd,
u8 kalive)
162 static void pd_set_presleep(
struct oz_pd *pd,
u8 presleep)
173 static struct oz_pd *oz_connect_req(
struct oz_pd *cur_pd,
struct oz_elt *elt,
181 u16 new_apps = g_apps;
183 struct oz_pd *free_pd = 0;
186 spin_lock_bh(&g_polling_lock);
188 struct oz_pd *pd2 = 0;
194 spin_lock_bh(&g_polling_lock);
207 spin_unlock_bh(&g_polling_lock);
239 oz_trace(
"Max frame:%u Ms per isoc:%u\n",
244 pd_set_presleep(pd, body->
presleep);
274 spin_unlock_bh(&g_polling_lock);
277 oz_trace(
"new_apps=0x%x total_apps=0x%x paused_apps=0x%x\n",
290 spin_unlock_bh(&g_polling_lock);
292 oz_send_conn_rsp(pd, rsp_status);
300 dev_put(old_net_dev);
308 static void oz_add_farewell(
struct oz_pd *pd,
u8 ep_num,
u8 index,
320 oz_trace(
"RX: Adding farewell report\n");
321 spin_lock(&g_polling_lock);
323 if ((f2->
ep_num == ep_num) && (f2->
index == index)) {
330 spin_unlock(&g_polling_lock);
337 static void oz_rx_frame(
struct sk_buff *skb)
343 struct oz_pd *pd = 0;
344 struct oz_hdr *oz_hdr = (
struct oz_hdr *)skb_network_header(skb);
352 "RX frame PN=0x%x LPN=0x%x control=0x%x\n",
354 mac_hdr = skb_mac_header(skb);
360 oz_trace(
"Incorrect protocol version: %d\n",
396 length -=
sizeof(
struct oz_hdr);
397 elt = (
struct oz_elt *)((
u8 *)oz_hdr +
sizeof(
struct oz_hdr));
399 while (length >=
sizeof(
struct oz_elt)) {
400 length -=
sizeof(
struct oz_elt) + elt->length;
406 oz_trace(
"RX: OZ_ELT_CONNECT_REQ\n");
407 pd = oz_connect_req(pd, elt, src_addr, skb->
dev);
410 oz_trace(
"RX: OZ_ELT_DISCONNECT\n");
417 oz_trace(
"RX: OZ_ELT_UPDATE_PARAM_REQ\n");
419 spin_lock(&g_polling_lock);
421 pd_set_presleep(pd, body->
presleep);
422 spin_unlock(&g_polling_lock);
429 oz_trace(
"RX: OZ_ELT_FAREWELL_REQ\n");
430 oz_add_farewell(pd, body->
ep_num,
432 elt->
length + 1 -
sizeof(*body));
463 spin_lock_bh(&g_binding_lock);
467 spin_unlock_bh(&g_binding_lock);
470 dev_put(b->
ptype.dev);
472 spin_lock_bh(&g_binding_lock);
474 spin_unlock_bh(&g_binding_lock);
479 spin_lock_bh(&g_polling_lock);
480 while (!list_empty(&g_pd_list)) {
484 spin_unlock_bh(&g_polling_lock);
487 spin_lock_bh(&g_polling_lock);
489 chain = g_timer_pool;
491 spin_unlock_bh(&g_polling_lock);
502 static void oz_pd_handle_timer(
struct oz_pd *pd,
int type)
513 spin_lock_bh(&g_polling_lock);
517 spin_unlock_bh(&g_polling_lock);
527 static void oz_protocol_timer(
unsigned long arg)
532 spin_lock_bh(&g_polling_lock);
538 spin_unlock_bh(&g_polling_lock);
545 spin_unlock_bh(&g_polling_lock);
549 oz_pd_handle_timer(pd, t->
type);
550 spin_lock_bh(&g_polling_lock);
552 t->
link.next = g_timer_pool;
553 g_timer_pool = &t->
link;
554 g_timer_pool_count++;
557 if (!list_empty(&g_timer_list)) {
567 spin_unlock_bh(&g_polling_lock);
574 oz_protocol_timer_start();
579 static void oz_protocol_timer_start(
void)
581 spin_lock_bh(&g_polling_lock);
582 if (!list_empty(&g_timer_list)) {
594 g_timer.expires = g_cur_timer->
due_time;
595 g_timer.function = oz_protocol_timer;
603 spin_unlock_bh(&g_polling_lock);
613 int restart_needed = 0;
615 spin_lock(&g_polling_lock);
619 if ((t->
pd == pd) && (t->
type == type)) {
620 if (g_cur_timer == t) {
633 g_timer_pool = g_timer_pool->
next;
634 g_timer_pool_count--;
650 if (t2 == g_cur_timer) {
663 spin_unlock(&g_polling_lock);
665 oz_protocol_timer_start();
675 int restart_needed = 0;
678 spin_lock(&g_polling_lock);
680 if ((t->
pd == pd) && ((type == 0) || (t->
type == type))) {
681 if (g_cur_timer == t) {
689 t->
link.next = g_timer_pool;
690 g_timer_pool = &t->
link;
691 g_timer_pool_count++;
702 else if (restart_needed)
704 spin_unlock(&g_polling_lock);
706 oz_protocol_timer_start();
722 spin_lock(&g_polling_lock);
724 spin_unlock(&g_polling_lock);
732 spin_unlock(&g_polling_lock);
742 spin_lock_bh(&g_polling_lock);
747 spin_unlock_bh(&g_polling_lock);
751 spin_unlock_bh(&g_polling_lock);
760 spin_lock_bh(&g_polling_lock);
762 g_apps |= (1<<app_id);
764 g_apps &= ~(1<<app_id);
765 spin_unlock_bh(&g_polling_lock);
778 spin_lock_bh(&g_rx_queue.lock);
779 if (g_processing_rx) {
782 __skb_queue_head(&g_rx_queue, skb);
783 spin_unlock_bh(&g_rx_queue.lock);
788 spin_unlock_bh(&g_rx_queue.lock);
790 spin_lock_bh(&g_rx_queue.lock);
791 if (skb_queue_empty(&g_rx_queue)) {
793 spin_unlock_bh(&g_rx_queue.lock);
798 skb = __skb_dequeue(&g_rx_queue);
813 binding->
ptype.func = oz_pkt_recv;
815 if (net_dev && *net_dev) {
816 oz_trace(
"Adding binding: %s\n", net_dev);
819 if (binding->
ptype.dev == 0) {
820 oz_trace(
"Netdev %s not found\n", net_dev);
825 oz_trace(
"Binding to all netcards\n");
826 binding->
ptype.dev = 0;
830 spin_lock_bh(&g_binding_lock);
831 binding->
next = g_binding;
833 spin_unlock_bh(&g_binding_lock);
840 static int compare_binding_name(
char *
s1,
char *
s2)
855 static void pd_stop_all_for_device(
struct net_device *net_dev)
861 spin_lock_bh(&g_polling_lock);
864 list_move(&pd->
link, &
h);
868 spin_unlock_bh(&g_polling_lock);
869 while (!list_empty(&
h)) {
882 oz_trace(
"Removing binding: %s\n", net_dev);
883 spin_lock_bh(&g_binding_lock);
887 if (compare_binding_name(binding->
name, net_dev)) {
888 oz_trace(
"Binding '%s' found\n", net_dev);
889 *link = binding->
next;
893 binding = binding->
next;
896 spin_unlock_bh(&g_binding_lock);
899 if (binding->
ptype.dev) {
900 dev_put(binding->
ptype.dev);
901 pd_stop_all_for_device(binding->
ptype.dev);
909 static char *oz_get_next_device_name(
char *
s,
char *dname,
int max_size)
913 while (*s && (*s !=
',') && max_size > 1) {
925 skb_queue_head_init(&g_rx_queue);
926 if (devs && (devs[0] ==
'*')) {
931 devs = oz_get_next_device_name(devs, d,
sizeof(d));
947 spin_lock_bh(&g_polling_lock);
949 if (count >= max_count)
954 spin_unlock_bh(&g_polling_lock);
961 spin_lock_bh(&g_polling_lock);
967 spin_unlock_bh(&g_polling_lock);