1 /*******************************************************************************
3 * Wireless device driver for Linux (wlags49).
5 * Copyright (c) 1998-2003 Agere Systems Inc.
9 * Initially developed by TriplePoint, Inc.
10 * http://www.triplepoint.com
12 *------------------------------------------------------------------------------
14 * This file contains handler functions registered with the net_device
17 *------------------------------------------------------------------------------
21 * This software is provided subject to the following terms and conditions,
22 * which you should read carefully before using the software. Using this
23 * software indicates your acceptance of these terms and conditions. If you do
24 * not agree with these terms and conditions, do not use the software.
26 * Copyright © 2003 Agere Systems Inc.
27 * All rights reserved.
29 * Redistribution and use in source or binary forms, with or without
30 * modifications, are permitted provided that the following conditions are met:
32 * . Redistributions of source code must retain the above copyright notice, this
33 * list of conditions and the following Disclaimer as comments in the code as
34 * well as in the documentation and/or other materials provided with the
37 * . Redistributions in binary form must reproduce the above copyright notice,
38 * this list of conditions and the following Disclaimer in the documentation
39 * and/or other materials provided with the distribution.
41 * . Neither the name of Agere Systems Inc. nor the names of the contributors
42 * may be used to endorse or promote products derived from this software
43 * without specific prior written permission.
47 * THIS SOFTWARE IS PROVIDED
\93AS IS
\94 AND ANY EXPRESS OR IMPLIED WARRANTIES,
48 * INCLUDING, BUT NOT LIMITED TO, INFRINGEMENT AND THE IMPLIED WARRANTIES OF
49 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. ANY
50 * USE, MODIFICATION OR DISTRIBUTION OF THIS SOFTWARE IS SOLELY AT THE USERS OWN
51 * RISK. IN NO EVENT SHALL AGERE SYSTEMS INC. OR CONTRIBUTORS BE LIABLE FOR ANY
52 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
53 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
54 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
55 * ON ANY THEORY OF LIABILITY, INCLUDING, BUT NOT LIMITED TO, CONTRACT, STRICT
56 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
57 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
60 ******************************************************************************/
62 /*******************************************************************************
64 ******************************************************************************/
65 #include <wl_version.h>
67 #include <linux/module.h>
68 #include <linux/slab.h>
69 #include <linux/types.h>
70 #include <linux/kernel.h>
71 #include <linux/netdevice.h>
72 #include <linux/ethtool.h>
73 #include <linux/etherdevice.h>
81 #include <wl_internal.h>
85 #include <wl_netdev.h>
89 #include <wl_profile.h>
90 #endif /* USE_PROFILE */
94 #endif /* BUS_PCMCIA */
101 #define MTU_MAX (HCF_MAX_MSG - ETH_HLEN - 8)
103 #define MTU_MAX (HCF_MAX_MSG - ETH_HLEN)
106 /*******************************************************************************
108 ******************************************************************************/
109 #define BLOCK_INPUT(buf, len) \
111 desc->buf_addr = buf; \
112 desc->BUF_SIZE = len; \
113 status = hcf_rcv_msg(&(lp->hcfCtx), desc, 0); \
116 #define BLOCK_INPUT_DMA(buf, len) memcpy( buf, desc_next->buf_addr, pktlen )
118 /*******************************************************************************
119 * function prototypes
120 ******************************************************************************/
122 /*******************************************************************************
124 *******************************************************************************
128 * We never need to do anything when a "Wireless" device is "initialized"
129 * by the net software, because we only register already-found cards.
133 * dev - a pointer to the device's net_device structure
138 * errno value otherwise
140 ******************************************************************************/
141 int wl_init(struct net_device *dev)
143 DBG_PARAM(DbgInfo, "dev", "%s (0x%p)", dev->name, dev);
147 /*============================================================================*/
149 /*******************************************************************************
151 *******************************************************************************
155 * Implement the SIOCSIFMAP interface.
159 * dev - a pointer to the device's net_device structure
160 * map - a pointer to the device's ifmap structure
167 ******************************************************************************/
168 int wl_config(struct net_device *dev, struct ifmap *map)
170 DBG_PARAM(DbgInfo, "dev", "%s (0x%p)", dev->name, dev);
171 DBG_PARAM(DbgInfo, "map", "0x%p", map);
174 * The only thing we care about here is a port change.
175 * Since this not needed, ignore the request.
177 DBG_TRACE(DbgInfo, "%s: %s called.\n", dev->name, __func__);
182 /*============================================================================*/
184 /*******************************************************************************
186 *******************************************************************************
190 * Return the current device statistics.
194 * dev - a pointer to the device's net_device structure
198 * a pointer to a net_device_stats structure containing the network
201 ******************************************************************************/
202 struct net_device_stats *wl_stats(struct net_device *dev)
208 struct net_device_stats *pStats;
209 struct wl_private *lp = wl_priv(dev);
211 /*DBG_PARAM( DbgInfo, "dev", "%s (0x%p)", dev->name, dev ); */
218 if (lp->useRTS == 1) {
219 wl_unlock(lp, &flags);
224 /* Return the statistics for the appropriate device */
227 for (count = 0; count < NUM_WDS_PORTS; count++) {
228 if (dev == lp->wds_port[count].dev) {
229 pStats = &(lp->wds_port[count].stats);
235 /* If pStats is still NULL, then the device is not a WDS port */
236 if (pStats == NULL) {
237 pStats = &(lp->stats);
240 wl_unlock(lp, &flags);
245 /*============================================================================*/
247 /*******************************************************************************
249 *******************************************************************************
257 * dev - a pointer to the device's net_device structure
264 ******************************************************************************/
265 int wl_open(struct net_device *dev)
267 int status = HCF_SUCCESS;
268 struct wl_private *lp = wl_priv(dev);
274 if (lp->useRTS == 1) {
275 DBG_TRACE(DbgInfo, "Skipping device open, in RTS mode\n");
276 wl_unlock(lp, &flags);
285 if (lp->portState == WVLAN_PORT_STATE_DISABLED) {
286 DBG_TRACE(DbgInfo, "Enabling Port 0\n");
287 status = wl_enable(lp);
289 if (status != HCF_SUCCESS) {
290 DBG_TRACE(DbgInfo, "Enable port 0 failed: 0x%x\n",
295 /* Holding the lock too long, make a gap to allow other processes */
296 wl_unlock(lp, &flags);
299 if (strlen(lp->fw_image_filename)) {
300 DBG_TRACE(DbgInfo, ";???? Kludgy way to force a download\n");
303 status = wl_apply(lp);
306 /* Holding the lock too long, make a gap to allow other processes */
307 wl_unlock(lp, &flags);
310 /* Unsuccessful, try reset of the card to recover */
311 if (status != HCF_SUCCESS)
312 status = wl_reset(dev);
314 /* Holding the lock too long, make a gap to allow other processes */
315 wl_unlock(lp, &flags);
318 if (status == HCF_SUCCESS) {
319 netif_carrier_on(dev);
320 WL_WDS_NETIF_CARRIER_ON(lp);
322 /* Start handling interrupts */
323 lp->is_handling_int = WL_HANDLING_INT;
326 netif_start_queue(dev);
327 WL_WDS_NETIF_START_QUEUE(lp);
329 wl_hcf_error(dev, status); /* Report the error */
330 netif_device_detach(dev); /* Stop the device and queue */
333 wl_unlock(lp, &flags);
338 /*============================================================================*/
340 /*******************************************************************************
342 *******************************************************************************
350 * dev - a pointer to the device's net_device structure
357 ******************************************************************************/
358 int wl_close(struct net_device *dev)
360 struct wl_private *lp = wl_priv(dev);
363 DBG_PARAM(DbgInfo, "dev", "%s (0x%p)", dev->name, dev);
365 /* Mark the adapter as busy */
366 netif_stop_queue(dev);
367 WL_WDS_NETIF_STOP_QUEUE(lp);
369 netif_carrier_off(dev);
370 WL_WDS_NETIF_CARRIER_OFF(lp);
373 * Shutdown the adapter:
374 * Disable adapter interrupts
383 /* Stop handling interrupts */
384 lp->is_handling_int = WL_NOT_HANDLING_INT;
387 if (lp->useRTS == 1) {
388 DBG_TRACE(DbgInfo, "Skipping device close, in RTS mode\n");
389 wl_unlock(lp, &flags);
394 /* Disable the ports */
397 wl_unlock(lp, &flags);
402 /*============================================================================*/
404 static void wl_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info)
406 strlcpy(info->driver, DRIVER_NAME, sizeof(info->driver));
407 strlcpy(info->version, DRV_VERSION_STR, sizeof(info->version));
409 if (dev->dev.parent) {
410 dev_set_name(dev->dev.parent, "%s", info->bus_info);
412 snprintf(info->bus_info, sizeof(info->bus_info),
415 } /* wl_get_drvinfo */
417 static struct ethtool_ops wl_ethtool_ops = {
418 .get_drvinfo = wl_get_drvinfo,
419 .get_link = ethtool_op_get_link,
422 /*******************************************************************************
424 *******************************************************************************
428 * The IOCTL handler for the device.
432 * dev - a pointer to the device's net_device struct.
433 * rq - a pointer to the IOCTL request buffer.
434 * cmd - the IOCTL command code.
439 * errno value otherwise
441 ******************************************************************************/
442 int wl_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
444 struct wl_private *lp = wl_priv(dev);
448 DBG_PARAM(DbgInfo, "dev", "%s (0x%p)", dev->name, dev);
449 DBG_PARAM(DbgInfo, "rq", "0x%p", rq);
450 DBG_PARAM(DbgInfo, "cmd", "0x%04x", cmd);
457 if (lp->useRTS == 1) {
458 /* Handle any RTS IOCTL here */
459 if (cmd == WL_IOCTL_RTS) {
460 DBG_TRACE(DbgInfo, "IOCTL: WL_IOCTL_RTS\n");
461 ret = wvlan_rts((struct rtsreq *)rq, dev->base_addr);
464 "IOCTL not supported in RTS mode: 0x%X\n",
469 goto out_act_int_on_unlock;
473 /* Only handle UIL IOCTL requests when the UIL has the system blocked. */
474 if (!((lp->flags & WVLAN2_UIL_BUSY) && (cmd != WVLAN2_IOCTL_UIL))) {
476 struct uilreq *urq = (struct uilreq *)rq;
480 /* ================== Private IOCTLs (up to 16) ================== */
482 case WVLAN2_IOCTL_UIL:
483 DBG_TRACE(DbgInfo, "IOCTL: WVLAN2_IOCTL_UIL\n");
484 ret = wvlan_uil(urq, lp);
489 DBG_TRACE(DbgInfo, "IOCTL CODE NOT SUPPORTED: 0x%X\n",
496 "DEVICE IS BUSY, CANNOT PROCESS REQUEST\n");
501 out_act_int_on_unlock:
505 wl_unlock(lp, &flags);
510 /*============================================================================*/
512 #ifdef CONFIG_NET_POLL_CONTROLLER
513 static void wl_poll(struct net_device *dev)
515 struct wl_private *lp = wl_priv(dev);
520 wl_isr(dev->irq, dev, ®s);
521 wl_unlock(lp, &flags);
525 /*******************************************************************************
527 *******************************************************************************
531 * The handler called when, for some reason, a Tx request is not completed.
535 * dev - a pointer to the device's net_device struct.
541 ******************************************************************************/
542 void wl_tx_timeout(struct net_device *dev)
548 struct wl_private *lp = wl_priv(dev);
549 struct net_device_stats *pStats = NULL;
551 DBG_WARNING(DbgInfo, "%s: Transmit timeout.\n", dev->name);
556 if (lp->useRTS == 1) {
558 "Skipping tx_timeout handler, in RTS mode\n");
559 wl_unlock(lp, &flags);
564 /* Figure out which device (the "root" device or WDS port) this timeout
568 for (count = 0; count < NUM_WDS_PORTS; count++) {
569 if (dev == lp->wds_port[count].dev) {
570 pStats = &(lp->wds_port[count].stats);
572 /* Break the loop so that we can use the counter to access WDS
573 information in the private structure */
580 /* If pStats is still NULL, then the device is not a WDS port */
581 if (pStats == NULL) {
582 pStats = &(lp->stats);
585 /* Accumulate the timeout error */
588 wl_unlock(lp, &flags);
589 } /* wl_tx_timeout */
591 /*============================================================================*/
593 /*******************************************************************************
595 *******************************************************************************
599 * The routine which performs data transmits.
603 * lp - a pointer to the device's wl_private struct.
610 ******************************************************************************/
611 int wl_send(struct wl_private *lp)
616 WVLAN_LFRAME *txF = NULL;
617 struct list_head *element;
619 /*------------------------------------------------------------------------*/
622 DBG_ERROR(DbgInfo, "Private adapter struct is NULL\n");
625 if (lp->dev == NULL) {
626 DBG_ERROR(DbgInfo, "net_device struct in wl_private is NULL\n");
631 * Check for the availability of FIDs; if none are available,
632 * don't take any frames off the txQ
634 if (lp->hcfCtx.IFB_RscInd == 0)
637 /* Reclaim the TxQ Elements and place them back on the free queue */
638 if (!list_empty(&(lp->txQ[0]))) {
639 element = lp->txQ[0].next;
641 txF = (WVLAN_LFRAME *) list_entry(element, WVLAN_LFRAME, node);
643 lp->txF.skb = txF->frame.skb;
644 lp->txF.port = txF->frame.port;
646 txF->frame.skb = NULL;
649 list_del(&(txF->node));
650 list_add(element, &(lp->txFree));
654 if (lp->txQ_count < TX_Q_LOW_WATER_MARK) {
655 if (lp->netif_queue_on == FALSE) {
656 DBG_TX(DbgInfo, "Kickstarting Q: %d\n",
658 netif_wake_queue(lp->dev);
659 WL_WDS_NETIF_WAKE_QUEUE(lp);
660 lp->netif_queue_on = TRUE;
666 if (lp->txF.skb == NULL) {
670 /* If the device has resources (FIDs) available, then Tx the packet */
671 /* Format the TxRequest and send it to the adapter */
672 len = lp->txF.skb->len < ETH_ZLEN ? ETH_ZLEN : lp->txF.skb->len;
674 desc = &(lp->desc_tx);
675 desc->buf_addr = lp->txF.skb->data;
677 desc->next_desc_addr = NULL;
679 status = hcf_send_msg(&(lp->hcfCtx), desc, lp->txF.port);
681 if (status == HCF_SUCCESS) {
682 lp->dev->trans_start = jiffies;
684 DBG_TX(DbgInfo, "Transmit...\n");
686 if (lp->txF.port == HCF_PORT_0) {
687 lp->stats.tx_packets++;
688 lp->stats.tx_bytes += lp->txF.skb->len;
692 lp->wds_port[((lp->txF.port >> 8) -
693 1)].stats.tx_packets++;
694 lp->wds_port[((lp->txF.port >> 8) -
695 1)].stats.tx_bytes += lp->txF.skb->len;
700 /* Free the skb and perform queue cleanup, as the buffer was
701 transmitted successfully */
702 dev_kfree_skb(lp->txF.skb);
711 /*============================================================================*/
713 /*******************************************************************************
715 *******************************************************************************
719 * The Tx handler function for the network layer.
723 * skb - a pointer to the sk_buff structure containing the data to transfer.
724 * dev - a pointer to the device's net_device structure.
731 ******************************************************************************/
732 int wl_tx(struct sk_buff *skb, struct net_device *dev, int port)
735 struct wl_private *lp = wl_priv(dev);
736 WVLAN_LFRAME *txF = NULL;
737 struct list_head *element;
738 /*------------------------------------------------------------------------*/
740 /* Grab the spinlock */
743 if (lp->flags & WVLAN2_UIL_BUSY) {
744 DBG_WARNING(DbgInfo, "UIL has device blocked\n");
745 /* Start dropping packets here??? */
746 wl_unlock(lp, &flags);
750 if (lp->useRTS == 1) {
751 DBG_PRINT("RTS: we're getting a Tx...\n");
752 wl_unlock(lp, &flags);
758 /* Get an element from the queue */
759 element = lp->txFree.next;
760 txF = (WVLAN_LFRAME *) list_entry(element, WVLAN_LFRAME, node);
762 DBG_ERROR(DbgInfo, "Problem with list_entry\n");
763 wl_unlock(lp, &flags);
766 /* Fill out the frame */
767 txF->frame.skb = skb;
768 txF->frame.port = port;
769 /* Move the frame to the txQ */
770 /* NOTE: Here's where we would do priority queueing */
771 list_move(&(txF->node), &(lp->txQ[0]));
774 if (lp->txQ_count >= DEFAULT_NUM_TX_FRAMES) {
775 DBG_TX(DbgInfo, "Q Full: %d\n", lp->txQ_count);
776 if (lp->netif_queue_on == TRUE) {
777 netif_stop_queue(lp->dev);
778 WL_WDS_NETIF_STOP_QUEUE(lp);
779 lp->netif_queue_on = FALSE;
783 wl_act_int_off(lp); /* Disable Interrupts */
785 /* Send the data to the hardware using the appropriate method */
788 wl_send_dma(lp, skb, port);
794 /* Re-enable Interrupts, release the spinlock and return */
796 wl_unlock(lp, &flags);
800 /*============================================================================*/
802 /*******************************************************************************
804 *******************************************************************************
808 * The routine which performs data reception.
812 * dev - a pointer to the device's net_device structure.
819 ******************************************************************************/
820 int wl_rx(struct net_device *dev)
824 struct wl_private *lp = wl_priv(dev);
829 /*------------------------------------------------------------------------*/
831 DBG_PARAM(DbgInfo, "dev", "%s (0x%p)", dev->name, dev);
833 if (!(lp->flags & WVLAN2_UIL_BUSY)) {
836 if (lp->useRTS == 1) {
837 DBG_PRINT("RTS: We're getting an Rx...\n");
842 /* Read the HFS_STAT register from the lookahead buffer */
843 hfs_stat = (hcf_16) ((lp->lookAheadBuf[HFS_STAT]) |
844 (lp->lookAheadBuf[HFS_STAT + 1] << 8));
846 /* Make sure the frame isn't bad */
847 if ((hfs_stat & HFS_STAT_ERR) != HCF_SUCCESS) {
849 "HFS_STAT_ERROR (0x%x) in Rx Packet\n",
850 lp->lookAheadBuf[HFS_STAT]);
854 /* Determine what port this packet is for */
855 port = (hfs_stat >> 8) & 0x0007;
856 DBG_RX(DbgInfo, "Rx frame for port %d\n", port);
858 pktlen = lp->hcfCtx.IFB_RxLen;
860 skb = ALLOC_SKB(pktlen);
862 /* Set the netdev based on the port */
871 skb->dev = lp->wds_port[port - 1].dev;
881 desc = &(lp->desc_rx);
883 desc->next_desc_addr = NULL;
886 #define BLOCK_INPUT(buf, len) \
887 desc->buf_addr = buf; \
888 desc->BUF_SIZE = len; \
889 status = hcf_rcv_msg(&(lp->hcfCtx), desc, 0)
892 GET_PACKET(skb->dev, skb, pktlen);
894 if (status == HCF_SUCCESS) {
898 lp->stats.rx_packets++;
899 lp->stats.rx_bytes += pktlen;
912 dev->last_rx = jiffies;
916 if (lp->spydata.spy_number > 0) {
921 wl_spy_gather(dev, srcaddr);
923 #endif /* WIRELESS_SPY */
924 #endif /* WIRELESS_EXT */
927 "Rx request to card FAILED\n");
930 lp->stats.rx_dropped++;
943 DBG_ERROR(DbgInfo, "Could not alloc skb\n");
946 lp->stats.rx_dropped++;
951 1].stats.rx_dropped++;
961 /*============================================================================*/
963 /*******************************************************************************
965 *******************************************************************************
969 * Function to handle multicast packets
973 * dev - a pointer to the device's net_device structure.
979 ******************************************************************************/
982 void wl_multicast(struct net_device *dev)
984 #if 1 /* (HCF_TYPE) & HCF_TYPE_STA */
986 * should we return an error status in AP mode ?
987 * seems reasonable that even an AP-only driver
988 * could afford this small additional footprint
992 struct netdev_hw_addr *ha;
993 struct wl_private *lp = wl_priv(dev);
996 DBG_PARAM(DbgInfo, "dev", "%s (0x%p)", dev->name, dev);
998 if (!wl_adapter_is_open(dev))
1002 if (DBG_FLAGS(DbgInfo) & DBG_PARAM_ON) {
1003 DBG_PRINT(" flags: %s%s%s\n",
1004 (dev->flags & IFF_PROMISC) ? "Promiscuous " : "",
1005 (dev->flags & IFF_MULTICAST) ? "Multicast " : "",
1006 (dev->flags & IFF_ALLMULTI) ? "All-Multicast" : "");
1008 DBG_PRINT(" mc_count: %d\n", netdev_mc_count(dev));
1010 netdev_for_each_mc_addr(ha, dev)
1011 DBG_PRINT(" %pM (%d)\n", ha->addr, dev->addr_len);
1015 if (!(lp->flags & WVLAN2_UIL_BUSY)) {
1018 if (lp->useRTS == 1) {
1019 DBG_TRACE(DbgInfo, "Skipping multicast, in RTS mode\n");
1022 #endif /* USE_RTS */
1024 wl_lock(lp, &flags);
1027 if (CNV_INT_TO_LITTLE(lp->hcfCtx.IFB_FWIdentity.comp_id) ==
1029 if (dev->flags & IFF_PROMISC) {
1030 /* Enable promiscuous mode */
1031 lp->ltvRecord.len = 2;
1032 lp->ltvRecord.typ = CFG_PROMISCUOUS_MODE;
1033 lp->ltvRecord.u.u16[0] = CNV_INT_TO_LITTLE(1);
1035 ("Enabling Promiscuous mode (IFF_PROMISC)\n");
1036 hcf_put_info(&(lp->hcfCtx),
1037 (LTVP) & (lp->ltvRecord));
1038 } else if ((netdev_mc_count(dev) > HCF_MAX_MULTICAST)
1039 || (dev->flags & IFF_ALLMULTI)) {
1040 /* Shutting off this filter will enable all multicast frames to
1041 be sent up from the device; however, this is a static RID, so
1042 a call to wl_apply() is needed */
1043 lp->ltvRecord.len = 2;
1044 lp->ltvRecord.typ = CFG_CNF_RX_ALL_GROUP_ADDR;
1045 lp->ltvRecord.u.u16[0] = CNV_INT_TO_LITTLE(0);
1047 ("Enabling all multicast mode (IFF_ALLMULTI)\n");
1048 hcf_put_info(&(lp->hcfCtx),
1049 (LTVP) & (lp->ltvRecord));
1051 } else if (!netdev_mc_empty(dev)) {
1052 /* Set the multicast addresses */
1054 (netdev_mc_count(dev) * 3) + 1;
1055 lp->ltvRecord.typ = CFG_GROUP_ADDR;
1058 netdev_for_each_mc_addr(ha, dev)
1060 (lp->ltvRecord.u.u8[x++ * ETH_ALEN]),
1061 ha->addr, ETH_ALEN);
1062 DBG_PRINT("Setting multicast list\n");
1063 hcf_put_info(&(lp->hcfCtx),
1064 (LTVP) & (lp->ltvRecord));
1066 /* Disable promiscuous mode */
1067 lp->ltvRecord.len = 2;
1068 lp->ltvRecord.typ = CFG_PROMISCUOUS_MODE;
1069 lp->ltvRecord.u.u16[0] = CNV_INT_TO_LITTLE(0);
1070 DBG_PRINT("Disabling Promiscuous mode\n");
1071 hcf_put_info(&(lp->hcfCtx),
1072 (LTVP) & (lp->ltvRecord));
1074 /* Disable multicast mode */
1075 lp->ltvRecord.len = 2;
1076 lp->ltvRecord.typ = CFG_GROUP_ADDR;
1077 DBG_PRINT("Disabling Multicast mode\n");
1078 hcf_put_info(&(lp->hcfCtx),
1079 (LTVP) & (lp->ltvRecord));
1082 * Turning on this filter will prevent all multicast frames from
1083 * being sent up from the device; however, this is a static RID,
1084 * so a call to wl_apply() is needed
1086 lp->ltvRecord.len = 2;
1087 lp->ltvRecord.typ = CFG_CNF_RX_ALL_GROUP_ADDR;
1088 lp->ltvRecord.u.u16[0] = CNV_INT_TO_LITTLE(1);
1090 ("Disabling all multicast mode (IFF_ALLMULTI)\n");
1091 hcf_put_info(&(lp->hcfCtx),
1092 (LTVP) & (lp->ltvRecord));
1097 wl_unlock(lp, &flags);
1099 #endif /* HCF_STA */
1100 } /* wl_multicast */
1102 /*============================================================================*/
1104 #else /* NEW_MULTICAST */
1106 void wl_multicast(struct net_device *dev, int num_addrs, void *addrs)
1108 DBG_PARAM(DbgInfo, "dev", "%s (0x%p)", dev->name, dev);
1109 DBG_PARAM(DbgInfo, "num_addrs", "%d", num_addrs);
1110 DBG_PARAM(DbgInfo, "addrs", "0x%p", addrs);
1112 #error Obsolete set multicast interface!
1113 } /* wl_multicast */
1115 /*============================================================================*/
1117 #endif /* NEW_MULTICAST */
1119 static const struct net_device_ops wl_netdev_ops = {
1120 .ndo_start_xmit = &wl_tx_port0,
1122 .ndo_set_config = &wl_config,
1123 .ndo_get_stats = &wl_stats,
1124 .ndo_set_rx_mode = &wl_multicast,
1126 .ndo_init = &wl_insert,
1127 .ndo_open = &wl_adapter_open,
1128 .ndo_stop = &wl_adapter_close,
1129 .ndo_do_ioctl = &wl_ioctl,
1131 .ndo_tx_timeout = &wl_tx_timeout,
1133 #ifdef CONFIG_NET_POLL_CONTROLLER
1134 .ndo_poll_controller = wl_poll,
1138 /*******************************************************************************
1140 *******************************************************************************
1144 * Create instances of net_device and wl_private for the new adapter
1145 * and register the device's entry points in the net_device structure.
1153 * a pointer to an allocated and initialized net_device struct for this
1156 ******************************************************************************/
1157 struct net_device *wl_device_alloc(void)
1159 struct net_device *dev = NULL;
1160 struct wl_private *lp = NULL;
1162 /* Alloc a net_device struct */
1163 dev = alloc_etherdev(sizeof(struct wl_private));
1168 * Initialize the 'next' pointer in the struct.
1169 * Currently only used for PCI,
1170 * but do it here just in case it's used
1171 * for other buses in the future
1176 if (dev->mtu > MTU_MAX) {
1177 DBG_WARNING(DbgInfo, "%s: MTU set too high, limiting to %d.\n",
1178 dev->name, MTU_MAX);
1182 /* Setup the function table in the device structure. */
1184 dev->wireless_handlers = (struct iw_handler_def *)&wl_iw_handler_def;
1185 lp->wireless_data.spy_data = &lp->spy_data;
1186 dev->wireless_data = &lp->wireless_data;
1188 dev->netdev_ops = &wl_netdev_ops;
1190 dev->watchdog_timeo = TX_TIMEOUT;
1192 dev->ethtool_ops = &wl_ethtool_ops;
1194 netif_stop_queue(dev);
1196 /* Allocate virtual devices for WDS support if needed */
1197 WL_WDS_DEVICE_ALLOC(lp);
1200 } /* wl_device_alloc */
1202 /*============================================================================*/
1204 /*******************************************************************************
1205 * wl_device_dealloc()
1206 *******************************************************************************
1210 * Free instances of net_device and wl_private strcutres for an adapter
1211 * and perform basic cleanup.
1215 * dev - a pointer to the device's net_device structure.
1221 ******************************************************************************/
1222 void wl_device_dealloc(struct net_device *dev)
1224 /* Dealloc the WDS ports */
1225 WL_WDS_DEVICE_DEALLOC(lp);
1228 } /* wl_device_dealloc */
1230 /*============================================================================*/
1232 /*******************************************************************************
1234 *******************************************************************************
1238 * The handler routine for Tx over HCF_PORT_0.
1242 * skb - a pointer to the sk_buff to transmit.
1243 * dev - a pointer to a net_device structure representing HCF_PORT_0.
1249 ******************************************************************************/
1250 int wl_tx_port0(struct sk_buff *skb, struct net_device *dev)
1252 DBG_TX(DbgInfo, "Tx on Port 0\n");
1254 return wl_tx(skb, dev, HCF_PORT_0);
1256 return wl_tx_dma(skb, dev, HCF_PORT_0);
1258 } /* wl_tx_port0i */
1260 /*============================================================================*/
1264 /*******************************************************************************
1266 *******************************************************************************
1270 * The handler routine for Tx over HCF_PORT_1.
1274 * skb - a pointer to the sk_buff to transmit.
1275 * dev - a pointer to a net_device structure representing HCF_PORT_1.
1281 ******************************************************************************/
1282 int wl_tx_port1(struct sk_buff *skb, struct net_device *dev)
1284 DBG_TX(DbgInfo, "Tx on Port 1\n");
1285 return wl_tx(skb, dev, HCF_PORT_1);
1288 /*============================================================================*/
1290 /*******************************************************************************
1292 *******************************************************************************
1296 * The handler routine for Tx over HCF_PORT_2.
1300 * skb - a pointer to the sk_buff to transmit.
1301 * dev - a pointer to a net_device structure representing HCF_PORT_2.
1307 ******************************************************************************/
1308 int wl_tx_port2(struct sk_buff *skb, struct net_device *dev)
1310 DBG_TX(DbgInfo, "Tx on Port 2\n");
1311 return wl_tx(skb, dev, HCF_PORT_2);
1314 /*============================================================================*/
1316 /*******************************************************************************
1318 *******************************************************************************
1322 * The handler routine for Tx over HCF_PORT_3.
1326 * skb - a pointer to the sk_buff to transmit.
1327 * dev - a pointer to a net_device structure representing HCF_PORT_3.
1333 ******************************************************************************/
1334 int wl_tx_port3(struct sk_buff *skb, struct net_device *dev)
1336 DBG_TX(DbgInfo, "Tx on Port 3\n");
1337 return wl_tx(skb, dev, HCF_PORT_3);
1340 /*============================================================================*/
1342 /*******************************************************************************
1344 *******************************************************************************
1348 * The handler routine for Tx over HCF_PORT_4.
1352 * skb - a pointer to the sk_buff to transmit.
1353 * dev - a pointer to a net_device structure representing HCF_PORT_4.
1359 ******************************************************************************/
1360 int wl_tx_port4(struct sk_buff *skb, struct net_device *dev)
1362 DBG_TX(DbgInfo, "Tx on Port 4\n");
1363 return wl_tx(skb, dev, HCF_PORT_4);
1366 /*============================================================================*/
1368 /*******************************************************************************
1370 *******************************************************************************
1374 * The handler routine for Tx over HCF_PORT_5.
1378 * skb - a pointer to the sk_buff to transmit.
1379 * dev - a pointer to a net_device structure representing HCF_PORT_5.
1385 ******************************************************************************/
1386 int wl_tx_port5(struct sk_buff *skb, struct net_device *dev)
1388 DBG_TX(DbgInfo, "Tx on Port 5\n");
1389 return wl_tx(skb, dev, HCF_PORT_5);
1392 /*============================================================================*/
1394 /*******************************************************************************
1396 *******************************************************************************
1400 * The handler routine for Tx over HCF_PORT_6.
1404 * skb - a pointer to the sk_buff to transmit.
1405 * dev - a pointer to a net_device structure representing HCF_PORT_6.
1411 ******************************************************************************/
1412 int wl_tx_port6(struct sk_buff *skb, struct net_device *dev)
1414 DBG_TX(DbgInfo, "Tx on Port 6\n");
1415 return wl_tx(skb, dev, HCF_PORT_6);
1418 /*============================================================================*/
1420 /*******************************************************************************
1421 * wl_wds_device_alloc()
1422 *******************************************************************************
1426 * Create instances of net_device to represent the WDS ports, and register
1427 * the device's entry points in the net_device structure.
1431 * lp - a pointer to the device's private adapter structure
1435 * N/A, but will place pointers to the allocated and initialized net_device
1436 * structs in the private adapter structure.
1438 ******************************************************************************/
1439 void wl_wds_device_alloc(struct wl_private *lp)
1443 /* WDS support requires additional net_device structs to be allocated,
1444 so that user space apps can use these virtual devices to specify the
1445 port on which to Tx/Rx */
1446 for (count = 0; count < NUM_WDS_PORTS; count++) {
1447 struct net_device *dev_wds = NULL;
1449 dev_wds = kzalloc(sizeof(struct net_device), GFP_KERNEL);
1453 ether_setup(dev_wds);
1455 lp->wds_port[count].dev = dev_wds;
1457 /* Re-use wl_init for all the devices, as it currently does nothing, but
1458 * is required. Re-use the stats/tx_timeout handler for all as well; the
1459 * WDS port which is requesting these operations can be determined by
1460 * the net_device pointer. Set the private member of all devices to point
1461 * to the same net_device struct; that way, all information gets
1462 * funnelled through the one "real" net_device. Name the WDS ports
1465 lp->wds_port[count].dev->init = &wl_init;
1466 lp->wds_port[count].dev->get_stats = &wl_stats;
1467 lp->wds_port[count].dev->tx_timeout = &wl_tx_timeout;
1468 lp->wds_port[count].dev->watchdog_timeo = TX_TIMEOUT;
1469 lp->wds_port[count].dev->priv = lp;
1471 sprintf(lp->wds_port[count].dev->name, "wds%d", count);
1474 /* Register the Tx handlers */
1475 lp->wds_port[0].dev->hard_start_xmit = &wl_tx_port1;
1476 lp->wds_port[1].dev->hard_start_xmit = &wl_tx_port2;
1477 lp->wds_port[2].dev->hard_start_xmit = &wl_tx_port3;
1478 lp->wds_port[3].dev->hard_start_xmit = &wl_tx_port4;
1479 lp->wds_port[4].dev->hard_start_xmit = &wl_tx_port5;
1480 lp->wds_port[5].dev->hard_start_xmit = &wl_tx_port6;
1482 WL_WDS_NETIF_STOP_QUEUE(lp);
1483 } /* wl_wds_device_alloc */
1485 /*============================================================================*/
1487 /*******************************************************************************
1488 * wl_wds_device_dealloc()
1489 *******************************************************************************
1493 * Free instances of net_device structures used to support WDS.
1497 * lp - a pointer to the device's private adapter structure
1503 ******************************************************************************/
1504 void wl_wds_device_dealloc(struct wl_private *lp)
1508 for (count = 0; count < NUM_WDS_PORTS; count++) {
1509 struct net_device *dev_wds = NULL;
1511 dev_wds = lp->wds_port[count].dev;
1513 if (dev_wds != NULL) {
1514 if (dev_wds->flags & IFF_UP) {
1516 dev_wds->flags &= ~(IFF_UP | IFF_RUNNING);
1519 free_netdev(dev_wds);
1520 lp->wds_port[count].dev = NULL;
1523 } /* wl_wds_device_dealloc */
1525 /*============================================================================*/
1527 /*******************************************************************************
1528 * wl_wds_netif_start_queue()
1529 *******************************************************************************
1533 * Used to start the netif queues of all the "virtual" network devices
1534 * which represent the WDS ports.
1538 * lp - a pointer to the device's private adapter structure
1544 ******************************************************************************/
1545 void wl_wds_netif_start_queue(struct wl_private *lp)
1548 /*------------------------------------------------------------------------*/
1551 for (count = 0; count < NUM_WDS_PORTS; count++) {
1552 if (lp->wds_port[count].is_registered &&
1553 lp->wds_port[count].netif_queue_on == FALSE) {
1554 netif_start_queue(lp->wds_port[count].dev);
1555 lp->wds_port[count].netif_queue_on = TRUE;
1559 } /* wl_wds_netif_start_queue */
1561 /*============================================================================*/
1563 /*******************************************************************************
1564 * wl_wds_netif_stop_queue()
1565 *******************************************************************************
1569 * Used to stop the netif queues of all the "virtual" network devices
1570 * which represent the WDS ports.
1574 * lp - a pointer to the device's private adapter structure
1580 ******************************************************************************/
1581 void wl_wds_netif_stop_queue(struct wl_private *lp)
1584 /*------------------------------------------------------------------------*/
1587 for (count = 0; count < NUM_WDS_PORTS; count++) {
1588 if (lp->wds_port[count].is_registered &&
1589 lp->wds_port[count].netif_queue_on == TRUE) {
1590 netif_stop_queue(lp->wds_port[count].dev);
1591 lp->wds_port[count].netif_queue_on = FALSE;
1595 } /* wl_wds_netif_stop_queue */
1597 /*============================================================================*/
1599 /*******************************************************************************
1600 * wl_wds_netif_wake_queue()
1601 *******************************************************************************
1605 * Used to wake the netif queues of all the "virtual" network devices
1606 * which represent the WDS ports.
1610 * lp - a pointer to the device's private adapter structure
1616 ******************************************************************************/
1617 void wl_wds_netif_wake_queue(struct wl_private *lp)
1620 /*------------------------------------------------------------------------*/
1623 for (count = 0; count < NUM_WDS_PORTS; count++) {
1624 if (lp->wds_port[count].is_registered &&
1625 lp->wds_port[count].netif_queue_on == FALSE) {
1626 netif_wake_queue(lp->wds_port[count].dev);
1627 lp->wds_port[count].netif_queue_on = TRUE;
1631 } /* wl_wds_netif_wake_queue */
1633 /*============================================================================*/
1635 /*******************************************************************************
1636 * wl_wds_netif_carrier_on()
1637 *******************************************************************************
1641 * Used to signal the network layer that carrier is present on all of the
1642 * "virtual" network devices which represent the WDS ports.
1646 * lp - a pointer to the device's private adapter structure
1652 ******************************************************************************/
1653 void wl_wds_netif_carrier_on(struct wl_private *lp)
1656 /*------------------------------------------------------------------------*/
1659 for (count = 0; count < NUM_WDS_PORTS; count++) {
1660 if (lp->wds_port[count].is_registered) {
1661 netif_carrier_on(lp->wds_port[count].dev);
1665 } /* wl_wds_netif_carrier_on */
1667 /*============================================================================*/
1669 /*******************************************************************************
1670 * wl_wds_netif_carrier_off()
1671 *******************************************************************************
1675 * Used to signal the network layer that carrier is NOT present on all of
1676 * the "virtual" network devices which represent the WDS ports.
1680 * lp - a pointer to the device's private adapter structure
1686 ******************************************************************************/
1687 void wl_wds_netif_carrier_off(struct wl_private *lp)
1692 for (count = 0; count < NUM_WDS_PORTS; count++) {
1693 if (lp->wds_port[count].is_registered)
1694 netif_carrier_off(lp->wds_port[count].dev);
1698 } /* wl_wds_netif_carrier_off */
1700 /*============================================================================*/
1702 #endif /* USE_WDS */
1705 /*******************************************************************************
1707 *******************************************************************************
1711 * The routine which performs data transmits when using busmaster DMA.
1715 * lp - a pointer to the device's wl_private struct.
1716 * skb - a pointer to the network layer's data buffer.
1717 * port - the Hermes port on which to transmit.
1724 ******************************************************************************/
1725 int wl_send_dma(struct wl_private *lp, struct sk_buff *skb, int port)
1728 DESC_STRCT *desc = NULL;
1729 DESC_STRCT *desc_next = NULL;
1730 /*------------------------------------------------------------------------*/
1733 DBG_ERROR(DbgInfo, "Private adapter struct is NULL\n");
1737 if (lp->dev == NULL) {
1738 DBG_ERROR(DbgInfo, "net_device struct in wl_private is NULL\n");
1742 /* AGAIN, ALL THE QUEUEING DONE HERE IN I/O MODE IS NOT PERFORMED */
1745 DBG_WARNING(DbgInfo, "Nothing to send.\n");
1751 /* Get a free descriptor */
1752 desc = wl_pci_dma_get_tx_packet(lp);
1755 if (lp->netif_queue_on == TRUE) {
1756 netif_stop_queue(lp->dev);
1757 WL_WDS_NETIF_STOP_QUEUE(lp);
1758 lp->netif_queue_on = FALSE;
1765 SET_BUF_CNT(desc, /*HCF_DMA_FD_CNT */ HFS_ADDR_DEST);
1766 SET_BUF_SIZE(desc, HCF_DMA_TX_BUF1_SIZE);
1768 desc_next = desc->next_desc_addr;
1770 if (desc_next->buf_addr == NULL) {
1771 DBG_ERROR(DbgInfo, "DMA descriptor buf_addr is NULL\n");
1775 /* Copy the payload into the DMA packet */
1776 memcpy(desc_next->buf_addr, skb->data, len);
1778 SET_BUF_CNT(desc_next, len);
1779 SET_BUF_SIZE(desc_next, HCF_MAX_PACKET_SIZE);
1781 hcf_dma_tx_put(&(lp->hcfCtx), desc, 0);
1783 /* Free the skb and perform queue cleanup, as the buffer was
1784 transmitted successfully */
1790 /*============================================================================*/
1792 /*******************************************************************************
1794 *******************************************************************************
1798 * The routine which performs data reception when using busmaster DMA.
1802 * dev - a pointer to the device's net_device structure.
1809 ******************************************************************************/
1810 int wl_rx_dma(struct net_device *dev)
1815 struct sk_buff *skb;
1816 struct wl_private *lp = NULL;
1817 DESC_STRCT *desc, *desc_next;
1818 /*------------------------------------------------------------------------*/
1820 DBG_PARAM(DbgInfo, "dev", "%s (0x%p)", dev->name, dev);
1822 if (((lp = dev->priv) != NULL) && !(lp->flags & WVLAN2_UIL_BUSY)) {
1825 if (lp->useRTS == 1) {
1826 DBG_PRINT("RTS: We're getting an Rx...\n");
1829 #endif /* USE_RTS */
1832 *if( lp->dma.status == 0 )
1835 desc = hcf_dma_rx_get(&(lp->hcfCtx));
1838 /* Check and see if we rcvd. a WMP frame */
1840 if((( *(hcf_8 *)&desc->buf_addr[HFS_STAT] ) &
1841 ( HFS_STAT_MSG_TYPE | HFS_STAT_ERR )) == HFS_STAT_WMP_MSG )
1843 DBG_TRACE( DbgInfo, "Got a WMP frame\n" );
1845 x.len = sizeof( CFG_MB_INFO_RANGE2_STRCT ) / sizeof( hcf_16 );
1846 x.typ = CFG_MB_INFO;
1847 x.base_typ = CFG_WMP;
1849 x.frag_buf[0].frag_len = GET_BUF_CNT( descp ) / sizeof( hcf_16 );
1850 x.frag_buf[0].frag_addr = (hcf_8 *) descp->buf_addr ;
1851 x.frag_buf[1].frag_len = ( GET_BUF_CNT( descp->next_desc_addr ) + 1 ) / sizeof( hcf_16 );
1852 x.frag_buf[1].frag_addr = (hcf_8 *) descp->next_desc_addr->buf_addr ;
1854 hcf_put_info( &( lp->hcfCtx ), (LTVP)&x );
1858 desc_next = desc->next_desc_addr;
1860 /* Make sure the buffer isn't empty */
1861 if (GET_BUF_CNT(desc) == 0) {
1862 DBG_WARNING(DbgInfo, "Buffer is empty!\n");
1864 /* Give the descriptor back to the HCF */
1865 hcf_dma_rx_put(&(lp->hcfCtx), desc);
1869 /* Read the HFS_STAT register from the lookahead buffer */
1870 hfs_stat = (hcf_16) (desc->buf_addr[HFS_STAT / 2]);
1872 /* Make sure the frame isn't bad */
1873 if ((hfs_stat & HFS_STAT_ERR) != HCF_SUCCESS) {
1874 DBG_WARNING(DbgInfo,
1875 "HFS_STAT_ERROR (0x%x) in Rx Packet\n",
1876 desc->buf_addr[HFS_STAT / 2]);
1878 /* Give the descriptor back to the HCF */
1879 hcf_dma_rx_put(&(lp->hcfCtx), desc);
1883 /* Determine what port this packet is for */
1884 port = (hfs_stat >> 8) & 0x0007;
1885 DBG_RX(DbgInfo, "Rx frame for port %d\n", port);
1887 pktlen = GET_BUF_CNT(desc_next);
1889 skb = ALLOC_SKB(pktlen);
1900 lp->wds_port[port - 1].dev;
1902 #endif /* USE_WDS */
1910 GET_PACKET_DMA(skb->dev, skb, pktlen);
1912 /* Give the descriptor back to the HCF */
1913 hcf_dma_rx_put(&(lp->hcfCtx), desc);
1918 lp->stats.rx_packets++;
1919 lp->stats.rx_bytes += pktlen;
1930 #endif /* USE_WDS */
1932 dev->last_rx = jiffies;
1936 "Could not alloc skb\n");
1939 lp->stats.rx_dropped++;
1947 #endif /* USE_WDS */
1957 /*============================================================================*/
1958 #endif /* ENABLE_DMA */