15 #include <asm/byteorder.h>
17 #include <linux/ipv6.h>
18 #include <linux/udp.h>
26 #define gdm_wimax_send(n, d, l) \
27 (n->phy_dev->send_func)(n->phy_dev->priv_dev, d, l, NULL, NULL)
28 #define gdm_wimax_send_with_cb(n, d, l, c, b) \
29 (n->phy_dev->send_func)(n->phy_dev->priv_dev, d, l, c, b)
30 #define gdm_wimax_rcv_with_cb(n, c, b) \
31 (n->phy_dev->rcv_func)(n->phy_dev->priv_dev, c, b)
33 #define EVT_MAX_SIZE 2048
43 static inline struct evt_entry *alloc_event_entry(
void);
44 static inline void free_event_entry(
struct evt_entry *
e);
45 static struct evt_entry *get_event_entry(
void);
46 static void put_event_entry(
struct evt_entry *
e);
58 static u8 gdm_wimax_macaddr[6] = {0x00, 0x0a, 0x3b, 0xf0, 0x01, 0x30};
61 static void gdm_wimax_ind_if_updown(
struct net_device *
dev,
int if_up);
63 #if defined(DEBUG_SDU)
68 for (i = 0; i <
size; i++) {
81 const char *
name =
"-";
95 sprintf(buf,
"0x%04x(%s)", protocol, name);
99 static const char *get_ip_protocol_name(
u8 ip_protocol)
102 const char *name =
"-";
104 switch (ip_protocol) {
116 sprintf(buf,
"%u(%s)", ip_protocol, name);
120 static const char *get_port_name(
u16 port)
123 const char *name =
"-";
127 name =
"DHCP-Server";
130 name =
"DHCP-Client";
137 sprintf(buf,
"%u(%s)", port, name);
141 static void dump_eth_packet(
const char *title,
u8 *
data,
int len)
149 protocol = (data[12]<<8) | data[13];
153 uh = (
struct udphdr *) ((
char *)ih +
sizeof(
struct iphdr));
158 uh = (
struct udphdr *) ((
char *)i6h +
sizeof(
struct ipv6hdr));
165 get_protocol_name(protocol),
166 get_ip_protocol_name(ip_protocol),
167 get_port_name(port));
170 if (!(data[0] == 0xff && data[1] == 0xff)) {
185 #if (DUMP_PACKET & DUMP_SDU_ALL)
186 printk_hex(data, len);
188 #if (DUMP_PACKET & DUMP_SDU_ARP)
190 printk_hex(data, len);
192 #if (DUMP_PACKET & DUMP_SDU_IP)
194 printk_hex(data, len);
196 #if (DUMP_PACKET & DUMP_SDU_IP_TCP)
198 printk_hex(data, len);
200 #if (DUMP_PACKET & DUMP_SDU_IP_UDP)
202 printk_hex(data, len);
204 #if (DUMP_PACKET & DUMP_SDU_IP_ICMP)
206 printk_hex(data, len);
214 static inline int gdm_wimax_header(
struct sk_buff **pskb)
227 skb_set_owner_w(skb2, skb->
sk);
244 struct nic *nic = netdev_priv(dev);
246 #if defined(DEBUG_HCI)
247 u8 *buf = (
u8 *) msg;
248 u16 hci_cmd = (buf[0]<<8) | buf[1];
249 u16 hci_len = (buf[2]<<8) | buf[3];
256 static int gdm_wimax_event_init(
void)
258 if (!wm_event.ref_cnt) {
260 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);
278 static void gdm_wimax_event_exit(
void)
280 if (wm_event.sock && --wm_event.ref_cnt == 0) {
295 spin_unlock_irqrestore(&wm_event.evt_lock, flags);
297 wm_event.sock =
NULL;
301 static inline struct evt_entry *alloc_event_entry(
void)
306 static inline void free_event_entry(
struct evt_entry *
e)
311 static struct evt_entry *get_event_entry(
void)
315 if (list_empty(&wm_event.freeq))
316 e = alloc_event_entry();
325 static void put_event_entry(
struct evt_entry *e)
340 while (!list_empty(&wm_event.evtq)) {
342 spin_unlock_irqrestore(&wm_event.evt_lock, flags);
352 spin_unlock_irqrestore(&wm_event.evt_lock, flags);
355 static int gdm_wimax_event_send(
struct net_device *
dev,
char *buf,
int size)
360 #if defined(DEBUG_HCI)
361 u16 hci_cmd = ((
u8)buf[0]<<8) | (
u8)buf[1];
362 u16 hci_len = ((
u8)buf[2]<<8) | (
u8)buf[3];
368 e = get_event_entry();
371 spin_unlock_irqrestore(&wm_event.evt_lock, flags);
380 spin_unlock_irqrestore(&wm_event.evt_lock, flags);
387 static void tx_complete(
void *
arg)
389 struct nic *nic =
arg;
391 if (netif_queue_stopped(nic->netdev))
392 netif_wake_queue(nic->netdev);
398 struct nic *nic = netdev_priv(dev);
403 netif_stop_queue(dev);
412 nic->stats.tx_packets++;
421 struct nic *nic = netdev_priv(dev);
424 #
if defined(DEBUG_SDU)
425 dump_eth_packet(
"TX", skb->
data, skb->
len);
428 ret = gdm_wimax_header(&skb);
434 #if !defined(LOOPBACK_TEST)
445 #if defined(CONFIG_WIMAX_GDM72XX_QOS)
463 u16 hci_pkt_buf[32 /
sizeof(
u16)];
464 u8 *pkt = (
u8 *) &hci_pkt_buf[0];
465 struct nic *nic = netdev_priv(dev);
476 hci_pkt_buf[1] =
H2B(8);
485 static int gdm_wimax_set_mac_addr(
struct net_device *dev,
void *
p)
489 if (netif_running(dev))
492 if (!is_valid_ether_addr(addr->
sa_data))
495 __gdm_wimax_set_mac_addr(dev, addr->
sa_data);
502 struct nic *nic = netdev_priv(dev);
507 static int gdm_wimax_open(
struct net_device *dev)
509 struct nic *nic = netdev_priv(dev);
512 netif_start_queue(dev);
515 gdm_wimax_ind_if_updown(dev, 1);
519 static int gdm_wimax_close(
struct net_device *dev)
521 struct nic *nic = netdev_priv(dev);
524 netif_stop_queue(dev);
527 gdm_wimax_ind_if_updown(dev, 0);
531 static void kdelete(
void **buf)
555 static int gdm_wimax_ioctl_set_data(
struct data_s *dst,
struct data_s *src)
580 static void gdm_wimax_cleanup_ioctl(
struct net_device *dev)
582 struct nic *nic = netdev_priv(dev);
586 kdelete(&nic->sdk_data[i].buf);
589 static void gdm_update_fsm(
struct net_device *dev,
struct fsm_s *new_fsm)
591 struct nic *nic = netdev_priv(dev);
592 struct fsm_s *cur_fsm =
604 #if defined(CONFIG_WIMAX_GDM72XX_QOS)
608 gdm_wimax_ind_fsm_update(dev, new_fsm);
615 struct nic *nic = netdev_priv(dev);
624 if (req->
data_id >= SIOC_DATA_MAX) {
626 "%s error: data-index(%d) is invalid!!\n",
631 ret = gdm_wimax_ioctl_get_data(&req->
data,
642 ret = gdm_wimax_ioctl_set_data(
656 static void gdm_wimax_prepare_device(
struct net_device *dev)
658 struct nic *nic = netdev_priv(dev);
659 u16 buf[32 /
sizeof(
u16)];
664 #define BIT_MULTI_CS 0
667 #define BIT_AGGREGATION 3
676 val = (1<<
BIT_WIMAX) | (1<<BIT_MULTI_CS);
677 #if defined(CONFIG_WIMAX_GDM72XX_QOS)
680 #if defined(CONFIG_WIMAX_GDM72XX_WIMAX2)
698 static int gdm_wimax_hci_get_tlv(
u8 *buf,
u8 *
T,
u16 *L,
u8 **
V)
700 #define __U82U16(b) ((u16)((u8 *)(b))[0] | ((u16)((u8 *)(b))[1] << 8))
704 if (buf[1] == 0x82) {
717 static int gdm_wimax_get_prepared_info(
struct net_device *dev,
char *buf,
725 cmd_evt =
B2H(*(
u16 *)&buf[0]);
726 cmd_len =
B2H(*(
u16 *)&buf[2]);
737 __func__, cmd_evt, len);
741 pos += gdm_wimax_hci_get_tlv(&buf[pos], &T, &L, &V);
745 "%s Invalid inofrmation result T/L "
746 "[%x/%d]\n", __func__, T, L);
756 gdm_wimax_event_send(dev, buf, len);
760 static void gdm_wimax_netif_rx(
struct net_device *dev,
char *buf,
int len)
762 struct nic *nic = netdev_priv(dev);
766 #if defined(DEBUG_SDU)
767 dump_eth_packet(
"RX", buf, len);
770 skb = dev_alloc_skb(len + 2);
777 nic->stats.rx_packets++;
778 nic->stats.rx_bytes +=
len;
790 static void gdm_wimax_transmit_aggr_pkt(
struct net_device *dev,
char *buf,
793 #define HCI_PADDING_BYTE 4
794 #define HCI_RESERVED_BYTE 4
799 hci = (
struct hci_s *) buf;
808 gdm_wimax_netif_rx(dev, hci->
data, length);
821 static void gdm_wimax_transmit_pkt(
struct net_device *dev,
char *buf,
int len)
823 #if defined(CONFIG_WIMAX_GDM72XX_QOS)
824 struct nic *nic = netdev_priv(dev);
832 cmd_evt =
B2H(*(
u16 *)&buf[0]);
833 cmd_len =
B2H(*(
u16 *)&buf[2]);
850 #if defined(CONFIG_WIMAX_GDM72XX_QOS)
857 if (!netif_queue_stopped(dev))
858 netif_stop_queue(dev);
859 }
else if (buf[4] == 1) {
860 if (netif_queue_stopped(dev))
861 netif_wake_queue(dev);
865 gdm_wimax_event_send(dev, buf, len);
870 static void gdm_wimax_ind_fsm_update(
struct net_device *dev,
struct fsm_s *fsm)
872 u16 buf[32 /
sizeof(
u16)];
873 u8 *hci_pkt_buf = (
u8 *)&buf[0];
880 gdm_wimax_event_send(dev, hci_pkt_buf,
881 HCI_HEADER_SIZE +
sizeof(
struct fsm_s));
884 static void gdm_wimax_ind_if_updown(
struct net_device *dev,
int if_up)
886 u16 buf[32 /
sizeof(
u16)];
888 unsigned char up_down;
895 hci->
data[0] = up_down;
897 gdm_wimax_event_send(dev, (
char *)hci, HCI_HEADER_SIZE+
sizeof(up_down));
900 static void rx_complete(
void *arg,
void *data,
int len)
902 struct nic *nic =
arg;
904 gdm_wimax_transmit_pkt(nic->netdev, data, len);
908 static void prepare_rx_complete(
void *arg,
void *data,
int len)
910 struct nic *nic =
arg;
913 ret = gdm_wimax_get_prepared_info(nic->netdev, data, len);
922 gdm_wimax_prepare_device(nic->netdev);
927 static void start_rx_proc(
struct nic *nic)
933 .ndo_open = gdm_wimax_open,
934 .ndo_stop = gdm_wimax_close,
935 .ndo_set_config = gdm_wimax_set_config,
936 .ndo_start_xmit = gdm_wimax_tx,
937 .ndo_get_stats = gdm_wimax_stats,
938 .ndo_set_mac_address = gdm_wimax_set_mac_addr,
939 .ndo_do_ioctl = gdm_wimax_ioctl,
944 struct nic *nic =
NULL;
960 memcpy(dev->
dev_addr, gdm_wimax_macaddr,
sizeof(gdm_wimax_macaddr));
962 nic = netdev_priv(dev);
963 memset(nic, 0,
sizeof(*nic));
966 nic->phy_dev = phy_dev;
970 ret = gdm_wimax_event_init();
980 #if defined(LOOPBACK_TEST)
981 netif_start_queue(dev);
987 #ifdef CONFIG_WIMAX_GDM72XX_QOS
994 gdm_wimax_prepare_device(dev);
1006 struct nic *nic = netdev_priv(phy_dev->
netdev);
1013 gdm_wimax_event_exit();
1015 #if defined(CONFIG_WIMAX_GDM72XX_QOS)
1019 gdm_wimax_cleanup_ioctl(phy_dev->
netdev);