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