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