blob: b3c6e7907790ec9e4c2a5ab9ab1d79e2a18bdc2a [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 Pavlic13877802005-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 *));
Frank Pavlic4965e972005-12-13 08:22:30 +0100516
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) &&
607 (memcmp(&addr->mac, &todo->mac,
608 OSA_ADDR_LEN) == 0)) {
609 found = 1;
610 break;
611 }
612 continue;
613 }
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) &&
697 (memcmp(&tmp->mac, &addr->mac,
698 OSA_ADDR_LEN) == 0)) {
699 found = 1;
700 break;
701 }
702 continue;
703 }
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;
Ursula Braun500f83a2005-09-30 10:19:19 +02001176 }
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);
1201
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;
1223 }
1224 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}
1846
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;
1940}
1941
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}
1969
1970static 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);
Ursula Braun500f83a2005-09-30 10:19:19 +02002582 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) &&
2766 qeth_check_qdio_errors(buffer->buffer,
2767 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
Ursula Braun9123e0d2005-09-30 10:17:24 +02003190 card->qdio.in_q = kmalloc(sizeof(struct qeth_qdio_q),
3191 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;
3479 if (rc2)
3480 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;
3494 if (rc2)
3495 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 }
3801 card->dev->flags |= IFF_UP;
3802 netif_start_queue(dev);
3803 card->data.state = CH_STATE_UP;
3804 card->state = CARD_STATE_UP;
3805
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
3820 netif_stop_queue(dev);
3821 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));
3961 if (hdr == NULL)
3962 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) &&
Frank Pavlic9a455812005-05-12 20:38:28 +02004101 !memcmp(skb->data + sizeof(struct qeth_hdr) +
4102 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
Frank Pavlic9cb90de2005-09-14 18:03:26 +02004388qeth_get_elements_no(struct qeth_card *card, void *hdr,
4389 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;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004419 int rc;
4420
4421 QETH_DBF_TEXT(trace, 6, "sendpkt");
4422
4423 if (!card->options.layer2) {
4424 ipv = qeth_get_ip_version(skb);
4425 if ((card->dev->hard_header == qeth_fake_header) && ipv) {
4426 if ((skb = qeth_pskb_unshare(skb,GFP_ATOMIC)) == NULL) {
4427 card->stats.tx_dropped++;
4428 dev_kfree_skb_irq(skb);
4429 return 0;
4430 }
Frank Pavlice23dd9c2005-05-12 20:38:11 +02004431 if(card->dev->type == ARPHRD_IEEE802_TR){
4432 skb_pull(skb, QETH_FAKE_LL_LEN_TR);
4433 } else {
4434 skb_pull(skb, QETH_FAKE_LL_LEN_ETH);
4435 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004436 }
4437 }
Ursula Braun500f83a2005-09-30 10:19:19 +02004438 if ((card->info.type == QETH_CARD_TYPE_OSN) &&
4439 (skb->protocol == htons(ETH_P_IPV6))) {
4440 dev_kfree_skb_any(skb);
4441 return 0;
4442 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004443 cast_type = qeth_get_cast_type(card, skb);
Ursula Braun500f83a2005-09-30 10:19:19 +02004444 if ((cast_type == RTN_BROADCAST) &&
4445 (card->info.broadcast_capable == 0)){
Linus Torvalds1da177e2005-04-16 15:20:36 -07004446 card->stats.tx_dropped++;
4447 card->stats.tx_errors++;
4448 dev_kfree_skb_any(skb);
4449 return NETDEV_TX_OK;
4450 }
4451 queue = card->qdio.out_qs
4452 [qeth_get_priority_queue(card, skb, ipv, cast_type)];
4453
4454 if (skb_shinfo(skb)->tso_size)
4455 large_send = card->options.large_send;
4456
Linus Torvalds1da177e2005-04-16 15:20:36 -07004457 /*are we able to do TSO ? If so ,prepare and send it from here */
4458 if ((large_send == QETH_LARGE_SEND_TSO) &&
4459 (cast_type == RTN_UNSPEC)) {
Frank Pavlic05e08a22005-05-12 20:39:09 +02004460 rc = qeth_tso_prepare_packet(card, skb, ipv, cast_type);
4461 if (rc) {
4462 card->stats.tx_dropped++;
4463 card->stats.tx_errors++;
4464 dev_kfree_skb_any(skb);
4465 return NETDEV_TX_OK;
4466 }
4467 elements_needed++;
4468 } else {
4469 if ((rc = qeth_prepare_skb(card, &skb, &hdr, ipv))) {
4470 QETH_DBF_TEXT_(trace, 4, "pskbe%d", rc);
4471 return rc;
4472 }
Ursula Braun500f83a2005-09-30 10:19:19 +02004473 if (card->info.type != QETH_CARD_TYPE_OSN)
4474 qeth_fill_header(card, hdr, skb, ipv, cast_type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004475 }
4476
Linus Torvalds1da177e2005-04-16 15:20:36 -07004477 if (large_send == QETH_LARGE_SEND_EDDP) {
4478 ctx = qeth_eddp_create_context(card, skb, hdr);
4479 if (ctx == NULL) {
4480 PRINT_WARN("could not create eddp context\n");
4481 return -EINVAL;
4482 }
4483 } else {
Frank Pavlic9cb90de2005-09-14 18:03:26 +02004484 int elems = qeth_get_elements_no(card,(void*) hdr, skb,
4485 elements_needed);
4486 if (!elems)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004487 return -EINVAL;
Frank Pavlic9cb90de2005-09-14 18:03:26 +02004488 elements_needed += elems;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004489 }
4490
4491 if (card->info.type != QETH_CARD_TYPE_IQD)
4492 rc = qeth_do_send_packet(card, queue, skb, hdr,
4493 elements_needed, ctx);
4494 else
4495 rc = qeth_do_send_packet_fast(card, queue, skb, hdr,
4496 elements_needed, ctx);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004497 if (!rc){
4498 card->stats.tx_packets++;
Frank Pavlic95f6b5a2006-03-22 16:03:39 +01004499 card->stats.tx_bytes += tx_bytes;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004500#ifdef CONFIG_QETH_PERF_STATS
Frank Pavlic05e08a22005-05-12 20:39:09 +02004501 if (skb_shinfo(skb)->tso_size &&
4502 !(large_send == QETH_LARGE_SEND_NO)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004503 card->perf_stats.large_send_bytes += skb->len;
4504 card->perf_stats.large_send_cnt++;
4505 }
4506 if (skb_shinfo(skb)->nr_frags > 0){
4507 card->perf_stats.sg_skbs_sent++;
4508 /* nr_frags + skb->data */
4509 card->perf_stats.sg_frags_sent +=
4510 skb_shinfo(skb)->nr_frags + 1;
4511 }
4512#endif /* CONFIG_QETH_PERF_STATS */
4513 }
4514 if (ctx != NULL) {
4515 /* drop creator's reference */
4516 qeth_eddp_put_context(ctx);
4517 /* free skb; it's not referenced by a buffer */
4518 if (rc == 0)
4519 dev_kfree_skb_any(skb);
4520
4521 }
4522 return rc;
4523}
4524
4525static int
4526qeth_mdio_read(struct net_device *dev, int phy_id, int regnum)
4527{
4528 struct qeth_card *card = (struct qeth_card *) dev->priv;
4529 int rc = 0;
4530
4531 switch(regnum){
4532 case MII_BMCR: /* Basic mode control register */
4533 rc = BMCR_FULLDPLX;
4534 if ((card->info.link_type != QETH_LINK_TYPE_GBIT_ETH)&&
Ursula Braun500f83a2005-09-30 10:19:19 +02004535 (card->info.link_type != QETH_LINK_TYPE_OSN) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07004536 (card->info.link_type != QETH_LINK_TYPE_10GBIT_ETH))
4537 rc |= BMCR_SPEED100;
4538 break;
4539 case MII_BMSR: /* Basic mode status register */
4540 rc = BMSR_ERCAP | BMSR_ANEGCOMPLETE | BMSR_LSTATUS |
4541 BMSR_10HALF | BMSR_10FULL | BMSR_100HALF | BMSR_100FULL |
4542 BMSR_100BASE4;
4543 break;
4544 case MII_PHYSID1: /* PHYS ID 1 */
4545 rc = (dev->dev_addr[0] << 16) | (dev->dev_addr[1] << 8) |
4546 dev->dev_addr[2];
4547 rc = (rc >> 5) & 0xFFFF;
4548 break;
4549 case MII_PHYSID2: /* PHYS ID 2 */
4550 rc = (dev->dev_addr[2] << 10) & 0xFFFF;
4551 break;
4552 case MII_ADVERTISE: /* Advertisement control reg */
4553 rc = ADVERTISE_ALL;
4554 break;
4555 case MII_LPA: /* Link partner ability reg */
4556 rc = LPA_10HALF | LPA_10FULL | LPA_100HALF | LPA_100FULL |
4557 LPA_100BASE4 | LPA_LPACK;
4558 break;
4559 case MII_EXPANSION: /* Expansion register */
4560 break;
4561 case MII_DCOUNTER: /* disconnect counter */
4562 break;
4563 case MII_FCSCOUNTER: /* false carrier counter */
4564 break;
4565 case MII_NWAYTEST: /* N-way auto-neg test register */
4566 break;
4567 case MII_RERRCOUNTER: /* rx error counter */
4568 rc = card->stats.rx_errors;
4569 break;
4570 case MII_SREVISION: /* silicon revision */
4571 break;
4572 case MII_RESV1: /* reserved 1 */
4573 break;
4574 case MII_LBRERROR: /* loopback, rx, bypass error */
4575 break;
4576 case MII_PHYADDR: /* physical address */
4577 break;
4578 case MII_RESV2: /* reserved 2 */
4579 break;
4580 case MII_TPISTATUS: /* TPI status for 10mbps */
4581 break;
4582 case MII_NCONFIG: /* network interface config */
4583 break;
4584 default:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004585 break;
4586 }
4587 return rc;
4588}
4589
Linus Torvalds1da177e2005-04-16 15:20:36 -07004590
4591static inline const char *
4592qeth_arp_get_error_cause(int *rc)
4593{
4594 switch (*rc) {
4595 case QETH_IPA_ARP_RC_FAILED:
4596 *rc = -EIO;
4597 return "operation failed";
4598 case QETH_IPA_ARP_RC_NOTSUPP:
4599 *rc = -EOPNOTSUPP;
4600 return "operation not supported";
4601 case QETH_IPA_ARP_RC_OUT_OF_RANGE:
4602 *rc = -EINVAL;
4603 return "argument out of range";
4604 case QETH_IPA_ARP_RC_Q_NOTSUPP:
4605 *rc = -EOPNOTSUPP;
4606 return "query operation not supported";
4607 case QETH_IPA_ARP_RC_Q_NO_DATA:
4608 *rc = -ENOENT;
4609 return "no query data available";
4610 default:
4611 return "unknown error";
4612 }
4613}
4614
4615static int
4616qeth_send_simple_setassparms(struct qeth_card *, enum qeth_ipa_funcs,
4617 __u16, long);
4618
4619static int
4620qeth_arp_set_no_entries(struct qeth_card *card, int no_entries)
4621{
4622 int tmp;
4623 int rc;
4624
4625 QETH_DBF_TEXT(trace,3,"arpstnoe");
4626
Frank Pavlicf3d242e2005-09-14 18:05:31 +02004627 /*
4628 * currently GuestLAN only supports the ARP assist function
4629 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_SET_NO_ENTRIES;
4630 * thus we say EOPNOTSUPP for this ARP function
4631 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07004632 if (card->info.guestlan)
4633 return -EOPNOTSUPP;
4634 if (!qeth_is_supported(card,IPA_ARP_PROCESSING)) {
4635 PRINT_WARN("ARP processing not supported "
4636 "on %s!\n", QETH_CARD_IFNAME(card));
4637 return -EOPNOTSUPP;
4638 }
4639 rc = qeth_send_simple_setassparms(card, IPA_ARP_PROCESSING,
4640 IPA_CMD_ASS_ARP_SET_NO_ENTRIES,
4641 no_entries);
4642 if (rc) {
4643 tmp = rc;
4644 PRINT_WARN("Could not set number of ARP entries on %s: "
4645 "%s (0x%x/%d)\n",
4646 QETH_CARD_IFNAME(card), qeth_arp_get_error_cause(&rc),
4647 tmp, tmp);
4648 }
4649 return rc;
4650}
4651
4652static inline void
4653qeth_copy_arp_entries_stripped(struct qeth_arp_query_info *qinfo,
4654 struct qeth_arp_query_data *qdata,
4655 int entry_size, int uentry_size)
4656{
4657 char *entry_ptr;
4658 char *uentry_ptr;
4659 int i;
4660
4661 entry_ptr = (char *)&qdata->data;
4662 uentry_ptr = (char *)(qinfo->udata + qinfo->udata_offset);
4663 for (i = 0; i < qdata->no_entries; ++i){
4664 /* strip off 32 bytes "media specific information" */
4665 memcpy(uentry_ptr, (entry_ptr + 32), entry_size - 32);
4666 entry_ptr += entry_size;
4667 uentry_ptr += uentry_size;
4668 }
4669}
4670
4671static int
4672qeth_arp_query_cb(struct qeth_card *card, struct qeth_reply *reply,
4673 unsigned long data)
4674{
4675 struct qeth_ipa_cmd *cmd;
4676 struct qeth_arp_query_data *qdata;
4677 struct qeth_arp_query_info *qinfo;
4678 int entry_size;
4679 int uentry_size;
4680 int i;
4681
4682 QETH_DBF_TEXT(trace,4,"arpquecb");
4683
4684 qinfo = (struct qeth_arp_query_info *) reply->param;
4685 cmd = (struct qeth_ipa_cmd *) data;
4686 if (cmd->hdr.return_code) {
4687 QETH_DBF_TEXT_(trace,4,"qaer1%i", cmd->hdr.return_code);
4688 return 0;
4689 }
4690 if (cmd->data.setassparms.hdr.return_code) {
4691 cmd->hdr.return_code = cmd->data.setassparms.hdr.return_code;
4692 QETH_DBF_TEXT_(trace,4,"qaer2%i", cmd->hdr.return_code);
4693 return 0;
4694 }
4695 qdata = &cmd->data.setassparms.data.query_arp;
4696 switch(qdata->reply_bits){
4697 case 5:
4698 uentry_size = entry_size = sizeof(struct qeth_arp_qi_entry5);
4699 if (qinfo->mask_bits & QETH_QARP_STRIP_ENTRIES)
4700 uentry_size = sizeof(struct qeth_arp_qi_entry5_short);
4701 break;
4702 case 7:
4703 /* fall through to default */
4704 default:
4705 /* tr is the same as eth -> entry7 */
4706 uentry_size = entry_size = sizeof(struct qeth_arp_qi_entry7);
4707 if (qinfo->mask_bits & QETH_QARP_STRIP_ENTRIES)
4708 uentry_size = sizeof(struct qeth_arp_qi_entry7_short);
4709 break;
4710 }
4711 /* check if there is enough room in userspace */
4712 if ((qinfo->udata_len - qinfo->udata_offset) <
4713 qdata->no_entries * uentry_size){
4714 QETH_DBF_TEXT_(trace, 4, "qaer3%i", -ENOMEM);
4715 cmd->hdr.return_code = -ENOMEM;
4716 PRINT_WARN("query ARP user space buffer is too small for "
4717 "the returned number of ARP entries. "
4718 "Aborting query!\n");
4719 goto out_error;
4720 }
4721 QETH_DBF_TEXT_(trace, 4, "anore%i",
4722 cmd->data.setassparms.hdr.number_of_replies);
4723 QETH_DBF_TEXT_(trace, 4, "aseqn%i", cmd->data.setassparms.hdr.seq_no);
4724 QETH_DBF_TEXT_(trace, 4, "anoen%i", qdata->no_entries);
4725
4726 if (qinfo->mask_bits & QETH_QARP_STRIP_ENTRIES) {
4727 /* strip off "media specific information" */
4728 qeth_copy_arp_entries_stripped(qinfo, qdata, entry_size,
4729 uentry_size);
4730 } else
4731 /*copy entries to user buffer*/
4732 memcpy(qinfo->udata + qinfo->udata_offset,
4733 (char *)&qdata->data, qdata->no_entries*uentry_size);
4734
4735 qinfo->no_entries += qdata->no_entries;
4736 qinfo->udata_offset += (qdata->no_entries*uentry_size);
4737 /* check if all replies received ... */
4738 if (cmd->data.setassparms.hdr.seq_no <
4739 cmd->data.setassparms.hdr.number_of_replies)
4740 return 1;
4741 memcpy(qinfo->udata, &qinfo->no_entries, 4);
4742 /* keep STRIP_ENTRIES flag so the user program can distinguish
4743 * stripped entries from normal ones */
4744 if (qinfo->mask_bits & QETH_QARP_STRIP_ENTRIES)
4745 qdata->reply_bits |= QETH_QARP_STRIP_ENTRIES;
4746 memcpy(qinfo->udata + QETH_QARP_MASK_OFFSET,&qdata->reply_bits,2);
4747 return 0;
4748out_error:
4749 i = 0;
4750 memcpy(qinfo->udata, &i, 4);
4751 return 0;
4752}
4753
4754static int
4755qeth_send_ipa_arp_cmd(struct qeth_card *card, struct qeth_cmd_buffer *iob,
4756 int len, int (*reply_cb)(struct qeth_card *,
4757 struct qeth_reply *,
4758 unsigned long),
4759 void *reply_param)
4760{
4761 QETH_DBF_TEXT(trace,4,"sendarp");
4762
4763 memcpy(iob->data, IPA_PDU_HEADER, IPA_PDU_HEADER_SIZE);
4764 memcpy(QETH_IPA_CMD_DEST_ADDR(iob->data),
4765 &card->token.ulp_connection_r, QETH_MPC_TOKEN_LENGTH);
4766 return qeth_send_control_data(card, IPA_PDU_HEADER_SIZE + len, iob,
4767 reply_cb, reply_param);
4768}
4769
4770static int
4771qeth_send_ipa_snmp_cmd(struct qeth_card *card, struct qeth_cmd_buffer *iob,
4772 int len, int (*reply_cb)(struct qeth_card *,
4773 struct qeth_reply *,
4774 unsigned long),
4775 void *reply_param)
4776{
4777 u16 s1, s2;
4778
4779 QETH_DBF_TEXT(trace,4,"sendsnmp");
4780
4781 memcpy(iob->data, IPA_PDU_HEADER, IPA_PDU_HEADER_SIZE);
4782 memcpy(QETH_IPA_CMD_DEST_ADDR(iob->data),
4783 &card->token.ulp_connection_r, QETH_MPC_TOKEN_LENGTH);
4784 /* adjust PDU length fields in IPA_PDU_HEADER */
4785 s1 = (u32) IPA_PDU_HEADER_SIZE + len;
4786 s2 = (u32) len;
4787 memcpy(QETH_IPA_PDU_LEN_TOTAL(iob->data), &s1, 2);
4788 memcpy(QETH_IPA_PDU_LEN_PDU1(iob->data), &s2, 2);
4789 memcpy(QETH_IPA_PDU_LEN_PDU2(iob->data), &s2, 2);
4790 memcpy(QETH_IPA_PDU_LEN_PDU3(iob->data), &s2, 2);
4791 return qeth_send_control_data(card, IPA_PDU_HEADER_SIZE + len, iob,
4792 reply_cb, reply_param);
4793}
4794
4795static struct qeth_cmd_buffer *
4796qeth_get_setassparms_cmd(struct qeth_card *, enum qeth_ipa_funcs,
4797 __u16, __u16, enum qeth_prot_versions);
4798static int
4799qeth_arp_query(struct qeth_card *card, char *udata)
4800{
4801 struct qeth_cmd_buffer *iob;
4802 struct qeth_arp_query_info qinfo = {0, };
4803 int tmp;
4804 int rc;
4805
4806 QETH_DBF_TEXT(trace,3,"arpquery");
4807
Linus Torvalds1da177e2005-04-16 15:20:36 -07004808 if (!qeth_is_supported(card,/*IPA_QUERY_ARP_ADDR_INFO*/
4809 IPA_ARP_PROCESSING)) {
4810 PRINT_WARN("ARP processing not supported "
4811 "on %s!\n", QETH_CARD_IFNAME(card));
4812 return -EOPNOTSUPP;
4813 }
4814 /* get size of userspace buffer and mask_bits -> 6 bytes */
4815 if (copy_from_user(&qinfo, udata, 6))
4816 return -EFAULT;
Eric Sesterhenn88abaab2006-03-24 03:15:31 -08004817 if (!(qinfo.udata = kzalloc(qinfo.udata_len, GFP_KERNEL)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004818 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004819 qinfo.udata_offset = QETH_QARP_ENTRIES_OFFSET;
4820 iob = qeth_get_setassparms_cmd(card, IPA_ARP_PROCESSING,
4821 IPA_CMD_ASS_ARP_QUERY_INFO,
4822 sizeof(int),QETH_PROT_IPV4);
4823
4824 rc = qeth_send_ipa_arp_cmd(card, iob,
4825 QETH_SETASS_BASE_LEN+QETH_ARP_CMD_LEN,
4826 qeth_arp_query_cb, (void *)&qinfo);
4827 if (rc) {
4828 tmp = rc;
4829 PRINT_WARN("Error while querying ARP cache on %s: %s "
4830 "(0x%x/%d)\n",
4831 QETH_CARD_IFNAME(card), qeth_arp_get_error_cause(&rc),
4832 tmp, tmp);
4833 copy_to_user(udata, qinfo.udata, 4);
4834 } else {
4835 copy_to_user(udata, qinfo.udata, qinfo.udata_len);
4836 }
4837 kfree(qinfo.udata);
4838 return rc;
4839}
4840
4841/**
4842 * SNMP command callback
4843 */
4844static int
4845qeth_snmp_command_cb(struct qeth_card *card, struct qeth_reply *reply,
4846 unsigned long sdata)
4847{
4848 struct qeth_ipa_cmd *cmd;
4849 struct qeth_arp_query_info *qinfo;
4850 struct qeth_snmp_cmd *snmp;
4851 unsigned char *data;
4852 __u16 data_len;
4853
4854 QETH_DBF_TEXT(trace,3,"snpcmdcb");
4855
4856 cmd = (struct qeth_ipa_cmd *) sdata;
4857 data = (unsigned char *)((char *)cmd - reply->offset);
4858 qinfo = (struct qeth_arp_query_info *) reply->param;
4859 snmp = &cmd->data.setadapterparms.data.snmp;
4860
4861 if (cmd->hdr.return_code) {
4862 QETH_DBF_TEXT_(trace,4,"scer1%i", cmd->hdr.return_code);
4863 return 0;
4864 }
4865 if (cmd->data.setadapterparms.hdr.return_code) {
4866 cmd->hdr.return_code = cmd->data.setadapterparms.hdr.return_code;
4867 QETH_DBF_TEXT_(trace,4,"scer2%i", cmd->hdr.return_code);
4868 return 0;
4869 }
4870 data_len = *((__u16*)QETH_IPA_PDU_LEN_PDU1(data));
4871 if (cmd->data.setadapterparms.hdr.seq_no == 1)
4872 data_len -= (__u16)((char *)&snmp->data - (char *)cmd);
4873 else
4874 data_len -= (__u16)((char*)&snmp->request - (char *)cmd);
4875
4876 /* check if there is enough room in userspace */
4877 if ((qinfo->udata_len - qinfo->udata_offset) < data_len) {
4878 QETH_DBF_TEXT_(trace, 4, "scer3%i", -ENOMEM);
4879 cmd->hdr.return_code = -ENOMEM;
4880 return 0;
4881 }
4882 QETH_DBF_TEXT_(trace, 4, "snore%i",
4883 cmd->data.setadapterparms.hdr.used_total);
4884 QETH_DBF_TEXT_(trace, 4, "sseqn%i", cmd->data.setadapterparms.hdr.seq_no);
4885 /*copy entries to user buffer*/
4886 if (cmd->data.setadapterparms.hdr.seq_no == 1) {
4887 memcpy(qinfo->udata + qinfo->udata_offset,
4888 (char *)snmp,
4889 data_len + offsetof(struct qeth_snmp_cmd,data));
4890 qinfo->udata_offset += offsetof(struct qeth_snmp_cmd, data);
4891 } else {
4892 memcpy(qinfo->udata + qinfo->udata_offset,
4893 (char *)&snmp->request, data_len);
4894 }
4895 qinfo->udata_offset += data_len;
4896 /* check if all replies received ... */
4897 QETH_DBF_TEXT_(trace, 4, "srtot%i",
4898 cmd->data.setadapterparms.hdr.used_total);
4899 QETH_DBF_TEXT_(trace, 4, "srseq%i",
4900 cmd->data.setadapterparms.hdr.seq_no);
4901 if (cmd->data.setadapterparms.hdr.seq_no <
4902 cmd->data.setadapterparms.hdr.used_total)
4903 return 1;
4904 return 0;
4905}
4906
4907static struct qeth_cmd_buffer *
4908qeth_get_ipacmd_buffer(struct qeth_card *, enum qeth_ipa_cmds,
4909 enum qeth_prot_versions );
4910
4911static struct qeth_cmd_buffer *
4912qeth_get_adapter_cmd(struct qeth_card *card, __u32 command, __u32 cmdlen)
4913{
4914 struct qeth_cmd_buffer *iob;
4915 struct qeth_ipa_cmd *cmd;
4916
4917 iob = qeth_get_ipacmd_buffer(card,IPA_CMD_SETADAPTERPARMS,
4918 QETH_PROT_IPV4);
4919 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
4920 cmd->data.setadapterparms.hdr.cmdlength = cmdlen;
4921 cmd->data.setadapterparms.hdr.command_code = command;
4922 cmd->data.setadapterparms.hdr.used_total = 1;
4923 cmd->data.setadapterparms.hdr.seq_no = 1;
4924
4925 return iob;
4926}
4927
4928/**
4929 * function to send SNMP commands to OSA-E card
4930 */
4931static int
4932qeth_snmp_command(struct qeth_card *card, char *udata)
4933{
4934 struct qeth_cmd_buffer *iob;
4935 struct qeth_ipa_cmd *cmd;
4936 struct qeth_snmp_ureq *ureq;
4937 int req_len;
4938 struct qeth_arp_query_info qinfo = {0, };
4939 int rc = 0;
4940
4941 QETH_DBF_TEXT(trace,3,"snmpcmd");
4942
4943 if (card->info.guestlan)
4944 return -EOPNOTSUPP;
4945
4946 if ((!qeth_adp_supported(card,IPA_SETADP_SET_SNMP_CONTROL)) &&
4947 (!card->options.layer2) ) {
4948 PRINT_WARN("SNMP Query MIBS not supported "
4949 "on %s!\n", QETH_CARD_IFNAME(card));
4950 return -EOPNOTSUPP;
4951 }
4952 /* skip 4 bytes (data_len struct member) to get req_len */
4953 if (copy_from_user(&req_len, udata + sizeof(int), sizeof(int)))
4954 return -EFAULT;
4955 ureq = kmalloc(req_len+sizeof(struct qeth_snmp_ureq_hdr), GFP_KERNEL);
4956 if (!ureq) {
4957 QETH_DBF_TEXT(trace, 2, "snmpnome");
4958 return -ENOMEM;
4959 }
4960 if (copy_from_user(ureq, udata,
4961 req_len+sizeof(struct qeth_snmp_ureq_hdr))){
4962 kfree(ureq);
4963 return -EFAULT;
4964 }
4965 qinfo.udata_len = ureq->hdr.data_len;
Eric Sesterhenn88abaab2006-03-24 03:15:31 -08004966 if (!(qinfo.udata = kzalloc(qinfo.udata_len, GFP_KERNEL))){
Linus Torvalds1da177e2005-04-16 15:20:36 -07004967 kfree(ureq);
4968 return -ENOMEM;
4969 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004970 qinfo.udata_offset = sizeof(struct qeth_snmp_ureq_hdr);
4971
4972 iob = qeth_get_adapter_cmd(card, IPA_SETADP_SET_SNMP_CONTROL,
4973 QETH_SNMP_SETADP_CMDLENGTH + req_len);
4974 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
4975 memcpy(&cmd->data.setadapterparms.data.snmp, &ureq->cmd, req_len);
4976 rc = qeth_send_ipa_snmp_cmd(card, iob, QETH_SETADP_BASE_LEN + req_len,
4977 qeth_snmp_command_cb, (void *)&qinfo);
4978 if (rc)
4979 PRINT_WARN("SNMP command failed on %s: (0x%x)\n",
4980 QETH_CARD_IFNAME(card), rc);
4981 else
4982 copy_to_user(udata, qinfo.udata, qinfo.udata_len);
4983
4984 kfree(ureq);
4985 kfree(qinfo.udata);
4986 return rc;
4987}
4988
4989static int
4990qeth_default_setassparms_cb(struct qeth_card *, struct qeth_reply *,
4991 unsigned long);
4992
4993static int
Frank Pavlic6c951b92005-11-10 13:51:25 +01004994qeth_default_setadapterparms_cb(struct qeth_card *card,
4995 struct qeth_reply *reply,
4996 unsigned long data);
4997static int
Linus Torvalds1da177e2005-04-16 15:20:36 -07004998qeth_send_setassparms(struct qeth_card *, struct qeth_cmd_buffer *,
4999 __u16, long,
5000 int (*reply_cb)
5001 (struct qeth_card *, struct qeth_reply *, unsigned long),
5002 void *reply_param);
5003
5004static int
5005qeth_arp_add_entry(struct qeth_card *card, struct qeth_arp_cache_entry *entry)
5006{
5007 struct qeth_cmd_buffer *iob;
5008 char buf[16];
5009 int tmp;
5010 int rc;
5011
5012 QETH_DBF_TEXT(trace,3,"arpadent");
5013
5014 /*
Frank Pavlicf3d242e2005-09-14 18:05:31 +02005015 * currently GuestLAN only supports the ARP assist function
5016 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_ADD_ENTRY;
5017 * thus we say EOPNOTSUPP for this ARP function
Linus Torvalds1da177e2005-04-16 15:20:36 -07005018 */
5019 if (card->info.guestlan)
5020 return -EOPNOTSUPP;
5021 if (!qeth_is_supported(card,IPA_ARP_PROCESSING)) {
5022 PRINT_WARN("ARP processing not supported "
5023 "on %s!\n", QETH_CARD_IFNAME(card));
5024 return -EOPNOTSUPP;
5025 }
5026
5027 iob = qeth_get_setassparms_cmd(card, IPA_ARP_PROCESSING,
5028 IPA_CMD_ASS_ARP_ADD_ENTRY,
5029 sizeof(struct qeth_arp_cache_entry),
5030 QETH_PROT_IPV4);
5031 rc = qeth_send_setassparms(card, iob,
5032 sizeof(struct qeth_arp_cache_entry),
5033 (unsigned long) entry,
5034 qeth_default_setassparms_cb, NULL);
5035 if (rc) {
5036 tmp = rc;
5037 qeth_ipaddr4_to_string((u8 *)entry->ipaddr, buf);
5038 PRINT_WARN("Could not add ARP entry for address %s on %s: "
5039 "%s (0x%x/%d)\n",
5040 buf, QETH_CARD_IFNAME(card),
5041 qeth_arp_get_error_cause(&rc), tmp, tmp);
5042 }
5043 return rc;
5044}
5045
5046static int
5047qeth_arp_remove_entry(struct qeth_card *card, struct qeth_arp_cache_entry *entry)
5048{
5049 struct qeth_cmd_buffer *iob;
5050 char buf[16] = {0, };
5051 int tmp;
5052 int rc;
5053
5054 QETH_DBF_TEXT(trace,3,"arprment");
5055
5056 /*
Frank Pavlicf3d242e2005-09-14 18:05:31 +02005057 * currently GuestLAN only supports the ARP assist function
5058 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_REMOVE_ENTRY;
5059 * thus we say EOPNOTSUPP for this ARP function
Linus Torvalds1da177e2005-04-16 15:20:36 -07005060 */
5061 if (card->info.guestlan)
5062 return -EOPNOTSUPP;
5063 if (!qeth_is_supported(card,IPA_ARP_PROCESSING)) {
5064 PRINT_WARN("ARP processing not supported "
5065 "on %s!\n", QETH_CARD_IFNAME(card));
5066 return -EOPNOTSUPP;
5067 }
5068 memcpy(buf, entry, 12);
5069 iob = qeth_get_setassparms_cmd(card, IPA_ARP_PROCESSING,
5070 IPA_CMD_ASS_ARP_REMOVE_ENTRY,
5071 12,
5072 QETH_PROT_IPV4);
5073 rc = qeth_send_setassparms(card, iob,
5074 12, (unsigned long)buf,
5075 qeth_default_setassparms_cb, NULL);
5076 if (rc) {
5077 tmp = rc;
5078 memset(buf, 0, 16);
5079 qeth_ipaddr4_to_string((u8 *)entry->ipaddr, buf);
5080 PRINT_WARN("Could not delete ARP entry for address %s on %s: "
5081 "%s (0x%x/%d)\n",
5082 buf, QETH_CARD_IFNAME(card),
5083 qeth_arp_get_error_cause(&rc), tmp, tmp);
5084 }
5085 return rc;
5086}
5087
5088static int
5089qeth_arp_flush_cache(struct qeth_card *card)
5090{
5091 int rc;
5092 int tmp;
5093
5094 QETH_DBF_TEXT(trace,3,"arpflush");
5095
5096 /*
Frank Pavlicf3d242e2005-09-14 18:05:31 +02005097 * currently GuestLAN only supports the ARP assist function
5098 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_FLUSH_CACHE;
5099 * thus we say EOPNOTSUPP for this ARP function
5100 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07005101 if (card->info.guestlan || (card->info.type == QETH_CARD_TYPE_IQD))
5102 return -EOPNOTSUPP;
5103 if (!qeth_is_supported(card,IPA_ARP_PROCESSING)) {
5104 PRINT_WARN("ARP processing not supported "
5105 "on %s!\n", QETH_CARD_IFNAME(card));
5106 return -EOPNOTSUPP;
5107 }
5108 rc = qeth_send_simple_setassparms(card, IPA_ARP_PROCESSING,
5109 IPA_CMD_ASS_ARP_FLUSH_CACHE, 0);
5110 if (rc){
5111 tmp = rc;
5112 PRINT_WARN("Could not flush ARP cache on %s: %s (0x%x/%d)\n",
5113 QETH_CARD_IFNAME(card), qeth_arp_get_error_cause(&rc),
5114 tmp, tmp);
5115 }
5116 return rc;
5117}
5118
5119static int
5120qeth_do_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
5121{
5122 struct qeth_card *card = (struct qeth_card *)dev->priv;
5123 struct qeth_arp_cache_entry arp_entry;
5124 struct mii_ioctl_data *mii_data;
5125 int rc = 0;
5126
5127 if (!card)
5128 return -ENODEV;
5129
5130 if ((card->state != CARD_STATE_UP) &&
5131 (card->state != CARD_STATE_SOFTSETUP))
5132 return -ENODEV;
5133
Ursula Braun500f83a2005-09-30 10:19:19 +02005134 if (card->info.type == QETH_CARD_TYPE_OSN)
5135 return -EPERM;
5136
Linus Torvalds1da177e2005-04-16 15:20:36 -07005137 switch (cmd){
5138 case SIOC_QETH_ARP_SET_NO_ENTRIES:
5139 if ( !capable(CAP_NET_ADMIN) ||
5140 (card->options.layer2) ) {
5141 rc = -EPERM;
5142 break;
5143 }
5144 rc = qeth_arp_set_no_entries(card, rq->ifr_ifru.ifru_ivalue);
5145 break;
5146 case SIOC_QETH_ARP_QUERY_INFO:
5147 if ( !capable(CAP_NET_ADMIN) ||
5148 (card->options.layer2) ) {
5149 rc = -EPERM;
5150 break;
5151 }
5152 rc = qeth_arp_query(card, rq->ifr_ifru.ifru_data);
5153 break;
5154 case SIOC_QETH_ARP_ADD_ENTRY:
5155 if ( !capable(CAP_NET_ADMIN) ||
5156 (card->options.layer2) ) {
5157 rc = -EPERM;
5158 break;
5159 }
5160 if (copy_from_user(&arp_entry, rq->ifr_ifru.ifru_data,
5161 sizeof(struct qeth_arp_cache_entry)))
5162 rc = -EFAULT;
5163 else
5164 rc = qeth_arp_add_entry(card, &arp_entry);
5165 break;
5166 case SIOC_QETH_ARP_REMOVE_ENTRY:
5167 if ( !capable(CAP_NET_ADMIN) ||
5168 (card->options.layer2) ) {
5169 rc = -EPERM;
5170 break;
5171 }
5172 if (copy_from_user(&arp_entry, rq->ifr_ifru.ifru_data,
5173 sizeof(struct qeth_arp_cache_entry)))
5174 rc = -EFAULT;
5175 else
5176 rc = qeth_arp_remove_entry(card, &arp_entry);
5177 break;
5178 case SIOC_QETH_ARP_FLUSH_CACHE:
5179 if ( !capable(CAP_NET_ADMIN) ||
5180 (card->options.layer2) ) {
5181 rc = -EPERM;
5182 break;
5183 }
5184 rc = qeth_arp_flush_cache(card);
5185 break;
5186 case SIOC_QETH_ADP_SET_SNMP_CONTROL:
5187 rc = qeth_snmp_command(card, rq->ifr_ifru.ifru_data);
5188 break;
5189 case SIOC_QETH_GET_CARD_TYPE:
5190 if ((card->info.type == QETH_CARD_TYPE_OSAE) &&
5191 !card->info.guestlan)
5192 return 1;
5193 return 0;
5194 break;
5195 case SIOCGMIIPHY:
5196 mii_data = if_mii(rq);
5197 mii_data->phy_id = 0;
5198 break;
5199 case SIOCGMIIREG:
5200 mii_data = if_mii(rq);
5201 if (mii_data->phy_id != 0)
5202 rc = -EINVAL;
5203 else
5204 mii_data->val_out = qeth_mdio_read(dev,mii_data->phy_id,
5205 mii_data->reg_num);
5206 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005207 default:
5208 rc = -EOPNOTSUPP;
5209 }
5210 if (rc)
5211 QETH_DBF_TEXT_(trace, 2, "ioce%d", rc);
5212 return rc;
5213}
5214
5215static struct net_device_stats *
5216qeth_get_stats(struct net_device *dev)
5217{
5218 struct qeth_card *card;
5219
5220 card = (struct qeth_card *) (dev->priv);
5221
5222 QETH_DBF_TEXT(trace,5,"getstat");
5223
5224 return &card->stats;
5225}
5226
5227static int
5228qeth_change_mtu(struct net_device *dev, int new_mtu)
5229{
5230 struct qeth_card *card;
5231 char dbf_text[15];
5232
5233 card = (struct qeth_card *) (dev->priv);
5234
5235 QETH_DBF_TEXT(trace,4,"chgmtu");
5236 sprintf(dbf_text, "%8x", new_mtu);
5237 QETH_DBF_TEXT(trace,4,dbf_text);
5238
5239 if (new_mtu < 64)
5240 return -EINVAL;
5241 if (new_mtu > 65535)
5242 return -EINVAL;
5243 if ((!qeth_is_supported(card,IPA_IP_FRAGMENTATION)) &&
5244 (!qeth_mtu_is_valid(card, new_mtu)))
5245 return -EINVAL;
5246 dev->mtu = new_mtu;
5247 return 0;
5248}
5249
5250#ifdef CONFIG_QETH_VLAN
5251static void
5252qeth_vlan_rx_register(struct net_device *dev, struct vlan_group *grp)
5253{
5254 struct qeth_card *card;
5255 unsigned long flags;
5256
5257 QETH_DBF_TEXT(trace,4,"vlanreg");
5258
5259 card = (struct qeth_card *) dev->priv;
5260 spin_lock_irqsave(&card->vlanlock, flags);
5261 card->vlangrp = grp;
5262 spin_unlock_irqrestore(&card->vlanlock, flags);
5263}
5264
5265static inline void
5266qeth_free_vlan_buffer(struct qeth_card *card, struct qeth_qdio_out_buffer *buf,
5267 unsigned short vid)
5268{
5269 int i;
5270 struct sk_buff *skb;
5271 struct sk_buff_head tmp_list;
5272
5273 skb_queue_head_init(&tmp_list);
5274 for(i = 0; i < QETH_MAX_BUFFER_ELEMENTS(card); ++i){
5275 while ((skb = skb_dequeue(&buf->skb_list))){
5276 if (vlan_tx_tag_present(skb) &&
5277 (vlan_tx_tag_get(skb) == vid)) {
5278 atomic_dec(&skb->users);
5279 dev_kfree_skb(skb);
5280 } else
5281 skb_queue_tail(&tmp_list, skb);
5282 }
5283 }
5284 while ((skb = skb_dequeue(&tmp_list)))
5285 skb_queue_tail(&buf->skb_list, skb);
5286}
5287
5288static void
5289qeth_free_vlan_skbs(struct qeth_card *card, unsigned short vid)
5290{
5291 int i, j;
5292
5293 QETH_DBF_TEXT(trace, 4, "frvlskbs");
5294 for (i = 0; i < card->qdio.no_out_queues; ++i){
5295 for (j = 0; j < QDIO_MAX_BUFFERS_PER_Q; ++j)
5296 qeth_free_vlan_buffer(card, &card->qdio.
5297 out_qs[i]->bufs[j], vid);
5298 }
5299}
5300
5301static void
5302qeth_free_vlan_addresses4(struct qeth_card *card, unsigned short vid)
5303{
5304 struct in_device *in_dev;
5305 struct in_ifaddr *ifa;
5306 struct qeth_ipaddr *addr;
5307
5308 QETH_DBF_TEXT(trace, 4, "frvaddr4");
Frank Pavlic6c88ad22005-11-10 13:49:28 +01005309
Linus Torvalds1da177e2005-04-16 15:20:36 -07005310 rcu_read_lock();
Herbert Xue5ed6392005-10-03 14:35:55 -07005311 in_dev = __in_dev_get_rcu(card->vlangrp->vlan_devices[vid]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005312 if (!in_dev)
5313 goto out;
5314 for (ifa = in_dev->ifa_list; ifa; ifa = ifa->ifa_next) {
5315 addr = qeth_get_addr_buffer(QETH_PROT_IPV4);
5316 if (addr){
5317 addr->u.a4.addr = ifa->ifa_address;
5318 addr->u.a4.mask = ifa->ifa_mask;
5319 addr->type = QETH_IP_TYPE_NORMAL;
5320 if (!qeth_delete_ip(card, addr))
5321 kfree(addr);
5322 }
5323 }
5324out:
5325 rcu_read_unlock();
5326}
5327
5328static void
5329qeth_free_vlan_addresses6(struct qeth_card *card, unsigned short vid)
5330{
5331#ifdef CONFIG_QETH_IPV6
5332 struct inet6_dev *in6_dev;
5333 struct inet6_ifaddr *ifa;
5334 struct qeth_ipaddr *addr;
5335
5336 QETH_DBF_TEXT(trace, 4, "frvaddr6");
Frank Pavlic6c88ad22005-11-10 13:49:28 +01005337
Linus Torvalds1da177e2005-04-16 15:20:36 -07005338 in6_dev = in6_dev_get(card->vlangrp->vlan_devices[vid]);
5339 if (!in6_dev)
5340 return;
5341 for (ifa = in6_dev->addr_list; ifa; ifa = ifa->lst_next){
5342 addr = qeth_get_addr_buffer(QETH_PROT_IPV6);
5343 if (addr){
5344 memcpy(&addr->u.a6.addr, &ifa->addr,
5345 sizeof(struct in6_addr));
5346 addr->u.a6.pfxlen = ifa->prefix_len;
5347 addr->type = QETH_IP_TYPE_NORMAL;
5348 if (!qeth_delete_ip(card, addr))
5349 kfree(addr);
5350 }
5351 }
5352 in6_dev_put(in6_dev);
5353#endif /* CONFIG_QETH_IPV6 */
5354}
5355
Frank Pavlic6c88ad22005-11-10 13:49:28 +01005356static void
5357qeth_free_vlan_addresses(struct qeth_card *card, unsigned short vid)
5358{
5359 if (card->options.layer2 || !card->vlangrp)
5360 return;
5361 qeth_free_vlan_addresses4(card, vid);
5362 qeth_free_vlan_addresses6(card, vid);
5363}
5364
Frank Pavlic508cc2b2005-11-10 13:49:15 +01005365static int
5366qeth_layer2_send_setdelvlan_cb(struct qeth_card *card,
5367 struct qeth_reply *reply,
5368 unsigned long data)
5369{
5370 struct qeth_ipa_cmd *cmd;
5371
5372 QETH_DBF_TEXT(trace, 2, "L2sdvcb");
5373 cmd = (struct qeth_ipa_cmd *) data;
5374 if (cmd->hdr.return_code) {
5375 PRINT_ERR("Error in processing VLAN %i on %s: 0x%x. "
5376 "Continuing\n",cmd->data.setdelvlan.vlan_id,
5377 QETH_CARD_IFNAME(card), cmd->hdr.return_code);
5378 QETH_DBF_TEXT_(trace, 2, "L2VL%4x", cmd->hdr.command);
5379 QETH_DBF_TEXT_(trace, 2, "L2%s", CARD_BUS_ID(card));
5380 QETH_DBF_TEXT_(trace, 2, "err%d", cmd->hdr.return_code);
5381 }
5382 return 0;
5383}
5384
5385static int
Linus Torvalds1da177e2005-04-16 15:20:36 -07005386qeth_layer2_send_setdelvlan(struct qeth_card *card, __u16 i,
5387 enum qeth_ipa_cmds ipacmd)
5388{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005389 struct qeth_ipa_cmd *cmd;
5390 struct qeth_cmd_buffer *iob;
5391
5392 QETH_DBF_TEXT_(trace, 4, "L2sdv%x",ipacmd);
5393 iob = qeth_get_ipacmd_buffer(card, ipacmd, QETH_PROT_IPV4);
5394 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
5395 cmd->data.setdelvlan.vlan_id = i;
Frank Pavlic508cc2b2005-11-10 13:49:15 +01005396 return qeth_send_ipa_cmd(card, iob,
5397 qeth_layer2_send_setdelvlan_cb, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005398}
5399
5400static void
5401qeth_layer2_process_vlans(struct qeth_card *card, int clear)
5402{
5403 unsigned short i;
5404
5405 QETH_DBF_TEXT(trace, 3, "L2prcvln");
5406
5407 if (!card->vlangrp)
5408 return;
5409 for (i = 0; i < VLAN_GROUP_ARRAY_LEN; i++) {
5410 if (card->vlangrp->vlan_devices[i] == NULL)
5411 continue;
5412 if (clear)
5413 qeth_layer2_send_setdelvlan(card, i, IPA_CMD_DELVLAN);
5414 else
5415 qeth_layer2_send_setdelvlan(card, i, IPA_CMD_SETVLAN);
5416 }
5417}
5418
5419/*add_vid is layer 2 used only ....*/
5420static void
5421qeth_vlan_rx_add_vid(struct net_device *dev, unsigned short vid)
5422{
5423 struct qeth_card *card;
5424
5425 QETH_DBF_TEXT_(trace, 4, "aid:%d", vid);
5426
5427 card = (struct qeth_card *) dev->priv;
5428 if (!card->options.layer2)
5429 return;
5430 qeth_layer2_send_setdelvlan(card, vid, IPA_CMD_SETVLAN);
5431}
5432
5433/*... kill_vid used for both modes*/
5434static void
5435qeth_vlan_rx_kill_vid(struct net_device *dev, unsigned short vid)
5436{
5437 struct qeth_card *card;
5438 unsigned long flags;
5439
5440 QETH_DBF_TEXT_(trace, 4, "kid:%d", vid);
5441
5442 card = (struct qeth_card *) dev->priv;
5443 /* free all skbs for the vlan device */
5444 qeth_free_vlan_skbs(card, vid);
5445 spin_lock_irqsave(&card->vlanlock, flags);
5446 /* unregister IP addresses of vlan device */
Frank Pavlic6c88ad22005-11-10 13:49:28 +01005447 qeth_free_vlan_addresses(card, vid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005448 if (card->vlangrp)
5449 card->vlangrp->vlan_devices[vid] = NULL;
5450 spin_unlock_irqrestore(&card->vlanlock, flags);
5451 if (card->options.layer2)
5452 qeth_layer2_send_setdelvlan(card, vid, IPA_CMD_DELVLAN);
5453 qeth_set_multicast_list(card->dev);
5454}
5455#endif
Frank Pavlic6c951b92005-11-10 13:51:25 +01005456/**
5457 * Examine hardware response to SET_PROMISC_MODE
5458 */
5459static int
5460qeth_setadp_promisc_mode_cb(struct qeth_card *card,
5461 struct qeth_reply *reply,
5462 unsigned long data)
5463{
5464 struct qeth_ipa_cmd *cmd;
5465 struct qeth_ipacmd_setadpparms *setparms;
5466
5467 QETH_DBF_TEXT(trace,4,"prmadpcb");
5468
5469 cmd = (struct qeth_ipa_cmd *) data;
5470 setparms = &(cmd->data.setadapterparms);
5471
5472 qeth_default_setadapterparms_cb(card, reply, (unsigned long)cmd);
5473 if (cmd->hdr.return_code) {
5474 QETH_DBF_TEXT_(trace,4,"prmrc%2.2x",cmd->hdr.return_code);
5475 setparms->data.mode = SET_PROMISC_MODE_OFF;
5476 }
5477 card->info.promisc_mode = setparms->data.mode;
5478 return 0;
5479}
5480/*
5481 * Set promiscuous mode (on or off) (SET_PROMISC_MODE command)
5482 */
5483static void
5484qeth_setadp_promisc_mode(struct qeth_card *card)
5485{
5486 enum qeth_ipa_promisc_modes mode;
5487 struct net_device *dev = card->dev;
5488 struct qeth_cmd_buffer *iob;
5489 struct qeth_ipa_cmd *cmd;
5490
5491 QETH_DBF_TEXT(trace, 4, "setprom");
5492
5493 if (((dev->flags & IFF_PROMISC) &&
5494 (card->info.promisc_mode == SET_PROMISC_MODE_ON)) ||
5495 (!(dev->flags & IFF_PROMISC) &&
5496 (card->info.promisc_mode == SET_PROMISC_MODE_OFF)))
5497 return;
5498 mode = SET_PROMISC_MODE_OFF;
5499 if (dev->flags & IFF_PROMISC)
5500 mode = SET_PROMISC_MODE_ON;
5501 QETH_DBF_TEXT_(trace, 4, "mode:%x", mode);
5502
5503 iob = qeth_get_adapter_cmd(card, IPA_SETADP_SET_PROMISC_MODE,
5504 sizeof(struct qeth_ipacmd_setadpparms));
5505 cmd = (struct qeth_ipa_cmd *)(iob->data + IPA_PDU_HEADER_SIZE);
5506 cmd->data.setadapterparms.data.mode = mode;
5507 qeth_send_ipa_cmd(card, iob, qeth_setadp_promisc_mode_cb, NULL);
5508}
Linus Torvalds1da177e2005-04-16 15:20:36 -07005509
5510/**
5511 * set multicast address on card
5512 */
5513static void
5514qeth_set_multicast_list(struct net_device *dev)
5515{
5516 struct qeth_card *card = (struct qeth_card *) dev->priv;
5517
Ursula Braun500f83a2005-09-30 10:19:19 +02005518 if (card->info.type == QETH_CARD_TYPE_OSN)
5519 return ;
5520
Frank Pavlic66cc5d52006-02-07 17:04:38 +01005521 QETH_DBF_TEXT(trace, 3, "setmulti");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005522 qeth_delete_mc_addresses(card);
Frank Pavlic6c88ad22005-11-10 13:49:28 +01005523 if (card->options.layer2) {
5524 qeth_layer2_add_multicast(card);
5525 goto out;
5526 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005527 qeth_add_multicast_ipv4(card);
5528#ifdef CONFIG_QETH_IPV6
5529 qeth_add_multicast_ipv6(card);
5530#endif
Frank Pavlic6c88ad22005-11-10 13:49:28 +01005531out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07005532 if (qeth_set_thread_start_bit(card, QETH_SET_IP_THREAD) == 0)
5533 schedule_work(&card->kernel_thread_starter);
Frank Pavlic6c951b92005-11-10 13:51:25 +01005534 if (!qeth_adp_supported(card, IPA_SETADP_SET_PROMISC_MODE))
5535 return;
5536 if (qeth_set_thread_start_bit(card, QETH_SET_PROMISC_MODE_THREAD)==0)
5537 schedule_work(&card->kernel_thread_starter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005538}
5539
5540static int
5541qeth_neigh_setup(struct net_device *dev, struct neigh_parms *np)
5542{
5543 return 0;
5544}
5545
5546static void
5547qeth_get_mac_for_ipm(__u32 ipm, char *mac, struct net_device *dev)
5548{
5549 if (dev->type == ARPHRD_IEEE802_TR)
5550 ip_tr_mc_map(ipm, mac);
5551 else
5552 ip_eth_mc_map(ipm, mac);
5553}
5554
5555static struct qeth_ipaddr *
5556qeth_get_addr_buffer(enum qeth_prot_versions prot)
5557{
5558 struct qeth_ipaddr *addr;
5559
Eric Sesterhenn88abaab2006-03-24 03:15:31 -08005560 addr = kzalloc(sizeof(struct qeth_ipaddr), GFP_ATOMIC);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005561 if (addr == NULL) {
5562 PRINT_WARN("Not enough memory to add address\n");
5563 return NULL;
5564 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005565 addr->type = QETH_IP_TYPE_NORMAL;
5566 addr->proto = prot;
5567 return addr;
5568}
5569
Ursula Braun500f83a2005-09-30 10:19:19 +02005570int
5571qeth_osn_assist(struct net_device *dev,
5572 void *data,
5573 int data_len)
5574{
5575 struct qeth_cmd_buffer *iob;
5576 struct qeth_card *card;
5577 int rc;
5578
5579 QETH_DBF_TEXT(trace, 2, "osnsdmc");
5580 if (!dev)
5581 return -ENODEV;
5582 card = (struct qeth_card *)dev->priv;
5583 if (!card)
5584 return -ENODEV;
5585 if ((card->state != CARD_STATE_UP) &&
5586 (card->state != CARD_STATE_SOFTSETUP))
5587 return -ENODEV;
5588 iob = qeth_wait_for_buffer(&card->write);
5589 memcpy(iob->data+IPA_PDU_HEADER_SIZE, data, data_len);
5590 rc = qeth_osn_send_ipa_cmd(card, iob, data_len);
5591 return rc;
5592}
5593
5594static struct net_device *
5595qeth_netdev_by_devno(unsigned char *read_dev_no)
5596{
5597 struct qeth_card *card;
5598 struct net_device *ndev;
5599 unsigned char *readno;
5600 __u16 temp_dev_no, card_dev_no;
5601 char *endp;
5602 unsigned long flags;
5603
5604 ndev = NULL;
5605 memcpy(&temp_dev_no, read_dev_no, 2);
5606 read_lock_irqsave(&qeth_card_list.rwlock, flags);
5607 list_for_each_entry(card, &qeth_card_list.list, list) {
5608 readno = CARD_RDEV_ID(card);
5609 readno += (strlen(readno) - 4);
5610 card_dev_no = simple_strtoul(readno, &endp, 16);
5611 if (card_dev_no == temp_dev_no) {
5612 ndev = card->dev;
5613 break;
5614 }
5615 }
5616 read_unlock_irqrestore(&qeth_card_list.rwlock, flags);
5617 return ndev;
5618}
5619
5620int
5621qeth_osn_register(unsigned char *read_dev_no,
5622 struct net_device **dev,
5623 int (*assist_cb)(struct net_device *, void *),
5624 int (*data_cb)(struct sk_buff *))
5625{
5626 struct qeth_card * card;
5627
5628 QETH_DBF_TEXT(trace, 2, "osnreg");
5629 *dev = qeth_netdev_by_devno(read_dev_no);
5630 if (*dev == NULL)
5631 return -ENODEV;
5632 card = (struct qeth_card *)(*dev)->priv;
5633 if (!card)
5634 return -ENODEV;
5635 if ((assist_cb == NULL) || (data_cb == NULL))
5636 return -EINVAL;
5637 card->osn_info.assist_cb = assist_cb;
5638 card->osn_info.data_cb = data_cb;
5639 return 0;
5640}
5641
5642void
5643qeth_osn_deregister(struct net_device * dev)
5644{
5645 struct qeth_card *card;
5646
5647 QETH_DBF_TEXT(trace, 2, "osndereg");
5648 if (!dev)
5649 return;
5650 card = (struct qeth_card *)dev->priv;
5651 if (!card)
5652 return;
5653 card->osn_info.assist_cb = NULL;
5654 card->osn_info.data_cb = NULL;
5655 return;
5656}
5657
Linus Torvalds1da177e2005-04-16 15:20:36 -07005658static void
5659qeth_delete_mc_addresses(struct qeth_card *card)
5660{
5661 struct qeth_ipaddr *iptodo;
5662 unsigned long flags;
5663
5664 QETH_DBF_TEXT(trace,4,"delmc");
5665 iptodo = qeth_get_addr_buffer(QETH_PROT_IPV4);
5666 if (!iptodo) {
5667 QETH_DBF_TEXT(trace, 2, "dmcnomem");
5668 return;
5669 }
5670 iptodo->type = QETH_IP_TYPE_DEL_ALL_MC;
5671 spin_lock_irqsave(&card->ip_lock, flags);
5672 if (!__qeth_insert_ip_todo(card, iptodo, 0))
5673 kfree(iptodo);
5674 spin_unlock_irqrestore(&card->ip_lock, flags);
5675}
5676
5677static inline void
5678qeth_add_mc(struct qeth_card *card, struct in_device *in4_dev)
5679{
5680 struct qeth_ipaddr *ipm;
5681 struct ip_mc_list *im4;
5682 char buf[MAX_ADDR_LEN];
5683
5684 QETH_DBF_TEXT(trace,4,"addmc");
5685 for (im4 = in4_dev->mc_list; im4; im4 = im4->next) {
5686 qeth_get_mac_for_ipm(im4->multiaddr, buf, in4_dev->dev);
5687 ipm = qeth_get_addr_buffer(QETH_PROT_IPV4);
5688 if (!ipm)
5689 continue;
5690 ipm->u.a4.addr = im4->multiaddr;
5691 memcpy(ipm->mac,buf,OSA_ADDR_LEN);
5692 ipm->is_multicast = 1;
5693 if (!qeth_add_ip(card,ipm))
5694 kfree(ipm);
5695 }
5696}
5697
5698static inline void
5699qeth_add_vlan_mc(struct qeth_card *card)
5700{
5701#ifdef CONFIG_QETH_VLAN
5702 struct in_device *in_dev;
5703 struct vlan_group *vg;
5704 int i;
5705
5706 QETH_DBF_TEXT(trace,4,"addmcvl");
5707 if ( ((card->options.layer2 == 0) &&
5708 (!qeth_is_supported(card,IPA_FULL_VLAN))) ||
5709 (card->vlangrp == NULL) )
5710 return ;
5711
5712 vg = card->vlangrp;
5713 for (i = 0; i < VLAN_GROUP_ARRAY_LEN; i++) {
5714 if (vg->vlan_devices[i] == NULL ||
5715 !(vg->vlan_devices[i]->flags & IFF_UP))
5716 continue;
5717 in_dev = in_dev_get(vg->vlan_devices[i]);
5718 if (!in_dev)
5719 continue;
5720 read_lock(&in_dev->mc_list_lock);
5721 qeth_add_mc(card,in_dev);
5722 read_unlock(&in_dev->mc_list_lock);
5723 in_dev_put(in_dev);
5724 }
5725#endif
5726}
5727
5728static void
5729qeth_add_multicast_ipv4(struct qeth_card *card)
5730{
5731 struct in_device *in4_dev;
5732
5733 QETH_DBF_TEXT(trace,4,"chkmcv4");
5734 in4_dev = in_dev_get(card->dev);
5735 if (in4_dev == NULL)
5736 return;
5737 read_lock(&in4_dev->mc_list_lock);
5738 qeth_add_mc(card, in4_dev);
5739 qeth_add_vlan_mc(card);
5740 read_unlock(&in4_dev->mc_list_lock);
5741 in_dev_put(in4_dev);
5742}
5743
Frank Pavlic6c88ad22005-11-10 13:49:28 +01005744static void
5745qeth_layer2_add_multicast(struct qeth_card *card)
5746{
5747 struct qeth_ipaddr *ipm;
5748 struct dev_mc_list *dm;
5749
5750 QETH_DBF_TEXT(trace,4,"L2addmc");
5751 for (dm = card->dev->mc_list; dm; dm = dm->next) {
5752 ipm = qeth_get_addr_buffer(QETH_PROT_IPV4);
5753 if (!ipm)
5754 continue;
5755 memcpy(ipm->mac,dm->dmi_addr,MAX_ADDR_LEN);
5756 ipm->is_multicast = 1;
5757 if (!qeth_add_ip(card, ipm))
5758 kfree(ipm);
5759 }
5760}
5761
Linus Torvalds1da177e2005-04-16 15:20:36 -07005762#ifdef CONFIG_QETH_IPV6
5763static inline void
5764qeth_add_mc6(struct qeth_card *card, struct inet6_dev *in6_dev)
5765{
5766 struct qeth_ipaddr *ipm;
5767 struct ifmcaddr6 *im6;
5768 char buf[MAX_ADDR_LEN];
5769
5770 QETH_DBF_TEXT(trace,4,"addmc6");
5771 for (im6 = in6_dev->mc_list; im6 != NULL; im6 = im6->next) {
5772 ndisc_mc_map(&im6->mca_addr, buf, in6_dev->dev, 0);
5773 ipm = qeth_get_addr_buffer(QETH_PROT_IPV6);
5774 if (!ipm)
5775 continue;
5776 ipm->is_multicast = 1;
5777 memcpy(ipm->mac,buf,OSA_ADDR_LEN);
5778 memcpy(&ipm->u.a6.addr,&im6->mca_addr.s6_addr,
5779 sizeof(struct in6_addr));
5780 if (!qeth_add_ip(card,ipm))
5781 kfree(ipm);
5782 }
5783}
5784
5785static inline void
5786qeth_add_vlan_mc6(struct qeth_card *card)
5787{
5788#ifdef CONFIG_QETH_VLAN
5789 struct inet6_dev *in_dev;
5790 struct vlan_group *vg;
5791 int i;
5792
5793 QETH_DBF_TEXT(trace,4,"admc6vl");
5794 if ( ((card->options.layer2 == 0) &&
5795 (!qeth_is_supported(card,IPA_FULL_VLAN))) ||
5796 (card->vlangrp == NULL))
5797 return ;
5798
5799 vg = card->vlangrp;
5800 for (i = 0; i < VLAN_GROUP_ARRAY_LEN; i++) {
5801 if (vg->vlan_devices[i] == NULL ||
5802 !(vg->vlan_devices[i]->flags & IFF_UP))
5803 continue;
5804 in_dev = in6_dev_get(vg->vlan_devices[i]);
5805 if (!in_dev)
5806 continue;
5807 read_lock(&in_dev->lock);
5808 qeth_add_mc6(card,in_dev);
5809 read_unlock(&in_dev->lock);
5810 in6_dev_put(in_dev);
5811 }
5812#endif /* CONFIG_QETH_VLAN */
5813}
5814
5815static void
5816qeth_add_multicast_ipv6(struct qeth_card *card)
5817{
5818 struct inet6_dev *in6_dev;
5819
5820 QETH_DBF_TEXT(trace,4,"chkmcv6");
Frank Pavlic6c6b3e72005-12-13 08:21:47 +01005821 if (!qeth_is_supported(card, IPA_IPV6))
Linus Torvalds1da177e2005-04-16 15:20:36 -07005822 return ;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005823 in6_dev = in6_dev_get(card->dev);
5824 if (in6_dev == NULL)
5825 return;
5826 read_lock(&in6_dev->lock);
5827 qeth_add_mc6(card, in6_dev);
5828 qeth_add_vlan_mc6(card);
5829 read_unlock(&in6_dev->lock);
5830 in6_dev_put(in6_dev);
5831}
5832#endif /* CONFIG_QETH_IPV6 */
5833
5834static int
5835qeth_layer2_send_setdelmac(struct qeth_card *card, __u8 *mac,
5836 enum qeth_ipa_cmds ipacmd,
5837 int (*reply_cb) (struct qeth_card *,
5838 struct qeth_reply*,
5839 unsigned long))
5840{
5841 struct qeth_ipa_cmd *cmd;
5842 struct qeth_cmd_buffer *iob;
5843
5844 QETH_DBF_TEXT(trace, 2, "L2sdmac");
5845 iob = qeth_get_ipacmd_buffer(card, ipacmd, QETH_PROT_IPV4);
5846 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
5847 cmd->data.setdelmac.mac_length = OSA_ADDR_LEN;
5848 memcpy(&cmd->data.setdelmac.mac, mac, OSA_ADDR_LEN);
5849 return qeth_send_ipa_cmd(card, iob, reply_cb, NULL);
5850}
5851
5852static int
5853qeth_layer2_send_setgroupmac_cb(struct qeth_card *card,
5854 struct qeth_reply *reply,
5855 unsigned long data)
5856{
5857 struct qeth_ipa_cmd *cmd;
5858 __u8 *mac;
5859
5860 QETH_DBF_TEXT(trace, 2, "L2Sgmacb");
5861 cmd = (struct qeth_ipa_cmd *) data;
5862 mac = &cmd->data.setdelmac.mac[0];
5863 /* MAC already registered, needed in couple/uncouple case */
5864 if (cmd->hdr.return_code == 0x2005) {
5865 PRINT_WARN("Group MAC %02x:%02x:%02x:%02x:%02x:%02x " \
5866 "already existing on %s \n",
5867 mac[0], mac[1], mac[2], mac[3], mac[4], mac[5],
5868 QETH_CARD_IFNAME(card));
5869 cmd->hdr.return_code = 0;
5870 }
5871 if (cmd->hdr.return_code)
5872 PRINT_ERR("Could not set group MAC " \
5873 "%02x:%02x:%02x:%02x:%02x:%02x on %s: %x\n",
5874 mac[0], mac[1], mac[2], mac[3], mac[4], mac[5],
5875 QETH_CARD_IFNAME(card),cmd->hdr.return_code);
5876 return 0;
5877}
5878
5879static int
5880qeth_layer2_send_setgroupmac(struct qeth_card *card, __u8 *mac)
5881{
5882 QETH_DBF_TEXT(trace, 2, "L2Sgmac");
5883 return qeth_layer2_send_setdelmac(card, mac, IPA_CMD_SETGMAC,
5884 qeth_layer2_send_setgroupmac_cb);
5885}
5886
5887static int
5888qeth_layer2_send_delgroupmac_cb(struct qeth_card *card,
5889 struct qeth_reply *reply,
5890 unsigned long data)
5891{
5892 struct qeth_ipa_cmd *cmd;
5893 __u8 *mac;
5894
5895 QETH_DBF_TEXT(trace, 2, "L2Dgmacb");
5896 cmd = (struct qeth_ipa_cmd *) data;
5897 mac = &cmd->data.setdelmac.mac[0];
5898 if (cmd->hdr.return_code)
5899 PRINT_ERR("Could not delete group MAC " \
5900 "%02x:%02x:%02x:%02x:%02x:%02x on %s: %x\n",
5901 mac[0], mac[1], mac[2], mac[3], mac[4], mac[5],
5902 QETH_CARD_IFNAME(card), cmd->hdr.return_code);
5903 return 0;
5904}
5905
5906static int
5907qeth_layer2_send_delgroupmac(struct qeth_card *card, __u8 *mac)
5908{
5909 QETH_DBF_TEXT(trace, 2, "L2Dgmac");
5910 return qeth_layer2_send_setdelmac(card, mac, IPA_CMD_DELGMAC,
5911 qeth_layer2_send_delgroupmac_cb);
5912}
5913
5914static int
5915qeth_layer2_send_setmac_cb(struct qeth_card *card,
5916 struct qeth_reply *reply,
5917 unsigned long data)
5918{
5919 struct qeth_ipa_cmd *cmd;
5920
5921 QETH_DBF_TEXT(trace, 2, "L2Smaccb");
5922 cmd = (struct qeth_ipa_cmd *) data;
5923 if (cmd->hdr.return_code) {
5924 QETH_DBF_TEXT_(trace, 2, "L2er%x", cmd->hdr.return_code);
5925 PRINT_WARN("Error in registering MAC address on " \
5926 "device %s: x%x\n", CARD_BUS_ID(card),
5927 cmd->hdr.return_code);
Frank Pavlice08d88c2005-11-10 13:51:17 +01005928 card->info.mac_bits &= ~QETH_LAYER2_MAC_REGISTERED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005929 cmd->hdr.return_code = -EIO;
5930 } else {
Frank Pavlice08d88c2005-11-10 13:51:17 +01005931 card->info.mac_bits |= QETH_LAYER2_MAC_REGISTERED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005932 memcpy(card->dev->dev_addr,cmd->data.setdelmac.mac,
5933 OSA_ADDR_LEN);
5934 PRINT_INFO("MAC address %2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x "
5935 "successfully registered on device %s\n",
5936 card->dev->dev_addr[0], card->dev->dev_addr[1],
5937 card->dev->dev_addr[2], card->dev->dev_addr[3],
5938 card->dev->dev_addr[4], card->dev->dev_addr[5],
5939 card->dev->name);
5940 }
5941 return 0;
5942}
5943
5944static int
5945qeth_layer2_send_setmac(struct qeth_card *card, __u8 *mac)
5946{
5947 QETH_DBF_TEXT(trace, 2, "L2Setmac");
5948 return qeth_layer2_send_setdelmac(card, mac, IPA_CMD_SETVMAC,
5949 qeth_layer2_send_setmac_cb);
5950}
5951
5952static int
5953qeth_layer2_send_delmac_cb(struct qeth_card *card,
5954 struct qeth_reply *reply,
5955 unsigned long data)
5956{
5957 struct qeth_ipa_cmd *cmd;
5958
5959 QETH_DBF_TEXT(trace, 2, "L2Dmaccb");
5960 cmd = (struct qeth_ipa_cmd *) data;
5961 if (cmd->hdr.return_code) {
5962 PRINT_WARN("Error in deregistering MAC address on " \
5963 "device %s: x%x\n", CARD_BUS_ID(card),
5964 cmd->hdr.return_code);
5965 QETH_DBF_TEXT_(trace, 2, "err%d", cmd->hdr.return_code);
5966 cmd->hdr.return_code = -EIO;
5967 return 0;
5968 }
Frank Pavlice08d88c2005-11-10 13:51:17 +01005969 card->info.mac_bits &= ~QETH_LAYER2_MAC_REGISTERED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005970
5971 return 0;
5972}
5973static int
5974qeth_layer2_send_delmac(struct qeth_card *card, __u8 *mac)
5975{
5976 QETH_DBF_TEXT(trace, 2, "L2Delmac");
Frank Pavlice08d88c2005-11-10 13:51:17 +01005977 if (!(card->info.mac_bits & QETH_LAYER2_MAC_REGISTERED))
Linus Torvalds1da177e2005-04-16 15:20:36 -07005978 return 0;
5979 return qeth_layer2_send_setdelmac(card, mac, IPA_CMD_DELVMAC,
5980 qeth_layer2_send_delmac_cb);
5981}
5982
5983static int
5984qeth_layer2_set_mac_address(struct net_device *dev, void *p)
5985{
5986 struct sockaddr *addr = p;
5987 struct qeth_card *card;
5988 int rc = 0;
5989
5990 QETH_DBF_TEXT(trace, 3, "setmac");
5991
5992 if (qeth_verify_dev(dev) != QETH_REAL_CARD) {
5993 QETH_DBF_TEXT(trace, 3, "setmcINV");
5994 return -EOPNOTSUPP;
5995 }
5996 card = (struct qeth_card *) dev->priv;
5997
5998 if (!card->options.layer2) {
Frank Pavlice08d88c2005-11-10 13:51:17 +01005999 PRINT_WARN("Setting MAC address on %s is not supported "
Linus Torvalds1da177e2005-04-16 15:20:36 -07006000 "in Layer 3 mode.\n", dev->name);
6001 QETH_DBF_TEXT(trace, 3, "setmcLY3");
6002 return -EOPNOTSUPP;
6003 }
Ursula Braun500f83a2005-09-30 10:19:19 +02006004 if (card->info.type == QETH_CARD_TYPE_OSN) {
6005 PRINT_WARN("Setting MAC address on %s is not supported.\n",
6006 dev->name);
6007 QETH_DBF_TEXT(trace, 3, "setmcOSN");
6008 return -EOPNOTSUPP;
6009 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07006010 QETH_DBF_TEXT_(trace, 3, "%s", CARD_BUS_ID(card));
6011 QETH_DBF_HEX(trace, 3, addr->sa_data, OSA_ADDR_LEN);
6012 rc = qeth_layer2_send_delmac(card, &card->dev->dev_addr[0]);
6013 if (!rc)
6014 rc = qeth_layer2_send_setmac(card, addr->sa_data);
6015 return rc;
6016}
6017
6018static void
6019qeth_fill_ipacmd_header(struct qeth_card *card, struct qeth_ipa_cmd *cmd,
6020 __u8 command, enum qeth_prot_versions prot)
6021{
6022 memset(cmd, 0, sizeof (struct qeth_ipa_cmd));
6023 cmd->hdr.command = command;
6024 cmd->hdr.initiator = IPA_CMD_INITIATOR_HOST;
6025 cmd->hdr.seqno = card->seqno.ipa;
6026 cmd->hdr.adapter_type = qeth_get_ipa_adp_type(card->info.link_type);
6027 cmd->hdr.rel_adapter_no = (__u8) card->info.portno;
6028 if (card->options.layer2)
6029 cmd->hdr.prim_version_no = 2;
6030 else
6031 cmd->hdr.prim_version_no = 1;
6032 cmd->hdr.param_count = 1;
6033 cmd->hdr.prot_version = prot;
6034 cmd->hdr.ipa_supported = 0;
6035 cmd->hdr.ipa_enabled = 0;
6036}
6037
6038static struct qeth_cmd_buffer *
6039qeth_get_ipacmd_buffer(struct qeth_card *card, enum qeth_ipa_cmds ipacmd,
6040 enum qeth_prot_versions prot)
6041{
6042 struct qeth_cmd_buffer *iob;
6043 struct qeth_ipa_cmd *cmd;
6044
6045 iob = qeth_wait_for_buffer(&card->write);
6046 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
6047 qeth_fill_ipacmd_header(card, cmd, ipacmd, prot);
6048
6049 return iob;
6050}
6051
6052static int
6053qeth_send_setdelmc(struct qeth_card *card, struct qeth_ipaddr *addr, int ipacmd)
6054{
6055 int rc;
6056 struct qeth_cmd_buffer *iob;
6057 struct qeth_ipa_cmd *cmd;
6058
6059 QETH_DBF_TEXT(trace,4,"setdelmc");
6060
6061 iob = qeth_get_ipacmd_buffer(card, ipacmd, addr->proto);
6062 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
6063 memcpy(&cmd->data.setdelipm.mac,addr->mac, OSA_ADDR_LEN);
6064 if (addr->proto == QETH_PROT_IPV6)
6065 memcpy(cmd->data.setdelipm.ip6, &addr->u.a6.addr,
6066 sizeof(struct in6_addr));
6067 else
6068 memcpy(&cmd->data.setdelipm.ip4, &addr->u.a4.addr,4);
6069
6070 rc = qeth_send_ipa_cmd(card, iob, NULL, NULL);
6071
6072 return rc;
6073}
6074static inline void
6075qeth_fill_netmask(u8 *netmask, unsigned int len)
6076{
6077 int i,j;
6078 for (i=0;i<16;i++) {
6079 j=(len)-(i*8);
6080 if (j >= 8)
6081 netmask[i] = 0xff;
6082 else if (j > 0)
6083 netmask[i] = (u8)(0xFF00>>j);
6084 else
6085 netmask[i] = 0;
6086 }
6087}
6088
6089static int
6090qeth_send_setdelip(struct qeth_card *card, struct qeth_ipaddr *addr,
6091 int ipacmd, unsigned int flags)
6092{
6093 int rc;
6094 struct qeth_cmd_buffer *iob;
6095 struct qeth_ipa_cmd *cmd;
6096 __u8 netmask[16];
6097
6098 QETH_DBF_TEXT(trace,4,"setdelip");
6099 QETH_DBF_TEXT_(trace,4,"flags%02X", flags);
6100
6101 iob = qeth_get_ipacmd_buffer(card, ipacmd, addr->proto);
6102 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
6103 if (addr->proto == QETH_PROT_IPV6) {
6104 memcpy(cmd->data.setdelip6.ip_addr, &addr->u.a6.addr,
6105 sizeof(struct in6_addr));
6106 qeth_fill_netmask(netmask,addr->u.a6.pfxlen);
6107 memcpy(cmd->data.setdelip6.mask, netmask,
6108 sizeof(struct in6_addr));
6109 cmd->data.setdelip6.flags = flags;
6110 } else {
6111 memcpy(cmd->data.setdelip4.ip_addr, &addr->u.a4.addr, 4);
6112 memcpy(cmd->data.setdelip4.mask, &addr->u.a4.mask, 4);
6113 cmd->data.setdelip4.flags = flags;
6114 }
6115
6116 rc = qeth_send_ipa_cmd(card, iob, NULL, NULL);
6117
6118 return rc;
6119}
6120
6121static int
6122qeth_layer2_register_addr_entry(struct qeth_card *card,
6123 struct qeth_ipaddr *addr)
6124{
6125 if (!addr->is_multicast)
6126 return 0;
6127 QETH_DBF_TEXT(trace, 2, "setgmac");
6128 QETH_DBF_HEX(trace,3,&addr->mac[0],OSA_ADDR_LEN);
6129 return qeth_layer2_send_setgroupmac(card, &addr->mac[0]);
6130}
6131
6132static int
6133qeth_layer2_deregister_addr_entry(struct qeth_card *card,
6134 struct qeth_ipaddr *addr)
6135{
6136 if (!addr->is_multicast)
6137 return 0;
6138 QETH_DBF_TEXT(trace, 2, "delgmac");
6139 QETH_DBF_HEX(trace,3,&addr->mac[0],OSA_ADDR_LEN);
6140 return qeth_layer2_send_delgroupmac(card, &addr->mac[0]);
6141}
6142
6143static int
6144qeth_layer3_register_addr_entry(struct qeth_card *card,
6145 struct qeth_ipaddr *addr)
6146{
6147 char buf[50];
6148 int rc;
6149 int cnt = 3;
6150
6151 if (addr->proto == QETH_PROT_IPV4) {
6152 QETH_DBF_TEXT(trace, 2,"setaddr4");
6153 QETH_DBF_HEX(trace, 3, &addr->u.a4.addr, sizeof(int));
6154 } else if (addr->proto == QETH_PROT_IPV6) {
6155 QETH_DBF_TEXT(trace, 2, "setaddr6");
6156 QETH_DBF_HEX(trace,3,&addr->u.a6.addr,8);
6157 QETH_DBF_HEX(trace,3,((char *)&addr->u.a6.addr)+8,8);
6158 } else {
6159 QETH_DBF_TEXT(trace, 2, "setaddr?");
6160 QETH_DBF_HEX(trace, 3, addr, sizeof(struct qeth_ipaddr));
6161 }
6162 do {
6163 if (addr->is_multicast)
6164 rc = qeth_send_setdelmc(card, addr, IPA_CMD_SETIPM);
6165 else
6166 rc = qeth_send_setdelip(card, addr, IPA_CMD_SETIP,
6167 addr->set_flags);
6168 if (rc)
6169 QETH_DBF_TEXT(trace, 2, "failed");
6170 } while ((--cnt > 0) && rc);
6171 if (rc){
6172 QETH_DBF_TEXT(trace, 2, "FAILED");
6173 qeth_ipaddr_to_string(addr->proto, (u8 *)&addr->u, buf);
6174 PRINT_WARN("Could not register IP address %s (rc=0x%x/%d)\n",
6175 buf, rc, rc);
6176 }
6177 return rc;
6178}
6179
6180static int
6181qeth_layer3_deregister_addr_entry(struct qeth_card *card,
6182 struct qeth_ipaddr *addr)
6183{
6184 //char buf[50];
6185 int rc;
6186
6187 if (addr->proto == QETH_PROT_IPV4) {
6188 QETH_DBF_TEXT(trace, 2,"deladdr4");
6189 QETH_DBF_HEX(trace, 3, &addr->u.a4.addr, sizeof(int));
6190 } else if (addr->proto == QETH_PROT_IPV6) {
6191 QETH_DBF_TEXT(trace, 2, "deladdr6");
6192 QETH_DBF_HEX(trace,3,&addr->u.a6.addr,8);
6193 QETH_DBF_HEX(trace,3,((char *)&addr->u.a6.addr)+8,8);
6194 } else {
6195 QETH_DBF_TEXT(trace, 2, "deladdr?");
6196 QETH_DBF_HEX(trace, 3, addr, sizeof(struct qeth_ipaddr));
6197 }
6198 if (addr->is_multicast)
6199 rc = qeth_send_setdelmc(card, addr, IPA_CMD_DELIPM);
6200 else
6201 rc = qeth_send_setdelip(card, addr, IPA_CMD_DELIP,
6202 addr->del_flags);
6203 if (rc) {
6204 QETH_DBF_TEXT(trace, 2, "failed");
6205 /* TODO: re-activate this warning as soon as we have a
6206 * clean mirco code
6207 qeth_ipaddr_to_string(addr->proto, (u8 *)&addr->u, buf);
6208 PRINT_WARN("Could not deregister IP address %s (rc=%x)\n",
6209 buf, rc);
6210 */
6211 }
6212 return rc;
6213}
6214
6215static int
6216qeth_register_addr_entry(struct qeth_card *card, struct qeth_ipaddr *addr)
6217{
6218 if (card->options.layer2)
6219 return qeth_layer2_register_addr_entry(card, addr);
6220
6221 return qeth_layer3_register_addr_entry(card, addr);
6222}
6223
6224static int
6225qeth_deregister_addr_entry(struct qeth_card *card, struct qeth_ipaddr *addr)
6226{
6227 if (card->options.layer2)
6228 return qeth_layer2_deregister_addr_entry(card, addr);
6229
6230 return qeth_layer3_deregister_addr_entry(card, addr);
6231}
6232
6233static u32
6234qeth_ethtool_get_tx_csum(struct net_device *dev)
6235{
6236 /* We may need to say that we support tx csum offload if
6237 * we do EDDP or TSO. There are discussions going on to
6238 * enforce rules in the stack and in ethtool that make
6239 * SG and TSO depend on HW_CSUM. At the moment there are
6240 * no such rules....
6241 * If we say yes here, we have to checksum outbound packets
6242 * any time. */
6243 return 0;
6244}
6245
6246static int
6247qeth_ethtool_set_tx_csum(struct net_device *dev, u32 data)
6248{
6249 return -EINVAL;
6250}
6251
6252static u32
6253qeth_ethtool_get_rx_csum(struct net_device *dev)
6254{
6255 struct qeth_card *card = (struct qeth_card *)dev->priv;
6256
6257 return (card->options.checksum_type == HW_CHECKSUMMING);
6258}
6259
6260static int
6261qeth_ethtool_set_rx_csum(struct net_device *dev, u32 data)
6262{
6263 struct qeth_card *card = (struct qeth_card *)dev->priv;
6264
6265 if ((card->state != CARD_STATE_DOWN) &&
6266 (card->state != CARD_STATE_RECOVER))
6267 return -EPERM;
6268 if (data)
6269 card->options.checksum_type = HW_CHECKSUMMING;
6270 else
6271 card->options.checksum_type = SW_CHECKSUMMING;
6272 return 0;
6273}
6274
6275static u32
6276qeth_ethtool_get_sg(struct net_device *dev)
6277{
6278 struct qeth_card *card = (struct qeth_card *)dev->priv;
6279
6280 return ((card->options.large_send != QETH_LARGE_SEND_NO) &&
6281 (dev->features & NETIF_F_SG));
6282}
6283
6284static int
6285qeth_ethtool_set_sg(struct net_device *dev, u32 data)
6286{
6287 struct qeth_card *card = (struct qeth_card *)dev->priv;
6288
6289 if (data) {
6290 if (card->options.large_send != QETH_LARGE_SEND_NO)
6291 dev->features |= NETIF_F_SG;
6292 else {
6293 dev->features &= ~NETIF_F_SG;
6294 return -EINVAL;
6295 }
6296 } else
6297 dev->features &= ~NETIF_F_SG;
6298 return 0;
6299}
6300
6301static u32
6302qeth_ethtool_get_tso(struct net_device *dev)
6303{
6304 struct qeth_card *card = (struct qeth_card *)dev->priv;
6305
6306 return ((card->options.large_send != QETH_LARGE_SEND_NO) &&
6307 (dev->features & NETIF_F_TSO));
6308}
6309
6310static int
6311qeth_ethtool_set_tso(struct net_device *dev, u32 data)
6312{
6313 struct qeth_card *card = (struct qeth_card *)dev->priv;
6314
6315 if (data) {
6316 if (card->options.large_send != QETH_LARGE_SEND_NO)
6317 dev->features |= NETIF_F_TSO;
6318 else {
6319 dev->features &= ~NETIF_F_TSO;
6320 return -EINVAL;
6321 }
6322 } else
6323 dev->features &= ~NETIF_F_TSO;
6324 return 0;
6325}
6326
6327static struct ethtool_ops qeth_ethtool_ops = {
6328 .get_tx_csum = qeth_ethtool_get_tx_csum,
6329 .set_tx_csum = qeth_ethtool_set_tx_csum,
6330 .get_rx_csum = qeth_ethtool_get_rx_csum,
6331 .set_rx_csum = qeth_ethtool_set_rx_csum,
6332 .get_sg = qeth_ethtool_get_sg,
6333 .set_sg = qeth_ethtool_set_sg,
6334 .get_tso = qeth_ethtool_get_tso,
6335 .set_tso = qeth_ethtool_set_tso,
6336};
6337
6338static int
6339qeth_netdev_init(struct net_device *dev)
6340{
6341 struct qeth_card *card;
6342
6343 card = (struct qeth_card *) dev->priv;
6344
6345 QETH_DBF_TEXT(trace,3,"initdev");
6346
6347 dev->tx_timeout = &qeth_tx_timeout;
6348 dev->watchdog_timeo = QETH_TX_TIMEOUT;
6349 dev->open = qeth_open;
6350 dev->stop = qeth_stop;
6351 dev->hard_start_xmit = qeth_hard_start_xmit;
6352 dev->do_ioctl = qeth_do_ioctl;
6353 dev->get_stats = qeth_get_stats;
6354 dev->change_mtu = qeth_change_mtu;
6355 dev->neigh_setup = qeth_neigh_setup;
6356 dev->set_multicast_list = qeth_set_multicast_list;
6357#ifdef CONFIG_QETH_VLAN
6358 dev->vlan_rx_register = qeth_vlan_rx_register;
6359 dev->vlan_rx_kill_vid = qeth_vlan_rx_kill_vid;
6360 dev->vlan_rx_add_vid = qeth_vlan_rx_add_vid;
6361#endif
6362 dev->hard_header = card->orig_hard_header;
6363 if (qeth_get_netdev_flags(card) & IFF_NOARP) {
6364 dev->rebuild_header = NULL;
6365 dev->hard_header = NULL;
6366 if (card->options.fake_ll)
6367 dev->hard_header = qeth_fake_header;
6368 dev->header_cache_update = NULL;
6369 dev->hard_header_cache = NULL;
6370 }
6371#ifdef CONFIG_QETH_IPV6
6372 /*IPv6 address autoconfiguration stuff*/
6373 if (!(card->info.unique_id & UNIQUE_ID_NOT_BY_CARD))
6374 card->dev->dev_id = card->info.unique_id & 0xffff;
6375#endif
6376 dev->hard_header_parse = NULL;
6377 dev->set_mac_address = qeth_layer2_set_mac_address;
6378 dev->flags |= qeth_get_netdev_flags(card);
6379 if ((card->options.fake_broadcast) ||
6380 (card->info.broadcast_capable))
6381 dev->flags |= IFF_BROADCAST;
6382 dev->hard_header_len =
6383 qeth_get_hlen(card->info.link_type) + card->options.add_hhlen;
6384 dev->addr_len = OSA_ADDR_LEN;
6385 dev->mtu = card->info.initial_mtu;
Ursula Braun500f83a2005-09-30 10:19:19 +02006386 if (card->info.type != QETH_CARD_TYPE_OSN)
6387 SET_ETHTOOL_OPS(dev, &qeth_ethtool_ops);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006388 SET_MODULE_OWNER(dev);
6389 return 0;
6390}
6391
6392static void
6393qeth_init_func_level(struct qeth_card *card)
6394{
6395 if (card->ipato.enabled) {
6396 if (card->info.type == QETH_CARD_TYPE_IQD)
6397 card->info.func_level =
6398 QETH_IDX_FUNC_LEVEL_IQD_ENA_IPAT;
6399 else
6400 card->info.func_level =
6401 QETH_IDX_FUNC_LEVEL_OSAE_ENA_IPAT;
6402 } else {
6403 if (card->info.type == QETH_CARD_TYPE_IQD)
Ursula Braun500f83a2005-09-30 10:19:19 +02006404 /*FIXME:why do we have same values for dis and ena for osae??? */
Linus Torvalds1da177e2005-04-16 15:20:36 -07006405 card->info.func_level =
6406 QETH_IDX_FUNC_LEVEL_IQD_DIS_IPAT;
6407 else
6408 card->info.func_level =
6409 QETH_IDX_FUNC_LEVEL_OSAE_DIS_IPAT;
6410 }
6411}
6412
6413/**
6414 * hardsetup card, initialize MPC and QDIO stuff
6415 */
6416static int
6417qeth_hardsetup_card(struct qeth_card *card)
6418{
6419 int retries = 3;
6420 int rc;
6421
6422 QETH_DBF_TEXT(setup, 2, "hrdsetup");
6423
6424retry:
6425 if (retries < 3){
6426 PRINT_WARN("Retrying to do IDX activates.\n");
6427 ccw_device_set_offline(CARD_DDEV(card));
6428 ccw_device_set_offline(CARD_WDEV(card));
6429 ccw_device_set_offline(CARD_RDEV(card));
6430 ccw_device_set_online(CARD_RDEV(card));
6431 ccw_device_set_online(CARD_WDEV(card));
6432 ccw_device_set_online(CARD_DDEV(card));
6433 }
Ursula Braun500f83a2005-09-30 10:19:19 +02006434 rc = qeth_qdio_clear_card(card,card->info.type!=QETH_CARD_TYPE_IQD);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006435 if (rc == -ERESTARTSYS) {
6436 QETH_DBF_TEXT(setup, 2, "break1");
6437 return rc;
6438 } else if (rc) {
6439 QETH_DBF_TEXT_(setup, 2, "1err%d", rc);
6440 if (--retries < 0)
6441 goto out;
6442 else
6443 goto retry;
6444 }
6445 if ((rc = qeth_get_unitaddr(card))){
6446 QETH_DBF_TEXT_(setup, 2, "2err%d", rc);
6447 return rc;
6448 }
6449 qeth_init_tokens(card);
6450 qeth_init_func_level(card);
6451 rc = qeth_idx_activate_channel(&card->read, qeth_idx_read_cb);
6452 if (rc == -ERESTARTSYS) {
6453 QETH_DBF_TEXT(setup, 2, "break2");
6454 return rc;
6455 } else if (rc) {
6456 QETH_DBF_TEXT_(setup, 2, "3err%d", rc);
6457 if (--retries < 0)
6458 goto out;
6459 else
6460 goto retry;
6461 }
6462 rc = qeth_idx_activate_channel(&card->write, qeth_idx_write_cb);
6463 if (rc == -ERESTARTSYS) {
6464 QETH_DBF_TEXT(setup, 2, "break3");
6465 return rc;
6466 } else if (rc) {
6467 QETH_DBF_TEXT_(setup, 2, "4err%d", rc);
6468 if (--retries < 0)
6469 goto out;
6470 else
6471 goto retry;
6472 }
6473 if ((rc = qeth_mpc_initialize(card))){
6474 QETH_DBF_TEXT_(setup, 2, "5err%d", rc);
6475 goto out;
6476 }
6477 /*network device will be recovered*/
6478 if (card->dev) {
6479 card->dev->hard_header = card->orig_hard_header;
6480 return 0;
6481 }
6482 /* at first set_online allocate netdev */
6483 card->dev = qeth_get_netdevice(card->info.type,
6484 card->info.link_type);
6485 if (!card->dev){
Ursula Braun500f83a2005-09-30 10:19:19 +02006486 qeth_qdio_clear_card(card, card->info.type !=
6487 QETH_CARD_TYPE_IQD);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006488 rc = -ENODEV;
6489 QETH_DBF_TEXT_(setup, 2, "6err%d", rc);
6490 goto out;
6491 }
6492 card->dev->priv = card;
6493 card->orig_hard_header = card->dev->hard_header;
6494 card->dev->type = qeth_get_arphdr_type(card->info.type,
6495 card->info.link_type);
6496 card->dev->init = qeth_netdev_init;
6497 return 0;
6498out:
6499 PRINT_ERR("Initialization in hardsetup failed! rc=%d\n", rc);
6500 return rc;
6501}
6502
6503static int
6504qeth_default_setassparms_cb(struct qeth_card *card, struct qeth_reply *reply,
6505 unsigned long data)
6506{
6507 struct qeth_ipa_cmd *cmd;
6508
6509 QETH_DBF_TEXT(trace,4,"defadpcb");
6510
6511 cmd = (struct qeth_ipa_cmd *) data;
6512 if (cmd->hdr.return_code == 0){
6513 cmd->hdr.return_code = cmd->data.setassparms.hdr.return_code;
6514 if (cmd->hdr.prot_version == QETH_PROT_IPV4)
6515 card->options.ipa4.enabled_funcs = cmd->hdr.ipa_enabled;
6516#ifdef CONFIG_QETH_IPV6
6517 if (cmd->hdr.prot_version == QETH_PROT_IPV6)
6518 card->options.ipa6.enabled_funcs = cmd->hdr.ipa_enabled;
6519#endif
6520 }
6521 if (cmd->data.setassparms.hdr.assist_no == IPA_INBOUND_CHECKSUM &&
6522 cmd->data.setassparms.hdr.command_code == IPA_CMD_ASS_START) {
6523 card->info.csum_mask = cmd->data.setassparms.data.flags_32bit;
6524 QETH_DBF_TEXT_(trace, 3, "csum:%d", card->info.csum_mask);
6525 }
6526 return 0;
6527}
6528
6529static int
6530qeth_default_setadapterparms_cb(struct qeth_card *card,
6531 struct qeth_reply *reply,
6532 unsigned long data)
6533{
6534 struct qeth_ipa_cmd *cmd;
6535
6536 QETH_DBF_TEXT(trace,4,"defadpcb");
6537
6538 cmd = (struct qeth_ipa_cmd *) data;
6539 if (cmd->hdr.return_code == 0)
6540 cmd->hdr.return_code = cmd->data.setadapterparms.hdr.return_code;
6541 return 0;
6542}
6543
Frank Pavlic6c951b92005-11-10 13:51:25 +01006544
6545
Linus Torvalds1da177e2005-04-16 15:20:36 -07006546static int
6547qeth_query_setadapterparms_cb(struct qeth_card *card, struct qeth_reply *reply,
6548 unsigned long data)
6549{
6550 struct qeth_ipa_cmd *cmd;
6551
6552 QETH_DBF_TEXT(trace,3,"quyadpcb");
6553
6554 cmd = (struct qeth_ipa_cmd *) data;
6555 if (cmd->data.setadapterparms.data.query_cmds_supp.lan_type & 0x7f)
6556 card->info.link_type =
6557 cmd->data.setadapterparms.data.query_cmds_supp.lan_type;
6558 card->options.adp.supported_funcs =
6559 cmd->data.setadapterparms.data.query_cmds_supp.supported_cmds;
6560 return qeth_default_setadapterparms_cb(card, reply, (unsigned long)cmd);
6561}
6562
6563static int
6564qeth_query_setadapterparms(struct qeth_card *card)
6565{
6566 int rc;
6567 struct qeth_cmd_buffer *iob;
6568
6569 QETH_DBF_TEXT(trace,3,"queryadp");
6570 iob = qeth_get_adapter_cmd(card, IPA_SETADP_QUERY_COMMANDS_SUPPORTED,
6571 sizeof(struct qeth_ipacmd_setadpparms));
6572 rc = qeth_send_ipa_cmd(card, iob, qeth_query_setadapterparms_cb, NULL);
6573 return rc;
6574}
6575
6576static int
6577qeth_setadpparms_change_macaddr_cb(struct qeth_card *card,
6578 struct qeth_reply *reply,
6579 unsigned long data)
6580{
6581 struct qeth_ipa_cmd *cmd;
6582
6583 QETH_DBF_TEXT(trace,4,"chgmaccb");
6584
6585 cmd = (struct qeth_ipa_cmd *) data;
Frank Pavlice08d88c2005-11-10 13:51:17 +01006586 if (!card->options.layer2 || card->info.guestlan ||
6587 !(card->info.mac_bits & QETH_LAYER2_MAC_READ)) {
6588 memcpy(card->dev->dev_addr,
6589 &cmd->data.setadapterparms.data.change_addr.addr,
6590 OSA_ADDR_LEN);
6591 card->info.mac_bits |= QETH_LAYER2_MAC_READ;
6592 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07006593 qeth_default_setadapterparms_cb(card, reply, (unsigned long) cmd);
6594 return 0;
6595}
6596
6597static int
6598qeth_setadpparms_change_macaddr(struct qeth_card *card)
6599{
6600 int rc;
6601 struct qeth_cmd_buffer *iob;
6602 struct qeth_ipa_cmd *cmd;
6603
6604 QETH_DBF_TEXT(trace,4,"chgmac");
6605
6606 iob = qeth_get_adapter_cmd(card,IPA_SETADP_ALTER_MAC_ADDRESS,
6607 sizeof(struct qeth_ipacmd_setadpparms));
6608 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
6609 cmd->data.setadapterparms.data.change_addr.cmd = CHANGE_ADDR_READ_MAC;
6610 cmd->data.setadapterparms.data.change_addr.addr_size = OSA_ADDR_LEN;
6611 memcpy(&cmd->data.setadapterparms.data.change_addr.addr,
6612 card->dev->dev_addr, OSA_ADDR_LEN);
6613 rc = qeth_send_ipa_cmd(card, iob, qeth_setadpparms_change_macaddr_cb,
6614 NULL);
6615 return rc;
6616}
6617
6618static int
6619qeth_send_setadp_mode(struct qeth_card *card, __u32 command, __u32 mode)
6620{
6621 int rc;
6622 struct qeth_cmd_buffer *iob;
6623 struct qeth_ipa_cmd *cmd;
6624
6625 QETH_DBF_TEXT(trace,4,"adpmode");
6626
6627 iob = qeth_get_adapter_cmd(card, command,
6628 sizeof(struct qeth_ipacmd_setadpparms));
6629 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
6630 cmd->data.setadapterparms.data.mode = mode;
6631 rc = qeth_send_ipa_cmd(card, iob, qeth_default_setadapterparms_cb,
6632 NULL);
6633 return rc;
6634}
6635
6636static inline int
6637qeth_setadapter_hstr(struct qeth_card *card)
6638{
6639 int rc;
6640
6641 QETH_DBF_TEXT(trace,4,"adphstr");
6642
6643 if (qeth_adp_supported(card,IPA_SETADP_SET_BROADCAST_MODE)) {
6644 rc = qeth_send_setadp_mode(card, IPA_SETADP_SET_BROADCAST_MODE,
6645 card->options.broadcast_mode);
6646 if (rc)
6647 PRINT_WARN("couldn't set broadcast mode on "
6648 "device %s: x%x\n",
6649 CARD_BUS_ID(card), rc);
6650 rc = qeth_send_setadp_mode(card, IPA_SETADP_ALTER_MAC_ADDRESS,
6651 card->options.macaddr_mode);
6652 if (rc)
6653 PRINT_WARN("couldn't set macaddr mode on "
6654 "device %s: x%x\n", CARD_BUS_ID(card), rc);
6655 return rc;
6656 }
6657 if (card->options.broadcast_mode == QETH_TR_BROADCAST_LOCAL)
6658 PRINT_WARN("set adapter parameters not available "
6659 "to set broadcast mode, using ALLRINGS "
6660 "on device %s:\n", CARD_BUS_ID(card));
6661 if (card->options.macaddr_mode == QETH_TR_MACADDR_CANONICAL)
6662 PRINT_WARN("set adapter parameters not available "
6663 "to set macaddr mode, using NONCANONICAL "
6664 "on device %s:\n", CARD_BUS_ID(card));
6665 return 0;
6666}
6667
6668static int
6669qeth_setadapter_parms(struct qeth_card *card)
6670{
6671 int rc;
6672
6673 QETH_DBF_TEXT(setup, 2, "setadprm");
6674
6675 if (!qeth_is_supported(card, IPA_SETADAPTERPARMS)){
6676 PRINT_WARN("set adapter parameters not supported "
6677 "on device %s.\n",
6678 CARD_BUS_ID(card));
6679 QETH_DBF_TEXT(setup, 2, " notsupp");
6680 return 0;
6681 }
6682 rc = qeth_query_setadapterparms(card);
6683 if (rc) {
6684 PRINT_WARN("couldn't set adapter parameters on device %s: "
6685 "x%x\n", CARD_BUS_ID(card), rc);
6686 return rc;
6687 }
6688 if (qeth_adp_supported(card,IPA_SETADP_ALTER_MAC_ADDRESS)) {
6689 rc = qeth_setadpparms_change_macaddr(card);
6690 if (rc)
6691 PRINT_WARN("couldn't get MAC address on "
6692 "device %s: x%x\n",
6693 CARD_BUS_ID(card), rc);
6694 }
6695
6696 if ((card->info.link_type == QETH_LINK_TYPE_HSTR) ||
6697 (card->info.link_type == QETH_LINK_TYPE_LANE_TR))
6698 rc = qeth_setadapter_hstr(card);
6699
6700 return rc;
6701}
6702
6703static int
6704qeth_layer2_initialize(struct qeth_card *card)
6705{
6706 int rc = 0;
6707
6708
6709 QETH_DBF_TEXT(setup, 2, "doL2init");
6710 QETH_DBF_TEXT_(setup, 2, "doL2%s", CARD_BUS_ID(card));
6711
Frank Pavlic6c951b92005-11-10 13:51:25 +01006712 rc = qeth_query_setadapterparms(card);
6713 if (rc) {
6714 PRINT_WARN("could not query adapter parameters on device %s: "
6715 "x%x\n", CARD_BUS_ID(card), rc);
6716 }
6717
Linus Torvalds1da177e2005-04-16 15:20:36 -07006718 rc = qeth_setadpparms_change_macaddr(card);
6719 if (rc) {
6720 PRINT_WARN("couldn't get MAC address on "
6721 "device %s: x%x\n",
6722 CARD_BUS_ID(card), rc);
6723 QETH_DBF_TEXT_(setup, 2,"1err%d",rc);
6724 return rc;
6725 }
6726 QETH_DBF_HEX(setup,2, card->dev->dev_addr, OSA_ADDR_LEN);
6727
6728 rc = qeth_layer2_send_setmac(card, &card->dev->dev_addr[0]);
6729 if (rc)
6730 QETH_DBF_TEXT_(setup, 2,"2err%d",rc);
6731 return 0;
6732}
6733
6734
6735static int
6736qeth_send_startstoplan(struct qeth_card *card, enum qeth_ipa_cmds ipacmd,
6737 enum qeth_prot_versions prot)
6738{
6739 int rc;
6740 struct qeth_cmd_buffer *iob;
6741
6742 iob = qeth_get_ipacmd_buffer(card,ipacmd,prot);
6743 rc = qeth_send_ipa_cmd(card, iob, NULL, NULL);
6744
6745 return rc;
6746}
6747
6748static int
6749qeth_send_startlan(struct qeth_card *card, enum qeth_prot_versions prot)
6750{
6751 int rc;
6752
6753 QETH_DBF_TEXT_(setup, 2, "strtlan%i", prot);
6754
6755 rc = qeth_send_startstoplan(card, IPA_CMD_STARTLAN, prot);
6756 return rc;
6757}
6758
6759static int
6760qeth_send_stoplan(struct qeth_card *card)
6761{
6762 int rc = 0;
6763
6764 /*
6765 * TODO: according to the IPA format document page 14,
6766 * TCP/IP (we!) never issue a STOPLAN
6767 * is this right ?!?
6768 */
6769 QETH_DBF_TEXT(trace, 2, "stoplan");
6770
6771 rc = qeth_send_startstoplan(card, IPA_CMD_STOPLAN, QETH_PROT_IPV4);
6772 return rc;
6773}
6774
6775static int
6776qeth_query_ipassists_cb(struct qeth_card *card, struct qeth_reply *reply,
6777 unsigned long data)
6778{
6779 struct qeth_ipa_cmd *cmd;
6780
6781 QETH_DBF_TEXT(setup, 2, "qipasscb");
6782
6783 cmd = (struct qeth_ipa_cmd *) data;
6784 if (cmd->hdr.prot_version == QETH_PROT_IPV4) {
6785 card->options.ipa4.supported_funcs = cmd->hdr.ipa_supported;
6786 card->options.ipa4.enabled_funcs = cmd->hdr.ipa_enabled;
Ursula Braun9123e0d2005-09-30 10:17:24 +02006787 /* Disable IPV6 support hard coded for Hipersockets */
6788 if(card->info.type == QETH_CARD_TYPE_IQD)
6789 card->options.ipa4.supported_funcs &= ~IPA_IPV6;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006790 } else {
6791#ifdef CONFIG_QETH_IPV6
6792 card->options.ipa6.supported_funcs = cmd->hdr.ipa_supported;
6793 card->options.ipa6.enabled_funcs = cmd->hdr.ipa_enabled;
6794#endif
6795 }
6796 QETH_DBF_TEXT(setup, 2, "suppenbl");
6797 QETH_DBF_TEXT_(setup, 2, "%x",cmd->hdr.ipa_supported);
6798 QETH_DBF_TEXT_(setup, 2, "%x",cmd->hdr.ipa_enabled);
6799 return 0;
6800}
6801
6802static int
6803qeth_query_ipassists(struct qeth_card *card, enum qeth_prot_versions prot)
6804{
6805 int rc;
6806 struct qeth_cmd_buffer *iob;
6807
6808 QETH_DBF_TEXT_(setup, 2, "qipassi%i", prot);
6809 if (card->options.layer2) {
6810 QETH_DBF_TEXT(setup, 2, "noprmly2");
6811 return -EPERM;
6812 }
6813
6814 iob = qeth_get_ipacmd_buffer(card,IPA_CMD_QIPASSIST,prot);
6815 rc = qeth_send_ipa_cmd(card, iob, qeth_query_ipassists_cb, NULL);
6816 return rc;
6817}
6818
6819static struct qeth_cmd_buffer *
6820qeth_get_setassparms_cmd(struct qeth_card *card, enum qeth_ipa_funcs ipa_func,
6821 __u16 cmd_code, __u16 len,
6822 enum qeth_prot_versions prot)
6823{
6824 struct qeth_cmd_buffer *iob;
6825 struct qeth_ipa_cmd *cmd;
6826
6827 QETH_DBF_TEXT(trace,4,"getasscm");
6828 iob = qeth_get_ipacmd_buffer(card,IPA_CMD_SETASSPARMS,prot);
6829
6830 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
6831 cmd->data.setassparms.hdr.assist_no = ipa_func;
6832 cmd->data.setassparms.hdr.length = 8 + len;
6833 cmd->data.setassparms.hdr.command_code = cmd_code;
6834 cmd->data.setassparms.hdr.return_code = 0;
6835 cmd->data.setassparms.hdr.seq_no = 0;
6836
6837 return iob;
6838}
6839
6840static int
6841qeth_send_setassparms(struct qeth_card *card, struct qeth_cmd_buffer *iob,
6842 __u16 len, long data,
6843 int (*reply_cb)
6844 (struct qeth_card *,struct qeth_reply *,unsigned long),
6845 void *reply_param)
6846{
6847 int rc;
6848 struct qeth_ipa_cmd *cmd;
6849
6850 QETH_DBF_TEXT(trace,4,"sendassp");
6851
6852 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
6853 if (len <= sizeof(__u32))
6854 cmd->data.setassparms.data.flags_32bit = (__u32) data;
Frank Pavlic1380fee2006-03-22 16:03:41 +01006855 else /* (len > sizeof(__u32)) */
Linus Torvalds1da177e2005-04-16 15:20:36 -07006856 memcpy(&cmd->data.setassparms.data, (void *) data, len);
6857
6858 rc = qeth_send_ipa_cmd(card, iob, reply_cb, reply_param);
6859 return rc;
6860}
6861
6862#ifdef CONFIG_QETH_IPV6
6863static int
6864qeth_send_simple_setassparms_ipv6(struct qeth_card *card,
6865 enum qeth_ipa_funcs ipa_func, __u16 cmd_code)
6866
6867{
6868 int rc;
6869 struct qeth_cmd_buffer *iob;
6870
6871 QETH_DBF_TEXT(trace,4,"simassp6");
6872 iob = qeth_get_setassparms_cmd(card, ipa_func, cmd_code,
6873 0, QETH_PROT_IPV6);
6874 rc = qeth_send_setassparms(card, iob, 0, 0,
6875 qeth_default_setassparms_cb, NULL);
6876 return rc;
6877}
6878#endif
6879
6880static int
6881qeth_send_simple_setassparms(struct qeth_card *card,
6882 enum qeth_ipa_funcs ipa_func,
6883 __u16 cmd_code, long data)
6884{
6885 int rc;
6886 int length = 0;
6887 struct qeth_cmd_buffer *iob;
6888
6889 QETH_DBF_TEXT(trace,4,"simassp4");
6890 if (data)
6891 length = sizeof(__u32);
6892 iob = qeth_get_setassparms_cmd(card, ipa_func, cmd_code,
6893 length, QETH_PROT_IPV4);
6894 rc = qeth_send_setassparms(card, iob, length, data,
6895 qeth_default_setassparms_cb, NULL);
6896 return rc;
6897}
6898
6899static inline int
6900qeth_start_ipa_arp_processing(struct qeth_card *card)
6901{
6902 int rc;
6903
6904 QETH_DBF_TEXT(trace,3,"ipaarp");
6905
6906 if (!qeth_is_supported(card,IPA_ARP_PROCESSING)) {
6907 PRINT_WARN("ARP processing not supported "
6908 "on %s!\n", QETH_CARD_IFNAME(card));
6909 return 0;
6910 }
6911 rc = qeth_send_simple_setassparms(card,IPA_ARP_PROCESSING,
6912 IPA_CMD_ASS_START, 0);
6913 if (rc) {
6914 PRINT_WARN("Could not start ARP processing "
6915 "assist on %s: 0x%x\n",
6916 QETH_CARD_IFNAME(card), rc);
6917 }
6918 return rc;
6919}
6920
6921static int
6922qeth_start_ipa_ip_fragmentation(struct qeth_card *card)
6923{
6924 int rc;
6925
6926 QETH_DBF_TEXT(trace,3,"ipaipfrg");
6927
6928 if (!qeth_is_supported(card, IPA_IP_FRAGMENTATION)) {
6929 PRINT_INFO("Hardware IP fragmentation not supported on %s\n",
6930 QETH_CARD_IFNAME(card));
6931 return -EOPNOTSUPP;
6932 }
6933
6934 rc = qeth_send_simple_setassparms(card, IPA_IP_FRAGMENTATION,
6935 IPA_CMD_ASS_START, 0);
6936 if (rc) {
6937 PRINT_WARN("Could not start Hardware IP fragmentation "
6938 "assist on %s: 0x%x\n",
6939 QETH_CARD_IFNAME(card), rc);
6940 } else
6941 PRINT_INFO("Hardware IP fragmentation enabled \n");
6942 return rc;
6943}
6944
6945static int
6946qeth_start_ipa_source_mac(struct qeth_card *card)
6947{
6948 int rc;
6949
6950 QETH_DBF_TEXT(trace,3,"stsrcmac");
6951
6952 if (!card->options.fake_ll)
6953 return -EOPNOTSUPP;
6954
6955 if (!qeth_is_supported(card, IPA_SOURCE_MAC)) {
6956 PRINT_INFO("Inbound source address not "
6957 "supported on %s\n", QETH_CARD_IFNAME(card));
6958 return -EOPNOTSUPP;
6959 }
6960
6961 rc = qeth_send_simple_setassparms(card, IPA_SOURCE_MAC,
6962 IPA_CMD_ASS_START, 0);
6963 if (rc)
6964 PRINT_WARN("Could not start inbound source "
6965 "assist on %s: 0x%x\n",
6966 QETH_CARD_IFNAME(card), rc);
6967 return rc;
6968}
6969
6970static int
6971qeth_start_ipa_vlan(struct qeth_card *card)
6972{
6973 int rc = 0;
6974
6975 QETH_DBF_TEXT(trace,3,"strtvlan");
6976
6977#ifdef CONFIG_QETH_VLAN
6978 if (!qeth_is_supported(card, IPA_FULL_VLAN)) {
6979 PRINT_WARN("VLAN not supported on %s\n", QETH_CARD_IFNAME(card));
6980 return -EOPNOTSUPP;
6981 }
6982
6983 rc = qeth_send_simple_setassparms(card, IPA_VLAN_PRIO,
6984 IPA_CMD_ASS_START,0);
6985 if (rc) {
6986 PRINT_WARN("Could not start vlan "
6987 "assist on %s: 0x%x\n",
6988 QETH_CARD_IFNAME(card), rc);
6989 } else {
6990 PRINT_INFO("VLAN enabled \n");
6991 card->dev->features |=
6992 NETIF_F_HW_VLAN_FILTER |
6993 NETIF_F_HW_VLAN_TX |
6994 NETIF_F_HW_VLAN_RX;
6995 }
6996#endif /* QETH_VLAN */
6997 return rc;
6998}
6999
7000static int
7001qeth_start_ipa_multicast(struct qeth_card *card)
7002{
7003 int rc;
7004
7005 QETH_DBF_TEXT(trace,3,"stmcast");
7006
7007 if (!qeth_is_supported(card, IPA_MULTICASTING)) {
7008 PRINT_WARN("Multicast not supported on %s\n",
7009 QETH_CARD_IFNAME(card));
7010 return -EOPNOTSUPP;
7011 }
7012
7013 rc = qeth_send_simple_setassparms(card, IPA_MULTICASTING,
7014 IPA_CMD_ASS_START,0);
7015 if (rc) {
7016 PRINT_WARN("Could not start multicast "
7017 "assist on %s: rc=%i\n",
7018 QETH_CARD_IFNAME(card), rc);
7019 } else {
7020 PRINT_INFO("Multicast enabled\n");
7021 card->dev->flags |= IFF_MULTICAST;
7022 }
7023 return rc;
7024}
7025
7026#ifdef CONFIG_QETH_IPV6
7027static int
7028qeth_softsetup_ipv6(struct qeth_card *card)
7029{
7030 int rc;
7031
7032 QETH_DBF_TEXT(trace,3,"softipv6");
7033
7034 netif_stop_queue(card->dev);
7035 rc = qeth_send_startlan(card, QETH_PROT_IPV6);
7036 if (rc) {
7037 PRINT_ERR("IPv6 startlan failed on %s\n",
7038 QETH_CARD_IFNAME(card));
7039 return rc;
7040 }
7041 netif_wake_queue(card->dev);
7042 rc = qeth_query_ipassists(card,QETH_PROT_IPV6);
7043 if (rc) {
7044 PRINT_ERR("IPv6 query ipassist failed on %s\n",
7045 QETH_CARD_IFNAME(card));
7046 return rc;
7047 }
7048 rc = qeth_send_simple_setassparms(card, IPA_IPV6,
7049 IPA_CMD_ASS_START, 3);
7050 if (rc) {
7051 PRINT_WARN("IPv6 start assist (version 4) failed "
7052 "on %s: 0x%x\n",
7053 QETH_CARD_IFNAME(card), rc);
7054 return rc;
7055 }
7056 rc = qeth_send_simple_setassparms_ipv6(card, IPA_IPV6,
7057 IPA_CMD_ASS_START);
7058 if (rc) {
7059 PRINT_WARN("IPV6 start assist (version 6) failed "
7060 "on %s: 0x%x\n",
7061 QETH_CARD_IFNAME(card), rc);
7062 return rc;
7063 }
7064 rc = qeth_send_simple_setassparms_ipv6(card, IPA_PASSTHRU,
7065 IPA_CMD_ASS_START);
7066 if (rc) {
7067 PRINT_WARN("Could not enable passthrough "
7068 "on %s: 0x%x\n",
7069 QETH_CARD_IFNAME(card), rc);
7070 return rc;
7071 }
7072 PRINT_INFO("IPV6 enabled \n");
7073 return 0;
7074}
7075
7076#endif
7077
7078static int
7079qeth_start_ipa_ipv6(struct qeth_card *card)
7080{
7081 int rc = 0;
7082#ifdef CONFIG_QETH_IPV6
7083 QETH_DBF_TEXT(trace,3,"strtipv6");
7084
7085 if (!qeth_is_supported(card, IPA_IPV6)) {
7086 PRINT_WARN("IPv6 not supported on %s\n",
7087 QETH_CARD_IFNAME(card));
7088 return 0;
7089 }
7090 rc = qeth_softsetup_ipv6(card);
7091#endif
7092 return rc ;
7093}
7094
7095static int
7096qeth_start_ipa_broadcast(struct qeth_card *card)
7097{
7098 int rc;
7099
7100 QETH_DBF_TEXT(trace,3,"stbrdcst");
7101 card->info.broadcast_capable = 0;
7102 if (!qeth_is_supported(card, IPA_FILTERING)) {
7103 PRINT_WARN("Broadcast not supported on %s\n",
7104 QETH_CARD_IFNAME(card));
7105 rc = -EOPNOTSUPP;
7106 goto out;
7107 }
7108 rc = qeth_send_simple_setassparms(card, IPA_FILTERING,
7109 IPA_CMD_ASS_START, 0);
7110 if (rc) {
7111 PRINT_WARN("Could not enable broadcasting filtering "
7112 "on %s: 0x%x\n",
7113 QETH_CARD_IFNAME(card), rc);
7114 goto out;
7115 }
7116
7117 rc = qeth_send_simple_setassparms(card, IPA_FILTERING,
7118 IPA_CMD_ASS_CONFIGURE, 1);
7119 if (rc) {
7120 PRINT_WARN("Could not set up broadcast filtering on %s: 0x%x\n",
7121 QETH_CARD_IFNAME(card), rc);
7122 goto out;
7123 }
7124 card->info.broadcast_capable = QETH_BROADCAST_WITH_ECHO;
7125 PRINT_INFO("Broadcast enabled \n");
7126 rc = qeth_send_simple_setassparms(card, IPA_FILTERING,
7127 IPA_CMD_ASS_ENABLE, 1);
7128 if (rc) {
7129 PRINT_WARN("Could not set up broadcast echo filtering on "
7130 "%s: 0x%x\n", QETH_CARD_IFNAME(card), rc);
7131 goto out;
7132 }
7133 card->info.broadcast_capable = QETH_BROADCAST_WITHOUT_ECHO;
7134out:
7135 if (card->info.broadcast_capable)
7136 card->dev->flags |= IFF_BROADCAST;
7137 else
7138 card->dev->flags &= ~IFF_BROADCAST;
7139 return rc;
7140}
7141
7142static int
7143qeth_send_checksum_command(struct qeth_card *card)
7144{
7145 int rc;
7146
7147 rc = qeth_send_simple_setassparms(card, IPA_INBOUND_CHECKSUM,
7148 IPA_CMD_ASS_START, 0);
7149 if (rc) {
7150 PRINT_WARN("Starting Inbound HW Checksumming failed on %s: "
7151 "0x%x,\ncontinuing using Inbound SW Checksumming\n",
7152 QETH_CARD_IFNAME(card), rc);
7153 return rc;
7154 }
7155 rc = qeth_send_simple_setassparms(card, IPA_INBOUND_CHECKSUM,
7156 IPA_CMD_ASS_ENABLE,
7157 card->info.csum_mask);
7158 if (rc) {
7159 PRINT_WARN("Enabling Inbound HW Checksumming failed on %s: "
7160 "0x%x,\ncontinuing using Inbound SW Checksumming\n",
7161 QETH_CARD_IFNAME(card), rc);
7162 return rc;
7163 }
7164 return 0;
7165}
7166
7167static int
7168qeth_start_ipa_checksum(struct qeth_card *card)
7169{
7170 int rc = 0;
7171
7172 QETH_DBF_TEXT(trace,3,"strtcsum");
7173
7174 if (card->options.checksum_type == NO_CHECKSUMMING) {
7175 PRINT_WARN("Using no checksumming on %s.\n",
7176 QETH_CARD_IFNAME(card));
7177 return 0;
7178 }
7179 if (card->options.checksum_type == SW_CHECKSUMMING) {
7180 PRINT_WARN("Using SW checksumming on %s.\n",
7181 QETH_CARD_IFNAME(card));
7182 return 0;
7183 }
7184 if (!qeth_is_supported(card, IPA_INBOUND_CHECKSUM)) {
7185 PRINT_WARN("Inbound HW Checksumming not "
7186 "supported on %s,\ncontinuing "
7187 "using Inbound SW Checksumming\n",
7188 QETH_CARD_IFNAME(card));
7189 card->options.checksum_type = SW_CHECKSUMMING;
7190 return 0;
7191 }
7192 rc = qeth_send_checksum_command(card);
7193 if (!rc) {
7194 PRINT_INFO("HW Checksumming (inbound) enabled \n");
7195 }
7196 return rc;
7197}
7198
7199static int
7200qeth_start_ipa_tso(struct qeth_card *card)
7201{
7202 int rc;
7203
7204 QETH_DBF_TEXT(trace,3,"sttso");
7205
7206 if (!qeth_is_supported(card, IPA_OUTBOUND_TSO)) {
7207 PRINT_WARN("Outbound TSO not supported on %s\n",
7208 QETH_CARD_IFNAME(card));
7209 rc = -EOPNOTSUPP;
7210 } else {
7211 rc = qeth_send_simple_setassparms(card, IPA_OUTBOUND_TSO,
7212 IPA_CMD_ASS_START,0);
7213 if (rc)
7214 PRINT_WARN("Could not start outbound TSO "
7215 "assist on %s: rc=%i\n",
7216 QETH_CARD_IFNAME(card), rc);
7217 else
7218 PRINT_INFO("Outbound TSO enabled\n");
7219 }
7220 if (rc && (card->options.large_send == QETH_LARGE_SEND_TSO)){
7221 card->options.large_send = QETH_LARGE_SEND_NO;
7222 card->dev->features &= ~ (NETIF_F_TSO | NETIF_F_SG);
7223 }
7224 return rc;
7225}
7226
7227static int
7228qeth_start_ipassists(struct qeth_card *card)
7229{
7230 QETH_DBF_TEXT(trace,3,"strtipas");
7231 qeth_start_ipa_arp_processing(card); /* go on*/
7232 qeth_start_ipa_ip_fragmentation(card); /* go on*/
7233 qeth_start_ipa_source_mac(card); /* go on*/
7234 qeth_start_ipa_vlan(card); /* go on*/
7235 qeth_start_ipa_multicast(card); /* go on*/
7236 qeth_start_ipa_ipv6(card); /* go on*/
7237 qeth_start_ipa_broadcast(card); /* go on*/
7238 qeth_start_ipa_checksum(card); /* go on*/
7239 qeth_start_ipa_tso(card); /* go on*/
7240 return 0;
7241}
7242
7243static int
7244qeth_send_setrouting(struct qeth_card *card, enum qeth_routing_types type,
7245 enum qeth_prot_versions prot)
7246{
7247 int rc;
7248 struct qeth_ipa_cmd *cmd;
7249 struct qeth_cmd_buffer *iob;
7250
7251 QETH_DBF_TEXT(trace,4,"setroutg");
7252 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_SETRTG, prot);
7253 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
7254 cmd->data.setrtg.type = (type);
7255 rc = qeth_send_ipa_cmd(card, iob, NULL, NULL);
7256
7257 return rc;
7258
7259}
7260
7261static void
7262qeth_correct_routing_type(struct qeth_card *card, enum qeth_routing_types *type,
7263 enum qeth_prot_versions prot)
7264{
7265 if (card->info.type == QETH_CARD_TYPE_IQD) {
7266 switch (*type) {
7267 case NO_ROUTER:
7268 case PRIMARY_CONNECTOR:
7269 case SECONDARY_CONNECTOR:
7270 case MULTICAST_ROUTER:
7271 return;
7272 default:
7273 goto out_inval;
7274 }
7275 } else {
7276 switch (*type) {
7277 case NO_ROUTER:
7278 case PRIMARY_ROUTER:
7279 case SECONDARY_ROUTER:
7280 return;
7281 case MULTICAST_ROUTER:
7282 if (qeth_is_ipafunc_supported(card, prot,
7283 IPA_OSA_MC_ROUTER))
7284 return;
7285 default:
7286 goto out_inval;
7287 }
7288 }
7289out_inval:
7290 PRINT_WARN("Routing type '%s' not supported for interface %s.\n"
7291 "Router status set to 'no router'.\n",
7292 ((*type == PRIMARY_ROUTER)? "primary router" :
7293 (*type == SECONDARY_ROUTER)? "secondary router" :
7294 (*type == PRIMARY_CONNECTOR)? "primary connector" :
7295 (*type == SECONDARY_CONNECTOR)? "secondary connector" :
7296 (*type == MULTICAST_ROUTER)? "multicast router" :
7297 "unknown"),
7298 card->dev->name);
7299 *type = NO_ROUTER;
7300}
7301
7302int
7303qeth_setrouting_v4(struct qeth_card *card)
7304{
7305 int rc;
7306
7307 QETH_DBF_TEXT(trace,3,"setrtg4");
7308
7309 qeth_correct_routing_type(card, &card->options.route4.type,
7310 QETH_PROT_IPV4);
7311
7312 rc = qeth_send_setrouting(card, card->options.route4.type,
7313 QETH_PROT_IPV4);
7314 if (rc) {
7315 card->options.route4.type = NO_ROUTER;
7316 PRINT_WARN("Error (0x%04x) while setting routing type on %s. "
7317 "Type set to 'no router'.\n",
7318 rc, QETH_CARD_IFNAME(card));
7319 }
7320 return rc;
7321}
7322
7323int
7324qeth_setrouting_v6(struct qeth_card *card)
7325{
7326 int rc = 0;
7327
7328 QETH_DBF_TEXT(trace,3,"setrtg6");
7329#ifdef CONFIG_QETH_IPV6
7330
7331 qeth_correct_routing_type(card, &card->options.route6.type,
7332 QETH_PROT_IPV6);
7333
Linus Torvalds1da177e2005-04-16 15:20:36 -07007334 rc = qeth_send_setrouting(card, card->options.route6.type,
7335 QETH_PROT_IPV6);
7336 if (rc) {
7337 card->options.route6.type = NO_ROUTER;
7338 PRINT_WARN("Error (0x%04x) while setting routing type on %s. "
7339 "Type set to 'no router'.\n",
7340 rc, QETH_CARD_IFNAME(card));
7341 }
7342#endif
7343 return rc;
7344}
7345
7346int
Frank Pavlic9cb90de2005-09-14 18:03:26 +02007347qeth_set_large_send(struct qeth_card *card, enum qeth_large_send_types type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007348{
7349 int rc = 0;
7350
Frank Pavlic9cb90de2005-09-14 18:03:26 +02007351 if (card->dev == NULL) {
7352 card->options.large_send = type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007353 return 0;
Frank Pavlic9cb90de2005-09-14 18:03:26 +02007354 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07007355 netif_stop_queue(card->dev);
Frank Pavlic9cb90de2005-09-14 18:03:26 +02007356 card->options.large_send = type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007357 switch (card->options.large_send) {
7358 case QETH_LARGE_SEND_EDDP:
7359 card->dev->features |= NETIF_F_TSO | NETIF_F_SG;
7360 break;
7361 case QETH_LARGE_SEND_TSO:
7362 if (qeth_is_supported(card, IPA_OUTBOUND_TSO)){
7363 card->dev->features |= NETIF_F_TSO | NETIF_F_SG;
7364 } else {
7365 PRINT_WARN("TSO not supported on %s. "
7366 "large_send set to 'no'.\n",
7367 card->dev->name);
7368 card->dev->features &= ~(NETIF_F_TSO | NETIF_F_SG);
7369 card->options.large_send = QETH_LARGE_SEND_NO;
7370 rc = -EOPNOTSUPP;
7371 }
7372 break;
7373 default: /* includes QETH_LARGE_SEND_NO */
7374 card->dev->features &= ~(NETIF_F_TSO | NETIF_F_SG);
7375 break;
7376 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07007377 netif_wake_queue(card->dev);
7378 return rc;
7379}
7380
7381/*
7382 * softsetup card: init IPA stuff
7383 */
7384static int
7385qeth_softsetup_card(struct qeth_card *card)
7386{
7387 int rc;
7388
7389 QETH_DBF_TEXT(setup, 2, "softsetp");
7390
7391 if ((rc = qeth_send_startlan(card, QETH_PROT_IPV4))){
7392 QETH_DBF_TEXT_(setup, 2, "1err%d", rc);
7393 if (rc == 0xe080){
7394 PRINT_WARN("LAN on card %s if offline! "
7395 "Continuing softsetup.\n",
7396 CARD_BUS_ID(card));
7397 card->lan_online = 0;
7398 } else
7399 return rc;
7400 } else
7401 card->lan_online = 1;
Ursula Braun500f83a2005-09-30 10:19:19 +02007402 if (card->info.type==QETH_CARD_TYPE_OSN)
7403 goto out;
Frank Pavlic66cc5d52006-02-07 17:04:38 +01007404 qeth_set_large_send(card, card->options.large_send);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007405 if (card->options.layer2) {
7406 card->dev->features |=
7407 NETIF_F_HW_VLAN_FILTER |
7408 NETIF_F_HW_VLAN_TX |
7409 NETIF_F_HW_VLAN_RX;
7410 card->dev->flags|=IFF_MULTICAST|IFF_BROADCAST;
7411 card->info.broadcast_capable=1;
7412 if ((rc = qeth_layer2_initialize(card))) {
7413 QETH_DBF_TEXT_(setup, 2, "L2err%d", rc);
7414 return rc;
7415 }
7416#ifdef CONFIG_QETH_VLAN
7417 qeth_layer2_process_vlans(card, 0);
7418#endif
7419 goto out;
7420 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07007421 if ((rc = qeth_setadapter_parms(card)))
7422 QETH_DBF_TEXT_(setup, 2, "2err%d", rc);
7423 if ((rc = qeth_start_ipassists(card)))
7424 QETH_DBF_TEXT_(setup, 2, "3err%d", rc);
7425 if ((rc = qeth_setrouting_v4(card)))
7426 QETH_DBF_TEXT_(setup, 2, "4err%d", rc);
7427 if ((rc = qeth_setrouting_v6(card)))
7428 QETH_DBF_TEXT_(setup, 2, "5err%d", rc);
7429out:
7430 netif_stop_queue(card->dev);
7431 return 0;
7432}
7433
7434#ifdef CONFIG_QETH_IPV6
7435static int
7436qeth_get_unique_id_cb(struct qeth_card *card, struct qeth_reply *reply,
7437 unsigned long data)
7438{
7439 struct qeth_ipa_cmd *cmd;
7440
7441 cmd = (struct qeth_ipa_cmd *) data;
7442 if (cmd->hdr.return_code == 0)
7443 card->info.unique_id = *((__u16 *)
7444 &cmd->data.create_destroy_addr.unique_id[6]);
7445 else {
7446 card->info.unique_id = UNIQUE_ID_IF_CREATE_ADDR_FAILED |
7447 UNIQUE_ID_NOT_BY_CARD;
7448 PRINT_WARN("couldn't get a unique id from the card on device "
7449 "%s (result=x%x), using default id. ipv6 "
7450 "autoconfig on other lpars may lead to duplicate "
7451 "ip addresses. please use manually "
7452 "configured ones.\n",
7453 CARD_BUS_ID(card), cmd->hdr.return_code);
7454 }
7455 return 0;
7456}
7457#endif
7458
7459static int
7460qeth_put_unique_id(struct qeth_card *card)
7461{
7462
7463 int rc = 0;
7464#ifdef CONFIG_QETH_IPV6
7465 struct qeth_cmd_buffer *iob;
7466 struct qeth_ipa_cmd *cmd;
7467
7468 QETH_DBF_TEXT(trace,2,"puniqeid");
7469
7470 if ((card->info.unique_id & UNIQUE_ID_NOT_BY_CARD) ==
7471 UNIQUE_ID_NOT_BY_CARD)
7472 return -1;
7473 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_DESTROY_ADDR,
7474 QETH_PROT_IPV6);
7475 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
7476 *((__u16 *) &cmd->data.create_destroy_addr.unique_id[6]) =
7477 card->info.unique_id;
7478 memcpy(&cmd->data.create_destroy_addr.unique_id[0],
7479 card->dev->dev_addr, OSA_ADDR_LEN);
7480 rc = qeth_send_ipa_cmd(card, iob, NULL, NULL);
7481#else
7482 card->info.unique_id = UNIQUE_ID_IF_CREATE_ADDR_FAILED |
7483 UNIQUE_ID_NOT_BY_CARD;
7484#endif
7485 return rc;
7486}
7487
7488/**
7489 * Clear IP List
7490 */
7491static void
7492qeth_clear_ip_list(struct qeth_card *card, int clean, int recover)
7493{
7494 struct qeth_ipaddr *addr, *tmp;
7495 unsigned long flags;
7496
7497 QETH_DBF_TEXT(trace,4,"clearip");
7498 spin_lock_irqsave(&card->ip_lock, flags);
7499 /* clear todo list */
7500 list_for_each_entry_safe(addr, tmp, card->ip_tbd_list, entry){
7501 list_del(&addr->entry);
7502 kfree(addr);
7503 }
7504
7505 while (!list_empty(&card->ip_list)) {
7506 addr = list_entry(card->ip_list.next,
7507 struct qeth_ipaddr, entry);
7508 list_del_init(&addr->entry);
7509 if (clean) {
7510 spin_unlock_irqrestore(&card->ip_lock, flags);
7511 qeth_deregister_addr_entry(card, addr);
7512 spin_lock_irqsave(&card->ip_lock, flags);
7513 }
7514 if (!recover || addr->is_multicast) {
7515 kfree(addr);
7516 continue;
7517 }
7518 list_add_tail(&addr->entry, card->ip_tbd_list);
7519 }
7520 spin_unlock_irqrestore(&card->ip_lock, flags);
7521}
7522
7523static void
7524qeth_set_allowed_threads(struct qeth_card *card, unsigned long threads,
7525 int clear_start_mask)
7526{
7527 unsigned long flags;
7528
7529 spin_lock_irqsave(&card->thread_mask_lock, flags);
7530 card->thread_allowed_mask = threads;
7531 if (clear_start_mask)
7532 card->thread_start_mask &= threads;
7533 spin_unlock_irqrestore(&card->thread_mask_lock, flags);
7534 wake_up(&card->wait_q);
7535}
7536
7537static inline int
7538qeth_threads_running(struct qeth_card *card, unsigned long threads)
7539{
7540 unsigned long flags;
7541 int rc = 0;
7542
7543 spin_lock_irqsave(&card->thread_mask_lock, flags);
7544 rc = (card->thread_running_mask & threads);
7545 spin_unlock_irqrestore(&card->thread_mask_lock, flags);
7546 return rc;
7547}
7548
7549static int
7550qeth_wait_for_threads(struct qeth_card *card, unsigned long threads)
7551{
7552 return wait_event_interruptible(card->wait_q,
7553 qeth_threads_running(card, threads) == 0);
7554}
7555
7556static int
Frank Pavlic05e08a22005-05-12 20:39:09 +02007557qeth_stop_card(struct qeth_card *card, int recovery_mode)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007558{
7559 int rc = 0;
7560
7561 QETH_DBF_TEXT(setup ,2,"stopcard");
7562 QETH_DBF_HEX(setup, 2, &card, sizeof(void *));
7563
7564 qeth_set_allowed_threads(card, 0, 1);
7565 if (qeth_wait_for_threads(card, ~QETH_RECOVER_THREAD))
7566 return -ERESTARTSYS;
7567 if (card->read.state == CH_STATE_UP &&
7568 card->write.state == CH_STATE_UP &&
7569 (card->state == CARD_STATE_UP)) {
Ursula Braun500f83a2005-09-30 10:19:19 +02007570 if (recovery_mode &&
7571 card->info.type != QETH_CARD_TYPE_OSN) {
Frank Pavlic05e08a22005-05-12 20:39:09 +02007572 qeth_stop(card->dev);
7573 } else {
7574 rtnl_lock();
7575 dev_close(card->dev);
7576 rtnl_unlock();
7577 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07007578 if (!card->use_hard_stop) {
7579 __u8 *mac = &card->dev->dev_addr[0];
7580 rc = qeth_layer2_send_delmac(card, mac);
7581 QETH_DBF_TEXT_(setup, 2, "Lerr%d", rc);
7582 if ((rc = qeth_send_stoplan(card)))
7583 QETH_DBF_TEXT_(setup, 2, "1err%d", rc);
7584 }
7585 card->state = CARD_STATE_SOFTSETUP;
7586 }
7587 if (card->state == CARD_STATE_SOFTSETUP) {
7588#ifdef CONFIG_QETH_VLAN
7589 if (card->options.layer2)
7590 qeth_layer2_process_vlans(card, 1);
7591#endif
7592 qeth_clear_ip_list(card, !card->use_hard_stop, 1);
7593 qeth_clear_ipacmd_list(card);
7594 card->state = CARD_STATE_HARDSETUP;
7595 }
7596 if (card->state == CARD_STATE_HARDSETUP) {
7597 if ((!card->use_hard_stop) &&
7598 (!card->options.layer2))
7599 if ((rc = qeth_put_unique_id(card)))
7600 QETH_DBF_TEXT_(setup, 2, "2err%d", rc);
7601 qeth_qdio_clear_card(card, 0);
7602 qeth_clear_qdio_buffers(card);
7603 qeth_clear_working_pool_list(card);
7604 card->state = CARD_STATE_DOWN;
7605 }
7606 if (card->state == CARD_STATE_DOWN) {
7607 qeth_clear_cmd_buffers(&card->read);
7608 qeth_clear_cmd_buffers(&card->write);
7609 }
7610 card->use_hard_stop = 0;
7611 return rc;
7612}
7613
7614
7615static int
7616qeth_get_unique_id(struct qeth_card *card)
7617{
7618 int rc = 0;
7619#ifdef CONFIG_QETH_IPV6
7620 struct qeth_cmd_buffer *iob;
7621 struct qeth_ipa_cmd *cmd;
7622
7623 QETH_DBF_TEXT(setup, 2, "guniqeid");
7624
7625 if (!qeth_is_supported(card,IPA_IPV6)) {
7626 card->info.unique_id = UNIQUE_ID_IF_CREATE_ADDR_FAILED |
7627 UNIQUE_ID_NOT_BY_CARD;
7628 return 0;
7629 }
7630
7631 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_CREATE_ADDR,
7632 QETH_PROT_IPV6);
7633 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
7634 *((__u16 *) &cmd->data.create_destroy_addr.unique_id[6]) =
7635 card->info.unique_id;
7636
7637 rc = qeth_send_ipa_cmd(card, iob, qeth_get_unique_id_cb, NULL);
7638#else
7639 card->info.unique_id = UNIQUE_ID_IF_CREATE_ADDR_FAILED |
7640 UNIQUE_ID_NOT_BY_CARD;
7641#endif
7642 return rc;
7643}
7644static void
7645qeth_print_status_with_portname(struct qeth_card *card)
7646{
7647 char dbf_text[15];
7648 int i;
7649
7650 sprintf(dbf_text, "%s", card->info.portname + 1);
7651 for (i = 0; i < 8; i++)
7652 dbf_text[i] =
7653 (char) _ebcasc[(__u8) dbf_text[i]];
7654 dbf_text[8] = 0;
7655 printk("qeth: Device %s/%s/%s is a%s card%s%s%s\n"
7656 "with link type %s (portname: %s)\n",
7657 CARD_RDEV_ID(card),
7658 CARD_WDEV_ID(card),
7659 CARD_DDEV_ID(card),
7660 qeth_get_cardname(card),
7661 (card->info.mcl_level[0]) ? " (level: " : "",
7662 (card->info.mcl_level[0]) ? card->info.mcl_level : "",
7663 (card->info.mcl_level[0]) ? ")" : "",
7664 qeth_get_cardname_short(card),
7665 dbf_text);
7666
7667}
7668
7669static void
7670qeth_print_status_no_portname(struct qeth_card *card)
7671{
7672 if (card->info.portname[0])
7673 printk("qeth: Device %s/%s/%s is a%s "
7674 "card%s%s%s\nwith link type %s "
7675 "(no portname needed by interface).\n",
7676 CARD_RDEV_ID(card),
7677 CARD_WDEV_ID(card),
7678 CARD_DDEV_ID(card),
7679 qeth_get_cardname(card),
7680 (card->info.mcl_level[0]) ? " (level: " : "",
7681 (card->info.mcl_level[0]) ? card->info.mcl_level : "",
7682 (card->info.mcl_level[0]) ? ")" : "",
7683 qeth_get_cardname_short(card));
7684 else
7685 printk("qeth: Device %s/%s/%s is a%s "
7686 "card%s%s%s\nwith link type %s.\n",
7687 CARD_RDEV_ID(card),
7688 CARD_WDEV_ID(card),
7689 CARD_DDEV_ID(card),
7690 qeth_get_cardname(card),
7691 (card->info.mcl_level[0]) ? " (level: " : "",
7692 (card->info.mcl_level[0]) ? card->info.mcl_level : "",
7693 (card->info.mcl_level[0]) ? ")" : "",
7694 qeth_get_cardname_short(card));
7695}
7696
7697static void
7698qeth_print_status_message(struct qeth_card *card)
7699{
7700 switch (card->info.type) {
7701 case QETH_CARD_TYPE_OSAE:
7702 /* VM will use a non-zero first character
7703 * to indicate a HiperSockets like reporting
7704 * of the level OSA sets the first character to zero
7705 * */
7706 if (!card->info.mcl_level[0]) {
7707 sprintf(card->info.mcl_level,"%02x%02x",
7708 card->info.mcl_level[2],
7709 card->info.mcl_level[3]);
7710
7711 card->info.mcl_level[QETH_MCL_LENGTH] = 0;
7712 break;
7713 }
7714 /* fallthrough */
7715 case QETH_CARD_TYPE_IQD:
7716 card->info.mcl_level[0] = (char) _ebcasc[(__u8)
7717 card->info.mcl_level[0]];
7718 card->info.mcl_level[1] = (char) _ebcasc[(__u8)
7719 card->info.mcl_level[1]];
7720 card->info.mcl_level[2] = (char) _ebcasc[(__u8)
7721 card->info.mcl_level[2]];
7722 card->info.mcl_level[3] = (char) _ebcasc[(__u8)
7723 card->info.mcl_level[3]];
7724 card->info.mcl_level[QETH_MCL_LENGTH] = 0;
7725 break;
7726 default:
7727 memset(&card->info.mcl_level[0], 0, QETH_MCL_LENGTH + 1);
7728 }
7729 if (card->info.portname_required)
7730 qeth_print_status_with_portname(card);
7731 else
7732 qeth_print_status_no_portname(card);
7733}
7734
7735static int
7736qeth_register_netdev(struct qeth_card *card)
7737{
7738 QETH_DBF_TEXT(setup, 3, "regnetd");
7739 if (card->dev->reg_state != NETREG_UNINITIALIZED) {
7740 qeth_netdev_init(card->dev);
7741 return 0;
7742 }
7743 /* sysfs magic */
7744 SET_NETDEV_DEV(card->dev, &card->gdev->dev);
7745 return register_netdev(card->dev);
7746}
7747
7748static void
Frank Pavlic05e08a22005-05-12 20:39:09 +02007749qeth_start_again(struct qeth_card *card, int recovery_mode)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007750{
7751 QETH_DBF_TEXT(setup ,2, "startag");
7752
Ursula Braun500f83a2005-09-30 10:19:19 +02007753 if (recovery_mode &&
7754 card->info.type != QETH_CARD_TYPE_OSN) {
Frank Pavlic05e08a22005-05-12 20:39:09 +02007755 qeth_open(card->dev);
7756 } else {
7757 rtnl_lock();
7758 dev_open(card->dev);
7759 rtnl_unlock();
7760 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07007761 /* this also sets saved unicast addresses */
7762 qeth_set_multicast_list(card->dev);
7763}
7764
7765
7766/* Layer 2 specific stuff */
7767#define IGNORE_PARAM_EQ(option,value,reset_value,msg) \
7768 if (card->options.option == value) { \
7769 PRINT_ERR("%s not supported with layer 2 " \
7770 "functionality, ignoring option on read" \
7771 "channel device %s .\n",msg,CARD_RDEV_ID(card)); \
7772 card->options.option = reset_value; \
7773 }
7774#define IGNORE_PARAM_NEQ(option,value,reset_value,msg) \
7775 if (card->options.option != value) { \
7776 PRINT_ERR("%s not supported with layer 2 " \
7777 "functionality, ignoring option on read" \
7778 "channel device %s .\n",msg,CARD_RDEV_ID(card)); \
7779 card->options.option = reset_value; \
7780 }
7781
7782
7783static void qeth_make_parameters_consistent(struct qeth_card *card)
7784{
7785
Ursula Braun500f83a2005-09-30 10:19:19 +02007786 if (card->options.layer2 == 0)
7787 return;
7788 if (card->info.type == QETH_CARD_TYPE_OSN)
7789 return;
7790 if (card->info.type == QETH_CARD_TYPE_IQD) {
7791 PRINT_ERR("Device %s does not support layer 2 functionality." \
7792 " Ignoring layer2 option.\n",CARD_BUS_ID(card));
7793 card->options.layer2 = 0;
7794 return;
7795 }
7796 IGNORE_PARAM_NEQ(route4.type, NO_ROUTER, NO_ROUTER,
7797 "Routing options are");
Linus Torvalds1da177e2005-04-16 15:20:36 -07007798#ifdef CONFIG_QETH_IPV6
Ursula Braun500f83a2005-09-30 10:19:19 +02007799 IGNORE_PARAM_NEQ(route6.type, NO_ROUTER, NO_ROUTER,
7800 "Routing options are");
Linus Torvalds1da177e2005-04-16 15:20:36 -07007801#endif
Ursula Braun500f83a2005-09-30 10:19:19 +02007802 IGNORE_PARAM_EQ(checksum_type, HW_CHECKSUMMING,
7803 QETH_CHECKSUM_DEFAULT,
7804 "Checksumming options are");
7805 IGNORE_PARAM_NEQ(broadcast_mode, QETH_TR_BROADCAST_ALLRINGS,
7806 QETH_TR_BROADCAST_ALLRINGS,
7807 "Broadcast mode options are");
7808 IGNORE_PARAM_NEQ(macaddr_mode, QETH_TR_MACADDR_NONCANONICAL,
7809 QETH_TR_MACADDR_NONCANONICAL,
7810 "Canonical MAC addr options are");
7811 IGNORE_PARAM_NEQ(fake_broadcast, 0, 0,
7812 "Broadcast faking options are");
7813 IGNORE_PARAM_NEQ(add_hhlen, DEFAULT_ADD_HHLEN,
7814 DEFAULT_ADD_HHLEN,"Option add_hhlen is");
7815 IGNORE_PARAM_NEQ(fake_ll, 0, 0,"Option fake_ll is");
Linus Torvalds1da177e2005-04-16 15:20:36 -07007816}
7817
7818
7819static int
Frank Pavlic05e08a22005-05-12 20:39:09 +02007820__qeth_set_online(struct ccwgroup_device *gdev, int recovery_mode)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007821{
7822 struct qeth_card *card = gdev->dev.driver_data;
7823 int rc = 0;
7824 enum qeth_card_states recover_flag;
7825
7826 BUG_ON(!card);
7827 QETH_DBF_TEXT(setup ,2, "setonlin");
7828 QETH_DBF_HEX(setup, 2, &card, sizeof(void *));
7829
7830 qeth_set_allowed_threads(card, QETH_RECOVER_THREAD, 1);
7831 if (qeth_wait_for_threads(card, ~QETH_RECOVER_THREAD)){
7832 PRINT_WARN("set_online of card %s interrupted by user!\n",
7833 CARD_BUS_ID(card));
7834 return -ERESTARTSYS;
7835 }
7836
7837 recover_flag = card->state;
7838 if ((rc = ccw_device_set_online(CARD_RDEV(card))) ||
7839 (rc = ccw_device_set_online(CARD_WDEV(card))) ||
7840 (rc = ccw_device_set_online(CARD_DDEV(card)))){
7841 QETH_DBF_TEXT_(setup, 2, "1err%d", rc);
7842 return -EIO;
7843 }
7844
Ursula Braun500f83a2005-09-30 10:19:19 +02007845 qeth_make_parameters_consistent(card);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007846
7847 if ((rc = qeth_hardsetup_card(card))){
7848 QETH_DBF_TEXT_(setup, 2, "2err%d", rc);
7849 goto out_remove;
7850 }
7851 card->state = CARD_STATE_HARDSETUP;
7852
7853 if (!(rc = qeth_query_ipassists(card,QETH_PROT_IPV4)))
7854 rc = qeth_get_unique_id(card);
7855
7856 if (rc && card->options.layer2 == 0) {
7857 QETH_DBF_TEXT_(setup, 2, "3err%d", rc);
7858 goto out_remove;
7859 }
7860 qeth_print_status_message(card);
7861 if ((rc = qeth_register_netdev(card))){
7862 QETH_DBF_TEXT_(setup, 2, "4err%d", rc);
7863 goto out_remove;
7864 }
7865 if ((rc = qeth_softsetup_card(card))){
7866 QETH_DBF_TEXT_(setup, 2, "5err%d", rc);
7867 goto out_remove;
7868 }
7869 card->state = CARD_STATE_SOFTSETUP;
7870
7871 if ((rc = qeth_init_qdio_queues(card))){
7872 QETH_DBF_TEXT_(setup, 2, "6err%d", rc);
7873 goto out_remove;
7874 }
Frank Pavlic4965e972005-12-13 08:22:30 +01007875 netif_carrier_on(card->dev);
7876
Linus Torvalds1da177e2005-04-16 15:20:36 -07007877 qeth_set_allowed_threads(card, 0xffffffff, 0);
7878 if (recover_flag == CARD_STATE_RECOVER)
Frank Pavlic05e08a22005-05-12 20:39:09 +02007879 qeth_start_again(card, recovery_mode);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007880 qeth_notify_processes();
7881 return 0;
7882out_remove:
7883 card->use_hard_stop = 1;
Frank Pavlic05e08a22005-05-12 20:39:09 +02007884 qeth_stop_card(card, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007885 ccw_device_set_offline(CARD_DDEV(card));
7886 ccw_device_set_offline(CARD_WDEV(card));
7887 ccw_device_set_offline(CARD_RDEV(card));
7888 if (recover_flag == CARD_STATE_RECOVER)
7889 card->state = CARD_STATE_RECOVER;
7890 else
7891 card->state = CARD_STATE_DOWN;
7892 return -ENODEV;
7893}
7894
Frank Pavlic05e08a22005-05-12 20:39:09 +02007895static int
7896qeth_set_online(struct ccwgroup_device *gdev)
7897{
7898 return __qeth_set_online(gdev, 0);
7899}
7900
Linus Torvalds1da177e2005-04-16 15:20:36 -07007901static struct ccw_device_id qeth_ids[] = {
7902 {CCW_DEVICE(0x1731, 0x01), driver_info:QETH_CARD_TYPE_OSAE},
7903 {CCW_DEVICE(0x1731, 0x05), driver_info:QETH_CARD_TYPE_IQD},
Ursula Braun500f83a2005-09-30 10:19:19 +02007904 {CCW_DEVICE(0x1731, 0x06), driver_info:QETH_CARD_TYPE_OSN},
Linus Torvalds1da177e2005-04-16 15:20:36 -07007905 {},
7906};
7907MODULE_DEVICE_TABLE(ccw, qeth_ids);
7908
7909struct device *qeth_root_dev = NULL;
7910
7911struct ccwgroup_driver qeth_ccwgroup_driver = {
7912 .owner = THIS_MODULE,
7913 .name = "qeth",
7914 .driver_id = 0xD8C5E3C8,
7915 .probe = qeth_probe_device,
7916 .remove = qeth_remove_device,
7917 .set_online = qeth_set_online,
7918 .set_offline = qeth_set_offline,
7919};
7920
7921struct ccw_driver qeth_ccw_driver = {
7922 .name = "qeth",
7923 .ids = qeth_ids,
7924 .probe = ccwgroup_probe_ccwdev,
7925 .remove = ccwgroup_remove_ccwdev,
7926};
7927
7928
7929static void
7930qeth_unregister_dbf_views(void)
7931{
7932 if (qeth_dbf_setup)
7933 debug_unregister(qeth_dbf_setup);
7934 if (qeth_dbf_qerr)
7935 debug_unregister(qeth_dbf_qerr);
7936 if (qeth_dbf_sense)
7937 debug_unregister(qeth_dbf_sense);
7938 if (qeth_dbf_misc)
7939 debug_unregister(qeth_dbf_misc);
7940 if (qeth_dbf_data)
7941 debug_unregister(qeth_dbf_data);
7942 if (qeth_dbf_control)
7943 debug_unregister(qeth_dbf_control);
7944 if (qeth_dbf_trace)
7945 debug_unregister(qeth_dbf_trace);
7946}
7947static int
7948qeth_register_dbf_views(void)
7949{
7950 qeth_dbf_setup = debug_register(QETH_DBF_SETUP_NAME,
Michael Holzheu66a464d2005-06-25 14:55:33 -07007951 QETH_DBF_SETUP_PAGES,
Linus Torvalds1da177e2005-04-16 15:20:36 -07007952 QETH_DBF_SETUP_NR_AREAS,
7953 QETH_DBF_SETUP_LEN);
7954 qeth_dbf_misc = debug_register(QETH_DBF_MISC_NAME,
Michael Holzheu66a464d2005-06-25 14:55:33 -07007955 QETH_DBF_MISC_PAGES,
Linus Torvalds1da177e2005-04-16 15:20:36 -07007956 QETH_DBF_MISC_NR_AREAS,
7957 QETH_DBF_MISC_LEN);
7958 qeth_dbf_data = debug_register(QETH_DBF_DATA_NAME,
Michael Holzheu66a464d2005-06-25 14:55:33 -07007959 QETH_DBF_DATA_PAGES,
Linus Torvalds1da177e2005-04-16 15:20:36 -07007960 QETH_DBF_DATA_NR_AREAS,
7961 QETH_DBF_DATA_LEN);
7962 qeth_dbf_control = debug_register(QETH_DBF_CONTROL_NAME,
Michael Holzheu66a464d2005-06-25 14:55:33 -07007963 QETH_DBF_CONTROL_PAGES,
Linus Torvalds1da177e2005-04-16 15:20:36 -07007964 QETH_DBF_CONTROL_NR_AREAS,
7965 QETH_DBF_CONTROL_LEN);
7966 qeth_dbf_sense = debug_register(QETH_DBF_SENSE_NAME,
Michael Holzheu66a464d2005-06-25 14:55:33 -07007967 QETH_DBF_SENSE_PAGES,
Linus Torvalds1da177e2005-04-16 15:20:36 -07007968 QETH_DBF_SENSE_NR_AREAS,
7969 QETH_DBF_SENSE_LEN);
7970 qeth_dbf_qerr = debug_register(QETH_DBF_QERR_NAME,
Michael Holzheu66a464d2005-06-25 14:55:33 -07007971 QETH_DBF_QERR_PAGES,
Linus Torvalds1da177e2005-04-16 15:20:36 -07007972 QETH_DBF_QERR_NR_AREAS,
7973 QETH_DBF_QERR_LEN);
7974 qeth_dbf_trace = debug_register(QETH_DBF_TRACE_NAME,
Michael Holzheu66a464d2005-06-25 14:55:33 -07007975 QETH_DBF_TRACE_PAGES,
Linus Torvalds1da177e2005-04-16 15:20:36 -07007976 QETH_DBF_TRACE_NR_AREAS,
7977 QETH_DBF_TRACE_LEN);
7978
7979 if ((qeth_dbf_setup == NULL) || (qeth_dbf_misc == NULL) ||
7980 (qeth_dbf_data == NULL) || (qeth_dbf_control == NULL) ||
7981 (qeth_dbf_sense == NULL) || (qeth_dbf_qerr == NULL) ||
7982 (qeth_dbf_trace == NULL)) {
7983 qeth_unregister_dbf_views();
7984 return -ENOMEM;
7985 }
7986 debug_register_view(qeth_dbf_setup, &debug_hex_ascii_view);
7987 debug_set_level(qeth_dbf_setup, QETH_DBF_SETUP_LEVEL);
7988
7989 debug_register_view(qeth_dbf_misc, &debug_hex_ascii_view);
7990 debug_set_level(qeth_dbf_misc, QETH_DBF_MISC_LEVEL);
7991
7992 debug_register_view(qeth_dbf_data, &debug_hex_ascii_view);
7993 debug_set_level(qeth_dbf_data, QETH_DBF_DATA_LEVEL);
7994
7995 debug_register_view(qeth_dbf_control, &debug_hex_ascii_view);
7996 debug_set_level(qeth_dbf_control, QETH_DBF_CONTROL_LEVEL);
7997
7998 debug_register_view(qeth_dbf_sense, &debug_hex_ascii_view);
7999 debug_set_level(qeth_dbf_sense, QETH_DBF_SENSE_LEVEL);
8000
8001 debug_register_view(qeth_dbf_qerr, &debug_hex_ascii_view);
8002 debug_set_level(qeth_dbf_qerr, QETH_DBF_QERR_LEVEL);
8003
8004 debug_register_view(qeth_dbf_trace, &debug_hex_ascii_view);
8005 debug_set_level(qeth_dbf_trace, QETH_DBF_TRACE_LEVEL);
8006
8007 return 0;
8008}
8009
8010#ifdef CONFIG_QETH_IPV6
8011extern struct neigh_table arp_tbl;
8012static struct neigh_ops *arp_direct_ops;
8013static int (*qeth_old_arp_constructor) (struct neighbour *);
8014
8015static struct neigh_ops arp_direct_ops_template = {
8016 .family = AF_INET,
8017 .destructor = NULL,
8018 .solicit = NULL,
8019 .error_report = NULL,
8020 .output = dev_queue_xmit,
8021 .connected_output = dev_queue_xmit,
8022 .hh_output = dev_queue_xmit,
8023 .queue_xmit = dev_queue_xmit
8024};
8025
8026static int
8027qeth_arp_constructor(struct neighbour *neigh)
8028{
8029 struct net_device *dev = neigh->dev;
8030 struct in_device *in_dev;
8031 struct neigh_parms *parms;
8032 struct qeth_card *card;
8033
8034 card = qeth_get_card_from_dev(dev);
8035 if (card == NULL)
8036 goto out;
8037 if((card->options.layer2) ||
8038 (card->dev->hard_header == qeth_fake_header))
8039 goto out;
8040
8041 rcu_read_lock();
Herbert Xue5ed6392005-10-03 14:35:55 -07008042 in_dev = __in_dev_get_rcu(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07008043 if (in_dev == NULL) {
8044 rcu_read_unlock();
8045 return -EINVAL;
8046 }
8047
8048 parms = in_dev->arp_parms;
8049 __neigh_parms_put(neigh->parms);
8050 neigh->parms = neigh_parms_clone(parms);
8051 rcu_read_unlock();
8052
8053 neigh->type = inet_addr_type(*(u32 *) neigh->primary_key);
8054 neigh->nud_state = NUD_NOARP;
8055 neigh->ops = arp_direct_ops;
8056 neigh->output = neigh->ops->queue_xmit;
8057 return 0;
8058out:
8059 return qeth_old_arp_constructor(neigh);
8060}
8061#endif /*CONFIG_QETH_IPV6*/
8062
8063/*
8064 * IP address takeover related functions
8065 */
8066static void
8067qeth_clear_ipato_list(struct qeth_card *card)
8068{
8069 struct qeth_ipato_entry *ipatoe, *tmp;
8070 unsigned long flags;
8071
8072 spin_lock_irqsave(&card->ip_lock, flags);
8073 list_for_each_entry_safe(ipatoe, tmp, &card->ipato.entries, entry) {
8074 list_del(&ipatoe->entry);
8075 kfree(ipatoe);
8076 }
8077 spin_unlock_irqrestore(&card->ip_lock, flags);
8078}
8079
8080int
8081qeth_add_ipato_entry(struct qeth_card *card, struct qeth_ipato_entry *new)
8082{
8083 struct qeth_ipato_entry *ipatoe;
8084 unsigned long flags;
8085 int rc = 0;
8086
8087 QETH_DBF_TEXT(trace, 2, "addipato");
8088 spin_lock_irqsave(&card->ip_lock, flags);
8089 list_for_each_entry(ipatoe, &card->ipato.entries, entry){
8090 if (ipatoe->proto != new->proto)
8091 continue;
8092 if (!memcmp(ipatoe->addr, new->addr,
8093 (ipatoe->proto == QETH_PROT_IPV4)? 4:16) &&
8094 (ipatoe->mask_bits == new->mask_bits)){
8095 PRINT_WARN("ipato entry already exists!\n");
8096 rc = -EEXIST;
8097 break;
8098 }
8099 }
8100 if (!rc) {
8101 list_add_tail(&new->entry, &card->ipato.entries);
8102 }
8103 spin_unlock_irqrestore(&card->ip_lock, flags);
8104 return rc;
8105}
8106
8107void
8108qeth_del_ipato_entry(struct qeth_card *card, enum qeth_prot_versions proto,
8109 u8 *addr, int mask_bits)
8110{
8111 struct qeth_ipato_entry *ipatoe, *tmp;
8112 unsigned long flags;
8113
8114 QETH_DBF_TEXT(trace, 2, "delipato");
8115 spin_lock_irqsave(&card->ip_lock, flags);
8116 list_for_each_entry_safe(ipatoe, tmp, &card->ipato.entries, entry){
8117 if (ipatoe->proto != proto)
8118 continue;
8119 if (!memcmp(ipatoe->addr, addr,
8120 (proto == QETH_PROT_IPV4)? 4:16) &&
8121 (ipatoe->mask_bits == mask_bits)){
8122 list_del(&ipatoe->entry);
8123 kfree(ipatoe);
8124 }
8125 }
8126 spin_unlock_irqrestore(&card->ip_lock, flags);
8127}
8128
8129static inline void
8130qeth_convert_addr_to_bits(u8 *addr, u8 *bits, int len)
8131{
8132 int i, j;
8133 u8 octet;
8134
8135 for (i = 0; i < len; ++i){
8136 octet = addr[i];
8137 for (j = 7; j >= 0; --j){
8138 bits[i*8 + j] = octet & 1;
8139 octet >>= 1;
8140 }
8141 }
8142}
8143
8144static int
8145qeth_is_addr_covered_by_ipato(struct qeth_card *card, struct qeth_ipaddr *addr)
8146{
8147 struct qeth_ipato_entry *ipatoe;
8148 u8 addr_bits[128] = {0, };
8149 u8 ipatoe_bits[128] = {0, };
8150 int rc = 0;
8151
8152 if (!card->ipato.enabled)
8153 return 0;
8154
8155 qeth_convert_addr_to_bits((u8 *) &addr->u, addr_bits,
8156 (addr->proto == QETH_PROT_IPV4)? 4:16);
8157 list_for_each_entry(ipatoe, &card->ipato.entries, entry){
8158 if (addr->proto != ipatoe->proto)
8159 continue;
8160 qeth_convert_addr_to_bits(ipatoe->addr, ipatoe_bits,
8161 (ipatoe->proto==QETH_PROT_IPV4) ?
8162 4:16);
8163 if (addr->proto == QETH_PROT_IPV4)
8164 rc = !memcmp(addr_bits, ipatoe_bits,
8165 min(32, ipatoe->mask_bits));
8166 else
8167 rc = !memcmp(addr_bits, ipatoe_bits,
8168 min(128, ipatoe->mask_bits));
8169 if (rc)
8170 break;
8171 }
8172 /* invert? */
8173 if ((addr->proto == QETH_PROT_IPV4) && card->ipato.invert4)
8174 rc = !rc;
8175 else if ((addr->proto == QETH_PROT_IPV6) && card->ipato.invert6)
8176 rc = !rc;
8177
8178 return rc;
8179}
8180
8181/*
8182 * VIPA related functions
8183 */
8184int
8185qeth_add_vipa(struct qeth_card *card, enum qeth_prot_versions proto,
8186 const u8 *addr)
8187{
8188 struct qeth_ipaddr *ipaddr;
8189 unsigned long flags;
8190 int rc = 0;
8191
8192 ipaddr = qeth_get_addr_buffer(proto);
8193 if (ipaddr){
8194 if (proto == QETH_PROT_IPV4){
8195 QETH_DBF_TEXT(trace, 2, "addvipa4");
8196 memcpy(&ipaddr->u.a4.addr, addr, 4);
8197 ipaddr->u.a4.mask = 0;
8198#ifdef CONFIG_QETH_IPV6
8199 } else if (proto == QETH_PROT_IPV6){
8200 QETH_DBF_TEXT(trace, 2, "addvipa6");
8201 memcpy(&ipaddr->u.a6.addr, addr, 16);
8202 ipaddr->u.a6.pfxlen = 0;
8203#endif
8204 }
8205 ipaddr->type = QETH_IP_TYPE_VIPA;
8206 ipaddr->set_flags = QETH_IPA_SETIP_VIPA_FLAG;
8207 ipaddr->del_flags = QETH_IPA_DELIP_VIPA_FLAG;
8208 } else
8209 return -ENOMEM;
8210 spin_lock_irqsave(&card->ip_lock, flags);
8211 if (__qeth_address_exists_in_list(&card->ip_list, ipaddr, 0) ||
8212 __qeth_address_exists_in_list(card->ip_tbd_list, ipaddr, 0))
8213 rc = -EEXIST;
8214 spin_unlock_irqrestore(&card->ip_lock, flags);
8215 if (rc){
8216 PRINT_WARN("Cannot add VIPA. Address already exists!\n");
8217 return rc;
8218 }
8219 if (!qeth_add_ip(card, ipaddr))
8220 kfree(ipaddr);
8221 if (qeth_set_thread_start_bit(card, QETH_SET_IP_THREAD) == 0)
8222 schedule_work(&card->kernel_thread_starter);
8223 return rc;
8224}
8225
8226void
8227qeth_del_vipa(struct qeth_card *card, enum qeth_prot_versions proto,
8228 const u8 *addr)
8229{
8230 struct qeth_ipaddr *ipaddr;
8231
8232 ipaddr = qeth_get_addr_buffer(proto);
8233 if (ipaddr){
8234 if (proto == QETH_PROT_IPV4){
8235 QETH_DBF_TEXT(trace, 2, "delvipa4");
8236 memcpy(&ipaddr->u.a4.addr, addr, 4);
8237 ipaddr->u.a4.mask = 0;
8238#ifdef CONFIG_QETH_IPV6
8239 } else if (proto == QETH_PROT_IPV6){
8240 QETH_DBF_TEXT(trace, 2, "delvipa6");
8241 memcpy(&ipaddr->u.a6.addr, addr, 16);
8242 ipaddr->u.a6.pfxlen = 0;
8243#endif
8244 }
8245 ipaddr->type = QETH_IP_TYPE_VIPA;
8246 } else
8247 return;
8248 if (!qeth_delete_ip(card, ipaddr))
8249 kfree(ipaddr);
8250 if (qeth_set_thread_start_bit(card, QETH_SET_IP_THREAD) == 0)
8251 schedule_work(&card->kernel_thread_starter);
8252}
8253
8254/*
8255 * proxy ARP related functions
8256 */
8257int
8258qeth_add_rxip(struct qeth_card *card, enum qeth_prot_versions proto,
8259 const u8 *addr)
8260{
8261 struct qeth_ipaddr *ipaddr;
8262 unsigned long flags;
8263 int rc = 0;
8264
8265 ipaddr = qeth_get_addr_buffer(proto);
8266 if (ipaddr){
8267 if (proto == QETH_PROT_IPV4){
8268 QETH_DBF_TEXT(trace, 2, "addrxip4");
8269 memcpy(&ipaddr->u.a4.addr, addr, 4);
8270 ipaddr->u.a4.mask = 0;
8271#ifdef CONFIG_QETH_IPV6
8272 } else if (proto == QETH_PROT_IPV6){
8273 QETH_DBF_TEXT(trace, 2, "addrxip6");
8274 memcpy(&ipaddr->u.a6.addr, addr, 16);
8275 ipaddr->u.a6.pfxlen = 0;
8276#endif
8277 }
8278 ipaddr->type = QETH_IP_TYPE_RXIP;
8279 ipaddr->set_flags = QETH_IPA_SETIP_TAKEOVER_FLAG;
8280 ipaddr->del_flags = 0;
8281 } else
8282 return -ENOMEM;
8283 spin_lock_irqsave(&card->ip_lock, flags);
8284 if (__qeth_address_exists_in_list(&card->ip_list, ipaddr, 0) ||
8285 __qeth_address_exists_in_list(card->ip_tbd_list, ipaddr, 0))
8286 rc = -EEXIST;
8287 spin_unlock_irqrestore(&card->ip_lock, flags);
8288 if (rc){
8289 PRINT_WARN("Cannot add RXIP. Address already exists!\n");
8290 return rc;
8291 }
8292 if (!qeth_add_ip(card, ipaddr))
8293 kfree(ipaddr);
8294 if (qeth_set_thread_start_bit(card, QETH_SET_IP_THREAD) == 0)
8295 schedule_work(&card->kernel_thread_starter);
8296 return 0;
8297}
8298
8299void
8300qeth_del_rxip(struct qeth_card *card, enum qeth_prot_versions proto,
8301 const u8 *addr)
8302{
8303 struct qeth_ipaddr *ipaddr;
8304
8305 ipaddr = qeth_get_addr_buffer(proto);
8306 if (ipaddr){
8307 if (proto == QETH_PROT_IPV4){
8308 QETH_DBF_TEXT(trace, 2, "addrxip4");
8309 memcpy(&ipaddr->u.a4.addr, addr, 4);
8310 ipaddr->u.a4.mask = 0;
8311#ifdef CONFIG_QETH_IPV6
8312 } else if (proto == QETH_PROT_IPV6){
8313 QETH_DBF_TEXT(trace, 2, "addrxip6");
8314 memcpy(&ipaddr->u.a6.addr, addr, 16);
8315 ipaddr->u.a6.pfxlen = 0;
8316#endif
8317 }
8318 ipaddr->type = QETH_IP_TYPE_RXIP;
8319 } else
8320 return;
8321 if (!qeth_delete_ip(card, ipaddr))
8322 kfree(ipaddr);
8323 if (qeth_set_thread_start_bit(card, QETH_SET_IP_THREAD) == 0)
8324 schedule_work(&card->kernel_thread_starter);
8325}
8326
8327/**
8328 * IP event handler
8329 */
8330static int
8331qeth_ip_event(struct notifier_block *this,
8332 unsigned long event,void *ptr)
8333{
8334 struct in_ifaddr *ifa = (struct in_ifaddr *)ptr;
8335 struct net_device *dev =(struct net_device *) ifa->ifa_dev->dev;
8336 struct qeth_ipaddr *addr;
8337 struct qeth_card *card;
8338
8339 QETH_DBF_TEXT(trace,3,"ipevent");
8340 card = qeth_get_card_from_dev(dev);
8341 if (!card)
8342 return NOTIFY_DONE;
8343 if (card->options.layer2)
8344 return NOTIFY_DONE;
8345
8346 addr = qeth_get_addr_buffer(QETH_PROT_IPV4);
8347 if (addr != NULL) {
8348 addr->u.a4.addr = ifa->ifa_address;
8349 addr->u.a4.mask = ifa->ifa_mask;
8350 addr->type = QETH_IP_TYPE_NORMAL;
8351 } else
8352 goto out;
8353
8354 switch(event) {
8355 case NETDEV_UP:
8356 if (!qeth_add_ip(card, addr))
8357 kfree(addr);
8358 break;
8359 case NETDEV_DOWN:
8360 if (!qeth_delete_ip(card, addr))
8361 kfree(addr);
8362 break;
8363 default:
8364 break;
8365 }
8366 if (qeth_set_thread_start_bit(card, QETH_SET_IP_THREAD) == 0)
8367 schedule_work(&card->kernel_thread_starter);
8368out:
8369 return NOTIFY_DONE;
8370}
8371
8372static struct notifier_block qeth_ip_notifier = {
8373 qeth_ip_event,
8374 0
8375};
8376
8377#ifdef CONFIG_QETH_IPV6
8378/**
8379 * IPv6 event handler
8380 */
8381static int
8382qeth_ip6_event(struct notifier_block *this,
8383 unsigned long event,void *ptr)
8384{
8385
8386 struct inet6_ifaddr *ifa = (struct inet6_ifaddr *)ptr;
8387 struct net_device *dev = (struct net_device *)ifa->idev->dev;
8388 struct qeth_ipaddr *addr;
8389 struct qeth_card *card;
8390
8391 QETH_DBF_TEXT(trace,3,"ip6event");
8392
8393 card = qeth_get_card_from_dev(dev);
8394 if (!card)
8395 return NOTIFY_DONE;
8396 if (!qeth_is_supported(card, IPA_IPV6))
8397 return NOTIFY_DONE;
8398
8399 addr = qeth_get_addr_buffer(QETH_PROT_IPV6);
8400 if (addr != NULL) {
8401 memcpy(&addr->u.a6.addr, &ifa->addr, sizeof(struct in6_addr));
8402 addr->u.a6.pfxlen = ifa->prefix_len;
8403 addr->type = QETH_IP_TYPE_NORMAL;
8404 } else
8405 goto out;
8406
8407 switch(event) {
8408 case NETDEV_UP:
8409 if (!qeth_add_ip(card, addr))
8410 kfree(addr);
8411 break;
8412 case NETDEV_DOWN:
8413 if (!qeth_delete_ip(card, addr))
8414 kfree(addr);
8415 break;
8416 default:
8417 break;
8418 }
8419 if (qeth_set_thread_start_bit(card, QETH_SET_IP_THREAD) == 0)
8420 schedule_work(&card->kernel_thread_starter);
8421out:
8422 return NOTIFY_DONE;
8423}
8424
8425static struct notifier_block qeth_ip6_notifier = {
8426 qeth_ip6_event,
8427 0
8428};
8429#endif
8430
8431static int
Cornelia Huck66aea232005-08-08 09:22:36 -07008432__qeth_reboot_event_card(struct device *dev, void *data)
8433{
8434 struct qeth_card *card;
8435
8436 card = (struct qeth_card *) dev->driver_data;
8437 qeth_clear_ip_list(card, 0, 0);
8438 qeth_qdio_clear_card(card, 0);
8439 return 0;
8440}
8441
8442static int
Linus Torvalds1da177e2005-04-16 15:20:36 -07008443qeth_reboot_event(struct notifier_block *this, unsigned long event, void *ptr)
8444{
8445
Cornelia Huck66aea232005-08-08 09:22:36 -07008446 driver_for_each_device(&qeth_ccwgroup_driver.driver, NULL, NULL,
8447 __qeth_reboot_event_card);
Linus Torvalds1da177e2005-04-16 15:20:36 -07008448 return NOTIFY_DONE;
8449}
8450
8451
8452static struct notifier_block qeth_reboot_notifier = {
8453 qeth_reboot_event,
8454 0
8455};
8456
8457static int
8458qeth_register_notifiers(void)
8459{
8460 int r;
8461
8462 QETH_DBF_TEXT(trace,5,"regnotif");
8463 if ((r = register_reboot_notifier(&qeth_reboot_notifier)))
8464 return r;
8465 if ((r = register_inetaddr_notifier(&qeth_ip_notifier)))
8466 goto out_reboot;
8467#ifdef CONFIG_QETH_IPV6
8468 if ((r = register_inet6addr_notifier(&qeth_ip6_notifier)))
8469 goto out_ipv4;
8470#endif
8471 return 0;
8472
8473#ifdef CONFIG_QETH_IPV6
8474out_ipv4:
8475 unregister_inetaddr_notifier(&qeth_ip_notifier);
8476#endif
8477out_reboot:
8478 unregister_reboot_notifier(&qeth_reboot_notifier);
8479 return r;
8480}
8481
8482/**
8483 * unregister all event notifiers
8484 */
8485static void
8486qeth_unregister_notifiers(void)
8487{
8488
8489 QETH_DBF_TEXT(trace,5,"unregnot");
8490 BUG_ON(unregister_reboot_notifier(&qeth_reboot_notifier));
8491 BUG_ON(unregister_inetaddr_notifier(&qeth_ip_notifier));
8492#ifdef CONFIG_QETH_IPV6
8493 BUG_ON(unregister_inet6addr_notifier(&qeth_ip6_notifier));
8494#endif /* QETH_IPV6 */
8495
8496}
8497
8498#ifdef CONFIG_QETH_IPV6
8499static int
8500qeth_ipv6_init(void)
8501{
8502 qeth_old_arp_constructor = arp_tbl.constructor;
8503 write_lock(&arp_tbl.lock);
8504 arp_tbl.constructor = qeth_arp_constructor;
8505 write_unlock(&arp_tbl.lock);
8506
8507 arp_direct_ops = (struct neigh_ops*)
8508 kmalloc(sizeof(struct neigh_ops), GFP_KERNEL);
8509 if (!arp_direct_ops)
8510 return -ENOMEM;
8511
8512 memcpy(arp_direct_ops, &arp_direct_ops_template,
8513 sizeof(struct neigh_ops));
8514
8515 return 0;
8516}
8517
8518static void
8519qeth_ipv6_uninit(void)
8520{
8521 write_lock(&arp_tbl.lock);
8522 arp_tbl.constructor = qeth_old_arp_constructor;
8523 write_unlock(&arp_tbl.lock);
8524 kfree(arp_direct_ops);
8525}
8526#endif /* CONFIG_QETH_IPV6 */
8527
8528static void
8529qeth_sysfs_unregister(void)
8530{
8531 qeth_remove_driver_attributes();
8532 ccw_driver_unregister(&qeth_ccw_driver);
8533 ccwgroup_driver_unregister(&qeth_ccwgroup_driver);
8534 s390_root_dev_unregister(qeth_root_dev);
8535}
8536/**
8537 * register qeth at sysfs
8538 */
8539static int
8540qeth_sysfs_register(void)
8541{
8542 int rc=0;
8543
8544 rc = ccwgroup_driver_register(&qeth_ccwgroup_driver);
8545 if (rc)
8546 return rc;
8547 rc = ccw_driver_register(&qeth_ccw_driver);
8548 if (rc)
8549 return rc;
8550 rc = qeth_create_driver_attributes();
8551 if (rc)
8552 return rc;
8553 qeth_root_dev = s390_root_dev_register("qeth");
8554 if (IS_ERR(qeth_root_dev)) {
8555 rc = PTR_ERR(qeth_root_dev);
8556 return rc;
8557 }
8558 return 0;
8559}
8560
8561/***
8562 * init function
8563 */
8564static int __init
8565qeth_init(void)
8566{
8567 int rc=0;
8568
Heiko Carstense018ba12006-02-01 03:06:31 -08008569 PRINT_INFO("loading %s\n", version);
Linus Torvalds1da177e2005-04-16 15:20:36 -07008570
8571 INIT_LIST_HEAD(&qeth_card_list.list);
8572 INIT_LIST_HEAD(&qeth_notify_list);
8573 spin_lock_init(&qeth_notify_lock);
8574 rwlock_init(&qeth_card_list.rwlock);
8575
8576 if (qeth_register_dbf_views())
8577 goto out_err;
8578 if (qeth_sysfs_register())
8579 goto out_sysfs;
8580
8581#ifdef CONFIG_QETH_IPV6
8582 if (qeth_ipv6_init()) {
8583 PRINT_ERR("Out of memory during ipv6 init.\n");
8584 goto out_sysfs;
8585 }
8586#endif /* QETH_IPV6 */
8587 if (qeth_register_notifiers())
8588 goto out_ipv6;
8589 if (qeth_create_procfs_entries())
8590 goto out_notifiers;
8591
8592 return rc;
8593
8594out_notifiers:
8595 qeth_unregister_notifiers();
8596out_ipv6:
8597#ifdef CONFIG_QETH_IPV6
8598 qeth_ipv6_uninit();
8599#endif /* QETH_IPV6 */
8600out_sysfs:
8601 qeth_sysfs_unregister();
8602 qeth_unregister_dbf_views();
8603out_err:
8604 PRINT_ERR("Initialization failed");
8605 return rc;
8606}
8607
8608static void
8609__exit qeth_exit(void)
8610{
8611 struct qeth_card *card, *tmp;
8612 unsigned long flags;
8613
8614 QETH_DBF_TEXT(trace,1, "cleanup.");
8615
8616 /*
8617 * Weed would not need to clean up our devices here, because the
8618 * common device layer calls qeth_remove_device for each device
8619 * as soon as we unregister our driver (done in qeth_sysfs_unregister).
8620 * But we do cleanup here so we can do a "soft" shutdown of our cards.
8621 * qeth_remove_device called by the common device layer would otherwise
8622 * do a "hard" shutdown (card->use_hard_stop is set to one in
8623 * qeth_remove_device).
8624 */
8625again:
8626 read_lock_irqsave(&qeth_card_list.rwlock, flags);
8627 list_for_each_entry_safe(card, tmp, &qeth_card_list.list, list){
8628 read_unlock_irqrestore(&qeth_card_list.rwlock, flags);
8629 qeth_set_offline(card->gdev);
8630 qeth_remove_device(card->gdev);
8631 goto again;
8632 }
8633 read_unlock_irqrestore(&qeth_card_list.rwlock, flags);
8634#ifdef CONFIG_QETH_IPV6
8635 qeth_ipv6_uninit();
8636#endif
8637 qeth_unregister_notifiers();
8638 qeth_remove_procfs_entries();
8639 qeth_sysfs_unregister();
8640 qeth_unregister_dbf_views();
8641 printk("qeth: removed\n");
8642}
8643
Ursula Braun500f83a2005-09-30 10:19:19 +02008644EXPORT_SYMBOL(qeth_osn_register);
8645EXPORT_SYMBOL(qeth_osn_deregister);
8646EXPORT_SYMBOL(qeth_osn_assist);
Linus Torvalds1da177e2005-04-16 15:20:36 -07008647module_init(qeth_init);
8648module_exit(qeth_exit);
Frank Pavlic13877802005-11-10 13:51:42 +01008649MODULE_AUTHOR("Frank Pavlic <fpavlic@de.ibm.com>");
Linus Torvalds1da177e2005-04-16 15:20:36 -07008650MODULE_DESCRIPTION("Linux on zSeries OSA Express and HiperSockets support\n" \
8651 "Copyright 2000,2003 IBM Corporation\n");
8652
8653MODULE_LICENSE("GPL");