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