2 * PS3 gelic network driver.
4 * Copyright (C) 2007 Sony Computer Entertainment Inc.
5 * Copyright 2006, 2007 Sony Corporation
7 * This file is based on: spider_net.c
9 * (C) Copyright IBM Corp. 2005
11 * Authors : Utz Bacher <utz.bacher@de.ibm.com>
12 * Jens Osterkamp <Jens.Osterkamp@de.ibm.com>
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2, or (at your option)
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, write to the Free Software
26 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
31 #include <linux/interrupt.h>
32 #include <linux/kernel.h>
33 #include <linux/module.h>
34 #include <linux/slab.h>
36 #include <linux/etherdevice.h>
37 #include <linux/ethtool.h>
38 #include <linux/if_vlan.h>
42 #include <linux/tcp.h>
44 #include <linux/dma-mapping.h>
45 #include <net/checksum.h>
46 #include <asm/firmware.h>
48 #include <asm/lv1call.h>
50 #include "ps3_gelic_net.h"
51 #include "ps3_gelic_wireless.h"
53 #define DRV_NAME "Gelic Network Driver"
54 #define DRV_VERSION "2.0"
56 MODULE_AUTHOR("SCE Inc.");
57 MODULE_DESCRIPTION("Gelic Network driver");
58 MODULE_LICENSE("GPL");
61 static inline void gelic_card_enable_rxdmac(struct gelic_card *card);
62 static inline void gelic_card_disable_rxdmac(struct gelic_card *card);
63 static inline void gelic_card_disable_txdmac(struct gelic_card *card);
64 static inline void gelic_card_reset_chain(struct gelic_card *card,
65 struct gelic_descr_chain *chain,
66 struct gelic_descr *start_descr);
69 int gelic_card_set_irq_mask(struct gelic_card *card, u64 mask)
73 status = lv1_net_set_interrupt_mask(bus_id(card), dev_id(card),
76 dev_info(ctodev(card),
77 "%s failed %d\n", __func__, status);
81 static inline void gelic_card_rx_irq_on(struct gelic_card *card)
83 card->irq_mask |= GELIC_CARD_RXINT;
84 gelic_card_set_irq_mask(card, card->irq_mask);
86 static inline void gelic_card_rx_irq_off(struct gelic_card *card)
88 card->irq_mask &= ~GELIC_CARD_RXINT;
89 gelic_card_set_irq_mask(card, card->irq_mask);
92 static void gelic_card_get_ether_port_status(struct gelic_card *card,
96 struct net_device *ether_netdev;
98 lv1_net_control(bus_id(card), dev_id(card),
99 GELIC_LV1_GET_ETH_PORT_STATUS,
100 GELIC_LV1_VLAN_TX_ETHERNET_0, 0, 0,
101 &card->ether_port_status, &v2);
104 ether_netdev = card->netdev[GELIC_PORT_ETHERNET_0];
105 if (card->ether_port_status & GELIC_LV1_ETHER_LINK_UP)
106 netif_carrier_on(ether_netdev);
108 netif_carrier_off(ether_netdev);
112 static int gelic_card_set_link_mode(struct gelic_card *card, int mode)
117 status = lv1_net_control(bus_id(card), dev_id(card),
118 GELIC_LV1_SET_NEGOTIATION_MODE,
119 GELIC_LV1_PHY_ETHERNET_0, mode, 0, &v1, &v2);
121 pr_info("%s: failed setting negotiation mode %d\n", __func__,
126 card->link_mode = mode;
130 void gelic_card_up(struct gelic_card *card)
132 pr_debug("%s: called\n", __func__);
133 mutex_lock(&card->updown_lock);
134 if (atomic_inc_return(&card->users) == 1) {
135 pr_debug("%s: real do\n", __func__);
137 gelic_card_set_irq_mask(card, card->irq_mask);
139 gelic_card_enable_rxdmac(card);
141 napi_enable(&card->napi);
143 mutex_unlock(&card->updown_lock);
144 pr_debug("%s: done\n", __func__);
147 void gelic_card_down(struct gelic_card *card)
150 pr_debug("%s: called\n", __func__);
151 mutex_lock(&card->updown_lock);
152 if (atomic_dec_if_positive(&card->users) == 0) {
153 pr_debug("%s: real do\n", __func__);
154 napi_disable(&card->napi);
156 * Disable irq. Wireless interrupts will
157 * be disabled later if any
159 mask = card->irq_mask & (GELIC_CARD_WLAN_EVENT_RECEIVED |
160 GELIC_CARD_WLAN_COMMAND_COMPLETED);
161 gelic_card_set_irq_mask(card, mask);
163 gelic_card_disable_rxdmac(card);
164 gelic_card_reset_chain(card, &card->rx_chain,
165 card->descr + GELIC_NET_TX_DESCRIPTORS);
167 gelic_card_disable_txdmac(card);
169 mutex_unlock(&card->updown_lock);
170 pr_debug("%s: done\n", __func__);
174 * gelic_descr_get_status -- returns the status of a descriptor
175 * @descr: descriptor to look at
177 * returns the status as in the dmac_cmd_status field of the descriptor
179 static enum gelic_descr_dma_status
180 gelic_descr_get_status(struct gelic_descr *descr)
182 return be32_to_cpu(descr->dmac_cmd_status) & GELIC_DESCR_DMA_STAT_MASK;
186 * gelic_descr_set_status -- sets the status of a descriptor
187 * @descr: descriptor to change
188 * @status: status to set in the descriptor
190 * changes the status to the specified value. Doesn't change other bits
193 static void gelic_descr_set_status(struct gelic_descr *descr,
194 enum gelic_descr_dma_status status)
196 descr->dmac_cmd_status = cpu_to_be32(status |
197 (be32_to_cpu(descr->dmac_cmd_status) &
198 ~GELIC_DESCR_DMA_STAT_MASK));
200 * dma_cmd_status field is used to indicate whether the descriptor
202 * Usually caller of this function wants to inform that to the
203 * hardware, so we assure here the hardware sees the change.
209 * gelic_card_free_chain - free descriptor chain
210 * @card: card structure
211 * @descr_in: address of desc
213 static void gelic_card_free_chain(struct gelic_card *card,
214 struct gelic_descr *descr_in)
216 struct gelic_descr *descr;
218 for (descr = descr_in; descr && descr->bus_addr; descr = descr->next) {
219 dma_unmap_single(ctodev(card), descr->bus_addr,
220 GELIC_DESCR_SIZE, DMA_BIDIRECTIONAL);
226 * gelic_card_init_chain - links descriptor chain
227 * @card: card structure
228 * @chain: address of chain
229 * @start_descr: address of descriptor array
230 * @no: number of descriptors
232 * we manage a circular list that mirrors the hardware structure,
233 * except that the hardware uses bus addresses.
235 * returns 0 on success, <0 on failure
237 static int gelic_card_init_chain(struct gelic_card *card,
238 struct gelic_descr_chain *chain,
239 struct gelic_descr *start_descr, int no)
242 struct gelic_descr *descr;
245 memset(descr, 0, sizeof(*descr) * no);
247 /* set up the hardware pointers in each descriptor */
248 for (i = 0; i < no; i++, descr++) {
249 gelic_descr_set_status(descr, GELIC_DESCR_DMA_NOT_IN_USE);
251 dma_map_single(ctodev(card), descr,
255 if (!descr->bus_addr)
258 descr->next = descr + 1;
259 descr->prev = descr - 1;
261 /* make them as ring */
262 (descr - 1)->next = start_descr;
263 start_descr->prev = (descr - 1);
265 /* chain bus addr of hw descriptor */
267 for (i = 0; i < no; i++, descr++) {
268 descr->next_descr_addr = cpu_to_be32(descr->next->bus_addr);
271 chain->head = start_descr;
272 chain->tail = start_descr;
274 /* do not chain last hw descriptor */
275 (descr - 1)->next_descr_addr = 0;
280 for (i--, descr--; 0 <= i; i--, descr--)
282 dma_unmap_single(ctodev(card), descr->bus_addr,
289 * gelic_card_reset_chain - reset status of a descriptor chain
290 * @card: card structure
291 * @chain: address of chain
292 * @start_descr: address of descriptor array
294 * Reset the status of dma descriptors to ready state
295 * and re-initialize the hardware chain for later use
297 static void gelic_card_reset_chain(struct gelic_card *card,
298 struct gelic_descr_chain *chain,
299 struct gelic_descr *start_descr)
301 struct gelic_descr *descr;
303 for (descr = start_descr; start_descr != descr->next; descr++) {
304 gelic_descr_set_status(descr, GELIC_DESCR_DMA_CARDOWNED);
305 descr->next_descr_addr = cpu_to_be32(descr->next->bus_addr);
308 chain->head = start_descr;
309 chain->tail = (descr - 1);
311 (descr - 1)->next_descr_addr = 0;
314 * gelic_descr_prepare_rx - reinitializes a rx descriptor
315 * @card: card structure
316 * @descr: descriptor to re-init
318 * return 0 on success, <0 on failure
320 * allocates a new rx skb, iommu-maps it and attaches it to the descriptor.
321 * Activate the descriptor state-wise
323 static int gelic_descr_prepare_rx(struct gelic_card *card,
324 struct gelic_descr *descr)
327 unsigned int bufsize;
329 if (gelic_descr_get_status(descr) != GELIC_DESCR_DMA_NOT_IN_USE)
330 dev_info(ctodev(card), "%s: ERROR status\n", __func__);
331 /* we need to round up the buffer size to a multiple of 128 */
332 bufsize = ALIGN(GELIC_NET_MAX_MTU, GELIC_NET_RXBUF_ALIGN);
334 /* and we need to have it 128 byte aligned, therefore we allocate a
336 descr->skb = dev_alloc_skb(bufsize + GELIC_NET_RXBUF_ALIGN - 1);
338 descr->buf_addr = 0; /* tell DMAC don't touch memory */
339 dev_info(ctodev(card),
340 "%s:allocate skb failed !!\n", __func__);
343 descr->buf_size = cpu_to_be32(bufsize);
344 descr->dmac_cmd_status = 0;
345 descr->result_size = 0;
346 descr->valid_size = 0;
347 descr->data_error = 0;
349 offset = ((unsigned long)descr->skb->data) &
350 (GELIC_NET_RXBUF_ALIGN - 1);
352 skb_reserve(descr->skb, GELIC_NET_RXBUF_ALIGN - offset);
353 /* io-mmu-map the skb */
354 descr->buf_addr = cpu_to_be32(dma_map_single(ctodev(card),
358 if (!descr->buf_addr) {
359 dev_kfree_skb_any(descr->skb);
361 dev_info(ctodev(card),
362 "%s:Could not iommu-map rx buffer\n", __func__);
363 gelic_descr_set_status(descr, GELIC_DESCR_DMA_NOT_IN_USE);
366 gelic_descr_set_status(descr, GELIC_DESCR_DMA_CARDOWNED);
372 * gelic_card_release_rx_chain - free all skb of rx descr
373 * @card: card structure
376 static void gelic_card_release_rx_chain(struct gelic_card *card)
378 struct gelic_descr *descr = card->rx_chain.head;
382 dma_unmap_single(ctodev(card),
383 be32_to_cpu(descr->buf_addr),
387 dev_kfree_skb_any(descr->skb);
389 gelic_descr_set_status(descr,
390 GELIC_DESCR_DMA_NOT_IN_USE);
393 } while (descr != card->rx_chain.head);
397 * gelic_card_fill_rx_chain - fills descriptors/skbs in the rx chains
398 * @card: card structure
400 * fills all descriptors in the rx chain: allocates skbs
401 * and iommu-maps them.
402 * returns 0 on success, < 0 on failure
404 static int gelic_card_fill_rx_chain(struct gelic_card *card)
406 struct gelic_descr *descr = card->rx_chain.head;
411 ret = gelic_descr_prepare_rx(card, descr);
416 } while (descr != card->rx_chain.head);
420 gelic_card_release_rx_chain(card);
425 * gelic_card_alloc_rx_skbs - allocates rx skbs in rx descriptor chains
426 * @card: card structure
428 * returns 0 on success, < 0 on failure
430 static int gelic_card_alloc_rx_skbs(struct gelic_card *card)
432 struct gelic_descr_chain *chain;
434 chain = &card->rx_chain;
435 ret = gelic_card_fill_rx_chain(card);
436 chain->tail = card->rx_top->prev; /* point to the last */
441 * gelic_descr_release_tx - processes a used tx descriptor
442 * @card: card structure
443 * @descr: descriptor to release
445 * releases a used tx descriptor (unmapping, freeing of skb)
447 static void gelic_descr_release_tx(struct gelic_card *card,
448 struct gelic_descr *descr)
450 struct sk_buff *skb = descr->skb;
452 BUG_ON(!(be32_to_cpu(descr->data_status) & GELIC_DESCR_TX_TAIL));
454 dma_unmap_single(ctodev(card), be32_to_cpu(descr->buf_addr), skb->len,
456 dev_kfree_skb_any(skb);
460 descr->next_descr_addr = 0;
461 descr->result_size = 0;
462 descr->valid_size = 0;
463 descr->data_status = 0;
464 descr->data_error = 0;
467 /* set descr status */
468 gelic_descr_set_status(descr, GELIC_DESCR_DMA_NOT_IN_USE);
471 static void gelic_card_stop_queues(struct gelic_card *card)
473 netif_stop_queue(card->netdev[GELIC_PORT_ETHERNET_0]);
475 if (card->netdev[GELIC_PORT_WIRELESS])
476 netif_stop_queue(card->netdev[GELIC_PORT_WIRELESS]);
478 static void gelic_card_wake_queues(struct gelic_card *card)
480 netif_wake_queue(card->netdev[GELIC_PORT_ETHERNET_0]);
482 if (card->netdev[GELIC_PORT_WIRELESS])
483 netif_wake_queue(card->netdev[GELIC_PORT_WIRELESS]);
486 * gelic_card_release_tx_chain - processes sent tx descriptors
487 * @card: adapter structure
488 * @stop: net_stop sequence
490 * releases the tx descriptors that gelic has finished with
492 static void gelic_card_release_tx_chain(struct gelic_card *card, int stop)
494 struct gelic_descr_chain *tx_chain;
495 enum gelic_descr_dma_status status;
496 struct net_device *netdev;
499 for (tx_chain = &card->tx_chain;
500 tx_chain->head != tx_chain->tail && tx_chain->tail;
501 tx_chain->tail = tx_chain->tail->next) {
502 status = gelic_descr_get_status(tx_chain->tail);
503 netdev = tx_chain->tail->skb->dev;
505 case GELIC_DESCR_DMA_RESPONSE_ERROR:
506 case GELIC_DESCR_DMA_PROTECTION_ERROR:
507 case GELIC_DESCR_DMA_FORCE_END:
508 if (printk_ratelimit())
509 dev_info(ctodev(card),
510 "%s: forcing end of tx descriptor " \
513 netdev->stats.tx_dropped++;
516 case GELIC_DESCR_DMA_COMPLETE:
517 if (tx_chain->tail->skb) {
518 netdev->stats.tx_packets++;
519 netdev->stats.tx_bytes +=
520 tx_chain->tail->skb->len;
524 case GELIC_DESCR_DMA_CARDOWNED:
525 /* pending tx request */
527 /* any other value (== GELIC_DESCR_DMA_NOT_IN_USE) */
531 gelic_descr_release_tx(card, tx_chain->tail);
535 if (!stop && release)
536 gelic_card_wake_queues(card);
540 * gelic_net_set_multi - sets multicast addresses and promisc flags
541 * @netdev: interface device structure
543 * gelic_net_set_multi configures multicast addresses as needed for the
544 * netdev interface. It also sets up multicast, allmulti and promisc
545 * flags appropriately
547 void gelic_net_set_multi(struct net_device *netdev)
549 struct gelic_card *card = netdev_card(netdev);
550 struct netdev_hw_addr *ha;
556 /* clear all multicast address */
557 status = lv1_net_remove_multicast_address(bus_id(card), dev_id(card),
560 dev_err(ctodev(card),
561 "lv1_net_remove_multicast_address failed %d\n",
563 /* set broadcast address */
564 status = lv1_net_add_multicast_address(bus_id(card), dev_id(card),
565 GELIC_NET_BROADCAST_ADDR, 0);
567 dev_err(ctodev(card),
568 "lv1_net_add_multicast_address failed, %d\n",
571 if ((netdev->flags & IFF_ALLMULTI) ||
572 (netdev_mc_count(netdev) > GELIC_NET_MC_COUNT_MAX)) {
573 status = lv1_net_add_multicast_address(bus_id(card),
577 dev_err(ctodev(card),
578 "lv1_net_add_multicast_address failed, %d\n",
583 /* set multicast addresses */
584 netdev_for_each_mc_addr(ha, netdev) {
587 for (i = 0; i < ETH_ALEN; i++) {
591 status = lv1_net_add_multicast_address(bus_id(card),
595 dev_err(ctodev(card),
596 "lv1_net_add_multicast_address failed, %d\n",
602 * gelic_card_enable_rxdmac - enables the receive DMA controller
603 * @card: card structure
605 * gelic_card_enable_rxdmac enables the DMA controller by setting RX_DMA_EN
606 * in the GDADMACCNTR register
608 static inline void gelic_card_enable_rxdmac(struct gelic_card *card)
613 if (gelic_descr_get_status(card->rx_chain.head) !=
614 GELIC_DESCR_DMA_CARDOWNED) {
615 printk(KERN_ERR "%s: status=%x\n", __func__,
616 be32_to_cpu(card->rx_chain.head->dmac_cmd_status));
617 printk(KERN_ERR "%s: nextphy=%x\n", __func__,
618 be32_to_cpu(card->rx_chain.head->next_descr_addr));
619 printk(KERN_ERR "%s: head=%p\n", __func__,
620 card->rx_chain.head);
623 status = lv1_net_start_rx_dma(bus_id(card), dev_id(card),
624 card->rx_chain.head->bus_addr, 0);
626 dev_info(ctodev(card),
627 "lv1_net_start_rx_dma failed, status=%d\n", status);
631 * gelic_card_disable_rxdmac - disables the receive DMA controller
632 * @card: card structure
634 * gelic_card_disable_rxdmac terminates processing on the DMA controller by
635 * turing off DMA and issuing a force end
637 static inline void gelic_card_disable_rxdmac(struct gelic_card *card)
641 /* this hvc blocks until the DMA in progress really stopped */
642 status = lv1_net_stop_rx_dma(bus_id(card), dev_id(card));
644 dev_err(ctodev(card),
645 "lv1_net_stop_rx_dma failed, %d\n", status);
649 * gelic_card_disable_txdmac - disables the transmit DMA controller
650 * @card: card structure
652 * gelic_card_disable_txdmac terminates processing on the DMA controller by
653 * turing off DMA and issuing a force end
655 static inline void gelic_card_disable_txdmac(struct gelic_card *card)
659 /* this hvc blocks until the DMA in progress really stopped */
660 status = lv1_net_stop_tx_dma(bus_id(card), dev_id(card));
662 dev_err(ctodev(card),
663 "lv1_net_stop_tx_dma failed, status=%d\n", status);
667 * gelic_net_stop - called upon ifconfig down
668 * @netdev: interface device structure
672 int gelic_net_stop(struct net_device *netdev)
674 struct gelic_card *card;
676 pr_debug("%s: start\n", __func__);
678 netif_stop_queue(netdev);
679 netif_carrier_off(netdev);
681 card = netdev_card(netdev);
682 gelic_card_down(card);
684 pr_debug("%s: done\n", __func__);
689 * gelic_card_get_next_tx_descr - returns the next available tx descriptor
690 * @card: device structure to get descriptor from
692 * returns the address of the next descriptor, or NULL if not available.
694 static struct gelic_descr *
695 gelic_card_get_next_tx_descr(struct gelic_card *card)
697 if (!card->tx_chain.head)
699 /* see if the next descriptor is free */
700 if (card->tx_chain.tail != card->tx_chain.head->next &&
701 gelic_descr_get_status(card->tx_chain.head) ==
702 GELIC_DESCR_DMA_NOT_IN_USE)
703 return card->tx_chain.head;
710 * gelic_net_set_txdescr_cmdstat - sets the tx descriptor command field
711 * @descr: descriptor structure to fill out
712 * @skb: packet to consider
714 * fills out the command and status field of the descriptor structure,
715 * depending on hardware checksum settings. This function assumes a wmb()
716 * has executed before.
718 static void gelic_descr_set_tx_cmdstat(struct gelic_descr *descr,
721 if (skb->ip_summed != CHECKSUM_PARTIAL)
722 descr->dmac_cmd_status =
723 cpu_to_be32(GELIC_DESCR_DMA_CMD_NO_CHKSUM |
724 GELIC_DESCR_TX_DMA_FRAME_TAIL);
727 * if yes: tcp? udp? */
728 if (skb->protocol == htons(ETH_P_IP)) {
729 if (ip_hdr(skb)->protocol == IPPROTO_TCP)
730 descr->dmac_cmd_status =
731 cpu_to_be32(GELIC_DESCR_DMA_CMD_TCP_CHKSUM |
732 GELIC_DESCR_TX_DMA_FRAME_TAIL);
734 else if (ip_hdr(skb)->protocol == IPPROTO_UDP)
735 descr->dmac_cmd_status =
736 cpu_to_be32(GELIC_DESCR_DMA_CMD_UDP_CHKSUM |
737 GELIC_DESCR_TX_DMA_FRAME_TAIL);
739 * the stack should checksum non-tcp and non-udp
740 * packets on his own: NETIF_F_IP_CSUM
742 descr->dmac_cmd_status =
743 cpu_to_be32(GELIC_DESCR_DMA_CMD_NO_CHKSUM |
744 GELIC_DESCR_TX_DMA_FRAME_TAIL);
749 static inline struct sk_buff *gelic_put_vlan_tag(struct sk_buff *skb,
752 struct vlan_ethhdr *veth;
753 static unsigned int c;
755 if (skb_headroom(skb) < VLAN_HLEN) {
756 struct sk_buff *sk_tmp = skb;
757 pr_debug("%s: hd=%d c=%ud\n", __func__, skb_headroom(skb), c);
758 skb = skb_realloc_headroom(sk_tmp, VLAN_HLEN);
761 dev_kfree_skb_any(sk_tmp);
763 veth = (struct vlan_ethhdr *)skb_push(skb, VLAN_HLEN);
765 /* Move the mac addresses to the top of buffer */
766 memmove(skb->data, skb->data + VLAN_HLEN, 2 * ETH_ALEN);
768 veth->h_vlan_proto = cpu_to_be16(ETH_P_8021Q);
769 veth->h_vlan_TCI = htons(tag);
775 * gelic_descr_prepare_tx - setup a descriptor for sending packets
776 * @card: card structure
777 * @descr: descriptor structure
778 * @skb: packet to use
780 * returns 0 on success, <0 on failure.
783 static int gelic_descr_prepare_tx(struct gelic_card *card,
784 struct gelic_descr *descr,
789 if (card->vlan_required) {
790 struct sk_buff *skb_tmp;
791 enum gelic_port_type type;
793 type = netdev_port(skb->dev)->type;
794 skb_tmp = gelic_put_vlan_tag(skb,
795 card->vlan[type].tx);
801 buf = dma_map_single(ctodev(card), skb->data, skb->len, DMA_TO_DEVICE);
804 dev_err(ctodev(card),
805 "dma map 2 failed (%p, %i). Dropping packet\n",
806 skb->data, skb->len);
810 descr->buf_addr = cpu_to_be32(buf);
811 descr->buf_size = cpu_to_be32(skb->len);
813 descr->data_status = 0;
814 descr->next_descr_addr = 0; /* terminate hw descr */
815 gelic_descr_set_tx_cmdstat(descr, skb);
817 /* bump free descriptor pointer */
818 card->tx_chain.head = descr->next;
823 * gelic_card_kick_txdma - enables TX DMA processing
824 * @card: card structure
825 * @descr: descriptor address to enable TX processing at
828 static int gelic_card_kick_txdma(struct gelic_card *card,
829 struct gelic_descr *descr)
833 if (card->tx_dma_progress)
836 if (gelic_descr_get_status(descr) == GELIC_DESCR_DMA_CARDOWNED) {
837 card->tx_dma_progress = 1;
838 status = lv1_net_start_tx_dma(bus_id(card), dev_id(card),
841 card->tx_dma_progress = 0;
842 dev_info(ctodev(card), "lv1_net_start_txdma failed," \
843 "status=%d\n", status);
850 * gelic_net_xmit - transmits a frame over the device
851 * @skb: packet to send out
852 * @netdev: interface device structure
854 * returns 0 on success, <0 on failure
856 int gelic_net_xmit(struct sk_buff *skb, struct net_device *netdev)
858 struct gelic_card *card = netdev_card(netdev);
859 struct gelic_descr *descr;
863 spin_lock_irqsave(&card->tx_lock, flags);
865 gelic_card_release_tx_chain(card, 0);
867 descr = gelic_card_get_next_tx_descr(card);
870 * no more descriptors free
872 gelic_card_stop_queues(card);
873 spin_unlock_irqrestore(&card->tx_lock, flags);
874 return NETDEV_TX_BUSY;
877 result = gelic_descr_prepare_tx(card, descr, skb);
880 * DMA map failed. As chances are that failure
881 * would continue, just release skb and return
883 netdev->stats.tx_dropped++;
884 dev_kfree_skb_any(skb);
885 spin_unlock_irqrestore(&card->tx_lock, flags);
889 * link this prepared descriptor to previous one
890 * to achieve high performance
892 descr->prev->next_descr_addr = cpu_to_be32(descr->bus_addr);
894 * as hardware descriptor is modified in the above lines,
895 * ensure that the hardware sees it
898 if (gelic_card_kick_txdma(card, descr)) {
901 * release descriptor which was just prepared
903 netdev->stats.tx_dropped++;
904 /* don't trigger BUG_ON() in gelic_descr_release_tx */
905 descr->data_status = cpu_to_be32(GELIC_DESCR_TX_TAIL);
906 gelic_descr_release_tx(card, descr);
908 card->tx_chain.head = descr;
909 /* reset hw termination */
910 descr->prev->next_descr_addr = 0;
911 dev_info(ctodev(card), "%s: kick failure\n", __func__);
914 spin_unlock_irqrestore(&card->tx_lock, flags);
919 * gelic_net_pass_skb_up - takes an skb from a descriptor and passes it on
920 * @descr: descriptor to process
921 * @card: card structure
922 * @netdev: net_device structure to be passed packet
924 * iommu-unmaps the skb, fills out skb structure and passes the data to the
925 * stack. The descriptor state is not changed.
927 static void gelic_net_pass_skb_up(struct gelic_descr *descr,
928 struct gelic_card *card,
929 struct net_device *netdev)
932 struct sk_buff *skb = descr->skb;
933 u32 data_status, data_error;
935 data_status = be32_to_cpu(descr->data_status);
936 data_error = be32_to_cpu(descr->data_error);
937 /* unmap skb buffer */
938 dma_unmap_single(ctodev(card), be32_to_cpu(descr->buf_addr),
942 skb_put(skb, be32_to_cpu(descr->valid_size)?
943 be32_to_cpu(descr->valid_size) :
944 be32_to_cpu(descr->result_size));
945 if (!descr->valid_size)
946 dev_info(ctodev(card), "buffer full %x %x %x\n",
947 be32_to_cpu(descr->result_size),
948 be32_to_cpu(descr->buf_size),
949 be32_to_cpu(descr->dmac_cmd_status));
953 * the card put 2 bytes vlan tag in front
954 * of the ethernet frame
957 skb->protocol = eth_type_trans(skb, netdev);
959 /* checksum offload */
960 if (netdev->features & NETIF_F_RXCSUM) {
961 if ((data_status & GELIC_DESCR_DATA_STATUS_CHK_MASK) &&
962 (!(data_error & GELIC_DESCR_DATA_ERROR_CHK_MASK)))
963 skb->ip_summed = CHECKSUM_UNNECESSARY;
965 skb_checksum_none_assert(skb);
967 skb_checksum_none_assert(skb);
969 /* update netdevice statistics */
970 netdev->stats.rx_packets++;
971 netdev->stats.rx_bytes += skb->len;
973 /* pass skb up to stack */
974 netif_receive_skb(skb);
978 * gelic_card_decode_one_descr - processes an rx descriptor
979 * @card: card structure
981 * returns 1 if a packet has been sent to the stack, otherwise 0
983 * processes an rx descriptor by iommu-unmapping the data buffer and passing
984 * the packet up to the stack
986 static int gelic_card_decode_one_descr(struct gelic_card *card)
988 enum gelic_descr_dma_status status;
989 struct gelic_descr_chain *chain = &card->rx_chain;
990 struct gelic_descr *descr = chain->head;
991 struct net_device *netdev = NULL;
992 int dmac_chain_ended;
994 status = gelic_descr_get_status(descr);
996 if (status == GELIC_DESCR_DMA_CARDOWNED)
999 if (status == GELIC_DESCR_DMA_NOT_IN_USE) {
1000 dev_dbg(ctodev(card), "dormant descr? %p\n", descr);
1004 /* netdevice select */
1005 if (card->vlan_required) {
1008 vid = *(u16 *)(descr->skb->data) & VLAN_VID_MASK;
1009 for (i = 0; i < GELIC_PORT_MAX; i++) {
1010 if (card->vlan[i].rx == vid) {
1011 netdev = card->netdev[i];
1015 if (GELIC_PORT_MAX <= i) {
1016 pr_info("%s: unknown packet vid=%x\n", __func__, vid);
1020 netdev = card->netdev[GELIC_PORT_ETHERNET_0];
1022 if ((status == GELIC_DESCR_DMA_RESPONSE_ERROR) ||
1023 (status == GELIC_DESCR_DMA_PROTECTION_ERROR) ||
1024 (status == GELIC_DESCR_DMA_FORCE_END)) {
1025 dev_info(ctodev(card), "dropping RX descriptor with state %x\n",
1027 netdev->stats.rx_dropped++;
1031 if (status == GELIC_DESCR_DMA_BUFFER_FULL) {
1033 * Buffer full would occur if and only if
1034 * the frame length was longer than the size of this
1035 * descriptor's buffer. If the frame length was equal
1036 * to or shorter than buffer'size, FRAME_END condition
1038 * Anyway this frame was longer than the MTU,
1041 dev_info(ctodev(card), "overlength frame\n");
1045 * descriptors any other than FRAME_END here should
1046 * be treated as error.
1048 if (status != GELIC_DESCR_DMA_FRAME_END) {
1049 dev_dbg(ctodev(card), "RX descriptor with state %x\n",
1054 /* ok, we've got a packet in descr */
1055 gelic_net_pass_skb_up(descr, card, netdev);
1058 /* is the current descriptor terminated with next_descr == NULL? */
1060 be32_to_cpu(descr->dmac_cmd_status) &
1061 GELIC_DESCR_RX_DMA_CHAIN_END;
1063 * So that always DMAC can see the end
1064 * of the descriptor chain to avoid
1065 * from unwanted DMAC overrun.
1067 descr->next_descr_addr = 0;
1069 /* change the descriptor state: */
1070 gelic_descr_set_status(descr, GELIC_DESCR_DMA_NOT_IN_USE);
1073 * this call can fail, but for now, just leave this
1074 * decriptor without skb
1076 gelic_descr_prepare_rx(card, descr);
1078 chain->tail = descr;
1079 chain->head = descr->next;
1082 * Set this descriptor the end of the chain.
1084 descr->prev->next_descr_addr = cpu_to_be32(descr->bus_addr);
1087 * If dmac chain was met, DMAC stopped.
1091 if (dmac_chain_ended)
1092 gelic_card_enable_rxdmac(card);
1098 * gelic_net_poll - NAPI poll function called by the stack to return packets
1099 * @napi: napi structure
1100 * @budget: number of packets we can pass to the stack at most
1102 * returns the number of the processed packets
1105 static int gelic_net_poll(struct napi_struct *napi, int budget)
1107 struct gelic_card *card = container_of(napi, struct gelic_card, napi);
1108 int packets_done = 0;
1110 while (packets_done < budget) {
1111 if (!gelic_card_decode_one_descr(card))
1117 if (packets_done < budget) {
1118 napi_complete(napi);
1119 gelic_card_rx_irq_on(card);
1121 return packets_done;
1124 * gelic_net_change_mtu - changes the MTU of an interface
1125 * @netdev: interface device structure
1126 * @new_mtu: new MTU value
1128 * returns 0 on success, <0 on failure
1130 int gelic_net_change_mtu(struct net_device *netdev, int new_mtu)
1132 /* no need to re-alloc skbs or so -- the max mtu is about 2.3k
1133 * and mtu is outbound only anyway */
1134 if ((new_mtu < GELIC_NET_MIN_MTU) ||
1135 (new_mtu > GELIC_NET_MAX_MTU)) {
1138 netdev->mtu = new_mtu;
1143 * gelic_card_interrupt - event handler for gelic_net
1145 static irqreturn_t gelic_card_interrupt(int irq, void *ptr)
1147 unsigned long flags;
1148 struct gelic_card *card = ptr;
1151 status = card->irq_status;
1156 status &= card->irq_mask;
1158 if (status & GELIC_CARD_RXINT) {
1159 gelic_card_rx_irq_off(card);
1160 napi_schedule(&card->napi);
1163 if (status & GELIC_CARD_TXINT) {
1164 spin_lock_irqsave(&card->tx_lock, flags);
1165 card->tx_dma_progress = 0;
1166 gelic_card_release_tx_chain(card, 0);
1167 /* kick outstanding tx descriptor if any */
1168 gelic_card_kick_txdma(card, card->tx_chain.tail);
1169 spin_unlock_irqrestore(&card->tx_lock, flags);
1172 /* ether port status changed */
1173 if (status & GELIC_CARD_PORT_STATUS_CHANGED)
1174 gelic_card_get_ether_port_status(card, 1);
1176 #ifdef CONFIG_GELIC_WIRELESS
1177 if (status & (GELIC_CARD_WLAN_EVENT_RECEIVED |
1178 GELIC_CARD_WLAN_COMMAND_COMPLETED))
1179 gelic_wl_interrupt(card->netdev[GELIC_PORT_WIRELESS], status);
1185 #ifdef CONFIG_NET_POLL_CONTROLLER
1187 * gelic_net_poll_controller - artificial interrupt for netconsole etc.
1188 * @netdev: interface device structure
1190 * see Documentation/networking/netconsole.txt
1192 void gelic_net_poll_controller(struct net_device *netdev)
1194 struct gelic_card *card = netdev_card(netdev);
1196 gelic_card_set_irq_mask(card, 0);
1197 gelic_card_interrupt(netdev->irq, netdev);
1198 gelic_card_set_irq_mask(card, card->irq_mask);
1200 #endif /* CONFIG_NET_POLL_CONTROLLER */
1203 * gelic_net_open - called upon ifconfig up
1204 * @netdev: interface device structure
1206 * returns 0 on success, <0 on failure
1208 * gelic_net_open allocates all the descriptors and memory needed for
1209 * operation, sets up multicast list and enables interrupts
1211 int gelic_net_open(struct net_device *netdev)
1213 struct gelic_card *card = netdev_card(netdev);
1215 dev_dbg(ctodev(card), " -> %s %p\n", __func__, netdev);
1217 gelic_card_up(card);
1219 netif_start_queue(netdev);
1220 gelic_card_get_ether_port_status(card, 1);
1222 dev_dbg(ctodev(card), " <- %s\n", __func__);
1226 void gelic_net_get_drvinfo(struct net_device *netdev,
1227 struct ethtool_drvinfo *info)
1229 strlcpy(info->driver, DRV_NAME, sizeof(info->driver));
1230 strlcpy(info->version, DRV_VERSION, sizeof(info->version));
1233 static int gelic_ether_get_settings(struct net_device *netdev,
1234 struct ethtool_cmd *cmd)
1236 struct gelic_card *card = netdev_card(netdev);
1238 gelic_card_get_ether_port_status(card, 0);
1240 if (card->ether_port_status & GELIC_LV1_ETHER_FULL_DUPLEX)
1241 cmd->duplex = DUPLEX_FULL;
1243 cmd->duplex = DUPLEX_HALF;
1245 switch (card->ether_port_status & GELIC_LV1_ETHER_SPEED_MASK) {
1246 case GELIC_LV1_ETHER_SPEED_10:
1247 ethtool_cmd_speed_set(cmd, SPEED_10);
1249 case GELIC_LV1_ETHER_SPEED_100:
1250 ethtool_cmd_speed_set(cmd, SPEED_100);
1252 case GELIC_LV1_ETHER_SPEED_1000:
1253 ethtool_cmd_speed_set(cmd, SPEED_1000);
1256 pr_info("%s: speed unknown\n", __func__);
1257 ethtool_cmd_speed_set(cmd, SPEED_10);
1261 cmd->supported = SUPPORTED_TP | SUPPORTED_Autoneg |
1262 SUPPORTED_10baseT_Half | SUPPORTED_10baseT_Full |
1263 SUPPORTED_100baseT_Half | SUPPORTED_100baseT_Full |
1264 SUPPORTED_1000baseT_Full;
1265 cmd->advertising = cmd->supported;
1266 if (card->link_mode & GELIC_LV1_ETHER_AUTO_NEG) {
1267 cmd->autoneg = AUTONEG_ENABLE;
1269 cmd->autoneg = AUTONEG_DISABLE;
1270 cmd->advertising &= ~ADVERTISED_Autoneg;
1272 cmd->port = PORT_TP;
1277 static int gelic_ether_set_settings(struct net_device *netdev,
1278 struct ethtool_cmd *cmd)
1280 struct gelic_card *card = netdev_card(netdev);
1284 if (cmd->autoneg == AUTONEG_ENABLE) {
1285 mode = GELIC_LV1_ETHER_AUTO_NEG;
1287 switch (cmd->speed) {
1289 mode = GELIC_LV1_ETHER_SPEED_10;
1292 mode = GELIC_LV1_ETHER_SPEED_100;
1295 mode = GELIC_LV1_ETHER_SPEED_1000;
1300 if (cmd->duplex == DUPLEX_FULL)
1301 mode |= GELIC_LV1_ETHER_FULL_DUPLEX;
1302 else if (cmd->speed == SPEED_1000) {
1303 pr_info("1000 half duplex is not supported.\n");
1308 ret = gelic_card_set_link_mode(card, mode);
1316 static void gelic_net_get_wol(struct net_device *netdev,
1317 struct ethtool_wolinfo *wol)
1319 if (0 <= ps3_compare_firmware_version(2, 2, 0))
1320 wol->supported = WAKE_MAGIC;
1324 wol->wolopts = ps3_sys_manager_get_wol() ? wol->supported : 0;
1325 memset(&wol->sopass, 0, sizeof(wol->sopass));
1327 static int gelic_net_set_wol(struct net_device *netdev,
1328 struct ethtool_wolinfo *wol)
1331 struct gelic_card *card;
1334 if (ps3_compare_firmware_version(2, 2, 0) < 0 ||
1335 !capable(CAP_NET_ADMIN))
1338 if (wol->wolopts & ~WAKE_MAGIC)
1341 card = netdev_card(netdev);
1342 if (wol->wolopts & WAKE_MAGIC) {
1343 status = lv1_net_control(bus_id(card), dev_id(card),
1345 GELIC_LV1_WOL_MAGIC_PACKET,
1346 0, GELIC_LV1_WOL_MP_ENABLE,
1349 pr_info("%s: enabling WOL failed %d\n", __func__,
1354 status = lv1_net_control(bus_id(card), dev_id(card),
1356 GELIC_LV1_WOL_ADD_MATCH_ADDR,
1357 0, GELIC_LV1_WOL_MATCH_ALL,
1360 ps3_sys_manager_set_wol(1);
1362 pr_info("%s: enabling WOL filter failed %d\n",
1367 status = lv1_net_control(bus_id(card), dev_id(card),
1369 GELIC_LV1_WOL_MAGIC_PACKET,
1370 0, GELIC_LV1_WOL_MP_DISABLE,
1373 pr_info("%s: disabling WOL failed %d\n", __func__,
1378 status = lv1_net_control(bus_id(card), dev_id(card),
1380 GELIC_LV1_WOL_DELETE_MATCH_ADDR,
1381 0, GELIC_LV1_WOL_MATCH_ALL,
1384 ps3_sys_manager_set_wol(0);
1386 pr_info("%s: removing WOL filter failed %d\n",
1395 static const struct ethtool_ops gelic_ether_ethtool_ops = {
1396 .get_drvinfo = gelic_net_get_drvinfo,
1397 .get_settings = gelic_ether_get_settings,
1398 .set_settings = gelic_ether_set_settings,
1399 .get_link = ethtool_op_get_link,
1400 .get_wol = gelic_net_get_wol,
1401 .set_wol = gelic_net_set_wol,
1405 * gelic_net_tx_timeout_task - task scheduled by the watchdog timeout
1406 * function (to be called not under interrupt status)
1407 * @work: work is context of tx timout task
1409 * called as task when tx hangs, resets interface (if interface is up)
1411 static void gelic_net_tx_timeout_task(struct work_struct *work)
1413 struct gelic_card *card =
1414 container_of(work, struct gelic_card, tx_timeout_task);
1415 struct net_device *netdev = card->netdev[GELIC_PORT_ETHERNET_0];
1417 dev_info(ctodev(card), "%s:Timed out. Restarting...\n", __func__);
1419 if (!(netdev->flags & IFF_UP))
1422 netif_device_detach(netdev);
1423 gelic_net_stop(netdev);
1425 gelic_net_open(netdev);
1426 netif_device_attach(netdev);
1429 atomic_dec(&card->tx_timeout_task_counter);
1433 * gelic_net_tx_timeout - called when the tx timeout watchdog kicks in.
1434 * @netdev: interface device structure
1436 * called, if tx hangs. Schedules a task that resets the interface
1438 void gelic_net_tx_timeout(struct net_device *netdev)
1440 struct gelic_card *card;
1442 card = netdev_card(netdev);
1443 atomic_inc(&card->tx_timeout_task_counter);
1444 if (netdev->flags & IFF_UP)
1445 schedule_work(&card->tx_timeout_task);
1447 atomic_dec(&card->tx_timeout_task_counter);
1450 static const struct net_device_ops gelic_netdevice_ops = {
1451 .ndo_open = gelic_net_open,
1452 .ndo_stop = gelic_net_stop,
1453 .ndo_start_xmit = gelic_net_xmit,
1454 .ndo_set_rx_mode = gelic_net_set_multi,
1455 .ndo_change_mtu = gelic_net_change_mtu,
1456 .ndo_tx_timeout = gelic_net_tx_timeout,
1457 .ndo_set_mac_address = eth_mac_addr,
1458 .ndo_validate_addr = eth_validate_addr,
1459 #ifdef CONFIG_NET_POLL_CONTROLLER
1460 .ndo_poll_controller = gelic_net_poll_controller,
1465 * gelic_ether_setup_netdev_ops - initialization of net_device operations
1466 * @netdev: net_device structure
1468 * fills out function pointers in the net_device structure
1470 static void gelic_ether_setup_netdev_ops(struct net_device *netdev,
1471 struct napi_struct *napi)
1473 netdev->watchdog_timeo = GELIC_NET_WATCHDOG_TIMEOUT;
1475 netif_napi_add(netdev, napi,
1476 gelic_net_poll, GELIC_NET_NAPI_WEIGHT);
1477 netdev->ethtool_ops = &gelic_ether_ethtool_ops;
1478 netdev->netdev_ops = &gelic_netdevice_ops;
1482 * gelic_ether_setup_netdev - initialization of net_device
1483 * @netdev: net_device structure
1484 * @card: card structure
1486 * Returns 0 on success or <0 on failure
1488 * gelic_ether_setup_netdev initializes the net_device structure
1491 int gelic_net_setup_netdev(struct net_device *netdev, struct gelic_card *card)
1496 netdev->hw_features = NETIF_F_IP_CSUM | NETIF_F_RXCSUM;
1498 netdev->features = NETIF_F_IP_CSUM;
1499 if (GELIC_CARD_RX_CSUM_DEFAULT)
1500 netdev->features |= NETIF_F_RXCSUM;
1502 status = lv1_net_control(bus_id(card), dev_id(card),
1503 GELIC_LV1_GET_MAC_ADDRESS,
1506 if (status || !is_valid_ether_addr((u8 *)&v1)) {
1507 dev_info(ctodev(card),
1508 "%s:lv1_net_control GET_MAC_ADDR failed %d\n",
1512 memcpy(netdev->dev_addr, &v1, ETH_ALEN);
1514 if (card->vlan_required) {
1515 netdev->hard_header_len += VLAN_HLEN;
1517 * As vlan is internally used,
1518 * we can not receive vlan packets
1520 netdev->features |= NETIF_F_VLAN_CHALLENGED;
1523 status = register_netdev(netdev);
1525 dev_err(ctodev(card), "%s:Couldn't register %s %d\n",
1526 __func__, netdev->name, status);
1529 dev_info(ctodev(card), "%s: MAC addr %pM\n",
1530 netdev->name, netdev->dev_addr);
1536 * gelic_alloc_card_net - allocates net_device and card structure
1538 * returns the card structure or NULL in case of errors
1540 * the card and net_device structures are linked to each other
1542 #define GELIC_ALIGN (32)
1543 static struct gelic_card *gelic_alloc_card_net(struct net_device **netdev)
1545 struct gelic_card *card;
1546 struct gelic_port *port;
1550 * gelic requires dma descriptor is 32 bytes aligned and
1551 * the hypervisor requires irq_status is 8 bytes aligned.
1553 BUILD_BUG_ON(offsetof(struct gelic_card, irq_status) % 8);
1554 BUILD_BUG_ON(offsetof(struct gelic_card, descr) % 32);
1556 sizeof(struct gelic_card) +
1557 sizeof(struct gelic_descr) * GELIC_NET_RX_DESCRIPTORS +
1558 sizeof(struct gelic_descr) * GELIC_NET_TX_DESCRIPTORS +
1561 p = kzalloc(alloc_size, GFP_KERNEL);
1564 card = PTR_ALIGN(p, GELIC_ALIGN);
1570 *netdev = alloc_etherdev(sizeof(struct gelic_port));
1572 kfree(card->unalign);
1575 port = netdev_priv(*netdev);
1578 port->netdev = *netdev;
1580 port->type = GELIC_PORT_ETHERNET_0;
1583 card->netdev[GELIC_PORT_ETHERNET_0] = *netdev;
1585 INIT_WORK(&card->tx_timeout_task, gelic_net_tx_timeout_task);
1586 init_waitqueue_head(&card->waitq);
1587 atomic_set(&card->tx_timeout_task_counter, 0);
1588 mutex_init(&card->updown_lock);
1589 atomic_set(&card->users, 0);
1594 static void gelic_card_get_vlan_info(struct gelic_card *card)
1603 [GELIC_PORT_ETHERNET_0] = {
1604 .tx = GELIC_LV1_VLAN_TX_ETHERNET_0,
1605 .rx = GELIC_LV1_VLAN_RX_ETHERNET_0
1607 [GELIC_PORT_WIRELESS] = {
1608 .tx = GELIC_LV1_VLAN_TX_WIRELESS,
1609 .rx = GELIC_LV1_VLAN_RX_WIRELESS
1613 for (i = 0; i < ARRAY_SIZE(vlan_id_ix); i++) {
1615 status = lv1_net_control(bus_id(card), dev_id(card),
1616 GELIC_LV1_GET_VLAN_ID,
1619 if (status || !v1) {
1620 if (status != LV1_NO_ENTRY)
1621 dev_dbg(ctodev(card),
1622 "get vlan id for tx(%d) failed(%d)\n",
1623 vlan_id_ix[i].tx, status);
1624 card->vlan[i].tx = 0;
1625 card->vlan[i].rx = 0;
1628 card->vlan[i].tx = (u16)v1;
1631 status = lv1_net_control(bus_id(card), dev_id(card),
1632 GELIC_LV1_GET_VLAN_ID,
1635 if (status || !v1) {
1636 if (status != LV1_NO_ENTRY)
1637 dev_info(ctodev(card),
1638 "get vlan id for rx(%d) failed(%d)\n",
1639 vlan_id_ix[i].rx, status);
1640 card->vlan[i].tx = 0;
1641 card->vlan[i].rx = 0;
1644 card->vlan[i].rx = (u16)v1;
1646 dev_dbg(ctodev(card), "vlan_id[%d] tx=%02x rx=%02x\n",
1647 i, card->vlan[i].tx, card->vlan[i].rx);
1650 if (card->vlan[GELIC_PORT_ETHERNET_0].tx) {
1651 BUG_ON(!card->vlan[GELIC_PORT_WIRELESS].tx);
1652 card->vlan_required = 1;
1654 card->vlan_required = 0;
1656 /* check wirelss capable firmware */
1657 if (ps3_compare_firmware_version(1, 6, 0) < 0) {
1658 card->vlan[GELIC_PORT_WIRELESS].tx = 0;
1659 card->vlan[GELIC_PORT_WIRELESS].rx = 0;
1662 dev_info(ctodev(card), "internal vlan %s\n",
1663 card->vlan_required? "enabled" : "disabled");
1666 * ps3_gelic_driver_probe - add a device to the control of this driver
1668 static int ps3_gelic_driver_probe(struct ps3_system_bus_device *dev)
1670 struct gelic_card *card;
1671 struct net_device *netdev;
1674 pr_debug("%s: called\n", __func__);
1676 udbg_shutdown_ps3gelic();
1678 result = ps3_open_hv_device(dev);
1681 dev_dbg(&dev->core, "%s:ps3_open_hv_device failed\n",
1686 result = ps3_dma_region_create(dev->d_region);
1689 dev_dbg(&dev->core, "%s:ps3_dma_region_create failed(%d)\n",
1691 BUG_ON("check region type");
1692 goto fail_dma_region;
1695 /* alloc card/netdevice */
1696 card = gelic_alloc_card_net(&netdev);
1698 dev_info(&dev->core, "%s:gelic_net_alloc_card failed\n",
1701 goto fail_alloc_card;
1703 ps3_system_bus_set_drvdata(dev, card);
1706 /* get internal vlan info */
1707 gelic_card_get_vlan_info(card);
1709 card->link_mode = GELIC_LV1_ETHER_AUTO_NEG;
1711 /* setup interrupt */
1712 result = lv1_net_set_interrupt_status_indicator(bus_id(card),
1714 ps3_mm_phys_to_lpar(__pa(&card->irq_status)),
1719 "%s:set_interrupt_status_indicator failed: %s\n",
1720 __func__, ps3_result(result));
1722 goto fail_status_indicator;
1725 result = ps3_sb_event_receive_port_setup(dev, PS3_BINDING_CPU_ANY,
1729 dev_info(ctodev(card),
1730 "%s:gelic_net_open_device failed (%d)\n",
1733 goto fail_alloc_irq;
1735 result = request_irq(card->irq, gelic_card_interrupt,
1736 IRQF_DISABLED, netdev->name, card);
1739 dev_info(ctodev(card), "%s:request_irq failed (%d)\n",
1741 goto fail_request_irq;
1744 /* setup card structure */
1745 card->irq_mask = GELIC_CARD_RXINT | GELIC_CARD_TXINT |
1746 GELIC_CARD_PORT_STATUS_CHANGED;
1749 if (gelic_card_init_chain(card, &card->tx_chain,
1750 card->descr, GELIC_NET_TX_DESCRIPTORS))
1752 if (gelic_card_init_chain(card, &card->rx_chain,
1753 card->descr + GELIC_NET_TX_DESCRIPTORS,
1754 GELIC_NET_RX_DESCRIPTORS))
1758 card->tx_top = card->tx_chain.head;
1759 card->rx_top = card->rx_chain.head;
1760 dev_dbg(ctodev(card), "descr rx %p, tx %p, size %#lx, num %#x\n",
1761 card->rx_top, card->tx_top, sizeof(struct gelic_descr),
1762 GELIC_NET_RX_DESCRIPTORS);
1763 /* allocate rx skbs */
1764 if (gelic_card_alloc_rx_skbs(card))
1765 goto fail_alloc_skbs;
1767 spin_lock_init(&card->tx_lock);
1768 card->tx_dma_progress = 0;
1770 /* setup net_device structure */
1771 netdev->irq = card->irq;
1772 SET_NETDEV_DEV(netdev, &card->dev->core);
1773 gelic_ether_setup_netdev_ops(netdev, &card->napi);
1774 result = gelic_net_setup_netdev(netdev, card);
1776 dev_dbg(&dev->core, "%s: setup_netdev failed %d",
1778 goto fail_setup_netdev;
1781 #ifdef CONFIG_GELIC_WIRELESS
1782 if (gelic_wl_driver_probe(card)) {
1783 dev_dbg(&dev->core, "%s: WL init failed\n", __func__);
1784 goto fail_setup_netdev;
1787 pr_debug("%s: done\n", __func__);
1792 gelic_card_free_chain(card, card->rx_chain.head);
1794 gelic_card_free_chain(card, card->tx_chain.head);
1796 free_irq(card->irq, card);
1797 netdev->irq = NO_IRQ;
1799 ps3_sb_event_receive_port_destroy(dev, card->irq);
1801 lv1_net_set_interrupt_status_indicator(bus_id(card),
1804 fail_status_indicator:
1805 ps3_system_bus_set_drvdata(dev, NULL);
1806 kfree(netdev_card(netdev)->unalign);
1807 free_netdev(netdev);
1809 ps3_dma_region_free(dev->d_region);
1811 ps3_close_hv_device(dev);
1817 * ps3_gelic_driver_remove - remove a device from the control of this driver
1820 static int ps3_gelic_driver_remove(struct ps3_system_bus_device *dev)
1822 struct gelic_card *card = ps3_system_bus_get_drvdata(dev);
1823 struct net_device *netdev0;
1824 pr_debug("%s: called\n", __func__);
1826 /* set auto-negotiation */
1827 gelic_card_set_link_mode(card, GELIC_LV1_ETHER_AUTO_NEG);
1829 #ifdef CONFIG_GELIC_WIRELESS
1830 gelic_wl_driver_remove(card);
1832 /* stop interrupt */
1833 gelic_card_set_irq_mask(card, 0);
1835 /* turn off DMA, force end */
1836 gelic_card_disable_rxdmac(card);
1837 gelic_card_disable_txdmac(card);
1839 /* release chains */
1840 gelic_card_release_tx_chain(card, 1);
1841 gelic_card_release_rx_chain(card);
1843 gelic_card_free_chain(card, card->tx_top);
1844 gelic_card_free_chain(card, card->rx_top);
1846 netdev0 = card->netdev[GELIC_PORT_ETHERNET_0];
1847 /* disconnect event port */
1848 free_irq(card->irq, card);
1849 netdev0->irq = NO_IRQ;
1850 ps3_sb_event_receive_port_destroy(card->dev, card->irq);
1852 wait_event(card->waitq,
1853 atomic_read(&card->tx_timeout_task_counter) == 0);
1855 lv1_net_set_interrupt_status_indicator(bus_id(card), dev_id(card),
1858 unregister_netdev(netdev0);
1859 kfree(netdev_card(netdev0)->unalign);
1860 free_netdev(netdev0);
1862 ps3_system_bus_set_drvdata(dev, NULL);
1864 ps3_dma_region_free(dev->d_region);
1866 ps3_close_hv_device(dev);
1868 pr_debug("%s: done\n", __func__);
1872 static struct ps3_system_bus_driver ps3_gelic_driver = {
1873 .match_id = PS3_MATCH_ID_GELIC,
1874 .probe = ps3_gelic_driver_probe,
1875 .remove = ps3_gelic_driver_remove,
1876 .shutdown = ps3_gelic_driver_remove,
1877 .core.name = "ps3_gelic_driver",
1878 .core.owner = THIS_MODULE,
1881 static int __init ps3_gelic_driver_init (void)
1883 return firmware_has_feature(FW_FEATURE_PS3_LV1)
1884 ? ps3_system_bus_driver_register(&ps3_gelic_driver)
1888 static void __exit ps3_gelic_driver_exit (void)
1890 ps3_system_bus_driver_unregister(&ps3_gelic_driver);
1893 module_init(ps3_gelic_driver_init);
1894 module_exit(ps3_gelic_driver_exit);
1896 MODULE_ALIAS(PS3_MODULE_ALIAS_GELIC);