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/kernel.h>
32 #include <linux/module.h>
34 #include <linux/etherdevice.h>
35 #include <linux/ethtool.h>
36 #include <linux/if_vlan.h>
40 #include <linux/tcp.h>
42 #include <linux/dma-mapping.h>
43 #include <net/checksum.h>
44 #include <asm/firmware.h>
46 #include <asm/lv1call.h>
48 #include "ps3_gelic_net.h"
50 #define DRV_NAME "Gelic Network Driver"
51 #define DRV_VERSION "1.1"
53 MODULE_AUTHOR("SCE Inc.");
54 MODULE_DESCRIPTION("Gelic Network driver");
55 MODULE_LICENSE("GPL");
58 static inline void gelic_card_enable_rxdmac(struct gelic_card *card);
59 static inline void gelic_card_disable_rxdmac(struct gelic_card *card);
60 static inline void gelic_card_disable_txdmac(struct gelic_card *card);
61 static inline void gelic_card_reset_chain(struct gelic_card *card,
62 struct gelic_descr_chain *chain,
63 struct gelic_descr *start_descr);
66 int gelic_card_set_irq_mask(struct gelic_card *card, u64 mask)
70 status = lv1_net_set_interrupt_mask(bus_id(card), dev_id(card),
73 dev_info(ctodev(card),
74 "%s failed %d\n", __func__, status);
78 static inline void gelic_card_rx_irq_on(struct gelic_card *card)
80 card->irq_mask |= GELIC_CARD_RXINT;
81 gelic_card_set_irq_mask(card, card->irq_mask);
83 static inline void gelic_card_rx_irq_off(struct gelic_card *card)
85 card->irq_mask &= ~GELIC_CARD_RXINT;
86 gelic_card_set_irq_mask(card, card->irq_mask);
89 static void gelic_card_get_ether_port_status(struct gelic_card *card,
93 struct net_device *ether_netdev;
95 lv1_net_control(bus_id(card), dev_id(card),
96 GELIC_LV1_GET_ETH_PORT_STATUS,
97 GELIC_LV1_VLAN_TX_ETHERNET, 0, 0,
98 &card->ether_port_status, &v2);
101 ether_netdev = card->netdev[GELIC_PORT_ETHERNET];
102 if (card->ether_port_status & GELIC_LV1_ETHER_LINK_UP)
103 netif_carrier_on(ether_netdev);
105 netif_carrier_off(ether_netdev);
109 void gelic_card_up(struct gelic_card *card)
111 pr_debug("%s: called\n", __func__);
112 down(&card->updown_lock);
113 if (atomic_inc_return(&card->users) == 1) {
114 pr_debug("%s: real do\n", __func__);
116 gelic_card_set_irq_mask(card, card->irq_mask);
118 gelic_card_enable_rxdmac(card);
120 napi_enable(&card->napi);
122 up(&card->updown_lock);
123 pr_debug("%s: done\n", __func__);
126 void gelic_card_down(struct gelic_card *card)
129 pr_debug("%s: called\n", __func__);
130 down(&card->updown_lock);
131 if (atomic_dec_if_positive(&card->users) == 0) {
132 pr_debug("%s: real do\n", __func__);
133 napi_disable(&card->napi);
135 * Disable irq. Wireless interrupts will
136 * be disabled later if any
138 mask = card->irq_mask & (GELIC_CARD_WLAN_EVENT_RECEIVED |
139 GELIC_CARD_WLAN_COMMAND_COMPLETED);
140 gelic_card_set_irq_mask(card, mask);
142 gelic_card_disable_rxdmac(card);
143 gelic_card_reset_chain(card, &card->rx_chain,
144 card->descr + GELIC_NET_TX_DESCRIPTORS);
146 gelic_card_disable_txdmac(card);
148 up(&card->updown_lock);
149 pr_debug("%s: done\n", __func__);
153 * gelic_descr_get_status -- returns the status of a descriptor
154 * @descr: descriptor to look at
156 * returns the status as in the dmac_cmd_status field of the descriptor
158 static enum gelic_descr_dma_status
159 gelic_descr_get_status(struct gelic_descr *descr)
161 return be32_to_cpu(descr->dmac_cmd_status) & GELIC_DESCR_DMA_STAT_MASK;
165 * gelic_descr_set_status -- sets the status of a descriptor
166 * @descr: descriptor to change
167 * @status: status to set in the descriptor
169 * changes the status to the specified value. Doesn't change other bits
172 static void gelic_descr_set_status(struct gelic_descr *descr,
173 enum gelic_descr_dma_status status)
175 descr->dmac_cmd_status = cpu_to_be32(status |
176 (be32_to_cpu(descr->dmac_cmd_status) &
177 ~GELIC_DESCR_DMA_STAT_MASK));
179 * dma_cmd_status field is used to indicate whether the descriptor
181 * Usually caller of this function wants to inform that to the
182 * hardware, so we assure here the hardware sees the change.
188 * gelic_card_free_chain - free descriptor chain
189 * @card: card structure
190 * @descr_in: address of desc
192 static void gelic_card_free_chain(struct gelic_card *card,
193 struct gelic_descr *descr_in)
195 struct gelic_descr *descr;
197 for (descr = descr_in; descr && descr->bus_addr; descr = descr->next) {
198 dma_unmap_single(ctodev(card), descr->bus_addr,
199 GELIC_DESCR_SIZE, DMA_BIDIRECTIONAL);
205 * gelic_card_init_chain - links descriptor chain
206 * @card: card structure
207 * @chain: address of chain
208 * @start_descr: address of descriptor array
209 * @no: number of descriptors
211 * we manage a circular list that mirrors the hardware structure,
212 * except that the hardware uses bus addresses.
214 * returns 0 on success, <0 on failure
216 static int gelic_card_init_chain(struct gelic_card *card,
217 struct gelic_descr_chain *chain,
218 struct gelic_descr *start_descr, int no)
221 struct gelic_descr *descr;
224 memset(descr, 0, sizeof(*descr) * no);
226 /* set up the hardware pointers in each descriptor */
227 for (i = 0; i < no; i++, descr++) {
228 gelic_descr_set_status(descr, GELIC_DESCR_DMA_NOT_IN_USE);
230 dma_map_single(ctodev(card), descr,
234 if (!descr->bus_addr)
237 descr->next = descr + 1;
238 descr->prev = descr - 1;
240 /* make them as ring */
241 (descr - 1)->next = start_descr;
242 start_descr->prev = (descr - 1);
244 /* chain bus addr of hw descriptor */
246 for (i = 0; i < no; i++, descr++) {
247 descr->next_descr_addr = cpu_to_be32(descr->next->bus_addr);
250 chain->head = start_descr;
251 chain->tail = start_descr;
253 /* do not chain last hw descriptor */
254 (descr - 1)->next_descr_addr = 0;
259 for (i--, descr--; 0 <= i; i--, descr--)
261 dma_unmap_single(ctodev(card), descr->bus_addr,
268 * gelic_card_reset_chain - reset status of a descriptor chain
269 * @card: card structure
270 * @chain: address of chain
271 * @start_descr: address of descriptor array
273 * Reset the status of dma descriptors to ready state
274 * and re-initialize the hardware chain for later use
276 static void gelic_card_reset_chain(struct gelic_card *card,
277 struct gelic_descr_chain *chain,
278 struct gelic_descr *start_descr)
280 struct gelic_descr *descr;
282 for (descr = start_descr; start_descr != descr->next; descr++) {
283 gelic_descr_set_status(descr, GELIC_DESCR_DMA_CARDOWNED);
284 descr->next_descr_addr = cpu_to_be32(descr->next->bus_addr);
287 chain->head = start_descr;
288 chain->tail = (descr - 1);
290 (descr - 1)->next_descr_addr = 0;
293 * gelic_descr_prepare_rx - reinitializes a rx descriptor
294 * @card: card structure
295 * @descr: descriptor to re-init
297 * return 0 on succes, <0 on failure
299 * allocates a new rx skb, iommu-maps it and attaches it to the descriptor.
300 * Activate the descriptor state-wise
302 static int gelic_descr_prepare_rx(struct gelic_card *card,
303 struct gelic_descr *descr)
306 unsigned int bufsize;
308 if (gelic_descr_get_status(descr) != GELIC_DESCR_DMA_NOT_IN_USE)
309 dev_info(ctodev(card), "%s: ERROR status \n", __func__);
310 /* we need to round up the buffer size to a multiple of 128 */
311 bufsize = ALIGN(GELIC_NET_MAX_MTU, GELIC_NET_RXBUF_ALIGN);
313 /* and we need to have it 128 byte aligned, therefore we allocate a
315 descr->skb = dev_alloc_skb(bufsize + GELIC_NET_RXBUF_ALIGN - 1);
317 descr->buf_addr = 0; /* tell DMAC don't touch memory */
318 dev_info(ctodev(card),
319 "%s:allocate skb failed !!\n", __func__);
322 descr->buf_size = cpu_to_be32(bufsize);
323 descr->dmac_cmd_status = 0;
324 descr->result_size = 0;
325 descr->valid_size = 0;
326 descr->data_error = 0;
328 offset = ((unsigned long)descr->skb->data) &
329 (GELIC_NET_RXBUF_ALIGN - 1);
331 skb_reserve(descr->skb, GELIC_NET_RXBUF_ALIGN - offset);
332 /* io-mmu-map the skb */
333 descr->buf_addr = cpu_to_be32(dma_map_single(ctodev(card),
337 if (!descr->buf_addr) {
338 dev_kfree_skb_any(descr->skb);
340 dev_info(ctodev(card),
341 "%s:Could not iommu-map rx buffer\n", __func__);
342 gelic_descr_set_status(descr, GELIC_DESCR_DMA_NOT_IN_USE);
345 gelic_descr_set_status(descr, GELIC_DESCR_DMA_CARDOWNED);
351 * gelic_card_release_rx_chain - free all skb of rx descr
352 * @card: card structure
355 static void gelic_card_release_rx_chain(struct gelic_card *card)
357 struct gelic_descr *descr = card->rx_chain.head;
361 dma_unmap_single(ctodev(card),
362 be32_to_cpu(descr->buf_addr),
366 dev_kfree_skb_any(descr->skb);
368 gelic_descr_set_status(descr,
369 GELIC_DESCR_DMA_NOT_IN_USE);
372 } while (descr != card->rx_chain.head);
376 * gelic_card_fill_rx_chain - fills descriptors/skbs in the rx chains
377 * @card: card structure
379 * fills all descriptors in the rx chain: allocates skbs
380 * and iommu-maps them.
381 * returns 0 on success, < 0 on failure
383 static int gelic_card_fill_rx_chain(struct gelic_card *card)
385 struct gelic_descr *descr = card->rx_chain.head;
390 ret = gelic_descr_prepare_rx(card, descr);
395 } while (descr != card->rx_chain.head);
399 gelic_card_release_rx_chain(card);
404 * gelic_card_alloc_rx_skbs - allocates rx skbs in rx descriptor chains
405 * @card: card structure
407 * returns 0 on success, < 0 on failure
409 static int gelic_card_alloc_rx_skbs(struct gelic_card *card)
411 struct gelic_descr_chain *chain;
413 chain = &card->rx_chain;
414 ret = gelic_card_fill_rx_chain(card);
415 chain->tail = card->rx_top->prev; /* point to the last */
420 * gelic_descr_release_tx - processes a used tx descriptor
421 * @card: card structure
422 * @descr: descriptor to release
424 * releases a used tx descriptor (unmapping, freeing of skb)
426 static void gelic_descr_release_tx(struct gelic_card *card,
427 struct gelic_descr *descr)
429 struct sk_buff *skb = descr->skb;
431 BUG_ON(!(be32_to_cpu(descr->data_status) & GELIC_DESCR_TX_TAIL));
433 dma_unmap_single(ctodev(card), be32_to_cpu(descr->buf_addr), skb->len,
435 dev_kfree_skb_any(skb);
439 descr->next_descr_addr = 0;
440 descr->result_size = 0;
441 descr->valid_size = 0;
442 descr->data_status = 0;
443 descr->data_error = 0;
446 /* set descr status */
447 gelic_descr_set_status(descr, GELIC_DESCR_DMA_NOT_IN_USE);
450 static void gelic_card_stop_queues(struct gelic_card *card)
452 netif_stop_queue(card->netdev[GELIC_PORT_ETHERNET]);
454 if (card->netdev[GELIC_PORT_WIRELESS])
455 netif_stop_queue(card->netdev[GELIC_PORT_WIRELESS]);
457 static void gelic_card_wake_queues(struct gelic_card *card)
459 netif_wake_queue(card->netdev[GELIC_PORT_ETHERNET]);
461 if (card->netdev[GELIC_PORT_WIRELESS])
462 netif_wake_queue(card->netdev[GELIC_PORT_WIRELESS]);
465 * gelic_card_release_tx_chain - processes sent tx descriptors
466 * @card: adapter structure
467 * @stop: net_stop sequence
469 * releases the tx descriptors that gelic has finished with
471 static void gelic_card_release_tx_chain(struct gelic_card *card, int stop)
473 struct gelic_descr_chain *tx_chain;
474 enum gelic_descr_dma_status status;
475 struct net_device *netdev;
478 for (tx_chain = &card->tx_chain;
479 tx_chain->head != tx_chain->tail && tx_chain->tail;
480 tx_chain->tail = tx_chain->tail->next) {
481 status = gelic_descr_get_status(tx_chain->tail);
482 netdev = tx_chain->tail->skb->dev;
484 case GELIC_DESCR_DMA_RESPONSE_ERROR:
485 case GELIC_DESCR_DMA_PROTECTION_ERROR:
486 case GELIC_DESCR_DMA_FORCE_END:
487 if (printk_ratelimit())
488 dev_info(ctodev(card),
489 "%s: forcing end of tx descriptor " \
492 netdev->stats.tx_dropped++;
495 case GELIC_DESCR_DMA_COMPLETE:
496 if (tx_chain->tail->skb) {
497 netdev->stats.tx_packets++;
498 netdev->stats.tx_bytes +=
499 tx_chain->tail->skb->len;
503 case GELIC_DESCR_DMA_CARDOWNED:
504 /* pending tx request */
506 /* any other value (== GELIC_DESCR_DMA_NOT_IN_USE) */
510 gelic_descr_release_tx(card, tx_chain->tail);
514 if (!stop && release)
515 gelic_card_wake_queues(card);
519 * gelic_net_set_multi - sets multicast addresses and promisc flags
520 * @netdev: interface device structure
522 * gelic_net_set_multi configures multicast addresses as needed for the
523 * netdev interface. It also sets up multicast, allmulti and promisc
524 * flags appropriately
526 void gelic_net_set_multi(struct net_device *netdev)
528 struct gelic_card *card = netdev_card(netdev);
529 struct dev_mc_list *mc;
535 /* clear all multicast address */
536 status = lv1_net_remove_multicast_address(bus_id(card), dev_id(card),
539 dev_err(ctodev(card),
540 "lv1_net_remove_multicast_address failed %d\n",
542 /* set broadcast address */
543 status = lv1_net_add_multicast_address(bus_id(card), dev_id(card),
544 GELIC_NET_BROADCAST_ADDR, 0);
546 dev_err(ctodev(card),
547 "lv1_net_add_multicast_address failed, %d\n",
550 if ((netdev->flags & IFF_ALLMULTI) ||
551 (netdev->mc_count > GELIC_NET_MC_COUNT_MAX)) {
552 status = lv1_net_add_multicast_address(bus_id(card),
556 dev_err(ctodev(card),
557 "lv1_net_add_multicast_address failed, %d\n",
562 /* set multicast addresses */
563 for (mc = netdev->mc_list; mc; mc = mc->next) {
566 for (i = 0; i < ETH_ALEN; i++) {
570 status = lv1_net_add_multicast_address(bus_id(card),
574 dev_err(ctodev(card),
575 "lv1_net_add_multicast_address failed, %d\n",
581 * gelic_card_enable_rxdmac - enables the receive DMA controller
582 * @card: card structure
584 * gelic_card_enable_rxdmac enables the DMA controller by setting RX_DMA_EN
585 * in the GDADMACCNTR register
587 static inline void gelic_card_enable_rxdmac(struct gelic_card *card)
592 if (gelic_descr_get_status(card->rx_chain.head) !=
593 GELIC_DESCR_DMA_CARDOWNED) {
594 printk(KERN_ERR "%s: status=%x\n", __func__,
595 be32_to_cpu(card->rx_chain.head->dmac_cmd_status));
596 printk(KERN_ERR "%s: nextphy=%x\n", __func__,
597 be32_to_cpu(card->rx_chain.head->next_descr_addr));
598 printk(KERN_ERR "%s: head=%p\n", __func__,
599 card->rx_chain.head);
602 status = lv1_net_start_rx_dma(bus_id(card), dev_id(card),
603 card->rx_chain.head->bus_addr, 0);
605 dev_info(ctodev(card),
606 "lv1_net_start_rx_dma failed, status=%d\n", status);
610 * gelic_card_disable_rxdmac - disables the receive DMA controller
611 * @card: card structure
613 * gelic_card_disable_rxdmac terminates processing on the DMA controller by
614 * turing off DMA and issueing a force end
616 static inline void gelic_card_disable_rxdmac(struct gelic_card *card)
620 /* this hvc blocks until the DMA in progress really stopped */
621 status = lv1_net_stop_rx_dma(bus_id(card), dev_id(card), 0);
623 dev_err(ctodev(card),
624 "lv1_net_stop_rx_dma faild, %d\n", status);
628 * gelic_card_disable_txdmac - disables the transmit DMA controller
629 * @card: card structure
631 * gelic_card_disable_txdmac terminates processing on the DMA controller by
632 * turing off DMA and issueing a force end
634 static inline void gelic_card_disable_txdmac(struct gelic_card *card)
638 /* this hvc blocks until the DMA in progress really stopped */
639 status = lv1_net_stop_tx_dma(bus_id(card), dev_id(card), 0);
641 dev_err(ctodev(card),
642 "lv1_net_stop_tx_dma faild, status=%d\n", status);
646 * gelic_net_stop - called upon ifconfig down
647 * @netdev: interface device structure
651 int gelic_net_stop(struct net_device *netdev)
653 struct gelic_card *card;
655 pr_debug("%s: start\n", __func__);
657 netif_stop_queue(netdev);
658 netif_carrier_off(netdev);
660 card = netdev_card(netdev);
661 gelic_card_down(card);
663 pr_debug("%s: done\n", __func__);
668 * gelic_card_get_next_tx_descr - returns the next available tx descriptor
669 * @card: device structure to get descriptor from
671 * returns the address of the next descriptor, or NULL if not available.
673 static struct gelic_descr *
674 gelic_card_get_next_tx_descr(struct gelic_card *card)
676 if (!card->tx_chain.head)
678 /* see if the next descriptor is free */
679 if (card->tx_chain.tail != card->tx_chain.head->next &&
680 gelic_descr_get_status(card->tx_chain.head) ==
681 GELIC_DESCR_DMA_NOT_IN_USE)
682 return card->tx_chain.head;
689 * gelic_net_set_txdescr_cmdstat - sets the tx descriptor command field
690 * @descr: descriptor structure to fill out
691 * @skb: packet to consider
693 * fills out the command and status field of the descriptor structure,
694 * depending on hardware checksum settings. This function assumes a wmb()
695 * has executed before.
697 static void gelic_descr_set_tx_cmdstat(struct gelic_descr *descr,
700 if (skb->ip_summed != CHECKSUM_PARTIAL)
701 descr->dmac_cmd_status =
702 cpu_to_be32(GELIC_DESCR_DMA_CMD_NO_CHKSUM |
703 GELIC_DESCR_TX_DMA_FRAME_TAIL);
706 * if yes: tcp? udp? */
707 if (skb->protocol == htons(ETH_P_IP)) {
708 if (ip_hdr(skb)->protocol == IPPROTO_TCP)
709 descr->dmac_cmd_status =
710 cpu_to_be32(GELIC_DESCR_DMA_CMD_TCP_CHKSUM |
711 GELIC_DESCR_TX_DMA_FRAME_TAIL);
713 else if (ip_hdr(skb)->protocol == IPPROTO_UDP)
714 descr->dmac_cmd_status =
715 cpu_to_be32(GELIC_DESCR_DMA_CMD_UDP_CHKSUM |
716 GELIC_DESCR_TX_DMA_FRAME_TAIL);
718 * the stack should checksum non-tcp and non-udp
719 * packets on his own: NETIF_F_IP_CSUM
721 descr->dmac_cmd_status =
722 cpu_to_be32(GELIC_DESCR_DMA_CMD_NO_CHKSUM |
723 GELIC_DESCR_TX_DMA_FRAME_TAIL);
728 static inline struct sk_buff *gelic_put_vlan_tag(struct sk_buff *skb,
731 struct vlan_ethhdr *veth;
732 static unsigned int c;
734 if (skb_headroom(skb) < VLAN_HLEN) {
735 struct sk_buff *sk_tmp = skb;
736 pr_debug("%s: hd=%d c=%ud\n", __func__, skb_headroom(skb), c);
737 skb = skb_realloc_headroom(sk_tmp, VLAN_HLEN);
740 dev_kfree_skb_any(sk_tmp);
742 veth = (struct vlan_ethhdr *)skb_push(skb, VLAN_HLEN);
744 /* Move the mac addresses to the top of buffer */
745 memmove(skb->data, skb->data + VLAN_HLEN, 2 * ETH_ALEN);
747 veth->h_vlan_proto = __constant_htons(ETH_P_8021Q);
748 veth->h_vlan_TCI = htons(tag);
754 * gelic_descr_prepare_tx - setup a descriptor for sending packets
755 * @card: card structure
756 * @descr: descriptor structure
757 * @skb: packet to use
759 * returns 0 on success, <0 on failure.
762 static int gelic_descr_prepare_tx(struct gelic_card *card,
763 struct gelic_descr *descr,
768 if (card->vlan_required) {
769 struct sk_buff *skb_tmp;
770 enum gelic_port_type type;
772 type = netdev_port(skb->dev)->type;
773 skb_tmp = gelic_put_vlan_tag(skb,
774 card->vlan[type].tx);
780 buf = dma_map_single(ctodev(card), skb->data, skb->len, DMA_TO_DEVICE);
783 dev_err(ctodev(card),
784 "dma map 2 failed (%p, %i). Dropping packet\n",
785 skb->data, skb->len);
789 descr->buf_addr = cpu_to_be32(buf);
790 descr->buf_size = cpu_to_be32(skb->len);
792 descr->data_status = 0;
793 descr->next_descr_addr = 0; /* terminate hw descr */
794 gelic_descr_set_tx_cmdstat(descr, skb);
796 /* bump free descriptor pointer */
797 card->tx_chain.head = descr->next;
802 * gelic_card_kick_txdma - enables TX DMA processing
803 * @card: card structure
804 * @descr: descriptor address to enable TX processing at
807 static int gelic_card_kick_txdma(struct gelic_card *card,
808 struct gelic_descr *descr)
812 if (card->tx_dma_progress)
815 if (gelic_descr_get_status(descr) == GELIC_DESCR_DMA_CARDOWNED) {
816 card->tx_dma_progress = 1;
817 status = lv1_net_start_tx_dma(bus_id(card), dev_id(card),
820 dev_info(ctodev(card), "lv1_net_start_txdma failed," \
821 "status=%d\n", status);
827 * gelic_net_xmit - transmits a frame over the device
828 * @skb: packet to send out
829 * @netdev: interface device structure
831 * returns 0 on success, <0 on failure
833 int gelic_net_xmit(struct sk_buff *skb, struct net_device *netdev)
835 struct gelic_card *card = netdev_card(netdev);
836 struct gelic_descr *descr;
840 spin_lock_irqsave(&card->tx_lock, flags);
842 gelic_card_release_tx_chain(card, 0);
844 descr = gelic_card_get_next_tx_descr(card);
847 * no more descriptors free
849 gelic_card_stop_queues(card);
850 spin_unlock_irqrestore(&card->tx_lock, flags);
851 return NETDEV_TX_BUSY;
854 result = gelic_descr_prepare_tx(card, descr, skb);
857 * DMA map failed. As chanses are that failure
858 * would continue, just release skb and return
860 netdev->stats.tx_dropped++;
861 dev_kfree_skb_any(skb);
862 spin_unlock_irqrestore(&card->tx_lock, flags);
866 * link this prepared descriptor to previous one
867 * to achieve high performance
869 descr->prev->next_descr_addr = cpu_to_be32(descr->bus_addr);
871 * as hardware descriptor is modified in the above lines,
872 * ensure that the hardware sees it
875 if (gelic_card_kick_txdma(card, descr)) {
878 * release descriptors which were just prepared
880 netdev->stats.tx_dropped++;
881 gelic_descr_release_tx(card, descr);
882 gelic_descr_release_tx(card, descr->next);
883 card->tx_chain.tail = descr->next->next;
884 dev_info(ctodev(card), "%s: kick failure\n", __func__);
886 /* OK, DMA started/reserved */
887 netdev->trans_start = jiffies;
890 spin_unlock_irqrestore(&card->tx_lock, flags);
895 * gelic_net_pass_skb_up - takes an skb from a descriptor and passes it on
896 * @descr: descriptor to process
897 * @card: card structure
898 * @netdev: net_device structure to be passed packet
900 * iommu-unmaps the skb, fills out skb structure and passes the data to the
901 * stack. The descriptor state is not changed.
903 static void gelic_net_pass_skb_up(struct gelic_descr *descr,
904 struct gelic_card *card,
905 struct net_device *netdev)
908 struct sk_buff *skb = descr->skb;
909 u32 data_status, data_error;
911 data_status = be32_to_cpu(descr->data_status);
912 data_error = be32_to_cpu(descr->data_error);
913 /* unmap skb buffer */
914 dma_unmap_single(ctodev(card), be32_to_cpu(descr->buf_addr),
918 skb_put(skb, be32_to_cpu(descr->valid_size)?
919 be32_to_cpu(descr->valid_size) :
920 be32_to_cpu(descr->result_size));
921 if (!descr->valid_size)
922 dev_info(ctodev(card), "buffer full %x %x %x\n",
923 be32_to_cpu(descr->result_size),
924 be32_to_cpu(descr->buf_size),
925 be32_to_cpu(descr->dmac_cmd_status));
929 * the card put 2 bytes vlan tag in front
930 * of the ethernet frame
933 skb->protocol = eth_type_trans(skb, netdev);
935 /* checksum offload */
937 if ((data_status & GELIC_DESCR_DATA_STATUS_CHK_MASK) &&
938 (!(data_error & GELIC_DESCR_DATA_ERROR_CHK_MASK)))
939 skb->ip_summed = CHECKSUM_UNNECESSARY;
941 skb->ip_summed = CHECKSUM_NONE;
943 skb->ip_summed = CHECKSUM_NONE;
945 /* update netdevice statistics */
946 netdev->stats.rx_packets++;
947 netdev->stats.rx_bytes += skb->len;
949 /* pass skb up to stack */
950 netif_receive_skb(skb);
954 * gelic_card_decode_one_descr - processes an rx descriptor
955 * @card: card structure
957 * returns 1 if a packet has been sent to the stack, otherwise 0
959 * processes an rx descriptor by iommu-unmapping the data buffer and passing
960 * the packet up to the stack
962 static int gelic_card_decode_one_descr(struct gelic_card *card)
964 enum gelic_descr_dma_status status;
965 struct gelic_descr_chain *chain = &card->rx_chain;
966 struct gelic_descr *descr = chain->head;
967 struct net_device *netdev = NULL;
968 int dmac_chain_ended;
970 status = gelic_descr_get_status(descr);
971 /* is this descriptor terminated with next_descr == NULL? */
973 be32_to_cpu(descr->dmac_cmd_status) &
974 GELIC_DESCR_RX_DMA_CHAIN_END;
976 if (status == GELIC_DESCR_DMA_CARDOWNED)
979 if (status == GELIC_DESCR_DMA_NOT_IN_USE) {
980 dev_dbg(ctodev(card), "dormant descr? %p\n", descr);
984 /* netdevice select */
985 if (card->vlan_required) {
988 vid = *(u16 *)(descr->skb->data) & VLAN_VID_MASK;
989 for (i = 0; i < GELIC_PORT_MAX; i++) {
990 if (card->vlan[i].rx == vid) {
991 netdev = card->netdev[i];
995 if (GELIC_PORT_MAX <= i) {
996 pr_info("%s: unknown packet vid=%x\n", __func__, vid);
1000 netdev = card->netdev[GELIC_PORT_ETHERNET];
1002 if ((status == GELIC_DESCR_DMA_RESPONSE_ERROR) ||
1003 (status == GELIC_DESCR_DMA_PROTECTION_ERROR) ||
1004 (status == GELIC_DESCR_DMA_FORCE_END)) {
1005 dev_info(ctodev(card), "dropping RX descriptor with state %x\n",
1007 netdev->stats.rx_dropped++;
1011 if (status == GELIC_DESCR_DMA_BUFFER_FULL) {
1013 * Buffer full would occur if and only if
1014 * the frame length was longer than the size of this
1015 * descriptor's buffer. If the frame length was equal
1016 * to or shorter than buffer'size, FRAME_END condition
1018 * Anyway this frame was longer than the MTU,
1021 dev_info(ctodev(card), "overlength frame\n");
1025 * descriptoers any other than FRAME_END here should
1026 * be treated as error.
1028 if (status != GELIC_DESCR_DMA_FRAME_END) {
1029 dev_dbg(ctodev(card), "RX descriptor with state %x\n",
1034 /* ok, we've got a packet in descr */
1035 gelic_net_pass_skb_up(descr, card, netdev);
1038 * So that always DMAC can see the end
1039 * of the descriptor chain to avoid
1040 * from unwanted DMAC overrun.
1042 descr->next_descr_addr = 0;
1044 /* change the descriptor state: */
1045 gelic_descr_set_status(descr, GELIC_DESCR_DMA_NOT_IN_USE);
1048 * this call can fail, but for now, just leave this
1049 * decriptor without skb
1051 gelic_descr_prepare_rx(card, descr);
1053 chain->tail = descr;
1054 chain->head = descr->next;
1057 * Set this descriptor the end of the chain.
1059 descr->prev->next_descr_addr = cpu_to_be32(descr->bus_addr);
1062 * If dmac chain was met, DMAC stopped.
1065 if (dmac_chain_ended) {
1066 card->rx_dma_restart_required = 1;
1067 dev_dbg(ctodev(card), "reenable rx dma scheduled\n");
1074 * gelic_net_poll - NAPI poll function called by the stack to return packets
1075 * @napi: napi structure
1076 * @budget: number of packets we can pass to the stack at most
1078 * returns the number of the processed packets
1081 static int gelic_net_poll(struct napi_struct *napi, int budget)
1083 struct gelic_card *card = container_of(napi, struct gelic_card, napi);
1084 int packets_done = 0;
1086 while (packets_done < budget) {
1087 if (!gelic_card_decode_one_descr(card))
1093 if (packets_done < budget) {
1094 napi_complete(napi);
1095 gelic_card_rx_irq_on(card);
1097 return packets_done;
1100 * gelic_net_change_mtu - changes the MTU of an interface
1101 * @netdev: interface device structure
1102 * @new_mtu: new MTU value
1104 * returns 0 on success, <0 on failure
1106 int gelic_net_change_mtu(struct net_device *netdev, int new_mtu)
1108 /* no need to re-alloc skbs or so -- the max mtu is about 2.3k
1109 * and mtu is outbound only anyway */
1110 if ((new_mtu < GELIC_NET_MIN_MTU) ||
1111 (new_mtu > GELIC_NET_MAX_MTU)) {
1114 netdev->mtu = new_mtu;
1119 * gelic_card_interrupt - event handler for gelic_net
1121 static irqreturn_t gelic_card_interrupt(int irq, void *ptr)
1123 unsigned long flags;
1124 struct gelic_card *card = ptr;
1127 status = card->irq_status;
1132 status &= card->irq_mask;
1134 if (card->rx_dma_restart_required) {
1135 card->rx_dma_restart_required = 0;
1136 gelic_card_enable_rxdmac(card);
1139 if (status & GELIC_CARD_RXINT) {
1140 gelic_card_rx_irq_off(card);
1141 napi_schedule(&card->napi);
1144 if (status & GELIC_CARD_TXINT) {
1145 spin_lock_irqsave(&card->tx_lock, flags);
1146 card->tx_dma_progress = 0;
1147 gelic_card_release_tx_chain(card, 0);
1148 /* kick outstanding tx descriptor if any */
1149 gelic_card_kick_txdma(card, card->tx_chain.tail);
1150 spin_unlock_irqrestore(&card->tx_lock, flags);
1153 /* ether port status changed */
1154 if (status & GELIC_CARD_PORT_STATUS_CHANGED)
1155 gelic_card_get_ether_port_status(card, 1);
1160 #ifdef CONFIG_NET_POLL_CONTROLLER
1162 * gelic_net_poll_controller - artificial interrupt for netconsole etc.
1163 * @netdev: interface device structure
1165 * see Documentation/networking/netconsole.txt
1167 void gelic_net_poll_controller(struct net_device *netdev)
1169 struct gelic_card *card = netdev_card(netdev);
1171 gelic_card_set_irq_mask(card, 0);
1172 gelic_card_interrupt(netdev->irq, netdev);
1173 gelic_card_set_irq_mask(card, card->irq_mask);
1175 #endif /* CONFIG_NET_POLL_CONTROLLER */
1178 * gelic_net_open - called upon ifonfig up
1179 * @netdev: interface device structure
1181 * returns 0 on success, <0 on failure
1183 * gelic_net_open allocates all the descriptors and memory needed for
1184 * operation, sets up multicast list and enables interrupts
1186 int gelic_net_open(struct net_device *netdev)
1188 struct gelic_card *card = netdev_card(netdev);
1190 dev_dbg(ctodev(card), " -> %s %p\n", __func__, netdev);
1192 gelic_card_up(card);
1194 netif_start_queue(netdev);
1195 gelic_card_get_ether_port_status(card, 1);
1197 dev_dbg(ctodev(card), " <- %s\n", __func__);
1201 void gelic_net_get_drvinfo(struct net_device *netdev,
1202 struct ethtool_drvinfo *info)
1204 strncpy(info->driver, DRV_NAME, sizeof(info->driver) - 1);
1205 strncpy(info->version, DRV_VERSION, sizeof(info->version) - 1);
1208 static int gelic_ether_get_settings(struct net_device *netdev,
1209 struct ethtool_cmd *cmd)
1211 struct gelic_card *card = netdev_card(netdev);
1213 gelic_card_get_ether_port_status(card, 0);
1215 if (card->ether_port_status & GELIC_LV1_ETHER_FULL_DUPLEX)
1216 cmd->duplex = DUPLEX_FULL;
1218 cmd->duplex = DUPLEX_HALF;
1220 switch (card->ether_port_status & GELIC_LV1_ETHER_SPEED_MASK) {
1221 case GELIC_LV1_ETHER_SPEED_10:
1222 cmd->speed = SPEED_10;
1224 case GELIC_LV1_ETHER_SPEED_100:
1225 cmd->speed = SPEED_100;
1227 case GELIC_LV1_ETHER_SPEED_1000:
1228 cmd->speed = SPEED_1000;
1231 pr_info("%s: speed unknown\n", __func__);
1232 cmd->speed = SPEED_10;
1236 cmd->supported = SUPPORTED_TP | SUPPORTED_Autoneg |
1237 SUPPORTED_10baseT_Half | SUPPORTED_10baseT_Full |
1238 SUPPORTED_100baseT_Half | SUPPORTED_100baseT_Full |
1239 SUPPORTED_1000baseT_Half | SUPPORTED_1000baseT_Full;
1240 cmd->advertising = cmd->supported;
1241 cmd->autoneg = AUTONEG_ENABLE; /* always enabled */
1242 cmd->port = PORT_TP;
1247 u32 gelic_net_get_rx_csum(struct net_device *netdev)
1249 struct gelic_card *card = netdev_card(netdev);
1251 return card->rx_csum;
1254 int gelic_net_set_rx_csum(struct net_device *netdev, u32 data)
1256 struct gelic_card *card = netdev_card(netdev);
1258 card->rx_csum = data;
1262 static struct ethtool_ops gelic_ether_ethtool_ops = {
1263 .get_drvinfo = gelic_net_get_drvinfo,
1264 .get_settings = gelic_ether_get_settings,
1265 .get_link = ethtool_op_get_link,
1266 .get_tx_csum = ethtool_op_get_tx_csum,
1267 .set_tx_csum = ethtool_op_set_tx_csum,
1268 .get_rx_csum = gelic_net_get_rx_csum,
1269 .set_rx_csum = gelic_net_set_rx_csum,
1273 * gelic_net_tx_timeout_task - task scheduled by the watchdog timeout
1274 * function (to be called not under interrupt status)
1275 * @work: work is context of tx timout task
1277 * called as task when tx hangs, resets interface (if interface is up)
1279 static void gelic_net_tx_timeout_task(struct work_struct *work)
1281 struct gelic_card *card =
1282 container_of(work, struct gelic_card, tx_timeout_task);
1283 struct net_device *netdev = card->netdev[GELIC_PORT_ETHERNET];
1285 dev_info(ctodev(card), "%s:Timed out. Restarting... \n", __func__);
1287 if (!(netdev->flags & IFF_UP))
1290 netif_device_detach(netdev);
1291 gelic_net_stop(netdev);
1293 gelic_net_open(netdev);
1294 netif_device_attach(netdev);
1297 atomic_dec(&card->tx_timeout_task_counter);
1301 * gelic_net_tx_timeout - called when the tx timeout watchdog kicks in.
1302 * @netdev: interface device structure
1304 * called, if tx hangs. Schedules a task that resets the interface
1306 void gelic_net_tx_timeout(struct net_device *netdev)
1308 struct gelic_card *card;
1310 card = netdev_card(netdev);
1311 atomic_inc(&card->tx_timeout_task_counter);
1312 if (netdev->flags & IFF_UP)
1313 schedule_work(&card->tx_timeout_task);
1315 atomic_dec(&card->tx_timeout_task_counter);
1319 * gelic_ether_setup_netdev_ops - initialization of net_device operations
1320 * @netdev: net_device structure
1322 * fills out function pointers in the net_device structure
1324 static void gelic_ether_setup_netdev_ops(struct net_device *netdev,
1325 struct napi_struct *napi)
1327 netdev->open = &gelic_net_open;
1328 netdev->stop = &gelic_net_stop;
1329 netdev->hard_start_xmit = &gelic_net_xmit;
1330 netdev->set_multicast_list = &gelic_net_set_multi;
1331 netdev->change_mtu = &gelic_net_change_mtu;
1333 netdev->tx_timeout = &gelic_net_tx_timeout;
1334 netdev->watchdog_timeo = GELIC_NET_WATCHDOG_TIMEOUT;
1336 netif_napi_add(netdev, napi,
1337 gelic_net_poll, GELIC_NET_NAPI_WEIGHT);
1338 netdev->ethtool_ops = &gelic_ether_ethtool_ops;
1339 #ifdef CONFIG_NET_POLL_CONTROLLER
1340 netdev->poll_controller = gelic_net_poll_controller;
1345 * gelic_ether_setup_netdev - initialization of net_device
1346 * @netdev: net_device structure
1347 * @card: card structure
1349 * Returns 0 on success or <0 on failure
1351 * gelic_ether_setup_netdev initializes the net_device structure
1354 int gelic_net_setup_netdev(struct net_device *netdev, struct gelic_card *card)
1358 DECLARE_MAC_BUF(mac);
1360 netdev->features = NETIF_F_IP_CSUM;
1362 status = lv1_net_control(bus_id(card), dev_id(card),
1363 GELIC_LV1_GET_MAC_ADDRESS,
1366 if (status || !is_valid_ether_addr((u8 *)&v1)) {
1367 dev_info(ctodev(card),
1368 "%s:lv1_net_control GET_MAC_ADDR failed %d\n",
1372 memcpy(netdev->dev_addr, &v1, ETH_ALEN);
1374 if (card->vlan_required) {
1375 netdev->hard_header_len += VLAN_HLEN;
1377 * As vlan is internally used,
1378 * we can not receive vlan packets
1380 netdev->features |= NETIF_F_VLAN_CHALLENGED;
1383 status = register_netdev(netdev);
1385 dev_err(ctodev(card), "%s:Couldn't register %s %d\n",
1386 __func__, netdev->name, status);
1389 dev_info(ctodev(card), "%s: MAC addr %s\n",
1391 print_mac(mac, netdev->dev_addr));
1397 * gelic_alloc_card_net - allocates net_device and card structure
1399 * returns the card structure or NULL in case of errors
1401 * the card and net_device structures are linked to each other
1403 #define GELIC_ALIGN (32)
1404 static struct gelic_card *gelic_alloc_card_net(struct net_device **netdev)
1406 struct gelic_card *card;
1407 struct gelic_port *port;
1411 * gelic requires dma descriptor is 32 bytes aligned and
1412 * the hypervisor requires irq_status is 8 bytes aligned.
1414 BUILD_BUG_ON(offsetof(struct gelic_card, irq_status) % 8);
1415 BUILD_BUG_ON(offsetof(struct gelic_card, descr) % 32);
1417 sizeof(struct gelic_card) +
1418 sizeof(struct gelic_descr) * GELIC_NET_RX_DESCRIPTORS +
1419 sizeof(struct gelic_descr) * GELIC_NET_TX_DESCRIPTORS +
1422 p = kzalloc(alloc_size, GFP_KERNEL);
1425 card = PTR_ALIGN(p, GELIC_ALIGN);
1431 *netdev = alloc_etherdev(sizeof(struct gelic_port));
1433 kfree(card->unalign);
1436 port = netdev_priv(*netdev);
1439 port->netdev = *netdev;
1441 port->type = GELIC_PORT_ETHERNET;
1444 card->netdev[GELIC_PORT_ETHERNET] = *netdev;
1446 INIT_WORK(&card->tx_timeout_task, gelic_net_tx_timeout_task);
1447 init_waitqueue_head(&card->waitq);
1448 atomic_set(&card->tx_timeout_task_counter, 0);
1449 init_MUTEX(&card->updown_lock);
1450 atomic_set(&card->users, 0);
1455 static void gelic_card_get_vlan_info(struct gelic_card *card)
1464 [GELIC_PORT_ETHERNET] = {
1465 .tx = GELIC_LV1_VLAN_TX_ETHERNET,
1466 .rx = GELIC_LV1_VLAN_RX_ETHERNET
1468 [GELIC_PORT_WIRELESS] = {
1469 .tx = GELIC_LV1_VLAN_TX_WIRELESS,
1470 .rx = GELIC_LV1_VLAN_RX_WIRELESS
1474 for (i = 0; i < ARRAY_SIZE(vlan_id_ix); i++) {
1476 status = lv1_net_control(bus_id(card), dev_id(card),
1477 GELIC_LV1_GET_VLAN_ID,
1480 if (status || !v1) {
1481 if (status != LV1_NO_ENTRY)
1482 dev_dbg(ctodev(card),
1483 "get vlan id for tx(%d) failed(%d)\n",
1484 vlan_id_ix[i].tx, status);
1485 card->vlan[i].tx = 0;
1486 card->vlan[i].rx = 0;
1489 card->vlan[i].tx = (u16)v1;
1492 status = lv1_net_control(bus_id(card), dev_id(card),
1493 GELIC_LV1_GET_VLAN_ID,
1496 if (status || !v1) {
1497 if (status != LV1_NO_ENTRY)
1498 dev_info(ctodev(card),
1499 "get vlan id for rx(%d) failed(%d)\n",
1500 vlan_id_ix[i].rx, status);
1501 card->vlan[i].tx = 0;
1502 card->vlan[i].rx = 0;
1505 card->vlan[i].rx = (u16)v1;
1507 dev_dbg(ctodev(card), "vlan_id[%d] tx=%02x rx=%02x\n",
1508 i, card->vlan[i].tx, card->vlan[i].rx);
1511 if (card->vlan[GELIC_PORT_ETHERNET].tx) {
1512 BUG_ON(!card->vlan[GELIC_PORT_WIRELESS].tx);
1513 card->vlan_required = 1;
1515 card->vlan_required = 0;
1517 /* check wirelss capable firmware */
1518 if (ps3_compare_firmware_version(1, 6, 0) < 0) {
1519 card->vlan[GELIC_PORT_WIRELESS].tx = 0;
1520 card->vlan[GELIC_PORT_WIRELESS].rx = 0;
1523 dev_info(ctodev(card), "internal vlan %s\n",
1524 card->vlan_required? "enabled" : "disabled");
1527 * ps3_gelic_driver_probe - add a device to the control of this driver
1529 static int ps3_gelic_driver_probe(struct ps3_system_bus_device *dev)
1531 struct gelic_card *card;
1532 struct net_device *netdev;
1535 pr_debug("%s: called\n", __func__);
1536 result = ps3_open_hv_device(dev);
1539 dev_dbg(&dev->core, "%s:ps3_open_hv_device failed\n",
1544 result = ps3_dma_region_create(dev->d_region);
1547 dev_dbg(&dev->core, "%s:ps3_dma_region_create failed(%d)\n",
1549 BUG_ON("check region type");
1550 goto fail_dma_region;
1553 /* alloc card/netdevice */
1554 card = gelic_alloc_card_net(&netdev);
1556 dev_info(&dev->core, "%s:gelic_net_alloc_card failed\n",
1559 goto fail_alloc_card;
1561 ps3_system_bus_set_driver_data(dev, card);
1564 /* get internal vlan info */
1565 gelic_card_get_vlan_info(card);
1567 /* setup interrupt */
1568 result = lv1_net_set_interrupt_status_indicator(bus_id(card),
1570 ps3_mm_phys_to_lpar(__pa(&card->irq_status)),
1575 "%s:set_interrupt_status_indicator failed: %s\n",
1576 __func__, ps3_result(result));
1578 goto fail_status_indicator;
1581 result = ps3_sb_event_receive_port_setup(dev, PS3_BINDING_CPU_ANY,
1585 dev_info(ctodev(card),
1586 "%s:gelic_net_open_device failed (%d)\n",
1589 goto fail_alloc_irq;
1591 result = request_irq(card->irq, gelic_card_interrupt,
1592 IRQF_DISABLED, netdev->name, card);
1595 dev_info(ctodev(card), "%s:request_irq failed (%d)\n",
1597 goto fail_request_irq;
1600 /* setup card structure */
1601 card->irq_mask = GELIC_CARD_RXINT | GELIC_CARD_TXINT |
1602 GELIC_CARD_PORT_STATUS_CHANGED;
1603 card->rx_csum = GELIC_CARD_RX_CSUM_DEFAULT;
1606 if (gelic_card_init_chain(card, &card->tx_chain,
1607 card->descr, GELIC_NET_TX_DESCRIPTORS))
1609 if (gelic_card_init_chain(card, &card->rx_chain,
1610 card->descr + GELIC_NET_TX_DESCRIPTORS,
1611 GELIC_NET_RX_DESCRIPTORS))
1615 card->tx_top = card->tx_chain.head;
1616 card->rx_top = card->rx_chain.head;
1617 dev_dbg(ctodev(card), "descr rx %p, tx %p, size %#lx, num %#x\n",
1618 card->rx_top, card->tx_top, sizeof(struct gelic_descr),
1619 GELIC_NET_RX_DESCRIPTORS);
1620 /* allocate rx skbs */
1621 if (gelic_card_alloc_rx_skbs(card))
1622 goto fail_alloc_skbs;
1624 spin_lock_init(&card->tx_lock);
1625 card->tx_dma_progress = 0;
1627 /* setup net_device structure */
1628 netdev->irq = card->irq;
1629 SET_NETDEV_DEV(netdev, &card->dev->core);
1630 gelic_ether_setup_netdev_ops(netdev, &card->napi);
1631 result = gelic_net_setup_netdev(netdev, card);
1633 dev_dbg(&dev->core, "%s: setup_netdev failed %d",
1635 goto fail_setup_netdev;
1638 pr_debug("%s: done\n", __func__);
1643 gelic_card_free_chain(card, card->rx_chain.head);
1645 gelic_card_free_chain(card, card->tx_chain.head);
1647 free_irq(card->irq, card);
1648 netdev->irq = NO_IRQ;
1650 ps3_sb_event_receive_port_destroy(dev, card->irq);
1652 lv1_net_set_interrupt_status_indicator(bus_id(card),
1655 fail_status_indicator:
1656 ps3_system_bus_set_driver_data(dev, NULL);
1657 kfree(netdev_card(netdev)->unalign);
1658 free_netdev(netdev);
1660 ps3_dma_region_free(dev->d_region);
1662 ps3_close_hv_device(dev);
1668 * ps3_gelic_driver_remove - remove a device from the control of this driver
1671 static int ps3_gelic_driver_remove(struct ps3_system_bus_device *dev)
1673 struct gelic_card *card = ps3_system_bus_get_driver_data(dev);
1674 struct net_device *netdev0;
1675 pr_debug("%s: called\n", __func__);
1677 /* stop interrupt */
1678 gelic_card_set_irq_mask(card, 0);
1680 /* turn off DMA, force end */
1681 gelic_card_disable_rxdmac(card);
1682 gelic_card_disable_txdmac(card);
1684 /* release chains */
1685 gelic_card_release_tx_chain(card, 1);
1686 gelic_card_release_rx_chain(card);
1688 gelic_card_free_chain(card, card->tx_top);
1689 gelic_card_free_chain(card, card->rx_top);
1691 netdev0 = card->netdev[GELIC_PORT_ETHERNET];
1692 /* disconnect event port */
1693 free_irq(card->irq, card);
1694 netdev0->irq = NO_IRQ;
1695 ps3_sb_event_receive_port_destroy(card->dev, card->irq);
1697 wait_event(card->waitq,
1698 atomic_read(&card->tx_timeout_task_counter) == 0);
1700 lv1_net_set_interrupt_status_indicator(bus_id(card), dev_id(card),
1703 unregister_netdev(netdev0);
1704 kfree(netdev_card(netdev0)->unalign);
1705 free_netdev(netdev0);
1707 ps3_system_bus_set_driver_data(dev, NULL);
1709 ps3_dma_region_free(dev->d_region);
1711 ps3_close_hv_device(dev);
1713 pr_debug("%s: done\n", __func__);
1717 static struct ps3_system_bus_driver ps3_gelic_driver = {
1718 .match_id = PS3_MATCH_ID_GELIC,
1719 .probe = ps3_gelic_driver_probe,
1720 .remove = ps3_gelic_driver_remove,
1721 .shutdown = ps3_gelic_driver_remove,
1722 .core.name = "ps3_gelic_driver",
1723 .core.owner = THIS_MODULE,
1726 static int __init ps3_gelic_driver_init (void)
1728 return firmware_has_feature(FW_FEATURE_PS3_LV1)
1729 ? ps3_system_bus_driver_register(&ps3_gelic_driver)
1733 static void __exit ps3_gelic_driver_exit (void)
1735 ps3_system_bus_driver_unregister(&ps3_gelic_driver);
1738 module_init(ps3_gelic_driver_init);
1739 module_exit(ps3_gelic_driver_exit);
1741 MODULE_ALIAS(PS3_MODULE_ALIAS_GELIC);