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);
234 /* If pStats is still NULL, then the device is not a WDS port */
236 pStats = &(lp->stats);
238 wl_unlock(lp, &flags);
243 /*============================================================================*/
245 /*******************************************************************************
247 *******************************************************************************
255 * dev - a pointer to the device's net_device structure
262 ******************************************************************************/
263 int wl_open(struct net_device *dev)
265 int status = HCF_SUCCESS;
266 struct wl_private *lp = wl_priv(dev);
272 if (lp->useRTS == 1) {
273 DBG_TRACE(DbgInfo, "Skipping device open, in RTS mode\n");
274 wl_unlock(lp, &flags);
283 if (lp->portState == WVLAN_PORT_STATE_DISABLED) {
284 DBG_TRACE(DbgInfo, "Enabling Port 0\n");
285 status = wl_enable(lp);
287 if (status != HCF_SUCCESS) {
288 DBG_TRACE(DbgInfo, "Enable port 0 failed: 0x%x\n",
293 /* Holding the lock too long, make a gap to allow other processes */
294 wl_unlock(lp, &flags);
297 if (strlen(lp->fw_image_filename)) {
298 DBG_TRACE(DbgInfo, ";???? Kludgy way to force a download\n");
301 status = wl_apply(lp);
304 /* Holding the lock too long, make a gap to allow other processes */
305 wl_unlock(lp, &flags);
308 /* Unsuccessful, try reset of the card to recover */
309 if (status != HCF_SUCCESS)
310 status = wl_reset(dev);
312 /* Holding the lock too long, make a gap to allow other processes */
313 wl_unlock(lp, &flags);
316 if (status == HCF_SUCCESS) {
317 netif_carrier_on(dev);
318 WL_WDS_NETIF_CARRIER_ON(lp);
320 /* Start handling interrupts */
321 lp->is_handling_int = WL_HANDLING_INT;
324 netif_start_queue(dev);
325 WL_WDS_NETIF_START_QUEUE(lp);
327 wl_hcf_error(dev, status); /* Report the error */
328 netif_device_detach(dev); /* Stop the device and queue */
331 wl_unlock(lp, &flags);
336 /*============================================================================*/
338 /*******************************************************************************
340 *******************************************************************************
348 * dev - a pointer to the device's net_device structure
355 ******************************************************************************/
356 int wl_close(struct net_device *dev)
358 struct wl_private *lp = wl_priv(dev);
361 DBG_PARAM(DbgInfo, "dev", "%s (0x%p)", dev->name, dev);
363 /* Mark the adapter as busy */
364 netif_stop_queue(dev);
365 WL_WDS_NETIF_STOP_QUEUE(lp);
367 netif_carrier_off(dev);
368 WL_WDS_NETIF_CARRIER_OFF(lp);
371 * Shutdown the adapter:
372 * Disable adapter interrupts
381 /* Stop handling interrupts */
382 lp->is_handling_int = WL_NOT_HANDLING_INT;
385 if (lp->useRTS == 1) {
386 DBG_TRACE(DbgInfo, "Skipping device close, in RTS mode\n");
387 wl_unlock(lp, &flags);
392 /* Disable the ports */
395 wl_unlock(lp, &flags);
400 /*============================================================================*/
402 static void wl_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info)
404 strlcpy(info->driver, DRIVER_NAME, sizeof(info->driver));
405 strlcpy(info->version, DRV_VERSION_STR, sizeof(info->version));
407 if (dev->dev.parent) {
408 dev_set_name(dev->dev.parent, "%s", info->bus_info);
410 snprintf(info->bus_info, sizeof(info->bus_info),
413 } /* wl_get_drvinfo */
415 static struct ethtool_ops wl_ethtool_ops = {
416 .get_drvinfo = wl_get_drvinfo,
417 .get_link = ethtool_op_get_link,
420 /*******************************************************************************
422 *******************************************************************************
426 * The IOCTL handler for the device.
430 * dev - a pointer to the device's net_device struct.
431 * rq - a pointer to the IOCTL request buffer.
432 * cmd - the IOCTL command code.
437 * errno value otherwise
439 ******************************************************************************/
440 int wl_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
442 struct wl_private *lp = wl_priv(dev);
446 DBG_PARAM(DbgInfo, "dev", "%s (0x%p)", dev->name, dev);
447 DBG_PARAM(DbgInfo, "rq", "0x%p", rq);
448 DBG_PARAM(DbgInfo, "cmd", "0x%04x", cmd);
455 if (lp->useRTS == 1) {
456 /* Handle any RTS IOCTL here */
457 if (cmd == WL_IOCTL_RTS) {
458 DBG_TRACE(DbgInfo, "IOCTL: WL_IOCTL_RTS\n");
459 ret = wvlan_rts((struct rtsreq *)rq, dev->base_addr);
462 "IOCTL not supported in RTS mode: 0x%X\n",
467 goto out_act_int_on_unlock;
471 /* Only handle UIL IOCTL requests when the UIL has the system blocked. */
472 if (!((lp->flags & WVLAN2_UIL_BUSY) && (cmd != WVLAN2_IOCTL_UIL))) {
474 struct uilreq *urq = (struct uilreq *)rq;
478 /* ================== Private IOCTLs (up to 16) ================== */
480 case WVLAN2_IOCTL_UIL:
481 DBG_TRACE(DbgInfo, "IOCTL: WVLAN2_IOCTL_UIL\n");
482 ret = wvlan_uil(urq, lp);
487 DBG_TRACE(DbgInfo, "IOCTL CODE NOT SUPPORTED: 0x%X\n",
494 "DEVICE IS BUSY, CANNOT PROCESS REQUEST\n");
499 out_act_int_on_unlock:
503 wl_unlock(lp, &flags);
508 /*============================================================================*/
510 #ifdef CONFIG_NET_POLL_CONTROLLER
511 static void wl_poll(struct net_device *dev)
513 struct wl_private *lp = wl_priv(dev);
518 wl_isr(dev->irq, dev, ®s);
519 wl_unlock(lp, &flags);
523 /*******************************************************************************
525 *******************************************************************************
529 * The handler called when, for some reason, a Tx request is not completed.
533 * dev - a pointer to the device's net_device struct.
539 ******************************************************************************/
540 void wl_tx_timeout(struct net_device *dev)
546 struct wl_private *lp = wl_priv(dev);
547 struct net_device_stats *pStats = NULL;
549 DBG_WARNING(DbgInfo, "%s: Transmit timeout.\n", dev->name);
554 if (lp->useRTS == 1) {
556 "Skipping tx_timeout handler, in RTS mode\n");
557 wl_unlock(lp, &flags);
562 /* Figure out which device (the "root" device or WDS port) this timeout
566 for (count = 0; count < NUM_WDS_PORTS; count++) {
567 if (dev == lp->wds_port[count].dev) {
568 pStats = &(lp->wds_port[count].stats);
570 /* Break the loop so that we can use the counter to access WDS
571 information in the private structure */
578 /* If pStats is still NULL, then the device is not a WDS port */
580 pStats = &(lp->stats);
582 /* Accumulate the timeout error */
585 wl_unlock(lp, &flags);
586 } /* wl_tx_timeout */
588 /*============================================================================*/
590 /*******************************************************************************
592 *******************************************************************************
596 * The routine which performs data transmits.
600 * lp - a pointer to the device's wl_private struct.
607 ******************************************************************************/
608 int wl_send(struct wl_private *lp)
613 WVLAN_LFRAME *txF = NULL;
614 struct list_head *element;
616 /*------------------------------------------------------------------------*/
619 DBG_ERROR(DbgInfo, "Private adapter struct is NULL\n");
622 if (lp->dev == NULL) {
623 DBG_ERROR(DbgInfo, "net_device struct in wl_private is NULL\n");
628 * Check for the availability of FIDs; if none are available,
629 * don't take any frames off the txQ
631 if (lp->hcfCtx.IFB_RscInd == 0)
634 /* Reclaim the TxQ Elements and place them back on the free queue */
635 if (!list_empty(&(lp->txQ[0]))) {
636 element = lp->txQ[0].next;
638 txF = (WVLAN_LFRAME *) list_entry(element, WVLAN_LFRAME, node);
640 lp->txF.skb = txF->frame.skb;
641 lp->txF.port = txF->frame.port;
643 txF->frame.skb = NULL;
646 list_del(&(txF->node));
647 list_add(element, &(lp->txFree));
651 if (lp->txQ_count < TX_Q_LOW_WATER_MARK) {
652 if (lp->netif_queue_on == FALSE) {
653 DBG_TX(DbgInfo, "Kickstarting Q: %d\n",
655 netif_wake_queue(lp->dev);
656 WL_WDS_NETIF_WAKE_QUEUE(lp);
657 lp->netif_queue_on = TRUE;
663 if (lp->txF.skb == NULL)
666 /* If the device has resources (FIDs) available, then Tx the packet */
667 /* Format the TxRequest and send it to the adapter */
668 len = lp->txF.skb->len < ETH_ZLEN ? ETH_ZLEN : lp->txF.skb->len;
670 desc = &(lp->desc_tx);
671 desc->buf_addr = lp->txF.skb->data;
673 desc->next_desc_addr = NULL;
675 status = hcf_send_msg(&(lp->hcfCtx), desc, lp->txF.port);
677 if (status == HCF_SUCCESS) {
678 lp->dev->trans_start = jiffies;
680 DBG_TX(DbgInfo, "Transmit...\n");
682 if (lp->txF.port == HCF_PORT_0) {
683 lp->stats.tx_packets++;
684 lp->stats.tx_bytes += lp->txF.skb->len;
688 lp->wds_port[((lp->txF.port >> 8) -
689 1)].stats.tx_packets++;
690 lp->wds_port[((lp->txF.port >> 8) -
691 1)].stats.tx_bytes += lp->txF.skb->len;
696 /* Free the skb and perform queue cleanup, as the buffer was
697 transmitted successfully */
698 dev_consume_skb_any( lp->txF.skb );
707 /*============================================================================*/
709 /*******************************************************************************
711 *******************************************************************************
715 * The Tx handler function for the network layer.
719 * skb - a pointer to the sk_buff structure containing the data to transfer.
720 * dev - a pointer to the device's net_device structure.
727 ******************************************************************************/
728 int wl_tx(struct sk_buff *skb, struct net_device *dev, int port)
731 struct wl_private *lp = wl_priv(dev);
732 WVLAN_LFRAME *txF = NULL;
733 struct list_head *element;
734 /*------------------------------------------------------------------------*/
736 /* Grab the spinlock */
739 if (lp->flags & WVLAN2_UIL_BUSY) {
740 DBG_WARNING(DbgInfo, "UIL has device blocked\n");
741 /* Start dropping packets here??? */
742 wl_unlock(lp, &flags);
746 if (lp->useRTS == 1) {
747 DBG_PRINT("RTS: we're getting a Tx...\n");
748 wl_unlock(lp, &flags);
754 /* Get an element from the queue */
755 element = lp->txFree.next;
756 txF = (WVLAN_LFRAME *) list_entry(element, WVLAN_LFRAME, node);
758 DBG_ERROR(DbgInfo, "Problem with list_entry\n");
759 wl_unlock(lp, &flags);
762 /* Fill out the frame */
763 txF->frame.skb = skb;
764 txF->frame.port = port;
765 /* Move the frame to the txQ */
766 /* NOTE: Here's where we would do priority queueing */
767 list_move(&(txF->node), &(lp->txQ[0]));
770 if (lp->txQ_count >= DEFAULT_NUM_TX_FRAMES) {
771 DBG_TX(DbgInfo, "Q Full: %d\n", lp->txQ_count);
772 if (lp->netif_queue_on == TRUE) {
773 netif_stop_queue(lp->dev);
774 WL_WDS_NETIF_STOP_QUEUE(lp);
775 lp->netif_queue_on = FALSE;
779 wl_act_int_off(lp); /* Disable Interrupts */
781 /* Send the data to the hardware using the appropriate method */
784 wl_send_dma(lp, skb, port);
790 /* Re-enable Interrupts, release the spinlock and return */
792 wl_unlock(lp, &flags);
796 /*============================================================================*/
798 /*******************************************************************************
800 *******************************************************************************
804 * The routine which performs data reception.
808 * dev - a pointer to the device's net_device structure.
815 ******************************************************************************/
816 int wl_rx(struct net_device *dev)
820 struct wl_private *lp = wl_priv(dev);
825 /*------------------------------------------------------------------------*/
827 DBG_PARAM(DbgInfo, "dev", "%s (0x%p)", dev->name, dev);
829 if (!(lp->flags & WVLAN2_UIL_BUSY)) {
832 if (lp->useRTS == 1) {
833 DBG_PRINT("RTS: We're getting an Rx...\n");
838 /* Read the HFS_STAT register from the lookahead buffer */
839 hfs_stat = (hcf_16) ((lp->lookAheadBuf[HFS_STAT]) |
840 (lp->lookAheadBuf[HFS_STAT + 1] << 8));
842 /* Make sure the frame isn't bad */
843 if ((hfs_stat & HFS_STAT_ERR) != HCF_SUCCESS) {
845 "HFS_STAT_ERROR (0x%x) in Rx Packet\n",
846 lp->lookAheadBuf[HFS_STAT]);
850 /* Determine what port this packet is for */
851 port = (hfs_stat >> 8) & 0x0007;
852 DBG_RX(DbgInfo, "Rx frame for port %d\n", port);
854 pktlen = lp->hcfCtx.IFB_RxLen;
856 skb = ALLOC_SKB(pktlen);
858 /* Set the netdev based on the port */
867 skb->dev = lp->wds_port[port - 1].dev;
877 desc = &(lp->desc_rx);
879 desc->next_desc_addr = NULL;
882 #define BLOCK_INPUT(buf, len) \
883 desc->buf_addr = buf; \
884 desc->BUF_SIZE = len; \
885 status = hcf_rcv_msg(&(lp->hcfCtx), desc, 0)
888 GET_PACKET(skb->dev, skb, pktlen);
890 if (status == HCF_SUCCESS) {
894 lp->stats.rx_packets++;
895 lp->stats.rx_bytes += pktlen;
908 dev->last_rx = jiffies;
912 if (lp->spydata.spy_number > 0) {
917 wl_spy_gather(dev, srcaddr);
919 #endif /* WIRELESS_SPY */
920 #endif /* WIRELESS_EXT */
923 "Rx request to card FAILED\n");
926 lp->stats.rx_dropped++;
938 DBG_ERROR(DbgInfo, "Could not alloc skb\n");
941 lp->stats.rx_dropped++;
945 1].stats.rx_dropped++;
955 /*============================================================================*/
957 /*******************************************************************************
959 *******************************************************************************
963 * Function to handle multicast packets
967 * dev - a pointer to the device's net_device structure.
973 ******************************************************************************/
976 void wl_multicast(struct net_device *dev)
978 #if 1 /* (HCF_TYPE) & HCF_TYPE_STA */
980 * should we return an error status in AP mode ?
981 * seems reasonable that even an AP-only driver
982 * could afford this small additional footprint
986 struct netdev_hw_addr *ha;
987 struct wl_private *lp = wl_priv(dev);
990 DBG_PARAM(DbgInfo, "dev", "%s (0x%p)", dev->name, dev);
992 if (!wl_adapter_is_open(dev))
996 if (DBG_FLAGS(DbgInfo) & DBG_PARAM_ON) {
997 DBG_PRINT(" flags: %s%s%s\n",
998 (dev->flags & IFF_PROMISC) ? "Promiscuous " : "",
999 (dev->flags & IFF_MULTICAST) ? "Multicast " : "",
1000 (dev->flags & IFF_ALLMULTI) ? "All-Multicast" : "");
1002 DBG_PRINT(" mc_count: %d\n", netdev_mc_count(dev));
1004 netdev_for_each_mc_addr(ha, dev)
1005 DBG_PRINT(" %pM (%d)\n", ha->addr, dev->addr_len);
1009 if (!(lp->flags & WVLAN2_UIL_BUSY)) {
1012 if (lp->useRTS == 1) {
1013 DBG_TRACE(DbgInfo, "Skipping multicast, in RTS mode\n");
1016 #endif /* USE_RTS */
1018 wl_lock(lp, &flags);
1021 if (CNV_INT_TO_LITTLE(lp->hcfCtx.IFB_FWIdentity.comp_id) ==
1023 if (dev->flags & IFF_PROMISC) {
1024 /* Enable promiscuous mode */
1025 lp->ltvRecord.len = 2;
1026 lp->ltvRecord.typ = CFG_PROMISCUOUS_MODE;
1027 lp->ltvRecord.u.u16[0] = CNV_INT_TO_LITTLE(1);
1029 ("Enabling Promiscuous mode (IFF_PROMISC)\n");
1030 hcf_put_info(&(lp->hcfCtx),
1031 (LTVP) & (lp->ltvRecord));
1032 } else if ((netdev_mc_count(dev) > HCF_MAX_MULTICAST)
1033 || (dev->flags & IFF_ALLMULTI)) {
1034 /* Shutting off this filter will enable all multicast frames to
1035 be sent up from the device; however, this is a static RID, so
1036 a call to wl_apply() is needed */
1037 lp->ltvRecord.len = 2;
1038 lp->ltvRecord.typ = CFG_CNF_RX_ALL_GROUP_ADDR;
1039 lp->ltvRecord.u.u16[0] = CNV_INT_TO_LITTLE(0);
1041 ("Enabling all multicast mode (IFF_ALLMULTI)\n");
1042 hcf_put_info(&(lp->hcfCtx),
1043 (LTVP) & (lp->ltvRecord));
1045 } else if (!netdev_mc_empty(dev)) {
1046 /* Set the multicast addresses */
1048 (netdev_mc_count(dev) * 3) + 1;
1049 lp->ltvRecord.typ = CFG_GROUP_ADDR;
1052 netdev_for_each_mc_addr(ha, dev)
1054 (lp->ltvRecord.u.u8[x++ * ETH_ALEN]),
1055 ha->addr, ETH_ALEN);
1056 DBG_PRINT("Setting multicast list\n");
1057 hcf_put_info(&(lp->hcfCtx),
1058 (LTVP) & (lp->ltvRecord));
1060 /* Disable promiscuous mode */
1061 lp->ltvRecord.len = 2;
1062 lp->ltvRecord.typ = CFG_PROMISCUOUS_MODE;
1063 lp->ltvRecord.u.u16[0] = CNV_INT_TO_LITTLE(0);
1064 DBG_PRINT("Disabling Promiscuous mode\n");
1065 hcf_put_info(&(lp->hcfCtx),
1066 (LTVP) & (lp->ltvRecord));
1068 /* Disable multicast mode */
1069 lp->ltvRecord.len = 2;
1070 lp->ltvRecord.typ = CFG_GROUP_ADDR;
1071 DBG_PRINT("Disabling Multicast mode\n");
1072 hcf_put_info(&(lp->hcfCtx),
1073 (LTVP) & (lp->ltvRecord));
1076 * Turning on this filter will prevent all multicast frames from
1077 * being sent up from the device; however, this is a static RID,
1078 * so a call to wl_apply() is needed
1080 lp->ltvRecord.len = 2;
1081 lp->ltvRecord.typ = CFG_CNF_RX_ALL_GROUP_ADDR;
1082 lp->ltvRecord.u.u16[0] = CNV_INT_TO_LITTLE(1);
1084 ("Disabling all multicast mode (IFF_ALLMULTI)\n");
1085 hcf_put_info(&(lp->hcfCtx),
1086 (LTVP) & (lp->ltvRecord));
1091 wl_unlock(lp, &flags);
1093 #endif /* HCF_STA */
1094 } /* wl_multicast */
1096 /*============================================================================*/
1098 #else /* NEW_MULTICAST */
1100 void wl_multicast(struct net_device *dev, int num_addrs, void *addrs)
1102 DBG_PARAM(DbgInfo, "dev", "%s (0x%p)", dev->name, dev);
1103 DBG_PARAM(DbgInfo, "num_addrs", "%d", num_addrs);
1104 DBG_PARAM(DbgInfo, "addrs", "0x%p", addrs);
1106 #error Obsolete set multicast interface!
1107 } /* wl_multicast */
1109 /*============================================================================*/
1111 #endif /* NEW_MULTICAST */
1113 static const struct net_device_ops wl_netdev_ops = {
1114 .ndo_start_xmit = &wl_tx_port0,
1116 .ndo_set_config = &wl_config,
1117 .ndo_get_stats = &wl_stats,
1118 .ndo_set_rx_mode = &wl_multicast,
1120 .ndo_init = &wl_insert,
1121 .ndo_open = &wl_adapter_open,
1122 .ndo_stop = &wl_adapter_close,
1123 .ndo_do_ioctl = &wl_ioctl,
1125 .ndo_tx_timeout = &wl_tx_timeout,
1127 #ifdef CONFIG_NET_POLL_CONTROLLER
1128 .ndo_poll_controller = wl_poll,
1132 /*******************************************************************************
1134 *******************************************************************************
1138 * Create instances of net_device and wl_private for the new adapter
1139 * and register the device's entry points in the net_device structure.
1147 * a pointer to an allocated and initialized net_device struct for this
1150 ******************************************************************************/
1151 struct net_device *wl_device_alloc(void)
1153 struct net_device *dev = NULL;
1154 struct wl_private *lp = NULL;
1156 /* Alloc a net_device struct */
1157 dev = alloc_etherdev(sizeof(struct wl_private));
1162 * Initialize the 'next' pointer in the struct.
1163 * Currently only used for PCI,
1164 * but do it here just in case it's used
1165 * for other buses in the future
1170 if (dev->mtu > MTU_MAX) {
1171 DBG_WARNING(DbgInfo, "%s: MTU set too high, limiting to %d.\n",
1172 dev->name, MTU_MAX);
1176 /* Setup the function table in the device structure. */
1178 dev->wireless_handlers = (struct iw_handler_def *)&wl_iw_handler_def;
1179 lp->wireless_data.spy_data = &lp->spy_data;
1180 dev->wireless_data = &lp->wireless_data;
1182 dev->netdev_ops = &wl_netdev_ops;
1184 dev->watchdog_timeo = TX_TIMEOUT;
1186 dev->ethtool_ops = &wl_ethtool_ops;
1188 netif_stop_queue(dev);
1190 /* Allocate virtual devices for WDS support if needed */
1191 WL_WDS_DEVICE_ALLOC(lp);
1194 } /* wl_device_alloc */
1196 /*============================================================================*/
1198 /*******************************************************************************
1199 * wl_device_dealloc()
1200 *******************************************************************************
1204 * Free instances of net_device and wl_private strcutres for an adapter
1205 * and perform basic cleanup.
1209 * dev - a pointer to the device's net_device structure.
1215 ******************************************************************************/
1216 void wl_device_dealloc(struct net_device *dev)
1218 /* Dealloc the WDS ports */
1219 WL_WDS_DEVICE_DEALLOC(lp);
1222 } /* wl_device_dealloc */
1224 /*============================================================================*/
1226 /*******************************************************************************
1228 *******************************************************************************
1232 * The handler routine for Tx over HCF_PORT_0.
1236 * skb - a pointer to the sk_buff to transmit.
1237 * dev - a pointer to a net_device structure representing HCF_PORT_0.
1243 ******************************************************************************/
1244 int wl_tx_port0(struct sk_buff *skb, struct net_device *dev)
1246 DBG_TX(DbgInfo, "Tx on Port 0\n");
1248 return wl_tx(skb, dev, HCF_PORT_0);
1250 return wl_tx_dma(skb, dev, HCF_PORT_0);
1252 } /* wl_tx_port0i */
1254 /*============================================================================*/
1258 /*******************************************************************************
1260 *******************************************************************************
1264 * The handler routine for Tx over HCF_PORT_1.
1268 * skb - a pointer to the sk_buff to transmit.
1269 * dev - a pointer to a net_device structure representing HCF_PORT_1.
1275 ******************************************************************************/
1276 int wl_tx_port1(struct sk_buff *skb, struct net_device *dev)
1278 DBG_TX(DbgInfo, "Tx on Port 1\n");
1279 return wl_tx(skb, dev, HCF_PORT_1);
1282 /*============================================================================*/
1284 /*******************************************************************************
1286 *******************************************************************************
1290 * The handler routine for Tx over HCF_PORT_2.
1294 * skb - a pointer to the sk_buff to transmit.
1295 * dev - a pointer to a net_device structure representing HCF_PORT_2.
1301 ******************************************************************************/
1302 int wl_tx_port2(struct sk_buff *skb, struct net_device *dev)
1304 DBG_TX(DbgInfo, "Tx on Port 2\n");
1305 return wl_tx(skb, dev, HCF_PORT_2);
1308 /*============================================================================*/
1310 /*******************************************************************************
1312 *******************************************************************************
1316 * The handler routine for Tx over HCF_PORT_3.
1320 * skb - a pointer to the sk_buff to transmit.
1321 * dev - a pointer to a net_device structure representing HCF_PORT_3.
1327 ******************************************************************************/
1328 int wl_tx_port3(struct sk_buff *skb, struct net_device *dev)
1330 DBG_TX(DbgInfo, "Tx on Port 3\n");
1331 return wl_tx(skb, dev, HCF_PORT_3);
1334 /*============================================================================*/
1336 /*******************************************************************************
1338 *******************************************************************************
1342 * The handler routine for Tx over HCF_PORT_4.
1346 * skb - a pointer to the sk_buff to transmit.
1347 * dev - a pointer to a net_device structure representing HCF_PORT_4.
1353 ******************************************************************************/
1354 int wl_tx_port4(struct sk_buff *skb, struct net_device *dev)
1356 DBG_TX(DbgInfo, "Tx on Port 4\n");
1357 return wl_tx(skb, dev, HCF_PORT_4);
1360 /*============================================================================*/
1362 /*******************************************************************************
1364 *******************************************************************************
1368 * The handler routine for Tx over HCF_PORT_5.
1372 * skb - a pointer to the sk_buff to transmit.
1373 * dev - a pointer to a net_device structure representing HCF_PORT_5.
1379 ******************************************************************************/
1380 int wl_tx_port5(struct sk_buff *skb, struct net_device *dev)
1382 DBG_TX(DbgInfo, "Tx on Port 5\n");
1383 return wl_tx(skb, dev, HCF_PORT_5);
1386 /*============================================================================*/
1388 /*******************************************************************************
1390 *******************************************************************************
1394 * The handler routine for Tx over HCF_PORT_6.
1398 * skb - a pointer to the sk_buff to transmit.
1399 * dev - a pointer to a net_device structure representing HCF_PORT_6.
1405 ******************************************************************************/
1406 int wl_tx_port6(struct sk_buff *skb, struct net_device *dev)
1408 DBG_TX(DbgInfo, "Tx on Port 6\n");
1409 return wl_tx(skb, dev, HCF_PORT_6);
1412 /*============================================================================*/
1414 /*******************************************************************************
1415 * wl_wds_device_alloc()
1416 *******************************************************************************
1420 * Create instances of net_device to represent the WDS ports, and register
1421 * the device's entry points in the net_device structure.
1425 * lp - a pointer to the device's private adapter structure
1429 * N/A, but will place pointers to the allocated and initialized net_device
1430 * structs in the private adapter structure.
1432 ******************************************************************************/
1433 void wl_wds_device_alloc(struct wl_private *lp)
1437 /* WDS support requires additional net_device structs to be allocated,
1438 so that user space apps can use these virtual devices to specify the
1439 port on which to Tx/Rx */
1440 for (count = 0; count < NUM_WDS_PORTS; count++) {
1441 struct net_device *dev_wds = NULL;
1443 dev_wds = kzalloc(sizeof(struct net_device), GFP_KERNEL);
1447 ether_setup(dev_wds);
1449 lp->wds_port[count].dev = dev_wds;
1451 /* Re-use wl_init for all the devices, as it currently does nothing, but
1452 * is required. Re-use the stats/tx_timeout handler for all as well; the
1453 * WDS port which is requesting these operations can be determined by
1454 * the net_device pointer. Set the private member of all devices to point
1455 * to the same net_device struct; that way, all information gets
1456 * funnelled through the one "real" net_device. Name the WDS ports
1459 lp->wds_port[count].dev->init = &wl_init;
1460 lp->wds_port[count].dev->get_stats = &wl_stats;
1461 lp->wds_port[count].dev->tx_timeout = &wl_tx_timeout;
1462 lp->wds_port[count].dev->watchdog_timeo = TX_TIMEOUT;
1463 lp->wds_port[count].dev->priv = lp;
1465 sprintf(lp->wds_port[count].dev->name, "wds%d", count);
1468 /* Register the Tx handlers */
1469 lp->wds_port[0].dev->hard_start_xmit = &wl_tx_port1;
1470 lp->wds_port[1].dev->hard_start_xmit = &wl_tx_port2;
1471 lp->wds_port[2].dev->hard_start_xmit = &wl_tx_port3;
1472 lp->wds_port[3].dev->hard_start_xmit = &wl_tx_port4;
1473 lp->wds_port[4].dev->hard_start_xmit = &wl_tx_port5;
1474 lp->wds_port[5].dev->hard_start_xmit = &wl_tx_port6;
1476 WL_WDS_NETIF_STOP_QUEUE(lp);
1477 } /* wl_wds_device_alloc */
1479 /*============================================================================*/
1481 /*******************************************************************************
1482 * wl_wds_device_dealloc()
1483 *******************************************************************************
1487 * Free instances of net_device structures used to support WDS.
1491 * lp - a pointer to the device's private adapter structure
1497 ******************************************************************************/
1498 void wl_wds_device_dealloc(struct wl_private *lp)
1502 for (count = 0; count < NUM_WDS_PORTS; count++) {
1503 struct net_device *dev_wds = NULL;
1505 dev_wds = lp->wds_port[count].dev;
1507 if (dev_wds != NULL) {
1508 if (dev_wds->flags & IFF_UP) {
1510 dev_wds->flags &= ~(IFF_UP | IFF_RUNNING);
1513 free_netdev(dev_wds);
1514 lp->wds_port[count].dev = NULL;
1517 } /* wl_wds_device_dealloc */
1519 /*============================================================================*/
1521 /*******************************************************************************
1522 * wl_wds_netif_start_queue()
1523 *******************************************************************************
1527 * Used to start the netif queues of all the "virtual" network devices
1528 * which represent the WDS ports.
1532 * lp - a pointer to the device's private adapter structure
1538 ******************************************************************************/
1539 void wl_wds_netif_start_queue(struct wl_private *lp)
1542 /*------------------------------------------------------------------------*/
1545 for (count = 0; count < NUM_WDS_PORTS; count++) {
1546 if (lp->wds_port[count].is_registered &&
1547 lp->wds_port[count].netif_queue_on == FALSE) {
1548 netif_start_queue(lp->wds_port[count].dev);
1549 lp->wds_port[count].netif_queue_on = TRUE;
1553 } /* wl_wds_netif_start_queue */
1555 /*============================================================================*/
1557 /*******************************************************************************
1558 * wl_wds_netif_stop_queue()
1559 *******************************************************************************
1563 * Used to stop the netif queues of all the "virtual" network devices
1564 * which represent the WDS ports.
1568 * lp - a pointer to the device's private adapter structure
1574 ******************************************************************************/
1575 void wl_wds_netif_stop_queue(struct wl_private *lp)
1578 /*------------------------------------------------------------------------*/
1581 for (count = 0; count < NUM_WDS_PORTS; count++) {
1582 if (lp->wds_port[count].is_registered &&
1583 lp->wds_port[count].netif_queue_on == TRUE) {
1584 netif_stop_queue(lp->wds_port[count].dev);
1585 lp->wds_port[count].netif_queue_on = FALSE;
1589 } /* wl_wds_netif_stop_queue */
1591 /*============================================================================*/
1593 /*******************************************************************************
1594 * wl_wds_netif_wake_queue()
1595 *******************************************************************************
1599 * Used to wake the netif queues of all the "virtual" network devices
1600 * which represent the WDS ports.
1604 * lp - a pointer to the device's private adapter structure
1610 ******************************************************************************/
1611 void wl_wds_netif_wake_queue(struct wl_private *lp)
1614 /*------------------------------------------------------------------------*/
1617 for (count = 0; count < NUM_WDS_PORTS; count++) {
1618 if (lp->wds_port[count].is_registered &&
1619 lp->wds_port[count].netif_queue_on == FALSE) {
1620 netif_wake_queue(lp->wds_port[count].dev);
1621 lp->wds_port[count].netif_queue_on = TRUE;
1625 } /* wl_wds_netif_wake_queue */
1627 /*============================================================================*/
1629 /*******************************************************************************
1630 * wl_wds_netif_carrier_on()
1631 *******************************************************************************
1635 * Used to signal the network layer that carrier is present on all of the
1636 * "virtual" network devices which represent the WDS ports.
1640 * lp - a pointer to the device's private adapter structure
1646 ******************************************************************************/
1647 void wl_wds_netif_carrier_on(struct wl_private *lp)
1650 /*------------------------------------------------------------------------*/
1653 for (count = 0; count < NUM_WDS_PORTS; count++) {
1654 if (lp->wds_port[count].is_registered)
1655 netif_carrier_on(lp->wds_port[count].dev);
1658 } /* wl_wds_netif_carrier_on */
1660 /*============================================================================*/
1662 /*******************************************************************************
1663 * wl_wds_netif_carrier_off()
1664 *******************************************************************************
1668 * Used to signal the network layer that carrier is NOT present on all of
1669 * the "virtual" network devices which represent the WDS ports.
1673 * lp - a pointer to the device's private adapter structure
1679 ******************************************************************************/
1680 void wl_wds_netif_carrier_off(struct wl_private *lp)
1685 for (count = 0; count < NUM_WDS_PORTS; count++) {
1686 if (lp->wds_port[count].is_registered)
1687 netif_carrier_off(lp->wds_port[count].dev);
1691 } /* wl_wds_netif_carrier_off */
1693 /*============================================================================*/
1695 #endif /* USE_WDS */
1698 /*******************************************************************************
1700 *******************************************************************************
1704 * The routine which performs data transmits when using busmaster DMA.
1708 * lp - a pointer to the device's wl_private struct.
1709 * skb - a pointer to the network layer's data buffer.
1710 * port - the Hermes port on which to transmit.
1717 ******************************************************************************/
1718 int wl_send_dma(struct wl_private *lp, struct sk_buff *skb, int port)
1721 DESC_STRCT *desc = NULL;
1722 DESC_STRCT *desc_next = NULL;
1723 /*------------------------------------------------------------------------*/
1726 DBG_ERROR(DbgInfo, "Private adapter struct is NULL\n");
1730 if (lp->dev == NULL) {
1731 DBG_ERROR(DbgInfo, "net_device struct in wl_private is NULL\n");
1735 /* AGAIN, ALL THE QUEUEING DONE HERE IN I/O MODE IS NOT PERFORMED */
1738 DBG_WARNING(DbgInfo, "Nothing to send.\n");
1744 /* Get a free descriptor */
1745 desc = wl_pci_dma_get_tx_packet(lp);
1748 if (lp->netif_queue_on == TRUE) {
1749 netif_stop_queue(lp->dev);
1750 WL_WDS_NETIF_STOP_QUEUE(lp);
1751 lp->netif_queue_on = FALSE;
1753 dev_kfree_skb_any( skb );
1758 SET_BUF_CNT(desc, /*HCF_DMA_FD_CNT */ HFS_ADDR_DEST);
1759 SET_BUF_SIZE(desc, HCF_DMA_TX_BUF1_SIZE);
1761 desc_next = desc->next_desc_addr;
1763 if (desc_next->buf_addr == NULL) {
1764 DBG_ERROR(DbgInfo, "DMA descriptor buf_addr is NULL\n");
1768 /* Copy the payload into the DMA packet */
1769 memcpy(desc_next->buf_addr, skb->data, len);
1771 SET_BUF_CNT(desc_next, len);
1772 SET_BUF_SIZE(desc_next, HCF_MAX_PACKET_SIZE);
1774 hcf_dma_tx_put(&(lp->hcfCtx), desc, 0);
1776 /* Free the skb and perform queue cleanup, as the buffer was
1777 transmitted successfully */
1778 dev_consume_skb_any( skb );
1783 /*============================================================================*/
1785 /*******************************************************************************
1787 *******************************************************************************
1791 * The routine which performs data reception when using busmaster DMA.
1795 * dev - a pointer to the device's net_device structure.
1802 ******************************************************************************/
1803 int wl_rx_dma(struct net_device *dev)
1808 struct sk_buff *skb;
1809 struct wl_private *lp = NULL;
1810 DESC_STRCT *desc, *desc_next;
1811 /*------------------------------------------------------------------------*/
1813 DBG_PARAM(DbgInfo, "dev", "%s (0x%p)", dev->name, dev);
1816 if ((lp != NULL) && !(lp->flags & WVLAN2_UIL_BUSY)) {
1819 if (lp->useRTS == 1) {
1820 DBG_PRINT("RTS: We're getting an Rx...\n");
1823 #endif /* USE_RTS */
1826 *if( lp->dma.status == 0 )
1829 desc = hcf_dma_rx_get(&(lp->hcfCtx));
1832 /* Check and see if we rcvd. a WMP frame */
1834 if((( *(hcf_8 *)&desc->buf_addr[HFS_STAT] ) &
1835 ( HFS_STAT_MSG_TYPE | HFS_STAT_ERR )) == HFS_STAT_WMP_MSG )
1837 DBG_TRACE( DbgInfo, "Got a WMP frame\n" );
1839 x.len = sizeof( CFG_MB_INFO_RANGE2_STRCT ) / sizeof( hcf_16 );
1840 x.typ = CFG_MB_INFO;
1841 x.base_typ = CFG_WMP;
1843 x.frag_buf[0].frag_len = GET_BUF_CNT( descp ) / sizeof( hcf_16 );
1844 x.frag_buf[0].frag_addr = (hcf_8 *) descp->buf_addr ;
1845 x.frag_buf[1].frag_len = ( GET_BUF_CNT( descp->next_desc_addr ) + 1 ) / sizeof( hcf_16 );
1846 x.frag_buf[1].frag_addr = (hcf_8 *) descp->next_desc_addr->buf_addr ;
1848 hcf_put_info( &( lp->hcfCtx ), (LTVP)&x );
1852 desc_next = desc->next_desc_addr;
1854 /* Make sure the buffer isn't empty */
1855 if (GET_BUF_CNT(desc) == 0) {
1856 DBG_WARNING(DbgInfo, "Buffer is empty!\n");
1858 /* Give the descriptor back to the HCF */
1859 hcf_dma_rx_put(&(lp->hcfCtx), desc);
1863 /* Read the HFS_STAT register from the lookahead buffer */
1864 hfs_stat = (hcf_16) (desc->buf_addr[HFS_STAT / 2]);
1866 /* Make sure the frame isn't bad */
1867 if ((hfs_stat & HFS_STAT_ERR) != HCF_SUCCESS) {
1868 DBG_WARNING(DbgInfo,
1869 "HFS_STAT_ERROR (0x%x) in Rx Packet\n",
1870 desc->buf_addr[HFS_STAT / 2]);
1872 /* Give the descriptor back to the HCF */
1873 hcf_dma_rx_put(&(lp->hcfCtx), desc);
1877 /* Determine what port this packet is for */
1878 port = (hfs_stat >> 8) & 0x0007;
1879 DBG_RX(DbgInfo, "Rx frame for port %d\n", port);
1881 pktlen = GET_BUF_CNT(desc_next);
1883 skb = ALLOC_SKB(pktlen);
1894 lp->wds_port[port - 1].dev;
1896 #endif /* USE_WDS */
1904 GET_PACKET_DMA(skb->dev, skb, pktlen);
1906 /* Give the descriptor back to the HCF */
1907 hcf_dma_rx_put(&(lp->hcfCtx), desc);
1912 lp->stats.rx_packets++;
1913 lp->stats.rx_bytes += pktlen;
1924 #endif /* USE_WDS */
1926 dev->last_rx = jiffies;
1930 "Could not alloc skb\n");
1933 lp->stats.rx_dropped++;
1940 #endif /* USE_WDS */
1950 /*============================================================================*/
1951 #endif /* ENABLE_DMA */