Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 1 | /* |
| 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> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 33 | #include <linux/slab.h> |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 34 | |
| 35 | #include <linux/etherdevice.h> |
| 36 | #include <linux/ethtool.h> |
| 37 | #include <linux/if_vlan.h> |
| 38 | |
| 39 | #include <linux/in.h> |
| 40 | #include <linux/ip.h> |
| 41 | #include <linux/tcp.h> |
| 42 | |
| 43 | #include <linux/dma-mapping.h> |
| 44 | #include <net/checksum.h> |
| 45 | #include <asm/firmware.h> |
| 46 | #include <asm/ps3.h> |
| 47 | #include <asm/lv1call.h> |
| 48 | |
| 49 | #include "ps3_gelic_net.h" |
Masakazu Mokuno | 09dde54 | 2008-02-07 19:58:57 +0900 | [diff] [blame] | 50 | #include "ps3_gelic_wireless.h" |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 51 | |
| 52 | #define DRV_NAME "Gelic Network Driver" |
Masakazu Mokuno | 09dde54 | 2008-02-07 19:58:57 +0900 | [diff] [blame] | 53 | #define DRV_VERSION "2.0" |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 54 | |
| 55 | MODULE_AUTHOR("SCE Inc."); |
| 56 | MODULE_DESCRIPTION("Gelic Network driver"); |
| 57 | MODULE_LICENSE("GPL"); |
| 58 | |
Masakazu Mokuno | 589866f | 2008-02-07 19:58:42 +0900 | [diff] [blame] | 59 | |
| 60 | static inline void gelic_card_enable_rxdmac(struct gelic_card *card); |
| 61 | static inline void gelic_card_disable_rxdmac(struct gelic_card *card); |
| 62 | static inline void gelic_card_disable_txdmac(struct gelic_card *card); |
| 63 | static inline void gelic_card_reset_chain(struct gelic_card *card, |
| 64 | struct gelic_descr_chain *chain, |
| 65 | struct gelic_descr *start_descr); |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 66 | |
| 67 | /* set irq_mask */ |
Masakazu Mokuno | 589866f | 2008-02-07 19:58:42 +0900 | [diff] [blame] | 68 | int gelic_card_set_irq_mask(struct gelic_card *card, u64 mask) |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 69 | { |
| 70 | int status; |
| 71 | |
| 72 | status = lv1_net_set_interrupt_mask(bus_id(card), dev_id(card), |
| 73 | mask, 0); |
| 74 | if (status) |
| 75 | dev_info(ctodev(card), |
Masakazu Mokuno | 589866f | 2008-02-07 19:58:42 +0900 | [diff] [blame] | 76 | "%s failed %d\n", __func__, status); |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 77 | return status; |
| 78 | } |
Masakazu Mokuno | 589866f | 2008-02-07 19:58:42 +0900 | [diff] [blame] | 79 | |
Masakazu Mokuno | 59e9732 | 2008-02-07 19:58:08 +0900 | [diff] [blame] | 80 | static inline void gelic_card_rx_irq_on(struct gelic_card *card) |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 81 | { |
Masakazu Mokuno | 589866f | 2008-02-07 19:58:42 +0900 | [diff] [blame] | 82 | card->irq_mask |= GELIC_CARD_RXINT; |
| 83 | gelic_card_set_irq_mask(card, card->irq_mask); |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 84 | } |
Masakazu Mokuno | 59e9732 | 2008-02-07 19:58:08 +0900 | [diff] [blame] | 85 | static inline void gelic_card_rx_irq_off(struct gelic_card *card) |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 86 | { |
Masakazu Mokuno | 589866f | 2008-02-07 19:58:42 +0900 | [diff] [blame] | 87 | card->irq_mask &= ~GELIC_CARD_RXINT; |
| 88 | gelic_card_set_irq_mask(card, card->irq_mask); |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 89 | } |
Masakazu Mokuno | 01fed4c | 2008-02-07 19:58:32 +0900 | [diff] [blame] | 90 | |
Masakazu Mokuno | 589866f | 2008-02-07 19:58:42 +0900 | [diff] [blame] | 91 | static void gelic_card_get_ether_port_status(struct gelic_card *card, |
| 92 | int inform) |
Masakazu Mokuno | 01fed4c | 2008-02-07 19:58:32 +0900 | [diff] [blame] | 93 | { |
| 94 | u64 v2; |
| 95 | struct net_device *ether_netdev; |
| 96 | |
| 97 | lv1_net_control(bus_id(card), dev_id(card), |
| 98 | GELIC_LV1_GET_ETH_PORT_STATUS, |
Geoff Levand | d4d7f1f | 2009-12-01 12:15:53 +0000 | [diff] [blame] | 99 | GELIC_LV1_VLAN_TX_ETHERNET_0, 0, 0, |
Masakazu Mokuno | 01fed4c | 2008-02-07 19:58:32 +0900 | [diff] [blame] | 100 | &card->ether_port_status, &v2); |
| 101 | |
| 102 | if (inform) { |
Geoff Levand | d4d7f1f | 2009-12-01 12:15:53 +0000 | [diff] [blame] | 103 | ether_netdev = card->netdev[GELIC_PORT_ETHERNET_0]; |
Masakazu Mokuno | 01fed4c | 2008-02-07 19:58:32 +0900 | [diff] [blame] | 104 | if (card->ether_port_status & GELIC_LV1_ETHER_LINK_UP) |
| 105 | netif_carrier_on(ether_netdev); |
| 106 | else |
| 107 | netif_carrier_off(ether_netdev); |
| 108 | } |
| 109 | } |
| 110 | |
Hideyuki Sasaki | 55873ed | 2009-12-01 12:15:58 +0000 | [diff] [blame] | 111 | static int gelic_card_set_link_mode(struct gelic_card *card, int mode) |
| 112 | { |
| 113 | int status; |
| 114 | u64 v1, v2; |
| 115 | |
| 116 | status = lv1_net_control(bus_id(card), dev_id(card), |
| 117 | GELIC_LV1_SET_NEGOTIATION_MODE, |
| 118 | GELIC_LV1_PHY_ETHERNET_0, mode, 0, &v1, &v2); |
| 119 | if (status) { |
| 120 | pr_info("%s: failed setting negotiation mode %d\n", __func__, |
| 121 | status); |
| 122 | return -EBUSY; |
| 123 | } |
| 124 | |
| 125 | card->link_mode = mode; |
| 126 | return 0; |
| 127 | } |
| 128 | |
Masakazu Mokuno | 589866f | 2008-02-07 19:58:42 +0900 | [diff] [blame] | 129 | void gelic_card_up(struct gelic_card *card) |
| 130 | { |
| 131 | pr_debug("%s: called\n", __func__); |
Daniel Walker | 2914f3e | 2008-05-22 00:00:03 -0700 | [diff] [blame] | 132 | mutex_lock(&card->updown_lock); |
Masakazu Mokuno | 589866f | 2008-02-07 19:58:42 +0900 | [diff] [blame] | 133 | if (atomic_inc_return(&card->users) == 1) { |
| 134 | pr_debug("%s: real do\n", __func__); |
| 135 | /* enable irq */ |
| 136 | gelic_card_set_irq_mask(card, card->irq_mask); |
| 137 | /* start rx */ |
| 138 | gelic_card_enable_rxdmac(card); |
| 139 | |
| 140 | napi_enable(&card->napi); |
| 141 | } |
Daniel Walker | 2914f3e | 2008-05-22 00:00:03 -0700 | [diff] [blame] | 142 | mutex_unlock(&card->updown_lock); |
Masakazu Mokuno | 589866f | 2008-02-07 19:58:42 +0900 | [diff] [blame] | 143 | pr_debug("%s: done\n", __func__); |
| 144 | } |
| 145 | |
| 146 | void gelic_card_down(struct gelic_card *card) |
| 147 | { |
| 148 | u64 mask; |
| 149 | pr_debug("%s: called\n", __func__); |
Daniel Walker | 2914f3e | 2008-05-22 00:00:03 -0700 | [diff] [blame] | 150 | mutex_lock(&card->updown_lock); |
Masakazu Mokuno | 589866f | 2008-02-07 19:58:42 +0900 | [diff] [blame] | 151 | if (atomic_dec_if_positive(&card->users) == 0) { |
| 152 | pr_debug("%s: real do\n", __func__); |
| 153 | napi_disable(&card->napi); |
| 154 | /* |
| 155 | * Disable irq. Wireless interrupts will |
| 156 | * be disabled later if any |
| 157 | */ |
| 158 | mask = card->irq_mask & (GELIC_CARD_WLAN_EVENT_RECEIVED | |
| 159 | GELIC_CARD_WLAN_COMMAND_COMPLETED); |
| 160 | gelic_card_set_irq_mask(card, mask); |
| 161 | /* stop rx */ |
| 162 | gelic_card_disable_rxdmac(card); |
| 163 | gelic_card_reset_chain(card, &card->rx_chain, |
| 164 | card->descr + GELIC_NET_TX_DESCRIPTORS); |
| 165 | /* stop tx */ |
| 166 | gelic_card_disable_txdmac(card); |
| 167 | } |
Daniel Walker | 2914f3e | 2008-05-22 00:00:03 -0700 | [diff] [blame] | 168 | mutex_unlock(&card->updown_lock); |
Masakazu Mokuno | 589866f | 2008-02-07 19:58:42 +0900 | [diff] [blame] | 169 | pr_debug("%s: done\n", __func__); |
| 170 | } |
Masakazu Mokuno | 01fed4c | 2008-02-07 19:58:32 +0900 | [diff] [blame] | 171 | |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 172 | /** |
Masakazu Mokuno | 59e9732 | 2008-02-07 19:58:08 +0900 | [diff] [blame] | 173 | * gelic_descr_get_status -- returns the status of a descriptor |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 174 | * @descr: descriptor to look at |
| 175 | * |
| 176 | * returns the status as in the dmac_cmd_status field of the descriptor |
| 177 | */ |
Masakazu Mokuno | 59e9732 | 2008-02-07 19:58:08 +0900 | [diff] [blame] | 178 | static enum gelic_descr_dma_status |
| 179 | gelic_descr_get_status(struct gelic_descr *descr) |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 180 | { |
Masakazu Mokuno | 59e9732 | 2008-02-07 19:58:08 +0900 | [diff] [blame] | 181 | return be32_to_cpu(descr->dmac_cmd_status) & GELIC_DESCR_DMA_STAT_MASK; |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 182 | } |
| 183 | |
| 184 | /** |
Masakazu Mokuno | 59e9732 | 2008-02-07 19:58:08 +0900 | [diff] [blame] | 185 | * gelic_descr_set_status -- sets the status of a descriptor |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 186 | * @descr: descriptor to change |
| 187 | * @status: status to set in the descriptor |
| 188 | * |
| 189 | * changes the status to the specified value. Doesn't change other bits |
| 190 | * in the status |
| 191 | */ |
Masakazu Mokuno | 59e9732 | 2008-02-07 19:58:08 +0900 | [diff] [blame] | 192 | static void gelic_descr_set_status(struct gelic_descr *descr, |
| 193 | enum gelic_descr_dma_status status) |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 194 | { |
Masakazu Mokuno | 59e9732 | 2008-02-07 19:58:08 +0900 | [diff] [blame] | 195 | descr->dmac_cmd_status = cpu_to_be32(status | |
Masakazu Mokuno | 589866f | 2008-02-07 19:58:42 +0900 | [diff] [blame] | 196 | (be32_to_cpu(descr->dmac_cmd_status) & |
| 197 | ~GELIC_DESCR_DMA_STAT_MASK)); |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 198 | /* |
| 199 | * dma_cmd_status field is used to indicate whether the descriptor |
| 200 | * is valid or not. |
| 201 | * Usually caller of this function wants to inform that to the |
| 202 | * hardware, so we assure here the hardware sees the change. |
| 203 | */ |
| 204 | wmb(); |
| 205 | } |
| 206 | |
| 207 | /** |
Masakazu Mokuno | 59e9732 | 2008-02-07 19:58:08 +0900 | [diff] [blame] | 208 | * gelic_card_free_chain - free descriptor chain |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 209 | * @card: card structure |
| 210 | * @descr_in: address of desc |
| 211 | */ |
Masakazu Mokuno | 59e9732 | 2008-02-07 19:58:08 +0900 | [diff] [blame] | 212 | static void gelic_card_free_chain(struct gelic_card *card, |
| 213 | struct gelic_descr *descr_in) |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 214 | { |
Masakazu Mokuno | 59e9732 | 2008-02-07 19:58:08 +0900 | [diff] [blame] | 215 | struct gelic_descr *descr; |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 216 | |
| 217 | for (descr = descr_in; descr && descr->bus_addr; descr = descr->next) { |
| 218 | dma_unmap_single(ctodev(card), descr->bus_addr, |
Masakazu Mokuno | 59e9732 | 2008-02-07 19:58:08 +0900 | [diff] [blame] | 219 | GELIC_DESCR_SIZE, DMA_BIDIRECTIONAL); |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 220 | descr->bus_addr = 0; |
| 221 | } |
| 222 | } |
| 223 | |
| 224 | /** |
Masakazu Mokuno | 59e9732 | 2008-02-07 19:58:08 +0900 | [diff] [blame] | 225 | * gelic_card_init_chain - links descriptor chain |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 226 | * @card: card structure |
| 227 | * @chain: address of chain |
| 228 | * @start_descr: address of descriptor array |
| 229 | * @no: number of descriptors |
| 230 | * |
| 231 | * we manage a circular list that mirrors the hardware structure, |
| 232 | * except that the hardware uses bus addresses. |
| 233 | * |
| 234 | * returns 0 on success, <0 on failure |
| 235 | */ |
Geert Uytterhoeven | 48dce82 | 2009-06-10 04:38:58 +0000 | [diff] [blame] | 236 | static int __devinit gelic_card_init_chain(struct gelic_card *card, |
| 237 | struct gelic_descr_chain *chain, |
| 238 | struct gelic_descr *start_descr, |
| 239 | int no) |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 240 | { |
| 241 | int i; |
Masakazu Mokuno | 59e9732 | 2008-02-07 19:58:08 +0900 | [diff] [blame] | 242 | struct gelic_descr *descr; |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 243 | |
| 244 | descr = start_descr; |
| 245 | memset(descr, 0, sizeof(*descr) * no); |
| 246 | |
| 247 | /* set up the hardware pointers in each descriptor */ |
| 248 | for (i = 0; i < no; i++, descr++) { |
Masakazu Mokuno | 59e9732 | 2008-02-07 19:58:08 +0900 | [diff] [blame] | 249 | gelic_descr_set_status(descr, GELIC_DESCR_DMA_NOT_IN_USE); |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 250 | descr->bus_addr = |
| 251 | dma_map_single(ctodev(card), descr, |
Masakazu Mokuno | 59e9732 | 2008-02-07 19:58:08 +0900 | [diff] [blame] | 252 | GELIC_DESCR_SIZE, |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 253 | DMA_BIDIRECTIONAL); |
| 254 | |
| 255 | if (!descr->bus_addr) |
| 256 | goto iommu_error; |
| 257 | |
| 258 | descr->next = descr + 1; |
| 259 | descr->prev = descr - 1; |
| 260 | } |
| 261 | /* make them as ring */ |
| 262 | (descr - 1)->next = start_descr; |
| 263 | start_descr->prev = (descr - 1); |
| 264 | |
| 265 | /* chain bus addr of hw descriptor */ |
| 266 | descr = start_descr; |
| 267 | for (i = 0; i < no; i++, descr++) { |
Masakazu Mokuno | 100e1d8 | 2008-02-07 19:57:54 +0900 | [diff] [blame] | 268 | descr->next_descr_addr = cpu_to_be32(descr->next->bus_addr); |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 269 | } |
| 270 | |
| 271 | chain->head = start_descr; |
| 272 | chain->tail = start_descr; |
| 273 | |
| 274 | /* do not chain last hw descriptor */ |
| 275 | (descr - 1)->next_descr_addr = 0; |
| 276 | |
| 277 | return 0; |
| 278 | |
| 279 | iommu_error: |
| 280 | for (i--, descr--; 0 <= i; i--, descr--) |
| 281 | if (descr->bus_addr) |
| 282 | dma_unmap_single(ctodev(card), descr->bus_addr, |
Masakazu Mokuno | 59e9732 | 2008-02-07 19:58:08 +0900 | [diff] [blame] | 283 | GELIC_DESCR_SIZE, |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 284 | DMA_BIDIRECTIONAL); |
| 285 | return -ENOMEM; |
| 286 | } |
| 287 | |
| 288 | /** |
Masakazu Mokuno | 589866f | 2008-02-07 19:58:42 +0900 | [diff] [blame] | 289 | * gelic_card_reset_chain - reset status of a descriptor chain |
| 290 | * @card: card structure |
| 291 | * @chain: address of chain |
| 292 | * @start_descr: address of descriptor array |
| 293 | * |
| 294 | * Reset the status of dma descriptors to ready state |
| 295 | * and re-initialize the hardware chain for later use |
| 296 | */ |
| 297 | static void gelic_card_reset_chain(struct gelic_card *card, |
| 298 | struct gelic_descr_chain *chain, |
| 299 | struct gelic_descr *start_descr) |
| 300 | { |
| 301 | struct gelic_descr *descr; |
| 302 | |
| 303 | for (descr = start_descr; start_descr != descr->next; descr++) { |
| 304 | gelic_descr_set_status(descr, GELIC_DESCR_DMA_CARDOWNED); |
| 305 | descr->next_descr_addr = cpu_to_be32(descr->next->bus_addr); |
| 306 | } |
| 307 | |
| 308 | chain->head = start_descr; |
| 309 | chain->tail = (descr - 1); |
| 310 | |
| 311 | (descr - 1)->next_descr_addr = 0; |
| 312 | } |
| 313 | /** |
Masakazu Mokuno | 59e9732 | 2008-02-07 19:58:08 +0900 | [diff] [blame] | 314 | * gelic_descr_prepare_rx - reinitializes a rx descriptor |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 315 | * @card: card structure |
| 316 | * @descr: descriptor to re-init |
| 317 | * |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 318 | * return 0 on success, <0 on failure |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 319 | * |
| 320 | * allocates a new rx skb, iommu-maps it and attaches it to the descriptor. |
| 321 | * Activate the descriptor state-wise |
| 322 | */ |
Masakazu Mokuno | 59e9732 | 2008-02-07 19:58:08 +0900 | [diff] [blame] | 323 | static int gelic_descr_prepare_rx(struct gelic_card *card, |
Masakazu Mokuno | 589866f | 2008-02-07 19:58:42 +0900 | [diff] [blame] | 324 | struct gelic_descr *descr) |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 325 | { |
| 326 | int offset; |
| 327 | unsigned int bufsize; |
| 328 | |
Masakazu Mokuno | 59e9732 | 2008-02-07 19:58:08 +0900 | [diff] [blame] | 329 | if (gelic_descr_get_status(descr) != GELIC_DESCR_DMA_NOT_IN_USE) |
Frans Pop | 583d077 | 2010-03-24 07:57:31 +0000 | [diff] [blame] | 330 | dev_info(ctodev(card), "%s: ERROR status\n", __func__); |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 331 | /* we need to round up the buffer size to a multiple of 128 */ |
| 332 | bufsize = ALIGN(GELIC_NET_MAX_MTU, GELIC_NET_RXBUF_ALIGN); |
| 333 | |
| 334 | /* and we need to have it 128 byte aligned, therefore we allocate a |
| 335 | * bit more */ |
Masakazu Mokuno | 589866f | 2008-02-07 19:58:42 +0900 | [diff] [blame] | 336 | descr->skb = dev_alloc_skb(bufsize + GELIC_NET_RXBUF_ALIGN - 1); |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 337 | if (!descr->skb) { |
| 338 | descr->buf_addr = 0; /* tell DMAC don't touch memory */ |
| 339 | dev_info(ctodev(card), |
| 340 | "%s:allocate skb failed !!\n", __func__); |
| 341 | return -ENOMEM; |
| 342 | } |
Masakazu Mokuno | 100e1d8 | 2008-02-07 19:57:54 +0900 | [diff] [blame] | 343 | descr->buf_size = cpu_to_be32(bufsize); |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 344 | descr->dmac_cmd_status = 0; |
| 345 | descr->result_size = 0; |
| 346 | descr->valid_size = 0; |
| 347 | descr->data_error = 0; |
| 348 | |
| 349 | offset = ((unsigned long)descr->skb->data) & |
| 350 | (GELIC_NET_RXBUF_ALIGN - 1); |
| 351 | if (offset) |
| 352 | skb_reserve(descr->skb, GELIC_NET_RXBUF_ALIGN - offset); |
| 353 | /* io-mmu-map the skb */ |
Masakazu Mokuno | 100e1d8 | 2008-02-07 19:57:54 +0900 | [diff] [blame] | 354 | descr->buf_addr = cpu_to_be32(dma_map_single(ctodev(card), |
| 355 | descr->skb->data, |
| 356 | GELIC_NET_MAX_MTU, |
| 357 | DMA_FROM_DEVICE)); |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 358 | if (!descr->buf_addr) { |
| 359 | dev_kfree_skb_any(descr->skb); |
| 360 | descr->skb = NULL; |
| 361 | dev_info(ctodev(card), |
| 362 | "%s:Could not iommu-map rx buffer\n", __func__); |
Masakazu Mokuno | 59e9732 | 2008-02-07 19:58:08 +0900 | [diff] [blame] | 363 | gelic_descr_set_status(descr, GELIC_DESCR_DMA_NOT_IN_USE); |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 364 | return -ENOMEM; |
| 365 | } else { |
Masakazu Mokuno | 59e9732 | 2008-02-07 19:58:08 +0900 | [diff] [blame] | 366 | gelic_descr_set_status(descr, GELIC_DESCR_DMA_CARDOWNED); |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 367 | return 0; |
| 368 | } |
| 369 | } |
| 370 | |
| 371 | /** |
Masakazu Mokuno | 59e9732 | 2008-02-07 19:58:08 +0900 | [diff] [blame] | 372 | * gelic_card_release_rx_chain - free all skb of rx descr |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 373 | * @card: card structure |
| 374 | * |
| 375 | */ |
Masakazu Mokuno | 59e9732 | 2008-02-07 19:58:08 +0900 | [diff] [blame] | 376 | static void gelic_card_release_rx_chain(struct gelic_card *card) |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 377 | { |
Masakazu Mokuno | 59e9732 | 2008-02-07 19:58:08 +0900 | [diff] [blame] | 378 | struct gelic_descr *descr = card->rx_chain.head; |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 379 | |
| 380 | do { |
| 381 | if (descr->skb) { |
| 382 | dma_unmap_single(ctodev(card), |
Masakazu Mokuno | 100e1d8 | 2008-02-07 19:57:54 +0900 | [diff] [blame] | 383 | be32_to_cpu(descr->buf_addr), |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 384 | descr->skb->len, |
| 385 | DMA_FROM_DEVICE); |
| 386 | descr->buf_addr = 0; |
| 387 | dev_kfree_skb_any(descr->skb); |
| 388 | descr->skb = NULL; |
Masakazu Mokuno | 59e9732 | 2008-02-07 19:58:08 +0900 | [diff] [blame] | 389 | gelic_descr_set_status(descr, |
| 390 | GELIC_DESCR_DMA_NOT_IN_USE); |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 391 | } |
| 392 | descr = descr->next; |
| 393 | } while (descr != card->rx_chain.head); |
| 394 | } |
| 395 | |
| 396 | /** |
Masakazu Mokuno | 59e9732 | 2008-02-07 19:58:08 +0900 | [diff] [blame] | 397 | * gelic_card_fill_rx_chain - fills descriptors/skbs in the rx chains |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 398 | * @card: card structure |
| 399 | * |
| 400 | * fills all descriptors in the rx chain: allocates skbs |
| 401 | * and iommu-maps them. |
Masakazu Mokuno | 59e9732 | 2008-02-07 19:58:08 +0900 | [diff] [blame] | 402 | * returns 0 on success, < 0 on failure |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 403 | */ |
Masakazu Mokuno | 59e9732 | 2008-02-07 19:58:08 +0900 | [diff] [blame] | 404 | static int gelic_card_fill_rx_chain(struct gelic_card *card) |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 405 | { |
Masakazu Mokuno | 59e9732 | 2008-02-07 19:58:08 +0900 | [diff] [blame] | 406 | struct gelic_descr *descr = card->rx_chain.head; |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 407 | int ret; |
| 408 | |
| 409 | do { |
| 410 | if (!descr->skb) { |
Masakazu Mokuno | 59e9732 | 2008-02-07 19:58:08 +0900 | [diff] [blame] | 411 | ret = gelic_descr_prepare_rx(card, descr); |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 412 | if (ret) |
| 413 | goto rewind; |
| 414 | } |
| 415 | descr = descr->next; |
| 416 | } while (descr != card->rx_chain.head); |
| 417 | |
| 418 | return 0; |
| 419 | rewind: |
Masakazu Mokuno | 59e9732 | 2008-02-07 19:58:08 +0900 | [diff] [blame] | 420 | gelic_card_release_rx_chain(card); |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 421 | return ret; |
| 422 | } |
| 423 | |
| 424 | /** |
Masakazu Mokuno | 59e9732 | 2008-02-07 19:58:08 +0900 | [diff] [blame] | 425 | * gelic_card_alloc_rx_skbs - allocates rx skbs in rx descriptor chains |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 426 | * @card: card structure |
| 427 | * |
Masakazu Mokuno | 59e9732 | 2008-02-07 19:58:08 +0900 | [diff] [blame] | 428 | * returns 0 on success, < 0 on failure |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 429 | */ |
Geert Uytterhoeven | 48dce82 | 2009-06-10 04:38:58 +0000 | [diff] [blame] | 430 | static int __devinit gelic_card_alloc_rx_skbs(struct gelic_card *card) |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 431 | { |
Masakazu Mokuno | 59e9732 | 2008-02-07 19:58:08 +0900 | [diff] [blame] | 432 | struct gelic_descr_chain *chain; |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 433 | int ret; |
| 434 | chain = &card->rx_chain; |
Masakazu Mokuno | 59e9732 | 2008-02-07 19:58:08 +0900 | [diff] [blame] | 435 | ret = gelic_card_fill_rx_chain(card); |
Masakazu Mokuno | 589866f | 2008-02-07 19:58:42 +0900 | [diff] [blame] | 436 | chain->tail = card->rx_top->prev; /* point to the last */ |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 437 | return ret; |
| 438 | } |
| 439 | |
| 440 | /** |
Masakazu Mokuno | 59e9732 | 2008-02-07 19:58:08 +0900 | [diff] [blame] | 441 | * gelic_descr_release_tx - processes a used tx descriptor |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 442 | * @card: card structure |
| 443 | * @descr: descriptor to release |
| 444 | * |
| 445 | * releases a used tx descriptor (unmapping, freeing of skb) |
| 446 | */ |
Masakazu Mokuno | 59e9732 | 2008-02-07 19:58:08 +0900 | [diff] [blame] | 447 | static void gelic_descr_release_tx(struct gelic_card *card, |
Masakazu Mokuno | 589866f | 2008-02-07 19:58:42 +0900 | [diff] [blame] | 448 | struct gelic_descr *descr) |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 449 | { |
Masakazu Mokuno | 173261e | 2007-08-31 22:22:32 +0900 | [diff] [blame] | 450 | struct sk_buff *skb = descr->skb; |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 451 | |
Masakazu Mokuno | 589866f | 2008-02-07 19:58:42 +0900 | [diff] [blame] | 452 | BUG_ON(!(be32_to_cpu(descr->data_status) & GELIC_DESCR_TX_TAIL)); |
| 453 | |
| 454 | dma_unmap_single(ctodev(card), be32_to_cpu(descr->buf_addr), skb->len, |
| 455 | DMA_TO_DEVICE); |
Masakazu Mokuno | 173261e | 2007-08-31 22:22:32 +0900 | [diff] [blame] | 456 | dev_kfree_skb_any(skb); |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 457 | |
| 458 | descr->buf_addr = 0; |
| 459 | descr->buf_size = 0; |
| 460 | descr->next_descr_addr = 0; |
| 461 | descr->result_size = 0; |
| 462 | descr->valid_size = 0; |
| 463 | descr->data_status = 0; |
| 464 | descr->data_error = 0; |
| 465 | descr->skb = NULL; |
| 466 | |
| 467 | /* set descr status */ |
Masakazu Mokuno | 59e9732 | 2008-02-07 19:58:08 +0900 | [diff] [blame] | 468 | gelic_descr_set_status(descr, GELIC_DESCR_DMA_NOT_IN_USE); |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 469 | } |
| 470 | |
Masakazu Mokuno | 589866f | 2008-02-07 19:58:42 +0900 | [diff] [blame] | 471 | static void gelic_card_stop_queues(struct gelic_card *card) |
| 472 | { |
Geoff Levand | d4d7f1f | 2009-12-01 12:15:53 +0000 | [diff] [blame] | 473 | netif_stop_queue(card->netdev[GELIC_PORT_ETHERNET_0]); |
Masakazu Mokuno | 589866f | 2008-02-07 19:58:42 +0900 | [diff] [blame] | 474 | |
| 475 | if (card->netdev[GELIC_PORT_WIRELESS]) |
| 476 | netif_stop_queue(card->netdev[GELIC_PORT_WIRELESS]); |
| 477 | } |
| 478 | static void gelic_card_wake_queues(struct gelic_card *card) |
| 479 | { |
Geoff Levand | d4d7f1f | 2009-12-01 12:15:53 +0000 | [diff] [blame] | 480 | netif_wake_queue(card->netdev[GELIC_PORT_ETHERNET_0]); |
Masakazu Mokuno | 589866f | 2008-02-07 19:58:42 +0900 | [diff] [blame] | 481 | |
| 482 | if (card->netdev[GELIC_PORT_WIRELESS]) |
| 483 | netif_wake_queue(card->netdev[GELIC_PORT_WIRELESS]); |
| 484 | } |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 485 | /** |
Masakazu Mokuno | 59e9732 | 2008-02-07 19:58:08 +0900 | [diff] [blame] | 486 | * gelic_card_release_tx_chain - processes sent tx descriptors |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 487 | * @card: adapter structure |
| 488 | * @stop: net_stop sequence |
| 489 | * |
| 490 | * releases the tx descriptors that gelic has finished with |
| 491 | */ |
Masakazu Mokuno | 59e9732 | 2008-02-07 19:58:08 +0900 | [diff] [blame] | 492 | static void gelic_card_release_tx_chain(struct gelic_card *card, int stop) |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 493 | { |
Masakazu Mokuno | 59e9732 | 2008-02-07 19:58:08 +0900 | [diff] [blame] | 494 | struct gelic_descr_chain *tx_chain; |
| 495 | enum gelic_descr_dma_status status; |
Masakazu Mokuno | 589866f | 2008-02-07 19:58:42 +0900 | [diff] [blame] | 496 | struct net_device *netdev; |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 497 | int release = 0; |
| 498 | |
| 499 | for (tx_chain = &card->tx_chain; |
| 500 | tx_chain->head != tx_chain->tail && tx_chain->tail; |
| 501 | tx_chain->tail = tx_chain->tail->next) { |
Masakazu Mokuno | 59e9732 | 2008-02-07 19:58:08 +0900 | [diff] [blame] | 502 | status = gelic_descr_get_status(tx_chain->tail); |
Masakazu Mokuno | 589866f | 2008-02-07 19:58:42 +0900 | [diff] [blame] | 503 | netdev = tx_chain->tail->skb->dev; |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 504 | switch (status) { |
Masakazu Mokuno | 59e9732 | 2008-02-07 19:58:08 +0900 | [diff] [blame] | 505 | case GELIC_DESCR_DMA_RESPONSE_ERROR: |
| 506 | case GELIC_DESCR_DMA_PROTECTION_ERROR: |
| 507 | case GELIC_DESCR_DMA_FORCE_END: |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 508 | if (printk_ratelimit()) |
| 509 | dev_info(ctodev(card), |
| 510 | "%s: forcing end of tx descriptor " \ |
| 511 | "with status %x\n", |
| 512 | __func__, status); |
Masakazu Mokuno | 589866f | 2008-02-07 19:58:42 +0900 | [diff] [blame] | 513 | netdev->stats.tx_dropped++; |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 514 | break; |
| 515 | |
Masakazu Mokuno | 59e9732 | 2008-02-07 19:58:08 +0900 | [diff] [blame] | 516 | case GELIC_DESCR_DMA_COMPLETE: |
Masakazu Mokuno | 48544cc | 2007-07-20 17:24:56 +0900 | [diff] [blame] | 517 | if (tx_chain->tail->skb) { |
Masakazu Mokuno | 589866f | 2008-02-07 19:58:42 +0900 | [diff] [blame] | 518 | netdev->stats.tx_packets++; |
| 519 | netdev->stats.tx_bytes += |
Masakazu Mokuno | 48544cc | 2007-07-20 17:24:56 +0900 | [diff] [blame] | 520 | tx_chain->tail->skb->len; |
| 521 | } |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 522 | break; |
| 523 | |
Masakazu Mokuno | 59e9732 | 2008-02-07 19:58:08 +0900 | [diff] [blame] | 524 | case GELIC_DESCR_DMA_CARDOWNED: |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 525 | /* pending tx request */ |
| 526 | default: |
Masakazu Mokuno | 59e9732 | 2008-02-07 19:58:08 +0900 | [diff] [blame] | 527 | /* any other value (== GELIC_DESCR_DMA_NOT_IN_USE) */ |
Masakazu Mokuno | 48544cc | 2007-07-20 17:24:56 +0900 | [diff] [blame] | 528 | if (!stop) |
| 529 | goto out; |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 530 | } |
Masakazu Mokuno | 59e9732 | 2008-02-07 19:58:08 +0900 | [diff] [blame] | 531 | gelic_descr_release_tx(card, tx_chain->tail); |
Masakazu Mokuno | 48544cc | 2007-07-20 17:24:56 +0900 | [diff] [blame] | 532 | release ++; |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 533 | } |
| 534 | out: |
Masakazu Mokuno | 173261e | 2007-08-31 22:22:32 +0900 | [diff] [blame] | 535 | if (!stop && release) |
Masakazu Mokuno | 589866f | 2008-02-07 19:58:42 +0900 | [diff] [blame] | 536 | gelic_card_wake_queues(card); |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 537 | } |
| 538 | |
| 539 | /** |
| 540 | * gelic_net_set_multi - sets multicast addresses and promisc flags |
| 541 | * @netdev: interface device structure |
| 542 | * |
| 543 | * gelic_net_set_multi configures multicast addresses as needed for the |
| 544 | * netdev interface. It also sets up multicast, allmulti and promisc |
| 545 | * flags appropriately |
| 546 | */ |
Masakazu Mokuno | 589866f | 2008-02-07 19:58:42 +0900 | [diff] [blame] | 547 | void gelic_net_set_multi(struct net_device *netdev) |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 548 | { |
Masakazu Mokuno | 589866f | 2008-02-07 19:58:42 +0900 | [diff] [blame] | 549 | struct gelic_card *card = netdev_card(netdev); |
Jiri Pirko | 22bedad | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 550 | struct netdev_hw_addr *ha; |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 551 | unsigned int i; |
| 552 | uint8_t *p; |
| 553 | u64 addr; |
| 554 | int status; |
| 555 | |
| 556 | /* clear all multicast address */ |
| 557 | status = lv1_net_remove_multicast_address(bus_id(card), dev_id(card), |
| 558 | 0, 1); |
| 559 | if (status) |
| 560 | dev_err(ctodev(card), |
| 561 | "lv1_net_remove_multicast_address failed %d\n", |
| 562 | status); |
| 563 | /* set broadcast address */ |
| 564 | status = lv1_net_add_multicast_address(bus_id(card), dev_id(card), |
| 565 | GELIC_NET_BROADCAST_ADDR, 0); |
| 566 | if (status) |
| 567 | dev_err(ctodev(card), |
| 568 | "lv1_net_add_multicast_address failed, %d\n", |
| 569 | status); |
| 570 | |
Masakazu Mokuno | 589866f | 2008-02-07 19:58:42 +0900 | [diff] [blame] | 571 | if ((netdev->flags & IFF_ALLMULTI) || |
Jiri Pirko | 4cd24ea | 2010-02-08 04:30:35 +0000 | [diff] [blame] | 572 | (netdev_mc_count(netdev) > GELIC_NET_MC_COUNT_MAX)) { |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 573 | status = lv1_net_add_multicast_address(bus_id(card), |
| 574 | dev_id(card), |
| 575 | 0, 1); |
| 576 | if (status) |
| 577 | dev_err(ctodev(card), |
| 578 | "lv1_net_add_multicast_address failed, %d\n", |
| 579 | status); |
| 580 | return; |
| 581 | } |
| 582 | |
Masakazu Mokuno | 589866f | 2008-02-07 19:58:42 +0900 | [diff] [blame] | 583 | /* set multicast addresses */ |
Jiri Pirko | 22bedad | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 584 | netdev_for_each_mc_addr(ha, netdev) { |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 585 | addr = 0; |
Jiri Pirko | 22bedad | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 586 | p = ha->addr; |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 587 | for (i = 0; i < ETH_ALEN; i++) { |
| 588 | addr <<= 8; |
| 589 | addr |= *p++; |
| 590 | } |
| 591 | status = lv1_net_add_multicast_address(bus_id(card), |
| 592 | dev_id(card), |
| 593 | addr, 0); |
| 594 | if (status) |
| 595 | dev_err(ctodev(card), |
| 596 | "lv1_net_add_multicast_address failed, %d\n", |
| 597 | status); |
| 598 | } |
| 599 | } |
| 600 | |
| 601 | /** |
Masakazu Mokuno | 59e9732 | 2008-02-07 19:58:08 +0900 | [diff] [blame] | 602 | * gelic_card_enable_rxdmac - enables the receive DMA controller |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 603 | * @card: card structure |
| 604 | * |
Masakazu Mokuno | 59e9732 | 2008-02-07 19:58:08 +0900 | [diff] [blame] | 605 | * gelic_card_enable_rxdmac enables the DMA controller by setting RX_DMA_EN |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 606 | * in the GDADMACCNTR register |
| 607 | */ |
Masakazu Mokuno | 59e9732 | 2008-02-07 19:58:08 +0900 | [diff] [blame] | 608 | static inline void gelic_card_enable_rxdmac(struct gelic_card *card) |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 609 | { |
| 610 | int status; |
| 611 | |
Masakazu Mokuno | 589866f | 2008-02-07 19:58:42 +0900 | [diff] [blame] | 612 | #ifdef DEBUG |
| 613 | if (gelic_descr_get_status(card->rx_chain.head) != |
| 614 | GELIC_DESCR_DMA_CARDOWNED) { |
| 615 | printk(KERN_ERR "%s: status=%x\n", __func__, |
| 616 | be32_to_cpu(card->rx_chain.head->dmac_cmd_status)); |
| 617 | printk(KERN_ERR "%s: nextphy=%x\n", __func__, |
| 618 | be32_to_cpu(card->rx_chain.head->next_descr_addr)); |
| 619 | printk(KERN_ERR "%s: head=%p\n", __func__, |
| 620 | card->rx_chain.head); |
| 621 | } |
| 622 | #endif |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 623 | status = lv1_net_start_rx_dma(bus_id(card), dev_id(card), |
Masakazu Mokuno | 589866f | 2008-02-07 19:58:42 +0900 | [diff] [blame] | 624 | card->rx_chain.head->bus_addr, 0); |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 625 | if (status) |
| 626 | dev_info(ctodev(card), |
| 627 | "lv1_net_start_rx_dma failed, status=%d\n", status); |
| 628 | } |
| 629 | |
| 630 | /** |
Masakazu Mokuno | 59e9732 | 2008-02-07 19:58:08 +0900 | [diff] [blame] | 631 | * gelic_card_disable_rxdmac - disables the receive DMA controller |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 632 | * @card: card structure |
| 633 | * |
Masakazu Mokuno | 59e9732 | 2008-02-07 19:58:08 +0900 | [diff] [blame] | 634 | * gelic_card_disable_rxdmac terminates processing on the DMA controller by |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 635 | * turing off DMA and issuing a force end |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 636 | */ |
Masakazu Mokuno | 59e9732 | 2008-02-07 19:58:08 +0900 | [diff] [blame] | 637 | static inline void gelic_card_disable_rxdmac(struct gelic_card *card) |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 638 | { |
| 639 | int status; |
| 640 | |
| 641 | /* this hvc blocks until the DMA in progress really stopped */ |
| 642 | status = lv1_net_stop_rx_dma(bus_id(card), dev_id(card), 0); |
| 643 | if (status) |
| 644 | dev_err(ctodev(card), |
Paul Bolle | 426d310 | 2010-08-07 12:30:03 +0200 | [diff] [blame] | 645 | "lv1_net_stop_rx_dma failed, %d\n", status); |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 646 | } |
| 647 | |
| 648 | /** |
Masakazu Mokuno | 59e9732 | 2008-02-07 19:58:08 +0900 | [diff] [blame] | 649 | * gelic_card_disable_txdmac - disables the transmit DMA controller |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 650 | * @card: card structure |
| 651 | * |
Masakazu Mokuno | 59e9732 | 2008-02-07 19:58:08 +0900 | [diff] [blame] | 652 | * gelic_card_disable_txdmac terminates processing on the DMA controller by |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 653 | * turing off DMA and issuing a force end |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 654 | */ |
Masakazu Mokuno | 59e9732 | 2008-02-07 19:58:08 +0900 | [diff] [blame] | 655 | static inline void gelic_card_disable_txdmac(struct gelic_card *card) |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 656 | { |
| 657 | int status; |
| 658 | |
| 659 | /* this hvc blocks until the DMA in progress really stopped */ |
| 660 | status = lv1_net_stop_tx_dma(bus_id(card), dev_id(card), 0); |
| 661 | if (status) |
| 662 | dev_err(ctodev(card), |
Paul Bolle | 426d310 | 2010-08-07 12:30:03 +0200 | [diff] [blame] | 663 | "lv1_net_stop_tx_dma failed, status=%d\n", status); |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 664 | } |
| 665 | |
| 666 | /** |
| 667 | * gelic_net_stop - called upon ifconfig down |
| 668 | * @netdev: interface device structure |
| 669 | * |
| 670 | * always returns 0 |
| 671 | */ |
Masakazu Mokuno | 589866f | 2008-02-07 19:58:42 +0900 | [diff] [blame] | 672 | int gelic_net_stop(struct net_device *netdev) |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 673 | { |
Masakazu Mokuno | 589866f | 2008-02-07 19:58:42 +0900 | [diff] [blame] | 674 | struct gelic_card *card; |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 675 | |
Masakazu Mokuno | 589866f | 2008-02-07 19:58:42 +0900 | [diff] [blame] | 676 | pr_debug("%s: start\n", __func__); |
| 677 | |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 678 | netif_stop_queue(netdev); |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 679 | netif_carrier_off(netdev); |
| 680 | |
Masakazu Mokuno | 589866f | 2008-02-07 19:58:42 +0900 | [diff] [blame] | 681 | card = netdev_card(netdev); |
| 682 | gelic_card_down(card); |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 683 | |
Masakazu Mokuno | 589866f | 2008-02-07 19:58:42 +0900 | [diff] [blame] | 684 | pr_debug("%s: done\n", __func__); |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 685 | return 0; |
| 686 | } |
| 687 | |
| 688 | /** |
Masakazu Mokuno | 59e9732 | 2008-02-07 19:58:08 +0900 | [diff] [blame] | 689 | * gelic_card_get_next_tx_descr - returns the next available tx descriptor |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 690 | * @card: device structure to get descriptor from |
| 691 | * |
| 692 | * returns the address of the next descriptor, or NULL if not available. |
| 693 | */ |
Masakazu Mokuno | 59e9732 | 2008-02-07 19:58:08 +0900 | [diff] [blame] | 694 | static struct gelic_descr * |
| 695 | gelic_card_get_next_tx_descr(struct gelic_card *card) |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 696 | { |
| 697 | if (!card->tx_chain.head) |
| 698 | return NULL; |
Masakazu Mokuno | 173261e | 2007-08-31 22:22:32 +0900 | [diff] [blame] | 699 | /* see if the next descriptor is free */ |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 700 | if (card->tx_chain.tail != card->tx_chain.head->next && |
Masakazu Mokuno | 59e9732 | 2008-02-07 19:58:08 +0900 | [diff] [blame] | 701 | gelic_descr_get_status(card->tx_chain.head) == |
| 702 | GELIC_DESCR_DMA_NOT_IN_USE) |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 703 | return card->tx_chain.head; |
| 704 | else |
| 705 | return NULL; |
| 706 | |
| 707 | } |
| 708 | |
| 709 | /** |
Masakazu Mokuno | 589866f | 2008-02-07 19:58:42 +0900 | [diff] [blame] | 710 | * gelic_net_set_txdescr_cmdstat - sets the tx descriptor command field |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 711 | * @descr: descriptor structure to fill out |
| 712 | * @skb: packet to consider |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 713 | * |
| 714 | * fills out the command and status field of the descriptor structure, |
| 715 | * depending on hardware checksum settings. This function assumes a wmb() |
| 716 | * has executed before. |
| 717 | */ |
Masakazu Mokuno | 59e9732 | 2008-02-07 19:58:08 +0900 | [diff] [blame] | 718 | static void gelic_descr_set_tx_cmdstat(struct gelic_descr *descr, |
| 719 | struct sk_buff *skb) |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 720 | { |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 721 | if (skb->ip_summed != CHECKSUM_PARTIAL) |
Masakazu Mokuno | 100e1d8 | 2008-02-07 19:57:54 +0900 | [diff] [blame] | 722 | descr->dmac_cmd_status = |
Masakazu Mokuno | 59e9732 | 2008-02-07 19:58:08 +0900 | [diff] [blame] | 723 | cpu_to_be32(GELIC_DESCR_DMA_CMD_NO_CHKSUM | |
| 724 | GELIC_DESCR_TX_DMA_FRAME_TAIL); |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 725 | else { |
| 726 | /* is packet ip? |
| 727 | * if yes: tcp? udp? */ |
| 728 | if (skb->protocol == htons(ETH_P_IP)) { |
| 729 | if (ip_hdr(skb)->protocol == IPPROTO_TCP) |
| 730 | descr->dmac_cmd_status = |
Masakazu Mokuno | 59e9732 | 2008-02-07 19:58:08 +0900 | [diff] [blame] | 731 | cpu_to_be32(GELIC_DESCR_DMA_CMD_TCP_CHKSUM | |
| 732 | GELIC_DESCR_TX_DMA_FRAME_TAIL); |
Masakazu Mokuno | 173261e | 2007-08-31 22:22:32 +0900 | [diff] [blame] | 733 | |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 734 | else if (ip_hdr(skb)->protocol == IPPROTO_UDP) |
| 735 | descr->dmac_cmd_status = |
Masakazu Mokuno | 59e9732 | 2008-02-07 19:58:08 +0900 | [diff] [blame] | 736 | cpu_to_be32(GELIC_DESCR_DMA_CMD_UDP_CHKSUM | |
| 737 | GELIC_DESCR_TX_DMA_FRAME_TAIL); |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 738 | else /* |
| 739 | * the stack should checksum non-tcp and non-udp |
| 740 | * packets on his own: NETIF_F_IP_CSUM |
| 741 | */ |
| 742 | descr->dmac_cmd_status = |
Masakazu Mokuno | 59e9732 | 2008-02-07 19:58:08 +0900 | [diff] [blame] | 743 | cpu_to_be32(GELIC_DESCR_DMA_CMD_NO_CHKSUM | |
| 744 | GELIC_DESCR_TX_DMA_FRAME_TAIL); |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 745 | } |
| 746 | } |
| 747 | } |
| 748 | |
Masakazu Mokuno | 173261e | 2007-08-31 22:22:32 +0900 | [diff] [blame] | 749 | static inline struct sk_buff *gelic_put_vlan_tag(struct sk_buff *skb, |
| 750 | unsigned short tag) |
| 751 | { |
| 752 | struct vlan_ethhdr *veth; |
| 753 | static unsigned int c; |
| 754 | |
| 755 | if (skb_headroom(skb) < VLAN_HLEN) { |
| 756 | struct sk_buff *sk_tmp = skb; |
| 757 | pr_debug("%s: hd=%d c=%ud\n", __func__, skb_headroom(skb), c); |
| 758 | skb = skb_realloc_headroom(sk_tmp, VLAN_HLEN); |
| 759 | if (!skb) |
| 760 | return NULL; |
| 761 | dev_kfree_skb_any(sk_tmp); |
| 762 | } |
| 763 | veth = (struct vlan_ethhdr *)skb_push(skb, VLAN_HLEN); |
| 764 | |
| 765 | /* Move the mac addresses to the top of buffer */ |
| 766 | memmove(skb->data, skb->data + VLAN_HLEN, 2 * ETH_ALEN); |
| 767 | |
Harvey Harrison | 09640e6 | 2009-02-01 00:45:17 -0800 | [diff] [blame] | 768 | veth->h_vlan_proto = cpu_to_be16(ETH_P_8021Q); |
Masakazu Mokuno | 173261e | 2007-08-31 22:22:32 +0900 | [diff] [blame] | 769 | veth->h_vlan_TCI = htons(tag); |
| 770 | |
| 771 | return skb; |
| 772 | } |
| 773 | |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 774 | /** |
Masakazu Mokuno | 589866f | 2008-02-07 19:58:42 +0900 | [diff] [blame] | 775 | * gelic_descr_prepare_tx - setup a descriptor for sending packets |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 776 | * @card: card structure |
| 777 | * @descr: descriptor structure |
| 778 | * @skb: packet to use |
| 779 | * |
| 780 | * returns 0 on success, <0 on failure. |
| 781 | * |
| 782 | */ |
Masakazu Mokuno | 59e9732 | 2008-02-07 19:58:08 +0900 | [diff] [blame] | 783 | static int gelic_descr_prepare_tx(struct gelic_card *card, |
| 784 | struct gelic_descr *descr, |
| 785 | struct sk_buff *skb) |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 786 | { |
Masakazu Mokuno | 173261e | 2007-08-31 22:22:32 +0900 | [diff] [blame] | 787 | dma_addr_t buf; |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 788 | |
Masakazu Mokuno | 589866f | 2008-02-07 19:58:42 +0900 | [diff] [blame] | 789 | if (card->vlan_required) { |
Masakazu Mokuno | 173261e | 2007-08-31 22:22:32 +0900 | [diff] [blame] | 790 | struct sk_buff *skb_tmp; |
Masakazu Mokuno | 589866f | 2008-02-07 19:58:42 +0900 | [diff] [blame] | 791 | enum gelic_port_type type; |
| 792 | |
| 793 | type = netdev_port(skb->dev)->type; |
Masakazu Mokuno | 173261e | 2007-08-31 22:22:32 +0900 | [diff] [blame] | 794 | skb_tmp = gelic_put_vlan_tag(skb, |
Masakazu Mokuno | 589866f | 2008-02-07 19:58:42 +0900 | [diff] [blame] | 795 | card->vlan[type].tx); |
Masakazu Mokuno | 173261e | 2007-08-31 22:22:32 +0900 | [diff] [blame] | 796 | if (!skb_tmp) |
| 797 | return -ENOMEM; |
| 798 | skb = skb_tmp; |
Masakazu Mokuno | 48544cc | 2007-07-20 17:24:56 +0900 | [diff] [blame] | 799 | } |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 800 | |
Masakazu Mokuno | 173261e | 2007-08-31 22:22:32 +0900 | [diff] [blame] | 801 | buf = dma_map_single(ctodev(card), skb->data, skb->len, DMA_TO_DEVICE); |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 802 | |
Masakazu Mokuno | 173261e | 2007-08-31 22:22:32 +0900 | [diff] [blame] | 803 | if (!buf) { |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 804 | dev_err(ctodev(card), |
| 805 | "dma map 2 failed (%p, %i). Dropping packet\n", |
Masakazu Mokuno | 173261e | 2007-08-31 22:22:32 +0900 | [diff] [blame] | 806 | skb->data, skb->len); |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 807 | return -ENOMEM; |
| 808 | } |
| 809 | |
Masakazu Mokuno | 100e1d8 | 2008-02-07 19:57:54 +0900 | [diff] [blame] | 810 | descr->buf_addr = cpu_to_be32(buf); |
| 811 | descr->buf_size = cpu_to_be32(skb->len); |
Masakazu Mokuno | 173261e | 2007-08-31 22:22:32 +0900 | [diff] [blame] | 812 | descr->skb = skb; |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 813 | descr->data_status = 0; |
Masakazu Mokuno | 173261e | 2007-08-31 22:22:32 +0900 | [diff] [blame] | 814 | descr->next_descr_addr = 0; /* terminate hw descr */ |
Masakazu Mokuno | 59e9732 | 2008-02-07 19:58:08 +0900 | [diff] [blame] | 815 | gelic_descr_set_tx_cmdstat(descr, skb); |
Masakazu Mokuno | 48544cc | 2007-07-20 17:24:56 +0900 | [diff] [blame] | 816 | |
| 817 | /* bump free descriptor pointer */ |
Masakazu Mokuno | 173261e | 2007-08-31 22:22:32 +0900 | [diff] [blame] | 818 | card->tx_chain.head = descr->next; |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 819 | return 0; |
| 820 | } |
| 821 | |
| 822 | /** |
Masakazu Mokuno | 59e9732 | 2008-02-07 19:58:08 +0900 | [diff] [blame] | 823 | * gelic_card_kick_txdma - enables TX DMA processing |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 824 | * @card: card structure |
| 825 | * @descr: descriptor address to enable TX processing at |
| 826 | * |
| 827 | */ |
Masakazu Mokuno | 59e9732 | 2008-02-07 19:58:08 +0900 | [diff] [blame] | 828 | static int gelic_card_kick_txdma(struct gelic_card *card, |
| 829 | struct gelic_descr *descr) |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 830 | { |
Masakazu Mokuno | 48544cc | 2007-07-20 17:24:56 +0900 | [diff] [blame] | 831 | int status = 0; |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 832 | |
| 833 | if (card->tx_dma_progress) |
| 834 | return 0; |
| 835 | |
Masakazu Mokuno | 59e9732 | 2008-02-07 19:58:08 +0900 | [diff] [blame] | 836 | if (gelic_descr_get_status(descr) == GELIC_DESCR_DMA_CARDOWNED) { |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 837 | card->tx_dma_progress = 1; |
Masakazu Mokuno | dc029ad | 2007-08-31 22:25:09 +0900 | [diff] [blame] | 838 | status = lv1_net_start_tx_dma(bus_id(card), dev_id(card), |
| 839 | descr->bus_addr, 0); |
| 840 | if (status) |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 841 | dev_info(ctodev(card), "lv1_net_start_txdma failed," \ |
Masakazu Mokuno | dc029ad | 2007-08-31 22:25:09 +0900 | [diff] [blame] | 842 | "status=%d\n", status); |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 843 | } |
| 844 | return status; |
| 845 | } |
| 846 | |
| 847 | /** |
| 848 | * gelic_net_xmit - transmits a frame over the device |
| 849 | * @skb: packet to send out |
| 850 | * @netdev: interface device structure |
| 851 | * |
| 852 | * returns 0 on success, <0 on failure |
| 853 | */ |
Masakazu Mokuno | 589866f | 2008-02-07 19:58:42 +0900 | [diff] [blame] | 854 | int gelic_net_xmit(struct sk_buff *skb, struct net_device *netdev) |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 855 | { |
Masakazu Mokuno | 589866f | 2008-02-07 19:58:42 +0900 | [diff] [blame] | 856 | struct gelic_card *card = netdev_card(netdev); |
Masakazu Mokuno | 59e9732 | 2008-02-07 19:58:08 +0900 | [diff] [blame] | 857 | struct gelic_descr *descr; |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 858 | int result; |
| 859 | unsigned long flags; |
| 860 | |
Masakazu Mokuno | 589866f | 2008-02-07 19:58:42 +0900 | [diff] [blame] | 861 | spin_lock_irqsave(&card->tx_lock, flags); |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 862 | |
Masakazu Mokuno | 59e9732 | 2008-02-07 19:58:08 +0900 | [diff] [blame] | 863 | gelic_card_release_tx_chain(card, 0); |
Masakazu Mokuno | 48544cc | 2007-07-20 17:24:56 +0900 | [diff] [blame] | 864 | |
Masakazu Mokuno | 59e9732 | 2008-02-07 19:58:08 +0900 | [diff] [blame] | 865 | descr = gelic_card_get_next_tx_descr(card); |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 866 | if (!descr) { |
Masakazu Mokuno | 48544cc | 2007-07-20 17:24:56 +0900 | [diff] [blame] | 867 | /* |
| 868 | * no more descriptors free |
| 869 | */ |
Masakazu Mokuno | 589866f | 2008-02-07 19:58:42 +0900 | [diff] [blame] | 870 | gelic_card_stop_queues(card); |
| 871 | spin_unlock_irqrestore(&card->tx_lock, flags); |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 872 | return NETDEV_TX_BUSY; |
| 873 | } |
Masakazu Mokuno | 48544cc | 2007-07-20 17:24:56 +0900 | [diff] [blame] | 874 | |
Masakazu Mokuno | 59e9732 | 2008-02-07 19:58:08 +0900 | [diff] [blame] | 875 | result = gelic_descr_prepare_tx(card, descr, skb); |
Masakazu Mokuno | 48544cc | 2007-07-20 17:24:56 +0900 | [diff] [blame] | 876 | if (result) { |
| 877 | /* |
| 878 | * DMA map failed. As chanses are that failure |
| 879 | * would continue, just release skb and return |
| 880 | */ |
Masakazu Mokuno | 589866f | 2008-02-07 19:58:42 +0900 | [diff] [blame] | 881 | netdev->stats.tx_dropped++; |
Masakazu Mokuno | 48544cc | 2007-07-20 17:24:56 +0900 | [diff] [blame] | 882 | dev_kfree_skb_any(skb); |
Masakazu Mokuno | 589866f | 2008-02-07 19:58:42 +0900 | [diff] [blame] | 883 | spin_unlock_irqrestore(&card->tx_lock, flags); |
Masakazu Mokuno | 48544cc | 2007-07-20 17:24:56 +0900 | [diff] [blame] | 884 | return NETDEV_TX_OK; |
| 885 | } |
| 886 | /* |
| 887 | * link this prepared descriptor to previous one |
| 888 | * to achieve high performance |
| 889 | */ |
Masakazu Mokuno | 100e1d8 | 2008-02-07 19:57:54 +0900 | [diff] [blame] | 890 | descr->prev->next_descr_addr = cpu_to_be32(descr->bus_addr); |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 891 | /* |
| 892 | * as hardware descriptor is modified in the above lines, |
| 893 | * ensure that the hardware sees it |
| 894 | */ |
| 895 | wmb(); |
Masakazu Mokuno | 59e9732 | 2008-02-07 19:58:08 +0900 | [diff] [blame] | 896 | if (gelic_card_kick_txdma(card, descr)) { |
Masakazu Mokuno | 48544cc | 2007-07-20 17:24:56 +0900 | [diff] [blame] | 897 | /* |
| 898 | * kick failed. |
| 899 | * release descriptors which were just prepared |
| 900 | */ |
Masakazu Mokuno | 589866f | 2008-02-07 19:58:42 +0900 | [diff] [blame] | 901 | netdev->stats.tx_dropped++; |
Masakazu Mokuno | 59e9732 | 2008-02-07 19:58:08 +0900 | [diff] [blame] | 902 | gelic_descr_release_tx(card, descr); |
| 903 | gelic_descr_release_tx(card, descr->next); |
Masakazu Mokuno | 48544cc | 2007-07-20 17:24:56 +0900 | [diff] [blame] | 904 | card->tx_chain.tail = descr->next->next; |
| 905 | dev_info(ctodev(card), "%s: kick failure\n", __func__); |
Masakazu Mokuno | 48544cc | 2007-07-20 17:24:56 +0900 | [diff] [blame] | 906 | } |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 907 | |
Masakazu Mokuno | 589866f | 2008-02-07 19:58:42 +0900 | [diff] [blame] | 908 | spin_unlock_irqrestore(&card->tx_lock, flags); |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 909 | return NETDEV_TX_OK; |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 910 | } |
| 911 | |
| 912 | /** |
| 913 | * gelic_net_pass_skb_up - takes an skb from a descriptor and passes it on |
| 914 | * @descr: descriptor to process |
| 915 | * @card: card structure |
Masakazu Mokuno | 589866f | 2008-02-07 19:58:42 +0900 | [diff] [blame] | 916 | * @netdev: net_device structure to be passed packet |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 917 | * |
| 918 | * iommu-unmaps the skb, fills out skb structure and passes the data to the |
| 919 | * stack. The descriptor state is not changed. |
| 920 | */ |
Masakazu Mokuno | 59e9732 | 2008-02-07 19:58:08 +0900 | [diff] [blame] | 921 | static void gelic_net_pass_skb_up(struct gelic_descr *descr, |
Masakazu Mokuno | 589866f | 2008-02-07 19:58:42 +0900 | [diff] [blame] | 922 | struct gelic_card *card, |
| 923 | struct net_device *netdev) |
| 924 | |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 925 | { |
Masakazu Mokuno | 589866f | 2008-02-07 19:58:42 +0900 | [diff] [blame] | 926 | struct sk_buff *skb = descr->skb; |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 927 | u32 data_status, data_error; |
| 928 | |
Masakazu Mokuno | 100e1d8 | 2008-02-07 19:57:54 +0900 | [diff] [blame] | 929 | data_status = be32_to_cpu(descr->data_status); |
| 930 | data_error = be32_to_cpu(descr->data_error); |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 931 | /* unmap skb buffer */ |
Masakazu Mokuno | 589866f | 2008-02-07 19:58:42 +0900 | [diff] [blame] | 932 | dma_unmap_single(ctodev(card), be32_to_cpu(descr->buf_addr), |
| 933 | GELIC_NET_MAX_MTU, |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 934 | DMA_FROM_DEVICE); |
| 935 | |
Masakazu Mokuno | 589866f | 2008-02-07 19:58:42 +0900 | [diff] [blame] | 936 | skb_put(skb, be32_to_cpu(descr->valid_size)? |
Masakazu Mokuno | 100e1d8 | 2008-02-07 19:57:54 +0900 | [diff] [blame] | 937 | be32_to_cpu(descr->valid_size) : |
| 938 | be32_to_cpu(descr->result_size)); |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 939 | if (!descr->valid_size) |
| 940 | dev_info(ctodev(card), "buffer full %x %x %x\n", |
Masakazu Mokuno | 100e1d8 | 2008-02-07 19:57:54 +0900 | [diff] [blame] | 941 | be32_to_cpu(descr->result_size), |
| 942 | be32_to_cpu(descr->buf_size), |
| 943 | be32_to_cpu(descr->dmac_cmd_status)); |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 944 | |
| 945 | descr->skb = NULL; |
| 946 | /* |
| 947 | * the card put 2 bytes vlan tag in front |
| 948 | * of the ethernet frame |
| 949 | */ |
| 950 | skb_pull(skb, 2); |
| 951 | skb->protocol = eth_type_trans(skb, netdev); |
| 952 | |
| 953 | /* checksum offload */ |
| 954 | if (card->rx_csum) { |
Masakazu Mokuno | 59e9732 | 2008-02-07 19:58:08 +0900 | [diff] [blame] | 955 | if ((data_status & GELIC_DESCR_DATA_STATUS_CHK_MASK) && |
| 956 | (!(data_error & GELIC_DESCR_DATA_ERROR_CHK_MASK))) |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 957 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
| 958 | else |
Eric Dumazet | bc8acf2 | 2010-09-02 13:07:41 -0700 | [diff] [blame] | 959 | skb_checksum_none_assert(skb); |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 960 | } else |
Eric Dumazet | bc8acf2 | 2010-09-02 13:07:41 -0700 | [diff] [blame] | 961 | skb_checksum_none_assert(skb); |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 962 | |
| 963 | /* update netdevice statistics */ |
Masakazu Mokuno | 589866f | 2008-02-07 19:58:42 +0900 | [diff] [blame] | 964 | netdev->stats.rx_packets++; |
| 965 | netdev->stats.rx_bytes += skb->len; |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 966 | |
| 967 | /* pass skb up to stack */ |
| 968 | netif_receive_skb(skb); |
| 969 | } |
| 970 | |
| 971 | /** |
Masakazu Mokuno | 59e9732 | 2008-02-07 19:58:08 +0900 | [diff] [blame] | 972 | * gelic_card_decode_one_descr - processes an rx descriptor |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 973 | * @card: card structure |
| 974 | * |
| 975 | * returns 1 if a packet has been sent to the stack, otherwise 0 |
| 976 | * |
| 977 | * processes an rx descriptor by iommu-unmapping the data buffer and passing |
| 978 | * the packet up to the stack |
| 979 | */ |
Masakazu Mokuno | 59e9732 | 2008-02-07 19:58:08 +0900 | [diff] [blame] | 980 | static int gelic_card_decode_one_descr(struct gelic_card *card) |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 981 | { |
Masakazu Mokuno | 59e9732 | 2008-02-07 19:58:08 +0900 | [diff] [blame] | 982 | enum gelic_descr_dma_status status; |
| 983 | struct gelic_descr_chain *chain = &card->rx_chain; |
Masakazu Mokuno | 589866f | 2008-02-07 19:58:42 +0900 | [diff] [blame] | 984 | struct gelic_descr *descr = chain->head; |
| 985 | struct net_device *netdev = NULL; |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 986 | int dmac_chain_ended; |
| 987 | |
Masakazu Mokuno | 59e9732 | 2008-02-07 19:58:08 +0900 | [diff] [blame] | 988 | status = gelic_descr_get_status(descr); |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 989 | /* is this descriptor terminated with next_descr == NULL? */ |
| 990 | dmac_chain_ended = |
Masakazu Mokuno | 100e1d8 | 2008-02-07 19:57:54 +0900 | [diff] [blame] | 991 | be32_to_cpu(descr->dmac_cmd_status) & |
Masakazu Mokuno | 59e9732 | 2008-02-07 19:58:08 +0900 | [diff] [blame] | 992 | GELIC_DESCR_RX_DMA_CHAIN_END; |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 993 | |
Masakazu Mokuno | 59e9732 | 2008-02-07 19:58:08 +0900 | [diff] [blame] | 994 | if (status == GELIC_DESCR_DMA_CARDOWNED) |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 995 | return 0; |
| 996 | |
Masakazu Mokuno | 59e9732 | 2008-02-07 19:58:08 +0900 | [diff] [blame] | 997 | if (status == GELIC_DESCR_DMA_NOT_IN_USE) { |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 998 | dev_dbg(ctodev(card), "dormant descr? %p\n", descr); |
| 999 | return 0; |
| 1000 | } |
| 1001 | |
Masakazu Mokuno | 589866f | 2008-02-07 19:58:42 +0900 | [diff] [blame] | 1002 | /* netdevice select */ |
| 1003 | if (card->vlan_required) { |
| 1004 | unsigned int i; |
| 1005 | u16 vid; |
| 1006 | vid = *(u16 *)(descr->skb->data) & VLAN_VID_MASK; |
| 1007 | for (i = 0; i < GELIC_PORT_MAX; i++) { |
| 1008 | if (card->vlan[i].rx == vid) { |
| 1009 | netdev = card->netdev[i]; |
| 1010 | break; |
| 1011 | } |
| 1012 | }; |
| 1013 | if (GELIC_PORT_MAX <= i) { |
| 1014 | pr_info("%s: unknown packet vid=%x\n", __func__, vid); |
| 1015 | goto refill; |
| 1016 | } |
| 1017 | } else |
Geoff Levand | d4d7f1f | 2009-12-01 12:15:53 +0000 | [diff] [blame] | 1018 | netdev = card->netdev[GELIC_PORT_ETHERNET_0]; |
Masakazu Mokuno | 589866f | 2008-02-07 19:58:42 +0900 | [diff] [blame] | 1019 | |
Masakazu Mokuno | 59e9732 | 2008-02-07 19:58:08 +0900 | [diff] [blame] | 1020 | if ((status == GELIC_DESCR_DMA_RESPONSE_ERROR) || |
| 1021 | (status == GELIC_DESCR_DMA_PROTECTION_ERROR) || |
| 1022 | (status == GELIC_DESCR_DMA_FORCE_END)) { |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 1023 | dev_info(ctodev(card), "dropping RX descriptor with state %x\n", |
| 1024 | status); |
Masakazu Mokuno | 589866f | 2008-02-07 19:58:42 +0900 | [diff] [blame] | 1025 | netdev->stats.rx_dropped++; |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 1026 | goto refill; |
| 1027 | } |
| 1028 | |
Masakazu Mokuno | 59e9732 | 2008-02-07 19:58:08 +0900 | [diff] [blame] | 1029 | if (status == GELIC_DESCR_DMA_BUFFER_FULL) { |
Masakazu Mokuno | fe6d3a4 | 2007-07-20 17:39:25 +0900 | [diff] [blame] | 1030 | /* |
| 1031 | * Buffer full would occur if and only if |
| 1032 | * the frame length was longer than the size of this |
| 1033 | * descriptor's buffer. If the frame length was equal |
| 1034 | * to or shorter than buffer'size, FRAME_END condition |
| 1035 | * would occur. |
| 1036 | * Anyway this frame was longer than the MTU, |
| 1037 | * just drop it. |
| 1038 | */ |
| 1039 | dev_info(ctodev(card), "overlength frame\n"); |
| 1040 | goto refill; |
| 1041 | } |
| 1042 | /* |
| 1043 | * descriptoers any other than FRAME_END here should |
| 1044 | * be treated as error. |
| 1045 | */ |
Masakazu Mokuno | 59e9732 | 2008-02-07 19:58:08 +0900 | [diff] [blame] | 1046 | if (status != GELIC_DESCR_DMA_FRAME_END) { |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 1047 | dev_dbg(ctodev(card), "RX descriptor with state %x\n", |
| 1048 | status); |
| 1049 | goto refill; |
| 1050 | } |
| 1051 | |
| 1052 | /* ok, we've got a packet in descr */ |
Masakazu Mokuno | 589866f | 2008-02-07 19:58:42 +0900 | [diff] [blame] | 1053 | gelic_net_pass_skb_up(descr, card, netdev); |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 1054 | refill: |
Masakazu Mokuno | fe6d3a4 | 2007-07-20 17:39:25 +0900 | [diff] [blame] | 1055 | /* |
| 1056 | * So that always DMAC can see the end |
| 1057 | * of the descriptor chain to avoid |
| 1058 | * from unwanted DMAC overrun. |
| 1059 | */ |
| 1060 | descr->next_descr_addr = 0; |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 1061 | |
| 1062 | /* change the descriptor state: */ |
Masakazu Mokuno | 59e9732 | 2008-02-07 19:58:08 +0900 | [diff] [blame] | 1063 | gelic_descr_set_status(descr, GELIC_DESCR_DMA_NOT_IN_USE); |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 1064 | |
Masakazu Mokuno | fe6d3a4 | 2007-07-20 17:39:25 +0900 | [diff] [blame] | 1065 | /* |
| 1066 | * this call can fail, but for now, just leave this |
| 1067 | * decriptor without skb |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 1068 | */ |
Masakazu Mokuno | 59e9732 | 2008-02-07 19:58:08 +0900 | [diff] [blame] | 1069 | gelic_descr_prepare_rx(card, descr); |
Masakazu Mokuno | fe6d3a4 | 2007-07-20 17:39:25 +0900 | [diff] [blame] | 1070 | |
Masakazu Mokuno | 589866f | 2008-02-07 19:58:42 +0900 | [diff] [blame] | 1071 | chain->tail = descr; |
| 1072 | chain->head = descr->next; |
Masakazu Mokuno | fe6d3a4 | 2007-07-20 17:39:25 +0900 | [diff] [blame] | 1073 | |
| 1074 | /* |
| 1075 | * Set this descriptor the end of the chain. |
| 1076 | */ |
Masakazu Mokuno | 100e1d8 | 2008-02-07 19:57:54 +0900 | [diff] [blame] | 1077 | descr->prev->next_descr_addr = cpu_to_be32(descr->bus_addr); |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 1078 | |
Masakazu Mokuno | fe6d3a4 | 2007-07-20 17:39:25 +0900 | [diff] [blame] | 1079 | /* |
| 1080 | * If dmac chain was met, DMAC stopped. |
| 1081 | * thus re-enable it |
| 1082 | */ |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 1083 | if (dmac_chain_ended) { |
Masakazu Mokuno | 583aae1 | 2007-07-20 17:35:54 +0900 | [diff] [blame] | 1084 | card->rx_dma_restart_required = 1; |
| 1085 | dev_dbg(ctodev(card), "reenable rx dma scheduled\n"); |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 1086 | } |
| 1087 | |
| 1088 | return 1; |
| 1089 | } |
| 1090 | |
| 1091 | /** |
| 1092 | * gelic_net_poll - NAPI poll function called by the stack to return packets |
Masakazu Mokuno | 589866f | 2008-02-07 19:58:42 +0900 | [diff] [blame] | 1093 | * @napi: napi structure |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 1094 | * @budget: number of packets we can pass to the stack at most |
| 1095 | * |
Masakazu Mokuno | 589866f | 2008-02-07 19:58:42 +0900 | [diff] [blame] | 1096 | * returns the number of the processed packets |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 1097 | * |
| 1098 | */ |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 1099 | static int gelic_net_poll(struct napi_struct *napi, int budget) |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 1100 | { |
Masakazu Mokuno | 59e9732 | 2008-02-07 19:58:08 +0900 | [diff] [blame] | 1101 | struct gelic_card *card = container_of(napi, struct gelic_card, napi); |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 1102 | int packets_done = 0; |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 1103 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 1104 | while (packets_done < budget) { |
Masakazu Mokuno | 59e9732 | 2008-02-07 19:58:08 +0900 | [diff] [blame] | 1105 | if (!gelic_card_decode_one_descr(card)) |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 1106 | break; |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 1107 | |
| 1108 | packets_done++; |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 1109 | } |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 1110 | |
| 1111 | if (packets_done < budget) { |
Masakazu Mokuno | 589866f | 2008-02-07 19:58:42 +0900 | [diff] [blame] | 1112 | napi_complete(napi); |
Masakazu Mokuno | 59e9732 | 2008-02-07 19:58:08 +0900 | [diff] [blame] | 1113 | gelic_card_rx_irq_on(card); |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 1114 | } |
| 1115 | return packets_done; |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 1116 | } |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 1117 | /** |
| 1118 | * gelic_net_change_mtu - changes the MTU of an interface |
| 1119 | * @netdev: interface device structure |
| 1120 | * @new_mtu: new MTU value |
| 1121 | * |
| 1122 | * returns 0 on success, <0 on failure |
| 1123 | */ |
Masakazu Mokuno | 589866f | 2008-02-07 19:58:42 +0900 | [diff] [blame] | 1124 | int gelic_net_change_mtu(struct net_device *netdev, int new_mtu) |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 1125 | { |
| 1126 | /* no need to re-alloc skbs or so -- the max mtu is about 2.3k |
| 1127 | * and mtu is outbound only anyway */ |
| 1128 | if ((new_mtu < GELIC_NET_MIN_MTU) || |
| 1129 | (new_mtu > GELIC_NET_MAX_MTU)) { |
| 1130 | return -EINVAL; |
| 1131 | } |
| 1132 | netdev->mtu = new_mtu; |
| 1133 | return 0; |
| 1134 | } |
| 1135 | |
| 1136 | /** |
Masakazu Mokuno | 59e9732 | 2008-02-07 19:58:08 +0900 | [diff] [blame] | 1137 | * gelic_card_interrupt - event handler for gelic_net |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 1138 | */ |
Masakazu Mokuno | 59e9732 | 2008-02-07 19:58:08 +0900 | [diff] [blame] | 1139 | static irqreturn_t gelic_card_interrupt(int irq, void *ptr) |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 1140 | { |
| 1141 | unsigned long flags; |
Masakazu Mokuno | 589866f | 2008-02-07 19:58:42 +0900 | [diff] [blame] | 1142 | struct gelic_card *card = ptr; |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 1143 | u64 status; |
| 1144 | |
| 1145 | status = card->irq_status; |
| 1146 | |
| 1147 | if (!status) |
| 1148 | return IRQ_NONE; |
| 1149 | |
Masakazu Mokuno | 589866f | 2008-02-07 19:58:42 +0900 | [diff] [blame] | 1150 | status &= card->irq_mask; |
| 1151 | |
Masakazu Mokuno | 583aae1 | 2007-07-20 17:35:54 +0900 | [diff] [blame] | 1152 | if (card->rx_dma_restart_required) { |
| 1153 | card->rx_dma_restart_required = 0; |
Masakazu Mokuno | 59e9732 | 2008-02-07 19:58:08 +0900 | [diff] [blame] | 1154 | gelic_card_enable_rxdmac(card); |
Masakazu Mokuno | 583aae1 | 2007-07-20 17:35:54 +0900 | [diff] [blame] | 1155 | } |
| 1156 | |
Masakazu Mokuno | 59e9732 | 2008-02-07 19:58:08 +0900 | [diff] [blame] | 1157 | if (status & GELIC_CARD_RXINT) { |
| 1158 | gelic_card_rx_irq_off(card); |
Masakazu Mokuno | 589866f | 2008-02-07 19:58:42 +0900 | [diff] [blame] | 1159 | napi_schedule(&card->napi); |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 1160 | } |
| 1161 | |
Masakazu Mokuno | 59e9732 | 2008-02-07 19:58:08 +0900 | [diff] [blame] | 1162 | if (status & GELIC_CARD_TXINT) { |
Masakazu Mokuno | 589866f | 2008-02-07 19:58:42 +0900 | [diff] [blame] | 1163 | spin_lock_irqsave(&card->tx_lock, flags); |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 1164 | card->tx_dma_progress = 0; |
Masakazu Mokuno | 59e9732 | 2008-02-07 19:58:08 +0900 | [diff] [blame] | 1165 | gelic_card_release_tx_chain(card, 0); |
Masakazu Mokuno | 48544cc | 2007-07-20 17:24:56 +0900 | [diff] [blame] | 1166 | /* kick outstanding tx descriptor if any */ |
Masakazu Mokuno | 59e9732 | 2008-02-07 19:58:08 +0900 | [diff] [blame] | 1167 | gelic_card_kick_txdma(card, card->tx_chain.tail); |
Masakazu Mokuno | 589866f | 2008-02-07 19:58:42 +0900 | [diff] [blame] | 1168 | spin_unlock_irqrestore(&card->tx_lock, flags); |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 1169 | } |
Masakazu Mokuno | 01fed4c | 2008-02-07 19:58:32 +0900 | [diff] [blame] | 1170 | |
| 1171 | /* ether port status changed */ |
| 1172 | if (status & GELIC_CARD_PORT_STATUS_CHANGED) |
| 1173 | gelic_card_get_ether_port_status(card, 1); |
Masakazu Mokuno | 589866f | 2008-02-07 19:58:42 +0900 | [diff] [blame] | 1174 | |
Masakazu Mokuno | 09dde54 | 2008-02-07 19:58:57 +0900 | [diff] [blame] | 1175 | #ifdef CONFIG_GELIC_WIRELESS |
| 1176 | if (status & (GELIC_CARD_WLAN_EVENT_RECEIVED | |
| 1177 | GELIC_CARD_WLAN_COMMAND_COMPLETED)) |
| 1178 | gelic_wl_interrupt(card->netdev[GELIC_PORT_WIRELESS], status); |
| 1179 | #endif |
| 1180 | |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 1181 | return IRQ_HANDLED; |
| 1182 | } |
| 1183 | |
| 1184 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 1185 | /** |
| 1186 | * gelic_net_poll_controller - artificial interrupt for netconsole etc. |
| 1187 | * @netdev: interface device structure |
| 1188 | * |
| 1189 | * see Documentation/networking/netconsole.txt |
| 1190 | */ |
Masakazu Mokuno | 589866f | 2008-02-07 19:58:42 +0900 | [diff] [blame] | 1191 | void gelic_net_poll_controller(struct net_device *netdev) |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 1192 | { |
Masakazu Mokuno | 589866f | 2008-02-07 19:58:42 +0900 | [diff] [blame] | 1193 | struct gelic_card *card = netdev_card(netdev); |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 1194 | |
Masakazu Mokuno | 59e9732 | 2008-02-07 19:58:08 +0900 | [diff] [blame] | 1195 | gelic_card_set_irq_mask(card, 0); |
| 1196 | gelic_card_interrupt(netdev->irq, netdev); |
Masakazu Mokuno | 589866f | 2008-02-07 19:58:42 +0900 | [diff] [blame] | 1197 | gelic_card_set_irq_mask(card, card->irq_mask); |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 1198 | } |
| 1199 | #endif /* CONFIG_NET_POLL_CONTROLLER */ |
| 1200 | |
| 1201 | /** |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 1202 | * gelic_net_open - called upon ifonfig up |
| 1203 | * @netdev: interface device structure |
| 1204 | * |
| 1205 | * returns 0 on success, <0 on failure |
| 1206 | * |
| 1207 | * gelic_net_open allocates all the descriptors and memory needed for |
| 1208 | * operation, sets up multicast list and enables interrupts |
| 1209 | */ |
Masakazu Mokuno | 589866f | 2008-02-07 19:58:42 +0900 | [diff] [blame] | 1210 | int gelic_net_open(struct net_device *netdev) |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 1211 | { |
Masakazu Mokuno | 589866f | 2008-02-07 19:58:42 +0900 | [diff] [blame] | 1212 | struct gelic_card *card = netdev_card(netdev); |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 1213 | |
Masakazu Mokuno | 589866f | 2008-02-07 19:58:42 +0900 | [diff] [blame] | 1214 | dev_dbg(ctodev(card), " -> %s %p\n", __func__, netdev); |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 1215 | |
Masakazu Mokuno | 589866f | 2008-02-07 19:58:42 +0900 | [diff] [blame] | 1216 | gelic_card_up(card); |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 1217 | |
| 1218 | netif_start_queue(netdev); |
Masakazu Mokuno | 01fed4c | 2008-02-07 19:58:32 +0900 | [diff] [blame] | 1219 | gelic_card_get_ether_port_status(card, 1); |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 1220 | |
Masakazu Mokuno | 589866f | 2008-02-07 19:58:42 +0900 | [diff] [blame] | 1221 | dev_dbg(ctodev(card), " <- %s\n", __func__); |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 1222 | return 0; |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 1223 | } |
| 1224 | |
Masakazu Mokuno | 589866f | 2008-02-07 19:58:42 +0900 | [diff] [blame] | 1225 | void gelic_net_get_drvinfo(struct net_device *netdev, |
| 1226 | struct ethtool_drvinfo *info) |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 1227 | { |
| 1228 | strncpy(info->driver, DRV_NAME, sizeof(info->driver) - 1); |
| 1229 | strncpy(info->version, DRV_VERSION, sizeof(info->version) - 1); |
| 1230 | } |
| 1231 | |
Masakazu Mokuno | 59e9732 | 2008-02-07 19:58:08 +0900 | [diff] [blame] | 1232 | static int gelic_ether_get_settings(struct net_device *netdev, |
| 1233 | struct ethtool_cmd *cmd) |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 1234 | { |
Masakazu Mokuno | 589866f | 2008-02-07 19:58:42 +0900 | [diff] [blame] | 1235 | struct gelic_card *card = netdev_card(netdev); |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 1236 | |
Masakazu Mokuno | 01fed4c | 2008-02-07 19:58:32 +0900 | [diff] [blame] | 1237 | gelic_card_get_ether_port_status(card, 0); |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 1238 | |
Masakazu Mokuno | 01fed4c | 2008-02-07 19:58:32 +0900 | [diff] [blame] | 1239 | if (card->ether_port_status & GELIC_LV1_ETHER_FULL_DUPLEX) |
| 1240 | cmd->duplex = DUPLEX_FULL; |
| 1241 | else |
| 1242 | cmd->duplex = DUPLEX_HALF; |
| 1243 | |
| 1244 | switch (card->ether_port_status & GELIC_LV1_ETHER_SPEED_MASK) { |
| 1245 | case GELIC_LV1_ETHER_SPEED_10: |
| 1246 | cmd->speed = SPEED_10; |
| 1247 | break; |
| 1248 | case GELIC_LV1_ETHER_SPEED_100: |
| 1249 | cmd->speed = SPEED_100; |
| 1250 | break; |
| 1251 | case GELIC_LV1_ETHER_SPEED_1000: |
| 1252 | cmd->speed = SPEED_1000; |
| 1253 | break; |
| 1254 | default: |
| 1255 | pr_info("%s: speed unknown\n", __func__); |
| 1256 | cmd->speed = SPEED_10; |
| 1257 | break; |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 1258 | } |
Masakazu Mokuno | 01fed4c | 2008-02-07 19:58:32 +0900 | [diff] [blame] | 1259 | |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 1260 | cmd->supported = SUPPORTED_TP | SUPPORTED_Autoneg | |
| 1261 | SUPPORTED_10baseT_Half | SUPPORTED_10baseT_Full | |
| 1262 | SUPPORTED_100baseT_Half | SUPPORTED_100baseT_Full | |
Hideyuki Sasaki | 55873ed | 2009-12-01 12:15:58 +0000 | [diff] [blame] | 1263 | SUPPORTED_1000baseT_Full; |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 1264 | cmd->advertising = cmd->supported; |
Hideyuki Sasaki | 55873ed | 2009-12-01 12:15:58 +0000 | [diff] [blame] | 1265 | if (card->link_mode & GELIC_LV1_ETHER_AUTO_NEG) { |
| 1266 | cmd->autoneg = AUTONEG_ENABLE; |
| 1267 | } else { |
| 1268 | cmd->autoneg = AUTONEG_DISABLE; |
| 1269 | cmd->advertising &= ~ADVERTISED_Autoneg; |
| 1270 | } |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 1271 | cmd->port = PORT_TP; |
| 1272 | |
| 1273 | return 0; |
| 1274 | } |
| 1275 | |
Hideyuki Sasaki | 55873ed | 2009-12-01 12:15:58 +0000 | [diff] [blame] | 1276 | static int gelic_ether_set_settings(struct net_device *netdev, |
| 1277 | struct ethtool_cmd *cmd) |
| 1278 | { |
| 1279 | struct gelic_card *card = netdev_card(netdev); |
| 1280 | u64 mode; |
| 1281 | int ret; |
| 1282 | |
| 1283 | if (cmd->autoneg == AUTONEG_ENABLE) { |
| 1284 | mode = GELIC_LV1_ETHER_AUTO_NEG; |
| 1285 | } else { |
| 1286 | switch (cmd->speed) { |
| 1287 | case SPEED_10: |
| 1288 | mode = GELIC_LV1_ETHER_SPEED_10; |
| 1289 | break; |
| 1290 | case SPEED_100: |
| 1291 | mode = GELIC_LV1_ETHER_SPEED_100; |
| 1292 | break; |
| 1293 | case SPEED_1000: |
| 1294 | mode = GELIC_LV1_ETHER_SPEED_1000; |
| 1295 | break; |
| 1296 | default: |
| 1297 | return -EINVAL; |
| 1298 | } |
| 1299 | if (cmd->duplex == DUPLEX_FULL) |
| 1300 | mode |= GELIC_LV1_ETHER_FULL_DUPLEX; |
| 1301 | else if (cmd->speed == SPEED_1000) { |
| 1302 | pr_info("1000 half duplex is not supported.\n"); |
| 1303 | return -EINVAL; |
| 1304 | } |
| 1305 | } |
| 1306 | |
| 1307 | ret = gelic_card_set_link_mode(card, mode); |
| 1308 | |
| 1309 | if (ret) |
| 1310 | return ret; |
| 1311 | |
| 1312 | return 0; |
| 1313 | } |
| 1314 | |
Masakazu Mokuno | 589866f | 2008-02-07 19:58:42 +0900 | [diff] [blame] | 1315 | u32 gelic_net_get_rx_csum(struct net_device *netdev) |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 1316 | { |
Masakazu Mokuno | 589866f | 2008-02-07 19:58:42 +0900 | [diff] [blame] | 1317 | struct gelic_card *card = netdev_card(netdev); |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 1318 | |
| 1319 | return card->rx_csum; |
| 1320 | } |
| 1321 | |
Masakazu Mokuno | 589866f | 2008-02-07 19:58:42 +0900 | [diff] [blame] | 1322 | int gelic_net_set_rx_csum(struct net_device *netdev, u32 data) |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 1323 | { |
Masakazu Mokuno | 589866f | 2008-02-07 19:58:42 +0900 | [diff] [blame] | 1324 | struct gelic_card *card = netdev_card(netdev); |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 1325 | |
| 1326 | card->rx_csum = data; |
| 1327 | return 0; |
| 1328 | } |
| 1329 | |
Masakazu Mokuno | 3faac21 | 2008-03-27 11:39:31 +1100 | [diff] [blame] | 1330 | static void gelic_net_get_wol(struct net_device *netdev, |
| 1331 | struct ethtool_wolinfo *wol) |
| 1332 | { |
| 1333 | if (0 <= ps3_compare_firmware_version(2, 2, 0)) |
| 1334 | wol->supported = WAKE_MAGIC; |
| 1335 | else |
| 1336 | wol->supported = 0; |
| 1337 | |
| 1338 | wol->wolopts = ps3_sys_manager_get_wol() ? wol->supported : 0; |
| 1339 | memset(&wol->sopass, 0, sizeof(wol->sopass)); |
| 1340 | } |
| 1341 | static int gelic_net_set_wol(struct net_device *netdev, |
| 1342 | struct ethtool_wolinfo *wol) |
| 1343 | { |
| 1344 | int status; |
| 1345 | struct gelic_card *card; |
| 1346 | u64 v1, v2; |
| 1347 | |
| 1348 | if (ps3_compare_firmware_version(2, 2, 0) < 0 || |
| 1349 | !capable(CAP_NET_ADMIN)) |
| 1350 | return -EPERM; |
| 1351 | |
| 1352 | if (wol->wolopts & ~WAKE_MAGIC) |
| 1353 | return -EINVAL; |
| 1354 | |
| 1355 | card = netdev_card(netdev); |
| 1356 | if (wol->wolopts & WAKE_MAGIC) { |
| 1357 | status = lv1_net_control(bus_id(card), dev_id(card), |
| 1358 | GELIC_LV1_SET_WOL, |
| 1359 | GELIC_LV1_WOL_MAGIC_PACKET, |
| 1360 | 0, GELIC_LV1_WOL_MP_ENABLE, |
| 1361 | &v1, &v2); |
| 1362 | if (status) { |
| 1363 | pr_info("%s: enabling WOL failed %d\n", __func__, |
| 1364 | status); |
| 1365 | status = -EIO; |
| 1366 | goto done; |
| 1367 | } |
| 1368 | status = lv1_net_control(bus_id(card), dev_id(card), |
| 1369 | GELIC_LV1_SET_WOL, |
| 1370 | GELIC_LV1_WOL_ADD_MATCH_ADDR, |
| 1371 | 0, GELIC_LV1_WOL_MATCH_ALL, |
| 1372 | &v1, &v2); |
| 1373 | if (!status) |
| 1374 | ps3_sys_manager_set_wol(1); |
| 1375 | else { |
| 1376 | pr_info("%s: enabling WOL filter failed %d\n", |
| 1377 | __func__, status); |
| 1378 | status = -EIO; |
| 1379 | } |
| 1380 | } else { |
| 1381 | status = lv1_net_control(bus_id(card), dev_id(card), |
| 1382 | GELIC_LV1_SET_WOL, |
| 1383 | GELIC_LV1_WOL_MAGIC_PACKET, |
| 1384 | 0, GELIC_LV1_WOL_MP_DISABLE, |
| 1385 | &v1, &v2); |
| 1386 | if (status) { |
| 1387 | pr_info("%s: disabling WOL failed %d\n", __func__, |
| 1388 | status); |
| 1389 | status = -EIO; |
| 1390 | goto done; |
| 1391 | } |
| 1392 | status = lv1_net_control(bus_id(card), dev_id(card), |
| 1393 | GELIC_LV1_SET_WOL, |
| 1394 | GELIC_LV1_WOL_DELETE_MATCH_ADDR, |
| 1395 | 0, GELIC_LV1_WOL_MATCH_ALL, |
| 1396 | &v1, &v2); |
| 1397 | if (!status) |
| 1398 | ps3_sys_manager_set_wol(0); |
| 1399 | else { |
| 1400 | pr_info("%s: removing WOL filter failed %d\n", |
| 1401 | __func__, status); |
| 1402 | status = -EIO; |
| 1403 | } |
| 1404 | } |
| 1405 | done: |
| 1406 | return status; |
| 1407 | } |
| 1408 | |
Stephen Hemminger | 0fc0b73 | 2009-09-02 01:03:33 -0700 | [diff] [blame] | 1409 | static const struct ethtool_ops gelic_ether_ethtool_ops = { |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 1410 | .get_drvinfo = gelic_net_get_drvinfo, |
Masakazu Mokuno | 59e9732 | 2008-02-07 19:58:08 +0900 | [diff] [blame] | 1411 | .get_settings = gelic_ether_get_settings, |
Hideyuki Sasaki | 55873ed | 2009-12-01 12:15:58 +0000 | [diff] [blame] | 1412 | .set_settings = gelic_ether_set_settings, |
Masakazu Mokuno | 7bc56b9 | 2008-02-07 19:58:20 +0900 | [diff] [blame] | 1413 | .get_link = ethtool_op_get_link, |
Masakazu Mokuno | 7bc56b9 | 2008-02-07 19:58:20 +0900 | [diff] [blame] | 1414 | .get_tx_csum = ethtool_op_get_tx_csum, |
| 1415 | .set_tx_csum = ethtool_op_set_tx_csum, |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 1416 | .get_rx_csum = gelic_net_get_rx_csum, |
| 1417 | .set_rx_csum = gelic_net_set_rx_csum, |
Masakazu Mokuno | 3faac21 | 2008-03-27 11:39:31 +1100 | [diff] [blame] | 1418 | .get_wol = gelic_net_get_wol, |
| 1419 | .set_wol = gelic_net_set_wol, |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 1420 | }; |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 1421 | |
| 1422 | /** |
| 1423 | * gelic_net_tx_timeout_task - task scheduled by the watchdog timeout |
| 1424 | * function (to be called not under interrupt status) |
| 1425 | * @work: work is context of tx timout task |
| 1426 | * |
| 1427 | * called as task when tx hangs, resets interface (if interface is up) |
| 1428 | */ |
| 1429 | static void gelic_net_tx_timeout_task(struct work_struct *work) |
| 1430 | { |
Masakazu Mokuno | 59e9732 | 2008-02-07 19:58:08 +0900 | [diff] [blame] | 1431 | struct gelic_card *card = |
| 1432 | container_of(work, struct gelic_card, tx_timeout_task); |
Geoff Levand | d4d7f1f | 2009-12-01 12:15:53 +0000 | [diff] [blame] | 1433 | struct net_device *netdev = card->netdev[GELIC_PORT_ETHERNET_0]; |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 1434 | |
Frans Pop | 583d077 | 2010-03-24 07:57:31 +0000 | [diff] [blame] | 1435 | dev_info(ctodev(card), "%s:Timed out. Restarting...\n", __func__); |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 1436 | |
| 1437 | if (!(netdev->flags & IFF_UP)) |
| 1438 | goto out; |
| 1439 | |
| 1440 | netif_device_detach(netdev); |
| 1441 | gelic_net_stop(netdev); |
| 1442 | |
| 1443 | gelic_net_open(netdev); |
| 1444 | netif_device_attach(netdev); |
| 1445 | |
| 1446 | out: |
| 1447 | atomic_dec(&card->tx_timeout_task_counter); |
| 1448 | } |
| 1449 | |
| 1450 | /** |
| 1451 | * gelic_net_tx_timeout - called when the tx timeout watchdog kicks in. |
| 1452 | * @netdev: interface device structure |
| 1453 | * |
| 1454 | * called, if tx hangs. Schedules a task that resets the interface |
| 1455 | */ |
Masakazu Mokuno | 589866f | 2008-02-07 19:58:42 +0900 | [diff] [blame] | 1456 | void gelic_net_tx_timeout(struct net_device *netdev) |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 1457 | { |
Masakazu Mokuno | 59e9732 | 2008-02-07 19:58:08 +0900 | [diff] [blame] | 1458 | struct gelic_card *card; |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 1459 | |
Masakazu Mokuno | 589866f | 2008-02-07 19:58:42 +0900 | [diff] [blame] | 1460 | card = netdev_card(netdev); |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 1461 | atomic_inc(&card->tx_timeout_task_counter); |
| 1462 | if (netdev->flags & IFF_UP) |
| 1463 | schedule_work(&card->tx_timeout_task); |
| 1464 | else |
| 1465 | atomic_dec(&card->tx_timeout_task_counter); |
| 1466 | } |
| 1467 | |
Masakazu Mokuno | 5384e83 | 2009-01-15 22:47:29 +0000 | [diff] [blame] | 1468 | static const struct net_device_ops gelic_netdevice_ops = { |
| 1469 | .ndo_open = gelic_net_open, |
| 1470 | .ndo_stop = gelic_net_stop, |
| 1471 | .ndo_start_xmit = gelic_net_xmit, |
| 1472 | .ndo_set_multicast_list = gelic_net_set_multi, |
| 1473 | .ndo_change_mtu = gelic_net_change_mtu, |
| 1474 | .ndo_tx_timeout = gelic_net_tx_timeout, |
Ben Hutchings | 240c102 | 2009-07-09 17:54:35 +0000 | [diff] [blame] | 1475 | .ndo_set_mac_address = eth_mac_addr, |
Masakazu Mokuno | 5384e83 | 2009-01-15 22:47:29 +0000 | [diff] [blame] | 1476 | .ndo_validate_addr = eth_validate_addr, |
| 1477 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 1478 | .ndo_poll_controller = gelic_net_poll_controller, |
| 1479 | #endif |
| 1480 | }; |
| 1481 | |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 1482 | /** |
Masakazu Mokuno | 59e9732 | 2008-02-07 19:58:08 +0900 | [diff] [blame] | 1483 | * gelic_ether_setup_netdev_ops - initialization of net_device operations |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 1484 | * @netdev: net_device structure |
| 1485 | * |
| 1486 | * fills out function pointers in the net_device structure |
| 1487 | */ |
Geert Uytterhoeven | 48dce82 | 2009-06-10 04:38:58 +0000 | [diff] [blame] | 1488 | static void __devinit gelic_ether_setup_netdev_ops(struct net_device *netdev, |
| 1489 | struct napi_struct *napi) |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 1490 | { |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 1491 | netdev->watchdog_timeo = GELIC_NET_WATCHDOG_TIMEOUT; |
Masakazu Mokuno | 589866f | 2008-02-07 19:58:42 +0900 | [diff] [blame] | 1492 | /* NAPI */ |
| 1493 | netif_napi_add(netdev, napi, |
| 1494 | gelic_net_poll, GELIC_NET_NAPI_WEIGHT); |
| 1495 | netdev->ethtool_ops = &gelic_ether_ethtool_ops; |
Masakazu Mokuno | 5384e83 | 2009-01-15 22:47:29 +0000 | [diff] [blame] | 1496 | netdev->netdev_ops = &gelic_netdevice_ops; |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 1497 | } |
| 1498 | |
| 1499 | /** |
Masakazu Mokuno | 589866f | 2008-02-07 19:58:42 +0900 | [diff] [blame] | 1500 | * gelic_ether_setup_netdev - initialization of net_device |
| 1501 | * @netdev: net_device structure |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 1502 | * @card: card structure |
| 1503 | * |
| 1504 | * Returns 0 on success or <0 on failure |
| 1505 | * |
Masakazu Mokuno | 589866f | 2008-02-07 19:58:42 +0900 | [diff] [blame] | 1506 | * gelic_ether_setup_netdev initializes the net_device structure |
| 1507 | * and register it. |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 1508 | **/ |
Geert Uytterhoeven | 48dce82 | 2009-06-10 04:38:58 +0000 | [diff] [blame] | 1509 | int __devinit gelic_net_setup_netdev(struct net_device *netdev, |
| 1510 | struct gelic_card *card) |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 1511 | { |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 1512 | int status; |
| 1513 | u64 v1, v2; |
| 1514 | |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 1515 | netdev->features = NETIF_F_IP_CSUM; |
| 1516 | |
| 1517 | status = lv1_net_control(bus_id(card), dev_id(card), |
Masakazu Mokuno | 59e9732 | 2008-02-07 19:58:08 +0900 | [diff] [blame] | 1518 | GELIC_LV1_GET_MAC_ADDRESS, |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 1519 | 0, 0, 0, &v1, &v2); |
Masakazu Mokuno | 589866f | 2008-02-07 19:58:42 +0900 | [diff] [blame] | 1520 | v1 <<= 16; |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 1521 | if (status || !is_valid_ether_addr((u8 *)&v1)) { |
| 1522 | dev_info(ctodev(card), |
| 1523 | "%s:lv1_net_control GET_MAC_ADDR failed %d\n", |
| 1524 | __func__, status); |
| 1525 | return -EINVAL; |
| 1526 | } |
Masakazu Mokuno | 589866f | 2008-02-07 19:58:42 +0900 | [diff] [blame] | 1527 | memcpy(netdev->dev_addr, &v1, ETH_ALEN); |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 1528 | |
Masakazu Mokuno | 589866f | 2008-02-07 19:58:42 +0900 | [diff] [blame] | 1529 | if (card->vlan_required) { |
Masakazu Mokuno | 173261e | 2007-08-31 22:22:32 +0900 | [diff] [blame] | 1530 | netdev->hard_header_len += VLAN_HLEN; |
Masakazu Mokuno | 589866f | 2008-02-07 19:58:42 +0900 | [diff] [blame] | 1531 | /* |
| 1532 | * As vlan is internally used, |
| 1533 | * we can not receive vlan packets |
| 1534 | */ |
| 1535 | netdev->features |= NETIF_F_VLAN_CHALLENGED; |
Masakazu Mokuno | 173261e | 2007-08-31 22:22:32 +0900 | [diff] [blame] | 1536 | } |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 1537 | |
| 1538 | status = register_netdev(netdev); |
| 1539 | if (status) { |
Masakazu Mokuno | 589866f | 2008-02-07 19:58:42 +0900 | [diff] [blame] | 1540 | dev_err(ctodev(card), "%s:Couldn't register %s %d\n", |
| 1541 | __func__, netdev->name, status); |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 1542 | return status; |
| 1543 | } |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 1544 | dev_info(ctodev(card), "%s: MAC addr %pM\n", |
| 1545 | netdev->name, netdev->dev_addr); |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 1546 | |
| 1547 | return 0; |
| 1548 | } |
| 1549 | |
| 1550 | /** |
Masakazu Mokuno | 59e9732 | 2008-02-07 19:58:08 +0900 | [diff] [blame] | 1551 | * gelic_alloc_card_net - allocates net_device and card structure |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 1552 | * |
| 1553 | * returns the card structure or NULL in case of errors |
| 1554 | * |
| 1555 | * the card and net_device structures are linked to each other |
| 1556 | */ |
Masakazu Mokuno | 589866f | 2008-02-07 19:58:42 +0900 | [diff] [blame] | 1557 | #define GELIC_ALIGN (32) |
Geert Uytterhoeven | 48dce82 | 2009-06-10 04:38:58 +0000 | [diff] [blame] | 1558 | static struct gelic_card * __devinit gelic_alloc_card_net(struct net_device **netdev) |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 1559 | { |
Masakazu Mokuno | 59e9732 | 2008-02-07 19:58:08 +0900 | [diff] [blame] | 1560 | struct gelic_card *card; |
Masakazu Mokuno | 589866f | 2008-02-07 19:58:42 +0900 | [diff] [blame] | 1561 | struct gelic_port *port; |
| 1562 | void *p; |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 1563 | size_t alloc_size; |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 1564 | /* |
Masakazu Mokuno | 589866f | 2008-02-07 19:58:42 +0900 | [diff] [blame] | 1565 | * gelic requires dma descriptor is 32 bytes aligned and |
| 1566 | * the hypervisor requires irq_status is 8 bytes aligned. |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 1567 | */ |
Masakazu Mokuno | 59e9732 | 2008-02-07 19:58:08 +0900 | [diff] [blame] | 1568 | BUILD_BUG_ON(offsetof(struct gelic_card, irq_status) % 8); |
| 1569 | BUILD_BUG_ON(offsetof(struct gelic_card, descr) % 32); |
Masakazu Mokuno | 589866f | 2008-02-07 19:58:42 +0900 | [diff] [blame] | 1570 | alloc_size = |
| 1571 | sizeof(struct gelic_card) + |
| 1572 | sizeof(struct gelic_descr) * GELIC_NET_RX_DESCRIPTORS + |
| 1573 | sizeof(struct gelic_descr) * GELIC_NET_TX_DESCRIPTORS + |
| 1574 | GELIC_ALIGN - 1; |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 1575 | |
Masakazu Mokuno | 589866f | 2008-02-07 19:58:42 +0900 | [diff] [blame] | 1576 | p = kzalloc(alloc_size, GFP_KERNEL); |
| 1577 | if (!p) |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 1578 | return NULL; |
Masakazu Mokuno | 589866f | 2008-02-07 19:58:42 +0900 | [diff] [blame] | 1579 | card = PTR_ALIGN(p, GELIC_ALIGN); |
| 1580 | card->unalign = p; |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 1581 | |
Masakazu Mokuno | 589866f | 2008-02-07 19:58:42 +0900 | [diff] [blame] | 1582 | /* |
| 1583 | * alloc netdev |
| 1584 | */ |
| 1585 | *netdev = alloc_etherdev(sizeof(struct gelic_port)); |
| 1586 | if (!netdev) { |
| 1587 | kfree(card->unalign); |
| 1588 | return NULL; |
| 1589 | } |
| 1590 | port = netdev_priv(*netdev); |
| 1591 | |
| 1592 | /* gelic_port */ |
| 1593 | port->netdev = *netdev; |
| 1594 | port->card = card; |
Geoff Levand | d4d7f1f | 2009-12-01 12:15:53 +0000 | [diff] [blame] | 1595 | port->type = GELIC_PORT_ETHERNET_0; |
Masakazu Mokuno | 589866f | 2008-02-07 19:58:42 +0900 | [diff] [blame] | 1596 | |
| 1597 | /* gelic_card */ |
Geoff Levand | d4d7f1f | 2009-12-01 12:15:53 +0000 | [diff] [blame] | 1598 | card->netdev[GELIC_PORT_ETHERNET_0] = *netdev; |
Masakazu Mokuno | 589866f | 2008-02-07 19:58:42 +0900 | [diff] [blame] | 1599 | |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 1600 | INIT_WORK(&card->tx_timeout_task, gelic_net_tx_timeout_task); |
| 1601 | init_waitqueue_head(&card->waitq); |
| 1602 | atomic_set(&card->tx_timeout_task_counter, 0); |
Daniel Walker | 2914f3e | 2008-05-22 00:00:03 -0700 | [diff] [blame] | 1603 | mutex_init(&card->updown_lock); |
Masakazu Mokuno | 589866f | 2008-02-07 19:58:42 +0900 | [diff] [blame] | 1604 | atomic_set(&card->users, 0); |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 1605 | |
| 1606 | return card; |
| 1607 | } |
| 1608 | |
Geert Uytterhoeven | 48dce82 | 2009-06-10 04:38:58 +0000 | [diff] [blame] | 1609 | static void __devinit gelic_card_get_vlan_info(struct gelic_card *card) |
Masakazu Mokuno | 589866f | 2008-02-07 19:58:42 +0900 | [diff] [blame] | 1610 | { |
| 1611 | u64 v1, v2; |
| 1612 | int status; |
| 1613 | unsigned int i; |
| 1614 | struct { |
| 1615 | int tx; |
| 1616 | int rx; |
| 1617 | } vlan_id_ix[2] = { |
Geoff Levand | d4d7f1f | 2009-12-01 12:15:53 +0000 | [diff] [blame] | 1618 | [GELIC_PORT_ETHERNET_0] = { |
| 1619 | .tx = GELIC_LV1_VLAN_TX_ETHERNET_0, |
| 1620 | .rx = GELIC_LV1_VLAN_RX_ETHERNET_0 |
Masakazu Mokuno | 589866f | 2008-02-07 19:58:42 +0900 | [diff] [blame] | 1621 | }, |
| 1622 | [GELIC_PORT_WIRELESS] = { |
| 1623 | .tx = GELIC_LV1_VLAN_TX_WIRELESS, |
| 1624 | .rx = GELIC_LV1_VLAN_RX_WIRELESS |
| 1625 | } |
| 1626 | }; |
| 1627 | |
| 1628 | for (i = 0; i < ARRAY_SIZE(vlan_id_ix); i++) { |
| 1629 | /* tx tag */ |
| 1630 | status = lv1_net_control(bus_id(card), dev_id(card), |
| 1631 | GELIC_LV1_GET_VLAN_ID, |
| 1632 | vlan_id_ix[i].tx, |
| 1633 | 0, 0, &v1, &v2); |
| 1634 | if (status || !v1) { |
| 1635 | if (status != LV1_NO_ENTRY) |
| 1636 | dev_dbg(ctodev(card), |
| 1637 | "get vlan id for tx(%d) failed(%d)\n", |
| 1638 | vlan_id_ix[i].tx, status); |
| 1639 | card->vlan[i].tx = 0; |
| 1640 | card->vlan[i].rx = 0; |
| 1641 | continue; |
| 1642 | } |
| 1643 | card->vlan[i].tx = (u16)v1; |
| 1644 | |
| 1645 | /* rx tag */ |
| 1646 | status = lv1_net_control(bus_id(card), dev_id(card), |
| 1647 | GELIC_LV1_GET_VLAN_ID, |
| 1648 | vlan_id_ix[i].rx, |
| 1649 | 0, 0, &v1, &v2); |
| 1650 | if (status || !v1) { |
| 1651 | if (status != LV1_NO_ENTRY) |
| 1652 | dev_info(ctodev(card), |
| 1653 | "get vlan id for rx(%d) failed(%d)\n", |
| 1654 | vlan_id_ix[i].rx, status); |
| 1655 | card->vlan[i].tx = 0; |
| 1656 | card->vlan[i].rx = 0; |
| 1657 | continue; |
| 1658 | } |
| 1659 | card->vlan[i].rx = (u16)v1; |
| 1660 | |
| 1661 | dev_dbg(ctodev(card), "vlan_id[%d] tx=%02x rx=%02x\n", |
| 1662 | i, card->vlan[i].tx, card->vlan[i].rx); |
| 1663 | } |
| 1664 | |
Geoff Levand | d4d7f1f | 2009-12-01 12:15:53 +0000 | [diff] [blame] | 1665 | if (card->vlan[GELIC_PORT_ETHERNET_0].tx) { |
Masakazu Mokuno | 589866f | 2008-02-07 19:58:42 +0900 | [diff] [blame] | 1666 | BUG_ON(!card->vlan[GELIC_PORT_WIRELESS].tx); |
| 1667 | card->vlan_required = 1; |
| 1668 | } else |
| 1669 | card->vlan_required = 0; |
| 1670 | |
| 1671 | /* check wirelss capable firmware */ |
| 1672 | if (ps3_compare_firmware_version(1, 6, 0) < 0) { |
| 1673 | card->vlan[GELIC_PORT_WIRELESS].tx = 0; |
| 1674 | card->vlan[GELIC_PORT_WIRELESS].rx = 0; |
| 1675 | } |
| 1676 | |
| 1677 | dev_info(ctodev(card), "internal vlan %s\n", |
| 1678 | card->vlan_required? "enabled" : "disabled"); |
| 1679 | } |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 1680 | /** |
| 1681 | * ps3_gelic_driver_probe - add a device to the control of this driver |
| 1682 | */ |
Geert Uytterhoeven | 48dce82 | 2009-06-10 04:38:58 +0000 | [diff] [blame] | 1683 | static int __devinit ps3_gelic_driver_probe(struct ps3_system_bus_device *dev) |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 1684 | { |
Masakazu Mokuno | 589866f | 2008-02-07 19:58:42 +0900 | [diff] [blame] | 1685 | struct gelic_card *card; |
| 1686 | struct net_device *netdev; |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 1687 | int result; |
| 1688 | |
Masakazu Mokuno | 589866f | 2008-02-07 19:58:42 +0900 | [diff] [blame] | 1689 | pr_debug("%s: called\n", __func__); |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 1690 | result = ps3_open_hv_device(dev); |
| 1691 | |
| 1692 | if (result) { |
Masakazu Mokuno | 589866f | 2008-02-07 19:58:42 +0900 | [diff] [blame] | 1693 | dev_dbg(&dev->core, "%s:ps3_open_hv_device failed\n", |
| 1694 | __func__); |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 1695 | goto fail_open; |
| 1696 | } |
| 1697 | |
| 1698 | result = ps3_dma_region_create(dev->d_region); |
| 1699 | |
| 1700 | if (result) { |
Masakazu Mokuno | 589866f | 2008-02-07 19:58:42 +0900 | [diff] [blame] | 1701 | dev_dbg(&dev->core, "%s:ps3_dma_region_create failed(%d)\n", |
| 1702 | __func__, result); |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 1703 | BUG_ON("check region type"); |
| 1704 | goto fail_dma_region; |
| 1705 | } |
| 1706 | |
Masakazu Mokuno | 589866f | 2008-02-07 19:58:42 +0900 | [diff] [blame] | 1707 | /* alloc card/netdevice */ |
| 1708 | card = gelic_alloc_card_net(&netdev); |
| 1709 | if (!card) { |
| 1710 | dev_info(&dev->core, "%s:gelic_net_alloc_card failed\n", |
| 1711 | __func__); |
| 1712 | result = -ENOMEM; |
| 1713 | goto fail_alloc_card; |
| 1714 | } |
Geert Uytterhoeven | 03fa68c | 2009-06-10 04:38:54 +0000 | [diff] [blame] | 1715 | ps3_system_bus_set_drvdata(dev, card); |
Masakazu Mokuno | 589866f | 2008-02-07 19:58:42 +0900 | [diff] [blame] | 1716 | card->dev = dev; |
| 1717 | |
| 1718 | /* get internal vlan info */ |
| 1719 | gelic_card_get_vlan_info(card); |
| 1720 | |
Hideyuki Sasaki | 55873ed | 2009-12-01 12:15:58 +0000 | [diff] [blame] | 1721 | card->link_mode = GELIC_LV1_ETHER_AUTO_NEG; |
| 1722 | |
Masakazu Mokuno | 589866f | 2008-02-07 19:58:42 +0900 | [diff] [blame] | 1723 | /* setup interrupt */ |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 1724 | result = lv1_net_set_interrupt_status_indicator(bus_id(card), |
| 1725 | dev_id(card), |
| 1726 | ps3_mm_phys_to_lpar(__pa(&card->irq_status)), |
| 1727 | 0); |
| 1728 | |
| 1729 | if (result) { |
| 1730 | dev_dbg(&dev->core, |
Masakazu Mokuno | 589866f | 2008-02-07 19:58:42 +0900 | [diff] [blame] | 1731 | "%s:set_interrupt_status_indicator failed: %s\n", |
| 1732 | __func__, ps3_result(result)); |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 1733 | result = -EIO; |
| 1734 | goto fail_status_indicator; |
| 1735 | } |
| 1736 | |
Masakazu Mokuno | 589866f | 2008-02-07 19:58:42 +0900 | [diff] [blame] | 1737 | result = ps3_sb_event_receive_port_setup(dev, PS3_BINDING_CPU_ANY, |
| 1738 | &card->irq); |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 1739 | |
| 1740 | if (result) { |
Masakazu Mokuno | 589866f | 2008-02-07 19:58:42 +0900 | [diff] [blame] | 1741 | dev_info(ctodev(card), |
| 1742 | "%s:gelic_net_open_device failed (%d)\n", |
| 1743 | __func__, result); |
| 1744 | result = -EPERM; |
| 1745 | goto fail_alloc_irq; |
| 1746 | } |
| 1747 | result = request_irq(card->irq, gelic_card_interrupt, |
| 1748 | IRQF_DISABLED, netdev->name, card); |
| 1749 | |
| 1750 | if (result) { |
| 1751 | dev_info(ctodev(card), "%s:request_irq failed (%d)\n", |
| 1752 | __func__, result); |
| 1753 | goto fail_request_irq; |
| 1754 | } |
| 1755 | |
| 1756 | /* setup card structure */ |
| 1757 | card->irq_mask = GELIC_CARD_RXINT | GELIC_CARD_TXINT | |
| 1758 | GELIC_CARD_PORT_STATUS_CHANGED; |
| 1759 | card->rx_csum = GELIC_CARD_RX_CSUM_DEFAULT; |
| 1760 | |
| 1761 | |
| 1762 | if (gelic_card_init_chain(card, &card->tx_chain, |
| 1763 | card->descr, GELIC_NET_TX_DESCRIPTORS)) |
| 1764 | goto fail_alloc_tx; |
| 1765 | if (gelic_card_init_chain(card, &card->rx_chain, |
| 1766 | card->descr + GELIC_NET_TX_DESCRIPTORS, |
| 1767 | GELIC_NET_RX_DESCRIPTORS)) |
| 1768 | goto fail_alloc_rx; |
| 1769 | |
| 1770 | /* head of chain */ |
| 1771 | card->tx_top = card->tx_chain.head; |
| 1772 | card->rx_top = card->rx_chain.head; |
| 1773 | dev_dbg(ctodev(card), "descr rx %p, tx %p, size %#lx, num %#x\n", |
| 1774 | card->rx_top, card->tx_top, sizeof(struct gelic_descr), |
| 1775 | GELIC_NET_RX_DESCRIPTORS); |
| 1776 | /* allocate rx skbs */ |
| 1777 | if (gelic_card_alloc_rx_skbs(card)) |
| 1778 | goto fail_alloc_skbs; |
| 1779 | |
| 1780 | spin_lock_init(&card->tx_lock); |
| 1781 | card->tx_dma_progress = 0; |
| 1782 | |
| 1783 | /* setup net_device structure */ |
| 1784 | netdev->irq = card->irq; |
| 1785 | SET_NETDEV_DEV(netdev, &card->dev->core); |
| 1786 | gelic_ether_setup_netdev_ops(netdev, &card->napi); |
| 1787 | result = gelic_net_setup_netdev(netdev, card); |
| 1788 | if (result) { |
| 1789 | dev_dbg(&dev->core, "%s: setup_netdev failed %d", |
| 1790 | __func__, result); |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 1791 | goto fail_setup_netdev; |
| 1792 | } |
| 1793 | |
Masakazu Mokuno | 09dde54 | 2008-02-07 19:58:57 +0900 | [diff] [blame] | 1794 | #ifdef CONFIG_GELIC_WIRELESS |
| 1795 | if (gelic_wl_driver_probe(card)) { |
| 1796 | dev_dbg(&dev->core, "%s: WL init failed\n", __func__); |
| 1797 | goto fail_setup_netdev; |
| 1798 | } |
| 1799 | #endif |
Masakazu Mokuno | 589866f | 2008-02-07 19:58:42 +0900 | [diff] [blame] | 1800 | pr_debug("%s: done\n", __func__); |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 1801 | return 0; |
| 1802 | |
| 1803 | fail_setup_netdev: |
Masakazu Mokuno | 589866f | 2008-02-07 19:58:42 +0900 | [diff] [blame] | 1804 | fail_alloc_skbs: |
| 1805 | gelic_card_free_chain(card, card->rx_chain.head); |
| 1806 | fail_alloc_rx: |
| 1807 | gelic_card_free_chain(card, card->tx_chain.head); |
| 1808 | fail_alloc_tx: |
| 1809 | free_irq(card->irq, card); |
| 1810 | netdev->irq = NO_IRQ; |
| 1811 | fail_request_irq: |
| 1812 | ps3_sb_event_receive_port_destroy(dev, card->irq); |
| 1813 | fail_alloc_irq: |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 1814 | lv1_net_set_interrupt_status_indicator(bus_id(card), |
Masakazu Mokuno | 589866f | 2008-02-07 19:58:42 +0900 | [diff] [blame] | 1815 | bus_id(card), |
| 1816 | 0, 0); |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 1817 | fail_status_indicator: |
Geert Uytterhoeven | 03fa68c | 2009-06-10 04:38:54 +0000 | [diff] [blame] | 1818 | ps3_system_bus_set_drvdata(dev, NULL); |
Masakazu Mokuno | 589866f | 2008-02-07 19:58:42 +0900 | [diff] [blame] | 1819 | kfree(netdev_card(netdev)->unalign); |
| 1820 | free_netdev(netdev); |
| 1821 | fail_alloc_card: |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 1822 | ps3_dma_region_free(dev->d_region); |
| 1823 | fail_dma_region: |
| 1824 | ps3_close_hv_device(dev); |
| 1825 | fail_open: |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 1826 | return result; |
| 1827 | } |
| 1828 | |
| 1829 | /** |
| 1830 | * ps3_gelic_driver_remove - remove a device from the control of this driver |
| 1831 | */ |
| 1832 | |
Masakazu Mokuno | 59e9732 | 2008-02-07 19:58:08 +0900 | [diff] [blame] | 1833 | static int ps3_gelic_driver_remove(struct ps3_system_bus_device *dev) |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 1834 | { |
Geert Uytterhoeven | 03fa68c | 2009-06-10 04:38:54 +0000 | [diff] [blame] | 1835 | struct gelic_card *card = ps3_system_bus_get_drvdata(dev); |
Masakazu Mokuno | 589866f | 2008-02-07 19:58:42 +0900 | [diff] [blame] | 1836 | struct net_device *netdev0; |
| 1837 | pr_debug("%s: called\n", __func__); |
| 1838 | |
Hideyuki Sasaki | 55873ed | 2009-12-01 12:15:58 +0000 | [diff] [blame] | 1839 | /* set auto-negotiation */ |
| 1840 | gelic_card_set_link_mode(card, GELIC_LV1_ETHER_AUTO_NEG); |
| 1841 | |
Masakazu Mokuno | 09dde54 | 2008-02-07 19:58:57 +0900 | [diff] [blame] | 1842 | #ifdef CONFIG_GELIC_WIRELESS |
| 1843 | gelic_wl_driver_remove(card); |
| 1844 | #endif |
Masakazu Mokuno | 589866f | 2008-02-07 19:58:42 +0900 | [diff] [blame] | 1845 | /* stop interrupt */ |
| 1846 | gelic_card_set_irq_mask(card, 0); |
| 1847 | |
| 1848 | /* turn off DMA, force end */ |
| 1849 | gelic_card_disable_rxdmac(card); |
| 1850 | gelic_card_disable_txdmac(card); |
| 1851 | |
| 1852 | /* release chains */ |
| 1853 | gelic_card_release_tx_chain(card, 1); |
| 1854 | gelic_card_release_rx_chain(card); |
| 1855 | |
| 1856 | gelic_card_free_chain(card, card->tx_top); |
| 1857 | gelic_card_free_chain(card, card->rx_top); |
| 1858 | |
Geoff Levand | d4d7f1f | 2009-12-01 12:15:53 +0000 | [diff] [blame] | 1859 | netdev0 = card->netdev[GELIC_PORT_ETHERNET_0]; |
Masakazu Mokuno | 589866f | 2008-02-07 19:58:42 +0900 | [diff] [blame] | 1860 | /* disconnect event port */ |
| 1861 | free_irq(card->irq, card); |
| 1862 | netdev0->irq = NO_IRQ; |
| 1863 | ps3_sb_event_receive_port_destroy(card->dev, card->irq); |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 1864 | |
| 1865 | wait_event(card->waitq, |
| 1866 | atomic_read(&card->tx_timeout_task_counter) == 0); |
| 1867 | |
| 1868 | lv1_net_set_interrupt_status_indicator(bus_id(card), dev_id(card), |
| 1869 | 0 , 0); |
| 1870 | |
Masakazu Mokuno | 589866f | 2008-02-07 19:58:42 +0900 | [diff] [blame] | 1871 | unregister_netdev(netdev0); |
| 1872 | kfree(netdev_card(netdev0)->unalign); |
| 1873 | free_netdev(netdev0); |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 1874 | |
Geert Uytterhoeven | 03fa68c | 2009-06-10 04:38:54 +0000 | [diff] [blame] | 1875 | ps3_system_bus_set_drvdata(dev, NULL); |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 1876 | |
| 1877 | ps3_dma_region_free(dev->d_region); |
| 1878 | |
| 1879 | ps3_close_hv_device(dev); |
| 1880 | |
Masakazu Mokuno | 589866f | 2008-02-07 19:58:42 +0900 | [diff] [blame] | 1881 | pr_debug("%s: done\n", __func__); |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 1882 | return 0; |
| 1883 | } |
| 1884 | |
| 1885 | static struct ps3_system_bus_driver ps3_gelic_driver = { |
| 1886 | .match_id = PS3_MATCH_ID_GELIC, |
| 1887 | .probe = ps3_gelic_driver_probe, |
| 1888 | .remove = ps3_gelic_driver_remove, |
| 1889 | .shutdown = ps3_gelic_driver_remove, |
| 1890 | .core.name = "ps3_gelic_driver", |
| 1891 | .core.owner = THIS_MODULE, |
| 1892 | }; |
| 1893 | |
| 1894 | static int __init ps3_gelic_driver_init (void) |
| 1895 | { |
| 1896 | return firmware_has_feature(FW_FEATURE_PS3_LV1) |
| 1897 | ? ps3_system_bus_driver_register(&ps3_gelic_driver) |
| 1898 | : -ENODEV; |
| 1899 | } |
| 1900 | |
| 1901 | static void __exit ps3_gelic_driver_exit (void) |
| 1902 | { |
| 1903 | ps3_system_bus_driver_unregister(&ps3_gelic_driver); |
| 1904 | } |
| 1905 | |
Masakazu Mokuno | 59e9732 | 2008-02-07 19:58:08 +0900 | [diff] [blame] | 1906 | module_init(ps3_gelic_driver_init); |
| 1907 | module_exit(ps3_gelic_driver_exit); |
Masakazu Mokuno | 02c1889 | 2007-07-05 20:11:16 +0900 | [diff] [blame] | 1908 | |
| 1909 | MODULE_ALIAS(PS3_MODULE_ALIAS_GELIC); |
| 1910 | |