blob: c9dd9c0ee22b8d310eba8e7a7c7e96134dc793a0 [file] [log] [blame]
Masakazu Mokuno02c18892007-07-05 20:11:16 +09001/*
2 * PS3 gelic network driver.
3 *
4 * Copyright (C) 2007 Sony Computer Entertainment Inc.
5 * Copyright 2006, 2007 Sony Corporation
6 *
7 * This file is based on: spider_net.c
8 *
9 * (C) Copyright IBM Corp. 2005
10 *
11 * Authors : Utz Bacher <utz.bacher@de.ibm.com>
12 * Jens Osterkamp <Jens.Osterkamp@de.ibm.com>
13 *
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)
17 * any later version.
18 *
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.
23 *
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.
27 */
28
29#undef DEBUG
30
31#include <linux/kernel.h>
32#include <linux/module.h>
33
34#include <linux/etherdevice.h>
35#include <linux/ethtool.h>
36#include <linux/if_vlan.h>
37
38#include <linux/in.h>
39#include <linux/ip.h>
40#include <linux/tcp.h>
41
42#include <linux/dma-mapping.h>
43#include <net/checksum.h>
44#include <asm/firmware.h>
45#include <asm/ps3.h>
46#include <asm/lv1call.h>
47
48#include "ps3_gelic_net.h"
49
50#define DRV_NAME "Gelic Network Driver"
Masakazu Mokuno589866f2008-02-07 19:58:42 +090051#define DRV_VERSION "1.1"
Masakazu Mokuno02c18892007-07-05 20:11:16 +090052
53MODULE_AUTHOR("SCE Inc.");
54MODULE_DESCRIPTION("Gelic Network driver");
55MODULE_LICENSE("GPL");
56
Masakazu Mokuno589866f2008-02-07 19:58:42 +090057
58static inline void gelic_card_enable_rxdmac(struct gelic_card *card);
59static inline void gelic_card_disable_rxdmac(struct gelic_card *card);
60static inline void gelic_card_disable_txdmac(struct gelic_card *card);
61static inline void gelic_card_reset_chain(struct gelic_card *card,
62 struct gelic_descr_chain *chain,
63 struct gelic_descr *start_descr);
Masakazu Mokuno02c18892007-07-05 20:11:16 +090064
65/* set irq_mask */
Masakazu Mokuno589866f2008-02-07 19:58:42 +090066int gelic_card_set_irq_mask(struct gelic_card *card, u64 mask)
Masakazu Mokuno02c18892007-07-05 20:11:16 +090067{
68 int status;
69
70 status = lv1_net_set_interrupt_mask(bus_id(card), dev_id(card),
71 mask, 0);
72 if (status)
73 dev_info(ctodev(card),
Masakazu Mokuno589866f2008-02-07 19:58:42 +090074 "%s failed %d\n", __func__, status);
Masakazu Mokuno02c18892007-07-05 20:11:16 +090075 return status;
76}
Masakazu Mokuno589866f2008-02-07 19:58:42 +090077
Masakazu Mokuno59e97322008-02-07 19:58:08 +090078static inline void gelic_card_rx_irq_on(struct gelic_card *card)
Masakazu Mokuno02c18892007-07-05 20:11:16 +090079{
Masakazu Mokuno589866f2008-02-07 19:58:42 +090080 card->irq_mask |= GELIC_CARD_RXINT;
81 gelic_card_set_irq_mask(card, card->irq_mask);
Masakazu Mokuno02c18892007-07-05 20:11:16 +090082}
Masakazu Mokuno59e97322008-02-07 19:58:08 +090083static inline void gelic_card_rx_irq_off(struct gelic_card *card)
Masakazu Mokuno02c18892007-07-05 20:11:16 +090084{
Masakazu Mokuno589866f2008-02-07 19:58:42 +090085 card->irq_mask &= ~GELIC_CARD_RXINT;
86 gelic_card_set_irq_mask(card, card->irq_mask);
Masakazu Mokuno02c18892007-07-05 20:11:16 +090087}
Masakazu Mokuno01fed4c2008-02-07 19:58:32 +090088
Masakazu Mokuno589866f2008-02-07 19:58:42 +090089static void gelic_card_get_ether_port_status(struct gelic_card *card,
90 int inform)
Masakazu Mokuno01fed4c2008-02-07 19:58:32 +090091{
92 u64 v2;
93 struct net_device *ether_netdev;
94
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);
99
100 if (inform) {
Masakazu Mokuno589866f2008-02-07 19:58:42 +0900101 ether_netdev = card->netdev[GELIC_PORT_ETHERNET];
Masakazu Mokuno01fed4c2008-02-07 19:58:32 +0900102 if (card->ether_port_status & GELIC_LV1_ETHER_LINK_UP)
103 netif_carrier_on(ether_netdev);
104 else
105 netif_carrier_off(ether_netdev);
106 }
107}
108
Masakazu Mokuno589866f2008-02-07 19:58:42 +0900109void gelic_card_up(struct gelic_card *card)
110{
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__);
115 /* enable irq */
116 gelic_card_set_irq_mask(card, card->irq_mask);
117 /* start rx */
118 gelic_card_enable_rxdmac(card);
119
120 napi_enable(&card->napi);
121 }
122 up(&card->updown_lock);
123 pr_debug("%s: done\n", __func__);
124}
125
126void gelic_card_down(struct gelic_card *card)
127{
128 u64 mask;
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);
134 /*
135 * Disable irq. Wireless interrupts will
136 * be disabled later if any
137 */
138 mask = card->irq_mask & (GELIC_CARD_WLAN_EVENT_RECEIVED |
139 GELIC_CARD_WLAN_COMMAND_COMPLETED);
140 gelic_card_set_irq_mask(card, mask);
141 /* stop rx */
142 gelic_card_disable_rxdmac(card);
143 gelic_card_reset_chain(card, &card->rx_chain,
144 card->descr + GELIC_NET_TX_DESCRIPTORS);
145 /* stop tx */
146 gelic_card_disable_txdmac(card);
147 }
148 up(&card->updown_lock);
149 pr_debug("%s: done\n", __func__);
150}
Masakazu Mokuno01fed4c2008-02-07 19:58:32 +0900151
Masakazu Mokuno02c18892007-07-05 20:11:16 +0900152/**
Masakazu Mokuno59e97322008-02-07 19:58:08 +0900153 * gelic_descr_get_status -- returns the status of a descriptor
Masakazu Mokuno02c18892007-07-05 20:11:16 +0900154 * @descr: descriptor to look at
155 *
156 * returns the status as in the dmac_cmd_status field of the descriptor
157 */
Masakazu Mokuno59e97322008-02-07 19:58:08 +0900158static enum gelic_descr_dma_status
159gelic_descr_get_status(struct gelic_descr *descr)
Masakazu Mokuno02c18892007-07-05 20:11:16 +0900160{
Masakazu Mokuno59e97322008-02-07 19:58:08 +0900161 return be32_to_cpu(descr->dmac_cmd_status) & GELIC_DESCR_DMA_STAT_MASK;
Masakazu Mokuno02c18892007-07-05 20:11:16 +0900162}
163
164/**
Masakazu Mokuno59e97322008-02-07 19:58:08 +0900165 * gelic_descr_set_status -- sets the status of a descriptor
Masakazu Mokuno02c18892007-07-05 20:11:16 +0900166 * @descr: descriptor to change
167 * @status: status to set in the descriptor
168 *
169 * changes the status to the specified value. Doesn't change other bits
170 * in the status
171 */
Masakazu Mokuno59e97322008-02-07 19:58:08 +0900172static void gelic_descr_set_status(struct gelic_descr *descr,
173 enum gelic_descr_dma_status status)
Masakazu Mokuno02c18892007-07-05 20:11:16 +0900174{
Masakazu Mokuno59e97322008-02-07 19:58:08 +0900175 descr->dmac_cmd_status = cpu_to_be32(status |
Masakazu Mokuno589866f2008-02-07 19:58:42 +0900176 (be32_to_cpu(descr->dmac_cmd_status) &
177 ~GELIC_DESCR_DMA_STAT_MASK));
Masakazu Mokuno02c18892007-07-05 20:11:16 +0900178 /*
179 * dma_cmd_status field is used to indicate whether the descriptor
180 * is valid or not.
181 * Usually caller of this function wants to inform that to the
182 * hardware, so we assure here the hardware sees the change.
183 */
184 wmb();
185}
186
187/**
Masakazu Mokuno59e97322008-02-07 19:58:08 +0900188 * gelic_card_free_chain - free descriptor chain
Masakazu Mokuno02c18892007-07-05 20:11:16 +0900189 * @card: card structure
190 * @descr_in: address of desc
191 */
Masakazu Mokuno59e97322008-02-07 19:58:08 +0900192static void gelic_card_free_chain(struct gelic_card *card,
193 struct gelic_descr *descr_in)
Masakazu Mokuno02c18892007-07-05 20:11:16 +0900194{
Masakazu Mokuno59e97322008-02-07 19:58:08 +0900195 struct gelic_descr *descr;
Masakazu Mokuno02c18892007-07-05 20:11:16 +0900196
197 for (descr = descr_in; descr && descr->bus_addr; descr = descr->next) {
198 dma_unmap_single(ctodev(card), descr->bus_addr,
Masakazu Mokuno59e97322008-02-07 19:58:08 +0900199 GELIC_DESCR_SIZE, DMA_BIDIRECTIONAL);
Masakazu Mokuno02c18892007-07-05 20:11:16 +0900200 descr->bus_addr = 0;
201 }
202}
203
204/**
Masakazu Mokuno59e97322008-02-07 19:58:08 +0900205 * gelic_card_init_chain - links descriptor chain
Masakazu Mokuno02c18892007-07-05 20:11:16 +0900206 * @card: card structure
207 * @chain: address of chain
208 * @start_descr: address of descriptor array
209 * @no: number of descriptors
210 *
211 * we manage a circular list that mirrors the hardware structure,
212 * except that the hardware uses bus addresses.
213 *
214 * returns 0 on success, <0 on failure
215 */
Masakazu Mokuno59e97322008-02-07 19:58:08 +0900216static int gelic_card_init_chain(struct gelic_card *card,
217 struct gelic_descr_chain *chain,
218 struct gelic_descr *start_descr, int no)
Masakazu Mokuno02c18892007-07-05 20:11:16 +0900219{
220 int i;
Masakazu Mokuno59e97322008-02-07 19:58:08 +0900221 struct gelic_descr *descr;
Masakazu Mokuno02c18892007-07-05 20:11:16 +0900222
223 descr = start_descr;
224 memset(descr, 0, sizeof(*descr) * no);
225
226 /* set up the hardware pointers in each descriptor */
227 for (i = 0; i < no; i++, descr++) {
Masakazu Mokuno59e97322008-02-07 19:58:08 +0900228 gelic_descr_set_status(descr, GELIC_DESCR_DMA_NOT_IN_USE);
Masakazu Mokuno02c18892007-07-05 20:11:16 +0900229 descr->bus_addr =
230 dma_map_single(ctodev(card), descr,
Masakazu Mokuno59e97322008-02-07 19:58:08 +0900231 GELIC_DESCR_SIZE,
Masakazu Mokuno02c18892007-07-05 20:11:16 +0900232 DMA_BIDIRECTIONAL);
233
234 if (!descr->bus_addr)
235 goto iommu_error;
236
237 descr->next = descr + 1;
238 descr->prev = descr - 1;
239 }
240 /* make them as ring */
241 (descr - 1)->next = start_descr;
242 start_descr->prev = (descr - 1);
243
244 /* chain bus addr of hw descriptor */
245 descr = start_descr;
246 for (i = 0; i < no; i++, descr++) {
Masakazu Mokuno100e1d82008-02-07 19:57:54 +0900247 descr->next_descr_addr = cpu_to_be32(descr->next->bus_addr);
Masakazu Mokuno02c18892007-07-05 20:11:16 +0900248 }
249
250 chain->head = start_descr;
251 chain->tail = start_descr;
252
253 /* do not chain last hw descriptor */
254 (descr - 1)->next_descr_addr = 0;
255
256 return 0;
257
258iommu_error:
259 for (i--, descr--; 0 <= i; i--, descr--)
260 if (descr->bus_addr)
261 dma_unmap_single(ctodev(card), descr->bus_addr,
Masakazu Mokuno59e97322008-02-07 19:58:08 +0900262 GELIC_DESCR_SIZE,
Masakazu Mokuno02c18892007-07-05 20:11:16 +0900263 DMA_BIDIRECTIONAL);
264 return -ENOMEM;
265}
266
267/**
Masakazu Mokuno589866f2008-02-07 19:58:42 +0900268 * 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
272 *
273 * Reset the status of dma descriptors to ready state
274 * and re-initialize the hardware chain for later use
275 */
276static void gelic_card_reset_chain(struct gelic_card *card,
277 struct gelic_descr_chain *chain,
278 struct gelic_descr *start_descr)
279{
280 struct gelic_descr *descr;
281
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);
285 }
286
287 chain->head = start_descr;
288 chain->tail = (descr - 1);
289
290 (descr - 1)->next_descr_addr = 0;
291}
292/**
Masakazu Mokuno59e97322008-02-07 19:58:08 +0900293 * gelic_descr_prepare_rx - reinitializes a rx descriptor
Masakazu Mokuno02c18892007-07-05 20:11:16 +0900294 * @card: card structure
295 * @descr: descriptor to re-init
296 *
297 * return 0 on succes, <0 on failure
298 *
299 * allocates a new rx skb, iommu-maps it and attaches it to the descriptor.
300 * Activate the descriptor state-wise
301 */
Masakazu Mokuno59e97322008-02-07 19:58:08 +0900302static int gelic_descr_prepare_rx(struct gelic_card *card,
Masakazu Mokuno589866f2008-02-07 19:58:42 +0900303 struct gelic_descr *descr)
Masakazu Mokuno02c18892007-07-05 20:11:16 +0900304{
305 int offset;
306 unsigned int bufsize;
307
Masakazu Mokuno59e97322008-02-07 19:58:08 +0900308 if (gelic_descr_get_status(descr) != GELIC_DESCR_DMA_NOT_IN_USE)
Masakazu Mokuno02c18892007-07-05 20:11:16 +0900309 dev_info(ctodev(card), "%s: ERROR status \n", __func__);
Masakazu Mokuno02c18892007-07-05 20:11:16 +0900310 /* we need to round up the buffer size to a multiple of 128 */
311 bufsize = ALIGN(GELIC_NET_MAX_MTU, GELIC_NET_RXBUF_ALIGN);
312
313 /* and we need to have it 128 byte aligned, therefore we allocate a
314 * bit more */
Masakazu Mokuno589866f2008-02-07 19:58:42 +0900315 descr->skb = dev_alloc_skb(bufsize + GELIC_NET_RXBUF_ALIGN - 1);
Masakazu Mokuno02c18892007-07-05 20:11:16 +0900316 if (!descr->skb) {
317 descr->buf_addr = 0; /* tell DMAC don't touch memory */
318 dev_info(ctodev(card),
319 "%s:allocate skb failed !!\n", __func__);
320 return -ENOMEM;
321 }
Masakazu Mokuno100e1d82008-02-07 19:57:54 +0900322 descr->buf_size = cpu_to_be32(bufsize);
Masakazu Mokuno02c18892007-07-05 20:11:16 +0900323 descr->dmac_cmd_status = 0;
324 descr->result_size = 0;
325 descr->valid_size = 0;
326 descr->data_error = 0;
327
328 offset = ((unsigned long)descr->skb->data) &
329 (GELIC_NET_RXBUF_ALIGN - 1);
330 if (offset)
331 skb_reserve(descr->skb, GELIC_NET_RXBUF_ALIGN - offset);
332 /* io-mmu-map the skb */
Masakazu Mokuno100e1d82008-02-07 19:57:54 +0900333 descr->buf_addr = cpu_to_be32(dma_map_single(ctodev(card),
334 descr->skb->data,
335 GELIC_NET_MAX_MTU,
336 DMA_FROM_DEVICE));
Masakazu Mokuno02c18892007-07-05 20:11:16 +0900337 if (!descr->buf_addr) {
338 dev_kfree_skb_any(descr->skb);
339 descr->skb = NULL;
340 dev_info(ctodev(card),
341 "%s:Could not iommu-map rx buffer\n", __func__);
Masakazu Mokuno59e97322008-02-07 19:58:08 +0900342 gelic_descr_set_status(descr, GELIC_DESCR_DMA_NOT_IN_USE);
Masakazu Mokuno02c18892007-07-05 20:11:16 +0900343 return -ENOMEM;
344 } else {
Masakazu Mokuno59e97322008-02-07 19:58:08 +0900345 gelic_descr_set_status(descr, GELIC_DESCR_DMA_CARDOWNED);
Masakazu Mokuno02c18892007-07-05 20:11:16 +0900346 return 0;
347 }
348}
349
350/**
Masakazu Mokuno59e97322008-02-07 19:58:08 +0900351 * gelic_card_release_rx_chain - free all skb of rx descr
Masakazu Mokuno02c18892007-07-05 20:11:16 +0900352 * @card: card structure
353 *
354 */
Masakazu Mokuno59e97322008-02-07 19:58:08 +0900355static void gelic_card_release_rx_chain(struct gelic_card *card)
Masakazu Mokuno02c18892007-07-05 20:11:16 +0900356{
Masakazu Mokuno59e97322008-02-07 19:58:08 +0900357 struct gelic_descr *descr = card->rx_chain.head;
Masakazu Mokuno02c18892007-07-05 20:11:16 +0900358
359 do {
360 if (descr->skb) {
361 dma_unmap_single(ctodev(card),
Masakazu Mokuno100e1d82008-02-07 19:57:54 +0900362 be32_to_cpu(descr->buf_addr),
Masakazu Mokuno02c18892007-07-05 20:11:16 +0900363 descr->skb->len,
364 DMA_FROM_DEVICE);
365 descr->buf_addr = 0;
366 dev_kfree_skb_any(descr->skb);
367 descr->skb = NULL;
Masakazu Mokuno59e97322008-02-07 19:58:08 +0900368 gelic_descr_set_status(descr,
369 GELIC_DESCR_DMA_NOT_IN_USE);
Masakazu Mokuno02c18892007-07-05 20:11:16 +0900370 }
371 descr = descr->next;
372 } while (descr != card->rx_chain.head);
373}
374
375/**
Masakazu Mokuno59e97322008-02-07 19:58:08 +0900376 * gelic_card_fill_rx_chain - fills descriptors/skbs in the rx chains
Masakazu Mokuno02c18892007-07-05 20:11:16 +0900377 * @card: card structure
378 *
379 * fills all descriptors in the rx chain: allocates skbs
380 * and iommu-maps them.
Masakazu Mokuno59e97322008-02-07 19:58:08 +0900381 * returns 0 on success, < 0 on failure
Masakazu Mokuno02c18892007-07-05 20:11:16 +0900382 */
Masakazu Mokuno59e97322008-02-07 19:58:08 +0900383static int gelic_card_fill_rx_chain(struct gelic_card *card)
Masakazu Mokuno02c18892007-07-05 20:11:16 +0900384{
Masakazu Mokuno59e97322008-02-07 19:58:08 +0900385 struct gelic_descr *descr = card->rx_chain.head;
Masakazu Mokuno02c18892007-07-05 20:11:16 +0900386 int ret;
387
388 do {
389 if (!descr->skb) {
Masakazu Mokuno59e97322008-02-07 19:58:08 +0900390 ret = gelic_descr_prepare_rx(card, descr);
Masakazu Mokuno02c18892007-07-05 20:11:16 +0900391 if (ret)
392 goto rewind;
393 }
394 descr = descr->next;
395 } while (descr != card->rx_chain.head);
396
397 return 0;
398rewind:
Masakazu Mokuno59e97322008-02-07 19:58:08 +0900399 gelic_card_release_rx_chain(card);
Masakazu Mokuno02c18892007-07-05 20:11:16 +0900400 return ret;
401}
402
403/**
Masakazu Mokuno59e97322008-02-07 19:58:08 +0900404 * gelic_card_alloc_rx_skbs - allocates rx skbs in rx descriptor chains
Masakazu Mokuno02c18892007-07-05 20:11:16 +0900405 * @card: card structure
406 *
Masakazu Mokuno59e97322008-02-07 19:58:08 +0900407 * returns 0 on success, < 0 on failure
Masakazu Mokuno02c18892007-07-05 20:11:16 +0900408 */
Masakazu Mokuno59e97322008-02-07 19:58:08 +0900409static int gelic_card_alloc_rx_skbs(struct gelic_card *card)
Masakazu Mokuno02c18892007-07-05 20:11:16 +0900410{
Masakazu Mokuno59e97322008-02-07 19:58:08 +0900411 struct gelic_descr_chain *chain;
Masakazu Mokuno02c18892007-07-05 20:11:16 +0900412 int ret;
413 chain = &card->rx_chain;
Masakazu Mokuno59e97322008-02-07 19:58:08 +0900414 ret = gelic_card_fill_rx_chain(card);
Masakazu Mokuno589866f2008-02-07 19:58:42 +0900415 chain->tail = card->rx_top->prev; /* point to the last */
Masakazu Mokuno02c18892007-07-05 20:11:16 +0900416 return ret;
417}
418
419/**
Masakazu Mokuno59e97322008-02-07 19:58:08 +0900420 * gelic_descr_release_tx - processes a used tx descriptor
Masakazu Mokuno02c18892007-07-05 20:11:16 +0900421 * @card: card structure
422 * @descr: descriptor to release
423 *
424 * releases a used tx descriptor (unmapping, freeing of skb)
425 */
Masakazu Mokuno59e97322008-02-07 19:58:08 +0900426static void gelic_descr_release_tx(struct gelic_card *card,
Masakazu Mokuno589866f2008-02-07 19:58:42 +0900427 struct gelic_descr *descr)
Masakazu Mokuno02c18892007-07-05 20:11:16 +0900428{
Masakazu Mokuno173261e2007-08-31 22:22:32 +0900429 struct sk_buff *skb = descr->skb;
Masakazu Mokuno02c18892007-07-05 20:11:16 +0900430
Masakazu Mokuno589866f2008-02-07 19:58:42 +0900431 BUG_ON(!(be32_to_cpu(descr->data_status) & GELIC_DESCR_TX_TAIL));
432
433 dma_unmap_single(ctodev(card), be32_to_cpu(descr->buf_addr), skb->len,
434 DMA_TO_DEVICE);
Masakazu Mokuno173261e2007-08-31 22:22:32 +0900435 dev_kfree_skb_any(skb);
Masakazu Mokuno02c18892007-07-05 20:11:16 +0900436
437 descr->buf_addr = 0;
438 descr->buf_size = 0;
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;
444 descr->skb = NULL;
445
446 /* set descr status */
Masakazu Mokuno59e97322008-02-07 19:58:08 +0900447 gelic_descr_set_status(descr, GELIC_DESCR_DMA_NOT_IN_USE);
Masakazu Mokuno02c18892007-07-05 20:11:16 +0900448}
449
Masakazu Mokuno589866f2008-02-07 19:58:42 +0900450static void gelic_card_stop_queues(struct gelic_card *card)
451{
452 netif_stop_queue(card->netdev[GELIC_PORT_ETHERNET]);
453
454 if (card->netdev[GELIC_PORT_WIRELESS])
455 netif_stop_queue(card->netdev[GELIC_PORT_WIRELESS]);
456}
457static void gelic_card_wake_queues(struct gelic_card *card)
458{
459 netif_wake_queue(card->netdev[GELIC_PORT_ETHERNET]);
460
461 if (card->netdev[GELIC_PORT_WIRELESS])
462 netif_wake_queue(card->netdev[GELIC_PORT_WIRELESS]);
463}
Masakazu Mokuno02c18892007-07-05 20:11:16 +0900464/**
Masakazu Mokuno59e97322008-02-07 19:58:08 +0900465 * gelic_card_release_tx_chain - processes sent tx descriptors
Masakazu Mokuno02c18892007-07-05 20:11:16 +0900466 * @card: adapter structure
467 * @stop: net_stop sequence
468 *
469 * releases the tx descriptors that gelic has finished with
470 */
Masakazu Mokuno59e97322008-02-07 19:58:08 +0900471static void gelic_card_release_tx_chain(struct gelic_card *card, int stop)
Masakazu Mokuno02c18892007-07-05 20:11:16 +0900472{
Masakazu Mokuno59e97322008-02-07 19:58:08 +0900473 struct gelic_descr_chain *tx_chain;
474 enum gelic_descr_dma_status status;
Masakazu Mokuno589866f2008-02-07 19:58:42 +0900475 struct net_device *netdev;
Masakazu Mokuno02c18892007-07-05 20:11:16 +0900476 int release = 0;
477
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) {
Masakazu Mokuno59e97322008-02-07 19:58:08 +0900481 status = gelic_descr_get_status(tx_chain->tail);
Masakazu Mokuno589866f2008-02-07 19:58:42 +0900482 netdev = tx_chain->tail->skb->dev;
Masakazu Mokuno02c18892007-07-05 20:11:16 +0900483 switch (status) {
Masakazu Mokuno59e97322008-02-07 19:58:08 +0900484 case GELIC_DESCR_DMA_RESPONSE_ERROR:
485 case GELIC_DESCR_DMA_PROTECTION_ERROR:
486 case GELIC_DESCR_DMA_FORCE_END:
Masakazu Mokuno02c18892007-07-05 20:11:16 +0900487 if (printk_ratelimit())
488 dev_info(ctodev(card),
489 "%s: forcing end of tx descriptor " \
490 "with status %x\n",
491 __func__, status);
Masakazu Mokuno589866f2008-02-07 19:58:42 +0900492 netdev->stats.tx_dropped++;
Masakazu Mokuno02c18892007-07-05 20:11:16 +0900493 break;
494
Masakazu Mokuno59e97322008-02-07 19:58:08 +0900495 case GELIC_DESCR_DMA_COMPLETE:
Masakazu Mokuno48544cc262007-07-20 17:24:56 +0900496 if (tx_chain->tail->skb) {
Masakazu Mokuno589866f2008-02-07 19:58:42 +0900497 netdev->stats.tx_packets++;
498 netdev->stats.tx_bytes +=
Masakazu Mokuno48544cc262007-07-20 17:24:56 +0900499 tx_chain->tail->skb->len;
500 }
Masakazu Mokuno02c18892007-07-05 20:11:16 +0900501 break;
502
Masakazu Mokuno59e97322008-02-07 19:58:08 +0900503 case GELIC_DESCR_DMA_CARDOWNED:
Masakazu Mokuno02c18892007-07-05 20:11:16 +0900504 /* pending tx request */
505 default:
Masakazu Mokuno59e97322008-02-07 19:58:08 +0900506 /* any other value (== GELIC_DESCR_DMA_NOT_IN_USE) */
Masakazu Mokuno48544cc262007-07-20 17:24:56 +0900507 if (!stop)
508 goto out;
Masakazu Mokuno02c18892007-07-05 20:11:16 +0900509 }
Masakazu Mokuno59e97322008-02-07 19:58:08 +0900510 gelic_descr_release_tx(card, tx_chain->tail);
Masakazu Mokuno48544cc262007-07-20 17:24:56 +0900511 release ++;
Masakazu Mokuno02c18892007-07-05 20:11:16 +0900512 }
513out:
Masakazu Mokuno173261e2007-08-31 22:22:32 +0900514 if (!stop && release)
Masakazu Mokuno589866f2008-02-07 19:58:42 +0900515 gelic_card_wake_queues(card);
Masakazu Mokuno02c18892007-07-05 20:11:16 +0900516}
517
518/**
519 * gelic_net_set_multi - sets multicast addresses and promisc flags
520 * @netdev: interface device structure
521 *
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
525 */
Masakazu Mokuno589866f2008-02-07 19:58:42 +0900526void gelic_net_set_multi(struct net_device *netdev)
Masakazu Mokuno02c18892007-07-05 20:11:16 +0900527{
Masakazu Mokuno589866f2008-02-07 19:58:42 +0900528 struct gelic_card *card = netdev_card(netdev);
Masakazu Mokuno02c18892007-07-05 20:11:16 +0900529 struct dev_mc_list *mc;
530 unsigned int i;
531 uint8_t *p;
532 u64 addr;
533 int status;
534
535 /* clear all multicast address */
536 status = lv1_net_remove_multicast_address(bus_id(card), dev_id(card),
537 0, 1);
538 if (status)
539 dev_err(ctodev(card),
540 "lv1_net_remove_multicast_address failed %d\n",
541 status);
542 /* set broadcast address */
543 status = lv1_net_add_multicast_address(bus_id(card), dev_id(card),
544 GELIC_NET_BROADCAST_ADDR, 0);
545 if (status)
546 dev_err(ctodev(card),
547 "lv1_net_add_multicast_address failed, %d\n",
548 status);
549
Masakazu Mokuno589866f2008-02-07 19:58:42 +0900550 if ((netdev->flags & IFF_ALLMULTI) ||
551 (netdev->mc_count > GELIC_NET_MC_COUNT_MAX)) {
Masakazu Mokuno02c18892007-07-05 20:11:16 +0900552 status = lv1_net_add_multicast_address(bus_id(card),
553 dev_id(card),
554 0, 1);
555 if (status)
556 dev_err(ctodev(card),
557 "lv1_net_add_multicast_address failed, %d\n",
558 status);
559 return;
560 }
561
Masakazu Mokuno589866f2008-02-07 19:58:42 +0900562 /* set multicast addresses */
Masakazu Mokuno02c18892007-07-05 20:11:16 +0900563 for (mc = netdev->mc_list; mc; mc = mc->next) {
564 addr = 0;
565 p = mc->dmi_addr;
566 for (i = 0; i < ETH_ALEN; i++) {
567 addr <<= 8;
568 addr |= *p++;
569 }
570 status = lv1_net_add_multicast_address(bus_id(card),
571 dev_id(card),
572 addr, 0);
573 if (status)
574 dev_err(ctodev(card),
575 "lv1_net_add_multicast_address failed, %d\n",
576 status);
577 }
578}
579
580/**
Masakazu Mokuno59e97322008-02-07 19:58:08 +0900581 * gelic_card_enable_rxdmac - enables the receive DMA controller
Masakazu Mokuno02c18892007-07-05 20:11:16 +0900582 * @card: card structure
583 *
Masakazu Mokuno59e97322008-02-07 19:58:08 +0900584 * gelic_card_enable_rxdmac enables the DMA controller by setting RX_DMA_EN
Masakazu Mokuno02c18892007-07-05 20:11:16 +0900585 * in the GDADMACCNTR register
586 */
Masakazu Mokuno59e97322008-02-07 19:58:08 +0900587static inline void gelic_card_enable_rxdmac(struct gelic_card *card)
Masakazu Mokuno02c18892007-07-05 20:11:16 +0900588{
589 int status;
590
Masakazu Mokuno589866f2008-02-07 19:58:42 +0900591#ifdef DEBUG
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);
600 }
601#endif
Masakazu Mokuno02c18892007-07-05 20:11:16 +0900602 status = lv1_net_start_rx_dma(bus_id(card), dev_id(card),
Masakazu Mokuno589866f2008-02-07 19:58:42 +0900603 card->rx_chain.head->bus_addr, 0);
Masakazu Mokuno02c18892007-07-05 20:11:16 +0900604 if (status)
605 dev_info(ctodev(card),
606 "lv1_net_start_rx_dma failed, status=%d\n", status);
607}
608
609/**
Masakazu Mokuno59e97322008-02-07 19:58:08 +0900610 * gelic_card_disable_rxdmac - disables the receive DMA controller
Masakazu Mokuno02c18892007-07-05 20:11:16 +0900611 * @card: card structure
612 *
Masakazu Mokuno59e97322008-02-07 19:58:08 +0900613 * gelic_card_disable_rxdmac terminates processing on the DMA controller by
Masakazu Mokuno02c18892007-07-05 20:11:16 +0900614 * turing off DMA and issueing a force end
615 */
Masakazu Mokuno59e97322008-02-07 19:58:08 +0900616static inline void gelic_card_disable_rxdmac(struct gelic_card *card)
Masakazu Mokuno02c18892007-07-05 20:11:16 +0900617{
618 int status;
619
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);
622 if (status)
623 dev_err(ctodev(card),
624 "lv1_net_stop_rx_dma faild, %d\n", status);
625}
626
627/**
Masakazu Mokuno59e97322008-02-07 19:58:08 +0900628 * gelic_card_disable_txdmac - disables the transmit DMA controller
Masakazu Mokuno02c18892007-07-05 20:11:16 +0900629 * @card: card structure
630 *
Masakazu Mokuno59e97322008-02-07 19:58:08 +0900631 * gelic_card_disable_txdmac terminates processing on the DMA controller by
Masakazu Mokuno02c18892007-07-05 20:11:16 +0900632 * turing off DMA and issueing a force end
633 */
Masakazu Mokuno59e97322008-02-07 19:58:08 +0900634static inline void gelic_card_disable_txdmac(struct gelic_card *card)
Masakazu Mokuno02c18892007-07-05 20:11:16 +0900635{
636 int status;
637
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);
640 if (status)
641 dev_err(ctodev(card),
642 "lv1_net_stop_tx_dma faild, status=%d\n", status);
643}
644
645/**
646 * gelic_net_stop - called upon ifconfig down
647 * @netdev: interface device structure
648 *
649 * always returns 0
650 */
Masakazu Mokuno589866f2008-02-07 19:58:42 +0900651int gelic_net_stop(struct net_device *netdev)
Masakazu Mokuno02c18892007-07-05 20:11:16 +0900652{
Masakazu Mokuno589866f2008-02-07 19:58:42 +0900653 struct gelic_card *card;
Masakazu Mokuno02c18892007-07-05 20:11:16 +0900654
Masakazu Mokuno589866f2008-02-07 19:58:42 +0900655 pr_debug("%s: start\n", __func__);
656
Masakazu Mokuno02c18892007-07-05 20:11:16 +0900657 netif_stop_queue(netdev);
Masakazu Mokuno02c18892007-07-05 20:11:16 +0900658 netif_carrier_off(netdev);
659
Masakazu Mokuno589866f2008-02-07 19:58:42 +0900660 card = netdev_card(netdev);
661 gelic_card_down(card);
Masakazu Mokuno02c18892007-07-05 20:11:16 +0900662
Masakazu Mokuno589866f2008-02-07 19:58:42 +0900663 pr_debug("%s: done\n", __func__);
Masakazu Mokuno02c18892007-07-05 20:11:16 +0900664 return 0;
665}
666
667/**
Masakazu Mokuno59e97322008-02-07 19:58:08 +0900668 * gelic_card_get_next_tx_descr - returns the next available tx descriptor
Masakazu Mokuno02c18892007-07-05 20:11:16 +0900669 * @card: device structure to get descriptor from
670 *
671 * returns the address of the next descriptor, or NULL if not available.
672 */
Masakazu Mokuno59e97322008-02-07 19:58:08 +0900673static struct gelic_descr *
674gelic_card_get_next_tx_descr(struct gelic_card *card)
Masakazu Mokuno02c18892007-07-05 20:11:16 +0900675{
676 if (!card->tx_chain.head)
677 return NULL;
Masakazu Mokuno173261e2007-08-31 22:22:32 +0900678 /* see if the next descriptor is free */
Masakazu Mokuno02c18892007-07-05 20:11:16 +0900679 if (card->tx_chain.tail != card->tx_chain.head->next &&
Masakazu Mokuno59e97322008-02-07 19:58:08 +0900680 gelic_descr_get_status(card->tx_chain.head) ==
681 GELIC_DESCR_DMA_NOT_IN_USE)
Masakazu Mokuno02c18892007-07-05 20:11:16 +0900682 return card->tx_chain.head;
683 else
684 return NULL;
685
686}
687
688/**
Masakazu Mokuno589866f2008-02-07 19:58:42 +0900689 * gelic_net_set_txdescr_cmdstat - sets the tx descriptor command field
Masakazu Mokuno02c18892007-07-05 20:11:16 +0900690 * @descr: descriptor structure to fill out
691 * @skb: packet to consider
Masakazu Mokuno02c18892007-07-05 20:11:16 +0900692 *
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.
696 */
Masakazu Mokuno59e97322008-02-07 19:58:08 +0900697static void gelic_descr_set_tx_cmdstat(struct gelic_descr *descr,
698 struct sk_buff *skb)
Masakazu Mokuno02c18892007-07-05 20:11:16 +0900699{
Masakazu Mokuno02c18892007-07-05 20:11:16 +0900700 if (skb->ip_summed != CHECKSUM_PARTIAL)
Masakazu Mokuno100e1d82008-02-07 19:57:54 +0900701 descr->dmac_cmd_status =
Masakazu Mokuno59e97322008-02-07 19:58:08 +0900702 cpu_to_be32(GELIC_DESCR_DMA_CMD_NO_CHKSUM |
703 GELIC_DESCR_TX_DMA_FRAME_TAIL);
Masakazu Mokuno02c18892007-07-05 20:11:16 +0900704 else {
705 /* is packet ip?
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 =
Masakazu Mokuno59e97322008-02-07 19:58:08 +0900710 cpu_to_be32(GELIC_DESCR_DMA_CMD_TCP_CHKSUM |
711 GELIC_DESCR_TX_DMA_FRAME_TAIL);
Masakazu Mokuno173261e2007-08-31 22:22:32 +0900712
Masakazu Mokuno02c18892007-07-05 20:11:16 +0900713 else if (ip_hdr(skb)->protocol == IPPROTO_UDP)
714 descr->dmac_cmd_status =
Masakazu Mokuno59e97322008-02-07 19:58:08 +0900715 cpu_to_be32(GELIC_DESCR_DMA_CMD_UDP_CHKSUM |
716 GELIC_DESCR_TX_DMA_FRAME_TAIL);
Masakazu Mokuno02c18892007-07-05 20:11:16 +0900717 else /*
718 * the stack should checksum non-tcp and non-udp
719 * packets on his own: NETIF_F_IP_CSUM
720 */
721 descr->dmac_cmd_status =
Masakazu Mokuno59e97322008-02-07 19:58:08 +0900722 cpu_to_be32(GELIC_DESCR_DMA_CMD_NO_CHKSUM |
723 GELIC_DESCR_TX_DMA_FRAME_TAIL);
Masakazu Mokuno02c18892007-07-05 20:11:16 +0900724 }
725 }
726}
727
Masakazu Mokuno173261e2007-08-31 22:22:32 +0900728static inline struct sk_buff *gelic_put_vlan_tag(struct sk_buff *skb,
729 unsigned short tag)
730{
731 struct vlan_ethhdr *veth;
732 static unsigned int c;
733
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);
738 if (!skb)
739 return NULL;
740 dev_kfree_skb_any(sk_tmp);
741 }
742 veth = (struct vlan_ethhdr *)skb_push(skb, VLAN_HLEN);
743
744 /* Move the mac addresses to the top of buffer */
745 memmove(skb->data, skb->data + VLAN_HLEN, 2 * ETH_ALEN);
746
747 veth->h_vlan_proto = __constant_htons(ETH_P_8021Q);
748 veth->h_vlan_TCI = htons(tag);
749
750 return skb;
751}
752
Masakazu Mokuno02c18892007-07-05 20:11:16 +0900753/**
Masakazu Mokuno589866f2008-02-07 19:58:42 +0900754 * gelic_descr_prepare_tx - setup a descriptor for sending packets
Masakazu Mokuno02c18892007-07-05 20:11:16 +0900755 * @card: card structure
756 * @descr: descriptor structure
757 * @skb: packet to use
758 *
759 * returns 0 on success, <0 on failure.
760 *
761 */
Masakazu Mokuno59e97322008-02-07 19:58:08 +0900762static int gelic_descr_prepare_tx(struct gelic_card *card,
763 struct gelic_descr *descr,
764 struct sk_buff *skb)
Masakazu Mokuno02c18892007-07-05 20:11:16 +0900765{
Masakazu Mokuno173261e2007-08-31 22:22:32 +0900766 dma_addr_t buf;
Masakazu Mokuno02c18892007-07-05 20:11:16 +0900767
Masakazu Mokuno589866f2008-02-07 19:58:42 +0900768 if (card->vlan_required) {
Masakazu Mokuno173261e2007-08-31 22:22:32 +0900769 struct sk_buff *skb_tmp;
Masakazu Mokuno589866f2008-02-07 19:58:42 +0900770 enum gelic_port_type type;
771
772 type = netdev_port(skb->dev)->type;
Masakazu Mokuno173261e2007-08-31 22:22:32 +0900773 skb_tmp = gelic_put_vlan_tag(skb,
Masakazu Mokuno589866f2008-02-07 19:58:42 +0900774 card->vlan[type].tx);
Masakazu Mokuno173261e2007-08-31 22:22:32 +0900775 if (!skb_tmp)
776 return -ENOMEM;
777 skb = skb_tmp;
Masakazu Mokuno48544cc262007-07-20 17:24:56 +0900778 }
Masakazu Mokuno02c18892007-07-05 20:11:16 +0900779
Masakazu Mokuno173261e2007-08-31 22:22:32 +0900780 buf = dma_map_single(ctodev(card), skb->data, skb->len, DMA_TO_DEVICE);
Masakazu Mokuno02c18892007-07-05 20:11:16 +0900781
Masakazu Mokuno173261e2007-08-31 22:22:32 +0900782 if (!buf) {
Masakazu Mokuno02c18892007-07-05 20:11:16 +0900783 dev_err(ctodev(card),
784 "dma map 2 failed (%p, %i). Dropping packet\n",
Masakazu Mokuno173261e2007-08-31 22:22:32 +0900785 skb->data, skb->len);
Masakazu Mokuno02c18892007-07-05 20:11:16 +0900786 return -ENOMEM;
787 }
788
Masakazu Mokuno100e1d82008-02-07 19:57:54 +0900789 descr->buf_addr = cpu_to_be32(buf);
790 descr->buf_size = cpu_to_be32(skb->len);
Masakazu Mokuno173261e2007-08-31 22:22:32 +0900791 descr->skb = skb;
Masakazu Mokuno02c18892007-07-05 20:11:16 +0900792 descr->data_status = 0;
Masakazu Mokuno173261e2007-08-31 22:22:32 +0900793 descr->next_descr_addr = 0; /* terminate hw descr */
Masakazu Mokuno59e97322008-02-07 19:58:08 +0900794 gelic_descr_set_tx_cmdstat(descr, skb);
Masakazu Mokuno48544cc262007-07-20 17:24:56 +0900795
796 /* bump free descriptor pointer */
Masakazu Mokuno173261e2007-08-31 22:22:32 +0900797 card->tx_chain.head = descr->next;
Masakazu Mokuno02c18892007-07-05 20:11:16 +0900798 return 0;
799}
800
801/**
Masakazu Mokuno59e97322008-02-07 19:58:08 +0900802 * gelic_card_kick_txdma - enables TX DMA processing
Masakazu Mokuno02c18892007-07-05 20:11:16 +0900803 * @card: card structure
804 * @descr: descriptor address to enable TX processing at
805 *
806 */
Masakazu Mokuno59e97322008-02-07 19:58:08 +0900807static int gelic_card_kick_txdma(struct gelic_card *card,
808 struct gelic_descr *descr)
Masakazu Mokuno02c18892007-07-05 20:11:16 +0900809{
Masakazu Mokuno48544cc262007-07-20 17:24:56 +0900810 int status = 0;
Masakazu Mokuno02c18892007-07-05 20:11:16 +0900811
812 if (card->tx_dma_progress)
813 return 0;
814
Masakazu Mokuno59e97322008-02-07 19:58:08 +0900815 if (gelic_descr_get_status(descr) == GELIC_DESCR_DMA_CARDOWNED) {
Masakazu Mokuno02c18892007-07-05 20:11:16 +0900816 card->tx_dma_progress = 1;
Masakazu Mokunodc029ad2007-08-31 22:25:09 +0900817 status = lv1_net_start_tx_dma(bus_id(card), dev_id(card),
818 descr->bus_addr, 0);
819 if (status)
Masakazu Mokuno02c18892007-07-05 20:11:16 +0900820 dev_info(ctodev(card), "lv1_net_start_txdma failed," \
Masakazu Mokunodc029ad2007-08-31 22:25:09 +0900821 "status=%d\n", status);
Masakazu Mokuno02c18892007-07-05 20:11:16 +0900822 }
823 return status;
824}
825
826/**
827 * gelic_net_xmit - transmits a frame over the device
828 * @skb: packet to send out
829 * @netdev: interface device structure
830 *
831 * returns 0 on success, <0 on failure
832 */
Masakazu Mokuno589866f2008-02-07 19:58:42 +0900833int gelic_net_xmit(struct sk_buff *skb, struct net_device *netdev)
Masakazu Mokuno02c18892007-07-05 20:11:16 +0900834{
Masakazu Mokuno589866f2008-02-07 19:58:42 +0900835 struct gelic_card *card = netdev_card(netdev);
Masakazu Mokuno59e97322008-02-07 19:58:08 +0900836 struct gelic_descr *descr;
Masakazu Mokuno02c18892007-07-05 20:11:16 +0900837 int result;
838 unsigned long flags;
839
Masakazu Mokuno589866f2008-02-07 19:58:42 +0900840 spin_lock_irqsave(&card->tx_lock, flags);
Masakazu Mokuno02c18892007-07-05 20:11:16 +0900841
Masakazu Mokuno59e97322008-02-07 19:58:08 +0900842 gelic_card_release_tx_chain(card, 0);
Masakazu Mokuno48544cc262007-07-20 17:24:56 +0900843
Masakazu Mokuno59e97322008-02-07 19:58:08 +0900844 descr = gelic_card_get_next_tx_descr(card);
Masakazu Mokuno02c18892007-07-05 20:11:16 +0900845 if (!descr) {
Masakazu Mokuno48544cc262007-07-20 17:24:56 +0900846 /*
847 * no more descriptors free
848 */
Masakazu Mokuno589866f2008-02-07 19:58:42 +0900849 gelic_card_stop_queues(card);
850 spin_unlock_irqrestore(&card->tx_lock, flags);
Masakazu Mokuno02c18892007-07-05 20:11:16 +0900851 return NETDEV_TX_BUSY;
852 }
Masakazu Mokuno48544cc262007-07-20 17:24:56 +0900853
Masakazu Mokuno59e97322008-02-07 19:58:08 +0900854 result = gelic_descr_prepare_tx(card, descr, skb);
Masakazu Mokuno48544cc262007-07-20 17:24:56 +0900855 if (result) {
856 /*
857 * DMA map failed. As chanses are that failure
858 * would continue, just release skb and return
859 */
Masakazu Mokuno589866f2008-02-07 19:58:42 +0900860 netdev->stats.tx_dropped++;
Masakazu Mokuno48544cc262007-07-20 17:24:56 +0900861 dev_kfree_skb_any(skb);
Masakazu Mokuno589866f2008-02-07 19:58:42 +0900862 spin_unlock_irqrestore(&card->tx_lock, flags);
Masakazu Mokuno48544cc262007-07-20 17:24:56 +0900863 return NETDEV_TX_OK;
864 }
865 /*
866 * link this prepared descriptor to previous one
867 * to achieve high performance
868 */
Masakazu Mokuno100e1d82008-02-07 19:57:54 +0900869 descr->prev->next_descr_addr = cpu_to_be32(descr->bus_addr);
Masakazu Mokuno02c18892007-07-05 20:11:16 +0900870 /*
871 * as hardware descriptor is modified in the above lines,
872 * ensure that the hardware sees it
873 */
874 wmb();
Masakazu Mokuno59e97322008-02-07 19:58:08 +0900875 if (gelic_card_kick_txdma(card, descr)) {
Masakazu Mokuno48544cc262007-07-20 17:24:56 +0900876 /*
877 * kick failed.
878 * release descriptors which were just prepared
879 */
Masakazu Mokuno589866f2008-02-07 19:58:42 +0900880 netdev->stats.tx_dropped++;
Masakazu Mokuno59e97322008-02-07 19:58:08 +0900881 gelic_descr_release_tx(card, descr);
882 gelic_descr_release_tx(card, descr->next);
Masakazu Mokuno48544cc262007-07-20 17:24:56 +0900883 card->tx_chain.tail = descr->next->next;
884 dev_info(ctodev(card), "%s: kick failure\n", __func__);
885 } else {
886 /* OK, DMA started/reserved */
887 netdev->trans_start = jiffies;
888 }
Masakazu Mokuno02c18892007-07-05 20:11:16 +0900889
Masakazu Mokuno589866f2008-02-07 19:58:42 +0900890 spin_unlock_irqrestore(&card->tx_lock, flags);
Masakazu Mokuno02c18892007-07-05 20:11:16 +0900891 return NETDEV_TX_OK;
Masakazu Mokuno02c18892007-07-05 20:11:16 +0900892}
893
894/**
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
Masakazu Mokuno589866f2008-02-07 19:58:42 +0900898 * @netdev: net_device structure to be passed packet
Masakazu Mokuno02c18892007-07-05 20:11:16 +0900899 *
900 * iommu-unmaps the skb, fills out skb structure and passes the data to the
901 * stack. The descriptor state is not changed.
902 */
Masakazu Mokuno59e97322008-02-07 19:58:08 +0900903static void gelic_net_pass_skb_up(struct gelic_descr *descr,
Masakazu Mokuno589866f2008-02-07 19:58:42 +0900904 struct gelic_card *card,
905 struct net_device *netdev)
906
Masakazu Mokuno02c18892007-07-05 20:11:16 +0900907{
Masakazu Mokuno589866f2008-02-07 19:58:42 +0900908 struct sk_buff *skb = descr->skb;
Masakazu Mokuno02c18892007-07-05 20:11:16 +0900909 u32 data_status, data_error;
910
Masakazu Mokuno100e1d82008-02-07 19:57:54 +0900911 data_status = be32_to_cpu(descr->data_status);
912 data_error = be32_to_cpu(descr->data_error);
Masakazu Mokuno02c18892007-07-05 20:11:16 +0900913 /* unmap skb buffer */
Masakazu Mokuno589866f2008-02-07 19:58:42 +0900914 dma_unmap_single(ctodev(card), be32_to_cpu(descr->buf_addr),
915 GELIC_NET_MAX_MTU,
Masakazu Mokuno02c18892007-07-05 20:11:16 +0900916 DMA_FROM_DEVICE);
917
Masakazu Mokuno589866f2008-02-07 19:58:42 +0900918 skb_put(skb, be32_to_cpu(descr->valid_size)?
Masakazu Mokuno100e1d82008-02-07 19:57:54 +0900919 be32_to_cpu(descr->valid_size) :
920 be32_to_cpu(descr->result_size));
Masakazu Mokuno02c18892007-07-05 20:11:16 +0900921 if (!descr->valid_size)
922 dev_info(ctodev(card), "buffer full %x %x %x\n",
Masakazu Mokuno100e1d82008-02-07 19:57:54 +0900923 be32_to_cpu(descr->result_size),
924 be32_to_cpu(descr->buf_size),
925 be32_to_cpu(descr->dmac_cmd_status));
Masakazu Mokuno02c18892007-07-05 20:11:16 +0900926
927 descr->skb = NULL;
928 /*
929 * the card put 2 bytes vlan tag in front
930 * of the ethernet frame
931 */
932 skb_pull(skb, 2);
933 skb->protocol = eth_type_trans(skb, netdev);
934
935 /* checksum offload */
936 if (card->rx_csum) {
Masakazu Mokuno59e97322008-02-07 19:58:08 +0900937 if ((data_status & GELIC_DESCR_DATA_STATUS_CHK_MASK) &&
938 (!(data_error & GELIC_DESCR_DATA_ERROR_CHK_MASK)))
Masakazu Mokuno02c18892007-07-05 20:11:16 +0900939 skb->ip_summed = CHECKSUM_UNNECESSARY;
940 else
941 skb->ip_summed = CHECKSUM_NONE;
942 } else
943 skb->ip_summed = CHECKSUM_NONE;
944
945 /* update netdevice statistics */
Masakazu Mokuno589866f2008-02-07 19:58:42 +0900946 netdev->stats.rx_packets++;
947 netdev->stats.rx_bytes += skb->len;
Masakazu Mokuno02c18892007-07-05 20:11:16 +0900948
949 /* pass skb up to stack */
950 netif_receive_skb(skb);
951}
952
953/**
Masakazu Mokuno59e97322008-02-07 19:58:08 +0900954 * gelic_card_decode_one_descr - processes an rx descriptor
Masakazu Mokuno02c18892007-07-05 20:11:16 +0900955 * @card: card structure
956 *
957 * returns 1 if a packet has been sent to the stack, otherwise 0
958 *
959 * processes an rx descriptor by iommu-unmapping the data buffer and passing
960 * the packet up to the stack
961 */
Masakazu Mokuno59e97322008-02-07 19:58:08 +0900962static int gelic_card_decode_one_descr(struct gelic_card *card)
Masakazu Mokuno02c18892007-07-05 20:11:16 +0900963{
Masakazu Mokuno59e97322008-02-07 19:58:08 +0900964 enum gelic_descr_dma_status status;
965 struct gelic_descr_chain *chain = &card->rx_chain;
Masakazu Mokuno589866f2008-02-07 19:58:42 +0900966 struct gelic_descr *descr = chain->head;
967 struct net_device *netdev = NULL;
Masakazu Mokuno02c18892007-07-05 20:11:16 +0900968 int dmac_chain_ended;
969
Masakazu Mokuno59e97322008-02-07 19:58:08 +0900970 status = gelic_descr_get_status(descr);
Masakazu Mokuno02c18892007-07-05 20:11:16 +0900971 /* is this descriptor terminated with next_descr == NULL? */
972 dmac_chain_ended =
Masakazu Mokuno100e1d82008-02-07 19:57:54 +0900973 be32_to_cpu(descr->dmac_cmd_status) &
Masakazu Mokuno59e97322008-02-07 19:58:08 +0900974 GELIC_DESCR_RX_DMA_CHAIN_END;
Masakazu Mokuno02c18892007-07-05 20:11:16 +0900975
Masakazu Mokuno59e97322008-02-07 19:58:08 +0900976 if (status == GELIC_DESCR_DMA_CARDOWNED)
Masakazu Mokuno02c18892007-07-05 20:11:16 +0900977 return 0;
978
Masakazu Mokuno59e97322008-02-07 19:58:08 +0900979 if (status == GELIC_DESCR_DMA_NOT_IN_USE) {
Masakazu Mokuno02c18892007-07-05 20:11:16 +0900980 dev_dbg(ctodev(card), "dormant descr? %p\n", descr);
981 return 0;
982 }
983
Masakazu Mokuno589866f2008-02-07 19:58:42 +0900984 /* netdevice select */
985 if (card->vlan_required) {
986 unsigned int i;
987 u16 vid;
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];
992 break;
993 }
994 };
995 if (GELIC_PORT_MAX <= i) {
996 pr_info("%s: unknown packet vid=%x\n", __func__, vid);
997 goto refill;
998 }
999 } else
1000 netdev = card->netdev[GELIC_PORT_ETHERNET];
1001
Masakazu Mokuno59e97322008-02-07 19:58:08 +09001002 if ((status == GELIC_DESCR_DMA_RESPONSE_ERROR) ||
1003 (status == GELIC_DESCR_DMA_PROTECTION_ERROR) ||
1004 (status == GELIC_DESCR_DMA_FORCE_END)) {
Masakazu Mokuno02c18892007-07-05 20:11:16 +09001005 dev_info(ctodev(card), "dropping RX descriptor with state %x\n",
1006 status);
Masakazu Mokuno589866f2008-02-07 19:58:42 +09001007 netdev->stats.rx_dropped++;
Masakazu Mokuno02c18892007-07-05 20:11:16 +09001008 goto refill;
1009 }
1010
Masakazu Mokuno59e97322008-02-07 19:58:08 +09001011 if (status == GELIC_DESCR_DMA_BUFFER_FULL) {
Masakazu Mokunofe6d3a42007-07-20 17:39:25 +09001012 /*
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
1017 * would occur.
1018 * Anyway this frame was longer than the MTU,
1019 * just drop it.
1020 */
1021 dev_info(ctodev(card), "overlength frame\n");
1022 goto refill;
1023 }
1024 /*
1025 * descriptoers any other than FRAME_END here should
1026 * be treated as error.
1027 */
Masakazu Mokuno59e97322008-02-07 19:58:08 +09001028 if (status != GELIC_DESCR_DMA_FRAME_END) {
Masakazu Mokuno02c18892007-07-05 20:11:16 +09001029 dev_dbg(ctodev(card), "RX descriptor with state %x\n",
1030 status);
1031 goto refill;
1032 }
1033
1034 /* ok, we've got a packet in descr */
Masakazu Mokuno589866f2008-02-07 19:58:42 +09001035 gelic_net_pass_skb_up(descr, card, netdev);
Masakazu Mokuno02c18892007-07-05 20:11:16 +09001036refill:
Masakazu Mokunofe6d3a42007-07-20 17:39:25 +09001037 /*
1038 * So that always DMAC can see the end
1039 * of the descriptor chain to avoid
1040 * from unwanted DMAC overrun.
1041 */
1042 descr->next_descr_addr = 0;
Masakazu Mokuno02c18892007-07-05 20:11:16 +09001043
1044 /* change the descriptor state: */
Masakazu Mokuno59e97322008-02-07 19:58:08 +09001045 gelic_descr_set_status(descr, GELIC_DESCR_DMA_NOT_IN_USE);
Masakazu Mokuno02c18892007-07-05 20:11:16 +09001046
Masakazu Mokunofe6d3a42007-07-20 17:39:25 +09001047 /*
1048 * this call can fail, but for now, just leave this
1049 * decriptor without skb
Masakazu Mokuno02c18892007-07-05 20:11:16 +09001050 */
Masakazu Mokuno59e97322008-02-07 19:58:08 +09001051 gelic_descr_prepare_rx(card, descr);
Masakazu Mokunofe6d3a42007-07-20 17:39:25 +09001052
Masakazu Mokuno589866f2008-02-07 19:58:42 +09001053 chain->tail = descr;
1054 chain->head = descr->next;
Masakazu Mokunofe6d3a42007-07-20 17:39:25 +09001055
1056 /*
1057 * Set this descriptor the end of the chain.
1058 */
Masakazu Mokuno100e1d82008-02-07 19:57:54 +09001059 descr->prev->next_descr_addr = cpu_to_be32(descr->bus_addr);
Masakazu Mokuno02c18892007-07-05 20:11:16 +09001060
Masakazu Mokunofe6d3a42007-07-20 17:39:25 +09001061 /*
1062 * If dmac chain was met, DMAC stopped.
1063 * thus re-enable it
1064 */
Masakazu Mokuno02c18892007-07-05 20:11:16 +09001065 if (dmac_chain_ended) {
Masakazu Mokuno583aae12007-07-20 17:35:54 +09001066 card->rx_dma_restart_required = 1;
1067 dev_dbg(ctodev(card), "reenable rx dma scheduled\n");
Masakazu Mokuno02c18892007-07-05 20:11:16 +09001068 }
1069
1070 return 1;
1071}
1072
1073/**
1074 * gelic_net_poll - NAPI poll function called by the stack to return packets
Masakazu Mokuno589866f2008-02-07 19:58:42 +09001075 * @napi: napi structure
Masakazu Mokuno02c18892007-07-05 20:11:16 +09001076 * @budget: number of packets we can pass to the stack at most
1077 *
Masakazu Mokuno589866f2008-02-07 19:58:42 +09001078 * returns the number of the processed packets
Masakazu Mokuno02c18892007-07-05 20:11:16 +09001079 *
1080 */
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001081static int gelic_net_poll(struct napi_struct *napi, int budget)
Masakazu Mokuno02c18892007-07-05 20:11:16 +09001082{
Masakazu Mokuno59e97322008-02-07 19:58:08 +09001083 struct gelic_card *card = container_of(napi, struct gelic_card, napi);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001084 int packets_done = 0;
Masakazu Mokuno02c18892007-07-05 20:11:16 +09001085
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001086 while (packets_done < budget) {
Masakazu Mokuno59e97322008-02-07 19:58:08 +09001087 if (!gelic_card_decode_one_descr(card))
Masakazu Mokuno02c18892007-07-05 20:11:16 +09001088 break;
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001089
1090 packets_done++;
Masakazu Mokuno02c18892007-07-05 20:11:16 +09001091 }
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001092
1093 if (packets_done < budget) {
Masakazu Mokuno589866f2008-02-07 19:58:42 +09001094 napi_complete(napi);
Masakazu Mokuno59e97322008-02-07 19:58:08 +09001095 gelic_card_rx_irq_on(card);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001096 }
1097 return packets_done;
Masakazu Mokuno02c18892007-07-05 20:11:16 +09001098}
Masakazu Mokuno02c18892007-07-05 20:11:16 +09001099/**
1100 * gelic_net_change_mtu - changes the MTU of an interface
1101 * @netdev: interface device structure
1102 * @new_mtu: new MTU value
1103 *
1104 * returns 0 on success, <0 on failure
1105 */
Masakazu Mokuno589866f2008-02-07 19:58:42 +09001106int gelic_net_change_mtu(struct net_device *netdev, int new_mtu)
Masakazu Mokuno02c18892007-07-05 20:11:16 +09001107{
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)) {
1112 return -EINVAL;
1113 }
1114 netdev->mtu = new_mtu;
1115 return 0;
1116}
1117
1118/**
Masakazu Mokuno59e97322008-02-07 19:58:08 +09001119 * gelic_card_interrupt - event handler for gelic_net
Masakazu Mokuno02c18892007-07-05 20:11:16 +09001120 */
Masakazu Mokuno59e97322008-02-07 19:58:08 +09001121static irqreturn_t gelic_card_interrupt(int irq, void *ptr)
Masakazu Mokuno02c18892007-07-05 20:11:16 +09001122{
1123 unsigned long flags;
Masakazu Mokuno589866f2008-02-07 19:58:42 +09001124 struct gelic_card *card = ptr;
Masakazu Mokuno02c18892007-07-05 20:11:16 +09001125 u64 status;
1126
1127 status = card->irq_status;
1128
1129 if (!status)
1130 return IRQ_NONE;
1131
Masakazu Mokuno589866f2008-02-07 19:58:42 +09001132 status &= card->irq_mask;
1133
Masakazu Mokuno583aae12007-07-20 17:35:54 +09001134 if (card->rx_dma_restart_required) {
1135 card->rx_dma_restart_required = 0;
Masakazu Mokuno59e97322008-02-07 19:58:08 +09001136 gelic_card_enable_rxdmac(card);
Masakazu Mokuno583aae12007-07-20 17:35:54 +09001137 }
1138
Masakazu Mokuno59e97322008-02-07 19:58:08 +09001139 if (status & GELIC_CARD_RXINT) {
1140 gelic_card_rx_irq_off(card);
Masakazu Mokuno589866f2008-02-07 19:58:42 +09001141 napi_schedule(&card->napi);
Masakazu Mokuno02c18892007-07-05 20:11:16 +09001142 }
1143
Masakazu Mokuno59e97322008-02-07 19:58:08 +09001144 if (status & GELIC_CARD_TXINT) {
Masakazu Mokuno589866f2008-02-07 19:58:42 +09001145 spin_lock_irqsave(&card->tx_lock, flags);
Masakazu Mokuno02c18892007-07-05 20:11:16 +09001146 card->tx_dma_progress = 0;
Masakazu Mokuno59e97322008-02-07 19:58:08 +09001147 gelic_card_release_tx_chain(card, 0);
Masakazu Mokuno48544cc262007-07-20 17:24:56 +09001148 /* kick outstanding tx descriptor if any */
Masakazu Mokuno59e97322008-02-07 19:58:08 +09001149 gelic_card_kick_txdma(card, card->tx_chain.tail);
Masakazu Mokuno589866f2008-02-07 19:58:42 +09001150 spin_unlock_irqrestore(&card->tx_lock, flags);
Masakazu Mokuno02c18892007-07-05 20:11:16 +09001151 }
Masakazu Mokuno01fed4c2008-02-07 19:58:32 +09001152
1153 /* ether port status changed */
1154 if (status & GELIC_CARD_PORT_STATUS_CHANGED)
1155 gelic_card_get_ether_port_status(card, 1);
Masakazu Mokuno589866f2008-02-07 19:58:42 +09001156
Masakazu Mokuno02c18892007-07-05 20:11:16 +09001157 return IRQ_HANDLED;
1158}
1159
1160#ifdef CONFIG_NET_POLL_CONTROLLER
1161/**
1162 * gelic_net_poll_controller - artificial interrupt for netconsole etc.
1163 * @netdev: interface device structure
1164 *
1165 * see Documentation/networking/netconsole.txt
1166 */
Masakazu Mokuno589866f2008-02-07 19:58:42 +09001167void gelic_net_poll_controller(struct net_device *netdev)
Masakazu Mokuno02c18892007-07-05 20:11:16 +09001168{
Masakazu Mokuno589866f2008-02-07 19:58:42 +09001169 struct gelic_card *card = netdev_card(netdev);
Masakazu Mokuno02c18892007-07-05 20:11:16 +09001170
Masakazu Mokuno59e97322008-02-07 19:58:08 +09001171 gelic_card_set_irq_mask(card, 0);
1172 gelic_card_interrupt(netdev->irq, netdev);
Masakazu Mokuno589866f2008-02-07 19:58:42 +09001173 gelic_card_set_irq_mask(card, card->irq_mask);
Masakazu Mokuno02c18892007-07-05 20:11:16 +09001174}
1175#endif /* CONFIG_NET_POLL_CONTROLLER */
1176
1177/**
Masakazu Mokuno02c18892007-07-05 20:11:16 +09001178 * gelic_net_open - called upon ifonfig up
1179 * @netdev: interface device structure
1180 *
1181 * returns 0 on success, <0 on failure
1182 *
1183 * gelic_net_open allocates all the descriptors and memory needed for
1184 * operation, sets up multicast list and enables interrupts
1185 */
Masakazu Mokuno589866f2008-02-07 19:58:42 +09001186int gelic_net_open(struct net_device *netdev)
Masakazu Mokuno02c18892007-07-05 20:11:16 +09001187{
Masakazu Mokuno589866f2008-02-07 19:58:42 +09001188 struct gelic_card *card = netdev_card(netdev);
Masakazu Mokuno02c18892007-07-05 20:11:16 +09001189
Masakazu Mokuno589866f2008-02-07 19:58:42 +09001190 dev_dbg(ctodev(card), " -> %s %p\n", __func__, netdev);
Masakazu Mokuno02c18892007-07-05 20:11:16 +09001191
Masakazu Mokuno589866f2008-02-07 19:58:42 +09001192 gelic_card_up(card);
Masakazu Mokuno02c18892007-07-05 20:11:16 +09001193
1194 netif_start_queue(netdev);
Masakazu Mokuno01fed4c2008-02-07 19:58:32 +09001195 gelic_card_get_ether_port_status(card, 1);
Masakazu Mokuno02c18892007-07-05 20:11:16 +09001196
Masakazu Mokuno589866f2008-02-07 19:58:42 +09001197 dev_dbg(ctodev(card), " <- %s\n", __func__);
Masakazu Mokuno02c18892007-07-05 20:11:16 +09001198 return 0;
Masakazu Mokuno02c18892007-07-05 20:11:16 +09001199}
1200
Masakazu Mokuno589866f2008-02-07 19:58:42 +09001201void gelic_net_get_drvinfo(struct net_device *netdev,
1202 struct ethtool_drvinfo *info)
Masakazu Mokuno02c18892007-07-05 20:11:16 +09001203{
1204 strncpy(info->driver, DRV_NAME, sizeof(info->driver) - 1);
1205 strncpy(info->version, DRV_VERSION, sizeof(info->version) - 1);
1206}
1207
Masakazu Mokuno59e97322008-02-07 19:58:08 +09001208static int gelic_ether_get_settings(struct net_device *netdev,
1209 struct ethtool_cmd *cmd)
Masakazu Mokuno02c18892007-07-05 20:11:16 +09001210{
Masakazu Mokuno589866f2008-02-07 19:58:42 +09001211 struct gelic_card *card = netdev_card(netdev);
Masakazu Mokuno02c18892007-07-05 20:11:16 +09001212
Masakazu Mokuno01fed4c2008-02-07 19:58:32 +09001213 gelic_card_get_ether_port_status(card, 0);
Masakazu Mokuno02c18892007-07-05 20:11:16 +09001214
Masakazu Mokuno01fed4c2008-02-07 19:58:32 +09001215 if (card->ether_port_status & GELIC_LV1_ETHER_FULL_DUPLEX)
1216 cmd->duplex = DUPLEX_FULL;
1217 else
1218 cmd->duplex = DUPLEX_HALF;
1219
1220 switch (card->ether_port_status & GELIC_LV1_ETHER_SPEED_MASK) {
1221 case GELIC_LV1_ETHER_SPEED_10:
1222 cmd->speed = SPEED_10;
1223 break;
1224 case GELIC_LV1_ETHER_SPEED_100:
1225 cmd->speed = SPEED_100;
1226 break;
1227 case GELIC_LV1_ETHER_SPEED_1000:
1228 cmd->speed = SPEED_1000;
1229 break;
1230 default:
1231 pr_info("%s: speed unknown\n", __func__);
1232 cmd->speed = SPEED_10;
1233 break;
Masakazu Mokuno02c18892007-07-05 20:11:16 +09001234 }
Masakazu Mokuno01fed4c2008-02-07 19:58:32 +09001235
Masakazu Mokuno02c18892007-07-05 20:11:16 +09001236 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;
Masakazu Mokuno02c18892007-07-05 20:11:16 +09001241 cmd->autoneg = AUTONEG_ENABLE; /* always enabled */
1242 cmd->port = PORT_TP;
1243
1244 return 0;
1245}
1246
Masakazu Mokuno589866f2008-02-07 19:58:42 +09001247u32 gelic_net_get_rx_csum(struct net_device *netdev)
Masakazu Mokuno02c18892007-07-05 20:11:16 +09001248{
Masakazu Mokuno589866f2008-02-07 19:58:42 +09001249 struct gelic_card *card = netdev_card(netdev);
Masakazu Mokuno02c18892007-07-05 20:11:16 +09001250
1251 return card->rx_csum;
1252}
1253
Masakazu Mokuno589866f2008-02-07 19:58:42 +09001254int gelic_net_set_rx_csum(struct net_device *netdev, u32 data)
Masakazu Mokuno02c18892007-07-05 20:11:16 +09001255{
Masakazu Mokuno589866f2008-02-07 19:58:42 +09001256 struct gelic_card *card = netdev_card(netdev);
Masakazu Mokuno02c18892007-07-05 20:11:16 +09001257
1258 card->rx_csum = data;
1259 return 0;
1260}
1261
Masakazu Mokuno589866f2008-02-07 19:58:42 +09001262static struct ethtool_ops gelic_ether_ethtool_ops = {
Masakazu Mokuno02c18892007-07-05 20:11:16 +09001263 .get_drvinfo = gelic_net_get_drvinfo,
Masakazu Mokuno59e97322008-02-07 19:58:08 +09001264 .get_settings = gelic_ether_get_settings,
Masakazu Mokuno7bc56b92008-02-07 19:58:20 +09001265 .get_link = ethtool_op_get_link,
Masakazu Mokuno7bc56b92008-02-07 19:58:20 +09001266 .get_tx_csum = ethtool_op_get_tx_csum,
1267 .set_tx_csum = ethtool_op_set_tx_csum,
Masakazu Mokuno02c18892007-07-05 20:11:16 +09001268 .get_rx_csum = gelic_net_get_rx_csum,
1269 .set_rx_csum = gelic_net_set_rx_csum,
1270};
Masakazu Mokuno02c18892007-07-05 20:11:16 +09001271
1272/**
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
1276 *
1277 * called as task when tx hangs, resets interface (if interface is up)
1278 */
1279static void gelic_net_tx_timeout_task(struct work_struct *work)
1280{
Masakazu Mokuno59e97322008-02-07 19:58:08 +09001281 struct gelic_card *card =
1282 container_of(work, struct gelic_card, tx_timeout_task);
Masakazu Mokuno589866f2008-02-07 19:58:42 +09001283 struct net_device *netdev = card->netdev[GELIC_PORT_ETHERNET];
Masakazu Mokuno02c18892007-07-05 20:11:16 +09001284
1285 dev_info(ctodev(card), "%s:Timed out. Restarting... \n", __func__);
1286
1287 if (!(netdev->flags & IFF_UP))
1288 goto out;
1289
1290 netif_device_detach(netdev);
1291 gelic_net_stop(netdev);
1292
1293 gelic_net_open(netdev);
1294 netif_device_attach(netdev);
1295
1296out:
1297 atomic_dec(&card->tx_timeout_task_counter);
1298}
1299
1300/**
1301 * gelic_net_tx_timeout - called when the tx timeout watchdog kicks in.
1302 * @netdev: interface device structure
1303 *
1304 * called, if tx hangs. Schedules a task that resets the interface
1305 */
Masakazu Mokuno589866f2008-02-07 19:58:42 +09001306void gelic_net_tx_timeout(struct net_device *netdev)
Masakazu Mokuno02c18892007-07-05 20:11:16 +09001307{
Masakazu Mokuno59e97322008-02-07 19:58:08 +09001308 struct gelic_card *card;
Masakazu Mokuno02c18892007-07-05 20:11:16 +09001309
Masakazu Mokuno589866f2008-02-07 19:58:42 +09001310 card = netdev_card(netdev);
Masakazu Mokuno02c18892007-07-05 20:11:16 +09001311 atomic_inc(&card->tx_timeout_task_counter);
1312 if (netdev->flags & IFF_UP)
1313 schedule_work(&card->tx_timeout_task);
1314 else
1315 atomic_dec(&card->tx_timeout_task_counter);
1316}
1317
1318/**
Masakazu Mokuno59e97322008-02-07 19:58:08 +09001319 * gelic_ether_setup_netdev_ops - initialization of net_device operations
Masakazu Mokuno02c18892007-07-05 20:11:16 +09001320 * @netdev: net_device structure
1321 *
1322 * fills out function pointers in the net_device structure
1323 */
Masakazu Mokuno589866f2008-02-07 19:58:42 +09001324static void gelic_ether_setup_netdev_ops(struct net_device *netdev,
1325 struct napi_struct *napi)
Masakazu Mokuno02c18892007-07-05 20:11:16 +09001326{
1327 netdev->open = &gelic_net_open;
1328 netdev->stop = &gelic_net_stop;
1329 netdev->hard_start_xmit = &gelic_net_xmit;
Masakazu Mokuno02c18892007-07-05 20:11:16 +09001330 netdev->set_multicast_list = &gelic_net_set_multi;
1331 netdev->change_mtu = &gelic_net_change_mtu;
1332 /* tx watchdog */
1333 netdev->tx_timeout = &gelic_net_tx_timeout;
1334 netdev->watchdog_timeo = GELIC_NET_WATCHDOG_TIMEOUT;
Masakazu Mokuno589866f2008-02-07 19:58:42 +09001335 /* NAPI */
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;
1341#endif
Masakazu Mokuno02c18892007-07-05 20:11:16 +09001342}
1343
1344/**
Masakazu Mokuno589866f2008-02-07 19:58:42 +09001345 * gelic_ether_setup_netdev - initialization of net_device
1346 * @netdev: net_device structure
Masakazu Mokuno02c18892007-07-05 20:11:16 +09001347 * @card: card structure
1348 *
1349 * Returns 0 on success or <0 on failure
1350 *
Masakazu Mokuno589866f2008-02-07 19:58:42 +09001351 * gelic_ether_setup_netdev initializes the net_device structure
1352 * and register it.
Masakazu Mokuno02c18892007-07-05 20:11:16 +09001353 **/
Masakazu Mokuno589866f2008-02-07 19:58:42 +09001354int gelic_net_setup_netdev(struct net_device *netdev, struct gelic_card *card)
Masakazu Mokuno02c18892007-07-05 20:11:16 +09001355{
Masakazu Mokuno02c18892007-07-05 20:11:16 +09001356 int status;
1357 u64 v1, v2;
Joe Perches0795af52007-10-03 17:59:30 -07001358 DECLARE_MAC_BUF(mac);
Masakazu Mokuno02c18892007-07-05 20:11:16 +09001359
Masakazu Mokuno02c18892007-07-05 20:11:16 +09001360 netdev->features = NETIF_F_IP_CSUM;
1361
1362 status = lv1_net_control(bus_id(card), dev_id(card),
Masakazu Mokuno59e97322008-02-07 19:58:08 +09001363 GELIC_LV1_GET_MAC_ADDRESS,
Masakazu Mokuno02c18892007-07-05 20:11:16 +09001364 0, 0, 0, &v1, &v2);
Masakazu Mokuno589866f2008-02-07 19:58:42 +09001365 v1 <<= 16;
Masakazu Mokuno02c18892007-07-05 20:11:16 +09001366 if (status || !is_valid_ether_addr((u8 *)&v1)) {
1367 dev_info(ctodev(card),
1368 "%s:lv1_net_control GET_MAC_ADDR failed %d\n",
1369 __func__, status);
1370 return -EINVAL;
1371 }
Masakazu Mokuno589866f2008-02-07 19:58:42 +09001372 memcpy(netdev->dev_addr, &v1, ETH_ALEN);
Masakazu Mokuno02c18892007-07-05 20:11:16 +09001373
Masakazu Mokuno589866f2008-02-07 19:58:42 +09001374 if (card->vlan_required) {
Masakazu Mokuno173261e2007-08-31 22:22:32 +09001375 netdev->hard_header_len += VLAN_HLEN;
Masakazu Mokuno589866f2008-02-07 19:58:42 +09001376 /*
1377 * As vlan is internally used,
1378 * we can not receive vlan packets
1379 */
1380 netdev->features |= NETIF_F_VLAN_CHALLENGED;
Masakazu Mokuno173261e2007-08-31 22:22:32 +09001381 }
Masakazu Mokuno02c18892007-07-05 20:11:16 +09001382
1383 status = register_netdev(netdev);
1384 if (status) {
Masakazu Mokuno589866f2008-02-07 19:58:42 +09001385 dev_err(ctodev(card), "%s:Couldn't register %s %d\n",
1386 __func__, netdev->name, status);
Masakazu Mokuno02c18892007-07-05 20:11:16 +09001387 return status;
1388 }
Masakazu Mokuno589866f2008-02-07 19:58:42 +09001389 dev_info(ctodev(card), "%s: MAC addr %s\n",
1390 netdev->name,
1391 print_mac(mac, netdev->dev_addr));
Masakazu Mokuno02c18892007-07-05 20:11:16 +09001392
1393 return 0;
1394}
1395
1396/**
Masakazu Mokuno59e97322008-02-07 19:58:08 +09001397 * gelic_alloc_card_net - allocates net_device and card structure
Masakazu Mokuno02c18892007-07-05 20:11:16 +09001398 *
1399 * returns the card structure or NULL in case of errors
1400 *
1401 * the card and net_device structures are linked to each other
1402 */
Masakazu Mokuno589866f2008-02-07 19:58:42 +09001403#define GELIC_ALIGN (32)
1404static struct gelic_card *gelic_alloc_card_net(struct net_device **netdev)
Masakazu Mokuno02c18892007-07-05 20:11:16 +09001405{
Masakazu Mokuno59e97322008-02-07 19:58:08 +09001406 struct gelic_card *card;
Masakazu Mokuno589866f2008-02-07 19:58:42 +09001407 struct gelic_port *port;
1408 void *p;
Masakazu Mokuno02c18892007-07-05 20:11:16 +09001409 size_t alloc_size;
Masakazu Mokuno02c18892007-07-05 20:11:16 +09001410 /*
Masakazu Mokuno589866f2008-02-07 19:58:42 +09001411 * gelic requires dma descriptor is 32 bytes aligned and
1412 * the hypervisor requires irq_status is 8 bytes aligned.
Masakazu Mokuno02c18892007-07-05 20:11:16 +09001413 */
Masakazu Mokuno59e97322008-02-07 19:58:08 +09001414 BUILD_BUG_ON(offsetof(struct gelic_card, irq_status) % 8);
1415 BUILD_BUG_ON(offsetof(struct gelic_card, descr) % 32);
Masakazu Mokuno589866f2008-02-07 19:58:42 +09001416 alloc_size =
1417 sizeof(struct gelic_card) +
1418 sizeof(struct gelic_descr) * GELIC_NET_RX_DESCRIPTORS +
1419 sizeof(struct gelic_descr) * GELIC_NET_TX_DESCRIPTORS +
1420 GELIC_ALIGN - 1;
Masakazu Mokuno02c18892007-07-05 20:11:16 +09001421
Masakazu Mokuno589866f2008-02-07 19:58:42 +09001422 p = kzalloc(alloc_size, GFP_KERNEL);
1423 if (!p)
Masakazu Mokuno02c18892007-07-05 20:11:16 +09001424 return NULL;
Masakazu Mokuno589866f2008-02-07 19:58:42 +09001425 card = PTR_ALIGN(p, GELIC_ALIGN);
1426 card->unalign = p;
Masakazu Mokuno02c18892007-07-05 20:11:16 +09001427
Masakazu Mokuno589866f2008-02-07 19:58:42 +09001428 /*
1429 * alloc netdev
1430 */
1431 *netdev = alloc_etherdev(sizeof(struct gelic_port));
1432 if (!netdev) {
1433 kfree(card->unalign);
1434 return NULL;
1435 }
1436 port = netdev_priv(*netdev);
1437
1438 /* gelic_port */
1439 port->netdev = *netdev;
1440 port->card = card;
1441 port->type = GELIC_PORT_ETHERNET;
1442
1443 /* gelic_card */
1444 card->netdev[GELIC_PORT_ETHERNET] = *netdev;
1445
Masakazu Mokuno02c18892007-07-05 20:11:16 +09001446 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);
Masakazu Mokuno589866f2008-02-07 19:58:42 +09001449 init_MUTEX(&card->updown_lock);
1450 atomic_set(&card->users, 0);
Masakazu Mokuno02c18892007-07-05 20:11:16 +09001451
1452 return card;
1453}
1454
Masakazu Mokuno589866f2008-02-07 19:58:42 +09001455static void gelic_card_get_vlan_info(struct gelic_card *card)
1456{
1457 u64 v1, v2;
1458 int status;
1459 unsigned int i;
1460 struct {
1461 int tx;
1462 int rx;
1463 } vlan_id_ix[2] = {
1464 [GELIC_PORT_ETHERNET] = {
1465 .tx = GELIC_LV1_VLAN_TX_ETHERNET,
1466 .rx = GELIC_LV1_VLAN_RX_ETHERNET
1467 },
1468 [GELIC_PORT_WIRELESS] = {
1469 .tx = GELIC_LV1_VLAN_TX_WIRELESS,
1470 .rx = GELIC_LV1_VLAN_RX_WIRELESS
1471 }
1472 };
1473
1474 for (i = 0; i < ARRAY_SIZE(vlan_id_ix); i++) {
1475 /* tx tag */
1476 status = lv1_net_control(bus_id(card), dev_id(card),
1477 GELIC_LV1_GET_VLAN_ID,
1478 vlan_id_ix[i].tx,
1479 0, 0, &v1, &v2);
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;
1487 continue;
1488 }
1489 card->vlan[i].tx = (u16)v1;
1490
1491 /* rx tag */
1492 status = lv1_net_control(bus_id(card), dev_id(card),
1493 GELIC_LV1_GET_VLAN_ID,
1494 vlan_id_ix[i].rx,
1495 0, 0, &v1, &v2);
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;
1503 continue;
1504 }
1505 card->vlan[i].rx = (u16)v1;
1506
1507 dev_dbg(ctodev(card), "vlan_id[%d] tx=%02x rx=%02x\n",
1508 i, card->vlan[i].tx, card->vlan[i].rx);
1509 }
1510
1511 if (card->vlan[GELIC_PORT_ETHERNET].tx) {
1512 BUG_ON(!card->vlan[GELIC_PORT_WIRELESS].tx);
1513 card->vlan_required = 1;
1514 } else
1515 card->vlan_required = 0;
1516
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;
1521 }
1522
1523 dev_info(ctodev(card), "internal vlan %s\n",
1524 card->vlan_required? "enabled" : "disabled");
1525}
Masakazu Mokuno02c18892007-07-05 20:11:16 +09001526/**
1527 * ps3_gelic_driver_probe - add a device to the control of this driver
1528 */
Masakazu Mokuno59e97322008-02-07 19:58:08 +09001529static int ps3_gelic_driver_probe(struct ps3_system_bus_device *dev)
Masakazu Mokuno02c18892007-07-05 20:11:16 +09001530{
Masakazu Mokuno589866f2008-02-07 19:58:42 +09001531 struct gelic_card *card;
1532 struct net_device *netdev;
Masakazu Mokuno02c18892007-07-05 20:11:16 +09001533 int result;
1534
Masakazu Mokuno589866f2008-02-07 19:58:42 +09001535 pr_debug("%s: called\n", __func__);
Masakazu Mokuno02c18892007-07-05 20:11:16 +09001536 result = ps3_open_hv_device(dev);
1537
1538 if (result) {
Masakazu Mokuno589866f2008-02-07 19:58:42 +09001539 dev_dbg(&dev->core, "%s:ps3_open_hv_device failed\n",
1540 __func__);
Masakazu Mokuno02c18892007-07-05 20:11:16 +09001541 goto fail_open;
1542 }
1543
1544 result = ps3_dma_region_create(dev->d_region);
1545
1546 if (result) {
Masakazu Mokuno589866f2008-02-07 19:58:42 +09001547 dev_dbg(&dev->core, "%s:ps3_dma_region_create failed(%d)\n",
1548 __func__, result);
Masakazu Mokuno02c18892007-07-05 20:11:16 +09001549 BUG_ON("check region type");
1550 goto fail_dma_region;
1551 }
1552
Masakazu Mokuno589866f2008-02-07 19:58:42 +09001553 /* alloc card/netdevice */
1554 card = gelic_alloc_card_net(&netdev);
1555 if (!card) {
1556 dev_info(&dev->core, "%s:gelic_net_alloc_card failed\n",
1557 __func__);
1558 result = -ENOMEM;
1559 goto fail_alloc_card;
1560 }
1561 ps3_system_bus_set_driver_data(dev, card);
1562 card->dev = dev;
1563
1564 /* get internal vlan info */
1565 gelic_card_get_vlan_info(card);
1566
1567 /* setup interrupt */
Masakazu Mokuno02c18892007-07-05 20:11:16 +09001568 result = lv1_net_set_interrupt_status_indicator(bus_id(card),
1569 dev_id(card),
1570 ps3_mm_phys_to_lpar(__pa(&card->irq_status)),
1571 0);
1572
1573 if (result) {
1574 dev_dbg(&dev->core,
Masakazu Mokuno589866f2008-02-07 19:58:42 +09001575 "%s:set_interrupt_status_indicator failed: %s\n",
1576 __func__, ps3_result(result));
Masakazu Mokuno02c18892007-07-05 20:11:16 +09001577 result = -EIO;
1578 goto fail_status_indicator;
1579 }
1580
Masakazu Mokuno589866f2008-02-07 19:58:42 +09001581 result = ps3_sb_event_receive_port_setup(dev, PS3_BINDING_CPU_ANY,
1582 &card->irq);
Masakazu Mokuno02c18892007-07-05 20:11:16 +09001583
1584 if (result) {
Masakazu Mokuno589866f2008-02-07 19:58:42 +09001585 dev_info(ctodev(card),
1586 "%s:gelic_net_open_device failed (%d)\n",
1587 __func__, result);
1588 result = -EPERM;
1589 goto fail_alloc_irq;
1590 }
1591 result = request_irq(card->irq, gelic_card_interrupt,
1592 IRQF_DISABLED, netdev->name, card);
1593
1594 if (result) {
1595 dev_info(ctodev(card), "%s:request_irq failed (%d)\n",
1596 __func__, result);
1597 goto fail_request_irq;
1598 }
1599
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;
1604
1605
1606 if (gelic_card_init_chain(card, &card->tx_chain,
1607 card->descr, GELIC_NET_TX_DESCRIPTORS))
1608 goto fail_alloc_tx;
1609 if (gelic_card_init_chain(card, &card->rx_chain,
1610 card->descr + GELIC_NET_TX_DESCRIPTORS,
1611 GELIC_NET_RX_DESCRIPTORS))
1612 goto fail_alloc_rx;
1613
1614 /* head of chain */
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;
1623
1624 spin_lock_init(&card->tx_lock);
1625 card->tx_dma_progress = 0;
1626
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);
1632 if (result) {
1633 dev_dbg(&dev->core, "%s: setup_netdev failed %d",
1634 __func__, result);
Masakazu Mokuno02c18892007-07-05 20:11:16 +09001635 goto fail_setup_netdev;
1636 }
1637
Masakazu Mokuno589866f2008-02-07 19:58:42 +09001638 pr_debug("%s: done\n", __func__);
Masakazu Mokuno02c18892007-07-05 20:11:16 +09001639 return 0;
1640
1641fail_setup_netdev:
Masakazu Mokuno589866f2008-02-07 19:58:42 +09001642fail_alloc_skbs:
1643 gelic_card_free_chain(card, card->rx_chain.head);
1644fail_alloc_rx:
1645 gelic_card_free_chain(card, card->tx_chain.head);
1646fail_alloc_tx:
1647 free_irq(card->irq, card);
1648 netdev->irq = NO_IRQ;
1649fail_request_irq:
1650 ps3_sb_event_receive_port_destroy(dev, card->irq);
1651fail_alloc_irq:
Masakazu Mokuno02c18892007-07-05 20:11:16 +09001652 lv1_net_set_interrupt_status_indicator(bus_id(card),
Masakazu Mokuno589866f2008-02-07 19:58:42 +09001653 bus_id(card),
1654 0, 0);
Masakazu Mokuno02c18892007-07-05 20:11:16 +09001655fail_status_indicator:
Masakazu Mokuno589866f2008-02-07 19:58:42 +09001656 ps3_system_bus_set_driver_data(dev, NULL);
1657 kfree(netdev_card(netdev)->unalign);
1658 free_netdev(netdev);
1659fail_alloc_card:
Masakazu Mokuno02c18892007-07-05 20:11:16 +09001660 ps3_dma_region_free(dev->d_region);
1661fail_dma_region:
1662 ps3_close_hv_device(dev);
1663fail_open:
Masakazu Mokuno02c18892007-07-05 20:11:16 +09001664 return result;
1665}
1666
1667/**
1668 * ps3_gelic_driver_remove - remove a device from the control of this driver
1669 */
1670
Masakazu Mokuno59e97322008-02-07 19:58:08 +09001671static int ps3_gelic_driver_remove(struct ps3_system_bus_device *dev)
Masakazu Mokuno02c18892007-07-05 20:11:16 +09001672{
Masakazu Mokuno59e97322008-02-07 19:58:08 +09001673 struct gelic_card *card = ps3_system_bus_get_driver_data(dev);
Masakazu Mokuno589866f2008-02-07 19:58:42 +09001674 struct net_device *netdev0;
1675 pr_debug("%s: called\n", __func__);
1676
1677 /* stop interrupt */
1678 gelic_card_set_irq_mask(card, 0);
1679
1680 /* turn off DMA, force end */
1681 gelic_card_disable_rxdmac(card);
1682 gelic_card_disable_txdmac(card);
1683
1684 /* release chains */
1685 gelic_card_release_tx_chain(card, 1);
1686 gelic_card_release_rx_chain(card);
1687
1688 gelic_card_free_chain(card, card->tx_top);
1689 gelic_card_free_chain(card, card->rx_top);
1690
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);
Masakazu Mokuno02c18892007-07-05 20:11:16 +09001696
1697 wait_event(card->waitq,
1698 atomic_read(&card->tx_timeout_task_counter) == 0);
1699
1700 lv1_net_set_interrupt_status_indicator(bus_id(card), dev_id(card),
1701 0 , 0);
1702
Masakazu Mokuno589866f2008-02-07 19:58:42 +09001703 unregister_netdev(netdev0);
1704 kfree(netdev_card(netdev0)->unalign);
1705 free_netdev(netdev0);
Masakazu Mokuno02c18892007-07-05 20:11:16 +09001706
1707 ps3_system_bus_set_driver_data(dev, NULL);
1708
1709 ps3_dma_region_free(dev->d_region);
1710
1711 ps3_close_hv_device(dev);
1712
Masakazu Mokuno589866f2008-02-07 19:58:42 +09001713 pr_debug("%s: done\n", __func__);
Masakazu Mokuno02c18892007-07-05 20:11:16 +09001714 return 0;
1715}
1716
1717static 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,
1724};
1725
1726static int __init ps3_gelic_driver_init (void)
1727{
1728 return firmware_has_feature(FW_FEATURE_PS3_LV1)
1729 ? ps3_system_bus_driver_register(&ps3_gelic_driver)
1730 : -ENODEV;
1731}
1732
1733static void __exit ps3_gelic_driver_exit (void)
1734{
1735 ps3_system_bus_driver_unregister(&ps3_gelic_driver);
1736}
1737
Masakazu Mokuno59e97322008-02-07 19:58:08 +09001738module_init(ps3_gelic_driver_init);
1739module_exit(ps3_gelic_driver_exit);
Masakazu Mokuno02c18892007-07-05 20:11:16 +09001740
1741MODULE_ALIAS(PS3_MODULE_ALIAS_GELIC);
1742