4 module_param(debug
, uint
, 0600);
5 MODULE_PARM_DESC(debug
, "Debug level (0=none,...,16=all)");
7 static const u32 default_msg
=
8 NETIF_MSG_DRV
| NETIF_MSG_PROBE
| NETIF_MSG_LINK
9 | NETIF_MSG_TIMER
| NETIF_MSG_TX_ERR
| NETIF_MSG_RX_ERR
10 | NETIF_MSG_IFUP
| NETIF_MSG_IFDOWN
;
12 struct net_device
*gblpnetdev
;
14 static INT
bcm_open(struct net_device
*dev
)
16 PMINI_ADAPTER Adapter
= GET_BCM_ADAPTER(dev
);
18 if (Adapter
->fw_download_done
== FALSE
) {
19 pr_notice(DRV_NAME
"%s: link up failed (download in progress)\n",
24 if (netif_msg_ifup(Adapter
))
25 pr_info(DRV_NAME
"%s: enabling interface\n", dev
->name
);
27 if (Adapter
->LinkUpStatus
) {
28 if (netif_msg_link(Adapter
))
29 pr_info(DRV_NAME
"%s: link up\n", dev
->name
);
31 netif_carrier_on(Adapter
->dev
);
32 netif_start_queue(Adapter
->dev
);
38 static INT
bcm_close(struct net_device
*dev
)
40 PMINI_ADAPTER Adapter
= GET_BCM_ADAPTER(dev
);
42 if (netif_msg_ifdown(Adapter
))
43 pr_info(DRV_NAME
"%s: disabling interface\n", dev
->name
);
45 netif_carrier_off(dev
);
46 netif_stop_queue(dev
);
51 static struct net_device_stats
*bcm_get_stats(struct net_device
*dev
)
53 PMINI_ADAPTER Adapter
= GET_BCM_ADAPTER(dev
);
54 struct net_device_stats
* netstats
= &dev
->stats
;
56 netstats
->rx_packets
= atomic_read(&Adapter
->RxRollOverCount
)*64*1024
57 + Adapter
->PrevNumRecvDescs
;
58 netstats
->rx_bytes
= atomic_read(&Adapter
->GoodRxByteCount
)
59 + atomic_read(&Adapter
->BadRxByteCount
);
61 netstats
->rx_dropped
= atomic_read(&Adapter
->RxPacketDroppedCount
);
62 netstats
->rx_errors
= atomic_read(&Adapter
->RxPacketDroppedCount
);
63 netstats
->tx_bytes
= atomic_read(&Adapter
->GoodTxByteCount
);
64 netstats
->tx_packets
= atomic_read(&Adapter
->TxTotalPacketCount
);
65 netstats
->tx_dropped
= atomic_read(&Adapter
->TxDroppedPacketCount
);
70 static u16
bcm_select_queue(struct net_device
*dev
, struct sk_buff
*skb
)
72 return ClassifyPacket(netdev_priv(dev
), skb
);
75 /*******************************************************************
76 * Function - bcm_transmit()
78 * Description - This is the main transmit function for our virtual
79 * interface(eth0). It handles the ARP packets. It
80 * clones this packet and then Queue it to a suitable
81 * Queue. Then calls the transmit_packet().
83 * Parameter - skb - Pointer to the socket buffer structure
84 * dev - Pointer to the virtual net device structure
86 *********************************************************************/
88 static netdev_tx_t
bcm_transmit(struct sk_buff
*skb
, struct net_device
*dev
)
90 PMINI_ADAPTER Adapter
= GET_BCM_ADAPTER(dev
);
91 u16 qindex
= skb_get_queue_mapping(skb
);
94 if (Adapter
->device_removed
|| !Adapter
->LinkUpStatus
)
97 if (Adapter
->TransferMode
!= IP_PACKET_ONLY_MODE
)
100 if (INVALID_QUEUE_INDEX
== qindex
)
103 if (Adapter
->PackInfo
[qindex
].uiCurrentPacketsOnHost
>=
104 SF_MAX_ALLOWED_PACKETS_TO_BACKUP
)
105 return NETDEV_TX_BUSY
;
107 /* Now Enqueue the packet */
108 if (netif_msg_tx_queued(Adapter
))
109 pr_info(DRV_NAME
"%s: enqueueing packet to queue %d\n",
112 spin_lock(&Adapter
->PackInfo
[qindex
].SFQueueLock
);
113 Adapter
->PackInfo
[qindex
].uiCurrentBytesOnHost
+= skb
->len
;
114 Adapter
->PackInfo
[qindex
].uiCurrentPacketsOnHost
++;
116 *((B_UINT32
*) skb
->cb
+ SKB_CB_LATENCY_OFFSET
) = jiffies
;
117 ENQUEUEPACKET(Adapter
->PackInfo
[qindex
].FirstTxQueue
,
118 Adapter
->PackInfo
[qindex
].LastTxQueue
, skb
);
119 atomic_inc(&Adapter
->TotalPacketCount
);
120 spin_unlock(&Adapter
->PackInfo
[qindex
].SFQueueLock
);
122 /* FIXME - this is racy and incorrect, replace with work queue */
123 if (!atomic_read(&Adapter
->TxPktAvail
)) {
124 atomic_set(&Adapter
->TxPktAvail
, 1);
125 wake_up(&Adapter
->tx_packet_wait_queue
);
137 @ingroup init_functions
138 Register other driver entry points with the kernel
140 static const struct net_device_ops bcmNetDevOps
= {
141 .ndo_open
= bcm_open
,
142 .ndo_stop
= bcm_close
,
143 .ndo_get_stats
= bcm_get_stats
,
144 .ndo_start_xmit
= bcm_transmit
,
145 .ndo_change_mtu
= eth_change_mtu
,
146 .ndo_set_mac_address
= eth_mac_addr
,
147 .ndo_validate_addr
= eth_validate_addr
,
148 .ndo_select_queue
= bcm_select_queue
,
151 static struct device_type wimax_type
= {
155 static int bcm_get_settings(struct net_device
*dev
, struct ethtool_cmd
*cmd
)
158 cmd
->advertising
= 0;
159 cmd
->speed
= SPEED_10000
;
160 cmd
->duplex
= DUPLEX_FULL
;
162 cmd
->phy_address
= 0;
163 cmd
->transceiver
= XCVR_INTERNAL
;
164 cmd
->autoneg
= AUTONEG_DISABLE
;
170 static void bcm_get_drvinfo(struct net_device
*dev
, struct ethtool_drvinfo
*info
)
172 PMINI_ADAPTER Adapter
= GET_BCM_ADAPTER(dev
);
173 PS_INTERFACE_ADAPTER psIntfAdapter
= Adapter
->pvInterfaceAdapter
;
174 struct usb_device
*udev
= interface_to_usbdev(psIntfAdapter
->interface
);
176 strcpy(info
->driver
, DRV_NAME
);
177 strcpy(info
->version
, DRV_VERSION
);
178 snprintf(info
->fw_version
, sizeof(info
->fw_version
), "%u.%u",
179 Adapter
->uiFlashLayoutMajorVersion
,
180 Adapter
->uiFlashLayoutMinorVersion
);
182 usb_make_path(udev
, info
->bus_info
, sizeof(info
->bus_info
));
185 static u32
bcm_get_link(struct net_device
*dev
)
187 PMINI_ADAPTER Adapter
= GET_BCM_ADAPTER(dev
);
189 return Adapter
->LinkUpStatus
;
192 static u32
bcm_get_msglevel (struct net_device
*dev
)
194 PMINI_ADAPTER Adapter
= GET_BCM_ADAPTER(dev
);
196 return Adapter
->msg_enable
;
199 static void bcm_set_msglevel (struct net_device
*dev
, u32 level
)
201 PMINI_ADAPTER Adapter
= GET_BCM_ADAPTER(dev
);
203 Adapter
->msg_enable
= level
;
206 static const struct ethtool_ops bcm_ethtool_ops
= {
207 .get_settings
= bcm_get_settings
,
208 .get_drvinfo
= bcm_get_drvinfo
,
209 .get_link
= bcm_get_link
,
210 .get_msglevel
= bcm_get_msglevel
,
211 .set_msglevel
= bcm_set_msglevel
,
214 int register_networkdev(PMINI_ADAPTER Adapter
)
216 struct net_device
*net
= Adapter
->dev
;
219 net
->netdev_ops
= &bcmNetDevOps
;
220 net
->ethtool_ops
= &bcm_ethtool_ops
;
221 net
->mtu
= MTU_SIZE
; /* 1400 Bytes */
222 net
->tx_queue_len
= TX_QLEN
;
223 net
->flags
|= IFF_NOARP
;
224 net
->flags
&= ~(IFF_BROADCAST
| IFF_MULTICAST
);
225 Adapter
->msg_enable
= netif_msg_init(debug
, default_msg
);
227 netif_carrier_off(net
);
229 SET_NETDEV_DEVTYPE(net
, &wimax_type
);
231 /* Read the MAC Address from EEPROM */
232 ReadMacAddressFromNVM(Adapter
);
234 result
= register_netdev(net
);
236 gblpnetdev
= Adapter
->dev
= net
;
245 static int bcm_init(void)
247 printk(KERN_INFO
"%s, %s\n", DRV_DESCRIPTION
, DRV_VERSION
);
248 printk(KERN_INFO
"%s\n", DRV_COPYRIGHT
);
250 return InterfaceInitialize();
254 static void bcm_exit(void)
259 module_init(bcm_init
);
260 module_exit(bcm_exit
);
262 MODULE_DESCRIPTION(DRV_DESCRIPTION
);
263 MODULE_VERSION(DRV_VERSION
);
264 MODULE_LICENSE ("GPL");