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