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"
49 #include "ps3_gelic_wireless.h"
51 #define DRV_NAME "Gelic Network Driver"
52 #define DRV_VERSION "2.0"
54 MODULE_AUTHOR("SCE Inc.");
55 MODULE_DESCRIPTION("Gelic Network driver");
56 MODULE_LICENSE("GPL");
59 static inline void gelic_card_enable_rxdmac(struct gelic_card
*card
);
60 static inline void gelic_card_disable_rxdmac(struct gelic_card
*card
);
61 static inline void gelic_card_disable_txdmac(struct gelic_card
*card
);
62 static inline void gelic_card_reset_chain(struct gelic_card
*card
,
63 struct gelic_descr_chain
*chain
,
64 struct gelic_descr
*start_descr
);
67 int gelic_card_set_irq_mask(struct gelic_card
*card
, u64 mask
)
71 status
= lv1_net_set_interrupt_mask(bus_id(card
), dev_id(card
),
74 dev_info(ctodev(card
),
75 "%s failed %d\n", __func__
, status
);
79 static inline void gelic_card_rx_irq_on(struct gelic_card
*card
)
81 card
->irq_mask
|= GELIC_CARD_RXINT
;
82 gelic_card_set_irq_mask(card
, card
->irq_mask
);
84 static inline void gelic_card_rx_irq_off(struct gelic_card
*card
)
86 card
->irq_mask
&= ~GELIC_CARD_RXINT
;
87 gelic_card_set_irq_mask(card
, card
->irq_mask
);
90 static void gelic_card_get_ether_port_status(struct gelic_card
*card
,
94 struct net_device
*ether_netdev
;
96 lv1_net_control(bus_id(card
), dev_id(card
),
97 GELIC_LV1_GET_ETH_PORT_STATUS
,
98 GELIC_LV1_VLAN_TX_ETHERNET
, 0, 0,
99 &card
->ether_port_status
, &v2
);
102 ether_netdev
= card
->netdev
[GELIC_PORT_ETHERNET
];
103 if (card
->ether_port_status
& GELIC_LV1_ETHER_LINK_UP
)
104 netif_carrier_on(ether_netdev
);
106 netif_carrier_off(ether_netdev
);
110 void gelic_card_up(struct gelic_card
*card
)
112 pr_debug("%s: called\n", __func__
);
113 mutex_lock(&card
->updown_lock
);
114 if (atomic_inc_return(&card
->users
) == 1) {
115 pr_debug("%s: real do\n", __func__
);
117 gelic_card_set_irq_mask(card
, card
->irq_mask
);
119 gelic_card_enable_rxdmac(card
);
121 napi_enable(&card
->napi
);
123 mutex_unlock(&card
->updown_lock
);
124 pr_debug("%s: done\n", __func__
);
127 void gelic_card_down(struct gelic_card
*card
)
130 pr_debug("%s: called\n", __func__
);
131 mutex_lock(&card
->updown_lock
);
132 if (atomic_dec_if_positive(&card
->users
) == 0) {
133 pr_debug("%s: real do\n", __func__
);
134 napi_disable(&card
->napi
);
136 * Disable irq. Wireless interrupts will
137 * be disabled later if any
139 mask
= card
->irq_mask
& (GELIC_CARD_WLAN_EVENT_RECEIVED
|
140 GELIC_CARD_WLAN_COMMAND_COMPLETED
);
141 gelic_card_set_irq_mask(card
, mask
);
143 gelic_card_disable_rxdmac(card
);
144 gelic_card_reset_chain(card
, &card
->rx_chain
,
145 card
->descr
+ GELIC_NET_TX_DESCRIPTORS
);
147 gelic_card_disable_txdmac(card
);
149 mutex_unlock(&card
->updown_lock
);
150 pr_debug("%s: done\n", __func__
);
154 * gelic_descr_get_status -- returns the status of a descriptor
155 * @descr: descriptor to look at
157 * returns the status as in the dmac_cmd_status field of the descriptor
159 static enum gelic_descr_dma_status
160 gelic_descr_get_status(struct gelic_descr
*descr
)
162 return be32_to_cpu(descr
->dmac_cmd_status
) & GELIC_DESCR_DMA_STAT_MASK
;
166 * gelic_descr_set_status -- sets the status of a descriptor
167 * @descr: descriptor to change
168 * @status: status to set in the descriptor
170 * changes the status to the specified value. Doesn't change other bits
173 static void gelic_descr_set_status(struct gelic_descr
*descr
,
174 enum gelic_descr_dma_status status
)
176 descr
->dmac_cmd_status
= cpu_to_be32(status
|
177 (be32_to_cpu(descr
->dmac_cmd_status
) &
178 ~GELIC_DESCR_DMA_STAT_MASK
));
180 * dma_cmd_status field is used to indicate whether the descriptor
182 * Usually caller of this function wants to inform that to the
183 * hardware, so we assure here the hardware sees the change.
189 * gelic_card_free_chain - free descriptor chain
190 * @card: card structure
191 * @descr_in: address of desc
193 static void gelic_card_free_chain(struct gelic_card
*card
,
194 struct gelic_descr
*descr_in
)
196 struct gelic_descr
*descr
;
198 for (descr
= descr_in
; descr
&& descr
->bus_addr
; descr
= descr
->next
) {
199 dma_unmap_single(ctodev(card
), descr
->bus_addr
,
200 GELIC_DESCR_SIZE
, DMA_BIDIRECTIONAL
);
206 * gelic_card_init_chain - links descriptor chain
207 * @card: card structure
208 * @chain: address of chain
209 * @start_descr: address of descriptor array
210 * @no: number of descriptors
212 * we manage a circular list that mirrors the hardware structure,
213 * except that the hardware uses bus addresses.
215 * returns 0 on success, <0 on failure
217 static int gelic_card_init_chain(struct gelic_card
*card
,
218 struct gelic_descr_chain
*chain
,
219 struct gelic_descr
*start_descr
, int no
)
222 struct gelic_descr
*descr
;
225 memset(descr
, 0, sizeof(*descr
) * no
);
227 /* set up the hardware pointers in each descriptor */
228 for (i
= 0; i
< no
; i
++, descr
++) {
229 gelic_descr_set_status(descr
, GELIC_DESCR_DMA_NOT_IN_USE
);
231 dma_map_single(ctodev(card
), descr
,
235 if (!descr
->bus_addr
)
238 descr
->next
= descr
+ 1;
239 descr
->prev
= descr
- 1;
241 /* make them as ring */
242 (descr
- 1)->next
= start_descr
;
243 start_descr
->prev
= (descr
- 1);
245 /* chain bus addr of hw descriptor */
247 for (i
= 0; i
< no
; i
++, descr
++) {
248 descr
->next_descr_addr
= cpu_to_be32(descr
->next
->bus_addr
);
251 chain
->head
= start_descr
;
252 chain
->tail
= start_descr
;
254 /* do not chain last hw descriptor */
255 (descr
- 1)->next_descr_addr
= 0;
260 for (i
--, descr
--; 0 <= i
; i
--, descr
--)
262 dma_unmap_single(ctodev(card
), descr
->bus_addr
,
269 * gelic_card_reset_chain - reset status of a descriptor chain
270 * @card: card structure
271 * @chain: address of chain
272 * @start_descr: address of descriptor array
274 * Reset the status of dma descriptors to ready state
275 * and re-initialize the hardware chain for later use
277 static void gelic_card_reset_chain(struct gelic_card
*card
,
278 struct gelic_descr_chain
*chain
,
279 struct gelic_descr
*start_descr
)
281 struct gelic_descr
*descr
;
283 for (descr
= start_descr
; start_descr
!= descr
->next
; descr
++) {
284 gelic_descr_set_status(descr
, GELIC_DESCR_DMA_CARDOWNED
);
285 descr
->next_descr_addr
= cpu_to_be32(descr
->next
->bus_addr
);
288 chain
->head
= start_descr
;
289 chain
->tail
= (descr
- 1);
291 (descr
- 1)->next_descr_addr
= 0;
294 * gelic_descr_prepare_rx - reinitializes a rx descriptor
295 * @card: card structure
296 * @descr: descriptor to re-init
298 * return 0 on succes, <0 on failure
300 * allocates a new rx skb, iommu-maps it and attaches it to the descriptor.
301 * Activate the descriptor state-wise
303 static int gelic_descr_prepare_rx(struct gelic_card
*card
,
304 struct gelic_descr
*descr
)
307 unsigned int bufsize
;
309 if (gelic_descr_get_status(descr
) != GELIC_DESCR_DMA_NOT_IN_USE
)
310 dev_info(ctodev(card
), "%s: ERROR status \n", __func__
);
311 /* we need to round up the buffer size to a multiple of 128 */
312 bufsize
= ALIGN(GELIC_NET_MAX_MTU
, GELIC_NET_RXBUF_ALIGN
);
314 /* and we need to have it 128 byte aligned, therefore we allocate a
316 descr
->skb
= dev_alloc_skb(bufsize
+ GELIC_NET_RXBUF_ALIGN
- 1);
318 descr
->buf_addr
= 0; /* tell DMAC don't touch memory */
319 dev_info(ctodev(card
),
320 "%s:allocate skb failed !!\n", __func__
);
323 descr
->buf_size
= cpu_to_be32(bufsize
);
324 descr
->dmac_cmd_status
= 0;
325 descr
->result_size
= 0;
326 descr
->valid_size
= 0;
327 descr
->data_error
= 0;
329 offset
= ((unsigned long)descr
->skb
->data
) &
330 (GELIC_NET_RXBUF_ALIGN
- 1);
332 skb_reserve(descr
->skb
, GELIC_NET_RXBUF_ALIGN
- offset
);
333 /* io-mmu-map the skb */
334 descr
->buf_addr
= cpu_to_be32(dma_map_single(ctodev(card
),
338 if (!descr
->buf_addr
) {
339 dev_kfree_skb_any(descr
->skb
);
341 dev_info(ctodev(card
),
342 "%s:Could not iommu-map rx buffer\n", __func__
);
343 gelic_descr_set_status(descr
, GELIC_DESCR_DMA_NOT_IN_USE
);
346 gelic_descr_set_status(descr
, GELIC_DESCR_DMA_CARDOWNED
);
352 * gelic_card_release_rx_chain - free all skb of rx descr
353 * @card: card structure
356 static void gelic_card_release_rx_chain(struct gelic_card
*card
)
358 struct gelic_descr
*descr
= card
->rx_chain
.head
;
362 dma_unmap_single(ctodev(card
),
363 be32_to_cpu(descr
->buf_addr
),
367 dev_kfree_skb_any(descr
->skb
);
369 gelic_descr_set_status(descr
,
370 GELIC_DESCR_DMA_NOT_IN_USE
);
373 } while (descr
!= card
->rx_chain
.head
);
377 * gelic_card_fill_rx_chain - fills descriptors/skbs in the rx chains
378 * @card: card structure
380 * fills all descriptors in the rx chain: allocates skbs
381 * and iommu-maps them.
382 * returns 0 on success, < 0 on failure
384 static int gelic_card_fill_rx_chain(struct gelic_card
*card
)
386 struct gelic_descr
*descr
= card
->rx_chain
.head
;
391 ret
= gelic_descr_prepare_rx(card
, descr
);
396 } while (descr
!= card
->rx_chain
.head
);
400 gelic_card_release_rx_chain(card
);
405 * gelic_card_alloc_rx_skbs - allocates rx skbs in rx descriptor chains
406 * @card: card structure
408 * returns 0 on success, < 0 on failure
410 static int gelic_card_alloc_rx_skbs(struct gelic_card
*card
)
412 struct gelic_descr_chain
*chain
;
414 chain
= &card
->rx_chain
;
415 ret
= gelic_card_fill_rx_chain(card
);
416 chain
->tail
= card
->rx_top
->prev
; /* point to the last */
421 * gelic_descr_release_tx - processes a used tx descriptor
422 * @card: card structure
423 * @descr: descriptor to release
425 * releases a used tx descriptor (unmapping, freeing of skb)
427 static void gelic_descr_release_tx(struct gelic_card
*card
,
428 struct gelic_descr
*descr
)
430 struct sk_buff
*skb
= descr
->skb
;
432 BUG_ON(!(be32_to_cpu(descr
->data_status
) & GELIC_DESCR_TX_TAIL
));
434 dma_unmap_single(ctodev(card
), be32_to_cpu(descr
->buf_addr
), skb
->len
,
436 dev_kfree_skb_any(skb
);
440 descr
->next_descr_addr
= 0;
441 descr
->result_size
= 0;
442 descr
->valid_size
= 0;
443 descr
->data_status
= 0;
444 descr
->data_error
= 0;
447 /* set descr status */
448 gelic_descr_set_status(descr
, GELIC_DESCR_DMA_NOT_IN_USE
);
451 static void gelic_card_stop_queues(struct gelic_card
*card
)
453 netif_stop_queue(card
->netdev
[GELIC_PORT_ETHERNET
]);
455 if (card
->netdev
[GELIC_PORT_WIRELESS
])
456 netif_stop_queue(card
->netdev
[GELIC_PORT_WIRELESS
]);
458 static void gelic_card_wake_queues(struct gelic_card
*card
)
460 netif_wake_queue(card
->netdev
[GELIC_PORT_ETHERNET
]);
462 if (card
->netdev
[GELIC_PORT_WIRELESS
])
463 netif_wake_queue(card
->netdev
[GELIC_PORT_WIRELESS
]);
466 * gelic_card_release_tx_chain - processes sent tx descriptors
467 * @card: adapter structure
468 * @stop: net_stop sequence
470 * releases the tx descriptors that gelic has finished with
472 static void gelic_card_release_tx_chain(struct gelic_card
*card
, int stop
)
474 struct gelic_descr_chain
*tx_chain
;
475 enum gelic_descr_dma_status status
;
476 struct net_device
*netdev
;
479 for (tx_chain
= &card
->tx_chain
;
480 tx_chain
->head
!= tx_chain
->tail
&& tx_chain
->tail
;
481 tx_chain
->tail
= tx_chain
->tail
->next
) {
482 status
= gelic_descr_get_status(tx_chain
->tail
);
483 netdev
= tx_chain
->tail
->skb
->dev
;
485 case GELIC_DESCR_DMA_RESPONSE_ERROR
:
486 case GELIC_DESCR_DMA_PROTECTION_ERROR
:
487 case GELIC_DESCR_DMA_FORCE_END
:
488 if (printk_ratelimit())
489 dev_info(ctodev(card
),
490 "%s: forcing end of tx descriptor " \
493 netdev
->stats
.tx_dropped
++;
496 case GELIC_DESCR_DMA_COMPLETE
:
497 if (tx_chain
->tail
->skb
) {
498 netdev
->stats
.tx_packets
++;
499 netdev
->stats
.tx_bytes
+=
500 tx_chain
->tail
->skb
->len
;
504 case GELIC_DESCR_DMA_CARDOWNED
:
505 /* pending tx request */
507 /* any other value (== GELIC_DESCR_DMA_NOT_IN_USE) */
511 gelic_descr_release_tx(card
, tx_chain
->tail
);
515 if (!stop
&& release
)
516 gelic_card_wake_queues(card
);
520 * gelic_net_set_multi - sets multicast addresses and promisc flags
521 * @netdev: interface device structure
523 * gelic_net_set_multi configures multicast addresses as needed for the
524 * netdev interface. It also sets up multicast, allmulti and promisc
525 * flags appropriately
527 void gelic_net_set_multi(struct net_device
*netdev
)
529 struct gelic_card
*card
= netdev_card(netdev
);
530 struct dev_mc_list
*mc
;
536 /* clear all multicast address */
537 status
= lv1_net_remove_multicast_address(bus_id(card
), dev_id(card
),
540 dev_err(ctodev(card
),
541 "lv1_net_remove_multicast_address failed %d\n",
543 /* set broadcast address */
544 status
= lv1_net_add_multicast_address(bus_id(card
), dev_id(card
),
545 GELIC_NET_BROADCAST_ADDR
, 0);
547 dev_err(ctodev(card
),
548 "lv1_net_add_multicast_address failed, %d\n",
551 if ((netdev
->flags
& IFF_ALLMULTI
) ||
552 (netdev
->mc_count
> GELIC_NET_MC_COUNT_MAX
)) {
553 status
= lv1_net_add_multicast_address(bus_id(card
),
557 dev_err(ctodev(card
),
558 "lv1_net_add_multicast_address failed, %d\n",
563 /* set multicast addresses */
564 for (mc
= netdev
->mc_list
; mc
; mc
= mc
->next
) {
567 for (i
= 0; i
< ETH_ALEN
; i
++) {
571 status
= lv1_net_add_multicast_address(bus_id(card
),
575 dev_err(ctodev(card
),
576 "lv1_net_add_multicast_address failed, %d\n",
582 * gelic_card_enable_rxdmac - enables the receive DMA controller
583 * @card: card structure
585 * gelic_card_enable_rxdmac enables the DMA controller by setting RX_DMA_EN
586 * in the GDADMACCNTR register
588 static inline void gelic_card_enable_rxdmac(struct gelic_card
*card
)
593 if (gelic_descr_get_status(card
->rx_chain
.head
) !=
594 GELIC_DESCR_DMA_CARDOWNED
) {
595 printk(KERN_ERR
"%s: status=%x\n", __func__
,
596 be32_to_cpu(card
->rx_chain
.head
->dmac_cmd_status
));
597 printk(KERN_ERR
"%s: nextphy=%x\n", __func__
,
598 be32_to_cpu(card
->rx_chain
.head
->next_descr_addr
));
599 printk(KERN_ERR
"%s: head=%p\n", __func__
,
600 card
->rx_chain
.head
);
603 status
= lv1_net_start_rx_dma(bus_id(card
), dev_id(card
),
604 card
->rx_chain
.head
->bus_addr
, 0);
606 dev_info(ctodev(card
),
607 "lv1_net_start_rx_dma failed, status=%d\n", status
);
611 * gelic_card_disable_rxdmac - disables the receive DMA controller
612 * @card: card structure
614 * gelic_card_disable_rxdmac terminates processing on the DMA controller by
615 * turing off DMA and issueing a force end
617 static inline void gelic_card_disable_rxdmac(struct gelic_card
*card
)
621 /* this hvc blocks until the DMA in progress really stopped */
622 status
= lv1_net_stop_rx_dma(bus_id(card
), dev_id(card
), 0);
624 dev_err(ctodev(card
),
625 "lv1_net_stop_rx_dma faild, %d\n", status
);
629 * gelic_card_disable_txdmac - disables the transmit DMA controller
630 * @card: card structure
632 * gelic_card_disable_txdmac terminates processing on the DMA controller by
633 * turing off DMA and issueing a force end
635 static inline void gelic_card_disable_txdmac(struct gelic_card
*card
)
639 /* this hvc blocks until the DMA in progress really stopped */
640 status
= lv1_net_stop_tx_dma(bus_id(card
), dev_id(card
), 0);
642 dev_err(ctodev(card
),
643 "lv1_net_stop_tx_dma faild, status=%d\n", status
);
647 * gelic_net_stop - called upon ifconfig down
648 * @netdev: interface device structure
652 int gelic_net_stop(struct net_device
*netdev
)
654 struct gelic_card
*card
;
656 pr_debug("%s: start\n", __func__
);
658 netif_stop_queue(netdev
);
659 netif_carrier_off(netdev
);
661 card
= netdev_card(netdev
);
662 gelic_card_down(card
);
664 pr_debug("%s: done\n", __func__
);
669 * gelic_card_get_next_tx_descr - returns the next available tx descriptor
670 * @card: device structure to get descriptor from
672 * returns the address of the next descriptor, or NULL if not available.
674 static struct gelic_descr
*
675 gelic_card_get_next_tx_descr(struct gelic_card
*card
)
677 if (!card
->tx_chain
.head
)
679 /* see if the next descriptor is free */
680 if (card
->tx_chain
.tail
!= card
->tx_chain
.head
->next
&&
681 gelic_descr_get_status(card
->tx_chain
.head
) ==
682 GELIC_DESCR_DMA_NOT_IN_USE
)
683 return card
->tx_chain
.head
;
690 * gelic_net_set_txdescr_cmdstat - sets the tx descriptor command field
691 * @descr: descriptor structure to fill out
692 * @skb: packet to consider
694 * fills out the command and status field of the descriptor structure,
695 * depending on hardware checksum settings. This function assumes a wmb()
696 * has executed before.
698 static void gelic_descr_set_tx_cmdstat(struct gelic_descr
*descr
,
701 if (skb
->ip_summed
!= CHECKSUM_PARTIAL
)
702 descr
->dmac_cmd_status
=
703 cpu_to_be32(GELIC_DESCR_DMA_CMD_NO_CHKSUM
|
704 GELIC_DESCR_TX_DMA_FRAME_TAIL
);
707 * if yes: tcp? udp? */
708 if (skb
->protocol
== htons(ETH_P_IP
)) {
709 if (ip_hdr(skb
)->protocol
== IPPROTO_TCP
)
710 descr
->dmac_cmd_status
=
711 cpu_to_be32(GELIC_DESCR_DMA_CMD_TCP_CHKSUM
|
712 GELIC_DESCR_TX_DMA_FRAME_TAIL
);
714 else if (ip_hdr(skb
)->protocol
== IPPROTO_UDP
)
715 descr
->dmac_cmd_status
=
716 cpu_to_be32(GELIC_DESCR_DMA_CMD_UDP_CHKSUM
|
717 GELIC_DESCR_TX_DMA_FRAME_TAIL
);
719 * the stack should checksum non-tcp and non-udp
720 * packets on his own: NETIF_F_IP_CSUM
722 descr
->dmac_cmd_status
=
723 cpu_to_be32(GELIC_DESCR_DMA_CMD_NO_CHKSUM
|
724 GELIC_DESCR_TX_DMA_FRAME_TAIL
);
729 static inline struct sk_buff
*gelic_put_vlan_tag(struct sk_buff
*skb
,
732 struct vlan_ethhdr
*veth
;
733 static unsigned int c
;
735 if (skb_headroom(skb
) < VLAN_HLEN
) {
736 struct sk_buff
*sk_tmp
= skb
;
737 pr_debug("%s: hd=%d c=%ud\n", __func__
, skb_headroom(skb
), c
);
738 skb
= skb_realloc_headroom(sk_tmp
, VLAN_HLEN
);
741 dev_kfree_skb_any(sk_tmp
);
743 veth
= (struct vlan_ethhdr
*)skb_push(skb
, VLAN_HLEN
);
745 /* Move the mac addresses to the top of buffer */
746 memmove(skb
->data
, skb
->data
+ VLAN_HLEN
, 2 * ETH_ALEN
);
748 veth
->h_vlan_proto
= __constant_htons(ETH_P_8021Q
);
749 veth
->h_vlan_TCI
= htons(tag
);
755 * gelic_descr_prepare_tx - setup a descriptor for sending packets
756 * @card: card structure
757 * @descr: descriptor structure
758 * @skb: packet to use
760 * returns 0 on success, <0 on failure.
763 static int gelic_descr_prepare_tx(struct gelic_card
*card
,
764 struct gelic_descr
*descr
,
769 if (card
->vlan_required
) {
770 struct sk_buff
*skb_tmp
;
771 enum gelic_port_type type
;
773 type
= netdev_port(skb
->dev
)->type
;
774 skb_tmp
= gelic_put_vlan_tag(skb
,
775 card
->vlan
[type
].tx
);
781 buf
= dma_map_single(ctodev(card
), skb
->data
, skb
->len
, DMA_TO_DEVICE
);
784 dev_err(ctodev(card
),
785 "dma map 2 failed (%p, %i). Dropping packet\n",
786 skb
->data
, skb
->len
);
790 descr
->buf_addr
= cpu_to_be32(buf
);
791 descr
->buf_size
= cpu_to_be32(skb
->len
);
793 descr
->data_status
= 0;
794 descr
->next_descr_addr
= 0; /* terminate hw descr */
795 gelic_descr_set_tx_cmdstat(descr
, skb
);
797 /* bump free descriptor pointer */
798 card
->tx_chain
.head
= descr
->next
;
803 * gelic_card_kick_txdma - enables TX DMA processing
804 * @card: card structure
805 * @descr: descriptor address to enable TX processing at
808 static int gelic_card_kick_txdma(struct gelic_card
*card
,
809 struct gelic_descr
*descr
)
813 if (card
->tx_dma_progress
)
816 if (gelic_descr_get_status(descr
) == GELIC_DESCR_DMA_CARDOWNED
) {
817 card
->tx_dma_progress
= 1;
818 status
= lv1_net_start_tx_dma(bus_id(card
), dev_id(card
),
821 dev_info(ctodev(card
), "lv1_net_start_txdma failed," \
822 "status=%d\n", status
);
828 * gelic_net_xmit - transmits a frame over the device
829 * @skb: packet to send out
830 * @netdev: interface device structure
832 * returns 0 on success, <0 on failure
834 int gelic_net_xmit(struct sk_buff
*skb
, struct net_device
*netdev
)
836 struct gelic_card
*card
= netdev_card(netdev
);
837 struct gelic_descr
*descr
;
841 spin_lock_irqsave(&card
->tx_lock
, flags
);
843 gelic_card_release_tx_chain(card
, 0);
845 descr
= gelic_card_get_next_tx_descr(card
);
848 * no more descriptors free
850 gelic_card_stop_queues(card
);
851 spin_unlock_irqrestore(&card
->tx_lock
, flags
);
852 return NETDEV_TX_BUSY
;
855 result
= gelic_descr_prepare_tx(card
, descr
, skb
);
858 * DMA map failed. As chanses are that failure
859 * would continue, just release skb and return
861 netdev
->stats
.tx_dropped
++;
862 dev_kfree_skb_any(skb
);
863 spin_unlock_irqrestore(&card
->tx_lock
, flags
);
867 * link this prepared descriptor to previous one
868 * to achieve high performance
870 descr
->prev
->next_descr_addr
= cpu_to_be32(descr
->bus_addr
);
872 * as hardware descriptor is modified in the above lines,
873 * ensure that the hardware sees it
876 if (gelic_card_kick_txdma(card
, descr
)) {
879 * release descriptors which were just prepared
881 netdev
->stats
.tx_dropped
++;
882 gelic_descr_release_tx(card
, descr
);
883 gelic_descr_release_tx(card
, descr
->next
);
884 card
->tx_chain
.tail
= descr
->next
->next
;
885 dev_info(ctodev(card
), "%s: kick failure\n", __func__
);
887 /* OK, DMA started/reserved */
888 netdev
->trans_start
= jiffies
;
891 spin_unlock_irqrestore(&card
->tx_lock
, flags
);
896 * gelic_net_pass_skb_up - takes an skb from a descriptor and passes it on
897 * @descr: descriptor to process
898 * @card: card structure
899 * @netdev: net_device structure to be passed packet
901 * iommu-unmaps the skb, fills out skb structure and passes the data to the
902 * stack. The descriptor state is not changed.
904 static void gelic_net_pass_skb_up(struct gelic_descr
*descr
,
905 struct gelic_card
*card
,
906 struct net_device
*netdev
)
909 struct sk_buff
*skb
= descr
->skb
;
910 u32 data_status
, data_error
;
912 data_status
= be32_to_cpu(descr
->data_status
);
913 data_error
= be32_to_cpu(descr
->data_error
);
914 /* unmap skb buffer */
915 dma_unmap_single(ctodev(card
), be32_to_cpu(descr
->buf_addr
),
919 skb_put(skb
, be32_to_cpu(descr
->valid_size
)?
920 be32_to_cpu(descr
->valid_size
) :
921 be32_to_cpu(descr
->result_size
));
922 if (!descr
->valid_size
)
923 dev_info(ctodev(card
), "buffer full %x %x %x\n",
924 be32_to_cpu(descr
->result_size
),
925 be32_to_cpu(descr
->buf_size
),
926 be32_to_cpu(descr
->dmac_cmd_status
));
930 * the card put 2 bytes vlan tag in front
931 * of the ethernet frame
934 skb
->protocol
= eth_type_trans(skb
, netdev
);
936 /* checksum offload */
938 if ((data_status
& GELIC_DESCR_DATA_STATUS_CHK_MASK
) &&
939 (!(data_error
& GELIC_DESCR_DATA_ERROR_CHK_MASK
)))
940 skb
->ip_summed
= CHECKSUM_UNNECESSARY
;
942 skb
->ip_summed
= CHECKSUM_NONE
;
944 skb
->ip_summed
= CHECKSUM_NONE
;
946 /* update netdevice statistics */
947 netdev
->stats
.rx_packets
++;
948 netdev
->stats
.rx_bytes
+= skb
->len
;
950 /* pass skb up to stack */
951 netif_receive_skb(skb
);
955 * gelic_card_decode_one_descr - processes an rx descriptor
956 * @card: card structure
958 * returns 1 if a packet has been sent to the stack, otherwise 0
960 * processes an rx descriptor by iommu-unmapping the data buffer and passing
961 * the packet up to the stack
963 static int gelic_card_decode_one_descr(struct gelic_card
*card
)
965 enum gelic_descr_dma_status status
;
966 struct gelic_descr_chain
*chain
= &card
->rx_chain
;
967 struct gelic_descr
*descr
= chain
->head
;
968 struct net_device
*netdev
= NULL
;
969 int dmac_chain_ended
;
971 status
= gelic_descr_get_status(descr
);
972 /* is this descriptor terminated with next_descr == NULL? */
974 be32_to_cpu(descr
->dmac_cmd_status
) &
975 GELIC_DESCR_RX_DMA_CHAIN_END
;
977 if (status
== GELIC_DESCR_DMA_CARDOWNED
)
980 if (status
== GELIC_DESCR_DMA_NOT_IN_USE
) {
981 dev_dbg(ctodev(card
), "dormant descr? %p\n", descr
);
985 /* netdevice select */
986 if (card
->vlan_required
) {
989 vid
= *(u16
*)(descr
->skb
->data
) & VLAN_VID_MASK
;
990 for (i
= 0; i
< GELIC_PORT_MAX
; i
++) {
991 if (card
->vlan
[i
].rx
== vid
) {
992 netdev
= card
->netdev
[i
];
996 if (GELIC_PORT_MAX
<= i
) {
997 pr_info("%s: unknown packet vid=%x\n", __func__
, vid
);
1001 netdev
= card
->netdev
[GELIC_PORT_ETHERNET
];
1003 if ((status
== GELIC_DESCR_DMA_RESPONSE_ERROR
) ||
1004 (status
== GELIC_DESCR_DMA_PROTECTION_ERROR
) ||
1005 (status
== GELIC_DESCR_DMA_FORCE_END
)) {
1006 dev_info(ctodev(card
), "dropping RX descriptor with state %x\n",
1008 netdev
->stats
.rx_dropped
++;
1012 if (status
== GELIC_DESCR_DMA_BUFFER_FULL
) {
1014 * Buffer full would occur if and only if
1015 * the frame length was longer than the size of this
1016 * descriptor's buffer. If the frame length was equal
1017 * to or shorter than buffer'size, FRAME_END condition
1019 * Anyway this frame was longer than the MTU,
1022 dev_info(ctodev(card
), "overlength frame\n");
1026 * descriptoers any other than FRAME_END here should
1027 * be treated as error.
1029 if (status
!= GELIC_DESCR_DMA_FRAME_END
) {
1030 dev_dbg(ctodev(card
), "RX descriptor with state %x\n",
1035 /* ok, we've got a packet in descr */
1036 gelic_net_pass_skb_up(descr
, card
, netdev
);
1039 * So that always DMAC can see the end
1040 * of the descriptor chain to avoid
1041 * from unwanted DMAC overrun.
1043 descr
->next_descr_addr
= 0;
1045 /* change the descriptor state: */
1046 gelic_descr_set_status(descr
, GELIC_DESCR_DMA_NOT_IN_USE
);
1049 * this call can fail, but for now, just leave this
1050 * decriptor without skb
1052 gelic_descr_prepare_rx(card
, descr
);
1054 chain
->tail
= descr
;
1055 chain
->head
= descr
->next
;
1058 * Set this descriptor the end of the chain.
1060 descr
->prev
->next_descr_addr
= cpu_to_be32(descr
->bus_addr
);
1063 * If dmac chain was met, DMAC stopped.
1066 if (dmac_chain_ended
) {
1067 card
->rx_dma_restart_required
= 1;
1068 dev_dbg(ctodev(card
), "reenable rx dma scheduled\n");
1075 * gelic_net_poll - NAPI poll function called by the stack to return packets
1076 * @napi: napi structure
1077 * @budget: number of packets we can pass to the stack at most
1079 * returns the number of the processed packets
1082 static int gelic_net_poll(struct napi_struct
*napi
, int budget
)
1084 struct gelic_card
*card
= container_of(napi
, struct gelic_card
, napi
);
1085 int packets_done
= 0;
1087 while (packets_done
< budget
) {
1088 if (!gelic_card_decode_one_descr(card
))
1094 if (packets_done
< budget
) {
1095 napi_complete(napi
);
1096 gelic_card_rx_irq_on(card
);
1098 return packets_done
;
1101 * gelic_net_change_mtu - changes the MTU of an interface
1102 * @netdev: interface device structure
1103 * @new_mtu: new MTU value
1105 * returns 0 on success, <0 on failure
1107 int gelic_net_change_mtu(struct net_device
*netdev
, int new_mtu
)
1109 /* no need to re-alloc skbs or so -- the max mtu is about 2.3k
1110 * and mtu is outbound only anyway */
1111 if ((new_mtu
< GELIC_NET_MIN_MTU
) ||
1112 (new_mtu
> GELIC_NET_MAX_MTU
)) {
1115 netdev
->mtu
= new_mtu
;
1120 * gelic_card_interrupt - event handler for gelic_net
1122 static irqreturn_t
gelic_card_interrupt(int irq
, void *ptr
)
1124 unsigned long flags
;
1125 struct gelic_card
*card
= ptr
;
1128 status
= card
->irq_status
;
1133 status
&= card
->irq_mask
;
1135 if (card
->rx_dma_restart_required
) {
1136 card
->rx_dma_restart_required
= 0;
1137 gelic_card_enable_rxdmac(card
);
1140 if (status
& GELIC_CARD_RXINT
) {
1141 gelic_card_rx_irq_off(card
);
1142 napi_schedule(&card
->napi
);
1145 if (status
& GELIC_CARD_TXINT
) {
1146 spin_lock_irqsave(&card
->tx_lock
, flags
);
1147 card
->tx_dma_progress
= 0;
1148 gelic_card_release_tx_chain(card
, 0);
1149 /* kick outstanding tx descriptor if any */
1150 gelic_card_kick_txdma(card
, card
->tx_chain
.tail
);
1151 spin_unlock_irqrestore(&card
->tx_lock
, flags
);
1154 /* ether port status changed */
1155 if (status
& GELIC_CARD_PORT_STATUS_CHANGED
)
1156 gelic_card_get_ether_port_status(card
, 1);
1158 #ifdef CONFIG_GELIC_WIRELESS
1159 if (status
& (GELIC_CARD_WLAN_EVENT_RECEIVED
|
1160 GELIC_CARD_WLAN_COMMAND_COMPLETED
))
1161 gelic_wl_interrupt(card
->netdev
[GELIC_PORT_WIRELESS
], status
);
1167 #ifdef CONFIG_NET_POLL_CONTROLLER
1169 * gelic_net_poll_controller - artificial interrupt for netconsole etc.
1170 * @netdev: interface device structure
1172 * see Documentation/networking/netconsole.txt
1174 void gelic_net_poll_controller(struct net_device
*netdev
)
1176 struct gelic_card
*card
= netdev_card(netdev
);
1178 gelic_card_set_irq_mask(card
, 0);
1179 gelic_card_interrupt(netdev
->irq
, netdev
);
1180 gelic_card_set_irq_mask(card
, card
->irq_mask
);
1182 #endif /* CONFIG_NET_POLL_CONTROLLER */
1185 * gelic_net_open - called upon ifonfig up
1186 * @netdev: interface device structure
1188 * returns 0 on success, <0 on failure
1190 * gelic_net_open allocates all the descriptors and memory needed for
1191 * operation, sets up multicast list and enables interrupts
1193 int gelic_net_open(struct net_device
*netdev
)
1195 struct gelic_card
*card
= netdev_card(netdev
);
1197 dev_dbg(ctodev(card
), " -> %s %p\n", __func__
, netdev
);
1199 gelic_card_up(card
);
1201 netif_start_queue(netdev
);
1202 gelic_card_get_ether_port_status(card
, 1);
1204 dev_dbg(ctodev(card
), " <- %s\n", __func__
);
1208 void gelic_net_get_drvinfo(struct net_device
*netdev
,
1209 struct ethtool_drvinfo
*info
)
1211 strncpy(info
->driver
, DRV_NAME
, sizeof(info
->driver
) - 1);
1212 strncpy(info
->version
, DRV_VERSION
, sizeof(info
->version
) - 1);
1215 static int gelic_ether_get_settings(struct net_device
*netdev
,
1216 struct ethtool_cmd
*cmd
)
1218 struct gelic_card
*card
= netdev_card(netdev
);
1220 gelic_card_get_ether_port_status(card
, 0);
1222 if (card
->ether_port_status
& GELIC_LV1_ETHER_FULL_DUPLEX
)
1223 cmd
->duplex
= DUPLEX_FULL
;
1225 cmd
->duplex
= DUPLEX_HALF
;
1227 switch (card
->ether_port_status
& GELIC_LV1_ETHER_SPEED_MASK
) {
1228 case GELIC_LV1_ETHER_SPEED_10
:
1229 cmd
->speed
= SPEED_10
;
1231 case GELIC_LV1_ETHER_SPEED_100
:
1232 cmd
->speed
= SPEED_100
;
1234 case GELIC_LV1_ETHER_SPEED_1000
:
1235 cmd
->speed
= SPEED_1000
;
1238 pr_info("%s: speed unknown\n", __func__
);
1239 cmd
->speed
= SPEED_10
;
1243 cmd
->supported
= SUPPORTED_TP
| SUPPORTED_Autoneg
|
1244 SUPPORTED_10baseT_Half
| SUPPORTED_10baseT_Full
|
1245 SUPPORTED_100baseT_Half
| SUPPORTED_100baseT_Full
|
1246 SUPPORTED_1000baseT_Half
| SUPPORTED_1000baseT_Full
;
1247 cmd
->advertising
= cmd
->supported
;
1248 cmd
->autoneg
= AUTONEG_ENABLE
; /* always enabled */
1249 cmd
->port
= PORT_TP
;
1254 u32
gelic_net_get_rx_csum(struct net_device
*netdev
)
1256 struct gelic_card
*card
= netdev_card(netdev
);
1258 return card
->rx_csum
;
1261 int gelic_net_set_rx_csum(struct net_device
*netdev
, u32 data
)
1263 struct gelic_card
*card
= netdev_card(netdev
);
1265 card
->rx_csum
= data
;
1269 static void gelic_net_get_wol(struct net_device
*netdev
,
1270 struct ethtool_wolinfo
*wol
)
1272 if (0 <= ps3_compare_firmware_version(2, 2, 0))
1273 wol
->supported
= WAKE_MAGIC
;
1277 wol
->wolopts
= ps3_sys_manager_get_wol() ? wol
->supported
: 0;
1278 memset(&wol
->sopass
, 0, sizeof(wol
->sopass
));
1280 static int gelic_net_set_wol(struct net_device
*netdev
,
1281 struct ethtool_wolinfo
*wol
)
1284 struct gelic_card
*card
;
1287 if (ps3_compare_firmware_version(2, 2, 0) < 0 ||
1288 !capable(CAP_NET_ADMIN
))
1291 if (wol
->wolopts
& ~WAKE_MAGIC
)
1294 card
= netdev_card(netdev
);
1295 if (wol
->wolopts
& WAKE_MAGIC
) {
1296 status
= lv1_net_control(bus_id(card
), dev_id(card
),
1298 GELIC_LV1_WOL_MAGIC_PACKET
,
1299 0, GELIC_LV1_WOL_MP_ENABLE
,
1302 pr_info("%s: enabling WOL failed %d\n", __func__
,
1307 status
= lv1_net_control(bus_id(card
), dev_id(card
),
1309 GELIC_LV1_WOL_ADD_MATCH_ADDR
,
1310 0, GELIC_LV1_WOL_MATCH_ALL
,
1313 ps3_sys_manager_set_wol(1);
1315 pr_info("%s: enabling WOL filter failed %d\n",
1320 status
= lv1_net_control(bus_id(card
), dev_id(card
),
1322 GELIC_LV1_WOL_MAGIC_PACKET
,
1323 0, GELIC_LV1_WOL_MP_DISABLE
,
1326 pr_info("%s: disabling WOL failed %d\n", __func__
,
1331 status
= lv1_net_control(bus_id(card
), dev_id(card
),
1333 GELIC_LV1_WOL_DELETE_MATCH_ADDR
,
1334 0, GELIC_LV1_WOL_MATCH_ALL
,
1337 ps3_sys_manager_set_wol(0);
1339 pr_info("%s: removing WOL filter failed %d\n",
1348 static struct ethtool_ops gelic_ether_ethtool_ops
= {
1349 .get_drvinfo
= gelic_net_get_drvinfo
,
1350 .get_settings
= gelic_ether_get_settings
,
1351 .get_link
= ethtool_op_get_link
,
1352 .get_tx_csum
= ethtool_op_get_tx_csum
,
1353 .set_tx_csum
= ethtool_op_set_tx_csum
,
1354 .get_rx_csum
= gelic_net_get_rx_csum
,
1355 .set_rx_csum
= gelic_net_set_rx_csum
,
1356 .get_wol
= gelic_net_get_wol
,
1357 .set_wol
= gelic_net_set_wol
,
1361 * gelic_net_tx_timeout_task - task scheduled by the watchdog timeout
1362 * function (to be called not under interrupt status)
1363 * @work: work is context of tx timout task
1365 * called as task when tx hangs, resets interface (if interface is up)
1367 static void gelic_net_tx_timeout_task(struct work_struct
*work
)
1369 struct gelic_card
*card
=
1370 container_of(work
, struct gelic_card
, tx_timeout_task
);
1371 struct net_device
*netdev
= card
->netdev
[GELIC_PORT_ETHERNET
];
1373 dev_info(ctodev(card
), "%s:Timed out. Restarting... \n", __func__
);
1375 if (!(netdev
->flags
& IFF_UP
))
1378 netif_device_detach(netdev
);
1379 gelic_net_stop(netdev
);
1381 gelic_net_open(netdev
);
1382 netif_device_attach(netdev
);
1385 atomic_dec(&card
->tx_timeout_task_counter
);
1389 * gelic_net_tx_timeout - called when the tx timeout watchdog kicks in.
1390 * @netdev: interface device structure
1392 * called, if tx hangs. Schedules a task that resets the interface
1394 void gelic_net_tx_timeout(struct net_device
*netdev
)
1396 struct gelic_card
*card
;
1398 card
= netdev_card(netdev
);
1399 atomic_inc(&card
->tx_timeout_task_counter
);
1400 if (netdev
->flags
& IFF_UP
)
1401 schedule_work(&card
->tx_timeout_task
);
1403 atomic_dec(&card
->tx_timeout_task_counter
);
1407 * gelic_ether_setup_netdev_ops - initialization of net_device operations
1408 * @netdev: net_device structure
1410 * fills out function pointers in the net_device structure
1412 static void gelic_ether_setup_netdev_ops(struct net_device
*netdev
,
1413 struct napi_struct
*napi
)
1415 netdev
->open
= &gelic_net_open
;
1416 netdev
->stop
= &gelic_net_stop
;
1417 netdev
->hard_start_xmit
= &gelic_net_xmit
;
1418 netdev
->set_multicast_list
= &gelic_net_set_multi
;
1419 netdev
->change_mtu
= &gelic_net_change_mtu
;
1421 netdev
->tx_timeout
= &gelic_net_tx_timeout
;
1422 netdev
->watchdog_timeo
= GELIC_NET_WATCHDOG_TIMEOUT
;
1424 netif_napi_add(netdev
, napi
,
1425 gelic_net_poll
, GELIC_NET_NAPI_WEIGHT
);
1426 netdev
->ethtool_ops
= &gelic_ether_ethtool_ops
;
1427 #ifdef CONFIG_NET_POLL_CONTROLLER
1428 netdev
->poll_controller
= gelic_net_poll_controller
;
1433 * gelic_ether_setup_netdev - initialization of net_device
1434 * @netdev: net_device structure
1435 * @card: card structure
1437 * Returns 0 on success or <0 on failure
1439 * gelic_ether_setup_netdev initializes the net_device structure
1442 int gelic_net_setup_netdev(struct net_device
*netdev
, struct gelic_card
*card
)
1447 netdev
->features
= NETIF_F_IP_CSUM
;
1449 status
= lv1_net_control(bus_id(card
), dev_id(card
),
1450 GELIC_LV1_GET_MAC_ADDRESS
,
1453 if (status
|| !is_valid_ether_addr((u8
*)&v1
)) {
1454 dev_info(ctodev(card
),
1455 "%s:lv1_net_control GET_MAC_ADDR failed %d\n",
1459 memcpy(netdev
->dev_addr
, &v1
, ETH_ALEN
);
1461 if (card
->vlan_required
) {
1462 netdev
->hard_header_len
+= VLAN_HLEN
;
1464 * As vlan is internally used,
1465 * we can not receive vlan packets
1467 netdev
->features
|= NETIF_F_VLAN_CHALLENGED
;
1470 status
= register_netdev(netdev
);
1472 dev_err(ctodev(card
), "%s:Couldn't register %s %d\n",
1473 __func__
, netdev
->name
, status
);
1476 dev_info(ctodev(card
), "%s: MAC addr %pM\n",
1477 netdev
->name
, netdev
->dev_addr
);
1483 * gelic_alloc_card_net - allocates net_device and card structure
1485 * returns the card structure or NULL in case of errors
1487 * the card and net_device structures are linked to each other
1489 #define GELIC_ALIGN (32)
1490 static struct gelic_card
*gelic_alloc_card_net(struct net_device
**netdev
)
1492 struct gelic_card
*card
;
1493 struct gelic_port
*port
;
1497 * gelic requires dma descriptor is 32 bytes aligned and
1498 * the hypervisor requires irq_status is 8 bytes aligned.
1500 BUILD_BUG_ON(offsetof(struct gelic_card
, irq_status
) % 8);
1501 BUILD_BUG_ON(offsetof(struct gelic_card
, descr
) % 32);
1503 sizeof(struct gelic_card
) +
1504 sizeof(struct gelic_descr
) * GELIC_NET_RX_DESCRIPTORS
+
1505 sizeof(struct gelic_descr
) * GELIC_NET_TX_DESCRIPTORS
+
1508 p
= kzalloc(alloc_size
, GFP_KERNEL
);
1511 card
= PTR_ALIGN(p
, GELIC_ALIGN
);
1517 *netdev
= alloc_etherdev(sizeof(struct gelic_port
));
1519 kfree(card
->unalign
);
1522 port
= netdev_priv(*netdev
);
1525 port
->netdev
= *netdev
;
1527 port
->type
= GELIC_PORT_ETHERNET
;
1530 card
->netdev
[GELIC_PORT_ETHERNET
] = *netdev
;
1532 INIT_WORK(&card
->tx_timeout_task
, gelic_net_tx_timeout_task
);
1533 init_waitqueue_head(&card
->waitq
);
1534 atomic_set(&card
->tx_timeout_task_counter
, 0);
1535 mutex_init(&card
->updown_lock
);
1536 atomic_set(&card
->users
, 0);
1541 static void gelic_card_get_vlan_info(struct gelic_card
*card
)
1550 [GELIC_PORT_ETHERNET
] = {
1551 .tx
= GELIC_LV1_VLAN_TX_ETHERNET
,
1552 .rx
= GELIC_LV1_VLAN_RX_ETHERNET
1554 [GELIC_PORT_WIRELESS
] = {
1555 .tx
= GELIC_LV1_VLAN_TX_WIRELESS
,
1556 .rx
= GELIC_LV1_VLAN_RX_WIRELESS
1560 for (i
= 0; i
< ARRAY_SIZE(vlan_id_ix
); i
++) {
1562 status
= lv1_net_control(bus_id(card
), dev_id(card
),
1563 GELIC_LV1_GET_VLAN_ID
,
1566 if (status
|| !v1
) {
1567 if (status
!= LV1_NO_ENTRY
)
1568 dev_dbg(ctodev(card
),
1569 "get vlan id for tx(%d) failed(%d)\n",
1570 vlan_id_ix
[i
].tx
, status
);
1571 card
->vlan
[i
].tx
= 0;
1572 card
->vlan
[i
].rx
= 0;
1575 card
->vlan
[i
].tx
= (u16
)v1
;
1578 status
= lv1_net_control(bus_id(card
), dev_id(card
),
1579 GELIC_LV1_GET_VLAN_ID
,
1582 if (status
|| !v1
) {
1583 if (status
!= LV1_NO_ENTRY
)
1584 dev_info(ctodev(card
),
1585 "get vlan id for rx(%d) failed(%d)\n",
1586 vlan_id_ix
[i
].rx
, status
);
1587 card
->vlan
[i
].tx
= 0;
1588 card
->vlan
[i
].rx
= 0;
1591 card
->vlan
[i
].rx
= (u16
)v1
;
1593 dev_dbg(ctodev(card
), "vlan_id[%d] tx=%02x rx=%02x\n",
1594 i
, card
->vlan
[i
].tx
, card
->vlan
[i
].rx
);
1597 if (card
->vlan
[GELIC_PORT_ETHERNET
].tx
) {
1598 BUG_ON(!card
->vlan
[GELIC_PORT_WIRELESS
].tx
);
1599 card
->vlan_required
= 1;
1601 card
->vlan_required
= 0;
1603 /* check wirelss capable firmware */
1604 if (ps3_compare_firmware_version(1, 6, 0) < 0) {
1605 card
->vlan
[GELIC_PORT_WIRELESS
].tx
= 0;
1606 card
->vlan
[GELIC_PORT_WIRELESS
].rx
= 0;
1609 dev_info(ctodev(card
), "internal vlan %s\n",
1610 card
->vlan_required
? "enabled" : "disabled");
1613 * ps3_gelic_driver_probe - add a device to the control of this driver
1615 static int ps3_gelic_driver_probe(struct ps3_system_bus_device
*dev
)
1617 struct gelic_card
*card
;
1618 struct net_device
*netdev
;
1621 pr_debug("%s: called\n", __func__
);
1622 result
= ps3_open_hv_device(dev
);
1625 dev_dbg(&dev
->core
, "%s:ps3_open_hv_device failed\n",
1630 result
= ps3_dma_region_create(dev
->d_region
);
1633 dev_dbg(&dev
->core
, "%s:ps3_dma_region_create failed(%d)\n",
1635 BUG_ON("check region type");
1636 goto fail_dma_region
;
1639 /* alloc card/netdevice */
1640 card
= gelic_alloc_card_net(&netdev
);
1642 dev_info(&dev
->core
, "%s:gelic_net_alloc_card failed\n",
1645 goto fail_alloc_card
;
1647 ps3_system_bus_set_driver_data(dev
, card
);
1650 /* get internal vlan info */
1651 gelic_card_get_vlan_info(card
);
1653 /* setup interrupt */
1654 result
= lv1_net_set_interrupt_status_indicator(bus_id(card
),
1656 ps3_mm_phys_to_lpar(__pa(&card
->irq_status
)),
1661 "%s:set_interrupt_status_indicator failed: %s\n",
1662 __func__
, ps3_result(result
));
1664 goto fail_status_indicator
;
1667 result
= ps3_sb_event_receive_port_setup(dev
, PS3_BINDING_CPU_ANY
,
1671 dev_info(ctodev(card
),
1672 "%s:gelic_net_open_device failed (%d)\n",
1675 goto fail_alloc_irq
;
1677 result
= request_irq(card
->irq
, gelic_card_interrupt
,
1678 IRQF_DISABLED
, netdev
->name
, card
);
1681 dev_info(ctodev(card
), "%s:request_irq failed (%d)\n",
1683 goto fail_request_irq
;
1686 /* setup card structure */
1687 card
->irq_mask
= GELIC_CARD_RXINT
| GELIC_CARD_TXINT
|
1688 GELIC_CARD_PORT_STATUS_CHANGED
;
1689 card
->rx_csum
= GELIC_CARD_RX_CSUM_DEFAULT
;
1692 if (gelic_card_init_chain(card
, &card
->tx_chain
,
1693 card
->descr
, GELIC_NET_TX_DESCRIPTORS
))
1695 if (gelic_card_init_chain(card
, &card
->rx_chain
,
1696 card
->descr
+ GELIC_NET_TX_DESCRIPTORS
,
1697 GELIC_NET_RX_DESCRIPTORS
))
1701 card
->tx_top
= card
->tx_chain
.head
;
1702 card
->rx_top
= card
->rx_chain
.head
;
1703 dev_dbg(ctodev(card
), "descr rx %p, tx %p, size %#lx, num %#x\n",
1704 card
->rx_top
, card
->tx_top
, sizeof(struct gelic_descr
),
1705 GELIC_NET_RX_DESCRIPTORS
);
1706 /* allocate rx skbs */
1707 if (gelic_card_alloc_rx_skbs(card
))
1708 goto fail_alloc_skbs
;
1710 spin_lock_init(&card
->tx_lock
);
1711 card
->tx_dma_progress
= 0;
1713 /* setup net_device structure */
1714 netdev
->irq
= card
->irq
;
1715 SET_NETDEV_DEV(netdev
, &card
->dev
->core
);
1716 gelic_ether_setup_netdev_ops(netdev
, &card
->napi
);
1717 result
= gelic_net_setup_netdev(netdev
, card
);
1719 dev_dbg(&dev
->core
, "%s: setup_netdev failed %d",
1721 goto fail_setup_netdev
;
1724 #ifdef CONFIG_GELIC_WIRELESS
1725 if (gelic_wl_driver_probe(card
)) {
1726 dev_dbg(&dev
->core
, "%s: WL init failed\n", __func__
);
1727 goto fail_setup_netdev
;
1730 pr_debug("%s: done\n", __func__
);
1735 gelic_card_free_chain(card
, card
->rx_chain
.head
);
1737 gelic_card_free_chain(card
, card
->tx_chain
.head
);
1739 free_irq(card
->irq
, card
);
1740 netdev
->irq
= NO_IRQ
;
1742 ps3_sb_event_receive_port_destroy(dev
, card
->irq
);
1744 lv1_net_set_interrupt_status_indicator(bus_id(card
),
1747 fail_status_indicator
:
1748 ps3_system_bus_set_driver_data(dev
, NULL
);
1749 kfree(netdev_card(netdev
)->unalign
);
1750 free_netdev(netdev
);
1752 ps3_dma_region_free(dev
->d_region
);
1754 ps3_close_hv_device(dev
);
1760 * ps3_gelic_driver_remove - remove a device from the control of this driver
1763 static int ps3_gelic_driver_remove(struct ps3_system_bus_device
*dev
)
1765 struct gelic_card
*card
= ps3_system_bus_get_driver_data(dev
);
1766 struct net_device
*netdev0
;
1767 pr_debug("%s: called\n", __func__
);
1769 #ifdef CONFIG_GELIC_WIRELESS
1770 gelic_wl_driver_remove(card
);
1772 /* stop interrupt */
1773 gelic_card_set_irq_mask(card
, 0);
1775 /* turn off DMA, force end */
1776 gelic_card_disable_rxdmac(card
);
1777 gelic_card_disable_txdmac(card
);
1779 /* release chains */
1780 gelic_card_release_tx_chain(card
, 1);
1781 gelic_card_release_rx_chain(card
);
1783 gelic_card_free_chain(card
, card
->tx_top
);
1784 gelic_card_free_chain(card
, card
->rx_top
);
1786 netdev0
= card
->netdev
[GELIC_PORT_ETHERNET
];
1787 /* disconnect event port */
1788 free_irq(card
->irq
, card
);
1789 netdev0
->irq
= NO_IRQ
;
1790 ps3_sb_event_receive_port_destroy(card
->dev
, card
->irq
);
1792 wait_event(card
->waitq
,
1793 atomic_read(&card
->tx_timeout_task_counter
) == 0);
1795 lv1_net_set_interrupt_status_indicator(bus_id(card
), dev_id(card
),
1798 unregister_netdev(netdev0
);
1799 kfree(netdev_card(netdev0
)->unalign
);
1800 free_netdev(netdev0
);
1802 ps3_system_bus_set_driver_data(dev
, NULL
);
1804 ps3_dma_region_free(dev
->d_region
);
1806 ps3_close_hv_device(dev
);
1808 pr_debug("%s: done\n", __func__
);
1812 static struct ps3_system_bus_driver ps3_gelic_driver
= {
1813 .match_id
= PS3_MATCH_ID_GELIC
,
1814 .probe
= ps3_gelic_driver_probe
,
1815 .remove
= ps3_gelic_driver_remove
,
1816 .shutdown
= ps3_gelic_driver_remove
,
1817 .core
.name
= "ps3_gelic_driver",
1818 .core
.owner
= THIS_MODULE
,
1821 static int __init
ps3_gelic_driver_init (void)
1823 return firmware_has_feature(FW_FEATURE_PS3_LV1
)
1824 ? ps3_system_bus_driver_register(&ps3_gelic_driver
)
1828 static void __exit
ps3_gelic_driver_exit (void)
1830 ps3_system_bus_driver_unregister(&ps3_gelic_driver
);
1833 module_init(ps3_gelic_driver_init
);
1834 module_exit(ps3_gelic_driver_exit
);
1836 MODULE_ALIAS(PS3_MODULE_ALIAS_GELIC
);