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");
62 int gelic_card_set_irq_mask(struct gelic_card
*card
, u64 mask
)
66 status
= lv1_net_set_interrupt_mask(bus_id(card
), dev_id(card
),
69 dev_info(ctodev(card
),
70 "%s failed %d\n", __func__
, status
);
74 static void gelic_card_rx_irq_on(struct gelic_card
*card
)
76 card
->irq_mask
|= GELIC_CARD_RXINT
;
77 gelic_card_set_irq_mask(card
, card
->irq_mask
);
79 static void gelic_card_rx_irq_off(struct gelic_card
*card
)
81 card
->irq_mask
&= ~GELIC_CARD_RXINT
;
82 gelic_card_set_irq_mask(card
, card
->irq_mask
);
85 static void gelic_card_get_ether_port_status(struct gelic_card
*card
,
89 struct net_device
*ether_netdev
;
91 lv1_net_control(bus_id(card
), dev_id(card
),
92 GELIC_LV1_GET_ETH_PORT_STATUS
,
93 GELIC_LV1_VLAN_TX_ETHERNET_0
, 0, 0,
94 &card
->ether_port_status
, &v2
);
97 ether_netdev
= card
->netdev
[GELIC_PORT_ETHERNET_0
];
98 if (card
->ether_port_status
& GELIC_LV1_ETHER_LINK_UP
)
99 netif_carrier_on(ether_netdev
);
101 netif_carrier_off(ether_netdev
);
106 * gelic_descr_get_status -- returns the status of a descriptor
107 * @descr: descriptor to look at
109 * returns the status as in the dmac_cmd_status field of the descriptor
111 static enum gelic_descr_dma_status
112 gelic_descr_get_status(struct gelic_descr
*descr
)
114 return be32_to_cpu(descr
->dmac_cmd_status
) & GELIC_DESCR_DMA_STAT_MASK
;
117 static int gelic_card_set_link_mode(struct gelic_card
*card
, int mode
)
122 status
= lv1_net_control(bus_id(card
), dev_id(card
),
123 GELIC_LV1_SET_NEGOTIATION_MODE
,
124 GELIC_LV1_PHY_ETHERNET_0
, mode
, 0, &v1
, &v2
);
126 pr_info("%s: failed setting negotiation mode %d\n", __func__
,
131 card
->link_mode
= mode
;
136 * gelic_card_disable_txdmac - disables the transmit DMA controller
137 * @card: card structure
139 * gelic_card_disable_txdmac terminates processing on the DMA controller by
140 * turing off DMA and issuing a force end
142 static void gelic_card_disable_txdmac(struct gelic_card
*card
)
146 /* this hvc blocks until the DMA in progress really stopped */
147 status
= lv1_net_stop_tx_dma(bus_id(card
), dev_id(card
));
149 dev_err(ctodev(card
),
150 "lv1_net_stop_tx_dma failed, status=%d\n", status
);
154 * gelic_card_enable_rxdmac - enables the receive DMA controller
155 * @card: card structure
157 * gelic_card_enable_rxdmac enables the DMA controller by setting RX_DMA_EN
158 * in the GDADMACCNTR register
160 static void gelic_card_enable_rxdmac(struct gelic_card
*card
)
165 if (gelic_descr_get_status(card
->rx_chain
.head
) !=
166 GELIC_DESCR_DMA_CARDOWNED
) {
167 printk(KERN_ERR
"%s: status=%x\n", __func__
,
168 be32_to_cpu(card
->rx_chain
.head
->dmac_cmd_status
));
169 printk(KERN_ERR
"%s: nextphy=%x\n", __func__
,
170 be32_to_cpu(card
->rx_chain
.head
->next_descr_addr
));
171 printk(KERN_ERR
"%s: head=%p\n", __func__
,
172 card
->rx_chain
.head
);
175 status
= lv1_net_start_rx_dma(bus_id(card
), dev_id(card
),
176 card
->rx_chain
.head
->bus_addr
, 0);
178 dev_info(ctodev(card
),
179 "lv1_net_start_rx_dma failed, status=%d\n", status
);
183 * gelic_card_disable_rxdmac - disables the receive DMA controller
184 * @card: card structure
186 * gelic_card_disable_rxdmac terminates processing on the DMA controller by
187 * turing off DMA and issuing a force end
189 static void gelic_card_disable_rxdmac(struct gelic_card
*card
)
193 /* this hvc blocks until the DMA in progress really stopped */
194 status
= lv1_net_stop_rx_dma(bus_id(card
), dev_id(card
));
196 dev_err(ctodev(card
),
197 "lv1_net_stop_rx_dma failed, %d\n", status
);
201 * gelic_descr_set_status -- sets the status of a descriptor
202 * @descr: descriptor to change
203 * @status: status to set in the descriptor
205 * changes the status to the specified value. Doesn't change other bits
208 static void gelic_descr_set_status(struct gelic_descr
*descr
,
209 enum gelic_descr_dma_status status
)
211 descr
->dmac_cmd_status
= cpu_to_be32(status
|
212 (be32_to_cpu(descr
->dmac_cmd_status
) &
213 ~GELIC_DESCR_DMA_STAT_MASK
));
215 * dma_cmd_status field is used to indicate whether the descriptor
217 * Usually caller of this function wants to inform that to the
218 * hardware, so we assure here the hardware sees the change.
224 * gelic_card_reset_chain - reset status of a descriptor chain
225 * @card: card structure
226 * @chain: address of chain
227 * @start_descr: address of descriptor array
229 * Reset the status of dma descriptors to ready state
230 * and re-initialize the hardware chain for later use
232 static void gelic_card_reset_chain(struct gelic_card
*card
,
233 struct gelic_descr_chain
*chain
,
234 struct gelic_descr
*start_descr
)
236 struct gelic_descr
*descr
;
238 for (descr
= start_descr
; start_descr
!= descr
->next
; descr
++) {
239 gelic_descr_set_status(descr
, GELIC_DESCR_DMA_CARDOWNED
);
240 descr
->next_descr_addr
= cpu_to_be32(descr
->next
->bus_addr
);
243 chain
->head
= start_descr
;
244 chain
->tail
= (descr
- 1);
246 (descr
- 1)->next_descr_addr
= 0;
249 void gelic_card_up(struct gelic_card
*card
)
251 pr_debug("%s: called\n", __func__
);
252 mutex_lock(&card
->updown_lock
);
253 if (atomic_inc_return(&card
->users
) == 1) {
254 pr_debug("%s: real do\n", __func__
);
256 gelic_card_set_irq_mask(card
, card
->irq_mask
);
258 gelic_card_enable_rxdmac(card
);
260 napi_enable(&card
->napi
);
262 mutex_unlock(&card
->updown_lock
);
263 pr_debug("%s: done\n", __func__
);
266 void gelic_card_down(struct gelic_card
*card
)
269 pr_debug("%s: called\n", __func__
);
270 mutex_lock(&card
->updown_lock
);
271 if (atomic_dec_if_positive(&card
->users
) == 0) {
272 pr_debug("%s: real do\n", __func__
);
273 napi_disable(&card
->napi
);
275 * Disable irq. Wireless interrupts will
276 * be disabled later if any
278 mask
= card
->irq_mask
& (GELIC_CARD_WLAN_EVENT_RECEIVED
|
279 GELIC_CARD_WLAN_COMMAND_COMPLETED
);
280 gelic_card_set_irq_mask(card
, mask
);
282 gelic_card_disable_rxdmac(card
);
283 gelic_card_reset_chain(card
, &card
->rx_chain
,
284 card
->descr
+ GELIC_NET_TX_DESCRIPTORS
);
286 gelic_card_disable_txdmac(card
);
288 mutex_unlock(&card
->updown_lock
);
289 pr_debug("%s: done\n", __func__
);
293 * gelic_card_free_chain - free descriptor chain
294 * @card: card structure
295 * @descr_in: address of desc
297 static void gelic_card_free_chain(struct gelic_card
*card
,
298 struct gelic_descr
*descr_in
)
300 struct gelic_descr
*descr
;
302 for (descr
= descr_in
; descr
&& descr
->bus_addr
; descr
= descr
->next
) {
303 dma_unmap_single(ctodev(card
), descr
->bus_addr
,
304 GELIC_DESCR_SIZE
, DMA_BIDIRECTIONAL
);
310 * gelic_card_init_chain - links descriptor chain
311 * @card: card structure
312 * @chain: address of chain
313 * @start_descr: address of descriptor array
314 * @no: number of descriptors
316 * we manage a circular list that mirrors the hardware structure,
317 * except that the hardware uses bus addresses.
319 * returns 0 on success, <0 on failure
321 static int gelic_card_init_chain(struct gelic_card
*card
,
322 struct gelic_descr_chain
*chain
,
323 struct gelic_descr
*start_descr
, int no
)
326 struct gelic_descr
*descr
;
329 memset(descr
, 0, sizeof(*descr
) * no
);
331 /* set up the hardware pointers in each descriptor */
332 for (i
= 0; i
< no
; i
++, descr
++) {
333 gelic_descr_set_status(descr
, GELIC_DESCR_DMA_NOT_IN_USE
);
335 dma_map_single(ctodev(card
), descr
,
339 if (!descr
->bus_addr
)
342 descr
->next
= descr
+ 1;
343 descr
->prev
= descr
- 1;
345 /* make them as ring */
346 (descr
- 1)->next
= start_descr
;
347 start_descr
->prev
= (descr
- 1);
349 /* chain bus addr of hw descriptor */
351 for (i
= 0; i
< no
; i
++, descr
++) {
352 descr
->next_descr_addr
= cpu_to_be32(descr
->next
->bus_addr
);
355 chain
->head
= start_descr
;
356 chain
->tail
= start_descr
;
358 /* do not chain last hw descriptor */
359 (descr
- 1)->next_descr_addr
= 0;
364 for (i
--, descr
--; 0 <= i
; i
--, descr
--)
366 dma_unmap_single(ctodev(card
), descr
->bus_addr
,
373 * gelic_descr_prepare_rx - reinitializes a rx descriptor
374 * @card: card structure
375 * @descr: descriptor to re-init
377 * return 0 on success, <0 on failure
379 * allocates a new rx skb, iommu-maps it and attaches it to the descriptor.
380 * Activate the descriptor state-wise
382 static int gelic_descr_prepare_rx(struct gelic_card
*card
,
383 struct gelic_descr
*descr
)
386 unsigned int bufsize
;
388 if (gelic_descr_get_status(descr
) != GELIC_DESCR_DMA_NOT_IN_USE
)
389 dev_info(ctodev(card
), "%s: ERROR status\n", __func__
);
390 /* we need to round up the buffer size to a multiple of 128 */
391 bufsize
= ALIGN(GELIC_NET_MAX_MTU
, GELIC_NET_RXBUF_ALIGN
);
393 /* and we need to have it 128 byte aligned, therefore we allocate a
395 descr
->skb
= dev_alloc_skb(bufsize
+ GELIC_NET_RXBUF_ALIGN
- 1);
397 descr
->buf_addr
= 0; /* tell DMAC don't touch memory */
398 dev_info(ctodev(card
),
399 "%s:allocate skb failed !!\n", __func__
);
402 descr
->buf_size
= cpu_to_be32(bufsize
);
403 descr
->dmac_cmd_status
= 0;
404 descr
->result_size
= 0;
405 descr
->valid_size
= 0;
406 descr
->data_error
= 0;
408 offset
= ((unsigned long)descr
->skb
->data
) &
409 (GELIC_NET_RXBUF_ALIGN
- 1);
411 skb_reserve(descr
->skb
, GELIC_NET_RXBUF_ALIGN
- offset
);
412 /* io-mmu-map the skb */
413 descr
->buf_addr
= cpu_to_be32(dma_map_single(ctodev(card
),
417 if (!descr
->buf_addr
) {
418 dev_kfree_skb_any(descr
->skb
);
420 dev_info(ctodev(card
),
421 "%s:Could not iommu-map rx buffer\n", __func__
);
422 gelic_descr_set_status(descr
, GELIC_DESCR_DMA_NOT_IN_USE
);
425 gelic_descr_set_status(descr
, GELIC_DESCR_DMA_CARDOWNED
);
431 * gelic_card_release_rx_chain - free all skb of rx descr
432 * @card: card structure
435 static void gelic_card_release_rx_chain(struct gelic_card
*card
)
437 struct gelic_descr
*descr
= card
->rx_chain
.head
;
441 dma_unmap_single(ctodev(card
),
442 be32_to_cpu(descr
->buf_addr
),
446 dev_kfree_skb_any(descr
->skb
);
448 gelic_descr_set_status(descr
,
449 GELIC_DESCR_DMA_NOT_IN_USE
);
452 } while (descr
!= card
->rx_chain
.head
);
456 * gelic_card_fill_rx_chain - fills descriptors/skbs in the rx chains
457 * @card: card structure
459 * fills all descriptors in the rx chain: allocates skbs
460 * and iommu-maps them.
461 * returns 0 on success, < 0 on failure
463 static int gelic_card_fill_rx_chain(struct gelic_card
*card
)
465 struct gelic_descr
*descr
= card
->rx_chain
.head
;
470 ret
= gelic_descr_prepare_rx(card
, descr
);
475 } while (descr
!= card
->rx_chain
.head
);
479 gelic_card_release_rx_chain(card
);
484 * gelic_card_alloc_rx_skbs - allocates rx skbs in rx descriptor chains
485 * @card: card structure
487 * returns 0 on success, < 0 on failure
489 static int gelic_card_alloc_rx_skbs(struct gelic_card
*card
)
491 struct gelic_descr_chain
*chain
;
493 chain
= &card
->rx_chain
;
494 ret
= gelic_card_fill_rx_chain(card
);
495 chain
->tail
= card
->rx_top
->prev
; /* point to the last */
500 * gelic_descr_release_tx - processes a used tx descriptor
501 * @card: card structure
502 * @descr: descriptor to release
504 * releases a used tx descriptor (unmapping, freeing of skb)
506 static void gelic_descr_release_tx(struct gelic_card
*card
,
507 struct gelic_descr
*descr
)
509 struct sk_buff
*skb
= descr
->skb
;
511 BUG_ON(!(be32_to_cpu(descr
->data_status
) & GELIC_DESCR_TX_TAIL
));
513 dma_unmap_single(ctodev(card
), be32_to_cpu(descr
->buf_addr
), skb
->len
,
515 dev_kfree_skb_any(skb
);
519 descr
->next_descr_addr
= 0;
520 descr
->result_size
= 0;
521 descr
->valid_size
= 0;
522 descr
->data_status
= 0;
523 descr
->data_error
= 0;
526 /* set descr status */
527 gelic_descr_set_status(descr
, GELIC_DESCR_DMA_NOT_IN_USE
);
530 static void gelic_card_stop_queues(struct gelic_card
*card
)
532 netif_stop_queue(card
->netdev
[GELIC_PORT_ETHERNET_0
]);
534 if (card
->netdev
[GELIC_PORT_WIRELESS
])
535 netif_stop_queue(card
->netdev
[GELIC_PORT_WIRELESS
]);
537 static void gelic_card_wake_queues(struct gelic_card
*card
)
539 netif_wake_queue(card
->netdev
[GELIC_PORT_ETHERNET_0
]);
541 if (card
->netdev
[GELIC_PORT_WIRELESS
])
542 netif_wake_queue(card
->netdev
[GELIC_PORT_WIRELESS
]);
545 * gelic_card_release_tx_chain - processes sent tx descriptors
546 * @card: adapter structure
547 * @stop: net_stop sequence
549 * releases the tx descriptors that gelic has finished with
551 static void gelic_card_release_tx_chain(struct gelic_card
*card
, int stop
)
553 struct gelic_descr_chain
*tx_chain
;
554 enum gelic_descr_dma_status status
;
555 struct net_device
*netdev
;
558 for (tx_chain
= &card
->tx_chain
;
559 tx_chain
->head
!= tx_chain
->tail
&& tx_chain
->tail
;
560 tx_chain
->tail
= tx_chain
->tail
->next
) {
561 status
= gelic_descr_get_status(tx_chain
->tail
);
562 netdev
= tx_chain
->tail
->skb
->dev
;
564 case GELIC_DESCR_DMA_RESPONSE_ERROR
:
565 case GELIC_DESCR_DMA_PROTECTION_ERROR
:
566 case GELIC_DESCR_DMA_FORCE_END
:
567 if (printk_ratelimit())
568 dev_info(ctodev(card
),
569 "%s: forcing end of tx descriptor " \
572 netdev
->stats
.tx_dropped
++;
575 case GELIC_DESCR_DMA_COMPLETE
:
576 if (tx_chain
->tail
->skb
) {
577 netdev
->stats
.tx_packets
++;
578 netdev
->stats
.tx_bytes
+=
579 tx_chain
->tail
->skb
->len
;
583 case GELIC_DESCR_DMA_CARDOWNED
:
584 /* pending tx request */
586 /* any other value (== GELIC_DESCR_DMA_NOT_IN_USE) */
590 gelic_descr_release_tx(card
, tx_chain
->tail
);
594 if (!stop
&& release
)
595 gelic_card_wake_queues(card
);
599 * gelic_net_set_multi - sets multicast addresses and promisc flags
600 * @netdev: interface device structure
602 * gelic_net_set_multi configures multicast addresses as needed for the
603 * netdev interface. It also sets up multicast, allmulti and promisc
604 * flags appropriately
606 void gelic_net_set_multi(struct net_device
*netdev
)
608 struct gelic_card
*card
= netdev_card(netdev
);
609 struct netdev_hw_addr
*ha
;
615 /* clear all multicast address */
616 status
= lv1_net_remove_multicast_address(bus_id(card
), dev_id(card
),
619 dev_err(ctodev(card
),
620 "lv1_net_remove_multicast_address failed %d\n",
622 /* set broadcast address */
623 status
= lv1_net_add_multicast_address(bus_id(card
), dev_id(card
),
624 GELIC_NET_BROADCAST_ADDR
, 0);
626 dev_err(ctodev(card
),
627 "lv1_net_add_multicast_address failed, %d\n",
630 if ((netdev
->flags
& IFF_ALLMULTI
) ||
631 (netdev_mc_count(netdev
) > GELIC_NET_MC_COUNT_MAX
)) {
632 status
= lv1_net_add_multicast_address(bus_id(card
),
636 dev_err(ctodev(card
),
637 "lv1_net_add_multicast_address failed, %d\n",
642 /* set multicast addresses */
643 netdev_for_each_mc_addr(ha
, netdev
) {
646 for (i
= 0; i
< ETH_ALEN
; i
++) {
650 status
= lv1_net_add_multicast_address(bus_id(card
),
654 dev_err(ctodev(card
),
655 "lv1_net_add_multicast_address failed, %d\n",
661 * gelic_net_stop - called upon ifconfig down
662 * @netdev: interface device structure
666 int gelic_net_stop(struct net_device
*netdev
)
668 struct gelic_card
*card
;
670 pr_debug("%s: start\n", __func__
);
672 netif_stop_queue(netdev
);
673 netif_carrier_off(netdev
);
675 card
= netdev_card(netdev
);
676 gelic_card_down(card
);
678 pr_debug("%s: done\n", __func__
);
683 * gelic_card_get_next_tx_descr - returns the next available tx descriptor
684 * @card: device structure to get descriptor from
686 * returns the address of the next descriptor, or NULL if not available.
688 static struct gelic_descr
*
689 gelic_card_get_next_tx_descr(struct gelic_card
*card
)
691 if (!card
->tx_chain
.head
)
693 /* see if the next descriptor is free */
694 if (card
->tx_chain
.tail
!= card
->tx_chain
.head
->next
&&
695 gelic_descr_get_status(card
->tx_chain
.head
) ==
696 GELIC_DESCR_DMA_NOT_IN_USE
)
697 return card
->tx_chain
.head
;
704 * gelic_net_set_txdescr_cmdstat - sets the tx descriptor command field
705 * @descr: descriptor structure to fill out
706 * @skb: packet to consider
708 * fills out the command and status field of the descriptor structure,
709 * depending on hardware checksum settings. This function assumes a wmb()
710 * has executed before.
712 static void gelic_descr_set_tx_cmdstat(struct gelic_descr
*descr
,
715 if (skb
->ip_summed
!= CHECKSUM_PARTIAL
)
716 descr
->dmac_cmd_status
=
717 cpu_to_be32(GELIC_DESCR_DMA_CMD_NO_CHKSUM
|
718 GELIC_DESCR_TX_DMA_FRAME_TAIL
);
721 * if yes: tcp? udp? */
722 if (skb
->protocol
== htons(ETH_P_IP
)) {
723 if (ip_hdr(skb
)->protocol
== IPPROTO_TCP
)
724 descr
->dmac_cmd_status
=
725 cpu_to_be32(GELIC_DESCR_DMA_CMD_TCP_CHKSUM
|
726 GELIC_DESCR_TX_DMA_FRAME_TAIL
);
728 else if (ip_hdr(skb
)->protocol
== IPPROTO_UDP
)
729 descr
->dmac_cmd_status
=
730 cpu_to_be32(GELIC_DESCR_DMA_CMD_UDP_CHKSUM
|
731 GELIC_DESCR_TX_DMA_FRAME_TAIL
);
733 * the stack should checksum non-tcp and non-udp
734 * packets on his own: NETIF_F_IP_CSUM
736 descr
->dmac_cmd_status
=
737 cpu_to_be32(GELIC_DESCR_DMA_CMD_NO_CHKSUM
|
738 GELIC_DESCR_TX_DMA_FRAME_TAIL
);
743 static struct sk_buff
*gelic_put_vlan_tag(struct sk_buff
*skb
,
746 struct vlan_ethhdr
*veth
;
747 static unsigned int c
;
749 if (skb_headroom(skb
) < VLAN_HLEN
) {
750 struct sk_buff
*sk_tmp
= skb
;
751 pr_debug("%s: hd=%d c=%ud\n", __func__
, skb_headroom(skb
), c
);
752 skb
= skb_realloc_headroom(sk_tmp
, VLAN_HLEN
);
755 dev_kfree_skb_any(sk_tmp
);
757 veth
= (struct vlan_ethhdr
*)skb_push(skb
, VLAN_HLEN
);
759 /* Move the mac addresses to the top of buffer */
760 memmove(skb
->data
, skb
->data
+ VLAN_HLEN
, 2 * ETH_ALEN
);
762 veth
->h_vlan_proto
= cpu_to_be16(ETH_P_8021Q
);
763 veth
->h_vlan_TCI
= htons(tag
);
769 * gelic_descr_prepare_tx - setup a descriptor for sending packets
770 * @card: card structure
771 * @descr: descriptor structure
772 * @skb: packet to use
774 * returns 0 on success, <0 on failure.
777 static int gelic_descr_prepare_tx(struct gelic_card
*card
,
778 struct gelic_descr
*descr
,
783 if (card
->vlan_required
) {
784 struct sk_buff
*skb_tmp
;
785 enum gelic_port_type type
;
787 type
= netdev_port(skb
->dev
)->type
;
788 skb_tmp
= gelic_put_vlan_tag(skb
,
789 card
->vlan
[type
].tx
);
795 buf
= dma_map_single(ctodev(card
), skb
->data
, skb
->len
, DMA_TO_DEVICE
);
798 dev_err(ctodev(card
),
799 "dma map 2 failed (%p, %i). Dropping packet\n",
800 skb
->data
, skb
->len
);
804 descr
->buf_addr
= cpu_to_be32(buf
);
805 descr
->buf_size
= cpu_to_be32(skb
->len
);
807 descr
->data_status
= 0;
808 descr
->next_descr_addr
= 0; /* terminate hw descr */
809 gelic_descr_set_tx_cmdstat(descr
, skb
);
811 /* bump free descriptor pointer */
812 card
->tx_chain
.head
= descr
->next
;
817 * gelic_card_kick_txdma - enables TX DMA processing
818 * @card: card structure
819 * @descr: descriptor address to enable TX processing at
822 static int gelic_card_kick_txdma(struct gelic_card
*card
,
823 struct gelic_descr
*descr
)
827 if (card
->tx_dma_progress
)
830 if (gelic_descr_get_status(descr
) == GELIC_DESCR_DMA_CARDOWNED
) {
831 card
->tx_dma_progress
= 1;
832 status
= lv1_net_start_tx_dma(bus_id(card
), dev_id(card
),
835 card
->tx_dma_progress
= 0;
836 dev_info(ctodev(card
), "lv1_net_start_txdma failed," \
837 "status=%d\n", status
);
844 * gelic_net_xmit - transmits a frame over the device
845 * @skb: packet to send out
846 * @netdev: interface device structure
848 * returns 0 on success, <0 on failure
850 int gelic_net_xmit(struct sk_buff
*skb
, struct net_device
*netdev
)
852 struct gelic_card
*card
= netdev_card(netdev
);
853 struct gelic_descr
*descr
;
857 spin_lock_irqsave(&card
->tx_lock
, flags
);
859 gelic_card_release_tx_chain(card
, 0);
861 descr
= gelic_card_get_next_tx_descr(card
);
864 * no more descriptors free
866 gelic_card_stop_queues(card
);
867 spin_unlock_irqrestore(&card
->tx_lock
, flags
);
868 return NETDEV_TX_BUSY
;
871 result
= gelic_descr_prepare_tx(card
, descr
, skb
);
874 * DMA map failed. As chances are that failure
875 * would continue, just release skb and return
877 netdev
->stats
.tx_dropped
++;
878 dev_kfree_skb_any(skb
);
879 spin_unlock_irqrestore(&card
->tx_lock
, flags
);
883 * link this prepared descriptor to previous one
884 * to achieve high performance
886 descr
->prev
->next_descr_addr
= cpu_to_be32(descr
->bus_addr
);
888 * as hardware descriptor is modified in the above lines,
889 * ensure that the hardware sees it
892 if (gelic_card_kick_txdma(card
, descr
)) {
895 * release descriptor which was just prepared
897 netdev
->stats
.tx_dropped
++;
898 /* don't trigger BUG_ON() in gelic_descr_release_tx */
899 descr
->data_status
= cpu_to_be32(GELIC_DESCR_TX_TAIL
);
900 gelic_descr_release_tx(card
, descr
);
902 card
->tx_chain
.head
= descr
;
903 /* reset hw termination */
904 descr
->prev
->next_descr_addr
= 0;
905 dev_info(ctodev(card
), "%s: kick failure\n", __func__
);
908 spin_unlock_irqrestore(&card
->tx_lock
, flags
);
913 * gelic_net_pass_skb_up - takes an skb from a descriptor and passes it on
914 * @descr: descriptor to process
915 * @card: card structure
916 * @netdev: net_device structure to be passed packet
918 * iommu-unmaps the skb, fills out skb structure and passes the data to the
919 * stack. The descriptor state is not changed.
921 static void gelic_net_pass_skb_up(struct gelic_descr
*descr
,
922 struct gelic_card
*card
,
923 struct net_device
*netdev
)
926 struct sk_buff
*skb
= descr
->skb
;
927 u32 data_status
, data_error
;
929 data_status
= be32_to_cpu(descr
->data_status
);
930 data_error
= be32_to_cpu(descr
->data_error
);
931 /* unmap skb buffer */
932 dma_unmap_single(ctodev(card
), be32_to_cpu(descr
->buf_addr
),
936 skb_put(skb
, be32_to_cpu(descr
->valid_size
)?
937 be32_to_cpu(descr
->valid_size
) :
938 be32_to_cpu(descr
->result_size
));
939 if (!descr
->valid_size
)
940 dev_info(ctodev(card
), "buffer full %x %x %x\n",
941 be32_to_cpu(descr
->result_size
),
942 be32_to_cpu(descr
->buf_size
),
943 be32_to_cpu(descr
->dmac_cmd_status
));
947 * the card put 2 bytes vlan tag in front
948 * of the ethernet frame
951 skb
->protocol
= eth_type_trans(skb
, netdev
);
953 /* checksum offload */
954 if (netdev
->features
& NETIF_F_RXCSUM
) {
955 if ((data_status
& GELIC_DESCR_DATA_STATUS_CHK_MASK
) &&
956 (!(data_error
& GELIC_DESCR_DATA_ERROR_CHK_MASK
)))
957 skb
->ip_summed
= CHECKSUM_UNNECESSARY
;
959 skb_checksum_none_assert(skb
);
961 skb_checksum_none_assert(skb
);
963 /* update netdevice statistics */
964 netdev
->stats
.rx_packets
++;
965 netdev
->stats
.rx_bytes
+= skb
->len
;
967 /* pass skb up to stack */
968 netif_receive_skb(skb
);
972 * gelic_card_decode_one_descr - processes an rx descriptor
973 * @card: card structure
975 * returns 1 if a packet has been sent to the stack, otherwise 0
977 * processes an rx descriptor by iommu-unmapping the data buffer and passing
978 * the packet up to the stack
980 static int gelic_card_decode_one_descr(struct gelic_card
*card
)
982 enum gelic_descr_dma_status status
;
983 struct gelic_descr_chain
*chain
= &card
->rx_chain
;
984 struct gelic_descr
*descr
= chain
->head
;
985 struct net_device
*netdev
= NULL
;
986 int dmac_chain_ended
;
988 status
= gelic_descr_get_status(descr
);
990 if (status
== GELIC_DESCR_DMA_CARDOWNED
)
993 if (status
== GELIC_DESCR_DMA_NOT_IN_USE
) {
994 dev_dbg(ctodev(card
), "dormant descr? %p\n", descr
);
998 /* netdevice select */
999 if (card
->vlan_required
) {
1002 vid
= *(u16
*)(descr
->skb
->data
) & VLAN_VID_MASK
;
1003 for (i
= 0; i
< GELIC_PORT_MAX
; i
++) {
1004 if (card
->vlan
[i
].rx
== vid
) {
1005 netdev
= card
->netdev
[i
];
1009 if (GELIC_PORT_MAX
<= i
) {
1010 pr_info("%s: unknown packet vid=%x\n", __func__
, vid
);
1014 netdev
= card
->netdev
[GELIC_PORT_ETHERNET_0
];
1016 if ((status
== GELIC_DESCR_DMA_RESPONSE_ERROR
) ||
1017 (status
== GELIC_DESCR_DMA_PROTECTION_ERROR
) ||
1018 (status
== GELIC_DESCR_DMA_FORCE_END
)) {
1019 dev_info(ctodev(card
), "dropping RX descriptor with state %x\n",
1021 netdev
->stats
.rx_dropped
++;
1025 if (status
== GELIC_DESCR_DMA_BUFFER_FULL
) {
1027 * Buffer full would occur if and only if
1028 * the frame length was longer than the size of this
1029 * descriptor's buffer. If the frame length was equal
1030 * to or shorter than buffer'size, FRAME_END condition
1032 * Anyway this frame was longer than the MTU,
1035 dev_info(ctodev(card
), "overlength frame\n");
1039 * descriptors any other than FRAME_END here should
1040 * be treated as error.
1042 if (status
!= GELIC_DESCR_DMA_FRAME_END
) {
1043 dev_dbg(ctodev(card
), "RX descriptor with state %x\n",
1048 /* ok, we've got a packet in descr */
1049 gelic_net_pass_skb_up(descr
, card
, netdev
);
1052 /* is the current descriptor terminated with next_descr == NULL? */
1054 be32_to_cpu(descr
->dmac_cmd_status
) &
1055 GELIC_DESCR_RX_DMA_CHAIN_END
;
1057 * So that always DMAC can see the end
1058 * of the descriptor chain to avoid
1059 * from unwanted DMAC overrun.
1061 descr
->next_descr_addr
= 0;
1063 /* change the descriptor state: */
1064 gelic_descr_set_status(descr
, GELIC_DESCR_DMA_NOT_IN_USE
);
1067 * this call can fail, but for now, just leave this
1068 * descriptor without skb
1070 gelic_descr_prepare_rx(card
, descr
);
1072 chain
->tail
= descr
;
1073 chain
->head
= descr
->next
;
1076 * Set this descriptor the end of the chain.
1078 descr
->prev
->next_descr_addr
= cpu_to_be32(descr
->bus_addr
);
1081 * If dmac chain was met, DMAC stopped.
1085 if (dmac_chain_ended
)
1086 gelic_card_enable_rxdmac(card
);
1092 * gelic_net_poll - NAPI poll function called by the stack to return packets
1093 * @napi: napi structure
1094 * @budget: number of packets we can pass to the stack at most
1096 * returns the number of the processed packets
1099 static int gelic_net_poll(struct napi_struct
*napi
, int budget
)
1101 struct gelic_card
*card
= container_of(napi
, struct gelic_card
, napi
);
1102 int packets_done
= 0;
1104 while (packets_done
< budget
) {
1105 if (!gelic_card_decode_one_descr(card
))
1111 if (packets_done
< budget
) {
1112 napi_complete_done(napi
, packets_done
);
1113 gelic_card_rx_irq_on(card
);
1115 return packets_done
;
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 (status
& GELIC_CARD_RXINT
) {
1135 gelic_card_rx_irq_off(card
);
1136 napi_schedule(&card
->napi
);
1139 if (status
& GELIC_CARD_TXINT
) {
1140 spin_lock_irqsave(&card
->tx_lock
, flags
);
1141 card
->tx_dma_progress
= 0;
1142 gelic_card_release_tx_chain(card
, 0);
1143 /* kick outstanding tx descriptor if any */
1144 gelic_card_kick_txdma(card
, card
->tx_chain
.tail
);
1145 spin_unlock_irqrestore(&card
->tx_lock
, flags
);
1148 /* ether port status changed */
1149 if (status
& GELIC_CARD_PORT_STATUS_CHANGED
)
1150 gelic_card_get_ether_port_status(card
, 1);
1152 #ifdef CONFIG_GELIC_WIRELESS
1153 if (status
& (GELIC_CARD_WLAN_EVENT_RECEIVED
|
1154 GELIC_CARD_WLAN_COMMAND_COMPLETED
))
1155 gelic_wl_interrupt(card
->netdev
[GELIC_PORT_WIRELESS
], status
);
1161 #ifdef CONFIG_NET_POLL_CONTROLLER
1163 * gelic_net_poll_controller - artificial interrupt for netconsole etc.
1164 * @netdev: interface device structure
1166 * see Documentation/networking/netconsole.txt
1168 void gelic_net_poll_controller(struct net_device
*netdev
)
1170 struct gelic_card
*card
= netdev_card(netdev
);
1172 gelic_card_set_irq_mask(card
, 0);
1173 gelic_card_interrupt(netdev
->irq
, netdev
);
1174 gelic_card_set_irq_mask(card
, card
->irq_mask
);
1176 #endif /* CONFIG_NET_POLL_CONTROLLER */
1179 * gelic_net_open - called upon ifconfig up
1180 * @netdev: interface device structure
1182 * returns 0 on success, <0 on failure
1184 * gelic_net_open allocates all the descriptors and memory needed for
1185 * operation, sets up multicast list and enables interrupts
1187 int gelic_net_open(struct net_device
*netdev
)
1189 struct gelic_card
*card
= netdev_card(netdev
);
1191 dev_dbg(ctodev(card
), " -> %s %p\n", __func__
, netdev
);
1193 gelic_card_up(card
);
1195 netif_start_queue(netdev
);
1196 gelic_card_get_ether_port_status(card
, 1);
1198 dev_dbg(ctodev(card
), " <- %s\n", __func__
);
1202 void gelic_net_get_drvinfo(struct net_device
*netdev
,
1203 struct ethtool_drvinfo
*info
)
1205 strlcpy(info
->driver
, DRV_NAME
, sizeof(info
->driver
));
1206 strlcpy(info
->version
, DRV_VERSION
, sizeof(info
->version
));
1209 static int gelic_ether_get_settings(struct net_device
*netdev
,
1210 struct ethtool_cmd
*cmd
)
1212 struct gelic_card
*card
= netdev_card(netdev
);
1214 gelic_card_get_ether_port_status(card
, 0);
1216 if (card
->ether_port_status
& GELIC_LV1_ETHER_FULL_DUPLEX
)
1217 cmd
->duplex
= DUPLEX_FULL
;
1219 cmd
->duplex
= DUPLEX_HALF
;
1221 switch (card
->ether_port_status
& GELIC_LV1_ETHER_SPEED_MASK
) {
1222 case GELIC_LV1_ETHER_SPEED_10
:
1223 ethtool_cmd_speed_set(cmd
, SPEED_10
);
1225 case GELIC_LV1_ETHER_SPEED_100
:
1226 ethtool_cmd_speed_set(cmd
, SPEED_100
);
1228 case GELIC_LV1_ETHER_SPEED_1000
:
1229 ethtool_cmd_speed_set(cmd
, SPEED_1000
);
1232 pr_info("%s: speed unknown\n", __func__
);
1233 ethtool_cmd_speed_set(cmd
, SPEED_10
);
1237 cmd
->supported
= SUPPORTED_TP
| SUPPORTED_Autoneg
|
1238 SUPPORTED_10baseT_Half
| SUPPORTED_10baseT_Full
|
1239 SUPPORTED_100baseT_Half
| SUPPORTED_100baseT_Full
|
1240 SUPPORTED_1000baseT_Full
;
1241 cmd
->advertising
= cmd
->supported
;
1242 if (card
->link_mode
& GELIC_LV1_ETHER_AUTO_NEG
) {
1243 cmd
->autoneg
= AUTONEG_ENABLE
;
1245 cmd
->autoneg
= AUTONEG_DISABLE
;
1246 cmd
->advertising
&= ~ADVERTISED_Autoneg
;
1248 cmd
->port
= PORT_TP
;
1253 static int gelic_ether_set_settings(struct net_device
*netdev
,
1254 struct ethtool_cmd
*cmd
)
1256 struct gelic_card
*card
= netdev_card(netdev
);
1260 if (cmd
->autoneg
== AUTONEG_ENABLE
) {
1261 mode
= GELIC_LV1_ETHER_AUTO_NEG
;
1263 switch (cmd
->speed
) {
1265 mode
= GELIC_LV1_ETHER_SPEED_10
;
1268 mode
= GELIC_LV1_ETHER_SPEED_100
;
1271 mode
= GELIC_LV1_ETHER_SPEED_1000
;
1276 if (cmd
->duplex
== DUPLEX_FULL
)
1277 mode
|= GELIC_LV1_ETHER_FULL_DUPLEX
;
1278 else if (cmd
->speed
== SPEED_1000
) {
1279 pr_info("1000 half duplex is not supported.\n");
1284 ret
= gelic_card_set_link_mode(card
, mode
);
1292 static void gelic_net_get_wol(struct net_device
*netdev
,
1293 struct ethtool_wolinfo
*wol
)
1295 if (0 <= ps3_compare_firmware_version(2, 2, 0))
1296 wol
->supported
= WAKE_MAGIC
;
1300 wol
->wolopts
= ps3_sys_manager_get_wol() ? wol
->supported
: 0;
1301 memset(&wol
->sopass
, 0, sizeof(wol
->sopass
));
1303 static int gelic_net_set_wol(struct net_device
*netdev
,
1304 struct ethtool_wolinfo
*wol
)
1307 struct gelic_card
*card
;
1310 if (ps3_compare_firmware_version(2, 2, 0) < 0 ||
1311 !capable(CAP_NET_ADMIN
))
1314 if (wol
->wolopts
& ~WAKE_MAGIC
)
1317 card
= netdev_card(netdev
);
1318 if (wol
->wolopts
& WAKE_MAGIC
) {
1319 status
= lv1_net_control(bus_id(card
), dev_id(card
),
1321 GELIC_LV1_WOL_MAGIC_PACKET
,
1322 0, GELIC_LV1_WOL_MP_ENABLE
,
1325 pr_info("%s: enabling WOL failed %d\n", __func__
,
1330 status
= lv1_net_control(bus_id(card
), dev_id(card
),
1332 GELIC_LV1_WOL_ADD_MATCH_ADDR
,
1333 0, GELIC_LV1_WOL_MATCH_ALL
,
1336 ps3_sys_manager_set_wol(1);
1338 pr_info("%s: enabling WOL filter failed %d\n",
1343 status
= lv1_net_control(bus_id(card
), dev_id(card
),
1345 GELIC_LV1_WOL_MAGIC_PACKET
,
1346 0, GELIC_LV1_WOL_MP_DISABLE
,
1349 pr_info("%s: disabling WOL failed %d\n", __func__
,
1354 status
= lv1_net_control(bus_id(card
), dev_id(card
),
1356 GELIC_LV1_WOL_DELETE_MATCH_ADDR
,
1357 0, GELIC_LV1_WOL_MATCH_ALL
,
1360 ps3_sys_manager_set_wol(0);
1362 pr_info("%s: removing WOL filter failed %d\n",
1371 static const struct ethtool_ops gelic_ether_ethtool_ops
= {
1372 .get_drvinfo
= gelic_net_get_drvinfo
,
1373 .get_settings
= gelic_ether_get_settings
,
1374 .set_settings
= gelic_ether_set_settings
,
1375 .get_link
= ethtool_op_get_link
,
1376 .get_wol
= gelic_net_get_wol
,
1377 .set_wol
= gelic_net_set_wol
,
1381 * gelic_net_tx_timeout_task - task scheduled by the watchdog timeout
1382 * function (to be called not under interrupt status)
1383 * @work: work is context of tx timout task
1385 * called as task when tx hangs, resets interface (if interface is up)
1387 static void gelic_net_tx_timeout_task(struct work_struct
*work
)
1389 struct gelic_card
*card
=
1390 container_of(work
, struct gelic_card
, tx_timeout_task
);
1391 struct net_device
*netdev
= card
->netdev
[GELIC_PORT_ETHERNET_0
];
1393 dev_info(ctodev(card
), "%s:Timed out. Restarting...\n", __func__
);
1395 if (!(netdev
->flags
& IFF_UP
))
1398 netif_device_detach(netdev
);
1399 gelic_net_stop(netdev
);
1401 gelic_net_open(netdev
);
1402 netif_device_attach(netdev
);
1405 atomic_dec(&card
->tx_timeout_task_counter
);
1409 * gelic_net_tx_timeout - called when the tx timeout watchdog kicks in.
1410 * @netdev: interface device structure
1412 * called, if tx hangs. Schedules a task that resets the interface
1414 void gelic_net_tx_timeout(struct net_device
*netdev
)
1416 struct gelic_card
*card
;
1418 card
= netdev_card(netdev
);
1419 atomic_inc(&card
->tx_timeout_task_counter
);
1420 if (netdev
->flags
& IFF_UP
)
1421 schedule_work(&card
->tx_timeout_task
);
1423 atomic_dec(&card
->tx_timeout_task_counter
);
1426 static const struct net_device_ops gelic_netdevice_ops
= {
1427 .ndo_open
= gelic_net_open
,
1428 .ndo_stop
= gelic_net_stop
,
1429 .ndo_start_xmit
= gelic_net_xmit
,
1430 .ndo_set_rx_mode
= gelic_net_set_multi
,
1431 .ndo_tx_timeout
= gelic_net_tx_timeout
,
1432 .ndo_set_mac_address
= eth_mac_addr
,
1433 .ndo_validate_addr
= eth_validate_addr
,
1434 #ifdef CONFIG_NET_POLL_CONTROLLER
1435 .ndo_poll_controller
= gelic_net_poll_controller
,
1440 * gelic_ether_setup_netdev_ops - initialization of net_device operations
1441 * @netdev: net_device structure
1443 * fills out function pointers in the net_device structure
1445 static void gelic_ether_setup_netdev_ops(struct net_device
*netdev
,
1446 struct napi_struct
*napi
)
1448 netdev
->watchdog_timeo
= GELIC_NET_WATCHDOG_TIMEOUT
;
1450 netif_napi_add(netdev
, napi
, gelic_net_poll
, NAPI_POLL_WEIGHT
);
1451 netdev
->ethtool_ops
= &gelic_ether_ethtool_ops
;
1452 netdev
->netdev_ops
= &gelic_netdevice_ops
;
1456 * gelic_ether_setup_netdev - initialization of net_device
1457 * @netdev: net_device structure
1458 * @card: card structure
1460 * Returns 0 on success or <0 on failure
1462 * gelic_ether_setup_netdev initializes the net_device structure
1465 int gelic_net_setup_netdev(struct net_device
*netdev
, struct gelic_card
*card
)
1470 netdev
->hw_features
= NETIF_F_IP_CSUM
| NETIF_F_RXCSUM
;
1472 netdev
->features
= NETIF_F_IP_CSUM
;
1473 if (GELIC_CARD_RX_CSUM_DEFAULT
)
1474 netdev
->features
|= NETIF_F_RXCSUM
;
1476 status
= lv1_net_control(bus_id(card
), dev_id(card
),
1477 GELIC_LV1_GET_MAC_ADDRESS
,
1480 if (status
|| !is_valid_ether_addr((u8
*)&v1
)) {
1481 dev_info(ctodev(card
),
1482 "%s:lv1_net_control GET_MAC_ADDR failed %d\n",
1486 memcpy(netdev
->dev_addr
, &v1
, ETH_ALEN
);
1488 if (card
->vlan_required
) {
1489 netdev
->hard_header_len
+= VLAN_HLEN
;
1491 * As vlan is internally used,
1492 * we can not receive vlan packets
1494 netdev
->features
|= NETIF_F_VLAN_CHALLENGED
;
1497 /* MTU range: 64 - 1518 */
1498 netdev
->min_mtu
= GELIC_NET_MIN_MTU
;
1499 netdev
->max_mtu
= GELIC_NET_MAX_MTU
;
1501 status
= register_netdev(netdev
);
1503 dev_err(ctodev(card
), "%s:Couldn't register %s %d\n",
1504 __func__
, netdev
->name
, status
);
1507 dev_info(ctodev(card
), "%s: MAC addr %pM\n",
1508 netdev
->name
, netdev
->dev_addr
);
1514 * gelic_alloc_card_net - allocates net_device and card structure
1516 * returns the card structure or NULL in case of errors
1518 * the card and net_device structures are linked to each other
1520 #define GELIC_ALIGN (32)
1521 static struct gelic_card
*gelic_alloc_card_net(struct net_device
**netdev
)
1523 struct gelic_card
*card
;
1524 struct gelic_port
*port
;
1528 * gelic requires dma descriptor is 32 bytes aligned and
1529 * the hypervisor requires irq_status is 8 bytes aligned.
1531 BUILD_BUG_ON(offsetof(struct gelic_card
, irq_status
) % 8);
1532 BUILD_BUG_ON(offsetof(struct gelic_card
, descr
) % 32);
1534 sizeof(struct gelic_card
) +
1535 sizeof(struct gelic_descr
) * GELIC_NET_RX_DESCRIPTORS
+
1536 sizeof(struct gelic_descr
) * GELIC_NET_TX_DESCRIPTORS
+
1539 p
= kzalloc(alloc_size
, GFP_KERNEL
);
1542 card
= PTR_ALIGN(p
, GELIC_ALIGN
);
1548 *netdev
= alloc_etherdev(sizeof(struct gelic_port
));
1550 kfree(card
->unalign
);
1553 port
= netdev_priv(*netdev
);
1556 port
->netdev
= *netdev
;
1558 port
->type
= GELIC_PORT_ETHERNET_0
;
1561 card
->netdev
[GELIC_PORT_ETHERNET_0
] = *netdev
;
1563 INIT_WORK(&card
->tx_timeout_task
, gelic_net_tx_timeout_task
);
1564 init_waitqueue_head(&card
->waitq
);
1565 atomic_set(&card
->tx_timeout_task_counter
, 0);
1566 mutex_init(&card
->updown_lock
);
1567 atomic_set(&card
->users
, 0);
1572 static void gelic_card_get_vlan_info(struct gelic_card
*card
)
1581 [GELIC_PORT_ETHERNET_0
] = {
1582 .tx
= GELIC_LV1_VLAN_TX_ETHERNET_0
,
1583 .rx
= GELIC_LV1_VLAN_RX_ETHERNET_0
1585 [GELIC_PORT_WIRELESS
] = {
1586 .tx
= GELIC_LV1_VLAN_TX_WIRELESS
,
1587 .rx
= GELIC_LV1_VLAN_RX_WIRELESS
1591 for (i
= 0; i
< ARRAY_SIZE(vlan_id_ix
); i
++) {
1593 status
= lv1_net_control(bus_id(card
), dev_id(card
),
1594 GELIC_LV1_GET_VLAN_ID
,
1597 if (status
|| !v1
) {
1598 if (status
!= LV1_NO_ENTRY
)
1599 dev_dbg(ctodev(card
),
1600 "get vlan id for tx(%d) failed(%d)\n",
1601 vlan_id_ix
[i
].tx
, status
);
1602 card
->vlan
[i
].tx
= 0;
1603 card
->vlan
[i
].rx
= 0;
1606 card
->vlan
[i
].tx
= (u16
)v1
;
1609 status
= lv1_net_control(bus_id(card
), dev_id(card
),
1610 GELIC_LV1_GET_VLAN_ID
,
1613 if (status
|| !v1
) {
1614 if (status
!= LV1_NO_ENTRY
)
1615 dev_info(ctodev(card
),
1616 "get vlan id for rx(%d) failed(%d)\n",
1617 vlan_id_ix
[i
].rx
, status
);
1618 card
->vlan
[i
].tx
= 0;
1619 card
->vlan
[i
].rx
= 0;
1622 card
->vlan
[i
].rx
= (u16
)v1
;
1624 dev_dbg(ctodev(card
), "vlan_id[%d] tx=%02x rx=%02x\n",
1625 i
, card
->vlan
[i
].tx
, card
->vlan
[i
].rx
);
1628 if (card
->vlan
[GELIC_PORT_ETHERNET_0
].tx
) {
1629 BUG_ON(!card
->vlan
[GELIC_PORT_WIRELESS
].tx
);
1630 card
->vlan_required
= 1;
1632 card
->vlan_required
= 0;
1634 /* check wirelss capable firmware */
1635 if (ps3_compare_firmware_version(1, 6, 0) < 0) {
1636 card
->vlan
[GELIC_PORT_WIRELESS
].tx
= 0;
1637 card
->vlan
[GELIC_PORT_WIRELESS
].rx
= 0;
1640 dev_info(ctodev(card
), "internal vlan %s\n",
1641 card
->vlan_required
? "enabled" : "disabled");
1644 * ps3_gelic_driver_probe - add a device to the control of this driver
1646 static int ps3_gelic_driver_probe(struct ps3_system_bus_device
*dev
)
1648 struct gelic_card
*card
;
1649 struct net_device
*netdev
;
1652 pr_debug("%s: called\n", __func__
);
1654 udbg_shutdown_ps3gelic();
1656 result
= ps3_open_hv_device(dev
);
1659 dev_dbg(&dev
->core
, "%s:ps3_open_hv_device failed\n",
1664 result
= ps3_dma_region_create(dev
->d_region
);
1667 dev_dbg(&dev
->core
, "%s:ps3_dma_region_create failed(%d)\n",
1669 BUG_ON("check region type");
1670 goto fail_dma_region
;
1673 /* alloc card/netdevice */
1674 card
= gelic_alloc_card_net(&netdev
);
1676 dev_info(&dev
->core
, "%s:gelic_net_alloc_card failed\n",
1679 goto fail_alloc_card
;
1681 ps3_system_bus_set_drvdata(dev
, card
);
1684 /* get internal vlan info */
1685 gelic_card_get_vlan_info(card
);
1687 card
->link_mode
= GELIC_LV1_ETHER_AUTO_NEG
;
1689 /* setup interrupt */
1690 result
= lv1_net_set_interrupt_status_indicator(bus_id(card
),
1692 ps3_mm_phys_to_lpar(__pa(&card
->irq_status
)),
1697 "%s:set_interrupt_status_indicator failed: %s\n",
1698 __func__
, ps3_result(result
));
1700 goto fail_status_indicator
;
1703 result
= ps3_sb_event_receive_port_setup(dev
, PS3_BINDING_CPU_ANY
,
1707 dev_info(ctodev(card
),
1708 "%s:gelic_net_open_device failed (%d)\n",
1711 goto fail_alloc_irq
;
1713 result
= request_irq(card
->irq
, gelic_card_interrupt
,
1714 0, netdev
->name
, card
);
1717 dev_info(ctodev(card
), "%s:request_irq failed (%d)\n",
1719 goto fail_request_irq
;
1722 /* setup card structure */
1723 card
->irq_mask
= GELIC_CARD_RXINT
| GELIC_CARD_TXINT
|
1724 GELIC_CARD_PORT_STATUS_CHANGED
;
1727 result
= gelic_card_init_chain(card
, &card
->tx_chain
,
1728 card
->descr
, GELIC_NET_TX_DESCRIPTORS
);
1731 result
= gelic_card_init_chain(card
, &card
->rx_chain
,
1732 card
->descr
+ GELIC_NET_TX_DESCRIPTORS
,
1733 GELIC_NET_RX_DESCRIPTORS
);
1738 card
->tx_top
= card
->tx_chain
.head
;
1739 card
->rx_top
= card
->rx_chain
.head
;
1740 dev_dbg(ctodev(card
), "descr rx %p, tx %p, size %#lx, num %#x\n",
1741 card
->rx_top
, card
->tx_top
, sizeof(struct gelic_descr
),
1742 GELIC_NET_RX_DESCRIPTORS
);
1743 /* allocate rx skbs */
1744 result
= gelic_card_alloc_rx_skbs(card
);
1746 goto fail_alloc_skbs
;
1748 spin_lock_init(&card
->tx_lock
);
1749 card
->tx_dma_progress
= 0;
1751 /* setup net_device structure */
1752 netdev
->irq
= card
->irq
;
1753 SET_NETDEV_DEV(netdev
, &card
->dev
->core
);
1754 gelic_ether_setup_netdev_ops(netdev
, &card
->napi
);
1755 result
= gelic_net_setup_netdev(netdev
, card
);
1757 dev_dbg(&dev
->core
, "%s: setup_netdev failed %d\n",
1759 goto fail_setup_netdev
;
1762 #ifdef CONFIG_GELIC_WIRELESS
1763 result
= gelic_wl_driver_probe(card
);
1765 dev_dbg(&dev
->core
, "%s: WL init failed\n", __func__
);
1766 goto fail_setup_netdev
;
1769 pr_debug("%s: done\n", __func__
);
1774 gelic_card_free_chain(card
, card
->rx_chain
.head
);
1776 gelic_card_free_chain(card
, card
->tx_chain
.head
);
1778 free_irq(card
->irq
, card
);
1781 ps3_sb_event_receive_port_destroy(dev
, card
->irq
);
1783 lv1_net_set_interrupt_status_indicator(bus_id(card
),
1786 fail_status_indicator
:
1787 ps3_system_bus_set_drvdata(dev
, NULL
);
1788 kfree(netdev_card(netdev
)->unalign
);
1789 free_netdev(netdev
);
1791 ps3_dma_region_free(dev
->d_region
);
1793 ps3_close_hv_device(dev
);
1799 * ps3_gelic_driver_remove - remove a device from the control of this driver
1802 static int ps3_gelic_driver_remove(struct ps3_system_bus_device
*dev
)
1804 struct gelic_card
*card
= ps3_system_bus_get_drvdata(dev
);
1805 struct net_device
*netdev0
;
1806 pr_debug("%s: called\n", __func__
);
1808 /* set auto-negotiation */
1809 gelic_card_set_link_mode(card
, GELIC_LV1_ETHER_AUTO_NEG
);
1811 #ifdef CONFIG_GELIC_WIRELESS
1812 gelic_wl_driver_remove(card
);
1814 /* stop interrupt */
1815 gelic_card_set_irq_mask(card
, 0);
1817 /* turn off DMA, force end */
1818 gelic_card_disable_rxdmac(card
);
1819 gelic_card_disable_txdmac(card
);
1821 /* release chains */
1822 gelic_card_release_tx_chain(card
, 1);
1823 gelic_card_release_rx_chain(card
);
1825 gelic_card_free_chain(card
, card
->tx_top
);
1826 gelic_card_free_chain(card
, card
->rx_top
);
1828 netdev0
= card
->netdev
[GELIC_PORT_ETHERNET_0
];
1829 /* disconnect event port */
1830 free_irq(card
->irq
, card
);
1832 ps3_sb_event_receive_port_destroy(card
->dev
, card
->irq
);
1834 wait_event(card
->waitq
,
1835 atomic_read(&card
->tx_timeout_task_counter
) == 0);
1837 lv1_net_set_interrupt_status_indicator(bus_id(card
), dev_id(card
),
1840 unregister_netdev(netdev0
);
1841 kfree(netdev_card(netdev0
)->unalign
);
1842 free_netdev(netdev0
);
1844 ps3_system_bus_set_drvdata(dev
, NULL
);
1846 ps3_dma_region_free(dev
->d_region
);
1848 ps3_close_hv_device(dev
);
1850 pr_debug("%s: done\n", __func__
);
1854 static struct ps3_system_bus_driver ps3_gelic_driver
= {
1855 .match_id
= PS3_MATCH_ID_GELIC
,
1856 .probe
= ps3_gelic_driver_probe
,
1857 .remove
= ps3_gelic_driver_remove
,
1858 .shutdown
= ps3_gelic_driver_remove
,
1859 .core
.name
= "ps3_gelic_driver",
1860 .core
.owner
= THIS_MODULE
,
1863 static int __init
ps3_gelic_driver_init (void)
1865 return firmware_has_feature(FW_FEATURE_PS3_LV1
)
1866 ? ps3_system_bus_driver_register(&ps3_gelic_driver
)
1870 static void __exit
ps3_gelic_driver_exit (void)
1872 ps3_system_bus_driver_unregister(&ps3_gelic_driver
);
1875 module_init(ps3_gelic_driver_init
);
1876 module_exit(ps3_gelic_driver_exit
);
1878 MODULE_ALIAS(PS3_MODULE_ALIAS_GELIC
);