diff options
author | Masakazu Mokuno <mokuno@sm.sony.co.jp> | 2008-02-07 05:58:42 -0500 |
---|---|---|
committer | Jeff Garzik <jeff@garzik.org> | 2008-02-11 10:30:02 -0500 |
commit | 589866f9f1cb14273b644993d362ec7845007f94 (patch) | |
tree | fc36f14ed3b8d583e30264bcb1f9c35fc6818b51 /drivers | |
parent | 01fed4c284def58b8a9ee0b915c3956b93c670b7 (diff) |
PS3: gelic: Add support for dual network interface
Add support for dual network (net_device) interface so that ethernet
and wireless can own separate ethX interfaces.
V2
- Fix the bug that bringing down and up the interface keeps rx
disabled.
- Make 'gelic_net_poll_controller()' extern , as David Woodhouse
pointed out at the previous submission.
- Fix weird usage of member names for the rx descriptor chain
V1
- Export functions which are convenient for both interfaces
- Move irq allocation/release code to driver probe/remove handlers
because interfaces share interrupts.
- Allocate skbs by using dev_alloc_skb() instead of netdev_alloc_skb()
as the interfaces share the hardware rx queue.
- Add gelic_port struct in order to abstract dual interface handling
- Change handlers for hardware queues so that they can handle dual
{source,destination} interfaces.
- Use new NAPI functions
This is a prerequisite for the new PS3 wireless support.
Signed-off-by: Jeff Garzik <jeff@garzik.org>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/net/ps3_gelic_net.c | 765 | ||||
-rw-r--r-- | drivers/net/ps3_gelic_net.h | 108 |
2 files changed, 564 insertions, 309 deletions
diff --git a/drivers/net/ps3_gelic_net.c b/drivers/net/ps3_gelic_net.c index 3b11b1ca0e77..c9dd9c0ee22b 100644 --- a/drivers/net/ps3_gelic_net.c +++ b/drivers/net/ps3_gelic_net.c | |||
@@ -48,27 +48,22 @@ | |||
48 | #include "ps3_gelic_net.h" | 48 | #include "ps3_gelic_net.h" |
49 | 49 | ||
50 | #define DRV_NAME "Gelic Network Driver" | 50 | #define DRV_NAME "Gelic Network Driver" |
51 | #define DRV_VERSION "1.0" | 51 | #define DRV_VERSION "1.1" |
52 | 52 | ||
53 | MODULE_AUTHOR("SCE Inc."); | 53 | MODULE_AUTHOR("SCE Inc."); |
54 | MODULE_DESCRIPTION("Gelic Network driver"); | 54 | MODULE_DESCRIPTION("Gelic Network driver"); |
55 | MODULE_LICENSE("GPL"); | 55 | MODULE_LICENSE("GPL"); |
56 | 56 | ||
57 | static inline struct device *ctodev(struct gelic_card *card) | 57 | |
58 | { | 58 | static inline void gelic_card_enable_rxdmac(struct gelic_card *card); |
59 | return &card->dev->core; | 59 | static inline void gelic_card_disable_rxdmac(struct gelic_card *card); |
60 | } | 60 | static inline void gelic_card_disable_txdmac(struct gelic_card *card); |
61 | static inline u64 bus_id(struct gelic_card *card) | 61 | static inline void gelic_card_reset_chain(struct gelic_card *card, |
62 | { | 62 | struct gelic_descr_chain *chain, |
63 | return card->dev->bus_id; | 63 | struct gelic_descr *start_descr); |
64 | } | ||
65 | static inline u64 dev_id(struct gelic_card *card) | ||
66 | { | ||
67 | return card->dev->dev_id; | ||
68 | } | ||
69 | 64 | ||
70 | /* set irq_mask */ | 65 | /* set irq_mask */ |
71 | static int gelic_card_set_irq_mask(struct gelic_card *card, u64 mask) | 66 | int gelic_card_set_irq_mask(struct gelic_card *card, u64 mask) |
72 | { | 67 | { |
73 | int status; | 68 | int status; |
74 | 69 | ||
@@ -76,20 +71,23 @@ static int gelic_card_set_irq_mask(struct gelic_card *card, u64 mask) | |||
76 | mask, 0); | 71 | mask, 0); |
77 | if (status) | 72 | if (status) |
78 | dev_info(ctodev(card), | 73 | dev_info(ctodev(card), |
79 | "lv1_net_set_interrupt_mask failed %d\n", status); | 74 | "%s failed %d\n", __func__, status); |
80 | return status; | 75 | return status; |
81 | } | 76 | } |
77 | |||
82 | static inline void gelic_card_rx_irq_on(struct gelic_card *card) | 78 | static inline void gelic_card_rx_irq_on(struct gelic_card *card) |
83 | { | 79 | { |
84 | gelic_card_set_irq_mask(card, card->ghiintmask | GELIC_CARD_RXINT); | 80 | card->irq_mask |= GELIC_CARD_RXINT; |
81 | gelic_card_set_irq_mask(card, card->irq_mask); | ||
85 | } | 82 | } |
86 | static inline void gelic_card_rx_irq_off(struct gelic_card *card) | 83 | static inline void gelic_card_rx_irq_off(struct gelic_card *card) |
87 | { | 84 | { |
88 | gelic_card_set_irq_mask(card, card->ghiintmask & ~GELIC_CARD_RXINT); | 85 | card->irq_mask &= ~GELIC_CARD_RXINT; |
86 | gelic_card_set_irq_mask(card, card->irq_mask); | ||
89 | } | 87 | } |
90 | 88 | ||
91 | static void | 89 | static void gelic_card_get_ether_port_status(struct gelic_card *card, |
92 | gelic_card_get_ether_port_status(struct gelic_card *card, int inform) | 90 | int inform) |
93 | { | 91 | { |
94 | u64 v2; | 92 | u64 v2; |
95 | struct net_device *ether_netdev; | 93 | struct net_device *ether_netdev; |
@@ -100,7 +98,7 @@ gelic_card_get_ether_port_status(struct gelic_card *card, int inform) | |||
100 | &card->ether_port_status, &v2); | 98 | &card->ether_port_status, &v2); |
101 | 99 | ||
102 | if (inform) { | 100 | if (inform) { |
103 | ether_netdev = card->netdev; | 101 | ether_netdev = card->netdev[GELIC_PORT_ETHERNET]; |
104 | if (card->ether_port_status & GELIC_LV1_ETHER_LINK_UP) | 102 | if (card->ether_port_status & GELIC_LV1_ETHER_LINK_UP) |
105 | netif_carrier_on(ether_netdev); | 103 | netif_carrier_on(ether_netdev); |
106 | else | 104 | else |
@@ -108,6 +106,48 @@ gelic_card_get_ether_port_status(struct gelic_card *card, int inform) | |||
108 | } | 106 | } |
109 | } | 107 | } |
110 | 108 | ||
109 | void 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 | |||
126 | void 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 | } | ||
111 | 151 | ||
112 | /** | 152 | /** |
113 | * gelic_descr_get_status -- returns the status of a descriptor | 153 | * gelic_descr_get_status -- returns the status of a descriptor |
@@ -133,8 +173,8 @@ static void gelic_descr_set_status(struct gelic_descr *descr, | |||
133 | enum gelic_descr_dma_status status) | 173 | enum gelic_descr_dma_status status) |
134 | { | 174 | { |
135 | descr->dmac_cmd_status = cpu_to_be32(status | | 175 | descr->dmac_cmd_status = cpu_to_be32(status | |
136 | (be32_to_cpu(descr->dmac_cmd_status) & | 176 | (be32_to_cpu(descr->dmac_cmd_status) & |
137 | ~GELIC_DESCR_DMA_STAT_MASK)); | 177 | ~GELIC_DESCR_DMA_STAT_MASK)); |
138 | /* | 178 | /* |
139 | * dma_cmd_status field is used to indicate whether the descriptor | 179 | * dma_cmd_status field is used to indicate whether the descriptor |
140 | * is valid or not. | 180 | * is valid or not. |
@@ -225,6 +265,31 @@ iommu_error: | |||
225 | } | 265 | } |
226 | 266 | ||
227 | /** | 267 | /** |
268 | * gelic_card_reset_chain - reset status of a descriptor chain | ||
269 | * @card: card structure | ||
270 | * @chain: address of chain | ||
271 | * @start_descr: address of descriptor array | ||
272 | * | ||
273 | * Reset the status of dma descriptors to ready state | ||
274 | * and re-initialize the hardware chain for later use | ||
275 | */ | ||
276 | static 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 | /** | ||
228 | * gelic_descr_prepare_rx - reinitializes a rx descriptor | 293 | * gelic_descr_prepare_rx - reinitializes a rx descriptor |
229 | * @card: card structure | 294 | * @card: card structure |
230 | * @descr: descriptor to re-init | 295 | * @descr: descriptor to re-init |
@@ -235,21 +300,19 @@ iommu_error: | |||
235 | * Activate the descriptor state-wise | 300 | * Activate the descriptor state-wise |
236 | */ | 301 | */ |
237 | static int gelic_descr_prepare_rx(struct gelic_card *card, | 302 | static int gelic_descr_prepare_rx(struct gelic_card *card, |
238 | struct gelic_descr *descr) | 303 | struct gelic_descr *descr) |
239 | { | 304 | { |
240 | int offset; | 305 | int offset; |
241 | unsigned int bufsize; | 306 | unsigned int bufsize; |
242 | 307 | ||
243 | if (gelic_descr_get_status(descr) != GELIC_DESCR_DMA_NOT_IN_USE) | 308 | if (gelic_descr_get_status(descr) != GELIC_DESCR_DMA_NOT_IN_USE) |
244 | dev_info(ctodev(card), "%s: ERROR status \n", __func__); | 309 | dev_info(ctodev(card), "%s: ERROR status \n", __func__); |
245 | |||
246 | /* we need to round up the buffer size to a multiple of 128 */ | 310 | /* we need to round up the buffer size to a multiple of 128 */ |
247 | bufsize = ALIGN(GELIC_NET_MAX_MTU, GELIC_NET_RXBUF_ALIGN); | 311 | bufsize = ALIGN(GELIC_NET_MAX_MTU, GELIC_NET_RXBUF_ALIGN); |
248 | 312 | ||
249 | /* and we need to have it 128 byte aligned, therefore we allocate a | 313 | /* and we need to have it 128 byte aligned, therefore we allocate a |
250 | * bit more */ | 314 | * bit more */ |
251 | descr->skb = netdev_alloc_skb(card->netdev, | 315 | descr->skb = dev_alloc_skb(bufsize + GELIC_NET_RXBUF_ALIGN - 1); |
252 | bufsize + GELIC_NET_RXBUF_ALIGN - 1); | ||
253 | if (!descr->skb) { | 316 | if (!descr->skb) { |
254 | descr->buf_addr = 0; /* tell DMAC don't touch memory */ | 317 | descr->buf_addr = 0; /* tell DMAC don't touch memory */ |
255 | dev_info(ctodev(card), | 318 | dev_info(ctodev(card), |
@@ -349,7 +412,7 @@ static int gelic_card_alloc_rx_skbs(struct gelic_card *card) | |||
349 | int ret; | 412 | int ret; |
350 | chain = &card->rx_chain; | 413 | chain = &card->rx_chain; |
351 | ret = gelic_card_fill_rx_chain(card); | 414 | ret = gelic_card_fill_rx_chain(card); |
352 | chain->head = card->rx_top->prev; /* point to the last */ | 415 | chain->tail = card->rx_top->prev; /* point to the last */ |
353 | return ret; | 416 | return ret; |
354 | } | 417 | } |
355 | 418 | ||
@@ -361,16 +424,14 @@ static int gelic_card_alloc_rx_skbs(struct gelic_card *card) | |||
361 | * releases a used tx descriptor (unmapping, freeing of skb) | 424 | * releases a used tx descriptor (unmapping, freeing of skb) |
362 | */ | 425 | */ |
363 | static void gelic_descr_release_tx(struct gelic_card *card, | 426 | static void gelic_descr_release_tx(struct gelic_card *card, |
364 | struct gelic_descr *descr) | 427 | struct gelic_descr *descr) |
365 | { | 428 | { |
366 | struct sk_buff *skb = descr->skb; | 429 | struct sk_buff *skb = descr->skb; |
367 | 430 | ||
368 | #ifdef DEBUG | 431 | BUG_ON(!(be32_to_cpu(descr->data_status) & GELIC_DESCR_TX_TAIL)); |
369 | BUG_ON(!(be32_to_cpu(descr->data_status) & | 432 | |
370 | (1 << GELIC_DESCR_TX_DMA_FRAME_TAIL))); | 433 | dma_unmap_single(ctodev(card), be32_to_cpu(descr->buf_addr), skb->len, |
371 | #endif | 434 | DMA_TO_DEVICE); |
372 | dma_unmap_single(ctodev(card), | ||
373 | be32_to_cpu(descr->buf_addr), skb->len, DMA_TO_DEVICE); | ||
374 | dev_kfree_skb_any(skb); | 435 | dev_kfree_skb_any(skb); |
375 | 436 | ||
376 | descr->buf_addr = 0; | 437 | descr->buf_addr = 0; |
@@ -386,6 +447,20 @@ static void gelic_descr_release_tx(struct gelic_card *card, | |||
386 | gelic_descr_set_status(descr, GELIC_DESCR_DMA_NOT_IN_USE); | 447 | gelic_descr_set_status(descr, GELIC_DESCR_DMA_NOT_IN_USE); |
387 | } | 448 | } |
388 | 449 | ||
450 | static 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 | } | ||
457 | static 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 | } | ||
389 | /** | 464 | /** |
390 | * gelic_card_release_tx_chain - processes sent tx descriptors | 465 | * gelic_card_release_tx_chain - processes sent tx descriptors |
391 | * @card: adapter structure | 466 | * @card: adapter structure |
@@ -397,12 +472,14 @@ static void gelic_card_release_tx_chain(struct gelic_card *card, int stop) | |||
397 | { | 472 | { |
398 | struct gelic_descr_chain *tx_chain; | 473 | struct gelic_descr_chain *tx_chain; |
399 | enum gelic_descr_dma_status status; | 474 | enum gelic_descr_dma_status status; |
475 | struct net_device *netdev; | ||
400 | int release = 0; | 476 | int release = 0; |
401 | 477 | ||
402 | for (tx_chain = &card->tx_chain; | 478 | for (tx_chain = &card->tx_chain; |
403 | tx_chain->head != tx_chain->tail && tx_chain->tail; | 479 | tx_chain->head != tx_chain->tail && tx_chain->tail; |
404 | tx_chain->tail = tx_chain->tail->next) { | 480 | tx_chain->tail = tx_chain->tail->next) { |
405 | status = gelic_descr_get_status(tx_chain->tail); | 481 | status = gelic_descr_get_status(tx_chain->tail); |
482 | netdev = tx_chain->tail->skb->dev; | ||
406 | switch (status) { | 483 | switch (status) { |
407 | case GELIC_DESCR_DMA_RESPONSE_ERROR: | 484 | case GELIC_DESCR_DMA_RESPONSE_ERROR: |
408 | case GELIC_DESCR_DMA_PROTECTION_ERROR: | 485 | case GELIC_DESCR_DMA_PROTECTION_ERROR: |
@@ -412,13 +489,13 @@ static void gelic_card_release_tx_chain(struct gelic_card *card, int stop) | |||
412 | "%s: forcing end of tx descriptor " \ | 489 | "%s: forcing end of tx descriptor " \ |
413 | "with status %x\n", | 490 | "with status %x\n", |
414 | __func__, status); | 491 | __func__, status); |
415 | card->netdev->stats.tx_dropped++; | 492 | netdev->stats.tx_dropped++; |
416 | break; | 493 | break; |
417 | 494 | ||
418 | case GELIC_DESCR_DMA_COMPLETE: | 495 | case GELIC_DESCR_DMA_COMPLETE: |
419 | if (tx_chain->tail->skb) { | 496 | if (tx_chain->tail->skb) { |
420 | card->netdev->stats.tx_packets++; | 497 | netdev->stats.tx_packets++; |
421 | card->netdev->stats.tx_bytes += | 498 | netdev->stats.tx_bytes += |
422 | tx_chain->tail->skb->len; | 499 | tx_chain->tail->skb->len; |
423 | } | 500 | } |
424 | break; | 501 | break; |
@@ -435,7 +512,7 @@ static void gelic_card_release_tx_chain(struct gelic_card *card, int stop) | |||
435 | } | 512 | } |
436 | out: | 513 | out: |
437 | if (!stop && release) | 514 | if (!stop && release) |
438 | netif_wake_queue(card->netdev); | 515 | gelic_card_wake_queues(card); |
439 | } | 516 | } |
440 | 517 | ||
441 | /** | 518 | /** |
@@ -446,9 +523,9 @@ out: | |||
446 | * netdev interface. It also sets up multicast, allmulti and promisc | 523 | * netdev interface. It also sets up multicast, allmulti and promisc |
447 | * flags appropriately | 524 | * flags appropriately |
448 | */ | 525 | */ |
449 | static void gelic_net_set_multi(struct net_device *netdev) | 526 | void gelic_net_set_multi(struct net_device *netdev) |
450 | { | 527 | { |
451 | struct gelic_card *card = netdev_priv(netdev); | 528 | struct gelic_card *card = netdev_card(netdev); |
452 | struct dev_mc_list *mc; | 529 | struct dev_mc_list *mc; |
453 | unsigned int i; | 530 | unsigned int i; |
454 | uint8_t *p; | 531 | uint8_t *p; |
@@ -470,8 +547,8 @@ static void gelic_net_set_multi(struct net_device *netdev) | |||
470 | "lv1_net_add_multicast_address failed, %d\n", | 547 | "lv1_net_add_multicast_address failed, %d\n", |
471 | status); | 548 | status); |
472 | 549 | ||
473 | if (netdev->flags & IFF_ALLMULTI | 550 | if ((netdev->flags & IFF_ALLMULTI) || |
474 | || netdev->mc_count > GELIC_NET_MC_COUNT_MAX) { /* list max */ | 551 | (netdev->mc_count > GELIC_NET_MC_COUNT_MAX)) { |
475 | status = lv1_net_add_multicast_address(bus_id(card), | 552 | status = lv1_net_add_multicast_address(bus_id(card), |
476 | dev_id(card), | 553 | dev_id(card), |
477 | 0, 1); | 554 | 0, 1); |
@@ -482,7 +559,7 @@ static void gelic_net_set_multi(struct net_device *netdev) | |||
482 | return; | 559 | return; |
483 | } | 560 | } |
484 | 561 | ||
485 | /* set multicast address */ | 562 | /* set multicast addresses */ |
486 | for (mc = netdev->mc_list; mc; mc = mc->next) { | 563 | for (mc = netdev->mc_list; mc; mc = mc->next) { |
487 | addr = 0; | 564 | addr = 0; |
488 | p = mc->dmi_addr; | 565 | p = mc->dmi_addr; |
@@ -511,8 +588,19 @@ static inline void gelic_card_enable_rxdmac(struct gelic_card *card) | |||
511 | { | 588 | { |
512 | int status; | 589 | int status; |
513 | 590 | ||
591 | #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 | ||
514 | status = lv1_net_start_rx_dma(bus_id(card), dev_id(card), | 602 | status = lv1_net_start_rx_dma(bus_id(card), dev_id(card), |
515 | card->rx_chain.tail->bus_addr, 0); | 603 | card->rx_chain.head->bus_addr, 0); |
516 | if (status) | 604 | if (status) |
517 | dev_info(ctodev(card), | 605 | dev_info(ctodev(card), |
518 | "lv1_net_start_rx_dma failed, status=%d\n", status); | 606 | "lv1_net_start_rx_dma failed, status=%d\n", status); |
@@ -560,33 +648,19 @@ static inline void gelic_card_disable_txdmac(struct gelic_card *card) | |||
560 | * | 648 | * |
561 | * always returns 0 | 649 | * always returns 0 |
562 | */ | 650 | */ |
563 | static int gelic_net_stop(struct net_device *netdev) | 651 | int gelic_net_stop(struct net_device *netdev) |
564 | { | 652 | { |
565 | struct gelic_card *card = netdev_priv(netdev); | 653 | struct gelic_card *card; |
566 | |||
567 | napi_disable(&card->napi); | ||
568 | netif_stop_queue(netdev); | ||
569 | |||
570 | /* turn off DMA, force end */ | ||
571 | gelic_card_disable_rxdmac(card); | ||
572 | gelic_card_disable_txdmac(card); | ||
573 | |||
574 | gelic_card_set_irq_mask(card, 0); | ||
575 | 654 | ||
576 | /* disconnect event port */ | 655 | pr_debug("%s: start\n", __func__); |
577 | free_irq(card->netdev->irq, card->netdev); | ||
578 | ps3_sb_event_receive_port_destroy(card->dev, card->netdev->irq); | ||
579 | card->netdev->irq = NO_IRQ; | ||
580 | 656 | ||
657 | netif_stop_queue(netdev); | ||
581 | netif_carrier_off(netdev); | 658 | netif_carrier_off(netdev); |
582 | 659 | ||
583 | /* release chains */ | 660 | card = netdev_card(netdev); |
584 | gelic_card_release_tx_chain(card, 1); | 661 | gelic_card_down(card); |
585 | gelic_card_release_rx_chain(card); | ||
586 | |||
587 | gelic_card_free_chain(card, card->tx_top); | ||
588 | gelic_card_free_chain(card, card->rx_top); | ||
589 | 662 | ||
663 | pr_debug("%s: done\n", __func__); | ||
590 | return 0; | 664 | return 0; |
591 | } | 665 | } |
592 | 666 | ||
@@ -612,7 +686,7 @@ gelic_card_get_next_tx_descr(struct gelic_card *card) | |||
612 | } | 686 | } |
613 | 687 | ||
614 | /** | 688 | /** |
615 | * gelic_descr_set_tx_cmdstat - sets the tx descriptor command field | 689 | * gelic_net_set_txdescr_cmdstat - sets the tx descriptor command field |
616 | * @descr: descriptor structure to fill out | 690 | * @descr: descriptor structure to fill out |
617 | * @skb: packet to consider | 691 | * @skb: packet to consider |
618 | * | 692 | * |
@@ -677,7 +751,7 @@ static inline struct sk_buff *gelic_put_vlan_tag(struct sk_buff *skb, | |||
677 | } | 751 | } |
678 | 752 | ||
679 | /** | 753 | /** |
680 | * gelic_descr_prepare_tx - get dma address of skb_data | 754 | * gelic_descr_prepare_tx - setup a descriptor for sending packets |
681 | * @card: card structure | 755 | * @card: card structure |
682 | * @descr: descriptor structure | 756 | * @descr: descriptor structure |
683 | * @skb: packet to use | 757 | * @skb: packet to use |
@@ -691,10 +765,13 @@ static int gelic_descr_prepare_tx(struct gelic_card *card, | |||
691 | { | 765 | { |
692 | dma_addr_t buf; | 766 | dma_addr_t buf; |
693 | 767 | ||
694 | if (card->vlan_index != -1) { | 768 | if (card->vlan_required) { |
695 | struct sk_buff *skb_tmp; | 769 | struct sk_buff *skb_tmp; |
770 | enum gelic_port_type type; | ||
771 | |||
772 | type = netdev_port(skb->dev)->type; | ||
696 | skb_tmp = gelic_put_vlan_tag(skb, | 773 | skb_tmp = gelic_put_vlan_tag(skb, |
697 | card->vlan_id[card->vlan_index]); | 774 | card->vlan[type].tx); |
698 | if (!skb_tmp) | 775 | if (!skb_tmp) |
699 | return -ENOMEM; | 776 | return -ENOMEM; |
700 | skb = skb_tmp; | 777 | skb = skb_tmp; |
@@ -753,14 +830,14 @@ static int gelic_card_kick_txdma(struct gelic_card *card, | |||
753 | * | 830 | * |
754 | * returns 0 on success, <0 on failure | 831 | * returns 0 on success, <0 on failure |
755 | */ | 832 | */ |
756 | static int gelic_net_xmit(struct sk_buff *skb, struct net_device *netdev) | 833 | int gelic_net_xmit(struct sk_buff *skb, struct net_device *netdev) |
757 | { | 834 | { |
758 | struct gelic_card *card = netdev_priv(netdev); | 835 | struct gelic_card *card = netdev_card(netdev); |
759 | struct gelic_descr *descr; | 836 | struct gelic_descr *descr; |
760 | int result; | 837 | int result; |
761 | unsigned long flags; | 838 | unsigned long flags; |
762 | 839 | ||
763 | spin_lock_irqsave(&card->tx_dma_lock, flags); | 840 | spin_lock_irqsave(&card->tx_lock, flags); |
764 | 841 | ||
765 | gelic_card_release_tx_chain(card, 0); | 842 | gelic_card_release_tx_chain(card, 0); |
766 | 843 | ||
@@ -769,8 +846,8 @@ static int gelic_net_xmit(struct sk_buff *skb, struct net_device *netdev) | |||
769 | /* | 846 | /* |
770 | * no more descriptors free | 847 | * no more descriptors free |
771 | */ | 848 | */ |
772 | netif_stop_queue(netdev); | 849 | gelic_card_stop_queues(card); |
773 | spin_unlock_irqrestore(&card->tx_dma_lock, flags); | 850 | spin_unlock_irqrestore(&card->tx_lock, flags); |
774 | return NETDEV_TX_BUSY; | 851 | return NETDEV_TX_BUSY; |
775 | } | 852 | } |
776 | 853 | ||
@@ -780,9 +857,9 @@ static int gelic_net_xmit(struct sk_buff *skb, struct net_device *netdev) | |||
780 | * DMA map failed. As chanses are that failure | 857 | * DMA map failed. As chanses are that failure |
781 | * would continue, just release skb and return | 858 | * would continue, just release skb and return |
782 | */ | 859 | */ |
783 | card->netdev->stats.tx_dropped++; | 860 | netdev->stats.tx_dropped++; |
784 | dev_kfree_skb_any(skb); | 861 | dev_kfree_skb_any(skb); |
785 | spin_unlock_irqrestore(&card->tx_dma_lock, flags); | 862 | spin_unlock_irqrestore(&card->tx_lock, flags); |
786 | return NETDEV_TX_OK; | 863 | return NETDEV_TX_OK; |
787 | } | 864 | } |
788 | /* | 865 | /* |
@@ -800,7 +877,7 @@ static int gelic_net_xmit(struct sk_buff *skb, struct net_device *netdev) | |||
800 | * kick failed. | 877 | * kick failed. |
801 | * release descriptors which were just prepared | 878 | * release descriptors which were just prepared |
802 | */ | 879 | */ |
803 | card->netdev->stats.tx_dropped++; | 880 | netdev->stats.tx_dropped++; |
804 | gelic_descr_release_tx(card, descr); | 881 | gelic_descr_release_tx(card, descr); |
805 | gelic_descr_release_tx(card, descr->next); | 882 | gelic_descr_release_tx(card, descr->next); |
806 | card->tx_chain.tail = descr->next->next; | 883 | card->tx_chain.tail = descr->next->next; |
@@ -810,7 +887,7 @@ static int gelic_net_xmit(struct sk_buff *skb, struct net_device *netdev) | |||
810 | netdev->trans_start = jiffies; | 887 | netdev->trans_start = jiffies; |
811 | } | 888 | } |
812 | 889 | ||
813 | spin_unlock_irqrestore(&card->tx_dma_lock, flags); | 890 | spin_unlock_irqrestore(&card->tx_lock, flags); |
814 | return NETDEV_TX_OK; | 891 | return NETDEV_TX_OK; |
815 | } | 892 | } |
816 | 893 | ||
@@ -818,27 +895,27 @@ static int gelic_net_xmit(struct sk_buff *skb, struct net_device *netdev) | |||
818 | * gelic_net_pass_skb_up - takes an skb from a descriptor and passes it on | 895 | * gelic_net_pass_skb_up - takes an skb from a descriptor and passes it on |
819 | * @descr: descriptor to process | 896 | * @descr: descriptor to process |
820 | * @card: card structure | 897 | * @card: card structure |
898 | * @netdev: net_device structure to be passed packet | ||
821 | * | 899 | * |
822 | * iommu-unmaps the skb, fills out skb structure and passes the data to the | 900 | * iommu-unmaps the skb, fills out skb structure and passes the data to the |
823 | * stack. The descriptor state is not changed. | 901 | * stack. The descriptor state is not changed. |
824 | */ | 902 | */ |
825 | static void gelic_net_pass_skb_up(struct gelic_descr *descr, | 903 | static void gelic_net_pass_skb_up(struct gelic_descr *descr, |
826 | struct gelic_card *card) | 904 | struct gelic_card *card, |
905 | struct net_device *netdev) | ||
906 | |||
827 | { | 907 | { |
828 | struct sk_buff *skb; | 908 | struct sk_buff *skb = descr->skb; |
829 | struct net_device *netdev; | ||
830 | u32 data_status, data_error; | 909 | u32 data_status, data_error; |
831 | 910 | ||
832 | data_status = be32_to_cpu(descr->data_status); | 911 | data_status = be32_to_cpu(descr->data_status); |
833 | data_error = be32_to_cpu(descr->data_error); | 912 | data_error = be32_to_cpu(descr->data_error); |
834 | netdev = card->netdev; | ||
835 | /* unmap skb buffer */ | 913 | /* unmap skb buffer */ |
836 | skb = descr->skb; | 914 | dma_unmap_single(ctodev(card), be32_to_cpu(descr->buf_addr), |
837 | dma_unmap_single(ctodev(card), | 915 | GELIC_NET_MAX_MTU, |
838 | be32_to_cpu(descr->buf_addr), GELIC_NET_MAX_MTU, | ||
839 | DMA_FROM_DEVICE); | 916 | DMA_FROM_DEVICE); |
840 | 917 | ||
841 | skb_put(skb, descr->valid_size ? | 918 | skb_put(skb, be32_to_cpu(descr->valid_size)? |
842 | be32_to_cpu(descr->valid_size) : | 919 | be32_to_cpu(descr->valid_size) : |
843 | be32_to_cpu(descr->result_size)); | 920 | be32_to_cpu(descr->result_size)); |
844 | if (!descr->valid_size) | 921 | if (!descr->valid_size) |
@@ -866,8 +943,8 @@ static void gelic_net_pass_skb_up(struct gelic_descr *descr, | |||
866 | skb->ip_summed = CHECKSUM_NONE; | 943 | skb->ip_summed = CHECKSUM_NONE; |
867 | 944 | ||
868 | /* update netdevice statistics */ | 945 | /* update netdevice statistics */ |
869 | card->netdev->stats.rx_packets++; | 946 | netdev->stats.rx_packets++; |
870 | card->netdev->stats.rx_bytes += skb->len; | 947 | netdev->stats.rx_bytes += skb->len; |
871 | 948 | ||
872 | /* pass skb up to stack */ | 949 | /* pass skb up to stack */ |
873 | netif_receive_skb(skb); | 950 | netif_receive_skb(skb); |
@@ -886,7 +963,8 @@ static int gelic_card_decode_one_descr(struct gelic_card *card) | |||
886 | { | 963 | { |
887 | enum gelic_descr_dma_status status; | 964 | enum gelic_descr_dma_status status; |
888 | struct gelic_descr_chain *chain = &card->rx_chain; | 965 | struct gelic_descr_chain *chain = &card->rx_chain; |
889 | struct gelic_descr *descr = chain->tail; | 966 | struct gelic_descr *descr = chain->head; |
967 | struct net_device *netdev = NULL; | ||
890 | int dmac_chain_ended; | 968 | int dmac_chain_ended; |
891 | 969 | ||
892 | status = gelic_descr_get_status(descr); | 970 | status = gelic_descr_get_status(descr); |
@@ -903,12 +981,30 @@ static int gelic_card_decode_one_descr(struct gelic_card *card) | |||
903 | return 0; | 981 | return 0; |
904 | } | 982 | } |
905 | 983 | ||
984 | /* 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 | |||
906 | if ((status == GELIC_DESCR_DMA_RESPONSE_ERROR) || | 1002 | if ((status == GELIC_DESCR_DMA_RESPONSE_ERROR) || |
907 | (status == GELIC_DESCR_DMA_PROTECTION_ERROR) || | 1003 | (status == GELIC_DESCR_DMA_PROTECTION_ERROR) || |
908 | (status == GELIC_DESCR_DMA_FORCE_END)) { | 1004 | (status == GELIC_DESCR_DMA_FORCE_END)) { |
909 | dev_info(ctodev(card), "dropping RX descriptor with state %x\n", | 1005 | dev_info(ctodev(card), "dropping RX descriptor with state %x\n", |
910 | status); | 1006 | status); |
911 | card->netdev->stats.rx_dropped++; | 1007 | netdev->stats.rx_dropped++; |
912 | goto refill; | 1008 | goto refill; |
913 | } | 1009 | } |
914 | 1010 | ||
@@ -936,7 +1032,7 @@ static int gelic_card_decode_one_descr(struct gelic_card *card) | |||
936 | } | 1032 | } |
937 | 1033 | ||
938 | /* ok, we've got a packet in descr */ | 1034 | /* ok, we've got a packet in descr */ |
939 | gelic_net_pass_skb_up(descr, card); | 1035 | gelic_net_pass_skb_up(descr, card, netdev); |
940 | refill: | 1036 | refill: |
941 | /* | 1037 | /* |
942 | * So that always DMAC can see the end | 1038 | * So that always DMAC can see the end |
@@ -954,8 +1050,8 @@ refill: | |||
954 | */ | 1050 | */ |
955 | gelic_descr_prepare_rx(card, descr); | 1051 | gelic_descr_prepare_rx(card, descr); |
956 | 1052 | ||
957 | chain->head = descr; | 1053 | chain->tail = descr; |
958 | chain->tail = descr->next; | 1054 | chain->head = descr->next; |
959 | 1055 | ||
960 | /* | 1056 | /* |
961 | * Set this descriptor the end of the chain. | 1057 | * Set this descriptor the end of the chain. |
@@ -976,17 +1072,15 @@ refill: | |||
976 | 1072 | ||
977 | /** | 1073 | /** |
978 | * gelic_net_poll - NAPI poll function called by the stack to return packets | 1074 | * gelic_net_poll - NAPI poll function called by the stack to return packets |
979 | * @netdev: interface device structure | 1075 | * @napi: napi structure |
980 | * @budget: number of packets we can pass to the stack at most | 1076 | * @budget: number of packets we can pass to the stack at most |
981 | * | 1077 | * |
982 | * returns 0 if no more packets available to the driver/stack. Returns 1, | 1078 | * returns the number of the processed packets |
983 | * if the quota is exceeded, but the driver has still packets. | ||
984 | * | 1079 | * |
985 | */ | 1080 | */ |
986 | static int gelic_net_poll(struct napi_struct *napi, int budget) | 1081 | static int gelic_net_poll(struct napi_struct *napi, int budget) |
987 | { | 1082 | { |
988 | struct gelic_card *card = container_of(napi, struct gelic_card, napi); | 1083 | struct gelic_card *card = container_of(napi, struct gelic_card, napi); |
989 | struct net_device *netdev = card->netdev; | ||
990 | int packets_done = 0; | 1084 | int packets_done = 0; |
991 | 1085 | ||
992 | while (packets_done < budget) { | 1086 | while (packets_done < budget) { |
@@ -997,7 +1091,7 @@ static int gelic_net_poll(struct napi_struct *napi, int budget) | |||
997 | } | 1091 | } |
998 | 1092 | ||
999 | if (packets_done < budget) { | 1093 | if (packets_done < budget) { |
1000 | netif_rx_complete(netdev, napi); | 1094 | napi_complete(napi); |
1001 | gelic_card_rx_irq_on(card); | 1095 | gelic_card_rx_irq_on(card); |
1002 | } | 1096 | } |
1003 | return packets_done; | 1097 | return packets_done; |
@@ -1009,7 +1103,7 @@ static int gelic_net_poll(struct napi_struct *napi, int budget) | |||
1009 | * | 1103 | * |
1010 | * returns 0 on success, <0 on failure | 1104 | * returns 0 on success, <0 on failure |
1011 | */ | 1105 | */ |
1012 | static int gelic_net_change_mtu(struct net_device *netdev, int new_mtu) | 1106 | int gelic_net_change_mtu(struct net_device *netdev, int new_mtu) |
1013 | { | 1107 | { |
1014 | /* no need to re-alloc skbs or so -- the max mtu is about 2.3k | 1108 | /* no need to re-alloc skbs or so -- the max mtu is about 2.3k |
1015 | * and mtu is outbound only anyway */ | 1109 | * and mtu is outbound only anyway */ |
@@ -1027,8 +1121,7 @@ static int gelic_net_change_mtu(struct net_device *netdev, int new_mtu) | |||
1027 | static irqreturn_t gelic_card_interrupt(int irq, void *ptr) | 1121 | static irqreturn_t gelic_card_interrupt(int irq, void *ptr) |
1028 | { | 1122 | { |
1029 | unsigned long flags; | 1123 | unsigned long flags; |
1030 | struct net_device *netdev = ptr; | 1124 | struct gelic_card *card = ptr; |
1031 | struct gelic_card *card = netdev_priv(netdev); | ||
1032 | u64 status; | 1125 | u64 status; |
1033 | 1126 | ||
1034 | status = card->irq_status; | 1127 | status = card->irq_status; |
@@ -1036,6 +1129,8 @@ static irqreturn_t gelic_card_interrupt(int irq, void *ptr) | |||
1036 | if (!status) | 1129 | if (!status) |
1037 | return IRQ_NONE; | 1130 | return IRQ_NONE; |
1038 | 1131 | ||
1132 | status &= card->irq_mask; | ||
1133 | |||
1039 | if (card->rx_dma_restart_required) { | 1134 | if (card->rx_dma_restart_required) { |
1040 | card->rx_dma_restart_required = 0; | 1135 | card->rx_dma_restart_required = 0; |
1041 | gelic_card_enable_rxdmac(card); | 1136 | gelic_card_enable_rxdmac(card); |
@@ -1043,21 +1138,22 @@ static irqreturn_t gelic_card_interrupt(int irq, void *ptr) | |||
1043 | 1138 | ||
1044 | if (status & GELIC_CARD_RXINT) { | 1139 | if (status & GELIC_CARD_RXINT) { |
1045 | gelic_card_rx_irq_off(card); | 1140 | gelic_card_rx_irq_off(card); |
1046 | netif_rx_schedule(netdev, &card->napi); | 1141 | napi_schedule(&card->napi); |
1047 | } | 1142 | } |
1048 | 1143 | ||
1049 | if (status & GELIC_CARD_TXINT) { | 1144 | if (status & GELIC_CARD_TXINT) { |
1050 | spin_lock_irqsave(&card->tx_dma_lock, flags); | 1145 | spin_lock_irqsave(&card->tx_lock, flags); |
1051 | card->tx_dma_progress = 0; | 1146 | card->tx_dma_progress = 0; |
1052 | gelic_card_release_tx_chain(card, 0); | 1147 | gelic_card_release_tx_chain(card, 0); |
1053 | /* kick outstanding tx descriptor if any */ | 1148 | /* kick outstanding tx descriptor if any */ |
1054 | gelic_card_kick_txdma(card, card->tx_chain.tail); | 1149 | gelic_card_kick_txdma(card, card->tx_chain.tail); |
1055 | spin_unlock_irqrestore(&card->tx_dma_lock, flags); | 1150 | spin_unlock_irqrestore(&card->tx_lock, flags); |
1056 | } | 1151 | } |
1057 | 1152 | ||
1058 | /* ether port status changed */ | 1153 | /* ether port status changed */ |
1059 | if (status & GELIC_CARD_PORT_STATUS_CHANGED) | 1154 | if (status & GELIC_CARD_PORT_STATUS_CHANGED) |
1060 | gelic_card_get_ether_port_status(card, 1); | 1155 | gelic_card_get_ether_port_status(card, 1); |
1156 | |||
1061 | return IRQ_HANDLED; | 1157 | return IRQ_HANDLED; |
1062 | } | 1158 | } |
1063 | 1159 | ||
@@ -1068,55 +1164,17 @@ static irqreturn_t gelic_card_interrupt(int irq, void *ptr) | |||
1068 | * | 1164 | * |
1069 | * see Documentation/networking/netconsole.txt | 1165 | * see Documentation/networking/netconsole.txt |
1070 | */ | 1166 | */ |
1071 | static void gelic_net_poll_controller(struct net_device *netdev) | 1167 | void gelic_net_poll_controller(struct net_device *netdev) |
1072 | { | 1168 | { |
1073 | struct gelic_card *card = netdev_priv(netdev); | 1169 | struct gelic_card *card = netdev_card(netdev); |
1074 | 1170 | ||
1075 | gelic_card_set_irq_mask(card, 0); | 1171 | gelic_card_set_irq_mask(card, 0); |
1076 | gelic_card_interrupt(netdev->irq, netdev); | 1172 | gelic_card_interrupt(netdev->irq, netdev); |
1077 | gelic_card_set_irq_mask(card, card->ghiintmask); | 1173 | gelic_card_set_irq_mask(card, card->irq_mask); |
1078 | } | 1174 | } |
1079 | #endif /* CONFIG_NET_POLL_CONTROLLER */ | 1175 | #endif /* CONFIG_NET_POLL_CONTROLLER */ |
1080 | 1176 | ||
1081 | /** | 1177 | /** |
1082 | * gelic_card_open - open device and map dma region | ||
1083 | * @card: card structure | ||
1084 | */ | ||
1085 | static int gelic_card_open(struct gelic_card *card) | ||
1086 | { | ||
1087 | int result; | ||
1088 | |||
1089 | result = ps3_sb_event_receive_port_setup(card->dev, PS3_BINDING_CPU_ANY, | ||
1090 | &card->netdev->irq); | ||
1091 | |||
1092 | if (result) { | ||
1093 | dev_info(ctodev(card), | ||
1094 | "%s:%d: recieve_port_setup failed (%d)\n", | ||
1095 | __func__, __LINE__, result); | ||
1096 | result = -EPERM; | ||
1097 | goto fail_alloc_irq; | ||
1098 | } | ||
1099 | |||
1100 | result = request_irq(card->netdev->irq, gelic_card_interrupt, | ||
1101 | IRQF_DISABLED, card->netdev->name, card->netdev); | ||
1102 | |||
1103 | if (result) { | ||
1104 | dev_info(ctodev(card), "%s:%d: request_irq failed (%d)\n", | ||
1105 | __func__, __LINE__, result); | ||
1106 | goto fail_request_irq; | ||
1107 | } | ||
1108 | |||
1109 | return 0; | ||
1110 | |||
1111 | fail_request_irq: | ||
1112 | ps3_sb_event_receive_port_destroy(card->dev, card->netdev->irq); | ||
1113 | card->netdev->irq = NO_IRQ; | ||
1114 | fail_alloc_irq: | ||
1115 | return result; | ||
1116 | } | ||
1117 | |||
1118 | |||
1119 | /** | ||
1120 | * gelic_net_open - called upon ifonfig up | 1178 | * gelic_net_open - called upon ifonfig up |
1121 | * @netdev: interface device structure | 1179 | * @netdev: interface device structure |
1122 | * | 1180 | * |
@@ -1125,56 +1183,23 @@ fail_alloc_irq: | |||
1125 | * gelic_net_open allocates all the descriptors and memory needed for | 1183 | * gelic_net_open allocates all the descriptors and memory needed for |
1126 | * operation, sets up multicast list and enables interrupts | 1184 | * operation, sets up multicast list and enables interrupts |
1127 | */ | 1185 | */ |
1128 | static int gelic_net_open(struct net_device *netdev) | 1186 | int gelic_net_open(struct net_device *netdev) |
1129 | { | 1187 | { |
1130 | struct gelic_card *card = netdev_priv(netdev); | 1188 | struct gelic_card *card = netdev_card(netdev); |
1131 | |||
1132 | dev_dbg(ctodev(card), " -> %s:%d\n", __func__, __LINE__); | ||
1133 | 1189 | ||
1134 | gelic_card_open(card); | 1190 | dev_dbg(ctodev(card), " -> %s %p\n", __func__, netdev); |
1135 | 1191 | ||
1136 | if (gelic_card_init_chain(card, &card->tx_chain, | 1192 | gelic_card_up(card); |
1137 | card->descr, GELIC_NET_TX_DESCRIPTORS)) | ||
1138 | goto alloc_tx_failed; | ||
1139 | if (gelic_card_init_chain(card, &card->rx_chain, | ||
1140 | card->descr + GELIC_NET_TX_DESCRIPTORS, | ||
1141 | GELIC_NET_RX_DESCRIPTORS)) | ||
1142 | goto alloc_rx_failed; | ||
1143 | |||
1144 | /* head of chain */ | ||
1145 | card->tx_top = card->tx_chain.head; | ||
1146 | card->rx_top = card->rx_chain.head; | ||
1147 | dev_dbg(ctodev(card), "descr rx %p, tx %p, size %#lx, num %#x\n", | ||
1148 | card->rx_top, card->tx_top, sizeof(struct gelic_descr), | ||
1149 | GELIC_NET_RX_DESCRIPTORS); | ||
1150 | /* allocate rx skbs */ | ||
1151 | if (gelic_card_alloc_rx_skbs(card)) | ||
1152 | goto alloc_skbs_failed; | ||
1153 | |||
1154 | napi_enable(&card->napi); | ||
1155 | |||
1156 | card->tx_dma_progress = 0; | ||
1157 | card->ghiintmask = GELIC_CARD_RXINT | GELIC_CARD_TXINT | | ||
1158 | GELIC_CARD_PORT_STATUS_CHANGED; | ||
1159 | |||
1160 | gelic_card_set_irq_mask(card, card->ghiintmask); | ||
1161 | gelic_card_enable_rxdmac(card); | ||
1162 | 1193 | ||
1163 | netif_start_queue(netdev); | 1194 | netif_start_queue(netdev); |
1164 | gelic_card_get_ether_port_status(card, 1); | 1195 | gelic_card_get_ether_port_status(card, 1); |
1165 | 1196 | ||
1197 | dev_dbg(ctodev(card), " <- %s\n", __func__); | ||
1166 | return 0; | 1198 | return 0; |
1167 | |||
1168 | alloc_skbs_failed: | ||
1169 | gelic_card_free_chain(card, card->rx_top); | ||
1170 | alloc_rx_failed: | ||
1171 | gelic_card_free_chain(card, card->tx_top); | ||
1172 | alloc_tx_failed: | ||
1173 | return -ENOMEM; | ||
1174 | } | 1199 | } |
1175 | 1200 | ||
1176 | static void gelic_net_get_drvinfo(struct net_device *netdev, | 1201 | void gelic_net_get_drvinfo(struct net_device *netdev, |
1177 | struct ethtool_drvinfo *info) | 1202 | struct ethtool_drvinfo *info) |
1178 | { | 1203 | { |
1179 | strncpy(info->driver, DRV_NAME, sizeof(info->driver) - 1); | 1204 | strncpy(info->driver, DRV_NAME, sizeof(info->driver) - 1); |
1180 | strncpy(info->version, DRV_VERSION, sizeof(info->version) - 1); | 1205 | strncpy(info->version, DRV_VERSION, sizeof(info->version) - 1); |
@@ -1183,7 +1208,7 @@ static void gelic_net_get_drvinfo(struct net_device *netdev, | |||
1183 | static int gelic_ether_get_settings(struct net_device *netdev, | 1208 | static int gelic_ether_get_settings(struct net_device *netdev, |
1184 | struct ethtool_cmd *cmd) | 1209 | struct ethtool_cmd *cmd) |
1185 | { | 1210 | { |
1186 | struct gelic_card *card = netdev_priv(netdev); | 1211 | struct gelic_card *card = netdev_card(netdev); |
1187 | 1212 | ||
1188 | gelic_card_get_ether_port_status(card, 0); | 1213 | gelic_card_get_ether_port_status(card, 0); |
1189 | 1214 | ||
@@ -1219,35 +1244,25 @@ static int gelic_ether_get_settings(struct net_device *netdev, | |||
1219 | return 0; | 1244 | return 0; |
1220 | } | 1245 | } |
1221 | 1246 | ||
1222 | static int gelic_net_nway_reset(struct net_device *netdev) | 1247 | u32 gelic_net_get_rx_csum(struct net_device *netdev) |
1223 | { | 1248 | { |
1224 | if (netif_running(netdev)) { | 1249 | struct gelic_card *card = netdev_card(netdev); |
1225 | gelic_net_stop(netdev); | ||
1226 | gelic_net_open(netdev); | ||
1227 | } | ||
1228 | return 0; | ||
1229 | } | ||
1230 | |||
1231 | static u32 gelic_net_get_rx_csum(struct net_device *netdev) | ||
1232 | { | ||
1233 | struct gelic_card *card = netdev_priv(netdev); | ||
1234 | 1250 | ||
1235 | return card->rx_csum; | 1251 | return card->rx_csum; |
1236 | } | 1252 | } |
1237 | 1253 | ||
1238 | static int gelic_net_set_rx_csum(struct net_device *netdev, u32 data) | 1254 | int gelic_net_set_rx_csum(struct net_device *netdev, u32 data) |
1239 | { | 1255 | { |
1240 | struct gelic_card *card = netdev_priv(netdev); | 1256 | struct gelic_card *card = netdev_card(netdev); |
1241 | 1257 | ||
1242 | card->rx_csum = data; | 1258 | card->rx_csum = data; |
1243 | return 0; | 1259 | return 0; |
1244 | } | 1260 | } |
1245 | 1261 | ||
1246 | static struct ethtool_ops gelic_net_ethtool_ops = { | 1262 | static struct ethtool_ops gelic_ether_ethtool_ops = { |
1247 | .get_drvinfo = gelic_net_get_drvinfo, | 1263 | .get_drvinfo = gelic_net_get_drvinfo, |
1248 | .get_settings = gelic_ether_get_settings, | 1264 | .get_settings = gelic_ether_get_settings, |
1249 | .get_link = ethtool_op_get_link, | 1265 | .get_link = ethtool_op_get_link, |
1250 | .nway_reset = gelic_net_nway_reset, | ||
1251 | .get_tx_csum = ethtool_op_get_tx_csum, | 1266 | .get_tx_csum = ethtool_op_get_tx_csum, |
1252 | .set_tx_csum = ethtool_op_set_tx_csum, | 1267 | .set_tx_csum = ethtool_op_set_tx_csum, |
1253 | .get_rx_csum = gelic_net_get_rx_csum, | 1268 | .get_rx_csum = gelic_net_get_rx_csum, |
@@ -1265,7 +1280,7 @@ static void gelic_net_tx_timeout_task(struct work_struct *work) | |||
1265 | { | 1280 | { |
1266 | struct gelic_card *card = | 1281 | struct gelic_card *card = |
1267 | container_of(work, struct gelic_card, tx_timeout_task); | 1282 | container_of(work, struct gelic_card, tx_timeout_task); |
1268 | struct net_device *netdev = card->netdev; | 1283 | struct net_device *netdev = card->netdev[GELIC_PORT_ETHERNET]; |
1269 | 1284 | ||
1270 | dev_info(ctodev(card), "%s:Timed out. Restarting... \n", __func__); | 1285 | dev_info(ctodev(card), "%s:Timed out. Restarting... \n", __func__); |
1271 | 1286 | ||
@@ -1288,11 +1303,11 @@ out: | |||
1288 | * | 1303 | * |
1289 | * called, if tx hangs. Schedules a task that resets the interface | 1304 | * called, if tx hangs. Schedules a task that resets the interface |
1290 | */ | 1305 | */ |
1291 | static void gelic_net_tx_timeout(struct net_device *netdev) | 1306 | void gelic_net_tx_timeout(struct net_device *netdev) |
1292 | { | 1307 | { |
1293 | struct gelic_card *card; | 1308 | struct gelic_card *card; |
1294 | 1309 | ||
1295 | card = netdev_priv(netdev); | 1310 | card = netdev_card(netdev); |
1296 | atomic_inc(&card->tx_timeout_task_counter); | 1311 | atomic_inc(&card->tx_timeout_task_counter); |
1297 | if (netdev->flags & IFF_UP) | 1312 | if (netdev->flags & IFF_UP) |
1298 | schedule_work(&card->tx_timeout_task); | 1313 | schedule_work(&card->tx_timeout_task); |
@@ -1306,7 +1321,8 @@ static void gelic_net_tx_timeout(struct net_device *netdev) | |||
1306 | * | 1321 | * |
1307 | * fills out function pointers in the net_device structure | 1322 | * fills out function pointers in the net_device structure |
1308 | */ | 1323 | */ |
1309 | static void gelic_ether_setup_netdev_ops(struct net_device *netdev) | 1324 | static void gelic_ether_setup_netdev_ops(struct net_device *netdev, |
1325 | struct napi_struct *napi) | ||
1310 | { | 1326 | { |
1311 | netdev->open = &gelic_net_open; | 1327 | netdev->open = &gelic_net_open; |
1312 | netdev->stop = &gelic_net_stop; | 1328 | netdev->stop = &gelic_net_stop; |
@@ -1316,86 +1332,63 @@ static void gelic_ether_setup_netdev_ops(struct net_device *netdev) | |||
1316 | /* tx watchdog */ | 1332 | /* tx watchdog */ |
1317 | netdev->tx_timeout = &gelic_net_tx_timeout; | 1333 | netdev->tx_timeout = &gelic_net_tx_timeout; |
1318 | netdev->watchdog_timeo = GELIC_NET_WATCHDOG_TIMEOUT; | 1334 | netdev->watchdog_timeo = GELIC_NET_WATCHDOG_TIMEOUT; |
1319 | netdev->ethtool_ops = &gelic_net_ethtool_ops; | 1335 | /* 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 | ||
1320 | } | 1342 | } |
1321 | 1343 | ||
1322 | /** | 1344 | /** |
1323 | * gelic_net_setup_netdev - initialization of net_device | 1345 | * gelic_ether_setup_netdev - initialization of net_device |
1346 | * @netdev: net_device structure | ||
1324 | * @card: card structure | 1347 | * @card: card structure |
1325 | * | 1348 | * |
1326 | * Returns 0 on success or <0 on failure | 1349 | * Returns 0 on success or <0 on failure |
1327 | * | 1350 | * |
1328 | * gelic_net_setup_netdev initializes the net_device structure | 1351 | * gelic_ether_setup_netdev initializes the net_device structure |
1352 | * and register it. | ||
1329 | **/ | 1353 | **/ |
1330 | static int gelic_net_setup_netdev(struct gelic_card *card) | 1354 | int gelic_net_setup_netdev(struct net_device *netdev, struct gelic_card *card) |
1331 | { | 1355 | { |
1332 | struct net_device *netdev = card->netdev; | ||
1333 | struct sockaddr addr; | ||
1334 | unsigned int i; | ||
1335 | int status; | 1356 | int status; |
1336 | u64 v1, v2; | 1357 | u64 v1, v2; |
1337 | DECLARE_MAC_BUF(mac); | 1358 | DECLARE_MAC_BUF(mac); |
1338 | 1359 | ||
1339 | SET_NETDEV_DEV(netdev, &card->dev->core); | ||
1340 | spin_lock_init(&card->tx_dma_lock); | ||
1341 | |||
1342 | card->rx_csum = GELIC_NET_RX_CSUM_DEFAULT; | ||
1343 | |||
1344 | gelic_ether_setup_netdev_ops(netdev); | ||
1345 | |||
1346 | netif_napi_add(netdev, &card->napi, | ||
1347 | gelic_net_poll, GELIC_NET_NAPI_WEIGHT); | ||
1348 | |||
1349 | netdev->features = NETIF_F_IP_CSUM; | 1360 | netdev->features = NETIF_F_IP_CSUM; |
1350 | 1361 | ||
1351 | status = lv1_net_control(bus_id(card), dev_id(card), | 1362 | status = lv1_net_control(bus_id(card), dev_id(card), |
1352 | GELIC_LV1_GET_MAC_ADDRESS, | 1363 | GELIC_LV1_GET_MAC_ADDRESS, |
1353 | 0, 0, 0, &v1, &v2); | 1364 | 0, 0, 0, &v1, &v2); |
1365 | v1 <<= 16; | ||
1354 | if (status || !is_valid_ether_addr((u8 *)&v1)) { | 1366 | if (status || !is_valid_ether_addr((u8 *)&v1)) { |
1355 | dev_info(ctodev(card), | 1367 | dev_info(ctodev(card), |
1356 | "%s:lv1_net_control GET_MAC_ADDR failed %d\n", | 1368 | "%s:lv1_net_control GET_MAC_ADDR failed %d\n", |
1357 | __func__, status); | 1369 | __func__, status); |
1358 | return -EINVAL; | 1370 | return -EINVAL; |
1359 | } | 1371 | } |
1360 | v1 <<= 16; | 1372 | memcpy(netdev->dev_addr, &v1, ETH_ALEN); |
1361 | memcpy(addr.sa_data, &v1, ETH_ALEN); | ||
1362 | memcpy(netdev->dev_addr, addr.sa_data, ETH_ALEN); | ||
1363 | dev_info(ctodev(card), "MAC addr %s\n", | ||
1364 | print_mac(mac, netdev->dev_addr)); | ||
1365 | |||
1366 | card->vlan_index = -1; /* no vlan */ | ||
1367 | for (i = 0; i < GELIC_NET_VLAN_MAX; i++) { | ||
1368 | status = lv1_net_control(bus_id(card), dev_id(card), | ||
1369 | GELIC_LV1_GET_VLAN_ID, | ||
1370 | i + 1, /* index; one based */ | ||
1371 | 0, 0, &v1, &v2); | ||
1372 | if (status == LV1_NO_ENTRY) { | ||
1373 | dev_dbg(ctodev(card), | ||
1374 | "GELIC_VLAN_ID no entry:%d, VLAN disabled\n", | ||
1375 | status); | ||
1376 | card->vlan_id[i] = 0; | ||
1377 | } else if (status) { | ||
1378 | dev_dbg(ctodev(card), | ||
1379 | "%s:get vlan id faild, status=%d\n", | ||
1380 | __func__, status); | ||
1381 | card->vlan_id[i] = 0; | ||
1382 | } else { | ||
1383 | card->vlan_id[i] = (u32)v1; | ||
1384 | dev_dbg(ctodev(card), "vlan_id:%d, %lx\n", i, v1); | ||
1385 | } | ||
1386 | } | ||
1387 | 1373 | ||
1388 | if (card->vlan_id[GELIC_LV1_VLAN_TX_ETHERNET - 1]) { | 1374 | if (card->vlan_required) { |
1389 | card->vlan_index = GELIC_LV1_VLAN_TX_ETHERNET - 1; | ||
1390 | netdev->hard_header_len += VLAN_HLEN; | 1375 | netdev->hard_header_len += VLAN_HLEN; |
1376 | /* | ||
1377 | * As vlan is internally used, | ||
1378 | * we can not receive vlan packets | ||
1379 | */ | ||
1380 | netdev->features |= NETIF_F_VLAN_CHALLENGED; | ||
1391 | } | 1381 | } |
1392 | 1382 | ||
1393 | status = register_netdev(netdev); | 1383 | status = register_netdev(netdev); |
1394 | if (status) { | 1384 | if (status) { |
1395 | dev_err(ctodev(card), "%s:Couldn't register net_device: %d\n", | 1385 | dev_err(ctodev(card), "%s:Couldn't register %s %d\n", |
1396 | __func__, status); | 1386 | __func__, netdev->name, status); |
1397 | return status; | 1387 | return status; |
1398 | } | 1388 | } |
1389 | dev_info(ctodev(card), "%s: MAC addr %s\n", | ||
1390 | netdev->name, | ||
1391 | print_mac(mac, netdev->dev_addr)); | ||
1399 | 1392 | ||
1400 | return 0; | 1393 | return 0; |
1401 | } | 1394 | } |
@@ -1407,72 +1400,171 @@ static int gelic_net_setup_netdev(struct gelic_card *card) | |||
1407 | * | 1400 | * |
1408 | * the card and net_device structures are linked to each other | 1401 | * the card and net_device structures are linked to each other |
1409 | */ | 1402 | */ |
1410 | static struct gelic_card *gelic_alloc_card_net(void) | 1403 | #define GELIC_ALIGN (32) |
1404 | static struct gelic_card *gelic_alloc_card_net(struct net_device **netdev) | ||
1411 | { | 1405 | { |
1412 | struct net_device *netdev; | ||
1413 | struct gelic_card *card; | 1406 | struct gelic_card *card; |
1407 | struct gelic_port *port; | ||
1408 | void *p; | ||
1414 | size_t alloc_size; | 1409 | size_t alloc_size; |
1415 | |||
1416 | alloc_size = sizeof(*card) + | ||
1417 | sizeof(struct gelic_descr) * GELIC_NET_RX_DESCRIPTORS + | ||
1418 | sizeof(struct gelic_descr) * GELIC_NET_TX_DESCRIPTORS; | ||
1419 | /* | 1410 | /* |
1420 | * we assume private data is allocated 32 bytes (or more) aligned | 1411 | * gelic requires dma descriptor is 32 bytes aligned and |
1421 | * so that gelic_descr should be 32 bytes aligned. | 1412 | * the hypervisor requires irq_status is 8 bytes aligned. |
1422 | * Current alloc_etherdev() does do it because NETDEV_ALIGN | ||
1423 | * is 32. | ||
1424 | * check this assumption here. | ||
1425 | */ | 1413 | */ |
1426 | BUILD_BUG_ON(NETDEV_ALIGN < 32); | ||
1427 | BUILD_BUG_ON(offsetof(struct gelic_card, irq_status) % 8); | 1414 | BUILD_BUG_ON(offsetof(struct gelic_card, irq_status) % 8); |
1428 | BUILD_BUG_ON(offsetof(struct gelic_card, descr) % 32); | 1415 | BUILD_BUG_ON(offsetof(struct gelic_card, descr) % 32); |
1416 | 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; | ||
1429 | 1421 | ||
1430 | netdev = alloc_etherdev(alloc_size); | 1422 | p = kzalloc(alloc_size, GFP_KERNEL); |
1431 | if (!netdev) | 1423 | if (!p) |
1432 | return NULL; | 1424 | return NULL; |
1425 | card = PTR_ALIGN(p, GELIC_ALIGN); | ||
1426 | card->unalign = p; | ||
1427 | |||
1428 | /* | ||
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; | ||
1433 | 1445 | ||
1434 | card = netdev_priv(netdev); | ||
1435 | card->netdev = netdev; | ||
1436 | INIT_WORK(&card->tx_timeout_task, gelic_net_tx_timeout_task); | 1446 | INIT_WORK(&card->tx_timeout_task, gelic_net_tx_timeout_task); |
1437 | init_waitqueue_head(&card->waitq); | 1447 | init_waitqueue_head(&card->waitq); |
1438 | atomic_set(&card->tx_timeout_task_counter, 0); | 1448 | atomic_set(&card->tx_timeout_task_counter, 0); |
1449 | init_MUTEX(&card->updown_lock); | ||
1450 | atomic_set(&card->users, 0); | ||
1439 | 1451 | ||
1440 | return card; | 1452 | return card; |
1441 | } | 1453 | } |
1442 | 1454 | ||
1455 | static 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 | } | ||
1443 | /** | 1526 | /** |
1444 | * ps3_gelic_driver_probe - add a device to the control of this driver | 1527 | * ps3_gelic_driver_probe - add a device to the control of this driver |
1445 | */ | 1528 | */ |
1446 | static int ps3_gelic_driver_probe(struct ps3_system_bus_device *dev) | 1529 | static int ps3_gelic_driver_probe(struct ps3_system_bus_device *dev) |
1447 | { | 1530 | { |
1448 | struct gelic_card *card = gelic_alloc_card_net(); | 1531 | struct gelic_card *card; |
1532 | struct net_device *netdev; | ||
1449 | int result; | 1533 | int result; |
1450 | 1534 | ||
1451 | if (!card) { | 1535 | pr_debug("%s: called\n", __func__); |
1452 | dev_info(&dev->core, "gelic_net_alloc_card failed\n"); | ||
1453 | result = -ENOMEM; | ||
1454 | goto fail_alloc_card; | ||
1455 | } | ||
1456 | |||
1457 | ps3_system_bus_set_driver_data(dev, card); | ||
1458 | card->dev = dev; | ||
1459 | |||
1460 | result = ps3_open_hv_device(dev); | 1536 | result = ps3_open_hv_device(dev); |
1461 | 1537 | ||
1462 | if (result) { | 1538 | if (result) { |
1463 | dev_dbg(&dev->core, "ps3_open_hv_device failed\n"); | 1539 | dev_dbg(&dev->core, "%s:ps3_open_hv_device failed\n", |
1540 | __func__); | ||
1464 | goto fail_open; | 1541 | goto fail_open; |
1465 | } | 1542 | } |
1466 | 1543 | ||
1467 | result = ps3_dma_region_create(dev->d_region); | 1544 | result = ps3_dma_region_create(dev->d_region); |
1468 | 1545 | ||
1469 | if (result) { | 1546 | if (result) { |
1470 | dev_dbg(&dev->core, "ps3_dma_region_create failed(%d)\n", | 1547 | dev_dbg(&dev->core, "%s:ps3_dma_region_create failed(%d)\n", |
1471 | result); | 1548 | __func__, result); |
1472 | BUG_ON("check region type"); | 1549 | BUG_ON("check region type"); |
1473 | goto fail_dma_region; | 1550 | goto fail_dma_region; |
1474 | } | 1551 | } |
1475 | 1552 | ||
1553 | /* 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 */ | ||
1476 | result = lv1_net_set_interrupt_status_indicator(bus_id(card), | 1568 | result = lv1_net_set_interrupt_status_indicator(bus_id(card), |
1477 | dev_id(card), | 1569 | dev_id(card), |
1478 | ps3_mm_phys_to_lpar(__pa(&card->irq_status)), | 1570 | ps3_mm_phys_to_lpar(__pa(&card->irq_status)), |
@@ -1480,34 +1572,95 @@ static int ps3_gelic_driver_probe(struct ps3_system_bus_device *dev) | |||
1480 | 1572 | ||
1481 | if (result) { | 1573 | if (result) { |
1482 | dev_dbg(&dev->core, | 1574 | dev_dbg(&dev->core, |
1483 | "lv1_net_set_interrupt_status_indicator failed: %s\n", | 1575 | "%s:set_interrupt_status_indicator failed: %s\n", |
1484 | ps3_result(result)); | 1576 | __func__, ps3_result(result)); |
1485 | result = -EIO; | 1577 | result = -EIO; |
1486 | goto fail_status_indicator; | 1578 | goto fail_status_indicator; |
1487 | } | 1579 | } |
1488 | 1580 | ||
1489 | result = gelic_net_setup_netdev(card); | 1581 | result = ps3_sb_event_receive_port_setup(dev, PS3_BINDING_CPU_ANY, |
1582 | &card->irq); | ||
1583 | |||
1584 | if (result) { | ||
1585 | 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; | ||
1490 | 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); | ||
1491 | if (result) { | 1632 | if (result) { |
1492 | dev_dbg(&dev->core, "%s:%d: ps3_dma_region_create failed: " | 1633 | dev_dbg(&dev->core, "%s: setup_netdev failed %d", |
1493 | "(%d)\n", __func__, __LINE__, result); | 1634 | __func__, result); |
1494 | goto fail_setup_netdev; | 1635 | goto fail_setup_netdev; |
1495 | } | 1636 | } |
1496 | 1637 | ||
1638 | pr_debug("%s: done\n", __func__); | ||
1497 | return 0; | 1639 | return 0; |
1498 | 1640 | ||
1499 | fail_setup_netdev: | 1641 | fail_setup_netdev: |
1642 | fail_alloc_skbs: | ||
1643 | gelic_card_free_chain(card, card->rx_chain.head); | ||
1644 | fail_alloc_rx: | ||
1645 | gelic_card_free_chain(card, card->tx_chain.head); | ||
1646 | fail_alloc_tx: | ||
1647 | free_irq(card->irq, card); | ||
1648 | netdev->irq = NO_IRQ; | ||
1649 | fail_request_irq: | ||
1650 | ps3_sb_event_receive_port_destroy(dev, card->irq); | ||
1651 | fail_alloc_irq: | ||
1500 | lv1_net_set_interrupt_status_indicator(bus_id(card), | 1652 | lv1_net_set_interrupt_status_indicator(bus_id(card), |
1501 | dev_id(card), | 1653 | bus_id(card), |
1502 | 0 , 0); | 1654 | 0, 0); |
1503 | fail_status_indicator: | 1655 | fail_status_indicator: |
1656 | ps3_system_bus_set_driver_data(dev, NULL); | ||
1657 | kfree(netdev_card(netdev)->unalign); | ||
1658 | free_netdev(netdev); | ||
1659 | fail_alloc_card: | ||
1504 | ps3_dma_region_free(dev->d_region); | 1660 | ps3_dma_region_free(dev->d_region); |
1505 | fail_dma_region: | 1661 | fail_dma_region: |
1506 | ps3_close_hv_device(dev); | 1662 | ps3_close_hv_device(dev); |
1507 | fail_open: | 1663 | fail_open: |
1508 | ps3_system_bus_set_driver_data(dev, NULL); | ||
1509 | free_netdev(card->netdev); | ||
1510 | fail_alloc_card: | ||
1511 | return result; | 1664 | return result; |
1512 | } | 1665 | } |
1513 | 1666 | ||
@@ -1518,6 +1671,28 @@ fail_alloc_card: | |||
1518 | static int ps3_gelic_driver_remove(struct ps3_system_bus_device *dev) | 1671 | static int ps3_gelic_driver_remove(struct ps3_system_bus_device *dev) |
1519 | { | 1672 | { |
1520 | struct gelic_card *card = ps3_system_bus_get_driver_data(dev); | 1673 | struct gelic_card *card = ps3_system_bus_get_driver_data(dev); |
1674 | struct net_device *netdev0; | ||
1675 | pr_debug("%s: called\n", __func__); | ||
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); | ||
1521 | 1696 | ||
1522 | wait_event(card->waitq, | 1697 | wait_event(card->waitq, |
1523 | atomic_read(&card->tx_timeout_task_counter) == 0); | 1698 | atomic_read(&card->tx_timeout_task_counter) == 0); |
@@ -1525,8 +1700,9 @@ static int ps3_gelic_driver_remove(struct ps3_system_bus_device *dev) | |||
1525 | lv1_net_set_interrupt_status_indicator(bus_id(card), dev_id(card), | 1700 | lv1_net_set_interrupt_status_indicator(bus_id(card), dev_id(card), |
1526 | 0 , 0); | 1701 | 0 , 0); |
1527 | 1702 | ||
1528 | unregister_netdev(card->netdev); | 1703 | unregister_netdev(netdev0); |
1529 | free_netdev(card->netdev); | 1704 | kfree(netdev_card(netdev0)->unalign); |
1705 | free_netdev(netdev0); | ||
1530 | 1706 | ||
1531 | ps3_system_bus_set_driver_data(dev, NULL); | 1707 | ps3_system_bus_set_driver_data(dev, NULL); |
1532 | 1708 | ||
@@ -1534,6 +1710,7 @@ static int ps3_gelic_driver_remove(struct ps3_system_bus_device *dev) | |||
1534 | 1710 | ||
1535 | ps3_close_hv_device(dev); | 1711 | ps3_close_hv_device(dev); |
1536 | 1712 | ||
1713 | pr_debug("%s: done\n", __func__); | ||
1537 | return 0; | 1714 | return 0; |
1538 | } | 1715 | } |
1539 | 1716 | ||
diff --git a/drivers/net/ps3_gelic_net.h b/drivers/net/ps3_gelic_net.h index 957221fa5d55..46cfdcdcdbea 100644 --- a/drivers/net/ps3_gelic_net.h +++ b/drivers/net/ps3_gelic_net.h | |||
@@ -35,12 +35,11 @@ | |||
35 | #define GELIC_NET_MAX_MTU VLAN_ETH_FRAME_LEN | 35 | #define GELIC_NET_MAX_MTU VLAN_ETH_FRAME_LEN |
36 | #define GELIC_NET_MIN_MTU VLAN_ETH_ZLEN | 36 | #define GELIC_NET_MIN_MTU VLAN_ETH_ZLEN |
37 | #define GELIC_NET_RXBUF_ALIGN 128 | 37 | #define GELIC_NET_RXBUF_ALIGN 128 |
38 | #define GELIC_NET_RX_CSUM_DEFAULT 1 /* hw chksum */ | 38 | #define GELIC_CARD_RX_CSUM_DEFAULT 1 /* hw chksum */ |
39 | #define GELIC_NET_WATCHDOG_TIMEOUT 5*HZ | 39 | #define GELIC_NET_WATCHDOG_TIMEOUT 5*HZ |
40 | #define GELIC_NET_NAPI_WEIGHT (GELIC_NET_RX_DESCRIPTORS) | 40 | #define GELIC_NET_NAPI_WEIGHT (GELIC_NET_RX_DESCRIPTORS) |
41 | #define GELIC_NET_BROADCAST_ADDR 0xffffffffffffL | 41 | #define GELIC_NET_BROADCAST_ADDR 0xffffffffffffL |
42 | #define GELIC_NET_VLAN_POS (VLAN_ETH_ALEN * 2) | 42 | |
43 | #define GELIC_NET_VLAN_MAX 4 | ||
44 | #define GELIC_NET_MC_COUNT_MAX 32 /* multicast address list */ | 43 | #define GELIC_NET_MC_COUNT_MAX 32 /* multicast address list */ |
45 | 44 | ||
46 | /* virtual interrupt status register bits */ | 45 | /* virtual interrupt status register bits */ |
@@ -206,6 +205,13 @@ enum gelic_lv1_vlan_index { | |||
206 | 205 | ||
207 | /* size of hardware part of gelic descriptor */ | 206 | /* size of hardware part of gelic descriptor */ |
208 | #define GELIC_DESCR_SIZE (32) | 207 | #define GELIC_DESCR_SIZE (32) |
208 | |||
209 | enum gelic_port_type { | ||
210 | GELIC_PORT_ETHERNET = 0, | ||
211 | GELIC_PORT_WIRELESS = 1, | ||
212 | GELIC_PORT_MAX | ||
213 | }; | ||
214 | |||
209 | struct gelic_descr { | 215 | struct gelic_descr { |
210 | /* as defined by the hardware */ | 216 | /* as defined by the hardware */ |
211 | __be32 buf_addr; | 217 | __be32 buf_addr; |
@@ -222,7 +228,6 @@ struct gelic_descr { | |||
222 | dma_addr_t bus_addr; | 228 | dma_addr_t bus_addr; |
223 | struct gelic_descr *next; | 229 | struct gelic_descr *next; |
224 | struct gelic_descr *prev; | 230 | struct gelic_descr *prev; |
225 | struct vlan_ethhdr vlan; | ||
226 | } __attribute__((aligned(32))); | 231 | } __attribute__((aligned(32))); |
227 | 232 | ||
228 | struct gelic_descr_chain { | 233 | struct gelic_descr_chain { |
@@ -231,43 +236,116 @@ struct gelic_descr_chain { | |||
231 | struct gelic_descr *tail; | 236 | struct gelic_descr *tail; |
232 | }; | 237 | }; |
233 | 238 | ||
239 | struct gelic_vlan_id { | ||
240 | u16 tx; | ||
241 | u16 rx; | ||
242 | }; | ||
243 | |||
234 | struct gelic_card { | 244 | struct gelic_card { |
235 | struct net_device *netdev; | ||
236 | struct napi_struct napi; | 245 | struct napi_struct napi; |
246 | struct net_device *netdev[GELIC_PORT_MAX]; | ||
237 | /* | 247 | /* |
238 | * hypervisor requires irq_status should be | 248 | * hypervisor requires irq_status should be |
239 | * 8 bytes aligned, but u64 member is | 249 | * 8 bytes aligned, but u64 member is |
240 | * always disposed in that manner | 250 | * always disposed in that manner |
241 | */ | 251 | */ |
242 | u64 irq_status; | 252 | u64 irq_status; |
243 | u64 ghiintmask; | 253 | u64 irq_mask; |
244 | 254 | ||
245 | struct ps3_system_bus_device *dev; | 255 | struct ps3_system_bus_device *dev; |
246 | u32 vlan_id[GELIC_NET_VLAN_MAX]; | 256 | struct gelic_vlan_id vlan[GELIC_PORT_MAX]; |
247 | int vlan_index; | 257 | int vlan_required; |
248 | 258 | ||
249 | struct gelic_descr_chain tx_chain; | 259 | struct gelic_descr_chain tx_chain; |
250 | struct gelic_descr_chain rx_chain; | 260 | struct gelic_descr_chain rx_chain; |
251 | int rx_dma_restart_required; | 261 | int rx_dma_restart_required; |
252 | /* gurad dmac descriptor chain*/ | ||
253 | spinlock_t chain_lock; | ||
254 | |||
255 | int rx_csum; | 262 | int rx_csum; |
256 | /* guard tx_dma_progress */ | 263 | /* |
257 | spinlock_t tx_dma_lock; | 264 | * tx_lock guards tx descriptor list and |
265 | * tx_dma_progress. | ||
266 | */ | ||
267 | spinlock_t tx_lock; | ||
258 | int tx_dma_progress; | 268 | int tx_dma_progress; |
259 | 269 | ||
260 | struct work_struct tx_timeout_task; | 270 | struct work_struct tx_timeout_task; |
261 | atomic_t tx_timeout_task_counter; | 271 | atomic_t tx_timeout_task_counter; |
262 | wait_queue_head_t waitq; | 272 | wait_queue_head_t waitq; |
263 | 273 | ||
274 | /* only first user should up the card */ | ||
275 | struct semaphore updown_lock; | ||
276 | atomic_t users; | ||
277 | |||
264 | u64 ether_port_status; | 278 | u64 ether_port_status; |
279 | /* original address returned by kzalloc */ | ||
280 | void *unalign; | ||
265 | 281 | ||
282 | /* | ||
283 | * each netdevice has copy of irq | ||
284 | */ | ||
285 | unsigned int irq; | ||
266 | struct gelic_descr *tx_top, *rx_top; | 286 | struct gelic_descr *tx_top, *rx_top; |
267 | struct gelic_descr descr[0]; | 287 | struct gelic_descr descr[0]; /* must be the last */ |
268 | }; | 288 | }; |
269 | 289 | ||
290 | struct gelic_port { | ||
291 | struct gelic_card *card; | ||
292 | struct net_device *netdev; | ||
293 | enum gelic_port_type type; | ||
294 | long priv[0]; /* long for alignment */ | ||
295 | }; | ||
270 | 296 | ||
271 | extern unsigned long p_to_lp(long pa); | 297 | static inline struct gelic_card *port_to_card(struct gelic_port *p) |
298 | { | ||
299 | return p->card; | ||
300 | } | ||
301 | static inline struct net_device *port_to_netdev(struct gelic_port *p) | ||
302 | { | ||
303 | return p->netdev; | ||
304 | } | ||
305 | static inline struct gelic_card *netdev_card(struct net_device *d) | ||
306 | { | ||
307 | return ((struct gelic_port *)netdev_priv(d))->card; | ||
308 | } | ||
309 | static inline struct gelic_port *netdev_port(struct net_device *d) | ||
310 | { | ||
311 | return (struct gelic_port *)netdev_priv(d); | ||
312 | } | ||
313 | static inline struct device *ctodev(struct gelic_card *card) | ||
314 | { | ||
315 | return &card->dev->core; | ||
316 | } | ||
317 | static inline u64 bus_id(struct gelic_card *card) | ||
318 | { | ||
319 | return card->dev->bus_id; | ||
320 | } | ||
321 | static inline u64 dev_id(struct gelic_card *card) | ||
322 | { | ||
323 | return card->dev->dev_id; | ||
324 | } | ||
325 | |||
326 | static inline void *port_priv(struct gelic_port *port) | ||
327 | { | ||
328 | return port->priv; | ||
329 | } | ||
330 | |||
331 | extern int gelic_card_set_irq_mask(struct gelic_card *card, u64 mask); | ||
332 | /* shared netdev ops */ | ||
333 | extern void gelic_card_up(struct gelic_card *card); | ||
334 | extern void gelic_card_down(struct gelic_card *card); | ||
335 | extern int gelic_net_open(struct net_device *netdev); | ||
336 | extern int gelic_net_stop(struct net_device *netdev); | ||
337 | extern int gelic_net_xmit(struct sk_buff *skb, struct net_device *netdev); | ||
338 | extern void gelic_net_set_multi(struct net_device *netdev); | ||
339 | extern void gelic_net_tx_timeout(struct net_device *netdev); | ||
340 | extern int gelic_net_change_mtu(struct net_device *netdev, int new_mtu); | ||
341 | extern int gelic_net_setup_netdev(struct net_device *netdev, | ||
342 | struct gelic_card *card); | ||
343 | |||
344 | /* shared ethtool ops */ | ||
345 | extern void gelic_net_get_drvinfo(struct net_device *netdev, | ||
346 | struct ethtool_drvinfo *info); | ||
347 | extern u32 gelic_net_get_rx_csum(struct net_device *netdev); | ||
348 | extern int gelic_net_set_rx_csum(struct net_device *netdev, u32 data); | ||
349 | extern void gelic_net_poll_controller(struct net_device *netdev); | ||
272 | 350 | ||
273 | #endif /* _GELIC_NET_H */ | 351 | #endif /* _GELIC_NET_H */ |