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