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