2 * Copyright (c) 2012 GCT Semiconductor, Inc. All rights reserved.
4 * This software is licensed under the terms of the GNU General Public
5 * License version 2, as published by the Free Software Foundation, and
6 * may be copied, distributed, and modified under those terms.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
14 #include <linux/version.h>
15 #include <linux/etherdevice.h>
16 #include <asm/byteorder.h>
18 #include <linux/ipv6.h>
19 #include <linux/udp.h>
22 #include "gdm_wimax.h"
25 #include "netlink_k.h"
27 #define gdm_wimax_send(n, d, l) \
28 (n->phy_dev->send_func)(n->phy_dev->priv_dev, d, l, NULL, NULL)
29 #define gdm_wimax_send_with_cb(n, d, l, c, b) \
30 (n->phy_dev->send_func)(n->phy_dev->priv_dev, d, l, c, b)
31 #define gdm_wimax_rcv_with_cb(n, c, b) \
32 (n->phy_dev->rcv_func)(n->phy_dev->priv_dev, c, b)
34 #define EVT_MAX_SIZE 2048
37 struct list_head list
;
38 struct net_device
*dev
;
39 char evt_data
[EVT_MAX_SIZE
];
43 static void __gdm_wimax_event_send(struct work_struct
*work
);
44 static inline struct evt_entry
*alloc_event_entry(void);
45 static inline void free_event_entry(struct evt_entry
*e
);
46 static struct evt_entry
*get_event_entry(void);
47 static void put_event_entry(struct evt_entry
*e
);
52 struct list_head evtq
;
55 struct list_head freeq
;
56 struct work_struct ws
;
59 static u8 gdm_wimax_macaddr
[6] = {0x00, 0x0a, 0x3b, 0xf0, 0x01, 0x30};
61 static void gdm_wimax_ind_fsm_update(struct net_device
*dev
, struct fsm_s
*fsm
);
62 static void gdm_wimax_ind_if_updown(struct net_device
*dev
, int if_up
);
64 #if defined(DEBUG_SDU)
65 static void printk_hex(u8
*buf
, u32 size
)
69 for (i
= 0; i
< size
; i
++) {
71 printk(KERN_DEBUG
"\n%02x ", *buf
++);
73 printk(KERN_DEBUG
"%02x ", *buf
++);
76 printk(KERN_DEBUG
"\n");
79 static const char *get_protocol_name(u16 protocol
)
82 const char *name
= "-";
96 sprintf(buf
, "0x%04x(%s)", protocol
, name
);
100 static const char *get_ip_protocol_name(u8 ip_protocol
)
103 const char *name
= "-";
105 switch (ip_protocol
) {
117 sprintf(buf
, "%u(%s)", ip_protocol
, name
);
121 static const char *get_port_name(u16 port
)
124 const char *name
= "-";
128 name
= "DHCP-Server";
131 name
= "DHCP-Client";
138 sprintf(buf
, "%u(%s)", port
, name
);
142 static void dump_eth_packet(const char *title
, u8
*data
, int len
)
144 struct iphdr
*ih
= NULL
;
145 struct udphdr
*uh
= NULL
;
150 protocol
= (data
[12]<<8) | data
[13];
151 ih
= (struct iphdr
*) (data
+ETH_HLEN
);
153 if (protocol
== ETH_P_IP
) {
154 uh
= (struct udphdr
*) ((char *)ih
+ sizeof(struct iphdr
));
155 ip_protocol
= ih
->protocol
;
156 port
= ntohs(uh
->dest
);
157 } else if (protocol
== ETH_P_IPV6
) {
158 struct ipv6hdr
*i6h
= (struct ipv6hdr
*) data
;
159 uh
= (struct udphdr
*) ((char *)i6h
+ sizeof(struct ipv6hdr
));
160 ip_protocol
= i6h
->nexthdr
;
161 port
= ntohs(uh
->dest
);
164 printk(KERN_DEBUG
"[%s] len=%d, %s, %s, %s\n",
166 get_protocol_name(protocol
),
167 get_ip_protocol_name(ip_protocol
),
168 get_port_name(port
));
171 if (!(data
[0] == 0xff && data
[1] == 0xff)) {
172 if (protocol
== ETH_P_IP
) {
173 printk(KERN_DEBUG
" src=%u.%u.%u.%u\n",
175 } else if (protocol
== ETH_P_IPV6
) {
177 printk(KERN_DEBUG
" src=%x:%x:%x:%x:%x:%x:%x:%x\n",
180 printk(KERN_DEBUG
" src=%pI6\n", &ih
->saddr
);
186 #if (DUMP_PACKET & DUMP_SDU_ALL)
187 printk_hex(data
, len
);
189 #if (DUMP_PACKET & DUMP_SDU_ARP)
190 if (protocol
== ETH_P_ARP
)
191 printk_hex(data
, len
);
193 #if (DUMP_PACKET & DUMP_SDU_IP)
194 if (protocol
== ETH_P_IP
|| protocol
== ETH_P_IPV6
)
195 printk_hex(data
, len
);
197 #if (DUMP_PACKET & DUMP_SDU_IP_TCP)
198 if (ip_protocol
== IPPROTO_TCP
)
199 printk_hex(data
, len
);
201 #if (DUMP_PACKET & DUMP_SDU_IP_UDP)
202 if (ip_protocol
== IPPROTO_UDP
)
203 printk_hex(data
, len
);
205 #if (DUMP_PACKET & DUMP_SDU_IP_ICMP)
206 if (ip_protocol
== IPPROTO_ICMP
)
207 printk_hex(data
, len
);
215 static inline int gdm_wimax_header(struct sk_buff
**pskb
)
217 u16 buf
[HCI_HEADER_SIZE
/ sizeof(u16
)];
218 struct sk_buff
*skb
= *pskb
;
221 if (unlikely(skb_headroom(skb
) < HCI_HEADER_SIZE
)) {
222 struct sk_buff
*skb2
;
224 skb2
= skb_realloc_headroom(skb
, HCI_HEADER_SIZE
);
228 skb_set_owner_w(skb2
, skb
->sk
);
233 skb_push(skb
, HCI_HEADER_SIZE
);
234 buf
[0] = H2B(WIMAX_TX_SDU
);
235 buf
[1] = H2B(skb
->len
- HCI_HEADER_SIZE
);
236 memcpy(skb
->data
, buf
, HCI_HEADER_SIZE
);
242 static void gdm_wimax_event_rcv(struct net_device
*dev
, u16 type
, void *msg
,
245 struct nic
*nic
= netdev_priv(dev
);
247 #if defined(DEBUG_HCI)
248 u8
*buf
= (u8
*) msg
;
249 u16 hci_cmd
= (buf
[0]<<8) | buf
[1];
250 u16 hci_len
= (buf
[2]<<8) | buf
[3];
251 printk(KERN_DEBUG
"H=>D: 0x%04x(%d)\n", hci_cmd
, hci_len
);
254 gdm_wimax_send(nic
, msg
, len
);
257 static int gdm_wimax_event_init(void)
259 if (wm_event
.ref_cnt
== 0) {
260 wm_event
.sock
= netlink_init(NETLINK_WIMAX
,
261 gdm_wimax_event_rcv
);
262 INIT_LIST_HEAD(&wm_event
.evtq
);
263 INIT_LIST_HEAD(&wm_event
.freeq
);
264 INIT_WORK(&wm_event
.ws
, __gdm_wimax_event_send
);
265 spin_lock_init(&wm_event
.evt_lock
);
273 printk(KERN_ERR
"Creating WiMax Event netlink is failed\n");
277 static void gdm_wimax_event_exit(void)
279 if (wm_event
.sock
&& --wm_event
.ref_cnt
== 0) {
280 struct evt_entry
*e
, *temp
;
283 spin_lock_irqsave(&wm_event
.evt_lock
, flags
);
285 list_for_each_entry_safe(e
, temp
, &wm_event
.evtq
, list
) {
289 list_for_each_entry_safe(e
, temp
, &wm_event
.freeq
, list
) {
294 spin_unlock_irqrestore(&wm_event
.evt_lock
, flags
);
295 netlink_exit(wm_event
.sock
);
296 wm_event
.sock
= NULL
;
300 static inline struct evt_entry
*alloc_event_entry(void)
302 return kmalloc(sizeof(struct evt_entry
), GFP_ATOMIC
);
305 static inline void free_event_entry(struct evt_entry
*e
)
310 static struct evt_entry
*get_event_entry(void)
314 if (list_empty(&wm_event
.freeq
))
315 e
= alloc_event_entry();
317 e
= list_entry(wm_event
.freeq
.next
, struct evt_entry
, list
);
324 static void put_event_entry(struct evt_entry
*e
)
328 list_add_tail(&e
->list
, &wm_event
.freeq
);
331 static void __gdm_wimax_event_send(struct work_struct
*work
)
337 spin_lock_irqsave(&wm_event
.evt_lock
, flags
);
339 while (!list_empty(&wm_event
.evtq
)) {
340 e
= list_entry(wm_event
.evtq
.next
, struct evt_entry
, list
);
341 spin_unlock_irqrestore(&wm_event
.evt_lock
, flags
);
343 sscanf(e
->dev
->name
, "wm%d", &idx
);
344 netlink_send(wm_event
.sock
, idx
, 0, e
->evt_data
, e
->size
);
346 spin_lock_irqsave(&wm_event
.evt_lock
, flags
);
351 spin_unlock_irqrestore(&wm_event
.evt_lock
, flags
);
354 static int gdm_wimax_event_send(struct net_device
*dev
, char *buf
, int size
)
359 #if defined(DEBUG_HCI)
360 u16 hci_cmd
= ((u8
)buf
[0]<<8) | (u8
)buf
[1];
361 u16 hci_len
= ((u8
)buf
[2]<<8) | (u8
)buf
[3];
362 printk(KERN_DEBUG
"D=>H: 0x%04x(%d)\n", hci_cmd
, hci_len
);
365 spin_lock_irqsave(&wm_event
.evt_lock
, flags
);
367 e
= get_event_entry();
369 printk(KERN_ERR
"%s: No memory for event\n", __func__
);
370 spin_unlock_irqrestore(&wm_event
.evt_lock
, flags
);
376 memcpy(e
->evt_data
, buf
, size
);
378 list_add_tail(&e
->list
, &wm_event
.evtq
);
379 spin_unlock_irqrestore(&wm_event
.evt_lock
, flags
);
381 schedule_work(&wm_event
.ws
);
386 static void tx_complete(void *arg
)
388 struct nic
*nic
= arg
;
390 if (netif_queue_stopped(nic
->netdev
))
391 netif_wake_queue(nic
->netdev
);
394 int gdm_wimax_send_tx(struct sk_buff
*skb
, struct net_device
*dev
)
397 struct nic
*nic
= netdev_priv(dev
);
399 ret
= gdm_wimax_send_with_cb(nic
, skb
->data
, skb
->len
, tx_complete
,
401 if (ret
== -ENOSPC
) {
402 netif_stop_queue(dev
);
407 skb_pull(skb
, HCI_HEADER_SIZE
);
411 nic
->stats
.tx_packets
++;
412 nic
->stats
.tx_bytes
+= skb
->len
- HCI_HEADER_SIZE
;
417 static int gdm_wimax_tx(struct sk_buff
*skb
, struct net_device
*dev
)
420 struct nic
*nic
= netdev_priv(dev
);
421 struct fsm_s
*fsm
= (struct fsm_s
*) nic
->sdk_data
[SIOC_DATA_FSM
].buf
;
423 #if defined(DEBUG_SDU)
424 dump_eth_packet("TX", skb
->data
, skb
->len
);
427 ret
= gdm_wimax_header(&skb
);
429 skb_pull(skb
, HCI_HEADER_SIZE
);
433 #if !defined(LOOPBACK_TEST)
435 printk(KERN_ERR
"ASSERTION ERROR: fsm is NULL!!\n");
436 else if (fsm
->m_status
!= M_CONNECTED
) {
437 printk(KERN_EMERG
"ASSERTION ERROR: Device is NOT ready. status=%d\n",
444 #if defined(CONFIG_WIMAX_GDM72XX_QOS)
445 ret
= gdm_qos_send_hci_pkt(skb
, dev
);
447 ret
= gdm_wimax_send_tx(skb
, dev
);
452 static int gdm_wimax_set_config(struct net_device
*dev
, struct ifmap
*map
)
454 if (dev
->flags
& IFF_UP
)
460 static void __gdm_wimax_set_mac_addr(struct net_device
*dev
, char *mac_addr
)
462 u16 hci_pkt_buf
[32 / sizeof(u16
)];
463 u8
*pkt
= (u8
*) &hci_pkt_buf
[0];
464 struct nic
*nic
= netdev_priv(dev
);
466 /* Since dev is registered as a ethernet device,
467 * ether_setup has made dev->addr_len to be ETH_ALEN
469 memcpy(dev
->dev_addr
, mac_addr
, dev
->addr_len
);
471 /* Let lower layer know of this change by sending
472 * SetInformation(MAC Address)
474 hci_pkt_buf
[0] = H2B(WIMAX_SET_INFO
); /* cmd_evt */
475 hci_pkt_buf
[1] = H2B(8); /* size */
478 memcpy(pkt
+ 6, mac_addr
, dev
->addr_len
); /* V */
480 gdm_wimax_send(nic
, pkt
, HCI_HEADER_SIZE
+ 8);
483 /* A driver function */
484 static int gdm_wimax_set_mac_addr(struct net_device
*dev
, void *p
)
486 struct sockaddr
*addr
= p
;
488 if (netif_running(dev
))
491 if (!is_valid_ether_addr(addr
->sa_data
))
492 return -EADDRNOTAVAIL
;
494 __gdm_wimax_set_mac_addr(dev
, addr
->sa_data
);
499 static struct net_device_stats
*gdm_wimax_stats(struct net_device
*dev
)
501 struct nic
*nic
= netdev_priv(dev
);
506 static int gdm_wimax_open(struct net_device
*dev
)
508 struct nic
*nic
= netdev_priv(dev
);
509 struct fsm_s
*fsm
= (struct fsm_s
*) nic
->sdk_data
[SIOC_DATA_FSM
].buf
;
511 netif_start_queue(dev
);
513 if (fsm
&& fsm
->m_status
!= M_INIT
)
514 gdm_wimax_ind_if_updown(dev
, 1);
518 static int gdm_wimax_close(struct net_device
*dev
)
520 struct nic
*nic
= netdev_priv(dev
);
521 struct fsm_s
*fsm
= (struct fsm_s
*) nic
->sdk_data
[SIOC_DATA_FSM
].buf
;
523 netif_stop_queue(dev
);
525 if (fsm
&& fsm
->m_status
!= M_INIT
)
526 gdm_wimax_ind_if_updown(dev
, 0);
530 static void kdelete(void **buf
)
538 static int gdm_wimax_ioctl_get_data(struct data_s
*dst
, struct data_s
*src
)
542 size
= dst
->size
< src
->size
? dst
->size
: src
->size
;
548 if (copy_to_user(dst
->buf
, src
->buf
, size
))
554 static int gdm_wimax_ioctl_set_data(struct data_s
*dst
, struct data_s
*src
)
564 if (!(dst
->buf
&& dst
->size
== src
->size
)) {
566 dst
->buf
= kmalloc(src
->size
, GFP_KERNEL
);
567 if (dst
->buf
== NULL
)
571 if (copy_from_user(dst
->buf
, src
->buf
, src
->size
)) {
575 dst
->size
= src
->size
;
579 static void gdm_wimax_cleanup_ioctl(struct net_device
*dev
)
581 struct nic
*nic
= netdev_priv(dev
);
584 for (i
= 0; i
< SIOC_DATA_MAX
; i
++)
585 kdelete(&nic
->sdk_data
[i
].buf
);
588 static void gdm_update_fsm(struct net_device
*dev
, struct fsm_s
*new_fsm
)
590 struct nic
*nic
= netdev_priv(dev
);
591 struct fsm_s
*cur_fsm
=
592 (struct fsm_s
*) nic
->sdk_data
[SIOC_DATA_FSM
].buf
;
597 if (cur_fsm
->m_status
!= new_fsm
->m_status
||
598 cur_fsm
->c_status
!= new_fsm
->c_status
) {
599 if (new_fsm
->m_status
== M_CONNECTED
)
600 netif_carrier_on(dev
);
601 else if (cur_fsm
->m_status
== M_CONNECTED
) {
602 netif_carrier_off(dev
);
603 #if defined(CONFIG_WIMAX_GDM72XX_QOS)
604 gdm_qos_release_list(nic
);
607 gdm_wimax_ind_fsm_update(dev
, new_fsm
);
611 static int gdm_wimax_ioctl(struct net_device
*dev
, struct ifreq
*ifr
, int cmd
)
613 struct wm_req_s
*req
= (struct wm_req_s
*) ifr
;
614 struct nic
*nic
= netdev_priv(dev
);
617 if (cmd
!= SIOCWMIOCTL
)
623 if (req
->data_id
>= SIOC_DATA_MAX
) {
625 "%s error: data-index(%d) is invalid!!\n",
626 __func__
, req
->data_id
);
629 if (req
->cmd
== SIOCG_DATA
) {
630 ret
= gdm_wimax_ioctl_get_data(&req
->data
,
631 &nic
->sdk_data
[req
->data_id
]);
634 } else if (req
->cmd
== SIOCS_DATA
) {
635 if (req
->data_id
== SIOC_DATA_FSM
) {
636 /*NOTE: gdm_update_fsm should be called
637 before gdm_wimax_ioctl_set_data is called*/
639 (struct fsm_s
*) req
->data
.buf
);
641 ret
= gdm_wimax_ioctl_set_data(
642 &nic
->sdk_data
[req
->data_id
], &req
->data
);
648 printk(KERN_ERR
"%s: %x unknown ioctl\n", __func__
, cmd
);
655 static void gdm_wimax_prepare_device(struct net_device
*dev
)
657 struct nic
*nic
= netdev_priv(dev
);
658 u16 buf
[32 / sizeof(u16
)];
659 struct hci_s
*hci
= (struct hci_s
*) buf
;
663 #define BIT_MULTI_CS 0
666 #define BIT_AGGREGATION 3
668 /* GetInformation mac address */
670 hci
->cmd_evt
= H2B(WIMAX_GET_INFO
);
671 hci
->data
[len
++] = TLV_T(T_MAC_ADDRESS
);
672 hci
->length
= H2B(len
);
673 gdm_wimax_send(nic
, hci
, HCI_HEADER_SIZE
+len
);
675 val
= (1<<BIT_WIMAX
) | (1<<BIT_MULTI_CS
);
676 #if defined(CONFIG_WIMAX_GDM72XX_QOS)
679 #if defined(CONFIG_WIMAX_GDM72XX_WIMAX2)
680 val
|= (1<<BIT_AGGREGATION
);
685 hci
->cmd_evt
= H2B(WIMAX_SET_INFO
);
686 hci
->data
[len
++] = TLV_T(T_CAPABILITY
);
687 hci
->data
[len
++] = TLV_L(T_CAPABILITY
);
689 memcpy(&hci
->data
[len
], &val
, TLV_L(T_CAPABILITY
));
690 len
+= TLV_L(T_CAPABILITY
);
691 hci
->length
= H2B(len
);
692 gdm_wimax_send(nic
, hci
, HCI_HEADER_SIZE
+len
);
694 printk(KERN_INFO
"GDM WiMax Set CAPABILITY: 0x%08X\n", DB2H(val
));
697 static int gdm_wimax_hci_get_tlv(u8
*buf
, u8
*T
, u16
*L
, u8
**V
)
699 #define __U82U16(b) ((u16)((u8 *)(b))[0] | ((u16)((u8 *)(b))[1] << 8))
703 if (buf
[1] == 0x82) {
704 *L
= B2H(__U82U16(&buf
[2]));
705 next_pos
= 1/*type*/+3/*len*/;
708 next_pos
= 1/*type*/+1/*len*/;
712 next_pos
+= *L
/*length of val*/;
716 static int gdm_wimax_get_prepared_info(struct net_device
*dev
, char *buf
,
721 u16 cmd_evt
, cmd_len
;
722 int pos
= HCI_HEADER_SIZE
;
724 cmd_evt
= B2H(*(u16
*)&buf
[0]);
725 cmd_len
= B2H(*(u16
*)&buf
[2]);
727 if (len
< cmd_len
+ HCI_HEADER_SIZE
) {
728 printk(KERN_ERR
"%s: invalid length [%d/%d]\n", __func__
,
729 cmd_len
+ HCI_HEADER_SIZE
, len
);
733 if (cmd_evt
== WIMAX_GET_INFO_RESULT
) {
735 printk(KERN_ERR
"%s: len is too short [%x/%d]\n",
736 __func__
, cmd_evt
, len
);
740 pos
+= gdm_wimax_hci_get_tlv(&buf
[pos
], &T
, &L
, &V
);
741 if (T
== TLV_T(T_MAC_ADDRESS
)) {
742 if (L
!= dev
->addr_len
) {
744 "%s Invalid inofrmation result T/L "
745 "[%x/%d]\n", __func__
, T
, L
);
749 "MAC change [%02x:%02x:%02x:%02x:%02x:%02x]"
750 "->[%02x:%02x:%02x:%02x:%02x:%02x]\n",
751 dev
->dev_addr
[0], dev
->dev_addr
[1],
752 dev
->dev_addr
[2], dev
->dev_addr
[3],
753 dev
->dev_addr
[4], dev
->dev_addr
[5],
754 V
[0], V
[1], V
[2], V
[3], V
[4], V
[5]);
755 memcpy(dev
->dev_addr
, V
, dev
->addr_len
);
760 gdm_wimax_event_send(dev
, buf
, len
);
764 static void gdm_wimax_netif_rx(struct net_device
*dev
, char *buf
, int len
)
766 struct nic
*nic
= netdev_priv(dev
);
770 #if defined(DEBUG_SDU)
771 dump_eth_packet("RX", buf
, len
);
774 skb
= dev_alloc_skb(len
+ 2);
776 printk(KERN_ERR
"%s: dev_alloc_skb failed!\n", __func__
);
781 nic
->stats
.rx_packets
++;
782 nic
->stats
.rx_bytes
+= len
;
784 memcpy(skb_put(skb
, len
), buf
, len
);
787 skb
->protocol
= eth_type_trans(skb
, dev
); /* what will happen? */
789 ret
= in_interrupt() ? netif_rx(skb
) : netif_rx_ni(skb
);
790 if (ret
== NET_RX_DROP
)
791 printk(KERN_ERR
"%s skb dropped\n", __func__
);
794 static void gdm_wimax_transmit_aggr_pkt(struct net_device
*dev
, char *buf
,
797 #define HCI_PADDING_BYTE 4
798 #define HCI_RESERVED_BYTE 4
803 hci
= (struct hci_s
*) buf
;
805 if (B2H(hci
->cmd_evt
) != WIMAX_RX_SDU
) {
806 printk(KERN_ERR
"Wrong cmd_evt(0x%04X)\n",
811 length
= B2H(hci
->length
);
812 gdm_wimax_netif_rx(dev
, hci
->data
, length
);
815 /* Add padding size */
816 length
+= HCI_PADDING_BYTE
- (length
& 0x3);
819 length
+= HCI_HEADER_SIZE
+ HCI_RESERVED_BYTE
;
825 static void gdm_wimax_transmit_pkt(struct net_device
*dev
, char *buf
, int len
)
827 #if defined(CONFIG_WIMAX_GDM72XX_QOS)
828 struct nic
*nic
= netdev_priv(dev
);
830 u16 cmd_evt
, cmd_len
;
832 /* This code is added for certain rx packet to be ignored. */
836 cmd_evt
= B2H(*(u16
*)&buf
[0]);
837 cmd_len
= B2H(*(u16
*)&buf
[2]);
839 if (len
< cmd_len
+ HCI_HEADER_SIZE
) {
841 printk(KERN_ERR
"%s: invalid length [%d/%d]\n",
842 __func__
, cmd_len
+ HCI_HEADER_SIZE
, len
);
847 case WIMAX_RX_SDU_AGGR
:
848 gdm_wimax_transmit_aggr_pkt(dev
, &buf
[HCI_HEADER_SIZE
],
852 gdm_wimax_netif_rx(dev
, &buf
[HCI_HEADER_SIZE
], cmd_len
);
854 #if defined(CONFIG_WIMAX_GDM72XX_QOS)
855 case WIMAX_EVT_MODEM_REPORT
:
856 gdm_recv_qos_hci_packet(nic
, buf
, len
);
859 case WIMAX_SDU_TX_FLOW
:
861 if (!netif_queue_stopped(dev
))
862 netif_stop_queue(dev
);
863 } else if (buf
[4] == 1) {
864 if (netif_queue_stopped(dev
))
865 netif_wake_queue(dev
);
869 gdm_wimax_event_send(dev
, buf
, len
);
874 static void gdm_wimax_ind_fsm_update(struct net_device
*dev
, struct fsm_s
*fsm
)
876 u16 buf
[32 / sizeof(u16
)];
877 u8
*hci_pkt_buf
= (u8
*)&buf
[0];
879 /* Indicate updating fsm */
880 buf
[0] = H2B(WIMAX_FSM_UPDATE
);
881 buf
[1] = H2B(sizeof(struct fsm_s
));
882 memcpy(&hci_pkt_buf
[HCI_HEADER_SIZE
], fsm
, sizeof(struct fsm_s
));
884 gdm_wimax_event_send(dev
, hci_pkt_buf
,
885 HCI_HEADER_SIZE
+ sizeof(struct fsm_s
));
888 static void gdm_wimax_ind_if_updown(struct net_device
*dev
, int if_up
)
890 u16 buf
[32 / sizeof(u16
)];
891 struct hci_s
*hci
= (struct hci_s
*) buf
;
892 unsigned char up_down
;
894 up_down
= if_up
? WIMAX_IF_UP
: WIMAX_IF_DOWN
;
896 /* Indicate updating fsm */
897 hci
->cmd_evt
= H2B(WIMAX_IF_UPDOWN
);
898 hci
->length
= H2B(sizeof(up_down
));
899 hci
->data
[0] = up_down
;
901 gdm_wimax_event_send(dev
, (char *)hci
, HCI_HEADER_SIZE
+sizeof(up_down
));
904 static void rx_complete(void *arg
, void *data
, int len
)
906 struct nic
*nic
= arg
;
908 gdm_wimax_transmit_pkt(nic
->netdev
, data
, len
);
909 gdm_wimax_rcv_with_cb(nic
, rx_complete
, nic
);
912 static void prepare_rx_complete(void *arg
, void *data
, int len
)
914 struct nic
*nic
= arg
;
917 ret
= gdm_wimax_get_prepared_info(nic
->netdev
, data
, len
);
919 gdm_wimax_rcv_with_cb(nic
, rx_complete
, nic
);
922 printk(KERN_ERR
"get_prepared_info failed(%d)\n", ret
);
923 gdm_wimax_rcv_with_cb(nic
, prepare_rx_complete
, nic
);
925 /* Re-prepare WiMax device */
926 gdm_wimax_prepare_device(nic
->netdev
);
931 static void start_rx_proc(struct nic
*nic
)
933 gdm_wimax_rcv_with_cb(nic
, prepare_rx_complete
, nic
);
936 static struct net_device_ops gdm_netdev_ops
= {
937 .ndo_open
= gdm_wimax_open
,
938 .ndo_stop
= gdm_wimax_close
,
939 .ndo_set_config
= gdm_wimax_set_config
,
940 .ndo_start_xmit
= gdm_wimax_tx
,
941 .ndo_get_stats
= gdm_wimax_stats
,
942 .ndo_set_mac_address
= gdm_wimax_set_mac_addr
,
943 .ndo_do_ioctl
= gdm_wimax_ioctl
,
946 int register_wimax_device(struct phy_dev
*phy_dev
, struct device
*pdev
)
948 struct nic
*nic
= NULL
;
949 struct net_device
*dev
;
952 dev
= (struct net_device
*)alloc_netdev(sizeof(*nic
),
953 "wm%d", ether_setup
);
956 printk(KERN_ERR
"alloc_etherdev failed\n");
960 SET_NETDEV_DEV(dev
, pdev
);
962 dev
->netdev_ops
= &gdm_netdev_ops
;
963 dev
->flags
&= ~IFF_MULTICAST
;
964 memcpy(dev
->dev_addr
, gdm_wimax_macaddr
, sizeof(gdm_wimax_macaddr
));
966 nic
= netdev_priv(dev
);
967 memset(nic
, 0, sizeof(*nic
));
970 nic
->phy_dev
= phy_dev
;
971 phy_dev
->netdev
= dev
;
973 /* event socket init */
974 ret
= gdm_wimax_event_init();
976 printk(KERN_ERR
"Cannot create event.\n");
980 ret
= register_netdev(dev
);
984 #if defined(LOOPBACK_TEST)
985 netif_start_queue(dev
);
986 netif_carrier_on(dev
);
988 netif_carrier_off(dev
);
991 #ifdef CONFIG_WIMAX_GDM72XX_QOS
997 /* Prepare WiMax device */
998 gdm_wimax_prepare_device(dev
);
1003 printk(KERN_ERR
"register_netdev failed\n");
1008 void unregister_wimax_device(struct phy_dev
*phy_dev
)
1010 struct nic
*nic
= netdev_priv(phy_dev
->netdev
);
1011 struct fsm_s
*fsm
= (struct fsm_s
*) nic
->sdk_data
[SIOC_DATA_FSM
].buf
;
1014 fsm
->m_status
= M_INIT
;
1015 unregister_netdev(nic
->netdev
);
1017 gdm_wimax_event_exit();
1019 #if defined(CONFIG_WIMAX_GDM72XX_QOS)
1020 gdm_qos_release_list(nic
);
1023 gdm_wimax_cleanup_ioctl(phy_dev
->netdev
);
1025 free_netdev(nic
->netdev
);