Merge branch 'master' of git://git.kernel.org/pub/scm/linux/kernel/git/kaber/nf-next-2.6
[linux-2.6.git] / drivers / net / ps3_gelic_net.c
index 2f515b8..89c4948 100644 (file)
 #include <asm/lv1call.h>
 
 #include "ps3_gelic_net.h"
+#include "ps3_gelic_wireless.h"
 
 #define DRV_NAME "Gelic Network Driver"
-#define DRV_VERSION "1.0"
+#define DRV_VERSION "2.0"
 
 MODULE_AUTHOR("SCE Inc.");
 MODULE_DESCRIPTION("Gelic Network driver");
 MODULE_LICENSE("GPL");
 
-static inline struct device *ctodev(struct gelic_net_card *card)
-{
-       return &card->dev->core;
-}
-static inline unsigned int bus_id(struct gelic_net_card *card)
-{
-       return card->dev->bus_id;
-}
-static inline unsigned int dev_id(struct gelic_net_card *card)
-{
-       return card->dev->dev_id;
-}
+
+static inline void gelic_card_enable_rxdmac(struct gelic_card *card);
+static inline void gelic_card_disable_rxdmac(struct gelic_card *card);
+static inline void gelic_card_disable_txdmac(struct gelic_card *card);
+static inline void gelic_card_reset_chain(struct gelic_card *card,
+                                         struct gelic_descr_chain *chain,
+                                         struct gelic_descr *start_descr);
 
 /* set irq_mask */
-static int gelic_net_set_irq_mask(struct gelic_net_card *card, u64 mask)
+int gelic_card_set_irq_mask(struct gelic_card *card, u64 mask)
 {
        int status;
 
@@ -76,54 +72,128 @@ static int gelic_net_set_irq_mask(struct gelic_net_card *card, u64 mask)
                                            mask, 0);
        if (status)
                dev_info(ctodev(card),
-                        "lv1_net_set_interrupt_mask failed %d\n", status);
+                        "%s failed %d\n", __func__, status);
        return status;
 }
-static inline void gelic_net_rx_irq_on(struct gelic_net_card *card)
+
+static inline void gelic_card_rx_irq_on(struct gelic_card *card)
 {
-       gelic_net_set_irq_mask(card, card->ghiintmask | GELIC_NET_RXINT);
+       card->irq_mask |= GELIC_CARD_RXINT;
+       gelic_card_set_irq_mask(card, card->irq_mask);
 }
-static inline void gelic_net_rx_irq_off(struct gelic_net_card *card)
+static inline void gelic_card_rx_irq_off(struct gelic_card *card)
+{
+       card->irq_mask &= ~GELIC_CARD_RXINT;
+       gelic_card_set_irq_mask(card, card->irq_mask);
+}
+
+static void gelic_card_get_ether_port_status(struct gelic_card *card,
+                                            int inform)
 {
-       gelic_net_set_irq_mask(card, card->ghiintmask & ~GELIC_NET_RXINT);
+       u64 v2;
+       struct net_device *ether_netdev;
+
+       lv1_net_control(bus_id(card), dev_id(card),
+                       GELIC_LV1_GET_ETH_PORT_STATUS,
+                       GELIC_LV1_VLAN_TX_ETHERNET_0, 0, 0,
+                       &card->ether_port_status, &v2);
+
+       if (inform) {
+               ether_netdev = card->netdev[GELIC_PORT_ETHERNET_0];
+               if (card->ether_port_status & GELIC_LV1_ETHER_LINK_UP)
+                       netif_carrier_on(ether_netdev);
+               else
+                       netif_carrier_off(ether_netdev);
+       }
 }
+
+static int gelic_card_set_link_mode(struct gelic_card *card, int mode)
+{
+       int status;
+       u64 v1, v2;
+
+       status = lv1_net_control(bus_id(card), dev_id(card),
+                                GELIC_LV1_SET_NEGOTIATION_MODE,
+                                GELIC_LV1_PHY_ETHERNET_0, mode, 0, &v1, &v2);
+       if (status) {
+               pr_info("%s: failed setting negotiation mode %d\n", __func__,
+                       status);
+               return -EBUSY;
+       }
+
+       card->link_mode = mode;
+       return 0;
+}
+
+void gelic_card_up(struct gelic_card *card)
+{
+       pr_debug("%s: called\n", __func__);
+       mutex_lock(&card->updown_lock);
+       if (atomic_inc_return(&card->users) == 1) {
+               pr_debug("%s: real do\n", __func__);
+               /* enable irq */
+               gelic_card_set_irq_mask(card, card->irq_mask);
+               /* start rx */
+               gelic_card_enable_rxdmac(card);
+
+               napi_enable(&card->napi);
+       }
+       mutex_unlock(&card->updown_lock);
+       pr_debug("%s: done\n", __func__);
+}
+
+void gelic_card_down(struct gelic_card *card)
+{
+       u64 mask;
+       pr_debug("%s: called\n", __func__);
+       mutex_lock(&card->updown_lock);
+       if (atomic_dec_if_positive(&card->users) == 0) {
+               pr_debug("%s: real do\n", __func__);
+               napi_disable(&card->napi);
+               /*
+                * Disable irq. Wireless interrupts will
+                * be disabled later if any
+                */
+               mask = card->irq_mask & (GELIC_CARD_WLAN_EVENT_RECEIVED |
+                                        GELIC_CARD_WLAN_COMMAND_COMPLETED);
+               gelic_card_set_irq_mask(card, mask);
+               /* stop rx */
+               gelic_card_disable_rxdmac(card);
+               gelic_card_reset_chain(card, &card->rx_chain,
+                                      card->descr + GELIC_NET_TX_DESCRIPTORS);
+               /* stop tx */
+               gelic_card_disable_txdmac(card);
+       }
+       mutex_unlock(&card->updown_lock);
+       pr_debug("%s: done\n", __func__);
+}
+
 /**
- * gelic_net_get_descr_status -- returns the status of a descriptor
+ * gelic_descr_get_status -- returns the status of a descriptor
  * @descr: descriptor to look at
  *
  * returns the status as in the dmac_cmd_status field of the descriptor
  */
-static enum gelic_net_descr_status
-gelic_net_get_descr_status(struct gelic_net_descr *descr)
+static enum gelic_descr_dma_status
+gelic_descr_get_status(struct gelic_descr *descr)
 {
-       u32 cmd_status;
-
-       cmd_status = descr->dmac_cmd_status;
-       cmd_status >>= GELIC_NET_DESCR_IND_PROC_SHIFT;
-       return cmd_status;
+       return be32_to_cpu(descr->dmac_cmd_status) & GELIC_DESCR_DMA_STAT_MASK;
 }
 
 /**
- * gelic_net_set_descr_status -- sets the status of a descriptor
+ * gelic_descr_set_status -- sets the status of a descriptor
  * @descr: descriptor to change
  * @status: status to set in the descriptor
  *
  * changes the status to the specified value. Doesn't change other bits
  * in the status
  */
-static void gelic_net_set_descr_status(struct gelic_net_descr *descr,
-                                      enum gelic_net_descr_status status)
+static void gelic_descr_set_status(struct gelic_descr *descr,
+                                  enum gelic_descr_dma_status status)
 {
-       u32 cmd_status;
-
-       /* read the status */
-       cmd_status = descr->dmac_cmd_status;
-       /* clean the upper 4 bits */
-       cmd_status &= GELIC_NET_DESCR_IND_PROC_MASKO;
-       /* add the status to it */
-       cmd_status |= ((u32)status) << GELIC_NET_DESCR_IND_PROC_SHIFT;
-       /* and write it back */
-       descr->dmac_cmd_status = cmd_status;
+       descr->dmac_cmd_status = cpu_to_be32(status |
+                       (be32_to_cpu(descr->dmac_cmd_status) &
+                        ~GELIC_DESCR_DMA_STAT_MASK));
        /*
         * dma_cmd_status field is used to indicate whether the descriptor
         * is valid or not.
@@ -134,24 +204,24 @@ static void gelic_net_set_descr_status(struct gelic_net_descr *descr,
 }
 
 /**
- * gelic_net_free_chain - free descriptor chain
+ * gelic_card_free_chain - free descriptor chain
  * @card: card structure
  * @descr_in: address of desc
  */
-static void gelic_net_free_chain(struct gelic_net_card *card,
-                                struct gelic_net_descr *descr_in)
+static void gelic_card_free_chain(struct gelic_card *card,
+                                 struct gelic_descr *descr_in)
 {
-       struct gelic_net_descr *descr;
+       struct gelic_descr *descr;
 
        for (descr = descr_in; descr && descr->bus_addr; descr = descr->next) {
                dma_unmap_single(ctodev(card), descr->bus_addr,
-                                GELIC_NET_DESCR_SIZE, DMA_BIDIRECTIONAL);
+                                GELIC_DESCR_SIZE, DMA_BIDIRECTIONAL);
                descr->bus_addr = 0;
        }
 }
 
 /**
- * gelic_net_init_chain - links descriptor chain
+ * gelic_card_init_chain - links descriptor chain
  * @card: card structure
  * @chain: address of chain
  * @start_descr: address of descriptor array
@@ -162,22 +232,23 @@ static void gelic_net_free_chain(struct gelic_net_card *card,
  *
  * returns 0 on success, <0 on failure
  */
