blob: 56009d76832639dc3f28445e271e6ed8eeb18518 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Heiko Carstense018ba12006-02-01 03:06:31 -08002 * linux/drivers/s390/net/qeth_main.c
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 *
4 * Linux on zSeries OSA Express and HiperSockets support
5 *
6 * Copyright 2000,2003 IBM Corporation
7 *
8 * Author(s): Original Code written by
9 * Utz Bacher (utz.bacher@de.ibm.com)
10 * Rewritten by
Frank Pavlic1387780f2005-11-10 13:51:42 +010011 * Frank Pavlic (fpavlic@de.ibm.com) and
Linus Torvalds1da177e2005-04-16 15:20:36 -070012 * Thomas Spatzier <tspat@de.ibm.com>
13 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070014 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2, or (at your option)
17 * any later version.
18 *
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, write to the Free Software
26 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27 */
28
Linus Torvalds1da177e2005-04-16 15:20:36 -070029
30#include <linux/config.h>
31#include <linux/module.h>
32#include <linux/moduleparam.h>
33#include <linux/string.h>
34#include <linux/errno.h>
35#include <linux/mm.h>
36#include <linux/ip.h>
37#include <linux/inetdevice.h>
38#include <linux/netdevice.h>
39#include <linux/sched.h>
40#include <linux/workqueue.h>
41#include <linux/kernel.h>
42#include <linux/slab.h>
43#include <linux/interrupt.h>
44#include <linux/tcp.h>
45#include <linux/icmp.h>
46#include <linux/skbuff.h>
47#include <linux/in.h>
48#include <linux/igmp.h>
49#include <linux/init.h>
50#include <linux/reboot.h>
51#include <linux/mii.h>
52#include <linux/rcupdate.h>
53#include <linux/ethtool.h>
54
55#include <net/arp.h>
56#include <net/ip.h>
57#include <net/route.h>
58
59#include <asm/ebcdic.h>
60#include <asm/io.h>
61#include <asm/qeth.h>
62#include <asm/timex.h>
63#include <asm/semaphore.h>
64#include <asm/uaccess.h>
Carsten Ottecfb1b552006-01-06 00:19:14 -080065#include <asm/s390_rdev.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070066
67#include "qeth.h"
68#include "qeth_mpc.h"
69#include "qeth_fs.h"
70#include "qeth_eddp.h"
71#include "qeth_tso.h"
72
Linus Torvalds1da177e2005-04-16 15:20:36 -070073static const char *version = "qeth S/390 OSA-Express driver";
74
75/**
76 * Debug Facility Stuff
77 */
78static debug_info_t *qeth_dbf_setup = NULL;
79static debug_info_t *qeth_dbf_data = NULL;
80static debug_info_t *qeth_dbf_misc = NULL;
81static debug_info_t *qeth_dbf_control = NULL;
82debug_info_t *qeth_dbf_trace = NULL;
83static debug_info_t *qeth_dbf_sense = NULL;
84static debug_info_t *qeth_dbf_qerr = NULL;
85
86DEFINE_PER_CPU(char[256], qeth_dbf_txt_buf);
87
88/**
89 * some more definitions and declarations
90 */
91static unsigned int known_devices[][10] = QETH_MODELLIST_ARRAY;
92
93/* list of our cards */
94struct qeth_card_list_struct qeth_card_list;
95/*process list want to be notified*/
96spinlock_t qeth_notify_lock;
97struct list_head qeth_notify_list;
98
99static void qeth_send_control_data_cb(struct qeth_channel *,
100 struct qeth_cmd_buffer *);
101
102/**
103 * here we go with function implementation
104 */
105static void
106qeth_init_qdio_info(struct qeth_card *card);
107
108static int
109qeth_init_qdio_queues(struct qeth_card *card);
110
111static int
112qeth_alloc_qdio_buffers(struct qeth_card *card);
113
114static void
115qeth_free_qdio_buffers(struct qeth_card *);
116
117static void
118qeth_clear_qdio_buffers(struct qeth_card *);
119
120static void
121qeth_clear_ip_list(struct qeth_card *, int, int);
122
123static void
124qeth_clear_ipacmd_list(struct qeth_card *);
125
126static int
127qeth_qdio_clear_card(struct qeth_card *, int);
128
129static void
130qeth_clear_working_pool_list(struct qeth_card *);
131
132static void
133qeth_clear_cmd_buffers(struct qeth_channel *);
134
135static int
136qeth_stop(struct net_device *);
137
138static void
139qeth_clear_ipato_list(struct qeth_card *);
140
141static int
142qeth_is_addr_covered_by_ipato(struct qeth_card *, struct qeth_ipaddr *);
143
144static void
145qeth_irq_tasklet(unsigned long);
146
147static int
148qeth_set_online(struct ccwgroup_device *);
149
Frank Pavlic05e08a22005-05-12 20:39:09 +0200150static int
151__qeth_set_online(struct ccwgroup_device *gdev, int recovery_mode);
152
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153static struct qeth_ipaddr *
154qeth_get_addr_buffer(enum qeth_prot_versions);
155
156static void
157qeth_set_multicast_list(struct net_device *);
158
159static void
Frank Pavlic6c951b92005-11-10 13:51:25 +0100160qeth_setadp_promisc_mode(struct qeth_card *);
161
162static void
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163qeth_notify_processes(void)
164{
165 /*notify all registered processes */
166 struct qeth_notify_list_struct *n_entry;
167
168 QETH_DBF_TEXT(trace,3,"procnoti");
169 spin_lock(&qeth_notify_lock);
170 list_for_each_entry(n_entry, &qeth_notify_list, list) {
171 send_sig(n_entry->signum, n_entry->task, 1);
172 }
173 spin_unlock(&qeth_notify_lock);
174
175}
176int
177qeth_notifier_unregister(struct task_struct *p)
178{
179 struct qeth_notify_list_struct *n_entry, *tmp;
180
181 QETH_DBF_TEXT(trace, 2, "notunreg");
182 spin_lock(&qeth_notify_lock);
183 list_for_each_entry_safe(n_entry, tmp, &qeth_notify_list, list) {
184 if (n_entry->task == p) {
185 list_del(&n_entry->list);
186 kfree(n_entry);
187 goto out;
188 }
189 }
190out:
191 spin_unlock(&qeth_notify_lock);
192 return 0;
193}
194int
195qeth_notifier_register(struct task_struct *p, int signum)
196{
197 struct qeth_notify_list_struct *n_entry;
198
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199 /*check first if entry already exists*/
200 spin_lock(&qeth_notify_lock);
201 list_for_each_entry(n_entry, &qeth_notify_list, list) {
202 if (n_entry->task == p) {
203 n_entry->signum = signum;
204 spin_unlock(&qeth_notify_lock);
205 return 0;
206 }
207 }
208 spin_unlock(&qeth_notify_lock);
209
210 n_entry = (struct qeth_notify_list_struct *)
211 kmalloc(sizeof(struct qeth_notify_list_struct),GFP_KERNEL);
212 if (!n_entry)
213 return -ENOMEM;
214 n_entry->task = p;
215 n_entry->signum = signum;
216 spin_lock(&qeth_notify_lock);
217 list_add(&n_entry->list,&qeth_notify_list);
218 spin_unlock(&qeth_notify_lock);
219 return 0;
220}
221
222
223/**
224 * free channel command buffers
225 */
226static void
227qeth_clean_channel(struct qeth_channel *channel)
228{
229 int cnt;
230
231 QETH_DBF_TEXT(setup, 2, "freech");
232 for (cnt = 0; cnt < QETH_CMD_BUFFER_NO; cnt++)
233 kfree(channel->iob[cnt].data);
234}
235
236/**
237 * free card
238 */
239static void
240qeth_free_card(struct qeth_card *card)
241{
242
243 QETH_DBF_TEXT(setup, 2, "freecrd");
244 QETH_DBF_HEX(setup, 2, &card, sizeof(void *));
245 qeth_clean_channel(&card->read);
246 qeth_clean_channel(&card->write);
247 if (card->dev)
248 free_netdev(card->dev);
249 qeth_clear_ip_list(card, 0, 0);
250 qeth_clear_ipato_list(card);
251 kfree(card->ip_tbd_list);
252 qeth_free_qdio_buffers(card);
253 kfree(card);
254}
255
256/**
257 * alloc memory for command buffer per channel
258 */
259static int
260qeth_setup_channel(struct qeth_channel *channel)
261{
262 int cnt;
263
264 QETH_DBF_TEXT(setup, 2, "setupch");
265 for (cnt=0; cnt < QETH_CMD_BUFFER_NO; cnt++) {
266 channel->iob[cnt].data = (char *)
267 kmalloc(QETH_BUFSIZE, GFP_DMA|GFP_KERNEL);
268 if (channel->iob[cnt].data == NULL)
269 break;
270 channel->iob[cnt].state = BUF_STATE_FREE;
271 channel->iob[cnt].channel = channel;
272 channel->iob[cnt].callback = qeth_send_control_data_cb;
273 channel->iob[cnt].rc = 0;
274 }
275 if (cnt < QETH_CMD_BUFFER_NO) {
276 while (cnt-- > 0)
277 kfree(channel->iob[cnt].data);
278 return -ENOMEM;
279 }
280 channel->buf_no = 0;
281 channel->io_buf_no = 0;
282 atomic_set(&channel->irq_pending, 0);
283 spin_lock_init(&channel->iob_lock);
284
285 init_waitqueue_head(&channel->wait_q);
286 channel->irq_tasklet.data = (unsigned long) channel;
287 channel->irq_tasklet.func = qeth_irq_tasklet;
288 return 0;
289}
290
291/**
292 * alloc memory for card structure
293 */
294static struct qeth_card *
295qeth_alloc_card(void)
296{
297 struct qeth_card *card;
298
299 QETH_DBF_TEXT(setup, 2, "alloccrd");
Eric Sesterhenn88abaab2006-03-24 03:15:31 -0800300 card = kzalloc(sizeof(struct qeth_card), GFP_DMA|GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301 if (!card)
302 return NULL;
303 QETH_DBF_HEX(setup, 2, &card, sizeof(void *));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304 if (qeth_setup_channel(&card->read)) {
305 kfree(card);
306 return NULL;
307 }
308 if (qeth_setup_channel(&card->write)) {
309 qeth_clean_channel(&card->read);
310 kfree(card);
311 return NULL;
312 }
313 return card;
314}
315
316static long
317__qeth_check_irb_error(struct ccw_device *cdev, struct irb *irb)
318{
319 if (!IS_ERR(irb))
320 return 0;
321
322 switch (PTR_ERR(irb)) {
323 case -EIO:
324 PRINT_WARN("i/o-error on device %s\n", cdev->dev.bus_id);
325 QETH_DBF_TEXT(trace, 2, "ckirberr");
326 QETH_DBF_TEXT_(trace, 2, " rc%d", -EIO);
327 break;
328 case -ETIMEDOUT:
329 PRINT_WARN("timeout on device %s\n", cdev->dev.bus_id);
330 QETH_DBF_TEXT(trace, 2, "ckirberr");
331 QETH_DBF_TEXT_(trace, 2, " rc%d", -ETIMEDOUT);
332 break;
333 default:
334 PRINT_WARN("unknown error %ld on device %s\n", PTR_ERR(irb),
335 cdev->dev.bus_id);
336 QETH_DBF_TEXT(trace, 2, "ckirberr");
337 QETH_DBF_TEXT(trace, 2, " rc???");
338 }
339 return PTR_ERR(irb);
340}
341
342static int
343qeth_get_problem(struct ccw_device *cdev, struct irb *irb)
344{
345 int dstat,cstat;
346 char *sense;
347
348 sense = (char *) irb->ecw;
349 cstat = irb->scsw.cstat;
350 dstat = irb->scsw.dstat;
351
352 if (cstat & (SCHN_STAT_CHN_CTRL_CHK | SCHN_STAT_INTF_CTRL_CHK |
353 SCHN_STAT_CHN_DATA_CHK | SCHN_STAT_CHAIN_CHECK |
354 SCHN_STAT_PROT_CHECK | SCHN_STAT_PROG_CHECK)) {
355 QETH_DBF_TEXT(trace,2, "CGENCHK");
356 PRINT_WARN("check on device %s, dstat=x%x, cstat=x%x ",
357 cdev->dev.bus_id, dstat, cstat);
358 HEXDUMP16(WARN, "irb: ", irb);
359 HEXDUMP16(WARN, "irb: ", ((char *) irb) + 32);
360 return 1;
361 }
362
363 if (dstat & DEV_STAT_UNIT_CHECK) {
364 if (sense[SENSE_RESETTING_EVENT_BYTE] &
365 SENSE_RESETTING_EVENT_FLAG) {
366 QETH_DBF_TEXT(trace,2,"REVIND");
367 return 1;
368 }
369 if (sense[SENSE_COMMAND_REJECT_BYTE] &
370 SENSE_COMMAND_REJECT_FLAG) {
371 QETH_DBF_TEXT(trace,2,"CMDREJi");
372 return 0;
373 }
374 if ((sense[2] == 0xaf) && (sense[3] == 0xfe)) {
375 QETH_DBF_TEXT(trace,2,"AFFE");
376 return 1;
377 }
378 if ((!sense[0]) && (!sense[1]) && (!sense[2]) && (!sense[3])) {
379 QETH_DBF_TEXT(trace,2,"ZEROSEN");
380 return 0;
381 }
382 QETH_DBF_TEXT(trace,2,"DGENCHK");
383 return 1;
384 }
385 return 0;
386}
387static int qeth_issue_next_read(struct qeth_card *);
388
389/**
390 * interrupt handler
391 */
392static void
393qeth_irq(struct ccw_device *cdev, unsigned long intparm, struct irb *irb)
394{
395 int rc;
396 int cstat,dstat;
397 struct qeth_cmd_buffer *buffer;
398 struct qeth_channel *channel;
399 struct qeth_card *card;
400
401 QETH_DBF_TEXT(trace,5,"irq");
402
403 if (__qeth_check_irb_error(cdev, irb))
404 return;
405 cstat = irb->scsw.cstat;
406 dstat = irb->scsw.dstat;
407
408 card = CARD_FROM_CDEV(cdev);
409 if (!card)
410 return;
411
412 if (card->read.ccwdev == cdev){
413 channel = &card->read;
414 QETH_DBF_TEXT(trace,5,"read");
415 } else if (card->write.ccwdev == cdev) {
416 channel = &card->write;
417 QETH_DBF_TEXT(trace,5,"write");
418 } else {
419 channel = &card->data;
420 QETH_DBF_TEXT(trace,5,"data");
421 }
422 atomic_set(&channel->irq_pending, 0);
423
424 if (irb->scsw.fctl & (SCSW_FCTL_CLEAR_FUNC))
425 channel->state = CH_STATE_STOPPED;
426
427 if (irb->scsw.fctl & (SCSW_FCTL_HALT_FUNC))
428 channel->state = CH_STATE_HALTED;
429
430 /*let's wake up immediately on data channel*/
431 if ((channel == &card->data) && (intparm != 0))
432 goto out;
433
434 if (intparm == QETH_CLEAR_CHANNEL_PARM) {
435 QETH_DBF_TEXT(trace, 6, "clrchpar");
436 /* we don't have to handle this further */
437 intparm = 0;
438 }
439 if (intparm == QETH_HALT_CHANNEL_PARM) {
440 QETH_DBF_TEXT(trace, 6, "hltchpar");
441 /* we don't have to handle this further */
442 intparm = 0;
443 }
444 if ((dstat & DEV_STAT_UNIT_EXCEP) ||
445 (dstat & DEV_STAT_UNIT_CHECK) ||
446 (cstat)) {
447 if (irb->esw.esw0.erw.cons) {
448 /* TODO: we should make this s390dbf */
449 PRINT_WARN("sense data available on channel %s.\n",
450 CHANNEL_ID(channel));
451 PRINT_WARN(" cstat 0x%X\n dstat 0x%X\n", cstat, dstat);
452 HEXDUMP16(WARN,"irb: ",irb);
453 HEXDUMP16(WARN,"sense data: ",irb->ecw);
454 }
455 rc = qeth_get_problem(cdev,irb);
456 if (rc) {
457 qeth_schedule_recovery(card);
458 goto out;
459 }
460 }
461
462 if (intparm) {
463 buffer = (struct qeth_cmd_buffer *) __va((addr_t)intparm);
464 buffer->state = BUF_STATE_PROCESSED;
465 }
466 if (channel == &card->data)
467 return;
468
469 if (channel == &card->read &&
470 channel->state == CH_STATE_UP)
471 qeth_issue_next_read(card);
472
473 tasklet_schedule(&channel->irq_tasklet);
474 return;
475out:
476 wake_up(&card->wait_q);
477}
478
479/**
480 * tasklet function scheduled from irq handler
481 */
482static void
483qeth_irq_tasklet(unsigned long data)
484{
485 struct qeth_card *card;
486 struct qeth_channel *channel;
487 struct qeth_cmd_buffer *iob;
488 __u8 index;
489
490 QETH_DBF_TEXT(trace,5,"irqtlet");
491 channel = (struct qeth_channel *) data;
492 iob = channel->iob;
493 index = channel->buf_no;
494 card = CARD_FROM_CDEV(channel->ccwdev);
495 while (iob[index].state == BUF_STATE_PROCESSED) {
496 if (iob[index].callback !=NULL) {
497 iob[index].callback(channel,iob + index);
498 }
499 index = (index + 1) % QETH_CMD_BUFFER_NO;
500 }
501 channel->buf_no = index;
502 wake_up(&card->wait_q);
503}
504
Frank Pavlic05e08a22005-05-12 20:39:09 +0200505static int qeth_stop_card(struct qeth_card *, int);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506
507static int
Frank Pavlic05e08a22005-05-12 20:39:09 +0200508__qeth_set_offline(struct ccwgroup_device *cgdev, int recovery_mode)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509{
510 struct qeth_card *card = (struct qeth_card *) cgdev->dev.driver_data;
Ursula Braun9123e0d2005-09-30 10:17:24 +0200511 int rc = 0, rc2 = 0, rc3 = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512 enum qeth_card_states recover_flag;
513
514 QETH_DBF_TEXT(setup, 3, "setoffl");
515 QETH_DBF_HEX(setup, 3, &card, sizeof(void *));
Jeff Garzike82b0f22006-05-26 21:58:38 -0400516
Frank Pavlic66cc5d52006-02-07 17:04:38 +0100517 if (card->dev && netif_carrier_ok(card->dev))
518 netif_carrier_off(card->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519 recover_flag = card->state;
Frank Pavlic05e08a22005-05-12 20:39:09 +0200520 if (qeth_stop_card(card, recovery_mode) == -ERESTARTSYS){
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521 PRINT_WARN("Stopping card %s interrupted by user!\n",
522 CARD_BUS_ID(card));
523 return -ERESTARTSYS;
524 }
Ursula Braun9123e0d2005-09-30 10:17:24 +0200525 rc = ccw_device_set_offline(CARD_DDEV(card));
526 rc2 = ccw_device_set_offline(CARD_WDEV(card));
527 rc3 = ccw_device_set_offline(CARD_RDEV(card));
528 if (!rc)
529 rc = (rc2) ? rc2 : rc3;
530 if (rc)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531 QETH_DBF_TEXT_(setup, 2, "1err%d", rc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532 if (recover_flag == CARD_STATE_UP)
533 card->state = CARD_STATE_RECOVER;
534 qeth_notify_processes();
535 return 0;
536}
537
538static int
Frank Pavlic05e08a22005-05-12 20:39:09 +0200539qeth_set_offline(struct ccwgroup_device *cgdev)
540{
541 return __qeth_set_offline(cgdev, 0);
542}
543
544static int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545qeth_wait_for_threads(struct qeth_card *card, unsigned long threads);
546
547
548static void
549qeth_remove_device(struct ccwgroup_device *cgdev)
550{
551 struct qeth_card *card = (struct qeth_card *) cgdev->dev.driver_data;
552 unsigned long flags;
553
554 QETH_DBF_TEXT(setup, 3, "rmdev");
555 QETH_DBF_HEX(setup, 3, &card, sizeof(void *));
556
557 if (!card)
558 return;
559
560 if (qeth_wait_for_threads(card, 0xffffffff))
561 return;
562
563 if (cgdev->state == CCWGROUP_ONLINE){
564 card->use_hard_stop = 1;
565 qeth_set_offline(cgdev);
566 }
567 /* remove form our internal list */
568 write_lock_irqsave(&qeth_card_list.rwlock, flags);
569 list_del(&card->list);
570 write_unlock_irqrestore(&qeth_card_list.rwlock, flags);
571 if (card->dev)
572 unregister_netdev(card->dev);
573 qeth_remove_device_attributes(&cgdev->dev);
574 qeth_free_card(card);
575 cgdev->dev.driver_data = NULL;
576 put_device(&cgdev->dev);
577}
578
579static int
580qeth_register_addr_entry(struct qeth_card *, struct qeth_ipaddr *);
581static int
582qeth_deregister_addr_entry(struct qeth_card *, struct qeth_ipaddr *);
583
584/**
585 * Add/remove address to/from card's ip list, i.e. try to add or remove
586 * reference to/from an IP address that is already registered on the card.
587 * Returns:
588 * 0 address was on card and its reference count has been adjusted,
589 * but is still > 0, so nothing has to be done
590 * also returns 0 if card was not on card and the todo was to delete
591 * the address -> there is also nothing to be done
592 * 1 address was not on card and the todo is to add it to the card's ip
593 * list
594 * -1 address was on card and its reference count has been decremented
595 * to <= 0 by the todo -> address must be removed from card
596 */
597static int
598__qeth_ref_ip_on_card(struct qeth_card *card, struct qeth_ipaddr *todo,
599 struct qeth_ipaddr **__addr)
600{
601 struct qeth_ipaddr *addr;
602 int found = 0;
603
604 list_for_each_entry(addr, &card->ip_list, entry) {
Frank Pavlic6c88ad22005-11-10 13:49:28 +0100605 if (card->options.layer2) {
606 if ((addr->type == todo->type) &&
Jeff Garzike82b0f22006-05-26 21:58:38 -0400607 (memcmp(&addr->mac, &todo->mac,
Frank Pavlic6c88ad22005-11-10 13:49:28 +0100608 OSA_ADDR_LEN) == 0)) {
609 found = 1;
610 break;
611 }
612 continue;
Jeff Garzike82b0f22006-05-26 21:58:38 -0400613 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614 if ((addr->proto == QETH_PROT_IPV4) &&
615 (todo->proto == QETH_PROT_IPV4) &&
616 (addr->type == todo->type) &&
617 (addr->u.a4.addr == todo->u.a4.addr) &&
Frank Pavlic6c88ad22005-11-10 13:49:28 +0100618 (addr->u.a4.mask == todo->u.a4.mask)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619 found = 1;
620 break;
621 }
622 if ((addr->proto == QETH_PROT_IPV6) &&
623 (todo->proto == QETH_PROT_IPV6) &&
624 (addr->type == todo->type) &&
625 (addr->u.a6.pfxlen == todo->u.a6.pfxlen) &&
626 (memcmp(&addr->u.a6.addr, &todo->u.a6.addr,
Frank Pavlic6c88ad22005-11-10 13:49:28 +0100627 sizeof(struct in6_addr)) == 0)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700628 found = 1;
629 break;
630 }
631 }
Frank Pavlic6c88ad22005-11-10 13:49:28 +0100632 if (found) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700633 addr->users += todo->users;
634 if (addr->users <= 0){
635 *__addr = addr;
636 return -1;
637 } else {
638 /* for VIPA and RXIP limit refcount to 1 */
639 if (addr->type != QETH_IP_TYPE_NORMAL)
640 addr->users = 1;
641 return 0;
642 }
643 }
Frank Pavlic6c88ad22005-11-10 13:49:28 +0100644 if (todo->users > 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645 /* for VIPA and RXIP limit refcount to 1 */
646 if (todo->type != QETH_IP_TYPE_NORMAL)
647 todo->users = 1;
648 return 1;
649 } else
650 return 0;
651}
652
653static inline int
654__qeth_address_exists_in_list(struct list_head *list, struct qeth_ipaddr *addr,
655 int same_type)
656{
657 struct qeth_ipaddr *tmp;
658
659 list_for_each_entry(tmp, list, entry) {
660 if ((tmp->proto == QETH_PROT_IPV4) &&
661 (addr->proto == QETH_PROT_IPV4) &&
662 ((same_type && (tmp->type == addr->type)) ||
663 (!same_type && (tmp->type != addr->type)) ) &&
664 (tmp->u.a4.addr == addr->u.a4.addr) ){
665 return 1;
666 }
667 if ((tmp->proto == QETH_PROT_IPV6) &&
668 (addr->proto == QETH_PROT_IPV6) &&
669 ((same_type && (tmp->type == addr->type)) ||
670 (!same_type && (tmp->type != addr->type)) ) &&
671 (memcmp(&tmp->u.a6.addr, &addr->u.a6.addr,
672 sizeof(struct in6_addr)) == 0) ) {
673 return 1;
674 }
675 }
676 return 0;
677}
678
679/*
680 * Add IP to be added to todo list. If there is already an "add todo"
681 * in this list we just incremenent the reference count.
682 * Returns 0 if we just incremented reference count.
683 */
684static int
685__qeth_insert_ip_todo(struct qeth_card *card, struct qeth_ipaddr *addr, int add)
686{
687 struct qeth_ipaddr *tmp, *t;
688 int found = 0;
689
690 list_for_each_entry_safe(tmp, t, card->ip_tbd_list, entry) {
691 if ((addr->type == QETH_IP_TYPE_DEL_ALL_MC) &&
692 (tmp->type == QETH_IP_TYPE_DEL_ALL_MC))
693 return 0;
Frank Pavlic6c88ad22005-11-10 13:49:28 +0100694 if (card->options.layer2) {
695 if ((tmp->type == addr->type) &&
696 (tmp->is_multicast == addr->is_multicast) &&
Jeff Garzike82b0f22006-05-26 21:58:38 -0400697 (memcmp(&tmp->mac, &addr->mac,
Frank Pavlic6c88ad22005-11-10 13:49:28 +0100698 OSA_ADDR_LEN) == 0)) {
699 found = 1;
700 break;
701 }
702 continue;
Jeff Garzike82b0f22006-05-26 21:58:38 -0400703 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700704 if ((tmp->proto == QETH_PROT_IPV4) &&
705 (addr->proto == QETH_PROT_IPV4) &&
706 (tmp->type == addr->type) &&
707 (tmp->is_multicast == addr->is_multicast) &&
708 (tmp->u.a4.addr == addr->u.a4.addr) &&
Frank Pavlic6c88ad22005-11-10 13:49:28 +0100709 (tmp->u.a4.mask == addr->u.a4.mask)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700710 found = 1;
711 break;
712 }
713 if ((tmp->proto == QETH_PROT_IPV6) &&
714 (addr->proto == QETH_PROT_IPV6) &&
715 (tmp->type == addr->type) &&
716 (tmp->is_multicast == addr->is_multicast) &&
717 (tmp->u.a6.pfxlen == addr->u.a6.pfxlen) &&
718 (memcmp(&tmp->u.a6.addr, &addr->u.a6.addr,
Frank Pavlic6c88ad22005-11-10 13:49:28 +0100719 sizeof(struct in6_addr)) == 0)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700720 found = 1;
721 break;
722 }
723 }
724 if (found){
725 if (addr->users != 0)
726 tmp->users += addr->users;
727 else
728 tmp->users += add? 1:-1;
Frank Pavlic6c88ad22005-11-10 13:49:28 +0100729 if (tmp->users == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700730 list_del(&tmp->entry);
731 kfree(tmp);
732 }
733 return 0;
734 } else {
735 if (addr->type == QETH_IP_TYPE_DEL_ALL_MC)
736 list_add(&addr->entry, card->ip_tbd_list);
737 else {
738 if (addr->users == 0)
739 addr->users += add? 1:-1;
740 if (add && (addr->type == QETH_IP_TYPE_NORMAL) &&
741 qeth_is_addr_covered_by_ipato(card, addr)){
742 QETH_DBF_TEXT(trace, 2, "tkovaddr");
743 addr->set_flags |= QETH_IPA_SETIP_TAKEOVER_FLAG;
744 }
745 list_add_tail(&addr->entry, card->ip_tbd_list);
746 }
747 return 1;
748 }
749}
750
751/**
752 * Remove IP address from list
753 */
754static int
755qeth_delete_ip(struct qeth_card *card, struct qeth_ipaddr *addr)
756{
757 unsigned long flags;
758 int rc = 0;
759
Frank Pavlic6c88ad22005-11-10 13:49:28 +0100760 QETH_DBF_TEXT(trace, 4, "delip");
761
762 if (card->options.layer2)
763 QETH_DBF_HEX(trace, 4, &addr->mac, 6);
764 else if (addr->proto == QETH_PROT_IPV4)
765 QETH_DBF_HEX(trace, 4, &addr->u.a4.addr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700766 else {
Frank Pavlic6c88ad22005-11-10 13:49:28 +0100767 QETH_DBF_HEX(trace, 4, &addr->u.a6.addr, 8);
768 QETH_DBF_HEX(trace, 4, ((char *)&addr->u.a6.addr) + 8, 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700769 }
770 spin_lock_irqsave(&card->ip_lock, flags);
771 rc = __qeth_insert_ip_todo(card, addr, 0);
772 spin_unlock_irqrestore(&card->ip_lock, flags);
773 return rc;
774}
775
776static int
777qeth_add_ip(struct qeth_card *card, struct qeth_ipaddr *addr)
778{
779 unsigned long flags;
780 int rc = 0;
781
Frank Pavlic6c88ad22005-11-10 13:49:28 +0100782 QETH_DBF_TEXT(trace, 4, "addip");
783 if (card->options.layer2)
784 QETH_DBF_HEX(trace, 4, &addr->mac, 6);
785 else if (addr->proto == QETH_PROT_IPV4)
786 QETH_DBF_HEX(trace, 4, &addr->u.a4.addr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700787 else {
Frank Pavlic6c88ad22005-11-10 13:49:28 +0100788 QETH_DBF_HEX(trace, 4, &addr->u.a6.addr, 8);
789 QETH_DBF_HEX(trace, 4, ((char *)&addr->u.a6.addr) + 8, 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700790 }
791 spin_lock_irqsave(&card->ip_lock, flags);
792 rc = __qeth_insert_ip_todo(card, addr, 1);
793 spin_unlock_irqrestore(&card->ip_lock, flags);
794 return rc;
795}
796
797static inline void
798__qeth_delete_all_mc(struct qeth_card *card, unsigned long *flags)
799{
800 struct qeth_ipaddr *addr, *tmp;
801 int rc;
Frank Pavlicd805d7c2005-11-10 13:50:58 +0100802again:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700803 list_for_each_entry_safe(addr, tmp, &card->ip_list, entry) {
804 if (addr->is_multicast) {
805 spin_unlock_irqrestore(&card->ip_lock, *flags);
806 rc = qeth_deregister_addr_entry(card, addr);
807 spin_lock_irqsave(&card->ip_lock, *flags);
808 if (!rc) {
809 list_del(&addr->entry);
810 kfree(addr);
Frank Pavlicd805d7c2005-11-10 13:50:58 +0100811 goto again;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700812 }
813 }
814 }
815}
816
817static void
818qeth_set_ip_addr_list(struct qeth_card *card)
819{
820 struct list_head *tbd_list;
821 struct qeth_ipaddr *todo, *addr;
822 unsigned long flags;
823 int rc;
824
825 QETH_DBF_TEXT(trace, 2, "sdiplist");
826 QETH_DBF_HEX(trace, 2, &card, sizeof(void *));
827
828 spin_lock_irqsave(&card->ip_lock, flags);
829 tbd_list = card->ip_tbd_list;
830 card->ip_tbd_list = kmalloc(sizeof(struct list_head), GFP_ATOMIC);
831 if (!card->ip_tbd_list) {
832 QETH_DBF_TEXT(trace, 0, "silnomem");
833 card->ip_tbd_list = tbd_list;
834 spin_unlock_irqrestore(&card->ip_lock, flags);
835 return;
836 } else
837 INIT_LIST_HEAD(card->ip_tbd_list);
838
839 while (!list_empty(tbd_list)){
840 todo = list_entry(tbd_list->next, struct qeth_ipaddr, entry);
841 list_del(&todo->entry);
842 if (todo->type == QETH_IP_TYPE_DEL_ALL_MC){
843 __qeth_delete_all_mc(card, &flags);
844 kfree(todo);
845 continue;
846 }
847 rc = __qeth_ref_ip_on_card(card, todo, &addr);
848 if (rc == 0) {
849 /* nothing to be done; only adjusted refcount */
850 kfree(todo);
851 } else if (rc == 1) {
852 /* new entry to be added to on-card list */
853 spin_unlock_irqrestore(&card->ip_lock, flags);
854 rc = qeth_register_addr_entry(card, todo);
855 spin_lock_irqsave(&card->ip_lock, flags);
856 if (!rc)
857 list_add_tail(&todo->entry, &card->ip_list);
858 else
859 kfree(todo);
860 } else if (rc == -1) {
861 /* on-card entry to be removed */
862 list_del_init(&addr->entry);
863 spin_unlock_irqrestore(&card->ip_lock, flags);
864 rc = qeth_deregister_addr_entry(card, addr);
865 spin_lock_irqsave(&card->ip_lock, flags);
866 if (!rc)
867 kfree(addr);
868 else
869 list_add_tail(&addr->entry, &card->ip_list);
870 kfree(todo);
871 }
872 }
873 spin_unlock_irqrestore(&card->ip_lock, flags);
874 kfree(tbd_list);
875}
876
877static void qeth_delete_mc_addresses(struct qeth_card *);
878static void qeth_add_multicast_ipv4(struct qeth_card *);
Frank Pavlic6c88ad22005-11-10 13:49:28 +0100879static void qeth_layer2_add_multicast(struct qeth_card *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700880#ifdef CONFIG_QETH_IPV6
881static void qeth_add_multicast_ipv6(struct qeth_card *);
882#endif
883
884static inline int
885qeth_set_thread_start_bit(struct qeth_card *card, unsigned long thread)
886{
887 unsigned long flags;
888
889 spin_lock_irqsave(&card->thread_mask_lock, flags);
890 if ( !(card->thread_allowed_mask & thread) ||
891 (card->thread_start_mask & thread) ) {
892 spin_unlock_irqrestore(&card->thread_mask_lock, flags);
893 return -EPERM;
894 }
895 card->thread_start_mask |= thread;
896 spin_unlock_irqrestore(&card->thread_mask_lock, flags);
897 return 0;
898}
899
900static void
901qeth_clear_thread_start_bit(struct qeth_card *card, unsigned long thread)
902{
903 unsigned long flags;
904
905 spin_lock_irqsave(&card->thread_mask_lock, flags);
906 card->thread_start_mask &= ~thread;
907 spin_unlock_irqrestore(&card->thread_mask_lock, flags);
908 wake_up(&card->wait_q);
909}
910
911static void
912qeth_clear_thread_running_bit(struct qeth_card *card, unsigned long thread)
913{
914 unsigned long flags;
915
916 spin_lock_irqsave(&card->thread_mask_lock, flags);
917 card->thread_running_mask &= ~thread;
918 spin_unlock_irqrestore(&card->thread_mask_lock, flags);
919 wake_up(&card->wait_q);
920}
921
922static inline int
923__qeth_do_run_thread(struct qeth_card *card, unsigned long thread)
924{
925 unsigned long flags;
926 int rc = 0;
927
928 spin_lock_irqsave(&card->thread_mask_lock, flags);
929 if (card->thread_start_mask & thread){
930 if ((card->thread_allowed_mask & thread) &&
931 !(card->thread_running_mask & thread)){
932 rc = 1;
933 card->thread_start_mask &= ~thread;
934 card->thread_running_mask |= thread;
935 } else
936 rc = -EPERM;
937 }
938 spin_unlock_irqrestore(&card->thread_mask_lock, flags);
939 return rc;
940}
941
942static int
943qeth_do_run_thread(struct qeth_card *card, unsigned long thread)
944{
945 int rc = 0;
946
947 wait_event(card->wait_q,
948 (rc = __qeth_do_run_thread(card, thread)) >= 0);
949 return rc;
950}
951
952static int
953qeth_register_ip_addresses(void *ptr)
954{
955 struct qeth_card *card;
956
957 card = (struct qeth_card *) ptr;
958 daemonize("qeth_reg_ip");
959 QETH_DBF_TEXT(trace,4,"regipth1");
960 if (!qeth_do_run_thread(card, QETH_SET_IP_THREAD))
961 return 0;
962 QETH_DBF_TEXT(trace,4,"regipth2");
963 qeth_set_ip_addr_list(card);
964 qeth_clear_thread_running_bit(card, QETH_SET_IP_THREAD);
965 return 0;
966}
967
Frank Pavlic6c951b92005-11-10 13:51:25 +0100968/*
969 * Drive the SET_PROMISC_MODE thread
970 */
971static int
972qeth_set_promisc_mode(void *ptr)
973{
974 struct qeth_card *card = (struct qeth_card *) ptr;
975
976 daemonize("qeth_setprm");
977 QETH_DBF_TEXT(trace,4,"setprm1");
978 if (!qeth_do_run_thread(card, QETH_SET_PROMISC_MODE_THREAD))
979 return 0;
980 QETH_DBF_TEXT(trace,4,"setprm2");
981 qeth_setadp_promisc_mode(card);
982 qeth_clear_thread_running_bit(card, QETH_SET_PROMISC_MODE_THREAD);
983 return 0;
984}
985
Linus Torvalds1da177e2005-04-16 15:20:36 -0700986static int
987qeth_recover(void *ptr)
988{
989 struct qeth_card *card;
990 int rc = 0;
991
992 card = (struct qeth_card *) ptr;
993 daemonize("qeth_recover");
994 QETH_DBF_TEXT(trace,2,"recover1");
995 QETH_DBF_HEX(trace, 2, &card, sizeof(void *));
996 if (!qeth_do_run_thread(card, QETH_RECOVER_THREAD))
997 return 0;
998 QETH_DBF_TEXT(trace,2,"recover2");
999 PRINT_WARN("Recovery of device %s started ...\n",
1000 CARD_BUS_ID(card));
1001 card->use_hard_stop = 1;
Frank Pavlic05e08a22005-05-12 20:39:09 +02001002 __qeth_set_offline(card->gdev,1);
1003 rc = __qeth_set_online(card->gdev,1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001004 if (!rc)
1005 PRINT_INFO("Device %s successfully recovered!\n",
1006 CARD_BUS_ID(card));
1007 else
1008 PRINT_INFO("Device %s could not be recovered!\n",
1009 CARD_BUS_ID(card));
1010 /* don't run another scheduled recovery */
1011 qeth_clear_thread_start_bit(card, QETH_RECOVER_THREAD);
1012 qeth_clear_thread_running_bit(card, QETH_RECOVER_THREAD);
1013 return 0;
1014}
1015
1016void
1017qeth_schedule_recovery(struct qeth_card *card)
1018{
1019 QETH_DBF_TEXT(trace,2,"startrec");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001020 if (qeth_set_thread_start_bit(card, QETH_RECOVER_THREAD) == 0)
1021 schedule_work(&card->kernel_thread_starter);
1022}
1023
1024static int
1025qeth_do_start_thread(struct qeth_card *card, unsigned long thread)
1026{
1027 unsigned long flags;
1028 int rc = 0;
1029
1030 spin_lock_irqsave(&card->thread_mask_lock, flags);
1031 QETH_DBF_TEXT_(trace, 4, " %02x%02x%02x",
1032 (u8) card->thread_start_mask,
1033 (u8) card->thread_allowed_mask,
1034 (u8) card->thread_running_mask);
1035 rc = (card->thread_start_mask & thread);
1036 spin_unlock_irqrestore(&card->thread_mask_lock, flags);
1037 return rc;
1038}
1039
1040static void
1041qeth_start_kernel_thread(struct qeth_card *card)
1042{
1043 QETH_DBF_TEXT(trace , 2, "strthrd");
1044
1045 if (card->read.state != CH_STATE_UP &&
1046 card->write.state != CH_STATE_UP)
1047 return;
1048
1049 if (qeth_do_start_thread(card, QETH_SET_IP_THREAD))
1050 kernel_thread(qeth_register_ip_addresses, (void *)card,SIGCHLD);
Frank Pavlic6c951b92005-11-10 13:51:25 +01001051 if (qeth_do_start_thread(card, QETH_SET_PROMISC_MODE_THREAD))
1052 kernel_thread(qeth_set_promisc_mode, (void *)card, SIGCHLD);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001053 if (qeth_do_start_thread(card, QETH_RECOVER_THREAD))
1054 kernel_thread(qeth_recover, (void *) card, SIGCHLD);
1055}
1056
1057
1058static void
1059qeth_set_intial_options(struct qeth_card *card)
1060{
1061 card->options.route4.type = NO_ROUTER;
1062#ifdef CONFIG_QETH_IPV6
1063 card->options.route6.type = NO_ROUTER;
1064#endif /* QETH_IPV6 */
1065 card->options.checksum_type = QETH_CHECKSUM_DEFAULT;
1066 card->options.broadcast_mode = QETH_TR_BROADCAST_ALLRINGS;
1067 card->options.macaddr_mode = QETH_TR_MACADDR_NONCANONICAL;
1068 card->options.fake_broadcast = 0;
1069 card->options.add_hhlen = DEFAULT_ADD_HHLEN;
1070 card->options.fake_ll = 0;
Ursula Braun500f83a2005-09-30 10:19:19 +02001071 if (card->info.type == QETH_CARD_TYPE_OSN)
1072 card->options.layer2 = 1;
1073 else
1074 card->options.layer2 = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001075}
1076
1077/**
1078 * initialize channels ,card and all state machines
1079 */
1080static int
1081qeth_setup_card(struct qeth_card *card)
1082{
1083
1084 QETH_DBF_TEXT(setup, 2, "setupcrd");
1085 QETH_DBF_HEX(setup, 2, &card, sizeof(void *));
1086
1087 card->read.state = CH_STATE_DOWN;
1088 card->write.state = CH_STATE_DOWN;
1089 card->data.state = CH_STATE_DOWN;
1090 card->state = CARD_STATE_DOWN;
1091 card->lan_online = 0;
1092 card->use_hard_stop = 0;
1093 card->dev = NULL;
1094#ifdef CONFIG_QETH_VLAN
1095 spin_lock_init(&card->vlanlock);
1096 card->vlangrp = NULL;
1097#endif
Ursula Braun9123e0d2005-09-30 10:17:24 +02001098 spin_lock_init(&card->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001099 spin_lock_init(&card->ip_lock);
1100 spin_lock_init(&card->thread_mask_lock);
1101 card->thread_start_mask = 0;
1102 card->thread_allowed_mask = 0;
1103 card->thread_running_mask = 0;
1104 INIT_WORK(&card->kernel_thread_starter,
1105 (void *)qeth_start_kernel_thread,card);
1106 INIT_LIST_HEAD(&card->ip_list);
1107 card->ip_tbd_list = kmalloc(sizeof(struct list_head), GFP_KERNEL);
1108 if (!card->ip_tbd_list) {
1109 QETH_DBF_TEXT(setup, 0, "iptbdnom");
1110 return -ENOMEM;
1111 }
1112 INIT_LIST_HEAD(card->ip_tbd_list);
1113 INIT_LIST_HEAD(&card->cmd_waiter_list);
1114 init_waitqueue_head(&card->wait_q);
1115 /* intial options */
1116 qeth_set_intial_options(card);
1117 /* IP address takeover */
1118 INIT_LIST_HEAD(&card->ipato.entries);
1119 card->ipato.enabled = 0;
1120 card->ipato.invert4 = 0;
1121 card->ipato.invert6 = 0;
1122 /* init QDIO stuff */
1123 qeth_init_qdio_info(card);
1124 return 0;
1125}
1126
1127static int
1128is_1920_device (struct qeth_card *card)
1129{
1130 int single_queue = 0;
1131 struct ccw_device *ccwdev;
1132 struct channelPath_dsc {
1133 u8 flags;
1134 u8 lsn;
1135 u8 desc;
1136 u8 chpid;
1137 u8 swla;
1138 u8 zeroes;
1139 u8 chla;
1140 u8 chpp;
1141 } *chp_dsc;
1142
1143 QETH_DBF_TEXT(setup, 2, "chk_1920");
1144
1145 ccwdev = card->data.ccwdev;
1146 chp_dsc = (struct channelPath_dsc *)ccw_device_get_chp_desc(ccwdev, 0);
1147 if (chp_dsc != NULL) {
1148 /* CHPP field bit 6 == 1 -> single queue */
1149 single_queue = ((chp_dsc->chpp & 0x02) == 0x02);
1150 kfree(chp_dsc);
1151 }
1152 QETH_DBF_TEXT_(setup, 2, "rc:%x", single_queue);
1153 return single_queue;
1154}
1155
1156static int
1157qeth_determine_card_type(struct qeth_card *card)
1158{
1159 int i = 0;
1160
1161 QETH_DBF_TEXT(setup, 2, "detcdtyp");
1162
Ursula Braun500f83a2005-09-30 10:19:19 +02001163 card->qdio.do_prio_queueing = QETH_PRIOQ_DEFAULT;
1164 card->qdio.default_out_queue = QETH_DEFAULT_QUEUE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001165 while (known_devices[i][4]) {
1166 if ((CARD_RDEV(card)->id.dev_type == known_devices[i][2]) &&
1167 (CARD_RDEV(card)->id.dev_model == known_devices[i][3])) {
1168 card->info.type = known_devices[i][4];
Ursula Braun500f83a2005-09-30 10:19:19 +02001169 card->qdio.no_out_queues = known_devices[i][8];
1170 card->info.is_multicast_different = known_devices[i][9];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001171 if (is_1920_device(card)) {
1172 PRINT_INFO("Priority Queueing not able "
1173 "due to hardware limitations!\n");
1174 card->qdio.no_out_queues = 1;
1175 card->qdio.default_out_queue = 0;
Jeff Garzike82b0f22006-05-26 21:58:38 -04001176 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001177 return 0;
1178 }
1179 i++;
1180 }
1181 card->info.type = QETH_CARD_TYPE_UNKNOWN;
1182 PRINT_ERR("unknown card type on device %s\n", CARD_BUS_ID(card));
1183 return -ENOENT;
1184}
1185
1186static int
1187qeth_probe_device(struct ccwgroup_device *gdev)
1188{
1189 struct qeth_card *card;
1190 struct device *dev;
1191 unsigned long flags;
1192 int rc;
1193
1194 QETH_DBF_TEXT(setup, 2, "probedev");
1195
1196 dev = &gdev->dev;
1197 if (!get_device(dev))
1198 return -ENODEV;
1199
Ursula Braun500f83a2005-09-30 10:19:19 +02001200 QETH_DBF_TEXT_(setup, 2, "%s", gdev->dev.bus_id);
Jeff Garzike82b0f22006-05-26 21:58:38 -04001201
Linus Torvalds1da177e2005-04-16 15:20:36 -07001202 card = qeth_alloc_card();
1203 if (!card) {
1204 put_device(dev);
1205 QETH_DBF_TEXT_(setup, 2, "1err%d", -ENOMEM);
1206 return -ENOMEM;
1207 }
1208 card->read.ccwdev = gdev->cdev[0];
1209 card->write.ccwdev = gdev->cdev[1];
1210 card->data.ccwdev = gdev->cdev[2];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001211 gdev->dev.driver_data = card;
1212 card->gdev = gdev;
1213 gdev->cdev[0]->handler = qeth_irq;
1214 gdev->cdev[1]->handler = qeth_irq;
1215 gdev->cdev[2]->handler = qeth_irq;
1216
Ursula Braun500f83a2005-09-30 10:19:19 +02001217 if ((rc = qeth_determine_card_type(card))){
1218 PRINT_WARN("%s: not a valid card type\n", __func__);
1219 QETH_DBF_TEXT_(setup, 2, "3err%d", rc);
1220 put_device(dev);
1221 qeth_free_card(card);
1222 return rc;
Jeff Garzike82b0f22006-05-26 21:58:38 -04001223 }
Ursula Braun500f83a2005-09-30 10:19:19 +02001224 if ((rc = qeth_setup_card(card))){
1225 QETH_DBF_TEXT_(setup, 2, "2err%d", rc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001226 put_device(dev);
1227 qeth_free_card(card);
1228 return rc;
1229 }
Ursula Braun500f83a2005-09-30 10:19:19 +02001230 rc = qeth_create_device_attributes(dev);
1231 if (rc) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001232 put_device(dev);
1233 qeth_free_card(card);
1234 return rc;
1235 }
1236 /* insert into our internal list */
1237 write_lock_irqsave(&qeth_card_list.rwlock, flags);
1238 list_add_tail(&card->list, &qeth_card_list.list);
1239 write_unlock_irqrestore(&qeth_card_list.rwlock, flags);
1240 return rc;
1241}
1242
1243
1244static int
1245qeth_get_unitaddr(struct qeth_card *card)
1246{
1247 int length;
1248 char *prcd;
1249 int rc;
1250
1251 QETH_DBF_TEXT(setup, 2, "getunit");
1252 rc = read_conf_data(CARD_DDEV(card), (void **) &prcd, &length);
1253 if (rc) {
1254 PRINT_ERR("read_conf_data for device %s returned %i\n",
1255 CARD_DDEV_ID(card), rc);
1256 return rc;
1257 }
1258 card->info.chpid = prcd[30];
1259 card->info.unit_addr2 = prcd[31];
1260 card->info.cula = prcd[63];
1261 card->info.guestlan = ((prcd[0x10] == _ascebc['V']) &&
1262 (prcd[0x11] == _ascebc['M']));
1263 return 0;
1264}
1265
1266static void
1267qeth_init_tokens(struct qeth_card *card)
1268{
1269 card->token.issuer_rm_w = 0x00010103UL;
1270 card->token.cm_filter_w = 0x00010108UL;
1271 card->token.cm_connection_w = 0x0001010aUL;
1272 card->token.ulp_filter_w = 0x0001010bUL;
1273 card->token.ulp_connection_w = 0x0001010dUL;
1274}
1275
1276static inline __u16
1277raw_devno_from_bus_id(char *id)
1278{
1279 id += (strlen(id) - 4);
1280 return (__u16) simple_strtoul(id, &id, 16);
1281}
1282/**
1283 * setup channel
1284 */
1285static void
1286qeth_setup_ccw(struct qeth_channel *channel,unsigned char *iob, __u32 len)
1287{
1288 struct qeth_card *card;
1289
1290 QETH_DBF_TEXT(trace, 4, "setupccw");
1291 card = CARD_FROM_CDEV(channel->ccwdev);
1292 if (channel == &card->read)
1293 memcpy(&channel->ccw, READ_CCW, sizeof(struct ccw1));
1294 else
1295 memcpy(&channel->ccw, WRITE_CCW, sizeof(struct ccw1));
1296 channel->ccw.count = len;
1297 channel->ccw.cda = (__u32) __pa(iob);
1298}
1299
1300/**
1301 * get free buffer for ccws (IDX activation, lancmds,ipassists...)
1302 */
1303static struct qeth_cmd_buffer *
1304__qeth_get_buffer(struct qeth_channel *channel)
1305{
1306 __u8 index;
1307
1308 QETH_DBF_TEXT(trace, 6, "getbuff");
1309 index = channel->io_buf_no;
1310 do {
1311 if (channel->iob[index].state == BUF_STATE_FREE) {
1312 channel->iob[index].state = BUF_STATE_LOCKED;
1313 channel->io_buf_no = (channel->io_buf_no + 1) %
1314 QETH_CMD_BUFFER_NO;
1315 memset(channel->iob[index].data, 0, QETH_BUFSIZE);
1316 return channel->iob + index;
1317 }
1318 index = (index + 1) % QETH_CMD_BUFFER_NO;
1319 } while(index != channel->io_buf_no);
1320
1321 return NULL;
1322}
1323
1324/**
1325 * release command buffer
1326 */
1327static void
1328qeth_release_buffer(struct qeth_channel *channel, struct qeth_cmd_buffer *iob)
1329{
1330 unsigned long flags;
1331
1332 QETH_DBF_TEXT(trace, 6, "relbuff");
1333 spin_lock_irqsave(&channel->iob_lock, flags);
1334 memset(iob->data, 0, QETH_BUFSIZE);
1335 iob->state = BUF_STATE_FREE;
1336 iob->callback = qeth_send_control_data_cb;
1337 iob->rc = 0;
1338 spin_unlock_irqrestore(&channel->iob_lock, flags);
1339}
1340
1341static struct qeth_cmd_buffer *
1342qeth_get_buffer(struct qeth_channel *channel)
1343{
1344 struct qeth_cmd_buffer *buffer = NULL;
1345 unsigned long flags;
1346
1347 spin_lock_irqsave(&channel->iob_lock, flags);
1348 buffer = __qeth_get_buffer(channel);
1349 spin_unlock_irqrestore(&channel->iob_lock, flags);
1350 return buffer;
1351}
1352
1353static struct qeth_cmd_buffer *
1354qeth_wait_for_buffer(struct qeth_channel *channel)
1355{
1356 struct qeth_cmd_buffer *buffer;
1357 wait_event(channel->wait_q,
1358 ((buffer = qeth_get_buffer(channel)) != NULL));
1359 return buffer;
1360}
1361
1362static void
1363qeth_clear_cmd_buffers(struct qeth_channel *channel)
1364{
Frank Pavlic1380fee2006-03-22 16:03:41 +01001365 int cnt;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001366
1367 for (cnt=0; cnt < QETH_CMD_BUFFER_NO; cnt++)
1368 qeth_release_buffer(channel,&channel->iob[cnt]);
1369 channel->buf_no = 0;
1370 channel->io_buf_no = 0;
1371}
1372
1373/**
1374 * start IDX for read and write channel
1375 */
1376static int
1377qeth_idx_activate_get_answer(struct qeth_channel *channel,
1378 void (*idx_reply_cb)(struct qeth_channel *,
1379 struct qeth_cmd_buffer *))
1380{
1381 struct qeth_cmd_buffer *iob;
1382 unsigned long flags;
1383 int rc;
1384 struct qeth_card *card;
1385
1386 QETH_DBF_TEXT(setup, 2, "idxanswr");
1387 card = CARD_FROM_CDEV(channel->ccwdev);
1388 iob = qeth_get_buffer(channel);
1389 iob->callback = idx_reply_cb;
1390 memcpy(&channel->ccw, READ_CCW, sizeof(struct ccw1));
1391 channel->ccw.count = QETH_BUFSIZE;
1392 channel->ccw.cda = (__u32) __pa(iob->data);
1393
1394 wait_event(card->wait_q,
Martin Schwidefsky973bd992006-01-06 00:19:07 -08001395 atomic_cmpxchg(&channel->irq_pending, 0, 1) == 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001396 QETH_DBF_TEXT(setup, 6, "noirqpnd");
1397 spin_lock_irqsave(get_ccwdev_lock(channel->ccwdev), flags);
1398 rc = ccw_device_start(channel->ccwdev,
1399 &channel->ccw,(addr_t) iob, 0, 0);
1400 spin_unlock_irqrestore(get_ccwdev_lock(channel->ccwdev), flags);
1401
1402 if (rc) {
1403 PRINT_ERR("qeth: Error2 in activating channel rc=%d\n",rc);
1404 QETH_DBF_TEXT_(setup, 2, "2err%d", rc);
1405 atomic_set(&channel->irq_pending, 0);
1406 wake_up(&card->wait_q);
1407 return rc;
1408 }
1409 rc = wait_event_interruptible_timeout(card->wait_q,
1410 channel->state == CH_STATE_UP, QETH_TIMEOUT);
1411 if (rc == -ERESTARTSYS)
1412 return rc;
1413 if (channel->state != CH_STATE_UP){
1414 rc = -ETIME;
1415 QETH_DBF_TEXT_(setup, 2, "3err%d", rc);
1416 qeth_clear_cmd_buffers(channel);
1417 } else
1418 rc = 0;
1419 return rc;
1420}
1421
1422static int
1423qeth_idx_activate_channel(struct qeth_channel *channel,
1424 void (*idx_reply_cb)(struct qeth_channel *,
1425 struct qeth_cmd_buffer *))
1426{
1427 struct qeth_card *card;
1428 struct qeth_cmd_buffer *iob;
1429 unsigned long flags;
1430 __u16 temp;
1431 int rc;
1432
1433 card = CARD_FROM_CDEV(channel->ccwdev);
1434
1435 QETH_DBF_TEXT(setup, 2, "idxactch");
1436
1437 iob = qeth_get_buffer(channel);
1438 iob->callback = idx_reply_cb;
1439 memcpy(&channel->ccw, WRITE_CCW, sizeof(struct ccw1));
1440 channel->ccw.count = IDX_ACTIVATE_SIZE;
1441 channel->ccw.cda = (__u32) __pa(iob->data);
1442 if (channel == &card->write) {
1443 memcpy(iob->data, IDX_ACTIVATE_WRITE, IDX_ACTIVATE_SIZE);
1444 memcpy(QETH_TRANSPORT_HEADER_SEQ_NO(iob->data),
1445 &card->seqno.trans_hdr, QETH_SEQ_NO_LENGTH);
1446 card->seqno.trans_hdr++;
1447 } else {
1448 memcpy(iob->data, IDX_ACTIVATE_READ, IDX_ACTIVATE_SIZE);
1449 memcpy(QETH_TRANSPORT_HEADER_SEQ_NO(iob->data),
1450 &card->seqno.trans_hdr, QETH_SEQ_NO_LENGTH);
1451 }
1452 memcpy(QETH_IDX_ACT_ISSUER_RM_TOKEN(iob->data),
1453 &card->token.issuer_rm_w,QETH_MPC_TOKEN_LENGTH);
1454 memcpy(QETH_IDX_ACT_FUNC_LEVEL(iob->data),
1455 &card->info.func_level,sizeof(__u16));
1456 temp = raw_devno_from_bus_id(CARD_DDEV_ID(card));
1457 memcpy(QETH_IDX_ACT_QDIO_DEV_CUA(iob->data), &temp, 2);
1458 temp = (card->info.cula << 8) + card->info.unit_addr2;
1459 memcpy(QETH_IDX_ACT_QDIO_DEV_REALADDR(iob->data), &temp, 2);
1460
1461 wait_event(card->wait_q,
Martin Schwidefsky973bd992006-01-06 00:19:07 -08001462 atomic_cmpxchg(&channel->irq_pending, 0, 1) == 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001463 QETH_DBF_TEXT(setup, 6, "noirqpnd");
1464 spin_lock_irqsave(get_ccwdev_lock(channel->ccwdev), flags);
1465 rc = ccw_device_start(channel->ccwdev,
1466 &channel->ccw,(addr_t) iob, 0, 0);
1467 spin_unlock_irqrestore(get_ccwdev_lock(channel->ccwdev), flags);
1468
1469 if (rc) {
1470 PRINT_ERR("qeth: Error1 in activating channel. rc=%d\n",rc);
1471 QETH_DBF_TEXT_(setup, 2, "1err%d", rc);
1472 atomic_set(&channel->irq_pending, 0);
1473 wake_up(&card->wait_q);
1474 return rc;
1475 }
1476 rc = wait_event_interruptible_timeout(card->wait_q,
1477 channel->state == CH_STATE_ACTIVATING, QETH_TIMEOUT);
1478 if (rc == -ERESTARTSYS)
1479 return rc;
1480 if (channel->state != CH_STATE_ACTIVATING) {
1481 PRINT_WARN("qeth: IDX activate timed out!\n");
1482 QETH_DBF_TEXT_(setup, 2, "2err%d", -ETIME);
1483 qeth_clear_cmd_buffers(channel);
1484 return -ETIME;
1485 }
1486 return qeth_idx_activate_get_answer(channel,idx_reply_cb);
1487}
1488
1489static int
1490qeth_peer_func_level(int level)
1491{
1492 if ((level & 0xff) == 8)
1493 return (level & 0xff) + 0x400;
1494 if (((level >> 8) & 3) == 1)
1495 return (level & 0xff) + 0x200;
1496 return level;
1497}
1498
1499static void
1500qeth_idx_write_cb(struct qeth_channel *channel, struct qeth_cmd_buffer *iob)
1501{
1502 struct qeth_card *card;
1503 __u16 temp;
1504
1505 QETH_DBF_TEXT(setup ,2, "idxwrcb");
1506
1507 if (channel->state == CH_STATE_DOWN) {
1508 channel->state = CH_STATE_ACTIVATING;
1509 goto out;
1510 }
1511 card = CARD_FROM_CDEV(channel->ccwdev);
1512
1513 if (!(QETH_IS_IDX_ACT_POS_REPLY(iob->data))) {
1514 PRINT_ERR("IDX_ACTIVATE on write channel device %s: negative "
1515 "reply\n", CARD_WDEV_ID(card));
1516 goto out;
1517 }
1518 memcpy(&temp, QETH_IDX_ACT_FUNC_LEVEL(iob->data), 2);
1519 if ((temp & ~0x0100) != qeth_peer_func_level(card->info.func_level)) {
1520 PRINT_WARN("IDX_ACTIVATE on write channel device %s: "
1521 "function level mismatch "
1522 "(sent: 0x%x, received: 0x%x)\n",
1523 CARD_WDEV_ID(card), card->info.func_level, temp);
1524 goto out;
1525 }
1526 channel->state = CH_STATE_UP;
1527out:
1528 qeth_release_buffer(channel, iob);
1529}
1530
1531static int
1532qeth_check_idx_response(unsigned char *buffer)
1533{
1534 if (!buffer)
1535 return 0;
1536
1537 QETH_DBF_HEX(control, 2, buffer, QETH_DBF_CONTROL_LEN);
1538 if ((buffer[2] & 0xc0) == 0xc0) {
1539 PRINT_WARN("received an IDX TERMINATE "
1540 "with cause code 0x%02x%s\n",
1541 buffer[4],
1542 ((buffer[4] == 0x22) ?
1543 " -- try another portname" : ""));
1544 QETH_DBF_TEXT(trace, 2, "ckidxres");
1545 QETH_DBF_TEXT(trace, 2, " idxterm");
1546 QETH_DBF_TEXT_(trace, 2, " rc%d", -EIO);
1547 return -EIO;
1548 }
1549 return 0;
1550}
1551
1552static void
1553qeth_idx_read_cb(struct qeth_channel *channel, struct qeth_cmd_buffer *iob)
1554{
1555 struct qeth_card *card;
1556 __u16 temp;
1557
1558 QETH_DBF_TEXT(setup , 2, "idxrdcb");
1559 if (channel->state == CH_STATE_DOWN) {
1560 channel->state = CH_STATE_ACTIVATING;
1561 goto out;
1562 }
1563
1564 card = CARD_FROM_CDEV(channel->ccwdev);
1565 if (qeth_check_idx_response(iob->data)) {
1566 goto out;
1567 }
1568 if (!(QETH_IS_IDX_ACT_POS_REPLY(iob->data))) {
1569 PRINT_ERR("IDX_ACTIVATE on read channel device %s: negative "
1570 "reply\n", CARD_RDEV_ID(card));
1571 goto out;
1572 }
1573
1574/**
1575 * temporary fix for microcode bug
1576 * to revert it,replace OR by AND
1577 */
1578 if ( (!QETH_IDX_NO_PORTNAME_REQUIRED(iob->data)) ||
1579 (card->info.type == QETH_CARD_TYPE_OSAE) )
1580 card->info.portname_required = 1;
1581
1582 memcpy(&temp, QETH_IDX_ACT_FUNC_LEVEL(iob->data), 2);
1583 if (temp != qeth_peer_func_level(card->info.func_level)) {
1584 PRINT_WARN("IDX_ACTIVATE on read channel device %s: function "
1585 "level mismatch (sent: 0x%x, received: 0x%x)\n",
1586 CARD_RDEV_ID(card), card->info.func_level, temp);
1587 goto out;
1588 }
1589 memcpy(&card->token.issuer_rm_r,
1590 QETH_IDX_ACT_ISSUER_RM_TOKEN(iob->data),
1591 QETH_MPC_TOKEN_LENGTH);
1592 memcpy(&card->info.mcl_level[0],
1593 QETH_IDX_REPLY_LEVEL(iob->data), QETH_MCL_LENGTH);
1594 channel->state = CH_STATE_UP;
1595out:
1596 qeth_release_buffer(channel,iob);
1597}
1598
1599static int
1600qeth_issue_next_read(struct qeth_card *card)
1601{
1602 int rc;
1603 struct qeth_cmd_buffer *iob;
1604
1605 QETH_DBF_TEXT(trace,5,"issnxrd");
1606 if (card->read.state != CH_STATE_UP)
1607 return -EIO;
1608 iob = qeth_get_buffer(&card->read);
1609 if (!iob) {
1610 PRINT_WARN("issue_next_read failed: no iob available!\n");
1611 return -ENOMEM;
1612 }
1613 qeth_setup_ccw(&card->read, iob->data, QETH_BUFSIZE);
1614 wait_event(card->wait_q,
Martin Schwidefsky973bd992006-01-06 00:19:07 -08001615 atomic_cmpxchg(&card->read.irq_pending, 0, 1) == 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001616 QETH_DBF_TEXT(trace, 6, "noirqpnd");
1617 rc = ccw_device_start(card->read.ccwdev, &card->read.ccw,
1618 (addr_t) iob, 0, 0);
1619 if (rc) {
1620 PRINT_ERR("Error in starting next read ccw! rc=%i\n", rc);
1621 atomic_set(&card->read.irq_pending, 0);
1622 qeth_schedule_recovery(card);
1623 wake_up(&card->wait_q);
1624 }
1625 return rc;
1626}
1627
1628static struct qeth_reply *
1629qeth_alloc_reply(struct qeth_card *card)
1630{
1631 struct qeth_reply *reply;
1632
Eric Sesterhenn88abaab2006-03-24 03:15:31 -08001633 reply = kzalloc(sizeof(struct qeth_reply), GFP_ATOMIC);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001634 if (reply){
Linus Torvalds1da177e2005-04-16 15:20:36 -07001635 atomic_set(&reply->refcnt, 1);
1636 reply->card = card;
1637 };
1638 return reply;
1639}
1640
1641static void
1642qeth_get_reply(struct qeth_reply *reply)
1643{
1644 WARN_ON(atomic_read(&reply->refcnt) <= 0);
1645 atomic_inc(&reply->refcnt);
1646}
1647
1648static void
1649qeth_put_reply(struct qeth_reply *reply)
1650{
1651 WARN_ON(atomic_read(&reply->refcnt) <= 0);
1652 if (atomic_dec_and_test(&reply->refcnt))
1653 kfree(reply);
1654}
1655
1656static void
1657qeth_cmd_timeout(unsigned long data)
1658{
1659 struct qeth_reply *reply, *list_reply, *r;
1660 unsigned long flags;
1661
1662 reply = (struct qeth_reply *) data;
1663 spin_lock_irqsave(&reply->card->lock, flags);
1664 list_for_each_entry_safe(list_reply, r,
1665 &reply->card->cmd_waiter_list, list) {
1666 if (reply == list_reply){
1667 qeth_get_reply(reply);
1668 list_del_init(&reply->list);
1669 spin_unlock_irqrestore(&reply->card->lock, flags);
1670 reply->rc = -ETIME;
1671 reply->received = 1;
1672 wake_up(&reply->wait_q);
1673 qeth_put_reply(reply);
1674 return;
1675 }
1676 }
1677 spin_unlock_irqrestore(&reply->card->lock, flags);
1678}
1679
Frank Pavlic66cc5d52006-02-07 17:04:38 +01001680
Linus Torvalds1da177e2005-04-16 15:20:36 -07001681static struct qeth_ipa_cmd *
1682qeth_check_ipa_data(struct qeth_card *card, struct qeth_cmd_buffer *iob)
1683{
1684 struct qeth_ipa_cmd *cmd = NULL;
1685
1686 QETH_DBF_TEXT(trace,5,"chkipad");
1687 if (IS_IPA(iob->data)){
1688 cmd = (struct qeth_ipa_cmd *) PDU_ENCAPSULATION(iob->data);
1689 if (IS_IPA_REPLY(cmd))
1690 return cmd;
1691 else {
1692 switch (cmd->hdr.command) {
1693 case IPA_CMD_STOPLAN:
1694 PRINT_WARN("Link failure on %s (CHPID 0x%X) - "
1695 "there is a network problem or "
1696 "someone pulled the cable or "
1697 "disabled the port.\n",
1698 QETH_CARD_IFNAME(card),
1699 card->info.chpid);
1700 card->lan_online = 0;
Frank Pavlic66cc5d52006-02-07 17:04:38 +01001701 if (card->dev && netif_carrier_ok(card->dev))
1702 netif_carrier_off(card->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001703 return NULL;
1704 case IPA_CMD_STARTLAN:
1705 PRINT_INFO("Link reestablished on %s "
1706 "(CHPID 0x%X). Scheduling "
1707 "IP address reset.\n",
1708 QETH_CARD_IFNAME(card),
1709 card->info.chpid);
Ursula Braun9123e0d2005-09-30 10:17:24 +02001710 qeth_schedule_recovery(card);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001711 return NULL;
Ursula Braun500f83a2005-09-30 10:19:19 +02001712 case IPA_CMD_MODCCID:
1713 return cmd;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001714 case IPA_CMD_REGISTER_LOCAL_ADDR:
1715 QETH_DBF_TEXT(trace,3, "irla");
1716 break;
1717 case IPA_CMD_UNREGISTER_LOCAL_ADDR:
1718 QETH_DBF_TEXT(trace,3, "urla");
1719 break;
1720 default:
1721 PRINT_WARN("Received data is IPA "
1722 "but not a reply!\n");
1723 break;
1724 }
1725 }
1726 }
1727 return cmd;
1728}
1729
1730/**
1731 * wake all waiting ipa commands
1732 */
1733static void
1734qeth_clear_ipacmd_list(struct qeth_card *card)
1735{
1736 struct qeth_reply *reply, *r;
1737 unsigned long flags;
1738
1739 QETH_DBF_TEXT(trace, 4, "clipalst");
1740
1741 spin_lock_irqsave(&card->lock, flags);
1742 list_for_each_entry_safe(reply, r, &card->cmd_waiter_list, list) {
1743 qeth_get_reply(reply);
1744 reply->rc = -EIO;
1745 reply->received = 1;
1746 list_del_init(&reply->list);
1747 wake_up(&reply->wait_q);
1748 qeth_put_reply(reply);
1749 }
1750 spin_unlock_irqrestore(&card->lock, flags);
1751}
1752
1753static void
1754qeth_send_control_data_cb(struct qeth_channel *channel,
1755 struct qeth_cmd_buffer *iob)
1756{
1757 struct qeth_card *card;
1758 struct qeth_reply *reply, *r;
1759 struct qeth_ipa_cmd *cmd;
1760 unsigned long flags;
1761 int keep_reply;
1762
1763 QETH_DBF_TEXT(trace,4,"sndctlcb");
1764
1765 card = CARD_FROM_CDEV(channel->ccwdev);
1766 if (qeth_check_idx_response(iob->data)) {
1767 qeth_clear_ipacmd_list(card);
1768 qeth_schedule_recovery(card);
1769 goto out;
1770 }
1771
1772 cmd = qeth_check_ipa_data(card, iob);
1773 if ((cmd == NULL) && (card->state != CARD_STATE_DOWN))
1774 goto out;
Ursula Braun500f83a2005-09-30 10:19:19 +02001775 /*in case of OSN : check if cmd is set */
1776 if (card->info.type == QETH_CARD_TYPE_OSN &&
1777 cmd &&
1778 cmd->hdr.command != IPA_CMD_STARTLAN &&
1779 card->osn_info.assist_cb != NULL) {
1780 card->osn_info.assist_cb(card->dev, cmd);
1781 goto out;
1782 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001783
1784 spin_lock_irqsave(&card->lock, flags);
1785 list_for_each_entry_safe(reply, r, &card->cmd_waiter_list, list) {
1786 if ((reply->seqno == QETH_IDX_COMMAND_SEQNO) ||
1787 ((cmd) && (reply->seqno == cmd->hdr.seqno))) {
1788 qeth_get_reply(reply);
1789 list_del_init(&reply->list);
1790 spin_unlock_irqrestore(&card->lock, flags);
1791 keep_reply = 0;
1792 if (reply->callback != NULL) {
1793 if (cmd) {
1794 reply->offset = (__u16)((char*)cmd -
1795 (char *)iob->data);
1796 keep_reply = reply->callback(card,
1797 reply,
1798 (unsigned long)cmd);
Ursula Braun500f83a2005-09-30 10:19:19 +02001799 } else
Linus Torvalds1da177e2005-04-16 15:20:36 -07001800 keep_reply = reply->callback(card,
1801 reply,
1802 (unsigned long)iob);
1803 }
1804 if (cmd)
1805 reply->rc = (u16) cmd->hdr.return_code;
1806 else if (iob->rc)
1807 reply->rc = iob->rc;
1808 if (keep_reply) {
1809 spin_lock_irqsave(&card->lock, flags);
1810 list_add_tail(&reply->list,
1811 &card->cmd_waiter_list);
1812 spin_unlock_irqrestore(&card->lock, flags);
1813 } else {
1814 reply->received = 1;
1815 wake_up(&reply->wait_q);
1816 }
1817 qeth_put_reply(reply);
1818 goto out;
1819 }
1820 }
1821 spin_unlock_irqrestore(&card->lock, flags);
1822out:
1823 memcpy(&card->seqno.pdu_hdr_ack,
1824 QETH_PDU_HEADER_SEQ_NO(iob->data),
1825 QETH_SEQ_NO_LENGTH);
1826 qeth_release_buffer(channel,iob);
1827}
1828
Ursula Braun500f83a2005-09-30 10:19:19 +02001829static inline void
1830qeth_prepare_control_data(struct qeth_card *card, int len,
1831struct qeth_cmd_buffer *iob)
1832{
1833 qeth_setup_ccw(&card->write,iob->data,len);
1834 iob->callback = qeth_release_buffer;
1835
1836 memcpy(QETH_TRANSPORT_HEADER_SEQ_NO(iob->data),
1837 &card->seqno.trans_hdr, QETH_SEQ_NO_LENGTH);
1838 card->seqno.trans_hdr++;
1839 memcpy(QETH_PDU_HEADER_SEQ_NO(iob->data),
1840 &card->seqno.pdu_hdr, QETH_SEQ_NO_LENGTH);
1841 card->seqno.pdu_hdr++;
1842 memcpy(QETH_PDU_HEADER_ACK_SEQ_NO(iob->data),
1843 &card->seqno.pdu_hdr_ack, QETH_SEQ_NO_LENGTH);
1844 QETH_DBF_HEX(control, 2, iob->data, QETH_DBF_CONTROL_LEN);
1845}
Jeff Garzike82b0f22006-05-26 21:58:38 -04001846
Linus Torvalds1da177e2005-04-16 15:20:36 -07001847static int
1848qeth_send_control_data(struct qeth_card *card, int len,
1849 struct qeth_cmd_buffer *iob,
1850 int (*reply_cb)
1851 (struct qeth_card *, struct qeth_reply*, unsigned long),
1852 void *reply_param)
1853
1854{
1855 int rc;
1856 unsigned long flags;
Ursula Braun500f83a2005-09-30 10:19:19 +02001857 struct qeth_reply *reply = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001858 struct timer_list timer;
1859
1860 QETH_DBF_TEXT(trace, 2, "sendctl");
1861
Linus Torvalds1da177e2005-04-16 15:20:36 -07001862 reply = qeth_alloc_reply(card);
1863 if (!reply) {
1864 PRINT_WARN("Could no alloc qeth_reply!\n");
1865 return -ENOMEM;
1866 }
1867 reply->callback = reply_cb;
1868 reply->param = reply_param;
1869 if (card->state == CARD_STATE_DOWN)
1870 reply->seqno = QETH_IDX_COMMAND_SEQNO;
1871 else
1872 reply->seqno = card->seqno.ipa++;
1873 init_timer(&timer);
1874 timer.function = qeth_cmd_timeout;
1875 timer.data = (unsigned long) reply;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001876 init_waitqueue_head(&reply->wait_q);
1877 spin_lock_irqsave(&card->lock, flags);
1878 list_add_tail(&reply->list, &card->cmd_waiter_list);
1879 spin_unlock_irqrestore(&card->lock, flags);
1880 QETH_DBF_HEX(control, 2, iob->data, QETH_DBF_CONTROL_LEN);
1881 wait_event(card->wait_q,
Martin Schwidefsky973bd992006-01-06 00:19:07 -08001882 atomic_cmpxchg(&card->write.irq_pending, 0, 1) == 0);
Ursula Braun500f83a2005-09-30 10:19:19 +02001883 qeth_prepare_control_data(card, len, iob);
1884 if (IS_IPA(iob->data))
1885 timer.expires = jiffies + QETH_IPA_TIMEOUT;
1886 else
1887 timer.expires = jiffies + QETH_TIMEOUT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001888 QETH_DBF_TEXT(trace, 6, "noirqpnd");
1889 spin_lock_irqsave(get_ccwdev_lock(card->write.ccwdev), flags);
1890 rc = ccw_device_start(card->write.ccwdev, &card->write.ccw,
1891 (addr_t) iob, 0, 0);
1892 spin_unlock_irqrestore(get_ccwdev_lock(card->write.ccwdev), flags);
1893 if (rc){
1894 PRINT_WARN("qeth_send_control_data: "
1895 "ccw_device_start rc = %i\n", rc);
1896 QETH_DBF_TEXT_(trace, 2, " err%d", rc);
1897 spin_lock_irqsave(&card->lock, flags);
1898 list_del_init(&reply->list);
1899 qeth_put_reply(reply);
1900 spin_unlock_irqrestore(&card->lock, flags);
1901 qeth_release_buffer(iob->channel, iob);
1902 atomic_set(&card->write.irq_pending, 0);
1903 wake_up(&card->wait_q);
1904 return rc;
1905 }
1906 add_timer(&timer);
1907 wait_event(reply->wait_q, reply->received);
1908 del_timer_sync(&timer);
1909 rc = reply->rc;
1910 qeth_put_reply(reply);
1911 return rc;
1912}
1913
1914static int
Ursula Braun500f83a2005-09-30 10:19:19 +02001915qeth_osn_send_control_data(struct qeth_card *card, int len,
1916 struct qeth_cmd_buffer *iob)
1917{
1918 unsigned long flags;
1919 int rc = 0;
1920
1921 QETH_DBF_TEXT(trace, 5, "osndctrd");
1922
1923 wait_event(card->wait_q,
Martin Schwidefsky973bd992006-01-06 00:19:07 -08001924 atomic_cmpxchg(&card->write.irq_pending, 0, 1) == 0);
Ursula Braun500f83a2005-09-30 10:19:19 +02001925 qeth_prepare_control_data(card, len, iob);
1926 QETH_DBF_TEXT(trace, 6, "osnoirqp");
1927 spin_lock_irqsave(get_ccwdev_lock(card->write.ccwdev), flags);
1928 rc = ccw_device_start(card->write.ccwdev, &card->write.ccw,
1929 (addr_t) iob, 0, 0);
1930 spin_unlock_irqrestore(get_ccwdev_lock(card->write.ccwdev), flags);
1931 if (rc){
1932 PRINT_WARN("qeth_osn_send_control_data: "
1933 "ccw_device_start rc = %i\n", rc);
1934 QETH_DBF_TEXT_(trace, 2, " err%d", rc);
1935 qeth_release_buffer(iob->channel, iob);
1936 atomic_set(&card->write.irq_pending, 0);
1937 wake_up(&card->wait_q);
1938 }
1939 return rc;
Jeff Garzike82b0f22006-05-26 21:58:38 -04001940}
Ursula Braun500f83a2005-09-30 10:19:19 +02001941
1942static inline void
1943qeth_prepare_ipa_cmd(struct qeth_card *card, struct qeth_cmd_buffer *iob,
1944 char prot_type)
1945{
1946 memcpy(iob->data, IPA_PDU_HEADER, IPA_PDU_HEADER_SIZE);
1947 memcpy(QETH_IPA_CMD_PROT_TYPE(iob->data),&prot_type,1);
1948 memcpy(QETH_IPA_CMD_DEST_ADDR(iob->data),
1949 &card->token.ulp_connection_r, QETH_MPC_TOKEN_LENGTH);
1950}
1951
1952static int
1953qeth_osn_send_ipa_cmd(struct qeth_card *card, struct qeth_cmd_buffer *iob,
1954 int data_len)
1955{
1956 u16 s1, s2;
1957
Frank Pavlic4965e972005-12-13 08:22:30 +01001958 QETH_DBF_TEXT(trace,4,"osndipa");
Ursula Braun500f83a2005-09-30 10:19:19 +02001959
1960 qeth_prepare_ipa_cmd(card, iob, QETH_PROT_OSN2);
1961 s1 = (u16)(IPA_PDU_HEADER_SIZE + data_len);
1962 s2 = (u16)data_len;
1963 memcpy(QETH_IPA_PDU_LEN_TOTAL(iob->data), &s1, 2);
1964 memcpy(QETH_IPA_PDU_LEN_PDU1(iob->data), &s2, 2);
1965 memcpy(QETH_IPA_PDU_LEN_PDU2(iob->data), &s2, 2);
1966 memcpy(QETH_IPA_PDU_LEN_PDU3(iob->data), &s2, 2);
1967 return qeth_osn_send_control_data(card, s1, iob);
1968}
Jeff Garzike82b0f22006-05-26 21:58:38 -04001969
Ursula Braun500f83a2005-09-30 10:19:19 +02001970static int
Linus Torvalds1da177e2005-04-16 15:20:36 -07001971qeth_send_ipa_cmd(struct qeth_card *card, struct qeth_cmd_buffer *iob,
1972 int (*reply_cb)
1973 (struct qeth_card *,struct qeth_reply*, unsigned long),
1974 void *reply_param)
1975{
1976 int rc;
1977 char prot_type;
1978
1979 QETH_DBF_TEXT(trace,4,"sendipa");
1980
Linus Torvalds1da177e2005-04-16 15:20:36 -07001981 if (card->options.layer2)
Ursula Braun500f83a2005-09-30 10:19:19 +02001982 if (card->info.type == QETH_CARD_TYPE_OSN)
1983 prot_type = QETH_PROT_OSN2;
1984 else
1985 prot_type = QETH_PROT_LAYER2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001986 else
1987 prot_type = QETH_PROT_TCPIP;
Ursula Braun500f83a2005-09-30 10:19:19 +02001988 qeth_prepare_ipa_cmd(card,iob,prot_type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001989 rc = qeth_send_control_data(card, IPA_CMD_LENGTH, iob,
1990 reply_cb, reply_param);
1991 return rc;
1992}
1993
1994
1995static int
1996qeth_cm_enable_cb(struct qeth_card *card, struct qeth_reply *reply,
1997 unsigned long data)
1998{
1999 struct qeth_cmd_buffer *iob;
2000
2001 QETH_DBF_TEXT(setup, 2, "cmenblcb");
2002
2003 iob = (struct qeth_cmd_buffer *) data;
2004 memcpy(&card->token.cm_filter_r,
2005 QETH_CM_ENABLE_RESP_FILTER_TOKEN(iob->data),
2006 QETH_MPC_TOKEN_LENGTH);
2007 QETH_DBF_TEXT_(setup, 2, " rc%d", iob->rc);
2008 return 0;
2009}
2010
2011static int
2012qeth_cm_enable(struct qeth_card *card)
2013{
2014 int rc;
2015 struct qeth_cmd_buffer *iob;
2016
2017 QETH_DBF_TEXT(setup,2,"cmenable");
2018
2019 iob = qeth_wait_for_buffer(&card->write);
2020 memcpy(iob->data, CM_ENABLE, CM_ENABLE_SIZE);
2021 memcpy(QETH_CM_ENABLE_ISSUER_RM_TOKEN(iob->data),
2022 &card->token.issuer_rm_r, QETH_MPC_TOKEN_LENGTH);
2023 memcpy(QETH_CM_ENABLE_FILTER_TOKEN(iob->data),
2024 &card->token.cm_filter_w, QETH_MPC_TOKEN_LENGTH);
2025
2026 rc = qeth_send_control_data(card, CM_ENABLE_SIZE, iob,
2027 qeth_cm_enable_cb, NULL);
2028 return rc;
2029}
2030
2031static int
2032qeth_cm_setup_cb(struct qeth_card *card, struct qeth_reply *reply,
2033 unsigned long data)
2034{
2035
2036 struct qeth_cmd_buffer *iob;
2037
2038 QETH_DBF_TEXT(setup, 2, "cmsetpcb");
2039
2040 iob = (struct qeth_cmd_buffer *) data;
2041 memcpy(&card->token.cm_connection_r,
2042 QETH_CM_SETUP_RESP_DEST_ADDR(iob->data),
2043 QETH_MPC_TOKEN_LENGTH);
2044 QETH_DBF_TEXT_(setup, 2, " rc%d", iob->rc);
2045 return 0;
2046}
2047
2048static int
2049qeth_cm_setup(struct qeth_card *card)
2050{
2051 int rc;
2052 struct qeth_cmd_buffer *iob;
2053
2054 QETH_DBF_TEXT(setup,2,"cmsetup");
2055
2056 iob = qeth_wait_for_buffer(&card->write);
2057 memcpy(iob->data, CM_SETUP, CM_SETUP_SIZE);
2058 memcpy(QETH_CM_SETUP_DEST_ADDR(iob->data),
2059 &card->token.issuer_rm_r, QETH_MPC_TOKEN_LENGTH);
2060 memcpy(QETH_CM_SETUP_CONNECTION_TOKEN(iob->data),
2061 &card->token.cm_connection_w, QETH_MPC_TOKEN_LENGTH);
2062 memcpy(QETH_CM_SETUP_FILTER_TOKEN(iob->data),
2063 &card->token.cm_filter_r, QETH_MPC_TOKEN_LENGTH);
2064 rc = qeth_send_control_data(card, CM_SETUP_SIZE, iob,
2065 qeth_cm_setup_cb, NULL);
2066 return rc;
2067
2068}
2069
2070static int
2071qeth_ulp_enable_cb(struct qeth_card *card, struct qeth_reply *reply,
2072 unsigned long data)
2073{
2074
2075 __u16 mtu, framesize;
2076 __u16 len;
2077 __u8 link_type;
2078 struct qeth_cmd_buffer *iob;
2079
2080 QETH_DBF_TEXT(setup, 2, "ulpenacb");
2081
2082 iob = (struct qeth_cmd_buffer *) data;
2083 memcpy(&card->token.ulp_filter_r,
2084 QETH_ULP_ENABLE_RESP_FILTER_TOKEN(iob->data),
2085 QETH_MPC_TOKEN_LENGTH);
2086 if (qeth_get_mtu_out_of_mpc(card->info.type)) {
2087 memcpy(&framesize, QETH_ULP_ENABLE_RESP_MAX_MTU(iob->data), 2);
2088 mtu = qeth_get_mtu_outof_framesize(framesize);
2089 if (!mtu) {
2090 iob->rc = -EINVAL;
2091 QETH_DBF_TEXT_(setup, 2, " rc%d", iob->rc);
2092 return 0;
2093 }
2094 card->info.max_mtu = mtu;
2095 card->info.initial_mtu = mtu;
2096 card->qdio.in_buf_size = mtu + 2 * PAGE_SIZE;
2097 } else {
2098 card->info.initial_mtu = qeth_get_initial_mtu_for_card(card);
2099 card->info.max_mtu = qeth_get_max_mtu_for_card(card->info.type);
2100 card->qdio.in_buf_size = QETH_IN_BUF_SIZE_DEFAULT;
2101 }
2102
2103 memcpy(&len, QETH_ULP_ENABLE_RESP_DIFINFO_LEN(iob->data), 2);
2104 if (len >= QETH_MPC_DIFINFO_LEN_INDICATES_LINK_TYPE) {
2105 memcpy(&link_type,
2106 QETH_ULP_ENABLE_RESP_LINK_TYPE(iob->data), 1);
2107 card->info.link_type = link_type;
2108 } else
2109 card->info.link_type = 0;
2110 QETH_DBF_TEXT_(setup, 2, " rc%d", iob->rc);
2111 return 0;
2112}
2113
2114static int
2115qeth_ulp_enable(struct qeth_card *card)
2116{
2117 int rc;
2118 char prot_type;
2119 struct qeth_cmd_buffer *iob;
2120
2121 /*FIXME: trace view callbacks*/
2122 QETH_DBF_TEXT(setup,2,"ulpenabl");
2123
2124 iob = qeth_wait_for_buffer(&card->write);
2125 memcpy(iob->data, ULP_ENABLE, ULP_ENABLE_SIZE);
2126
2127 *(QETH_ULP_ENABLE_LINKNUM(iob->data)) =
2128 (__u8) card->info.portno;
2129 if (card->options.layer2)
Ursula Braun500f83a2005-09-30 10:19:19 +02002130 if (card->info.type == QETH_CARD_TYPE_OSN)
2131 prot_type = QETH_PROT_OSN2;
2132 else
2133 prot_type = QETH_PROT_LAYER2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002134 else
2135 prot_type = QETH_PROT_TCPIP;
2136
2137 memcpy(QETH_ULP_ENABLE_PROT_TYPE(iob->data),&prot_type,1);
2138 memcpy(QETH_ULP_ENABLE_DEST_ADDR(iob->data),
2139 &card->token.cm_connection_r, QETH_MPC_TOKEN_LENGTH);
2140 memcpy(QETH_ULP_ENABLE_FILTER_TOKEN(iob->data),
2141 &card->token.ulp_filter_w, QETH_MPC_TOKEN_LENGTH);
2142 memcpy(QETH_ULP_ENABLE_PORTNAME_AND_LL(iob->data),
2143 card->info.portname, 9);
2144 rc = qeth_send_control_data(card, ULP_ENABLE_SIZE, iob,
2145 qeth_ulp_enable_cb, NULL);
2146 return rc;
2147
2148}
2149
2150static inline __u16
2151__raw_devno_from_bus_id(char *id)
2152{
2153 id += (strlen(id) - 4);
2154 return (__u16) simple_strtoul(id, &id, 16);
2155}
2156
2157static int
2158qeth_ulp_setup_cb(struct qeth_card *card, struct qeth_reply *reply,
2159 unsigned long data)
2160{
2161 struct qeth_cmd_buffer *iob;
2162
2163 QETH_DBF_TEXT(setup, 2, "ulpstpcb");
2164
2165 iob = (struct qeth_cmd_buffer *) data;
2166 memcpy(&card->token.ulp_connection_r,
2167 QETH_ULP_SETUP_RESP_CONNECTION_TOKEN(iob->data),
2168 QETH_MPC_TOKEN_LENGTH);
2169 QETH_DBF_TEXT_(setup, 2, " rc%d", iob->rc);
2170 return 0;
2171}
2172
2173static int
2174qeth_ulp_setup(struct qeth_card *card)
2175{
2176 int rc;
2177 __u16 temp;
2178 struct qeth_cmd_buffer *iob;
2179
2180 QETH_DBF_TEXT(setup,2,"ulpsetup");
2181
2182 iob = qeth_wait_for_buffer(&card->write);
2183 memcpy(iob->data, ULP_SETUP, ULP_SETUP_SIZE);
2184
2185 memcpy(QETH_ULP_SETUP_DEST_ADDR(iob->data),
2186 &card->token.cm_connection_r, QETH_MPC_TOKEN_LENGTH);
2187 memcpy(QETH_ULP_SETUP_CONNECTION_TOKEN(iob->data),
2188 &card->token.ulp_connection_w, QETH_MPC_TOKEN_LENGTH);
2189 memcpy(QETH_ULP_SETUP_FILTER_TOKEN(iob->data),
2190 &card->token.ulp_filter_r, QETH_MPC_TOKEN_LENGTH);
2191
2192 temp = __raw_devno_from_bus_id(CARD_DDEV_ID(card));
2193 memcpy(QETH_ULP_SETUP_CUA(iob->data), &temp, 2);
2194 temp = (card->info.cula << 8) + card->info.unit_addr2;
2195 memcpy(QETH_ULP_SETUP_REAL_DEVADDR(iob->data), &temp, 2);
2196 rc = qeth_send_control_data(card, ULP_SETUP_SIZE, iob,
2197 qeth_ulp_setup_cb, NULL);
2198 return rc;
2199}
2200
2201static inline int
Frank Pavlic6c6b3e72005-12-13 08:21:47 +01002202qeth_check_qdio_errors(struct qdio_buffer *buf, unsigned int qdio_error,
2203 unsigned int siga_error, const char *dbftext)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002204{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002205 if (qdio_error || siga_error) {
Frank Pavlic6c6b3e72005-12-13 08:21:47 +01002206 QETH_DBF_TEXT(trace, 2, dbftext);
2207 QETH_DBF_TEXT(qerr, 2, dbftext);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002208 QETH_DBF_TEXT_(qerr, 2, " F15=%02X",
Frank Pavlic6c6b3e72005-12-13 08:21:47 +01002209 buf->element[15].flags & 0xff);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002210 QETH_DBF_TEXT_(qerr, 2, " F14=%02X",
Frank Pavlic6c6b3e72005-12-13 08:21:47 +01002211 buf->element[14].flags & 0xff);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002212 QETH_DBF_TEXT_(qerr, 2, " qerr=%X", qdio_error);
2213 QETH_DBF_TEXT_(qerr, 2, " serr=%X", siga_error);
Frank Pavlic6c6b3e72005-12-13 08:21:47 +01002214 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002215 }
Frank Pavlic6c6b3e72005-12-13 08:21:47 +01002216 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002217}
2218
2219static inline struct sk_buff *
Ursula Braun500f83a2005-09-30 10:19:19 +02002220qeth_get_skb(unsigned int length, struct qeth_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002221{
2222 struct sk_buff* skb;
Ursula Braun500f83a2005-09-30 10:19:19 +02002223 int add_len;
2224
2225 add_len = 0;
2226 if (hdr->hdr.osn.id == QETH_HEADER_TYPE_OSN)
2227 add_len = sizeof(struct qeth_hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002228#ifdef CONFIG_QETH_VLAN
Ursula Braun500f83a2005-09-30 10:19:19 +02002229 else
2230 add_len = VLAN_HLEN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002231#endif
Ursula Braun500f83a2005-09-30 10:19:19 +02002232 skb = dev_alloc_skb(length + add_len);
2233 if (skb && add_len)
2234 skb_reserve(skb, add_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002235 return skb;
2236}
2237
2238static inline struct sk_buff *
2239qeth_get_next_skb(struct qeth_card *card, struct qdio_buffer *buffer,
2240 struct qdio_buffer_element **__element, int *__offset,
2241 struct qeth_hdr **hdr)
2242{
2243 struct qdio_buffer_element *element = *__element;
2244 int offset = *__offset;
2245 struct sk_buff *skb = NULL;
2246 int skb_len;
2247 void *data_ptr;
2248 int data_len;
2249
2250 QETH_DBF_TEXT(trace,6,"nextskb");
2251 /* qeth_hdr must not cross element boundaries */
2252 if (element->length < offset + sizeof(struct qeth_hdr)){
2253 if (qeth_is_last_sbale(element))
2254 return NULL;
2255 element++;
2256 offset = 0;
2257 if (element->length < sizeof(struct qeth_hdr))
2258 return NULL;
2259 }
2260 *hdr = element->addr + offset;
2261
2262 offset += sizeof(struct qeth_hdr);
2263 if (card->options.layer2)
Ursula Braun500f83a2005-09-30 10:19:19 +02002264 if (card->info.type == QETH_CARD_TYPE_OSN)
2265 skb_len = (*hdr)->hdr.osn.pdu_length;
2266 else
2267 skb_len = (*hdr)->hdr.l2.pkt_length;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002268 else
2269 skb_len = (*hdr)->hdr.l3.length;
2270
2271 if (!skb_len)
2272 return NULL;
2273 if (card->options.fake_ll){
Frank Pavlice23dd9c2005-05-12 20:38:11 +02002274 if(card->dev->type == ARPHRD_IEEE802_TR){
Ursula Braun500f83a2005-09-30 10:19:19 +02002275 if (!(skb = qeth_get_skb(skb_len+QETH_FAKE_LL_LEN_TR, *hdr)))
Frank Pavlice23dd9c2005-05-12 20:38:11 +02002276 goto no_mem;
2277 skb_reserve(skb,QETH_FAKE_LL_LEN_TR);
2278 } else {
Ursula Braun500f83a2005-09-30 10:19:19 +02002279 if (!(skb = qeth_get_skb(skb_len+QETH_FAKE_LL_LEN_ETH, *hdr)))
Frank Pavlice23dd9c2005-05-12 20:38:11 +02002280 goto no_mem;
2281 skb_reserve(skb,QETH_FAKE_LL_LEN_ETH);
2282 }
Ursula Braun500f83a2005-09-30 10:19:19 +02002283 } else if (!(skb = qeth_get_skb(skb_len, *hdr)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002284 goto no_mem;
2285 data_ptr = element->addr + offset;
2286 while (skb_len) {
2287 data_len = min(skb_len, (int)(element->length - offset));
2288 if (data_len)
2289 memcpy(skb_put(skb, data_len), data_ptr, data_len);
2290 skb_len -= data_len;
2291 if (skb_len){
2292 if (qeth_is_last_sbale(element)){
2293 QETH_DBF_TEXT(trace,4,"unexeob");
2294 QETH_DBF_TEXT_(trace,4,"%s",CARD_BUS_ID(card));
2295 QETH_DBF_TEXT(qerr,2,"unexeob");
2296 QETH_DBF_TEXT_(qerr,2,"%s",CARD_BUS_ID(card));
2297 QETH_DBF_HEX(misc,4,buffer,sizeof(*buffer));
2298 dev_kfree_skb_any(skb);
2299 card->stats.rx_errors++;
2300 return NULL;
2301 }
2302 element++;
2303 offset = 0;
2304 data_ptr = element->addr;
2305 } else {
2306 offset += data_len;
2307 }
2308 }
2309 *__element = element;
2310 *__offset = offset;
2311 return skb;
2312no_mem:
2313 if (net_ratelimit()){
2314 PRINT_WARN("No memory for packet received on %s.\n",
2315 QETH_CARD_IFNAME(card));
2316 QETH_DBF_TEXT(trace,2,"noskbmem");
2317 QETH_DBF_TEXT_(trace,2,"%s",CARD_BUS_ID(card));
2318 }
2319 card->stats.rx_dropped++;
2320 return NULL;
2321}
2322
Alexey Dobriyanab611482005-07-12 12:08:43 -07002323static inline __be16
Linus Torvalds1da177e2005-04-16 15:20:36 -07002324qeth_type_trans(struct sk_buff *skb, struct net_device *dev)
2325{
2326 struct qeth_card *card;
2327 struct ethhdr *eth;
2328
2329 QETH_DBF_TEXT(trace,6,"typtrans");
2330
2331 card = (struct qeth_card *)dev->priv;
2332#ifdef CONFIG_TR
2333 if ((card->info.link_type == QETH_LINK_TYPE_HSTR) ||
2334 (card->info.link_type == QETH_LINK_TYPE_LANE_TR))
2335 return tr_type_trans(skb,dev);
2336#endif /* CONFIG_TR */
2337 skb->mac.raw = skb->data;
2338 skb_pull(skb, ETH_HLEN );
2339 eth = eth_hdr(skb);
2340
2341 if (*eth->h_dest & 1) {
2342 if (memcmp(eth->h_dest, dev->broadcast, ETH_ALEN) == 0)
2343 skb->pkt_type = PACKET_BROADCAST;
2344 else
2345 skb->pkt_type = PACKET_MULTICAST;
2346 } else if (memcmp(eth->h_dest, dev->dev_addr, ETH_ALEN))
2347 skb->pkt_type = PACKET_OTHERHOST;
2348
2349 if (ntohs(eth->h_proto) >= 1536)
2350 return eth->h_proto;
2351 if (*(unsigned short *) (skb->data) == 0xFFFF)
2352 return htons(ETH_P_802_3);
2353 return htons(ETH_P_802_2);
2354}
2355
2356static inline void
Frank Pavlice23dd9c2005-05-12 20:38:11 +02002357qeth_rebuild_skb_fake_ll_tr(struct qeth_card *card, struct sk_buff *skb,
2358 struct qeth_hdr *hdr)
2359{
2360 struct trh_hdr *fake_hdr;
2361 struct trllc *fake_llc;
2362 struct iphdr *ip_hdr;
2363
2364 QETH_DBF_TEXT(trace,5,"skbfktr");
2365 skb->mac.raw = skb->data - QETH_FAKE_LL_LEN_TR;
2366 /* this is a fake ethernet header */
2367 fake_hdr = (struct trh_hdr *) skb->mac.raw;
2368
2369 /* the destination MAC address */
2370 switch (skb->pkt_type){
2371 case PACKET_MULTICAST:
2372 switch (skb->protocol){
2373#ifdef CONFIG_QETH_IPV6
2374 case __constant_htons(ETH_P_IPV6):
2375 ndisc_mc_map((struct in6_addr *)
2376 skb->data + QETH_FAKE_LL_V6_ADDR_POS,
2377 fake_hdr->daddr, card->dev, 0);
2378 break;
2379#endif /* CONFIG_QETH_IPV6 */
2380 case __constant_htons(ETH_P_IP):
2381 ip_hdr = (struct iphdr *)skb->data;
2382 ip_tr_mc_map(ip_hdr->daddr, fake_hdr->daddr);
2383 break;
2384 default:
2385 memcpy(fake_hdr->daddr, card->dev->dev_addr, TR_ALEN);
2386 }
2387 break;
2388 case PACKET_BROADCAST:
2389 memset(fake_hdr->daddr, 0xff, TR_ALEN);
2390 break;
2391 default:
2392 memcpy(fake_hdr->daddr, card->dev->dev_addr, TR_ALEN);
2393 }
2394 /* the source MAC address */
2395 if (hdr->hdr.l3.ext_flags & QETH_HDR_EXT_SRC_MAC_ADDR)
2396 memcpy(fake_hdr->saddr, &hdr->hdr.l3.dest_addr[2], TR_ALEN);
2397 else
2398 memset(fake_hdr->saddr, 0, TR_ALEN);
2399 fake_hdr->rcf=0;
2400 fake_llc = (struct trllc*)&(fake_hdr->rcf);
2401 fake_llc->dsap = EXTENDED_SAP;
2402 fake_llc->ssap = EXTENDED_SAP;
2403 fake_llc->llc = UI_CMD;
2404 fake_llc->protid[0] = 0;
2405 fake_llc->protid[1] = 0;
2406 fake_llc->protid[2] = 0;
2407 fake_llc->ethertype = ETH_P_IP;
2408}
2409
2410static inline void
2411qeth_rebuild_skb_fake_ll_eth(struct qeth_card *card, struct sk_buff *skb,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002412 struct qeth_hdr *hdr)
2413{
2414 struct ethhdr *fake_hdr;
2415 struct iphdr *ip_hdr;
2416
Frank Pavlice23dd9c2005-05-12 20:38:11 +02002417 QETH_DBF_TEXT(trace,5,"skbfketh");
2418 skb->mac.raw = skb->data - QETH_FAKE_LL_LEN_ETH;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002419 /* this is a fake ethernet header */
2420 fake_hdr = (struct ethhdr *) skb->mac.raw;
2421
2422 /* the destination MAC address */
2423 switch (skb->pkt_type){
2424 case PACKET_MULTICAST:
2425 switch (skb->protocol){
2426#ifdef CONFIG_QETH_IPV6
2427 case __constant_htons(ETH_P_IPV6):
2428 ndisc_mc_map((struct in6_addr *)
2429 skb->data + QETH_FAKE_LL_V6_ADDR_POS,
2430 fake_hdr->h_dest, card->dev, 0);
2431 break;
2432#endif /* CONFIG_QETH_IPV6 */
2433 case __constant_htons(ETH_P_IP):
2434 ip_hdr = (struct iphdr *)skb->data;
Frank Pavlice23dd9c2005-05-12 20:38:11 +02002435 ip_eth_mc_map(ip_hdr->daddr, fake_hdr->h_dest);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002436 break;
2437 default:
2438 memcpy(fake_hdr->h_dest, card->dev->dev_addr, ETH_ALEN);
2439 }
2440 break;
2441 case PACKET_BROADCAST:
2442 memset(fake_hdr->h_dest, 0xff, ETH_ALEN);
2443 break;
2444 default:
2445 memcpy(fake_hdr->h_dest, card->dev->dev_addr, ETH_ALEN);
2446 }
2447 /* the source MAC address */
2448 if (hdr->hdr.l3.ext_flags & QETH_HDR_EXT_SRC_MAC_ADDR)
2449 memcpy(fake_hdr->h_source, &hdr->hdr.l3.dest_addr[2], ETH_ALEN);
2450 else
2451 memset(fake_hdr->h_source, 0, ETH_ALEN);
2452 /* the protocol */
2453 fake_hdr->h_proto = skb->protocol;
2454}
2455
2456static inline void
Frank Pavlice23dd9c2005-05-12 20:38:11 +02002457qeth_rebuild_skb_fake_ll(struct qeth_card *card, struct sk_buff *skb,
2458 struct qeth_hdr *hdr)
2459{
2460 if (card->dev->type == ARPHRD_IEEE802_TR)
2461 qeth_rebuild_skb_fake_ll_tr(card, skb, hdr);
2462 else
2463 qeth_rebuild_skb_fake_ll_eth(card, skb, hdr);
2464}
2465
2466static inline void
Linus Torvalds1da177e2005-04-16 15:20:36 -07002467qeth_rebuild_skb_vlan(struct qeth_card *card, struct sk_buff *skb,
2468 struct qeth_hdr *hdr)
2469{
2470#ifdef CONFIG_QETH_VLAN
2471 u16 *vlan_tag;
2472
2473 if (hdr->hdr.l3.ext_flags &
2474 (QETH_HDR_EXT_VLAN_FRAME | QETH_HDR_EXT_INCLUDE_VLAN_TAG)) {
2475 vlan_tag = (u16 *) skb_push(skb, VLAN_HLEN);
2476 *vlan_tag = (hdr->hdr.l3.ext_flags & QETH_HDR_EXT_VLAN_FRAME)?
2477 hdr->hdr.l3.vlan_id : *((u16 *)&hdr->hdr.l3.dest_addr[12]);
2478 *(vlan_tag + 1) = skb->protocol;
2479 skb->protocol = __constant_htons(ETH_P_8021Q);
2480 }
2481#endif /* CONFIG_QETH_VLAN */
2482}
2483
2484static inline __u16
2485qeth_layer2_rebuild_skb(struct qeth_card *card, struct sk_buff *skb,
2486 struct qeth_hdr *hdr)
2487{
2488 unsigned short vlan_id = 0;
2489#ifdef CONFIG_QETH_VLAN
2490 struct vlan_hdr *vhdr;
2491#endif
2492
2493 skb->pkt_type = PACKET_HOST;
2494 skb->protocol = qeth_type_trans(skb, skb->dev);
2495 if (card->options.checksum_type == NO_CHECKSUMMING)
2496 skb->ip_summed = CHECKSUM_UNNECESSARY;
2497 else
2498 skb->ip_summed = CHECKSUM_NONE;
2499#ifdef CONFIG_QETH_VLAN
2500 if (hdr->hdr.l2.flags[2] & (QETH_LAYER2_FLAG_VLAN)) {
2501 vhdr = (struct vlan_hdr *) skb->data;
2502 skb->protocol =
2503 __constant_htons(vhdr->h_vlan_encapsulated_proto);
2504 vlan_id = hdr->hdr.l2.vlan_id;
2505 skb_pull(skb, VLAN_HLEN);
2506 }
2507#endif
Ursula Braun9123e0d2005-09-30 10:17:24 +02002508 *((__u32 *)skb->cb) = ++card->seqno.pkt_seqno;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002509 return vlan_id;
2510}
2511
2512static inline void
2513qeth_rebuild_skb(struct qeth_card *card, struct sk_buff *skb,
2514 struct qeth_hdr *hdr)
2515{
2516#ifdef CONFIG_QETH_IPV6
2517 if (hdr->hdr.l3.flags & QETH_HDR_PASSTHRU) {
2518 skb->pkt_type = PACKET_HOST;
2519 skb->protocol = qeth_type_trans(skb, card->dev);
2520 return;
2521 }
2522#endif /* CONFIG_QETH_IPV6 */
2523 skb->protocol = htons((hdr->hdr.l3.flags & QETH_HDR_IPV6)? ETH_P_IPV6 :
2524 ETH_P_IP);
2525 switch (hdr->hdr.l3.flags & QETH_HDR_CAST_MASK){
2526 case QETH_CAST_UNICAST:
2527 skb->pkt_type = PACKET_HOST;
2528 break;
2529 case QETH_CAST_MULTICAST:
2530 skb->pkt_type = PACKET_MULTICAST;
2531 card->stats.multicast++;
2532 break;
2533 case QETH_CAST_BROADCAST:
2534 skb->pkt_type = PACKET_BROADCAST;
2535 card->stats.multicast++;
2536 break;
2537 case QETH_CAST_ANYCAST:
2538 case QETH_CAST_NOCAST:
2539 default:
2540 skb->pkt_type = PACKET_HOST;
2541 }
2542 qeth_rebuild_skb_vlan(card, skb, hdr);
2543 if (card->options.fake_ll)
2544 qeth_rebuild_skb_fake_ll(card, skb, hdr);
2545 else
2546 skb->mac.raw = skb->data;
2547 skb->ip_summed = card->options.checksum_type;
2548 if (card->options.checksum_type == HW_CHECKSUMMING){
2549 if ( (hdr->hdr.l3.ext_flags &
2550 (QETH_HDR_EXT_CSUM_HDR_REQ |
2551 QETH_HDR_EXT_CSUM_TRANSP_REQ)) ==
2552 (QETH_HDR_EXT_CSUM_HDR_REQ |
2553 QETH_HDR_EXT_CSUM_TRANSP_REQ) )
2554 skb->ip_summed = CHECKSUM_UNNECESSARY;
2555 else
2556 skb->ip_summed = SW_CHECKSUMMING;
2557 }
2558}
2559
2560static inline void
2561qeth_process_inbound_buffer(struct qeth_card *card,
2562 struct qeth_qdio_buffer *buf, int index)
2563{
2564 struct qdio_buffer_element *element;
2565 struct sk_buff *skb;
2566 struct qeth_hdr *hdr;
2567 int offset;
2568 int rxrc;
2569 __u16 vlan_tag = 0;
2570
2571 /* get first element of current buffer */
2572 element = (struct qdio_buffer_element *)&buf->buffer->element[0];
2573 offset = 0;
2574#ifdef CONFIG_QETH_PERF_STATS
2575 card->perf_stats.bufs_rec++;
2576#endif
2577 while((skb = qeth_get_next_skb(card, buf->buffer, &element,
2578 &offset, &hdr))) {
2579 skb->dev = card->dev;
2580 if (hdr->hdr.l2.id == QETH_HEADER_TYPE_LAYER2)
2581 vlan_tag = qeth_layer2_rebuild_skb(card, skb, hdr);
Jeff Garzike82b0f22006-05-26 21:58:38 -04002582 else if (hdr->hdr.l3.id == QETH_HEADER_TYPE_LAYER3)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002583 qeth_rebuild_skb(card, skb, hdr);
Ursula Braun500f83a2005-09-30 10:19:19 +02002584 else { /*in case of OSN*/
2585 skb_push(skb, sizeof(struct qeth_hdr));
2586 memcpy(skb->data, hdr, sizeof(struct qeth_hdr));
2587 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002588 /* is device UP ? */
2589 if (!(card->dev->flags & IFF_UP)){
2590 dev_kfree_skb_any(skb);
2591 continue;
2592 }
2593#ifdef CONFIG_QETH_VLAN
2594 if (vlan_tag)
2595 vlan_hwaccel_rx(skb, card->vlangrp, vlan_tag);
2596 else
2597#endif
Ursula Braun500f83a2005-09-30 10:19:19 +02002598 if (card->info.type == QETH_CARD_TYPE_OSN)
2599 rxrc = card->osn_info.data_cb(skb);
2600 else
2601 rxrc = netif_rx(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002602 card->dev->last_rx = jiffies;
2603 card->stats.rx_packets++;
2604 card->stats.rx_bytes += skb->len;
2605 }
2606}
2607
2608static inline struct qeth_buffer_pool_entry *
2609qeth_get_buffer_pool_entry(struct qeth_card *card)
2610{
2611 struct qeth_buffer_pool_entry *entry;
2612
2613 QETH_DBF_TEXT(trace, 6, "gtbfplen");
2614 if (!list_empty(&card->qdio.in_buf_pool.entry_list)) {
2615 entry = list_entry(card->qdio.in_buf_pool.entry_list.next,
2616 struct qeth_buffer_pool_entry, list);
2617 list_del_init(&entry->list);
2618 return entry;
2619 }
2620 return NULL;
2621}
2622
2623static inline void
2624qeth_init_input_buffer(struct qeth_card *card, struct qeth_qdio_buffer *buf)
2625{
2626 struct qeth_buffer_pool_entry *pool_entry;
2627 int i;
2628
2629 pool_entry = qeth_get_buffer_pool_entry(card);
2630 /*
2631 * since the buffer is accessed only from the input_tasklet
2632 * there shouldn't be a need to synchronize; also, since we use
2633 * the QETH_IN_BUF_REQUEUE_THRESHOLD we should never run out off
2634 * buffers
2635 */
2636 BUG_ON(!pool_entry);
2637
2638 buf->pool_entry = pool_entry;
2639 for(i = 0; i < QETH_MAX_BUFFER_ELEMENTS(card); ++i){
2640 buf->buffer->element[i].length = PAGE_SIZE;
2641 buf->buffer->element[i].addr = pool_entry->elements[i];
2642 if (i == QETH_MAX_BUFFER_ELEMENTS(card) - 1)
2643 buf->buffer->element[i].flags = SBAL_FLAGS_LAST_ENTRY;
2644 else
2645 buf->buffer->element[i].flags = 0;
2646 }
2647 buf->state = QETH_QDIO_BUF_EMPTY;
2648}
2649
2650static inline void
2651qeth_clear_output_buffer(struct qeth_qdio_out_q *queue,
2652 struct qeth_qdio_out_buffer *buf)
2653{
2654 int i;
2655 struct sk_buff *skb;
2656
2657 /* is PCI flag set on buffer? */
2658 if (buf->buffer->element[0].flags & 0x40)
2659 atomic_dec(&queue->set_pci_flags_count);
2660
2661 while ((skb = skb_dequeue(&buf->skb_list))){
2662 atomic_dec(&skb->users);
2663 dev_kfree_skb_any(skb);
2664 }
2665 qeth_eddp_buf_release_contexts(buf);
2666 for(i = 0; i < QETH_MAX_BUFFER_ELEMENTS(queue->card); ++i){
2667 buf->buffer->element[i].length = 0;
2668 buf->buffer->element[i].addr = NULL;
2669 buf->buffer->element[i].flags = 0;
2670 }
2671 buf->next_element_to_fill = 0;
2672 atomic_set(&buf->state, QETH_QDIO_BUF_EMPTY);
2673}
2674
2675static inline void
2676qeth_queue_input_buffer(struct qeth_card *card, int index)
2677{
2678 struct qeth_qdio_q *queue = card->qdio.in_q;
2679 int count;
2680 int i;
2681 int rc;
2682
2683 QETH_DBF_TEXT(trace,6,"queinbuf");
2684 count = (index < queue->next_buf_to_init)?
2685 card->qdio.in_buf_pool.buf_count -
2686 (queue->next_buf_to_init - index) :
2687 card->qdio.in_buf_pool.buf_count -
2688 (queue->next_buf_to_init + QDIO_MAX_BUFFERS_PER_Q - index);
2689 /* only requeue at a certain threshold to avoid SIGAs */
2690 if (count >= QETH_IN_BUF_REQUEUE_THRESHOLD(card)){
2691 for (i = queue->next_buf_to_init;
2692 i < queue->next_buf_to_init + count; ++i)
2693 qeth_init_input_buffer(card,
2694 &queue->bufs[i % QDIO_MAX_BUFFERS_PER_Q]);
2695 /*
2696 * according to old code it should be avoided to requeue all
2697 * 128 buffers in order to benefit from PCI avoidance.
2698 * this function keeps at least one buffer (the buffer at
2699 * 'index') un-requeued -> this buffer is the first buffer that
2700 * will be requeued the next time
2701 */
2702#ifdef CONFIG_QETH_PERF_STATS
2703 card->perf_stats.inbound_do_qdio_cnt++;
2704 card->perf_stats.inbound_do_qdio_start_time = qeth_get_micros();
2705#endif
2706 rc = do_QDIO(CARD_DDEV(card),
2707 QDIO_FLAG_SYNC_INPUT | QDIO_FLAG_UNDER_INTERRUPT,
2708 0, queue->next_buf_to_init, count, NULL);
2709#ifdef CONFIG_QETH_PERF_STATS
2710 card->perf_stats.inbound_do_qdio_time += qeth_get_micros() -
2711 card->perf_stats.inbound_do_qdio_start_time;
2712#endif
2713 if (rc){
2714 PRINT_WARN("qeth_queue_input_buffer's do_QDIO "
2715 "return %i (device %s).\n",
2716 rc, CARD_DDEV_ID(card));
2717 QETH_DBF_TEXT(trace,2,"qinberr");
2718 QETH_DBF_TEXT_(trace,2,"%s",CARD_BUS_ID(card));
2719 }
2720 queue->next_buf_to_init = (queue->next_buf_to_init + count) %
2721 QDIO_MAX_BUFFERS_PER_Q;
2722 }
2723}
2724
2725static inline void
2726qeth_put_buffer_pool_entry(struct qeth_card *card,
2727 struct qeth_buffer_pool_entry *entry)
2728{
2729 QETH_DBF_TEXT(trace, 6, "ptbfplen");
2730 list_add_tail(&entry->list, &card->qdio.in_buf_pool.entry_list);
2731}
2732
2733static void
2734qeth_qdio_input_handler(struct ccw_device * ccwdev, unsigned int status,
2735 unsigned int qdio_err, unsigned int siga_err,
2736 unsigned int queue, int first_element, int count,
2737 unsigned long card_ptr)
2738{
2739 struct net_device *net_dev;
2740 struct qeth_card *card;
2741 struct qeth_qdio_buffer *buffer;
2742 int index;
2743 int i;
2744
2745 QETH_DBF_TEXT(trace, 6, "qdinput");
2746 card = (struct qeth_card *) card_ptr;
2747 net_dev = card->dev;
2748#ifdef CONFIG_QETH_PERF_STATS
2749 card->perf_stats.inbound_cnt++;
2750 card->perf_stats.inbound_start_time = qeth_get_micros();
2751#endif
2752 if (status & QDIO_STATUS_LOOK_FOR_ERROR) {
2753 if (status & QDIO_STATUS_ACTIVATE_CHECK_CONDITION){
2754 QETH_DBF_TEXT(trace, 1,"qdinchk");
2755 QETH_DBF_TEXT_(trace,1,"%s",CARD_BUS_ID(card));
2756 QETH_DBF_TEXT_(trace,1,"%04X%04X",first_element,count);
2757 QETH_DBF_TEXT_(trace,1,"%04X%04X", queue, status);
2758 qeth_schedule_recovery(card);
2759 return;
2760 }
2761 }
2762 for (i = first_element; i < (first_element + count); ++i) {
2763 index = i % QDIO_MAX_BUFFERS_PER_Q;
2764 buffer = &card->qdio.in_q->bufs[index];
Frank Pavlic6c6b3e72005-12-13 08:21:47 +01002765 if (!((status & QDIO_STATUS_LOOK_FOR_ERROR) &&
Jeff Garzike82b0f22006-05-26 21:58:38 -04002766 qeth_check_qdio_errors(buffer->buffer,
Frank Pavlic6c6b3e72005-12-13 08:21:47 +01002767 qdio_err, siga_err,"qinerr")))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002768 qeth_process_inbound_buffer(card, buffer, index);
2769 /* clear buffer and give back to hardware */
2770 qeth_put_buffer_pool_entry(card, buffer->pool_entry);
2771 qeth_queue_input_buffer(card, index);
2772 }
2773#ifdef CONFIG_QETH_PERF_STATS
2774 card->perf_stats.inbound_time += qeth_get_micros() -
2775 card->perf_stats.inbound_start_time;
2776#endif
2777}
2778
2779static inline int
2780qeth_handle_send_error(struct qeth_card *card,
2781 struct qeth_qdio_out_buffer *buffer,
Frank Pavlic6c6b3e72005-12-13 08:21:47 +01002782 unsigned int qdio_err, unsigned int siga_err)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002783{
2784 int sbalf15 = buffer->buffer->element[15].flags & 0xff;
2785 int cc = siga_err & 3;
2786
2787 QETH_DBF_TEXT(trace, 6, "hdsnderr");
Frank Pavlic6c6b3e72005-12-13 08:21:47 +01002788 qeth_check_qdio_errors(buffer->buffer, qdio_err, siga_err, "qouterr");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002789 switch (cc) {
2790 case 0:
2791 if (qdio_err){
2792 QETH_DBF_TEXT(trace, 1,"lnkfail");
2793 QETH_DBF_TEXT_(trace,1,"%s",CARD_BUS_ID(card));
2794 QETH_DBF_TEXT_(trace,1,"%04x %02x",
2795 (u16)qdio_err, (u8)sbalf15);
2796 return QETH_SEND_ERROR_LINK_FAILURE;
2797 }
2798 return QETH_SEND_ERROR_NONE;
2799 case 2:
2800 if (siga_err & QDIO_SIGA_ERROR_B_BIT_SET) {
2801 QETH_DBF_TEXT(trace, 1, "SIGAcc2B");
2802 QETH_DBF_TEXT_(trace,1,"%s",CARD_BUS_ID(card));
2803 return QETH_SEND_ERROR_KICK_IT;
2804 }
2805 if ((sbalf15 >= 15) && (sbalf15 <= 31))
2806 return QETH_SEND_ERROR_RETRY;
2807 return QETH_SEND_ERROR_LINK_FAILURE;
2808 /* look at qdio_error and sbalf 15 */
2809 case 1:
2810 QETH_DBF_TEXT(trace, 1, "SIGAcc1");
2811 QETH_DBF_TEXT_(trace,1,"%s",CARD_BUS_ID(card));
2812 return QETH_SEND_ERROR_LINK_FAILURE;
2813 case 3:
Frank Pavlic1380fee2006-03-22 16:03:41 +01002814 default:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002815 QETH_DBF_TEXT(trace, 1, "SIGAcc3");
2816 QETH_DBF_TEXT_(trace,1,"%s",CARD_BUS_ID(card));
2817 return QETH_SEND_ERROR_KICK_IT;
2818 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002819}
2820
2821void
2822qeth_flush_buffers(struct qeth_qdio_out_q *queue, int under_int,
2823 int index, int count)
2824{
2825 struct qeth_qdio_out_buffer *buf;
2826 int rc;
2827 int i;
2828
2829 QETH_DBF_TEXT(trace, 6, "flushbuf");
2830
2831 for (i = index; i < index + count; ++i) {
2832 buf = &queue->bufs[i % QDIO_MAX_BUFFERS_PER_Q];
2833 buf->buffer->element[buf->next_element_to_fill - 1].flags |=
2834 SBAL_FLAGS_LAST_ENTRY;
2835
2836 if (queue->card->info.type == QETH_CARD_TYPE_IQD)
2837 continue;
2838
2839 if (!queue->do_pack){
2840 if ((atomic_read(&queue->used_buffers) >=
2841 (QETH_HIGH_WATERMARK_PACK -
2842 QETH_WATERMARK_PACK_FUZZ)) &&
2843 !atomic_read(&queue->set_pci_flags_count)){
2844 /* it's likely that we'll go to packing
2845 * mode soon */
2846 atomic_inc(&queue->set_pci_flags_count);
2847 buf->buffer->element[0].flags |= 0x40;
2848 }
2849 } else {
2850 if (!atomic_read(&queue->set_pci_flags_count)){
2851 /*
2852 * there's no outstanding PCI any more, so we
2853 * have to request a PCI to be sure the the PCI
2854 * will wake at some time in the future then we
2855 * can flush packed buffers that might still be
2856 * hanging around, which can happen if no
2857 * further send was requested by the stack
2858 */
2859 atomic_inc(&queue->set_pci_flags_count);
2860 buf->buffer->element[0].flags |= 0x40;
2861 }
2862 }
2863 }
2864
2865 queue->card->dev->trans_start = jiffies;
2866#ifdef CONFIG_QETH_PERF_STATS
2867 queue->card->perf_stats.outbound_do_qdio_cnt++;
2868 queue->card->perf_stats.outbound_do_qdio_start_time = qeth_get_micros();
2869#endif
2870 if (under_int)
2871 rc = do_QDIO(CARD_DDEV(queue->card),
2872 QDIO_FLAG_SYNC_OUTPUT | QDIO_FLAG_UNDER_INTERRUPT,
2873 queue->queue_no, index, count, NULL);
2874 else
2875 rc = do_QDIO(CARD_DDEV(queue->card), QDIO_FLAG_SYNC_OUTPUT,
2876 queue->queue_no, index, count, NULL);
2877#ifdef CONFIG_QETH_PERF_STATS
2878 queue->card->perf_stats.outbound_do_qdio_time += qeth_get_micros() -
2879 queue->card->perf_stats.outbound_do_qdio_start_time;
2880#endif
2881 if (rc){
Linus Torvalds1da177e2005-04-16 15:20:36 -07002882 QETH_DBF_TEXT(trace, 2, "flushbuf");
2883 QETH_DBF_TEXT_(trace, 2, " err%d", rc);
Frank Pavlicf3d242e2005-09-14 18:05:31 +02002884 QETH_DBF_TEXT_(trace, 2, "%s", CARD_DDEV_ID(queue->card));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002885 queue->card->stats.tx_errors += count;
2886 /* this must not happen under normal circumstances. if it
2887 * happens something is really wrong -> recover */
2888 qeth_schedule_recovery(queue->card);
2889 return;
2890 }
2891 atomic_add(count, &queue->used_buffers);
2892#ifdef CONFIG_QETH_PERF_STATS
2893 queue->card->perf_stats.bufs_sent += count;
2894#endif
2895}
2896
2897/*
2898 * Switched to packing state if the number of used buffers on a queue
2899 * reaches a certain limit.
2900 */
2901static inline void
2902qeth_switch_to_packing_if_needed(struct qeth_qdio_out_q *queue)
2903{
2904 if (!queue->do_pack) {
2905 if (atomic_read(&queue->used_buffers)
2906 >= QETH_HIGH_WATERMARK_PACK){
2907 /* switch non-PACKING -> PACKING */
2908 QETH_DBF_TEXT(trace, 6, "np->pack");
2909#ifdef CONFIG_QETH_PERF_STATS
2910 queue->card->perf_stats.sc_dp_p++;
2911#endif
2912 queue->do_pack = 1;
2913 }
2914 }
2915}
2916
2917/*
2918 * Switches from packing to non-packing mode. If there is a packing
2919 * buffer on the queue this buffer will be prepared to be flushed.
2920 * In that case 1 is returned to inform the caller. If no buffer
2921 * has to be flushed, zero is returned.
2922 */
2923static inline int
2924qeth_switch_to_nonpacking_if_needed(struct qeth_qdio_out_q *queue)
2925{
2926 struct qeth_qdio_out_buffer *buffer;
2927 int flush_count = 0;
2928
2929 if (queue->do_pack) {
2930 if (atomic_read(&queue->used_buffers)
2931 <= QETH_LOW_WATERMARK_PACK) {
2932 /* switch PACKING -> non-PACKING */
2933 QETH_DBF_TEXT(trace, 6, "pack->np");
2934#ifdef CONFIG_QETH_PERF_STATS
2935 queue->card->perf_stats.sc_p_dp++;
2936#endif
2937 queue->do_pack = 0;
2938 /* flush packing buffers */
2939 buffer = &queue->bufs[queue->next_buf_to_fill];
2940 if ((atomic_read(&buffer->state) ==
2941 QETH_QDIO_BUF_EMPTY) &&
2942 (buffer->next_element_to_fill > 0)) {
2943 atomic_set(&buffer->state,QETH_QDIO_BUF_PRIMED);
2944 flush_count++;
2945 queue->next_buf_to_fill =
2946 (queue->next_buf_to_fill + 1) %
2947 QDIO_MAX_BUFFERS_PER_Q;
2948 }
2949 }
2950 }
2951 return flush_count;
2952}
2953
2954/*
2955 * Called to flush a packing buffer if no more pci flags are on the queue.
2956 * Checks if there is a packing buffer and prepares it to be flushed.
2957 * In that case returns 1, otherwise zero.
2958 */
2959static inline int
2960qeth_flush_buffers_on_no_pci(struct qeth_qdio_out_q *queue)
2961{
2962 struct qeth_qdio_out_buffer *buffer;
2963
2964 buffer = &queue->bufs[queue->next_buf_to_fill];
2965 if((atomic_read(&buffer->state) == QETH_QDIO_BUF_EMPTY) &&
2966 (buffer->next_element_to_fill > 0)){
2967 /* it's a packing buffer */
2968 atomic_set(&buffer->state, QETH_QDIO_BUF_PRIMED);
2969 queue->next_buf_to_fill =
2970 (queue->next_buf_to_fill + 1) % QDIO_MAX_BUFFERS_PER_Q;
2971 return 1;
2972 }
2973 return 0;
2974}
2975
2976static inline void
2977qeth_check_outbound_queue(struct qeth_qdio_out_q *queue)
2978{
2979 int index;
2980 int flush_cnt = 0;
2981 int q_was_packing = 0;
2982
2983 /*
2984 * check if weed have to switch to non-packing mode or if
2985 * we have to get a pci flag out on the queue
2986 */
2987 if ((atomic_read(&queue->used_buffers) <= QETH_LOW_WATERMARK_PACK) ||
2988 !atomic_read(&queue->set_pci_flags_count)){
2989 if (atomic_swap(&queue->state, QETH_OUT_Q_LOCKED_FLUSH) ==
2990 QETH_OUT_Q_UNLOCKED) {
2991 /*
2992 * If we get in here, there was no action in
2993 * do_send_packet. So, we check if there is a
2994 * packing buffer to be flushed here.
2995 */
2996 netif_stop_queue(queue->card->dev);
2997 index = queue->next_buf_to_fill;
2998 q_was_packing = queue->do_pack;
2999 flush_cnt += qeth_switch_to_nonpacking_if_needed(queue);
3000 if (!flush_cnt &&
3001 !atomic_read(&queue->set_pci_flags_count))
3002 flush_cnt +=
3003 qeth_flush_buffers_on_no_pci(queue);
3004#ifdef CONFIG_QETH_PERF_STATS
3005 if (q_was_packing)
3006 queue->card->perf_stats.bufs_sent_pack +=
3007 flush_cnt;
3008#endif
3009 if (flush_cnt)
3010 qeth_flush_buffers(queue, 1, index, flush_cnt);
3011 atomic_set(&queue->state, QETH_OUT_Q_UNLOCKED);
3012 }
3013 }
3014}
3015
3016static void
3017qeth_qdio_output_handler(struct ccw_device * ccwdev, unsigned int status,
3018 unsigned int qdio_error, unsigned int siga_error,
3019 unsigned int __queue, int first_element, int count,
3020 unsigned long card_ptr)
3021{
3022 struct qeth_card *card = (struct qeth_card *) card_ptr;
3023 struct qeth_qdio_out_q *queue = card->qdio.out_qs[__queue];
3024 struct qeth_qdio_out_buffer *buffer;
3025 int i;
3026
3027 QETH_DBF_TEXT(trace, 6, "qdouhdl");
3028 if (status & QDIO_STATUS_LOOK_FOR_ERROR) {
3029 if (status & QDIO_STATUS_ACTIVATE_CHECK_CONDITION){
Frank Pavlicf3d242e2005-09-14 18:05:31 +02003030 QETH_DBF_TEXT(trace, 2, "achkcond");
3031 QETH_DBF_TEXT_(trace, 2, "%s", CARD_BUS_ID(card));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003032 QETH_DBF_TEXT_(trace, 2, "%08x", status);
3033 netif_stop_queue(card->dev);
3034 qeth_schedule_recovery(card);
3035 return;
3036 }
3037 }
3038#ifdef CONFIG_QETH_PERF_STATS
3039 card->perf_stats.outbound_handler_cnt++;
3040 card->perf_stats.outbound_handler_start_time = qeth_get_micros();
3041#endif
3042 for(i = first_element; i < (first_element + count); ++i){
3043 buffer = &queue->bufs[i % QDIO_MAX_BUFFERS_PER_Q];
3044 /*we only handle the KICK_IT error by doing a recovery */
Frank Pavlic6c6b3e72005-12-13 08:21:47 +01003045 if (qeth_handle_send_error(card, buffer,
3046 qdio_error, siga_error)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003047 == QETH_SEND_ERROR_KICK_IT){
3048 netif_stop_queue(card->dev);
3049 qeth_schedule_recovery(card);
3050 return;
3051 }
3052 qeth_clear_output_buffer(queue, buffer);
3053 }
3054 atomic_sub(count, &queue->used_buffers);
3055 /* check if we need to do something on this outbound queue */
3056 if (card->info.type != QETH_CARD_TYPE_IQD)
3057 qeth_check_outbound_queue(queue);
3058
3059 netif_wake_queue(queue->card->dev);
3060#ifdef CONFIG_QETH_PERF_STATS
3061 card->perf_stats.outbound_handler_time += qeth_get_micros() -
3062 card->perf_stats.outbound_handler_start_time;
3063#endif
3064}
3065
3066static void
3067qeth_create_qib_param_field(struct qeth_card *card, char *param_field)
3068{
3069
3070 param_field[0] = _ascebc['P'];
3071 param_field[1] = _ascebc['C'];
3072 param_field[2] = _ascebc['I'];
3073 param_field[3] = _ascebc['T'];
3074 *((unsigned int *) (&param_field[4])) = QETH_PCI_THRESHOLD_A(card);
3075 *((unsigned int *) (&param_field[8])) = QETH_PCI_THRESHOLD_B(card);
3076 *((unsigned int *) (&param_field[12])) = QETH_PCI_TIMER_VALUE(card);
3077}
3078
3079static void
3080qeth_create_qib_param_field_blkt(struct qeth_card *card, char *param_field)
3081{
3082 param_field[16] = _ascebc['B'];
3083 param_field[17] = _ascebc['L'];
3084 param_field[18] = _ascebc['K'];
3085 param_field[19] = _ascebc['T'];
3086 *((unsigned int *) (&param_field[20])) = card->info.blkt.time_total;
3087 *((unsigned int *) (&param_field[24])) = card->info.blkt.inter_packet;
3088 *((unsigned int *) (&param_field[28])) = card->info.blkt.inter_packet_jumbo;
3089}
3090
3091static void
3092qeth_initialize_working_pool_list(struct qeth_card *card)
3093{
3094 struct qeth_buffer_pool_entry *entry;
3095
3096 QETH_DBF_TEXT(trace,5,"inwrklst");
3097
3098 list_for_each_entry(entry,
3099 &card->qdio.init_pool.entry_list, init_list) {
3100 qeth_put_buffer_pool_entry(card,entry);
3101 }
3102}
3103
3104static void
3105qeth_clear_working_pool_list(struct qeth_card *card)
3106{
3107 struct qeth_buffer_pool_entry *pool_entry, *tmp;
3108
3109 QETH_DBF_TEXT(trace,5,"clwrklst");
3110 list_for_each_entry_safe(pool_entry, tmp,
3111 &card->qdio.in_buf_pool.entry_list, list){
3112 list_del(&pool_entry->list);
3113 }
3114}
3115
3116static void
3117qeth_free_buffer_pool(struct qeth_card *card)
3118{
3119 struct qeth_buffer_pool_entry *pool_entry, *tmp;
3120 int i=0;
3121 QETH_DBF_TEXT(trace,5,"freepool");
3122 list_for_each_entry_safe(pool_entry, tmp,
3123 &card->qdio.init_pool.entry_list, init_list){
3124 for (i = 0; i < QETH_MAX_BUFFER_ELEMENTS(card); ++i)
3125 free_page((unsigned long)pool_entry->elements[i]);
3126 list_del(&pool_entry->init_list);
3127 kfree(pool_entry);
3128 }
3129}
3130
3131static int
3132qeth_alloc_buffer_pool(struct qeth_card *card)
3133{
3134 struct qeth_buffer_pool_entry *pool_entry;
3135 void *ptr;
3136 int i, j;
3137
3138 QETH_DBF_TEXT(trace,5,"alocpool");
3139 for (i = 0; i < card->qdio.init_pool.buf_count; ++i){
3140 pool_entry = kmalloc(sizeof(*pool_entry), GFP_KERNEL);
3141 if (!pool_entry){
3142 qeth_free_buffer_pool(card);
3143 return -ENOMEM;
3144 }
3145 for(j = 0; j < QETH_MAX_BUFFER_ELEMENTS(card); ++j){
Ursula Braun9123e0d2005-09-30 10:17:24 +02003146 ptr = (void *) __get_free_page(GFP_KERNEL|GFP_DMA);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003147 if (!ptr) {
3148 while (j > 0)
3149 free_page((unsigned long)
3150 pool_entry->elements[--j]);
3151 kfree(pool_entry);
3152 qeth_free_buffer_pool(card);
3153 return -ENOMEM;
3154 }
3155 pool_entry->elements[j] = ptr;
3156 }
3157 list_add(&pool_entry->init_list,
3158 &card->qdio.init_pool.entry_list);
3159 }
3160 return 0;
3161}
3162
3163int
3164qeth_realloc_buffer_pool(struct qeth_card *card, int bufcnt)
3165{
3166 QETH_DBF_TEXT(trace, 2, "realcbp");
3167
3168 if ((card->state != CARD_STATE_DOWN) &&
3169 (card->state != CARD_STATE_RECOVER))
3170 return -EPERM;
3171
3172 /* TODO: steel/add buffers from/to a running card's buffer pool (?) */
3173 qeth_clear_working_pool_list(card);
3174 qeth_free_buffer_pool(card);
3175 card->qdio.in_buf_pool.buf_count = bufcnt;
3176 card->qdio.init_pool.buf_count = bufcnt;
3177 return qeth_alloc_buffer_pool(card);
3178}
3179
3180static int
3181qeth_alloc_qdio_buffers(struct qeth_card *card)
3182{
3183 int i, j;
3184
3185 QETH_DBF_TEXT(setup, 2, "allcqdbf");
3186
3187 if (card->qdio.state == QETH_QDIO_ALLOCATED)
3188 return 0;
3189
Jeff Garzike82b0f22006-05-26 21:58:38 -04003190 card->qdio.in_q = kmalloc(sizeof(struct qeth_qdio_q),
Ursula Braun9123e0d2005-09-30 10:17:24 +02003191 GFP_KERNEL|GFP_DMA);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003192 if (!card->qdio.in_q)
3193 return - ENOMEM;
3194 QETH_DBF_TEXT(setup, 2, "inq");
3195 QETH_DBF_HEX(setup, 2, &card->qdio.in_q, sizeof(void *));
3196 memset(card->qdio.in_q, 0, sizeof(struct qeth_qdio_q));
3197 /* give inbound qeth_qdio_buffers their qdio_buffers */
3198 for (i = 0; i < QDIO_MAX_BUFFERS_PER_Q; ++i)
3199 card->qdio.in_q->bufs[i].buffer =
3200 &card->qdio.in_q->qdio_bufs[i];
3201 /* inbound buffer pool */
3202 if (qeth_alloc_buffer_pool(card)){
3203 kfree(card->qdio.in_q);
3204 return -ENOMEM;
3205 }
3206 /* outbound */
3207 card->qdio.out_qs =
3208 kmalloc(card->qdio.no_out_queues *
3209 sizeof(struct qeth_qdio_out_q *), GFP_KERNEL);
3210 if (!card->qdio.out_qs){
3211 qeth_free_buffer_pool(card);
3212 return -ENOMEM;
3213 }
3214 for (i = 0; i < card->qdio.no_out_queues; ++i){
3215 card->qdio.out_qs[i] = kmalloc(sizeof(struct qeth_qdio_out_q),
Ursula Braun9123e0d2005-09-30 10:17:24 +02003216 GFP_KERNEL|GFP_DMA);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003217 if (!card->qdio.out_qs[i]){
3218 while (i > 0)
3219 kfree(card->qdio.out_qs[--i]);
3220 kfree(card->qdio.out_qs);
3221 return -ENOMEM;
3222 }
3223 QETH_DBF_TEXT_(setup, 2, "outq %i", i);
3224 QETH_DBF_HEX(setup, 2, &card->qdio.out_qs[i], sizeof(void *));
3225 memset(card->qdio.out_qs[i], 0, sizeof(struct qeth_qdio_out_q));
3226 card->qdio.out_qs[i]->queue_no = i;
3227 /* give outbound qeth_qdio_buffers their qdio_buffers */
3228 for (j = 0; j < QDIO_MAX_BUFFERS_PER_Q; ++j){
3229 card->qdio.out_qs[i]->bufs[j].buffer =
3230 &card->qdio.out_qs[i]->qdio_bufs[j];
3231 skb_queue_head_init(&card->qdio.out_qs[i]->bufs[j].
3232 skb_list);
3233 INIT_LIST_HEAD(&card->qdio.out_qs[i]->bufs[j].ctx_list);
3234 }
3235 }
3236 card->qdio.state = QETH_QDIO_ALLOCATED;
3237 return 0;
3238}
3239
3240static void
3241qeth_free_qdio_buffers(struct qeth_card *card)
3242{
3243 int i, j;
3244
3245 QETH_DBF_TEXT(trace, 2, "freeqdbf");
3246 if (card->qdio.state == QETH_QDIO_UNINITIALIZED)
3247 return;
3248 kfree(card->qdio.in_q);
3249 /* inbound buffer pool */
3250 qeth_free_buffer_pool(card);
3251 /* free outbound qdio_qs */
3252 for (i = 0; i < card->qdio.no_out_queues; ++i){
3253 for (j = 0; j < QDIO_MAX_BUFFERS_PER_Q; ++j)
3254 qeth_clear_output_buffer(card->qdio.out_qs[i],
3255 &card->qdio.out_qs[i]->bufs[j]);
3256 kfree(card->qdio.out_qs[i]);
3257 }
3258 kfree(card->qdio.out_qs);
3259 card->qdio.state = QETH_QDIO_UNINITIALIZED;
3260}
3261
3262static void
3263qeth_clear_qdio_buffers(struct qeth_card *card)
3264{
3265 int i, j;
3266
3267 QETH_DBF_TEXT(trace, 2, "clearqdbf");
3268 /* clear outbound buffers to free skbs */
3269 for (i = 0; i < card->qdio.no_out_queues; ++i)
3270 if (card->qdio.out_qs[i]){
3271 for (j = 0; j < QDIO_MAX_BUFFERS_PER_Q; ++j)
3272 qeth_clear_output_buffer(card->qdio.out_qs[i],
3273 &card->qdio.out_qs[i]->bufs[j]);
3274 }
3275}
3276
3277static void
3278qeth_init_qdio_info(struct qeth_card *card)
3279{
3280 QETH_DBF_TEXT(setup, 4, "intqdinf");
3281 card->qdio.state = QETH_QDIO_UNINITIALIZED;
3282 /* inbound */
3283 card->qdio.in_buf_size = QETH_IN_BUF_SIZE_DEFAULT;
3284 card->qdio.init_pool.buf_count = QETH_IN_BUF_COUNT_DEFAULT;
3285 card->qdio.in_buf_pool.buf_count = card->qdio.init_pool.buf_count;
3286 INIT_LIST_HEAD(&card->qdio.in_buf_pool.entry_list);
3287 INIT_LIST_HEAD(&card->qdio.init_pool.entry_list);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003288}
3289
3290static int
3291qeth_init_qdio_queues(struct qeth_card *card)
3292{
3293 int i, j;
3294 int rc;
3295
3296 QETH_DBF_TEXT(setup, 2, "initqdqs");
3297
3298 /* inbound queue */
3299 memset(card->qdio.in_q->qdio_bufs, 0,
3300 QDIO_MAX_BUFFERS_PER_Q * sizeof(struct qdio_buffer));
3301 qeth_initialize_working_pool_list(card);
3302 /*give only as many buffers to hardware as we have buffer pool entries*/
3303 for (i = 0; i < card->qdio.in_buf_pool.buf_count - 1; ++i)
3304 qeth_init_input_buffer(card, &card->qdio.in_q->bufs[i]);
3305 card->qdio.in_q->next_buf_to_init = card->qdio.in_buf_pool.buf_count - 1;
3306 rc = do_QDIO(CARD_DDEV(card), QDIO_FLAG_SYNC_INPUT, 0, 0,
3307 card->qdio.in_buf_pool.buf_count - 1, NULL);
3308 if (rc) {
3309 QETH_DBF_TEXT_(setup, 2, "1err%d", rc);
3310 return rc;
3311 }
3312 rc = qdio_synchronize(CARD_DDEV(card), QDIO_FLAG_SYNC_INPUT, 0);
3313 if (rc) {
3314 QETH_DBF_TEXT_(setup, 2, "2err%d", rc);
3315 return rc;
3316 }
3317 /* outbound queue */
3318 for (i = 0; i < card->qdio.no_out_queues; ++i){
3319 memset(card->qdio.out_qs[i]->qdio_bufs, 0,
3320 QDIO_MAX_BUFFERS_PER_Q * sizeof(struct qdio_buffer));
3321 for (j = 0; j < QDIO_MAX_BUFFERS_PER_Q; ++j){
3322 qeth_clear_output_buffer(card->qdio.out_qs[i],
3323 &card->qdio.out_qs[i]->bufs[j]);
3324 }
3325 card->qdio.out_qs[i]->card = card;
3326 card->qdio.out_qs[i]->next_buf_to_fill = 0;
3327 card->qdio.out_qs[i]->do_pack = 0;
3328 atomic_set(&card->qdio.out_qs[i]->used_buffers,0);
3329 atomic_set(&card->qdio.out_qs[i]->set_pci_flags_count, 0);
3330 atomic_set(&card->qdio.out_qs[i]->state,
3331 QETH_OUT_Q_UNLOCKED);
3332 }
3333 return 0;
3334}
3335
3336static int
3337qeth_qdio_establish(struct qeth_card *card)
3338{
3339 struct qdio_initialize init_data;
3340 char *qib_param_field;
3341 struct qdio_buffer **in_sbal_ptrs;
3342 struct qdio_buffer **out_sbal_ptrs;
3343 int i, j, k;
3344 int rc;
3345
3346 QETH_DBF_TEXT(setup, 2, "qdioest");
3347
Eric Sesterhenn88abaab2006-03-24 03:15:31 -08003348 qib_param_field = kzalloc(QDIO_MAX_BUFFERS_PER_Q * sizeof(char),
Linus Torvalds1da177e2005-04-16 15:20:36 -07003349 GFP_KERNEL);
3350 if (!qib_param_field)
3351 return -ENOMEM;
3352
Linus Torvalds1da177e2005-04-16 15:20:36 -07003353 qeth_create_qib_param_field(card, qib_param_field);
3354 qeth_create_qib_param_field_blkt(card, qib_param_field);
3355
3356 in_sbal_ptrs = kmalloc(QDIO_MAX_BUFFERS_PER_Q * sizeof(void *),
3357 GFP_KERNEL);
3358 if (!in_sbal_ptrs) {
3359 kfree(qib_param_field);
3360 return -ENOMEM;
3361 }
3362 for(i = 0; i < QDIO_MAX_BUFFERS_PER_Q; ++i)
3363 in_sbal_ptrs[i] = (struct qdio_buffer *)
3364 virt_to_phys(card->qdio.in_q->bufs[i].buffer);
3365
3366 out_sbal_ptrs =
3367 kmalloc(card->qdio.no_out_queues * QDIO_MAX_BUFFERS_PER_Q *
3368 sizeof(void *), GFP_KERNEL);
3369 if (!out_sbal_ptrs) {
3370 kfree(in_sbal_ptrs);
3371 kfree(qib_param_field);
3372 return -ENOMEM;
3373 }
3374 for(i = 0, k = 0; i < card->qdio.no_out_queues; ++i)
3375 for(j = 0; j < QDIO_MAX_BUFFERS_PER_Q; ++j, ++k){
3376 out_sbal_ptrs[k] = (struct qdio_buffer *)
3377 virt_to_phys(card->qdio.out_qs[i]->
3378 bufs[j].buffer);
3379 }
3380
3381 memset(&init_data, 0, sizeof(struct qdio_initialize));
3382 init_data.cdev = CARD_DDEV(card);
3383 init_data.q_format = qeth_get_qdio_q_format(card);
3384 init_data.qib_param_field_format = 0;
3385 init_data.qib_param_field = qib_param_field;
3386 init_data.min_input_threshold = QETH_MIN_INPUT_THRESHOLD;
3387 init_data.max_input_threshold = QETH_MAX_INPUT_THRESHOLD;
3388 init_data.min_output_threshold = QETH_MIN_OUTPUT_THRESHOLD;
3389 init_data.max_output_threshold = QETH_MAX_OUTPUT_THRESHOLD;
3390 init_data.no_input_qs = 1;
3391 init_data.no_output_qs = card->qdio.no_out_queues;
3392 init_data.input_handler = (qdio_handler_t *)
3393 qeth_qdio_input_handler;
3394 init_data.output_handler = (qdio_handler_t *)
3395 qeth_qdio_output_handler;
3396 init_data.int_parm = (unsigned long) card;
3397 init_data.flags = QDIO_INBOUND_0COPY_SBALS |
3398 QDIO_OUTBOUND_0COPY_SBALS |
3399 QDIO_USE_OUTBOUND_PCIS;
3400 init_data.input_sbal_addr_array = (void **) in_sbal_ptrs;
3401 init_data.output_sbal_addr_array = (void **) out_sbal_ptrs;
3402
3403 if (!(rc = qdio_initialize(&init_data)))
3404 card->qdio.state = QETH_QDIO_ESTABLISHED;
3405
3406 kfree(out_sbal_ptrs);
3407 kfree(in_sbal_ptrs);
3408 kfree(qib_param_field);
3409 return rc;
3410}
3411
3412static int
3413qeth_qdio_activate(struct qeth_card *card)
3414{
3415 QETH_DBF_TEXT(setup,3,"qdioact");
3416 return qdio_activate(CARD_DDEV(card), 0);
3417}
3418
3419static int
3420qeth_clear_channel(struct qeth_channel *channel)
3421{
3422 unsigned long flags;
3423 struct qeth_card *card;
3424 int rc;
3425
3426 QETH_DBF_TEXT(trace,3,"clearch");
3427 card = CARD_FROM_CDEV(channel->ccwdev);
3428 spin_lock_irqsave(get_ccwdev_lock(channel->ccwdev), flags);
3429 rc = ccw_device_clear(channel->ccwdev, QETH_CLEAR_CHANNEL_PARM);
3430 spin_unlock_irqrestore(get_ccwdev_lock(channel->ccwdev), flags);
3431
3432 if (rc)
3433 return rc;
3434 rc = wait_event_interruptible_timeout(card->wait_q,
3435 channel->state==CH_STATE_STOPPED, QETH_TIMEOUT);
3436 if (rc == -ERESTARTSYS)
3437 return rc;
3438 if (channel->state != CH_STATE_STOPPED)
3439 return -ETIME;
3440 channel->state = CH_STATE_DOWN;
3441 return 0;
3442}
3443
3444static int
3445qeth_halt_channel(struct qeth_channel *channel)
3446{
3447 unsigned long flags;
3448 struct qeth_card *card;
3449 int rc;
3450
3451 QETH_DBF_TEXT(trace,3,"haltch");
3452 card = CARD_FROM_CDEV(channel->ccwdev);
3453 spin_lock_irqsave(get_ccwdev_lock(channel->ccwdev), flags);
3454 rc = ccw_device_halt(channel->ccwdev, QETH_HALT_CHANNEL_PARM);
3455 spin_unlock_irqrestore(get_ccwdev_lock(channel->ccwdev), flags);
3456
3457 if (rc)
3458 return rc;
3459 rc = wait_event_interruptible_timeout(card->wait_q,
3460 channel->state==CH_STATE_HALTED, QETH_TIMEOUT);
3461 if (rc == -ERESTARTSYS)
3462 return rc;
3463 if (channel->state != CH_STATE_HALTED)
3464 return -ETIME;
3465 return 0;
3466}
3467
3468static int
3469qeth_halt_channels(struct qeth_card *card)
3470{
Frank Pavlicf3d242e2005-09-14 18:05:31 +02003471 int rc1 = 0, rc2=0, rc3 = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003472
3473 QETH_DBF_TEXT(trace,3,"haltchs");
Frank Pavlicf3d242e2005-09-14 18:05:31 +02003474 rc1 = qeth_halt_channel(&card->read);
3475 rc2 = qeth_halt_channel(&card->write);
3476 rc3 = qeth_halt_channel(&card->data);
3477 if (rc1)
3478 return rc1;
Jeff Garzike82b0f22006-05-26 21:58:38 -04003479 if (rc2)
Frank Pavlicf3d242e2005-09-14 18:05:31 +02003480 return rc2;
3481 return rc3;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003482}
3483static int
3484qeth_clear_channels(struct qeth_card *card)
3485{
Frank Pavlicf3d242e2005-09-14 18:05:31 +02003486 int rc1 = 0, rc2=0, rc3 = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003487
3488 QETH_DBF_TEXT(trace,3,"clearchs");
Frank Pavlicf3d242e2005-09-14 18:05:31 +02003489 rc1 = qeth_clear_channel(&card->read);
3490 rc2 = qeth_clear_channel(&card->write);
3491 rc3 = qeth_clear_channel(&card->data);
3492 if (rc1)
3493 return rc1;
Jeff Garzike82b0f22006-05-26 21:58:38 -04003494 if (rc2)
Frank Pavlicf3d242e2005-09-14 18:05:31 +02003495 return rc2;
3496 return rc3;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003497}
3498
3499static int
3500qeth_clear_halt_card(struct qeth_card *card, int halt)
3501{
3502 int rc = 0;
3503
3504 QETH_DBF_TEXT(trace,3,"clhacrd");
3505 QETH_DBF_HEX(trace, 3, &card, sizeof(void *));
3506
3507 if (halt)
3508 rc = qeth_halt_channels(card);
3509 if (rc)
3510 return rc;
3511 return qeth_clear_channels(card);
3512}
3513
3514static int
3515qeth_qdio_clear_card(struct qeth_card *card, int use_halt)
3516{
3517 int rc = 0;
3518
3519 QETH_DBF_TEXT(trace,3,"qdioclr");
3520 if (card->qdio.state == QETH_QDIO_ESTABLISHED){
3521 if ((rc = qdio_cleanup(CARD_DDEV(card),
3522 (card->info.type == QETH_CARD_TYPE_IQD) ?
3523 QDIO_FLAG_CLEANUP_USING_HALT :
3524 QDIO_FLAG_CLEANUP_USING_CLEAR)))
3525 QETH_DBF_TEXT_(trace, 3, "1err%d", rc);
3526 card->qdio.state = QETH_QDIO_ALLOCATED;
3527 }
3528 if ((rc = qeth_clear_halt_card(card, use_halt)))
3529 QETH_DBF_TEXT_(trace, 3, "2err%d", rc);
3530 card->state = CARD_STATE_DOWN;
3531 return rc;
3532}
3533
3534static int
3535qeth_dm_act(struct qeth_card *card)
3536{
3537 int rc;
3538 struct qeth_cmd_buffer *iob;
3539
3540 QETH_DBF_TEXT(setup,2,"dmact");
3541
3542 iob = qeth_wait_for_buffer(&card->write);
3543 memcpy(iob->data, DM_ACT, DM_ACT_SIZE);
3544
3545 memcpy(QETH_DM_ACT_DEST_ADDR(iob->data),
3546 &card->token.cm_connection_r, QETH_MPC_TOKEN_LENGTH);
3547 memcpy(QETH_DM_ACT_CONNECTION_TOKEN(iob->data),
3548 &card->token.ulp_connection_r, QETH_MPC_TOKEN_LENGTH);
3549 rc = qeth_send_control_data(card, DM_ACT_SIZE, iob, NULL, NULL);
3550 return rc;
3551}
3552
3553static int
3554qeth_mpc_initialize(struct qeth_card *card)
3555{
3556 int rc;
3557
3558 QETH_DBF_TEXT(setup,2,"mpcinit");
3559
3560 if ((rc = qeth_issue_next_read(card))){
3561 QETH_DBF_TEXT_(setup, 2, "1err%d", rc);
3562 return rc;
3563 }
3564 if ((rc = qeth_cm_enable(card))){
3565 QETH_DBF_TEXT_(setup, 2, "2err%d", rc);
Frank Pavlicf3d242e2005-09-14 18:05:31 +02003566 goto out_qdio;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003567 }
3568 if ((rc = qeth_cm_setup(card))){
3569 QETH_DBF_TEXT_(setup, 2, "3err%d", rc);
Frank Pavlicf3d242e2005-09-14 18:05:31 +02003570 goto out_qdio;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003571 }
3572 if ((rc = qeth_ulp_enable(card))){
3573 QETH_DBF_TEXT_(setup, 2, "4err%d", rc);
Frank Pavlicf3d242e2005-09-14 18:05:31 +02003574 goto out_qdio;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003575 }
3576 if ((rc = qeth_ulp_setup(card))){
3577 QETH_DBF_TEXT_(setup, 2, "5err%d", rc);
Frank Pavlicf3d242e2005-09-14 18:05:31 +02003578 goto out_qdio;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003579 }
3580 if ((rc = qeth_alloc_qdio_buffers(card))){
3581 QETH_DBF_TEXT_(setup, 2, "5err%d", rc);
Frank Pavlicf3d242e2005-09-14 18:05:31 +02003582 goto out_qdio;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003583 }
3584 if ((rc = qeth_qdio_establish(card))){
3585 QETH_DBF_TEXT_(setup, 2, "6err%d", rc);
3586 qeth_free_qdio_buffers(card);
3587 goto out_qdio;
3588 }
3589 if ((rc = qeth_qdio_activate(card))){
3590 QETH_DBF_TEXT_(setup, 2, "7err%d", rc);
3591 goto out_qdio;
3592 }
3593 if ((rc = qeth_dm_act(card))){
3594 QETH_DBF_TEXT_(setup, 2, "8err%d", rc);
3595 goto out_qdio;
3596 }
3597
3598 return 0;
3599out_qdio:
Ursula Braun500f83a2005-09-30 10:19:19 +02003600 qeth_qdio_clear_card(card, card->info.type!=QETH_CARD_TYPE_IQD);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003601 return rc;
3602}
3603
3604static struct net_device *
3605qeth_get_netdevice(enum qeth_card_types type, enum qeth_link_types linktype)
3606{
3607 struct net_device *dev = NULL;
3608
3609 switch (type) {
3610 case QETH_CARD_TYPE_OSAE:
3611 switch (linktype) {
3612 case QETH_LINK_TYPE_LANE_TR:
3613 case QETH_LINK_TYPE_HSTR:
3614#ifdef CONFIG_TR
3615 dev = alloc_trdev(0);
3616#endif /* CONFIG_TR */
3617 break;
3618 default:
3619 dev = alloc_etherdev(0);
3620 }
3621 break;
3622 case QETH_CARD_TYPE_IQD:
3623 dev = alloc_netdev(0, "hsi%d", ether_setup);
3624 break;
Ursula Braun500f83a2005-09-30 10:19:19 +02003625 case QETH_CARD_TYPE_OSN:
3626 dev = alloc_netdev(0, "osn%d", ether_setup);
3627 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003628 default:
3629 dev = alloc_etherdev(0);
3630 }
3631 return dev;
3632}
3633
3634/*hard_header fake function; used in case fake_ll is set */
3635static int
3636qeth_fake_header(struct sk_buff *skb, struct net_device *dev,
3637 unsigned short type, void *daddr, void *saddr,
3638 unsigned len)
3639{
Frank Pavlice23dd9c2005-05-12 20:38:11 +02003640 if(dev->type == ARPHRD_IEEE802_TR){
3641 struct trh_hdr *hdr;
3642 hdr = (struct trh_hdr *)skb_push(skb, QETH_FAKE_LL_LEN_TR);
3643 memcpy(hdr->saddr, dev->dev_addr, TR_ALEN);
3644 memcpy(hdr->daddr, "FAKELL", TR_ALEN);
3645 return QETH_FAKE_LL_LEN_TR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003646
Frank Pavlice23dd9c2005-05-12 20:38:11 +02003647 } else {
3648 struct ethhdr *hdr;
3649 hdr = (struct ethhdr *)skb_push(skb, QETH_FAKE_LL_LEN_ETH);
3650 memcpy(hdr->h_source, dev->dev_addr, ETH_ALEN);
3651 memcpy(hdr->h_dest, "FAKELL", ETH_ALEN);
3652 if (type != ETH_P_802_3)
3653 hdr->h_proto = htons(type);
3654 else
3655 hdr->h_proto = htons(len);
3656 return QETH_FAKE_LL_LEN_ETH;
3657
3658 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003659}
3660
3661static inline int
3662qeth_send_packet(struct qeth_card *, struct sk_buff *);
3663
3664static int
3665qeth_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
3666{
3667 int rc;
3668 struct qeth_card *card;
3669
3670 QETH_DBF_TEXT(trace, 6, "hrdstxmi");
3671 card = (struct qeth_card *)dev->priv;
3672 if (skb==NULL) {
3673 card->stats.tx_dropped++;
3674 card->stats.tx_errors++;
3675 /* return OK; otherwise ksoftirqd goes to 100% */
3676 return NETDEV_TX_OK;
3677 }
3678 if ((card->state != CARD_STATE_UP) || !card->lan_online) {
3679 card->stats.tx_dropped++;
3680 card->stats.tx_errors++;
3681 card->stats.tx_carrier_errors++;
3682 dev_kfree_skb_any(skb);
3683 /* return OK; otherwise ksoftirqd goes to 100% */
3684 return NETDEV_TX_OK;
3685 }
3686#ifdef CONFIG_QETH_PERF_STATS
3687 card->perf_stats.outbound_cnt++;
3688 card->perf_stats.outbound_start_time = qeth_get_micros();
3689#endif
3690 netif_stop_queue(dev);
3691 if ((rc = qeth_send_packet(card, skb))) {
3692 if (rc == -EBUSY) {
3693 return NETDEV_TX_BUSY;
3694 } else {
3695 card->stats.tx_errors++;
3696 card->stats.tx_dropped++;
3697 dev_kfree_skb_any(skb);
3698 /*set to OK; otherwise ksoftirqd goes to 100% */
3699 rc = NETDEV_TX_OK;
3700 }
3701 }
3702 netif_wake_queue(dev);
3703#ifdef CONFIG_QETH_PERF_STATS
3704 card->perf_stats.outbound_time += qeth_get_micros() -
3705 card->perf_stats.outbound_start_time;
3706#endif
3707 return rc;
3708}
3709
3710static int
3711qeth_verify_vlan_dev(struct net_device *dev, struct qeth_card *card)
3712{
3713 int rc = 0;
3714#ifdef CONFIG_QETH_VLAN
3715 struct vlan_group *vg;
3716 int i;
3717
3718 if (!(vg = card->vlangrp))
3719 return rc;
3720
3721 for (i = 0; i < VLAN_GROUP_ARRAY_LEN; i++){
3722 if (vg->vlan_devices[i] == dev){
3723 rc = QETH_VLAN_CARD;
3724 break;
3725 }
3726 }
Frank Pavlic6c6b3e72005-12-13 08:21:47 +01003727 if (rc && !(VLAN_DEV_INFO(dev)->real_dev->priv == (void *)card))
3728 return 0;
3729
Linus Torvalds1da177e2005-04-16 15:20:36 -07003730#endif
3731 return rc;
3732}
3733
3734static int
3735qeth_verify_dev(struct net_device *dev)
3736{
3737 struct qeth_card *card;
3738 unsigned long flags;
3739 int rc = 0;
3740
3741 read_lock_irqsave(&qeth_card_list.rwlock, flags);
3742 list_for_each_entry(card, &qeth_card_list.list, list){
3743 if (card->dev == dev){
3744 rc = QETH_REAL_CARD;
3745 break;
3746 }
3747 rc = qeth_verify_vlan_dev(dev, card);
3748 if (rc)
3749 break;
3750 }
3751 read_unlock_irqrestore(&qeth_card_list.rwlock, flags);
3752
3753 return rc;
3754}
3755
3756static struct qeth_card *
3757qeth_get_card_from_dev(struct net_device *dev)
3758{
3759 struct qeth_card *card = NULL;
3760 int rc;
3761
3762 rc = qeth_verify_dev(dev);
3763 if (rc == QETH_REAL_CARD)
3764 card = (struct qeth_card *)dev->priv;
3765 else if (rc == QETH_VLAN_CARD)
3766 card = (struct qeth_card *)
3767 VLAN_DEV_INFO(dev)->real_dev->priv;
3768
3769 QETH_DBF_TEXT_(trace, 4, "%d", rc);
3770 return card ;
3771}
3772
3773static void
3774qeth_tx_timeout(struct net_device *dev)
3775{
3776 struct qeth_card *card;
3777
3778 card = (struct qeth_card *) dev->priv;
3779 card->stats.tx_errors++;
3780 qeth_schedule_recovery(card);
3781}
3782
3783static int
3784qeth_open(struct net_device *dev)
3785{
3786 struct qeth_card *card;
3787
3788 QETH_DBF_TEXT(trace, 4, "qethopen");
3789
3790 card = (struct qeth_card *) dev->priv;
3791
3792 if (card->state != CARD_STATE_SOFTSETUP)
3793 return -ENODEV;
3794
Ursula Braun500f83a2005-09-30 10:19:19 +02003795 if ( (card->info.type != QETH_CARD_TYPE_OSN) &&
3796 (card->options.layer2) &&
Frank Pavlice08d88c2005-11-10 13:51:17 +01003797 (!(card->info.mac_bits & QETH_LAYER2_MAC_REGISTERED))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003798 QETH_DBF_TEXT(trace,4,"nomacadr");
3799 return -EPERM;
3800 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003801 card->data.state = CH_STATE_UP;
3802 card->state = CARD_STATE_UP;
Ursula Braunba1aa082006-05-24 09:51:13 +02003803 card->dev->flags |= IFF_UP;
3804 netif_start_queue(dev);
Jeff Garzike82b0f22006-05-26 21:58:38 -04003805
Frank Pavlic4965e972005-12-13 08:22:30 +01003806 if (!card->lan_online && netif_carrier_ok(dev))
3807 netif_carrier_off(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003808 return 0;
3809}
3810
3811static int
3812qeth_stop(struct net_device *dev)
3813{
3814 struct qeth_card *card;
3815
3816 QETH_DBF_TEXT(trace, 4, "qethstop");
3817
3818 card = (struct qeth_card *) dev->priv;
3819
Ursula Braunb85e1fa2006-05-24 09:51:11 +02003820 netif_tx_disable(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003821 card->dev->flags &= ~IFF_UP;
3822 if (card->state == CARD_STATE_UP)
3823 card->state = CARD_STATE_SOFTSETUP;
3824 return 0;
3825}
3826
3827static inline int
3828qeth_get_cast_type(struct qeth_card *card, struct sk_buff *skb)
3829{
3830 int cast_type = RTN_UNSPEC;
3831
Ursula Braun500f83a2005-09-30 10:19:19 +02003832 if (card->info.type == QETH_CARD_TYPE_OSN)
3833 return cast_type;
3834
Linus Torvalds1da177e2005-04-16 15:20:36 -07003835 if (skb->dst && skb->dst->neighbour){
3836 cast_type = skb->dst->neighbour->type;
3837 if ((cast_type == RTN_BROADCAST) ||
3838 (cast_type == RTN_MULTICAST) ||
3839 (cast_type == RTN_ANYCAST))
3840 return cast_type;
3841 else
3842 return RTN_UNSPEC;
3843 }
3844 /* try something else */
3845 if (skb->protocol == ETH_P_IPV6)
3846 return (skb->nh.raw[24] == 0xff) ? RTN_MULTICAST : 0;
3847 else if (skb->protocol == ETH_P_IP)
3848 return ((skb->nh.raw[16] & 0xf0) == 0xe0) ? RTN_MULTICAST : 0;
3849 /* ... */
3850 if (!memcmp(skb->data, skb->dev->broadcast, 6))
3851 return RTN_BROADCAST;
3852 else {
3853 u16 hdr_mac;
3854
3855 hdr_mac = *((u16 *)skb->data);
3856 /* tr multicast? */
3857 switch (card->info.link_type) {
3858 case QETH_LINK_TYPE_HSTR:
3859 case QETH_LINK_TYPE_LANE_TR:
3860 if ((hdr_mac == QETH_TR_MAC_NC) ||
3861 (hdr_mac == QETH_TR_MAC_C))
3862 return RTN_MULTICAST;
Frank Pavlic1380fee2006-03-22 16:03:41 +01003863 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003864 /* eth or so multicast? */
3865 default:
3866 if ((hdr_mac == QETH_ETH_MAC_V4) ||
3867 (hdr_mac == QETH_ETH_MAC_V6))
3868 return RTN_MULTICAST;
3869 }
3870 }
3871 return cast_type;
3872}
3873
3874static inline int
3875qeth_get_priority_queue(struct qeth_card *card, struct sk_buff *skb,
3876 int ipv, int cast_type)
3877{
3878 if (!ipv && (card->info.type == QETH_CARD_TYPE_OSAE))
3879 return card->qdio.default_out_queue;
3880 switch (card->qdio.no_out_queues) {
3881 case 4:
3882 if (cast_type && card->info.is_multicast_different)
3883 return card->info.is_multicast_different &
3884 (card->qdio.no_out_queues - 1);
3885 if (card->qdio.do_prio_queueing && (ipv == 4)) {
3886 if (card->qdio.do_prio_queueing==QETH_PRIO_Q_ING_TOS){
3887 if (skb->nh.iph->tos & IP_TOS_NOTIMPORTANT)
3888 return 3;
3889 if (skb->nh.iph->tos & IP_TOS_HIGHRELIABILITY)
3890 return 2;
3891 if (skb->nh.iph->tos & IP_TOS_HIGHTHROUGHPUT)
3892 return 1;
3893 if (skb->nh.iph->tos & IP_TOS_LOWDELAY)
3894 return 0;
3895 }
3896 if (card->qdio.do_prio_queueing==QETH_PRIO_Q_ING_PREC)
3897 return 3 - (skb->nh.iph->tos >> 6);
3898 } else if (card->qdio.do_prio_queueing && (ipv == 6)) {
3899 /* TODO: IPv6!!! */
3900 }
3901 return card->qdio.default_out_queue;
3902 case 1: /* fallthrough for single-out-queue 1920-device */
3903 default:
3904 return card->qdio.default_out_queue;
3905 }
3906}
3907
3908static inline int
3909qeth_get_ip_version(struct sk_buff *skb)
3910{
3911 switch (skb->protocol) {
3912 case ETH_P_IPV6:
3913 return 6;
3914 case ETH_P_IP:
3915 return 4;
3916 default:
3917 return 0;
3918 }
3919}
3920
3921static inline int
3922qeth_prepare_skb(struct qeth_card *card, struct sk_buff **skb,
3923 struct qeth_hdr **hdr, int ipv)
3924{
Ursula Braun500f83a2005-09-30 10:19:19 +02003925 int rc = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003926#ifdef CONFIG_QETH_VLAN
3927 u16 *tag;
3928#endif
3929
3930 QETH_DBF_TEXT(trace, 6, "prepskb");
Ursula Braun500f83a2005-09-30 10:19:19 +02003931 if (card->info.type == QETH_CARD_TYPE_OSN) {
3932 *hdr = (struct qeth_hdr *)(*skb)->data;
3933 return rc;
3934 }
Frank Pavlic9cb90de2005-09-14 18:03:26 +02003935 rc = qeth_realloc_headroom(card, skb, sizeof(struct qeth_hdr));
3936 if (rc)
3937 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003938#ifdef CONFIG_QETH_VLAN
3939 if (card->vlangrp && vlan_tx_tag_present(*skb) &&
3940 ((ipv == 6) || card->options.layer2) ) {
3941 /*
3942 * Move the mac addresses (6 bytes src, 6 bytes dest)
3943 * to the beginning of the new header. We are using three
3944 * memcpys instead of one memmove to save cycles.
3945 */
3946 skb_push(*skb, VLAN_HLEN);
3947 memcpy((*skb)->data, (*skb)->data + 4, 4);
3948 memcpy((*skb)->data + 4, (*skb)->data + 8, 4);
3949 memcpy((*skb)->data + 8, (*skb)->data + 12, 4);
3950 tag = (u16 *)((*skb)->data + 12);
3951 /*
3952 * first two bytes = ETH_P_8021Q (0x8100)
3953 * second two bytes = VLANID
3954 */
3955 *tag = __constant_htons(ETH_P_8021Q);
3956 *(tag + 1) = htons(vlan_tx_tag_get(*skb));
3957 }
3958#endif
3959 *hdr = (struct qeth_hdr *)
3960 qeth_push_skb(card, skb, sizeof(struct qeth_hdr));
Ursula Braunba1aa082006-05-24 09:51:13 +02003961 if (*hdr == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003962 return -EINVAL;
3963 return 0;
3964}
3965
3966static inline u8
3967qeth_get_qeth_hdr_flags4(int cast_type)
3968{
3969 if (cast_type == RTN_MULTICAST)
3970 return QETH_CAST_MULTICAST;
3971 if (cast_type == RTN_BROADCAST)
3972 return QETH_CAST_BROADCAST;
3973 return QETH_CAST_UNICAST;
3974}
3975
3976static inline u8
3977qeth_get_qeth_hdr_flags6(int cast_type)
3978{
3979 u8 ct = QETH_HDR_PASSTHRU | QETH_HDR_IPV6;
3980 if (cast_type == RTN_MULTICAST)
3981 return ct | QETH_CAST_MULTICAST;
3982 if (cast_type == RTN_ANYCAST)
3983 return ct | QETH_CAST_ANYCAST;
3984 if (cast_type == RTN_BROADCAST)
3985 return ct | QETH_CAST_BROADCAST;
3986 return ct | QETH_CAST_UNICAST;
3987}
3988
3989static inline void
3990qeth_layer2_get_packet_type(struct qeth_card *card, struct qeth_hdr *hdr,
3991 struct sk_buff *skb)
3992{
3993 __u16 hdr_mac;
3994
3995 if (!memcmp(skb->data+QETH_HEADER_SIZE,
3996 skb->dev->broadcast,6)) { /* broadcast? */
3997 *(__u32 *)hdr->hdr.l2.flags |=
3998 QETH_LAYER2_FLAG_BROADCAST << 8;
3999 return;
4000 }
4001 hdr_mac=*((__u16*)skb->data);
4002 /* tr multicast? */
4003 switch (card->info.link_type) {
4004 case QETH_LINK_TYPE_HSTR:
4005 case QETH_LINK_TYPE_LANE_TR:
4006 if ((hdr_mac == QETH_TR_MAC_NC) ||
4007 (hdr_mac == QETH_TR_MAC_C) )
4008 *(__u32 *)hdr->hdr.l2.flags |=
4009 QETH_LAYER2_FLAG_MULTICAST << 8;
4010 else
4011 *(__u32 *)hdr->hdr.l2.flags |=
4012 QETH_LAYER2_FLAG_UNICAST << 8;
4013 break;
4014 /* eth or so multicast? */
4015 default:
4016 if ( (hdr_mac==QETH_ETH_MAC_V4) ||
4017 (hdr_mac==QETH_ETH_MAC_V6) )
4018 *(__u32 *)hdr->hdr.l2.flags |=
4019 QETH_LAYER2_FLAG_MULTICAST << 8;
4020 else
4021 *(__u32 *)hdr->hdr.l2.flags |=
4022 QETH_LAYER2_FLAG_UNICAST << 8;
4023 }
4024}
4025
4026static inline void
4027qeth_layer2_fill_header(struct qeth_card *card, struct qeth_hdr *hdr,
4028 struct sk_buff *skb, int cast_type)
4029{
4030 memset(hdr, 0, sizeof(struct qeth_hdr));
4031 hdr->hdr.l2.id = QETH_HEADER_TYPE_LAYER2;
4032
4033 /* set byte 0 to "0x02" and byte 3 to casting flags */
4034 if (cast_type==RTN_MULTICAST)
4035 *(__u32 *)hdr->hdr.l2.flags |= QETH_LAYER2_FLAG_MULTICAST << 8;
4036 else if (cast_type==RTN_BROADCAST)
4037 *(__u32 *)hdr->hdr.l2.flags |= QETH_LAYER2_FLAG_BROADCAST << 8;
4038 else
4039 qeth_layer2_get_packet_type(card, hdr, skb);
4040
4041 hdr->hdr.l2.pkt_length = skb->len-QETH_HEADER_SIZE;
4042#ifdef CONFIG_QETH_VLAN
4043 /* VSWITCH relies on the VLAN
4044 * information to be present in
4045 * the QDIO header */
4046 if ((card->vlangrp != NULL) &&
4047 vlan_tx_tag_present(skb)) {
4048 *(__u32 *)hdr->hdr.l2.flags |= QETH_LAYER2_FLAG_VLAN << 8;
4049 hdr->hdr.l2.vlan_id = vlan_tx_tag_get(skb);
4050 }
4051#endif
4052}
4053
4054void
4055qeth_fill_header(struct qeth_card *card, struct qeth_hdr *hdr,
4056 struct sk_buff *skb, int ipv, int cast_type)
4057{
4058 QETH_DBF_TEXT(trace, 6, "fillhdr");
4059
4060 memset(hdr, 0, sizeof(struct qeth_hdr));
4061 if (card->options.layer2) {
4062 qeth_layer2_fill_header(card, hdr, skb, cast_type);
4063 return;
4064 }
4065 hdr->hdr.l3.id = QETH_HEADER_TYPE_LAYER3;
4066 hdr->hdr.l3.ext_flags = 0;
4067#ifdef CONFIG_QETH_VLAN
4068 /*
4069 * before we're going to overwrite this location with next hop ip.
4070 * v6 uses passthrough, v4 sets the tag in the QDIO header.
4071 */
4072 if (card->vlangrp && vlan_tx_tag_present(skb)) {
4073 hdr->hdr.l3.ext_flags = (ipv == 4) ?
4074 QETH_HDR_EXT_VLAN_FRAME :
4075 QETH_HDR_EXT_INCLUDE_VLAN_TAG;
4076 hdr->hdr.l3.vlan_id = vlan_tx_tag_get(skb);
4077 }
4078#endif /* CONFIG_QETH_VLAN */
4079 hdr->hdr.l3.length = skb->len - sizeof(struct qeth_hdr);
4080 if (ipv == 4) { /* IPv4 */
4081 hdr->hdr.l3.flags = qeth_get_qeth_hdr_flags4(cast_type);
4082 memset(hdr->hdr.l3.dest_addr, 0, 12);
4083 if ((skb->dst) && (skb->dst->neighbour)) {
4084 *((u32 *) (&hdr->hdr.l3.dest_addr[12])) =
4085 *((u32 *) skb->dst->neighbour->primary_key);
4086 } else {
4087 /* fill in destination address used in ip header */
4088 *((u32 *) (&hdr->hdr.l3.dest_addr[12])) = skb->nh.iph->daddr;
4089 }
4090 } else if (ipv == 6) { /* IPv6 or passthru */
4091 hdr->hdr.l3.flags = qeth_get_qeth_hdr_flags6(cast_type);
4092 if ((skb->dst) && (skb->dst->neighbour)) {
4093 memcpy(hdr->hdr.l3.dest_addr,
4094 skb->dst->neighbour->primary_key, 16);
4095 } else {
4096 /* fill in destination address used in ip header */
4097 memcpy(hdr->hdr.l3.dest_addr, &skb->nh.ipv6h->daddr, 16);
4098 }
4099 } else { /* passthrough */
Frank Pavlice23dd9c2005-05-12 20:38:11 +02004100 if((skb->dev->type == ARPHRD_IEEE802_TR) &&
Jeff Garzike82b0f22006-05-26 21:58:38 -04004101 !memcmp(skb->data + sizeof(struct qeth_hdr) +
Frank Pavlic9a455812005-05-12 20:38:28 +02004102 sizeof(__u16), skb->dev->broadcast, 6)) {
4103 hdr->hdr.l3.flags = QETH_CAST_BROADCAST |
4104 QETH_HDR_PASSTHRU;
Frank Pavlice23dd9c2005-05-12 20:38:11 +02004105 } else if (!memcmp(skb->data + sizeof(struct qeth_hdr),
Linus Torvalds1da177e2005-04-16 15:20:36 -07004106 skb->dev->broadcast, 6)) { /* broadcast? */
Frank Pavlice23dd9c2005-05-12 20:38:11 +02004107 hdr->hdr.l3.flags = QETH_CAST_BROADCAST |
4108 QETH_HDR_PASSTHRU;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004109 } else {
4110 hdr->hdr.l3.flags = (cast_type == RTN_MULTICAST) ?
4111 QETH_CAST_MULTICAST | QETH_HDR_PASSTHRU :
4112 QETH_CAST_UNICAST | QETH_HDR_PASSTHRU;
4113 }
4114 }
4115}
4116
4117static inline void
Linus Torvalds1da177e2005-04-16 15:20:36 -07004118__qeth_fill_buffer(struct sk_buff *skb, struct qdio_buffer *buffer,
Frank Pavlic05e08a22005-05-12 20:39:09 +02004119 int is_tso, int *next_element_to_fill)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004120{
4121 int length = skb->len;
4122 int length_here;
4123 int element;
4124 char *data;
Frank Pavlic05e08a22005-05-12 20:39:09 +02004125 int first_lap ;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004126
4127 element = *next_element_to_fill;
4128 data = skb->data;
Frank Pavlic05e08a22005-05-12 20:39:09 +02004129 first_lap = (is_tso == 0 ? 1 : 0);
4130
Linus Torvalds1da177e2005-04-16 15:20:36 -07004131 while (length > 0) {
4132 /* length_here is the remaining amount of data in this page */
4133 length_here = PAGE_SIZE - ((unsigned long) data % PAGE_SIZE);
4134 if (length < length_here)
4135 length_here = length;
Frank Pavlic05e08a22005-05-12 20:39:09 +02004136
Linus Torvalds1da177e2005-04-16 15:20:36 -07004137 buffer->element[element].addr = data;
4138 buffer->element[element].length = length_here;
4139 length -= length_here;
Frank Pavlic05e08a22005-05-12 20:39:09 +02004140 if (!length) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004141 if (first_lap)
4142 buffer->element[element].flags = 0;
4143 else
4144 buffer->element[element].flags =
4145 SBAL_FLAGS_LAST_FRAG;
4146 } else {
4147 if (first_lap)
4148 buffer->element[element].flags =
4149 SBAL_FLAGS_FIRST_FRAG;
4150 else
4151 buffer->element[element].flags =
4152 SBAL_FLAGS_MIDDLE_FRAG;
4153 }
4154 data += length_here;
4155 element++;
4156 first_lap = 0;
4157 }
4158 *next_element_to_fill = element;
4159}
4160
4161static inline int
4162qeth_fill_buffer(struct qeth_qdio_out_q *queue,
4163 struct qeth_qdio_out_buffer *buf,
4164 struct sk_buff *skb)
4165{
4166 struct qdio_buffer *buffer;
Frank Pavlic05e08a22005-05-12 20:39:09 +02004167 struct qeth_hdr_tso *hdr;
4168 int flush_cnt = 0, hdr_len, large_send = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004169
4170 QETH_DBF_TEXT(trace, 6, "qdfillbf");
Frank Pavlic05e08a22005-05-12 20:39:09 +02004171
Linus Torvalds1da177e2005-04-16 15:20:36 -07004172 buffer = buf->buffer;
4173 atomic_inc(&skb->users);
4174 skb_queue_tail(&buf->skb_list, skb);
Frank Pavlic05e08a22005-05-12 20:39:09 +02004175
4176 hdr = (struct qeth_hdr_tso *) skb->data;
4177 /*check first on TSO ....*/
4178 if (hdr->hdr.hdr.l3.id == QETH_HEADER_TYPE_TSO) {
4179 int element = buf->next_element_to_fill;
4180
4181 hdr_len = sizeof(struct qeth_hdr_tso) + hdr->ext.dg_hdr_len;
4182 /*fill first buffer entry only with header information */
4183 buffer->element[element].addr = skb->data;
4184 buffer->element[element].length = hdr_len;
4185 buffer->element[element].flags = SBAL_FLAGS_FIRST_FRAG;
4186 buf->next_element_to_fill++;
4187 skb->data += hdr_len;
4188 skb->len -= hdr_len;
4189 large_send = 1;
4190 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004191 if (skb_shinfo(skb)->nr_frags == 0)
Frank Pavlic05e08a22005-05-12 20:39:09 +02004192 __qeth_fill_buffer(skb, buffer, large_send,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004193 (int *)&buf->next_element_to_fill);
4194 else
Frank Pavlic05e08a22005-05-12 20:39:09 +02004195 __qeth_fill_buffer_frag(skb, buffer, large_send,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004196 (int *)&buf->next_element_to_fill);
4197
4198 if (!queue->do_pack) {
4199 QETH_DBF_TEXT(trace, 6, "fillbfnp");
4200 /* set state to PRIMED -> will be flushed */
4201 atomic_set(&buf->state, QETH_QDIO_BUF_PRIMED);
4202 flush_cnt = 1;
4203 } else {
4204 QETH_DBF_TEXT(trace, 6, "fillbfpa");
4205#ifdef CONFIG_QETH_PERF_STATS
4206 queue->card->perf_stats.skbs_sent_pack++;
4207#endif
4208 if (buf->next_element_to_fill >=
4209 QETH_MAX_BUFFER_ELEMENTS(queue->card)) {
4210 /*
4211 * packed buffer if full -> set state PRIMED
4212 * -> will be flushed
4213 */
4214 atomic_set(&buf->state, QETH_QDIO_BUF_PRIMED);
4215 flush_cnt = 1;
4216 }
4217 }
4218 return flush_cnt;
4219}
4220
4221static inline int
4222qeth_do_send_packet_fast(struct qeth_card *card, struct qeth_qdio_out_q *queue,
4223 struct sk_buff *skb, struct qeth_hdr *hdr,
4224 int elements_needed,
4225 struct qeth_eddp_context *ctx)
4226{
4227 struct qeth_qdio_out_buffer *buffer;
4228 int buffers_needed = 0;
4229 int flush_cnt = 0;
4230 int index;
4231
4232 QETH_DBF_TEXT(trace, 6, "dosndpfa");
4233
4234 /* spin until we get the queue ... */
Martin Schwidefsky973bd992006-01-06 00:19:07 -08004235 while (atomic_cmpxchg(&queue->state, QETH_OUT_Q_UNLOCKED,
4236 QETH_OUT_Q_LOCKED) != QETH_OUT_Q_UNLOCKED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004237 /* ... now we've got the queue */
4238 index = queue->next_buf_to_fill;
4239 buffer = &queue->bufs[queue->next_buf_to_fill];
4240 /*
4241 * check if buffer is empty to make sure that we do not 'overtake'
4242 * ourselves and try to fill a buffer that is already primed
4243 */
4244 if (atomic_read(&buffer->state) != QETH_QDIO_BUF_EMPTY) {
4245 card->stats.tx_dropped++;
4246 atomic_set(&queue->state, QETH_OUT_Q_UNLOCKED);
4247 return -EBUSY;
4248 }
4249 if (ctx == NULL)
4250 queue->next_buf_to_fill = (queue->next_buf_to_fill + 1) %
4251 QDIO_MAX_BUFFERS_PER_Q;
4252 else {
4253 buffers_needed = qeth_eddp_check_buffers_for_context(queue,ctx);
4254 if (buffers_needed < 0) {
4255 card->stats.tx_dropped++;
4256 atomic_set(&queue->state, QETH_OUT_Q_UNLOCKED);
4257 return -EBUSY;
4258 }
4259 queue->next_buf_to_fill =
4260 (queue->next_buf_to_fill + buffers_needed) %
4261 QDIO_MAX_BUFFERS_PER_Q;
4262 }
4263 atomic_set(&queue->state, QETH_OUT_Q_UNLOCKED);
4264 if (ctx == NULL) {
4265 qeth_fill_buffer(queue, buffer, skb);
4266 qeth_flush_buffers(queue, 0, index, 1);
4267 } else {
4268 flush_cnt = qeth_eddp_fill_buffer(queue, ctx, index);
4269 WARN_ON(buffers_needed != flush_cnt);
4270 qeth_flush_buffers(queue, 0, index, flush_cnt);
4271 }
4272 return 0;
4273}
4274
4275static inline int
4276qeth_do_send_packet(struct qeth_card *card, struct qeth_qdio_out_q *queue,
4277 struct sk_buff *skb, struct qeth_hdr *hdr,
4278 int elements_needed, struct qeth_eddp_context *ctx)
4279{
4280 struct qeth_qdio_out_buffer *buffer;
4281 int start_index;
4282 int flush_count = 0;
4283 int do_pack = 0;
4284 int tmp;
4285 int rc = 0;
4286
4287 QETH_DBF_TEXT(trace, 6, "dosndpkt");
4288
4289 /* spin until we get the queue ... */
Martin Schwidefsky973bd992006-01-06 00:19:07 -08004290 while (atomic_cmpxchg(&queue->state, QETH_OUT_Q_UNLOCKED,
4291 QETH_OUT_Q_LOCKED) != QETH_OUT_Q_UNLOCKED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004292 start_index = queue->next_buf_to_fill;
4293 buffer = &queue->bufs[queue->next_buf_to_fill];
4294 /*
4295 * check if buffer is empty to make sure that we do not 'overtake'
4296 * ourselves and try to fill a buffer that is already primed
4297 */
4298 if (atomic_read(&buffer->state) != QETH_QDIO_BUF_EMPTY){
4299 card->stats.tx_dropped++;
4300 atomic_set(&queue->state, QETH_OUT_Q_UNLOCKED);
4301 return -EBUSY;
4302 }
4303 /* check if we need to switch packing state of this queue */
4304 qeth_switch_to_packing_if_needed(queue);
4305 if (queue->do_pack){
4306 do_pack = 1;
4307 if (ctx == NULL) {
4308 /* does packet fit in current buffer? */
4309 if((QETH_MAX_BUFFER_ELEMENTS(card) -
4310 buffer->next_element_to_fill) < elements_needed){
4311 /* ... no -> set state PRIMED */
4312 atomic_set(&buffer->state,QETH_QDIO_BUF_PRIMED);
4313 flush_count++;
4314 queue->next_buf_to_fill =
4315 (queue->next_buf_to_fill + 1) %
4316 QDIO_MAX_BUFFERS_PER_Q;
4317 buffer = &queue->bufs[queue->next_buf_to_fill];
4318 /* we did a step forward, so check buffer state
4319 * again */
4320 if (atomic_read(&buffer->state) !=
4321 QETH_QDIO_BUF_EMPTY){
4322 card->stats.tx_dropped++;
4323 qeth_flush_buffers(queue, 0, start_index, flush_count);
4324 atomic_set(&queue->state, QETH_OUT_Q_UNLOCKED);
4325 return -EBUSY;
4326 }
4327 }
4328 } else {
4329 /* check if we have enough elements (including following
4330 * free buffers) to handle eddp context */
4331 if (qeth_eddp_check_buffers_for_context(queue,ctx) < 0){
4332 printk("eddp tx_dropped 1\n");
4333 card->stats.tx_dropped++;
4334 rc = -EBUSY;
4335 goto out;
4336 }
4337 }
4338 }
4339 if (ctx == NULL)
4340 tmp = qeth_fill_buffer(queue, buffer, skb);
4341 else {
4342 tmp = qeth_eddp_fill_buffer(queue,ctx,queue->next_buf_to_fill);
4343 if (tmp < 0) {
4344 printk("eddp tx_dropped 2\n");
4345 card->stats.tx_dropped++;
4346 rc = - EBUSY;
4347 goto out;
4348 }
4349 }
4350 queue->next_buf_to_fill = (queue->next_buf_to_fill + tmp) %
4351 QDIO_MAX_BUFFERS_PER_Q;
4352 flush_count += tmp;
4353out:
4354 if (flush_count)
4355 qeth_flush_buffers(queue, 0, start_index, flush_count);
Frank Pavlicd805d7c2005-11-10 13:50:58 +01004356 else if (!atomic_read(&queue->set_pci_flags_count))
4357 atomic_swap(&queue->state, QETH_OUT_Q_LOCKED_FLUSH);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004358 /*
4359 * queue->state will go from LOCKED -> UNLOCKED or from
4360 * LOCKED_FLUSH -> LOCKED if output_handler wanted to 'notify' us
4361 * (switch packing state or flush buffer to get another pci flag out).
4362 * In that case we will enter this loop
4363 */
4364 while (atomic_dec_return(&queue->state)){
4365 flush_count = 0;
4366 start_index = queue->next_buf_to_fill;
4367 /* check if we can go back to non-packing state */
4368 flush_count += qeth_switch_to_nonpacking_if_needed(queue);
4369 /*
4370 * check if we need to flush a packing buffer to get a pci
4371 * flag out on the queue
4372 */
4373 if (!flush_count && !atomic_read(&queue->set_pci_flags_count))
4374 flush_count += qeth_flush_buffers_on_no_pci(queue);
4375 if (flush_count)
4376 qeth_flush_buffers(queue, 0, start_index, flush_count);
4377 }
4378 /* at this point the queue is UNLOCKED again */
4379#ifdef CONFIG_QETH_PERF_STATS
4380 if (do_pack)
4381 queue->card->perf_stats.bufs_sent_pack += flush_count;
4382#endif /* CONFIG_QETH_PERF_STATS */
4383
4384 return rc;
4385}
4386
4387static inline int
Jeff Garzike82b0f22006-05-26 21:58:38 -04004388qeth_get_elements_no(struct qeth_card *card, void *hdr,
Frank Pavlic9cb90de2005-09-14 18:03:26 +02004389 struct sk_buff *skb, int elems)
Frank Pavlic05e08a22005-05-12 20:39:09 +02004390{
4391 int elements_needed = 0;
4392
4393 if (skb_shinfo(skb)->nr_frags > 0) {
4394 elements_needed = (skb_shinfo(skb)->nr_frags + 1);
4395 }
4396 if (elements_needed == 0 )
4397 elements_needed = 1 + (((((unsigned long) hdr) % PAGE_SIZE)
4398 + skb->len) >> PAGE_SHIFT);
Frank Pavlic9cb90de2005-09-14 18:03:26 +02004399 if ((elements_needed + elems) > QETH_MAX_BUFFER_ELEMENTS(card)){
Frank Pavlic05e08a22005-05-12 20:39:09 +02004400 PRINT_ERR("qeth_do_send_packet: invalid size of "
Frank Pavlic9cb90de2005-09-14 18:03:26 +02004401 "IP packet (Number=%d / Length=%d). Discarded.\n",
4402 (elements_needed+elems), skb->len);
Frank Pavlic05e08a22005-05-12 20:39:09 +02004403 return 0;
4404 }
4405 return elements_needed;
4406}
4407
4408static inline int
Linus Torvalds1da177e2005-04-16 15:20:36 -07004409qeth_send_packet(struct qeth_card *card, struct sk_buff *skb)
4410{
4411 int ipv = 0;
4412 int cast_type;
4413 struct qeth_qdio_out_q *queue;
Frank Pavlicf3d242e2005-09-14 18:05:31 +02004414 struct qeth_hdr *hdr = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004415 int elements_needed = 0;
4416 enum qeth_large_send_types large_send = QETH_LARGE_SEND_NO;
4417 struct qeth_eddp_context *ctx = NULL;
Frank Pavlic95f6b5a2006-03-22 16:03:39 +01004418 int tx_bytes = skb->len;
Ursula Braunba1aa082006-05-24 09:51:13 +02004419 unsigned short nr_frags = skb_shinfo(skb)->nr_frags;
Herbert Xu79671682006-06-22 02:40:14 -07004420 unsigned short tso_size = skb_shinfo(skb)->gso_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004421 int rc;
4422
4423 QETH_DBF_TEXT(trace, 6, "sendpkt");
4424
4425 if (!card->options.layer2) {
4426 ipv = qeth_get_ip_version(skb);
4427 if ((card->dev->hard_header == qeth_fake_header) && ipv) {
4428 if ((skb = qeth_pskb_unshare(skb,GFP_ATOMIC)) == NULL) {
4429 card->stats.tx_dropped++;
4430 dev_kfree_skb_irq(skb);
4431 return 0;
4432 }
Frank Pavlice23dd9c2005-05-12 20:38:11 +02004433 if(card->dev->type == ARPHRD_IEEE802_TR){
4434 skb_pull(skb, QETH_FAKE_LL_LEN_TR);
4435 } else {
4436 skb_pull(skb, QETH_FAKE_LL_LEN_ETH);
4437 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004438 }
4439 }
Ursula Braun500f83a2005-09-30 10:19:19 +02004440 if ((card->info.type == QETH_CARD_TYPE_OSN) &&
4441 (skb->protocol == htons(ETH_P_IPV6))) {
4442 dev_kfree_skb_any(skb);
4443 return 0;
4444 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004445 cast_type = qeth_get_cast_type(card, skb);
Jeff Garzike82b0f22006-05-26 21:58:38 -04004446 if ((cast_type == RTN_BROADCAST) &&
Ursula Braun500f83a2005-09-30 10:19:19 +02004447 (card->info.broadcast_capable == 0)){
Linus Torvalds1da177e2005-04-16 15:20:36 -07004448 card->stats.tx_dropped++;
4449 card->stats.tx_errors++;
4450 dev_kfree_skb_any(skb);
4451 return NETDEV_TX_OK;
4452 }
4453 queue = card->qdio.out_qs
4454 [qeth_get_priority_queue(card, skb, ipv, cast_type)];
4455
Herbert Xu79671682006-06-22 02:40:14 -07004456 if (skb_shinfo(skb)->gso_size)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004457 large_send = card->options.large_send;
4458
Linus Torvalds1da177e2005-04-16 15:20:36 -07004459 /*are we able to do TSO ? If so ,prepare and send it from here */
4460 if ((large_send == QETH_LARGE_SEND_TSO) &&
4461 (cast_type == RTN_UNSPEC)) {
Frank Pavlic05e08a22005-05-12 20:39:09 +02004462 rc = qeth_tso_prepare_packet(card, skb, ipv, cast_type);
4463 if (rc) {
4464 card->stats.tx_dropped++;
4465 card->stats.tx_errors++;
4466 dev_kfree_skb_any(skb);
4467 return NETDEV_TX_OK;
Jeff Garzike82b0f22006-05-26 21:58:38 -04004468 }
Frank Pavlic05e08a22005-05-12 20:39:09 +02004469 elements_needed++;
4470 } else {
4471 if ((rc = qeth_prepare_skb(card, &skb, &hdr, ipv))) {
4472 QETH_DBF_TEXT_(trace, 4, "pskbe%d", rc);
4473 return rc;
4474 }
Ursula Braun500f83a2005-09-30 10:19:19 +02004475 if (card->info.type != QETH_CARD_TYPE_OSN)
4476 qeth_fill_header(card, hdr, skb, ipv, cast_type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004477 }
4478
Linus Torvalds1da177e2005-04-16 15:20:36 -07004479 if (large_send == QETH_LARGE_SEND_EDDP) {
4480 ctx = qeth_eddp_create_context(card, skb, hdr);
4481 if (ctx == NULL) {
4482 PRINT_WARN("could not create eddp context\n");
4483 return -EINVAL;
4484 }
4485 } else {
Frank Pavlic9cb90de2005-09-14 18:03:26 +02004486 int elems = qeth_get_elements_no(card,(void*) hdr, skb,
4487 elements_needed);
4488 if (!elems)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004489 return -EINVAL;
Frank Pavlic9cb90de2005-09-14 18:03:26 +02004490 elements_needed += elems;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004491 }
4492
4493 if (card->info.type != QETH_CARD_TYPE_IQD)
4494 rc = qeth_do_send_packet(card, queue, skb, hdr,
4495 elements_needed, ctx);
4496 else
4497 rc = qeth_do_send_packet_fast(card, queue, skb, hdr,
4498 elements_needed, ctx);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004499 if (!rc){
4500 card->stats.tx_packets++;
Frank Pavlic95f6b5a2006-03-22 16:03:39 +01004501 card->stats.tx_bytes += tx_bytes;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004502#ifdef CONFIG_QETH_PERF_STATS
Ursula Braunba1aa082006-05-24 09:51:13 +02004503 if (tso_size &&
Frank Pavlic05e08a22005-05-12 20:39:09 +02004504 !(large_send == QETH_LARGE_SEND_NO)) {
Ursula Braunba1aa082006-05-24 09:51:13 +02004505 card->perf_stats.large_send_bytes += tx_bytes;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004506 card->perf_stats.large_send_cnt++;
4507 }
Ursula Braunba1aa082006-05-24 09:51:13 +02004508 if (nr_frags > 0){
Linus Torvalds1da177e2005-04-16 15:20:36 -07004509 card->perf_stats.sg_skbs_sent++;
4510 /* nr_frags + skb->data */
4511 card->perf_stats.sg_frags_sent +=
Ursula Braunba1aa082006-05-24 09:51:13 +02004512 nr_frags + 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004513 }
4514#endif /* CONFIG_QETH_PERF_STATS */
4515 }
4516 if (ctx != NULL) {
4517 /* drop creator's reference */
4518 qeth_eddp_put_context(ctx);
4519 /* free skb; it's not referenced by a buffer */
4520 if (rc == 0)
4521 dev_kfree_skb_any(skb);
4522
4523 }
4524 return rc;
4525}
4526
4527static int
4528qeth_mdio_read(struct net_device *dev, int phy_id, int regnum)
4529{
4530 struct qeth_card *card = (struct qeth_card *) dev->priv;
4531 int rc = 0;
4532
4533 switch(regnum){
4534 case MII_BMCR: /* Basic mode control register */
4535 rc = BMCR_FULLDPLX;
4536 if ((card->info.link_type != QETH_LINK_TYPE_GBIT_ETH)&&
Ursula Braun500f83a2005-09-30 10:19:19 +02004537 (card->info.link_type != QETH_LINK_TYPE_OSN) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07004538 (card->info.link_type != QETH_LINK_TYPE_10GBIT_ETH))
4539 rc |= BMCR_SPEED100;
4540 break;
4541 case MII_BMSR: /* Basic mode status register */
4542 rc = BMSR_ERCAP | BMSR_ANEGCOMPLETE | BMSR_LSTATUS |
4543 BMSR_10HALF | BMSR_10FULL | BMSR_100HALF | BMSR_100FULL |
4544 BMSR_100BASE4;
4545 break;
4546 case MII_PHYSID1: /* PHYS ID 1 */
4547 rc = (dev->dev_addr[0] << 16) | (dev->dev_addr[1] << 8) |
4548 dev->dev_addr[2];
4549 rc = (rc >> 5) & 0xFFFF;
4550 break;
4551 case MII_PHYSID2: /* PHYS ID 2 */
4552 rc = (dev->dev_addr[2] << 10) & 0xFFFF;
4553 break;
4554 case MII_ADVERTISE: /* Advertisement control reg */
4555 rc = ADVERTISE_ALL;
4556 break;
4557 case MII_LPA: /* Link partner ability reg */
4558 rc = LPA_10HALF | LPA_10FULL | LPA_100HALF | LPA_100FULL |
4559 LPA_100BASE4 | LPA_LPACK;
4560 break;
4561 case MII_EXPANSION: /* Expansion register */
4562 break;
4563 case MII_DCOUNTER: /* disconnect counter */
4564 break;
4565 case MII_FCSCOUNTER: /* false carrier counter */
4566 break;
4567 case MII_NWAYTEST: /* N-way auto-neg test register */
4568 break;
4569 case MII_RERRCOUNTER: /* rx error counter */
4570 rc = card->stats.rx_errors;
4571 break;
4572 case MII_SREVISION: /* silicon revision */
4573 break;
4574 case MII_RESV1: /* reserved 1 */
4575 break;
4576 case MII_LBRERROR: /* loopback, rx, bypass error */
4577 break;
4578 case MII_PHYADDR: /* physical address */
4579 break;
4580 case MII_RESV2: /* reserved 2 */
4581 break;
4582 case MII_TPISTATUS: /* TPI status for 10mbps */
4583 break;
4584 case MII_NCONFIG: /* network interface config */
4585 break;
4586 default:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004587 break;
4588 }
4589 return rc;
4590}
4591
Linus Torvalds1da177e2005-04-16 15:20:36 -07004592
4593static inline const char *
4594qeth_arp_get_error_cause(int *rc)
4595{
4596 switch (*rc) {
4597 case QETH_IPA_ARP_RC_FAILED:
4598 *rc = -EIO;
4599 return "operation failed";
4600 case QETH_IPA_ARP_RC_NOTSUPP:
4601 *rc = -EOPNOTSUPP;
4602 return "operation not supported";
4603 case QETH_IPA_ARP_RC_OUT_OF_RANGE:
4604 *rc = -EINVAL;
4605 return "argument out of range";
4606 case QETH_IPA_ARP_RC_Q_NOTSUPP:
4607 *rc = -EOPNOTSUPP;
4608 return "query operation not supported";
4609 case QETH_IPA_ARP_RC_Q_NO_DATA:
4610 *rc = -ENOENT;
4611 return "no query data available";
4612 default:
4613 return "unknown error";
4614 }
4615}
4616
4617static int
4618qeth_send_simple_setassparms(struct qeth_card *, enum qeth_ipa_funcs,
4619 __u16, long);
4620
4621static int
4622qeth_arp_set_no_entries(struct qeth_card *card, int no_entries)
4623{
4624 int tmp;
4625 int rc;
4626
4627 QETH_DBF_TEXT(trace,3,"arpstnoe");
4628
Frank Pavlicf3d242e2005-09-14 18:05:31 +02004629 /*
4630 * currently GuestLAN only supports the ARP assist function
4631 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_SET_NO_ENTRIES;
4632 * thus we say EOPNOTSUPP for this ARP function
4633 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07004634 if (card->info.guestlan)
4635 return -EOPNOTSUPP;
4636 if (!qeth_is_supported(card,IPA_ARP_PROCESSING)) {
4637 PRINT_WARN("ARP processing not supported "
4638 "on %s!\n", QETH_CARD_IFNAME(card));
4639 return -EOPNOTSUPP;
4640 }
4641 rc = qeth_send_simple_setassparms(card, IPA_ARP_PROCESSING,
4642 IPA_CMD_ASS_ARP_SET_NO_ENTRIES,
4643 no_entries);
4644 if (rc) {
4645 tmp = rc;
4646 PRINT_WARN("Could not set number of ARP entries on %s: "
4647 "%s (0x%x/%d)\n",
4648 QETH_CARD_IFNAME(card), qeth_arp_get_error_cause(&rc),
4649 tmp, tmp);
4650 }
4651 return rc;
4652}
4653
4654static inline void
4655qeth_copy_arp_entries_stripped(struct qeth_arp_query_info *qinfo,
4656 struct qeth_arp_query_data *qdata,
4657 int entry_size, int uentry_size)
4658{
4659 char *entry_ptr;
4660 char *uentry_ptr;
4661 int i;
4662
4663 entry_ptr = (char *)&qdata->data;
4664 uentry_ptr = (char *)(qinfo->udata + qinfo->udata_offset);
4665 for (i = 0; i < qdata->no_entries; ++i){
4666 /* strip off 32 bytes "media specific information" */
4667 memcpy(uentry_ptr, (entry_ptr + 32), entry_size - 32);
4668 entry_ptr += entry_size;
4669 uentry_ptr += uentry_size;
4670 }
4671}
4672
4673static int
4674qeth_arp_query_cb(struct qeth_card *card, struct qeth_reply *reply,
4675 unsigned long data)
4676{
4677 struct qeth_ipa_cmd *cmd;
4678 struct qeth_arp_query_data *qdata;
4679 struct qeth_arp_query_info *qinfo;
4680 int entry_size;
4681 int uentry_size;
4682 int i;
4683
4684 QETH_DBF_TEXT(trace,4,"arpquecb");
4685
4686 qinfo = (struct qeth_arp_query_info *) reply->param;
4687 cmd = (struct qeth_ipa_cmd *) data;
4688 if (cmd->hdr.return_code) {
4689 QETH_DBF_TEXT_(trace,4,"qaer1%i", cmd->hdr.return_code);
4690 return 0;
4691 }
4692 if (cmd->data.setassparms.hdr.return_code) {
4693 cmd->hdr.return_code = cmd->data.setassparms.hdr.return_code;
4694 QETH_DBF_TEXT_(trace,4,"qaer2%i", cmd->hdr.return_code);
4695 return 0;
4696 }
4697 qdata = &cmd->data.setassparms.data.query_arp;
4698 switch(qdata->reply_bits){
4699 case 5:
4700 uentry_size = entry_size = sizeof(struct qeth_arp_qi_entry5);
4701 if (qinfo->mask_bits & QETH_QARP_STRIP_ENTRIES)
4702 uentry_size = sizeof(struct qeth_arp_qi_entry5_short);
4703 break;
4704 case 7:
4705 /* fall through to default */
4706 default:
4707 /* tr is the same as eth -> entry7 */
4708 uentry_size = entry_size = sizeof(struct qeth_arp_qi_entry7);
4709 if (qinfo->mask_bits & QETH_QARP_STRIP_ENTRIES)
4710 uentry_size = sizeof(struct qeth_arp_qi_entry7_short);
4711 break;
4712 }
4713 /* check if there is enough room in userspace */
4714 if ((qinfo->udata_len - qinfo->udata_offset) <
4715 qdata->no_entries * uentry_size){
4716 QETH_DBF_TEXT_(trace, 4, "qaer3%i", -ENOMEM);
4717 cmd->hdr.return_code = -ENOMEM;
4718 PRINT_WARN("query ARP user space buffer is too small for "
4719 "the returned number of ARP entries. "
4720 "Aborting query!\n");
4721 goto out_error;
4722 }
4723 QETH_DBF_TEXT_(trace, 4, "anore%i",
4724 cmd->data.setassparms.hdr.number_of_replies);
4725 QETH_DBF_TEXT_(trace, 4, "aseqn%i", cmd->data.setassparms.hdr.seq_no);
4726 QETH_DBF_TEXT_(trace, 4, "anoen%i", qdata->no_entries);
4727
4728 if (qinfo->mask_bits & QETH_QARP_STRIP_ENTRIES) {
4729 /* strip off "media specific information" */
4730 qeth_copy_arp_entries_stripped(qinfo, qdata, entry_size,
4731 uentry_size);
4732 } else
4733 /*copy entries to user buffer*/
4734 memcpy(qinfo->udata + qinfo->udata_offset,
4735 (char *)&qdata->data, qdata->no_entries*uentry_size);
4736
4737 qinfo->no_entries += qdata->no_entries;
4738 qinfo->udata_offset += (qdata->no_entries*uentry_size);
4739 /* check if all replies received ... */
4740 if (cmd->data.setassparms.hdr.seq_no <
4741 cmd->data.setassparms.hdr.number_of_replies)
4742 return 1;
4743 memcpy(qinfo->udata, &qinfo->no_entries, 4);
4744 /* keep STRIP_ENTRIES flag so the user program can distinguish
4745 * stripped entries from normal ones */
4746 if (qinfo->mask_bits & QETH_QARP_STRIP_ENTRIES)
4747 qdata->reply_bits |= QETH_QARP_STRIP_ENTRIES;
4748 memcpy(qinfo->udata + QETH_QARP_MASK_OFFSET,&qdata->reply_bits,2);
4749 return 0;
4750out_error:
4751 i = 0;
4752 memcpy(qinfo->udata, &i, 4);
4753 return 0;
4754}
4755
4756static int
4757qeth_send_ipa_arp_cmd(struct qeth_card *card, struct qeth_cmd_buffer *iob,
4758 int len, int (*reply_cb)(struct qeth_card *,
4759 struct qeth_reply *,
4760 unsigned long),
4761 void *reply_param)
4762{
4763 QETH_DBF_TEXT(trace,4,"sendarp");
4764
4765 memcpy(iob->data, IPA_PDU_HEADER, IPA_PDU_HEADER_SIZE);
4766 memcpy(QETH_IPA_CMD_DEST_ADDR(iob->data),
4767 &card->token.ulp_connection_r, QETH_MPC_TOKEN_LENGTH);
4768 return qeth_send_control_data(card, IPA_PDU_HEADER_SIZE + len, iob,
4769 reply_cb, reply_param);
4770}
4771
4772static int
4773qeth_send_ipa_snmp_cmd(struct qeth_card *card, struct qeth_cmd_buffer *iob,
4774 int len, int (*reply_cb)(struct qeth_card *,
4775 struct qeth_reply *,
4776 unsigned long),
4777 void *reply_param)
4778{
4779 u16 s1, s2;
4780
4781 QETH_DBF_TEXT(trace,4,"sendsnmp");
4782
4783 memcpy(iob->data, IPA_PDU_HEADER, IPA_PDU_HEADER_SIZE);
4784 memcpy(QETH_IPA_CMD_DEST_ADDR(iob->data),
4785 &card->token.ulp_connection_r, QETH_MPC_TOKEN_LENGTH);
4786 /* adjust PDU length fields in IPA_PDU_HEADER */
4787 s1 = (u32) IPA_PDU_HEADER_SIZE + len;
4788 s2 = (u32) len;
4789 memcpy(QETH_IPA_PDU_LEN_TOTAL(iob->data), &s1, 2);
4790 memcpy(QETH_IPA_PDU_LEN_PDU1(iob->data), &s2, 2);
4791 memcpy(QETH_IPA_PDU_LEN_PDU2(iob->data), &s2, 2);
4792 memcpy(QETH_IPA_PDU_LEN_PDU3(iob->data), &s2, 2);
4793 return qeth_send_control_data(card, IPA_PDU_HEADER_SIZE + len, iob,
4794 reply_cb, reply_param);
4795}
4796
4797static struct qeth_cmd_buffer *
4798qeth_get_setassparms_cmd(struct qeth_card *, enum qeth_ipa_funcs,
4799 __u16, __u16, enum qeth_prot_versions);
4800static int
4801qeth_arp_query(struct qeth_card *card, char *udata)
4802{
4803 struct qeth_cmd_buffer *iob;
4804 struct qeth_arp_query_info qinfo = {0, };
4805 int tmp;
4806 int rc;
4807
4808 QETH_DBF_TEXT(trace,3,"arpquery");
4809
Linus Torvalds1da177e2005-04-16 15:20:36 -07004810 if (!qeth_is_supported(card,/*IPA_QUERY_ARP_ADDR_INFO*/
4811 IPA_ARP_PROCESSING)) {
4812 PRINT_WARN("ARP processing not supported "
4813 "on %s!\n", QETH_CARD_IFNAME(card));
4814 return -EOPNOTSUPP;
4815 }
4816 /* get size of userspace buffer and mask_bits -> 6 bytes */
4817 if (copy_from_user(&qinfo, udata, 6))
4818 return -EFAULT;
Eric Sesterhenn88abaab2006-03-24 03:15:31 -08004819 if (!(qinfo.udata = kzalloc(qinfo.udata_len, GFP_KERNEL)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004820 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004821 qinfo.udata_offset = QETH_QARP_ENTRIES_OFFSET;
4822 iob = qeth_get_setassparms_cmd(card, IPA_ARP_PROCESSING,
4823 IPA_CMD_ASS_ARP_QUERY_INFO,
4824 sizeof(int),QETH_PROT_IPV4);
4825
4826 rc = qeth_send_ipa_arp_cmd(card, iob,
4827 QETH_SETASS_BASE_LEN+QETH_ARP_CMD_LEN,
4828 qeth_arp_query_cb, (void *)&qinfo);
4829 if (rc) {
4830 tmp = rc;
4831 PRINT_WARN("Error while querying ARP cache on %s: %s "
4832 "(0x%x/%d)\n",
4833 QETH_CARD_IFNAME(card), qeth_arp_get_error_cause(&rc),
4834 tmp, tmp);
4835 copy_to_user(udata, qinfo.udata, 4);
4836 } else {
4837 copy_to_user(udata, qinfo.udata, qinfo.udata_len);
4838 }
4839 kfree(qinfo.udata);
4840 return rc;
4841}
4842
4843/**
4844 * SNMP command callback
4845 */
4846static int
4847qeth_snmp_command_cb(struct qeth_card *card, struct qeth_reply *reply,
4848 unsigned long sdata)
4849{
4850 struct qeth_ipa_cmd *cmd;
4851 struct qeth_arp_query_info *qinfo;
4852 struct qeth_snmp_cmd *snmp;
4853 unsigned char *data;
4854 __u16 data_len;
4855
4856 QETH_DBF_TEXT(trace,3,"snpcmdcb");
4857
4858 cmd = (struct qeth_ipa_cmd *) sdata;
4859 data = (unsigned char *)((char *)cmd - reply->offset);
4860 qinfo = (struct qeth_arp_query_info *) reply->param;
4861 snmp = &cmd->data.setadapterparms.data.snmp;
4862
4863 if (cmd->hdr.return_code) {
4864 QETH_DBF_TEXT_(trace,4,"scer1%i", cmd->hdr.return_code);
4865 return 0;
4866 }
4867 if (cmd->data.setadapterparms.hdr.return_code) {
4868 cmd->hdr.return_code = cmd->data.setadapterparms.hdr.return_code;
4869 QETH_DBF_TEXT_(trace,4,"scer2%i", cmd->hdr.return_code);
4870 return 0;
4871 }
4872 data_len = *((__u16*)QETH_IPA_PDU_LEN_PDU1(data));
4873 if (cmd->data.setadapterparms.hdr.seq_no == 1)
4874 data_len -= (__u16)((char *)&snmp->data - (char *)cmd);
4875 else
4876 data_len -= (__u16)((char*)&snmp->request - (char *)cmd);
4877
4878 /* check if there is enough room in userspace */
4879 if ((qinfo->udata_len - qinfo->udata_offset) < data_len) {
4880 QETH_DBF_TEXT_(trace, 4, "scer3%i", -ENOMEM);
4881 cmd->hdr.return_code = -ENOMEM;
4882 return 0;
4883 }
4884 QETH_DBF_TEXT_(trace, 4, "snore%i",
4885 cmd->data.setadapterparms.hdr.used_total);
4886 QETH_DBF_TEXT_(trace, 4, "sseqn%i", cmd->data.setadapterparms.hdr.seq_no);
4887 /*copy entries to user buffer*/
4888 if (cmd->data.setadapterparms.hdr.seq_no == 1) {
4889 memcpy(qinfo->udata + qinfo->udata_offset,
4890 (char *)snmp,
4891 data_len + offsetof(struct qeth_snmp_cmd,data));
4892 qinfo->udata_offset += offsetof(struct qeth_snmp_cmd, data);
4893 } else {
4894 memcpy(qinfo->udata + qinfo->udata_offset,
4895 (char *)&snmp->request, data_len);
4896 }
4897 qinfo->udata_offset += data_len;
4898 /* check if all replies received ... */
4899 QETH_DBF_TEXT_(trace, 4, "srtot%i",
4900 cmd->data.setadapterparms.hdr.used_total);
4901 QETH_DBF_TEXT_(trace, 4, "srseq%i",
4902 cmd->data.setadapterparms.hdr.seq_no);
4903 if (cmd->data.setadapterparms.hdr.seq_no <
4904 cmd->data.setadapterparms.hdr.used_total)
4905 return 1;
4906 return 0;
4907}
4908
4909static struct qeth_cmd_buffer *
4910qeth_get_ipacmd_buffer(struct qeth_card *, enum qeth_ipa_cmds,
4911 enum qeth_prot_versions );
4912
4913static struct qeth_cmd_buffer *
4914qeth_get_adapter_cmd(struct qeth_card *card, __u32 command, __u32 cmdlen)
4915{
4916 struct qeth_cmd_buffer *iob;
4917 struct qeth_ipa_cmd *cmd;
4918
4919 iob = qeth_get_ipacmd_buffer(card,IPA_CMD_SETADAPTERPARMS,
4920 QETH_PROT_IPV4);
4921 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
4922 cmd->data.setadapterparms.hdr.cmdlength = cmdlen;
4923 cmd->data.setadapterparms.hdr.command_code = command;
4924 cmd->data.setadapterparms.hdr.used_total = 1;
4925 cmd->data.setadapterparms.hdr.seq_no = 1;
4926
4927 return iob;
4928}
4929
4930/**
4931 * function to send SNMP commands to OSA-E card
4932 */
4933static int
4934qeth_snmp_command(struct qeth_card *card, char *udata)
4935{
4936 struct qeth_cmd_buffer *iob;
4937 struct qeth_ipa_cmd *cmd;
4938 struct qeth_snmp_ureq *ureq;
4939 int req_len;
4940 struct qeth_arp_query_info qinfo = {0, };
4941 int rc = 0;
4942
4943 QETH_DBF_TEXT(trace,3,"snmpcmd");
4944
4945 if (card->info.guestlan)
4946 return -EOPNOTSUPP;
4947
4948 if ((!qeth_adp_supported(card,IPA_SETADP_SET_SNMP_CONTROL)) &&
4949 (!card->options.layer2) ) {
4950 PRINT_WARN("SNMP Query MIBS not supported "
4951 "on %s!\n", QETH_CARD_IFNAME(card));
4952 return -EOPNOTSUPP;
4953 }
4954 /* skip 4 bytes (data_len struct member) to get req_len */
4955 if (copy_from_user(&req_len, udata + sizeof(int), sizeof(int)))
4956 return -EFAULT;
4957 ureq = kmalloc(req_len+sizeof(struct qeth_snmp_ureq_hdr), GFP_KERNEL);
4958 if (!ureq) {
4959 QETH_DBF_TEXT(trace, 2, "snmpnome");
4960 return -ENOMEM;
4961 }
4962 if (copy_from_user(ureq, udata,
4963 req_len+sizeof(struct qeth_snmp_ureq_hdr))){
4964 kfree(ureq);
4965 return -EFAULT;
4966 }
4967 qinfo.udata_len = ureq->hdr.data_len;
Eric Sesterhenn88abaab2006-03-24 03:15:31 -08004968 if (!(qinfo.udata = kzalloc(qinfo.udata_len, GFP_KERNEL))){
Linus Torvalds1da177e2005-04-16 15:20:36 -07004969 kfree(ureq);
4970 return -ENOMEM;
4971 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004972 qinfo.udata_offset = sizeof(struct qeth_snmp_ureq_hdr);
4973
4974 iob = qeth_get_adapter_cmd(card, IPA_SETADP_SET_SNMP_CONTROL,
4975 QETH_SNMP_SETADP_CMDLENGTH + req_len);
4976 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
4977 memcpy(&cmd->data.setadapterparms.data.snmp, &ureq->cmd, req_len);
4978 rc = qeth_send_ipa_snmp_cmd(card, iob, QETH_SETADP_BASE_LEN + req_len,
4979 qeth_snmp_command_cb, (void *)&qinfo);
4980 if (rc)
4981 PRINT_WARN("SNMP command failed on %s: (0x%x)\n",
4982 QETH_CARD_IFNAME(card), rc);
4983 else
4984 copy_to_user(udata, qinfo.udata, qinfo.udata_len);
4985
4986 kfree(ureq);
4987 kfree(qinfo.udata);
4988 return rc;
4989}
4990
4991static int
4992qeth_default_setassparms_cb(struct qeth_card *, struct qeth_reply *,
4993 unsigned long);
4994
4995static int
Frank Pavlic6c951b92005-11-10 13:51:25 +01004996qeth_default_setadapterparms_cb(struct qeth_card *card,
4997 struct qeth_reply *reply,
4998 unsigned long data);
4999static int
Linus Torvalds1da177e2005-04-16 15:20:36 -07005000qeth_send_setassparms(struct qeth_card *, struct qeth_cmd_buffer *,
5001 __u16, long,
5002 int (*reply_cb)
5003 (struct qeth_card *, struct qeth_reply *, unsigned long),
5004 void *reply_param);
5005
5006static int
5007qeth_arp_add_entry(struct qeth_card *card, struct qeth_arp_cache_entry *entry)
5008{
5009 struct qeth_cmd_buffer *iob;
5010 char buf[16];
5011 int tmp;
5012 int rc;
5013
5014 QETH_DBF_TEXT(trace,3,"arpadent");
5015
5016 /*
Frank Pavlicf3d242e2005-09-14 18:05:31 +02005017 * currently GuestLAN only supports the ARP assist function
5018 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_ADD_ENTRY;
5019 * thus we say EOPNOTSUPP for this ARP function
Linus Torvalds1da177e2005-04-16 15:20:36 -07005020 */
5021 if (card->info.guestlan)
5022 return -EOPNOTSUPP;
5023 if (!qeth_is_supported(card,IPA_ARP_PROCESSING)) {
5024 PRINT_WARN("ARP processing not supported "
5025 "on %s!\n", QETH_CARD_IFNAME(card));
5026 return -EOPNOTSUPP;
5027 }
5028
5029 iob = qeth_get_setassparms_cmd(card, IPA_ARP_PROCESSING,
5030 IPA_CMD_ASS_ARP_ADD_ENTRY,
5031 sizeof(struct qeth_arp_cache_entry),
5032 QETH_PROT_IPV4);
5033 rc = qeth_send_setassparms(card, iob,
5034 sizeof(struct qeth_arp_cache_entry),
5035 (unsigned long) entry,
5036 qeth_default_setassparms_cb, NULL);
5037 if (rc) {
5038 tmp = rc;
5039 qeth_ipaddr4_to_string((u8 *)entry->ipaddr, buf);
5040 PRINT_WARN("Could not add ARP entry for address %s on %s: "
5041 "%s (0x%x/%d)\n",
5042 buf, QETH_CARD_IFNAME(card),
5043 qeth_arp_get_error_cause(&rc), tmp, tmp);
5044 }
5045 return rc;
5046}
5047
5048static int
5049qeth_arp_remove_entry(struct qeth_card *card, struct qeth_arp_cache_entry *entry)
5050{
5051 struct qeth_cmd_buffer *iob;
5052 char buf[16] = {0, };
5053 int tmp;
5054 int rc;
5055
5056 QETH_DBF_TEXT(trace,3,"arprment");
5057
5058 /*
Frank Pavlicf3d242e2005-09-14 18:05:31 +02005059 * currently GuestLAN only supports the ARP assist function
5060 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_REMOVE_ENTRY;
5061 * thus we say EOPNOTSUPP for this ARP function
Linus Torvalds1da177e2005-04-16 15:20:36 -07005062 */
5063 if (card->info.guestlan)
5064 return -EOPNOTSUPP;
5065 if (!qeth_is_supported(card,IPA_ARP_PROCESSING)) {
5066 PRINT_WARN("ARP processing not supported "
5067 "on %s!\n", QETH_CARD_IFNAME(card));
5068 return -EOPNOTSUPP;
5069 }
5070 memcpy(buf, entry, 12);
5071 iob = qeth_get_setassparms_cmd(card, IPA_ARP_PROCESSING,
5072 IPA_CMD_ASS_ARP_REMOVE_ENTRY,
5073 12,
5074 QETH_PROT_IPV4);
5075 rc = qeth_send_setassparms(card, iob,
5076 12, (unsigned long)buf,
5077 qeth_default_setassparms_cb, NULL);
5078 if (rc) {
5079 tmp = rc;
5080 memset(buf, 0, 16);
5081 qeth_ipaddr4_to_string((u8 *)entry->ipaddr, buf);
5082 PRINT_WARN("Could not delete ARP entry for address %s on %s: "
5083 "%s (0x%x/%d)\n",
5084 buf, QETH_CARD_IFNAME(card),
5085 qeth_arp_get_error_cause(&rc), tmp, tmp);
5086 }
5087 return rc;
5088}
5089
5090static int
5091qeth_arp_flush_cache(struct qeth_card *card)
5092{
5093 int rc;
5094 int tmp;
5095
5096 QETH_DBF_TEXT(trace,3,"arpflush");
5097
5098 /*
Frank Pavlicf3d242e2005-09-14 18:05:31 +02005099 * currently GuestLAN only supports the ARP assist function
5100 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_FLUSH_CACHE;
5101 * thus we say EOPNOTSUPP for this ARP function
5102 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07005103 if (card->info.guestlan || (card->info.type == QETH_CARD_TYPE_IQD))
5104 return -EOPNOTSUPP;
5105 if (!qeth_is_supported(card,IPA_ARP_PROCESSING)) {
5106 PRINT_WARN("ARP processing not supported "
5107 "on %s!\n", QETH_CARD_IFNAME(card));
5108 return -EOPNOTSUPP;
5109 }
5110 rc = qeth_send_simple_setassparms(card, IPA_ARP_PROCESSING,
5111 IPA_CMD_ASS_ARP_FLUSH_CACHE, 0);
5112 if (rc){
5113 tmp = rc;
5114 PRINT_WARN("Could not flush ARP cache on %s: %s (0x%x/%d)\n",
5115 QETH_CARD_IFNAME(card), qeth_arp_get_error_cause(&rc),
5116 tmp, tmp);
5117 }
5118 return rc;
5119}
5120
5121static int
5122qeth_do_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
5123{
5124 struct qeth_card *card = (struct qeth_card *)dev->priv;
5125 struct qeth_arp_cache_entry arp_entry;
5126 struct mii_ioctl_data *mii_data;
5127 int rc = 0;
5128
5129 if (!card)
5130 return -ENODEV;
5131
5132 if ((card->state != CARD_STATE_UP) &&
5133 (card->state != CARD_STATE_SOFTSETUP))
5134 return -ENODEV;
5135
Ursula Braun500f83a2005-09-30 10:19:19 +02005136 if (card->info.type == QETH_CARD_TYPE_OSN)
5137 return -EPERM;
5138
Linus Torvalds1da177e2005-04-16 15:20:36 -07005139 switch (cmd){
5140 case SIOC_QETH_ARP_SET_NO_ENTRIES:
5141 if ( !capable(CAP_NET_ADMIN) ||
5142 (card->options.layer2) ) {
5143 rc = -EPERM;
5144 break;
5145 }
5146 rc = qeth_arp_set_no_entries(card, rq->ifr_ifru.ifru_ivalue);
5147 break;
5148 case SIOC_QETH_ARP_QUERY_INFO:
5149 if ( !capable(CAP_NET_ADMIN) ||
5150 (card->options.layer2) ) {
5151 rc = -EPERM;
5152 break;
5153 }
5154 rc = qeth_arp_query(card, rq->ifr_ifru.ifru_data);
5155 break;
5156 case SIOC_QETH_ARP_ADD_ENTRY:
5157 if ( !capable(CAP_NET_ADMIN) ||
5158 (card->options.layer2) ) {
5159 rc = -EPERM;
5160 break;
5161 }
5162 if (copy_from_user(&arp_entry, rq->ifr_ifru.ifru_data,
5163 sizeof(struct qeth_arp_cache_entry)))
5164 rc = -EFAULT;
5165 else
5166 rc = qeth_arp_add_entry(card, &arp_entry);
5167 break;
5168 case SIOC_QETH_ARP_REMOVE_ENTRY:
5169 if ( !capable(CAP_NET_ADMIN) ||
5170 (card->options.layer2) ) {
5171 rc = -EPERM;
5172 break;
5173 }
5174 if (copy_from_user(&arp_entry, rq->ifr_ifru.ifru_data,
5175 sizeof(struct qeth_arp_cache_entry)))
5176 rc = -EFAULT;
5177 else
5178 rc = qeth_arp_remove_entry(card, &arp_entry);
5179 break;
5180 case SIOC_QETH_ARP_FLUSH_CACHE:
5181 if ( !capable(CAP_NET_ADMIN) ||
5182 (card->options.layer2) ) {
5183 rc = -EPERM;
5184 break;
5185 }
5186 rc = qeth_arp_flush_cache(card);
5187 break;
5188 case SIOC_QETH_ADP_SET_SNMP_CONTROL:
5189 rc = qeth_snmp_command(card, rq->ifr_ifru.ifru_data);
5190 break;
5191 case SIOC_QETH_GET_CARD_TYPE:
5192 if ((card->info.type == QETH_CARD_TYPE_OSAE) &&
5193 !card->info.guestlan)
5194 return 1;
5195 return 0;
5196 break;
5197 case SIOCGMIIPHY:
5198 mii_data = if_mii(rq);
5199 mii_data->phy_id = 0;
5200 break;
5201 case SIOCGMIIREG:
5202 mii_data = if_mii(rq);
5203 if (mii_data->phy_id != 0)
5204 rc = -EINVAL;
5205 else
5206 mii_data->val_out = qeth_mdio_read(dev,mii_data->phy_id,
5207 mii_data->reg_num);
5208 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005209 default:
5210 rc = -EOPNOTSUPP;
5211 }
5212 if (rc)
5213 QETH_DBF_TEXT_(trace, 2, "ioce%d", rc);
5214 return rc;
5215}
5216
5217static struct net_device_stats *
5218qeth_get_stats(struct net_device *dev)
5219{
5220 struct qeth_card *card;
5221
5222 card = (struct qeth_card *) (dev->priv);
5223
5224 QETH_DBF_TEXT(trace,5,"getstat");
5225
5226 return &card->stats;
5227}
5228
5229static int
5230qeth_change_mtu(struct net_device *dev, int new_mtu)
5231{
5232 struct qeth_card *card;
5233 char dbf_text[15];
5234
5235 card = (struct qeth_card *) (dev->priv);
5236
5237 QETH_DBF_TEXT(trace,4,"chgmtu");
5238 sprintf(dbf_text, "%8x", new_mtu);
5239 QETH_DBF_TEXT(trace,4,dbf_text);
5240
5241 if (new_mtu < 64)
5242 return -EINVAL;
5243 if (new_mtu > 65535)
5244 return -EINVAL;
5245 if ((!qeth_is_supported(card,IPA_IP_FRAGMENTATION)) &&
5246 (!qeth_mtu_is_valid(card, new_mtu)))
5247 return -EINVAL;
5248 dev->mtu = new_mtu;
5249 return 0;
5250}
5251
5252#ifdef CONFIG_QETH_VLAN
5253static void
5254qeth_vlan_rx_register(struct net_device *dev, struct vlan_group *grp)
5255{
5256 struct qeth_card *card;
5257 unsigned long flags;
5258
5259 QETH_DBF_TEXT(trace,4,"vlanreg");
5260
5261 card = (struct qeth_card *) dev->priv;
5262 spin_lock_irqsave(&card->vlanlock, flags);
5263 card->vlangrp = grp;
5264 spin_unlock_irqrestore(&card->vlanlock, flags);
5265}
5266
5267static inline void
5268qeth_free_vlan_buffer(struct qeth_card *card, struct qeth_qdio_out_buffer *buf,
5269 unsigned short vid)
5270{
5271 int i;
5272 struct sk_buff *skb;
5273 struct sk_buff_head tmp_list;
5274
5275 skb_queue_head_init(&tmp_list);
5276 for(i = 0; i < QETH_MAX_BUFFER_ELEMENTS(card); ++i){
5277 while ((skb = skb_dequeue(&buf->skb_list))){
5278 if (vlan_tx_tag_present(skb) &&
5279 (vlan_tx_tag_get(skb) == vid)) {
5280 atomic_dec(&skb->users);
5281 dev_kfree_skb(skb);
5282 } else
5283 skb_queue_tail(&tmp_list, skb);
5284 }
5285 }
5286 while ((skb = skb_dequeue(&tmp_list)))
5287 skb_queue_tail(&buf->skb_list, skb);
5288}
5289
5290static void
5291qeth_free_vlan_skbs(struct qeth_card *card, unsigned short vid)
5292{
5293 int i, j;
5294
5295 QETH_DBF_TEXT(trace, 4, "frvlskbs");
5296 for (i = 0; i < card->qdio.no_out_queues; ++i){
5297 for (j = 0; j < QDIO_MAX_BUFFERS_PER_Q; ++j)
5298 qeth_free_vlan_buffer(card, &card->qdio.
5299 out_qs[i]->bufs[j], vid);
5300 }
5301}
5302
5303static void
5304qeth_free_vlan_addresses4(struct qeth_card *card, unsigned short vid)
5305{
5306 struct in_device *in_dev;
5307 struct in_ifaddr *ifa;
5308 struct qeth_ipaddr *addr;
5309
5310 QETH_DBF_TEXT(trace, 4, "frvaddr4");
Frank Pavlic6c88ad22005-11-10 13:49:28 +01005311
Linus Torvalds1da177e2005-04-16 15:20:36 -07005312 rcu_read_lock();
Herbert Xue5ed6392005-10-03 14:35:55 -07005313 in_dev = __in_dev_get_rcu(card->vlangrp->vlan_devices[vid]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005314 if (!in_dev)
5315 goto out;
5316 for (ifa = in_dev->ifa_list; ifa; ifa = ifa->ifa_next) {
5317 addr = qeth_get_addr_buffer(QETH_PROT_IPV4);
5318 if (addr){
5319 addr->u.a4.addr = ifa->ifa_address;
5320 addr->u.a4.mask = ifa->ifa_mask;
5321 addr->type = QETH_IP_TYPE_NORMAL;
5322 if (!qeth_delete_ip(card, addr))
5323 kfree(addr);
5324 }
5325 }
5326out:
5327 rcu_read_unlock();
5328}
5329
5330static void
5331qeth_free_vlan_addresses6(struct qeth_card *card, unsigned short vid)
5332{
5333#ifdef CONFIG_QETH_IPV6
5334 struct inet6_dev *in6_dev;
5335 struct inet6_ifaddr *ifa;
5336 struct qeth_ipaddr *addr;
5337
5338 QETH_DBF_TEXT(trace, 4, "frvaddr6");
Frank Pavlic6c88ad22005-11-10 13:49:28 +01005339
Linus Torvalds1da177e2005-04-16 15:20:36 -07005340 in6_dev = in6_dev_get(card->vlangrp->vlan_devices[vid]);
5341 if (!in6_dev)
5342 return;
5343 for (ifa = in6_dev->addr_list; ifa; ifa = ifa->lst_next){
5344 addr = qeth_get_addr_buffer(QETH_PROT_IPV6);
5345 if (addr){
5346 memcpy(&addr->u.a6.addr, &ifa->addr,
5347 sizeof(struct in6_addr));
5348 addr->u.a6.pfxlen = ifa->prefix_len;
5349 addr->type = QETH_IP_TYPE_NORMAL;
5350 if (!qeth_delete_ip(card, addr))
5351 kfree(addr);
5352 }
5353 }
5354 in6_dev_put(in6_dev);
5355#endif /* CONFIG_QETH_IPV6 */
5356}
5357
Frank Pavlic6c88ad22005-11-10 13:49:28 +01005358static void
5359qeth_free_vlan_addresses(struct qeth_card *card, unsigned short vid)
5360{
5361 if (card->options.layer2 || !card->vlangrp)
5362 return;
5363 qeth_free_vlan_addresses4(card, vid);
5364 qeth_free_vlan_addresses6(card, vid);
5365}
5366
Frank Pavlic508cc2b2005-11-10 13:49:15 +01005367static int
5368qeth_layer2_send_setdelvlan_cb(struct qeth_card *card,
5369 struct qeth_reply *reply,
5370 unsigned long data)
5371{
5372 struct qeth_ipa_cmd *cmd;
5373
5374 QETH_DBF_TEXT(trace, 2, "L2sdvcb");
5375 cmd = (struct qeth_ipa_cmd *) data;
5376 if (cmd->hdr.return_code) {
5377 PRINT_ERR("Error in processing VLAN %i on %s: 0x%x. "
Jeff Garzike82b0f22006-05-26 21:58:38 -04005378 "Continuing\n",cmd->data.setdelvlan.vlan_id,
Frank Pavlic508cc2b2005-11-10 13:49:15 +01005379 QETH_CARD_IFNAME(card), cmd->hdr.return_code);
5380 QETH_DBF_TEXT_(trace, 2, "L2VL%4x", cmd->hdr.command);
5381 QETH_DBF_TEXT_(trace, 2, "L2%s", CARD_BUS_ID(card));
5382 QETH_DBF_TEXT_(trace, 2, "err%d", cmd->hdr.return_code);
5383 }
5384 return 0;
5385}
5386
5387static int
Linus Torvalds1da177e2005-04-16 15:20:36 -07005388qeth_layer2_send_setdelvlan(struct qeth_card *card, __u16 i,
5389 enum qeth_ipa_cmds ipacmd)
5390{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005391 struct qeth_ipa_cmd *cmd;
5392 struct qeth_cmd_buffer *iob;
5393
5394 QETH_DBF_TEXT_(trace, 4, "L2sdv%x",ipacmd);
5395 iob = qeth_get_ipacmd_buffer(card, ipacmd, QETH_PROT_IPV4);
5396 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
5397 cmd->data.setdelvlan.vlan_id = i;
Jeff Garzike82b0f22006-05-26 21:58:38 -04005398 return qeth_send_ipa_cmd(card, iob,
Frank Pavlic508cc2b2005-11-10 13:49:15 +01005399 qeth_layer2_send_setdelvlan_cb, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005400}
5401
5402static void
5403qeth_layer2_process_vlans(struct qeth_card *card, int clear)
5404{
5405 unsigned short i;
5406
5407 QETH_DBF_TEXT(trace, 3, "L2prcvln");
5408
5409 if (!card->vlangrp)
5410 return;
5411 for (i = 0; i < VLAN_GROUP_ARRAY_LEN; i++) {
5412 if (card->vlangrp->vlan_devices[i] == NULL)
5413 continue;
5414 if (clear)
5415 qeth_layer2_send_setdelvlan(card, i, IPA_CMD_DELVLAN);
5416 else
5417 qeth_layer2_send_setdelvlan(card, i, IPA_CMD_SETVLAN);
5418 }
5419}
5420
5421/*add_vid is layer 2 used only ....*/
5422static void
5423qeth_vlan_rx_add_vid(struct net_device *dev, unsigned short vid)
5424{
5425 struct qeth_card *card;
5426
5427 QETH_DBF_TEXT_(trace, 4, "aid:%d", vid);
5428
5429 card = (struct qeth_card *) dev->priv;
5430 if (!card->options.layer2)
5431 return;
5432 qeth_layer2_send_setdelvlan(card, vid, IPA_CMD_SETVLAN);
5433}
5434
5435/*... kill_vid used for both modes*/
5436static void
5437qeth_vlan_rx_kill_vid(struct net_device *dev, unsigned short vid)
5438{
5439 struct qeth_card *card;
5440 unsigned long flags;
5441
5442 QETH_DBF_TEXT_(trace, 4, "kid:%d", vid);
5443
5444 card = (struct qeth_card *) dev->priv;
5445 /* free all skbs for the vlan device */
5446 qeth_free_vlan_skbs(card, vid);
5447 spin_lock_irqsave(&card->vlanlock, flags);
5448 /* unregister IP addresses of vlan device */
Frank Pavlic6c88ad22005-11-10 13:49:28 +01005449 qeth_free_vlan_addresses(card, vid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005450 if (card->vlangrp)
5451 card->vlangrp->vlan_devices[vid] = NULL;
5452 spin_unlock_irqrestore(&card->vlanlock, flags);
5453 if (card->options.layer2)
5454 qeth_layer2_send_setdelvlan(card, vid, IPA_CMD_DELVLAN);
5455 qeth_set_multicast_list(card->dev);
5456}
5457#endif
Frank Pavlic6c951b92005-11-10 13:51:25 +01005458/**
5459 * Examine hardware response to SET_PROMISC_MODE
5460 */
5461static int
Jeff Garzike82b0f22006-05-26 21:58:38 -04005462qeth_setadp_promisc_mode_cb(struct qeth_card *card,
Frank Pavlic6c951b92005-11-10 13:51:25 +01005463 struct qeth_reply *reply,
5464 unsigned long data)
5465{
5466 struct qeth_ipa_cmd *cmd;
5467 struct qeth_ipacmd_setadpparms *setparms;
5468
5469 QETH_DBF_TEXT(trace,4,"prmadpcb");
5470
5471 cmd = (struct qeth_ipa_cmd *) data;
5472 setparms = &(cmd->data.setadapterparms);
Jeff Garzike82b0f22006-05-26 21:58:38 -04005473
Frank Pavlic6c951b92005-11-10 13:51:25 +01005474 qeth_default_setadapterparms_cb(card, reply, (unsigned long)cmd);
Jeff Garzike82b0f22006-05-26 21:58:38 -04005475 if (cmd->hdr.return_code) {
5476 QETH_DBF_TEXT_(trace,4,"prmrc%2.2x",cmd->hdr.return_code);
Frank Pavlic6c951b92005-11-10 13:51:25 +01005477 setparms->data.mode = SET_PROMISC_MODE_OFF;
5478 }
5479 card->info.promisc_mode = setparms->data.mode;
5480 return 0;
5481}
5482/*
5483 * Set promiscuous mode (on or off) (SET_PROMISC_MODE command)
5484 */
5485static void
5486qeth_setadp_promisc_mode(struct qeth_card *card)
5487{
5488 enum qeth_ipa_promisc_modes mode;
5489 struct net_device *dev = card->dev;
5490 struct qeth_cmd_buffer *iob;
5491 struct qeth_ipa_cmd *cmd;
5492
5493 QETH_DBF_TEXT(trace, 4, "setprom");
5494
5495 if (((dev->flags & IFF_PROMISC) &&
5496 (card->info.promisc_mode == SET_PROMISC_MODE_ON)) ||
5497 (!(dev->flags & IFF_PROMISC) &&
5498 (card->info.promisc_mode == SET_PROMISC_MODE_OFF)))
5499 return;
5500 mode = SET_PROMISC_MODE_OFF;
5501 if (dev->flags & IFF_PROMISC)
5502 mode = SET_PROMISC_MODE_ON;
5503 QETH_DBF_TEXT_(trace, 4, "mode:%x", mode);
5504
5505 iob = qeth_get_adapter_cmd(card, IPA_SETADP_SET_PROMISC_MODE,
5506 sizeof(struct qeth_ipacmd_setadpparms));
5507 cmd = (struct qeth_ipa_cmd *)(iob->data + IPA_PDU_HEADER_SIZE);
5508 cmd->data.setadapterparms.data.mode = mode;
5509 qeth_send_ipa_cmd(card, iob, qeth_setadp_promisc_mode_cb, NULL);
5510}
Linus Torvalds1da177e2005-04-16 15:20:36 -07005511
5512/**
5513 * set multicast address on card
5514 */
5515static void
5516qeth_set_multicast_list(struct net_device *dev)
5517{
5518 struct qeth_card *card = (struct qeth_card *) dev->priv;
5519
Ursula Braun500f83a2005-09-30 10:19:19 +02005520 if (card->info.type == QETH_CARD_TYPE_OSN)
5521 return ;
Jeff Garzike82b0f22006-05-26 21:58:38 -04005522
Frank Pavlic66cc5d52006-02-07 17:04:38 +01005523 QETH_DBF_TEXT(trace, 3, "setmulti");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005524 qeth_delete_mc_addresses(card);
Frank Pavlic6c88ad22005-11-10 13:49:28 +01005525 if (card->options.layer2) {
5526 qeth_layer2_add_multicast(card);
5527 goto out;
5528 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005529 qeth_add_multicast_ipv4(card);
5530#ifdef CONFIG_QETH_IPV6
5531 qeth_add_multicast_ipv6(card);
5532#endif
Frank Pavlic6c88ad22005-11-10 13:49:28 +01005533out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07005534 if (qeth_set_thread_start_bit(card, QETH_SET_IP_THREAD) == 0)
5535 schedule_work(&card->kernel_thread_starter);
Frank Pavlic6c951b92005-11-10 13:51:25 +01005536 if (!qeth_adp_supported(card, IPA_SETADP_SET_PROMISC_MODE))
5537 return;
5538 if (qeth_set_thread_start_bit(card, QETH_SET_PROMISC_MODE_THREAD)==0)
5539 schedule_work(&card->kernel_thread_starter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005540}
5541
5542static int
5543qeth_neigh_setup(struct net_device *dev, struct neigh_parms *np)
5544{
5545 return 0;
5546}
5547
5548static void
5549qeth_get_mac_for_ipm(__u32 ipm, char *mac, struct net_device *dev)
5550{
5551 if (dev->type == ARPHRD_IEEE802_TR)
5552 ip_tr_mc_map(ipm, mac);
5553 else
5554 ip_eth_mc_map(ipm, mac);
5555}
5556
5557static struct qeth_ipaddr *
5558qeth_get_addr_buffer(enum qeth_prot_versions prot)
5559{
5560 struct qeth_ipaddr *addr;
5561
Eric Sesterhenn88abaab2006-03-24 03:15:31 -08005562 addr = kzalloc(sizeof(struct qeth_ipaddr), GFP_ATOMIC);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005563 if (addr == NULL) {
5564 PRINT_WARN("Not enough memory to add address\n");
5565 return NULL;
5566 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005567 addr->type = QETH_IP_TYPE_NORMAL;
5568 addr->proto = prot;
5569 return addr;
5570}
5571
Ursula Braun500f83a2005-09-30 10:19:19 +02005572int
5573qeth_osn_assist(struct net_device *dev,
5574 void *data,
5575 int data_len)
5576{
5577 struct qeth_cmd_buffer *iob;
5578 struct qeth_card *card;
5579 int rc;
Jeff Garzike82b0f22006-05-26 21:58:38 -04005580
Ursula Braun500f83a2005-09-30 10:19:19 +02005581 QETH_DBF_TEXT(trace, 2, "osnsdmc");
5582 if (!dev)
5583 return -ENODEV;
5584 card = (struct qeth_card *)dev->priv;
5585 if (!card)
5586 return -ENODEV;
5587 if ((card->state != CARD_STATE_UP) &&
5588 (card->state != CARD_STATE_SOFTSETUP))
5589 return -ENODEV;
5590 iob = qeth_wait_for_buffer(&card->write);
5591 memcpy(iob->data+IPA_PDU_HEADER_SIZE, data, data_len);
5592 rc = qeth_osn_send_ipa_cmd(card, iob, data_len);
5593 return rc;
5594}
5595
5596static struct net_device *
5597qeth_netdev_by_devno(unsigned char *read_dev_no)
5598{
5599 struct qeth_card *card;
5600 struct net_device *ndev;
5601 unsigned char *readno;
5602 __u16 temp_dev_no, card_dev_no;
5603 char *endp;
5604 unsigned long flags;
5605
5606 ndev = NULL;
5607 memcpy(&temp_dev_no, read_dev_no, 2);
5608 read_lock_irqsave(&qeth_card_list.rwlock, flags);
5609 list_for_each_entry(card, &qeth_card_list.list, list) {
5610 readno = CARD_RDEV_ID(card);
5611 readno += (strlen(readno) - 4);
5612 card_dev_no = simple_strtoul(readno, &endp, 16);
5613 if (card_dev_no == temp_dev_no) {
5614 ndev = card->dev;
5615 break;
5616 }
5617 }
5618 read_unlock_irqrestore(&qeth_card_list.rwlock, flags);
5619 return ndev;
5620}
5621
5622int
5623qeth_osn_register(unsigned char *read_dev_no,
5624 struct net_device **dev,
5625 int (*assist_cb)(struct net_device *, void *),
5626 int (*data_cb)(struct sk_buff *))
5627{
5628 struct qeth_card * card;
5629
5630 QETH_DBF_TEXT(trace, 2, "osnreg");
5631 *dev = qeth_netdev_by_devno(read_dev_no);
5632 if (*dev == NULL)
5633 return -ENODEV;
5634 card = (struct qeth_card *)(*dev)->priv;
5635 if (!card)
5636 return -ENODEV;
5637 if ((assist_cb == NULL) || (data_cb == NULL))
5638 return -EINVAL;
5639 card->osn_info.assist_cb = assist_cb;
5640 card->osn_info.data_cb = data_cb;
5641 return 0;
5642}
5643
5644void
5645qeth_osn_deregister(struct net_device * dev)
5646{
5647 struct qeth_card *card;
5648
5649 QETH_DBF_TEXT(trace, 2, "osndereg");
5650 if (!dev)
5651 return;
5652 card = (struct qeth_card *)dev->priv;
5653 if (!card)
5654 return;
5655 card->osn_info.assist_cb = NULL;
5656 card->osn_info.data_cb = NULL;
5657 return;
5658}
Jeff Garzike82b0f22006-05-26 21:58:38 -04005659
Linus Torvalds1da177e2005-04-16 15:20:36 -07005660static void
5661qeth_delete_mc_addresses(struct qeth_card *card)
5662{
5663 struct qeth_ipaddr *iptodo;
5664 unsigned long flags;
5665
5666 QETH_DBF_TEXT(trace,4,"delmc");
5667 iptodo = qeth_get_addr_buffer(QETH_PROT_IPV4);
5668 if (!iptodo) {
5669 QETH_DBF_TEXT(trace, 2, "dmcnomem");
5670 return;
5671 }
5672 iptodo->type = QETH_IP_TYPE_DEL_ALL_MC;
5673 spin_lock_irqsave(&card->ip_lock, flags);
5674 if (!__qeth_insert_ip_todo(card, iptodo, 0))
5675 kfree(iptodo);
5676 spin_unlock_irqrestore(&card->ip_lock, flags);
5677}
5678
5679static inline void
5680qeth_add_mc(struct qeth_card *card, struct in_device *in4_dev)
5681{
5682 struct qeth_ipaddr *ipm;
5683 struct ip_mc_list *im4;
5684 char buf[MAX_ADDR_LEN];
5685
5686 QETH_DBF_TEXT(trace,4,"addmc");
5687 for (im4 = in4_dev->mc_list; im4; im4 = im4->next) {
5688 qeth_get_mac_for_ipm(im4->multiaddr, buf, in4_dev->dev);
5689 ipm = qeth_get_addr_buffer(QETH_PROT_IPV4);
5690 if (!ipm)
5691 continue;
5692 ipm->u.a4.addr = im4->multiaddr;
5693 memcpy(ipm->mac,buf,OSA_ADDR_LEN);
5694 ipm->is_multicast = 1;
5695 if (!qeth_add_ip(card,ipm))
5696 kfree(ipm);
5697 }
5698}
5699
5700static inline void
5701qeth_add_vlan_mc(struct qeth_card *card)
5702{
5703#ifdef CONFIG_QETH_VLAN
5704 struct in_device *in_dev;
5705 struct vlan_group *vg;
5706 int i;
5707
5708 QETH_DBF_TEXT(trace,4,"addmcvl");
5709 if ( ((card->options.layer2 == 0) &&
5710 (!qeth_is_supported(card,IPA_FULL_VLAN))) ||
5711 (card->vlangrp == NULL) )
5712 return ;
5713
5714 vg = card->vlangrp;
5715 for (i = 0; i < VLAN_GROUP_ARRAY_LEN; i++) {
5716 if (vg->vlan_devices[i] == NULL ||
5717 !(vg->vlan_devices[i]->flags & IFF_UP))
5718 continue;
5719 in_dev = in_dev_get(vg->vlan_devices[i]);
5720 if (!in_dev)
5721 continue;
5722 read_lock(&in_dev->mc_list_lock);
5723 qeth_add_mc(card,in_dev);
5724 read_unlock(&in_dev->mc_list_lock);
5725 in_dev_put(in_dev);
5726 }
5727#endif
5728}
5729
5730static void
5731qeth_add_multicast_ipv4(struct qeth_card *card)
5732{
5733 struct in_device *in4_dev;
5734
5735 QETH_DBF_TEXT(trace,4,"chkmcv4");
5736 in4_dev = in_dev_get(card->dev);
5737 if (in4_dev == NULL)
5738 return;
5739 read_lock(&in4_dev->mc_list_lock);
5740 qeth_add_mc(card, in4_dev);
5741 qeth_add_vlan_mc(card);
5742 read_unlock(&in4_dev->mc_list_lock);
5743 in_dev_put(in4_dev);
5744}
5745
Frank Pavlic6c88ad22005-11-10 13:49:28 +01005746static void
5747qeth_layer2_add_multicast(struct qeth_card *card)
5748{
5749 struct qeth_ipaddr *ipm;
5750 struct dev_mc_list *dm;
5751
5752 QETH_DBF_TEXT(trace,4,"L2addmc");
5753 for (dm = card->dev->mc_list; dm; dm = dm->next) {
5754 ipm = qeth_get_addr_buffer(QETH_PROT_IPV4);
5755 if (!ipm)
5756 continue;
5757 memcpy(ipm->mac,dm->dmi_addr,MAX_ADDR_LEN);
5758 ipm->is_multicast = 1;
5759 if (!qeth_add_ip(card, ipm))
5760 kfree(ipm);
5761 }
5762}
5763
Linus Torvalds1da177e2005-04-16 15:20:36 -07005764#ifdef CONFIG_QETH_IPV6
5765static inline void
5766qeth_add_mc6(struct qeth_card *card, struct inet6_dev *in6_dev)
5767{
5768 struct qeth_ipaddr *ipm;
5769 struct ifmcaddr6 *im6;
5770 char buf[MAX_ADDR_LEN];
5771
5772 QETH_DBF_TEXT(trace,4,"addmc6");
5773 for (im6 = in6_dev->mc_list; im6 != NULL; im6 = im6->next) {
5774 ndisc_mc_map(&im6->mca_addr, buf, in6_dev->dev, 0);
5775 ipm = qeth_get_addr_buffer(QETH_PROT_IPV6);
5776 if (!ipm)
5777 continue;
5778 ipm->is_multicast = 1;
5779 memcpy(ipm->mac,buf,OSA_ADDR_LEN);
5780 memcpy(&ipm->u.a6.addr,&im6->mca_addr.s6_addr,
5781 sizeof(struct in6_addr));
5782 if (!qeth_add_ip(card,ipm))
5783 kfree(ipm);
5784 }
5785}
5786
5787static inline void
5788qeth_add_vlan_mc6(struct qeth_card *card)
5789{
5790#ifdef CONFIG_QETH_VLAN
5791 struct inet6_dev *in_dev;
5792 struct vlan_group *vg;
5793 int i;
5794
5795 QETH_DBF_TEXT(trace,4,"admc6vl");
5796 if ( ((card->options.layer2 == 0) &&
5797 (!qeth_is_supported(card,IPA_FULL_VLAN))) ||
5798 (card->vlangrp == NULL))
5799 return ;
5800
5801 vg = card->vlangrp;
5802 for (i = 0; i < VLAN_GROUP_ARRAY_LEN; i++) {
5803 if (vg->vlan_devices[i] == NULL ||
5804 !(vg->vlan_devices[i]->flags & IFF_UP))
5805 continue;
5806 in_dev = in6_dev_get(vg->vlan_devices[i]);
5807 if (!in_dev)
5808 continue;
5809 read_lock(&in_dev->lock);
5810 qeth_add_mc6(card,in_dev);
5811 read_unlock(&in_dev->lock);
5812 in6_dev_put(in_dev);
5813 }
5814#endif /* CONFIG_QETH_VLAN */
5815}
5816
5817static void
5818qeth_add_multicast_ipv6(struct qeth_card *card)
5819{
5820 struct inet6_dev *in6_dev;
5821
5822 QETH_DBF_TEXT(trace,4,"chkmcv6");
Jeff Garzike82b0f22006-05-26 21:58:38 -04005823 if (!qeth_is_supported(card, IPA_IPV6))
Linus Torvalds1da177e2005-04-16 15:20:36 -07005824 return ;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005825 in6_dev = in6_dev_get(card->dev);
5826 if (in6_dev == NULL)
5827 return;
5828 read_lock(&in6_dev->lock);
5829 qeth_add_mc6(card, in6_dev);
5830 qeth_add_vlan_mc6(card);
5831 read_unlock(&in6_dev->lock);
5832 in6_dev_put(in6_dev);
5833}
5834#endif /* CONFIG_QETH_IPV6 */
5835
5836static int
5837qeth_layer2_send_setdelmac(struct qeth_card *card, __u8 *mac,
5838 enum qeth_ipa_cmds ipacmd,
5839 int (*reply_cb) (struct qeth_card *,
5840 struct qeth_reply*,
5841 unsigned long))
5842{
5843 struct qeth_ipa_cmd *cmd;
5844 struct qeth_cmd_buffer *iob;
5845
5846 QETH_DBF_TEXT(trace, 2, "L2sdmac");
5847 iob = qeth_get_ipacmd_buffer(card, ipacmd, QETH_PROT_IPV4);
5848 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
5849 cmd->data.setdelmac.mac_length = OSA_ADDR_LEN;
5850 memcpy(&cmd->data.setdelmac.mac, mac, OSA_ADDR_LEN);
5851 return qeth_send_ipa_cmd(card, iob, reply_cb, NULL);
5852}
5853
5854static int
5855qeth_layer2_send_setgroupmac_cb(struct qeth_card *card,
5856 struct qeth_reply *reply,
5857 unsigned long data)
5858{
5859 struct qeth_ipa_cmd *cmd;
5860 __u8 *mac;
5861
5862 QETH_DBF_TEXT(trace, 2, "L2Sgmacb");
5863 cmd = (struct qeth_ipa_cmd *) data;
5864 mac = &cmd->data.setdelmac.mac[0];
5865 /* MAC already registered, needed in couple/uncouple case */
5866 if (cmd->hdr.return_code == 0x2005) {
5867 PRINT_WARN("Group MAC %02x:%02x:%02x:%02x:%02x:%02x " \
5868 "already existing on %s \n",
5869 mac[0], mac[1], mac[2], mac[3], mac[4], mac[5],
5870 QETH_CARD_IFNAME(card));
5871 cmd->hdr.return_code = 0;
5872 }
5873 if (cmd->hdr.return_code)
5874 PRINT_ERR("Could not set group MAC " \
5875 "%02x:%02x:%02x:%02x:%02x:%02x on %s: %x\n",
5876 mac[0], mac[1], mac[2], mac[3], mac[4], mac[5],
5877 QETH_CARD_IFNAME(card),cmd->hdr.return_code);
5878 return 0;
5879}
5880
5881static int
5882qeth_layer2_send_setgroupmac(struct qeth_card *card, __u8 *mac)
5883{
5884 QETH_DBF_TEXT(trace, 2, "L2Sgmac");
5885 return qeth_layer2_send_setdelmac(card, mac, IPA_CMD_SETGMAC,
5886 qeth_layer2_send_setgroupmac_cb);
5887}
5888
5889static int
5890qeth_layer2_send_delgroupmac_cb(struct qeth_card *card,
5891 struct qeth_reply *reply,
5892 unsigned long data)
5893{
5894 struct qeth_ipa_cmd *cmd;
5895 __u8 *mac;
5896
5897 QETH_DBF_TEXT(trace, 2, "L2Dgmacb");
5898 cmd = (struct qeth_ipa_cmd *) data;
5899 mac = &cmd->data.setdelmac.mac[0];
5900 if (cmd->hdr.return_code)
5901 PRINT_ERR("Could not delete group MAC " \
5902 "%02x:%02x:%02x:%02x:%02x:%02x on %s: %x\n",
5903 mac[0], mac[1], mac[2], mac[3], mac[4], mac[5],
5904 QETH_CARD_IFNAME(card), cmd->hdr.return_code);
5905 return 0;
5906}
5907
5908static int
5909qeth_layer2_send_delgroupmac(struct qeth_card *card, __u8 *mac)
5910{
5911 QETH_DBF_TEXT(trace, 2, "L2Dgmac");
5912 return qeth_layer2_send_setdelmac(card, mac, IPA_CMD_DELGMAC,
5913 qeth_layer2_send_delgroupmac_cb);
5914}
5915
5916static int
5917qeth_layer2_send_setmac_cb(struct qeth_card *card,
5918 struct qeth_reply *reply,
5919 unsigned long data)
5920{
5921 struct qeth_ipa_cmd *cmd;
5922
5923 QETH_DBF_TEXT(trace, 2, "L2Smaccb");
5924 cmd = (struct qeth_ipa_cmd *) data;
5925 if (cmd->hdr.return_code) {
5926 QETH_DBF_TEXT_(trace, 2, "L2er%x", cmd->hdr.return_code);
5927 PRINT_WARN("Error in registering MAC address on " \
5928 "device %s: x%x\n", CARD_BUS_ID(card),
5929 cmd->hdr.return_code);
Frank Pavlice08d88c2005-11-10 13:51:17 +01005930 card->info.mac_bits &= ~QETH_LAYER2_MAC_REGISTERED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005931 cmd->hdr.return_code = -EIO;
5932 } else {
Frank Pavlice08d88c2005-11-10 13:51:17 +01005933 card->info.mac_bits |= QETH_LAYER2_MAC_REGISTERED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005934 memcpy(card->dev->dev_addr,cmd->data.setdelmac.mac,
5935 OSA_ADDR_LEN);
5936 PRINT_INFO("MAC address %2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x "
5937 "successfully registered on device %s\n",
5938 card->dev->dev_addr[0], card->dev->dev_addr[1],
5939 card->dev->dev_addr[2], card->dev->dev_addr[3],
5940 card->dev->dev_addr[4], card->dev->dev_addr[5],
5941 card->dev->name);
5942 }
5943 return 0;
5944}
5945
5946static int
5947qeth_layer2_send_setmac(struct qeth_card *card, __u8 *mac)
5948{
5949 QETH_DBF_TEXT(trace, 2, "L2Setmac");
5950 return qeth_layer2_send_setdelmac(card, mac, IPA_CMD_SETVMAC,
5951 qeth_layer2_send_setmac_cb);
5952}
5953
5954static int
5955qeth_layer2_send_delmac_cb(struct qeth_card *card,
5956 struct qeth_reply *reply,
5957 unsigned long data)
5958{
5959 struct qeth_ipa_cmd *cmd;
5960
5961 QETH_DBF_TEXT(trace, 2, "L2Dmaccb");
5962 cmd = (struct qeth_ipa_cmd *) data;
5963 if (cmd->hdr.return_code) {
5964 PRINT_WARN("Error in deregistering MAC address on " \
5965 "device %s: x%x\n", CARD_BUS_ID(card),
5966 cmd->hdr.return_code);
5967 QETH_DBF_TEXT_(trace, 2, "err%d", cmd->hdr.return_code);
5968 cmd->hdr.return_code = -EIO;
5969 return 0;
5970 }
Frank Pavlice08d88c2005-11-10 13:51:17 +01005971 card->info.mac_bits &= ~QETH_LAYER2_MAC_REGISTERED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005972
5973 return 0;
5974}
5975static int
5976qeth_layer2_send_delmac(struct qeth_card *card, __u8 *mac)
5977{
5978 QETH_DBF_TEXT(trace, 2, "L2Delmac");
Frank Pavlice08d88c2005-11-10 13:51:17 +01005979 if (!(card->info.mac_bits & QETH_LAYER2_MAC_REGISTERED))
Linus Torvalds1da177e2005-04-16 15:20:36 -07005980 return 0;
5981 return qeth_layer2_send_setdelmac(card, mac, IPA_CMD_DELVMAC,
5982 qeth_layer2_send_delmac_cb);
5983}
5984
5985static int
5986qeth_layer2_set_mac_address(struct net_device *dev, void *p)
5987{
5988 struct sockaddr *addr = p;
5989 struct qeth_card *card;
5990 int rc = 0;
5991
5992 QETH_DBF_TEXT(trace, 3, "setmac");
5993
5994 if (qeth_verify_dev(dev) != QETH_REAL_CARD) {
5995 QETH_DBF_TEXT(trace, 3, "setmcINV");
5996 return -EOPNOTSUPP;
5997 }
5998 card = (struct qeth_card *) dev->priv;
5999
6000 if (!card->options.layer2) {
Frank Pavlice08d88c2005-11-10 13:51:17 +01006001 PRINT_WARN("Setting MAC address on %s is not supported "
Linus Torvalds1da177e2005-04-16 15:20:36 -07006002 "in Layer 3 mode.\n", dev->name);
6003 QETH_DBF_TEXT(trace, 3, "setmcLY3");
6004 return -EOPNOTSUPP;
6005 }
Ursula Braun500f83a2005-09-30 10:19:19 +02006006 if (card->info.type == QETH_CARD_TYPE_OSN) {
6007 PRINT_WARN("Setting MAC address on %s is not supported.\n",
6008 dev->name);
6009 QETH_DBF_TEXT(trace, 3, "setmcOSN");
6010 return -EOPNOTSUPP;
6011 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07006012 QETH_DBF_TEXT_(trace, 3, "%s", CARD_BUS_ID(card));
6013 QETH_DBF_HEX(trace, 3, addr->sa_data, OSA_ADDR_LEN);
6014 rc = qeth_layer2_send_delmac(card, &card->dev->dev_addr[0]);
6015 if (!rc)
6016 rc = qeth_layer2_send_setmac(card, addr->sa_data);
6017 return rc;
6018}
6019
6020static void
6021qeth_fill_ipacmd_header(struct qeth_card *card, struct qeth_ipa_cmd *cmd,
6022 __u8 command, enum qeth_prot_versions prot)
6023{
6024 memset(cmd, 0, sizeof (struct qeth_ipa_cmd));
6025 cmd->hdr.command = command;
6026 cmd->hdr.initiator = IPA_CMD_INITIATOR_HOST;
6027 cmd->hdr.seqno = card->seqno.ipa;
6028 cmd->hdr.adapter_type = qeth_get_ipa_adp_type(card->info.link_type);
6029 cmd->hdr.rel_adapter_no = (__u8) card->info.portno;
6030 if (card->options.layer2)
6031 cmd->hdr.prim_version_no = 2;
6032 else
6033 cmd->hdr.prim_version_no = 1;
6034 cmd->hdr.param_count = 1;
6035 cmd->hdr.prot_version = prot;
6036 cmd->hdr.ipa_supported = 0;
6037 cmd->hdr.ipa_enabled = 0;
6038}
6039
6040static struct qeth_cmd_buffer *
6041qeth_get_ipacmd_buffer(struct qeth_card *card, enum qeth_ipa_cmds ipacmd,
6042 enum qeth_prot_versions prot)
6043{
6044 struct qeth_cmd_buffer *iob;
6045 struct qeth_ipa_cmd *cmd;
6046
6047 iob = qeth_wait_for_buffer(&card->write);
6048 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
6049 qeth_fill_ipacmd_header(card, cmd, ipacmd, prot);
6050
6051 return iob;
6052}
6053
6054static int
6055qeth_send_setdelmc(struct qeth_card *card, struct qeth_ipaddr *addr, int ipacmd)
6056{
6057 int rc;
6058 struct qeth_cmd_buffer *iob;
6059 struct qeth_ipa_cmd *cmd;
6060
6061 QETH_DBF_TEXT(trace,4,"setdelmc");
6062
6063 iob = qeth_get_ipacmd_buffer(card, ipacmd, addr->proto);
6064 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
6065 memcpy(&cmd->data.setdelipm.mac,addr->mac, OSA_ADDR_LEN);
6066 if (addr->proto == QETH_PROT_IPV6)
6067 memcpy(cmd->data.setdelipm.ip6, &addr->u.a6.addr,
6068 sizeof(struct in6_addr));
6069 else
6070 memcpy(&cmd->data.setdelipm.ip4, &addr->u.a4.addr,4);
6071
6072 rc = qeth_send_ipa_cmd(card, iob, NULL, NULL);
6073
6074 return rc;
6075}
6076static inline void
6077qeth_fill_netmask(u8 *netmask, unsigned int len)
6078{
6079 int i,j;
6080 for (i=0;i<16;i++) {
6081 j=(len)-(i*8);
6082 if (j >= 8)
6083 netmask[i] = 0xff;
6084 else if (j > 0)
6085 netmask[i] = (u8)(0xFF00>>j);
6086 else
6087 netmask[i] = 0;
6088 }
6089}
6090
6091static int
6092qeth_send_setdelip(struct qeth_card *card, struct qeth_ipaddr *addr,
6093 int ipacmd, unsigned int flags)
6094{
6095 int rc;
6096 struct qeth_cmd_buffer *iob;
6097 struct qeth_ipa_cmd *cmd;
6098 __u8 netmask[16];
6099
6100 QETH_DBF_TEXT(trace,4,"setdelip");
6101 QETH_DBF_TEXT_(trace,4,"flags%02X", flags);
6102
6103 iob = qeth_get_ipacmd_buffer(card, ipacmd, addr->proto);
6104 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
6105 if (addr->proto == QETH_PROT_IPV6) {
6106 memcpy(cmd->data.setdelip6.ip_addr, &addr->u.a6.addr,
6107 sizeof(struct in6_addr));
6108 qeth_fill_netmask(netmask,addr->u.a6.pfxlen);
6109 memcpy(cmd->data.setdelip6.mask, netmask,
6110 sizeof(struct in6_addr));
6111 cmd->data.setdelip6.flags = flags;
6112 } else {
6113 memcpy(cmd->data.setdelip4.ip_addr, &addr->u.a4.addr, 4);
6114 memcpy(cmd->data.setdelip4.mask, &addr->u.a4.mask, 4);
6115 cmd->data.setdelip4.flags = flags;
6116 }
6117
6118 rc = qeth_send_ipa_cmd(card, iob, NULL, NULL);
6119
6120 return rc;
6121}
6122
6123static int
6124qeth_layer2_register_addr_entry(struct qeth_card *card,
6125 struct qeth_ipaddr *addr)
6126{
6127 if (!addr->is_multicast)
6128 return 0;
6129 QETH_DBF_TEXT(trace, 2, "setgmac");
6130 QETH_DBF_HEX(trace,3,&addr->mac[0],OSA_ADDR_LEN);
6131 return qeth_layer2_send_setgroupmac(card, &addr->mac[0]);
6132}
6133
6134static int
6135qeth_layer2_deregister_addr_entry(struct qeth_card *card,
6136 struct qeth_ipaddr *addr)
6137{
6138 if (!addr->is_multicast)
6139 return 0;
6140 QETH_DBF_TEXT(trace, 2, "delgmac");
6141 QETH_DBF_HEX(trace,3,&addr->mac[0],OSA_ADDR_LEN);
6142 return qeth_layer2_send_delgroupmac(card, &addr->mac[0]);
6143}
6144
6145static int
6146qeth_layer3_register_addr_entry(struct qeth_card *card,
6147 struct qeth_ipaddr *addr)
6148{
6149 char buf[50];
6150 int rc;
6151 int cnt = 3;
6152
6153 if (addr->proto == QETH_PROT_IPV4) {
6154 QETH_DBF_TEXT(trace, 2,"setaddr4");
6155 QETH_DBF_HEX(trace, 3, &addr->u.a4.addr, sizeof(int));
6156 } else if (addr->proto == QETH_PROT_IPV6) {
6157 QETH_DBF_TEXT(trace, 2, "setaddr6");
6158 QETH_DBF_HEX(trace,3,&addr->u.a6.addr,8);
6159 QETH_DBF_HEX(trace,3,((char *)&addr->u.a6.addr)+8,8);
6160 } else {
6161 QETH_DBF_TEXT(trace, 2, "setaddr?");
6162 QETH_DBF_HEX(trace, 3, addr, sizeof(struct qeth_ipaddr));
6163 }
6164 do {
6165 if (addr->is_multicast)
6166 rc = qeth_send_setdelmc(card, addr, IPA_CMD_SETIPM);
6167 else
6168 rc = qeth_send_setdelip(card, addr, IPA_CMD_SETIP,
6169 addr->set_flags);
6170 if (rc)
6171 QETH_DBF_TEXT(trace, 2, "failed");
6172 } while ((--cnt > 0) && rc);
6173 if (rc){
6174 QETH_DBF_TEXT(trace, 2, "FAILED");
6175 qeth_ipaddr_to_string(addr->proto, (u8 *)&addr->u, buf);
6176 PRINT_WARN("Could not register IP address %s (rc=0x%x/%d)\n",
6177 buf, rc, rc);
6178 }
6179 return rc;
6180}
6181
6182static int
6183qeth_layer3_deregister_addr_entry(struct qeth_card *card,
6184 struct qeth_ipaddr *addr)
6185{
6186 //char buf[50];
6187 int rc;
6188
6189 if (addr->proto == QETH_PROT_IPV4) {
6190 QETH_DBF_TEXT(trace, 2,"deladdr4");
6191 QETH_DBF_HEX(trace, 3, &addr->u.a4.addr, sizeof(int));
6192 } else if (addr->proto == QETH_PROT_IPV6) {
6193 QETH_DBF_TEXT(trace, 2, "deladdr6");
6194 QETH_DBF_HEX(trace,3,&addr->u.a6.addr,8);
6195 QETH_DBF_HEX(trace,3,((char *)&addr->u.a6.addr)+8,8);
6196 } else {
6197 QETH_DBF_TEXT(trace, 2, "deladdr?");
6198 QETH_DBF_HEX(trace, 3, addr, sizeof(struct qeth_ipaddr));
6199 }
6200 if (addr->is_multicast)
6201 rc = qeth_send_setdelmc(card, addr, IPA_CMD_DELIPM);
6202 else
6203 rc = qeth_send_setdelip(card, addr, IPA_CMD_DELIP,
6204 addr->del_flags);
6205 if (rc) {
6206 QETH_DBF_TEXT(trace, 2, "failed");
6207 /* TODO: re-activate this warning as soon as we have a
6208 * clean mirco code
6209 qeth_ipaddr_to_string(addr->proto, (u8 *)&addr->u, buf);
6210 PRINT_WARN("Could not deregister IP address %s (rc=%x)\n",
6211 buf, rc);
6212 */
6213 }
6214 return rc;
6215}
6216
6217static int
6218qeth_register_addr_entry(struct qeth_card *card, struct qeth_ipaddr *addr)
6219{
6220 if (card->options.layer2)
6221 return qeth_layer2_register_addr_entry(card, addr);
6222
6223 return qeth_layer3_register_addr_entry(card, addr);
6224}
6225
6226static int
6227qeth_deregister_addr_entry(struct qeth_card *card, struct qeth_ipaddr *addr)
6228{
6229 if (card->options.layer2)
6230 return qeth_layer2_deregister_addr_entry(card, addr);
6231
6232 return qeth_layer3_deregister_addr_entry(card, addr);
6233}
6234
6235static u32
6236qeth_ethtool_get_tx_csum(struct net_device *dev)
6237{
6238 /* We may need to say that we support tx csum offload if
6239 * we do EDDP or TSO. There are discussions going on to
6240 * enforce rules in the stack and in ethtool that make
6241 * SG and TSO depend on HW_CSUM. At the moment there are
6242 * no such rules....
6243 * If we say yes here, we have to checksum outbound packets
6244 * any time. */
6245 return 0;
6246}
6247
6248static int
6249qeth_ethtool_set_tx_csum(struct net_device *dev, u32 data)
6250{
6251 return -EINVAL;
6252}
6253
6254static u32
6255qeth_ethtool_get_rx_csum(struct net_device *dev)
6256{
6257 struct qeth_card *card = (struct qeth_card *)dev->priv;
6258
6259 return (card->options.checksum_type == HW_CHECKSUMMING);
6260}
6261
6262static int
6263qeth_ethtool_set_rx_csum(struct net_device *dev, u32 data)
6264{
6265 struct qeth_card *card = (struct qeth_card *)dev->priv;
6266
6267 if ((card->state != CARD_STATE_DOWN) &&
6268 (card->state != CARD_STATE_RECOVER))
6269 return -EPERM;
6270 if (data)
6271 card->options.checksum_type = HW_CHECKSUMMING;
6272 else
6273 card->options.checksum_type = SW_CHECKSUMMING;
6274 return 0;
6275}
6276
6277static u32
6278qeth_ethtool_get_sg(struct net_device *dev)
6279{
6280 struct qeth_card *card = (struct qeth_card *)dev->priv;
6281
6282 return ((card->options.large_send != QETH_LARGE_SEND_NO) &&
6283 (dev->features & NETIF_F_SG));
6284}
6285
6286static int
6287qeth_ethtool_set_sg(struct net_device *dev, u32 data)
6288{
6289 struct qeth_card *card = (struct qeth_card *)dev->priv;
6290
6291 if (data) {
6292 if (card->options.large_send != QETH_LARGE_SEND_NO)
6293 dev->features |= NETIF_F_SG;
6294 else {
6295 dev->features &= ~NETIF_F_SG;
6296 return -EINVAL;
6297 }
6298 } else
6299 dev->features &= ~NETIF_F_SG;
6300 return 0;
6301}
6302
6303static u32
6304qeth_ethtool_get_tso(struct net_device *dev)
6305{
6306 struct qeth_card *card = (struct qeth_card *)dev->priv;
6307
6308 return ((card->options.large_send != QETH_LARGE_SEND_NO) &&
6309 (dev->features & NETIF_F_TSO));
6310}
6311
6312static int
6313qeth_ethtool_set_tso(struct net_device *dev, u32 data)
6314{
6315 struct qeth_card *card = (struct qeth_card *)dev->priv;
6316
6317 if (data) {
6318 if (card->options.large_send != QETH_LARGE_SEND_NO)
6319 dev->features |= NETIF_F_TSO;
6320 else {
6321 dev->features &= ~NETIF_F_TSO;
6322 return -EINVAL;
6323 }
6324 } else
6325 dev->features &= ~NETIF_F_TSO;
6326 return 0;
6327}
6328
6329static struct ethtool_ops qeth_ethtool_ops = {
6330 .get_tx_csum = qeth_ethtool_get_tx_csum,
6331 .set_tx_csum = qeth_ethtool_set_tx_csum,
6332 .get_rx_csum = qeth_ethtool_get_rx_csum,
6333 .set_rx_csum = qeth_ethtool_set_rx_csum,
6334 .get_sg = qeth_ethtool_get_sg,
6335 .set_sg = qeth_ethtool_set_sg,
6336 .get_tso = qeth_ethtool_get_tso,
6337 .set_tso = qeth_ethtool_set_tso,
6338};
6339
6340static int
6341qeth_netdev_init(struct net_device *dev)
6342{
6343 struct qeth_card *card;
6344
6345 card = (struct qeth_card *) dev->priv;
6346
6347 QETH_DBF_TEXT(trace,3,"initdev");
6348
6349 dev->tx_timeout = &qeth_tx_timeout;
6350 dev->watchdog_timeo = QETH_TX_TIMEOUT;
6351 dev->open = qeth_open;
6352 dev->stop = qeth_stop;
6353 dev->hard_start_xmit = qeth_hard_start_xmit;
6354 dev->do_ioctl = qeth_do_ioctl;
6355 dev->get_stats = qeth_get_stats;
6356 dev->change_mtu = qeth_change_mtu;
6357 dev->neigh_setup = qeth_neigh_setup;
6358 dev->set_multicast_list = qeth_set_multicast_list;
6359#ifdef CONFIG_QETH_VLAN
6360 dev->vlan_rx_register = qeth_vlan_rx_register;
6361 dev->vlan_rx_kill_vid = qeth_vlan_rx_kill_vid;
6362 dev->vlan_rx_add_vid = qeth_vlan_rx_add_vid;
6363#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07006364 if (qeth_get_netdev_flags(card) & IFF_NOARP) {
6365 dev->rebuild_header = NULL;
6366 dev->hard_header = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006367 dev->header_cache_update = NULL;
6368 dev->hard_header_cache = NULL;
6369 }
6370#ifdef CONFIG_QETH_IPV6
6371 /*IPv6 address autoconfiguration stuff*/
6372 if (!(card->info.unique_id & UNIQUE_ID_NOT_BY_CARD))
6373 card->dev->dev_id = card->info.unique_id & 0xffff;
6374#endif
Jeff Garzike82b0f22006-05-26 21:58:38 -04006375 if (card->options.fake_ll &&
Ursula Braunba1aa082006-05-24 09:51:13 +02006376 (qeth_get_netdev_flags(card) & IFF_NOARP))
6377 dev->hard_header = qeth_fake_header;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006378 dev->hard_header_parse = NULL;
6379 dev->set_mac_address = qeth_layer2_set_mac_address;
6380 dev->flags |= qeth_get_netdev_flags(card);
6381 if ((card->options.fake_broadcast) ||
6382 (card->info.broadcast_capable))
6383 dev->flags |= IFF_BROADCAST;
6384 dev->hard_header_len =
6385 qeth_get_hlen(card->info.link_type) + card->options.add_hhlen;
6386 dev->addr_len = OSA_ADDR_LEN;
6387 dev->mtu = card->info.initial_mtu;
Ursula Braun500f83a2005-09-30 10:19:19 +02006388 if (card->info.type != QETH_CARD_TYPE_OSN)
6389 SET_ETHTOOL_OPS(dev, &qeth_ethtool_ops);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006390 SET_MODULE_OWNER(dev);
6391 return 0;
6392}
6393
6394static void
6395qeth_init_func_level(struct qeth_card *card)
6396{
6397 if (card->ipato.enabled) {
6398 if (card->info.type == QETH_CARD_TYPE_IQD)
6399 card->info.func_level =
6400 QETH_IDX_FUNC_LEVEL_IQD_ENA_IPAT;
6401 else
6402 card->info.func_level =
6403 QETH_IDX_FUNC_LEVEL_OSAE_ENA_IPAT;
6404 } else {
6405 if (card->info.type == QETH_CARD_TYPE_IQD)
Ursula Braun500f83a2005-09-30 10:19:19 +02006406 /*FIXME:why do we have same values for dis and ena for osae??? */
Linus Torvalds1da177e2005-04-16 15:20:36 -07006407 card->info.func_level =
6408 QETH_IDX_FUNC_LEVEL_IQD_DIS_IPAT;
6409 else
6410 card->info.func_level =
6411 QETH_IDX_FUNC_LEVEL_OSAE_DIS_IPAT;
6412 }
6413}
6414
6415/**
6416 * hardsetup card, initialize MPC and QDIO stuff
6417 */
6418static int
6419qeth_hardsetup_card(struct qeth_card *card)
6420{
6421 int retries = 3;
6422 int rc;
6423
6424 QETH_DBF_TEXT(setup, 2, "hrdsetup");
6425
6426retry:
6427 if (retries < 3){
6428 PRINT_WARN("Retrying to do IDX activates.\n");
6429 ccw_device_set_offline(CARD_DDEV(card));
6430 ccw_device_set_offline(CARD_WDEV(card));
6431 ccw_device_set_offline(CARD_RDEV(card));
6432 ccw_device_set_online(CARD_RDEV(card));
6433 ccw_device_set_online(CARD_WDEV(card));
6434 ccw_device_set_online(CARD_DDEV(card));
6435 }
Ursula Braun500f83a2005-09-30 10:19:19 +02006436 rc = qeth_qdio_clear_card(card,card->info.type!=QETH_CARD_TYPE_IQD);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006437 if (rc == -ERESTARTSYS) {
6438 QETH_DBF_TEXT(setup, 2, "break1");
6439 return rc;
6440 } else if (rc) {
6441 QETH_DBF_TEXT_(setup, 2, "1err%d", rc);
6442 if (--retries < 0)
6443 goto out;
6444 else
6445 goto retry;
6446 }
6447 if ((rc = qeth_get_unitaddr(card))){
6448 QETH_DBF_TEXT_(setup, 2, "2err%d", rc);
6449 return rc;
6450 }
6451 qeth_init_tokens(card);
6452 qeth_init_func_level(card);
6453 rc = qeth_idx_activate_channel(&card->read, qeth_idx_read_cb);
6454 if (rc == -ERESTARTSYS) {
6455 QETH_DBF_TEXT(setup, 2, "break2");
6456 return rc;
6457 } else if (rc) {
6458 QETH_DBF_TEXT_(setup, 2, "3err%d", rc);
6459 if (--retries < 0)
6460 goto out;
6461 else
6462 goto retry;
6463 }
6464 rc = qeth_idx_activate_channel(&card->write, qeth_idx_write_cb);
6465 if (rc == -ERESTARTSYS) {
6466 QETH_DBF_TEXT(setup, 2, "break3");
6467 return rc;
6468 } else if (rc) {
6469 QETH_DBF_TEXT_(setup, 2, "4err%d", rc);
6470 if (--retries < 0)
6471 goto out;
6472 else
6473 goto retry;
6474 }
6475 if ((rc = qeth_mpc_initialize(card))){
6476 QETH_DBF_TEXT_(setup, 2, "5err%d", rc);
6477 goto out;
6478 }
6479 /*network device will be recovered*/
6480 if (card->dev) {
6481 card->dev->hard_header = card->orig_hard_header;
Jeff Garzike82b0f22006-05-26 21:58:38 -04006482 if (card->options.fake_ll &&
Ursula Braunb85e1fa2006-05-24 09:51:11 +02006483 (qeth_get_netdev_flags(card) & IFF_NOARP))
6484 card->dev->hard_header = qeth_fake_header;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006485 return 0;
6486 }
6487 /* at first set_online allocate netdev */
6488 card->dev = qeth_get_netdevice(card->info.type,
6489 card->info.link_type);
6490 if (!card->dev){
Ursula Braun500f83a2005-09-30 10:19:19 +02006491 qeth_qdio_clear_card(card, card->info.type !=
6492 QETH_CARD_TYPE_IQD);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006493 rc = -ENODEV;
6494 QETH_DBF_TEXT_(setup, 2, "6err%d", rc);
6495 goto out;
6496 }
6497 card->dev->priv = card;
6498 card->orig_hard_header = card->dev->hard_header;
6499 card->dev->type = qeth_get_arphdr_type(card->info.type,
6500 card->info.link_type);
6501 card->dev->init = qeth_netdev_init;
6502 return 0;
6503out:
6504 PRINT_ERR("Initialization in hardsetup failed! rc=%d\n", rc);
6505 return rc;
6506}
6507
6508static int
6509qeth_default_setassparms_cb(struct qeth_card *card, struct qeth_reply *reply,
6510 unsigned long data)
6511{
6512 struct qeth_ipa_cmd *cmd;
6513
6514 QETH_DBF_TEXT(trace,4,"defadpcb");
6515
6516 cmd = (struct qeth_ipa_cmd *) data;
6517 if (cmd->hdr.return_code == 0){
6518 cmd->hdr.return_code = cmd->data.setassparms.hdr.return_code;
6519 if (cmd->hdr.prot_version == QETH_PROT_IPV4)
6520 card->options.ipa4.enabled_funcs = cmd->hdr.ipa_enabled;
6521#ifdef CONFIG_QETH_IPV6
6522 if (cmd->hdr.prot_version == QETH_PROT_IPV6)
6523 card->options.ipa6.enabled_funcs = cmd->hdr.ipa_enabled;
6524#endif
6525 }
6526 if (cmd->data.setassparms.hdr.assist_no == IPA_INBOUND_CHECKSUM &&
6527 cmd->data.setassparms.hdr.command_code == IPA_CMD_ASS_START) {
6528 card->info.csum_mask = cmd->data.setassparms.data.flags_32bit;
6529 QETH_DBF_TEXT_(trace, 3, "csum:%d", card->info.csum_mask);
6530 }
6531 return 0;
6532}
6533
6534static int
6535qeth_default_setadapterparms_cb(struct qeth_card *card,
6536 struct qeth_reply *reply,
6537 unsigned long data)
6538{
6539 struct qeth_ipa_cmd *cmd;
6540
6541 QETH_DBF_TEXT(trace,4,"defadpcb");
6542
6543 cmd = (struct qeth_ipa_cmd *) data;
6544 if (cmd->hdr.return_code == 0)
6545 cmd->hdr.return_code = cmd->data.setadapterparms.hdr.return_code;
6546 return 0;
6547}
6548
Frank Pavlic6c951b92005-11-10 13:51:25 +01006549
6550
Linus Torvalds1da177e2005-04-16 15:20:36 -07006551static int
6552qeth_query_setadapterparms_cb(struct qeth_card *card, struct qeth_reply *reply,
6553 unsigned long data)
6554{
6555 struct qeth_ipa_cmd *cmd;
6556
6557 QETH_DBF_TEXT(trace,3,"quyadpcb");
6558
6559 cmd = (struct qeth_ipa_cmd *) data;
6560 if (cmd->data.setadapterparms.data.query_cmds_supp.lan_type & 0x7f)
6561 card->info.link_type =
6562 cmd->data.setadapterparms.data.query_cmds_supp.lan_type;
6563 card->options.adp.supported_funcs =
6564 cmd->data.setadapterparms.data.query_cmds_supp.supported_cmds;
6565 return qeth_default_setadapterparms_cb(card, reply, (unsigned long)cmd);
6566}
6567
6568static int
6569qeth_query_setadapterparms(struct qeth_card *card)
6570{
6571 int rc;
6572 struct qeth_cmd_buffer *iob;
6573
6574 QETH_DBF_TEXT(trace,3,"queryadp");
6575 iob = qeth_get_adapter_cmd(card, IPA_SETADP_QUERY_COMMANDS_SUPPORTED,
6576 sizeof(struct qeth_ipacmd_setadpparms));
6577 rc = qeth_send_ipa_cmd(card, iob, qeth_query_setadapterparms_cb, NULL);
6578 return rc;
6579}
6580
6581static int
6582qeth_setadpparms_change_macaddr_cb(struct qeth_card *card,
6583 struct qeth_reply *reply,
6584 unsigned long data)
6585{
6586 struct qeth_ipa_cmd *cmd;
6587
6588 QETH_DBF_TEXT(trace,4,"chgmaccb");
6589
6590 cmd = (struct qeth_ipa_cmd *) data;
Frank Pavlice08d88c2005-11-10 13:51:17 +01006591 if (!card->options.layer2 || card->info.guestlan ||
Jeff Garzike82b0f22006-05-26 21:58:38 -04006592 !(card->info.mac_bits & QETH_LAYER2_MAC_READ)) {
Frank Pavlice08d88c2005-11-10 13:51:17 +01006593 memcpy(card->dev->dev_addr,
6594 &cmd->data.setadapterparms.data.change_addr.addr,
6595 OSA_ADDR_LEN);
6596 card->info.mac_bits |= QETH_LAYER2_MAC_READ;
6597 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07006598 qeth_default_setadapterparms_cb(card, reply, (unsigned long) cmd);
6599 return 0;
6600}
6601
6602static int
6603qeth_setadpparms_change_macaddr(struct qeth_card *card)
6604{
6605 int rc;
6606 struct qeth_cmd_buffer *iob;
6607 struct qeth_ipa_cmd *cmd;
6608
6609 QETH_DBF_TEXT(trace,4,"chgmac");
6610
6611 iob = qeth_get_adapter_cmd(card,IPA_SETADP_ALTER_MAC_ADDRESS,
6612 sizeof(struct qeth_ipacmd_setadpparms));
6613 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
6614 cmd->data.setadapterparms.data.change_addr.cmd = CHANGE_ADDR_READ_MAC;
6615 cmd->data.setadapterparms.data.change_addr.addr_size = OSA_ADDR_LEN;
6616 memcpy(&cmd->data.setadapterparms.data.change_addr.addr,
6617 card->dev->dev_addr, OSA_ADDR_LEN);
6618 rc = qeth_send_ipa_cmd(card, iob, qeth_setadpparms_change_macaddr_cb,
6619 NULL);
6620 return rc;
6621}
6622
6623static int
6624qeth_send_setadp_mode(struct qeth_card *card, __u32 command, __u32 mode)
6625{
6626 int rc;
6627 struct qeth_cmd_buffer *iob;
6628 struct qeth_ipa_cmd *cmd;
6629
6630 QETH_DBF_TEXT(trace,4,"adpmode");
6631
6632 iob = qeth_get_adapter_cmd(card, command,
6633 sizeof(struct qeth_ipacmd_setadpparms));
6634 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
6635 cmd->data.setadapterparms.data.mode = mode;
6636 rc = qeth_send_ipa_cmd(card, iob, qeth_default_setadapterparms_cb,
6637 NULL);
6638 return rc;
6639}
6640
6641static inline int
6642qeth_setadapter_hstr(struct qeth_card *card)
6643{
6644 int rc;
6645
6646 QETH_DBF_TEXT(trace,4,"adphstr");
6647
6648 if (qeth_adp_supported(card,IPA_SETADP_SET_BROADCAST_MODE)) {
6649 rc = qeth_send_setadp_mode(card, IPA_SETADP_SET_BROADCAST_MODE,
6650 card->options.broadcast_mode);
6651 if (rc)
6652 PRINT_WARN("couldn't set broadcast mode on "
6653 "device %s: x%x\n",
6654 CARD_BUS_ID(card), rc);
6655 rc = qeth_send_setadp_mode(card, IPA_SETADP_ALTER_MAC_ADDRESS,
6656 card->options.macaddr_mode);
6657 if (rc)
6658 PRINT_WARN("couldn't set macaddr mode on "
6659 "device %s: x%x\n", CARD_BUS_ID(card), rc);
6660 return rc;
6661 }
6662 if (card->options.broadcast_mode == QETH_TR_BROADCAST_LOCAL)
6663 PRINT_WARN("set adapter parameters not available "
6664 "to set broadcast mode, using ALLRINGS "
6665 "on device %s:\n", CARD_BUS_ID(card));
6666 if (card->options.macaddr_mode == QETH_TR_MACADDR_CANONICAL)
6667 PRINT_WARN("set adapter parameters not available "
6668 "to set macaddr mode, using NONCANONICAL "
6669 "on device %s:\n", CARD_BUS_ID(card));
6670 return 0;
6671}
6672
6673static int
6674qeth_setadapter_parms(struct qeth_card *card)
6675{
6676 int rc;
6677
6678 QETH_DBF_TEXT(setup, 2, "setadprm");
6679
6680 if (!qeth_is_supported(card, IPA_SETADAPTERPARMS)){
6681 PRINT_WARN("set adapter parameters not supported "
6682 "on device %s.\n",
6683 CARD_BUS_ID(card));
6684 QETH_DBF_TEXT(setup, 2, " notsupp");
6685 return 0;
6686 }
6687 rc = qeth_query_setadapterparms(card);
6688 if (rc) {
6689 PRINT_WARN("couldn't set adapter parameters on device %s: "
6690 "x%x\n", CARD_BUS_ID(card), rc);
6691 return rc;
6692 }
6693 if (qeth_adp_supported(card,IPA_SETADP_ALTER_MAC_ADDRESS)) {
6694 rc = qeth_setadpparms_change_macaddr(card);
6695 if (rc)
6696 PRINT_WARN("couldn't get MAC address on "
6697 "device %s: x%x\n",
6698 CARD_BUS_ID(card), rc);
6699 }
6700
6701 if ((card->info.link_type == QETH_LINK_TYPE_HSTR) ||
6702 (card->info.link_type == QETH_LINK_TYPE_LANE_TR))
6703 rc = qeth_setadapter_hstr(card);
6704
6705 return rc;
6706}
6707
6708static int
6709qeth_layer2_initialize(struct qeth_card *card)
6710{
6711 int rc = 0;
6712
6713
6714 QETH_DBF_TEXT(setup, 2, "doL2init");
6715 QETH_DBF_TEXT_(setup, 2, "doL2%s", CARD_BUS_ID(card));
6716
Frank Pavlic6c951b92005-11-10 13:51:25 +01006717 rc = qeth_query_setadapterparms(card);
6718 if (rc) {
6719 PRINT_WARN("could not query adapter parameters on device %s: "
6720 "x%x\n", CARD_BUS_ID(card), rc);
6721 }
6722
Linus Torvalds1da177e2005-04-16 15:20:36 -07006723 rc = qeth_setadpparms_change_macaddr(card);
6724 if (rc) {
6725 PRINT_WARN("couldn't get MAC address on "
6726 "device %s: x%x\n",
6727 CARD_BUS_ID(card), rc);
6728 QETH_DBF_TEXT_(setup, 2,"1err%d",rc);
6729 return rc;
6730 }
6731 QETH_DBF_HEX(setup,2, card->dev->dev_addr, OSA_ADDR_LEN);
6732
6733 rc = qeth_layer2_send_setmac(card, &card->dev->dev_addr[0]);
6734 if (rc)
6735 QETH_DBF_TEXT_(setup, 2,"2err%d",rc);
6736 return 0;
6737}
6738
6739
6740static int
6741qeth_send_startstoplan(struct qeth_card *card, enum qeth_ipa_cmds ipacmd,
6742 enum qeth_prot_versions prot)
6743{
6744 int rc;
6745 struct qeth_cmd_buffer *iob;
6746
6747 iob = qeth_get_ipacmd_buffer(card,ipacmd,prot);
6748 rc = qeth_send_ipa_cmd(card, iob, NULL, NULL);
6749
6750 return rc;
6751}
6752
6753static int
6754qeth_send_startlan(struct qeth_card *card, enum qeth_prot_versions prot)
6755{
6756 int rc;
6757
6758 QETH_DBF_TEXT_(setup, 2, "strtlan%i", prot);
6759
6760 rc = qeth_send_startstoplan(card, IPA_CMD_STARTLAN, prot);
6761 return rc;
6762}
6763
6764static int
6765qeth_send_stoplan(struct qeth_card *card)
6766{
6767 int rc = 0;
6768
6769 /*
6770 * TODO: according to the IPA format document page 14,
6771 * TCP/IP (we!) never issue a STOPLAN
6772 * is this right ?!?
6773 */
6774 QETH_DBF_TEXT(trace, 2, "stoplan");
6775
6776 rc = qeth_send_startstoplan(card, IPA_CMD_STOPLAN, QETH_PROT_IPV4);
6777 return rc;
6778}
6779
6780static int
6781qeth_query_ipassists_cb(struct qeth_card *card, struct qeth_reply *reply,
6782 unsigned long data)
6783{
6784 struct qeth_ipa_cmd *cmd;
6785
6786 QETH_DBF_TEXT(setup, 2, "qipasscb");
6787
6788 cmd = (struct qeth_ipa_cmd *) data;
6789 if (cmd->hdr.prot_version == QETH_PROT_IPV4) {
6790 card->options.ipa4.supported_funcs = cmd->hdr.ipa_supported;
6791 card->options.ipa4.enabled_funcs = cmd->hdr.ipa_enabled;
Ursula Braun9123e0d2005-09-30 10:17:24 +02006792 /* Disable IPV6 support hard coded for Hipersockets */
6793 if(card->info.type == QETH_CARD_TYPE_IQD)
6794 card->options.ipa4.supported_funcs &= ~IPA_IPV6;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006795 } else {
6796#ifdef CONFIG_QETH_IPV6
6797 card->options.ipa6.supported_funcs = cmd->hdr.ipa_supported;
6798 card->options.ipa6.enabled_funcs = cmd->hdr.ipa_enabled;
6799#endif
6800 }
6801 QETH_DBF_TEXT(setup, 2, "suppenbl");
6802 QETH_DBF_TEXT_(setup, 2, "%x",cmd->hdr.ipa_supported);
6803 QETH_DBF_TEXT_(setup, 2, "%x",cmd->hdr.ipa_enabled);
6804 return 0;
6805}
6806
6807static int
6808qeth_query_ipassists(struct qeth_card *card, enum qeth_prot_versions prot)
6809{
6810 int rc;
6811 struct qeth_cmd_buffer *iob;
6812
6813 QETH_DBF_TEXT_(setup, 2, "qipassi%i", prot);
6814 if (card->options.layer2) {
6815 QETH_DBF_TEXT(setup, 2, "noprmly2");
6816 return -EPERM;
6817 }
6818
6819 iob = qeth_get_ipacmd_buffer(card,IPA_CMD_QIPASSIST,prot);
6820 rc = qeth_send_ipa_cmd(card, iob, qeth_query_ipassists_cb, NULL);
6821 return rc;
6822}
6823
6824static struct qeth_cmd_buffer *
6825qeth_get_setassparms_cmd(struct qeth_card *card, enum qeth_ipa_funcs ipa_func,
6826 __u16 cmd_code, __u16 len,
6827 enum qeth_prot_versions prot)
6828{
6829 struct qeth_cmd_buffer *iob;
6830 struct qeth_ipa_cmd *cmd;
6831
6832 QETH_DBF_TEXT(trace,4,"getasscm");
6833 iob = qeth_get_ipacmd_buffer(card,IPA_CMD_SETASSPARMS,prot);
6834
6835 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
6836 cmd->data.setassparms.hdr.assist_no = ipa_func;
6837 cmd->data.setassparms.hdr.length = 8 + len;
6838 cmd->data.setassparms.hdr.command_code = cmd_code;
6839 cmd->data.setassparms.hdr.return_code = 0;
6840 cmd->data.setassparms.hdr.seq_no = 0;
6841
6842 return iob;
6843}
6844
6845static int
6846qeth_send_setassparms(struct qeth_card *card, struct qeth_cmd_buffer *iob,
6847 __u16 len, long data,
6848 int (*reply_cb)
6849 (struct qeth_card *,struct qeth_reply *,unsigned long),
6850 void *reply_param)
6851{
6852 int rc;
6853 struct qeth_ipa_cmd *cmd;
6854
6855 QETH_DBF_TEXT(trace,4,"sendassp");
6856
6857 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
6858 if (len <= sizeof(__u32))
6859 cmd->data.setassparms.data.flags_32bit = (__u32) data;
Frank Pavlic1380fee2006-03-22 16:03:41 +01006860 else /* (len > sizeof(__u32)) */
Linus Torvalds1da177e2005-04-16 15:20:36 -07006861 memcpy(&cmd->data.setassparms.data, (void *) data, len);
6862
6863 rc = qeth_send_ipa_cmd(card, iob, reply_cb, reply_param);
6864 return rc;
6865}
6866
6867#ifdef CONFIG_QETH_IPV6
6868static int
6869qeth_send_simple_setassparms_ipv6(struct qeth_card *card,
6870 enum qeth_ipa_funcs ipa_func, __u16 cmd_code)
6871
6872{
6873 int rc;
6874 struct qeth_cmd_buffer *iob;
6875
6876 QETH_DBF_TEXT(trace,4,"simassp6");
6877 iob = qeth_get_setassparms_cmd(card, ipa_func, cmd_code,
6878 0, QETH_PROT_IPV6);
6879 rc = qeth_send_setassparms(card, iob, 0, 0,
6880 qeth_default_setassparms_cb, NULL);
6881 return rc;
6882}
6883#endif
6884
6885static int
6886qeth_send_simple_setassparms(struct qeth_card *card,
6887 enum qeth_ipa_funcs ipa_func,
6888 __u16 cmd_code, long data)
6889{
6890 int rc;
6891 int length = 0;
6892 struct qeth_cmd_buffer *iob;
6893
6894 QETH_DBF_TEXT(trace,4,"simassp4");
6895 if (data)
6896 length = sizeof(__u32);
6897 iob = qeth_get_setassparms_cmd(card, ipa_func, cmd_code,
6898 length, QETH_PROT_IPV4);
6899 rc = qeth_send_setassparms(card, iob, length, data,
6900 qeth_default_setassparms_cb, NULL);
6901 return rc;
6902}
6903
6904static inline int
6905qeth_start_ipa_arp_processing(struct qeth_card *card)
6906{
6907 int rc;
6908
6909 QETH_DBF_TEXT(trace,3,"ipaarp");
6910
6911 if (!qeth_is_supported(card,IPA_ARP_PROCESSING)) {
6912 PRINT_WARN("ARP processing not supported "
6913 "on %s!\n", QETH_CARD_IFNAME(card));
6914 return 0;
6915 }
6916 rc = qeth_send_simple_setassparms(card,IPA_ARP_PROCESSING,
6917 IPA_CMD_ASS_START, 0);
6918 if (rc) {
6919 PRINT_WARN("Could not start ARP processing "
6920 "assist on %s: 0x%x\n",
6921 QETH_CARD_IFNAME(card), rc);
6922 }
6923 return rc;
6924}
6925
6926static int
6927qeth_start_ipa_ip_fragmentation(struct qeth_card *card)
6928{
6929 int rc;
6930
6931 QETH_DBF_TEXT(trace,3,"ipaipfrg");
6932
6933 if (!qeth_is_supported(card, IPA_IP_FRAGMENTATION)) {
6934 PRINT_INFO("Hardware IP fragmentation not supported on %s\n",
6935 QETH_CARD_IFNAME(card));
6936 return -EOPNOTSUPP;
6937 }
6938
6939 rc = qeth_send_simple_setassparms(card, IPA_IP_FRAGMENTATION,
6940 IPA_CMD_ASS_START, 0);
6941 if (rc) {
6942 PRINT_WARN("Could not start Hardware IP fragmentation "
6943 "assist on %s: 0x%x\n",
6944 QETH_CARD_IFNAME(card), rc);
6945 } else
6946 PRINT_INFO("Hardware IP fragmentation enabled \n");
6947 return rc;
6948}
6949
6950static int
6951qeth_start_ipa_source_mac(struct qeth_card *card)
6952{
6953 int rc;
6954
6955 QETH_DBF_TEXT(trace,3,"stsrcmac");
6956
6957 if (!card->options.fake_ll)
6958 return -EOPNOTSUPP;
6959
6960 if (!qeth_is_supported(card, IPA_SOURCE_MAC)) {
6961 PRINT_INFO("Inbound source address not "
6962 "supported on %s\n", QETH_CARD_IFNAME(card));
6963 return -EOPNOTSUPP;
6964 }
6965
6966 rc = qeth_send_simple_setassparms(card, IPA_SOURCE_MAC,
6967 IPA_CMD_ASS_START, 0);
6968 if (rc)
6969 PRINT_WARN("Could not start inbound source "
6970 "assist on %s: 0x%x\n",
6971 QETH_CARD_IFNAME(card), rc);
6972 return rc;
6973}
6974
6975static int
6976qeth_start_ipa_vlan(struct qeth_card *card)
6977{
6978 int rc = 0;
6979
6980 QETH_DBF_TEXT(trace,3,"strtvlan");
6981
6982#ifdef CONFIG_QETH_VLAN
6983 if (!qeth_is_supported(card, IPA_FULL_VLAN)) {
6984 PRINT_WARN("VLAN not supported on %s\n", QETH_CARD_IFNAME(card));
6985 return -EOPNOTSUPP;
6986 }
6987
6988 rc = qeth_send_simple_setassparms(card, IPA_VLAN_PRIO,
6989 IPA_CMD_ASS_START,0);
6990 if (rc) {
6991 PRINT_WARN("Could not start vlan "
6992 "assist on %s: 0x%x\n",
6993 QETH_CARD_IFNAME(card), rc);
6994 } else {
6995 PRINT_INFO("VLAN enabled \n");
6996 card->dev->features |=
6997 NETIF_F_HW_VLAN_FILTER |
6998 NETIF_F_HW_VLAN_TX |
6999 NETIF_F_HW_VLAN_RX;
7000 }
7001#endif /* QETH_VLAN */
7002 return rc;
7003}
7004
7005static int
7006qeth_start_ipa_multicast(struct qeth_card *card)
7007{
7008 int rc;
7009
7010 QETH_DBF_TEXT(trace,3,"stmcast");
7011
7012 if (!qeth_is_supported(card, IPA_MULTICASTING)) {
7013 PRINT_WARN("Multicast not supported on %s\n",
7014 QETH_CARD_IFNAME(card));
7015 return -EOPNOTSUPP;
7016 }
7017
7018 rc = qeth_send_simple_setassparms(card, IPA_MULTICASTING,
7019 IPA_CMD_ASS_START,0);
7020 if (rc) {
7021 PRINT_WARN("Could not start multicast "
7022 "assist on %s: rc=%i\n",
7023 QETH_CARD_IFNAME(card), rc);
7024 } else {
7025 PRINT_INFO("Multicast enabled\n");
7026 card->dev->flags |= IFF_MULTICAST;
7027 }
7028 return rc;
7029}
7030
7031#ifdef CONFIG_QETH_IPV6
7032static int
7033qeth_softsetup_ipv6(struct qeth_card *card)
7034{
7035 int rc;
7036
7037 QETH_DBF_TEXT(trace,3,"softipv6");
7038
Linus Torvalds1da177e2005-04-16 15:20:36 -07007039 rc = qeth_send_startlan(card, QETH_PROT_IPV6);
7040 if (rc) {
7041 PRINT_ERR("IPv6 startlan failed on %s\n",
7042 QETH_CARD_IFNAME(card));
7043 return rc;
7044 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07007045 rc = qeth_query_ipassists(card,QETH_PROT_IPV6);
7046 if (rc) {
7047 PRINT_ERR("IPv6 query ipassist failed on %s\n",
7048 QETH_CARD_IFNAME(card));
7049 return rc;
7050 }
7051 rc = qeth_send_simple_setassparms(card, IPA_IPV6,
7052 IPA_CMD_ASS_START, 3);
7053 if (rc) {
7054 PRINT_WARN("IPv6 start assist (version 4) failed "
7055 "on %s: 0x%x\n",
7056 QETH_CARD_IFNAME(card), rc);
7057 return rc;
7058 }
7059 rc = qeth_send_simple_setassparms_ipv6(card, IPA_IPV6,
7060 IPA_CMD_ASS_START);
7061 if (rc) {
7062 PRINT_WARN("IPV6 start assist (version 6) failed "
7063 "on %s: 0x%x\n",
7064 QETH_CARD_IFNAME(card), rc);
7065 return rc;
7066 }
7067 rc = qeth_send_simple_setassparms_ipv6(card, IPA_PASSTHRU,
7068 IPA_CMD_ASS_START);
7069 if (rc) {
7070 PRINT_WARN("Could not enable passthrough "
7071 "on %s: 0x%x\n",
7072 QETH_CARD_IFNAME(card), rc);
7073 return rc;
7074 }
7075 PRINT_INFO("IPV6 enabled \n");
7076 return 0;
7077}
7078
7079#endif
7080
7081static int
7082qeth_start_ipa_ipv6(struct qeth_card *card)
7083{
7084 int rc = 0;
7085#ifdef CONFIG_QETH_IPV6
7086 QETH_DBF_TEXT(trace,3,"strtipv6");
7087
7088 if (!qeth_is_supported(card, IPA_IPV6)) {
7089 PRINT_WARN("IPv6 not supported on %s\n",
7090 QETH_CARD_IFNAME(card));
7091 return 0;
7092 }
7093 rc = qeth_softsetup_ipv6(card);
7094#endif
7095 return rc ;
7096}
7097
7098static int
7099qeth_start_ipa_broadcast(struct qeth_card *card)
7100{
7101 int rc;
7102
7103 QETH_DBF_TEXT(trace,3,"stbrdcst");
7104 card->info.broadcast_capable = 0;
7105 if (!qeth_is_supported(card, IPA_FILTERING)) {
7106 PRINT_WARN("Broadcast not supported on %s\n",
7107 QETH_CARD_IFNAME(card));
7108 rc = -EOPNOTSUPP;
7109 goto out;
7110 }
7111 rc = qeth_send_simple_setassparms(card, IPA_FILTERING,
7112 IPA_CMD_ASS_START, 0);
7113 if (rc) {
7114 PRINT_WARN("Could not enable broadcasting filtering "
7115 "on %s: 0x%x\n",
7116 QETH_CARD_IFNAME(card), rc);
7117 goto out;
7118 }
7119
7120 rc = qeth_send_simple_setassparms(card, IPA_FILTERING,
7121 IPA_CMD_ASS_CONFIGURE, 1);
7122 if (rc) {
7123 PRINT_WARN("Could not set up broadcast filtering on %s: 0x%x\n",
7124 QETH_CARD_IFNAME(card), rc);
7125 goto out;
7126 }
7127 card->info.broadcast_capable = QETH_BROADCAST_WITH_ECHO;
7128 PRINT_INFO("Broadcast enabled \n");
7129 rc = qeth_send_simple_setassparms(card, IPA_FILTERING,
7130 IPA_CMD_ASS_ENABLE, 1);
7131 if (rc) {
7132 PRINT_WARN("Could not set up broadcast echo filtering on "
7133 "%s: 0x%x\n", QETH_CARD_IFNAME(card), rc);
7134 goto out;
7135 }
7136 card->info.broadcast_capable = QETH_BROADCAST_WITHOUT_ECHO;
7137out:
7138 if (card->info.broadcast_capable)
7139 card->dev->flags |= IFF_BROADCAST;
7140 else
7141 card->dev->flags &= ~IFF_BROADCAST;
7142 return rc;
7143}
7144
7145static int
7146qeth_send_checksum_command(struct qeth_card *card)
7147{
7148 int rc;
7149
7150 rc = qeth_send_simple_setassparms(card, IPA_INBOUND_CHECKSUM,
7151 IPA_CMD_ASS_START, 0);
7152 if (rc) {
7153 PRINT_WARN("Starting Inbound HW Checksumming failed on %s: "
7154 "0x%x,\ncontinuing using Inbound SW Checksumming\n",
7155 QETH_CARD_IFNAME(card), rc);
7156 return rc;
7157 }
7158 rc = qeth_send_simple_setassparms(card, IPA_INBOUND_CHECKSUM,
7159 IPA_CMD_ASS_ENABLE,
7160 card->info.csum_mask);
7161 if (rc) {
7162 PRINT_WARN("Enabling Inbound HW Checksumming failed on %s: "
7163 "0x%x,\ncontinuing using Inbound SW Checksumming\n",
7164 QETH_CARD_IFNAME(card), rc);
7165 return rc;
7166 }
7167 return 0;
7168}
7169
7170static int
7171qeth_start_ipa_checksum(struct qeth_card *card)
7172{
7173 int rc = 0;
7174
7175 QETH_DBF_TEXT(trace,3,"strtcsum");
7176
7177 if (card->options.checksum_type == NO_CHECKSUMMING) {
7178 PRINT_WARN("Using no checksumming on %s.\n",
7179 QETH_CARD_IFNAME(card));
7180 return 0;
7181 }
7182 if (card->options.checksum_type == SW_CHECKSUMMING) {
7183 PRINT_WARN("Using SW checksumming on %s.\n",
7184 QETH_CARD_IFNAME(card));
7185 return 0;
7186 }
7187 if (!qeth_is_supported(card, IPA_INBOUND_CHECKSUM)) {
7188 PRINT_WARN("Inbound HW Checksumming not "
7189 "supported on %s,\ncontinuing "
7190 "using Inbound SW Checksumming\n",
7191 QETH_CARD_IFNAME(card));
7192 card->options.checksum_type = SW_CHECKSUMMING;
7193 return 0;
7194 }
7195 rc = qeth_send_checksum_command(card);
7196 if (!rc) {
7197 PRINT_INFO("HW Checksumming (inbound) enabled \n");
7198 }
7199 return rc;
7200}
7201
7202static int
7203qeth_start_ipa_tso(struct qeth_card *card)
7204{
7205 int rc;
7206
7207 QETH_DBF_TEXT(trace,3,"sttso");
7208
7209 if (!qeth_is_supported(card, IPA_OUTBOUND_TSO)) {
7210 PRINT_WARN("Outbound TSO not supported on %s\n",
7211 QETH_CARD_IFNAME(card));
7212 rc = -EOPNOTSUPP;
7213 } else {
7214 rc = qeth_send_simple_setassparms(card, IPA_OUTBOUND_TSO,
7215 IPA_CMD_ASS_START,0);
7216 if (rc)
7217 PRINT_WARN("Could not start outbound TSO "
7218 "assist on %s: rc=%i\n",
7219 QETH_CARD_IFNAME(card), rc);
7220 else
7221 PRINT_INFO("Outbound TSO enabled\n");
7222 }
7223 if (rc && (card->options.large_send == QETH_LARGE_SEND_TSO)){
7224 card->options.large_send = QETH_LARGE_SEND_NO;
7225 card->dev->features &= ~ (NETIF_F_TSO | NETIF_F_SG);
7226 }
7227 return rc;
7228}
7229
7230static int
7231qeth_start_ipassists(struct qeth_card *card)
7232{
7233 QETH_DBF_TEXT(trace,3,"strtipas");
7234 qeth_start_ipa_arp_processing(card); /* go on*/
7235 qeth_start_ipa_ip_fragmentation(card); /* go on*/
7236 qeth_start_ipa_source_mac(card); /* go on*/
7237 qeth_start_ipa_vlan(card); /* go on*/
7238 qeth_start_ipa_multicast(card); /* go on*/
7239 qeth_start_ipa_ipv6(card); /* go on*/
7240 qeth_start_ipa_broadcast(card); /* go on*/
7241 qeth_start_ipa_checksum(card); /* go on*/
7242 qeth_start_ipa_tso(card); /* go on*/
7243 return 0;
7244}
7245
7246static int
7247qeth_send_setrouting(struct qeth_card *card, enum qeth_routing_types type,
7248 enum qeth_prot_versions prot)
7249{
7250 int rc;
7251 struct qeth_ipa_cmd *cmd;
7252 struct qeth_cmd_buffer *iob;
7253
7254 QETH_DBF_TEXT(trace,4,"setroutg");
7255 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_SETRTG, prot);
7256 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
7257 cmd->data.setrtg.type = (type);
7258 rc = qeth_send_ipa_cmd(card, iob, NULL, NULL);
7259
7260 return rc;
7261
7262}
7263
7264static void
7265qeth_correct_routing_type(struct qeth_card *card, enum qeth_routing_types *type,
7266 enum qeth_prot_versions prot)
7267{
7268 if (card->info.type == QETH_CARD_TYPE_IQD) {
7269 switch (*type) {
7270 case NO_ROUTER:
7271 case PRIMARY_CONNECTOR:
7272 case SECONDARY_CONNECTOR:
7273 case MULTICAST_ROUTER:
7274 return;
7275 default:
7276 goto out_inval;
7277 }
7278 } else {
7279 switch (*type) {
7280 case NO_ROUTER:
7281 case PRIMARY_ROUTER:
7282 case SECONDARY_ROUTER:
7283 return;
7284 case MULTICAST_ROUTER:
7285 if (qeth_is_ipafunc_supported(card, prot,
7286 IPA_OSA_MC_ROUTER))
7287 return;
7288 default:
7289 goto out_inval;
7290 }
7291 }
7292out_inval:
7293 PRINT_WARN("Routing type '%s' not supported for interface %s.\n"
7294 "Router status set to 'no router'.\n",
7295 ((*type == PRIMARY_ROUTER)? "primary router" :
7296 (*type == SECONDARY_ROUTER)? "secondary router" :
7297 (*type == PRIMARY_CONNECTOR)? "primary connector" :
7298 (*type == SECONDARY_CONNECTOR)? "secondary connector" :
7299 (*type == MULTICAST_ROUTER)? "multicast router" :
7300 "unknown"),
7301 card->dev->name);
7302 *type = NO_ROUTER;
7303}
7304
7305int
7306qeth_setrouting_v4(struct qeth_card *card)
7307{
7308 int rc;
7309
7310 QETH_DBF_TEXT(trace,3,"setrtg4");
7311
7312 qeth_correct_routing_type(card, &card->options.route4.type,
7313 QETH_PROT_IPV4);
7314
7315 rc = qeth_send_setrouting(card, card->options.route4.type,
7316 QETH_PROT_IPV4);
7317 if (rc) {
7318 card->options.route4.type = NO_ROUTER;
7319 PRINT_WARN("Error (0x%04x) while setting routing type on %s. "
7320 "Type set to 'no router'.\n",
7321 rc, QETH_CARD_IFNAME(card));
7322 }
7323 return rc;
7324}
7325
7326int
7327qeth_setrouting_v6(struct qeth_card *card)
7328{
7329 int rc = 0;
7330
7331 QETH_DBF_TEXT(trace,3,"setrtg6");
7332#ifdef CONFIG_QETH_IPV6
7333
7334 qeth_correct_routing_type(card, &card->options.route6.type,
7335 QETH_PROT_IPV6);
7336
Linus Torvalds1da177e2005-04-16 15:20:36 -07007337 rc = qeth_send_setrouting(card, card->options.route6.type,
7338 QETH_PROT_IPV6);
7339 if (rc) {
7340 card->options.route6.type = NO_ROUTER;
7341 PRINT_WARN("Error (0x%04x) while setting routing type on %s. "
7342 "Type set to 'no router'.\n",
7343 rc, QETH_CARD_IFNAME(card));
7344 }
7345#endif
7346 return rc;
7347}
7348
7349int
Frank Pavlic9cb90de2005-09-14 18:03:26 +02007350qeth_set_large_send(struct qeth_card *card, enum qeth_large_send_types type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007351{
7352 int rc = 0;
7353
Frank Pavlic9cb90de2005-09-14 18:03:26 +02007354 if (card->dev == NULL) {
7355 card->options.large_send = type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007356 return 0;
Frank Pavlic9cb90de2005-09-14 18:03:26 +02007357 }
Ursula Braunb85e1fa2006-05-24 09:51:11 +02007358 if (card->state == CARD_STATE_UP)
7359 netif_tx_disable(card->dev);
Frank Pavlic9cb90de2005-09-14 18:03:26 +02007360 card->options.large_send = type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007361 switch (card->options.large_send) {
7362 case QETH_LARGE_SEND_EDDP:
7363 card->dev->features |= NETIF_F_TSO | NETIF_F_SG;
7364 break;
7365 case QETH_LARGE_SEND_TSO:
7366 if (qeth_is_supported(card, IPA_OUTBOUND_TSO)){
7367 card->dev->features |= NETIF_F_TSO | NETIF_F_SG;
7368 } else {
7369 PRINT_WARN("TSO not supported on %s. "
7370 "large_send set to 'no'.\n",
7371 card->dev->name);
7372 card->dev->features &= ~(NETIF_F_TSO | NETIF_F_SG);
7373 card->options.large_send = QETH_LARGE_SEND_NO;
7374 rc = -EOPNOTSUPP;
7375 }
7376 break;
7377 default: /* includes QETH_LARGE_SEND_NO */
7378 card->dev->features &= ~(NETIF_F_TSO | NETIF_F_SG);
7379 break;
7380 }
Ursula Braunb85e1fa2006-05-24 09:51:11 +02007381 if (card->state == CARD_STATE_UP)
7382 netif_wake_queue(card->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007383 return rc;
7384}
7385
7386/*
7387 * softsetup card: init IPA stuff
7388 */
7389static int
7390qeth_softsetup_card(struct qeth_card *card)
7391{
7392 int rc;
7393
7394 QETH_DBF_TEXT(setup, 2, "softsetp");
7395
7396 if ((rc = qeth_send_startlan(card, QETH_PROT_IPV4))){
7397 QETH_DBF_TEXT_(setup, 2, "1err%d", rc);
7398 if (rc == 0xe080){
7399 PRINT_WARN("LAN on card %s if offline! "
7400 "Continuing softsetup.\n",
7401 CARD_BUS_ID(card));
7402 card->lan_online = 0;
7403 } else
7404 return rc;
7405 } else
7406 card->lan_online = 1;
Ursula Braun500f83a2005-09-30 10:19:19 +02007407 if (card->info.type==QETH_CARD_TYPE_OSN)
7408 goto out;
Frank Pavlic66cc5d52006-02-07 17:04:38 +01007409 qeth_set_large_send(card, card->options.large_send);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007410 if (card->options.layer2) {
7411 card->dev->features |=
7412 NETIF_F_HW_VLAN_FILTER |
7413 NETIF_F_HW_VLAN_TX |
7414 NETIF_F_HW_VLAN_RX;
7415 card->dev->flags|=IFF_MULTICAST|IFF_BROADCAST;
7416 card->info.broadcast_capable=1;
7417 if ((rc = qeth_layer2_initialize(card))) {
7418 QETH_DBF_TEXT_(setup, 2, "L2err%d", rc);
7419 return rc;
7420 }
7421#ifdef CONFIG_QETH_VLAN
7422 qeth_layer2_process_vlans(card, 0);
7423#endif
7424 goto out;
7425 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07007426 if ((rc = qeth_setadapter_parms(card)))
7427 QETH_DBF_TEXT_(setup, 2, "2err%d", rc);
7428 if ((rc = qeth_start_ipassists(card)))
7429 QETH_DBF_TEXT_(setup, 2, "3err%d", rc);
7430 if ((rc = qeth_setrouting_v4(card)))
7431 QETH_DBF_TEXT_(setup, 2, "4err%d", rc);
7432 if ((rc = qeth_setrouting_v6(card)))
7433 QETH_DBF_TEXT_(setup, 2, "5err%d", rc);
7434out:
Ursula Braunb85e1fa2006-05-24 09:51:11 +02007435 netif_tx_disable(card->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007436 return 0;
7437}
7438
7439#ifdef CONFIG_QETH_IPV6
7440static int
7441qeth_get_unique_id_cb(struct qeth_card *card, struct qeth_reply *reply,
7442 unsigned long data)
7443{
7444 struct qeth_ipa_cmd *cmd;
7445
7446 cmd = (struct qeth_ipa_cmd *) data;
7447 if (cmd->hdr.return_code == 0)
7448 card->info.unique_id = *((__u16 *)
7449 &cmd->data.create_destroy_addr.unique_id[6]);
7450 else {
7451 card->info.unique_id = UNIQUE_ID_IF_CREATE_ADDR_FAILED |
7452 UNIQUE_ID_NOT_BY_CARD;
7453 PRINT_WARN("couldn't get a unique id from the card on device "
7454 "%s (result=x%x), using default id. ipv6 "
7455 "autoconfig on other lpars may lead to duplicate "
7456 "ip addresses. please use manually "
7457 "configured ones.\n",
7458 CARD_BUS_ID(card), cmd->hdr.return_code);
7459 }
7460 return 0;
7461}
7462#endif
7463
7464static int
7465qeth_put_unique_id(struct qeth_card *card)
7466{
7467
7468 int rc = 0;
7469#ifdef CONFIG_QETH_IPV6
7470 struct qeth_cmd_buffer *iob;
7471 struct qeth_ipa_cmd *cmd;
7472
7473 QETH_DBF_TEXT(trace,2,"puniqeid");
7474
7475 if ((card->info.unique_id & UNIQUE_ID_NOT_BY_CARD) ==
7476 UNIQUE_ID_NOT_BY_CARD)
7477 return -1;
7478 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_DESTROY_ADDR,
7479 QETH_PROT_IPV6);
7480 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
7481 *((__u16 *) &cmd->data.create_destroy_addr.unique_id[6]) =
7482 card->info.unique_id;
7483 memcpy(&cmd->data.create_destroy_addr.unique_id[0],
7484 card->dev->dev_addr, OSA_ADDR_LEN);
7485 rc = qeth_send_ipa_cmd(card, iob, NULL, NULL);
7486#else
7487 card->info.unique_id = UNIQUE_ID_IF_CREATE_ADDR_FAILED |
7488 UNIQUE_ID_NOT_BY_CARD;
7489#endif
7490 return rc;
7491}
7492
7493/**
7494 * Clear IP List
7495 */
7496static void
7497qeth_clear_ip_list(struct qeth_card *card, int clean, int recover)
7498{
7499 struct qeth_ipaddr *addr, *tmp;
7500 unsigned long flags;
7501
7502 QETH_DBF_TEXT(trace,4,"clearip");
7503 spin_lock_irqsave(&card->ip_lock, flags);
7504 /* clear todo list */
7505 list_for_each_entry_safe(addr, tmp, card->ip_tbd_list, entry){
7506 list_del(&addr->entry);
7507 kfree(addr);
7508 }
7509
7510 while (!list_empty(&card->ip_list)) {
7511 addr = list_entry(card->ip_list.next,
7512 struct qeth_ipaddr, entry);
7513 list_del_init(&addr->entry);
7514 if (clean) {
7515 spin_unlock_irqrestore(&card->ip_lock, flags);
7516 qeth_deregister_addr_entry(card, addr);
7517 spin_lock_irqsave(&card->ip_lock, flags);
7518 }
7519 if (!recover || addr->is_multicast) {
7520 kfree(addr);
7521 continue;
7522 }
7523 list_add_tail(&addr->entry, card->ip_tbd_list);
7524 }
7525 spin_unlock_irqrestore(&card->ip_lock, flags);
7526}
7527
7528static void
7529qeth_set_allowed_threads(struct qeth_card *card, unsigned long threads,
7530 int clear_start_mask)
7531{
7532 unsigned long flags;
7533
7534 spin_lock_irqsave(&card->thread_mask_lock, flags);
7535 card->thread_allowed_mask = threads;
7536 if (clear_start_mask)
7537 card->thread_start_mask &= threads;
7538 spin_unlock_irqrestore(&card->thread_mask_lock, flags);
7539 wake_up(&card->wait_q);
7540}
7541
7542static inline int
7543qeth_threads_running(struct qeth_card *card, unsigned long threads)
7544{
7545 unsigned long flags;
7546 int rc = 0;
7547
7548 spin_lock_irqsave(&card->thread_mask_lock, flags);
7549 rc = (card->thread_running_mask & threads);
7550 spin_unlock_irqrestore(&card->thread_mask_lock, flags);
7551 return rc;
7552}
7553
7554static int
7555qeth_wait_for_threads(struct qeth_card *card, unsigned long threads)
7556{
7557 return wait_event_interruptible(card->wait_q,
7558 qeth_threads_running(card, threads) == 0);
7559}
7560
7561static int
Frank Pavlic05e08a22005-05-12 20:39:09 +02007562qeth_stop_card(struct qeth_card *card, int recovery_mode)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007563{
7564 int rc = 0;
7565
7566 QETH_DBF_TEXT(setup ,2,"stopcard");
7567 QETH_DBF_HEX(setup, 2, &card, sizeof(void *));
7568
7569 qeth_set_allowed_threads(card, 0, 1);
7570 if (qeth_wait_for_threads(card, ~QETH_RECOVER_THREAD))
7571 return -ERESTARTSYS;
7572 if (card->read.state == CH_STATE_UP &&
7573 card->write.state == CH_STATE_UP &&
7574 (card->state == CARD_STATE_UP)) {
Jeff Garzike82b0f22006-05-26 21:58:38 -04007575 if (recovery_mode &&
Ursula Braun500f83a2005-09-30 10:19:19 +02007576 card->info.type != QETH_CARD_TYPE_OSN) {
Frank Pavlic05e08a22005-05-12 20:39:09 +02007577 qeth_stop(card->dev);
7578 } else {
7579 rtnl_lock();
7580 dev_close(card->dev);
7581 rtnl_unlock();
7582 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07007583 if (!card->use_hard_stop) {
7584 __u8 *mac = &card->dev->dev_addr[0];
7585 rc = qeth_layer2_send_delmac(card, mac);
7586 QETH_DBF_TEXT_(setup, 2, "Lerr%d", rc);
7587 if ((rc = qeth_send_stoplan(card)))
7588 QETH_DBF_TEXT_(setup, 2, "1err%d", rc);
7589 }
7590 card->state = CARD_STATE_SOFTSETUP;
7591 }
7592 if (card->state == CARD_STATE_SOFTSETUP) {
7593#ifdef CONFIG_QETH_VLAN
7594 if (card->options.layer2)
7595 qeth_layer2_process_vlans(card, 1);
7596#endif
7597 qeth_clear_ip_list(card, !card->use_hard_stop, 1);
7598 qeth_clear_ipacmd_list(card);
7599 card->state = CARD_STATE_HARDSETUP;
7600 }
7601 if (card->state == CARD_STATE_HARDSETUP) {
7602 if ((!card->use_hard_stop) &&
7603 (!card->options.layer2))
7604 if ((rc = qeth_put_unique_id(card)))
7605 QETH_DBF_TEXT_(setup, 2, "2err%d", rc);
7606 qeth_qdio_clear_card(card, 0);
7607 qeth_clear_qdio_buffers(card);
7608 qeth_clear_working_pool_list(card);
7609 card->state = CARD_STATE_DOWN;
7610 }
7611 if (card->state == CARD_STATE_DOWN) {
7612 qeth_clear_cmd_buffers(&card->read);
7613 qeth_clear_cmd_buffers(&card->write);
7614 }
7615 card->use_hard_stop = 0;
7616 return rc;
7617}
7618
7619
7620static int
7621qeth_get_unique_id(struct qeth_card *card)
7622{
7623 int rc = 0;
7624#ifdef CONFIG_QETH_IPV6
7625 struct qeth_cmd_buffer *iob;
7626 struct qeth_ipa_cmd *cmd;
7627
7628 QETH_DBF_TEXT(setup, 2, "guniqeid");
7629
7630 if (!qeth_is_supported(card,IPA_IPV6)) {
7631 card->info.unique_id = UNIQUE_ID_IF_CREATE_ADDR_FAILED |
7632 UNIQUE_ID_NOT_BY_CARD;
7633 return 0;
7634 }
7635
7636 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_CREATE_ADDR,
7637 QETH_PROT_IPV6);
7638 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
7639 *((__u16 *) &cmd->data.create_destroy_addr.unique_id[6]) =
7640 card->info.unique_id;
7641
7642 rc = qeth_send_ipa_cmd(card, iob, qeth_get_unique_id_cb, NULL);
7643#else
7644 card->info.unique_id = UNIQUE_ID_IF_CREATE_ADDR_FAILED |
7645 UNIQUE_ID_NOT_BY_CARD;
7646#endif
7647 return rc;
7648}
7649static void
7650qeth_print_status_with_portname(struct qeth_card *card)
7651{
7652 char dbf_text[15];
7653 int i;
7654
7655 sprintf(dbf_text, "%s", card->info.portname + 1);
7656 for (i = 0; i < 8; i++)
7657 dbf_text[i] =
7658 (char) _ebcasc[(__u8) dbf_text[i]];
7659 dbf_text[8] = 0;
7660 printk("qeth: Device %s/%s/%s is a%s card%s%s%s\n"
7661 "with link type %s (portname: %s)\n",
7662 CARD_RDEV_ID(card),
7663 CARD_WDEV_ID(card),
7664 CARD_DDEV_ID(card),
7665 qeth_get_cardname(card),
7666 (card->info.mcl_level[0]) ? " (level: " : "",
7667 (card->info.mcl_level[0]) ? card->info.mcl_level : "",
7668 (card->info.mcl_level[0]) ? ")" : "",
7669 qeth_get_cardname_short(card),
7670 dbf_text);
7671
7672}
7673
7674static void
7675qeth_print_status_no_portname(struct qeth_card *card)
7676{
7677 if (card->info.portname[0])
7678 printk("qeth: Device %s/%s/%s is a%s "
7679 "card%s%s%s\nwith link type %s "
7680 "(no portname needed by interface).\n",
7681 CARD_RDEV_ID(card),
7682 CARD_WDEV_ID(card),
7683 CARD_DDEV_ID(card),
7684 qeth_get_cardname(card),
7685 (card->info.mcl_level[0]) ? " (level: " : "",
7686 (card->info.mcl_level[0]) ? card->info.mcl_level : "",
7687 (card->info.mcl_level[0]) ? ")" : "",
7688 qeth_get_cardname_short(card));
7689 else
7690 printk("qeth: Device %s/%s/%s is a%s "
7691 "card%s%s%s\nwith link type %s.\n",
7692 CARD_RDEV_ID(card),
7693 CARD_WDEV_ID(card),
7694 CARD_DDEV_ID(card),
7695 qeth_get_cardname(card),
7696 (card->info.mcl_level[0]) ? " (level: " : "",
7697 (card->info.mcl_level[0]) ? card->info.mcl_level : "",
7698 (card->info.mcl_level[0]) ? ")" : "",
7699 qeth_get_cardname_short(card));
7700}
7701
7702static void
7703qeth_print_status_message(struct qeth_card *card)
7704{
7705 switch (card->info.type) {
7706 case QETH_CARD_TYPE_OSAE:
7707 /* VM will use a non-zero first character
7708 * to indicate a HiperSockets like reporting
7709 * of the level OSA sets the first character to zero
7710 * */
7711 if (!card->info.mcl_level[0]) {
7712 sprintf(card->info.mcl_level,"%02x%02x",
7713 card->info.mcl_level[2],
7714 card->info.mcl_level[3]);
7715
7716 card->info.mcl_level[QETH_MCL_LENGTH] = 0;
7717 break;
7718 }
7719 /* fallthrough */
7720 case QETH_CARD_TYPE_IQD:
7721 card->info.mcl_level[0] = (char) _ebcasc[(__u8)
7722 card->info.mcl_level[0]];
7723 card->info.mcl_level[1] = (char) _ebcasc[(__u8)
7724 card->info.mcl_level[1]];
7725 card->info.mcl_level[2] = (char) _ebcasc[(__u8)
7726 card->info.mcl_level[2]];
7727 card->info.mcl_level[3] = (char) _ebcasc[(__u8)
7728 card->info.mcl_level[3]];
7729 card->info.mcl_level[QETH_MCL_LENGTH] = 0;
7730 break;
7731 default:
7732 memset(&card->info.mcl_level[0], 0, QETH_MCL_LENGTH + 1);
7733 }
7734 if (card->info.portname_required)
7735 qeth_print_status_with_portname(card);
7736 else
7737 qeth_print_status_no_portname(card);
7738}
7739
7740static int
7741qeth_register_netdev(struct qeth_card *card)
7742{
7743 QETH_DBF_TEXT(setup, 3, "regnetd");
Jeff Garzike82b0f22006-05-26 21:58:38 -04007744 if (card->dev->reg_state != NETREG_UNINITIALIZED)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007745 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007746 /* sysfs magic */
7747 SET_NETDEV_DEV(card->dev, &card->gdev->dev);
7748 return register_netdev(card->dev);
7749}
7750
7751static void
Frank Pavlic05e08a22005-05-12 20:39:09 +02007752qeth_start_again(struct qeth_card *card, int recovery_mode)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007753{
7754 QETH_DBF_TEXT(setup ,2, "startag");
7755
Jeff Garzike82b0f22006-05-26 21:58:38 -04007756 if (recovery_mode &&
Ursula Braun500f83a2005-09-30 10:19:19 +02007757 card->info.type != QETH_CARD_TYPE_OSN) {
Frank Pavlic05e08a22005-05-12 20:39:09 +02007758 qeth_open(card->dev);
7759 } else {
7760 rtnl_lock();
7761 dev_open(card->dev);
7762 rtnl_unlock();
7763 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07007764 /* this also sets saved unicast addresses */
7765 qeth_set_multicast_list(card->dev);
7766}
7767
7768
7769/* Layer 2 specific stuff */
7770#define IGNORE_PARAM_EQ(option,value,reset_value,msg) \
7771 if (card->options.option == value) { \
7772 PRINT_ERR("%s not supported with layer 2 " \
7773 "functionality, ignoring option on read" \
7774 "channel device %s .\n",msg,CARD_RDEV_ID(card)); \
7775 card->options.option = reset_value; \
7776 }
7777#define IGNORE_PARAM_NEQ(option,value,reset_value,msg) \
7778 if (card->options.option != value) { \
7779 PRINT_ERR("%s not supported with layer 2 " \
7780 "functionality, ignoring option on read" \
7781 "channel device %s .\n",msg,CARD_RDEV_ID(card)); \
7782 card->options.option = reset_value; \
7783 }
7784
7785
7786static void qeth_make_parameters_consistent(struct qeth_card *card)
7787{
7788
Ursula Braun500f83a2005-09-30 10:19:19 +02007789 if (card->options.layer2 == 0)
7790 return;
7791 if (card->info.type == QETH_CARD_TYPE_OSN)
7792 return;
7793 if (card->info.type == QETH_CARD_TYPE_IQD) {
7794 PRINT_ERR("Device %s does not support layer 2 functionality." \
7795 " Ignoring layer2 option.\n",CARD_BUS_ID(card));
7796 card->options.layer2 = 0;
7797 return;
7798 }
7799 IGNORE_PARAM_NEQ(route4.type, NO_ROUTER, NO_ROUTER,
7800 "Routing options are");
Linus Torvalds1da177e2005-04-16 15:20:36 -07007801#ifdef CONFIG_QETH_IPV6
Ursula Braun500f83a2005-09-30 10:19:19 +02007802 IGNORE_PARAM_NEQ(route6.type, NO_ROUTER, NO_ROUTER,
7803 "Routing options are");
Linus Torvalds1da177e2005-04-16 15:20:36 -07007804#endif
Ursula Braun500f83a2005-09-30 10:19:19 +02007805 IGNORE_PARAM_EQ(checksum_type, HW_CHECKSUMMING,
7806 QETH_CHECKSUM_DEFAULT,
7807 "Checksumming options are");
7808 IGNORE_PARAM_NEQ(broadcast_mode, QETH_TR_BROADCAST_ALLRINGS,
7809 QETH_TR_BROADCAST_ALLRINGS,
7810 "Broadcast mode options are");
7811 IGNORE_PARAM_NEQ(macaddr_mode, QETH_TR_MACADDR_NONCANONICAL,
7812 QETH_TR_MACADDR_NONCANONICAL,
7813 "Canonical MAC addr options are");
7814 IGNORE_PARAM_NEQ(fake_broadcast, 0, 0,
7815 "Broadcast faking options are");
7816 IGNORE_PARAM_NEQ(add_hhlen, DEFAULT_ADD_HHLEN,
7817 DEFAULT_ADD_HHLEN,"Option add_hhlen is");
7818 IGNORE_PARAM_NEQ(fake_ll, 0, 0,"Option fake_ll is");
Linus Torvalds1da177e2005-04-16 15:20:36 -07007819}
7820
7821
7822static int
Frank Pavlic05e08a22005-05-12 20:39:09 +02007823__qeth_set_online(struct ccwgroup_device *gdev, int recovery_mode)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007824{
7825 struct qeth_card *card = gdev->dev.driver_data;
7826 int rc = 0;
7827 enum qeth_card_states recover_flag;
7828
7829 BUG_ON(!card);
7830 QETH_DBF_TEXT(setup ,2, "setonlin");
7831 QETH_DBF_HEX(setup, 2, &card, sizeof(void *));
7832
7833 qeth_set_allowed_threads(card, QETH_RECOVER_THREAD, 1);
7834 if (qeth_wait_for_threads(card, ~QETH_RECOVER_THREAD)){
7835 PRINT_WARN("set_online of card %s interrupted by user!\n",
7836 CARD_BUS_ID(card));
7837 return -ERESTARTSYS;
7838 }
7839
7840 recover_flag = card->state;
7841 if ((rc = ccw_device_set_online(CARD_RDEV(card))) ||
7842 (rc = ccw_device_set_online(CARD_WDEV(card))) ||
7843 (rc = ccw_device_set_online(CARD_DDEV(card)))){
7844 QETH_DBF_TEXT_(setup, 2, "1err%d", rc);
7845 return -EIO;
7846 }
7847
Ursula Braun500f83a2005-09-30 10:19:19 +02007848 qeth_make_parameters_consistent(card);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007849
7850 if ((rc = qeth_hardsetup_card(card))){
7851 QETH_DBF_TEXT_(setup, 2, "2err%d", rc);
7852 goto out_remove;
7853 }
7854 card->state = CARD_STATE_HARDSETUP;
7855
7856 if (!(rc = qeth_query_ipassists(card,QETH_PROT_IPV4)))
7857 rc = qeth_get_unique_id(card);
7858
7859 if (rc && card->options.layer2 == 0) {
7860 QETH_DBF_TEXT_(setup, 2, "3err%d", rc);
7861 goto out_remove;
7862 }
7863 qeth_print_status_message(card);
7864 if ((rc = qeth_register_netdev(card))){
7865 QETH_DBF_TEXT_(setup, 2, "4err%d", rc);
7866 goto out_remove;
7867 }
7868 if ((rc = qeth_softsetup_card(card))){
7869 QETH_DBF_TEXT_(setup, 2, "5err%d", rc);
7870 goto out_remove;
7871 }
7872 card->state = CARD_STATE_SOFTSETUP;
7873
7874 if ((rc = qeth_init_qdio_queues(card))){
7875 QETH_DBF_TEXT_(setup, 2, "6err%d", rc);
7876 goto out_remove;
7877 }
Frank Pavlic4965e972005-12-13 08:22:30 +01007878 netif_carrier_on(card->dev);
7879
Linus Torvalds1da177e2005-04-16 15:20:36 -07007880 qeth_set_allowed_threads(card, 0xffffffff, 0);
7881 if (recover_flag == CARD_STATE_RECOVER)
Frank Pavlic05e08a22005-05-12 20:39:09 +02007882 qeth_start_again(card, recovery_mode);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007883 qeth_notify_processes();
7884 return 0;
7885out_remove:
7886 card->use_hard_stop = 1;
Frank Pavlic05e08a22005-05-12 20:39:09 +02007887 qeth_stop_card(card, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007888 ccw_device_set_offline(CARD_DDEV(card));
7889 ccw_device_set_offline(CARD_WDEV(card));
7890 ccw_device_set_offline(CARD_RDEV(card));
7891 if (recover_flag == CARD_STATE_RECOVER)
7892 card->state = CARD_STATE_RECOVER;
7893 else
7894 card->state = CARD_STATE_DOWN;
7895 return -ENODEV;
7896}
7897
Frank Pavlic05e08a22005-05-12 20:39:09 +02007898static int
7899qeth_set_online(struct ccwgroup_device *gdev)
7900{
7901 return __qeth_set_online(gdev, 0);
7902}
7903
Linus Torvalds1da177e2005-04-16 15:20:36 -07007904static struct ccw_device_id qeth_ids[] = {
7905 {CCW_DEVICE(0x1731, 0x01), driver_info:QETH_CARD_TYPE_OSAE},
7906 {CCW_DEVICE(0x1731, 0x05), driver_info:QETH_CARD_TYPE_IQD},
Ursula Braun500f83a2005-09-30 10:19:19 +02007907 {CCW_DEVICE(0x1731, 0x06), driver_info:QETH_CARD_TYPE_OSN},
Linus Torvalds1da177e2005-04-16 15:20:36 -07007908 {},
7909};
7910MODULE_DEVICE_TABLE(ccw, qeth_ids);
7911
7912struct device *qeth_root_dev = NULL;
7913
7914struct ccwgroup_driver qeth_ccwgroup_driver = {
7915 .owner = THIS_MODULE,
7916 .name = "qeth",
7917 .driver_id = 0xD8C5E3C8,
7918 .probe = qeth_probe_device,
7919 .remove = qeth_remove_device,
7920 .set_online = qeth_set_online,
7921 .set_offline = qeth_set_offline,
7922};
7923
7924struct ccw_driver qeth_ccw_driver = {
7925 .name = "qeth",
7926 .ids = qeth_ids,
7927 .probe = ccwgroup_probe_ccwdev,
7928 .remove = ccwgroup_remove_ccwdev,
7929};
7930
7931
7932static void
7933qeth_unregister_dbf_views(void)
7934{
7935 if (qeth_dbf_setup)
7936 debug_unregister(qeth_dbf_setup);
7937 if (qeth_dbf_qerr)
7938 debug_unregister(qeth_dbf_qerr);
7939 if (qeth_dbf_sense)
7940 debug_unregister(qeth_dbf_sense);
7941 if (qeth_dbf_misc)
7942 debug_unregister(qeth_dbf_misc);
7943 if (qeth_dbf_data)
7944 debug_unregister(qeth_dbf_data);
7945 if (qeth_dbf_control)
7946 debug_unregister(qeth_dbf_control);
7947 if (qeth_dbf_trace)
7948 debug_unregister(qeth_dbf_trace);
7949}
7950static int
7951qeth_register_dbf_views(void)
7952{
7953 qeth_dbf_setup = debug_register(QETH_DBF_SETUP_NAME,
Michael Holzheu66a464d2005-06-25 14:55:33 -07007954 QETH_DBF_SETUP_PAGES,
Linus Torvalds1da177e2005-04-16 15:20:36 -07007955 QETH_DBF_SETUP_NR_AREAS,
7956 QETH_DBF_SETUP_LEN);
7957 qeth_dbf_misc = debug_register(QETH_DBF_MISC_NAME,
Michael Holzheu66a464d2005-06-25 14:55:33 -07007958 QETH_DBF_MISC_PAGES,
Linus Torvalds1da177e2005-04-16 15:20:36 -07007959 QETH_DBF_MISC_NR_AREAS,
7960 QETH_DBF_MISC_LEN);
7961 qeth_dbf_data = debug_register(QETH_DBF_DATA_NAME,
Michael Holzheu66a464d2005-06-25 14:55:33 -07007962 QETH_DBF_DATA_PAGES,
Linus Torvalds1da177e2005-04-16 15:20:36 -07007963 QETH_DBF_DATA_NR_AREAS,
7964 QETH_DBF_DATA_LEN);
7965 qeth_dbf_control = debug_register(QETH_DBF_CONTROL_NAME,
Michael Holzheu66a464d2005-06-25 14:55:33 -07007966 QETH_DBF_CONTROL_PAGES,
Linus Torvalds1da177e2005-04-16 15:20:36 -07007967 QETH_DBF_CONTROL_NR_AREAS,
7968 QETH_DBF_CONTROL_LEN);
7969 qeth_dbf_sense = debug_register(QETH_DBF_SENSE_NAME,
Michael Holzheu66a464d2005-06-25 14:55:33 -07007970 QETH_DBF_SENSE_PAGES,
Linus Torvalds1da177e2005-04-16 15:20:36 -07007971 QETH_DBF_SENSE_NR_AREAS,
7972 QETH_DBF_SENSE_LEN);
7973 qeth_dbf_qerr = debug_register(QETH_DBF_QERR_NAME,
Michael Holzheu66a464d2005-06-25 14:55:33 -07007974 QETH_DBF_QERR_PAGES,
Linus Torvalds1da177e2005-04-16 15:20:36 -07007975 QETH_DBF_QERR_NR_AREAS,
7976 QETH_DBF_QERR_LEN);
7977 qeth_dbf_trace = debug_register(QETH_DBF_TRACE_NAME,
Michael Holzheu66a464d2005-06-25 14:55:33 -07007978 QETH_DBF_TRACE_PAGES,
Linus Torvalds1da177e2005-04-16 15:20:36 -07007979 QETH_DBF_TRACE_NR_AREAS,
7980 QETH_DBF_TRACE_LEN);
7981
7982 if ((qeth_dbf_setup == NULL) || (qeth_dbf_misc == NULL) ||
7983 (qeth_dbf_data == NULL) || (qeth_dbf_control == NULL) ||
7984 (qeth_dbf_sense == NULL) || (qeth_dbf_qerr == NULL) ||
7985 (qeth_dbf_trace == NULL)) {
7986 qeth_unregister_dbf_views();
7987 return -ENOMEM;
7988 }
7989 debug_register_view(qeth_dbf_setup, &debug_hex_ascii_view);
7990 debug_set_level(qeth_dbf_setup, QETH_DBF_SETUP_LEVEL);
7991
7992 debug_register_view(qeth_dbf_misc, &debug_hex_ascii_view);
7993 debug_set_level(qeth_dbf_misc, QETH_DBF_MISC_LEVEL);
7994
7995 debug_register_view(qeth_dbf_data, &debug_hex_ascii_view);
7996 debug_set_level(qeth_dbf_data, QETH_DBF_DATA_LEVEL);
7997
7998 debug_register_view(qeth_dbf_control, &debug_hex_ascii_view);
7999 debug_set_level(qeth_dbf_control, QETH_DBF_CONTROL_LEVEL);
8000
8001 debug_register_view(qeth_dbf_sense, &debug_hex_ascii_view);
8002 debug_set_level(qeth_dbf_sense, QETH_DBF_SENSE_LEVEL);
8003
8004 debug_register_view(qeth_dbf_qerr, &debug_hex_ascii_view);
8005 debug_set_level(qeth_dbf_qerr, QETH_DBF_QERR_LEVEL);
8006
8007 debug_register_view(qeth_dbf_trace, &debug_hex_ascii_view);
8008 debug_set_level(qeth_dbf_trace, QETH_DBF_TRACE_LEVEL);
8009
8010 return 0;
8011}
8012
8013#ifdef CONFIG_QETH_IPV6
8014extern struct neigh_table arp_tbl;
8015static struct neigh_ops *arp_direct_ops;
8016static int (*qeth_old_arp_constructor) (struct neighbour *);
8017
8018static struct neigh_ops arp_direct_ops_template = {
8019 .family = AF_INET,
Linus Torvalds1da177e2005-04-16 15:20:36 -07008020 .solicit = NULL,
8021 .error_report = NULL,
8022 .output = dev_queue_xmit,
8023 .connected_output = dev_queue_xmit,
8024 .hh_output = dev_queue_xmit,
8025 .queue_xmit = dev_queue_xmit
8026};
8027
8028static int
8029qeth_arp_constructor(struct neighbour *neigh)
8030{
8031 struct net_device *dev = neigh->dev;
8032 struct in_device *in_dev;
8033 struct neigh_parms *parms;
8034 struct qeth_card *card;
8035
8036 card = qeth_get_card_from_dev(dev);
8037 if (card == NULL)
8038 goto out;
8039 if((card->options.layer2) ||
8040 (card->dev->hard_header == qeth_fake_header))
8041 goto out;
8042
8043 rcu_read_lock();
Herbert Xue5ed6392005-10-03 14:35:55 -07008044 in_dev = __in_dev_get_rcu(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07008045 if (in_dev == NULL) {
8046 rcu_read_unlock();
8047 return -EINVAL;
8048 }
8049
8050 parms = in_dev->arp_parms;
8051 __neigh_parms_put(neigh->parms);
8052 neigh->parms = neigh_parms_clone(parms);
8053 rcu_read_unlock();
8054
8055 neigh->type = inet_addr_type(*(u32 *) neigh->primary_key);
8056 neigh->nud_state = NUD_NOARP;
8057 neigh->ops = arp_direct_ops;
8058 neigh->output = neigh->ops->queue_xmit;
8059 return 0;
8060out:
8061 return qeth_old_arp_constructor(neigh);
8062}
8063#endif /*CONFIG_QETH_IPV6*/
8064
8065/*
8066 * IP address takeover related functions
8067 */
8068static void
8069qeth_clear_ipato_list(struct qeth_card *card)
8070{
8071 struct qeth_ipato_entry *ipatoe, *tmp;
8072 unsigned long flags;
8073
8074 spin_lock_irqsave(&card->ip_lock, flags);
8075 list_for_each_entry_safe(ipatoe, tmp, &card->ipato.entries, entry) {
8076 list_del(&ipatoe->entry);
8077 kfree(ipatoe);
8078 }
8079 spin_unlock_irqrestore(&card->ip_lock, flags);
8080}
8081
8082int
8083qeth_add_ipato_entry(struct qeth_card *card, struct qeth_ipato_entry *new)
8084{
8085 struct qeth_ipato_entry *ipatoe;
8086 unsigned long flags;
8087 int rc = 0;
8088
8089 QETH_DBF_TEXT(trace, 2, "addipato");
8090 spin_lock_irqsave(&card->ip_lock, flags);
8091 list_for_each_entry(ipatoe, &card->ipato.entries, entry){
8092 if (ipatoe->proto != new->proto)
8093 continue;
8094 if (!memcmp(ipatoe->addr, new->addr,
8095 (ipatoe->proto == QETH_PROT_IPV4)? 4:16) &&
8096 (ipatoe->mask_bits == new->mask_bits)){
8097 PRINT_WARN("ipato entry already exists!\n");
8098 rc = -EEXIST;
8099 break;
8100 }
8101 }
8102 if (!rc) {
8103 list_add_tail(&new->entry, &card->ipato.entries);
8104 }
8105 spin_unlock_irqrestore(&card->ip_lock, flags);
8106 return rc;
8107}
8108
8109void
8110qeth_del_ipato_entry(struct qeth_card *card, enum qeth_prot_versions proto,
8111 u8 *addr, int mask_bits)
8112{
8113 struct qeth_ipato_entry *ipatoe, *tmp;
8114 unsigned long flags;
8115
8116 QETH_DBF_TEXT(trace, 2, "delipato");
8117 spin_lock_irqsave(&card->ip_lock, flags);
8118 list_for_each_entry_safe(ipatoe, tmp, &card->ipato.entries, entry){
8119 if (ipatoe->proto != proto)
8120 continue;
8121 if (!memcmp(ipatoe->addr, addr,
8122 (proto == QETH_PROT_IPV4)? 4:16) &&
8123 (ipatoe->mask_bits == mask_bits)){
8124 list_del(&ipatoe->entry);
8125 kfree(ipatoe);
8126 }
8127 }
8128 spin_unlock_irqrestore(&card->ip_lock, flags);
8129}
8130
8131static inline void
8132qeth_convert_addr_to_bits(u8 *addr, u8 *bits, int len)
8133{
8134 int i, j;
8135 u8 octet;
8136
8137 for (i = 0; i < len; ++i){
8138 octet = addr[i];
8139 for (j = 7; j >= 0; --j){
8140 bits[i*8 + j] = octet & 1;
8141 octet >>= 1;
8142 }
8143 }
8144}
8145
8146static int
8147qeth_is_addr_covered_by_ipato(struct qeth_card *card, struct qeth_ipaddr *addr)
8148{
8149 struct qeth_ipato_entry *ipatoe;
8150 u8 addr_bits[128] = {0, };
8151 u8 ipatoe_bits[128] = {0, };
8152 int rc = 0;
8153
8154 if (!card->ipato.enabled)
8155 return 0;
8156
8157 qeth_convert_addr_to_bits((u8 *) &addr->u, addr_bits,
8158 (addr->proto == QETH_PROT_IPV4)? 4:16);
8159 list_for_each_entry(ipatoe, &card->ipato.entries, entry){
8160 if (addr->proto != ipatoe->proto)
8161 continue;
8162 qeth_convert_addr_to_bits(ipatoe->addr, ipatoe_bits,
8163 (ipatoe->proto==QETH_PROT_IPV4) ?
8164 4:16);
8165 if (addr->proto == QETH_PROT_IPV4)
8166 rc = !memcmp(addr_bits, ipatoe_bits,
8167 min(32, ipatoe->mask_bits));
8168 else
8169 rc = !memcmp(addr_bits, ipatoe_bits,
8170 min(128, ipatoe->mask_bits));
8171 if (rc)
8172 break;
8173 }
8174 /* invert? */
8175 if ((addr->proto == QETH_PROT_IPV4) && card->ipato.invert4)
8176 rc = !rc;
8177 else if ((addr->proto == QETH_PROT_IPV6) && card->ipato.invert6)
8178 rc = !rc;
8179
8180 return rc;
8181}
8182
8183/*
8184 * VIPA related functions
8185 */
8186int
8187qeth_add_vipa(struct qeth_card *card, enum qeth_prot_versions proto,
8188 const u8 *addr)
8189{
8190 struct qeth_ipaddr *ipaddr;
8191 unsigned long flags;
8192 int rc = 0;
8193
8194 ipaddr = qeth_get_addr_buffer(proto);
8195 if (ipaddr){
8196 if (proto == QETH_PROT_IPV4){
8197 QETH_DBF_TEXT(trace, 2, "addvipa4");
8198 memcpy(&ipaddr->u.a4.addr, addr, 4);
8199 ipaddr->u.a4.mask = 0;
8200#ifdef CONFIG_QETH_IPV6
8201 } else if (proto == QETH_PROT_IPV6){
8202 QETH_DBF_TEXT(trace, 2, "addvipa6");
8203 memcpy(&ipaddr->u.a6.addr, addr, 16);
8204 ipaddr->u.a6.pfxlen = 0;
8205#endif
8206 }
8207 ipaddr->type = QETH_IP_TYPE_VIPA;
8208 ipaddr->set_flags = QETH_IPA_SETIP_VIPA_FLAG;
8209 ipaddr->del_flags = QETH_IPA_DELIP_VIPA_FLAG;
8210 } else
8211 return -ENOMEM;
8212 spin_lock_irqsave(&card->ip_lock, flags);
8213 if (__qeth_address_exists_in_list(&card->ip_list, ipaddr, 0) ||
8214 __qeth_address_exists_in_list(card->ip_tbd_list, ipaddr, 0))
8215 rc = -EEXIST;
8216 spin_unlock_irqrestore(&card->ip_lock, flags);
8217 if (rc){
8218 PRINT_WARN("Cannot add VIPA. Address already exists!\n");
8219 return rc;
8220 }
8221 if (!qeth_add_ip(card, ipaddr))
8222 kfree(ipaddr);
8223 if (qeth_set_thread_start_bit(card, QETH_SET_IP_THREAD) == 0)
8224 schedule_work(&card->kernel_thread_starter);
8225 return rc;
8226}
8227
8228void
8229qeth_del_vipa(struct qeth_card *card, enum qeth_prot_versions proto,
8230 const u8 *addr)
8231{
8232 struct qeth_ipaddr *ipaddr;
8233
8234 ipaddr = qeth_get_addr_buffer(proto);
8235 if (ipaddr){
8236 if (proto == QETH_PROT_IPV4){
8237 QETH_DBF_TEXT(trace, 2, "delvipa4");
8238 memcpy(&ipaddr->u.a4.addr, addr, 4);
8239 ipaddr->u.a4.mask = 0;
8240#ifdef CONFIG_QETH_IPV6
8241 } else if (proto == QETH_PROT_IPV6){
8242 QETH_DBF_TEXT(trace, 2, "delvipa6");
8243 memcpy(&ipaddr->u.a6.addr, addr, 16);
8244 ipaddr->u.a6.pfxlen = 0;
8245#endif
8246 }
8247 ipaddr->type = QETH_IP_TYPE_VIPA;
8248 } else
8249 return;
8250 if (!qeth_delete_ip(card, ipaddr))
8251 kfree(ipaddr);
8252 if (qeth_set_thread_start_bit(card, QETH_SET_IP_THREAD) == 0)
8253 schedule_work(&card->kernel_thread_starter);
8254}
8255
8256/*
8257 * proxy ARP related functions
8258 */
8259int
8260qeth_add_rxip(struct qeth_card *card, enum qeth_prot_versions proto,
8261 const u8 *addr)
8262{
8263 struct qeth_ipaddr *ipaddr;
8264 unsigned long flags;
8265 int rc = 0;
8266
8267 ipaddr = qeth_get_addr_buffer(proto);
8268 if (ipaddr){
8269 if (proto == QETH_PROT_IPV4){
8270 QETH_DBF_TEXT(trace, 2, "addrxip4");
8271 memcpy(&ipaddr->u.a4.addr, addr, 4);
8272 ipaddr->u.a4.mask = 0;
8273#ifdef CONFIG_QETH_IPV6
8274 } else if (proto == QETH_PROT_IPV6){
8275 QETH_DBF_TEXT(trace, 2, "addrxip6");
8276 memcpy(&ipaddr->u.a6.addr, addr, 16);
8277 ipaddr->u.a6.pfxlen = 0;
8278#endif
8279 }
8280 ipaddr->type = QETH_IP_TYPE_RXIP;
8281 ipaddr->set_flags = QETH_IPA_SETIP_TAKEOVER_FLAG;
8282 ipaddr->del_flags = 0;
8283 } else
8284 return -ENOMEM;
8285 spin_lock_irqsave(&card->ip_lock, flags);
8286 if (__qeth_address_exists_in_list(&card->ip_list, ipaddr, 0) ||
8287 __qeth_address_exists_in_list(card->ip_tbd_list, ipaddr, 0))
8288 rc = -EEXIST;
8289 spin_unlock_irqrestore(&card->ip_lock, flags);
8290 if (rc){
8291 PRINT_WARN("Cannot add RXIP. Address already exists!\n");
8292 return rc;
8293 }
8294 if (!qeth_add_ip(card, ipaddr))
8295 kfree(ipaddr);
8296 if (qeth_set_thread_start_bit(card, QETH_SET_IP_THREAD) == 0)
8297 schedule_work(&card->kernel_thread_starter);
8298 return 0;
8299}
8300
8301void
8302qeth_del_rxip(struct qeth_card *card, enum qeth_prot_versions proto,
8303 const u8 *addr)
8304{
8305 struct qeth_ipaddr *ipaddr;
8306
8307 ipaddr = qeth_get_addr_buffer(proto);
8308 if (ipaddr){
8309 if (proto == QETH_PROT_IPV4){
8310 QETH_DBF_TEXT(trace, 2, "addrxip4");
8311 memcpy(&ipaddr->u.a4.addr, addr, 4);
8312 ipaddr->u.a4.mask = 0;
8313#ifdef CONFIG_QETH_IPV6
8314 } else if (proto == QETH_PROT_IPV6){
8315 QETH_DBF_TEXT(trace, 2, "addrxip6");
8316 memcpy(&ipaddr->u.a6.addr, addr, 16);
8317 ipaddr->u.a6.pfxlen = 0;
8318#endif
8319 }
8320 ipaddr->type = QETH_IP_TYPE_RXIP;
8321 } else
8322 return;
8323 if (!qeth_delete_ip(card, ipaddr))
8324 kfree(ipaddr);
8325 if (qeth_set_thread_start_bit(card, QETH_SET_IP_THREAD) == 0)
8326 schedule_work(&card->kernel_thread_starter);
8327}
8328
8329/**
8330 * IP event handler
8331 */
8332static int
8333qeth_ip_event(struct notifier_block *this,
8334 unsigned long event,void *ptr)
8335{
8336 struct in_ifaddr *ifa = (struct in_ifaddr *)ptr;
8337 struct net_device *dev =(struct net_device *) ifa->ifa_dev->dev;
8338 struct qeth_ipaddr *addr;
8339 struct qeth_card *card;
8340
8341 QETH_DBF_TEXT(trace,3,"ipevent");
8342 card = qeth_get_card_from_dev(dev);
8343 if (!card)
8344 return NOTIFY_DONE;
8345 if (card->options.layer2)
8346 return NOTIFY_DONE;
8347
8348 addr = qeth_get_addr_buffer(QETH_PROT_IPV4);
8349 if (addr != NULL) {
8350 addr->u.a4.addr = ifa->ifa_address;
8351 addr->u.a4.mask = ifa->ifa_mask;
8352 addr->type = QETH_IP_TYPE_NORMAL;
8353 } else
8354 goto out;
8355
8356 switch(event) {
8357 case NETDEV_UP:
8358 if (!qeth_add_ip(card, addr))
8359 kfree(addr);
8360 break;
8361 case NETDEV_DOWN:
8362 if (!qeth_delete_ip(card, addr))
8363 kfree(addr);
8364 break;
8365 default:
8366 break;
8367 }
8368 if (qeth_set_thread_start_bit(card, QETH_SET_IP_THREAD) == 0)
8369 schedule_work(&card->kernel_thread_starter);
8370out:
8371 return NOTIFY_DONE;
8372}
8373
8374static struct notifier_block qeth_ip_notifier = {
8375 qeth_ip_event,
8376 0
8377};
8378
8379#ifdef CONFIG_QETH_IPV6
8380/**
8381 * IPv6 event handler
8382 */
8383static int
8384qeth_ip6_event(struct notifier_block *this,
8385 unsigned long event,void *ptr)
8386{
8387
8388 struct inet6_ifaddr *ifa = (struct inet6_ifaddr *)ptr;
8389 struct net_device *dev = (struct net_device *)ifa->idev->dev;
8390 struct qeth_ipaddr *addr;
8391 struct qeth_card *card;
8392
8393 QETH_DBF_TEXT(trace,3,"ip6event");
8394
8395 card = qeth_get_card_from_dev(dev);
8396 if (!card)
8397 return NOTIFY_DONE;
8398 if (!qeth_is_supported(card, IPA_IPV6))
8399 return NOTIFY_DONE;
8400
8401 addr = qeth_get_addr_buffer(QETH_PROT_IPV6);
8402 if (addr != NULL) {
8403 memcpy(&addr->u.a6.addr, &ifa->addr, sizeof(struct in6_addr));
8404 addr->u.a6.pfxlen = ifa->prefix_len;
8405 addr->type = QETH_IP_TYPE_NORMAL;
8406 } else
8407 goto out;
8408
8409 switch(event) {
8410 case NETDEV_UP:
8411 if (!qeth_add_ip(card, addr))
8412 kfree(addr);
8413 break;
8414 case NETDEV_DOWN:
8415 if (!qeth_delete_ip(card, addr))
8416 kfree(addr);
8417 break;
8418 default:
8419 break;
8420 }
8421 if (qeth_set_thread_start_bit(card, QETH_SET_IP_THREAD) == 0)
8422 schedule_work(&card->kernel_thread_starter);
8423out:
8424 return NOTIFY_DONE;
8425}
8426
8427static struct notifier_block qeth_ip6_notifier = {
8428 qeth_ip6_event,
8429 0
8430};
8431#endif
8432
8433static int
Cornelia Huck66aea232005-08-08 09:22:36 -07008434__qeth_reboot_event_card(struct device *dev, void *data)
8435{
8436 struct qeth_card *card;
8437
8438 card = (struct qeth_card *) dev->driver_data;
8439 qeth_clear_ip_list(card, 0, 0);
8440 qeth_qdio_clear_card(card, 0);
8441 return 0;
8442}
8443
8444static int
Linus Torvalds1da177e2005-04-16 15:20:36 -07008445qeth_reboot_event(struct notifier_block *this, unsigned long event, void *ptr)
8446{
8447
Cornelia Huck66aea232005-08-08 09:22:36 -07008448 driver_for_each_device(&qeth_ccwgroup_driver.driver, NULL, NULL,
8449 __qeth_reboot_event_card);
Linus Torvalds1da177e2005-04-16 15:20:36 -07008450 return NOTIFY_DONE;
8451}
8452
8453
8454static struct notifier_block qeth_reboot_notifier = {
8455 qeth_reboot_event,
8456 0
8457};
8458
8459static int
8460qeth_register_notifiers(void)
8461{
8462 int r;
8463
8464 QETH_DBF_TEXT(trace,5,"regnotif");
8465 if ((r = register_reboot_notifier(&qeth_reboot_notifier)))
8466 return r;
8467 if ((r = register_inetaddr_notifier(&qeth_ip_notifier)))
8468 goto out_reboot;
8469#ifdef CONFIG_QETH_IPV6
8470 if ((r = register_inet6addr_notifier(&qeth_ip6_notifier)))
8471 goto out_ipv4;
8472#endif
8473 return 0;
8474
8475#ifdef CONFIG_QETH_IPV6
8476out_ipv4:
8477 unregister_inetaddr_notifier(&qeth_ip_notifier);
8478#endif
8479out_reboot:
8480 unregister_reboot_notifier(&qeth_reboot_notifier);
8481 return r;
8482}
8483
8484/**
8485 * unregister all event notifiers
8486 */
8487static void
8488qeth_unregister_notifiers(void)
8489{
8490
8491 QETH_DBF_TEXT(trace,5,"unregnot");
8492 BUG_ON(unregister_reboot_notifier(&qeth_reboot_notifier));
8493 BUG_ON(unregister_inetaddr_notifier(&qeth_ip_notifier));
8494#ifdef CONFIG_QETH_IPV6
8495 BUG_ON(unregister_inet6addr_notifier(&qeth_ip6_notifier));
8496#endif /* QETH_IPV6 */
8497
8498}
8499
8500#ifdef CONFIG_QETH_IPV6
8501static int
8502qeth_ipv6_init(void)
8503{
8504 qeth_old_arp_constructor = arp_tbl.constructor;
8505 write_lock(&arp_tbl.lock);
8506 arp_tbl.constructor = qeth_arp_constructor;
8507 write_unlock(&arp_tbl.lock);
8508
8509 arp_direct_ops = (struct neigh_ops*)
8510 kmalloc(sizeof(struct neigh_ops), GFP_KERNEL);
8511 if (!arp_direct_ops)
8512 return -ENOMEM;
8513
8514 memcpy(arp_direct_ops, &arp_direct_ops_template,
8515 sizeof(struct neigh_ops));
8516
8517 return 0;
8518}
8519
8520static void
8521qeth_ipv6_uninit(void)
8522{
8523 write_lock(&arp_tbl.lock);
8524 arp_tbl.constructor = qeth_old_arp_constructor;
8525 write_unlock(&arp_tbl.lock);
8526 kfree(arp_direct_ops);
8527}
8528#endif /* CONFIG_QETH_IPV6 */
8529
8530static void
8531qeth_sysfs_unregister(void)
8532{
8533 qeth_remove_driver_attributes();
8534 ccw_driver_unregister(&qeth_ccw_driver);
8535 ccwgroup_driver_unregister(&qeth_ccwgroup_driver);
8536 s390_root_dev_unregister(qeth_root_dev);
8537}
8538/**
8539 * register qeth at sysfs
8540 */
8541static int
8542qeth_sysfs_register(void)
8543{
8544 int rc=0;
8545
8546 rc = ccwgroup_driver_register(&qeth_ccwgroup_driver);
8547 if (rc)
8548 return rc;
8549 rc = ccw_driver_register(&qeth_ccw_driver);
8550 if (rc)
8551 return rc;
8552 rc = qeth_create_driver_attributes();
8553 if (rc)
8554 return rc;
8555 qeth_root_dev = s390_root_dev_register("qeth");
8556 if (IS_ERR(qeth_root_dev)) {
8557 rc = PTR_ERR(qeth_root_dev);
8558 return rc;
8559 }
8560 return 0;
8561}
8562
8563/***
8564 * init function
8565 */
8566static int __init
8567qeth_init(void)
8568{
8569 int rc=0;
8570
Heiko Carstense018ba12006-02-01 03:06:31 -08008571 PRINT_INFO("loading %s\n", version);
Linus Torvalds1da177e2005-04-16 15:20:36 -07008572
8573 INIT_LIST_HEAD(&qeth_card_list.list);
8574 INIT_LIST_HEAD(&qeth_notify_list);
8575 spin_lock_init(&qeth_notify_lock);
8576 rwlock_init(&qeth_card_list.rwlock);
8577
8578 if (qeth_register_dbf_views())
8579 goto out_err;
8580 if (qeth_sysfs_register())
8581 goto out_sysfs;
8582
8583#ifdef CONFIG_QETH_IPV6
8584 if (qeth_ipv6_init()) {
8585 PRINT_ERR("Out of memory during ipv6 init.\n");
8586 goto out_sysfs;
8587 }
8588#endif /* QETH_IPV6 */
8589 if (qeth_register_notifiers())
8590 goto out_ipv6;
8591 if (qeth_create_procfs_entries())
8592 goto out_notifiers;
8593
8594 return rc;
8595
8596out_notifiers:
8597 qeth_unregister_notifiers();
8598out_ipv6:
8599#ifdef CONFIG_QETH_IPV6
8600 qeth_ipv6_uninit();
8601#endif /* QETH_IPV6 */
8602out_sysfs:
8603 qeth_sysfs_unregister();
8604 qeth_unregister_dbf_views();
8605out_err:
8606 PRINT_ERR("Initialization failed");
8607 return rc;
8608}
8609
8610static void
8611__exit qeth_exit(void)
8612{
8613 struct qeth_card *card, *tmp;
8614 unsigned long flags;
8615
8616 QETH_DBF_TEXT(trace,1, "cleanup.");
8617
8618 /*
8619 * Weed would not need to clean up our devices here, because the
8620 * common device layer calls qeth_remove_device for each device
8621 * as soon as we unregister our driver (done in qeth_sysfs_unregister).
8622 * But we do cleanup here so we can do a "soft" shutdown of our cards.
8623 * qeth_remove_device called by the common device layer would otherwise
8624 * do a "hard" shutdown (card->use_hard_stop is set to one in
8625 * qeth_remove_device).
8626 */
8627again:
8628 read_lock_irqsave(&qeth_card_list.rwlock, flags);
8629 list_for_each_entry_safe(card, tmp, &qeth_card_list.list, list){
8630 read_unlock_irqrestore(&qeth_card_list.rwlock, flags);
8631 qeth_set_offline(card->gdev);
8632 qeth_remove_device(card->gdev);
8633 goto again;
8634 }
8635 read_unlock_irqrestore(&qeth_card_list.rwlock, flags);
8636#ifdef CONFIG_QETH_IPV6
8637 qeth_ipv6_uninit();
8638#endif
8639 qeth_unregister_notifiers();
8640 qeth_remove_procfs_entries();
8641 qeth_sysfs_unregister();
8642 qeth_unregister_dbf_views();
8643 printk("qeth: removed\n");
8644}
8645
Ursula Braun500f83a2005-09-30 10:19:19 +02008646EXPORT_SYMBOL(qeth_osn_register);
8647EXPORT_SYMBOL(qeth_osn_deregister);
8648EXPORT_SYMBOL(qeth_osn_assist);
Linus Torvalds1da177e2005-04-16 15:20:36 -07008649module_init(qeth_init);
8650module_exit(qeth_exit);
Frank Pavlic1387780f2005-11-10 13:51:42 +01008651MODULE_AUTHOR("Frank Pavlic <fpavlic@de.ibm.com>");
Linus Torvalds1da177e2005-04-16 15:20:36 -07008652MODULE_DESCRIPTION("Linux on zSeries OSA Express and HiperSockets support\n" \
8653 "Copyright 2000,2003 IBM Corporation\n");
8654
8655MODULE_LICENSE("GPL");