32 #include <linux/kernel.h>
33 #include <linux/module.h>
34 #include <linux/slab.h>
37 #include <linux/ethtool.h>
38 #include <linux/if_vlan.h>
42 #include <linux/tcp.h>
53 #define DRV_NAME "Gelic Network Driver"
54 #define DRV_VERSION "2.0"
61 static inline void gelic_card_enable_rxdmac(
struct gelic_card *
card);
62 static inline void gelic_card_disable_rxdmac(
struct gelic_card *
card);
63 static inline void gelic_card_disable_txdmac(
struct gelic_card *
card);
73 status = lv1_net_set_interrupt_mask(bus_id(card),
dev_id(card),
77 "%s failed %d\n", __func__, status);
92 static void gelic_card_get_ether_port_status(
struct gelic_card *
card,
98 lv1_net_control(bus_id(card),
dev_id(card),
112 static int gelic_card_set_link_mode(
struct gelic_card *card,
int mode)
117 status = lv1_net_control(bus_id(card),
dev_id(card),
121 pr_info(
"%s: failed setting negotiation mode %d\n", __func__,
135 pr_debug(
"%s: real do\n", __func__);
139 gelic_card_enable_rxdmac(card);
141 napi_enable(&card->
napi);
153 pr_debug(
"%s: real do\n", __func__);
154 napi_disable(&card->
napi);
163 gelic_card_disable_rxdmac(card);
164 gelic_card_reset_chain(card, &card->
rx_chain,
167 gelic_card_disable_txdmac(card);
213 static void gelic_card_free_chain(
struct gelic_card *card,
218 for (descr = descr_in; descr && descr->
bus_addr; descr = descr->
next) {
246 memset(descr, 0,
sizeof(*descr) * no);
249 for (i = 0; i <
no; i++, descr++) {
259 descr->
next = descr + 1;
260 descr->
prev = descr - 1;
263 (descr - 1)->
next = start_descr;
264 start_descr->
prev = (descr - 1);
268 for (i = 0; i <
no; i++, descr++) {
272 chain->
head = start_descr;
273 chain->
tail = start_descr;
281 for (i--, descr--; 0 <=
i; i--, descr--)
298 static void gelic_card_reset_chain(
struct gelic_card *card,
304 for (descr = start_descr; start_descr != descr->
next; descr++) {
309 chain->
head = start_descr;
310 chain->
tail = (descr - 1);
324 static int gelic_descr_prepare_rx(
struct gelic_card *card,
331 dev_info(ctodev(card),
"%s: ERROR status\n", __func__);
341 "%s:allocate skb failed !!\n", __func__);
350 offset = ((
unsigned long)descr->
skb->data) &
363 "%s:Could not iommu-map rx buffer\n", __func__);
377 static void gelic_card_release_rx_chain(
struct gelic_card *card)
390 gelic_descr_set_status(descr,
394 }
while (descr != card->
rx_chain.head);
405 static int gelic_card_fill_rx_chain(
struct gelic_card *card)
412 ret = gelic_descr_prepare_rx(card, descr);
417 }
while (descr != card->
rx_chain.head);
421 gelic_card_release_rx_chain(card);
436 ret = gelic_card_fill_rx_chain(card);
448 static void gelic_descr_release_tx(
struct gelic_card *card,
472 static void gelic_card_stop_queues(
struct gelic_card *card)
479 static void gelic_card_wake_queues(
struct gelic_card *card)
493 static void gelic_card_release_tx_chain(
struct gelic_card *card,
int stop)
502 tx_chain->
tail = tx_chain->
tail->next) {
503 status = gelic_descr_get_status(tx_chain->
tail);
504 netdev = tx_chain->
tail->skb->dev;
509 if (printk_ratelimit())
511 "%s: forcing end of tx descriptor " \
514 netdev->
stats.tx_dropped++;
518 if (tx_chain->
tail->skb) {
519 netdev->
stats.tx_packets++;
520 netdev->
stats.tx_bytes +=
521 tx_chain->
tail->skb->len;
532 gelic_descr_release_tx(card, tx_chain->
tail);
536 if (!stop && release)
537 gelic_card_wake_queues(card);
550 struct gelic_card *card = netdev_card(netdev);
558 status = lv1_net_remove_multicast_address(bus_id(card),
dev_id(card),
562 "lv1_net_remove_multicast_address failed %d\n",
565 status = lv1_net_add_multicast_address(bus_id(card),
dev_id(card),
569 "lv1_net_add_multicast_address failed, %d\n",
574 status = lv1_net_add_multicast_address(bus_id(card),
579 "lv1_net_add_multicast_address failed, %d\n",
592 status = lv1_net_add_multicast_address(bus_id(card),
597 "lv1_net_add_multicast_address failed, %d\n",
609 static inline void gelic_card_enable_rxdmac(
struct gelic_card *card)
614 if (gelic_descr_get_status(card->
rx_chain.head) !=
624 status = lv1_net_start_rx_dma(bus_id(card),
dev_id(card),
628 "lv1_net_start_rx_dma failed, status=%d\n", status);
638 static inline void gelic_card_disable_rxdmac(
struct gelic_card *card)
643 status = lv1_net_stop_rx_dma(bus_id(card),
dev_id(card));
646 "lv1_net_stop_rx_dma failed, %d\n", status);
656 static inline void gelic_card_disable_txdmac(
struct gelic_card *card)
661 status = lv1_net_stop_tx_dma(bus_id(card),
dev_id(card));
664 "lv1_net_stop_tx_dma failed, status=%d\n", status);
679 netif_stop_queue(netdev);
682 card = netdev_card(netdev);
696 gelic_card_get_next_tx_descr(
struct gelic_card *card)
702 gelic_descr_get_status(card->
tx_chain.head) ==
719 static void gelic_descr_set_tx_cmdstat(
struct gelic_descr *descr,
750 static inline struct sk_buff *gelic_put_vlan_tag(
struct sk_buff *skb,
754 static unsigned int c;
758 pr_debug(
"%s: hd=%d c=%ud\n", __func__, skb_headroom(skb), c);
784 static int gelic_descr_prepare_tx(
struct gelic_card *card,
794 type = netdev_port(skb->
dev)->type;
795 skb_tmp = gelic_put_vlan_tag(skb,
796 card->
vlan[type].tx);
806 "dma map 2 failed (%p, %i). Dropping packet\n",
816 gelic_descr_set_tx_cmdstat(descr, skb);
829 static int gelic_card_kick_txdma(
struct gelic_card *card,
839 status = lv1_net_start_tx_dma(bus_id(card),
dev_id(card),
843 dev_info(ctodev(card),
"lv1_net_start_txdma failed," \
844 "status=%d\n", status);
859 struct gelic_card *card = netdev_card(netdev);
866 gelic_card_release_tx_chain(card, 0);
868 descr = gelic_card_get_next_tx_descr(card);
873 gelic_card_stop_queues(card);
874 spin_unlock_irqrestore(&card->
tx_lock, flags);
878 result = gelic_descr_prepare_tx(card, descr, skb);
884 netdev->
stats.tx_dropped++;
886 spin_unlock_irqrestore(&card->
tx_lock, flags);
899 if (gelic_card_kick_txdma(card, descr)) {
904 netdev->
stats.tx_dropped++;
907 gelic_descr_release_tx(card, descr);
911 descr->
prev->next_descr_addr = 0;
912 dev_info(ctodev(card),
"%s: kick failure\n", __func__);
915 spin_unlock_irqrestore(&card->
tx_lock, flags);
928 static void gelic_net_pass_skb_up(
struct gelic_descr *descr,
947 dev_info(ctodev(card),
"buffer full %x %x %x\n",
966 skb_checksum_none_assert(skb);
968 skb_checksum_none_assert(skb);
971 netdev->
stats.rx_packets++;
987 static int gelic_card_decode_one_descr(
struct gelic_card *card)
993 int dmac_chain_ended;
995 status = gelic_descr_get_status(descr);
1001 dev_dbg(ctodev(card),
"dormant descr? %p\n", descr);
1011 if (card->
vlan[i].rx == vid) {
1016 if (GELIC_PORT_MAX <= i) {
1017 pr_info(
"%s: unknown packet vid=%x\n", __func__, vid);
1026 dev_info(ctodev(card),
"dropping RX descriptor with state %x\n",
1028 netdev->
stats.rx_dropped++;
1042 dev_info(ctodev(card),
"overlength frame\n");
1050 dev_dbg(ctodev(card),
"RX descriptor with state %x\n",
1056 gelic_net_pass_skb_up(descr, card, netdev);
1077 gelic_descr_prepare_rx(card, descr);
1092 if (dmac_chain_ended)
1093 gelic_card_enable_rxdmac(card);
1109 int packets_done = 0;
1111 while (packets_done < budget) {
1112 if (!gelic_card_decode_one_descr(card))
1118 if (packets_done < budget) {
1120 gelic_card_rx_irq_on(card);
1122 return packets_done;
1139 netdev->
mtu = new_mtu;
1148 unsigned long flags;
1160 gelic_card_rx_irq_off(card);
1161 napi_schedule(&card->
napi);
1167 gelic_card_release_tx_chain(card, 0);
1169 gelic_card_kick_txdma(card, card->
tx_chain.tail);
1170 spin_unlock_irqrestore(&card->
tx_lock, flags);
1175 gelic_card_get_ether_port_status(card, 1);
1177 #ifdef CONFIG_GELIC_WIRELESS
1186 #ifdef CONFIG_NET_POLL_CONTROLLER
1195 struct gelic_card *card = netdev_card(netdev);
1198 gelic_card_interrupt(netdev->
irq, netdev);
1214 struct gelic_card *card = netdev_card(netdev);
1216 dev_dbg(ctodev(card),
" -> %s %p\n", __func__, netdev);
1220 netif_start_queue(netdev);
1221 gelic_card_get_ether_port_status(card, 1);
1223 dev_dbg(ctodev(card),
" <- %s\n", __func__);
1234 static int gelic_ether_get_settings(
struct net_device *netdev,
1237 struct gelic_card *card = netdev_card(netdev);
1239 gelic_card_get_ether_port_status(card, 0);
1248 ethtool_cmd_speed_set(cmd,
SPEED_10);
1257 pr_info(
"%s: speed unknown\n", __func__);
1258 ethtool_cmd_speed_set(cmd,
SPEED_10);
1278 static int gelic_ether_set_settings(
struct net_device *netdev,
1281 struct gelic_card *card = netdev_card(netdev);
1288 switch (cmd->
speed) {
1304 pr_info(
"1000 half duplex is not supported.\n");
1309 ret = gelic_card_set_link_mode(card, mode);
1317 static void gelic_net_get_wol(
struct net_device *netdev,
1328 static int gelic_net_set_wol(
struct net_device *netdev,
1342 card = netdev_card(netdev);
1344 status = lv1_net_control(bus_id(card),
dev_id(card),
1350 pr_info(
"%s: enabling WOL failed %d\n", __func__,
1355 status = lv1_net_control(bus_id(card),
dev_id(card),
1363 pr_info(
"%s: enabling WOL filter failed %d\n",
1368 status = lv1_net_control(bus_id(card),
dev_id(card),
1374 pr_info(
"%s: disabling WOL failed %d\n", __func__,
1379 status = lv1_net_control(bus_id(card),
dev_id(card),
1387 pr_info(
"%s: removing WOL filter failed %d\n",
1396 static const struct ethtool_ops gelic_ether_ethtool_ops = {
1398 .get_settings = gelic_ether_get_settings,
1399 .set_settings = gelic_ether_set_settings,
1401 .get_wol = gelic_net_get_wol,
1402 .set_wol = gelic_net_set_wol,
1418 dev_info(ctodev(card),
"%s:Timed out. Restarting...\n", __func__);
1443 card = netdev_card(netdev);
1460 #ifdef CONFIG_NET_POLL_CONTROLLER
1504 status = lv1_net_control(bus_id(card),
dev_id(card),
1508 if (status || !is_valid_ether_addr((
u8 *)&v1)) {
1510 "%s:lv1_net_control GET_MAC_ADDR failed %d\n",
1527 dev_err(ctodev(card),
"%s:Couldn't register %s %d\n",
1528 __func__, netdev->
name, status);
1531 dev_info(ctodev(card),
"%s: MAC addr %pM\n",
1544 #define GELIC_ALIGN (32)
1572 *netdev = alloc_etherdev(
sizeof(
struct gelic_port));
1577 port = netdev_priv(*netdev);
1615 for (i = 0; i <
ARRAY_SIZE(vlan_id_ix); i++) {
1617 status = lv1_net_control(bus_id(card),
dev_id(card),
1621 if (status || !v1) {
1624 "get vlan id for tx(%d) failed(%d)\n",
1625 vlan_id_ix[i].
tx, status);
1626 card->
vlan[
i].tx = 0;
1627 card->
vlan[
i].rx = 0;
1633 status = lv1_net_control(bus_id(card),
dev_id(card),
1637 if (status || !v1) {
1640 "get vlan id for rx(%d) failed(%d)\n",
1641 vlan_id_ix[i].
rx, status);
1642 card->
vlan[
i].tx = 0;
1643 card->
vlan[
i].rx = 0;
1648 dev_dbg(ctodev(card),
"vlan_id[%d] tx=%02x rx=%02x\n",
1649 i, card->
vlan[i].tx, card->
vlan[i].rx);
1664 dev_info(ctodev(card),
"internal vlan %s\n",
1676 pr_debug(
"%s: called\n", __func__);
1683 dev_dbg(&dev->
core,
"%s:ps3_open_hv_device failed\n",
1691 dev_dbg(&dev->
core,
"%s:ps3_dma_region_create failed(%d)\n",
1693 BUG_ON(
"check region type");
1694 goto fail_dma_region;
1698 card = gelic_alloc_card_net(&netdev);
1700 dev_info(&dev->
core,
"%s:gelic_net_alloc_card failed\n",
1703 goto fail_alloc_card;
1705 ps3_system_bus_set_drvdata(dev, card);
1709 gelic_card_get_vlan_info(card);
1714 result = lv1_net_set_interrupt_status_indicator(bus_id(card),
1721 "%s:set_interrupt_status_indicator failed: %s\n",
1722 __func__, ps3_result(result));
1724 goto fail_status_indicator;
1732 "%s:gelic_net_open_device failed (%d)\n",
1735 goto fail_alloc_irq;
1741 dev_info(ctodev(card),
"%s:request_irq failed (%d)\n",
1743 goto fail_request_irq;
1747 card->
irq_mask = GELIC_CARD_RXINT | GELIC_CARD_TXINT |
1751 if (gelic_card_init_chain(card, &card->
tx_chain,
1754 if (gelic_card_init_chain(card, &card->
rx_chain,
1762 dev_dbg(ctodev(card),
"descr rx %p, tx %p, size %#lx, num %#x\n",
1766 if (gelic_card_alloc_rx_skbs(card))
1767 goto fail_alloc_skbs;
1775 gelic_ether_setup_netdev_ops(netdev, &card->
napi);
1780 goto fail_setup_netdev;
1783 #ifdef CONFIG_GELIC_WIRELESS
1785 dev_dbg(&dev->
core,
"%s: WL init failed\n", __func__);
1786 goto fail_setup_netdev;
1794 gelic_card_free_chain(card, card->
rx_chain.head);
1796 gelic_card_free_chain(card, card->
tx_chain.head);
1803 lv1_net_set_interrupt_status_indicator(bus_id(card),
1806 fail_status_indicator:
1807 ps3_system_bus_set_drvdata(dev,
NULL);
1808 kfree(netdev_card(netdev)->unalign);
1824 struct gelic_card *card = ps3_system_bus_get_drvdata(dev);
1826 pr_debug(
"%s: called\n", __func__);
1831 #ifdef CONFIG_GELIC_WIRELESS
1838 gelic_card_disable_rxdmac(card);
1839 gelic_card_disable_txdmac(card);
1842 gelic_card_release_tx_chain(card, 1);
1843 gelic_card_release_rx_chain(card);
1845 gelic_card_free_chain(card, card->
tx_top);
1846 gelic_card_free_chain(card, card->
rx_top);
1857 lv1_net_set_interrupt_status_indicator(bus_id(card),
dev_id(card),
1861 kfree(netdev_card(netdev0)->unalign);
1864 ps3_system_bus_set_drvdata(dev,
NULL);
1876 .probe = ps3_gelic_driver_probe,
1877 .remove = ps3_gelic_driver_remove,
1878 .shutdown = ps3_gelic_driver_remove,
1879 .core.name =
"ps3_gelic_driver",
1883 static int __init ps3_gelic_driver_init (
void)
1885 return firmware_has_feature(FW_FEATURE_PS3_LV1)
1890 static void __exit ps3_gelic_driver_exit (
void)