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