x86/PCI: use host bridge _CRS info on ASUS M2V-MX SE
[linux-btrfs-devel.git] / drivers / staging / bcm / Bcmnet.c
blob133e146a3dd46fd39b70b95cf7f2f6c801b307fe
1 #include "headers.h"
3 struct net_device *gblpnetdev;
5 static INT bcm_open(struct net_device *dev)
7 PMINI_ADAPTER Adapter = GET_BCM_ADAPTER(dev);
9 if (Adapter->fw_download_done == FALSE) {
10 pr_notice(PFX "%s: link up failed (download in progress)\n",
11 dev->name);
12 return -EBUSY;
15 if (netif_msg_ifup(Adapter))
16 pr_info(PFX "%s: enabling interface\n", dev->name);
18 if (Adapter->LinkUpStatus) {
19 if (netif_msg_link(Adapter))
20 pr_info(PFX "%s: link up\n", dev->name);
22 netif_carrier_on(Adapter->dev);
23 netif_start_queue(Adapter->dev);
26 return 0;
29 static INT bcm_close(struct net_device *dev)
31 PMINI_ADAPTER Adapter = GET_BCM_ADAPTER(dev);
33 if (netif_msg_ifdown(Adapter))
34 pr_info(PFX "%s: disabling interface\n", dev->name);
36 netif_carrier_off(dev);
37 netif_stop_queue(dev);
39 return 0;
42 static u16 bcm_select_queue(struct net_device *dev, struct sk_buff *skb)
44 return ClassifyPacket(netdev_priv(dev), skb);
47 /*******************************************************************
48 * Function - bcm_transmit()
50 * Description - This is the main transmit function for our virtual
51 * interface(eth0). It handles the ARP packets. It
52 * clones this packet and then Queue it to a suitable
53 * Queue. Then calls the transmit_packet().
55 * Parameter - skb - Pointer to the socket buffer structure
56 * dev - Pointer to the virtual net device structure
58 *********************************************************************/
60 static netdev_tx_t bcm_transmit(struct sk_buff *skb, struct net_device *dev)
62 PMINI_ADAPTER Adapter = GET_BCM_ADAPTER(dev);
63 u16 qindex = skb_get_queue_mapping(skb);
66 if (Adapter->device_removed || !Adapter->LinkUpStatus)
67 goto drop;
69 if (Adapter->TransferMode != IP_PACKET_ONLY_MODE)
70 goto drop;
72 if (INVALID_QUEUE_INDEX == qindex)
73 goto drop;
75 if (Adapter->PackInfo[qindex].uiCurrentPacketsOnHost >=
76 SF_MAX_ALLOWED_PACKETS_TO_BACKUP)
77 return NETDEV_TX_BUSY;
79 /* Now Enqueue the packet */
80 if (netif_msg_tx_queued(Adapter))
81 pr_info(PFX "%s: enqueueing packet to queue %d\n",
82 dev->name, qindex);
84 spin_lock(&Adapter->PackInfo[qindex].SFQueueLock);
85 Adapter->PackInfo[qindex].uiCurrentBytesOnHost += skb->len;
86 Adapter->PackInfo[qindex].uiCurrentPacketsOnHost++;
88 *((B_UINT32 *) skb->cb + SKB_CB_LATENCY_OFFSET) = jiffies;
89 ENQUEUEPACKET(Adapter->PackInfo[qindex].FirstTxQueue,
90 Adapter->PackInfo[qindex].LastTxQueue, skb);
91 atomic_inc(&Adapter->TotalPacketCount);
92 spin_unlock(&Adapter->PackInfo[qindex].SFQueueLock);
94 /* FIXME - this is racy and incorrect, replace with work queue */
95 if (!atomic_read(&Adapter->TxPktAvail)) {
96 atomic_set(&Adapter->TxPktAvail, 1);
97 wake_up(&Adapter->tx_packet_wait_queue);
99 return NETDEV_TX_OK;
101 drop:
102 dev_kfree_skb(skb);
103 return NETDEV_TX_OK;
109 @ingroup init_functions
110 Register other driver entry points with the kernel
112 static const struct net_device_ops bcmNetDevOps = {
113 .ndo_open = bcm_open,
114 .ndo_stop = bcm_close,
115 .ndo_start_xmit = bcm_transmit,
116 .ndo_change_mtu = eth_change_mtu,
117 .ndo_set_mac_address = eth_mac_addr,
118 .ndo_validate_addr = eth_validate_addr,
119 .ndo_select_queue = bcm_select_queue,
122 static struct device_type wimax_type = {
123 .name = "wimax",
126 static int bcm_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
128 cmd->supported = 0;
129 cmd->advertising = 0;
130 cmd->speed = SPEED_10000;
131 cmd->duplex = DUPLEX_FULL;
132 cmd->port = PORT_TP;
133 cmd->phy_address = 0;
134 cmd->transceiver = XCVR_INTERNAL;
135 cmd->autoneg = AUTONEG_DISABLE;
136 cmd->maxtxpkt = 0;
137 cmd->maxrxpkt = 0;
138 return 0;
141 static void bcm_get_drvinfo(struct net_device *dev,
142 struct ethtool_drvinfo *info)
144 PMINI_ADAPTER Adapter = GET_BCM_ADAPTER(dev);
145 PS_INTERFACE_ADAPTER psIntfAdapter = Adapter->pvInterfaceAdapter;
146 struct usb_device *udev = interface_to_usbdev(psIntfAdapter->interface);
148 strcpy(info->driver, DRV_NAME);
149 strcpy(info->version, DRV_VERSION);
150 snprintf(info->fw_version, sizeof(info->fw_version), "%u.%u",
151 Adapter->uiFlashLayoutMajorVersion,
152 Adapter->uiFlashLayoutMinorVersion);
154 usb_make_path(udev, info->bus_info, sizeof(info->bus_info));
157 static u32 bcm_get_link(struct net_device *dev)
159 PMINI_ADAPTER Adapter = GET_BCM_ADAPTER(dev);
161 return Adapter->LinkUpStatus;
164 static u32 bcm_get_msglevel(struct net_device *dev)
166 PMINI_ADAPTER Adapter = GET_BCM_ADAPTER(dev);
168 return Adapter->msg_enable;
171 static void bcm_set_msglevel(struct net_device *dev, u32 level)
173 PMINI_ADAPTER Adapter = GET_BCM_ADAPTER(dev);
175 Adapter->msg_enable = level;
178 static const struct ethtool_ops bcm_ethtool_ops = {
179 .get_settings = bcm_get_settings,
180 .get_drvinfo = bcm_get_drvinfo,
181 .get_link = bcm_get_link,
182 .get_msglevel = bcm_get_msglevel,
183 .set_msglevel = bcm_set_msglevel,
186 int register_networkdev(PMINI_ADAPTER Adapter)
188 struct net_device *net = Adapter->dev;
189 PS_INTERFACE_ADAPTER IntfAdapter = Adapter->pvInterfaceAdapter;
190 struct usb_interface *udev = IntfAdapter->interface;
191 struct usb_device *xdev = IntfAdapter->udev;
193 int result;
195 net->netdev_ops = &bcmNetDevOps;
196 net->ethtool_ops = &bcm_ethtool_ops;
197 net->mtu = MTU_SIZE; /* 1400 Bytes */
198 net->tx_queue_len = TX_QLEN;
199 net->flags |= IFF_NOARP;
201 netif_carrier_off(net);
203 SET_NETDEV_DEVTYPE(net, &wimax_type);
205 /* Read the MAC Address from EEPROM */
206 result = ReadMacAddressFromNVM(Adapter);
207 if (result != STATUS_SUCCESS) {
208 dev_err(&udev->dev,
209 PFX "Error in Reading the mac Address: %d", result);
210 return -EIO;
213 result = register_netdev(net);
214 if (result)
215 return result;
217 gblpnetdev = Adapter->dev;
219 if (netif_msg_probe(Adapter))
220 dev_info(&udev->dev, PFX "%s: register usb-%s-%s %pM\n",
221 net->name, xdev->bus->bus_name, xdev->devpath,
222 net->dev_addr);
224 return 0;
227 void unregister_networkdev(PMINI_ADAPTER Adapter)
229 struct net_device *net = Adapter->dev;
230 PS_INTERFACE_ADAPTER IntfAdapter = Adapter->pvInterfaceAdapter;
231 struct usb_interface *udev = IntfAdapter->interface;
232 struct usb_device *xdev = IntfAdapter->udev;
234 if (netif_msg_probe(Adapter))
235 dev_info(&udev->dev, PFX "%s: unregister usb-%s%s\n",
236 net->name, xdev->bus->bus_name, xdev->devpath);
238 unregister_netdev(Adapter->dev);