-static int gelic_net_init_chain(struct gelic_net_card *card,
-                               struct gelic_net_descr_chain *chain,
-                               struct gelic_net_descr *start_descr, int no)
+static int __devinit gelic_card_init_chain(struct gelic_card *card,
+                                          struct gelic_descr_chain *chain,
+                                          struct gelic_descr *start_descr,
+                                          int no)
 {
        int i;
-       struct gelic_net_descr *descr;
+       struct gelic_descr *descr;
 
        descr = start_descr;
        memset(descr, 0, sizeof(*descr) * no);
 
        /* set up the hardware pointers in each descriptor */
        for (i = 0; i < no; i++, descr++) {
-               gelic_net_set_descr_status(descr, GELIC_NET_DESCR_NOT_IN_USE);
+               gelic_descr_set_status(descr, GELIC_DESCR_DMA_NOT_IN_USE);
                descr->bus_addr =
                        dma_map_single(ctodev(card), descr,
-                                      GELIC_NET_DESCR_SIZE,
+                                      GELIC_DESCR_SIZE,
                                       DMA_BIDIRECTIONAL);
 
                if (!descr->bus_addr)
@@ -193,7 +264,7 @@ static int gelic_net_init_chain(struct gelic_net_card *card,
        /* chain bus addr of hw descriptor */
        descr = start_descr;
        for (i = 0; i < no; i++, descr++) {
-               descr->next_descr_addr = descr->next->bus_addr;
+               descr->next_descr_addr = cpu_to_be32(descr->next->bus_addr);
        }
 
        chain->head = start_descr;
@@ -208,13 +279,38 @@ iommu_error:
        for (i--, descr--; 0 <= i; i--, descr--)
                if (descr->bus_addr)
                        dma_unmap_single(ctodev(card), descr->bus_addr,
-                                        GELIC_NET_DESCR_SIZE,
+                                        GELIC_DESCR_SIZE,
                                         DMA_BIDIRECTIONAL);
        return -ENOMEM;
 }
 
 /**
- * gelic_net_prepare_rx_descr - reinitializes a rx descriptor
+ * gelic_card_reset_chain - reset status of a descriptor chain
+ * @card: card structure
+ * @chain: address of chain
+ * @start_descr: address of descriptor array
+ *
+ * Reset the status of dma descriptors to ready state
+ * and re-initialize the hardware chain for later use
+ */
+static void gelic_card_reset_chain(struct gelic_card *card,
+                                  struct gelic_descr_chain *chain,
+                                  struct gelic_descr *start_descr)
+{
+       struct gelic_descr *descr;
+
+       for (descr = start_descr; start_descr != descr->next; descr++) {
+               gelic_descr_set_status(descr, GELIC_DESCR_DMA_CARDOWNED);
+               descr->next_descr_addr = cpu_to_be32(descr->next->bus_addr);
+       }
+
+       chain->head = start_descr;
+       chain->tail = (descr - 1);
+
+       (descr - 1)->next_descr_addr = 0;
+}
+/**
+ * gelic_descr_prepare_rx - reinitializes a rx descriptor
  * @card: card structure
  * @descr: descriptor to re-init
  *
@@ -223,29 +319,27 @@ iommu_error:
  * allocates a new rx skb, iommu-maps it and attaches it to the descriptor.
  * Activate the descriptor state-wise
  */
-static int gelic_net_prepare_rx_descr(struct gelic_net_card *card,
-                                     struct gelic_net_descr *descr)
+static int gelic_descr_prepare_rx(struct gelic_card *card,
+                                 struct gelic_descr *descr)
 {
        int offset;
        unsigned int bufsize;
 
-       if (gelic_net_get_descr_status(descr) !=  GELIC_NET_DESCR_NOT_IN_USE) {
+       if (gelic_descr_get_status(descr) !=  GELIC_DESCR_DMA_NOT_IN_USE)
                dev_info(ctodev(card), "%s: ERROR status \n", __func__);
-       }
        /* we need to round up the buffer size to a multiple of 128 */
        bufsize = ALIGN(GELIC_NET_MAX_MTU, GELIC_NET_RXBUF_ALIGN);
 
        /* and we need to have it 128 byte aligned, therefore we allocate a
         * bit more */
-       descr->skb = netdev_alloc_skb(card->netdev,
-               bufsize + GELIC_NET_RXBUF_ALIGN - 1);
+       descr->skb = dev_alloc_skb(bufsize + GELIC_NET_RXBUF_ALIGN - 1);
        if (!descr->skb) {
                descr->buf_addr = 0; /* tell DMAC don't touch memory */
                dev_info(ctodev(card),
                         "%s:allocate skb failed !!\n", __func__);
                return -ENOMEM;
        }
-       descr->buf_size = bufsize;
+       descr->buf_size = cpu_to_be32(bufsize);
        descr->dmac_cmd_status = 0;
        descr->result_size = 0;
        descr->valid_size = 0;
@@ -256,63 +350,64 @@ static int gelic_net_prepare_rx_descr(struct gelic_net_card *card,
        if (offset)
                skb_reserve(descr->skb, GELIC_NET_RXBUF_ALIGN - offset);
        /* io-mmu-map the skb */
-       descr->buf_addr = dma_map_single(ctodev(card), descr->skb->data,
-                                        GELIC_NET_MAX_MTU,
-                                        DMA_FROM_DEVICE);
+       descr->buf_addr = cpu_to_be32(dma_map_single(ctodev(card),
+                                                    descr->skb->data,
+                                                    GELIC_NET_MAX_MTU,
+                                                    DMA_FROM_DEVICE));
        if (!descr->buf_addr) {
                dev_kfree_skb_any(descr->skb);
                descr->skb = NULL;
                dev_info(ctodev(card),
                         "%s:Could not iommu-map rx buffer\n", __func__);
-               gelic_net_set_descr_status(descr, GELIC_NET_DESCR_NOT_IN_USE);
+               gelic_descr_set_status(descr, GELIC_DESCR_DMA_NOT_IN_USE);
                return -ENOMEM;
        } else {
-               gelic_net_set_descr_status(descr, GELIC_NET_DESCR_CARDOWNED);
+               gelic_descr_set_status(descr, GELIC_DESCR_DMA_CARDOWNED);
                return 0;
        }
 }
 
 /**
- * gelic_net_release_rx_chain - free all skb of rx descr
+ * gelic_card_release_rx_chain - free all skb of rx descr
  * @card: card structure
  *
  */
-static void gelic_net_release_rx_chain(struct gelic_net_card *card)
+static void gelic_card_release_rx_chain(struct gelic_card *card)
 {
-       struct gelic_net_descr *descr = card->rx_chain.head;
+       struct gelic_descr *descr = card->rx_chain.head;
 
        do {
                if (descr->skb) {
                        dma_unmap_single(ctodev(card),
-                                        descr->buf_addr,
+                                        be32_to_cpu(descr->buf_addr),
                                         descr->skb->len,
                                         DMA_FROM_DEVICE);
                        descr->buf_addr = 0;
                        dev_kfree_skb_any(descr->skb);
                        descr->skb = NULL;
-                       gelic_net_set_descr_status(descr,
-                                                  GELIC_NET_DESCR_NOT_IN_USE);
+                       gelic_descr_set_status(descr,
+                                              GELIC_DESCR_DMA_NOT_IN_USE);
                }
                descr = descr->next;
        } while (descr != card->rx_chain.head);
 }
 
 /**
- * gelic_net_fill_rx_chain - fills descriptors/skbs in the rx chains
+ * gelic_card_fill_rx_chain - fills descriptors/skbs in the rx chains
  * @card: card structure
  *
  * fills all descriptors in the rx chain: allocates skbs
  * and iommu-maps them.
- * returns 0 on success, <0 on failure
+ * returns 0 on success, < 0 on failure
  */
-static int gelic_net_fill_rx_chain(struct gelic_net_card *card)
+static int gelic_card_fill_rx_chain(struct gelic_card *card)
 {
-       struct gelic_net_descr *descr = card->rx_chain.head;
+       struct gelic_descr *descr = card->rx_chain.head;
        int ret;
 
        do {
                if (!descr->skb) {
-                       ret = gelic_net_prepare_rx_descr(card, descr);
+                       ret = gelic_descr_prepare_rx(card, descr);
                        if (ret)
                                goto rewind;
                }
@@ -321,49 +416,43 @@ static int gelic_net_fill_rx_chain(struct gelic_net_card *card)
 
        return 0;
 rewind:
-       gelic_net_release_rx_chain(card);
+       gelic_card_release_rx_chain(card);
        return ret;
 }
 
 /**
- * gelic_net_alloc_rx_skbs - allocates rx skbs in rx descriptor chains
+ * gelic_card_alloc_rx_skbs - allocates rx skbs in rx descriptor chains
  * @card: card structure
  *
- * returns 0 on success, <0 on failure
+ * returns 0 on success, < 0 on failure
  */
-static int gelic_net_alloc_rx_skbs(struct gelic_net_card *card)
+static int __devinit gelic_card_alloc_rx_skbs(struct gelic_card *card)
 {
-       struct gelic_net_descr_chain *chain;
+       struct gelic_descr_chain *chain;
        int ret;
        chain = &card->rx_chain;
-       ret = gelic_net_fill_rx_chain(card);
-       chain->head = card->rx_top->prev; /* point to the last */
+       ret = gelic_card_fill_rx_chain(card);
+       chain->tail = card->rx_top->prev; /* point to the last */
        return ret;
 }
 
 /**
- * gelic_net_release_tx_descr - processes a used tx descriptor
+ * gelic_descr_release_tx - processes a used tx descriptor
  * @card: card structure
  * @descr: descriptor to release
  *
  * releases a used tx descriptor (unmapping, freeing of skb)
  */
-static void gelic_net_release_tx_descr(struct gelic_net_card *card,
-                           struct gelic_net_descr *descr)
+static void gelic_descr_release_tx(struct gelic_card *card,
+                                      struct gelic_descr *descr)
 {
-       struct sk_buff *skb;
+       struct sk_buff *skb = descr->skb;
 
+       BUG_ON(!(be32_to_cpu(descr->data_status) & GELIC_DESCR_TX_TAIL));
 
-       if (descr->data_status & (1 << GELIC_NET_TXDESC_TAIL)) {
-               /* 2nd descriptor */
-               skb = descr->skb;
-               dma_unmap_single(ctodev(card), descr->buf_addr, skb->len,
-                                DMA_TO_DEVICE);
-               dev_kfree_skb_any(skb);
-       } else {
-               dma_unmap_single(ctodev(card), descr->buf_addr,
-                                descr->buf_size, DMA_TO_DEVICE);
-       }
+       dma_unmap_single(ctodev(card), be32_to_cpu(descr->buf_addr), skb->len,
+                        DMA_TO_DEVICE);
+       dev_kfree_skb_any(skb);
 
        descr->buf_addr = 0;
        descr->buf_size = 0;
@@ -375,59 +464,75 @@ static void gelic_net_release_tx_descr(struct gelic_net_card *card,
        descr->skb = NULL;
 
        /* set descr status */
-       gelic_net_set_descr_status(descr, GELIC_NET_DESCR_NOT_IN_USE);
+       gelic_descr_set_status(descr, GELIC_DESCR_DMA_NOT_IN_USE);
+}
+
+static void gelic_card_stop_queues(struct gelic_card *card)
+{
+       netif_stop_queue(card->netdev[GELIC_PORT_ETHERNET_0]);
+
+       if (card->netdev[GELIC_PORT_WIRELESS])
+               netif_stop_queue(card->netdev[GELIC_PORT_WIRELESS]);
 }
+static void gelic_card_wake_queues(struct gelic_card *card)
+{
+       netif_wake_queue(card->netdev[GELIC_PORT_ETHERNET_0]);
 
+       if (card->netdev[GELIC_PORT_WIRELESS])
+               netif_wake_queue(card->netdev[GELIC_PORT_WIRELESS]);
+}
 /**
- * gelic_net_release_tx_chain - processes sent tx descriptors
+ * gelic_card_release_tx_chain - processes sent tx descriptors
  * @card: adapter structure
  * @stop: net_stop sequence
  *
  * releases the tx descriptors that gelic has finished with
  */
-static void gelic_net_release_tx_chain(struct gelic_net_card *card, int stop)
+static void gelic_card_release_tx_chain(struct gelic_card *card, int stop)
 {
-       struct gelic_net_descr_chain *tx_chain;
-       enum gelic_net_descr_status status;
+       struct gelic_descr_chain *tx_chain;
+       enum gelic_descr_dma_status status;
+       struct net_device *netdev;
        int release = 0;
 
        for (tx_chain = &card->tx_chain;
             tx_chain->head != tx_chain->tail && tx_chain->tail;
             tx_chain->tail = tx_chain->tail->next) {
-               status = gelic_net_get_descr_status(tx_chain->tail);
+               status = gelic_descr_get_status(tx_chain->tail);
+               netdev = tx_chain->tail->skb->dev;
                switch (status) {
-               case GELIC_NET_DESCR_RESPONSE_ERROR:
-               case GELIC_NET_DESCR_PROTECTION_ERROR:
-               case GELIC_NET_DESCR_FORCE_END:
+               case GELIC_DESCR_DMA_RESPONSE_ERROR:
+               case GELIC_DESCR_DMA_PROTECTION_ERROR:
+               case GELIC_DESCR_DMA_FORCE_END:
                        if (printk_ratelimit())
                                dev_info(ctodev(card),
                                         "%s: forcing end of tx descriptor " \
                                         "with status %x\n",
                                         __func__, status);
-                       card->netdev->stats.tx_dropped++;
+                       netdev->stats.tx_dropped++;
                        break;
 
-               case GELIC_NET_DESCR_COMPLETE:
+               case GELIC_DESCR_DMA_COMPLETE:
                        if (tx_chain->tail->skb) {
-                               card->netdev->stats.tx_packets++;
-                               card->netdev->stats.tx_bytes +=
+                               netdev->stats.tx_packets++;
+                               netdev->stats.tx_bytes +=
                                        tx_chain->tail->skb->len;
                        }
                        break;
 
-               case GELIC_NET_DESCR_CARDOWNED:
+               case GELIC_DESCR_DMA_CARDOWNED:
                        /* pending tx request */
                default:
-                       /* any other value (== GELIC_NET_DESCR_NOT_IN_USE) */
+                       /* any other value (== GELIC_DESCR_DMA_NOT_IN_USE) */
                        if (!stop)
                                goto out;
                }
-               gelic_net_release_tx_descr(card, tx_chain->tail);
+               gelic_descr_release_tx(card, tx_chain->tail);
                release ++;
        }
 out:
-       if (!stop && (2 < release))
-               netif_wake_queue(card->netdev);
+       if (!stop && release)
+               gelic_card_wake_queues(card);
 }
 
 /**
@@ -438,9 +543,9 @@ out:
  * netdev interface. It also sets up multicast, allmulti and promisc
  * flags appropriately
  */
-static void gelic_net_set_multi(struct net_device *netdev)
+void gelic_net_set_multi(struct net_device *netdev)
 {
-       struct gelic_net_card *card = netdev_priv(netdev);
+       struct gelic_card *card = netdev_card(netdev);
        struct dev_mc_list *mc;
        unsigned int i;
        uint8_t *p;
@@ -462,8 +567,8 @@ static void gelic_net_set_multi(struct net_device *netdev)
                        "lv1_net_add_multicast_address failed, %d\n",
                        status);
 
-       if (netdev->flags & IFF_ALLMULTI
-               || netdev->mc_count > GELIC_NET_MC_COUNT_MAX) { /* list max */
+       if ((netdev->flags & IFF_ALLMULTI) ||
+           (netdev->mc_count > GELIC_NET_MC_COUNT_MAX)) {
                status = lv1_net_add_multicast_address(bus_id(card),
                                                       dev_id(card),
                                                       0, 1);
@@ -474,7 +579,7 @@ static void gelic_net_set_multi(struct net_device *netdev)
                return;
        }
 
-       /* set multicast address */
+       /* set multicast addresses */
        for (mc = netdev->mc_list; mc; mc = mc->next) {
                addr = 0;
                p = mc->dmi_addr;
@@ -493,31 +598,42 @@ static void gelic_net_set_multi(struct net_device *netdev)
 }
 
 /**
- * gelic_net_enable_rxdmac - enables the receive DMA controller
+ * gelic_card_enable_rxdmac - enables the receive DMA controller
  * @card: card structure
  *
- * gelic_net_enable_rxdmac enables the DMA controller by setting RX_DMA_EN
+ * gelic_card_enable_rxdmac enables the DMA controller by setting RX_DMA_EN
  * in the GDADMACCNTR register
  */
-static inline void gelic_net_enable_rxdmac(struct gelic_net_card *card)
+static inline void gelic_card_enable_rxdmac(struct gelic_card *card)
 {
        int status;
 
+#ifdef DEBUG
+       if (gelic_descr_get_status(card->rx_chain.head) !=
+           GELIC_DESCR_DMA_CARDOWNED) {
+               printk(KERN_ERR "%s: status=%x\n", __func__,
+                      be32_to_cpu(card->rx_chain.head->dmac_cmd_status));
+               printk(KERN_ERR "%s: nextphy=%x\n", __func__,
+                      be32_to_cpu(card->rx_chain.head->next_descr_addr));
+               printk(KERN_ERR "%s: head=%p\n", __func__,
+                      card->rx_chain.head);
+       }
+#endif
        status = lv1_net_start_rx_dma(bus_id(card), dev_id(card),
-                               card->rx_chain.tail->bus_addr, 0);
+                               card->rx_chain.head->bus_addr, 0);
        if (status)
                dev_info(ctodev(card),
                         "lv1_net_start_rx_dma failed, status=%d\n", status);
 }
 
 /**
- * gelic_net_disable_rxdmac - disables the receive DMA controller
+ * gelic_card_disable_rxdmac - disables the receive DMA controller
  * @card: card structure
  *
- * gelic_net_disable_rxdmac terminates processing on the DMA controller by
+ * gelic_card_disable_rxdmac terminates processing on the DMA controller by
  * turing off DMA and issueing a force end
  */
-static inline void gelic_net_disable_rxdmac(struct gelic_net_card *card)
+static inline void gelic_card_disable_rxdmac(struct gelic_card *card)
 {
        int status;
 
@@ -529,13 +645,13 @@ static inline void gelic_net_disable_rxdmac(struct gelic_net_card *card)
 }
 
 /**
- * gelic_net_disable_txdmac - disables the transmit DMA controller
+ * gelic_card_disable_txdmac - disables the transmit DMA controller
  * @card: card structure
  *
- * gelic_net_disable_txdmac terminates processing on the DMA controller by
+ * gelic_card_disable_txdmac terminates processing on the DMA controller by
  * turing off DMA and issueing a force end
  */
-static inline void gelic_net_disable_txdmac(struct gelic_net_card *card)
+static inline void gelic_card_disable_txdmac(struct gelic_card *card)
 {
        int status;
 
@@ -552,54 +668,37 @@ static inline void gelic_net_disable_txdmac(struct gelic_net_card *card)
  *
  * always returns 0
  */
-static int gelic_net_stop(struct net_device *netdev)
+int gelic_net_stop(struct net_device *netdev)
 {
-       struct gelic_net_card *card = netdev_priv(netdev);
-
-       netif_poll_disable(netdev);
-       netif_stop_queue(netdev);
-
-       /* turn off DMA, force end */
-       gelic_net_disable_rxdmac(card);
-       gelic_net_disable_txdmac(card);
+       struct gelic_card *card;
 
-       gelic_net_set_irq_mask(card, 0);
-
-       /* disconnect event port */
-       free_irq(card->netdev->irq, card->netdev);
-       ps3_sb_event_receive_port_destroy(card->dev, card->netdev->irq);
-       card->netdev->irq = NO_IRQ;
+       pr_debug("%s: start\n", __func__);
 
+       netif_stop_queue(netdev);
        netif_carrier_off(netdev);
 
-       /* release chains */
-       gelic_net_release_tx_chain(card, 1);
-       gelic_net_release_rx_chain(card);
-
-       gelic_net_free_chain(card, card->tx_top);
-       gelic_net_free_chain(card, card->rx_top);
+       card = netdev_card(netdev);
+       gelic_card_down(card);
 
+       pr_debug("%s: done\n", __func__);
        return 0;
 }
 
 /**
- * gelic_net_get_next_tx_descr - returns the next available tx descriptor
+ * gelic_card_get_next_tx_descr - returns the next available tx descriptor
  * @card: device structure to get descriptor from
  *
  * returns the address of the next descriptor, or NULL if not available.
  */
-static struct gelic_net_descr *
-gelic_net_get_next_tx_descr(struct gelic_net_card *card)
+static struct gelic_descr *
+gelic_card_get_next_tx_descr(struct gelic_card *card)
 {
        if (!card->tx_chain.head)
                return NULL;
-       /*  see if we can two consecutive free descrs */
+       /*  see if the next descriptor is free */
        if (card->tx_chain.tail != card->tx_chain.head->next &&
-           gelic_net_get_descr_status(card->tx_chain.head) ==
-           GELIC_NET_DESCR_NOT_IN_USE &&
-           card->tx_chain.tail != card->tx_chain.head->next->next &&
-           gelic_net_get_descr_status(card->tx_chain.head->next) ==
-            GELIC_NET_DESCR_NOT_IN_USE )
+           gelic_descr_get_status(card->tx_chain.head) ==
+           GELIC_DESCR_DMA_NOT_IN_USE)
                return card->tx_chain.head;
        else
                return NULL;
@@ -610,46 +709,69 @@ gelic_net_get_next_tx_descr(struct gelic_net_card *card)
  * gelic_net_set_txdescr_cmdstat - sets the tx descriptor command field
  * @descr: descriptor structure to fill out
  * @skb: packet to consider
- * @middle: middle of frame
  *
  * fills out the command and status field of the descriptor structure,
  * depending on hardware checksum settings. This function assumes a wmb()
  * has executed before.
  */
-static void gelic_net_set_txdescr_cmdstat(struct gelic_net_descr *descr,
-                                         struct sk_buff *skb, int middle)
+static void gelic_descr_set_tx_cmdstat(struct gelic_descr *descr,
+                                      struct sk_buff *skb)
 {
-       u32 eofr;
-
-       if (middle)
-               eofr = 0;
-       else
-               eofr = GELIC_NET_DMAC_CMDSTAT_END_FRAME;
-
        if (skb->ip_summed != CHECKSUM_PARTIAL)
-               descr->dmac_cmd_status = GELIC_NET_DMAC_CMDSTAT_NOCS | eofr;
+               descr->dmac_cmd_status =
+                       cpu_to_be32(GELIC_DESCR_DMA_CMD_NO_CHKSUM |
+                                   GELIC_DESCR_TX_DMA_FRAME_TAIL);
        else {
                /* is packet ip?
                 * if yes: tcp? udp? */
                if (skb->protocol == htons(ETH_P_IP)) {
                        if (ip_hdr(skb)->protocol == IPPROTO_TCP)
                                descr->dmac_cmd_status =
-                                       GELIC_NET_DMAC_CMDSTAT_TCPCS | eofr;
+                               cpu_to_be32(GELIC_DESCR_DMA_CMD_TCP_CHKSUM |
+                                           GELIC_DESCR_TX_DMA_FRAME_TAIL);
+
                        else if (ip_hdr(skb)->protocol == IPPROTO_UDP)
                                descr->dmac_cmd_status =
-                                       GELIC_NET_DMAC_CMDSTAT_UDPCS | eofr;
+                               cpu_to_be32(GELIC_DESCR_DMA_CMD_UDP_CHKSUM |
+                                           GELIC_DESCR_TX_DMA_FRAME_TAIL);
                        else    /*
                                 * the stack should checksum non-tcp and non-udp
                                 * packets on his own: NETIF_F_IP_CSUM
                                 */
                                descr->dmac_cmd_status =
-                                       GELIC_NET_DMAC_CMDSTAT_NOCS | eofr;
+                               cpu_to_be32(GELIC_DESCR_DMA_CMD_NO_CHKSUM |
+                                           GELIC_DESCR_TX_DMA_FRAME_TAIL);
                }
        }
 }
 
+static inline struct sk_buff *gelic_put_vlan_tag(struct sk_buff *skb,
+                                                unsigned short tag)
+{
+       struct vlan_ethhdr *veth;
+       static unsigned int c;
+
+       if (skb_headroom(skb) < VLAN_HLEN) {
+               struct sk_buff *sk_tmp = skb;
+               pr_debug("%s: hd=%d c=%ud\n", __func__, skb_headroom(skb), c);
+               skb = skb_realloc_headroom(sk_tmp, VLAN_HLEN);
+               if (!skb)
+                       return NULL;
+               dev_kfree_skb_any(sk_tmp);
+       }
+       veth = (struct vlan_ethhdr *)skb_push(skb, VLAN_HLEN);
+
+       /* Move the mac addresses to the top of buffer */
+       memmove(skb->data, skb->data + VLAN_HLEN, 2 * ETH_ALEN);
+
+       veth->h_vlan_proto = cpu_to_be16(ETH_P_8021Q);
+       veth->h_vlan_TCI = htons(tag);
+
+       return skb;
+}
+
 /**
- * gelic_net_prepare_tx_descr_v - get dma address of skb_data
+ * gelic_descr_prepare_tx - setup a descriptor for sending packets
  * @card: card structure
  * @descr: descriptor structure
  * @skb: packet to use
@@ -657,101 +779,66 @@ static void gelic_net_set_txdescr_cmdstat(struct gelic_net_descr *descr,
  * returns 0 on success, <0 on failure.
  *
  */
-static int gelic_net_prepare_tx_descr_v(struct gelic_net_card *card,
-                                       struct gelic_net_descr *descr,
-                                       struct sk_buff *skb)
+static int gelic_descr_prepare_tx(struct gelic_card *card,
+                                 struct gelic_descr *descr,
+                                 struct sk_buff *skb)
 {
-       dma_addr_t buf[2];
-       unsigned int vlan_len;
-       struct gelic_net_descr *sec_descr = descr->next;
-
-       if (skb->len < GELIC_NET_VLAN_POS)
-               return -EINVAL;
-
-       vlan_len = GELIC_NET_VLAN_POS;
-       memcpy(&descr->vlan, skb->data, vlan_len);
-       if (card->vlan_index != -1) {
-               /* internal vlan tag used */
-               descr->vlan.h_vlan_proto = htons(ETH_P_8021Q); /* vlan 0x8100*/
-               descr->vlan.h_vlan_TCI = htons(card->vlan_id[card->vlan_index]);
-               vlan_len += VLAN_HLEN; /* added for above two lines */
+       dma_addr_t buf;
+
+       if (card->vlan_required) {
+               struct sk_buff *skb_tmp;
+               enum gelic_port_type type;
+
+               type = netdev_port(skb->dev)->type;
+               skb_tmp = gelic_put_vlan_tag(skb,
+                                            card->vlan[type].tx);
+               if (!skb_tmp)
+                       return -ENOMEM;
+               skb = skb_tmp;
        }
 
-       /* map data area */
-       buf[0] = dma_map_single(ctodev(card), &descr->vlan,
-                            vlan_len, DMA_TO_DEVICE);
+       buf = dma_map_single(ctodev(card), skb->data, skb->len, DMA_TO_DEVICE);
 
-       if (!buf[0]) {
-               dev_err(ctodev(card),
-                       "dma map 1 failed (%p, %i). Dropping packet\n",
-                       skb->data, vlan_len);
-               return -ENOMEM;
-       }
-
-       buf[1] = dma_map_single(ctodev(card), skb->data + GELIC_NET_VLAN_POS,
-                            skb->len - GELIC_NET_VLAN_POS,
-                            DMA_TO_DEVICE);
-
-       if (!buf[1]) {
+       if (!buf) {
                dev_err(ctodev(card),
                        "dma map 2 failed (%p, %i). Dropping packet\n",
-                       skb->data + GELIC_NET_VLAN_POS,
-                       skb->len - GELIC_NET_VLAN_POS);
-               dma_unmap_single(ctodev(card), buf[0], vlan_len,
-                                DMA_TO_DEVICE);
+                       skb->data, skb->len);
                return -ENOMEM;
        }
 
-       /* first descr */
-       descr->buf_addr = buf[0];
-       descr->buf_size = vlan_len;
-       descr->skb = NULL; /* not used */
+       descr->buf_addr = cpu_to_be32(buf);
+       descr->buf_size = cpu_to_be32(skb->len);
+       descr->skb = skb;
        descr->data_status = 0;
-       descr->next_descr_addr = descr->next->bus_addr;
-       gelic_net_set_txdescr_cmdstat(descr, skb, 1); /* not the frame end */
-
-       /* second descr */
-       sec_descr->buf_addr = buf[1];
-       sec_descr->buf_size = skb->len - GELIC_NET_VLAN_POS;
-       sec_descr->skb = skb;
-       sec_descr->data_status = 0;
-       sec_descr->next_descr_addr = 0; /* terminate hw descr */
-       gelic_net_set_txdescr_cmdstat(sec_descr, skb, 0);
+       descr->next_descr_addr = 0; /* terminate hw descr */
+       gelic_descr_set_tx_cmdstat(descr, skb);
 
        /* bump free descriptor pointer */
-       card->tx_chain.head = sec_descr->next;
+       card->tx_chain.head = descr->next;
        return 0;
 }
 
 /**
- * gelic_net_kick_txdma - enables TX DMA processing
+ * gelic_card_kick_txdma - enables TX DMA processing
  * @card: card structure
  * @descr: descriptor address to enable TX processing at
  *
  */
-static int gelic_net_kick_txdma(struct gelic_net_card *card,
-                               struct gelic_net_descr *descr)
+static int gelic_card_kick_txdma(struct gelic_card *card,
+                                struct gelic_descr *descr)
 {
        int status = 0;
-       int count = 10;
 
        if (card->tx_dma_progress)
                return 0;
 
-       if (gelic_net_get_descr_status(descr) == GELIC_NET_DESCR_CARDOWNED) {
+       if (gelic_descr_get_status(descr) == GELIC_DESCR_DMA_CARDOWNED) {
                card->tx_dma_progress = 1;
-               /* sometimes we need retry here */
-               while (count--) {
-                       status = lv1_net_start_tx_dma(bus_id(card),
-                                                     dev_id(card),
-                                                     descr->bus_addr, 0);
-                       if (!status)
-                               break;
-               }
-               if (!count)
+               status = lv1_net_start_tx_dma(bus_id(card), dev_id(card),
+                                             descr->bus_addr, 0);
+               if (status)
                        dev_info(ctodev(card), "lv1_net_start_txdma failed," \
-                               "status=%d %#lx\n",
-                                status, card->irq_status);
+                                "status=%d\n", status);
        }
        return status;
 }
@@ -763,56 +850,56 @@ static int gelic_net_kick_txdma(struct gelic_net_card *card,
  *
  * returns 0 on success, <0 on failure
  */
-static int gelic_net_xmit(struct sk_buff *skb, struct net_device *netdev)
+int gelic_net_xmit(struct sk_buff *skb, struct net_device *netdev)
 {
-       struct gelic_net_card *card = netdev_priv(netdev);
-       struct gelic_net_descr *descr;
+       struct gelic_card *card = netdev_card(netdev);
+       struct gelic_descr *descr;
        int result;
        unsigned long flags;
 
-       spin_lock_irqsave(&card->tx_dma_lock, flags);
+       spin_lock_irqsave(&card->tx_lock, flags);
 
-       gelic_net_release_tx_chain(card, 0);
+       gelic_card_release_tx_chain(card, 0);
 
-       descr = gelic_net_get_next_tx_descr(card);
+       descr = gelic_card_get_next_tx_descr(card);
        if (!descr) {
                /*
                 * no more descriptors free
                 */
-               netif_stop_queue(netdev);
-               spin_unlock_irqrestore(&card->tx_dma_lock, flags);
+               gelic_card_stop_queues(card);
+               spin_unlock_irqrestore(&card->tx_lock, flags);
                return NETDEV_TX_BUSY;
        }
 
-       result = gelic_net_prepare_tx_descr_v(card, descr, skb);
+       result = gelic_descr_prepare_tx(card, descr, skb);
        if (result) {
                /*
                 * DMA map failed.  As chanses are that failure
                 * would continue, just release skb and return
                 */
-               card->netdev->stats.tx_dropped++;
+               netdev->stats.tx_dropped++;
                dev_kfree_skb_any(skb);
-               spin_unlock_irqrestore(&card->tx_dma_lock, flags);
+               spin_unlock_irqrestore(&card->tx_lock, flags);
                return NETDEV_TX_OK;
        }
        /*
         * link this prepared descriptor to previous one
         * to achieve high performance
         */
-       descr->prev->next_descr_addr = descr->bus_addr;
+       descr->prev->next_descr_addr = cpu_to_be32(descr->bus_addr);
        /*
         * as hardware descriptor is modified in the above lines,
         * ensure that the hardware sees it
         */
        wmb();
-       if (gelic_net_kick_txdma(card, descr)) {
+       if (gelic_card_kick_txdma(card, descr)) {
                /*
                 * kick failed.
                 * release descriptors which were just prepared
                 */
-               card->netdev->stats.tx_dropped++;
-               gelic_net_release_tx_descr(card, descr);
-               gelic_net_release_tx_descr(card, descr->next);
+               netdev->stats.tx_dropped++;
+               gelic_descr_release_tx(card, descr);
+               gelic_descr_release_tx(card, descr->next);
                card->tx_chain.tail = descr->next->next;
                dev_info(ctodev(card), "%s: kick failure\n", __func__);
        } else {
@@ -820,7 +907,7 @@ static int gelic_net_xmit(struct sk_buff *skb, struct net_device *netdev)
                netdev->trans_start = jiffies;
        }
 
-       spin_unlock_irqrestore(&card->tx_dma_lock, flags);
+       spin_unlock_irqrestore(&card->tx_lock, flags);
        return NETDEV_TX_OK;
 }
 
@@ -828,30 +915,34 @@ static int gelic_net_xmit(struct sk_buff *skb, struct net_device *netdev)
  * gelic_net_pass_skb_up - takes an skb from a descriptor and passes it on
  * @descr: descriptor to process
  * @card: card structure
+ * @netdev: net_device structure to be passed packet
  *
  * iommu-unmaps the skb, fills out skb structure and passes the data to the
  * stack. The descriptor state is not changed.
  */
-static void gelic_net_pass_skb_up(struct gelic_net_descr *descr,
-                                struct gelic_net_card *card)
+static void gelic_net_pass_skb_up(struct gelic_descr *descr,
+                                 struct gelic_card *card,
+                                 struct net_device *netdev)
+
 {
-       struct sk_buff *skb;
-       struct net_device *netdev;
+       struct sk_buff *skb = descr->skb;
        u32 data_status, data_error;
 
-       data_status = descr->data_status;
-       data_error = descr->data_error;
-       netdev = card->netdev;
+       data_status = be32_to_cpu(descr->data_status);
+       data_error = be32_to_cpu(descr->data_error);
        /* unmap skb buffer */
-       skb = descr->skb;
-       dma_unmap_single(ctodev(card), descr->buf_addr, GELIC_NET_MAX_MTU,
+       dma_unmap_single(ctodev(card), be32_to_cpu(descr->buf_addr),
+                        GELIC_NET_MAX_MTU,
                         DMA_FROM_DEVICE);
 
-       skb_put(skb, descr->valid_size? descr->valid_size : descr->result_size);
+       skb_put(skb, be32_to_cpu(descr->valid_size)?
+               be32_to_cpu(descr->valid_size) :
+               be32_to_cpu(descr->result_size));
        if (!descr->valid_size)
                dev_info(ctodev(card), "buffer full %x %x %x\n",
-                        descr->result_size, descr->buf_size,
-                        descr->dmac_cmd_status);
+                        be32_to_cpu(descr->result_size),
+                        be32_to_cpu(descr->buf_size),
+                        be32_to_cpu(descr->dmac_cmd_status));
 
        descr->skb = NULL;
        /*
@@ -863,8 +954,8 @@ static void gelic_net_pass_skb_up(struct gelic_net_descr *descr,
 
        /* checksum offload */
        if (card->rx_csum) {
-               if ((data_status & GELIC_NET_DATA_STATUS_CHK_MASK) &&
-                   (!(data_error & GELIC_NET_DATA_ERROR_CHK_MASK)))
+               if ((data_status & GELIC_DESCR_DATA_STATUS_CHK_MASK) &&
+                   (!(data_error & GELIC_DESCR_DATA_ERROR_CHK_MASK)))
                        skb->ip_summed = CHECKSUM_UNNECESSARY;
                else
                        skb->ip_summed = CHECKSUM_NONE;
@@ -872,15 +963,15 @@ static void gelic_net_pass_skb_up(struct gelic_net_descr *descr,
                skb->ip_summed = CHECKSUM_NONE;
 
        /* update netdevice statistics */
-       card->netdev->stats.rx_packets++;
-       card->netdev->stats.rx_bytes += skb->len;
+       netdev->stats.rx_packets++;
+       netdev->stats.rx_bytes += skb->len;
 
        /* pass skb up to stack */
        netif_receive_skb(skb);
 }
 
 /**
- * gelic_net_decode_one_descr - processes an rx descriptor
+ * gelic_card_decode_one_descr - processes an rx descriptor
  * @card: card structure
  *
  * returns 1 if a packet has been sent to the stack, otherwise 0
@@ -888,63 +979,112 @@ static void gelic_net_pass_skb_up(struct gelic_net_descr *descr,
  * processes an rx descriptor by iommu-unmapping the data buffer and passing
  * the packet up to the stack
  */
-static int gelic_net_decode_one_descr(struct gelic_net_card *card)
+static int gelic_card_decode_one_descr(struct gelic_card *card)
 {
-       enum gelic_net_descr_status status;
-       struct gelic_net_descr_chain *chain = &card->rx_chain;
-       struct gelic_net_descr *descr = chain->tail;
+       enum gelic_descr_dma_status status;
+       struct gelic_descr_chain *chain = &card->rx_chain;
+       struct gelic_descr *descr = chain->head;
+       struct net_device *netdev = NULL;
        int dmac_chain_ended;
 
-       status = gelic_net_get_descr_status(descr);
+       status = gelic_descr_get_status(descr);
        /* is this descriptor terminated with next_descr == NULL? */
        dmac_chain_ended =
-               descr->dmac_cmd_status & GELIC_NET_DMAC_CMDSTAT_RXDCEIS;
+               be32_to_cpu(descr->dmac_cmd_status) &
+               GELIC_DESCR_RX_DMA_CHAIN_END;
 
-       if (status == GELIC_NET_DESCR_CARDOWNED)
+       if (status == GELIC_DESCR_DMA_CARDOWNED)
                return 0;
 
-       if (status == GELIC_NET_DESCR_NOT_IN_USE) {
+       if (status == GELIC_DESCR_DMA_NOT_IN_USE) {
                dev_dbg(ctodev(card), "dormant descr? %p\n", descr);
                return 0;
        }
 
-       if ((status == GELIC_NET_DESCR_RESPONSE_ERROR) ||
-           (status == GELIC_NET_DESCR_PROTECTION_ERROR) ||
-           (status == GELIC_NET_DESCR_FORCE_END)) {
+       /* netdevice select */
+       if (card->vlan_required) {
+               unsigned int i;
+               u16 vid;
+               vid = *(u16 *)(descr->skb->data) & VLAN_VID_MASK;
+               for (i = 0; i < GELIC_PORT_MAX; i++) {
+                       if (card->vlan[i].rx == vid) {
+                               netdev = card->netdev[i];
+                               break;
+                       }
+               };
+               if (GELIC_PORT_MAX <= i) {
+                       pr_info("%s: unknown packet vid=%x\n", __func__, vid);
+                       goto refill;
+               }
+       } else
+               netdev = card->netdev[GELIC_PORT_ETHERNET_0];
+
+       if ((status == GELIC_DESCR_DMA_RESPONSE_ERROR) ||
+           (status == GELIC_DESCR_DMA_PROTECTION_ERROR) ||
+           (status == GELIC_DESCR_DMA_FORCE_END)) {
                dev_info(ctodev(card), "dropping RX descriptor with state %x\n",
                         status);
-               card->netdev->stats.rx_dropped++;
+               netdev->stats.rx_dropped++;
                goto refill;
        }
 
-       if ((status != GELIC_NET_DESCR_COMPLETE) &&
-           (status != GELIC_NET_DESCR_FRAME_END)) {
+       if (status == GELIC_DESCR_DMA_BUFFER_FULL) {
+               /*
+                * Buffer full would occur if and only if
+                * the frame length was longer than the size of this
+                * descriptor's buffer.  If the frame length was equal
+                * to or shorter than buffer'size, FRAME_END condition
+                * would occur.
+                * Anyway this frame was longer than the MTU,
+                * just drop it.
+                */
+               dev_info(ctodev(card), "overlength frame\n");
+               goto refill;
+       }
+       /*
+        * descriptoers any other than FRAME_END here should
+        * be treated as error.
+        */
+       if (status != GELIC_DESCR_DMA_FRAME_END) {
                dev_dbg(ctodev(card), "RX descriptor with state %x\n",
                        status);
                goto refill;
        }
 
        /* ok, we've got a packet in descr */
-       gelic_net_pass_skb_up(descr, card); /* 1: skb_up sccess */
-
+       gelic_net_pass_skb_up(descr, card, netdev);
 refill:
-       descr->next_descr_addr = 0; /* unlink the descr */
+       /*
+        * So that always DMAC can see the end
+        * of the descriptor chain to avoid
+        * from unwanted DMAC overrun.
+        */
+       descr->next_descr_addr = 0;
 
        /* change the descriptor state: */
-       gelic_net_set_descr_status(descr, GELIC_NET_DESCR_NOT_IN_USE);
+       gelic_descr_set_status(descr, GELIC_DESCR_DMA_NOT_IN_USE);
 
-       /* refill one desc
-        * FIXME: this can fail, but for now, just leave this
-        * descriptor without skb
+       /*
+        * this call can fail, but for now, just leave this
+        * decriptor without skb
         */
-       gelic_net_prepare_rx_descr(card, descr);
-       chain->head = descr;
-       chain->tail = descr->next;
-       descr->prev->next_descr_addr = descr->bus_addr;
+       gelic_descr_prepare_rx(card, descr);
 
+       chain->tail = descr;
+       chain->head = descr->next;
+
+       /*
+        * Set this descriptor the end of the chain.
+        */
+       descr->prev->next_descr_addr = cpu_to_be32(descr->bus_addr);
+
+       /*
+        * If dmac chain was met, DMAC stopped.
+        * thus re-enable it
+        */
        if (dmac_chain_ended) {
-               gelic_net_enable_rxdmac(card);
-               dev_dbg(ctodev(card), "reenable rx dma\n");
+               card->rx_dma_restart_required = 1;
+               dev_dbg(ctodev(card), "reenable rx dma scheduled\n");
        }
 
        return 1;
@@ -952,39 +1092,29 @@ refill:
 
 /**
  * gelic_net_poll - NAPI poll function called by the stack to return packets
- * @netdev: interface device structure
+ * @napi: napi structure
  * @budget: number of packets we can pass to the stack at most
  *
- * returns 0 if no more packets available to the driver/stack. Returns 1,
- * if the quota is exceeded, but the driver has still packets.
+ * returns the number of the processed packets
  *
  */
-static int gelic_net_poll(struct net_device *netdev, int *budget)
+static int gelic_net_poll(struct napi_struct *napi, int budget)
 {
-       struct gelic_net_card *card = netdev_priv(netdev);
-       int packets_to_do, packets_done = 0;
-       int no_more_packets = 0;
-
-       packets_to_do = min(*budget, netdev->quota);
-
-       while (packets_to_do) {
-               if (gelic_net_decode_one_descr(card)) {
-                       packets_done++;
-                       packets_to_do--;
-               } else {
-                       /* no more packets for the stack */
-                       no_more_packets = 1;
+       struct gelic_card *card = container_of(napi, struct gelic_card, napi);
+       int packets_done = 0;
+
+       while (packets_done < budget) {
+               if (!gelic_card_decode_one_descr(card))
                        break;
-               }
+
+               packets_done++;
        }
-       netdev->quota -= packets_done;
-       *budget -= packets_done;
-       if (no_more_packets) {
-               netif_rx_complete(netdev);
-               gelic_net_rx_irq_on(card);
-               return 0;
-       } else
-               return 1;
+
+       if (packets_done < budget) {
+               napi_complete(napi);
+               gelic_card_rx_irq_on(card);
+       }
+       return packets_done;
 }
 /**
  * gelic_net_change_mtu - changes the MTU of an interface
@@ -993,7 +1123,7 @@ static int gelic_net_poll(struct net_device *netdev, int *budget)
  *
  * returns 0 on success, <0 on failure
  */
-static int gelic_net_change_mtu(struct net_device *netdev, int new_mtu)
+int gelic_net_change_mtu(struct net_device *netdev, int new_mtu)
 {
        /* no need to re-alloc skbs or so -- the max mtu is about 2.3k
         * and mtu is outbound only anyway */
@@ -1006,13 +1136,12 @@ static int gelic_net_change_mtu(struct net_device *netdev, int new_mtu)
 }
 
 /**
- * gelic_net_interrupt - event handler for gelic_net
+ * gelic_card_interrupt - event handler for gelic_net
  */
-static irqreturn_t gelic_net_interrupt(int irq, void *ptr)
+static irqreturn_t gelic_card_interrupt(int irq, void *ptr)
 {
        unsigned long flags;
-       struct net_device *netdev = ptr;
-       struct gelic_net_card *card = netdev_priv(netdev);
+       struct gelic_card *card = ptr;
        u64 status;
 
        status = card->irq_status;
@@ -1020,19 +1149,37 @@ static irqreturn_t gelic_net_interrupt(int irq, void *ptr)
        if (!status)
                return IRQ_NONE;
 
-       if (status & GELIC_NET_RXINT) {
-               gelic_net_rx_irq_off(card);
-               netif_rx_schedule(netdev);
+       status &= card->irq_mask;
+
+       if (card->rx_dma_restart_required) {
+               card->rx_dma_restart_required = 0;
+               gelic_card_enable_rxdmac(card);
        }
 
-       if (status & GELIC_NET_TXINT) {
-               spin_lock_irqsave(&card->tx_dma_lock, flags);
+       if (status & GELIC_CARD_RXINT) {
+               gelic_card_rx_irq_off(card);
+               napi_schedule(&card->napi);
+       }
+
+       if (status & GELIC_CARD_TXINT) {
+               spin_lock_irqsave(&card->tx_lock, flags);
                card->tx_dma_progress = 0;
-               gelic_net_release_tx_chain(card, 0);
+               gelic_card_release_tx_chain(card, 0);
                /* kick outstanding tx descriptor if any */
-               gelic_net_kick_txdma(card, card->tx_chain.tail);
-               spin_unlock_irqrestore(&card->tx_dma_lock, flags);
+               gelic_card_kick_txdma(card, card->tx_chain.tail);
+               spin_unlock_irqrestore(&card->tx_lock, flags);
        }
+
+       /* ether port status changed */
+       if (status & GELIC_CARD_PORT_STATUS_CHANGED)
+               gelic_card_get_ether_port_status(card, 1);
+
+#ifdef CONFIG_GELIC_WIRELESS
+       if (status & (GELIC_CARD_WLAN_EVENT_RECEIVED |
+                     GELIC_CARD_WLAN_COMMAND_COMPLETED))
+               gelic_wl_interrupt(card->netdev[GELIC_PORT_WIRELESS], status);
+#endif
+
        return IRQ_HANDLED;
 }
 
@@ -1043,55 +1190,17 @@ static irqreturn_t gelic_net_interrupt(int irq, void *ptr)
  *
  * see Documentation/networking/netconsole.txt
  */
-static void gelic_net_poll_controller(struct net_device *netdev)
+void gelic_net_poll_controller(struct net_device *netdev)
 {
-       struct gelic_net_card *card = netdev_priv(netdev);
+       struct gelic_card *card = netdev_card(netdev);
 
-       gelic_net_set_irq_mask(card, 0);
-       gelic_net_interrupt(netdev->irq, netdev);
-       gelic_net_set_irq_mask(card, card->ghiintmask);
+       gelic_card_set_irq_mask(card, 0);
+       gelic_card_interrupt(netdev->irq, netdev);
+       gelic_card_set_irq_mask(card, card->irq_mask);
 }
 #endif /* CONFIG_NET_POLL_CONTROLLER */
 
 /**
- * gelic_net_open_device - open device and map dma region
- * @card: card structure
- */
-static int gelic_net_open_device(struct gelic_net_card *card)
-{
-       int result;
-
-       result = ps3_sb_event_receive_port_setup(card->dev, PS3_BINDING_CPU_ANY,
-               &card->netdev->irq);
-
-       if (result) {
-               dev_info(ctodev(card),
-                        "%s:%d: gelic_net_open_device failed (%d)\n",
-                        __func__, __LINE__, result);
-               result = -EPERM;
-               goto fail_alloc_irq;
-       }
-
-       result = request_irq(card->netdev->irq, gelic_net_interrupt,
-                            IRQF_DISABLED, "gelic network", card->netdev);
-
-       if (result) {
-               dev_info(ctodev(card), "%s:%d: request_irq failed (%d)\n",
-                       __func__, __LINE__, result);
-               goto fail_request_irq;
-       }
-
-       return 0;
-
-fail_request_irq:
-       ps3_sb_event_receive_port_destroy(card->dev, card->netdev->irq);
-       card->netdev->irq = NO_IRQ;
-fail_alloc_irq:
-       return result;
-}
-
-
-/**
  * gelic_net_open - called upon ifonfig up
  * @netdev: interface device structure
  *
@@ -1100,170 +1209,216 @@ fail_alloc_irq:
  * gelic_net_open allocates all the descriptors and memory needed for
  * operation, sets up multicast list and enables interrupts
  */
-static int gelic_net_open(struct net_device *netdev)
+int gelic_net_open(struct net_device *netdev)
 {
-       struct gelic_net_card *card = netdev_priv(netdev);
-
-       dev_dbg(ctodev(card), " -> %s:%d\n", __func__, __LINE__);
+       struct gelic_card *card = netdev_card(netdev);
 
-       gelic_net_open_device(card);
+       dev_dbg(ctodev(card), " -> %s %p\n", __func__, netdev);
 
-       if (gelic_net_init_chain(card, &card->tx_chain,
-                       card->descr, GELIC_NET_TX_DESCRIPTORS))
-               goto alloc_tx_failed;
-       if (gelic_net_init_chain(card, &card->rx_chain,
-                                card->descr + GELIC_NET_TX_DESCRIPTORS,
-                                GELIC_NET_RX_DESCRIPTORS))
-               goto alloc_rx_failed;
-
-       /* head of chain */
-       card->tx_top = card->tx_chain.head;
-       card->rx_top = card->rx_chain.head;
-       dev_dbg(ctodev(card), "descr rx %p, tx %p, size %#lx, num %#x\n",
-               card->rx_top, card->tx_top, sizeof(struct gelic_net_descr),
-               GELIC_NET_RX_DESCRIPTORS);
-       /* allocate rx skbs */
-       if (gelic_net_alloc_rx_skbs(card))
-               goto alloc_skbs_failed;
-
-       card->tx_dma_progress = 0;
-       card->ghiintmask = GELIC_NET_RXINT | GELIC_NET_TXINT;
-
-       gelic_net_set_irq_mask(card, card->ghiintmask);
-       gelic_net_enable_rxdmac(card);
+       gelic_card_up(card);
 
        netif_start_queue(netdev);
-       netif_carrier_on(netdev);
-       netif_poll_enable(netdev);
+       gelic_card_get_ether_port_status(card, 1);
 
+       dev_dbg(ctodev(card), " <- %s\n", __func__);
        return 0;
-
-alloc_skbs_failed:
-       gelic_net_free_chain(card, card->rx_top);
-alloc_rx_failed:
-       gelic_net_free_chain(card, card->tx_top);
-alloc_tx_failed:
-       return -ENOMEM;
 }
 
-static void gelic_net_get_drvinfo (struct net_device *netdev,
-                                  struct ethtool_drvinfo *info)
+void gelic_net_get_drvinfo(struct net_device *netdev,
+                          struct ethtool_drvinfo *info)
 {
        strncpy(info->driver, DRV_NAME, sizeof(info->driver) - 1);
        strncpy(info->version, DRV_VERSION, sizeof(info->version) - 1);
 }
 
-static int gelic_net_get_settings(struct net_device *netdev,
-                                 struct ethtool_cmd *cmd)
+static int gelic_ether_get_settings(struct net_device *netdev,
+                                   struct ethtool_cmd *cmd)
 {
-       struct gelic_net_card *card = netdev_priv(netdev);
-       int status;
-       u64 v1, v2;
-       int speed, duplex;
+       struct gelic_card *card = netdev_card(netdev);
 
-       speed = duplex = -1;
-       status = lv1_net_control(bus_id(card), dev_id(card),
-                       GELIC_NET_GET_ETH_PORT_STATUS, GELIC_NET_PORT, 0, 0,
-                       &v1, &v2);
-       if (status) {
-               /* link down */
-       } else {
-               if (v1 & GELIC_NET_FULL_DUPLEX) {
-                       duplex = DUPLEX_FULL;
-               } else {
-                       duplex = DUPLEX_HALF;
-               }
+       gelic_card_get_ether_port_status(card, 0);
 
-               if (v1 & GELIC_NET_SPEED_10 ) {
-                       speed = SPEED_10;
-               } else if (v1 & GELIC_NET_SPEED_100) {
-                       speed = SPEED_100;
-               } else if (v1 & GELIC_NET_SPEED_1000) {
-                       speed = SPEED_1000;
-               }
+       if (card->ether_port_status & GELIC_LV1_ETHER_FULL_DUPLEX)
+               cmd->duplex = DUPLEX_FULL;
+       else
+               cmd->duplex = DUPLEX_HALF;
+
+       switch (card->ether_port_status & GELIC_LV1_ETHER_SPEED_MASK) {
+       case GELIC_LV1_ETHER_SPEED_10:
+               cmd->speed = SPEED_10;
+               break;
+       case GELIC_LV1_ETHER_SPEED_100:
+               cmd->speed = SPEED_100;
+               break;
+       case GELIC_LV1_ETHER_SPEED_1000:
+               cmd->speed = SPEED_1000;
+               break;
+       default:
+               pr_info("%s: speed unknown\n", __func__);
+               cmd->speed = SPEED_10;
+               break;
        }
+
        cmd->supported = SUPPORTED_TP | SUPPORTED_Autoneg |
                        SUPPORTED_10baseT_Half | SUPPORTED_10baseT_Full |
                        SUPPORTED_100baseT_Half | SUPPORTED_100baseT_Full |
-                       SUPPORTED_1000baseT_Half | SUPPORTED_1000baseT_Full;
+                       SUPPORTED_1000baseT_Full;
        cmd->advertising = cmd->supported;
-       cmd->speed = speed;
-       cmd->duplex = duplex;
-       cmd->autoneg = AUTONEG_ENABLE; /* always enabled */
+       if (card->link_mode & GELIC_LV1_ETHER_AUTO_NEG) {
+               cmd->autoneg = AUTONEG_ENABLE;
+       } else {
+               cmd->autoneg = AUTONEG_DISABLE;
+               cmd->advertising &= ~ADVERTISED_Autoneg;
+       }
        cmd->port = PORT_TP;
 
        return 0;
 }
 
-static u32 gelic_net_get_link(struct net_device *netdev)
+static int gelic_ether_set_settings(struct net_device *netdev,
+                                   struct ethtool_cmd *cmd)
 {
-       struct gelic_net_card *card = netdev_priv(netdev);
-       int status;
-       u64 v1, v2;
-       int link;
+       struct gelic_card *card = netdev_card(netdev);
+       u64 mode;
+       int ret;
 
-       status = lv1_net_control(bus_id(card), dev_id(card),
-                       GELIC_NET_GET_ETH_PORT_STATUS, GELIC_NET_PORT, 0, 0,
-                       &v1, &v2);
-       if (status)
-               return 0; /* link down */
+       if (cmd->autoneg == AUTONEG_ENABLE) {
+               mode = GELIC_LV1_ETHER_AUTO_NEG;
+       } else {
+               switch (cmd->speed) {
+               case SPEED_10:
+                       mode = GELIC_LV1_ETHER_SPEED_10;
+                       break;
+               case SPEED_100:
+                       mode = GELIC_LV1_ETHER_SPEED_100;
+                       break;
+               case SPEED_1000:
+                       mode = GELIC_LV1_ETHER_SPEED_1000;
+                       break;
+               default:
+                       return -EINVAL;
+               }
+               if (cmd->duplex == DUPLEX_FULL)
+                       mode |= GELIC_LV1_ETHER_FULL_DUPLEX;
+               else if (cmd->speed == SPEED_1000) {
+                       pr_info("1000 half duplex is not supported.\n");
+                       return -EINVAL;
+               }
+       }
 
-       if (v1 & GELIC_NET_LINK_UP)
-               link = 1;
-       else
-               link = 0;
+       ret = gelic_card_set_link_mode(card, mode);
 
-       return link;
-}
+       if (ret)
+               return ret;
 
-static int gelic_net_nway_reset(struct net_device *netdev)
-{
-       if (netif_running(netdev)) {
-               gelic_net_stop(netdev);
-               gelic_net_open(netdev);
-       }
        return 0;
 }
 
-static u32 gelic_net_get_tx_csum(struct net_device *netdev)
+u32 gelic_net_get_rx_csum(struct net_device *netdev)
 {
-       return (netdev->features & NETIF_F_IP_CSUM) != 0;
+       struct gelic_card *card = netdev_card(netdev);
+
+       return card->rx_csum;
 }
 
-static int gelic_net_set_tx_csum(struct net_device *netdev, u32 data)
+int gelic_net_set_rx_csum(struct net_device *netdev, u32 data)
 {
-       if (data)
-               netdev->features |= NETIF_F_IP_CSUM;
-       else
-               netdev->features &= ~NETIF_F_IP_CSUM;
+       struct gelic_card *card = netdev_card(netdev);
 
+       card->rx_csum = data;
        return 0;
 }
 
-static u32 gelic_net_get_rx_csum(struct net_device *netdev)
+static void gelic_net_get_wol(struct net_device *netdev,
+                             struct ethtool_wolinfo *wol)
 {
-       struct gelic_net_card *card = netdev_priv(netdev);
+       if (0 <= ps3_compare_firmware_version(2, 2, 0))
+               wol->supported = WAKE_MAGIC;
+       else
+               wol->supported = 0;
 
-       return card->rx_csum;
+       wol->wolopts = ps3_sys_manager_get_wol() ? wol->supported : 0;
+       memset(&wol->sopass, 0, sizeof(wol->sopass));
 }
-
-static int gelic_net_set_rx_csum(struct net_device *netdev, u32 data)
+static int gelic_net_set_wol(struct net_device *netdev,
+                            struct ethtool_wolinfo *wol)
 {
-       struct gelic_net_card *card = netdev_priv(netdev);
+       int status;
+       struct gelic_card *card;
+       u64 v1, v2;
 
-       card->rx_csum = data;
-       return 0;
+       if (ps3_compare_firmware_version(2, 2, 0) < 0 ||
+           !capable(CAP_NET_ADMIN))
+               return -EPERM;
+
+       if (wol->wolopts & ~WAKE_MAGIC)
+               return -EINVAL;
+
+       card = netdev_card(netdev);
+       if (wol->wolopts & WAKE_MAGIC) {
+               status = lv1_net_control(bus_id(card), dev_id(card),
+                                        GELIC_LV1_SET_WOL,
+                                        GELIC_LV1_WOL_MAGIC_PACKET,
+                                        0, GELIC_LV1_WOL_MP_ENABLE,
+                                        &v1, &v2);
+               if (status) {
+                       pr_info("%s: enabling WOL failed %d\n", __func__,
+                               status);
+                       status = -EIO;
+                       goto done;
+               }
+               status = lv1_net_control(bus_id(card), dev_id(card),
+                                        GELIC_LV1_SET_WOL,
+                                        GELIC_LV1_WOL_ADD_MATCH_ADDR,
+                                        0, GELIC_LV1_WOL_MATCH_ALL,
+                                        &v1, &v2);
+               if (!status)
+                       ps3_sys_manager_set_wol(1);
+               else {
+                       pr_info("%s: enabling WOL filter failed %d\n",
+                               __func__, status);
+                       status = -EIO;
+               }
+       } else {
+               status = lv1_net_control(bus_id(card), dev_id(card),
+                                        GELIC_LV1_SET_WOL,
+                                        GELIC_LV1_WOL_MAGIC_PACKET,
+                                        0, GELIC_LV1_WOL_MP_DISABLE,
+                                        &v1, &v2);
+               if (status) {
+                       pr_info("%s: disabling WOL failed %d\n", __func__,
+                               status);
+                       status = -EIO;
+                       goto done;
+               }
+               status = lv1_net_control(bus_id(card), dev_id(card),
+                                        GELIC_LV1_SET_WOL,
+                                        GELIC_LV1_WOL_DELETE_MATCH_ADDR,
+                                        0, GELIC_LV1_WOL_MATCH_ALL,
+                                        &v1, &v2);
+               if (!status)
+                       ps3_sys_manager_set_wol(0);
+               else {
+                       pr_info("%s: removing WOL filter failed %d\n",
+                               __func__, status);
+                       status = -EIO;
+               }
+       }
+done:
+       return status;
 }
 
-static struct ethtool_ops gelic_net_ethtool_ops = {
+static const struct ethtool_ops gelic_ether_ethtool_ops = {
        .get_drvinfo    = gelic_net_get_drvinfo,
-       .get_settings   = gelic_net_get_settings,
-       .get_link       = gelic_net_get_link,
-       .nway_reset     = gelic_net_nway_reset,
-       .get_tx_csum    = gelic_net_get_tx_csum,
-       .set_tx_csum    = gelic_net_set_tx_csum,
+       .get_settings   = gelic_ether_get_settings,
+       .set_settings   = gelic_ether_set_settings,
+       .get_link       = ethtool_op_get_link,
+       .get_tx_csum    = ethtool_op_get_tx_csum,
+       .set_tx_csum    = ethtool_op_set_tx_csum,
        .get_rx_csum    = gelic_net_get_rx_csum,
        .set_rx_csum    = gelic_net_set_rx_csum,
+       .get_wol        = gelic_net_get_wol,
+       .set_wol        = gelic_net_set_wol,
 };
 
 /**
@@ -1275,9 +1430,9 @@ static struct ethtool_ops gelic_net_ethtool_ops = {
  */
 static void gelic_net_tx_timeout_task(struct work_struct *work)
 {
-       struct gelic_net_card *card =
-               container_of(work, struct gelic_net_card, tx_timeout_task);
-       struct net_device *netdev = card->netdev;
+       struct gelic_card *card =
+               container_of(work, struct gelic_card, tx_timeout_task);
+       struct net_device *netdev = card->netdev[GELIC_PORT_ETHERNET_0];
 
        dev_info(ctodev(card), "%s:Timed out. Restarting... \n", __func__);
 
@@ -1300,11 +1455,11 @@ out:
  *
  * called, if tx hangs. Schedules a task that resets the interface
  */
-static void gelic_net_tx_timeout(struct net_device *netdev)
+void gelic_net_tx_timeout(struct net_device *netdev)
 {
-       struct gelic_net_card *card;
+       struct gelic_card *card;
 
-       card = netdev_priv(netdev);
+       card = netdev_card(netdev);
        atomic_inc(&card->tx_timeout_task_counter);
        if (netdev->flags & IFF_UP)
                schedule_work(&card->tx_timeout_task);
@@ -1312,178 +1467,262 @@ static void gelic_net_tx_timeout(struct net_device *netdev)
                atomic_dec(&card->tx_timeout_task_counter);
 }
 
+static const struct net_device_ops gelic_netdevice_ops = {
+       .ndo_open = gelic_net_open,
+       .ndo_stop = gelic_net_stop,
+       .ndo_start_xmit = gelic_net_xmit,
+       .ndo_set_multicast_list = gelic_net_set_multi,
+       .ndo_change_mtu = gelic_net_change_mtu,
+       .ndo_tx_timeout = gelic_net_tx_timeout,
+       .ndo_set_mac_address = eth_mac_addr,
+       .ndo_validate_addr = eth_validate_addr,
+#ifdef CONFIG_NET_POLL_CONTROLLER
+       .ndo_poll_controller = gelic_net_poll_controller,
+#endif
+};
+
 /**
- * gelic_net_setup_netdev_ops - initialization of net_device operations
+ * gelic_ether_setup_netdev_ops - initialization of net_device operations
  * @netdev: net_device structure
  *
  * fills out function pointers in the net_device structure
  */
-static void gelic_net_setup_netdev_ops(struct net_device *netdev)
+static void __devinit gelic_ether_setup_netdev_ops(struct net_device *netdev,
+                                                  struct napi_struct *napi)
 {
-       netdev->open = &gelic_net_open;
-       netdev->stop = &gelic_net_stop;
-       netdev->hard_start_xmit = &gelic_net_xmit;
-       netdev->set_multicast_list = &gelic_net_set_multi;
-       netdev->change_mtu = &gelic_net_change_mtu;
-       /* tx watchdog */
-       netdev->tx_timeout = &gelic_net_tx_timeout;
        netdev->watchdog_timeo = GELIC_NET_WATCHDOG_TIMEOUT;
        /* NAPI */
-       netdev->poll = &gelic_net_poll;
-       netdev->weight = GELIC_NET_NAPI_WEIGHT;
-       netdev->ethtool_ops = &gelic_net_ethtool_ops;
+       netif_napi_add(netdev, napi,
+                      gelic_net_poll, GELIC_NET_NAPI_WEIGHT);
+       netdev->ethtool_ops = &gelic_ether_ethtool_ops;
+       netdev->netdev_ops = &gelic_netdevice_ops;
 }
 
 /**
- * gelic_net_setup_netdev - initialization of net_device
+ * gelic_ether_setup_netdev - initialization of net_device
+ * @netdev: net_device structure
  * @card: card structure
  *
  * Returns 0 on success or <0 on failure
  *
- * gelic_net_setup_netdev initializes the net_device structure
+ * gelic_ether_setup_netdev initializes the net_device structure
+ * and register it.
  **/
-static int gelic_net_setup_netdev(struct gelic_net_card *card)
+int __devinit gelic_net_setup_netdev(struct net_device *netdev,
+                                    struct gelic_card *card)
 {
-       struct net_device *netdev = card->netdev;
-       struct sockaddr addr;
-       unsigned int i;
        int status;
        u64 v1, v2;
 
-       SET_MODULE_OWNER(netdev);
-       SET_NETDEV_DEV(netdev, &card->dev->core);
-       spin_lock_init(&card->tx_dma_lock);
-
-       card->rx_csum = GELIC_NET_RX_CSUM_DEFAULT;
-
-       gelic_net_setup_netdev_ops(netdev);
-
        netdev->features = NETIF_F_IP_CSUM;
 
        status = lv1_net_control(bus_id(card), dev_id(card),
-                                GELIC_NET_GET_MAC_ADDRESS,
+                                GELIC_LV1_GET_MAC_ADDRESS,
                                 0, 0, 0, &v1, &v2);
+       v1 <<= 16;
        if (status || !is_valid_ether_addr((u8 *)&v1)) {
                dev_info(ctodev(card),
                         "%s:lv1_net_control GET_MAC_ADDR failed %d\n",
                         __func__, status);
                return -EINVAL;
        }
-       v1 <<= 16;
-       memcpy(addr.sa_data, &v1, ETH_ALEN);
-       memcpy(netdev->dev_addr, addr.sa_data, ETH_ALEN);
-       dev_info(ctodev(card), "MAC addr %02x:%02x:%02x:%02x:%02x:%02x\n",
-                netdev->dev_addr[0], netdev->dev_addr[1],
-                netdev->dev_addr[2], netdev->dev_addr[3],
-                netdev->dev_addr[4], netdev->dev_addr[5]);
-
-       card->vlan_index = -1;  /* no vlan */
-       for (i = 0; i < GELIC_NET_VLAN_MAX; i++) {
-               status = lv1_net_control(bus_id(card), dev_id(card),
-                                       GELIC_NET_GET_VLAN_ID,
-                                       i + 1, /* index; one based */
-                                       0, 0, &v1, &v2);
-               if (status == GELIC_NET_VLAN_NO_ENTRY) {
-                       dev_dbg(ctodev(card),
-                               "GELIC_VLAN_ID no entry:%d, VLAN disabled\n",
-                               status);
-                       card->vlan_id[i] = 0;
-               } else if (status) {
-                       dev_dbg(ctodev(card),
-                               "%s:GELIC_NET_VLAN_ID faild, status=%d\n",
-                               __func__, status);
-                       card->vlan_id[i] = 0;
-               } else {
-                       card->vlan_id[i] = (u32)v1;
-                       dev_dbg(ctodev(card), "vlan_id:%d, %lx\n", i, v1);
-               }
+       memcpy(netdev->dev_addr, &v1, ETH_ALEN);
+
+       if (card->vlan_required) {
+               netdev->hard_header_len += VLAN_HLEN;
+               /*
+                * As vlan is internally used,
+                * we can not receive vlan packets
+                */
+               netdev->features |= NETIF_F_VLAN_CHALLENGED;
        }
-       if (card->vlan_id[GELIC_NET_VLAN_WIRED - 1])
-               card->vlan_index = GELIC_NET_VLAN_WIRED - 1;
 
        status = register_netdev(netdev);
        if (status) {
-               dev_err(ctodev(card), "%s:Couldn't register net_device: %d\n",
-                       __func__, status);
+               dev_err(ctodev(card), "%s:Couldn't register %s %d\n",
+                       __func__, netdev->name, status);
                return status;
        }
+       dev_info(ctodev(card), "%s: MAC addr %pM\n",
+                netdev->name, netdev->dev_addr);
 
        return 0;
 }
 
 /**
- * gelic_net_alloc_card - allocates net_device and card structure
+ * gelic_alloc_card_net - allocates net_device and card structure
  *
  * returns the card structure or NULL in case of errors
  *
  * the card and net_device structures are linked to each other
  */
-static struct gelic_net_card *gelic_net_alloc_card(void)
+#define GELIC_ALIGN (32)
+static struct gelic_card * __devinit gelic_alloc_card_net(struct net_device **netdev)
 {
-       struct net_device *netdev;
-       struct gelic_net_card *card;
+       struct gelic_card *card;
+       struct gelic_port *port;
+       void *p;
        size_t alloc_size;
-
-       alloc_size = sizeof (*card) +
-               sizeof (struct gelic_net_descr) * GELIC_NET_RX_DESCRIPTORS +
-               sizeof (struct gelic_net_descr) * GELIC_NET_TX_DESCRIPTORS;
        /*
-        * we assume private data is allocated 32 bytes (or more) aligned
-        * so that gelic_net_descr should be 32 bytes aligned.
-        * Current alloc_etherdev() does do it because NETDEV_ALIGN
-        * is 32.
-        * check this assumption here.
+        * gelic requires dma descriptor is 32 bytes aligned and
+        * the hypervisor requires irq_status is 8 bytes aligned.
         */
-       BUILD_BUG_ON(NETDEV_ALIGN < 32);
-       BUILD_BUG_ON(offsetof(struct gelic_net_card, irq_status) % 8);
-       BUILD_BUG_ON(offsetof(struct gelic_net_card, descr) % 32);
+       BUILD_BUG_ON(offsetof(struct gelic_card, irq_status) % 8);
+       BUILD_BUG_ON(offsetof(struct gelic_card, descr) % 32);
+       alloc_size =
+               sizeof(struct gelic_card) +
+               sizeof(struct gelic_descr) * GELIC_NET_RX_DESCRIPTORS +
+               sizeof(struct gelic_descr) * GELIC_NET_TX_DESCRIPTORS +
+               GELIC_ALIGN - 1;
+
+       p  = kzalloc(alloc_size, GFP_KERNEL);
+       if (!p)
+               return NULL;
+       card = PTR_ALIGN(p, GELIC_ALIGN);
+       card->unalign = p;
 
-       netdev = alloc_etherdev(alloc_size);
-       if (!netdev)
+       /*
+        * alloc netdev
+        */
+       *netdev = alloc_etherdev(sizeof(struct gelic_port));
+       if (!netdev) {
+               kfree(card->unalign);
                return NULL;
+       }
+       port = netdev_priv(*netdev);
+
+       /* gelic_port */
+       port->netdev = *netdev;
+       port->card = card;
+       port->type = GELIC_PORT_ETHERNET_0;
+
+       /* gelic_card */
+       card->netdev[GELIC_PORT_ETHERNET_0] = *netdev;
 
-       card = netdev_priv(netdev);
-       card->netdev = netdev;
        INIT_WORK(&card->tx_timeout_task, gelic_net_tx_timeout_task);
        init_waitqueue_head(&card->waitq);
        atomic_set(&card->tx_timeout_task_counter, 0);
+       mutex_init(&card->updown_lock);
+       atomic_set(&card->users, 0);
 
        return card;
 }
 
+static void __devinit gelic_card_get_vlan_info(struct gelic_card *card)
+{
+       u64 v1, v2;
+       int status;
+       unsigned int i;
+       struct {
+               int tx;
+               int rx;
+       } vlan_id_ix[2] = {
+               [GELIC_PORT_ETHERNET_0] = {
+                       .tx = GELIC_LV1_VLAN_TX_ETHERNET_0,
+                       .rx = GELIC_LV1_VLAN_RX_ETHERNET_0
+               },
+               [GELIC_PORT_WIRELESS] = {
+                       .tx = GELIC_LV1_VLAN_TX_WIRELESS,
+                       .rx = GELIC_LV1_VLAN_RX_WIRELESS
+               }
+       };
+
+       for (i = 0; i < ARRAY_SIZE(vlan_id_ix); i++) {
+               /* tx tag */
+               status = lv1_net_control(bus_id(card), dev_id(card),
+                                        GELIC_LV1_GET_VLAN_ID,
+                                        vlan_id_ix[i].tx,
+                                        0, 0, &v1, &v2);
+               if (status || !v1) {
+                       if (status != LV1_NO_ENTRY)
+                               dev_dbg(ctodev(card),
+                                       "get vlan id for tx(%d) failed(%d)\n",
+                                       vlan_id_ix[i].tx, status);
+                       card->vlan[i].tx = 0;
+                       card->vlan[i].rx = 0;
+                       continue;
+               }
+               card->vlan[i].tx = (u16)v1;
+
+               /* rx tag */
+               status = lv1_net_control(bus_id(card), dev_id(card),
+                                        GELIC_LV1_GET_VLAN_ID,
+                                        vlan_id_ix[i].rx,
+                                        0, 0, &v1, &v2);
+               if (status || !v1) {
+                       if (status != LV1_NO_ENTRY)
+                               dev_info(ctodev(card),
+                                        "get vlan id for rx(%d) failed(%d)\n",
+                                        vlan_id_ix[i].rx, status);
+                       card->vlan[i].tx = 0;
+                       card->vlan[i].rx = 0;
+                       continue;
+               }
+               card->vlan[i].rx = (u16)v1;
+
+               dev_dbg(ctodev(card), "vlan_id[%d] tx=%02x rx=%02x\n",
+                       i, card->vlan[i].tx, card->vlan[i].rx);
+       }
+
+       if (card->vlan[GELIC_PORT_ETHERNET_0].tx) {
+               BUG_ON(!card->vlan[GELIC_PORT_WIRELESS].tx);
+               card->vlan_required = 1;
+       } else
+               card->vlan_required = 0;
+
+       /* check wirelss capable firmware */
+       if (ps3_compare_firmware_version(1, 6, 0) < 0) {
+               card->vlan[GELIC_PORT_WIRELESS].tx = 0;
+               card->vlan[GELIC_PORT_WIRELESS].rx = 0;
+       }
+
+       dev_info(ctodev(card), "internal vlan %s\n",
+                card->vlan_required? "enabled" : "disabled");
+}
 /**
  * ps3_gelic_driver_probe - add a device to the control of this driver
  */
-static int ps3_gelic_driver_probe (struct ps3_system_bus_device *dev)
+static int __devinit ps3_gelic_driver_probe(struct ps3_system_bus_device *dev)
 {
-       struct gelic_net_card *card = gelic_net_alloc_card();
+       struct gelic_card *card;
+       struct net_device *netdev;
        int result;
 
-       if (!card) {
-               dev_info(&dev->core, "gelic_net_alloc_card failed\n");
-               result = -ENOMEM;
-               goto fail_alloc_card;
-       }
-
-       ps3_system_bus_set_driver_data(dev, card);
-       card->dev = dev;
-
+       pr_debug("%s: called\n", __func__);
        result = ps3_open_hv_device(dev);
 
        if (result) {
-               dev_dbg(&dev->core, "ps3_open_hv_device failed\n");
+               dev_dbg(&dev->core, "%s:ps3_open_hv_device failed\n",
+                       __func__);
                goto fail_open;
        }
 
        result = ps3_dma_region_create(dev->d_region);
 
        if (result) {
-               dev_dbg(&dev->core, "ps3_dma_region_create failed(%d)\n",
-                       result);
+               dev_dbg(&dev->core, "%s:ps3_dma_region_create failed(%d)\n",
+                       __func__, result);
                BUG_ON("check region type");
                goto fail_dma_region;
        }
 
+       /* alloc card/netdevice */
+       card = gelic_alloc_card_net(&netdev);
+       if (!card) {
+               dev_info(&dev->core, "%s:gelic_net_alloc_card failed\n",
+                        __func__);
+               result = -ENOMEM;
+               goto fail_alloc_card;
+       }
+       ps3_system_bus_set_drvdata(dev, card);
+       card->dev = dev;
+
+       /* get internal vlan info */
+       gelic_card_get_vlan_info(card);
+
+       card->link_mode = GELIC_LV1_ETHER_AUTO_NEG;
+
+       /* setup interrupt */
        result = lv1_net_set_interrupt_status_indicator(bus_id(card),
                                                        dev_id(card),
                ps3_mm_phys_to_lpar(__pa(&card->irq_status)),
@@ -1491,34 +1730,101 @@ static int ps3_gelic_driver_probe (struct ps3_system_bus_device *dev)
 
        if (result) {
                dev_dbg(&dev->core,
-                       "lv1_net_set_interrupt_status_indicator failed: %s\n",
-                       ps3_result(result));
+                       "%s:set_interrupt_status_indicator failed: %s\n",
+                       __func__, ps3_result(result));
                result = -EIO;
                goto fail_status_indicator;
        }
 
-       result = gelic_net_setup_netdev(card);
+       result = ps3_sb_event_receive_port_setup(dev, PS3_BINDING_CPU_ANY,
+               &card->irq);
 
        if (result) {
-               dev_dbg(&dev->core, "%s:%d: ps3_dma_region_create failed: "
-                       "(%d)\n", __func__, __LINE__, result);
+               dev_info(ctodev(card),
+                        "%s:gelic_net_open_device failed (%d)\n",
+                        __func__, result);
+               result = -EPERM;
+               goto fail_alloc_irq;
+       }
+       result = request_irq(card->irq, gelic_card_interrupt,
+                            IRQF_DISABLED, netdev->name, card);
+
+       if (result) {
+               dev_info(ctodev(card), "%s:request_irq failed (%d)\n",
+                       __func__, result);
+               goto fail_request_irq;
+       }
+
+       /* setup card structure */
+       card->irq_mask = GELIC_CARD_RXINT | GELIC_CARD_TXINT |
+               GELIC_CARD_PORT_STATUS_CHANGED;
+       card->rx_csum = GELIC_CARD_RX_CSUM_DEFAULT;
+
+
+       if (gelic_card_init_chain(card, &card->tx_chain,
+                       card->descr, GELIC_NET_TX_DESCRIPTORS))
+               goto fail_alloc_tx;
+       if (gelic_card_init_chain(card, &card->rx_chain,
+                                card->descr + GELIC_NET_TX_DESCRIPTORS,
+                                GELIC_NET_RX_DESCRIPTORS))
+               goto fail_alloc_rx;
+
+       /* head of chain */
+       card->tx_top = card->tx_chain.head;
+       card->rx_top = card->rx_chain.head;
+       dev_dbg(ctodev(card), "descr rx %p, tx %p, size %#lx, num %#x\n",
+               card->rx_top, card->tx_top, sizeof(struct gelic_descr),
+               GELIC_NET_RX_DESCRIPTORS);
+       /* allocate rx skbs */
+       if (gelic_card_alloc_rx_skbs(card))
+               goto fail_alloc_skbs;
+
+       spin_lock_init(&card->tx_lock);
+       card->tx_dma_progress = 0;
+
+       /* setup net_device structure */
+       netdev->irq = card->irq;
+       SET_NETDEV_DEV(netdev, &card->dev->core);
+       gelic_ether_setup_netdev_ops(netdev, &card->napi);
+       result = gelic_net_setup_netdev(netdev, card);
+       if (result) {
+               dev_dbg(&dev->core, "%s: setup_netdev failed %d",
+                       __func__, result);
                goto fail_setup_netdev;
        }
 
+#ifdef CONFIG_GELIC_WIRELESS
+       if (gelic_wl_driver_probe(card)) {
+               dev_dbg(&dev->core, "%s: WL init failed\n", __func__);
+               goto fail_setup_netdev;
+       }
+#endif
+       pr_debug("%s: done\n", __func__);
        return 0;
 
 fail_setup_netdev:
+fail_alloc_skbs:
+       gelic_card_free_chain(card, card->rx_chain.head);
+fail_alloc_rx:
+       gelic_card_free_chain(card, card->tx_chain.head);
+fail_alloc_tx:
+       free_irq(card->irq, card);
+       netdev->irq = NO_IRQ;
+fail_request_irq:
+       ps3_sb_event_receive_port_destroy(dev, card->irq);
+fail_alloc_irq:
        lv1_net_set_interrupt_status_indicator(bus_id(card),
                                               bus_id(card),
-                                              0 , 0);
+                                              0, 0);
 fail_status_indicator:
+       ps3_system_bus_set_drvdata(dev, NULL);
+       kfree(netdev_card(netdev)->unalign);
+       free_netdev(netdev);
+fail_alloc_card:
        ps3_dma_region_free(dev->d_region);
 fail_dma_region:
        ps3_close_hv_device(dev);
 fail_open:
-       ps3_system_bus_set_driver_data(dev, NULL);
-       free_netdev(card->netdev);
-fail_alloc_card:
        return result;
 }
 
@@ -1526,9 +1832,37 @@ fail_alloc_card:
  * ps3_gelic_driver_remove - remove a device from the control of this driver
  */
 
-static int ps3_gelic_driver_remove (struct ps3_system_bus_device *dev)
+static int ps3_gelic_driver_remove(struct ps3_system_bus_device *dev)
 {
-       struct gelic_net_card *card = ps3_system_bus_get_driver_data(dev);
+       struct gelic_card *card = ps3_system_bus_get_drvdata(dev);
+       struct net_device *netdev0;
+       pr_debug("%s: called\n", __func__);
+
+       /* set auto-negotiation */
+       gelic_card_set_link_mode(card, GELIC_LV1_ETHER_AUTO_NEG);
+
+#ifdef CONFIG_GELIC_WIRELESS
+       gelic_wl_driver_remove(card);
+#endif
+       /* stop interrupt */
+       gelic_card_set_irq_mask(card, 0);
+
+       /* turn off DMA, force end */
+       gelic_card_disable_rxdmac(card);
+       gelic_card_disable_txdmac(card);
+
+       /* release chains */
+       gelic_card_release_tx_chain(card, 1);
+       gelic_card_release_rx_chain(card);
+
+       gelic_card_free_chain(card, card->tx_top);
+       gelic_card_free_chain(card, card->rx_top);
+
+       netdev0 = card->netdev[GELIC_PORT_ETHERNET_0];
+       /* disconnect event port */
+       free_irq(card->irq, card);
+       netdev0->irq = NO_IRQ;
+       ps3_sb_event_receive_port_destroy(card->dev, card->irq);
 
        wait_event(card->waitq,
                   atomic_read(&card->tx_timeout_task_counter) == 0);
@@ -1536,15 +1870,17 @@ static int ps3_gelic_driver_remove (struct ps3_system_bus_device *dev)
        lv1_net_set_interrupt_status_indicator(bus_id(card), dev_id(card),
                                               0 , 0);
 
-       unregister_netdev(card->netdev);
-       free_netdev(card->netdev);
+       unregister_netdev(netdev0);
+       kfree(netdev_card(netdev0)->unalign);
+       free_netdev(netdev0);
 
-       ps3_system_bus_set_driver_data(dev, NULL);
+       ps3_system_bus_set_drvdata(dev, NULL);
 
        ps3_dma_region_free(dev->d_region);
 
        ps3_close_hv_device(dev);
 
+       pr_debug("%s: done\n", __func__);
        return 0;
 }
 
@@ -1569,8 +1905,8 @@ static void __exit ps3_gelic_driver_exit (void)
        ps3_system_bus_driver_unregister(&ps3_gelic_driver);
 }
 
-module_init (ps3_gelic_driver_init);
-module_exit (ps3_gelic_driver_exit);
+module_init(ps3_gelic_driver_init);
+module_exit(ps3_gelic_driver_exit);
 
 MODULE_ALIAS(PS3_MODULE_ALIAS_GELIC);