blob: 86b0c44165c198a73a3dc9fca8ef390aab71782a [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Heiko Carstense018ba12006-02-01 03:06:31 -08002 * linux/drivers/s390/net/qeth_main.c
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 *
4 * Linux on zSeries OSA Express and HiperSockets support
5 *
6 * Copyright 2000,2003 IBM Corporation
7 *
8 * Author(s): Original Code written by
9 * Utz Bacher (utz.bacher@de.ibm.com)
10 * Rewritten by
Frank Pavlic1387780f2005-11-10 13:51:42 +010011 * Frank Pavlic (fpavlic@de.ibm.com) and
Linus Torvalds1da177e2005-04-16 15:20:36 -070012 * Thomas Spatzier <tspat@de.ibm.com>
13 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070014 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2, or (at your option)
17 * any later version.
18 *
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, write to the Free Software
26 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27 */
28
Linus Torvalds1da177e2005-04-16 15:20:36 -070029
Linus Torvalds1da177e2005-04-16 15:20:36 -070030#include <linux/module.h>
31#include <linux/moduleparam.h>
32#include <linux/string.h>
33#include <linux/errno.h>
34#include <linux/mm.h>
35#include <linux/ip.h>
36#include <linux/inetdevice.h>
37#include <linux/netdevice.h>
38#include <linux/sched.h>
39#include <linux/workqueue.h>
40#include <linux/kernel.h>
41#include <linux/slab.h>
42#include <linux/interrupt.h>
43#include <linux/tcp.h>
44#include <linux/icmp.h>
45#include <linux/skbuff.h>
46#include <linux/in.h>
47#include <linux/igmp.h>
48#include <linux/init.h>
49#include <linux/reboot.h>
50#include <linux/mii.h>
51#include <linux/rcupdate.h>
52#include <linux/ethtool.h>
53
54#include <net/arp.h>
55#include <net/ip.h>
56#include <net/route.h>
57
58#include <asm/ebcdic.h>
59#include <asm/io.h>
60#include <asm/qeth.h>
61#include <asm/timex.h>
62#include <asm/semaphore.h>
63#include <asm/uaccess.h>
Carsten Ottecfb1b552006-01-06 00:19:14 -080064#include <asm/s390_rdev.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070065
66#include "qeth.h"
67#include "qeth_mpc.h"
68#include "qeth_fs.h"
69#include "qeth_eddp.h"
70#include "qeth_tso.h"
71
Linus Torvalds1da177e2005-04-16 15:20:36 -070072static const char *version = "qeth S/390 OSA-Express driver";
73
74/**
75 * Debug Facility Stuff
76 */
77static debug_info_t *qeth_dbf_setup = NULL;
78static debug_info_t *qeth_dbf_data = NULL;
79static debug_info_t *qeth_dbf_misc = NULL;
80static debug_info_t *qeth_dbf_control = NULL;
81debug_info_t *qeth_dbf_trace = NULL;
82static debug_info_t *qeth_dbf_sense = NULL;
83static debug_info_t *qeth_dbf_qerr = NULL;
84
85DEFINE_PER_CPU(char[256], qeth_dbf_txt_buf);
86
Heiko Carstens91ebe2a2006-07-03 00:25:26 -070087static struct lock_class_key qdio_out_skb_queue_key;
88
Linus Torvalds1da177e2005-04-16 15:20:36 -070089/**
90 * some more definitions and declarations
91 */
92static unsigned int known_devices[][10] = QETH_MODELLIST_ARRAY;
93
94/* list of our cards */
95struct qeth_card_list_struct qeth_card_list;
96/*process list want to be notified*/
97spinlock_t qeth_notify_lock;
98struct list_head qeth_notify_list;
99
100static void qeth_send_control_data_cb(struct qeth_channel *,
101 struct qeth_cmd_buffer *);
102
103/**
104 * here we go with function implementation
105 */
106static void
107qeth_init_qdio_info(struct qeth_card *card);
108
109static int
110qeth_init_qdio_queues(struct qeth_card *card);
111
112static int
113qeth_alloc_qdio_buffers(struct qeth_card *card);
114
115static void
116qeth_free_qdio_buffers(struct qeth_card *);
117
118static void
119qeth_clear_qdio_buffers(struct qeth_card *);
120
121static void
122qeth_clear_ip_list(struct qeth_card *, int, int);
123
124static void
125qeth_clear_ipacmd_list(struct qeth_card *);
126
127static int
128qeth_qdio_clear_card(struct qeth_card *, int);
129
130static void
131qeth_clear_working_pool_list(struct qeth_card *);
132
133static void
134qeth_clear_cmd_buffers(struct qeth_channel *);
135
136static int
137qeth_stop(struct net_device *);
138
139static void
140qeth_clear_ipato_list(struct qeth_card *);
141
142static int
143qeth_is_addr_covered_by_ipato(struct qeth_card *, struct qeth_ipaddr *);
144
145static void
146qeth_irq_tasklet(unsigned long);
147
148static int
149qeth_set_online(struct ccwgroup_device *);
150
Frank Pavlic05e08a22005-05-12 20:39:09 +0200151static int
152__qeth_set_online(struct ccwgroup_device *gdev, int recovery_mode);
153
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154static struct qeth_ipaddr *
155qeth_get_addr_buffer(enum qeth_prot_versions);
156
157static void
158qeth_set_multicast_list(struct net_device *);
159
160static void
Frank Pavlic6c951b92005-11-10 13:51:25 +0100161qeth_setadp_promisc_mode(struct qeth_card *);
162
163static void
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164qeth_notify_processes(void)
165{
166 /*notify all registered processes */
167 struct qeth_notify_list_struct *n_entry;
168
169 QETH_DBF_TEXT(trace,3,"procnoti");
170 spin_lock(&qeth_notify_lock);
171 list_for_each_entry(n_entry, &qeth_notify_list, list) {
172 send_sig(n_entry->signum, n_entry->task, 1);
173 }
174 spin_unlock(&qeth_notify_lock);
175
176}
177int
178qeth_notifier_unregister(struct task_struct *p)
179{
180 struct qeth_notify_list_struct *n_entry, *tmp;
181
182 QETH_DBF_TEXT(trace, 2, "notunreg");
183 spin_lock(&qeth_notify_lock);
184 list_for_each_entry_safe(n_entry, tmp, &qeth_notify_list, list) {
185 if (n_entry->task == p) {
186 list_del(&n_entry->list);
187 kfree(n_entry);
188 goto out;
189 }
190 }
191out:
192 spin_unlock(&qeth_notify_lock);
193 return 0;
194}
195int
196qeth_notifier_register(struct task_struct *p, int signum)
197{
198 struct qeth_notify_list_struct *n_entry;
199
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200 /*check first if entry already exists*/
201 spin_lock(&qeth_notify_lock);
202 list_for_each_entry(n_entry, &qeth_notify_list, list) {
203 if (n_entry->task == p) {
204 n_entry->signum = signum;
205 spin_unlock(&qeth_notify_lock);
206 return 0;
207 }
208 }
209 spin_unlock(&qeth_notify_lock);
210
211 n_entry = (struct qeth_notify_list_struct *)
212 kmalloc(sizeof(struct qeth_notify_list_struct),GFP_KERNEL);
213 if (!n_entry)
214 return -ENOMEM;
215 n_entry->task = p;
216 n_entry->signum = signum;
217 spin_lock(&qeth_notify_lock);
218 list_add(&n_entry->list,&qeth_notify_list);
219 spin_unlock(&qeth_notify_lock);
220 return 0;
221}
222
223
224/**
225 * free channel command buffers
226 */
227static void
228qeth_clean_channel(struct qeth_channel *channel)
229{
230 int cnt;
231
232 QETH_DBF_TEXT(setup, 2, "freech");
233 for (cnt = 0; cnt < QETH_CMD_BUFFER_NO; cnt++)
234 kfree(channel->iob[cnt].data);
235}
236
237/**
238 * free card
239 */
240static void
241qeth_free_card(struct qeth_card *card)
242{
243
244 QETH_DBF_TEXT(setup, 2, "freecrd");
245 QETH_DBF_HEX(setup, 2, &card, sizeof(void *));
246 qeth_clean_channel(&card->read);
247 qeth_clean_channel(&card->write);
248 if (card->dev)
249 free_netdev(card->dev);
250 qeth_clear_ip_list(card, 0, 0);
251 qeth_clear_ipato_list(card);
252 kfree(card->ip_tbd_list);
253 qeth_free_qdio_buffers(card);
254 kfree(card);
255}
256
257/**
258 * alloc memory for command buffer per channel
259 */
260static int
261qeth_setup_channel(struct qeth_channel *channel)
262{
263 int cnt;
264
265 QETH_DBF_TEXT(setup, 2, "setupch");
266 for (cnt=0; cnt < QETH_CMD_BUFFER_NO; cnt++) {
267 channel->iob[cnt].data = (char *)
268 kmalloc(QETH_BUFSIZE, GFP_DMA|GFP_KERNEL);
269 if (channel->iob[cnt].data == NULL)
270 break;
271 channel->iob[cnt].state = BUF_STATE_FREE;
272 channel->iob[cnt].channel = channel;
273 channel->iob[cnt].callback = qeth_send_control_data_cb;
274 channel->iob[cnt].rc = 0;
275 }
276 if (cnt < QETH_CMD_BUFFER_NO) {
277 while (cnt-- > 0)
278 kfree(channel->iob[cnt].data);
279 return -ENOMEM;
280 }
281 channel->buf_no = 0;
282 channel->io_buf_no = 0;
283 atomic_set(&channel->irq_pending, 0);
284 spin_lock_init(&channel->iob_lock);
285
286 init_waitqueue_head(&channel->wait_q);
287 channel->irq_tasklet.data = (unsigned long) channel;
288 channel->irq_tasklet.func = qeth_irq_tasklet;
289 return 0;
290}
291
292/**
293 * alloc memory for card structure
294 */
295static struct qeth_card *
296qeth_alloc_card(void)
297{
298 struct qeth_card *card;
299
300 QETH_DBF_TEXT(setup, 2, "alloccrd");
Eric Sesterhenn88abaab2006-03-24 03:15:31 -0800301 card = kzalloc(sizeof(struct qeth_card), GFP_DMA|GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302 if (!card)
303 return NULL;
304 QETH_DBF_HEX(setup, 2, &card, sizeof(void *));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305 if (qeth_setup_channel(&card->read)) {
306 kfree(card);
307 return NULL;
308 }
309 if (qeth_setup_channel(&card->write)) {
310 qeth_clean_channel(&card->read);
311 kfree(card);
312 return NULL;
313 }
314 return card;
315}
316
317static long
Cornelia Huck6c82a8a2007-05-04 18:47:52 +0200318__qeth_check_irb_error(struct ccw_device *cdev, unsigned long intparm,
319 struct irb *irb)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320{
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);
Cornelia Huck6c82a8a2007-05-04 18:47:52 +0200334 if (intparm == QETH_RCD_PARM) {
335 struct qeth_card *card = CARD_FROM_CDEV(cdev);
336
337 if (card && (card->data.ccwdev == cdev)) {
338 card->data.state = CH_STATE_DOWN;
339 wake_up(&card->wait_q);
340 }
341 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342 break;
343 default:
344 PRINT_WARN("unknown error %ld on device %s\n", PTR_ERR(irb),
345 cdev->dev.bus_id);
346 QETH_DBF_TEXT(trace, 2, "ckirberr");
347 QETH_DBF_TEXT(trace, 2, " rc???");
348 }
349 return PTR_ERR(irb);
350}
351
352static int
353qeth_get_problem(struct ccw_device *cdev, struct irb *irb)
354{
355 int dstat,cstat;
356 char *sense;
357
358 sense = (char *) irb->ecw;
359 cstat = irb->scsw.cstat;
360 dstat = irb->scsw.dstat;
361
362 if (cstat & (SCHN_STAT_CHN_CTRL_CHK | SCHN_STAT_INTF_CTRL_CHK |
363 SCHN_STAT_CHN_DATA_CHK | SCHN_STAT_CHAIN_CHECK |
364 SCHN_STAT_PROT_CHECK | SCHN_STAT_PROG_CHECK)) {
365 QETH_DBF_TEXT(trace,2, "CGENCHK");
366 PRINT_WARN("check on device %s, dstat=x%x, cstat=x%x ",
367 cdev->dev.bus_id, dstat, cstat);
368 HEXDUMP16(WARN, "irb: ", irb);
369 HEXDUMP16(WARN, "irb: ", ((char *) irb) + 32);
370 return 1;
371 }
372
373 if (dstat & DEV_STAT_UNIT_CHECK) {
374 if (sense[SENSE_RESETTING_EVENT_BYTE] &
375 SENSE_RESETTING_EVENT_FLAG) {
376 QETH_DBF_TEXT(trace,2,"REVIND");
377 return 1;
378 }
379 if (sense[SENSE_COMMAND_REJECT_BYTE] &
380 SENSE_COMMAND_REJECT_FLAG) {
381 QETH_DBF_TEXT(trace,2,"CMDREJi");
382 return 0;
383 }
384 if ((sense[2] == 0xaf) && (sense[3] == 0xfe)) {
385 QETH_DBF_TEXT(trace,2,"AFFE");
386 return 1;
387 }
388 if ((!sense[0]) && (!sense[1]) && (!sense[2]) && (!sense[3])) {
389 QETH_DBF_TEXT(trace,2,"ZEROSEN");
390 return 0;
391 }
392 QETH_DBF_TEXT(trace,2,"DGENCHK");
393 return 1;
394 }
395 return 0;
396}
397static int qeth_issue_next_read(struct qeth_card *);
398
399/**
400 * interrupt handler
401 */
402static void
403qeth_irq(struct ccw_device *cdev, unsigned long intparm, struct irb *irb)
404{
405 int rc;
406 int cstat,dstat;
407 struct qeth_cmd_buffer *buffer;
408 struct qeth_channel *channel;
409 struct qeth_card *card;
410
411 QETH_DBF_TEXT(trace,5,"irq");
412
Cornelia Huck6c82a8a2007-05-04 18:47:52 +0200413 if (__qeth_check_irb_error(cdev, intparm, irb))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414 return;
415 cstat = irb->scsw.cstat;
416 dstat = irb->scsw.dstat;
417
418 card = CARD_FROM_CDEV(cdev);
419 if (!card)
420 return;
421
422 if (card->read.ccwdev == cdev){
423 channel = &card->read;
424 QETH_DBF_TEXT(trace,5,"read");
425 } else if (card->write.ccwdev == cdev) {
426 channel = &card->write;
427 QETH_DBF_TEXT(trace,5,"write");
428 } else {
429 channel = &card->data;
430 QETH_DBF_TEXT(trace,5,"data");
431 }
432 atomic_set(&channel->irq_pending, 0);
433
434 if (irb->scsw.fctl & (SCSW_FCTL_CLEAR_FUNC))
435 channel->state = CH_STATE_STOPPED;
436
437 if (irb->scsw.fctl & (SCSW_FCTL_HALT_FUNC))
438 channel->state = CH_STATE_HALTED;
439
440 /*let's wake up immediately on data channel*/
Cornelia Huck6c82a8a2007-05-04 18:47:52 +0200441 if ((channel == &card->data) && (intparm != 0) &&
442 (intparm != QETH_RCD_PARM))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443 goto out;
444
445 if (intparm == QETH_CLEAR_CHANNEL_PARM) {
446 QETH_DBF_TEXT(trace, 6, "clrchpar");
447 /* we don't have to handle this further */
448 intparm = 0;
449 }
450 if (intparm == QETH_HALT_CHANNEL_PARM) {
451 QETH_DBF_TEXT(trace, 6, "hltchpar");
452 /* we don't have to handle this further */
453 intparm = 0;
454 }
455 if ((dstat & DEV_STAT_UNIT_EXCEP) ||
456 (dstat & DEV_STAT_UNIT_CHECK) ||
457 (cstat)) {
458 if (irb->esw.esw0.erw.cons) {
459 /* TODO: we should make this s390dbf */
460 PRINT_WARN("sense data available on channel %s.\n",
461 CHANNEL_ID(channel));
462 PRINT_WARN(" cstat 0x%X\n dstat 0x%X\n", cstat, dstat);
463 HEXDUMP16(WARN,"irb: ",irb);
464 HEXDUMP16(WARN,"sense data: ",irb->ecw);
465 }
Cornelia Huck6c82a8a2007-05-04 18:47:52 +0200466 if (intparm == QETH_RCD_PARM) {
467 channel->state = CH_STATE_DOWN;
468 goto out;
469 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470 rc = qeth_get_problem(cdev,irb);
471 if (rc) {
472 qeth_schedule_recovery(card);
473 goto out;
474 }
475 }
476
Cornelia Huck6c82a8a2007-05-04 18:47:52 +0200477 if (intparm == QETH_RCD_PARM) {
478 channel->state = CH_STATE_RCD_DONE;
479 goto out;
480 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481 if (intparm) {
482 buffer = (struct qeth_cmd_buffer *) __va((addr_t)intparm);
483 buffer->state = BUF_STATE_PROCESSED;
484 }
485 if (channel == &card->data)
486 return;
487
488 if (channel == &card->read &&
489 channel->state == CH_STATE_UP)
490 qeth_issue_next_read(card);
491
Frank Blaschkaee2db682007-01-08 17:30:11 +0100492 qeth_irq_tasklet((unsigned long)channel);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493 return;
494out:
495 wake_up(&card->wait_q);
496}
497
498/**
499 * tasklet function scheduled from irq handler
500 */
501static void
502qeth_irq_tasklet(unsigned long data)
503{
504 struct qeth_card *card;
505 struct qeth_channel *channel;
506 struct qeth_cmd_buffer *iob;
507 __u8 index;
508
509 QETH_DBF_TEXT(trace,5,"irqtlet");
510 channel = (struct qeth_channel *) data;
511 iob = channel->iob;
512 index = channel->buf_no;
513 card = CARD_FROM_CDEV(channel->ccwdev);
514 while (iob[index].state == BUF_STATE_PROCESSED) {
515 if (iob[index].callback !=NULL) {
516 iob[index].callback(channel,iob + index);
517 }
518 index = (index + 1) % QETH_CMD_BUFFER_NO;
519 }
520 channel->buf_no = index;
521 wake_up(&card->wait_q);
522}
523
Frank Pavlic05e08a22005-05-12 20:39:09 +0200524static int qeth_stop_card(struct qeth_card *, int);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525
526static int
Frank Pavlic05e08a22005-05-12 20:39:09 +0200527__qeth_set_offline(struct ccwgroup_device *cgdev, int recovery_mode)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528{
529 struct qeth_card *card = (struct qeth_card *) cgdev->dev.driver_data;
Ursula Braun9123e0d2005-09-30 10:17:24 +0200530 int rc = 0, rc2 = 0, rc3 = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531 enum qeth_card_states recover_flag;
532
533 QETH_DBF_TEXT(setup, 3, "setoffl");
534 QETH_DBF_HEX(setup, 3, &card, sizeof(void *));
Jeff Garzike82b0f22006-05-26 21:58:38 -0400535
Frank Pavlic66cc5d52006-02-07 17:04:38 +0100536 if (card->dev && netif_carrier_ok(card->dev))
537 netif_carrier_off(card->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538 recover_flag = card->state;
Frank Pavlic05e08a22005-05-12 20:39:09 +0200539 if (qeth_stop_card(card, recovery_mode) == -ERESTARTSYS){
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540 PRINT_WARN("Stopping card %s interrupted by user!\n",
541 CARD_BUS_ID(card));
542 return -ERESTARTSYS;
543 }
Ursula Braun9123e0d2005-09-30 10:17:24 +0200544 rc = ccw_device_set_offline(CARD_DDEV(card));
545 rc2 = ccw_device_set_offline(CARD_WDEV(card));
546 rc3 = ccw_device_set_offline(CARD_RDEV(card));
547 if (!rc)
548 rc = (rc2) ? rc2 : rc3;
549 if (rc)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550 QETH_DBF_TEXT_(setup, 2, "1err%d", rc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551 if (recover_flag == CARD_STATE_UP)
552 card->state = CARD_STATE_RECOVER;
553 qeth_notify_processes();
554 return 0;
555}
556
557static int
Frank Pavlic05e08a22005-05-12 20:39:09 +0200558qeth_set_offline(struct ccwgroup_device *cgdev)
559{
560 return __qeth_set_offline(cgdev, 0);
561}
562
563static int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564qeth_wait_for_threads(struct qeth_card *card, unsigned long threads);
565
566
567static void
568qeth_remove_device(struct ccwgroup_device *cgdev)
569{
570 struct qeth_card *card = (struct qeth_card *) cgdev->dev.driver_data;
571 unsigned long flags;
572
573 QETH_DBF_TEXT(setup, 3, "rmdev");
574 QETH_DBF_HEX(setup, 3, &card, sizeof(void *));
575
576 if (!card)
577 return;
578
579 if (qeth_wait_for_threads(card, 0xffffffff))
580 return;
581
582 if (cgdev->state == CCWGROUP_ONLINE){
583 card->use_hard_stop = 1;
584 qeth_set_offline(cgdev);
585 }
586 /* remove form our internal list */
587 write_lock_irqsave(&qeth_card_list.rwlock, flags);
588 list_del(&card->list);
589 write_unlock_irqrestore(&qeth_card_list.rwlock, flags);
590 if (card->dev)
591 unregister_netdev(card->dev);
592 qeth_remove_device_attributes(&cgdev->dev);
593 qeth_free_card(card);
594 cgdev->dev.driver_data = NULL;
595 put_device(&cgdev->dev);
596}
597
598static int
599qeth_register_addr_entry(struct qeth_card *, struct qeth_ipaddr *);
600static int
601qeth_deregister_addr_entry(struct qeth_card *, struct qeth_ipaddr *);
602
603/**
604 * Add/remove address to/from card's ip list, i.e. try to add or remove
605 * reference to/from an IP address that is already registered on the card.
606 * Returns:
607 * 0 address was on card and its reference count has been adjusted,
608 * but is still > 0, so nothing has to be done
609 * also returns 0 if card was not on card and the todo was to delete
610 * the address -> there is also nothing to be done
611 * 1 address was not on card and the todo is to add it to the card's ip
612 * list
613 * -1 address was on card and its reference count has been decremented
614 * to <= 0 by the todo -> address must be removed from card
615 */
616static int
617__qeth_ref_ip_on_card(struct qeth_card *card, struct qeth_ipaddr *todo,
618 struct qeth_ipaddr **__addr)
619{
620 struct qeth_ipaddr *addr;
621 int found = 0;
622
623 list_for_each_entry(addr, &card->ip_list, entry) {
Frank Pavlic6c88ad22005-11-10 13:49:28 +0100624 if (card->options.layer2) {
625 if ((addr->type == todo->type) &&
Jeff Garzike82b0f22006-05-26 21:58:38 -0400626 (memcmp(&addr->mac, &todo->mac,
Frank Pavlic6c88ad22005-11-10 13:49:28 +0100627 OSA_ADDR_LEN) == 0)) {
628 found = 1;
629 break;
630 }
631 continue;
Jeff Garzike82b0f22006-05-26 21:58:38 -0400632 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700633 if ((addr->proto == QETH_PROT_IPV4) &&
634 (todo->proto == QETH_PROT_IPV4) &&
635 (addr->type == todo->type) &&
636 (addr->u.a4.addr == todo->u.a4.addr) &&
Frank Pavlic6c88ad22005-11-10 13:49:28 +0100637 (addr->u.a4.mask == todo->u.a4.mask)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700638 found = 1;
639 break;
640 }
641 if ((addr->proto == QETH_PROT_IPV6) &&
642 (todo->proto == QETH_PROT_IPV6) &&
643 (addr->type == todo->type) &&
644 (addr->u.a6.pfxlen == todo->u.a6.pfxlen) &&
645 (memcmp(&addr->u.a6.addr, &todo->u.a6.addr,
Frank Pavlic6c88ad22005-11-10 13:49:28 +0100646 sizeof(struct in6_addr)) == 0)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647 found = 1;
648 break;
649 }
650 }
Frank Pavlic6c88ad22005-11-10 13:49:28 +0100651 if (found) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700652 addr->users += todo->users;
653 if (addr->users <= 0){
654 *__addr = addr;
655 return -1;
656 } else {
657 /* for VIPA and RXIP limit refcount to 1 */
658 if (addr->type != QETH_IP_TYPE_NORMAL)
659 addr->users = 1;
660 return 0;
661 }
662 }
Frank Pavlic6c88ad22005-11-10 13:49:28 +0100663 if (todo->users > 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700664 /* for VIPA and RXIP limit refcount to 1 */
665 if (todo->type != QETH_IP_TYPE_NORMAL)
666 todo->users = 1;
667 return 1;
668 } else
669 return 0;
670}
671
Heiko Carstens4d284ca2007-02-05 21:18:53 +0100672static int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673__qeth_address_exists_in_list(struct list_head *list, struct qeth_ipaddr *addr,
674 int same_type)
675{
676 struct qeth_ipaddr *tmp;
677
678 list_for_each_entry(tmp, list, entry) {
679 if ((tmp->proto == QETH_PROT_IPV4) &&
680 (addr->proto == QETH_PROT_IPV4) &&
681 ((same_type && (tmp->type == addr->type)) ||
682 (!same_type && (tmp->type != addr->type)) ) &&
683 (tmp->u.a4.addr == addr->u.a4.addr) ){
684 return 1;
685 }
686 if ((tmp->proto == QETH_PROT_IPV6) &&
687 (addr->proto == QETH_PROT_IPV6) &&
688 ((same_type && (tmp->type == addr->type)) ||
689 (!same_type && (tmp->type != addr->type)) ) &&
690 (memcmp(&tmp->u.a6.addr, &addr->u.a6.addr,
691 sizeof(struct in6_addr)) == 0) ) {
692 return 1;
693 }
694 }
695 return 0;
696}
697
698/*
699 * Add IP to be added to todo list. If there is already an "add todo"
700 * in this list we just incremenent the reference count.
701 * Returns 0 if we just incremented reference count.
702 */
703static int
704__qeth_insert_ip_todo(struct qeth_card *card, struct qeth_ipaddr *addr, int add)
705{
706 struct qeth_ipaddr *tmp, *t;
707 int found = 0;
708
709 list_for_each_entry_safe(tmp, t, card->ip_tbd_list, entry) {
710 if ((addr->type == QETH_IP_TYPE_DEL_ALL_MC) &&
711 (tmp->type == QETH_IP_TYPE_DEL_ALL_MC))
712 return 0;
Frank Pavlic6c88ad22005-11-10 13:49:28 +0100713 if (card->options.layer2) {
714 if ((tmp->type == addr->type) &&
715 (tmp->is_multicast == addr->is_multicast) &&
Jeff Garzike82b0f22006-05-26 21:58:38 -0400716 (memcmp(&tmp->mac, &addr->mac,
Frank Pavlic6c88ad22005-11-10 13:49:28 +0100717 OSA_ADDR_LEN) == 0)) {
718 found = 1;
719 break;
720 }
721 continue;
Jeff Garzike82b0f22006-05-26 21:58:38 -0400722 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700723 if ((tmp->proto == QETH_PROT_IPV4) &&
724 (addr->proto == QETH_PROT_IPV4) &&
725 (tmp->type == addr->type) &&
726 (tmp->is_multicast == addr->is_multicast) &&
727 (tmp->u.a4.addr == addr->u.a4.addr) &&
Frank Pavlic6c88ad22005-11-10 13:49:28 +0100728 (tmp->u.a4.mask == addr->u.a4.mask)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700729 found = 1;
730 break;
731 }
732 if ((tmp->proto == QETH_PROT_IPV6) &&
733 (addr->proto == QETH_PROT_IPV6) &&
734 (tmp->type == addr->type) &&
735 (tmp->is_multicast == addr->is_multicast) &&
736 (tmp->u.a6.pfxlen == addr->u.a6.pfxlen) &&
737 (memcmp(&tmp->u.a6.addr, &addr->u.a6.addr,
Frank Pavlic6c88ad22005-11-10 13:49:28 +0100738 sizeof(struct in6_addr)) == 0)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700739 found = 1;
740 break;
741 }
742 }
743 if (found){
744 if (addr->users != 0)
745 tmp->users += addr->users;
746 else
747 tmp->users += add? 1:-1;
Frank Pavlic6c88ad22005-11-10 13:49:28 +0100748 if (tmp->users == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700749 list_del(&tmp->entry);
750 kfree(tmp);
751 }
752 return 0;
753 } else {
754 if (addr->type == QETH_IP_TYPE_DEL_ALL_MC)
755 list_add(&addr->entry, card->ip_tbd_list);
756 else {
757 if (addr->users == 0)
758 addr->users += add? 1:-1;
759 if (add && (addr->type == QETH_IP_TYPE_NORMAL) &&
760 qeth_is_addr_covered_by_ipato(card, addr)){
761 QETH_DBF_TEXT(trace, 2, "tkovaddr");
762 addr->set_flags |= QETH_IPA_SETIP_TAKEOVER_FLAG;
763 }
764 list_add_tail(&addr->entry, card->ip_tbd_list);
765 }
766 return 1;
767 }
768}
769
770/**
771 * Remove IP address from list
772 */
773static int
774qeth_delete_ip(struct qeth_card *card, struct qeth_ipaddr *addr)
775{
776 unsigned long flags;
777 int rc = 0;
778
Frank Pavlic6c88ad22005-11-10 13:49:28 +0100779 QETH_DBF_TEXT(trace, 4, "delip");
780
781 if (card->options.layer2)
782 QETH_DBF_HEX(trace, 4, &addr->mac, 6);
783 else if (addr->proto == QETH_PROT_IPV4)
784 QETH_DBF_HEX(trace, 4, &addr->u.a4.addr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700785 else {
Frank Pavlic6c88ad22005-11-10 13:49:28 +0100786 QETH_DBF_HEX(trace, 4, &addr->u.a6.addr, 8);
787 QETH_DBF_HEX(trace, 4, ((char *)&addr->u.a6.addr) + 8, 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700788 }
789 spin_lock_irqsave(&card->ip_lock, flags);
790 rc = __qeth_insert_ip_todo(card, addr, 0);
791 spin_unlock_irqrestore(&card->ip_lock, flags);
792 return rc;
793}
794
795static int
796qeth_add_ip(struct qeth_card *card, struct qeth_ipaddr *addr)
797{
798 unsigned long flags;
799 int rc = 0;
800
Frank Pavlic6c88ad22005-11-10 13:49:28 +0100801 QETH_DBF_TEXT(trace, 4, "addip");
802 if (card->options.layer2)
803 QETH_DBF_HEX(trace, 4, &addr->mac, 6);
804 else if (addr->proto == QETH_PROT_IPV4)
805 QETH_DBF_HEX(trace, 4, &addr->u.a4.addr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700806 else {
Frank Pavlic6c88ad22005-11-10 13:49:28 +0100807 QETH_DBF_HEX(trace, 4, &addr->u.a6.addr, 8);
808 QETH_DBF_HEX(trace, 4, ((char *)&addr->u.a6.addr) + 8, 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700809 }
810 spin_lock_irqsave(&card->ip_lock, flags);
811 rc = __qeth_insert_ip_todo(card, addr, 1);
812 spin_unlock_irqrestore(&card->ip_lock, flags);
813 return rc;
814}
815
Heiko Carstens4d284ca2007-02-05 21:18:53 +0100816static void
Linus Torvalds1da177e2005-04-16 15:20:36 -0700817__qeth_delete_all_mc(struct qeth_card *card, unsigned long *flags)
818{
819 struct qeth_ipaddr *addr, *tmp;
820 int rc;
Frank Pavlicd805d7c2005-11-10 13:50:58 +0100821again:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700822 list_for_each_entry_safe(addr, tmp, &card->ip_list, entry) {
823 if (addr->is_multicast) {
824 spin_unlock_irqrestore(&card->ip_lock, *flags);
825 rc = qeth_deregister_addr_entry(card, addr);
826 spin_lock_irqsave(&card->ip_lock, *flags);
827 if (!rc) {
828 list_del(&addr->entry);
829 kfree(addr);
Frank Pavlicd805d7c2005-11-10 13:50:58 +0100830 goto again;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700831 }
832 }
833 }
834}
835
836static void
837qeth_set_ip_addr_list(struct qeth_card *card)
838{
839 struct list_head *tbd_list;
840 struct qeth_ipaddr *todo, *addr;
841 unsigned long flags;
842 int rc;
843
844 QETH_DBF_TEXT(trace, 2, "sdiplist");
845 QETH_DBF_HEX(trace, 2, &card, sizeof(void *));
846
847 spin_lock_irqsave(&card->ip_lock, flags);
848 tbd_list = card->ip_tbd_list;
849 card->ip_tbd_list = kmalloc(sizeof(struct list_head), GFP_ATOMIC);
850 if (!card->ip_tbd_list) {
851 QETH_DBF_TEXT(trace, 0, "silnomem");
852 card->ip_tbd_list = tbd_list;
853 spin_unlock_irqrestore(&card->ip_lock, flags);
854 return;
855 } else
856 INIT_LIST_HEAD(card->ip_tbd_list);
857
858 while (!list_empty(tbd_list)){
859 todo = list_entry(tbd_list->next, struct qeth_ipaddr, entry);
860 list_del(&todo->entry);
861 if (todo->type == QETH_IP_TYPE_DEL_ALL_MC){
862 __qeth_delete_all_mc(card, &flags);
863 kfree(todo);
864 continue;
865 }
866 rc = __qeth_ref_ip_on_card(card, todo, &addr);
867 if (rc == 0) {
868 /* nothing to be done; only adjusted refcount */
869 kfree(todo);
870 } else if (rc == 1) {
871 /* new entry to be added to on-card list */
872 spin_unlock_irqrestore(&card->ip_lock, flags);
873 rc = qeth_register_addr_entry(card, todo);
874 spin_lock_irqsave(&card->ip_lock, flags);
875 if (!rc)
876 list_add_tail(&todo->entry, &card->ip_list);
877 else
878 kfree(todo);
879 } else if (rc == -1) {
880 /* on-card entry to be removed */
881 list_del_init(&addr->entry);
882 spin_unlock_irqrestore(&card->ip_lock, flags);
883 rc = qeth_deregister_addr_entry(card, addr);
884 spin_lock_irqsave(&card->ip_lock, flags);
885 if (!rc)
886 kfree(addr);
887 else
888 list_add_tail(&addr->entry, &card->ip_list);
889 kfree(todo);
890 }
891 }
892 spin_unlock_irqrestore(&card->ip_lock, flags);
893 kfree(tbd_list);
894}
895
896static void qeth_delete_mc_addresses(struct qeth_card *);
897static void qeth_add_multicast_ipv4(struct qeth_card *);
Frank Pavlic6c88ad22005-11-10 13:49:28 +0100898static void qeth_layer2_add_multicast(struct qeth_card *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700899#ifdef CONFIG_QETH_IPV6
900static void qeth_add_multicast_ipv6(struct qeth_card *);
901#endif
902
Heiko Carstens4d284ca2007-02-05 21:18:53 +0100903static int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700904qeth_set_thread_start_bit(struct qeth_card *card, unsigned long thread)
905{
906 unsigned long flags;
907
908 spin_lock_irqsave(&card->thread_mask_lock, flags);
909 if ( !(card->thread_allowed_mask & thread) ||
910 (card->thread_start_mask & thread) ) {
911 spin_unlock_irqrestore(&card->thread_mask_lock, flags);
912 return -EPERM;
913 }
914 card->thread_start_mask |= thread;
915 spin_unlock_irqrestore(&card->thread_mask_lock, flags);
916 return 0;
917}
918
919static void
920qeth_clear_thread_start_bit(struct qeth_card *card, unsigned long thread)
921{
922 unsigned long flags;
923
924 spin_lock_irqsave(&card->thread_mask_lock, flags);
925 card->thread_start_mask &= ~thread;
926 spin_unlock_irqrestore(&card->thread_mask_lock, flags);
927 wake_up(&card->wait_q);
928}
929
930static void
931qeth_clear_thread_running_bit(struct qeth_card *card, unsigned long thread)
932{
933 unsigned long flags;
934
935 spin_lock_irqsave(&card->thread_mask_lock, flags);
936 card->thread_running_mask &= ~thread;
937 spin_unlock_irqrestore(&card->thread_mask_lock, flags);
938 wake_up(&card->wait_q);
939}
940
Heiko Carstens4d284ca2007-02-05 21:18:53 +0100941static int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700942__qeth_do_run_thread(struct qeth_card *card, unsigned long thread)
943{
944 unsigned long flags;
945 int rc = 0;
946
947 spin_lock_irqsave(&card->thread_mask_lock, flags);
948 if (card->thread_start_mask & thread){
949 if ((card->thread_allowed_mask & thread) &&
950 !(card->thread_running_mask & thread)){
951 rc = 1;
952 card->thread_start_mask &= ~thread;
953 card->thread_running_mask |= thread;
954 } else
955 rc = -EPERM;
956 }
957 spin_unlock_irqrestore(&card->thread_mask_lock, flags);
958 return rc;
959}
960
961static int
962qeth_do_run_thread(struct qeth_card *card, unsigned long thread)
963{
964 int rc = 0;
965
966 wait_event(card->wait_q,
967 (rc = __qeth_do_run_thread(card, thread)) >= 0);
968 return rc;
969}
970
971static int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700972qeth_recover(void *ptr)
973{
974 struct qeth_card *card;
975 int rc = 0;
976
977 card = (struct qeth_card *) ptr;
978 daemonize("qeth_recover");
979 QETH_DBF_TEXT(trace,2,"recover1");
980 QETH_DBF_HEX(trace, 2, &card, sizeof(void *));
981 if (!qeth_do_run_thread(card, QETH_RECOVER_THREAD))
982 return 0;
983 QETH_DBF_TEXT(trace,2,"recover2");
984 PRINT_WARN("Recovery of device %s started ...\n",
985 CARD_BUS_ID(card));
986 card->use_hard_stop = 1;
Frank Pavlic05e08a22005-05-12 20:39:09 +0200987 __qeth_set_offline(card->gdev,1);
988 rc = __qeth_set_online(card->gdev,1);
Ursula Braund81ef0f2007-06-20 12:56:49 +0200989 /* don't run another scheduled recovery */
990 qeth_clear_thread_start_bit(card, QETH_RECOVER_THREAD);
991 qeth_clear_thread_running_bit(card, QETH_RECOVER_THREAD);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700992 if (!rc)
993 PRINT_INFO("Device %s successfully recovered!\n",
994 CARD_BUS_ID(card));
995 else
996 PRINT_INFO("Device %s could not be recovered!\n",
997 CARD_BUS_ID(card));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700998 return 0;
999}
1000
1001void
1002qeth_schedule_recovery(struct qeth_card *card)
1003{
1004 QETH_DBF_TEXT(trace,2,"startrec");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001005 if (qeth_set_thread_start_bit(card, QETH_RECOVER_THREAD) == 0)
1006 schedule_work(&card->kernel_thread_starter);
1007}
1008
1009static int
1010qeth_do_start_thread(struct qeth_card *card, unsigned long thread)
1011{
1012 unsigned long flags;
1013 int rc = 0;
1014
1015 spin_lock_irqsave(&card->thread_mask_lock, flags);
1016 QETH_DBF_TEXT_(trace, 4, " %02x%02x%02x",
1017 (u8) card->thread_start_mask,
1018 (u8) card->thread_allowed_mask,
1019 (u8) card->thread_running_mask);
1020 rc = (card->thread_start_mask & thread);
1021 spin_unlock_irqrestore(&card->thread_mask_lock, flags);
1022 return rc;
1023}
1024
1025static void
Al Viro4927b3f2006-12-06 19:18:20 +00001026qeth_start_kernel_thread(struct work_struct *work)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001027{
Al Viro4927b3f2006-12-06 19:18:20 +00001028 struct qeth_card *card = container_of(work, struct qeth_card, kernel_thread_starter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001029 QETH_DBF_TEXT(trace , 2, "strthrd");
1030
1031 if (card->read.state != CH_STATE_UP &&
1032 card->write.state != CH_STATE_UP)
1033 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001034 if (qeth_do_start_thread(card, QETH_RECOVER_THREAD))
1035 kernel_thread(qeth_recover, (void *) card, SIGCHLD);
1036}
1037
1038
1039static void
1040qeth_set_intial_options(struct qeth_card *card)
1041{
1042 card->options.route4.type = NO_ROUTER;
1043#ifdef CONFIG_QETH_IPV6
1044 card->options.route6.type = NO_ROUTER;
1045#endif /* QETH_IPV6 */
1046 card->options.checksum_type = QETH_CHECKSUM_DEFAULT;
1047 card->options.broadcast_mode = QETH_TR_BROADCAST_ALLRINGS;
1048 card->options.macaddr_mode = QETH_TR_MACADDR_NONCANONICAL;
1049 card->options.fake_broadcast = 0;
1050 card->options.add_hhlen = DEFAULT_ADD_HHLEN;
1051 card->options.fake_ll = 0;
Ursula Braun500f83a2005-09-30 10:19:19 +02001052 if (card->info.type == QETH_CARD_TYPE_OSN)
1053 card->options.layer2 = 1;
1054 else
1055 card->options.layer2 = 0;
Frank Blaschka95c78c82007-01-08 17:29:34 +01001056 card->options.performance_stats = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001057}
1058
1059/**
1060 * initialize channels ,card and all state machines
1061 */
1062static int
1063qeth_setup_card(struct qeth_card *card)
1064{
1065
1066 QETH_DBF_TEXT(setup, 2, "setupcrd");
1067 QETH_DBF_HEX(setup, 2, &card, sizeof(void *));
1068
1069 card->read.state = CH_STATE_DOWN;
1070 card->write.state = CH_STATE_DOWN;
1071 card->data.state = CH_STATE_DOWN;
1072 card->state = CARD_STATE_DOWN;
1073 card->lan_online = 0;
1074 card->use_hard_stop = 0;
1075 card->dev = NULL;
1076#ifdef CONFIG_QETH_VLAN
1077 spin_lock_init(&card->vlanlock);
1078 card->vlangrp = NULL;
1079#endif
Ursula Braun9123e0d2005-09-30 10:17:24 +02001080 spin_lock_init(&card->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001081 spin_lock_init(&card->ip_lock);
1082 spin_lock_init(&card->thread_mask_lock);
1083 card->thread_start_mask = 0;
1084 card->thread_allowed_mask = 0;
1085 card->thread_running_mask = 0;
Al Viro4927b3f2006-12-06 19:18:20 +00001086 INIT_WORK(&card->kernel_thread_starter, qeth_start_kernel_thread);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001087 INIT_LIST_HEAD(&card->ip_list);
1088 card->ip_tbd_list = kmalloc(sizeof(struct list_head), GFP_KERNEL);
1089 if (!card->ip_tbd_list) {
1090 QETH_DBF_TEXT(setup, 0, "iptbdnom");
1091 return -ENOMEM;
1092 }
1093 INIT_LIST_HEAD(card->ip_tbd_list);
1094 INIT_LIST_HEAD(&card->cmd_waiter_list);
1095 init_waitqueue_head(&card->wait_q);
1096 /* intial options */
1097 qeth_set_intial_options(card);
1098 /* IP address takeover */
1099 INIT_LIST_HEAD(&card->ipato.entries);
1100 card->ipato.enabled = 0;
1101 card->ipato.invert4 = 0;
1102 card->ipato.invert6 = 0;
1103 /* init QDIO stuff */
1104 qeth_init_qdio_info(card);
1105 return 0;
1106}
1107
1108static int
1109is_1920_device (struct qeth_card *card)
1110{
1111 int single_queue = 0;
1112 struct ccw_device *ccwdev;
1113 struct channelPath_dsc {
1114 u8 flags;
1115 u8 lsn;
1116 u8 desc;
1117 u8 chpid;
1118 u8 swla;
1119 u8 zeroes;
1120 u8 chla;
1121 u8 chpp;
1122 } *chp_dsc;
1123
1124 QETH_DBF_TEXT(setup, 2, "chk_1920");
1125
1126 ccwdev = card->data.ccwdev;
1127 chp_dsc = (struct channelPath_dsc *)ccw_device_get_chp_desc(ccwdev, 0);
1128 if (chp_dsc != NULL) {
1129 /* CHPP field bit 6 == 1 -> single queue */
1130 single_queue = ((chp_dsc->chpp & 0x02) == 0x02);
1131 kfree(chp_dsc);
1132 }
1133 QETH_DBF_TEXT_(setup, 2, "rc:%x", single_queue);
1134 return single_queue;
1135}
1136
1137static int
1138qeth_determine_card_type(struct qeth_card *card)
1139{
1140 int i = 0;
1141
1142 QETH_DBF_TEXT(setup, 2, "detcdtyp");
1143
Ursula Braun500f83a2005-09-30 10:19:19 +02001144 card->qdio.do_prio_queueing = QETH_PRIOQ_DEFAULT;
1145 card->qdio.default_out_queue = QETH_DEFAULT_QUEUE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001146 while (known_devices[i][4]) {
1147 if ((CARD_RDEV(card)->id.dev_type == known_devices[i][2]) &&
1148 (CARD_RDEV(card)->id.dev_model == known_devices[i][3])) {
1149 card->info.type = known_devices[i][4];
Ursula Braun500f83a2005-09-30 10:19:19 +02001150 card->qdio.no_out_queues = known_devices[i][8];
1151 card->info.is_multicast_different = known_devices[i][9];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001152 if (is_1920_device(card)) {
1153 PRINT_INFO("Priority Queueing not able "
1154 "due to hardware limitations!\n");
1155 card->qdio.no_out_queues = 1;
1156 card->qdio.default_out_queue = 0;
Jeff Garzike82b0f22006-05-26 21:58:38 -04001157 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001158 return 0;
1159 }
1160 i++;
1161 }
1162 card->info.type = QETH_CARD_TYPE_UNKNOWN;
1163 PRINT_ERR("unknown card type on device %s\n", CARD_BUS_ID(card));
1164 return -ENOENT;
1165}
1166
1167static int
1168qeth_probe_device(struct ccwgroup_device *gdev)
1169{
1170 struct qeth_card *card;
1171 struct device *dev;
1172 unsigned long flags;
1173 int rc;
1174
1175 QETH_DBF_TEXT(setup, 2, "probedev");
1176
1177 dev = &gdev->dev;
1178 if (!get_device(dev))
1179 return -ENODEV;
1180
Ursula Braun500f83a2005-09-30 10:19:19 +02001181 QETH_DBF_TEXT_(setup, 2, "%s", gdev->dev.bus_id);
Jeff Garzike82b0f22006-05-26 21:58:38 -04001182
Linus Torvalds1da177e2005-04-16 15:20:36 -07001183 card = qeth_alloc_card();
1184 if (!card) {
1185 put_device(dev);
1186 QETH_DBF_TEXT_(setup, 2, "1err%d", -ENOMEM);
1187 return -ENOMEM;
1188 }
1189 card->read.ccwdev = gdev->cdev[0];
1190 card->write.ccwdev = gdev->cdev[1];
1191 card->data.ccwdev = gdev->cdev[2];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001192 gdev->dev.driver_data = card;
1193 card->gdev = gdev;
1194 gdev->cdev[0]->handler = qeth_irq;
1195 gdev->cdev[1]->handler = qeth_irq;
1196 gdev->cdev[2]->handler = qeth_irq;
1197
Ursula Braun500f83a2005-09-30 10:19:19 +02001198 if ((rc = qeth_determine_card_type(card))){
1199 PRINT_WARN("%s: not a valid card type\n", __func__);
1200 QETH_DBF_TEXT_(setup, 2, "3err%d", rc);
1201 put_device(dev);
1202 qeth_free_card(card);
1203 return rc;
Jeff Garzike82b0f22006-05-26 21:58:38 -04001204 }
Ursula Braun500f83a2005-09-30 10:19:19 +02001205 if ((rc = qeth_setup_card(card))){
1206 QETH_DBF_TEXT_(setup, 2, "2err%d", rc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001207 put_device(dev);
1208 qeth_free_card(card);
1209 return rc;
1210 }
Ursula Braun500f83a2005-09-30 10:19:19 +02001211 rc = qeth_create_device_attributes(dev);
1212 if (rc) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001213 put_device(dev);
1214 qeth_free_card(card);
1215 return rc;
1216 }
1217 /* insert into our internal list */
1218 write_lock_irqsave(&qeth_card_list.rwlock, flags);
1219 list_add_tail(&card->list, &qeth_card_list.list);
1220 write_unlock_irqrestore(&qeth_card_list.rwlock, flags);
1221 return rc;
1222}
1223
1224
Cornelia Huck6c82a8a2007-05-04 18:47:52 +02001225static int qeth_read_conf_data(struct qeth_card *card, void **buffer,
1226 int *length)
1227{
1228 struct ciw *ciw;
1229 char *rcd_buf;
1230 int ret;
1231 struct qeth_channel *channel = &card->data;
1232 unsigned long flags;
1233
1234 /*
1235 * scan for RCD command in extended SenseID data
1236 */
1237 ciw = ccw_device_get_ciw(channel->ccwdev, CIW_TYPE_RCD);
1238 if (!ciw || ciw->cmd == 0)
1239 return -EOPNOTSUPP;
1240 rcd_buf = kzalloc(ciw->count, GFP_KERNEL | GFP_DMA);
1241 if (!rcd_buf)
1242 return -ENOMEM;
1243
1244 channel->ccw.cmd_code = ciw->cmd;
1245 channel->ccw.cda = (__u32) __pa (rcd_buf);
1246 channel->ccw.count = ciw->count;
1247 channel->ccw.flags = CCW_FLAG_SLI;
1248 channel->state = CH_STATE_RCD;
1249 spin_lock_irqsave(get_ccwdev_lock(channel->ccwdev), flags);
1250 ret = ccw_device_start_timeout(channel->ccwdev, &channel->ccw,
1251 QETH_RCD_PARM, LPM_ANYPATH, 0,
1252 QETH_RCD_TIMEOUT);
1253 spin_unlock_irqrestore(get_ccwdev_lock(channel->ccwdev), flags);
1254 if (!ret)
1255 wait_event(card->wait_q,
1256 (channel->state == CH_STATE_RCD_DONE ||
1257 channel->state == CH_STATE_DOWN));
1258 if (channel->state == CH_STATE_DOWN)
1259 ret = -EIO;
1260 else
1261 channel->state = CH_STATE_DOWN;
1262 if (ret) {
1263 kfree(rcd_buf);
1264 *buffer = NULL;
1265 *length = 0;
1266 } else {
1267 *length = ciw->count;
1268 *buffer = rcd_buf;
1269 }
1270 return ret;
1271}
1272
Linus Torvalds1da177e2005-04-16 15:20:36 -07001273static int
1274qeth_get_unitaddr(struct qeth_card *card)
1275{
1276 int length;
1277 char *prcd;
1278 int rc;
1279
1280 QETH_DBF_TEXT(setup, 2, "getunit");
Cornelia Huck6c82a8a2007-05-04 18:47:52 +02001281 rc = qeth_read_conf_data(card, (void **) &prcd, &length);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001282 if (rc) {
Cornelia Huck6c82a8a2007-05-04 18:47:52 +02001283 PRINT_ERR("qeth_read_conf_data for device %s returned %i\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001284 CARD_DDEV_ID(card), rc);
1285 return rc;
1286 }
1287 card->info.chpid = prcd[30];
1288 card->info.unit_addr2 = prcd[31];
1289 card->info.cula = prcd[63];
1290 card->info.guestlan = ((prcd[0x10] == _ascebc['V']) &&
1291 (prcd[0x11] == _ascebc['M']));
Cornelia Huck6c82a8a2007-05-04 18:47:52 +02001292 kfree(prcd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001293 return 0;
1294}
1295
1296static void
1297qeth_init_tokens(struct qeth_card *card)
1298{
1299 card->token.issuer_rm_w = 0x00010103UL;
1300 card->token.cm_filter_w = 0x00010108UL;
1301 card->token.cm_connection_w = 0x0001010aUL;
1302 card->token.ulp_filter_w = 0x0001010bUL;
1303 card->token.ulp_connection_w = 0x0001010dUL;
1304}
1305
1306static inline __u16
1307raw_devno_from_bus_id(char *id)
1308{
1309 id += (strlen(id) - 4);
1310 return (__u16) simple_strtoul(id, &id, 16);
1311}
1312/**
1313 * setup channel
1314 */
1315static void
1316qeth_setup_ccw(struct qeth_channel *channel,unsigned char *iob, __u32 len)
1317{
1318 struct qeth_card *card;
1319
1320 QETH_DBF_TEXT(trace, 4, "setupccw");
1321 card = CARD_FROM_CDEV(channel->ccwdev);
1322 if (channel == &card->read)
1323 memcpy(&channel->ccw, READ_CCW, sizeof(struct ccw1));
1324 else
1325 memcpy(&channel->ccw, WRITE_CCW, sizeof(struct ccw1));
1326 channel->ccw.count = len;
1327 channel->ccw.cda = (__u32) __pa(iob);
1328}
1329
1330/**
1331 * get free buffer for ccws (IDX activation, lancmds,ipassists...)
1332 */
1333static struct qeth_cmd_buffer *
1334__qeth_get_buffer(struct qeth_channel *channel)
1335{
1336 __u8 index;
1337
1338 QETH_DBF_TEXT(trace, 6, "getbuff");
1339 index = channel->io_buf_no;
1340 do {
1341 if (channel->iob[index].state == BUF_STATE_FREE) {
1342 channel->iob[index].state = BUF_STATE_LOCKED;
1343 channel->io_buf_no = (channel->io_buf_no + 1) %
1344 QETH_CMD_BUFFER_NO;
1345 memset(channel->iob[index].data, 0, QETH_BUFSIZE);
1346 return channel->iob + index;
1347 }
1348 index = (index + 1) % QETH_CMD_BUFFER_NO;
1349 } while(index != channel->io_buf_no);
1350
1351 return NULL;
1352}
1353
1354/**
1355 * release command buffer
1356 */
1357static void
1358qeth_release_buffer(struct qeth_channel *channel, struct qeth_cmd_buffer *iob)
1359{
1360 unsigned long flags;
1361
1362 QETH_DBF_TEXT(trace, 6, "relbuff");
1363 spin_lock_irqsave(&channel->iob_lock, flags);
1364 memset(iob->data, 0, QETH_BUFSIZE);
1365 iob->state = BUF_STATE_FREE;
1366 iob->callback = qeth_send_control_data_cb;
1367 iob->rc = 0;
1368 spin_unlock_irqrestore(&channel->iob_lock, flags);
1369}
1370
1371static struct qeth_cmd_buffer *
1372qeth_get_buffer(struct qeth_channel *channel)
1373{
1374 struct qeth_cmd_buffer *buffer = NULL;
1375 unsigned long flags;
1376
1377 spin_lock_irqsave(&channel->iob_lock, flags);
1378 buffer = __qeth_get_buffer(channel);
1379 spin_unlock_irqrestore(&channel->iob_lock, flags);
1380 return buffer;
1381}
1382
1383static struct qeth_cmd_buffer *
1384qeth_wait_for_buffer(struct qeth_channel *channel)
1385{
1386 struct qeth_cmd_buffer *buffer;
1387 wait_event(channel->wait_q,
1388 ((buffer = qeth_get_buffer(channel)) != NULL));
1389 return buffer;
1390}
1391
1392static void
1393qeth_clear_cmd_buffers(struct qeth_channel *channel)
1394{
Frank Pavlic1380fee2006-03-22 16:03:41 +01001395 int cnt;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001396
1397 for (cnt=0; cnt < QETH_CMD_BUFFER_NO; cnt++)
1398 qeth_release_buffer(channel,&channel->iob[cnt]);
1399 channel->buf_no = 0;
1400 channel->io_buf_no = 0;
1401}
1402
1403/**
1404 * start IDX for read and write channel
1405 */
1406static int
1407qeth_idx_activate_get_answer(struct qeth_channel *channel,
1408 void (*idx_reply_cb)(struct qeth_channel *,
1409 struct qeth_cmd_buffer *))
1410{
1411 struct qeth_cmd_buffer *iob;
1412 unsigned long flags;
1413 int rc;
1414 struct qeth_card *card;
1415
1416 QETH_DBF_TEXT(setup, 2, "idxanswr");
1417 card = CARD_FROM_CDEV(channel->ccwdev);
1418 iob = qeth_get_buffer(channel);
1419 iob->callback = idx_reply_cb;
1420 memcpy(&channel->ccw, READ_CCW, sizeof(struct ccw1));
1421 channel->ccw.count = QETH_BUFSIZE;
1422 channel->ccw.cda = (__u32) __pa(iob->data);
1423
1424 wait_event(card->wait_q,
Martin Schwidefsky973bd992006-01-06 00:19:07 -08001425 atomic_cmpxchg(&channel->irq_pending, 0, 1) == 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001426 QETH_DBF_TEXT(setup, 6, "noirqpnd");
1427 spin_lock_irqsave(get_ccwdev_lock(channel->ccwdev), flags);
1428 rc = ccw_device_start(channel->ccwdev,
1429 &channel->ccw,(addr_t) iob, 0, 0);
1430 spin_unlock_irqrestore(get_ccwdev_lock(channel->ccwdev), flags);
1431
1432 if (rc) {
1433 PRINT_ERR("qeth: Error2 in activating channel rc=%d\n",rc);
1434 QETH_DBF_TEXT_(setup, 2, "2err%d", rc);
1435 atomic_set(&channel->irq_pending, 0);
1436 wake_up(&card->wait_q);
1437 return rc;
1438 }
1439 rc = wait_event_interruptible_timeout(card->wait_q,
1440 channel->state == CH_STATE_UP, QETH_TIMEOUT);
1441 if (rc == -ERESTARTSYS)
1442 return rc;
1443 if (channel->state != CH_STATE_UP){
1444 rc = -ETIME;
1445 QETH_DBF_TEXT_(setup, 2, "3err%d", rc);
1446 qeth_clear_cmd_buffers(channel);
1447 } else
1448 rc = 0;
1449 return rc;
1450}
1451
1452static int
1453qeth_idx_activate_channel(struct qeth_channel *channel,
1454 void (*idx_reply_cb)(struct qeth_channel *,
1455 struct qeth_cmd_buffer *))
1456{
1457 struct qeth_card *card;
1458 struct qeth_cmd_buffer *iob;
1459 unsigned long flags;
1460 __u16 temp;
1461 int rc;
1462
1463 card = CARD_FROM_CDEV(channel->ccwdev);
1464
1465 QETH_DBF_TEXT(setup, 2, "idxactch");
1466
1467 iob = qeth_get_buffer(channel);
1468 iob->callback = idx_reply_cb;
1469 memcpy(&channel->ccw, WRITE_CCW, sizeof(struct ccw1));
1470 channel->ccw.count = IDX_ACTIVATE_SIZE;
1471 channel->ccw.cda = (__u32) __pa(iob->data);
1472 if (channel == &card->write) {
1473 memcpy(iob->data, IDX_ACTIVATE_WRITE, IDX_ACTIVATE_SIZE);
1474 memcpy(QETH_TRANSPORT_HEADER_SEQ_NO(iob->data),
1475 &card->seqno.trans_hdr, QETH_SEQ_NO_LENGTH);
1476 card->seqno.trans_hdr++;
1477 } else {
1478 memcpy(iob->data, IDX_ACTIVATE_READ, IDX_ACTIVATE_SIZE);
1479 memcpy(QETH_TRANSPORT_HEADER_SEQ_NO(iob->data),
1480 &card->seqno.trans_hdr, QETH_SEQ_NO_LENGTH);
1481 }
1482 memcpy(QETH_IDX_ACT_ISSUER_RM_TOKEN(iob->data),
1483 &card->token.issuer_rm_w,QETH_MPC_TOKEN_LENGTH);
1484 memcpy(QETH_IDX_ACT_FUNC_LEVEL(iob->data),
1485 &card->info.func_level,sizeof(__u16));
1486 temp = raw_devno_from_bus_id(CARD_DDEV_ID(card));
1487 memcpy(QETH_IDX_ACT_QDIO_DEV_CUA(iob->data), &temp, 2);
1488 temp = (card->info.cula << 8) + card->info.unit_addr2;
1489 memcpy(QETH_IDX_ACT_QDIO_DEV_REALADDR(iob->data), &temp, 2);
1490
1491 wait_event(card->wait_q,
Martin Schwidefsky973bd992006-01-06 00:19:07 -08001492 atomic_cmpxchg(&channel->irq_pending, 0, 1) == 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001493 QETH_DBF_TEXT(setup, 6, "noirqpnd");
1494 spin_lock_irqsave(get_ccwdev_lock(channel->ccwdev), flags);
1495 rc = ccw_device_start(channel->ccwdev,
1496 &channel->ccw,(addr_t) iob, 0, 0);
1497 spin_unlock_irqrestore(get_ccwdev_lock(channel->ccwdev), flags);
1498
1499 if (rc) {
1500 PRINT_ERR("qeth: Error1 in activating channel. rc=%d\n",rc);
1501 QETH_DBF_TEXT_(setup, 2, "1err%d", rc);
1502 atomic_set(&channel->irq_pending, 0);
1503 wake_up(&card->wait_q);
1504 return rc;
1505 }
1506 rc = wait_event_interruptible_timeout(card->wait_q,
1507 channel->state == CH_STATE_ACTIVATING, QETH_TIMEOUT);
1508 if (rc == -ERESTARTSYS)
1509 return rc;
1510 if (channel->state != CH_STATE_ACTIVATING) {
1511 PRINT_WARN("qeth: IDX activate timed out!\n");
1512 QETH_DBF_TEXT_(setup, 2, "2err%d", -ETIME);
1513 qeth_clear_cmd_buffers(channel);
1514 return -ETIME;
1515 }
1516 return qeth_idx_activate_get_answer(channel,idx_reply_cb);
1517}
1518
1519static int
1520qeth_peer_func_level(int level)
1521{
1522 if ((level & 0xff) == 8)
1523 return (level & 0xff) + 0x400;
1524 if (((level >> 8) & 3) == 1)
1525 return (level & 0xff) + 0x200;
1526 return level;
1527}
1528
1529static void
1530qeth_idx_write_cb(struct qeth_channel *channel, struct qeth_cmd_buffer *iob)
1531{
1532 struct qeth_card *card;
1533 __u16 temp;
1534
1535 QETH_DBF_TEXT(setup ,2, "idxwrcb");
1536
1537 if (channel->state == CH_STATE_DOWN) {
1538 channel->state = CH_STATE_ACTIVATING;
1539 goto out;
1540 }
1541 card = CARD_FROM_CDEV(channel->ccwdev);
1542
1543 if (!(QETH_IS_IDX_ACT_POS_REPLY(iob->data))) {
1544 PRINT_ERR("IDX_ACTIVATE on write channel device %s: negative "
1545 "reply\n", CARD_WDEV_ID(card));
1546 goto out;
1547 }
1548 memcpy(&temp, QETH_IDX_ACT_FUNC_LEVEL(iob->data), 2);
1549 if ((temp & ~0x0100) != qeth_peer_func_level(card->info.func_level)) {
1550 PRINT_WARN("IDX_ACTIVATE on write channel device %s: "
1551 "function level mismatch "
1552 "(sent: 0x%x, received: 0x%x)\n",
1553 CARD_WDEV_ID(card), card->info.func_level, temp);
1554 goto out;
1555 }
1556 channel->state = CH_STATE_UP;
1557out:
1558 qeth_release_buffer(channel, iob);
1559}
1560
1561static int
1562qeth_check_idx_response(unsigned char *buffer)
1563{
1564 if (!buffer)
1565 return 0;
1566
1567 QETH_DBF_HEX(control, 2, buffer, QETH_DBF_CONTROL_LEN);
1568 if ((buffer[2] & 0xc0) == 0xc0) {
1569 PRINT_WARN("received an IDX TERMINATE "
1570 "with cause code 0x%02x%s\n",
1571 buffer[4],
1572 ((buffer[4] == 0x22) ?
1573 " -- try another portname" : ""));
1574 QETH_DBF_TEXT(trace, 2, "ckidxres");
1575 QETH_DBF_TEXT(trace, 2, " idxterm");
1576 QETH_DBF_TEXT_(trace, 2, " rc%d", -EIO);
1577 return -EIO;
1578 }
1579 return 0;
1580}
1581
1582static void
1583qeth_idx_read_cb(struct qeth_channel *channel, struct qeth_cmd_buffer *iob)
1584{
1585 struct qeth_card *card;
1586 __u16 temp;
1587
1588 QETH_DBF_TEXT(setup , 2, "idxrdcb");
1589 if (channel->state == CH_STATE_DOWN) {
1590 channel->state = CH_STATE_ACTIVATING;
1591 goto out;
1592 }
1593
1594 card = CARD_FROM_CDEV(channel->ccwdev);
1595 if (qeth_check_idx_response(iob->data)) {
1596 goto out;
1597 }
1598 if (!(QETH_IS_IDX_ACT_POS_REPLY(iob->data))) {
1599 PRINT_ERR("IDX_ACTIVATE on read channel device %s: negative "
1600 "reply\n", CARD_RDEV_ID(card));
1601 goto out;
1602 }
1603
1604/**
1605 * temporary fix for microcode bug
1606 * to revert it,replace OR by AND
1607 */
1608 if ( (!QETH_IDX_NO_PORTNAME_REQUIRED(iob->data)) ||
1609 (card->info.type == QETH_CARD_TYPE_OSAE) )
1610 card->info.portname_required = 1;
1611
1612 memcpy(&temp, QETH_IDX_ACT_FUNC_LEVEL(iob->data), 2);
1613 if (temp != qeth_peer_func_level(card->info.func_level)) {
1614 PRINT_WARN("IDX_ACTIVATE on read channel device %s: function "
1615 "level mismatch (sent: 0x%x, received: 0x%x)\n",
1616 CARD_RDEV_ID(card), card->info.func_level, temp);
1617 goto out;
1618 }
1619 memcpy(&card->token.issuer_rm_r,
1620 QETH_IDX_ACT_ISSUER_RM_TOKEN(iob->data),
1621 QETH_MPC_TOKEN_LENGTH);
1622 memcpy(&card->info.mcl_level[0],
1623 QETH_IDX_REPLY_LEVEL(iob->data), QETH_MCL_LENGTH);
1624 channel->state = CH_STATE_UP;
1625out:
1626 qeth_release_buffer(channel,iob);
1627}
1628
1629static int
1630qeth_issue_next_read(struct qeth_card *card)
1631{
1632 int rc;
1633 struct qeth_cmd_buffer *iob;
1634
1635 QETH_DBF_TEXT(trace,5,"issnxrd");
1636 if (card->read.state != CH_STATE_UP)
1637 return -EIO;
1638 iob = qeth_get_buffer(&card->read);
1639 if (!iob) {
1640 PRINT_WARN("issue_next_read failed: no iob available!\n");
1641 return -ENOMEM;
1642 }
1643 qeth_setup_ccw(&card->read, iob->data, QETH_BUFSIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001644 QETH_DBF_TEXT(trace, 6, "noirqpnd");
1645 rc = ccw_device_start(card->read.ccwdev, &card->read.ccw,
1646 (addr_t) iob, 0, 0);
1647 if (rc) {
1648 PRINT_ERR("Error in starting next read ccw! rc=%i\n", rc);
1649 atomic_set(&card->read.irq_pending, 0);
1650 qeth_schedule_recovery(card);
1651 wake_up(&card->wait_q);
1652 }
1653 return rc;
1654}
1655
1656static struct qeth_reply *
1657qeth_alloc_reply(struct qeth_card *card)
1658{
1659 struct qeth_reply *reply;
1660
Eric Sesterhenn88abaab2006-03-24 03:15:31 -08001661 reply = kzalloc(sizeof(struct qeth_reply), GFP_ATOMIC);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001662 if (reply){
Linus Torvalds1da177e2005-04-16 15:20:36 -07001663 atomic_set(&reply->refcnt, 1);
Frank Blaschkaee2db682007-01-08 17:30:11 +01001664 atomic_set(&reply->received, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001665 reply->card = card;
1666 };
1667 return reply;
1668}
1669
1670static void
1671qeth_get_reply(struct qeth_reply *reply)
1672{
1673 WARN_ON(atomic_read(&reply->refcnt) <= 0);
1674 atomic_inc(&reply->refcnt);
1675}
1676
1677static void
1678qeth_put_reply(struct qeth_reply *reply)
1679{
1680 WARN_ON(atomic_read(&reply->refcnt) <= 0);
1681 if (atomic_dec_and_test(&reply->refcnt))
1682 kfree(reply);
1683}
1684
Peter Tiedemann7dd976f2007-05-02 15:19:35 +02001685static void
1686qeth_issue_ipa_msg(struct qeth_ipa_cmd *cmd, struct qeth_card *card)
1687{
1688 int rc;
1689 int com;
1690 char * ipa_name;
1691
1692 com = cmd->hdr.command;
1693 rc = cmd->hdr.return_code;
1694 ipa_name = qeth_get_ipa_cmd_name(com);
1695
1696 PRINT_ERR("%s(x%X) for %s returned x%X \"%s\"\n", ipa_name, com,
1697 QETH_CARD_IFNAME(card), rc, qeth_get_ipa_msg(rc));
1698}
1699
Linus Torvalds1da177e2005-04-16 15:20:36 -07001700static struct qeth_ipa_cmd *
1701qeth_check_ipa_data(struct qeth_card *card, struct qeth_cmd_buffer *iob)
1702{
1703 struct qeth_ipa_cmd *cmd = NULL;
1704
1705 QETH_DBF_TEXT(trace,5,"chkipad");
1706 if (IS_IPA(iob->data)){
1707 cmd = (struct qeth_ipa_cmd *) PDU_ENCAPSULATION(iob->data);
Peter Tiedemann7dd976f2007-05-02 15:19:35 +02001708 if (IS_IPA_REPLY(cmd)) {
1709 if (cmd->hdr.return_code)
1710 qeth_issue_ipa_msg(cmd, card);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001711 return cmd;
Peter Tiedemann7dd976f2007-05-02 15:19:35 +02001712 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001713 else {
1714 switch (cmd->hdr.command) {
1715 case IPA_CMD_STOPLAN:
1716 PRINT_WARN("Link failure on %s (CHPID 0x%X) - "
1717 "there is a network problem or "
1718 "someone pulled the cable or "
1719 "disabled the port.\n",
1720 QETH_CARD_IFNAME(card),
1721 card->info.chpid);
1722 card->lan_online = 0;
Frank Pavlic66cc5d52006-02-07 17:04:38 +01001723 if (card->dev && netif_carrier_ok(card->dev))
1724 netif_carrier_off(card->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001725 return NULL;
1726 case IPA_CMD_STARTLAN:
1727 PRINT_INFO("Link reestablished on %s "
1728 "(CHPID 0x%X). Scheduling "
1729 "IP address reset.\n",
1730 QETH_CARD_IFNAME(card),
1731 card->info.chpid);
Frank Pavlic330b6362006-09-15 16:25:56 +02001732 netif_carrier_on(card->dev);
Ursula Braun9123e0d2005-09-30 10:17:24 +02001733 qeth_schedule_recovery(card);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001734 return NULL;
Ursula Braun500f83a2005-09-30 10:19:19 +02001735 case IPA_CMD_MODCCID:
1736 return cmd;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001737 case IPA_CMD_REGISTER_LOCAL_ADDR:
1738 QETH_DBF_TEXT(trace,3, "irla");
1739 break;
1740 case IPA_CMD_UNREGISTER_LOCAL_ADDR:
1741 QETH_DBF_TEXT(trace,3, "urla");
1742 break;
1743 default:
1744 PRINT_WARN("Received data is IPA "
1745 "but not a reply!\n");
1746 break;
1747 }
1748 }
1749 }
1750 return cmd;
1751}
1752
1753/**
1754 * wake all waiting ipa commands
1755 */
1756static void
1757qeth_clear_ipacmd_list(struct qeth_card *card)
1758{
1759 struct qeth_reply *reply, *r;
1760 unsigned long flags;
1761
1762 QETH_DBF_TEXT(trace, 4, "clipalst");
1763
1764 spin_lock_irqsave(&card->lock, flags);
1765 list_for_each_entry_safe(reply, r, &card->cmd_waiter_list, list) {
1766 qeth_get_reply(reply);
1767 reply->rc = -EIO;
Frank Blaschkaee2db682007-01-08 17:30:11 +01001768 atomic_inc(&reply->received);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001769 list_del_init(&reply->list);
1770 wake_up(&reply->wait_q);
1771 qeth_put_reply(reply);
1772 }
1773 spin_unlock_irqrestore(&card->lock, flags);
1774}
1775
1776static void
1777qeth_send_control_data_cb(struct qeth_channel *channel,
1778 struct qeth_cmd_buffer *iob)
1779{
1780 struct qeth_card *card;
1781 struct qeth_reply *reply, *r;
1782 struct qeth_ipa_cmd *cmd;
1783 unsigned long flags;
1784 int keep_reply;
1785
1786 QETH_DBF_TEXT(trace,4,"sndctlcb");
1787
1788 card = CARD_FROM_CDEV(channel->ccwdev);
1789 if (qeth_check_idx_response(iob->data)) {
1790 qeth_clear_ipacmd_list(card);
1791 qeth_schedule_recovery(card);
1792 goto out;
1793 }
1794
1795 cmd = qeth_check_ipa_data(card, iob);
1796 if ((cmd == NULL) && (card->state != CARD_STATE_DOWN))
1797 goto out;
Ursula Braun500f83a2005-09-30 10:19:19 +02001798 /*in case of OSN : check if cmd is set */
1799 if (card->info.type == QETH_CARD_TYPE_OSN &&
1800 cmd &&
1801 cmd->hdr.command != IPA_CMD_STARTLAN &&
1802 card->osn_info.assist_cb != NULL) {
1803 card->osn_info.assist_cb(card->dev, cmd);
1804 goto out;
1805 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001806
1807 spin_lock_irqsave(&card->lock, flags);
1808 list_for_each_entry_safe(reply, r, &card->cmd_waiter_list, list) {
1809 if ((reply->seqno == QETH_IDX_COMMAND_SEQNO) ||
1810 ((cmd) && (reply->seqno == cmd->hdr.seqno))) {
1811 qeth_get_reply(reply);
1812 list_del_init(&reply->list);
1813 spin_unlock_irqrestore(&card->lock, flags);
1814 keep_reply = 0;
1815 if (reply->callback != NULL) {
1816 if (cmd) {
1817 reply->offset = (__u16)((char*)cmd -
1818 (char *)iob->data);
1819 keep_reply = reply->callback(card,
1820 reply,
1821 (unsigned long)cmd);
Ursula Braun500f83a2005-09-30 10:19:19 +02001822 } else
Linus Torvalds1da177e2005-04-16 15:20:36 -07001823 keep_reply = reply->callback(card,
1824 reply,
1825 (unsigned long)iob);
1826 }
1827 if (cmd)
1828 reply->rc = (u16) cmd->hdr.return_code;
1829 else if (iob->rc)
1830 reply->rc = iob->rc;
1831 if (keep_reply) {
1832 spin_lock_irqsave(&card->lock, flags);
1833 list_add_tail(&reply->list,
1834 &card->cmd_waiter_list);
1835 spin_unlock_irqrestore(&card->lock, flags);
1836 } else {
Frank Blaschkaee2db682007-01-08 17:30:11 +01001837 atomic_inc(&reply->received);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001838 wake_up(&reply->wait_q);
1839 }
1840 qeth_put_reply(reply);
1841 goto out;
1842 }
1843 }
1844 spin_unlock_irqrestore(&card->lock, flags);
1845out:
1846 memcpy(&card->seqno.pdu_hdr_ack,
1847 QETH_PDU_HEADER_SEQ_NO(iob->data),
1848 QETH_SEQ_NO_LENGTH);
1849 qeth_release_buffer(channel,iob);
1850}
1851
Heiko Carstens4d284ca2007-02-05 21:18:53 +01001852static void
Ursula Braun500f83a2005-09-30 10:19:19 +02001853qeth_prepare_control_data(struct qeth_card *card, int len,
Heiko Carstens4d284ca2007-02-05 21:18:53 +01001854 struct qeth_cmd_buffer *iob)
Ursula Braun500f83a2005-09-30 10:19:19 +02001855{
1856 qeth_setup_ccw(&card->write,iob->data,len);
1857 iob->callback = qeth_release_buffer;
1858
1859 memcpy(QETH_TRANSPORT_HEADER_SEQ_NO(iob->data),
1860 &card->seqno.trans_hdr, QETH_SEQ_NO_LENGTH);
1861 card->seqno.trans_hdr++;
1862 memcpy(QETH_PDU_HEADER_SEQ_NO(iob->data),
1863 &card->seqno.pdu_hdr, QETH_SEQ_NO_LENGTH);
1864 card->seqno.pdu_hdr++;
1865 memcpy(QETH_PDU_HEADER_ACK_SEQ_NO(iob->data),
1866 &card->seqno.pdu_hdr_ack, QETH_SEQ_NO_LENGTH);
1867 QETH_DBF_HEX(control, 2, iob->data, QETH_DBF_CONTROL_LEN);
1868}
Jeff Garzike82b0f22006-05-26 21:58:38 -04001869
Linus Torvalds1da177e2005-04-16 15:20:36 -07001870static int
1871qeth_send_control_data(struct qeth_card *card, int len,
1872 struct qeth_cmd_buffer *iob,
1873 int (*reply_cb)
1874 (struct qeth_card *, struct qeth_reply*, unsigned long),
1875 void *reply_param)
1876
1877{
1878 int rc;
1879 unsigned long flags;
Ursula Braun500f83a2005-09-30 10:19:19 +02001880 struct qeth_reply *reply = NULL;
Frank Blaschkaee2db682007-01-08 17:30:11 +01001881 unsigned long timeout;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001882
1883 QETH_DBF_TEXT(trace, 2, "sendctl");
1884
Linus Torvalds1da177e2005-04-16 15:20:36 -07001885 reply = qeth_alloc_reply(card);
1886 if (!reply) {
1887 PRINT_WARN("Could no alloc qeth_reply!\n");
1888 return -ENOMEM;
1889 }
1890 reply->callback = reply_cb;
1891 reply->param = reply_param;
1892 if (card->state == CARD_STATE_DOWN)
1893 reply->seqno = QETH_IDX_COMMAND_SEQNO;
1894 else
1895 reply->seqno = card->seqno.ipa++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001896 init_waitqueue_head(&reply->wait_q);
1897 spin_lock_irqsave(&card->lock, flags);
1898 list_add_tail(&reply->list, &card->cmd_waiter_list);
1899 spin_unlock_irqrestore(&card->lock, flags);
1900 QETH_DBF_HEX(control, 2, iob->data, QETH_DBF_CONTROL_LEN);
Frank Blaschkaee2db682007-01-08 17:30:11 +01001901
1902 while (atomic_cmpxchg(&card->write.irq_pending, 0, 1)) ;
Ursula Braun500f83a2005-09-30 10:19:19 +02001903 qeth_prepare_control_data(card, len, iob);
Frank Blaschkaee2db682007-01-08 17:30:11 +01001904
Ursula Braun500f83a2005-09-30 10:19:19 +02001905 if (IS_IPA(iob->data))
Frank Blaschkaee2db682007-01-08 17:30:11 +01001906 timeout = jiffies + QETH_IPA_TIMEOUT;
Ursula Braun500f83a2005-09-30 10:19:19 +02001907 else
Frank Blaschkaee2db682007-01-08 17:30:11 +01001908 timeout = jiffies + QETH_TIMEOUT;
1909
Linus Torvalds1da177e2005-04-16 15:20:36 -07001910 QETH_DBF_TEXT(trace, 6, "noirqpnd");
1911 spin_lock_irqsave(get_ccwdev_lock(card->write.ccwdev), flags);
1912 rc = ccw_device_start(card->write.ccwdev, &card->write.ccw,
1913 (addr_t) iob, 0, 0);
1914 spin_unlock_irqrestore(get_ccwdev_lock(card->write.ccwdev), flags);
1915 if (rc){
1916 PRINT_WARN("qeth_send_control_data: "
1917 "ccw_device_start rc = %i\n", rc);
1918 QETH_DBF_TEXT_(trace, 2, " err%d", rc);
1919 spin_lock_irqsave(&card->lock, flags);
1920 list_del_init(&reply->list);
1921 qeth_put_reply(reply);
1922 spin_unlock_irqrestore(&card->lock, flags);
1923 qeth_release_buffer(iob->channel, iob);
1924 atomic_set(&card->write.irq_pending, 0);
1925 wake_up(&card->wait_q);
1926 return rc;
1927 }
Frank Blaschkaee2db682007-01-08 17:30:11 +01001928 while (!atomic_read(&reply->received)) {
1929 if (time_after(jiffies, timeout)) {
1930 spin_lock_irqsave(&reply->card->lock, flags);
1931 list_del_init(&reply->list);
1932 spin_unlock_irqrestore(&reply->card->lock, flags);
1933 reply->rc = -ETIME;
1934 atomic_inc(&reply->received);
1935 wake_up(&reply->wait_q);
1936 }
1937 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001938 rc = reply->rc;
1939 qeth_put_reply(reply);
1940 return rc;
1941}
1942
1943static int
Ursula Braun500f83a2005-09-30 10:19:19 +02001944qeth_osn_send_control_data(struct qeth_card *card, int len,
1945 struct qeth_cmd_buffer *iob)
1946{
1947 unsigned long flags;
1948 int rc = 0;
1949
1950 QETH_DBF_TEXT(trace, 5, "osndctrd");
1951
1952 wait_event(card->wait_q,
Martin Schwidefsky973bd992006-01-06 00:19:07 -08001953 atomic_cmpxchg(&card->write.irq_pending, 0, 1) == 0);
Ursula Braun500f83a2005-09-30 10:19:19 +02001954 qeth_prepare_control_data(card, len, iob);
1955 QETH_DBF_TEXT(trace, 6, "osnoirqp");
1956 spin_lock_irqsave(get_ccwdev_lock(card->write.ccwdev), flags);
1957 rc = ccw_device_start(card->write.ccwdev, &card->write.ccw,
1958 (addr_t) iob, 0, 0);
1959 spin_unlock_irqrestore(get_ccwdev_lock(card->write.ccwdev), flags);
1960 if (rc){
1961 PRINT_WARN("qeth_osn_send_control_data: "
1962 "ccw_device_start rc = %i\n", rc);
1963 QETH_DBF_TEXT_(trace, 2, " err%d", rc);
1964 qeth_release_buffer(iob->channel, iob);
1965 atomic_set(&card->write.irq_pending, 0);
1966 wake_up(&card->wait_q);
1967 }
1968 return rc;
Jeff Garzike82b0f22006-05-26 21:58:38 -04001969}
Ursula Braun500f83a2005-09-30 10:19:19 +02001970
1971static inline void
1972qeth_prepare_ipa_cmd(struct qeth_card *card, struct qeth_cmd_buffer *iob,
1973 char prot_type)
1974{
1975 memcpy(iob->data, IPA_PDU_HEADER, IPA_PDU_HEADER_SIZE);
1976 memcpy(QETH_IPA_CMD_PROT_TYPE(iob->data),&prot_type,1);
1977 memcpy(QETH_IPA_CMD_DEST_ADDR(iob->data),
1978 &card->token.ulp_connection_r, QETH_MPC_TOKEN_LENGTH);
1979}
1980
1981static int
1982qeth_osn_send_ipa_cmd(struct qeth_card *card, struct qeth_cmd_buffer *iob,
1983 int data_len)
1984{
1985 u16 s1, s2;
1986
Frank Pavlic4965e972005-12-13 08:22:30 +01001987 QETH_DBF_TEXT(trace,4,"osndipa");
Ursula Braun500f83a2005-09-30 10:19:19 +02001988
1989 qeth_prepare_ipa_cmd(card, iob, QETH_PROT_OSN2);
1990 s1 = (u16)(IPA_PDU_HEADER_SIZE + data_len);
1991 s2 = (u16)data_len;
1992 memcpy(QETH_IPA_PDU_LEN_TOTAL(iob->data), &s1, 2);
1993 memcpy(QETH_IPA_PDU_LEN_PDU1(iob->data), &s2, 2);
1994 memcpy(QETH_IPA_PDU_LEN_PDU2(iob->data), &s2, 2);
1995 memcpy(QETH_IPA_PDU_LEN_PDU3(iob->data), &s2, 2);
1996 return qeth_osn_send_control_data(card, s1, iob);
1997}
Jeff Garzike82b0f22006-05-26 21:58:38 -04001998
Ursula Braun500f83a2005-09-30 10:19:19 +02001999static int
Linus Torvalds1da177e2005-04-16 15:20:36 -07002000qeth_send_ipa_cmd(struct qeth_card *card, struct qeth_cmd_buffer *iob,
2001 int (*reply_cb)
2002 (struct qeth_card *,struct qeth_reply*, unsigned long),
2003 void *reply_param)
2004{
2005 int rc;
2006 char prot_type;
2007
2008 QETH_DBF_TEXT(trace,4,"sendipa");
2009
Linus Torvalds1da177e2005-04-16 15:20:36 -07002010 if (card->options.layer2)
Ursula Braun500f83a2005-09-30 10:19:19 +02002011 if (card->info.type == QETH_CARD_TYPE_OSN)
2012 prot_type = QETH_PROT_OSN2;
2013 else
2014 prot_type = QETH_PROT_LAYER2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002015 else
2016 prot_type = QETH_PROT_TCPIP;
Ursula Braun500f83a2005-09-30 10:19:19 +02002017 qeth_prepare_ipa_cmd(card,iob,prot_type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002018 rc = qeth_send_control_data(card, IPA_CMD_LENGTH, iob,
2019 reply_cb, reply_param);
2020 return rc;
2021}
2022
2023
2024static int
2025qeth_cm_enable_cb(struct qeth_card *card, struct qeth_reply *reply,
2026 unsigned long data)
2027{
2028 struct qeth_cmd_buffer *iob;
2029
2030 QETH_DBF_TEXT(setup, 2, "cmenblcb");
2031
2032 iob = (struct qeth_cmd_buffer *) data;
2033 memcpy(&card->token.cm_filter_r,
2034 QETH_CM_ENABLE_RESP_FILTER_TOKEN(iob->data),
2035 QETH_MPC_TOKEN_LENGTH);
2036 QETH_DBF_TEXT_(setup, 2, " rc%d", iob->rc);
2037 return 0;
2038}
2039
2040static int
2041qeth_cm_enable(struct qeth_card *card)
2042{
2043 int rc;
2044 struct qeth_cmd_buffer *iob;
2045
2046 QETH_DBF_TEXT(setup,2,"cmenable");
2047
2048 iob = qeth_wait_for_buffer(&card->write);
2049 memcpy(iob->data, CM_ENABLE, CM_ENABLE_SIZE);
2050 memcpy(QETH_CM_ENABLE_ISSUER_RM_TOKEN(iob->data),
2051 &card->token.issuer_rm_r, QETH_MPC_TOKEN_LENGTH);
2052 memcpy(QETH_CM_ENABLE_FILTER_TOKEN(iob->data),
2053 &card->token.cm_filter_w, QETH_MPC_TOKEN_LENGTH);
2054
2055 rc = qeth_send_control_data(card, CM_ENABLE_SIZE, iob,
2056 qeth_cm_enable_cb, NULL);
2057 return rc;
2058}
2059
2060static int
2061qeth_cm_setup_cb(struct qeth_card *card, struct qeth_reply *reply,
2062 unsigned long data)
2063{
2064
2065 struct qeth_cmd_buffer *iob;
2066
2067 QETH_DBF_TEXT(setup, 2, "cmsetpcb");
2068
2069 iob = (struct qeth_cmd_buffer *) data;
2070 memcpy(&card->token.cm_connection_r,
2071 QETH_CM_SETUP_RESP_DEST_ADDR(iob->data),
2072 QETH_MPC_TOKEN_LENGTH);
2073 QETH_DBF_TEXT_(setup, 2, " rc%d", iob->rc);
2074 return 0;
2075}
2076
2077static int
2078qeth_cm_setup(struct qeth_card *card)
2079{
2080 int rc;
2081 struct qeth_cmd_buffer *iob;
2082
2083 QETH_DBF_TEXT(setup,2,"cmsetup");
2084
2085 iob = qeth_wait_for_buffer(&card->write);
2086 memcpy(iob->data, CM_SETUP, CM_SETUP_SIZE);
2087 memcpy(QETH_CM_SETUP_DEST_ADDR(iob->data),
2088 &card->token.issuer_rm_r, QETH_MPC_TOKEN_LENGTH);
2089 memcpy(QETH_CM_SETUP_CONNECTION_TOKEN(iob->data),
2090 &card->token.cm_connection_w, QETH_MPC_TOKEN_LENGTH);
2091 memcpy(QETH_CM_SETUP_FILTER_TOKEN(iob->data),
2092 &card->token.cm_filter_r, QETH_MPC_TOKEN_LENGTH);
2093 rc = qeth_send_control_data(card, CM_SETUP_SIZE, iob,
2094 qeth_cm_setup_cb, NULL);
2095 return rc;
2096
2097}
2098
2099static int
2100qeth_ulp_enable_cb(struct qeth_card *card, struct qeth_reply *reply,
2101 unsigned long data)
2102{
2103
2104 __u16 mtu, framesize;
2105 __u16 len;
2106 __u8 link_type;
2107 struct qeth_cmd_buffer *iob;
2108
2109 QETH_DBF_TEXT(setup, 2, "ulpenacb");
2110
2111 iob = (struct qeth_cmd_buffer *) data;
2112 memcpy(&card->token.ulp_filter_r,
2113 QETH_ULP_ENABLE_RESP_FILTER_TOKEN(iob->data),
2114 QETH_MPC_TOKEN_LENGTH);
2115 if (qeth_get_mtu_out_of_mpc(card->info.type)) {
2116 memcpy(&framesize, QETH_ULP_ENABLE_RESP_MAX_MTU(iob->data), 2);
2117 mtu = qeth_get_mtu_outof_framesize(framesize);
2118 if (!mtu) {
2119 iob->rc = -EINVAL;
2120 QETH_DBF_TEXT_(setup, 2, " rc%d", iob->rc);
2121 return 0;
2122 }
2123 card->info.max_mtu = mtu;
2124 card->info.initial_mtu = mtu;
2125 card->qdio.in_buf_size = mtu + 2 * PAGE_SIZE;
2126 } else {
2127 card->info.initial_mtu = qeth_get_initial_mtu_for_card(card);
2128 card->info.max_mtu = qeth_get_max_mtu_for_card(card->info.type);
2129 card->qdio.in_buf_size = QETH_IN_BUF_SIZE_DEFAULT;
2130 }
2131
2132 memcpy(&len, QETH_ULP_ENABLE_RESP_DIFINFO_LEN(iob->data), 2);
2133 if (len >= QETH_MPC_DIFINFO_LEN_INDICATES_LINK_TYPE) {
2134 memcpy(&link_type,
2135 QETH_ULP_ENABLE_RESP_LINK_TYPE(iob->data), 1);
2136 card->info.link_type = link_type;
2137 } else
2138 card->info.link_type = 0;
2139 QETH_DBF_TEXT_(setup, 2, " rc%d", iob->rc);
2140 return 0;
2141}
2142
2143static int
2144qeth_ulp_enable(struct qeth_card *card)
2145{
2146 int rc;
2147 char prot_type;
2148 struct qeth_cmd_buffer *iob;
2149
2150 /*FIXME: trace view callbacks*/
2151 QETH_DBF_TEXT(setup,2,"ulpenabl");
2152
2153 iob = qeth_wait_for_buffer(&card->write);
2154 memcpy(iob->data, ULP_ENABLE, ULP_ENABLE_SIZE);
2155
2156 *(QETH_ULP_ENABLE_LINKNUM(iob->data)) =
2157 (__u8) card->info.portno;
2158 if (card->options.layer2)
Ursula Braun500f83a2005-09-30 10:19:19 +02002159 if (card->info.type == QETH_CARD_TYPE_OSN)
2160 prot_type = QETH_PROT_OSN2;
2161 else
2162 prot_type = QETH_PROT_LAYER2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002163 else
2164 prot_type = QETH_PROT_TCPIP;
2165
2166 memcpy(QETH_ULP_ENABLE_PROT_TYPE(iob->data),&prot_type,1);
2167 memcpy(QETH_ULP_ENABLE_DEST_ADDR(iob->data),
2168 &card->token.cm_connection_r, QETH_MPC_TOKEN_LENGTH);
2169 memcpy(QETH_ULP_ENABLE_FILTER_TOKEN(iob->data),
2170 &card->token.ulp_filter_w, QETH_MPC_TOKEN_LENGTH);
2171 memcpy(QETH_ULP_ENABLE_PORTNAME_AND_LL(iob->data),
2172 card->info.portname, 9);
2173 rc = qeth_send_control_data(card, ULP_ENABLE_SIZE, iob,
2174 qeth_ulp_enable_cb, NULL);
2175 return rc;
2176
2177}
2178
Linus Torvalds1da177e2005-04-16 15:20:36 -07002179static int
2180qeth_ulp_setup_cb(struct qeth_card *card, struct qeth_reply *reply,
2181 unsigned long data)
2182{
2183 struct qeth_cmd_buffer *iob;
2184
2185 QETH_DBF_TEXT(setup, 2, "ulpstpcb");
2186
2187 iob = (struct qeth_cmd_buffer *) data;
2188 memcpy(&card->token.ulp_connection_r,
2189 QETH_ULP_SETUP_RESP_CONNECTION_TOKEN(iob->data),
2190 QETH_MPC_TOKEN_LENGTH);
2191 QETH_DBF_TEXT_(setup, 2, " rc%d", iob->rc);
2192 return 0;
2193}
2194
2195static int
2196qeth_ulp_setup(struct qeth_card *card)
2197{
2198 int rc;
2199 __u16 temp;
2200 struct qeth_cmd_buffer *iob;
Cornelia Huckdc5bc0c2007-06-20 13:00:20 +02002201 struct ccw_dev_id dev_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002202
2203 QETH_DBF_TEXT(setup,2,"ulpsetup");
2204
2205 iob = qeth_wait_for_buffer(&card->write);
2206 memcpy(iob->data, ULP_SETUP, ULP_SETUP_SIZE);
2207
2208 memcpy(QETH_ULP_SETUP_DEST_ADDR(iob->data),
2209 &card->token.cm_connection_r, QETH_MPC_TOKEN_LENGTH);
2210 memcpy(QETH_ULP_SETUP_CONNECTION_TOKEN(iob->data),
2211 &card->token.ulp_connection_w, QETH_MPC_TOKEN_LENGTH);
2212 memcpy(QETH_ULP_SETUP_FILTER_TOKEN(iob->data),
2213 &card->token.ulp_filter_r, QETH_MPC_TOKEN_LENGTH);
2214
Cornelia Huckdc5bc0c2007-06-20 13:00:20 +02002215 ccw_device_get_id(CARD_DDEV(card), &dev_id);
2216 memcpy(QETH_ULP_SETUP_CUA(iob->data), &dev_id.devno, 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002217 temp = (card->info.cula << 8) + card->info.unit_addr2;
2218 memcpy(QETH_ULP_SETUP_REAL_DEVADDR(iob->data), &temp, 2);
2219 rc = qeth_send_control_data(card, ULP_SETUP_SIZE, iob,
2220 qeth_ulp_setup_cb, NULL);
2221 return rc;
2222}
2223
2224static inline int
Frank Pavlic6c6b3e72005-12-13 08:21:47 +01002225qeth_check_qdio_errors(struct qdio_buffer *buf, unsigned int qdio_error,
2226 unsigned int siga_error, const char *dbftext)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002227{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002228 if (qdio_error || siga_error) {
Frank Pavlic6c6b3e72005-12-13 08:21:47 +01002229 QETH_DBF_TEXT(trace, 2, dbftext);
2230 QETH_DBF_TEXT(qerr, 2, dbftext);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002231 QETH_DBF_TEXT_(qerr, 2, " F15=%02X",
Frank Pavlic6c6b3e72005-12-13 08:21:47 +01002232 buf->element[15].flags & 0xff);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002233 QETH_DBF_TEXT_(qerr, 2, " F14=%02X",
Frank Pavlic6c6b3e72005-12-13 08:21:47 +01002234 buf->element[14].flags & 0xff);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002235 QETH_DBF_TEXT_(qerr, 2, " qerr=%X", qdio_error);
2236 QETH_DBF_TEXT_(qerr, 2, " serr=%X", siga_error);
Frank Pavlic6c6b3e72005-12-13 08:21:47 +01002237 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002238 }
Frank Pavlic6c6b3e72005-12-13 08:21:47 +01002239 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002240}
2241
Heiko Carstens4d284ca2007-02-05 21:18:53 +01002242static struct sk_buff *
Ursula Braun500f83a2005-09-30 10:19:19 +02002243qeth_get_skb(unsigned int length, struct qeth_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002244{
2245 struct sk_buff* skb;
Ursula Braun500f83a2005-09-30 10:19:19 +02002246 int add_len;
2247
2248 add_len = 0;
2249 if (hdr->hdr.osn.id == QETH_HEADER_TYPE_OSN)
2250 add_len = sizeof(struct qeth_hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002251#ifdef CONFIG_QETH_VLAN
Ursula Braun500f83a2005-09-30 10:19:19 +02002252 else
2253 add_len = VLAN_HLEN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002254#endif
Ursula Braun500f83a2005-09-30 10:19:19 +02002255 skb = dev_alloc_skb(length + add_len);
2256 if (skb && add_len)
2257 skb_reserve(skb, add_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002258 return skb;
2259}
2260
Heiko Carstens4d284ca2007-02-05 21:18:53 +01002261static struct sk_buff *
Linus Torvalds1da177e2005-04-16 15:20:36 -07002262qeth_get_next_skb(struct qeth_card *card, struct qdio_buffer *buffer,
2263 struct qdio_buffer_element **__element, int *__offset,
2264 struct qeth_hdr **hdr)
2265{
2266 struct qdio_buffer_element *element = *__element;
2267 int offset = *__offset;
2268 struct sk_buff *skb = NULL;
2269 int skb_len;
2270 void *data_ptr;
2271 int data_len;
2272
2273 QETH_DBF_TEXT(trace,6,"nextskb");
2274 /* qeth_hdr must not cross element boundaries */
2275 if (element->length < offset + sizeof(struct qeth_hdr)){
2276 if (qeth_is_last_sbale(element))
2277 return NULL;
2278 element++;
2279 offset = 0;
2280 if (element->length < sizeof(struct qeth_hdr))
2281 return NULL;
2282 }
2283 *hdr = element->addr + offset;
2284
2285 offset += sizeof(struct qeth_hdr);
2286 if (card->options.layer2)
Ursula Braun500f83a2005-09-30 10:19:19 +02002287 if (card->info.type == QETH_CARD_TYPE_OSN)
2288 skb_len = (*hdr)->hdr.osn.pdu_length;
2289 else
2290 skb_len = (*hdr)->hdr.l2.pkt_length;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002291 else
2292 skb_len = (*hdr)->hdr.l3.length;
2293
2294 if (!skb_len)
2295 return NULL;
2296 if (card->options.fake_ll){
Frank Pavlice23dd9c2005-05-12 20:38:11 +02002297 if(card->dev->type == ARPHRD_IEEE802_TR){
Ursula Braun500f83a2005-09-30 10:19:19 +02002298 if (!(skb = qeth_get_skb(skb_len+QETH_FAKE_LL_LEN_TR, *hdr)))
Frank Pavlice23dd9c2005-05-12 20:38:11 +02002299 goto no_mem;
2300 skb_reserve(skb,QETH_FAKE_LL_LEN_TR);
2301 } else {
Ursula Braun500f83a2005-09-30 10:19:19 +02002302 if (!(skb = qeth_get_skb(skb_len+QETH_FAKE_LL_LEN_ETH, *hdr)))
Frank Pavlice23dd9c2005-05-12 20:38:11 +02002303 goto no_mem;
2304 skb_reserve(skb,QETH_FAKE_LL_LEN_ETH);
2305 }
Ursula Braun500f83a2005-09-30 10:19:19 +02002306 } else if (!(skb = qeth_get_skb(skb_len, *hdr)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002307 goto no_mem;
2308 data_ptr = element->addr + offset;
2309 while (skb_len) {
2310 data_len = min(skb_len, (int)(element->length - offset));
2311 if (data_len)
2312 memcpy(skb_put(skb, data_len), data_ptr, data_len);
2313 skb_len -= data_len;
2314 if (skb_len){
2315 if (qeth_is_last_sbale(element)){
2316 QETH_DBF_TEXT(trace,4,"unexeob");
2317 QETH_DBF_TEXT_(trace,4,"%s",CARD_BUS_ID(card));
2318 QETH_DBF_TEXT(qerr,2,"unexeob");
2319 QETH_DBF_TEXT_(qerr,2,"%s",CARD_BUS_ID(card));
2320 QETH_DBF_HEX(misc,4,buffer,sizeof(*buffer));
2321 dev_kfree_skb_any(skb);
2322 card->stats.rx_errors++;
2323 return NULL;
2324 }
2325 element++;
2326 offset = 0;
2327 data_ptr = element->addr;
2328 } else {
2329 offset += data_len;
2330 }
2331 }
2332 *__element = element;
2333 *__offset = offset;
2334 return skb;
2335no_mem:
2336 if (net_ratelimit()){
2337 PRINT_WARN("No memory for packet received on %s.\n",
2338 QETH_CARD_IFNAME(card));
2339 QETH_DBF_TEXT(trace,2,"noskbmem");
2340 QETH_DBF_TEXT_(trace,2,"%s",CARD_BUS_ID(card));
2341 }
2342 card->stats.rx_dropped++;
2343 return NULL;
2344}
2345
Heiko Carstens4d284ca2007-02-05 21:18:53 +01002346static __be16
Linus Torvalds1da177e2005-04-16 15:20:36 -07002347qeth_type_trans(struct sk_buff *skb, struct net_device *dev)
2348{
2349 struct qeth_card *card;
2350 struct ethhdr *eth;
2351
2352 QETH_DBF_TEXT(trace,6,"typtrans");
2353
2354 card = (struct qeth_card *)dev->priv;
2355#ifdef CONFIG_TR
2356 if ((card->info.link_type == QETH_LINK_TYPE_HSTR) ||
2357 (card->info.link_type == QETH_LINK_TYPE_LANE_TR))
2358 return tr_type_trans(skb,dev);
2359#endif /* CONFIG_TR */
Arnaldo Carvalho de Melo459a98e2007-03-19 15:30:44 -07002360 skb_reset_mac_header(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002361 skb_pull(skb, ETH_HLEN );
2362 eth = eth_hdr(skb);
2363
2364 if (*eth->h_dest & 1) {
2365 if (memcmp(eth->h_dest, dev->broadcast, ETH_ALEN) == 0)
2366 skb->pkt_type = PACKET_BROADCAST;
2367 else
2368 skb->pkt_type = PACKET_MULTICAST;
2369 } else if (memcmp(eth->h_dest, dev->dev_addr, ETH_ALEN))
2370 skb->pkt_type = PACKET_OTHERHOST;
2371
2372 if (ntohs(eth->h_proto) >= 1536)
2373 return eth->h_proto;
2374 if (*(unsigned short *) (skb->data) == 0xFFFF)
2375 return htons(ETH_P_802_3);
2376 return htons(ETH_P_802_2);
2377}
2378
Heiko Carstens4d284ca2007-02-05 21:18:53 +01002379static void
Frank Pavlice23dd9c2005-05-12 20:38:11 +02002380qeth_rebuild_skb_fake_ll_tr(struct qeth_card *card, struct sk_buff *skb,
2381 struct qeth_hdr *hdr)
2382{
2383 struct trh_hdr *fake_hdr;
2384 struct trllc *fake_llc;
2385 struct iphdr *ip_hdr;
2386
2387 QETH_DBF_TEXT(trace,5,"skbfktr");
Arnaldo Carvalho de Melo48d49d0c2007-03-10 12:30:58 -03002388 skb_set_mac_header(skb, -QETH_FAKE_LL_LEN_TR);
Frank Pavlice23dd9c2005-05-12 20:38:11 +02002389 /* this is a fake ethernet header */
Arnaldo Carvalho de Meloc1a4b862007-03-19 15:27:07 -07002390 fake_hdr = tr_hdr(skb);
Frank Pavlice23dd9c2005-05-12 20:38:11 +02002391
2392 /* the destination MAC address */
2393 switch (skb->pkt_type){
2394 case PACKET_MULTICAST:
2395 switch (skb->protocol){
2396#ifdef CONFIG_QETH_IPV6
2397 case __constant_htons(ETH_P_IPV6):
2398 ndisc_mc_map((struct in6_addr *)
2399 skb->data + QETH_FAKE_LL_V6_ADDR_POS,
2400 fake_hdr->daddr, card->dev, 0);
2401 break;
2402#endif /* CONFIG_QETH_IPV6 */
2403 case __constant_htons(ETH_P_IP):
2404 ip_hdr = (struct iphdr *)skb->data;
2405 ip_tr_mc_map(ip_hdr->daddr, fake_hdr->daddr);
2406 break;
2407 default:
2408 memcpy(fake_hdr->daddr, card->dev->dev_addr, TR_ALEN);
2409 }
2410 break;
2411 case PACKET_BROADCAST:
2412 memset(fake_hdr->daddr, 0xff, TR_ALEN);
2413 break;
2414 default:
2415 memcpy(fake_hdr->daddr, card->dev->dev_addr, TR_ALEN);
2416 }
2417 /* the source MAC address */
2418 if (hdr->hdr.l3.ext_flags & QETH_HDR_EXT_SRC_MAC_ADDR)
2419 memcpy(fake_hdr->saddr, &hdr->hdr.l3.dest_addr[2], TR_ALEN);
2420 else
2421 memset(fake_hdr->saddr, 0, TR_ALEN);
2422 fake_hdr->rcf=0;
2423 fake_llc = (struct trllc*)&(fake_hdr->rcf);
2424 fake_llc->dsap = EXTENDED_SAP;
2425 fake_llc->ssap = EXTENDED_SAP;
2426 fake_llc->llc = UI_CMD;
2427 fake_llc->protid[0] = 0;
2428 fake_llc->protid[1] = 0;
2429 fake_llc->protid[2] = 0;
2430 fake_llc->ethertype = ETH_P_IP;
2431}
2432
Heiko Carstens4d284ca2007-02-05 21:18:53 +01002433static void
Frank Pavlice23dd9c2005-05-12 20:38:11 +02002434qeth_rebuild_skb_fake_ll_eth(struct qeth_card *card, struct sk_buff *skb,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002435 struct qeth_hdr *hdr)
2436{
2437 struct ethhdr *fake_hdr;
2438 struct iphdr *ip_hdr;
2439
Frank Pavlice23dd9c2005-05-12 20:38:11 +02002440 QETH_DBF_TEXT(trace,5,"skbfketh");
Arnaldo Carvalho de Melo48d49d0c2007-03-10 12:30:58 -03002441 skb_set_mac_header(skb, -QETH_FAKE_LL_LEN_ETH);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002442 /* this is a fake ethernet header */
Arnaldo Carvalho de Melo4839fcc2007-03-10 11:13:59 -03002443 fake_hdr = eth_hdr(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002444
2445 /* the destination MAC address */
2446 switch (skb->pkt_type){
2447 case PACKET_MULTICAST:
2448 switch (skb->protocol){
2449#ifdef CONFIG_QETH_IPV6
2450 case __constant_htons(ETH_P_IPV6):
2451 ndisc_mc_map((struct in6_addr *)
2452 skb->data + QETH_FAKE_LL_V6_ADDR_POS,
2453 fake_hdr->h_dest, card->dev, 0);
2454 break;
2455#endif /* CONFIG_QETH_IPV6 */
2456 case __constant_htons(ETH_P_IP):
2457 ip_hdr = (struct iphdr *)skb->data;
Frank Pavlice23dd9c2005-05-12 20:38:11 +02002458 ip_eth_mc_map(ip_hdr->daddr, fake_hdr->h_dest);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002459 break;
2460 default:
2461 memcpy(fake_hdr->h_dest, card->dev->dev_addr, ETH_ALEN);
2462 }
2463 break;
2464 case PACKET_BROADCAST:
2465 memset(fake_hdr->h_dest, 0xff, ETH_ALEN);
2466 break;
2467 default:
2468 memcpy(fake_hdr->h_dest, card->dev->dev_addr, ETH_ALEN);
2469 }
2470 /* the source MAC address */
2471 if (hdr->hdr.l3.ext_flags & QETH_HDR_EXT_SRC_MAC_ADDR)
2472 memcpy(fake_hdr->h_source, &hdr->hdr.l3.dest_addr[2], ETH_ALEN);
2473 else
2474 memset(fake_hdr->h_source, 0, ETH_ALEN);
2475 /* the protocol */
2476 fake_hdr->h_proto = skb->protocol;
2477}
2478
2479static inline void
Frank Pavlice23dd9c2005-05-12 20:38:11 +02002480qeth_rebuild_skb_fake_ll(struct qeth_card *card, struct sk_buff *skb,
2481 struct qeth_hdr *hdr)
2482{
2483 if (card->dev->type == ARPHRD_IEEE802_TR)
2484 qeth_rebuild_skb_fake_ll_tr(card, skb, hdr);
2485 else
2486 qeth_rebuild_skb_fake_ll_eth(card, skb, hdr);
2487}
2488
Frank Blaschka95c78c82007-01-08 17:29:34 +01002489static inline void
Linus Torvalds1da177e2005-04-16 15:20:36 -07002490qeth_layer2_rebuild_skb(struct qeth_card *card, struct sk_buff *skb,
2491 struct qeth_hdr *hdr)
2492{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002493 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;
Ursula Braun9123e0d2005-09-30 10:17:24 +02002499 *((__u32 *)skb->cb) = ++card->seqno.pkt_seqno;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002500}
2501
Heiko Carstens4d284ca2007-02-05 21:18:53 +01002502static __u16
Linus Torvalds1da177e2005-04-16 15:20:36 -07002503qeth_rebuild_skb(struct qeth_card *card, struct sk_buff *skb,
2504 struct qeth_hdr *hdr)
2505{
Frank Pavlic330b6362006-09-15 16:25:56 +02002506 unsigned short vlan_id = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002507#ifdef CONFIG_QETH_IPV6
2508 if (hdr->hdr.l3.flags & QETH_HDR_PASSTHRU) {
2509 skb->pkt_type = PACKET_HOST;
2510 skb->protocol = qeth_type_trans(skb, card->dev);
Frank Pavlic330b6362006-09-15 16:25:56 +02002511 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002512 }
2513#endif /* CONFIG_QETH_IPV6 */
2514 skb->protocol = htons((hdr->hdr.l3.flags & QETH_HDR_IPV6)? ETH_P_IPV6 :
2515 ETH_P_IP);
2516 switch (hdr->hdr.l3.flags & QETH_HDR_CAST_MASK){
2517 case QETH_CAST_UNICAST:
2518 skb->pkt_type = PACKET_HOST;
2519 break;
2520 case QETH_CAST_MULTICAST:
2521 skb->pkt_type = PACKET_MULTICAST;
2522 card->stats.multicast++;
2523 break;
2524 case QETH_CAST_BROADCAST:
2525 skb->pkt_type = PACKET_BROADCAST;
2526 card->stats.multicast++;
2527 break;
2528 case QETH_CAST_ANYCAST:
2529 case QETH_CAST_NOCAST:
2530 default:
2531 skb->pkt_type = PACKET_HOST;
2532 }
Frank Pavlic330b6362006-09-15 16:25:56 +02002533
2534 if (hdr->hdr.l3.ext_flags &
2535 (QETH_HDR_EXT_VLAN_FRAME | QETH_HDR_EXT_INCLUDE_VLAN_TAG)) {
2536 vlan_id = (hdr->hdr.l3.ext_flags & QETH_HDR_EXT_VLAN_FRAME)?
2537 hdr->hdr.l3.vlan_id : *((u16 *)&hdr->hdr.l3.dest_addr[12]);
2538 }
2539
Linus Torvalds1da177e2005-04-16 15:20:36 -07002540 if (card->options.fake_ll)
2541 qeth_rebuild_skb_fake_ll(card, skb, hdr);
2542 else
Arnaldo Carvalho de Melo459a98e2007-03-19 15:30:44 -07002543 skb_reset_mac_header(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002544 skb->ip_summed = card->options.checksum_type;
2545 if (card->options.checksum_type == HW_CHECKSUMMING){
2546 if ( (hdr->hdr.l3.ext_flags &
2547 (QETH_HDR_EXT_CSUM_HDR_REQ |
2548 QETH_HDR_EXT_CSUM_TRANSP_REQ)) ==
2549 (QETH_HDR_EXT_CSUM_HDR_REQ |
2550 QETH_HDR_EXT_CSUM_TRANSP_REQ) )
2551 skb->ip_summed = CHECKSUM_UNNECESSARY;
2552 else
2553 skb->ip_summed = SW_CHECKSUMMING;
2554 }
Frank Pavlic330b6362006-09-15 16:25:56 +02002555 return vlan_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002556}
2557
Heiko Carstens4d284ca2007-02-05 21:18:53 +01002558static void
Linus Torvalds1da177e2005-04-16 15:20:36 -07002559qeth_process_inbound_buffer(struct qeth_card *card,
2560 struct qeth_qdio_buffer *buf, int index)
2561{
2562 struct qdio_buffer_element *element;
2563 struct sk_buff *skb;
2564 struct qeth_hdr *hdr;
2565 int offset;
2566 int rxrc;
2567 __u16 vlan_tag = 0;
2568
2569 /* get first element of current buffer */
2570 element = (struct qdio_buffer_element *)&buf->buffer->element[0];
2571 offset = 0;
Frank Pavlic09d2d382006-09-15 16:26:34 +02002572 if (card->options.performance_stats)
2573 card->perf_stats.bufs_rec++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002574 while((skb = qeth_get_next_skb(card, buf->buffer, &element,
2575 &offset, &hdr))) {
2576 skb->dev = card->dev;
2577 if (hdr->hdr.l2.id == QETH_HEADER_TYPE_LAYER2)
Frank Blaschka95c78c82007-01-08 17:29:34 +01002578 qeth_layer2_rebuild_skb(card, skb, hdr);
Jeff Garzike82b0f22006-05-26 21:58:38 -04002579 else if (hdr->hdr.l3.id == QETH_HEADER_TYPE_LAYER3)
Frank Pavlic330b6362006-09-15 16:25:56 +02002580 vlan_tag = qeth_rebuild_skb(card, skb, hdr);
Ursula Braun500f83a2005-09-30 10:19:19 +02002581 else { /*in case of OSN*/
2582 skb_push(skb, sizeof(struct qeth_hdr));
Arnaldo Carvalho de Melo27d7ff42007-03-31 11:55:19 -03002583 skb_copy_to_linear_data(skb, hdr,
2584 sizeof(struct qeth_hdr));
Ursula Braun500f83a2005-09-30 10:19:19 +02002585 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002586 /* is device UP ? */
2587 if (!(card->dev->flags & IFF_UP)){
2588 dev_kfree_skb_any(skb);
2589 continue;
2590 }
Ursula Braun500f83a2005-09-30 10:19:19 +02002591 if (card->info.type == QETH_CARD_TYPE_OSN)
2592 rxrc = card->osn_info.data_cb(skb);
2593 else
Frank Pavlic330b6362006-09-15 16:25:56 +02002594#ifdef CONFIG_QETH_VLAN
2595 if (vlan_tag)
2596 if (card->vlangrp)
2597 vlan_hwaccel_rx(skb, card->vlangrp, vlan_tag);
2598 else {
2599 dev_kfree_skb_any(skb);
2600 continue;
2601 }
2602 else
2603#endif
Ursula Braun500f83a2005-09-30 10:19:19 +02002604 rxrc = netif_rx(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002605 card->dev->last_rx = jiffies;
2606 card->stats.rx_packets++;
2607 card->stats.rx_bytes += skb->len;
2608 }
2609}
2610
Heiko Carstens4d284ca2007-02-05 21:18:53 +01002611static struct qeth_buffer_pool_entry *
Linus Torvalds1da177e2005-04-16 15:20:36 -07002612qeth_get_buffer_pool_entry(struct qeth_card *card)
2613{
2614 struct qeth_buffer_pool_entry *entry;
2615
2616 QETH_DBF_TEXT(trace, 6, "gtbfplen");
2617 if (!list_empty(&card->qdio.in_buf_pool.entry_list)) {
2618 entry = list_entry(card->qdio.in_buf_pool.entry_list.next,
2619 struct qeth_buffer_pool_entry, list);
2620 list_del_init(&entry->list);
2621 return entry;
2622 }
2623 return NULL;
2624}
2625
Heiko Carstens4d284ca2007-02-05 21:18:53 +01002626static void
Linus Torvalds1da177e2005-04-16 15:20:36 -07002627qeth_init_input_buffer(struct qeth_card *card, struct qeth_qdio_buffer *buf)
2628{
2629 struct qeth_buffer_pool_entry *pool_entry;
2630 int i;
Frank Pavlic09d2d382006-09-15 16:26:34 +02002631
Linus Torvalds1da177e2005-04-16 15:20:36 -07002632 pool_entry = qeth_get_buffer_pool_entry(card);
2633 /*
2634 * since the buffer is accessed only from the input_tasklet
2635 * there shouldn't be a need to synchronize; also, since we use
2636 * the QETH_IN_BUF_REQUEUE_THRESHOLD we should never run out off
2637 * buffers
2638 */
2639 BUG_ON(!pool_entry);
2640
2641 buf->pool_entry = pool_entry;
2642 for(i = 0; i < QETH_MAX_BUFFER_ELEMENTS(card); ++i){
2643 buf->buffer->element[i].length = PAGE_SIZE;
2644 buf->buffer->element[i].addr = pool_entry->elements[i];
2645 if (i == QETH_MAX_BUFFER_ELEMENTS(card) - 1)
2646 buf->buffer->element[i].flags = SBAL_FLAGS_LAST_ENTRY;
2647 else
2648 buf->buffer->element[i].flags = 0;
2649 }
2650 buf->state = QETH_QDIO_BUF_EMPTY;
2651}
2652
Heiko Carstens4d284ca2007-02-05 21:18:53 +01002653static void
Linus Torvalds1da177e2005-04-16 15:20:36 -07002654qeth_clear_output_buffer(struct qeth_qdio_out_q *queue,
2655 struct qeth_qdio_out_buffer *buf)
2656{
2657 int i;
2658 struct sk_buff *skb;
2659
2660 /* is PCI flag set on buffer? */
2661 if (buf->buffer->element[0].flags & 0x40)
2662 atomic_dec(&queue->set_pci_flags_count);
2663
2664 while ((skb = skb_dequeue(&buf->skb_list))){
2665 atomic_dec(&skb->users);
2666 dev_kfree_skb_any(skb);
2667 }
2668 qeth_eddp_buf_release_contexts(buf);
2669 for(i = 0; i < QETH_MAX_BUFFER_ELEMENTS(queue->card); ++i){
2670 buf->buffer->element[i].length = 0;
2671 buf->buffer->element[i].addr = NULL;
2672 buf->buffer->element[i].flags = 0;
2673 }
2674 buf->next_element_to_fill = 0;
2675 atomic_set(&buf->state, QETH_QDIO_BUF_EMPTY);
2676}
2677
Heiko Carstens4d284ca2007-02-05 21:18:53 +01002678static void
Linus Torvalds1da177e2005-04-16 15:20:36 -07002679qeth_queue_input_buffer(struct qeth_card *card, int index)
2680{
2681 struct qeth_qdio_q *queue = card->qdio.in_q;
2682 int count;
2683 int i;
2684 int rc;
2685
2686 QETH_DBF_TEXT(trace,6,"queinbuf");
2687 count = (index < queue->next_buf_to_init)?
2688 card->qdio.in_buf_pool.buf_count -
2689 (queue->next_buf_to_init - index) :
2690 card->qdio.in_buf_pool.buf_count -
2691 (queue->next_buf_to_init + QDIO_MAX_BUFFERS_PER_Q - index);
2692 /* only requeue at a certain threshold to avoid SIGAs */
2693 if (count >= QETH_IN_BUF_REQUEUE_THRESHOLD(card)){
2694 for (i = queue->next_buf_to_init;
2695 i < queue->next_buf_to_init + count; ++i)
2696 qeth_init_input_buffer(card,
2697 &queue->bufs[i % QDIO_MAX_BUFFERS_PER_Q]);
2698 /*
2699 * according to old code it should be avoided to requeue all
2700 * 128 buffers in order to benefit from PCI avoidance.
2701 * this function keeps at least one buffer (the buffer at
2702 * 'index') un-requeued -> this buffer is the first buffer that
2703 * will be requeued the next time
2704 */
Frank Pavlic09d2d382006-09-15 16:26:34 +02002705 if (card->options.performance_stats) {
2706 card->perf_stats.inbound_do_qdio_cnt++;
2707 card->perf_stats.inbound_do_qdio_start_time =
2708 qeth_get_micros();
2709 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002710 rc = do_QDIO(CARD_DDEV(card),
2711 QDIO_FLAG_SYNC_INPUT | QDIO_FLAG_UNDER_INTERRUPT,
2712 0, queue->next_buf_to_init, count, NULL);
Frank Pavlic09d2d382006-09-15 16:26:34 +02002713 if (card->options.performance_stats)
2714 card->perf_stats.inbound_do_qdio_time +=
2715 qeth_get_micros() -
2716 card->perf_stats.inbound_do_qdio_start_time;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002717 if (rc){
2718 PRINT_WARN("qeth_queue_input_buffer's do_QDIO "
2719 "return %i (device %s).\n",
2720 rc, CARD_DDEV_ID(card));
2721 QETH_DBF_TEXT(trace,2,"qinberr");
2722 QETH_DBF_TEXT_(trace,2,"%s",CARD_BUS_ID(card));
2723 }
2724 queue->next_buf_to_init = (queue->next_buf_to_init + count) %
2725 QDIO_MAX_BUFFERS_PER_Q;
2726 }
2727}
2728
2729static inline void
2730qeth_put_buffer_pool_entry(struct qeth_card *card,
2731 struct qeth_buffer_pool_entry *entry)
2732{
2733 QETH_DBF_TEXT(trace, 6, "ptbfplen");
2734 list_add_tail(&entry->list, &card->qdio.in_buf_pool.entry_list);
2735}
2736
2737static void
2738qeth_qdio_input_handler(struct ccw_device * ccwdev, unsigned int status,
2739 unsigned int qdio_err, unsigned int siga_err,
2740 unsigned int queue, int first_element, int count,
2741 unsigned long card_ptr)
2742{
2743 struct net_device *net_dev;
2744 struct qeth_card *card;
2745 struct qeth_qdio_buffer *buffer;
2746 int index;
2747 int i;
2748
2749 QETH_DBF_TEXT(trace, 6, "qdinput");
2750 card = (struct qeth_card *) card_ptr;
2751 net_dev = card->dev;
Frank Pavlic09d2d382006-09-15 16:26:34 +02002752 if (card->options.performance_stats) {
2753 card->perf_stats.inbound_cnt++;
2754 card->perf_stats.inbound_start_time = qeth_get_micros();
2755 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002756 if (status & QDIO_STATUS_LOOK_FOR_ERROR) {
2757 if (status & QDIO_STATUS_ACTIVATE_CHECK_CONDITION){
2758 QETH_DBF_TEXT(trace, 1,"qdinchk");
2759 QETH_DBF_TEXT_(trace,1,"%s",CARD_BUS_ID(card));
2760 QETH_DBF_TEXT_(trace,1,"%04X%04X",first_element,count);
2761 QETH_DBF_TEXT_(trace,1,"%04X%04X", queue, status);
2762 qeth_schedule_recovery(card);
2763 return;
2764 }
2765 }
2766 for (i = first_element; i < (first_element + count); ++i) {
2767 index = i % QDIO_MAX_BUFFERS_PER_Q;
2768 buffer = &card->qdio.in_q->bufs[index];
Frank Pavlic6c6b3e72005-12-13 08:21:47 +01002769 if (!((status & QDIO_STATUS_LOOK_FOR_ERROR) &&
Jeff Garzike82b0f22006-05-26 21:58:38 -04002770 qeth_check_qdio_errors(buffer->buffer,
Frank Pavlic6c6b3e72005-12-13 08:21:47 +01002771 qdio_err, siga_err,"qinerr")))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002772 qeth_process_inbound_buffer(card, buffer, index);
2773 /* clear buffer and give back to hardware */
2774 qeth_put_buffer_pool_entry(card, buffer->pool_entry);
2775 qeth_queue_input_buffer(card, index);
2776 }
Frank Pavlic09d2d382006-09-15 16:26:34 +02002777 if (card->options.performance_stats)
2778 card->perf_stats.inbound_time += qeth_get_micros() -
2779 card->perf_stats.inbound_start_time;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002780}
2781
Heiko Carstens4d284ca2007-02-05 21:18:53 +01002782static int
Linus Torvalds1da177e2005-04-16 15:20:36 -07002783qeth_handle_send_error(struct qeth_card *card,
2784 struct qeth_qdio_out_buffer *buffer,
Frank Pavlic6c6b3e72005-12-13 08:21:47 +01002785 unsigned int qdio_err, unsigned int siga_err)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002786{
2787 int sbalf15 = buffer->buffer->element[15].flags & 0xff;
2788 int cc = siga_err & 3;
2789
2790 QETH_DBF_TEXT(trace, 6, "hdsnderr");
Frank Pavlic6c6b3e72005-12-13 08:21:47 +01002791 qeth_check_qdio_errors(buffer->buffer, qdio_err, siga_err, "qouterr");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002792 switch (cc) {
2793 case 0:
2794 if (qdio_err){
2795 QETH_DBF_TEXT(trace, 1,"lnkfail");
2796 QETH_DBF_TEXT_(trace,1,"%s",CARD_BUS_ID(card));
2797 QETH_DBF_TEXT_(trace,1,"%04x %02x",
2798 (u16)qdio_err, (u8)sbalf15);
2799 return QETH_SEND_ERROR_LINK_FAILURE;
2800 }
2801 return QETH_SEND_ERROR_NONE;
2802 case 2:
2803 if (siga_err & QDIO_SIGA_ERROR_B_BIT_SET) {
2804 QETH_DBF_TEXT(trace, 1, "SIGAcc2B");
2805 QETH_DBF_TEXT_(trace,1,"%s",CARD_BUS_ID(card));
2806 return QETH_SEND_ERROR_KICK_IT;
2807 }
2808 if ((sbalf15 >= 15) && (sbalf15 <= 31))
2809 return QETH_SEND_ERROR_RETRY;
2810 return QETH_SEND_ERROR_LINK_FAILURE;
2811 /* look at qdio_error and sbalf 15 */
2812 case 1:
2813 QETH_DBF_TEXT(trace, 1, "SIGAcc1");
2814 QETH_DBF_TEXT_(trace,1,"%s",CARD_BUS_ID(card));
2815 return QETH_SEND_ERROR_LINK_FAILURE;
2816 case 3:
Frank Pavlic1380fee2006-03-22 16:03:41 +01002817 default:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002818 QETH_DBF_TEXT(trace, 1, "SIGAcc3");
2819 QETH_DBF_TEXT_(trace,1,"%s",CARD_BUS_ID(card));
2820 return QETH_SEND_ERROR_KICK_IT;
2821 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002822}
2823
2824void
2825qeth_flush_buffers(struct qeth_qdio_out_q *queue, int under_int,
2826 int index, int count)
2827{
2828 struct qeth_qdio_out_buffer *buf;
2829 int rc;
2830 int i;
Ursula Braun1f8bdae2007-05-02 15:18:07 +02002831 unsigned int qdio_flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002832
2833 QETH_DBF_TEXT(trace, 6, "flushbuf");
2834
2835 for (i = index; i < index + count; ++i) {
2836 buf = &queue->bufs[i % QDIO_MAX_BUFFERS_PER_Q];
2837 buf->buffer->element[buf->next_element_to_fill - 1].flags |=
2838 SBAL_FLAGS_LAST_ENTRY;
2839
2840 if (queue->card->info.type == QETH_CARD_TYPE_IQD)
2841 continue;
2842
2843 if (!queue->do_pack){
2844 if ((atomic_read(&queue->used_buffers) >=
2845 (QETH_HIGH_WATERMARK_PACK -
2846 QETH_WATERMARK_PACK_FUZZ)) &&
2847 !atomic_read(&queue->set_pci_flags_count)){
2848 /* it's likely that we'll go to packing
2849 * mode soon */
2850 atomic_inc(&queue->set_pci_flags_count);
2851 buf->buffer->element[0].flags |= 0x40;
2852 }
2853 } else {
2854 if (!atomic_read(&queue->set_pci_flags_count)){
2855 /*
2856 * there's no outstanding PCI any more, so we
Michael Opdenacker59c51592007-05-09 08:57:56 +02002857 * have to request a PCI to be sure that the PCI
Linus Torvalds1da177e2005-04-16 15:20:36 -07002858 * will wake at some time in the future then we
2859 * can flush packed buffers that might still be
2860 * hanging around, which can happen if no
2861 * further send was requested by the stack
2862 */
2863 atomic_inc(&queue->set_pci_flags_count);
2864 buf->buffer->element[0].flags |= 0x40;
2865 }
2866 }
2867 }
2868
2869 queue->card->dev->trans_start = jiffies;
Frank Pavlic09d2d382006-09-15 16:26:34 +02002870 if (queue->card->options.performance_stats) {
2871 queue->card->perf_stats.outbound_do_qdio_cnt++;
2872 queue->card->perf_stats.outbound_do_qdio_start_time =
2873 qeth_get_micros();
2874 }
Ursula Braun1f8bdae2007-05-02 15:18:07 +02002875 qdio_flags = QDIO_FLAG_SYNC_OUTPUT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002876 if (under_int)
Ursula Braun1f8bdae2007-05-02 15:18:07 +02002877 qdio_flags |= QDIO_FLAG_UNDER_INTERRUPT;
2878 if (atomic_read(&queue->set_pci_flags_count))
2879 qdio_flags |= QDIO_FLAG_PCI_OUT;
2880 rc = do_QDIO(CARD_DDEV(queue->card), qdio_flags,
2881 queue->queue_no, index, count, NULL);
Frank Pavlic09d2d382006-09-15 16:26:34 +02002882 if (queue->card->options.performance_stats)
2883 queue->card->perf_stats.outbound_do_qdio_time +=
2884 qeth_get_micros() -
2885 queue->card->perf_stats.outbound_do_qdio_start_time;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002886 if (rc){
Linus Torvalds1da177e2005-04-16 15:20:36 -07002887 QETH_DBF_TEXT(trace, 2, "flushbuf");
2888 QETH_DBF_TEXT_(trace, 2, " err%d", rc);
Frank Pavlicf3d242e2005-09-14 18:05:31 +02002889 QETH_DBF_TEXT_(trace, 2, "%s", CARD_DDEV_ID(queue->card));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002890 queue->card->stats.tx_errors += count;
2891 /* this must not happen under normal circumstances. if it
2892 * happens something is really wrong -> recover */
2893 qeth_schedule_recovery(queue->card);
2894 return;
2895 }
2896 atomic_add(count, &queue->used_buffers);
Frank Pavlic09d2d382006-09-15 16:26:34 +02002897 if (queue->card->options.performance_stats)
2898 queue->card->perf_stats.bufs_sent += count;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002899}
2900
2901/*
2902 * Switched to packing state if the number of used buffers on a queue
2903 * reaches a certain limit.
2904 */
Heiko Carstens4d284ca2007-02-05 21:18:53 +01002905static void
Linus Torvalds1da177e2005-04-16 15:20:36 -07002906qeth_switch_to_packing_if_needed(struct qeth_qdio_out_q *queue)
2907{
2908 if (!queue->do_pack) {
2909 if (atomic_read(&queue->used_buffers)
2910 >= QETH_HIGH_WATERMARK_PACK){
2911 /* switch non-PACKING -> PACKING */
2912 QETH_DBF_TEXT(trace, 6, "np->pack");
Frank Pavlic09d2d382006-09-15 16:26:34 +02002913 if (queue->card->options.performance_stats)
2914 queue->card->perf_stats.sc_dp_p++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002915 queue->do_pack = 1;
2916 }
2917 }
2918}
2919
2920/*
2921 * Switches from packing to non-packing mode. If there is a packing
2922 * buffer on the queue this buffer will be prepared to be flushed.
2923 * In that case 1 is returned to inform the caller. If no buffer
2924 * has to be flushed, zero is returned.
2925 */
Heiko Carstens4d284ca2007-02-05 21:18:53 +01002926static int
Linus Torvalds1da177e2005-04-16 15:20:36 -07002927qeth_switch_to_nonpacking_if_needed(struct qeth_qdio_out_q *queue)
2928{
2929 struct qeth_qdio_out_buffer *buffer;
2930 int flush_count = 0;
2931
2932 if (queue->do_pack) {
2933 if (atomic_read(&queue->used_buffers)
2934 <= QETH_LOW_WATERMARK_PACK) {
2935 /* switch PACKING -> non-PACKING */
2936 QETH_DBF_TEXT(trace, 6, "pack->np");
Frank Pavlic09d2d382006-09-15 16:26:34 +02002937 if (queue->card->options.performance_stats)
2938 queue->card->perf_stats.sc_p_dp++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002939 queue->do_pack = 0;
2940 /* flush packing buffers */
2941 buffer = &queue->bufs[queue->next_buf_to_fill];
2942 if ((atomic_read(&buffer->state) ==
2943 QETH_QDIO_BUF_EMPTY) &&
2944 (buffer->next_element_to_fill > 0)) {
2945 atomic_set(&buffer->state,QETH_QDIO_BUF_PRIMED);
2946 flush_count++;
2947 queue->next_buf_to_fill =
2948 (queue->next_buf_to_fill + 1) %
2949 QDIO_MAX_BUFFERS_PER_Q;
Frank Pavlic09d2d382006-09-15 16:26:34 +02002950 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002951 }
2952 }
2953 return flush_count;
2954}
2955
2956/*
2957 * Called to flush a packing buffer if no more pci flags are on the queue.
2958 * Checks if there is a packing buffer and prepares it to be flushed.
2959 * In that case returns 1, otherwise zero.
2960 */
Heiko Carstens4d284ca2007-02-05 21:18:53 +01002961static int
Linus Torvalds1da177e2005-04-16 15:20:36 -07002962qeth_flush_buffers_on_no_pci(struct qeth_qdio_out_q *queue)
2963{
2964 struct qeth_qdio_out_buffer *buffer;
2965
2966 buffer = &queue->bufs[queue->next_buf_to_fill];
2967 if((atomic_read(&buffer->state) == QETH_QDIO_BUF_EMPTY) &&
2968 (buffer->next_element_to_fill > 0)){
2969 /* it's a packing buffer */
2970 atomic_set(&buffer->state, QETH_QDIO_BUF_PRIMED);
2971 queue->next_buf_to_fill =
2972 (queue->next_buf_to_fill + 1) % QDIO_MAX_BUFFERS_PER_Q;
2973 return 1;
2974 }
2975 return 0;
2976}
2977
Heiko Carstens4d284ca2007-02-05 21:18:53 +01002978static void
Linus Torvalds1da177e2005-04-16 15:20:36 -07002979qeth_check_outbound_queue(struct qeth_qdio_out_q *queue)
2980{
2981 int index;
2982 int flush_cnt = 0;
2983 int q_was_packing = 0;
2984
2985 /*
2986 * check if weed have to switch to non-packing mode or if
2987 * we have to get a pci flag out on the queue
2988 */
2989 if ((atomic_read(&queue->used_buffers) <= QETH_LOW_WATERMARK_PACK) ||
2990 !atomic_read(&queue->set_pci_flags_count)){
Ursula Braun9163bb22006-12-04 15:40:59 +01002991 if (atomic_xchg(&queue->state, QETH_OUT_Q_LOCKED_FLUSH) ==
Linus Torvalds1da177e2005-04-16 15:20:36 -07002992 QETH_OUT_Q_UNLOCKED) {
2993 /*
2994 * If we get in here, there was no action in
2995 * do_send_packet. So, we check if there is a
2996 * packing buffer to be flushed here.
2997 */
2998 netif_stop_queue(queue->card->dev);
2999 index = queue->next_buf_to_fill;
3000 q_was_packing = queue->do_pack;
3001 flush_cnt += qeth_switch_to_nonpacking_if_needed(queue);
3002 if (!flush_cnt &&
3003 !atomic_read(&queue->set_pci_flags_count))
3004 flush_cnt +=
3005 qeth_flush_buffers_on_no_pci(queue);
Frank Pavlic09d2d382006-09-15 16:26:34 +02003006 if (queue->card->options.performance_stats &&
3007 q_was_packing)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003008 queue->card->perf_stats.bufs_sent_pack +=
3009 flush_cnt;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003010 if (flush_cnt)
3011 qeth_flush_buffers(queue, 1, index, flush_cnt);
3012 atomic_set(&queue->state, QETH_OUT_Q_UNLOCKED);
3013 }
3014 }
3015}
3016
3017static void
3018qeth_qdio_output_handler(struct ccw_device * ccwdev, unsigned int status,
3019 unsigned int qdio_error, unsigned int siga_error,
3020 unsigned int __queue, int first_element, int count,
3021 unsigned long card_ptr)
3022{
3023 struct qeth_card *card = (struct qeth_card *) card_ptr;
3024 struct qeth_qdio_out_q *queue = card->qdio.out_qs[__queue];
3025 struct qeth_qdio_out_buffer *buffer;
3026 int i;
3027
3028 QETH_DBF_TEXT(trace, 6, "qdouhdl");
3029 if (status & QDIO_STATUS_LOOK_FOR_ERROR) {
3030 if (status & QDIO_STATUS_ACTIVATE_CHECK_CONDITION){
Frank Pavlicf3d242e2005-09-14 18:05:31 +02003031 QETH_DBF_TEXT(trace, 2, "achkcond");
3032 QETH_DBF_TEXT_(trace, 2, "%s", CARD_BUS_ID(card));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003033 QETH_DBF_TEXT_(trace, 2, "%08x", status);
3034 netif_stop_queue(card->dev);
3035 qeth_schedule_recovery(card);
3036 return;
3037 }
3038 }
Frank Pavlic09d2d382006-09-15 16:26:34 +02003039 if (card->options.performance_stats) {
3040 card->perf_stats.outbound_handler_cnt++;
3041 card->perf_stats.outbound_handler_start_time =
3042 qeth_get_micros();
3043 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003044 for(i = first_element; i < (first_element + count); ++i){
3045 buffer = &queue->bufs[i % QDIO_MAX_BUFFERS_PER_Q];
3046 /*we only handle the KICK_IT error by doing a recovery */
Frank Pavlic6c6b3e72005-12-13 08:21:47 +01003047 if (qeth_handle_send_error(card, buffer,
3048 qdio_error, siga_error)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003049 == QETH_SEND_ERROR_KICK_IT){
3050 netif_stop_queue(card->dev);
3051 qeth_schedule_recovery(card);
3052 return;
3053 }
3054 qeth_clear_output_buffer(queue, buffer);
3055 }
3056 atomic_sub(count, &queue->used_buffers);
3057 /* check if we need to do something on this outbound queue */
3058 if (card->info.type != QETH_CARD_TYPE_IQD)
3059 qeth_check_outbound_queue(queue);
3060
3061 netif_wake_queue(queue->card->dev);
Frank Pavlic09d2d382006-09-15 16:26:34 +02003062 if (card->options.performance_stats)
3063 card->perf_stats.outbound_handler_time += qeth_get_micros() -
3064 card->perf_stats.outbound_handler_start_time;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003065}
3066
3067static void
3068qeth_create_qib_param_field(struct qeth_card *card, char *param_field)
3069{
3070
3071 param_field[0] = _ascebc['P'];
3072 param_field[1] = _ascebc['C'];
3073 param_field[2] = _ascebc['I'];
3074 param_field[3] = _ascebc['T'];
3075 *((unsigned int *) (&param_field[4])) = QETH_PCI_THRESHOLD_A(card);
3076 *((unsigned int *) (&param_field[8])) = QETH_PCI_THRESHOLD_B(card);
3077 *((unsigned int *) (&param_field[12])) = QETH_PCI_TIMER_VALUE(card);
3078}
3079
3080static void
3081qeth_create_qib_param_field_blkt(struct qeth_card *card, char *param_field)
3082{
3083 param_field[16] = _ascebc['B'];
3084 param_field[17] = _ascebc['L'];
3085 param_field[18] = _ascebc['K'];
3086 param_field[19] = _ascebc['T'];
3087 *((unsigned int *) (&param_field[20])) = card->info.blkt.time_total;
3088 *((unsigned int *) (&param_field[24])) = card->info.blkt.inter_packet;
3089 *((unsigned int *) (&param_field[28])) = card->info.blkt.inter_packet_jumbo;
3090}
3091
3092static void
3093qeth_initialize_working_pool_list(struct qeth_card *card)
3094{
3095 struct qeth_buffer_pool_entry *entry;
3096
3097 QETH_DBF_TEXT(trace,5,"inwrklst");
3098
3099 list_for_each_entry(entry,
3100 &card->qdio.init_pool.entry_list, init_list) {
3101 qeth_put_buffer_pool_entry(card,entry);
3102 }
3103}
3104
3105static void
3106qeth_clear_working_pool_list(struct qeth_card *card)
3107{
3108 struct qeth_buffer_pool_entry *pool_entry, *tmp;
3109
3110 QETH_DBF_TEXT(trace,5,"clwrklst");
3111 list_for_each_entry_safe(pool_entry, tmp,
3112 &card->qdio.in_buf_pool.entry_list, list){
3113 list_del(&pool_entry->list);
3114 }
3115}
3116
3117static void
3118qeth_free_buffer_pool(struct qeth_card *card)
3119{
3120 struct qeth_buffer_pool_entry *pool_entry, *tmp;
3121 int i=0;
3122 QETH_DBF_TEXT(trace,5,"freepool");
3123 list_for_each_entry_safe(pool_entry, tmp,
3124 &card->qdio.init_pool.entry_list, init_list){
3125 for (i = 0; i < QETH_MAX_BUFFER_ELEMENTS(card); ++i)
3126 free_page((unsigned long)pool_entry->elements[i]);
3127 list_del(&pool_entry->init_list);
3128 kfree(pool_entry);
3129 }
3130}
3131
3132static int
3133qeth_alloc_buffer_pool(struct qeth_card *card)
3134{
3135 struct qeth_buffer_pool_entry *pool_entry;
3136 void *ptr;
3137 int i, j;
3138
3139 QETH_DBF_TEXT(trace,5,"alocpool");
3140 for (i = 0; i < card->qdio.init_pool.buf_count; ++i){
3141 pool_entry = kmalloc(sizeof(*pool_entry), GFP_KERNEL);
3142 if (!pool_entry){
3143 qeth_free_buffer_pool(card);
3144 return -ENOMEM;
3145 }
3146 for(j = 0; j < QETH_MAX_BUFFER_ELEMENTS(card); ++j){
Ursula Braun9123e0d2005-09-30 10:17:24 +02003147 ptr = (void *) __get_free_page(GFP_KERNEL|GFP_DMA);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003148 if (!ptr) {
3149 while (j > 0)
3150 free_page((unsigned long)
3151 pool_entry->elements[--j]);
3152 kfree(pool_entry);
3153 qeth_free_buffer_pool(card);
3154 return -ENOMEM;
3155 }
3156 pool_entry->elements[j] = ptr;
3157 }
3158 list_add(&pool_entry->init_list,
3159 &card->qdio.init_pool.entry_list);
3160 }
3161 return 0;
3162}
3163
3164int
3165qeth_realloc_buffer_pool(struct qeth_card *card, int bufcnt)
3166{
3167 QETH_DBF_TEXT(trace, 2, "realcbp");
3168
3169 if ((card->state != CARD_STATE_DOWN) &&
3170 (card->state != CARD_STATE_RECOVER))
3171 return -EPERM;
3172
3173 /* TODO: steel/add buffers from/to a running card's buffer pool (?) */
3174 qeth_clear_working_pool_list(card);
3175 qeth_free_buffer_pool(card);
3176 card->qdio.in_buf_pool.buf_count = bufcnt;
3177 card->qdio.init_pool.buf_count = bufcnt;
3178 return qeth_alloc_buffer_pool(card);
3179}
3180
3181static int
3182qeth_alloc_qdio_buffers(struct qeth_card *card)
3183{
3184 int i, j;
3185
3186 QETH_DBF_TEXT(setup, 2, "allcqdbf");
3187
Frank Pavlicf956b692006-09-15 16:26:52 +02003188 if (atomic_cmpxchg(&card->qdio.state, QETH_QDIO_UNINITIALIZED,
3189 QETH_QDIO_ALLOCATED) != QETH_QDIO_UNINITIALIZED)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003190 return 0;
3191
Jeff Garzike82b0f22006-05-26 21:58:38 -04003192 card->qdio.in_q = kmalloc(sizeof(struct qeth_qdio_q),
Ursula Braun9123e0d2005-09-30 10:17:24 +02003193 GFP_KERNEL|GFP_DMA);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003194 if (!card->qdio.in_q)
Frank Pavlicf956b692006-09-15 16:26:52 +02003195 goto out_nomem;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003196 QETH_DBF_TEXT(setup, 2, "inq");
3197 QETH_DBF_HEX(setup, 2, &card->qdio.in_q, sizeof(void *));
3198 memset(card->qdio.in_q, 0, sizeof(struct qeth_qdio_q));
3199 /* give inbound qeth_qdio_buffers their qdio_buffers */
3200 for (i = 0; i < QDIO_MAX_BUFFERS_PER_Q; ++i)
3201 card->qdio.in_q->bufs[i].buffer =
3202 &card->qdio.in_q->qdio_bufs[i];
3203 /* inbound buffer pool */
Frank Pavlicf956b692006-09-15 16:26:52 +02003204 if (qeth_alloc_buffer_pool(card))
3205 goto out_freeinq;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003206 /* outbound */
3207 card->qdio.out_qs =
3208 kmalloc(card->qdio.no_out_queues *
3209 sizeof(struct qeth_qdio_out_q *), GFP_KERNEL);
Frank Pavlicf956b692006-09-15 16:26:52 +02003210 if (!card->qdio.out_qs)
3211 goto out_freepool;
3212 for (i = 0; i < card->qdio.no_out_queues; ++i) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003213 card->qdio.out_qs[i] = kmalloc(sizeof(struct qeth_qdio_out_q),
Ursula Braun9123e0d2005-09-30 10:17:24 +02003214 GFP_KERNEL|GFP_DMA);
Frank Pavlicf956b692006-09-15 16:26:52 +02003215 if (!card->qdio.out_qs[i])
3216 goto out_freeoutq;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003217 QETH_DBF_TEXT_(setup, 2, "outq %i", i);
3218 QETH_DBF_HEX(setup, 2, &card->qdio.out_qs[i], sizeof(void *));
3219 memset(card->qdio.out_qs[i], 0, sizeof(struct qeth_qdio_out_q));
3220 card->qdio.out_qs[i]->queue_no = i;
3221 /* give outbound qeth_qdio_buffers their qdio_buffers */
3222 for (j = 0; j < QDIO_MAX_BUFFERS_PER_Q; ++j){
3223 card->qdio.out_qs[i]->bufs[j].buffer =
3224 &card->qdio.out_qs[i]->qdio_bufs[j];
3225 skb_queue_head_init(&card->qdio.out_qs[i]->bufs[j].
3226 skb_list);
Heiko Carstens91ebe2a2006-07-03 00:25:26 -07003227 lockdep_set_class(
3228 &card->qdio.out_qs[i]->bufs[j].skb_list.lock,
3229 &qdio_out_skb_queue_key);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003230 INIT_LIST_HEAD(&card->qdio.out_qs[i]->bufs[j].ctx_list);
3231 }
3232 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003233 return 0;
Frank Pavlicf956b692006-09-15 16:26:52 +02003234
3235out_freeoutq:
3236 while (i > 0)
3237 kfree(card->qdio.out_qs[--i]);
3238 kfree(card->qdio.out_qs);
3239out_freepool:
3240 qeth_free_buffer_pool(card);
3241out_freeinq:
3242 kfree(card->qdio.in_q);
3243out_nomem:
3244 atomic_set(&card->qdio.state, QETH_QDIO_UNINITIALIZED);
3245 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003246}
3247
3248static void
3249qeth_free_qdio_buffers(struct qeth_card *card)
3250{
3251 int i, j;
3252
3253 QETH_DBF_TEXT(trace, 2, "freeqdbf");
Ursula Braun9163bb22006-12-04 15:40:59 +01003254 if (atomic_xchg(&card->qdio.state, QETH_QDIO_UNINITIALIZED) ==
Frank Pavlicf956b692006-09-15 16:26:52 +02003255 QETH_QDIO_UNINITIALIZED)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003256 return;
3257 kfree(card->qdio.in_q);
3258 /* inbound buffer pool */
3259 qeth_free_buffer_pool(card);
3260 /* free outbound qdio_qs */
3261 for (i = 0; i < card->qdio.no_out_queues; ++i){
3262 for (j = 0; j < QDIO_MAX_BUFFERS_PER_Q; ++j)
3263 qeth_clear_output_buffer(card->qdio.out_qs[i],
3264 &card->qdio.out_qs[i]->bufs[j]);
3265 kfree(card->qdio.out_qs[i]);
3266 }
3267 kfree(card->qdio.out_qs);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003268}
3269
3270static void
3271qeth_clear_qdio_buffers(struct qeth_card *card)
3272{
3273 int i, j;
3274
3275 QETH_DBF_TEXT(trace, 2, "clearqdbf");
3276 /* clear outbound buffers to free skbs */
3277 for (i = 0; i < card->qdio.no_out_queues; ++i)
3278 if (card->qdio.out_qs[i]){
3279 for (j = 0; j < QDIO_MAX_BUFFERS_PER_Q; ++j)
3280 qeth_clear_output_buffer(card->qdio.out_qs[i],
3281 &card->qdio.out_qs[i]->bufs[j]);
3282 }
3283}
3284
3285static void
3286qeth_init_qdio_info(struct qeth_card *card)
3287{
3288 QETH_DBF_TEXT(setup, 4, "intqdinf");
Frank Pavlicf956b692006-09-15 16:26:52 +02003289 atomic_set(&card->qdio.state, QETH_QDIO_UNINITIALIZED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003290 /* inbound */
3291 card->qdio.in_buf_size = QETH_IN_BUF_SIZE_DEFAULT;
3292 card->qdio.init_pool.buf_count = QETH_IN_BUF_COUNT_DEFAULT;
3293 card->qdio.in_buf_pool.buf_count = card->qdio.init_pool.buf_count;
3294 INIT_LIST_HEAD(&card->qdio.in_buf_pool.entry_list);
3295 INIT_LIST_HEAD(&card->qdio.init_pool.entry_list);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003296}
3297
3298static int
3299qeth_init_qdio_queues(struct qeth_card *card)
3300{
3301 int i, j;
3302 int rc;
3303
3304 QETH_DBF_TEXT(setup, 2, "initqdqs");
3305
3306 /* inbound queue */
3307 memset(card->qdio.in_q->qdio_bufs, 0,
3308 QDIO_MAX_BUFFERS_PER_Q * sizeof(struct qdio_buffer));
3309 qeth_initialize_working_pool_list(card);
3310 /*give only as many buffers to hardware as we have buffer pool entries*/
3311 for (i = 0; i < card->qdio.in_buf_pool.buf_count - 1; ++i)
3312 qeth_init_input_buffer(card, &card->qdio.in_q->bufs[i]);
3313 card->qdio.in_q->next_buf_to_init = card->qdio.in_buf_pool.buf_count - 1;
3314 rc = do_QDIO(CARD_DDEV(card), QDIO_FLAG_SYNC_INPUT, 0, 0,
3315 card->qdio.in_buf_pool.buf_count - 1, NULL);
3316 if (rc) {
3317 QETH_DBF_TEXT_(setup, 2, "1err%d", rc);
3318 return rc;
3319 }
3320 rc = qdio_synchronize(CARD_DDEV(card), QDIO_FLAG_SYNC_INPUT, 0);
3321 if (rc) {
3322 QETH_DBF_TEXT_(setup, 2, "2err%d", rc);
3323 return rc;
3324 }
3325 /* outbound queue */
3326 for (i = 0; i < card->qdio.no_out_queues; ++i){
3327 memset(card->qdio.out_qs[i]->qdio_bufs, 0,
3328 QDIO_MAX_BUFFERS_PER_Q * sizeof(struct qdio_buffer));
3329 for (j = 0; j < QDIO_MAX_BUFFERS_PER_Q; ++j){
3330 qeth_clear_output_buffer(card->qdio.out_qs[i],
3331 &card->qdio.out_qs[i]->bufs[j]);
3332 }
3333 card->qdio.out_qs[i]->card = card;
3334 card->qdio.out_qs[i]->next_buf_to_fill = 0;
3335 card->qdio.out_qs[i]->do_pack = 0;
3336 atomic_set(&card->qdio.out_qs[i]->used_buffers,0);
3337 atomic_set(&card->qdio.out_qs[i]->set_pci_flags_count, 0);
3338 atomic_set(&card->qdio.out_qs[i]->state,
3339 QETH_OUT_Q_UNLOCKED);
3340 }
3341 return 0;
3342}
3343
3344static int
3345qeth_qdio_establish(struct qeth_card *card)
3346{
3347 struct qdio_initialize init_data;
3348 char *qib_param_field;
3349 struct qdio_buffer **in_sbal_ptrs;
3350 struct qdio_buffer **out_sbal_ptrs;
3351 int i, j, k;
Frank Pavlicf956b692006-09-15 16:26:52 +02003352 int rc = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003353
3354 QETH_DBF_TEXT(setup, 2, "qdioest");
3355
Eric Sesterhenn88abaab2006-03-24 03:15:31 -08003356 qib_param_field = kzalloc(QDIO_MAX_BUFFERS_PER_Q * sizeof(char),
Linus Torvalds1da177e2005-04-16 15:20:36 -07003357 GFP_KERNEL);
3358 if (!qib_param_field)
3359 return -ENOMEM;
3360
Linus Torvalds1da177e2005-04-16 15:20:36 -07003361 qeth_create_qib_param_field(card, qib_param_field);
3362 qeth_create_qib_param_field_blkt(card, qib_param_field);
3363
3364 in_sbal_ptrs = kmalloc(QDIO_MAX_BUFFERS_PER_Q * sizeof(void *),
3365 GFP_KERNEL);
3366 if (!in_sbal_ptrs) {
3367 kfree(qib_param_field);
3368 return -ENOMEM;
3369 }
3370 for(i = 0; i < QDIO_MAX_BUFFERS_PER_Q; ++i)
3371 in_sbal_ptrs[i] = (struct qdio_buffer *)
3372 virt_to_phys(card->qdio.in_q->bufs[i].buffer);
3373
3374 out_sbal_ptrs =
3375 kmalloc(card->qdio.no_out_queues * QDIO_MAX_BUFFERS_PER_Q *
3376 sizeof(void *), GFP_KERNEL);
3377 if (!out_sbal_ptrs) {
3378 kfree(in_sbal_ptrs);
3379 kfree(qib_param_field);
3380 return -ENOMEM;
3381 }
3382 for(i = 0, k = 0; i < card->qdio.no_out_queues; ++i)
3383 for(j = 0; j < QDIO_MAX_BUFFERS_PER_Q; ++j, ++k){
3384 out_sbal_ptrs[k] = (struct qdio_buffer *)
3385 virt_to_phys(card->qdio.out_qs[i]->
3386 bufs[j].buffer);
3387 }
3388
3389 memset(&init_data, 0, sizeof(struct qdio_initialize));
3390 init_data.cdev = CARD_DDEV(card);
3391 init_data.q_format = qeth_get_qdio_q_format(card);
3392 init_data.qib_param_field_format = 0;
3393 init_data.qib_param_field = qib_param_field;
3394 init_data.min_input_threshold = QETH_MIN_INPUT_THRESHOLD;
3395 init_data.max_input_threshold = QETH_MAX_INPUT_THRESHOLD;
3396 init_data.min_output_threshold = QETH_MIN_OUTPUT_THRESHOLD;
3397 init_data.max_output_threshold = QETH_MAX_OUTPUT_THRESHOLD;
3398 init_data.no_input_qs = 1;
3399 init_data.no_output_qs = card->qdio.no_out_queues;
3400 init_data.input_handler = (qdio_handler_t *)
3401 qeth_qdio_input_handler;
3402 init_data.output_handler = (qdio_handler_t *)
3403 qeth_qdio_output_handler;
3404 init_data.int_parm = (unsigned long) card;
3405 init_data.flags = QDIO_INBOUND_0COPY_SBALS |
3406 QDIO_OUTBOUND_0COPY_SBALS |
3407 QDIO_USE_OUTBOUND_PCIS;
3408 init_data.input_sbal_addr_array = (void **) in_sbal_ptrs;
3409 init_data.output_sbal_addr_array = (void **) out_sbal_ptrs;
3410
Frank Pavlicf956b692006-09-15 16:26:52 +02003411 if (atomic_cmpxchg(&card->qdio.state, QETH_QDIO_ALLOCATED,
3412 QETH_QDIO_ESTABLISHED) == QETH_QDIO_ALLOCATED)
3413 if ((rc = qdio_initialize(&init_data)))
3414 atomic_set(&card->qdio.state, QETH_QDIO_ALLOCATED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003415
3416 kfree(out_sbal_ptrs);
3417 kfree(in_sbal_ptrs);
3418 kfree(qib_param_field);
3419 return rc;
3420}
3421
3422static int
3423qeth_qdio_activate(struct qeth_card *card)
3424{
3425 QETH_DBF_TEXT(setup,3,"qdioact");
3426 return qdio_activate(CARD_DDEV(card), 0);
3427}
3428
3429static int
3430qeth_clear_channel(struct qeth_channel *channel)
3431{
3432 unsigned long flags;
3433 struct qeth_card *card;
3434 int rc;
3435
3436 QETH_DBF_TEXT(trace,3,"clearch");
3437 card = CARD_FROM_CDEV(channel->ccwdev);
3438 spin_lock_irqsave(get_ccwdev_lock(channel->ccwdev), flags);
3439 rc = ccw_device_clear(channel->ccwdev, QETH_CLEAR_CHANNEL_PARM);
3440 spin_unlock_irqrestore(get_ccwdev_lock(channel->ccwdev), flags);
3441
3442 if (rc)
3443 return rc;
3444 rc = wait_event_interruptible_timeout(card->wait_q,
3445 channel->state==CH_STATE_STOPPED, QETH_TIMEOUT);
3446 if (rc == -ERESTARTSYS)
3447 return rc;
3448 if (channel->state != CH_STATE_STOPPED)
3449 return -ETIME;
3450 channel->state = CH_STATE_DOWN;
3451 return 0;
3452}
3453
3454static int
3455qeth_halt_channel(struct qeth_channel *channel)
3456{
3457 unsigned long flags;
3458 struct qeth_card *card;
3459 int rc;
3460
3461 QETH_DBF_TEXT(trace,3,"haltch");
3462 card = CARD_FROM_CDEV(channel->ccwdev);
3463 spin_lock_irqsave(get_ccwdev_lock(channel->ccwdev), flags);
3464 rc = ccw_device_halt(channel->ccwdev, QETH_HALT_CHANNEL_PARM);
3465 spin_unlock_irqrestore(get_ccwdev_lock(channel->ccwdev), flags);
3466
3467 if (rc)
3468 return rc;
3469 rc = wait_event_interruptible_timeout(card->wait_q,
3470 channel->state==CH_STATE_HALTED, QETH_TIMEOUT);
3471 if (rc == -ERESTARTSYS)
3472 return rc;
3473 if (channel->state != CH_STATE_HALTED)
3474 return -ETIME;
3475 return 0;
3476}
3477
3478static int
3479qeth_halt_channels(struct qeth_card *card)
3480{
Frank Pavlicf3d242e2005-09-14 18:05:31 +02003481 int rc1 = 0, rc2=0, rc3 = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003482
3483 QETH_DBF_TEXT(trace,3,"haltchs");
Frank Pavlicf3d242e2005-09-14 18:05:31 +02003484 rc1 = qeth_halt_channel(&card->read);
3485 rc2 = qeth_halt_channel(&card->write);
3486 rc3 = qeth_halt_channel(&card->data);
3487 if (rc1)
3488 return rc1;
Jeff Garzike82b0f22006-05-26 21:58:38 -04003489 if (rc2)
Frank Pavlicf3d242e2005-09-14 18:05:31 +02003490 return rc2;
3491 return rc3;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003492}
3493static int
3494qeth_clear_channels(struct qeth_card *card)
3495{
Frank Pavlicf3d242e2005-09-14 18:05:31 +02003496 int rc1 = 0, rc2=0, rc3 = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003497
3498 QETH_DBF_TEXT(trace,3,"clearchs");
Frank Pavlicf3d242e2005-09-14 18:05:31 +02003499 rc1 = qeth_clear_channel(&card->read);
3500 rc2 = qeth_clear_channel(&card->write);
3501 rc3 = qeth_clear_channel(&card->data);
3502 if (rc1)
3503 return rc1;
Jeff Garzike82b0f22006-05-26 21:58:38 -04003504 if (rc2)
Frank Pavlicf3d242e2005-09-14 18:05:31 +02003505 return rc2;
3506 return rc3;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003507}
3508
3509static int
3510qeth_clear_halt_card(struct qeth_card *card, int halt)
3511{
3512 int rc = 0;
3513
3514 QETH_DBF_TEXT(trace,3,"clhacrd");
3515 QETH_DBF_HEX(trace, 3, &card, sizeof(void *));
3516
3517 if (halt)
3518 rc = qeth_halt_channels(card);
3519 if (rc)
3520 return rc;
3521 return qeth_clear_channels(card);
3522}
3523
3524static int
3525qeth_qdio_clear_card(struct qeth_card *card, int use_halt)
3526{
3527 int rc = 0;
3528
3529 QETH_DBF_TEXT(trace,3,"qdioclr");
Frank Pavlicf956b692006-09-15 16:26:52 +02003530 switch (atomic_cmpxchg(&card->qdio.state, QETH_QDIO_ESTABLISHED,
3531 QETH_QDIO_CLEANING)) {
3532 case QETH_QDIO_ESTABLISHED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003533 if ((rc = qdio_cleanup(CARD_DDEV(card),
Frank Pavlicf956b692006-09-15 16:26:52 +02003534 (card->info.type == QETH_CARD_TYPE_IQD) ?
3535 QDIO_FLAG_CLEANUP_USING_HALT :
3536 QDIO_FLAG_CLEANUP_USING_CLEAR)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003537 QETH_DBF_TEXT_(trace, 3, "1err%d", rc);
Frank Pavlicf956b692006-09-15 16:26:52 +02003538 atomic_set(&card->qdio.state, QETH_QDIO_ALLOCATED);
3539 break;
3540 case QETH_QDIO_CLEANING:
3541 return rc;
3542 default:
3543 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003544 }
3545 if ((rc = qeth_clear_halt_card(card, use_halt)))
3546 QETH_DBF_TEXT_(trace, 3, "2err%d", rc);
3547 card->state = CARD_STATE_DOWN;
3548 return rc;
3549}
3550
3551static int
3552qeth_dm_act(struct qeth_card *card)
3553{
3554 int rc;
3555 struct qeth_cmd_buffer *iob;
3556
3557 QETH_DBF_TEXT(setup,2,"dmact");
3558
3559 iob = qeth_wait_for_buffer(&card->write);
3560 memcpy(iob->data, DM_ACT, DM_ACT_SIZE);
3561
3562 memcpy(QETH_DM_ACT_DEST_ADDR(iob->data),
3563 &card->token.cm_connection_r, QETH_MPC_TOKEN_LENGTH);
3564 memcpy(QETH_DM_ACT_CONNECTION_TOKEN(iob->data),
3565 &card->token.ulp_connection_r, QETH_MPC_TOKEN_LENGTH);
3566 rc = qeth_send_control_data(card, DM_ACT_SIZE, iob, NULL, NULL);
3567 return rc;
3568}
3569
3570static int
3571qeth_mpc_initialize(struct qeth_card *card)
3572{
3573 int rc;
3574
3575 QETH_DBF_TEXT(setup,2,"mpcinit");
3576
3577 if ((rc = qeth_issue_next_read(card))){
3578 QETH_DBF_TEXT_(setup, 2, "1err%d", rc);
3579 return rc;
3580 }
3581 if ((rc = qeth_cm_enable(card))){
3582 QETH_DBF_TEXT_(setup, 2, "2err%d", rc);
Frank Pavlicf3d242e2005-09-14 18:05:31 +02003583 goto out_qdio;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003584 }
3585 if ((rc = qeth_cm_setup(card))){
3586 QETH_DBF_TEXT_(setup, 2, "3err%d", rc);
Frank Pavlicf3d242e2005-09-14 18:05:31 +02003587 goto out_qdio;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003588 }
3589 if ((rc = qeth_ulp_enable(card))){
3590 QETH_DBF_TEXT_(setup, 2, "4err%d", rc);
Frank Pavlicf3d242e2005-09-14 18:05:31 +02003591 goto out_qdio;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003592 }
3593 if ((rc = qeth_ulp_setup(card))){
3594 QETH_DBF_TEXT_(setup, 2, "5err%d", rc);
Frank Pavlicf3d242e2005-09-14 18:05:31 +02003595 goto out_qdio;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003596 }
3597 if ((rc = qeth_alloc_qdio_buffers(card))){
3598 QETH_DBF_TEXT_(setup, 2, "5err%d", rc);
Frank Pavlicf3d242e2005-09-14 18:05:31 +02003599 goto out_qdio;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003600 }
3601 if ((rc = qeth_qdio_establish(card))){
3602 QETH_DBF_TEXT_(setup, 2, "6err%d", rc);
3603 qeth_free_qdio_buffers(card);
3604 goto out_qdio;
3605 }
3606 if ((rc = qeth_qdio_activate(card))){
3607 QETH_DBF_TEXT_(setup, 2, "7err%d", rc);
3608 goto out_qdio;
3609 }
3610 if ((rc = qeth_dm_act(card))){
3611 QETH_DBF_TEXT_(setup, 2, "8err%d", rc);
3612 goto out_qdio;
3613 }
3614
3615 return 0;
3616out_qdio:
Ursula Braun500f83a2005-09-30 10:19:19 +02003617 qeth_qdio_clear_card(card, card->info.type!=QETH_CARD_TYPE_IQD);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003618 return rc;
3619}
3620
3621static struct net_device *
3622qeth_get_netdevice(enum qeth_card_types type, enum qeth_link_types linktype)
3623{
3624 struct net_device *dev = NULL;
3625
3626 switch (type) {
3627 case QETH_CARD_TYPE_OSAE:
3628 switch (linktype) {
3629 case QETH_LINK_TYPE_LANE_TR:
3630 case QETH_LINK_TYPE_HSTR:
3631#ifdef CONFIG_TR
3632 dev = alloc_trdev(0);
3633#endif /* CONFIG_TR */
3634 break;
3635 default:
3636 dev = alloc_etherdev(0);
3637 }
3638 break;
3639 case QETH_CARD_TYPE_IQD:
3640 dev = alloc_netdev(0, "hsi%d", ether_setup);
3641 break;
Ursula Braun500f83a2005-09-30 10:19:19 +02003642 case QETH_CARD_TYPE_OSN:
3643 dev = alloc_netdev(0, "osn%d", ether_setup);
3644 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003645 default:
3646 dev = alloc_etherdev(0);
3647 }
3648 return dev;
3649}
3650
3651/*hard_header fake function; used in case fake_ll is set */
3652static int
3653qeth_fake_header(struct sk_buff *skb, struct net_device *dev,
3654 unsigned short type, void *daddr, void *saddr,
3655 unsigned len)
3656{
Frank Pavlice23dd9c2005-05-12 20:38:11 +02003657 if(dev->type == ARPHRD_IEEE802_TR){
3658 struct trh_hdr *hdr;
3659 hdr = (struct trh_hdr *)skb_push(skb, QETH_FAKE_LL_LEN_TR);
3660 memcpy(hdr->saddr, dev->dev_addr, TR_ALEN);
3661 memcpy(hdr->daddr, "FAKELL", TR_ALEN);
3662 return QETH_FAKE_LL_LEN_TR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003663
Frank Pavlice23dd9c2005-05-12 20:38:11 +02003664 } else {
3665 struct ethhdr *hdr;
3666 hdr = (struct ethhdr *)skb_push(skb, QETH_FAKE_LL_LEN_ETH);
3667 memcpy(hdr->h_source, dev->dev_addr, ETH_ALEN);
3668 memcpy(hdr->h_dest, "FAKELL", ETH_ALEN);
3669 if (type != ETH_P_802_3)
3670 hdr->h_proto = htons(type);
3671 else
3672 hdr->h_proto = htons(len);
3673 return QETH_FAKE_LL_LEN_ETH;
3674
3675 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003676}
3677
Heiko Carstens4d284ca2007-02-05 21:18:53 +01003678static int
Linus Torvalds1da177e2005-04-16 15:20:36 -07003679qeth_send_packet(struct qeth_card *, struct sk_buff *);
3680
3681static int
3682qeth_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
3683{
3684 int rc;
3685 struct qeth_card *card;
3686
3687 QETH_DBF_TEXT(trace, 6, "hrdstxmi");
3688 card = (struct qeth_card *)dev->priv;
3689 if (skb==NULL) {
3690 card->stats.tx_dropped++;
3691 card->stats.tx_errors++;
3692 /* return OK; otherwise ksoftirqd goes to 100% */
3693 return NETDEV_TX_OK;
3694 }
3695 if ((card->state != CARD_STATE_UP) || !card->lan_online) {
3696 card->stats.tx_dropped++;
3697 card->stats.tx_errors++;
3698 card->stats.tx_carrier_errors++;
3699 dev_kfree_skb_any(skb);
3700 /* return OK; otherwise ksoftirqd goes to 100% */
3701 return NETDEV_TX_OK;
3702 }
Frank Pavlic09d2d382006-09-15 16:26:34 +02003703 if (card->options.performance_stats) {
3704 card->perf_stats.outbound_cnt++;
3705 card->perf_stats.outbound_start_time = qeth_get_micros();
3706 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003707 netif_stop_queue(dev);
3708 if ((rc = qeth_send_packet(card, skb))) {
3709 if (rc == -EBUSY) {
3710 return NETDEV_TX_BUSY;
3711 } else {
3712 card->stats.tx_errors++;
3713 card->stats.tx_dropped++;
3714 dev_kfree_skb_any(skb);
3715 /*set to OK; otherwise ksoftirqd goes to 100% */
3716 rc = NETDEV_TX_OK;
3717 }
3718 }
3719 netif_wake_queue(dev);
Frank Pavlic09d2d382006-09-15 16:26:34 +02003720 if (card->options.performance_stats)
3721 card->perf_stats.outbound_time += qeth_get_micros() -
3722 card->perf_stats.outbound_start_time;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003723 return rc;
3724}
3725
3726static int
3727qeth_verify_vlan_dev(struct net_device *dev, struct qeth_card *card)
3728{
3729 int rc = 0;
3730#ifdef CONFIG_QETH_VLAN
3731 struct vlan_group *vg;
3732 int i;
3733
3734 if (!(vg = card->vlangrp))
3735 return rc;
3736
3737 for (i = 0; i < VLAN_GROUP_ARRAY_LEN; i++){
Dan Aloni5c15bde2007-03-02 20:44:51 -08003738 if (vlan_group_get_device(vg, i) == dev){
Linus Torvalds1da177e2005-04-16 15:20:36 -07003739 rc = QETH_VLAN_CARD;
3740 break;
3741 }
3742 }
Frank Pavlic6c6b3e72005-12-13 08:21:47 +01003743 if (rc && !(VLAN_DEV_INFO(dev)->real_dev->priv == (void *)card))
3744 return 0;
3745
Linus Torvalds1da177e2005-04-16 15:20:36 -07003746#endif
3747 return rc;
3748}
3749
3750static int
3751qeth_verify_dev(struct net_device *dev)
3752{
3753 struct qeth_card *card;
3754 unsigned long flags;
3755 int rc = 0;
3756
3757 read_lock_irqsave(&qeth_card_list.rwlock, flags);
3758 list_for_each_entry(card, &qeth_card_list.list, list){
3759 if (card->dev == dev){
3760 rc = QETH_REAL_CARD;
3761 break;
3762 }
3763 rc = qeth_verify_vlan_dev(dev, card);
3764 if (rc)
3765 break;
3766 }
3767 read_unlock_irqrestore(&qeth_card_list.rwlock, flags);
3768
3769 return rc;
3770}
3771
3772static struct qeth_card *
3773qeth_get_card_from_dev(struct net_device *dev)
3774{
3775 struct qeth_card *card = NULL;
3776 int rc;
3777
3778 rc = qeth_verify_dev(dev);
3779 if (rc == QETH_REAL_CARD)
3780 card = (struct qeth_card *)dev->priv;
3781 else if (rc == QETH_VLAN_CARD)
3782 card = (struct qeth_card *)
3783 VLAN_DEV_INFO(dev)->real_dev->priv;
3784
3785 QETH_DBF_TEXT_(trace, 4, "%d", rc);
3786 return card ;
3787}
3788
3789static void
3790qeth_tx_timeout(struct net_device *dev)
3791{
3792 struct qeth_card *card;
3793
3794 card = (struct qeth_card *) dev->priv;
3795 card->stats.tx_errors++;
3796 qeth_schedule_recovery(card);
3797}
3798
3799static int
3800qeth_open(struct net_device *dev)
3801{
3802 struct qeth_card *card;
3803
3804 QETH_DBF_TEXT(trace, 4, "qethopen");
3805
3806 card = (struct qeth_card *) dev->priv;
3807
3808 if (card->state != CARD_STATE_SOFTSETUP)
3809 return -ENODEV;
3810
Ursula Braun500f83a2005-09-30 10:19:19 +02003811 if ( (card->info.type != QETH_CARD_TYPE_OSN) &&
3812 (card->options.layer2) &&
Frank Pavlice08d88c2005-11-10 13:51:17 +01003813 (!(card->info.mac_bits & QETH_LAYER2_MAC_REGISTERED))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003814 QETH_DBF_TEXT(trace,4,"nomacadr");
3815 return -EPERM;
3816 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003817 card->data.state = CH_STATE_UP;
3818 card->state = CARD_STATE_UP;
Ursula Braunba1aa082006-05-24 09:51:13 +02003819 card->dev->flags |= IFF_UP;
3820 netif_start_queue(dev);
Jeff Garzike82b0f22006-05-26 21:58:38 -04003821
Frank Pavlic4965e972005-12-13 08:22:30 +01003822 if (!card->lan_online && netif_carrier_ok(dev))
3823 netif_carrier_off(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003824 return 0;
3825}
3826
3827static int
3828qeth_stop(struct net_device *dev)
3829{
3830 struct qeth_card *card;
3831
3832 QETH_DBF_TEXT(trace, 4, "qethstop");
3833
3834 card = (struct qeth_card *) dev->priv;
3835
Ursula Braunb85e1fa2006-05-24 09:51:11 +02003836 netif_tx_disable(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003837 card->dev->flags &= ~IFF_UP;
3838 if (card->state == CARD_STATE_UP)
3839 card->state = CARD_STATE_SOFTSETUP;
3840 return 0;
3841}
3842
Heiko Carstens4d284ca2007-02-05 21:18:53 +01003843static int
Linus Torvalds1da177e2005-04-16 15:20:36 -07003844qeth_get_cast_type(struct qeth_card *card, struct sk_buff *skb)
3845{
3846 int cast_type = RTN_UNSPEC;
3847
Ursula Braun500f83a2005-09-30 10:19:19 +02003848 if (card->info.type == QETH_CARD_TYPE_OSN)
3849 return cast_type;
3850
Linus Torvalds1da177e2005-04-16 15:20:36 -07003851 if (skb->dst && skb->dst->neighbour){
3852 cast_type = skb->dst->neighbour->type;
3853 if ((cast_type == RTN_BROADCAST) ||
3854 (cast_type == RTN_MULTICAST) ||
3855 (cast_type == RTN_ANYCAST))
3856 return cast_type;
3857 else
3858 return RTN_UNSPEC;
3859 }
3860 /* try something else */
3861 if (skb->protocol == ETH_P_IPV6)
Arnaldo Carvalho de Melod56f90a2007-04-10 20:50:43 -07003862 return (skb_network_header(skb)[24] == 0xff) ?
3863 RTN_MULTICAST : 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003864 else if (skb->protocol == ETH_P_IP)
Arnaldo Carvalho de Melod56f90a2007-04-10 20:50:43 -07003865 return ((skb_network_header(skb)[16] & 0xf0) == 0xe0) ?
3866 RTN_MULTICAST : 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003867 /* ... */
3868 if (!memcmp(skb->data, skb->dev->broadcast, 6))
3869 return RTN_BROADCAST;
3870 else {
3871 u16 hdr_mac;
3872
3873 hdr_mac = *((u16 *)skb->data);
3874 /* tr multicast? */
3875 switch (card->info.link_type) {
3876 case QETH_LINK_TYPE_HSTR:
3877 case QETH_LINK_TYPE_LANE_TR:
3878 if ((hdr_mac == QETH_TR_MAC_NC) ||
3879 (hdr_mac == QETH_TR_MAC_C))
3880 return RTN_MULTICAST;
Frank Pavlic1380fee2006-03-22 16:03:41 +01003881 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003882 /* eth or so multicast? */
3883 default:
3884 if ((hdr_mac == QETH_ETH_MAC_V4) ||
3885 (hdr_mac == QETH_ETH_MAC_V6))
3886 return RTN_MULTICAST;
3887 }
3888 }
3889 return cast_type;
3890}
3891
Heiko Carstens4d284ca2007-02-05 21:18:53 +01003892static int
Linus Torvalds1da177e2005-04-16 15:20:36 -07003893qeth_get_priority_queue(struct qeth_card *card, struct sk_buff *skb,
3894 int ipv, int cast_type)
3895{
3896 if (!ipv && (card->info.type == QETH_CARD_TYPE_OSAE))
3897 return card->qdio.default_out_queue;
3898 switch (card->qdio.no_out_queues) {
3899 case 4:
3900 if (cast_type && card->info.is_multicast_different)
3901 return card->info.is_multicast_different &
3902 (card->qdio.no_out_queues - 1);
3903 if (card->qdio.do_prio_queueing && (ipv == 4)) {
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07003904 const u8 tos = ip_hdr(skb)->tos;
3905
Linus Torvalds1da177e2005-04-16 15:20:36 -07003906 if (card->qdio.do_prio_queueing==QETH_PRIO_Q_ING_TOS){
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07003907 if (tos & IP_TOS_NOTIMPORTANT)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003908 return 3;
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07003909 if (tos & IP_TOS_HIGHRELIABILITY)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003910 return 2;
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07003911 if (tos & IP_TOS_HIGHTHROUGHPUT)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003912 return 1;
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07003913 if (tos & IP_TOS_LOWDELAY)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003914 return 0;
3915 }
3916 if (card->qdio.do_prio_queueing==QETH_PRIO_Q_ING_PREC)
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07003917 return 3 - (tos >> 6);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003918 } else if (card->qdio.do_prio_queueing && (ipv == 6)) {
3919 /* TODO: IPv6!!! */
3920 }
3921 return card->qdio.default_out_queue;
3922 case 1: /* fallthrough for single-out-queue 1920-device */
3923 default:
3924 return card->qdio.default_out_queue;
3925 }
3926}
3927
3928static inline int
3929qeth_get_ip_version(struct sk_buff *skb)
3930{
3931 switch (skb->protocol) {
3932 case ETH_P_IPV6:
3933 return 6;
3934 case ETH_P_IP:
3935 return 4;
3936 default:
3937 return 0;
3938 }
3939}
3940
Heiko Carstens4d284ca2007-02-05 21:18:53 +01003941static struct qeth_hdr *
Frank Pavlicf7b65d72006-09-15 16:26:19 +02003942__qeth_prepare_skb(struct qeth_card *card, struct sk_buff *skb, int ipv)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003943{
Linus Torvalds1da177e2005-04-16 15:20:36 -07003944#ifdef CONFIG_QETH_VLAN
3945 u16 *tag;
Frank Pavlicf7b65d72006-09-15 16:26:19 +02003946 if (card->vlangrp && vlan_tx_tag_present(skb) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07003947 ((ipv == 6) || card->options.layer2) ) {
3948 /*
3949 * Move the mac addresses (6 bytes src, 6 bytes dest)
3950 * to the beginning of the new header. We are using three
3951 * memcpys instead of one memmove to save cycles.
3952 */
Frank Pavlicf7b65d72006-09-15 16:26:19 +02003953 skb_push(skb, VLAN_HLEN);
Arnaldo Carvalho de Melo27d7ff42007-03-31 11:55:19 -03003954 skb_copy_to_linear_data(skb, skb->data + 4, 4);
3955 skb_copy_to_linear_data_offset(skb, 4, skb->data + 8, 4);
3956 skb_copy_to_linear_data_offset(skb, 8, skb->data + 12, 4);
Frank Pavlicf7b65d72006-09-15 16:26:19 +02003957 tag = (u16 *)(skb->data + 12);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003958 /*
3959 * first two bytes = ETH_P_8021Q (0x8100)
3960 * second two bytes = VLANID
3961 */
3962 *tag = __constant_htons(ETH_P_8021Q);
Frank Pavlicf7b65d72006-09-15 16:26:19 +02003963 *(tag + 1) = htons(vlan_tx_tag_get(skb));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003964 }
3965#endif
Frank Pavlicf7b65d72006-09-15 16:26:19 +02003966 return ((struct qeth_hdr *)
3967 qeth_push_skb(card, skb, sizeof(struct qeth_hdr)));
3968}
3969
Heiko Carstens4d284ca2007-02-05 21:18:53 +01003970static void
Frank Pavlicf7b65d72006-09-15 16:26:19 +02003971__qeth_free_new_skb(struct sk_buff *orig_skb, struct sk_buff *new_skb)
3972{
3973 if (orig_skb != new_skb)
3974 dev_kfree_skb_any(new_skb);
3975}
3976
Heiko Carstens4d284ca2007-02-05 21:18:53 +01003977static struct sk_buff *
Frank Pavlicf7b65d72006-09-15 16:26:19 +02003978qeth_prepare_skb(struct qeth_card *card, struct sk_buff *skb,
3979 struct qeth_hdr **hdr, int ipv)
3980{
Frank Blaschka2d36c162007-01-08 17:29:58 +01003981 struct sk_buff *new_skb, *new_skb2;
Frank Pavlicf7b65d72006-09-15 16:26:19 +02003982
3983 QETH_DBF_TEXT(trace, 6, "prepskb");
Frank Blaschka2d36c162007-01-08 17:29:58 +01003984 new_skb = skb;
3985 new_skb = qeth_pskb_unshare(skb, GFP_ATOMIC);
3986 if (!new_skb)
Frank Pavlicf7b65d72006-09-15 16:26:19 +02003987 return NULL;
Frank Blaschka2d36c162007-01-08 17:29:58 +01003988 new_skb2 = qeth_realloc_headroom(card, new_skb,
3989 sizeof(struct qeth_hdr));
3990 if (!new_skb2) {
3991 __qeth_free_new_skb(skb, new_skb);
3992 return NULL;
3993 }
3994 if (new_skb != skb)
3995 __qeth_free_new_skb(new_skb2, new_skb);
3996 new_skb = new_skb2;
Frank Pavlicf7b65d72006-09-15 16:26:19 +02003997 *hdr = __qeth_prepare_skb(card, new_skb, ipv);
3998 if (*hdr == NULL) {
3999 __qeth_free_new_skb(skb, new_skb);
4000 return NULL;
4001 }
4002 return new_skb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004003}
4004
4005static inline u8
4006qeth_get_qeth_hdr_flags4(int cast_type)
4007{
4008 if (cast_type == RTN_MULTICAST)
4009 return QETH_CAST_MULTICAST;
4010 if (cast_type == RTN_BROADCAST)
4011 return QETH_CAST_BROADCAST;
4012 return QETH_CAST_UNICAST;
4013}
4014
4015static inline u8
4016qeth_get_qeth_hdr_flags6(int cast_type)
4017{
4018 u8 ct = QETH_HDR_PASSTHRU | QETH_HDR_IPV6;
4019 if (cast_type == RTN_MULTICAST)
4020 return ct | QETH_CAST_MULTICAST;
4021 if (cast_type == RTN_ANYCAST)
4022 return ct | QETH_CAST_ANYCAST;
4023 if (cast_type == RTN_BROADCAST)
4024 return ct | QETH_CAST_BROADCAST;
4025 return ct | QETH_CAST_UNICAST;
4026}
4027
Heiko Carstens4d284ca2007-02-05 21:18:53 +01004028static void
Linus Torvalds1da177e2005-04-16 15:20:36 -07004029qeth_layer2_get_packet_type(struct qeth_card *card, struct qeth_hdr *hdr,
4030 struct sk_buff *skb)
4031{
4032 __u16 hdr_mac;
4033
4034 if (!memcmp(skb->data+QETH_HEADER_SIZE,
4035 skb->dev->broadcast,6)) { /* broadcast? */
4036 *(__u32 *)hdr->hdr.l2.flags |=
4037 QETH_LAYER2_FLAG_BROADCAST << 8;
4038 return;
4039 }
4040 hdr_mac=*((__u16*)skb->data);
4041 /* tr multicast? */
4042 switch (card->info.link_type) {
4043 case QETH_LINK_TYPE_HSTR:
4044 case QETH_LINK_TYPE_LANE_TR:
4045 if ((hdr_mac == QETH_TR_MAC_NC) ||
4046 (hdr_mac == QETH_TR_MAC_C) )
4047 *(__u32 *)hdr->hdr.l2.flags |=
4048 QETH_LAYER2_FLAG_MULTICAST << 8;
4049 else
4050 *(__u32 *)hdr->hdr.l2.flags |=
4051 QETH_LAYER2_FLAG_UNICAST << 8;
4052 break;
4053 /* eth or so multicast? */
4054 default:
4055 if ( (hdr_mac==QETH_ETH_MAC_V4) ||
4056 (hdr_mac==QETH_ETH_MAC_V6) )
4057 *(__u32 *)hdr->hdr.l2.flags |=
4058 QETH_LAYER2_FLAG_MULTICAST << 8;
4059 else
4060 *(__u32 *)hdr->hdr.l2.flags |=
4061 QETH_LAYER2_FLAG_UNICAST << 8;
4062 }
4063}
4064
Heiko Carstens4d284ca2007-02-05 21:18:53 +01004065static void
Linus Torvalds1da177e2005-04-16 15:20:36 -07004066qeth_layer2_fill_header(struct qeth_card *card, struct qeth_hdr *hdr,
4067 struct sk_buff *skb, int cast_type)
4068{
4069 memset(hdr, 0, sizeof(struct qeth_hdr));
4070 hdr->hdr.l2.id = QETH_HEADER_TYPE_LAYER2;
4071
4072 /* set byte 0 to "0x02" and byte 3 to casting flags */
4073 if (cast_type==RTN_MULTICAST)
4074 *(__u32 *)hdr->hdr.l2.flags |= QETH_LAYER2_FLAG_MULTICAST << 8;
4075 else if (cast_type==RTN_BROADCAST)
4076 *(__u32 *)hdr->hdr.l2.flags |= QETH_LAYER2_FLAG_BROADCAST << 8;
4077 else
4078 qeth_layer2_get_packet_type(card, hdr, skb);
4079
4080 hdr->hdr.l2.pkt_length = skb->len-QETH_HEADER_SIZE;
4081#ifdef CONFIG_QETH_VLAN
4082 /* VSWITCH relies on the VLAN
4083 * information to be present in
4084 * the QDIO header */
4085 if ((card->vlangrp != NULL) &&
4086 vlan_tx_tag_present(skb)) {
4087 *(__u32 *)hdr->hdr.l2.flags |= QETH_LAYER2_FLAG_VLAN << 8;
4088 hdr->hdr.l2.vlan_id = vlan_tx_tag_get(skb);
4089 }
4090#endif
4091}
4092
4093void
4094qeth_fill_header(struct qeth_card *card, struct qeth_hdr *hdr,
4095 struct sk_buff *skb, int ipv, int cast_type)
4096{
4097 QETH_DBF_TEXT(trace, 6, "fillhdr");
4098
4099 memset(hdr, 0, sizeof(struct qeth_hdr));
4100 if (card->options.layer2) {
4101 qeth_layer2_fill_header(card, hdr, skb, cast_type);
4102 return;
4103 }
4104 hdr->hdr.l3.id = QETH_HEADER_TYPE_LAYER3;
4105 hdr->hdr.l3.ext_flags = 0;
4106#ifdef CONFIG_QETH_VLAN
4107 /*
4108 * before we're going to overwrite this location with next hop ip.
4109 * v6 uses passthrough, v4 sets the tag in the QDIO header.
4110 */
4111 if (card->vlangrp && vlan_tx_tag_present(skb)) {
4112 hdr->hdr.l3.ext_flags = (ipv == 4) ?
4113 QETH_HDR_EXT_VLAN_FRAME :
4114 QETH_HDR_EXT_INCLUDE_VLAN_TAG;
4115 hdr->hdr.l3.vlan_id = vlan_tx_tag_get(skb);
4116 }
4117#endif /* CONFIG_QETH_VLAN */
4118 hdr->hdr.l3.length = skb->len - sizeof(struct qeth_hdr);
4119 if (ipv == 4) { /* IPv4 */
4120 hdr->hdr.l3.flags = qeth_get_qeth_hdr_flags4(cast_type);
4121 memset(hdr->hdr.l3.dest_addr, 0, 12);
4122 if ((skb->dst) && (skb->dst->neighbour)) {
4123 *((u32 *) (&hdr->hdr.l3.dest_addr[12])) =
4124 *((u32 *) skb->dst->neighbour->primary_key);
4125 } else {
4126 /* fill in destination address used in ip header */
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07004127 *((u32 *)(&hdr->hdr.l3.dest_addr[12])) =
4128 ip_hdr(skb)->daddr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004129 }
4130 } else if (ipv == 6) { /* IPv6 or passthru */
4131 hdr->hdr.l3.flags = qeth_get_qeth_hdr_flags6(cast_type);
4132 if ((skb->dst) && (skb->dst->neighbour)) {
4133 memcpy(hdr->hdr.l3.dest_addr,
4134 skb->dst->neighbour->primary_key, 16);
4135 } else {
4136 /* fill in destination address used in ip header */
Arnaldo Carvalho de Melo0660e032007-04-25 17:54:47 -07004137 memcpy(hdr->hdr.l3.dest_addr,
4138 &ipv6_hdr(skb)->daddr, 16);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004139 }
4140 } else { /* passthrough */
Frank Pavlice23dd9c2005-05-12 20:38:11 +02004141 if((skb->dev->type == ARPHRD_IEEE802_TR) &&
Jeff Garzike82b0f22006-05-26 21:58:38 -04004142 !memcmp(skb->data + sizeof(struct qeth_hdr) +
Frank Pavlic9a455812005-05-12 20:38:28 +02004143 sizeof(__u16), skb->dev->broadcast, 6)) {
4144 hdr->hdr.l3.flags = QETH_CAST_BROADCAST |
4145 QETH_HDR_PASSTHRU;
Frank Pavlice23dd9c2005-05-12 20:38:11 +02004146 } else if (!memcmp(skb->data + sizeof(struct qeth_hdr),
Linus Torvalds1da177e2005-04-16 15:20:36 -07004147 skb->dev->broadcast, 6)) { /* broadcast? */
Frank Pavlice23dd9c2005-05-12 20:38:11 +02004148 hdr->hdr.l3.flags = QETH_CAST_BROADCAST |
4149 QETH_HDR_PASSTHRU;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004150 } else {
4151 hdr->hdr.l3.flags = (cast_type == RTN_MULTICAST) ?
4152 QETH_CAST_MULTICAST | QETH_HDR_PASSTHRU :
4153 QETH_CAST_UNICAST | QETH_HDR_PASSTHRU;
4154 }
4155 }
4156}
4157
Heiko Carstens4d284ca2007-02-05 21:18:53 +01004158static void
Linus Torvalds1da177e2005-04-16 15:20:36 -07004159__qeth_fill_buffer(struct sk_buff *skb, struct qdio_buffer *buffer,
Frank Pavlic05e08a22005-05-12 20:39:09 +02004160 int is_tso, int *next_element_to_fill)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004161{
4162 int length = skb->len;
4163 int length_here;
4164 int element;
4165 char *data;
Frank Pavlic05e08a22005-05-12 20:39:09 +02004166 int first_lap ;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004167
4168 element = *next_element_to_fill;
4169 data = skb->data;
Frank Pavlic05e08a22005-05-12 20:39:09 +02004170 first_lap = (is_tso == 0 ? 1 : 0);
4171
Linus Torvalds1da177e2005-04-16 15:20:36 -07004172 while (length > 0) {
4173 /* length_here is the remaining amount of data in this page */
4174 length_here = PAGE_SIZE - ((unsigned long) data % PAGE_SIZE);
4175 if (length < length_here)
4176 length_here = length;
Frank Pavlic05e08a22005-05-12 20:39:09 +02004177
Linus Torvalds1da177e2005-04-16 15:20:36 -07004178 buffer->element[element].addr = data;
4179 buffer->element[element].length = length_here;
4180 length -= length_here;
Frank Pavlic05e08a22005-05-12 20:39:09 +02004181 if (!length) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004182 if (first_lap)
4183 buffer->element[element].flags = 0;
4184 else
4185 buffer->element[element].flags =
4186 SBAL_FLAGS_LAST_FRAG;
4187 } else {
4188 if (first_lap)
4189 buffer->element[element].flags =
4190 SBAL_FLAGS_FIRST_FRAG;
4191 else
4192 buffer->element[element].flags =
4193 SBAL_FLAGS_MIDDLE_FRAG;
4194 }
4195 data += length_here;
4196 element++;
4197 first_lap = 0;
4198 }
4199 *next_element_to_fill = element;
4200}
4201
Heiko Carstens4d284ca2007-02-05 21:18:53 +01004202static int
Linus Torvalds1da177e2005-04-16 15:20:36 -07004203qeth_fill_buffer(struct qeth_qdio_out_q *queue,
4204 struct qeth_qdio_out_buffer *buf,
4205 struct sk_buff *skb)
4206{
4207 struct qdio_buffer *buffer;
Frank Pavlic05e08a22005-05-12 20:39:09 +02004208 struct qeth_hdr_tso *hdr;
4209 int flush_cnt = 0, hdr_len, large_send = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004210
4211 QETH_DBF_TEXT(trace, 6, "qdfillbf");
Frank Pavlic05e08a22005-05-12 20:39:09 +02004212
Linus Torvalds1da177e2005-04-16 15:20:36 -07004213 buffer = buf->buffer;
4214 atomic_inc(&skb->users);
4215 skb_queue_tail(&buf->skb_list, skb);
Frank Pavlic05e08a22005-05-12 20:39:09 +02004216
4217 hdr = (struct qeth_hdr_tso *) skb->data;
4218 /*check first on TSO ....*/
4219 if (hdr->hdr.hdr.l3.id == QETH_HEADER_TYPE_TSO) {
4220 int element = buf->next_element_to_fill;
4221
4222 hdr_len = sizeof(struct qeth_hdr_tso) + hdr->ext.dg_hdr_len;
4223 /*fill first buffer entry only with header information */
4224 buffer->element[element].addr = skb->data;
4225 buffer->element[element].length = hdr_len;
4226 buffer->element[element].flags = SBAL_FLAGS_FIRST_FRAG;
4227 buf->next_element_to_fill++;
4228 skb->data += hdr_len;
4229 skb->len -= hdr_len;
4230 large_send = 1;
4231 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004232 if (skb_shinfo(skb)->nr_frags == 0)
Frank Pavlic05e08a22005-05-12 20:39:09 +02004233 __qeth_fill_buffer(skb, buffer, large_send,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004234 (int *)&buf->next_element_to_fill);
4235 else
Frank Pavlic05e08a22005-05-12 20:39:09 +02004236 __qeth_fill_buffer_frag(skb, buffer, large_send,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004237 (int *)&buf->next_element_to_fill);
4238
4239 if (!queue->do_pack) {
4240 QETH_DBF_TEXT(trace, 6, "fillbfnp");
4241 /* set state to PRIMED -> will be flushed */
4242 atomic_set(&buf->state, QETH_QDIO_BUF_PRIMED);
4243 flush_cnt = 1;
4244 } else {
4245 QETH_DBF_TEXT(trace, 6, "fillbfpa");
Frank Pavlic09d2d382006-09-15 16:26:34 +02004246 if (queue->card->options.performance_stats)
4247 queue->card->perf_stats.skbs_sent_pack++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004248 if (buf->next_element_to_fill >=
4249 QETH_MAX_BUFFER_ELEMENTS(queue->card)) {
4250 /*
4251 * packed buffer if full -> set state PRIMED
4252 * -> will be flushed
4253 */
4254 atomic_set(&buf->state, QETH_QDIO_BUF_PRIMED);
4255 flush_cnt = 1;
4256 }
4257 }
4258 return flush_cnt;
4259}
4260
Heiko Carstens4d284ca2007-02-05 21:18:53 +01004261static int
Linus Torvalds1da177e2005-04-16 15:20:36 -07004262qeth_do_send_packet_fast(struct qeth_card *card, struct qeth_qdio_out_q *queue,
4263 struct sk_buff *skb, struct qeth_hdr *hdr,
4264 int elements_needed,
4265 struct qeth_eddp_context *ctx)
4266{
4267 struct qeth_qdio_out_buffer *buffer;
4268 int buffers_needed = 0;
4269 int flush_cnt = 0;
4270 int index;
4271
4272 QETH_DBF_TEXT(trace, 6, "dosndpfa");
4273
4274 /* spin until we get the queue ... */
Martin Schwidefsky973bd992006-01-06 00:19:07 -08004275 while (atomic_cmpxchg(&queue->state, QETH_OUT_Q_UNLOCKED,
4276 QETH_OUT_Q_LOCKED) != QETH_OUT_Q_UNLOCKED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004277 /* ... now we've got the queue */
4278 index = queue->next_buf_to_fill;
4279 buffer = &queue->bufs[queue->next_buf_to_fill];
4280 /*
4281 * check if buffer is empty to make sure that we do not 'overtake'
4282 * ourselves and try to fill a buffer that is already primed
4283 */
Frank Pavlicf7b65d72006-09-15 16:26:19 +02004284 if (atomic_read(&buffer->state) != QETH_QDIO_BUF_EMPTY)
4285 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004286 if (ctx == NULL)
4287 queue->next_buf_to_fill = (queue->next_buf_to_fill + 1) %
4288 QDIO_MAX_BUFFERS_PER_Q;
4289 else {
4290 buffers_needed = qeth_eddp_check_buffers_for_context(queue,ctx);
Frank Pavlicf7b65d72006-09-15 16:26:19 +02004291 if (buffers_needed < 0)
4292 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004293 queue->next_buf_to_fill =
4294 (queue->next_buf_to_fill + buffers_needed) %
4295 QDIO_MAX_BUFFERS_PER_Q;
4296 }
4297 atomic_set(&queue->state, QETH_OUT_Q_UNLOCKED);
4298 if (ctx == NULL) {
4299 qeth_fill_buffer(queue, buffer, skb);
4300 qeth_flush_buffers(queue, 0, index, 1);
4301 } else {
4302 flush_cnt = qeth_eddp_fill_buffer(queue, ctx, index);
4303 WARN_ON(buffers_needed != flush_cnt);
4304 qeth_flush_buffers(queue, 0, index, flush_cnt);
4305 }
4306 return 0;
Frank Pavlicf7b65d72006-09-15 16:26:19 +02004307out:
4308 atomic_set(&queue->state, QETH_OUT_Q_UNLOCKED);
4309 return -EBUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004310}
4311
Heiko Carstens4d284ca2007-02-05 21:18:53 +01004312static int
Linus Torvalds1da177e2005-04-16 15:20:36 -07004313qeth_do_send_packet(struct qeth_card *card, struct qeth_qdio_out_q *queue,
4314 struct sk_buff *skb, struct qeth_hdr *hdr,
4315 int elements_needed, struct qeth_eddp_context *ctx)
4316{
4317 struct qeth_qdio_out_buffer *buffer;
4318 int start_index;
4319 int flush_count = 0;
4320 int do_pack = 0;
4321 int tmp;
4322 int rc = 0;
4323
4324 QETH_DBF_TEXT(trace, 6, "dosndpkt");
4325
4326 /* spin until we get the queue ... */
Martin Schwidefsky973bd992006-01-06 00:19:07 -08004327 while (atomic_cmpxchg(&queue->state, QETH_OUT_Q_UNLOCKED,
4328 QETH_OUT_Q_LOCKED) != QETH_OUT_Q_UNLOCKED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004329 start_index = queue->next_buf_to_fill;
4330 buffer = &queue->bufs[queue->next_buf_to_fill];
4331 /*
4332 * check if buffer is empty to make sure that we do not 'overtake'
4333 * ourselves and try to fill a buffer that is already primed
4334 */
Frank Pavlicf7b65d72006-09-15 16:26:19 +02004335 if (atomic_read(&buffer->state) != QETH_QDIO_BUF_EMPTY) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004336 atomic_set(&queue->state, QETH_OUT_Q_UNLOCKED);
4337 return -EBUSY;
4338 }
4339 /* check if we need to switch packing state of this queue */
4340 qeth_switch_to_packing_if_needed(queue);
4341 if (queue->do_pack){
4342 do_pack = 1;
4343 if (ctx == NULL) {
4344 /* does packet fit in current buffer? */
4345 if((QETH_MAX_BUFFER_ELEMENTS(card) -
4346 buffer->next_element_to_fill) < elements_needed){
4347 /* ... no -> set state PRIMED */
4348 atomic_set(&buffer->state,QETH_QDIO_BUF_PRIMED);
4349 flush_count++;
4350 queue->next_buf_to_fill =
4351 (queue->next_buf_to_fill + 1) %
4352 QDIO_MAX_BUFFERS_PER_Q;
4353 buffer = &queue->bufs[queue->next_buf_to_fill];
4354 /* we did a step forward, so check buffer state
4355 * again */
4356 if (atomic_read(&buffer->state) !=
4357 QETH_QDIO_BUF_EMPTY){
Linus Torvalds1da177e2005-04-16 15:20:36 -07004358 qeth_flush_buffers(queue, 0, start_index, flush_count);
4359 atomic_set(&queue->state, QETH_OUT_Q_UNLOCKED);
4360 return -EBUSY;
4361 }
4362 }
4363 } else {
4364 /* check if we have enough elements (including following
4365 * free buffers) to handle eddp context */
4366 if (qeth_eddp_check_buffers_for_context(queue,ctx) < 0){
4367 printk("eddp tx_dropped 1\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004368 rc = -EBUSY;
4369 goto out;
4370 }
4371 }
4372 }
4373 if (ctx == NULL)
4374 tmp = qeth_fill_buffer(queue, buffer, skb);
4375 else {
4376 tmp = qeth_eddp_fill_buffer(queue,ctx,queue->next_buf_to_fill);
4377 if (tmp < 0) {
4378 printk("eddp tx_dropped 2\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004379 rc = - EBUSY;
4380 goto out;
4381 }
4382 }
4383 queue->next_buf_to_fill = (queue->next_buf_to_fill + tmp) %
4384 QDIO_MAX_BUFFERS_PER_Q;
4385 flush_count += tmp;
4386out:
4387 if (flush_count)
4388 qeth_flush_buffers(queue, 0, start_index, flush_count);
Frank Pavlicd805d7c2005-11-10 13:50:58 +01004389 else if (!atomic_read(&queue->set_pci_flags_count))
Ursula Braun9163bb22006-12-04 15:40:59 +01004390 atomic_xchg(&queue->state, QETH_OUT_Q_LOCKED_FLUSH);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004391 /*
4392 * queue->state will go from LOCKED -> UNLOCKED or from
4393 * LOCKED_FLUSH -> LOCKED if output_handler wanted to 'notify' us
4394 * (switch packing state or flush buffer to get another pci flag out).
4395 * In that case we will enter this loop
4396 */
4397 while (atomic_dec_return(&queue->state)){
4398 flush_count = 0;
4399 start_index = queue->next_buf_to_fill;
4400 /* check if we can go back to non-packing state */
4401 flush_count += qeth_switch_to_nonpacking_if_needed(queue);
4402 /*
4403 * check if we need to flush a packing buffer to get a pci
4404 * flag out on the queue
4405 */
4406 if (!flush_count && !atomic_read(&queue->set_pci_flags_count))
4407 flush_count += qeth_flush_buffers_on_no_pci(queue);
4408 if (flush_count)
4409 qeth_flush_buffers(queue, 0, start_index, flush_count);
4410 }
4411 /* at this point the queue is UNLOCKED again */
Frank Pavlic09d2d382006-09-15 16:26:34 +02004412 if (queue->card->options.performance_stats && do_pack)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004413 queue->card->perf_stats.bufs_sent_pack += flush_count;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004414
4415 return rc;
4416}
4417
Heiko Carstens4d284ca2007-02-05 21:18:53 +01004418static int
Jeff Garzike82b0f22006-05-26 21:58:38 -04004419qeth_get_elements_no(struct qeth_card *card, void *hdr,
Frank Pavlic9cb90de2005-09-14 18:03:26 +02004420 struct sk_buff *skb, int elems)
Frank Pavlic05e08a22005-05-12 20:39:09 +02004421{
4422 int elements_needed = 0;
4423
Frank Pavlicf7b65d72006-09-15 16:26:19 +02004424 if (skb_shinfo(skb)->nr_frags > 0)
Frank Pavlic05e08a22005-05-12 20:39:09 +02004425 elements_needed = (skb_shinfo(skb)->nr_frags + 1);
Frank Pavlicf7b65d72006-09-15 16:26:19 +02004426 if (elements_needed == 0)
Frank Pavlic05e08a22005-05-12 20:39:09 +02004427 elements_needed = 1 + (((((unsigned long) hdr) % PAGE_SIZE)
4428 + skb->len) >> PAGE_SHIFT);
Frank Pavlic9cb90de2005-09-14 18:03:26 +02004429 if ((elements_needed + elems) > QETH_MAX_BUFFER_ELEMENTS(card)){
Frank Pavlicf7b65d72006-09-15 16:26:19 +02004430 PRINT_ERR("Invalid size of IP packet "
4431 "(Number=%d / Length=%d). Discarded.\n",
Frank Pavlic9cb90de2005-09-14 18:03:26 +02004432 (elements_needed+elems), skb->len);
Frank Pavlic05e08a22005-05-12 20:39:09 +02004433 return 0;
4434 }
4435 return elements_needed;
4436}
4437
Frank Pavlicf7b65d72006-09-15 16:26:19 +02004438
Heiko Carstens4d284ca2007-02-05 21:18:53 +01004439static int
Linus Torvalds1da177e2005-04-16 15:20:36 -07004440qeth_send_packet(struct qeth_card *card, struct sk_buff *skb)
4441{
4442 int ipv = 0;
4443 int cast_type;
4444 struct qeth_qdio_out_q *queue;
Frank Pavlicf3d242e2005-09-14 18:05:31 +02004445 struct qeth_hdr *hdr = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004446 int elements_needed = 0;
4447 enum qeth_large_send_types large_send = QETH_LARGE_SEND_NO;
4448 struct qeth_eddp_context *ctx = NULL;
Frank Pavlic95f6b5a2006-03-22 16:03:39 +01004449 int tx_bytes = skb->len;
Ursula Braunba1aa082006-05-24 09:51:13 +02004450 unsigned short nr_frags = skb_shinfo(skb)->nr_frags;
Herbert Xu79671682006-06-22 02:40:14 -07004451 unsigned short tso_size = skb_shinfo(skb)->gso_size;
Frank Pavlicf7b65d72006-09-15 16:26:19 +02004452 struct sk_buff *new_skb, *new_skb2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004453 int rc;
4454
4455 QETH_DBF_TEXT(trace, 6, "sendpkt");
4456
Frank Pavlicf7b65d72006-09-15 16:26:19 +02004457 new_skb = skb;
4458 if ((card->info.type == QETH_CARD_TYPE_OSN) &&
4459 (skb->protocol == htons(ETH_P_IPV6)))
4460 return -EPERM;
4461 cast_type = qeth_get_cast_type(card, skb);
4462 if ((cast_type == RTN_BROADCAST) &&
4463 (card->info.broadcast_capable == 0))
4464 return -EPERM;
4465 queue = card->qdio.out_qs
4466 [qeth_get_priority_queue(card, skb, ipv, cast_type)];
Linus Torvalds1da177e2005-04-16 15:20:36 -07004467 if (!card->options.layer2) {
4468 ipv = qeth_get_ip_version(skb);
4469 if ((card->dev->hard_header == qeth_fake_header) && ipv) {
Frank Pavlicf7b65d72006-09-15 16:26:19 +02004470 new_skb = qeth_pskb_unshare(skb, GFP_ATOMIC);
4471 if (!new_skb)
4472 return -ENOMEM;
Frank Pavlice23dd9c2005-05-12 20:38:11 +02004473 if(card->dev->type == ARPHRD_IEEE802_TR){
Frank Pavlicf7b65d72006-09-15 16:26:19 +02004474 skb_pull(new_skb, QETH_FAKE_LL_LEN_TR);
Frank Pavlice23dd9c2005-05-12 20:38:11 +02004475 } else {
Frank Pavlicf7b65d72006-09-15 16:26:19 +02004476 skb_pull(new_skb, QETH_FAKE_LL_LEN_ETH);
Frank Pavlice23dd9c2005-05-12 20:38:11 +02004477 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004478 }
4479 }
Herbert Xu89114af2006-07-08 13:34:32 -07004480 if (skb_is_gso(skb))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004481 large_send = card->options.large_send;
Frank Pavlicf7b65d72006-09-15 16:26:19 +02004482 /* check on OSN device*/
4483 if (card->info.type == QETH_CARD_TYPE_OSN)
4484 hdr = (struct qeth_hdr *)new_skb->data;
4485 /*are we able to do TSO ? */
Linus Torvalds1da177e2005-04-16 15:20:36 -07004486 if ((large_send == QETH_LARGE_SEND_TSO) &&
4487 (cast_type == RTN_UNSPEC)) {
Frank Pavlicf7b65d72006-09-15 16:26:19 +02004488 rc = qeth_tso_prepare_packet(card, new_skb, ipv, cast_type);
Frank Pavlic05e08a22005-05-12 20:39:09 +02004489 if (rc) {
Frank Pavlicf7b65d72006-09-15 16:26:19 +02004490 __qeth_free_new_skb(skb, new_skb);
Frank Pavlic05e08a22005-05-12 20:39:09 +02004491 return rc;
4492 }
Frank Pavlicf7b65d72006-09-15 16:26:19 +02004493 elements_needed++;
4494 } else if (card->info.type != QETH_CARD_TYPE_OSN) {
4495 new_skb2 = qeth_prepare_skb(card, new_skb, &hdr, ipv);
4496 if (!new_skb2) {
4497 __qeth_free_new_skb(skb, new_skb);
4498 return -EINVAL;
4499 }
4500 if (new_skb != skb)
4501 __qeth_free_new_skb(new_skb2, new_skb);
4502 new_skb = new_skb2;
4503 qeth_fill_header(card, hdr, new_skb, ipv, cast_type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004504 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004505 if (large_send == QETH_LARGE_SEND_EDDP) {
Ursula Brauna4c48a22007-05-02 15:17:11 +02004506 ctx = qeth_eddp_create_context(card, new_skb, hdr,
4507 skb->sk->sk_protocol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004508 if (ctx == NULL) {
Frank Pavlicf7b65d72006-09-15 16:26:19 +02004509 __qeth_free_new_skb(skb, new_skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004510 PRINT_WARN("could not create eddp context\n");
4511 return -EINVAL;
4512 }
4513 } else {
Frank Pavlicf7b65d72006-09-15 16:26:19 +02004514 int elems = qeth_get_elements_no(card,(void*) hdr, new_skb,
Frank Pavlic9cb90de2005-09-14 18:03:26 +02004515 elements_needed);
Frank Pavlicf7b65d72006-09-15 16:26:19 +02004516 if (!elems) {
4517 __qeth_free_new_skb(skb, new_skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004518 return -EINVAL;
Frank Pavlicf7b65d72006-09-15 16:26:19 +02004519 }
Frank Pavlic9cb90de2005-09-14 18:03:26 +02004520 elements_needed += elems;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004521 }
4522
4523 if (card->info.type != QETH_CARD_TYPE_IQD)
Frank Pavlicf7b65d72006-09-15 16:26:19 +02004524 rc = qeth_do_send_packet(card, queue, new_skb, hdr,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004525 elements_needed, ctx);
4526 else
Frank Pavlicf7b65d72006-09-15 16:26:19 +02004527 rc = qeth_do_send_packet_fast(card, queue, new_skb, hdr,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004528 elements_needed, ctx);
Frank Pavlicf7b65d72006-09-15 16:26:19 +02004529 if (!rc) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004530 card->stats.tx_packets++;
Frank Pavlic95f6b5a2006-03-22 16:03:39 +01004531 card->stats.tx_bytes += tx_bytes;
Frank Pavlicf7b65d72006-09-15 16:26:19 +02004532 if (new_skb != skb)
4533 dev_kfree_skb_any(skb);
Frank Pavlic09d2d382006-09-15 16:26:34 +02004534 if (card->options.performance_stats) {
4535 if (tso_size &&
4536 !(large_send == QETH_LARGE_SEND_NO)) {
4537 card->perf_stats.large_send_bytes += tx_bytes;
4538 card->perf_stats.large_send_cnt++;
4539 }
4540 if (nr_frags > 0) {
4541 card->perf_stats.sg_skbs_sent++;
4542 /* nr_frags + skb->data */
4543 card->perf_stats.sg_frags_sent +=
4544 nr_frags + 1;
4545 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004546 }
Frank Pavlicf7b65d72006-09-15 16:26:19 +02004547 } else {
4548 card->stats.tx_dropped++;
4549 __qeth_free_new_skb(skb, new_skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004550 }
4551 if (ctx != NULL) {
4552 /* drop creator's reference */
4553 qeth_eddp_put_context(ctx);
4554 /* free skb; it's not referenced by a buffer */
Frank Pavlicf7b65d72006-09-15 16:26:19 +02004555 if (!rc)
4556 dev_kfree_skb_any(new_skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004557 }
4558 return rc;
4559}
4560
4561static int
4562qeth_mdio_read(struct net_device *dev, int phy_id, int regnum)
4563{
4564 struct qeth_card *card = (struct qeth_card *) dev->priv;
4565 int rc = 0;
4566
4567 switch(regnum){
4568 case MII_BMCR: /* Basic mode control register */
4569 rc = BMCR_FULLDPLX;
4570 if ((card->info.link_type != QETH_LINK_TYPE_GBIT_ETH)&&
Ursula Braun500f83a2005-09-30 10:19:19 +02004571 (card->info.link_type != QETH_LINK_TYPE_OSN) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07004572 (card->info.link_type != QETH_LINK_TYPE_10GBIT_ETH))
4573 rc |= BMCR_SPEED100;
4574 break;
4575 case MII_BMSR: /* Basic mode status register */
4576 rc = BMSR_ERCAP | BMSR_ANEGCOMPLETE | BMSR_LSTATUS |
4577 BMSR_10HALF | BMSR_10FULL | BMSR_100HALF | BMSR_100FULL |
4578 BMSR_100BASE4;
4579 break;
4580 case MII_PHYSID1: /* PHYS ID 1 */
4581 rc = (dev->dev_addr[0] << 16) | (dev->dev_addr[1] << 8) |
4582 dev->dev_addr[2];
4583 rc = (rc >> 5) & 0xFFFF;
4584 break;
4585 case MII_PHYSID2: /* PHYS ID 2 */
4586 rc = (dev->dev_addr[2] << 10) & 0xFFFF;
4587 break;
4588 case MII_ADVERTISE: /* Advertisement control reg */
4589 rc = ADVERTISE_ALL;
4590 break;
4591 case MII_LPA: /* Link partner ability reg */
4592 rc = LPA_10HALF | LPA_10FULL | LPA_100HALF | LPA_100FULL |
4593 LPA_100BASE4 | LPA_LPACK;
4594 break;
4595 case MII_EXPANSION: /* Expansion register */
4596 break;
4597 case MII_DCOUNTER: /* disconnect counter */
4598 break;
4599 case MII_FCSCOUNTER: /* false carrier counter */
4600 break;
4601 case MII_NWAYTEST: /* N-way auto-neg test register */
4602 break;
4603 case MII_RERRCOUNTER: /* rx error counter */
4604 rc = card->stats.rx_errors;
4605 break;
4606 case MII_SREVISION: /* silicon revision */
4607 break;
4608 case MII_RESV1: /* reserved 1 */
4609 break;
4610 case MII_LBRERROR: /* loopback, rx, bypass error */
4611 break;
4612 case MII_PHYADDR: /* physical address */
4613 break;
4614 case MII_RESV2: /* reserved 2 */
4615 break;
4616 case MII_TPISTATUS: /* TPI status for 10mbps */
4617 break;
4618 case MII_NCONFIG: /* network interface config */
4619 break;
4620 default:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004621 break;
4622 }
4623 return rc;
4624}
4625
Linus Torvalds1da177e2005-04-16 15:20:36 -07004626
Heiko Carstens4d284ca2007-02-05 21:18:53 +01004627static const char *
Linus Torvalds1da177e2005-04-16 15:20:36 -07004628qeth_arp_get_error_cause(int *rc)
4629{
4630 switch (*rc) {
4631 case QETH_IPA_ARP_RC_FAILED:
4632 *rc = -EIO;
4633 return "operation failed";
4634 case QETH_IPA_ARP_RC_NOTSUPP:
4635 *rc = -EOPNOTSUPP;
4636 return "operation not supported";
4637 case QETH_IPA_ARP_RC_OUT_OF_RANGE:
4638 *rc = -EINVAL;
4639 return "argument out of range";
4640 case QETH_IPA_ARP_RC_Q_NOTSUPP:
4641 *rc = -EOPNOTSUPP;
4642 return "query operation not supported";
4643 case QETH_IPA_ARP_RC_Q_NO_DATA:
4644 *rc = -ENOENT;
4645 return "no query data available";
4646 default:
4647 return "unknown error";
4648 }
4649}
4650
4651static int
4652qeth_send_simple_setassparms(struct qeth_card *, enum qeth_ipa_funcs,
4653 __u16, long);
4654
4655static int
4656qeth_arp_set_no_entries(struct qeth_card *card, int no_entries)
4657{
4658 int tmp;
4659 int rc;
4660
4661 QETH_DBF_TEXT(trace,3,"arpstnoe");
4662
Frank Pavlicf3d242e2005-09-14 18:05:31 +02004663 /*
4664 * currently GuestLAN only supports the ARP assist function
4665 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_SET_NO_ENTRIES;
4666 * thus we say EOPNOTSUPP for this ARP function
4667 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07004668 if (card->info.guestlan)
4669 return -EOPNOTSUPP;
4670 if (!qeth_is_supported(card,IPA_ARP_PROCESSING)) {
4671 PRINT_WARN("ARP processing not supported "
4672 "on %s!\n", QETH_CARD_IFNAME(card));
4673 return -EOPNOTSUPP;
4674 }
4675 rc = qeth_send_simple_setassparms(card, IPA_ARP_PROCESSING,
4676 IPA_CMD_ASS_ARP_SET_NO_ENTRIES,
4677 no_entries);
4678 if (rc) {
4679 tmp = rc;
4680 PRINT_WARN("Could not set number of ARP entries on %s: "
4681 "%s (0x%x/%d)\n",
4682 QETH_CARD_IFNAME(card), qeth_arp_get_error_cause(&rc),
4683 tmp, tmp);
4684 }
4685 return rc;
4686}
4687
Heiko Carstens4d284ca2007-02-05 21:18:53 +01004688static void
Linus Torvalds1da177e2005-04-16 15:20:36 -07004689qeth_copy_arp_entries_stripped(struct qeth_arp_query_info *qinfo,
4690 struct qeth_arp_query_data *qdata,
4691 int entry_size, int uentry_size)
4692{
4693 char *entry_ptr;
4694 char *uentry_ptr;
4695 int i;
4696
4697 entry_ptr = (char *)&qdata->data;
4698 uentry_ptr = (char *)(qinfo->udata + qinfo->udata_offset);
4699 for (i = 0; i < qdata->no_entries; ++i){
4700 /* strip off 32 bytes "media specific information" */
4701 memcpy(uentry_ptr, (entry_ptr + 32), entry_size - 32);
4702 entry_ptr += entry_size;
4703 uentry_ptr += uentry_size;
4704 }
4705}
4706
4707static int
4708qeth_arp_query_cb(struct qeth_card *card, struct qeth_reply *reply,
4709 unsigned long data)
4710{
4711 struct qeth_ipa_cmd *cmd;
4712 struct qeth_arp_query_data *qdata;
4713 struct qeth_arp_query_info *qinfo;
4714 int entry_size;
4715 int uentry_size;
4716 int i;
4717
4718 QETH_DBF_TEXT(trace,4,"arpquecb");
4719
4720 qinfo = (struct qeth_arp_query_info *) reply->param;
4721 cmd = (struct qeth_ipa_cmd *) data;
4722 if (cmd->hdr.return_code) {
4723 QETH_DBF_TEXT_(trace,4,"qaer1%i", cmd->hdr.return_code);
4724 return 0;
4725 }
4726 if (cmd->data.setassparms.hdr.return_code) {
4727 cmd->hdr.return_code = cmd->data.setassparms.hdr.return_code;
4728 QETH_DBF_TEXT_(trace,4,"qaer2%i", cmd->hdr.return_code);
4729 return 0;
4730 }
4731 qdata = &cmd->data.setassparms.data.query_arp;
4732 switch(qdata->reply_bits){
4733 case 5:
4734 uentry_size = entry_size = sizeof(struct qeth_arp_qi_entry5);
4735 if (qinfo->mask_bits & QETH_QARP_STRIP_ENTRIES)
4736 uentry_size = sizeof(struct qeth_arp_qi_entry5_short);
4737 break;
4738 case 7:
4739 /* fall through to default */
4740 default:
4741 /* tr is the same as eth -> entry7 */
4742 uentry_size = entry_size = sizeof(struct qeth_arp_qi_entry7);
4743 if (qinfo->mask_bits & QETH_QARP_STRIP_ENTRIES)
4744 uentry_size = sizeof(struct qeth_arp_qi_entry7_short);
4745 break;
4746 }
4747 /* check if there is enough room in userspace */
4748 if ((qinfo->udata_len - qinfo->udata_offset) <
4749 qdata->no_entries * uentry_size){
4750 QETH_DBF_TEXT_(trace, 4, "qaer3%i", -ENOMEM);
4751 cmd->hdr.return_code = -ENOMEM;
4752 PRINT_WARN("query ARP user space buffer is too small for "
4753 "the returned number of ARP entries. "
4754 "Aborting query!\n");
4755 goto out_error;
4756 }
4757 QETH_DBF_TEXT_(trace, 4, "anore%i",
4758 cmd->data.setassparms.hdr.number_of_replies);
4759 QETH_DBF_TEXT_(trace, 4, "aseqn%i", cmd->data.setassparms.hdr.seq_no);
4760 QETH_DBF_TEXT_(trace, 4, "anoen%i", qdata->no_entries);
4761
4762 if (qinfo->mask_bits & QETH_QARP_STRIP_ENTRIES) {
4763 /* strip off "media specific information" */
4764 qeth_copy_arp_entries_stripped(qinfo, qdata, entry_size,
4765 uentry_size);
4766 } else
4767 /*copy entries to user buffer*/
4768 memcpy(qinfo->udata + qinfo->udata_offset,
4769 (char *)&qdata->data, qdata->no_entries*uentry_size);
4770
4771 qinfo->no_entries += qdata->no_entries;
4772 qinfo->udata_offset += (qdata->no_entries*uentry_size);
4773 /* check if all replies received ... */
4774 if (cmd->data.setassparms.hdr.seq_no <
4775 cmd->data.setassparms.hdr.number_of_replies)
4776 return 1;
4777 memcpy(qinfo->udata, &qinfo->no_entries, 4);
4778 /* keep STRIP_ENTRIES flag so the user program can distinguish
4779 * stripped entries from normal ones */
4780 if (qinfo->mask_bits & QETH_QARP_STRIP_ENTRIES)
4781 qdata->reply_bits |= QETH_QARP_STRIP_ENTRIES;
4782 memcpy(qinfo->udata + QETH_QARP_MASK_OFFSET,&qdata->reply_bits,2);
4783 return 0;
4784out_error:
4785 i = 0;
4786 memcpy(qinfo->udata, &i, 4);
4787 return 0;
4788}
4789
4790static int
4791qeth_send_ipa_arp_cmd(struct qeth_card *card, struct qeth_cmd_buffer *iob,
4792 int len, int (*reply_cb)(struct qeth_card *,
4793 struct qeth_reply *,
4794 unsigned long),
4795 void *reply_param)
4796{
4797 QETH_DBF_TEXT(trace,4,"sendarp");
4798
4799 memcpy(iob->data, IPA_PDU_HEADER, IPA_PDU_HEADER_SIZE);
4800 memcpy(QETH_IPA_CMD_DEST_ADDR(iob->data),
4801 &card->token.ulp_connection_r, QETH_MPC_TOKEN_LENGTH);
4802 return qeth_send_control_data(card, IPA_PDU_HEADER_SIZE + len, iob,
4803 reply_cb, reply_param);
4804}
4805
4806static int
4807qeth_send_ipa_snmp_cmd(struct qeth_card *card, struct qeth_cmd_buffer *iob,
4808 int len, int (*reply_cb)(struct qeth_card *,
4809 struct qeth_reply *,
4810 unsigned long),
4811 void *reply_param)
4812{
4813 u16 s1, s2;
4814
4815 QETH_DBF_TEXT(trace,4,"sendsnmp");
4816
4817 memcpy(iob->data, IPA_PDU_HEADER, IPA_PDU_HEADER_SIZE);
4818 memcpy(QETH_IPA_CMD_DEST_ADDR(iob->data),
4819 &card->token.ulp_connection_r, QETH_MPC_TOKEN_LENGTH);
4820 /* adjust PDU length fields in IPA_PDU_HEADER */
4821 s1 = (u32) IPA_PDU_HEADER_SIZE + len;
4822 s2 = (u32) len;
4823 memcpy(QETH_IPA_PDU_LEN_TOTAL(iob->data), &s1, 2);
4824 memcpy(QETH_IPA_PDU_LEN_PDU1(iob->data), &s2, 2);
4825 memcpy(QETH_IPA_PDU_LEN_PDU2(iob->data), &s2, 2);
4826 memcpy(QETH_IPA_PDU_LEN_PDU3(iob->data), &s2, 2);
4827 return qeth_send_control_data(card, IPA_PDU_HEADER_SIZE + len, iob,
4828 reply_cb, reply_param);
4829}
4830
4831static struct qeth_cmd_buffer *
4832qeth_get_setassparms_cmd(struct qeth_card *, enum qeth_ipa_funcs,
4833 __u16, __u16, enum qeth_prot_versions);
4834static int
Heiko Carstensd2c993d2006-07-12 16:41:55 +02004835qeth_arp_query(struct qeth_card *card, char __user *udata)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004836{
4837 struct qeth_cmd_buffer *iob;
4838 struct qeth_arp_query_info qinfo = {0, };
4839 int tmp;
4840 int rc;
4841
4842 QETH_DBF_TEXT(trace,3,"arpquery");
4843
Linus Torvalds1da177e2005-04-16 15:20:36 -07004844 if (!qeth_is_supported(card,/*IPA_QUERY_ARP_ADDR_INFO*/
4845 IPA_ARP_PROCESSING)) {
4846 PRINT_WARN("ARP processing not supported "
4847 "on %s!\n", QETH_CARD_IFNAME(card));
4848 return -EOPNOTSUPP;
4849 }
4850 /* get size of userspace buffer and mask_bits -> 6 bytes */
4851 if (copy_from_user(&qinfo, udata, 6))
4852 return -EFAULT;
Eric Sesterhenn88abaab2006-03-24 03:15:31 -08004853 if (!(qinfo.udata = kzalloc(qinfo.udata_len, GFP_KERNEL)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004854 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004855 qinfo.udata_offset = QETH_QARP_ENTRIES_OFFSET;
4856 iob = qeth_get_setassparms_cmd(card, IPA_ARP_PROCESSING,
4857 IPA_CMD_ASS_ARP_QUERY_INFO,
4858 sizeof(int),QETH_PROT_IPV4);
4859
4860 rc = qeth_send_ipa_arp_cmd(card, iob,
4861 QETH_SETASS_BASE_LEN+QETH_ARP_CMD_LEN,
4862 qeth_arp_query_cb, (void *)&qinfo);
4863 if (rc) {
4864 tmp = rc;
4865 PRINT_WARN("Error while querying ARP cache on %s: %s "
4866 "(0x%x/%d)\n",
4867 QETH_CARD_IFNAME(card), qeth_arp_get_error_cause(&rc),
4868 tmp, tmp);
Heiko Carstens3a6b95c2006-12-28 13:05:36 +01004869 if (copy_to_user(udata, qinfo.udata, 4))
4870 rc = -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004871 } else {
Heiko Carstens3a6b95c2006-12-28 13:05:36 +01004872 if (copy_to_user(udata, qinfo.udata, qinfo.udata_len))
4873 rc = -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004874 }
4875 kfree(qinfo.udata);
4876 return rc;
4877}
4878
4879/**
4880 * SNMP command callback
4881 */
4882static int
4883qeth_snmp_command_cb(struct qeth_card *card, struct qeth_reply *reply,
4884 unsigned long sdata)
4885{
4886 struct qeth_ipa_cmd *cmd;
4887 struct qeth_arp_query_info *qinfo;
4888 struct qeth_snmp_cmd *snmp;
4889 unsigned char *data;
4890 __u16 data_len;
4891
4892 QETH_DBF_TEXT(trace,3,"snpcmdcb");
4893
4894 cmd = (struct qeth_ipa_cmd *) sdata;
4895 data = (unsigned char *)((char *)cmd - reply->offset);
4896 qinfo = (struct qeth_arp_query_info *) reply->param;
4897 snmp = &cmd->data.setadapterparms.data.snmp;
4898
4899 if (cmd->hdr.return_code) {
4900 QETH_DBF_TEXT_(trace,4,"scer1%i", cmd->hdr.return_code);
4901 return 0;
4902 }
4903 if (cmd->data.setadapterparms.hdr.return_code) {
4904 cmd->hdr.return_code = cmd->data.setadapterparms.hdr.return_code;
4905 QETH_DBF_TEXT_(trace,4,"scer2%i", cmd->hdr.return_code);
4906 return 0;
4907 }
4908 data_len = *((__u16*)QETH_IPA_PDU_LEN_PDU1(data));
4909 if (cmd->data.setadapterparms.hdr.seq_no == 1)
4910 data_len -= (__u16)((char *)&snmp->data - (char *)cmd);
4911 else
4912 data_len -= (__u16)((char*)&snmp->request - (char *)cmd);
4913
4914 /* check if there is enough room in userspace */
4915 if ((qinfo->udata_len - qinfo->udata_offset) < data_len) {
4916 QETH_DBF_TEXT_(trace, 4, "scer3%i", -ENOMEM);
4917 cmd->hdr.return_code = -ENOMEM;
4918 return 0;
4919 }
4920 QETH_DBF_TEXT_(trace, 4, "snore%i",
4921 cmd->data.setadapterparms.hdr.used_total);
4922 QETH_DBF_TEXT_(trace, 4, "sseqn%i", cmd->data.setadapterparms.hdr.seq_no);
4923 /*copy entries to user buffer*/
4924 if (cmd->data.setadapterparms.hdr.seq_no == 1) {
4925 memcpy(qinfo->udata + qinfo->udata_offset,
4926 (char *)snmp,
4927 data_len + offsetof(struct qeth_snmp_cmd,data));
4928 qinfo->udata_offset += offsetof(struct qeth_snmp_cmd, data);
4929 } else {
4930 memcpy(qinfo->udata + qinfo->udata_offset,
4931 (char *)&snmp->request, data_len);
4932 }
4933 qinfo->udata_offset += data_len;
4934 /* check if all replies received ... */
4935 QETH_DBF_TEXT_(trace, 4, "srtot%i",
4936 cmd->data.setadapterparms.hdr.used_total);
4937 QETH_DBF_TEXT_(trace, 4, "srseq%i",
4938 cmd->data.setadapterparms.hdr.seq_no);
4939 if (cmd->data.setadapterparms.hdr.seq_no <
4940 cmd->data.setadapterparms.hdr.used_total)
4941 return 1;
4942 return 0;
4943}
4944
4945static struct qeth_cmd_buffer *
4946qeth_get_ipacmd_buffer(struct qeth_card *, enum qeth_ipa_cmds,
4947 enum qeth_prot_versions );
4948
4949static struct qeth_cmd_buffer *
4950qeth_get_adapter_cmd(struct qeth_card *card, __u32 command, __u32 cmdlen)
4951{
4952 struct qeth_cmd_buffer *iob;
4953 struct qeth_ipa_cmd *cmd;
4954
4955 iob = qeth_get_ipacmd_buffer(card,IPA_CMD_SETADAPTERPARMS,
4956 QETH_PROT_IPV4);
4957 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
4958 cmd->data.setadapterparms.hdr.cmdlength = cmdlen;
4959 cmd->data.setadapterparms.hdr.command_code = command;
4960 cmd->data.setadapterparms.hdr.used_total = 1;
4961 cmd->data.setadapterparms.hdr.seq_no = 1;
4962
4963 return iob;
4964}
4965
4966/**
4967 * function to send SNMP commands to OSA-E card
4968 */
4969static int
Heiko Carstensd2c993d2006-07-12 16:41:55 +02004970qeth_snmp_command(struct qeth_card *card, char __user *udata)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004971{
4972 struct qeth_cmd_buffer *iob;
4973 struct qeth_ipa_cmd *cmd;
4974 struct qeth_snmp_ureq *ureq;
4975 int req_len;
4976 struct qeth_arp_query_info qinfo = {0, };
4977 int rc = 0;
4978
4979 QETH_DBF_TEXT(trace,3,"snmpcmd");
4980
4981 if (card->info.guestlan)
4982 return -EOPNOTSUPP;
4983
4984 if ((!qeth_adp_supported(card,IPA_SETADP_SET_SNMP_CONTROL)) &&
4985 (!card->options.layer2) ) {
4986 PRINT_WARN("SNMP Query MIBS not supported "
4987 "on %s!\n", QETH_CARD_IFNAME(card));
4988 return -EOPNOTSUPP;
4989 }
4990 /* skip 4 bytes (data_len struct member) to get req_len */
4991 if (copy_from_user(&req_len, udata + sizeof(int), sizeof(int)))
4992 return -EFAULT;
4993 ureq = kmalloc(req_len+sizeof(struct qeth_snmp_ureq_hdr), GFP_KERNEL);
4994 if (!ureq) {
4995 QETH_DBF_TEXT(trace, 2, "snmpnome");
4996 return -ENOMEM;
4997 }
4998 if (copy_from_user(ureq, udata,
4999 req_len+sizeof(struct qeth_snmp_ureq_hdr))){
5000 kfree(ureq);
5001 return -EFAULT;
5002 }
5003 qinfo.udata_len = ureq->hdr.data_len;
Eric Sesterhenn88abaab2006-03-24 03:15:31 -08005004 if (!(qinfo.udata = kzalloc(qinfo.udata_len, GFP_KERNEL))){
Linus Torvalds1da177e2005-04-16 15:20:36 -07005005 kfree(ureq);
5006 return -ENOMEM;
5007 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005008 qinfo.udata_offset = sizeof(struct qeth_snmp_ureq_hdr);
5009
5010 iob = qeth_get_adapter_cmd(card, IPA_SETADP_SET_SNMP_CONTROL,
5011 QETH_SNMP_SETADP_CMDLENGTH + req_len);
5012 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
5013 memcpy(&cmd->data.setadapterparms.data.snmp, &ureq->cmd, req_len);
5014 rc = qeth_send_ipa_snmp_cmd(card, iob, QETH_SETADP_BASE_LEN + req_len,
5015 qeth_snmp_command_cb, (void *)&qinfo);
5016 if (rc)
5017 PRINT_WARN("SNMP command failed on %s: (0x%x)\n",
5018 QETH_CARD_IFNAME(card), rc);
Heiko Carstens3a6b95c2006-12-28 13:05:36 +01005019 else {
5020 if (copy_to_user(udata, qinfo.udata, qinfo.udata_len))
5021 rc = -EFAULT;
5022 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005023
5024 kfree(ureq);
5025 kfree(qinfo.udata);
5026 return rc;
5027}
5028
5029static int
5030qeth_default_setassparms_cb(struct qeth_card *, struct qeth_reply *,
5031 unsigned long);
5032
5033static int
Frank Pavlic6c951b92005-11-10 13:51:25 +01005034qeth_default_setadapterparms_cb(struct qeth_card *card,
5035 struct qeth_reply *reply,
5036 unsigned long data);
5037static int
Linus Torvalds1da177e2005-04-16 15:20:36 -07005038qeth_send_setassparms(struct qeth_card *, struct qeth_cmd_buffer *,
5039 __u16, long,
5040 int (*reply_cb)
5041 (struct qeth_card *, struct qeth_reply *, unsigned long),
5042 void *reply_param);
5043
5044static int
5045qeth_arp_add_entry(struct qeth_card *card, struct qeth_arp_cache_entry *entry)
5046{
5047 struct qeth_cmd_buffer *iob;
5048 char buf[16];
5049 int tmp;
5050 int rc;
5051
5052 QETH_DBF_TEXT(trace,3,"arpadent");
5053
5054 /*
Frank Pavlicf3d242e2005-09-14 18:05:31 +02005055 * currently GuestLAN only supports the ARP assist function
5056 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_ADD_ENTRY;
5057 * thus we say EOPNOTSUPP for this ARP function
Linus Torvalds1da177e2005-04-16 15:20:36 -07005058 */
5059 if (card->info.guestlan)
5060 return -EOPNOTSUPP;
5061 if (!qeth_is_supported(card,IPA_ARP_PROCESSING)) {
5062 PRINT_WARN("ARP processing not supported "
5063 "on %s!\n", QETH_CARD_IFNAME(card));
5064 return -EOPNOTSUPP;
5065 }
5066
5067 iob = qeth_get_setassparms_cmd(card, IPA_ARP_PROCESSING,
5068 IPA_CMD_ASS_ARP_ADD_ENTRY,
5069 sizeof(struct qeth_arp_cache_entry),
5070 QETH_PROT_IPV4);
5071 rc = qeth_send_setassparms(card, iob,
5072 sizeof(struct qeth_arp_cache_entry),
5073 (unsigned long) entry,
5074 qeth_default_setassparms_cb, NULL);
5075 if (rc) {
5076 tmp = rc;
5077 qeth_ipaddr4_to_string((u8 *)entry->ipaddr, buf);
5078 PRINT_WARN("Could not add ARP entry for address %s on %s: "
5079 "%s (0x%x/%d)\n",
5080 buf, QETH_CARD_IFNAME(card),
5081 qeth_arp_get_error_cause(&rc), tmp, tmp);
5082 }
5083 return rc;
5084}
5085
5086static int
5087qeth_arp_remove_entry(struct qeth_card *card, struct qeth_arp_cache_entry *entry)
5088{
5089 struct qeth_cmd_buffer *iob;
5090 char buf[16] = {0, };
5091 int tmp;
5092 int rc;
5093
5094 QETH_DBF_TEXT(trace,3,"arprment");
5095
5096 /*
Frank Pavlicf3d242e2005-09-14 18:05:31 +02005097 * currently GuestLAN only supports the ARP assist function
5098 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_REMOVE_ENTRY;
5099 * thus we say EOPNOTSUPP for this ARP function
Linus Torvalds1da177e2005-04-16 15:20:36 -07005100 */
5101 if (card->info.guestlan)
5102 return -EOPNOTSUPP;
5103 if (!qeth_is_supported(card,IPA_ARP_PROCESSING)) {
5104 PRINT_WARN("ARP processing not supported "
5105 "on %s!\n", QETH_CARD_IFNAME(card));
5106 return -EOPNOTSUPP;
5107 }
5108 memcpy(buf, entry, 12);
5109 iob = qeth_get_setassparms_cmd(card, IPA_ARP_PROCESSING,
5110 IPA_CMD_ASS_ARP_REMOVE_ENTRY,
5111 12,
5112 QETH_PROT_IPV4);
5113 rc = qeth_send_setassparms(card, iob,
5114 12, (unsigned long)buf,
5115 qeth_default_setassparms_cb, NULL);
5116 if (rc) {
5117 tmp = rc;
5118 memset(buf, 0, 16);
5119 qeth_ipaddr4_to_string((u8 *)entry->ipaddr, buf);
5120 PRINT_WARN("Could not delete ARP entry for address %s on %s: "
5121 "%s (0x%x/%d)\n",
5122 buf, QETH_CARD_IFNAME(card),
5123 qeth_arp_get_error_cause(&rc), tmp, tmp);
5124 }
5125 return rc;
5126}
5127
5128static int
5129qeth_arp_flush_cache(struct qeth_card *card)
5130{
5131 int rc;
5132 int tmp;
5133
5134 QETH_DBF_TEXT(trace,3,"arpflush");
5135
5136 /*
Frank Pavlicf3d242e2005-09-14 18:05:31 +02005137 * currently GuestLAN only supports the ARP assist function
5138 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_FLUSH_CACHE;
5139 * thus we say EOPNOTSUPP for this ARP function
5140 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07005141 if (card->info.guestlan || (card->info.type == QETH_CARD_TYPE_IQD))
5142 return -EOPNOTSUPP;
5143 if (!qeth_is_supported(card,IPA_ARP_PROCESSING)) {
5144 PRINT_WARN("ARP processing not supported "
5145 "on %s!\n", QETH_CARD_IFNAME(card));
5146 return -EOPNOTSUPP;
5147 }
5148 rc = qeth_send_simple_setassparms(card, IPA_ARP_PROCESSING,
5149 IPA_CMD_ASS_ARP_FLUSH_CACHE, 0);
5150 if (rc){
5151 tmp = rc;
5152 PRINT_WARN("Could not flush ARP cache on %s: %s (0x%x/%d)\n",
5153 QETH_CARD_IFNAME(card), qeth_arp_get_error_cause(&rc),
5154 tmp, tmp);
5155 }
5156 return rc;
5157}
5158
5159static int
5160qeth_do_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
5161{
5162 struct qeth_card *card = (struct qeth_card *)dev->priv;
5163 struct qeth_arp_cache_entry arp_entry;
5164 struct mii_ioctl_data *mii_data;
5165 int rc = 0;
5166
5167 if (!card)
5168 return -ENODEV;
5169
5170 if ((card->state != CARD_STATE_UP) &&
5171 (card->state != CARD_STATE_SOFTSETUP))
5172 return -ENODEV;
5173
Ursula Braun500f83a2005-09-30 10:19:19 +02005174 if (card->info.type == QETH_CARD_TYPE_OSN)
5175 return -EPERM;
5176
Linus Torvalds1da177e2005-04-16 15:20:36 -07005177 switch (cmd){
5178 case SIOC_QETH_ARP_SET_NO_ENTRIES:
5179 if ( !capable(CAP_NET_ADMIN) ||
5180 (card->options.layer2) ) {
5181 rc = -EPERM;
5182 break;
5183 }
5184 rc = qeth_arp_set_no_entries(card, rq->ifr_ifru.ifru_ivalue);
5185 break;
5186 case SIOC_QETH_ARP_QUERY_INFO:
5187 if ( !capable(CAP_NET_ADMIN) ||
5188 (card->options.layer2) ) {
5189 rc = -EPERM;
5190 break;
5191 }
5192 rc = qeth_arp_query(card, rq->ifr_ifru.ifru_data);
5193 break;
5194 case SIOC_QETH_ARP_ADD_ENTRY:
5195 if ( !capable(CAP_NET_ADMIN) ||
5196 (card->options.layer2) ) {
5197 rc = -EPERM;
5198 break;
5199 }
5200 if (copy_from_user(&arp_entry, rq->ifr_ifru.ifru_data,
5201 sizeof(struct qeth_arp_cache_entry)))
5202 rc = -EFAULT;
5203 else
5204 rc = qeth_arp_add_entry(card, &arp_entry);
5205 break;
5206 case SIOC_QETH_ARP_REMOVE_ENTRY:
5207 if ( !capable(CAP_NET_ADMIN) ||
5208 (card->options.layer2) ) {
5209 rc = -EPERM;
5210 break;
5211 }
5212 if (copy_from_user(&arp_entry, rq->ifr_ifru.ifru_data,
5213 sizeof(struct qeth_arp_cache_entry)))
5214 rc = -EFAULT;
5215 else
5216 rc = qeth_arp_remove_entry(card, &arp_entry);
5217 break;
5218 case SIOC_QETH_ARP_FLUSH_CACHE:
5219 if ( !capable(CAP_NET_ADMIN) ||
5220 (card->options.layer2) ) {
5221 rc = -EPERM;
5222 break;
5223 }
5224 rc = qeth_arp_flush_cache(card);
5225 break;
5226 case SIOC_QETH_ADP_SET_SNMP_CONTROL:
5227 rc = qeth_snmp_command(card, rq->ifr_ifru.ifru_data);
5228 break;
5229 case SIOC_QETH_GET_CARD_TYPE:
5230 if ((card->info.type == QETH_CARD_TYPE_OSAE) &&
5231 !card->info.guestlan)
5232 return 1;
5233 return 0;
5234 break;
5235 case SIOCGMIIPHY:
5236 mii_data = if_mii(rq);
5237 mii_data->phy_id = 0;
5238 break;
5239 case SIOCGMIIREG:
5240 mii_data = if_mii(rq);
5241 if (mii_data->phy_id != 0)
5242 rc = -EINVAL;
5243 else
5244 mii_data->val_out = qeth_mdio_read(dev,mii_data->phy_id,
5245 mii_data->reg_num);
5246 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005247 default:
5248 rc = -EOPNOTSUPP;
5249 }
5250 if (rc)
5251 QETH_DBF_TEXT_(trace, 2, "ioce%d", rc);
5252 return rc;
5253}
5254
5255static struct net_device_stats *
5256qeth_get_stats(struct net_device *dev)
5257{
5258 struct qeth_card *card;
5259
5260 card = (struct qeth_card *) (dev->priv);
5261
5262 QETH_DBF_TEXT(trace,5,"getstat");
5263
5264 return &card->stats;
5265}
5266
5267static int
5268qeth_change_mtu(struct net_device *dev, int new_mtu)
5269{
5270 struct qeth_card *card;
5271 char dbf_text[15];
5272
5273 card = (struct qeth_card *) (dev->priv);
5274
5275 QETH_DBF_TEXT(trace,4,"chgmtu");
5276 sprintf(dbf_text, "%8x", new_mtu);
5277 QETH_DBF_TEXT(trace,4,dbf_text);
5278
5279 if (new_mtu < 64)
5280 return -EINVAL;
5281 if (new_mtu > 65535)
5282 return -EINVAL;
5283 if ((!qeth_is_supported(card,IPA_IP_FRAGMENTATION)) &&
5284 (!qeth_mtu_is_valid(card, new_mtu)))
5285 return -EINVAL;
5286 dev->mtu = new_mtu;
5287 return 0;
5288}
5289
5290#ifdef CONFIG_QETH_VLAN
5291static void
5292qeth_vlan_rx_register(struct net_device *dev, struct vlan_group *grp)
5293{
5294 struct qeth_card *card;
5295 unsigned long flags;
5296
5297 QETH_DBF_TEXT(trace,4,"vlanreg");
5298
5299 card = (struct qeth_card *) dev->priv;
5300 spin_lock_irqsave(&card->vlanlock, flags);
5301 card->vlangrp = grp;
5302 spin_unlock_irqrestore(&card->vlanlock, flags);
5303}
5304
Heiko Carstens4d284ca2007-02-05 21:18:53 +01005305static void
Linus Torvalds1da177e2005-04-16 15:20:36 -07005306qeth_free_vlan_buffer(struct qeth_card *card, struct qeth_qdio_out_buffer *buf,
5307 unsigned short vid)
5308{
5309 int i;
5310 struct sk_buff *skb;
5311 struct sk_buff_head tmp_list;
5312
5313 skb_queue_head_init(&tmp_list);
Heiko Carstens91ebe2a2006-07-03 00:25:26 -07005314 lockdep_set_class(&tmp_list.lock, &qdio_out_skb_queue_key);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005315 for(i = 0; i < QETH_MAX_BUFFER_ELEMENTS(card); ++i){
5316 while ((skb = skb_dequeue(&buf->skb_list))){
5317 if (vlan_tx_tag_present(skb) &&
5318 (vlan_tx_tag_get(skb) == vid)) {
5319 atomic_dec(&skb->users);
5320 dev_kfree_skb(skb);
5321 } else
5322 skb_queue_tail(&tmp_list, skb);
5323 }
5324 }
5325 while ((skb = skb_dequeue(&tmp_list)))
5326 skb_queue_tail(&buf->skb_list, skb);
5327}
5328
5329static void
5330qeth_free_vlan_skbs(struct qeth_card *card, unsigned short vid)
5331{
5332 int i, j;
5333
5334 QETH_DBF_TEXT(trace, 4, "frvlskbs");
5335 for (i = 0; i < card->qdio.no_out_queues; ++i){
5336 for (j = 0; j < QDIO_MAX_BUFFERS_PER_Q; ++j)
5337 qeth_free_vlan_buffer(card, &card->qdio.
5338 out_qs[i]->bufs[j], vid);
5339 }
5340}
5341
5342static void
5343qeth_free_vlan_addresses4(struct qeth_card *card, unsigned short vid)
5344{
5345 struct in_device *in_dev;
5346 struct in_ifaddr *ifa;
5347 struct qeth_ipaddr *addr;
5348
5349 QETH_DBF_TEXT(trace, 4, "frvaddr4");
Frank Pavlic6c88ad22005-11-10 13:49:28 +01005350
Linus Torvalds1da177e2005-04-16 15:20:36 -07005351 rcu_read_lock();
Dan Aloni5c15bde2007-03-02 20:44:51 -08005352 in_dev = __in_dev_get_rcu(vlan_group_get_device(card->vlangrp, vid));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005353 if (!in_dev)
5354 goto out;
5355 for (ifa = in_dev->ifa_list; ifa; ifa = ifa->ifa_next) {
5356 addr = qeth_get_addr_buffer(QETH_PROT_IPV4);
5357 if (addr){
5358 addr->u.a4.addr = ifa->ifa_address;
5359 addr->u.a4.mask = ifa->ifa_mask;
5360 addr->type = QETH_IP_TYPE_NORMAL;
5361 if (!qeth_delete_ip(card, addr))
5362 kfree(addr);
5363 }
5364 }
5365out:
5366 rcu_read_unlock();
5367}
5368
5369static void
5370qeth_free_vlan_addresses6(struct qeth_card *card, unsigned short vid)
5371{
5372#ifdef CONFIG_QETH_IPV6
5373 struct inet6_dev *in6_dev;
5374 struct inet6_ifaddr *ifa;
5375 struct qeth_ipaddr *addr;
5376
5377 QETH_DBF_TEXT(trace, 4, "frvaddr6");
Frank Pavlic6c88ad22005-11-10 13:49:28 +01005378
Dan Aloni5c15bde2007-03-02 20:44:51 -08005379 in6_dev = in6_dev_get(vlan_group_get_device(card->vlangrp, vid));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005380 if (!in6_dev)
5381 return;
5382 for (ifa = in6_dev->addr_list; ifa; ifa = ifa->lst_next){
5383 addr = qeth_get_addr_buffer(QETH_PROT_IPV6);
5384 if (addr){
5385 memcpy(&addr->u.a6.addr, &ifa->addr,
5386 sizeof(struct in6_addr));
5387 addr->u.a6.pfxlen = ifa->prefix_len;
5388 addr->type = QETH_IP_TYPE_NORMAL;
5389 if (!qeth_delete_ip(card, addr))
5390 kfree(addr);
5391 }
5392 }
5393 in6_dev_put(in6_dev);
5394#endif /* CONFIG_QETH_IPV6 */
5395}
5396
Frank Pavlic6c88ad22005-11-10 13:49:28 +01005397static void
5398qeth_free_vlan_addresses(struct qeth_card *card, unsigned short vid)
5399{
5400 if (card->options.layer2 || !card->vlangrp)
5401 return;
5402 qeth_free_vlan_addresses4(card, vid);
5403 qeth_free_vlan_addresses6(card, vid);
5404}
5405
Frank Pavlic508cc2b2005-11-10 13:49:15 +01005406static int
5407qeth_layer2_send_setdelvlan_cb(struct qeth_card *card,
5408 struct qeth_reply *reply,
5409 unsigned long data)
5410{
5411 struct qeth_ipa_cmd *cmd;
5412
5413 QETH_DBF_TEXT(trace, 2, "L2sdvcb");
5414 cmd = (struct qeth_ipa_cmd *) data;
5415 if (cmd->hdr.return_code) {
5416 PRINT_ERR("Error in processing VLAN %i on %s: 0x%x. "
Jeff Garzike82b0f22006-05-26 21:58:38 -04005417 "Continuing\n",cmd->data.setdelvlan.vlan_id,
Frank Pavlic508cc2b2005-11-10 13:49:15 +01005418 QETH_CARD_IFNAME(card), cmd->hdr.return_code);
5419 QETH_DBF_TEXT_(trace, 2, "L2VL%4x", cmd->hdr.command);
5420 QETH_DBF_TEXT_(trace, 2, "L2%s", CARD_BUS_ID(card));
5421 QETH_DBF_TEXT_(trace, 2, "err%d", cmd->hdr.return_code);
5422 }
5423 return 0;
5424}
5425
5426static int
Linus Torvalds1da177e2005-04-16 15:20:36 -07005427qeth_layer2_send_setdelvlan(struct qeth_card *card, __u16 i,
5428 enum qeth_ipa_cmds ipacmd)
5429{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005430 struct qeth_ipa_cmd *cmd;
5431 struct qeth_cmd_buffer *iob;
5432
5433 QETH_DBF_TEXT_(trace, 4, "L2sdv%x",ipacmd);
5434 iob = qeth_get_ipacmd_buffer(card, ipacmd, QETH_PROT_IPV4);
5435 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
5436 cmd->data.setdelvlan.vlan_id = i;
Jeff Garzike82b0f22006-05-26 21:58:38 -04005437 return qeth_send_ipa_cmd(card, iob,
Frank Pavlic508cc2b2005-11-10 13:49:15 +01005438 qeth_layer2_send_setdelvlan_cb, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005439}
5440
5441static void
5442qeth_layer2_process_vlans(struct qeth_card *card, int clear)
5443{
5444 unsigned short i;
5445
5446 QETH_DBF_TEXT(trace, 3, "L2prcvln");
5447
5448 if (!card->vlangrp)
5449 return;
5450 for (i = 0; i < VLAN_GROUP_ARRAY_LEN; i++) {
Dan Aloni5c15bde2007-03-02 20:44:51 -08005451 if (vlan_group_get_device(card->vlangrp, i) == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005452 continue;
5453 if (clear)
5454 qeth_layer2_send_setdelvlan(card, i, IPA_CMD_DELVLAN);
5455 else
5456 qeth_layer2_send_setdelvlan(card, i, IPA_CMD_SETVLAN);
5457 }
5458}
5459
5460/*add_vid is layer 2 used only ....*/
5461static void
5462qeth_vlan_rx_add_vid(struct net_device *dev, unsigned short vid)
5463{
5464 struct qeth_card *card;
5465
5466 QETH_DBF_TEXT_(trace, 4, "aid:%d", vid);
5467
5468 card = (struct qeth_card *) dev->priv;
5469 if (!card->options.layer2)
5470 return;
5471 qeth_layer2_send_setdelvlan(card, vid, IPA_CMD_SETVLAN);
5472}
5473
5474/*... kill_vid used for both modes*/
5475static void
5476qeth_vlan_rx_kill_vid(struct net_device *dev, unsigned short vid)
5477{
5478 struct qeth_card *card;
5479 unsigned long flags;
5480
5481 QETH_DBF_TEXT_(trace, 4, "kid:%d", vid);
5482
5483 card = (struct qeth_card *) dev->priv;
5484 /* free all skbs for the vlan device */
5485 qeth_free_vlan_skbs(card, vid);
5486 spin_lock_irqsave(&card->vlanlock, flags);
5487 /* unregister IP addresses of vlan device */
Frank Pavlic6c88ad22005-11-10 13:49:28 +01005488 qeth_free_vlan_addresses(card, vid);
Dan Aloni5c15bde2007-03-02 20:44:51 -08005489 vlan_group_set_device(card->vlangrp, vid, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005490 spin_unlock_irqrestore(&card->vlanlock, flags);
5491 if (card->options.layer2)
5492 qeth_layer2_send_setdelvlan(card, vid, IPA_CMD_DELVLAN);
5493 qeth_set_multicast_list(card->dev);
5494}
5495#endif
Frank Pavlic6c951b92005-11-10 13:51:25 +01005496/**
5497 * Examine hardware response to SET_PROMISC_MODE
5498 */
5499static int
Jeff Garzike82b0f22006-05-26 21:58:38 -04005500qeth_setadp_promisc_mode_cb(struct qeth_card *card,
Frank Pavlic6c951b92005-11-10 13:51:25 +01005501 struct qeth_reply *reply,
5502 unsigned long data)
5503{
5504 struct qeth_ipa_cmd *cmd;
5505 struct qeth_ipacmd_setadpparms *setparms;
5506
5507 QETH_DBF_TEXT(trace,4,"prmadpcb");
5508
5509 cmd = (struct qeth_ipa_cmd *) data;
5510 setparms = &(cmd->data.setadapterparms);
Jeff Garzike82b0f22006-05-26 21:58:38 -04005511
Frank Pavlic6c951b92005-11-10 13:51:25 +01005512 qeth_default_setadapterparms_cb(card, reply, (unsigned long)cmd);
Jeff Garzike82b0f22006-05-26 21:58:38 -04005513 if (cmd->hdr.return_code) {
5514 QETH_DBF_TEXT_(trace,4,"prmrc%2.2x",cmd->hdr.return_code);
Frank Pavlic6c951b92005-11-10 13:51:25 +01005515 setparms->data.mode = SET_PROMISC_MODE_OFF;
5516 }
5517 card->info.promisc_mode = setparms->data.mode;
5518 return 0;
5519}
5520/*
5521 * Set promiscuous mode (on or off) (SET_PROMISC_MODE command)
5522 */
5523static void
5524qeth_setadp_promisc_mode(struct qeth_card *card)
5525{
5526 enum qeth_ipa_promisc_modes mode;
5527 struct net_device *dev = card->dev;
5528 struct qeth_cmd_buffer *iob;
5529 struct qeth_ipa_cmd *cmd;
5530
5531 QETH_DBF_TEXT(trace, 4, "setprom");
5532
5533 if (((dev->flags & IFF_PROMISC) &&
5534 (card->info.promisc_mode == SET_PROMISC_MODE_ON)) ||
5535 (!(dev->flags & IFF_PROMISC) &&
5536 (card->info.promisc_mode == SET_PROMISC_MODE_OFF)))
5537 return;
5538 mode = SET_PROMISC_MODE_OFF;
5539 if (dev->flags & IFF_PROMISC)
5540 mode = SET_PROMISC_MODE_ON;
5541 QETH_DBF_TEXT_(trace, 4, "mode:%x", mode);
5542
5543 iob = qeth_get_adapter_cmd(card, IPA_SETADP_SET_PROMISC_MODE,
5544 sizeof(struct qeth_ipacmd_setadpparms));
5545 cmd = (struct qeth_ipa_cmd *)(iob->data + IPA_PDU_HEADER_SIZE);
5546 cmd->data.setadapterparms.data.mode = mode;
5547 qeth_send_ipa_cmd(card, iob, qeth_setadp_promisc_mode_cb, NULL);
5548}
Linus Torvalds1da177e2005-04-16 15:20:36 -07005549
5550/**
5551 * set multicast address on card
5552 */
5553static void
5554qeth_set_multicast_list(struct net_device *dev)
5555{
5556 struct qeth_card *card = (struct qeth_card *) dev->priv;
5557
Ursula Braun500f83a2005-09-30 10:19:19 +02005558 if (card->info.type == QETH_CARD_TYPE_OSN)
5559 return ;
Jeff Garzike82b0f22006-05-26 21:58:38 -04005560
Frank Pavlic66cc5d52006-02-07 17:04:38 +01005561 QETH_DBF_TEXT(trace, 3, "setmulti");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005562 qeth_delete_mc_addresses(card);
Frank Pavlic6c88ad22005-11-10 13:49:28 +01005563 if (card->options.layer2) {
5564 qeth_layer2_add_multicast(card);
5565 goto out;
5566 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005567 qeth_add_multicast_ipv4(card);
5568#ifdef CONFIG_QETH_IPV6
5569 qeth_add_multicast_ipv6(card);
5570#endif
Frank Pavlic6c88ad22005-11-10 13:49:28 +01005571out:
Frank Blaschkaee2db682007-01-08 17:30:11 +01005572 qeth_set_ip_addr_list(card);
Frank Pavlic6c951b92005-11-10 13:51:25 +01005573 if (!qeth_adp_supported(card, IPA_SETADP_SET_PROMISC_MODE))
5574 return;
Frank Blaschkaee2db682007-01-08 17:30:11 +01005575 qeth_setadp_promisc_mode(card);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005576}
5577
5578static int
5579qeth_neigh_setup(struct net_device *dev, struct neigh_parms *np)
5580{
5581 return 0;
5582}
5583
5584static void
5585qeth_get_mac_for_ipm(__u32 ipm, char *mac, struct net_device *dev)
5586{
5587 if (dev->type == ARPHRD_IEEE802_TR)
5588 ip_tr_mc_map(ipm, mac);
5589 else
5590 ip_eth_mc_map(ipm, mac);
5591}
5592
5593static struct qeth_ipaddr *
5594qeth_get_addr_buffer(enum qeth_prot_versions prot)
5595{
5596 struct qeth_ipaddr *addr;
5597
Eric Sesterhenn88abaab2006-03-24 03:15:31 -08005598 addr = kzalloc(sizeof(struct qeth_ipaddr), GFP_ATOMIC);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005599 if (addr == NULL) {
5600 PRINT_WARN("Not enough memory to add address\n");
5601 return NULL;
5602 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005603 addr->type = QETH_IP_TYPE_NORMAL;
5604 addr->proto = prot;
5605 return addr;
5606}
5607
Ursula Braun500f83a2005-09-30 10:19:19 +02005608int
5609qeth_osn_assist(struct net_device *dev,
5610 void *data,
5611 int data_len)
5612{
5613 struct qeth_cmd_buffer *iob;
5614 struct qeth_card *card;
5615 int rc;
Jeff Garzike82b0f22006-05-26 21:58:38 -04005616
Ursula Braun500f83a2005-09-30 10:19:19 +02005617 QETH_DBF_TEXT(trace, 2, "osnsdmc");
5618 if (!dev)
5619 return -ENODEV;
5620 card = (struct qeth_card *)dev->priv;
5621 if (!card)
5622 return -ENODEV;
5623 if ((card->state != CARD_STATE_UP) &&
5624 (card->state != CARD_STATE_SOFTSETUP))
5625 return -ENODEV;
5626 iob = qeth_wait_for_buffer(&card->write);
5627 memcpy(iob->data+IPA_PDU_HEADER_SIZE, data, data_len);
5628 rc = qeth_osn_send_ipa_cmd(card, iob, data_len);
5629 return rc;
5630}
5631
5632static struct net_device *
5633qeth_netdev_by_devno(unsigned char *read_dev_no)
5634{
5635 struct qeth_card *card;
5636 struct net_device *ndev;
5637 unsigned char *readno;
5638 __u16 temp_dev_no, card_dev_no;
5639 char *endp;
5640 unsigned long flags;
5641
5642 ndev = NULL;
5643 memcpy(&temp_dev_no, read_dev_no, 2);
5644 read_lock_irqsave(&qeth_card_list.rwlock, flags);
5645 list_for_each_entry(card, &qeth_card_list.list, list) {
5646 readno = CARD_RDEV_ID(card);
5647 readno += (strlen(readno) - 4);
5648 card_dev_no = simple_strtoul(readno, &endp, 16);
5649 if (card_dev_no == temp_dev_no) {
5650 ndev = card->dev;
5651 break;
5652 }
5653 }
5654 read_unlock_irqrestore(&qeth_card_list.rwlock, flags);
5655 return ndev;
5656}
5657
5658int
5659qeth_osn_register(unsigned char *read_dev_no,
5660 struct net_device **dev,
5661 int (*assist_cb)(struct net_device *, void *),
5662 int (*data_cb)(struct sk_buff *))
5663{
5664 struct qeth_card * card;
5665
5666 QETH_DBF_TEXT(trace, 2, "osnreg");
5667 *dev = qeth_netdev_by_devno(read_dev_no);
5668 if (*dev == NULL)
5669 return -ENODEV;
5670 card = (struct qeth_card *)(*dev)->priv;
5671 if (!card)
5672 return -ENODEV;
5673 if ((assist_cb == NULL) || (data_cb == NULL))
5674 return -EINVAL;
5675 card->osn_info.assist_cb = assist_cb;
5676 card->osn_info.data_cb = data_cb;
5677 return 0;
5678}
5679
5680void
5681qeth_osn_deregister(struct net_device * dev)
5682{
5683 struct qeth_card *card;
5684
5685 QETH_DBF_TEXT(trace, 2, "osndereg");
5686 if (!dev)
5687 return;
5688 card = (struct qeth_card *)dev->priv;
5689 if (!card)
5690 return;
5691 card->osn_info.assist_cb = NULL;
5692 card->osn_info.data_cb = NULL;
5693 return;
5694}
Jeff Garzike82b0f22006-05-26 21:58:38 -04005695
Linus Torvalds1da177e2005-04-16 15:20:36 -07005696static void
5697qeth_delete_mc_addresses(struct qeth_card *card)
5698{
5699 struct qeth_ipaddr *iptodo;
5700 unsigned long flags;
5701
5702 QETH_DBF_TEXT(trace,4,"delmc");
5703 iptodo = qeth_get_addr_buffer(QETH_PROT_IPV4);
5704 if (!iptodo) {
5705 QETH_DBF_TEXT(trace, 2, "dmcnomem");
5706 return;
5707 }
5708 iptodo->type = QETH_IP_TYPE_DEL_ALL_MC;
5709 spin_lock_irqsave(&card->ip_lock, flags);
5710 if (!__qeth_insert_ip_todo(card, iptodo, 0))
5711 kfree(iptodo);
5712 spin_unlock_irqrestore(&card->ip_lock, flags);
5713}
5714
Heiko Carstens4d284ca2007-02-05 21:18:53 +01005715static void
Linus Torvalds1da177e2005-04-16 15:20:36 -07005716qeth_add_mc(struct qeth_card *card, struct in_device *in4_dev)
5717{
5718 struct qeth_ipaddr *ipm;
5719 struct ip_mc_list *im4;
5720 char buf[MAX_ADDR_LEN];
5721
5722 QETH_DBF_TEXT(trace,4,"addmc");
5723 for (im4 = in4_dev->mc_list; im4; im4 = im4->next) {
5724 qeth_get_mac_for_ipm(im4->multiaddr, buf, in4_dev->dev);
5725 ipm = qeth_get_addr_buffer(QETH_PROT_IPV4);
5726 if (!ipm)
5727 continue;
5728 ipm->u.a4.addr = im4->multiaddr;
5729 memcpy(ipm->mac,buf,OSA_ADDR_LEN);
5730 ipm->is_multicast = 1;
5731 if (!qeth_add_ip(card,ipm))
5732 kfree(ipm);
5733 }
5734}
5735
5736static inline void
5737qeth_add_vlan_mc(struct qeth_card *card)
5738{
5739#ifdef CONFIG_QETH_VLAN
5740 struct in_device *in_dev;
5741 struct vlan_group *vg;
5742 int i;
5743
5744 QETH_DBF_TEXT(trace,4,"addmcvl");
5745 if ( ((card->options.layer2 == 0) &&
5746 (!qeth_is_supported(card,IPA_FULL_VLAN))) ||
5747 (card->vlangrp == NULL) )
5748 return ;
5749
5750 vg = card->vlangrp;
5751 for (i = 0; i < VLAN_GROUP_ARRAY_LEN; i++) {
Dan Aloni5c15bde2007-03-02 20:44:51 -08005752 struct net_device *netdev = vlan_group_get_device(vg, i);
5753 if (netdev == NULL ||
5754 !(netdev->flags & IFF_UP))
Linus Torvalds1da177e2005-04-16 15:20:36 -07005755 continue;
Dan Aloni5c15bde2007-03-02 20:44:51 -08005756 in_dev = in_dev_get(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005757 if (!in_dev)
5758 continue;
5759 read_lock(&in_dev->mc_list_lock);
5760 qeth_add_mc(card,in_dev);
5761 read_unlock(&in_dev->mc_list_lock);
5762 in_dev_put(in_dev);
5763 }
5764#endif
5765}
5766
5767static void
5768qeth_add_multicast_ipv4(struct qeth_card *card)
5769{
5770 struct in_device *in4_dev;
5771
5772 QETH_DBF_TEXT(trace,4,"chkmcv4");
5773 in4_dev = in_dev_get(card->dev);
5774 if (in4_dev == NULL)
5775 return;
5776 read_lock(&in4_dev->mc_list_lock);
5777 qeth_add_mc(card, in4_dev);
5778 qeth_add_vlan_mc(card);
5779 read_unlock(&in4_dev->mc_list_lock);
5780 in_dev_put(in4_dev);
5781}
5782
Frank Pavlic6c88ad22005-11-10 13:49:28 +01005783static void
5784qeth_layer2_add_multicast(struct qeth_card *card)
5785{
5786 struct qeth_ipaddr *ipm;
5787 struct dev_mc_list *dm;
5788
5789 QETH_DBF_TEXT(trace,4,"L2addmc");
5790 for (dm = card->dev->mc_list; dm; dm = dm->next) {
5791 ipm = qeth_get_addr_buffer(QETH_PROT_IPV4);
5792 if (!ipm)
5793 continue;
5794 memcpy(ipm->mac,dm->dmi_addr,MAX_ADDR_LEN);
5795 ipm->is_multicast = 1;
5796 if (!qeth_add_ip(card, ipm))
5797 kfree(ipm);
5798 }
5799}
5800
Linus Torvalds1da177e2005-04-16 15:20:36 -07005801#ifdef CONFIG_QETH_IPV6
Heiko Carstens4d284ca2007-02-05 21:18:53 +01005802static void
Linus Torvalds1da177e2005-04-16 15:20:36 -07005803qeth_add_mc6(struct qeth_card *card, struct inet6_dev *in6_dev)
5804{
5805 struct qeth_ipaddr *ipm;
5806 struct ifmcaddr6 *im6;
5807 char buf[MAX_ADDR_LEN];
5808
5809 QETH_DBF_TEXT(trace,4,"addmc6");
5810 for (im6 = in6_dev->mc_list; im6 != NULL; im6 = im6->next) {
5811 ndisc_mc_map(&im6->mca_addr, buf, in6_dev->dev, 0);
5812 ipm = qeth_get_addr_buffer(QETH_PROT_IPV6);
5813 if (!ipm)
5814 continue;
5815 ipm->is_multicast = 1;
5816 memcpy(ipm->mac,buf,OSA_ADDR_LEN);
5817 memcpy(&ipm->u.a6.addr,&im6->mca_addr.s6_addr,
5818 sizeof(struct in6_addr));
5819 if (!qeth_add_ip(card,ipm))
5820 kfree(ipm);
5821 }
5822}
5823
5824static inline void
5825qeth_add_vlan_mc6(struct qeth_card *card)
5826{
5827#ifdef CONFIG_QETH_VLAN
5828 struct inet6_dev *in_dev;
5829 struct vlan_group *vg;
5830 int i;
5831
5832 QETH_DBF_TEXT(trace,4,"admc6vl");
5833 if ( ((card->options.layer2 == 0) &&
5834 (!qeth_is_supported(card,IPA_FULL_VLAN))) ||
5835 (card->vlangrp == NULL))
5836 return ;
5837
5838 vg = card->vlangrp;
5839 for (i = 0; i < VLAN_GROUP_ARRAY_LEN; i++) {
Dan Aloni5c15bde2007-03-02 20:44:51 -08005840 struct net_device *netdev = vlan_group_get_device(vg, i);
5841 if (netdev == NULL ||
5842 !(netdev->flags & IFF_UP))
Linus Torvalds1da177e2005-04-16 15:20:36 -07005843 continue;
Dan Aloni5c15bde2007-03-02 20:44:51 -08005844 in_dev = in6_dev_get(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005845 if (!in_dev)
5846 continue;
Ursula Braunadd3f2f2007-06-20 12:58:02 +02005847 read_lock_bh(&in_dev->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005848 qeth_add_mc6(card,in_dev);
Ursula Braunadd3f2f2007-06-20 12:58:02 +02005849 read_unlock_bh(&in_dev->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005850 in6_dev_put(in_dev);
5851 }
5852#endif /* CONFIG_QETH_VLAN */
5853}
5854
5855static void
5856qeth_add_multicast_ipv6(struct qeth_card *card)
5857{
5858 struct inet6_dev *in6_dev;
5859
5860 QETH_DBF_TEXT(trace,4,"chkmcv6");
Jeff Garzike82b0f22006-05-26 21:58:38 -04005861 if (!qeth_is_supported(card, IPA_IPV6))
Linus Torvalds1da177e2005-04-16 15:20:36 -07005862 return ;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005863 in6_dev = in6_dev_get(card->dev);
5864 if (in6_dev == NULL)
5865 return;
Ursula Braunadd3f2f2007-06-20 12:58:02 +02005866 read_lock_bh(&in6_dev->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005867 qeth_add_mc6(card, in6_dev);
5868 qeth_add_vlan_mc6(card);
Ursula Braunadd3f2f2007-06-20 12:58:02 +02005869 read_unlock_bh(&in6_dev->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005870 in6_dev_put(in6_dev);
5871}
5872#endif /* CONFIG_QETH_IPV6 */
5873
5874static int
5875qeth_layer2_send_setdelmac(struct qeth_card *card, __u8 *mac,
5876 enum qeth_ipa_cmds ipacmd,
5877 int (*reply_cb) (struct qeth_card *,
5878 struct qeth_reply*,
5879 unsigned long))
5880{
5881 struct qeth_ipa_cmd *cmd;
5882 struct qeth_cmd_buffer *iob;
5883
5884 QETH_DBF_TEXT(trace, 2, "L2sdmac");
5885 iob = qeth_get_ipacmd_buffer(card, ipacmd, QETH_PROT_IPV4);
5886 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
5887 cmd->data.setdelmac.mac_length = OSA_ADDR_LEN;
5888 memcpy(&cmd->data.setdelmac.mac, mac, OSA_ADDR_LEN);
5889 return qeth_send_ipa_cmd(card, iob, reply_cb, NULL);
5890}
5891
5892static int
5893qeth_layer2_send_setgroupmac_cb(struct qeth_card *card,
5894 struct qeth_reply *reply,
5895 unsigned long data)
5896{
5897 struct qeth_ipa_cmd *cmd;
5898 __u8 *mac;
5899
5900 QETH_DBF_TEXT(trace, 2, "L2Sgmacb");
5901 cmd = (struct qeth_ipa_cmd *) data;
5902 mac = &cmd->data.setdelmac.mac[0];
5903 /* MAC already registered, needed in couple/uncouple case */
5904 if (cmd->hdr.return_code == 0x2005) {
5905 PRINT_WARN("Group MAC %02x:%02x:%02x:%02x:%02x:%02x " \
5906 "already existing on %s \n",
5907 mac[0], mac[1], mac[2], mac[3], mac[4], mac[5],
5908 QETH_CARD_IFNAME(card));
5909 cmd->hdr.return_code = 0;
5910 }
5911 if (cmd->hdr.return_code)
5912 PRINT_ERR("Could not set group MAC " \
5913 "%02x:%02x:%02x:%02x:%02x:%02x on %s: %x\n",
5914 mac[0], mac[1], mac[2], mac[3], mac[4], mac[5],
5915 QETH_CARD_IFNAME(card),cmd->hdr.return_code);
5916 return 0;
5917}
5918
5919static int
5920qeth_layer2_send_setgroupmac(struct qeth_card *card, __u8 *mac)
5921{
5922 QETH_DBF_TEXT(trace, 2, "L2Sgmac");
5923 return qeth_layer2_send_setdelmac(card, mac, IPA_CMD_SETGMAC,
5924 qeth_layer2_send_setgroupmac_cb);
5925}
5926
5927static int
5928qeth_layer2_send_delgroupmac_cb(struct qeth_card *card,
5929 struct qeth_reply *reply,
5930 unsigned long data)
5931{
5932 struct qeth_ipa_cmd *cmd;
5933 __u8 *mac;
5934
5935 QETH_DBF_TEXT(trace, 2, "L2Dgmacb");
5936 cmd = (struct qeth_ipa_cmd *) data;
5937 mac = &cmd->data.setdelmac.mac[0];
5938 if (cmd->hdr.return_code)
5939 PRINT_ERR("Could not delete group MAC " \
5940 "%02x:%02x:%02x:%02x:%02x:%02x on %s: %x\n",
5941 mac[0], mac[1], mac[2], mac[3], mac[4], mac[5],
5942 QETH_CARD_IFNAME(card), cmd->hdr.return_code);
5943 return 0;
5944}
5945
5946static int
5947qeth_layer2_send_delgroupmac(struct qeth_card *card, __u8 *mac)
5948{
5949 QETH_DBF_TEXT(trace, 2, "L2Dgmac");
5950 return qeth_layer2_send_setdelmac(card, mac, IPA_CMD_DELGMAC,
5951 qeth_layer2_send_delgroupmac_cb);
5952}
5953
5954static int
5955qeth_layer2_send_setmac_cb(struct qeth_card *card,
5956 struct qeth_reply *reply,
5957 unsigned long data)
5958{
5959 struct qeth_ipa_cmd *cmd;
5960
5961 QETH_DBF_TEXT(trace, 2, "L2Smaccb");
5962 cmd = (struct qeth_ipa_cmd *) data;
5963 if (cmd->hdr.return_code) {
5964 QETH_DBF_TEXT_(trace, 2, "L2er%x", cmd->hdr.return_code);
Frank Pavlice08d88c2005-11-10 13:51:17 +01005965 card->info.mac_bits &= ~QETH_LAYER2_MAC_REGISTERED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005966 cmd->hdr.return_code = -EIO;
5967 } else {
Frank Pavlice08d88c2005-11-10 13:51:17 +01005968 card->info.mac_bits |= QETH_LAYER2_MAC_REGISTERED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005969 memcpy(card->dev->dev_addr,cmd->data.setdelmac.mac,
5970 OSA_ADDR_LEN);
5971 PRINT_INFO("MAC address %2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x "
5972 "successfully registered on device %s\n",
5973 card->dev->dev_addr[0], card->dev->dev_addr[1],
5974 card->dev->dev_addr[2], card->dev->dev_addr[3],
5975 card->dev->dev_addr[4], card->dev->dev_addr[5],
5976 card->dev->name);
5977 }
5978 return 0;
5979}
5980
5981static int
5982qeth_layer2_send_setmac(struct qeth_card *card, __u8 *mac)
5983{
5984 QETH_DBF_TEXT(trace, 2, "L2Setmac");
5985 return qeth_layer2_send_setdelmac(card, mac, IPA_CMD_SETVMAC,
5986 qeth_layer2_send_setmac_cb);
5987}
5988
5989static int
5990qeth_layer2_send_delmac_cb(struct qeth_card *card,
5991 struct qeth_reply *reply,
5992 unsigned long data)
5993{
5994 struct qeth_ipa_cmd *cmd;
5995
5996 QETH_DBF_TEXT(trace, 2, "L2Dmaccb");
5997 cmd = (struct qeth_ipa_cmd *) data;
5998 if (cmd->hdr.return_code) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005999 QETH_DBF_TEXT_(trace, 2, "err%d", cmd->hdr.return_code);
6000 cmd->hdr.return_code = -EIO;
6001 return 0;
6002 }
Frank Pavlice08d88c2005-11-10 13:51:17 +01006003 card->info.mac_bits &= ~QETH_LAYER2_MAC_REGISTERED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006004
6005 return 0;
6006}
6007static int
6008qeth_layer2_send_delmac(struct qeth_card *card, __u8 *mac)
6009{
6010 QETH_DBF_TEXT(trace, 2, "L2Delmac");
Frank Pavlice08d88c2005-11-10 13:51:17 +01006011 if (!(card->info.mac_bits & QETH_LAYER2_MAC_REGISTERED))
Linus Torvalds1da177e2005-04-16 15:20:36 -07006012 return 0;
6013 return qeth_layer2_send_setdelmac(card, mac, IPA_CMD_DELVMAC,
6014 qeth_layer2_send_delmac_cb);
6015}
6016
6017static int
6018qeth_layer2_set_mac_address(struct net_device *dev, void *p)
6019{
6020 struct sockaddr *addr = p;
6021 struct qeth_card *card;
6022 int rc = 0;
6023
6024 QETH_DBF_TEXT(trace, 3, "setmac");
6025
6026 if (qeth_verify_dev(dev) != QETH_REAL_CARD) {
6027 QETH_DBF_TEXT(trace, 3, "setmcINV");
6028 return -EOPNOTSUPP;
6029 }
6030 card = (struct qeth_card *) dev->priv;
6031
6032 if (!card->options.layer2) {
Frank Pavlice08d88c2005-11-10 13:51:17 +01006033 PRINT_WARN("Setting MAC address on %s is not supported "
Linus Torvalds1da177e2005-04-16 15:20:36 -07006034 "in Layer 3 mode.\n", dev->name);
6035 QETH_DBF_TEXT(trace, 3, "setmcLY3");
6036 return -EOPNOTSUPP;
6037 }
Ursula Braun500f83a2005-09-30 10:19:19 +02006038 if (card->info.type == QETH_CARD_TYPE_OSN) {
6039 PRINT_WARN("Setting MAC address on %s is not supported.\n",
6040 dev->name);
6041 QETH_DBF_TEXT(trace, 3, "setmcOSN");
6042 return -EOPNOTSUPP;
6043 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07006044 QETH_DBF_TEXT_(trace, 3, "%s", CARD_BUS_ID(card));
6045 QETH_DBF_HEX(trace, 3, addr->sa_data, OSA_ADDR_LEN);
6046 rc = qeth_layer2_send_delmac(card, &card->dev->dev_addr[0]);
6047 if (!rc)
6048 rc = qeth_layer2_send_setmac(card, addr->sa_data);
6049 return rc;
6050}
6051
6052static void
6053qeth_fill_ipacmd_header(struct qeth_card *card, struct qeth_ipa_cmd *cmd,
6054 __u8 command, enum qeth_prot_versions prot)
6055{
6056 memset(cmd, 0, sizeof (struct qeth_ipa_cmd));
6057 cmd->hdr.command = command;
6058 cmd->hdr.initiator = IPA_CMD_INITIATOR_HOST;
6059 cmd->hdr.seqno = card->seqno.ipa;
6060 cmd->hdr.adapter_type = qeth_get_ipa_adp_type(card->info.link_type);
6061 cmd->hdr.rel_adapter_no = (__u8) card->info.portno;
6062 if (card->options.layer2)
6063 cmd->hdr.prim_version_no = 2;
6064 else
6065 cmd->hdr.prim_version_no = 1;
6066 cmd->hdr.param_count = 1;
6067 cmd->hdr.prot_version = prot;
6068 cmd->hdr.ipa_supported = 0;
6069 cmd->hdr.ipa_enabled = 0;
6070}
6071
6072static struct qeth_cmd_buffer *
6073qeth_get_ipacmd_buffer(struct qeth_card *card, enum qeth_ipa_cmds ipacmd,
6074 enum qeth_prot_versions prot)
6075{
6076 struct qeth_cmd_buffer *iob;
6077 struct qeth_ipa_cmd *cmd;
6078
6079 iob = qeth_wait_for_buffer(&card->write);
6080 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
6081 qeth_fill_ipacmd_header(card, cmd, ipacmd, prot);
6082
6083 return iob;
6084}
6085
6086static int
6087qeth_send_setdelmc(struct qeth_card *card, struct qeth_ipaddr *addr, int ipacmd)
6088{
6089 int rc;
6090 struct qeth_cmd_buffer *iob;
6091 struct qeth_ipa_cmd *cmd;
6092
6093 QETH_DBF_TEXT(trace,4,"setdelmc");
6094
6095 iob = qeth_get_ipacmd_buffer(card, ipacmd, addr->proto);
6096 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
6097 memcpy(&cmd->data.setdelipm.mac,addr->mac, OSA_ADDR_LEN);
6098 if (addr->proto == QETH_PROT_IPV6)
6099 memcpy(cmd->data.setdelipm.ip6, &addr->u.a6.addr,
6100 sizeof(struct in6_addr));
6101 else
6102 memcpy(&cmd->data.setdelipm.ip4, &addr->u.a4.addr,4);
6103
6104 rc = qeth_send_ipa_cmd(card, iob, NULL, NULL);
6105
6106 return rc;
6107}
Heiko Carstens4d284ca2007-02-05 21:18:53 +01006108static void
Linus Torvalds1da177e2005-04-16 15:20:36 -07006109qeth_fill_netmask(u8 *netmask, unsigned int len)
6110{
6111 int i,j;
6112 for (i=0;i<16;i++) {
6113 j=(len)-(i*8);
6114 if (j >= 8)
6115 netmask[i] = 0xff;
6116 else if (j > 0)
6117 netmask[i] = (u8)(0xFF00>>j);
6118 else
6119 netmask[i] = 0;
6120 }
6121}
6122
6123static int
6124qeth_send_setdelip(struct qeth_card *card, struct qeth_ipaddr *addr,
6125 int ipacmd, unsigned int flags)
6126{
6127 int rc;
6128 struct qeth_cmd_buffer *iob;
6129 struct qeth_ipa_cmd *cmd;
6130 __u8 netmask[16];
6131
6132 QETH_DBF_TEXT(trace,4,"setdelip");
6133 QETH_DBF_TEXT_(trace,4,"flags%02X", flags);
6134
6135 iob = qeth_get_ipacmd_buffer(card, ipacmd, addr->proto);
6136 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
6137 if (addr->proto == QETH_PROT_IPV6) {
6138 memcpy(cmd->data.setdelip6.ip_addr, &addr->u.a6.addr,
6139 sizeof(struct in6_addr));
6140 qeth_fill_netmask(netmask,addr->u.a6.pfxlen);
6141 memcpy(cmd->data.setdelip6.mask, netmask,
6142 sizeof(struct in6_addr));
6143 cmd->data.setdelip6.flags = flags;
6144 } else {
6145 memcpy(cmd->data.setdelip4.ip_addr, &addr->u.a4.addr, 4);
6146 memcpy(cmd->data.setdelip4.mask, &addr->u.a4.mask, 4);
6147 cmd->data.setdelip4.flags = flags;
6148 }
6149
6150 rc = qeth_send_ipa_cmd(card, iob, NULL, NULL);
6151
6152 return rc;
6153}
6154
6155static int
6156qeth_layer2_register_addr_entry(struct qeth_card *card,
6157 struct qeth_ipaddr *addr)
6158{
6159 if (!addr->is_multicast)
6160 return 0;
6161 QETH_DBF_TEXT(trace, 2, "setgmac");
6162 QETH_DBF_HEX(trace,3,&addr->mac[0],OSA_ADDR_LEN);
6163 return qeth_layer2_send_setgroupmac(card, &addr->mac[0]);
6164}
6165
6166static int
6167qeth_layer2_deregister_addr_entry(struct qeth_card *card,
6168 struct qeth_ipaddr *addr)
6169{
6170 if (!addr->is_multicast)
6171 return 0;
6172 QETH_DBF_TEXT(trace, 2, "delgmac");
6173 QETH_DBF_HEX(trace,3,&addr->mac[0],OSA_ADDR_LEN);
6174 return qeth_layer2_send_delgroupmac(card, &addr->mac[0]);
6175}
6176
6177static int
6178qeth_layer3_register_addr_entry(struct qeth_card *card,
6179 struct qeth_ipaddr *addr)
6180{
6181 char buf[50];
6182 int rc;
6183 int cnt = 3;
6184
6185 if (addr->proto == QETH_PROT_IPV4) {
6186 QETH_DBF_TEXT(trace, 2,"setaddr4");
6187 QETH_DBF_HEX(trace, 3, &addr->u.a4.addr, sizeof(int));
6188 } else if (addr->proto == QETH_PROT_IPV6) {
6189 QETH_DBF_TEXT(trace, 2, "setaddr6");
6190 QETH_DBF_HEX(trace,3,&addr->u.a6.addr,8);
6191 QETH_DBF_HEX(trace,3,((char *)&addr->u.a6.addr)+8,8);
6192 } else {
6193 QETH_DBF_TEXT(trace, 2, "setaddr?");
6194 QETH_DBF_HEX(trace, 3, addr, sizeof(struct qeth_ipaddr));
6195 }
6196 do {
6197 if (addr->is_multicast)
6198 rc = qeth_send_setdelmc(card, addr, IPA_CMD_SETIPM);
6199 else
6200 rc = qeth_send_setdelip(card, addr, IPA_CMD_SETIP,
6201 addr->set_flags);
6202 if (rc)
6203 QETH_DBF_TEXT(trace, 2, "failed");
6204 } while ((--cnt > 0) && rc);
6205 if (rc){
6206 QETH_DBF_TEXT(trace, 2, "FAILED");
6207 qeth_ipaddr_to_string(addr->proto, (u8 *)&addr->u, buf);
6208 PRINT_WARN("Could not register IP address %s (rc=0x%x/%d)\n",
6209 buf, rc, rc);
6210 }
6211 return rc;
6212}
6213
6214static int
6215qeth_layer3_deregister_addr_entry(struct qeth_card *card,
6216 struct qeth_ipaddr *addr)
6217{
6218 //char buf[50];
6219 int rc;
6220
6221 if (addr->proto == QETH_PROT_IPV4) {
6222 QETH_DBF_TEXT(trace, 2,"deladdr4");
6223 QETH_DBF_HEX(trace, 3, &addr->u.a4.addr, sizeof(int));
6224 } else if (addr->proto == QETH_PROT_IPV6) {
6225 QETH_DBF_TEXT(trace, 2, "deladdr6");
6226 QETH_DBF_HEX(trace,3,&addr->u.a6.addr,8);
6227 QETH_DBF_HEX(trace,3,((char *)&addr->u.a6.addr)+8,8);
6228 } else {
6229 QETH_DBF_TEXT(trace, 2, "deladdr?");
6230 QETH_DBF_HEX(trace, 3, addr, sizeof(struct qeth_ipaddr));
6231 }
6232 if (addr->is_multicast)
6233 rc = qeth_send_setdelmc(card, addr, IPA_CMD_DELIPM);
6234 else
6235 rc = qeth_send_setdelip(card, addr, IPA_CMD_DELIP,
6236 addr->del_flags);
6237 if (rc) {
6238 QETH_DBF_TEXT(trace, 2, "failed");
6239 /* TODO: re-activate this warning as soon as we have a
6240 * clean mirco code
6241 qeth_ipaddr_to_string(addr->proto, (u8 *)&addr->u, buf);
6242 PRINT_WARN("Could not deregister IP address %s (rc=%x)\n",
6243 buf, rc);
6244 */
6245 }
6246 return rc;
6247}
6248
6249static int
6250qeth_register_addr_entry(struct qeth_card *card, struct qeth_ipaddr *addr)
6251{
6252 if (card->options.layer2)
6253 return qeth_layer2_register_addr_entry(card, addr);
6254
6255 return qeth_layer3_register_addr_entry(card, addr);
6256}
6257
6258static int
6259qeth_deregister_addr_entry(struct qeth_card *card, struct qeth_ipaddr *addr)
6260{
6261 if (card->options.layer2)
6262 return qeth_layer2_deregister_addr_entry(card, addr);
6263
6264 return qeth_layer3_deregister_addr_entry(card, addr);
6265}
6266
6267static u32
6268qeth_ethtool_get_tx_csum(struct net_device *dev)
6269{
6270 /* We may need to say that we support tx csum offload if
6271 * we do EDDP or TSO. There are discussions going on to
6272 * enforce rules in the stack and in ethtool that make
6273 * SG and TSO depend on HW_CSUM. At the moment there are
6274 * no such rules....
6275 * If we say yes here, we have to checksum outbound packets
6276 * any time. */
6277 return 0;
6278}
6279
6280static int
6281qeth_ethtool_set_tx_csum(struct net_device *dev, u32 data)
6282{
6283 return -EINVAL;
6284}
6285
6286static u32
6287qeth_ethtool_get_rx_csum(struct net_device *dev)
6288{
6289 struct qeth_card *card = (struct qeth_card *)dev->priv;
6290
6291 return (card->options.checksum_type == HW_CHECKSUMMING);
6292}
6293
6294static int
6295qeth_ethtool_set_rx_csum(struct net_device *dev, u32 data)
6296{
6297 struct qeth_card *card = (struct qeth_card *)dev->priv;
6298
6299 if ((card->state != CARD_STATE_DOWN) &&
6300 (card->state != CARD_STATE_RECOVER))
6301 return -EPERM;
6302 if (data)
6303 card->options.checksum_type = HW_CHECKSUMMING;
6304 else
6305 card->options.checksum_type = SW_CHECKSUMMING;
6306 return 0;
6307}
6308
6309static u32
6310qeth_ethtool_get_sg(struct net_device *dev)
6311{
6312 struct qeth_card *card = (struct qeth_card *)dev->priv;
6313
6314 return ((card->options.large_send != QETH_LARGE_SEND_NO) &&
6315 (dev->features & NETIF_F_SG));
6316}
6317
6318static int
6319qeth_ethtool_set_sg(struct net_device *dev, u32 data)
6320{
6321 struct qeth_card *card = (struct qeth_card *)dev->priv;
6322
6323 if (data) {
6324 if (card->options.large_send != QETH_LARGE_SEND_NO)
6325 dev->features |= NETIF_F_SG;
6326 else {
6327 dev->features &= ~NETIF_F_SG;
6328 return -EINVAL;
6329 }
6330 } else
6331 dev->features &= ~NETIF_F_SG;
6332 return 0;
6333}
6334
6335static u32
6336qeth_ethtool_get_tso(struct net_device *dev)
6337{
6338 struct qeth_card *card = (struct qeth_card *)dev->priv;
6339
6340 return ((card->options.large_send != QETH_LARGE_SEND_NO) &&
6341 (dev->features & NETIF_F_TSO));
6342}
6343
6344static int
6345qeth_ethtool_set_tso(struct net_device *dev, u32 data)
6346{
6347 struct qeth_card *card = (struct qeth_card *)dev->priv;
6348
6349 if (data) {
6350 if (card->options.large_send != QETH_LARGE_SEND_NO)
6351 dev->features |= NETIF_F_TSO;
6352 else {
6353 dev->features &= ~NETIF_F_TSO;
6354 return -EINVAL;
6355 }
6356 } else
6357 dev->features &= ~NETIF_F_TSO;
6358 return 0;
6359}
6360
6361static struct ethtool_ops qeth_ethtool_ops = {
6362 .get_tx_csum = qeth_ethtool_get_tx_csum,
6363 .set_tx_csum = qeth_ethtool_set_tx_csum,
6364 .get_rx_csum = qeth_ethtool_get_rx_csum,
6365 .set_rx_csum = qeth_ethtool_set_rx_csum,
6366 .get_sg = qeth_ethtool_get_sg,
6367 .set_sg = qeth_ethtool_set_sg,
6368 .get_tso = qeth_ethtool_get_tso,
6369 .set_tso = qeth_ethtool_set_tso,
6370};
6371
6372static int
Frank Blaschka2d36c162007-01-08 17:29:58 +01006373qeth_hard_header_parse(struct sk_buff *skb, unsigned char *haddr)
6374{
6375 struct qeth_card *card;
6376 struct ethhdr *eth;
6377
6378 card = qeth_get_card_from_dev(skb->dev);
6379 if (card->options.layer2)
6380 goto haveheader;
6381#ifdef CONFIG_QETH_IPV6
6382 /* cause of the manipulated arp constructor and the ARP
6383 flag for OSAE devices we have some nasty exceptions */
6384 if (card->info.type == QETH_CARD_TYPE_OSAE) {
6385 if (!card->options.fake_ll) {
6386 if ((skb->pkt_type==PACKET_OUTGOING) &&
6387 (skb->protocol==ETH_P_IPV6))
6388 goto haveheader;
6389 else
6390 return 0;
6391 } else {
6392 if ((skb->pkt_type==PACKET_OUTGOING) &&
6393 (skb->protocol==ETH_P_IP))
6394 return 0;
6395 else
6396 goto haveheader;
6397 }
6398 }
6399#endif
6400 if (!card->options.fake_ll)
6401 return 0;
6402haveheader:
6403 eth = eth_hdr(skb);
6404 memcpy(haddr, eth->h_source, ETH_ALEN);
6405 return ETH_ALEN;
6406}
6407
6408static int
Linus Torvalds1da177e2005-04-16 15:20:36 -07006409qeth_netdev_init(struct net_device *dev)
6410{
6411 struct qeth_card *card;
6412
6413 card = (struct qeth_card *) dev->priv;
6414
6415 QETH_DBF_TEXT(trace,3,"initdev");
6416
6417 dev->tx_timeout = &qeth_tx_timeout;
6418 dev->watchdog_timeo = QETH_TX_TIMEOUT;
6419 dev->open = qeth_open;
6420 dev->stop = qeth_stop;
6421 dev->hard_start_xmit = qeth_hard_start_xmit;
6422 dev->do_ioctl = qeth_do_ioctl;
6423 dev->get_stats = qeth_get_stats;
6424 dev->change_mtu = qeth_change_mtu;
6425 dev->neigh_setup = qeth_neigh_setup;
6426 dev->set_multicast_list = qeth_set_multicast_list;
6427#ifdef CONFIG_QETH_VLAN
6428 dev->vlan_rx_register = qeth_vlan_rx_register;
6429 dev->vlan_rx_kill_vid = qeth_vlan_rx_kill_vid;
6430 dev->vlan_rx_add_vid = qeth_vlan_rx_add_vid;
6431#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07006432 if (qeth_get_netdev_flags(card) & IFF_NOARP) {
6433 dev->rebuild_header = NULL;
6434 dev->hard_header = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006435 dev->header_cache_update = NULL;
6436 dev->hard_header_cache = NULL;
6437 }
6438#ifdef CONFIG_QETH_IPV6
6439 /*IPv6 address autoconfiguration stuff*/
6440 if (!(card->info.unique_id & UNIQUE_ID_NOT_BY_CARD))
6441 card->dev->dev_id = card->info.unique_id & 0xffff;
6442#endif
Jeff Garzike82b0f22006-05-26 21:58:38 -04006443 if (card->options.fake_ll &&
Ursula Braunba1aa082006-05-24 09:51:13 +02006444 (qeth_get_netdev_flags(card) & IFF_NOARP))
6445 dev->hard_header = qeth_fake_header;
Frank Blaschka2d36c162007-01-08 17:29:58 +01006446 if (dev->type == ARPHRD_IEEE802_TR)
6447 dev->hard_header_parse = NULL;
6448 else
6449 dev->hard_header_parse = qeth_hard_header_parse;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006450 dev->set_mac_address = qeth_layer2_set_mac_address;
6451 dev->flags |= qeth_get_netdev_flags(card);
6452 if ((card->options.fake_broadcast) ||
6453 (card->info.broadcast_capable))
6454 dev->flags |= IFF_BROADCAST;
6455 dev->hard_header_len =
6456 qeth_get_hlen(card->info.link_type) + card->options.add_hhlen;
6457 dev->addr_len = OSA_ADDR_LEN;
6458 dev->mtu = card->info.initial_mtu;
Ursula Braun500f83a2005-09-30 10:19:19 +02006459 if (card->info.type != QETH_CARD_TYPE_OSN)
6460 SET_ETHTOOL_OPS(dev, &qeth_ethtool_ops);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006461 SET_MODULE_OWNER(dev);
6462 return 0;
6463}
6464
6465static void
6466qeth_init_func_level(struct qeth_card *card)
6467{
6468 if (card->ipato.enabled) {
6469 if (card->info.type == QETH_CARD_TYPE_IQD)
6470 card->info.func_level =
6471 QETH_IDX_FUNC_LEVEL_IQD_ENA_IPAT;
6472 else
6473 card->info.func_level =
6474 QETH_IDX_FUNC_LEVEL_OSAE_ENA_IPAT;
6475 } else {
6476 if (card->info.type == QETH_CARD_TYPE_IQD)
Ursula Braun500f83a2005-09-30 10:19:19 +02006477 /*FIXME:why do we have same values for dis and ena for osae??? */
Linus Torvalds1da177e2005-04-16 15:20:36 -07006478 card->info.func_level =
6479 QETH_IDX_FUNC_LEVEL_IQD_DIS_IPAT;
6480 else
6481 card->info.func_level =
6482 QETH_IDX_FUNC_LEVEL_OSAE_DIS_IPAT;
6483 }
6484}
6485
6486/**
6487 * hardsetup card, initialize MPC and QDIO stuff
6488 */
6489static int
6490qeth_hardsetup_card(struct qeth_card *card)
6491{
6492 int retries = 3;
6493 int rc;
6494
6495 QETH_DBF_TEXT(setup, 2, "hrdsetup");
6496
6497retry:
6498 if (retries < 3){
6499 PRINT_WARN("Retrying to do IDX activates.\n");
6500 ccw_device_set_offline(CARD_DDEV(card));
6501 ccw_device_set_offline(CARD_WDEV(card));
6502 ccw_device_set_offline(CARD_RDEV(card));
6503 ccw_device_set_online(CARD_RDEV(card));
6504 ccw_device_set_online(CARD_WDEV(card));
6505 ccw_device_set_online(CARD_DDEV(card));
6506 }
Ursula Braun500f83a2005-09-30 10:19:19 +02006507 rc = qeth_qdio_clear_card(card,card->info.type!=QETH_CARD_TYPE_IQD);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006508 if (rc == -ERESTARTSYS) {
6509 QETH_DBF_TEXT(setup, 2, "break1");
6510 return rc;
6511 } else if (rc) {
6512 QETH_DBF_TEXT_(setup, 2, "1err%d", rc);
6513 if (--retries < 0)
6514 goto out;
6515 else
6516 goto retry;
6517 }
6518 if ((rc = qeth_get_unitaddr(card))){
6519 QETH_DBF_TEXT_(setup, 2, "2err%d", rc);
6520 return rc;
6521 }
6522 qeth_init_tokens(card);
6523 qeth_init_func_level(card);
6524 rc = qeth_idx_activate_channel(&card->read, qeth_idx_read_cb);
6525 if (rc == -ERESTARTSYS) {
6526 QETH_DBF_TEXT(setup, 2, "break2");
6527 return rc;
6528 } else if (rc) {
6529 QETH_DBF_TEXT_(setup, 2, "3err%d", rc);
6530 if (--retries < 0)
6531 goto out;
6532 else
6533 goto retry;
6534 }
6535 rc = qeth_idx_activate_channel(&card->write, qeth_idx_write_cb);
6536 if (rc == -ERESTARTSYS) {
6537 QETH_DBF_TEXT(setup, 2, "break3");
6538 return rc;
6539 } else if (rc) {
6540 QETH_DBF_TEXT_(setup, 2, "4err%d", rc);
6541 if (--retries < 0)
6542 goto out;
6543 else
6544 goto retry;
6545 }
6546 if ((rc = qeth_mpc_initialize(card))){
6547 QETH_DBF_TEXT_(setup, 2, "5err%d", rc);
6548 goto out;
6549 }
6550 /*network device will be recovered*/
6551 if (card->dev) {
6552 card->dev->hard_header = card->orig_hard_header;
Jeff Garzike82b0f22006-05-26 21:58:38 -04006553 if (card->options.fake_ll &&
Ursula Braunb85e1fa2006-05-24 09:51:11 +02006554 (qeth_get_netdev_flags(card) & IFF_NOARP))
6555 card->dev->hard_header = qeth_fake_header;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006556 return 0;
6557 }
6558 /* at first set_online allocate netdev */
6559 card->dev = qeth_get_netdevice(card->info.type,
6560 card->info.link_type);
6561 if (!card->dev){
Ursula Braun500f83a2005-09-30 10:19:19 +02006562 qeth_qdio_clear_card(card, card->info.type !=
6563 QETH_CARD_TYPE_IQD);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006564 rc = -ENODEV;
6565 QETH_DBF_TEXT_(setup, 2, "6err%d", rc);
6566 goto out;
6567 }
6568 card->dev->priv = card;
6569 card->orig_hard_header = card->dev->hard_header;
6570 card->dev->type = qeth_get_arphdr_type(card->info.type,
6571 card->info.link_type);
6572 card->dev->init = qeth_netdev_init;
6573 return 0;
6574out:
6575 PRINT_ERR("Initialization in hardsetup failed! rc=%d\n", rc);
6576 return rc;
6577}
6578
6579static int
6580qeth_default_setassparms_cb(struct qeth_card *card, struct qeth_reply *reply,
6581 unsigned long data)
6582{
6583 struct qeth_ipa_cmd *cmd;
6584
6585 QETH_DBF_TEXT(trace,4,"defadpcb");
6586
6587 cmd = (struct qeth_ipa_cmd *) data;
6588 if (cmd->hdr.return_code == 0){
6589 cmd->hdr.return_code = cmd->data.setassparms.hdr.return_code;
6590 if (cmd->hdr.prot_version == QETH_PROT_IPV4)
6591 card->options.ipa4.enabled_funcs = cmd->hdr.ipa_enabled;
6592#ifdef CONFIG_QETH_IPV6
6593 if (cmd->hdr.prot_version == QETH_PROT_IPV6)
6594 card->options.ipa6.enabled_funcs = cmd->hdr.ipa_enabled;
6595#endif
6596 }
6597 if (cmd->data.setassparms.hdr.assist_no == IPA_INBOUND_CHECKSUM &&
6598 cmd->data.setassparms.hdr.command_code == IPA_CMD_ASS_START) {
6599 card->info.csum_mask = cmd->data.setassparms.data.flags_32bit;
6600 QETH_DBF_TEXT_(trace, 3, "csum:%d", card->info.csum_mask);
6601 }
6602 return 0;
6603}
6604
6605static int
6606qeth_default_setadapterparms_cb(struct qeth_card *card,
6607 struct qeth_reply *reply,
6608 unsigned long data)
6609{
6610 struct qeth_ipa_cmd *cmd;
6611
6612 QETH_DBF_TEXT(trace,4,"defadpcb");
6613
6614 cmd = (struct qeth_ipa_cmd *) data;
6615 if (cmd->hdr.return_code == 0)
6616 cmd->hdr.return_code = cmd->data.setadapterparms.hdr.return_code;
6617 return 0;
6618}
6619
Frank Pavlic6c951b92005-11-10 13:51:25 +01006620
6621
Linus Torvalds1da177e2005-04-16 15:20:36 -07006622static int
6623qeth_query_setadapterparms_cb(struct qeth_card *card, struct qeth_reply *reply,
6624 unsigned long data)
6625{
6626 struct qeth_ipa_cmd *cmd;
6627
6628 QETH_DBF_TEXT(trace,3,"quyadpcb");
6629
6630 cmd = (struct qeth_ipa_cmd *) data;
6631 if (cmd->data.setadapterparms.data.query_cmds_supp.lan_type & 0x7f)
6632 card->info.link_type =
6633 cmd->data.setadapterparms.data.query_cmds_supp.lan_type;
6634 card->options.adp.supported_funcs =
6635 cmd->data.setadapterparms.data.query_cmds_supp.supported_cmds;
6636 return qeth_default_setadapterparms_cb(card, reply, (unsigned long)cmd);
6637}
6638
6639static int
6640qeth_query_setadapterparms(struct qeth_card *card)
6641{
6642 int rc;
6643 struct qeth_cmd_buffer *iob;
6644
6645 QETH_DBF_TEXT(trace,3,"queryadp");
6646 iob = qeth_get_adapter_cmd(card, IPA_SETADP_QUERY_COMMANDS_SUPPORTED,
6647 sizeof(struct qeth_ipacmd_setadpparms));
6648 rc = qeth_send_ipa_cmd(card, iob, qeth_query_setadapterparms_cb, NULL);
6649 return rc;
6650}
6651
6652static int
6653qeth_setadpparms_change_macaddr_cb(struct qeth_card *card,
6654 struct qeth_reply *reply,
6655 unsigned long data)
6656{
6657 struct qeth_ipa_cmd *cmd;
6658
6659 QETH_DBF_TEXT(trace,4,"chgmaccb");
6660
6661 cmd = (struct qeth_ipa_cmd *) data;
Ursula Brauna4c48a22007-05-02 15:17:11 +02006662 if (!card->options.layer2 ||
Jeff Garzike82b0f22006-05-26 21:58:38 -04006663 !(card->info.mac_bits & QETH_LAYER2_MAC_READ)) {
Frank Pavlice08d88c2005-11-10 13:51:17 +01006664 memcpy(card->dev->dev_addr,
6665 &cmd->data.setadapterparms.data.change_addr.addr,
6666 OSA_ADDR_LEN);
6667 card->info.mac_bits |= QETH_LAYER2_MAC_READ;
6668 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07006669 qeth_default_setadapterparms_cb(card, reply, (unsigned long) cmd);
6670 return 0;
6671}
6672
6673static int
6674qeth_setadpparms_change_macaddr(struct qeth_card *card)
6675{
6676 int rc;
6677 struct qeth_cmd_buffer *iob;
6678 struct qeth_ipa_cmd *cmd;
6679
6680 QETH_DBF_TEXT(trace,4,"chgmac");
6681
6682 iob = qeth_get_adapter_cmd(card,IPA_SETADP_ALTER_MAC_ADDRESS,
6683 sizeof(struct qeth_ipacmd_setadpparms));
6684 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
6685 cmd->data.setadapterparms.data.change_addr.cmd = CHANGE_ADDR_READ_MAC;
6686 cmd->data.setadapterparms.data.change_addr.addr_size = OSA_ADDR_LEN;
6687 memcpy(&cmd->data.setadapterparms.data.change_addr.addr,
6688 card->dev->dev_addr, OSA_ADDR_LEN);
6689 rc = qeth_send_ipa_cmd(card, iob, qeth_setadpparms_change_macaddr_cb,
6690 NULL);
6691 return rc;
6692}
6693
6694static int
6695qeth_send_setadp_mode(struct qeth_card *card, __u32 command, __u32 mode)
6696{
6697 int rc;
6698 struct qeth_cmd_buffer *iob;
6699 struct qeth_ipa_cmd *cmd;
6700
6701 QETH_DBF_TEXT(trace,4,"adpmode");
6702
6703 iob = qeth_get_adapter_cmd(card, command,
6704 sizeof(struct qeth_ipacmd_setadpparms));
6705 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
6706 cmd->data.setadapterparms.data.mode = mode;
6707 rc = qeth_send_ipa_cmd(card, iob, qeth_default_setadapterparms_cb,
6708 NULL);
6709 return rc;
6710}
6711
Heiko Carstens4d284ca2007-02-05 21:18:53 +01006712static int
Linus Torvalds1da177e2005-04-16 15:20:36 -07006713qeth_setadapter_hstr(struct qeth_card *card)
6714{
6715 int rc;
6716
6717 QETH_DBF_TEXT(trace,4,"adphstr");
6718
6719 if (qeth_adp_supported(card,IPA_SETADP_SET_BROADCAST_MODE)) {
6720 rc = qeth_send_setadp_mode(card, IPA_SETADP_SET_BROADCAST_MODE,
6721 card->options.broadcast_mode);
6722 if (rc)
6723 PRINT_WARN("couldn't set broadcast mode on "
6724 "device %s: x%x\n",
6725 CARD_BUS_ID(card), rc);
6726 rc = qeth_send_setadp_mode(card, IPA_SETADP_ALTER_MAC_ADDRESS,
6727 card->options.macaddr_mode);
6728 if (rc)
6729 PRINT_WARN("couldn't set macaddr mode on "
6730 "device %s: x%x\n", CARD_BUS_ID(card), rc);
6731 return rc;
6732 }
6733 if (card->options.broadcast_mode == QETH_TR_BROADCAST_LOCAL)
6734 PRINT_WARN("set adapter parameters not available "
6735 "to set broadcast mode, using ALLRINGS "
6736 "on device %s:\n", CARD_BUS_ID(card));
6737 if (card->options.macaddr_mode == QETH_TR_MACADDR_CANONICAL)
6738 PRINT_WARN("set adapter parameters not available "
6739 "to set macaddr mode, using NONCANONICAL "
6740 "on device %s:\n", CARD_BUS_ID(card));
6741 return 0;
6742}
6743
6744static int
6745qeth_setadapter_parms(struct qeth_card *card)
6746{
6747 int rc;
6748
6749 QETH_DBF_TEXT(setup, 2, "setadprm");
6750
6751 if (!qeth_is_supported(card, IPA_SETADAPTERPARMS)){
6752 PRINT_WARN("set adapter parameters not supported "
6753 "on device %s.\n",
6754 CARD_BUS_ID(card));
6755 QETH_DBF_TEXT(setup, 2, " notsupp");
6756 return 0;
6757 }
6758 rc = qeth_query_setadapterparms(card);
6759 if (rc) {
6760 PRINT_WARN("couldn't set adapter parameters on device %s: "
6761 "x%x\n", CARD_BUS_ID(card), rc);
6762 return rc;
6763 }
6764 if (qeth_adp_supported(card,IPA_SETADP_ALTER_MAC_ADDRESS)) {
6765 rc = qeth_setadpparms_change_macaddr(card);
6766 if (rc)
6767 PRINT_WARN("couldn't get MAC address on "
6768 "device %s: x%x\n",
6769 CARD_BUS_ID(card), rc);
6770 }
6771
6772 if ((card->info.link_type == QETH_LINK_TYPE_HSTR) ||
6773 (card->info.link_type == QETH_LINK_TYPE_LANE_TR))
6774 rc = qeth_setadapter_hstr(card);
6775
6776 return rc;
6777}
6778
6779static int
6780qeth_layer2_initialize(struct qeth_card *card)
6781{
6782 int rc = 0;
6783
6784
6785 QETH_DBF_TEXT(setup, 2, "doL2init");
6786 QETH_DBF_TEXT_(setup, 2, "doL2%s", CARD_BUS_ID(card));
6787
Frank Pavlic6c951b92005-11-10 13:51:25 +01006788 rc = qeth_query_setadapterparms(card);
6789 if (rc) {
6790 PRINT_WARN("could not query adapter parameters on device %s: "
6791 "x%x\n", CARD_BUS_ID(card), rc);
6792 }
6793
Linus Torvalds1da177e2005-04-16 15:20:36 -07006794 rc = qeth_setadpparms_change_macaddr(card);
6795 if (rc) {
6796 PRINT_WARN("couldn't get MAC address on "
6797 "device %s: x%x\n",
6798 CARD_BUS_ID(card), rc);
6799 QETH_DBF_TEXT_(setup, 2,"1err%d",rc);
6800 return rc;
6801 }
6802 QETH_DBF_HEX(setup,2, card->dev->dev_addr, OSA_ADDR_LEN);
6803
6804 rc = qeth_layer2_send_setmac(card, &card->dev->dev_addr[0]);
6805 if (rc)
6806 QETH_DBF_TEXT_(setup, 2,"2err%d",rc);
6807 return 0;
6808}
6809
6810
6811static int
6812qeth_send_startstoplan(struct qeth_card *card, enum qeth_ipa_cmds ipacmd,
6813 enum qeth_prot_versions prot)
6814{
6815 int rc;
6816 struct qeth_cmd_buffer *iob;
6817
6818 iob = qeth_get_ipacmd_buffer(card,ipacmd,prot);
6819 rc = qeth_send_ipa_cmd(card, iob, NULL, NULL);
6820
6821 return rc;
6822}
6823
6824static int
6825qeth_send_startlan(struct qeth_card *card, enum qeth_prot_versions prot)
6826{
6827 int rc;
6828
6829 QETH_DBF_TEXT_(setup, 2, "strtlan%i", prot);
6830
6831 rc = qeth_send_startstoplan(card, IPA_CMD_STARTLAN, prot);
6832 return rc;
6833}
6834
6835static int
6836qeth_send_stoplan(struct qeth_card *card)
6837{
6838 int rc = 0;
6839
6840 /*
6841 * TODO: according to the IPA format document page 14,
6842 * TCP/IP (we!) never issue a STOPLAN
6843 * is this right ?!?
6844 */
6845 QETH_DBF_TEXT(trace, 2, "stoplan");
6846
6847 rc = qeth_send_startstoplan(card, IPA_CMD_STOPLAN, QETH_PROT_IPV4);
6848 return rc;
6849}
6850
6851static int
6852qeth_query_ipassists_cb(struct qeth_card *card, struct qeth_reply *reply,
6853 unsigned long data)
6854{
6855 struct qeth_ipa_cmd *cmd;
6856
6857 QETH_DBF_TEXT(setup, 2, "qipasscb");
6858
6859 cmd = (struct qeth_ipa_cmd *) data;
6860 if (cmd->hdr.prot_version == QETH_PROT_IPV4) {
6861 card->options.ipa4.supported_funcs = cmd->hdr.ipa_supported;
6862 card->options.ipa4.enabled_funcs = cmd->hdr.ipa_enabled;
Ursula Braun9123e0d2005-09-30 10:17:24 +02006863 /* Disable IPV6 support hard coded for Hipersockets */
6864 if(card->info.type == QETH_CARD_TYPE_IQD)
6865 card->options.ipa4.supported_funcs &= ~IPA_IPV6;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006866 } else {
6867#ifdef CONFIG_QETH_IPV6
6868 card->options.ipa6.supported_funcs = cmd->hdr.ipa_supported;
6869 card->options.ipa6.enabled_funcs = cmd->hdr.ipa_enabled;
6870#endif
6871 }
6872 QETH_DBF_TEXT(setup, 2, "suppenbl");
6873 QETH_DBF_TEXT_(setup, 2, "%x",cmd->hdr.ipa_supported);
6874 QETH_DBF_TEXT_(setup, 2, "%x",cmd->hdr.ipa_enabled);
6875 return 0;
6876}
6877
6878static int
6879qeth_query_ipassists(struct qeth_card *card, enum qeth_prot_versions prot)
6880{
6881 int rc;
6882 struct qeth_cmd_buffer *iob;
6883
6884 QETH_DBF_TEXT_(setup, 2, "qipassi%i", prot);
6885 if (card->options.layer2) {
6886 QETH_DBF_TEXT(setup, 2, "noprmly2");
6887 return -EPERM;
6888 }
6889
6890 iob = qeth_get_ipacmd_buffer(card,IPA_CMD_QIPASSIST,prot);
6891 rc = qeth_send_ipa_cmd(card, iob, qeth_query_ipassists_cb, NULL);
6892 return rc;
6893}
6894
6895static struct qeth_cmd_buffer *
6896qeth_get_setassparms_cmd(struct qeth_card *card, enum qeth_ipa_funcs ipa_func,
6897 __u16 cmd_code, __u16 len,
6898 enum qeth_prot_versions prot)
6899{
6900 struct qeth_cmd_buffer *iob;
6901 struct qeth_ipa_cmd *cmd;
6902
6903 QETH_DBF_TEXT(trace,4,"getasscm");
6904 iob = qeth_get_ipacmd_buffer(card,IPA_CMD_SETASSPARMS,prot);
6905
6906 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
6907 cmd->data.setassparms.hdr.assist_no = ipa_func;
6908 cmd->data.setassparms.hdr.length = 8 + len;
6909 cmd->data.setassparms.hdr.command_code = cmd_code;
6910 cmd->data.setassparms.hdr.return_code = 0;
6911 cmd->data.setassparms.hdr.seq_no = 0;
6912
6913 return iob;
6914}
6915
6916static int
6917qeth_send_setassparms(struct qeth_card *card, struct qeth_cmd_buffer *iob,
6918 __u16 len, long data,
6919 int (*reply_cb)
6920 (struct qeth_card *,struct qeth_reply *,unsigned long),
6921 void *reply_param)
6922{
6923 int rc;
6924 struct qeth_ipa_cmd *cmd;
6925
6926 QETH_DBF_TEXT(trace,4,"sendassp");
6927
6928 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
6929 if (len <= sizeof(__u32))
6930 cmd->data.setassparms.data.flags_32bit = (__u32) data;
Frank Pavlic1380fee2006-03-22 16:03:41 +01006931 else /* (len > sizeof(__u32)) */
Linus Torvalds1da177e2005-04-16 15:20:36 -07006932 memcpy(&cmd->data.setassparms.data, (void *) data, len);
6933
6934 rc = qeth_send_ipa_cmd(card, iob, reply_cb, reply_param);
6935 return rc;
6936}
6937
6938#ifdef CONFIG_QETH_IPV6
6939static int
6940qeth_send_simple_setassparms_ipv6(struct qeth_card *card,
6941 enum qeth_ipa_funcs ipa_func, __u16 cmd_code)
6942
6943{
6944 int rc;
6945 struct qeth_cmd_buffer *iob;
6946
6947 QETH_DBF_TEXT(trace,4,"simassp6");
6948 iob = qeth_get_setassparms_cmd(card, ipa_func, cmd_code,
6949 0, QETH_PROT_IPV6);
6950 rc = qeth_send_setassparms(card, iob, 0, 0,
6951 qeth_default_setassparms_cb, NULL);
6952 return rc;
6953}
6954#endif
6955
6956static int
6957qeth_send_simple_setassparms(struct qeth_card *card,
6958 enum qeth_ipa_funcs ipa_func,
6959 __u16 cmd_code, long data)
6960{
6961 int rc;
6962 int length = 0;
6963 struct qeth_cmd_buffer *iob;
6964
6965 QETH_DBF_TEXT(trace,4,"simassp4");
6966 if (data)
6967 length = sizeof(__u32);
6968 iob = qeth_get_setassparms_cmd(card, ipa_func, cmd_code,
6969 length, QETH_PROT_IPV4);
6970 rc = qeth_send_setassparms(card, iob, length, data,
6971 qeth_default_setassparms_cb, NULL);
6972 return rc;
6973}
6974
Heiko Carstens4d284ca2007-02-05 21:18:53 +01006975static int
Linus Torvalds1da177e2005-04-16 15:20:36 -07006976qeth_start_ipa_arp_processing(struct qeth_card *card)
6977{
6978 int rc;
6979
6980 QETH_DBF_TEXT(trace,3,"ipaarp");
6981
6982 if (!qeth_is_supported(card,IPA_ARP_PROCESSING)) {
6983 PRINT_WARN("ARP processing not supported "
6984 "on %s!\n", QETH_CARD_IFNAME(card));
6985 return 0;
6986 }
6987 rc = qeth_send_simple_setassparms(card,IPA_ARP_PROCESSING,
6988 IPA_CMD_ASS_START, 0);
6989 if (rc) {
6990 PRINT_WARN("Could not start ARP processing "
6991 "assist on %s: 0x%x\n",
6992 QETH_CARD_IFNAME(card), rc);
6993 }
6994 return rc;
6995}
6996
6997static int
6998qeth_start_ipa_ip_fragmentation(struct qeth_card *card)
6999{
7000 int rc;
7001
7002 QETH_DBF_TEXT(trace,3,"ipaipfrg");
7003
7004 if (!qeth_is_supported(card, IPA_IP_FRAGMENTATION)) {
7005 PRINT_INFO("Hardware IP fragmentation not supported on %s\n",
7006 QETH_CARD_IFNAME(card));
7007 return -EOPNOTSUPP;
7008 }
7009
7010 rc = qeth_send_simple_setassparms(card, IPA_IP_FRAGMENTATION,
7011 IPA_CMD_ASS_START, 0);
7012 if (rc) {
7013 PRINT_WARN("Could not start Hardware IP fragmentation "
7014 "assist on %s: 0x%x\n",
7015 QETH_CARD_IFNAME(card), rc);
7016 } else
7017 PRINT_INFO("Hardware IP fragmentation enabled \n");
7018 return rc;
7019}
7020
7021static int
7022qeth_start_ipa_source_mac(struct qeth_card *card)
7023{
7024 int rc;
7025
7026 QETH_DBF_TEXT(trace,3,"stsrcmac");
7027
7028 if (!card->options.fake_ll)
7029 return -EOPNOTSUPP;
7030
7031 if (!qeth_is_supported(card, IPA_SOURCE_MAC)) {
7032 PRINT_INFO("Inbound source address not "
7033 "supported on %s\n", QETH_CARD_IFNAME(card));
7034 return -EOPNOTSUPP;
7035 }
7036
7037 rc = qeth_send_simple_setassparms(card, IPA_SOURCE_MAC,
7038 IPA_CMD_ASS_START, 0);
7039 if (rc)
7040 PRINT_WARN("Could not start inbound source "
7041 "assist on %s: 0x%x\n",
7042 QETH_CARD_IFNAME(card), rc);
7043 return rc;
7044}
7045
7046static int
7047qeth_start_ipa_vlan(struct qeth_card *card)
7048{
7049 int rc = 0;
7050
7051 QETH_DBF_TEXT(trace,3,"strtvlan");
7052
7053#ifdef CONFIG_QETH_VLAN
7054 if (!qeth_is_supported(card, IPA_FULL_VLAN)) {
7055 PRINT_WARN("VLAN not supported on %s\n", QETH_CARD_IFNAME(card));
7056 return -EOPNOTSUPP;
7057 }
7058
7059 rc = qeth_send_simple_setassparms(card, IPA_VLAN_PRIO,
7060 IPA_CMD_ASS_START,0);
7061 if (rc) {
7062 PRINT_WARN("Could not start vlan "
7063 "assist on %s: 0x%x\n",
7064 QETH_CARD_IFNAME(card), rc);
7065 } else {
7066 PRINT_INFO("VLAN enabled \n");
7067 card->dev->features |=
7068 NETIF_F_HW_VLAN_FILTER |
7069 NETIF_F_HW_VLAN_TX |
7070 NETIF_F_HW_VLAN_RX;
7071 }
7072#endif /* QETH_VLAN */
7073 return rc;
7074}
7075
7076static int
7077qeth_start_ipa_multicast(struct qeth_card *card)
7078{
7079 int rc;
7080
7081 QETH_DBF_TEXT(trace,3,"stmcast");
7082
7083 if (!qeth_is_supported(card, IPA_MULTICASTING)) {
7084 PRINT_WARN("Multicast not supported on %s\n",
7085 QETH_CARD_IFNAME(card));
7086 return -EOPNOTSUPP;
7087 }
7088
7089 rc = qeth_send_simple_setassparms(card, IPA_MULTICASTING,
7090 IPA_CMD_ASS_START,0);
7091 if (rc) {
7092 PRINT_WARN("Could not start multicast "
7093 "assist on %s: rc=%i\n",
7094 QETH_CARD_IFNAME(card), rc);
7095 } else {
7096 PRINT_INFO("Multicast enabled\n");
7097 card->dev->flags |= IFF_MULTICAST;
7098 }
7099 return rc;
7100}
7101
7102#ifdef CONFIG_QETH_IPV6
7103static int
7104qeth_softsetup_ipv6(struct qeth_card *card)
7105{
7106 int rc;
7107
7108 QETH_DBF_TEXT(trace,3,"softipv6");
7109
Linus Torvalds1da177e2005-04-16 15:20:36 -07007110 rc = qeth_send_startlan(card, QETH_PROT_IPV6);
7111 if (rc) {
7112 PRINT_ERR("IPv6 startlan failed on %s\n",
7113 QETH_CARD_IFNAME(card));
7114 return rc;
7115 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07007116 rc = qeth_query_ipassists(card,QETH_PROT_IPV6);
7117 if (rc) {
7118 PRINT_ERR("IPv6 query ipassist failed on %s\n",
7119 QETH_CARD_IFNAME(card));
7120 return rc;
7121 }
7122 rc = qeth_send_simple_setassparms(card, IPA_IPV6,
7123 IPA_CMD_ASS_START, 3);
7124 if (rc) {
7125 PRINT_WARN("IPv6 start assist (version 4) failed "
7126 "on %s: 0x%x\n",
7127 QETH_CARD_IFNAME(card), rc);
7128 return rc;
7129 }
7130 rc = qeth_send_simple_setassparms_ipv6(card, IPA_IPV6,
7131 IPA_CMD_ASS_START);
7132 if (rc) {
7133 PRINT_WARN("IPV6 start assist (version 6) failed "
7134 "on %s: 0x%x\n",
7135 QETH_CARD_IFNAME(card), rc);
7136 return rc;
7137 }
7138 rc = qeth_send_simple_setassparms_ipv6(card, IPA_PASSTHRU,
7139 IPA_CMD_ASS_START);
7140 if (rc) {
7141 PRINT_WARN("Could not enable passthrough "
7142 "on %s: 0x%x\n",
7143 QETH_CARD_IFNAME(card), rc);
7144 return rc;
7145 }
7146 PRINT_INFO("IPV6 enabled \n");
7147 return 0;
7148}
7149
7150#endif
7151
7152static int
7153qeth_start_ipa_ipv6(struct qeth_card *card)
7154{
7155 int rc = 0;
7156#ifdef CONFIG_QETH_IPV6
7157 QETH_DBF_TEXT(trace,3,"strtipv6");
7158
7159 if (!qeth_is_supported(card, IPA_IPV6)) {
7160 PRINT_WARN("IPv6 not supported on %s\n",
7161 QETH_CARD_IFNAME(card));
7162 return 0;
7163 }
7164 rc = qeth_softsetup_ipv6(card);
7165#endif
7166 return rc ;
7167}
7168
7169static int
7170qeth_start_ipa_broadcast(struct qeth_card *card)
7171{
7172 int rc;
7173
7174 QETH_DBF_TEXT(trace,3,"stbrdcst");
7175 card->info.broadcast_capable = 0;
7176 if (!qeth_is_supported(card, IPA_FILTERING)) {
7177 PRINT_WARN("Broadcast not supported on %s\n",
7178 QETH_CARD_IFNAME(card));
7179 rc = -EOPNOTSUPP;
7180 goto out;
7181 }
7182 rc = qeth_send_simple_setassparms(card, IPA_FILTERING,
7183 IPA_CMD_ASS_START, 0);
7184 if (rc) {
7185 PRINT_WARN("Could not enable broadcasting filtering "
7186 "on %s: 0x%x\n",
7187 QETH_CARD_IFNAME(card), rc);
7188 goto out;
7189 }
7190
7191 rc = qeth_send_simple_setassparms(card, IPA_FILTERING,
7192 IPA_CMD_ASS_CONFIGURE, 1);
7193 if (rc) {
7194 PRINT_WARN("Could not set up broadcast filtering on %s: 0x%x\n",
7195 QETH_CARD_IFNAME(card), rc);
7196 goto out;
7197 }
7198 card->info.broadcast_capable = QETH_BROADCAST_WITH_ECHO;
7199 PRINT_INFO("Broadcast enabled \n");
7200 rc = qeth_send_simple_setassparms(card, IPA_FILTERING,
7201 IPA_CMD_ASS_ENABLE, 1);
7202 if (rc) {
7203 PRINT_WARN("Could not set up broadcast echo filtering on "
7204 "%s: 0x%x\n", QETH_CARD_IFNAME(card), rc);
7205 goto out;
7206 }
7207 card->info.broadcast_capable = QETH_BROADCAST_WITHOUT_ECHO;
7208out:
7209 if (card->info.broadcast_capable)
7210 card->dev->flags |= IFF_BROADCAST;
7211 else
7212 card->dev->flags &= ~IFF_BROADCAST;
7213 return rc;
7214}
7215
7216static int
7217qeth_send_checksum_command(struct qeth_card *card)
7218{
7219 int rc;
7220
7221 rc = qeth_send_simple_setassparms(card, IPA_INBOUND_CHECKSUM,
7222 IPA_CMD_ASS_START, 0);
7223 if (rc) {
7224 PRINT_WARN("Starting Inbound HW Checksumming failed on %s: "
7225 "0x%x,\ncontinuing using Inbound SW Checksumming\n",
7226 QETH_CARD_IFNAME(card), rc);
7227 return rc;
7228 }
7229 rc = qeth_send_simple_setassparms(card, IPA_INBOUND_CHECKSUM,
7230 IPA_CMD_ASS_ENABLE,
7231 card->info.csum_mask);
7232 if (rc) {
7233 PRINT_WARN("Enabling Inbound HW Checksumming failed on %s: "
7234 "0x%x,\ncontinuing using Inbound SW Checksumming\n",
7235 QETH_CARD_IFNAME(card), rc);
7236 return rc;
7237 }
7238 return 0;
7239}
7240
7241static int
7242qeth_start_ipa_checksum(struct qeth_card *card)
7243{
7244 int rc = 0;
7245
7246 QETH_DBF_TEXT(trace,3,"strtcsum");
7247
7248 if (card->options.checksum_type == NO_CHECKSUMMING) {
7249 PRINT_WARN("Using no checksumming on %s.\n",
7250 QETH_CARD_IFNAME(card));
7251 return 0;
7252 }
7253 if (card->options.checksum_type == SW_CHECKSUMMING) {
7254 PRINT_WARN("Using SW checksumming on %s.\n",
7255 QETH_CARD_IFNAME(card));
7256 return 0;
7257 }
7258 if (!qeth_is_supported(card, IPA_INBOUND_CHECKSUM)) {
7259 PRINT_WARN("Inbound HW Checksumming not "
7260 "supported on %s,\ncontinuing "
7261 "using Inbound SW Checksumming\n",
7262 QETH_CARD_IFNAME(card));
7263 card->options.checksum_type = SW_CHECKSUMMING;
7264 return 0;
7265 }
7266 rc = qeth_send_checksum_command(card);
7267 if (!rc) {
7268 PRINT_INFO("HW Checksumming (inbound) enabled \n");
7269 }
7270 return rc;
7271}
7272
7273static int
7274qeth_start_ipa_tso(struct qeth_card *card)
7275{
7276 int rc;
7277
7278 QETH_DBF_TEXT(trace,3,"sttso");
7279
7280 if (!qeth_is_supported(card, IPA_OUTBOUND_TSO)) {
7281 PRINT_WARN("Outbound TSO not supported on %s\n",
7282 QETH_CARD_IFNAME(card));
7283 rc = -EOPNOTSUPP;
7284 } else {
7285 rc = qeth_send_simple_setassparms(card, IPA_OUTBOUND_TSO,
7286 IPA_CMD_ASS_START,0);
7287 if (rc)
7288 PRINT_WARN("Could not start outbound TSO "
7289 "assist on %s: rc=%i\n",
7290 QETH_CARD_IFNAME(card), rc);
7291 else
7292 PRINT_INFO("Outbound TSO enabled\n");
7293 }
7294 if (rc && (card->options.large_send == QETH_LARGE_SEND_TSO)){
7295 card->options.large_send = QETH_LARGE_SEND_NO;
7296 card->dev->features &= ~ (NETIF_F_TSO | NETIF_F_SG);
7297 }
7298 return rc;
7299}
7300
7301static int
7302qeth_start_ipassists(struct qeth_card *card)
7303{
7304 QETH_DBF_TEXT(trace,3,"strtipas");
7305 qeth_start_ipa_arp_processing(card); /* go on*/
7306 qeth_start_ipa_ip_fragmentation(card); /* go on*/
7307 qeth_start_ipa_source_mac(card); /* go on*/
7308 qeth_start_ipa_vlan(card); /* go on*/
7309 qeth_start_ipa_multicast(card); /* go on*/
7310 qeth_start_ipa_ipv6(card); /* go on*/
7311 qeth_start_ipa_broadcast(card); /* go on*/
7312 qeth_start_ipa_checksum(card); /* go on*/
7313 qeth_start_ipa_tso(card); /* go on*/
7314 return 0;
7315}
7316
7317static int
7318qeth_send_setrouting(struct qeth_card *card, enum qeth_routing_types type,
7319 enum qeth_prot_versions prot)
7320{
7321 int rc;
7322 struct qeth_ipa_cmd *cmd;
7323 struct qeth_cmd_buffer *iob;
7324
7325 QETH_DBF_TEXT(trace,4,"setroutg");
7326 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_SETRTG, prot);
7327 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
7328 cmd->data.setrtg.type = (type);
7329 rc = qeth_send_ipa_cmd(card, iob, NULL, NULL);
7330
7331 return rc;
7332
7333}
7334
7335static void
7336qeth_correct_routing_type(struct qeth_card *card, enum qeth_routing_types *type,
7337 enum qeth_prot_versions prot)
7338{
7339 if (card->info.type == QETH_CARD_TYPE_IQD) {
7340 switch (*type) {
7341 case NO_ROUTER:
7342 case PRIMARY_CONNECTOR:
7343 case SECONDARY_CONNECTOR:
7344 case MULTICAST_ROUTER:
7345 return;
7346 default:
7347 goto out_inval;
7348 }
7349 } else {
7350 switch (*type) {
7351 case NO_ROUTER:
7352 case PRIMARY_ROUTER:
7353 case SECONDARY_ROUTER:
7354 return;
7355 case MULTICAST_ROUTER:
7356 if (qeth_is_ipafunc_supported(card, prot,
7357 IPA_OSA_MC_ROUTER))
7358 return;
7359 default:
7360 goto out_inval;
7361 }
7362 }
7363out_inval:
7364 PRINT_WARN("Routing type '%s' not supported for interface %s.\n"
7365 "Router status set to 'no router'.\n",
7366 ((*type == PRIMARY_ROUTER)? "primary router" :
7367 (*type == SECONDARY_ROUTER)? "secondary router" :
7368 (*type == PRIMARY_CONNECTOR)? "primary connector" :
7369 (*type == SECONDARY_CONNECTOR)? "secondary connector" :
7370 (*type == MULTICAST_ROUTER)? "multicast router" :
7371 "unknown"),
7372 card->dev->name);
7373 *type = NO_ROUTER;
7374}
7375
7376int
7377qeth_setrouting_v4(struct qeth_card *card)
7378{
7379 int rc;
7380
7381 QETH_DBF_TEXT(trace,3,"setrtg4");
7382
7383 qeth_correct_routing_type(card, &card->options.route4.type,
7384 QETH_PROT_IPV4);
7385
7386 rc = qeth_send_setrouting(card, card->options.route4.type,
7387 QETH_PROT_IPV4);
7388 if (rc) {
7389 card->options.route4.type = NO_ROUTER;
7390 PRINT_WARN("Error (0x%04x) while setting routing type on %s. "
7391 "Type set to 'no router'.\n",
7392 rc, QETH_CARD_IFNAME(card));
7393 }
7394 return rc;
7395}
7396
7397int
7398qeth_setrouting_v6(struct qeth_card *card)
7399{
7400 int rc = 0;
7401
7402 QETH_DBF_TEXT(trace,3,"setrtg6");
7403#ifdef CONFIG_QETH_IPV6
7404
Frank Pavlic8b98a372006-09-15 16:27:02 +02007405 if (!qeth_is_supported(card, IPA_IPV6))
7406 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007407 qeth_correct_routing_type(card, &card->options.route6.type,
7408 QETH_PROT_IPV6);
7409
Linus Torvalds1da177e2005-04-16 15:20:36 -07007410 rc = qeth_send_setrouting(card, card->options.route6.type,
7411 QETH_PROT_IPV6);
7412 if (rc) {
7413 card->options.route6.type = NO_ROUTER;
7414 PRINT_WARN("Error (0x%04x) while setting routing type on %s. "
7415 "Type set to 'no router'.\n",
7416 rc, QETH_CARD_IFNAME(card));
7417 }
7418#endif
7419 return rc;
7420}
7421
7422int
Frank Pavlic9cb90de2005-09-14 18:03:26 +02007423qeth_set_large_send(struct qeth_card *card, enum qeth_large_send_types type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007424{
7425 int rc = 0;
7426
Frank Pavlic9cb90de2005-09-14 18:03:26 +02007427 if (card->dev == NULL) {
7428 card->options.large_send = type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007429 return 0;
Frank Pavlic9cb90de2005-09-14 18:03:26 +02007430 }
Ursula Braunb85e1fa2006-05-24 09:51:11 +02007431 if (card->state == CARD_STATE_UP)
7432 netif_tx_disable(card->dev);
Frank Pavlic9cb90de2005-09-14 18:03:26 +02007433 card->options.large_send = type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007434 switch (card->options.large_send) {
7435 case QETH_LARGE_SEND_EDDP:
7436 card->dev->features |= NETIF_F_TSO | NETIF_F_SG;
7437 break;
7438 case QETH_LARGE_SEND_TSO:
7439 if (qeth_is_supported(card, IPA_OUTBOUND_TSO)){
7440 card->dev->features |= NETIF_F_TSO | NETIF_F_SG;
7441 } else {
7442 PRINT_WARN("TSO not supported on %s. "
7443 "large_send set to 'no'.\n",
7444 card->dev->name);
7445 card->dev->features &= ~(NETIF_F_TSO | NETIF_F_SG);
7446 card->options.large_send = QETH_LARGE_SEND_NO;
7447 rc = -EOPNOTSUPP;
7448 }
7449 break;
7450 default: /* includes QETH_LARGE_SEND_NO */
7451 card->dev->features &= ~(NETIF_F_TSO | NETIF_F_SG);
7452 break;
7453 }
Ursula Braunb85e1fa2006-05-24 09:51:11 +02007454 if (card->state == CARD_STATE_UP)
7455 netif_wake_queue(card->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007456 return rc;
7457}
7458
7459/*
7460 * softsetup card: init IPA stuff
7461 */
7462static int
7463qeth_softsetup_card(struct qeth_card *card)
7464{
7465 int rc;
7466
7467 QETH_DBF_TEXT(setup, 2, "softsetp");
7468
7469 if ((rc = qeth_send_startlan(card, QETH_PROT_IPV4))){
7470 QETH_DBF_TEXT_(setup, 2, "1err%d", rc);
7471 if (rc == 0xe080){
7472 PRINT_WARN("LAN on card %s if offline! "
Ursula Braund81ef0f2007-06-20 12:56:49 +02007473 "Waiting for STARTLAN from card.\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07007474 CARD_BUS_ID(card));
7475 card->lan_online = 0;
Ursula Braund81ef0f2007-06-20 12:56:49 +02007476 }
7477 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007478 } else
7479 card->lan_online = 1;
Ursula Braun500f83a2005-09-30 10:19:19 +02007480 if (card->info.type==QETH_CARD_TYPE_OSN)
7481 goto out;
Frank Pavlic66cc5d52006-02-07 17:04:38 +01007482 qeth_set_large_send(card, card->options.large_send);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007483 if (card->options.layer2) {
7484 card->dev->features |=
7485 NETIF_F_HW_VLAN_FILTER |
7486 NETIF_F_HW_VLAN_TX |
7487 NETIF_F_HW_VLAN_RX;
7488 card->dev->flags|=IFF_MULTICAST|IFF_BROADCAST;
7489 card->info.broadcast_capable=1;
7490 if ((rc = qeth_layer2_initialize(card))) {
7491 QETH_DBF_TEXT_(setup, 2, "L2err%d", rc);
7492 return rc;
7493 }
7494#ifdef CONFIG_QETH_VLAN
7495 qeth_layer2_process_vlans(card, 0);
7496#endif
7497 goto out;
7498 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07007499 if ((rc = qeth_setadapter_parms(card)))
7500 QETH_DBF_TEXT_(setup, 2, "2err%d", rc);
7501 if ((rc = qeth_start_ipassists(card)))
7502 QETH_DBF_TEXT_(setup, 2, "3err%d", rc);
7503 if ((rc = qeth_setrouting_v4(card)))
7504 QETH_DBF_TEXT_(setup, 2, "4err%d", rc);
7505 if ((rc = qeth_setrouting_v6(card)))
7506 QETH_DBF_TEXT_(setup, 2, "5err%d", rc);
7507out:
Ursula Braunb85e1fa2006-05-24 09:51:11 +02007508 netif_tx_disable(card->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007509 return 0;
7510}
7511
7512#ifdef CONFIG_QETH_IPV6
7513static int
7514qeth_get_unique_id_cb(struct qeth_card *card, struct qeth_reply *reply,
7515 unsigned long data)
7516{
7517 struct qeth_ipa_cmd *cmd;
7518
7519 cmd = (struct qeth_ipa_cmd *) data;
7520 if (cmd->hdr.return_code == 0)
7521 card->info.unique_id = *((__u16 *)
7522 &cmd->data.create_destroy_addr.unique_id[6]);
7523 else {
7524 card->info.unique_id = UNIQUE_ID_IF_CREATE_ADDR_FAILED |
7525 UNIQUE_ID_NOT_BY_CARD;
7526 PRINT_WARN("couldn't get a unique id from the card on device "
7527 "%s (result=x%x), using default id. ipv6 "
7528 "autoconfig on other lpars may lead to duplicate "
7529 "ip addresses. please use manually "
7530 "configured ones.\n",
7531 CARD_BUS_ID(card), cmd->hdr.return_code);
7532 }
7533 return 0;
7534}
7535#endif
7536
7537static int
7538qeth_put_unique_id(struct qeth_card *card)
7539{
7540
7541 int rc = 0;
7542#ifdef CONFIG_QETH_IPV6
7543 struct qeth_cmd_buffer *iob;
7544 struct qeth_ipa_cmd *cmd;
7545
7546 QETH_DBF_TEXT(trace,2,"puniqeid");
7547
7548 if ((card->info.unique_id & UNIQUE_ID_NOT_BY_CARD) ==
7549 UNIQUE_ID_NOT_BY_CARD)
7550 return -1;
7551 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_DESTROY_ADDR,
7552 QETH_PROT_IPV6);
7553 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
7554 *((__u16 *) &cmd->data.create_destroy_addr.unique_id[6]) =
7555 card->info.unique_id;
7556 memcpy(&cmd->data.create_destroy_addr.unique_id[0],
7557 card->dev->dev_addr, OSA_ADDR_LEN);
7558 rc = qeth_send_ipa_cmd(card, iob, NULL, NULL);
7559#else
7560 card->info.unique_id = UNIQUE_ID_IF_CREATE_ADDR_FAILED |
7561 UNIQUE_ID_NOT_BY_CARD;
7562#endif
7563 return rc;
7564}
7565
7566/**
7567 * Clear IP List
7568 */
7569static void
7570qeth_clear_ip_list(struct qeth_card *card, int clean, int recover)
7571{
7572 struct qeth_ipaddr *addr, *tmp;
7573 unsigned long flags;
7574
7575 QETH_DBF_TEXT(trace,4,"clearip");
7576 spin_lock_irqsave(&card->ip_lock, flags);
7577 /* clear todo list */
7578 list_for_each_entry_safe(addr, tmp, card->ip_tbd_list, entry){
7579 list_del(&addr->entry);
7580 kfree(addr);
7581 }
7582
7583 while (!list_empty(&card->ip_list)) {
7584 addr = list_entry(card->ip_list.next,
7585 struct qeth_ipaddr, entry);
7586 list_del_init(&addr->entry);
7587 if (clean) {
7588 spin_unlock_irqrestore(&card->ip_lock, flags);
7589 qeth_deregister_addr_entry(card, addr);
7590 spin_lock_irqsave(&card->ip_lock, flags);
7591 }
7592 if (!recover || addr->is_multicast) {
7593 kfree(addr);
7594 continue;
7595 }
7596 list_add_tail(&addr->entry, card->ip_tbd_list);
7597 }
7598 spin_unlock_irqrestore(&card->ip_lock, flags);
7599}
7600
7601static void
7602qeth_set_allowed_threads(struct qeth_card *card, unsigned long threads,
7603 int clear_start_mask)
7604{
7605 unsigned long flags;
7606
7607 spin_lock_irqsave(&card->thread_mask_lock, flags);
7608 card->thread_allowed_mask = threads;
7609 if (clear_start_mask)
7610 card->thread_start_mask &= threads;
7611 spin_unlock_irqrestore(&card->thread_mask_lock, flags);
7612 wake_up(&card->wait_q);
7613}
7614
Heiko Carstens4d284ca2007-02-05 21:18:53 +01007615static int
Linus Torvalds1da177e2005-04-16 15:20:36 -07007616qeth_threads_running(struct qeth_card *card, unsigned long threads)
7617{
7618 unsigned long flags;
7619 int rc = 0;
7620
7621 spin_lock_irqsave(&card->thread_mask_lock, flags);
7622 rc = (card->thread_running_mask & threads);
7623 spin_unlock_irqrestore(&card->thread_mask_lock, flags);
7624 return rc;
7625}
7626
7627static int
7628qeth_wait_for_threads(struct qeth_card *card, unsigned long threads)
7629{
7630 return wait_event_interruptible(card->wait_q,
7631 qeth_threads_running(card, threads) == 0);
7632}
7633
7634static int
Frank Pavlic05e08a22005-05-12 20:39:09 +02007635qeth_stop_card(struct qeth_card *card, int recovery_mode)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007636{
7637 int rc = 0;
7638
7639 QETH_DBF_TEXT(setup ,2,"stopcard");
7640 QETH_DBF_HEX(setup, 2, &card, sizeof(void *));
7641
7642 qeth_set_allowed_threads(card, 0, 1);
7643 if (qeth_wait_for_threads(card, ~QETH_RECOVER_THREAD))
7644 return -ERESTARTSYS;
7645 if (card->read.state == CH_STATE_UP &&
7646 card->write.state == CH_STATE_UP &&
7647 (card->state == CARD_STATE_UP)) {
Jeff Garzike82b0f22006-05-26 21:58:38 -04007648 if (recovery_mode &&
Ursula Braun500f83a2005-09-30 10:19:19 +02007649 card->info.type != QETH_CARD_TYPE_OSN) {
Frank Pavlic05e08a22005-05-12 20:39:09 +02007650 qeth_stop(card->dev);
7651 } else {
7652 rtnl_lock();
7653 dev_close(card->dev);
7654 rtnl_unlock();
7655 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07007656 if (!card->use_hard_stop) {
7657 __u8 *mac = &card->dev->dev_addr[0];
7658 rc = qeth_layer2_send_delmac(card, mac);
7659 QETH_DBF_TEXT_(setup, 2, "Lerr%d", rc);
7660 if ((rc = qeth_send_stoplan(card)))
7661 QETH_DBF_TEXT_(setup, 2, "1err%d", rc);
7662 }
7663 card->state = CARD_STATE_SOFTSETUP;
7664 }
7665 if (card->state == CARD_STATE_SOFTSETUP) {
7666#ifdef CONFIG_QETH_VLAN
7667 if (card->options.layer2)
7668 qeth_layer2_process_vlans(card, 1);
7669#endif
7670 qeth_clear_ip_list(card, !card->use_hard_stop, 1);
7671 qeth_clear_ipacmd_list(card);
7672 card->state = CARD_STATE_HARDSETUP;
7673 }
7674 if (card->state == CARD_STATE_HARDSETUP) {
7675 if ((!card->use_hard_stop) &&
7676 (!card->options.layer2))
7677 if ((rc = qeth_put_unique_id(card)))
7678 QETH_DBF_TEXT_(setup, 2, "2err%d", rc);
7679 qeth_qdio_clear_card(card, 0);
7680 qeth_clear_qdio_buffers(card);
7681 qeth_clear_working_pool_list(card);
7682 card->state = CARD_STATE_DOWN;
7683 }
7684 if (card->state == CARD_STATE_DOWN) {
7685 qeth_clear_cmd_buffers(&card->read);
7686 qeth_clear_cmd_buffers(&card->write);
7687 }
7688 card->use_hard_stop = 0;
7689 return rc;
7690}
7691
7692
7693static int
7694qeth_get_unique_id(struct qeth_card *card)
7695{
7696 int rc = 0;
7697#ifdef CONFIG_QETH_IPV6
7698 struct qeth_cmd_buffer *iob;
7699 struct qeth_ipa_cmd *cmd;
7700
7701 QETH_DBF_TEXT(setup, 2, "guniqeid");
7702
7703 if (!qeth_is_supported(card,IPA_IPV6)) {
7704 card->info.unique_id = UNIQUE_ID_IF_CREATE_ADDR_FAILED |
7705 UNIQUE_ID_NOT_BY_CARD;
7706 return 0;
7707 }
7708
7709 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_CREATE_ADDR,
7710 QETH_PROT_IPV6);
7711 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
7712 *((__u16 *) &cmd->data.create_destroy_addr.unique_id[6]) =
7713 card->info.unique_id;
7714
7715 rc = qeth_send_ipa_cmd(card, iob, qeth_get_unique_id_cb, NULL);
7716#else
7717 card->info.unique_id = UNIQUE_ID_IF_CREATE_ADDR_FAILED |
7718 UNIQUE_ID_NOT_BY_CARD;
7719#endif
7720 return rc;
7721}
7722static void
7723qeth_print_status_with_portname(struct qeth_card *card)
7724{
7725 char dbf_text[15];
7726 int i;
7727
7728 sprintf(dbf_text, "%s", card->info.portname + 1);
7729 for (i = 0; i < 8; i++)
7730 dbf_text[i] =
7731 (char) _ebcasc[(__u8) dbf_text[i]];
7732 dbf_text[8] = 0;
7733 printk("qeth: Device %s/%s/%s is a%s card%s%s%s\n"
7734 "with link type %s (portname: %s)\n",
7735 CARD_RDEV_ID(card),
7736 CARD_WDEV_ID(card),
7737 CARD_DDEV_ID(card),
7738 qeth_get_cardname(card),
7739 (card->info.mcl_level[0]) ? " (level: " : "",
7740 (card->info.mcl_level[0]) ? card->info.mcl_level : "",
7741 (card->info.mcl_level[0]) ? ")" : "",
7742 qeth_get_cardname_short(card),
7743 dbf_text);
7744
7745}
7746
7747static void
7748qeth_print_status_no_portname(struct qeth_card *card)
7749{
7750 if (card->info.portname[0])
7751 printk("qeth: Device %s/%s/%s is a%s "
7752 "card%s%s%s\nwith link type %s "
7753 "(no portname needed by interface).\n",
7754 CARD_RDEV_ID(card),
7755 CARD_WDEV_ID(card),
7756 CARD_DDEV_ID(card),
7757 qeth_get_cardname(card),
7758 (card->info.mcl_level[0]) ? " (level: " : "",
7759 (card->info.mcl_level[0]) ? card->info.mcl_level : "",
7760 (card->info.mcl_level[0]) ? ")" : "",
7761 qeth_get_cardname_short(card));
7762 else
7763 printk("qeth: Device %s/%s/%s is a%s "
7764 "card%s%s%s\nwith link type %s.\n",
7765 CARD_RDEV_ID(card),
7766 CARD_WDEV_ID(card),
7767 CARD_DDEV_ID(card),
7768 qeth_get_cardname(card),
7769 (card->info.mcl_level[0]) ? " (level: " : "",
7770 (card->info.mcl_level[0]) ? card->info.mcl_level : "",
7771 (card->info.mcl_level[0]) ? ")" : "",
7772 qeth_get_cardname_short(card));
7773}
7774
7775static void
7776qeth_print_status_message(struct qeth_card *card)
7777{
7778 switch (card->info.type) {
7779 case QETH_CARD_TYPE_OSAE:
7780 /* VM will use a non-zero first character
7781 * to indicate a HiperSockets like reporting
7782 * of the level OSA sets the first character to zero
7783 * */
7784 if (!card->info.mcl_level[0]) {
7785 sprintf(card->info.mcl_level,"%02x%02x",
7786 card->info.mcl_level[2],
7787 card->info.mcl_level[3]);
7788
7789 card->info.mcl_level[QETH_MCL_LENGTH] = 0;
7790 break;
7791 }
7792 /* fallthrough */
7793 case QETH_CARD_TYPE_IQD:
Ursula Braund78f6642007-06-20 12:55:18 +02007794 if (card->info.guestlan) {
7795 card->info.mcl_level[0] = (char) _ebcasc[(__u8)
7796 card->info.mcl_level[0]];
7797 card->info.mcl_level[1] = (char) _ebcasc[(__u8)
7798 card->info.mcl_level[1]];
7799 card->info.mcl_level[2] = (char) _ebcasc[(__u8)
7800 card->info.mcl_level[2]];
7801 card->info.mcl_level[3] = (char) _ebcasc[(__u8)
7802 card->info.mcl_level[3]];
7803 card->info.mcl_level[QETH_MCL_LENGTH] = 0;
7804 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07007805 break;
7806 default:
7807 memset(&card->info.mcl_level[0], 0, QETH_MCL_LENGTH + 1);
7808 }
7809 if (card->info.portname_required)
7810 qeth_print_status_with_portname(card);
7811 else
7812 qeth_print_status_no_portname(card);
7813}
7814
7815static int
7816qeth_register_netdev(struct qeth_card *card)
7817{
7818 QETH_DBF_TEXT(setup, 3, "regnetd");
Jeff Garzike82b0f22006-05-26 21:58:38 -04007819 if (card->dev->reg_state != NETREG_UNINITIALIZED)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007820 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007821 /* sysfs magic */
7822 SET_NETDEV_DEV(card->dev, &card->gdev->dev);
7823 return register_netdev(card->dev);
7824}
7825
7826static void
Frank Pavlic05e08a22005-05-12 20:39:09 +02007827qeth_start_again(struct qeth_card *card, int recovery_mode)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007828{
7829 QETH_DBF_TEXT(setup ,2, "startag");
7830
Jeff Garzike82b0f22006-05-26 21:58:38 -04007831 if (recovery_mode &&
Ursula Braun500f83a2005-09-30 10:19:19 +02007832 card->info.type != QETH_CARD_TYPE_OSN) {
Frank Pavlic05e08a22005-05-12 20:39:09 +02007833 qeth_open(card->dev);
7834 } else {
7835 rtnl_lock();
7836 dev_open(card->dev);
7837 rtnl_unlock();
7838 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07007839 /* this also sets saved unicast addresses */
7840 qeth_set_multicast_list(card->dev);
7841}
7842
7843
7844/* Layer 2 specific stuff */
7845#define IGNORE_PARAM_EQ(option,value,reset_value,msg) \
7846 if (card->options.option == value) { \
7847 PRINT_ERR("%s not supported with layer 2 " \
7848 "functionality, ignoring option on read" \
7849 "channel device %s .\n",msg,CARD_RDEV_ID(card)); \
7850 card->options.option = reset_value; \
7851 }
7852#define IGNORE_PARAM_NEQ(option,value,reset_value,msg) \
7853 if (card->options.option != value) { \
7854 PRINT_ERR("%s not supported with layer 2 " \
7855 "functionality, ignoring option on read" \
7856 "channel device %s .\n",msg,CARD_RDEV_ID(card)); \
7857 card->options.option = reset_value; \
7858 }
7859
7860
7861static void qeth_make_parameters_consistent(struct qeth_card *card)
7862{
7863
Ursula Braun500f83a2005-09-30 10:19:19 +02007864 if (card->options.layer2 == 0)
7865 return;
7866 if (card->info.type == QETH_CARD_TYPE_OSN)
7867 return;
7868 if (card->info.type == QETH_CARD_TYPE_IQD) {
7869 PRINT_ERR("Device %s does not support layer 2 functionality." \
7870 " Ignoring layer2 option.\n",CARD_BUS_ID(card));
7871 card->options.layer2 = 0;
7872 return;
7873 }
7874 IGNORE_PARAM_NEQ(route4.type, NO_ROUTER, NO_ROUTER,
7875 "Routing options are");
Linus Torvalds1da177e2005-04-16 15:20:36 -07007876#ifdef CONFIG_QETH_IPV6
Ursula Braun500f83a2005-09-30 10:19:19 +02007877 IGNORE_PARAM_NEQ(route6.type, NO_ROUTER, NO_ROUTER,
7878 "Routing options are");
Linus Torvalds1da177e2005-04-16 15:20:36 -07007879#endif
Ursula Braun500f83a2005-09-30 10:19:19 +02007880 IGNORE_PARAM_EQ(checksum_type, HW_CHECKSUMMING,
7881 QETH_CHECKSUM_DEFAULT,
7882 "Checksumming options are");
7883 IGNORE_PARAM_NEQ(broadcast_mode, QETH_TR_BROADCAST_ALLRINGS,
7884 QETH_TR_BROADCAST_ALLRINGS,
7885 "Broadcast mode options are");
7886 IGNORE_PARAM_NEQ(macaddr_mode, QETH_TR_MACADDR_NONCANONICAL,
7887 QETH_TR_MACADDR_NONCANONICAL,
7888 "Canonical MAC addr options are");
7889 IGNORE_PARAM_NEQ(fake_broadcast, 0, 0,
7890 "Broadcast faking options are");
7891 IGNORE_PARAM_NEQ(add_hhlen, DEFAULT_ADD_HHLEN,
7892 DEFAULT_ADD_HHLEN,"Option add_hhlen is");
7893 IGNORE_PARAM_NEQ(fake_ll, 0, 0,"Option fake_ll is");
Linus Torvalds1da177e2005-04-16 15:20:36 -07007894}
7895
7896
7897static int
Frank Pavlic05e08a22005-05-12 20:39:09 +02007898__qeth_set_online(struct ccwgroup_device *gdev, int recovery_mode)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007899{
7900 struct qeth_card *card = gdev->dev.driver_data;
7901 int rc = 0;
7902 enum qeth_card_states recover_flag;
7903
7904 BUG_ON(!card);
7905 QETH_DBF_TEXT(setup ,2, "setonlin");
7906 QETH_DBF_HEX(setup, 2, &card, sizeof(void *));
7907
7908 qeth_set_allowed_threads(card, QETH_RECOVER_THREAD, 1);
7909 if (qeth_wait_for_threads(card, ~QETH_RECOVER_THREAD)){
7910 PRINT_WARN("set_online of card %s interrupted by user!\n",
7911 CARD_BUS_ID(card));
7912 return -ERESTARTSYS;
7913 }
7914
7915 recover_flag = card->state;
7916 if ((rc = ccw_device_set_online(CARD_RDEV(card))) ||
7917 (rc = ccw_device_set_online(CARD_WDEV(card))) ||
7918 (rc = ccw_device_set_online(CARD_DDEV(card)))){
7919 QETH_DBF_TEXT_(setup, 2, "1err%d", rc);
7920 return -EIO;
7921 }
7922
Ursula Braun500f83a2005-09-30 10:19:19 +02007923 qeth_make_parameters_consistent(card);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007924
7925 if ((rc = qeth_hardsetup_card(card))){
7926 QETH_DBF_TEXT_(setup, 2, "2err%d", rc);
7927 goto out_remove;
7928 }
7929 card->state = CARD_STATE_HARDSETUP;
7930
7931 if (!(rc = qeth_query_ipassists(card,QETH_PROT_IPV4)))
7932 rc = qeth_get_unique_id(card);
7933
7934 if (rc && card->options.layer2 == 0) {
7935 QETH_DBF_TEXT_(setup, 2, "3err%d", rc);
7936 goto out_remove;
7937 }
7938 qeth_print_status_message(card);
7939 if ((rc = qeth_register_netdev(card))){
7940 QETH_DBF_TEXT_(setup, 2, "4err%d", rc);
7941 goto out_remove;
7942 }
7943 if ((rc = qeth_softsetup_card(card))){
7944 QETH_DBF_TEXT_(setup, 2, "5err%d", rc);
7945 goto out_remove;
7946 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07007947
7948 if ((rc = qeth_init_qdio_queues(card))){
7949 QETH_DBF_TEXT_(setup, 2, "6err%d", rc);
7950 goto out_remove;
7951 }
Frank Pavlic09d2d382006-09-15 16:26:34 +02007952 card->state = CARD_STATE_SOFTSETUP;
Frank Pavlic4965e972005-12-13 08:22:30 +01007953 netif_carrier_on(card->dev);
7954
Linus Torvalds1da177e2005-04-16 15:20:36 -07007955 qeth_set_allowed_threads(card, 0xffffffff, 0);
7956 if (recover_flag == CARD_STATE_RECOVER)
Frank Pavlic05e08a22005-05-12 20:39:09 +02007957 qeth_start_again(card, recovery_mode);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007958 qeth_notify_processes();
7959 return 0;
7960out_remove:
7961 card->use_hard_stop = 1;
Frank Pavlic05e08a22005-05-12 20:39:09 +02007962 qeth_stop_card(card, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007963 ccw_device_set_offline(CARD_DDEV(card));
7964 ccw_device_set_offline(CARD_WDEV(card));
7965 ccw_device_set_offline(CARD_RDEV(card));
7966 if (recover_flag == CARD_STATE_RECOVER)
7967 card->state = CARD_STATE_RECOVER;
7968 else
7969 card->state = CARD_STATE_DOWN;
7970 return -ENODEV;
7971}
7972
Frank Pavlic05e08a22005-05-12 20:39:09 +02007973static int
7974qeth_set_online(struct ccwgroup_device *gdev)
7975{
7976 return __qeth_set_online(gdev, 0);
7977}
7978
Linus Torvalds1da177e2005-04-16 15:20:36 -07007979static struct ccw_device_id qeth_ids[] = {
Heiko Carstensd2c993d2006-07-12 16:41:55 +02007980 {CCW_DEVICE(0x1731, 0x01), .driver_info = QETH_CARD_TYPE_OSAE},
7981 {CCW_DEVICE(0x1731, 0x05), .driver_info = QETH_CARD_TYPE_IQD},
7982 {CCW_DEVICE(0x1731, 0x06), .driver_info = QETH_CARD_TYPE_OSN},
Linus Torvalds1da177e2005-04-16 15:20:36 -07007983 {},
7984};
7985MODULE_DEVICE_TABLE(ccw, qeth_ids);
7986
7987struct device *qeth_root_dev = NULL;
7988
7989struct ccwgroup_driver qeth_ccwgroup_driver = {
7990 .owner = THIS_MODULE,
7991 .name = "qeth",
7992 .driver_id = 0xD8C5E3C8,
7993 .probe = qeth_probe_device,
7994 .remove = qeth_remove_device,
7995 .set_online = qeth_set_online,
7996 .set_offline = qeth_set_offline,
7997};
7998
7999struct ccw_driver qeth_ccw_driver = {
8000 .name = "qeth",
8001 .ids = qeth_ids,
8002 .probe = ccwgroup_probe_ccwdev,
8003 .remove = ccwgroup_remove_ccwdev,
8004};
8005
8006
8007static void
8008qeth_unregister_dbf_views(void)
8009{
8010 if (qeth_dbf_setup)
8011 debug_unregister(qeth_dbf_setup);
8012 if (qeth_dbf_qerr)
8013 debug_unregister(qeth_dbf_qerr);
8014 if (qeth_dbf_sense)
8015 debug_unregister(qeth_dbf_sense);
8016 if (qeth_dbf_misc)
8017 debug_unregister(qeth_dbf_misc);
8018 if (qeth_dbf_data)
8019 debug_unregister(qeth_dbf_data);
8020 if (qeth_dbf_control)
8021 debug_unregister(qeth_dbf_control);
8022 if (qeth_dbf_trace)
8023 debug_unregister(qeth_dbf_trace);
8024}
8025static int
8026qeth_register_dbf_views(void)
8027{
8028 qeth_dbf_setup = debug_register(QETH_DBF_SETUP_NAME,
Michael Holzheu66a464d2005-06-25 14:55:33 -07008029 QETH_DBF_SETUP_PAGES,
Linus Torvalds1da177e2005-04-16 15:20:36 -07008030 QETH_DBF_SETUP_NR_AREAS,
8031 QETH_DBF_SETUP_LEN);
8032 qeth_dbf_misc = debug_register(QETH_DBF_MISC_NAME,
Michael Holzheu66a464d2005-06-25 14:55:33 -07008033 QETH_DBF_MISC_PAGES,
Linus Torvalds1da177e2005-04-16 15:20:36 -07008034 QETH_DBF_MISC_NR_AREAS,
8035 QETH_DBF_MISC_LEN);
8036 qeth_dbf_data = debug_register(QETH_DBF_DATA_NAME,
Michael Holzheu66a464d2005-06-25 14:55:33 -07008037 QETH_DBF_DATA_PAGES,
Linus Torvalds1da177e2005-04-16 15:20:36 -07008038 QETH_DBF_DATA_NR_AREAS,
8039 QETH_DBF_DATA_LEN);
8040 qeth_dbf_control = debug_register(QETH_DBF_CONTROL_NAME,
Michael Holzheu66a464d2005-06-25 14:55:33 -07008041 QETH_DBF_CONTROL_PAGES,
Linus Torvalds1da177e2005-04-16 15:20:36 -07008042 QETH_DBF_CONTROL_NR_AREAS,
8043 QETH_DBF_CONTROL_LEN);
8044 qeth_dbf_sense = debug_register(QETH_DBF_SENSE_NAME,
Michael Holzheu66a464d2005-06-25 14:55:33 -07008045 QETH_DBF_SENSE_PAGES,
Linus Torvalds1da177e2005-04-16 15:20:36 -07008046 QETH_DBF_SENSE_NR_AREAS,
8047 QETH_DBF_SENSE_LEN);
8048 qeth_dbf_qerr = debug_register(QETH_DBF_QERR_NAME,
Michael Holzheu66a464d2005-06-25 14:55:33 -07008049 QETH_DBF_QERR_PAGES,
Linus Torvalds1da177e2005-04-16 15:20:36 -07008050 QETH_DBF_QERR_NR_AREAS,
8051 QETH_DBF_QERR_LEN);
8052 qeth_dbf_trace = debug_register(QETH_DBF_TRACE_NAME,
Michael Holzheu66a464d2005-06-25 14:55:33 -07008053 QETH_DBF_TRACE_PAGES,
Linus Torvalds1da177e2005-04-16 15:20:36 -07008054 QETH_DBF_TRACE_NR_AREAS,
8055 QETH_DBF_TRACE_LEN);
8056
8057 if ((qeth_dbf_setup == NULL) || (qeth_dbf_misc == NULL) ||
8058 (qeth_dbf_data == NULL) || (qeth_dbf_control == NULL) ||
8059 (qeth_dbf_sense == NULL) || (qeth_dbf_qerr == NULL) ||
8060 (qeth_dbf_trace == NULL)) {
8061 qeth_unregister_dbf_views();
8062 return -ENOMEM;
8063 }
8064 debug_register_view(qeth_dbf_setup, &debug_hex_ascii_view);
8065 debug_set_level(qeth_dbf_setup, QETH_DBF_SETUP_LEVEL);
8066
8067 debug_register_view(qeth_dbf_misc, &debug_hex_ascii_view);
8068 debug_set_level(qeth_dbf_misc, QETH_DBF_MISC_LEVEL);
8069
8070 debug_register_view(qeth_dbf_data, &debug_hex_ascii_view);
8071 debug_set_level(qeth_dbf_data, QETH_DBF_DATA_LEVEL);
8072
8073 debug_register_view(qeth_dbf_control, &debug_hex_ascii_view);
8074 debug_set_level(qeth_dbf_control, QETH_DBF_CONTROL_LEVEL);
8075
8076 debug_register_view(qeth_dbf_sense, &debug_hex_ascii_view);
8077 debug_set_level(qeth_dbf_sense, QETH_DBF_SENSE_LEVEL);
8078
8079 debug_register_view(qeth_dbf_qerr, &debug_hex_ascii_view);
8080 debug_set_level(qeth_dbf_qerr, QETH_DBF_QERR_LEVEL);
8081
8082 debug_register_view(qeth_dbf_trace, &debug_hex_ascii_view);
8083 debug_set_level(qeth_dbf_trace, QETH_DBF_TRACE_LEVEL);
8084
8085 return 0;
8086}
8087
8088#ifdef CONFIG_QETH_IPV6
8089extern struct neigh_table arp_tbl;
8090static struct neigh_ops *arp_direct_ops;
8091static int (*qeth_old_arp_constructor) (struct neighbour *);
8092
8093static struct neigh_ops arp_direct_ops_template = {
8094 .family = AF_INET,
Linus Torvalds1da177e2005-04-16 15:20:36 -07008095 .solicit = NULL,
8096 .error_report = NULL,
8097 .output = dev_queue_xmit,
8098 .connected_output = dev_queue_xmit,
8099 .hh_output = dev_queue_xmit,
8100 .queue_xmit = dev_queue_xmit
8101};
8102
8103static int
8104qeth_arp_constructor(struct neighbour *neigh)
8105{
8106 struct net_device *dev = neigh->dev;
8107 struct in_device *in_dev;
8108 struct neigh_parms *parms;
8109 struct qeth_card *card;
8110
8111 card = qeth_get_card_from_dev(dev);
8112 if (card == NULL)
8113 goto out;
8114 if((card->options.layer2) ||
8115 (card->dev->hard_header == qeth_fake_header))
8116 goto out;
8117
8118 rcu_read_lock();
Herbert Xue5ed6392005-10-03 14:35:55 -07008119 in_dev = __in_dev_get_rcu(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07008120 if (in_dev == NULL) {
8121 rcu_read_unlock();
8122 return -EINVAL;
8123 }
8124
8125 parms = in_dev->arp_parms;
8126 __neigh_parms_put(neigh->parms);
8127 neigh->parms = neigh_parms_clone(parms);
8128 rcu_read_unlock();
8129
Al Virofd683222006-09-26 22:17:51 -07008130 neigh->type = inet_addr_type(*(__be32 *) neigh->primary_key);
Linus Torvalds1da177e2005-04-16 15:20:36 -07008131 neigh->nud_state = NUD_NOARP;
8132 neigh->ops = arp_direct_ops;
8133 neigh->output = neigh->ops->queue_xmit;
8134 return 0;
8135out:
8136 return qeth_old_arp_constructor(neigh);
8137}
8138#endif /*CONFIG_QETH_IPV6*/
8139
8140/*
8141 * IP address takeover related functions
8142 */
8143static void
8144qeth_clear_ipato_list(struct qeth_card *card)
8145{
8146 struct qeth_ipato_entry *ipatoe, *tmp;
8147 unsigned long flags;
8148
8149 spin_lock_irqsave(&card->ip_lock, flags);
8150 list_for_each_entry_safe(ipatoe, tmp, &card->ipato.entries, entry) {
8151 list_del(&ipatoe->entry);
8152 kfree(ipatoe);
8153 }
8154 spin_unlock_irqrestore(&card->ip_lock, flags);
8155}
8156
8157int
8158qeth_add_ipato_entry(struct qeth_card *card, struct qeth_ipato_entry *new)
8159{
8160 struct qeth_ipato_entry *ipatoe;
8161 unsigned long flags;
8162 int rc = 0;
8163
8164 QETH_DBF_TEXT(trace, 2, "addipato");
8165 spin_lock_irqsave(&card->ip_lock, flags);
8166 list_for_each_entry(ipatoe, &card->ipato.entries, entry){
8167 if (ipatoe->proto != new->proto)
8168 continue;
8169 if (!memcmp(ipatoe->addr, new->addr,
8170 (ipatoe->proto == QETH_PROT_IPV4)? 4:16) &&
8171 (ipatoe->mask_bits == new->mask_bits)){
8172 PRINT_WARN("ipato entry already exists!\n");
8173 rc = -EEXIST;
8174 break;
8175 }
8176 }
8177 if (!rc) {
8178 list_add_tail(&new->entry, &card->ipato.entries);
8179 }
8180 spin_unlock_irqrestore(&card->ip_lock, flags);
8181 return rc;
8182}
8183
8184void
8185qeth_del_ipato_entry(struct qeth_card *card, enum qeth_prot_versions proto,
8186 u8 *addr, int mask_bits)
8187{
8188 struct qeth_ipato_entry *ipatoe, *tmp;
8189 unsigned long flags;
8190
8191 QETH_DBF_TEXT(trace, 2, "delipato");
8192 spin_lock_irqsave(&card->ip_lock, flags);
8193 list_for_each_entry_safe(ipatoe, tmp, &card->ipato.entries, entry){
8194 if (ipatoe->proto != proto)
8195 continue;
8196 if (!memcmp(ipatoe->addr, addr,
8197 (proto == QETH_PROT_IPV4)? 4:16) &&
8198 (ipatoe->mask_bits == mask_bits)){
8199 list_del(&ipatoe->entry);
8200 kfree(ipatoe);
8201 }
8202 }
8203 spin_unlock_irqrestore(&card->ip_lock, flags);
8204}
8205
Heiko Carstens4d284ca2007-02-05 21:18:53 +01008206static void
Linus Torvalds1da177e2005-04-16 15:20:36 -07008207qeth_convert_addr_to_bits(u8 *addr, u8 *bits, int len)
8208{
8209 int i, j;
8210 u8 octet;
8211
8212 for (i = 0; i < len; ++i){
8213 octet = addr[i];
8214 for (j = 7; j >= 0; --j){
8215 bits[i*8 + j] = octet & 1;
8216 octet >>= 1;
8217 }
8218 }
8219}
8220
8221static int
8222qeth_is_addr_covered_by_ipato(struct qeth_card *card, struct qeth_ipaddr *addr)
8223{
8224 struct qeth_ipato_entry *ipatoe;
8225 u8 addr_bits[128] = {0, };
8226 u8 ipatoe_bits[128] = {0, };
8227 int rc = 0;
8228
8229 if (!card->ipato.enabled)
8230 return 0;
8231
8232 qeth_convert_addr_to_bits((u8 *) &addr->u, addr_bits,
8233 (addr->proto == QETH_PROT_IPV4)? 4:16);
8234 list_for_each_entry(ipatoe, &card->ipato.entries, entry){
8235 if (addr->proto != ipatoe->proto)
8236 continue;
8237 qeth_convert_addr_to_bits(ipatoe->addr, ipatoe_bits,
8238 (ipatoe->proto==QETH_PROT_IPV4) ?
8239 4:16);
8240 if (addr->proto == QETH_PROT_IPV4)
8241 rc = !memcmp(addr_bits, ipatoe_bits,
8242 min(32, ipatoe->mask_bits));
8243 else
8244 rc = !memcmp(addr_bits, ipatoe_bits,
8245 min(128, ipatoe->mask_bits));
8246 if (rc)
8247 break;
8248 }
8249 /* invert? */
8250 if ((addr->proto == QETH_PROT_IPV4) && card->ipato.invert4)
8251 rc = !rc;
8252 else if ((addr->proto == QETH_PROT_IPV6) && card->ipato.invert6)
8253 rc = !rc;
8254
8255 return rc;
8256}
8257
8258/*
8259 * VIPA related functions
8260 */
8261int
8262qeth_add_vipa(struct qeth_card *card, enum qeth_prot_versions proto,
8263 const u8 *addr)
8264{
8265 struct qeth_ipaddr *ipaddr;
8266 unsigned long flags;
8267 int rc = 0;
8268
8269 ipaddr = qeth_get_addr_buffer(proto);
8270 if (ipaddr){
8271 if (proto == QETH_PROT_IPV4){
8272 QETH_DBF_TEXT(trace, 2, "addvipa4");
8273 memcpy(&ipaddr->u.a4.addr, addr, 4);
8274 ipaddr->u.a4.mask = 0;
8275#ifdef CONFIG_QETH_IPV6
8276 } else if (proto == QETH_PROT_IPV6){
8277 QETH_DBF_TEXT(trace, 2, "addvipa6");
8278 memcpy(&ipaddr->u.a6.addr, addr, 16);
8279 ipaddr->u.a6.pfxlen = 0;
8280#endif
8281 }
8282 ipaddr->type = QETH_IP_TYPE_VIPA;
8283 ipaddr->set_flags = QETH_IPA_SETIP_VIPA_FLAG;
8284 ipaddr->del_flags = QETH_IPA_DELIP_VIPA_FLAG;
8285 } else
8286 return -ENOMEM;
8287 spin_lock_irqsave(&card->ip_lock, flags);
8288 if (__qeth_address_exists_in_list(&card->ip_list, ipaddr, 0) ||
8289 __qeth_address_exists_in_list(card->ip_tbd_list, ipaddr, 0))
8290 rc = -EEXIST;
8291 spin_unlock_irqrestore(&card->ip_lock, flags);
8292 if (rc){
8293 PRINT_WARN("Cannot add VIPA. Address already exists!\n");
8294 return rc;
8295 }
8296 if (!qeth_add_ip(card, ipaddr))
8297 kfree(ipaddr);
Frank Blaschkaee2db682007-01-08 17:30:11 +01008298 qeth_set_ip_addr_list(card);
Linus Torvalds1da177e2005-04-16 15:20:36 -07008299 return rc;
8300}
8301
8302void
8303qeth_del_vipa(struct qeth_card *card, enum qeth_prot_versions proto,
8304 const u8 *addr)
8305{
8306 struct qeth_ipaddr *ipaddr;
8307
8308 ipaddr = qeth_get_addr_buffer(proto);
8309 if (ipaddr){
8310 if (proto == QETH_PROT_IPV4){
8311 QETH_DBF_TEXT(trace, 2, "delvipa4");
8312 memcpy(&ipaddr->u.a4.addr, addr, 4);
8313 ipaddr->u.a4.mask = 0;
8314#ifdef CONFIG_QETH_IPV6
8315 } else if (proto == QETH_PROT_IPV6){
8316 QETH_DBF_TEXT(trace, 2, "delvipa6");
8317 memcpy(&ipaddr->u.a6.addr, addr, 16);
8318 ipaddr->u.a6.pfxlen = 0;
8319#endif
8320 }
8321 ipaddr->type = QETH_IP_TYPE_VIPA;
8322 } else
8323 return;
8324 if (!qeth_delete_ip(card, ipaddr))
8325 kfree(ipaddr);
Frank Blaschkaee2db682007-01-08 17:30:11 +01008326 qeth_set_ip_addr_list(card);
Linus Torvalds1da177e2005-04-16 15:20:36 -07008327}
8328
8329/*
8330 * proxy ARP related functions
8331 */
8332int
8333qeth_add_rxip(struct qeth_card *card, enum qeth_prot_versions proto,
8334 const u8 *addr)
8335{
8336 struct qeth_ipaddr *ipaddr;
8337 unsigned long flags;
8338 int rc = 0;
8339
8340 ipaddr = qeth_get_addr_buffer(proto);
8341 if (ipaddr){
8342 if (proto == QETH_PROT_IPV4){
8343 QETH_DBF_TEXT(trace, 2, "addrxip4");
8344 memcpy(&ipaddr->u.a4.addr, addr, 4);
8345 ipaddr->u.a4.mask = 0;
8346#ifdef CONFIG_QETH_IPV6
8347 } else if (proto == QETH_PROT_IPV6){
8348 QETH_DBF_TEXT(trace, 2, "addrxip6");
8349 memcpy(&ipaddr->u.a6.addr, addr, 16);
8350 ipaddr->u.a6.pfxlen = 0;
8351#endif
8352 }
8353 ipaddr->type = QETH_IP_TYPE_RXIP;
8354 ipaddr->set_flags = QETH_IPA_SETIP_TAKEOVER_FLAG;
8355 ipaddr->del_flags = 0;
8356 } else
8357 return -ENOMEM;
8358 spin_lock_irqsave(&card->ip_lock, flags);
8359 if (__qeth_address_exists_in_list(&card->ip_list, ipaddr, 0) ||
8360 __qeth_address_exists_in_list(card->ip_tbd_list, ipaddr, 0))
8361 rc = -EEXIST;
8362 spin_unlock_irqrestore(&card->ip_lock, flags);
8363 if (rc){
8364 PRINT_WARN("Cannot add RXIP. Address already exists!\n");
8365 return rc;
8366 }
8367 if (!qeth_add_ip(card, ipaddr))
8368 kfree(ipaddr);
Frank Blaschkaee2db682007-01-08 17:30:11 +01008369 qeth_set_ip_addr_list(card);
Linus Torvalds1da177e2005-04-16 15:20:36 -07008370 return 0;
8371}
8372
8373void
8374qeth_del_rxip(struct qeth_card *card, enum qeth_prot_versions proto,
8375 const u8 *addr)
8376{
8377 struct qeth_ipaddr *ipaddr;
8378
8379 ipaddr = qeth_get_addr_buffer(proto);
8380 if (ipaddr){
8381 if (proto == QETH_PROT_IPV4){
8382 QETH_DBF_TEXT(trace, 2, "addrxip4");
8383 memcpy(&ipaddr->u.a4.addr, addr, 4);
8384 ipaddr->u.a4.mask = 0;
8385#ifdef CONFIG_QETH_IPV6
8386 } else if (proto == QETH_PROT_IPV6){
8387 QETH_DBF_TEXT(trace, 2, "addrxip6");
8388 memcpy(&ipaddr->u.a6.addr, addr, 16);
8389 ipaddr->u.a6.pfxlen = 0;
8390#endif
8391 }
8392 ipaddr->type = QETH_IP_TYPE_RXIP;
8393 } else
8394 return;
8395 if (!qeth_delete_ip(card, ipaddr))
8396 kfree(ipaddr);
Frank Blaschkaee2db682007-01-08 17:30:11 +01008397 qeth_set_ip_addr_list(card);
Linus Torvalds1da177e2005-04-16 15:20:36 -07008398}
8399
8400/**
8401 * IP event handler
8402 */
8403static int
8404qeth_ip_event(struct notifier_block *this,
8405 unsigned long event,void *ptr)
8406{
8407 struct in_ifaddr *ifa = (struct in_ifaddr *)ptr;
8408 struct net_device *dev =(struct net_device *) ifa->ifa_dev->dev;
8409 struct qeth_ipaddr *addr;
8410 struct qeth_card *card;
8411
8412 QETH_DBF_TEXT(trace,3,"ipevent");
8413 card = qeth_get_card_from_dev(dev);
8414 if (!card)
8415 return NOTIFY_DONE;
8416 if (card->options.layer2)
8417 return NOTIFY_DONE;
8418
8419 addr = qeth_get_addr_buffer(QETH_PROT_IPV4);
8420 if (addr != NULL) {
8421 addr->u.a4.addr = ifa->ifa_address;
8422 addr->u.a4.mask = ifa->ifa_mask;
8423 addr->type = QETH_IP_TYPE_NORMAL;
8424 } else
8425 goto out;
8426
8427 switch(event) {
8428 case NETDEV_UP:
8429 if (!qeth_add_ip(card, addr))
8430 kfree(addr);
8431 break;
8432 case NETDEV_DOWN:
8433 if (!qeth_delete_ip(card, addr))
8434 kfree(addr);
8435 break;
8436 default:
8437 break;
8438 }
Frank Blaschkaee2db682007-01-08 17:30:11 +01008439 qeth_set_ip_addr_list(card);
Linus Torvalds1da177e2005-04-16 15:20:36 -07008440out:
8441 return NOTIFY_DONE;
8442}
8443
8444static struct notifier_block qeth_ip_notifier = {
8445 qeth_ip_event,
Heiko Carstensd2c993d2006-07-12 16:41:55 +02008446 NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07008447};
8448
8449#ifdef CONFIG_QETH_IPV6
8450/**
8451 * IPv6 event handler
8452 */
8453static int
8454qeth_ip6_event(struct notifier_block *this,
8455 unsigned long event,void *ptr)
8456{
8457
8458 struct inet6_ifaddr *ifa = (struct inet6_ifaddr *)ptr;
8459 struct net_device *dev = (struct net_device *)ifa->idev->dev;
8460 struct qeth_ipaddr *addr;
8461 struct qeth_card *card;
8462
8463 QETH_DBF_TEXT(trace,3,"ip6event");
8464
8465 card = qeth_get_card_from_dev(dev);
8466 if (!card)
8467 return NOTIFY_DONE;
8468 if (!qeth_is_supported(card, IPA_IPV6))
8469 return NOTIFY_DONE;
8470
8471 addr = qeth_get_addr_buffer(QETH_PROT_IPV6);
8472 if (addr != NULL) {
8473 memcpy(&addr->u.a6.addr, &ifa->addr, sizeof(struct in6_addr));
8474 addr->u.a6.pfxlen = ifa->prefix_len;
8475 addr->type = QETH_IP_TYPE_NORMAL;
8476 } else
8477 goto out;
8478
8479 switch(event) {
8480 case NETDEV_UP:
8481 if (!qeth_add_ip(card, addr))
8482 kfree(addr);
8483 break;
8484 case NETDEV_DOWN:
8485 if (!qeth_delete_ip(card, addr))
8486 kfree(addr);
8487 break;
8488 default:
8489 break;
8490 }
Frank Blaschkaee2db682007-01-08 17:30:11 +01008491 qeth_set_ip_addr_list(card);
Linus Torvalds1da177e2005-04-16 15:20:36 -07008492out:
8493 return NOTIFY_DONE;
8494}
8495
8496static struct notifier_block qeth_ip6_notifier = {
8497 qeth_ip6_event,
Heiko Carstensd2c993d2006-07-12 16:41:55 +02008498 NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07008499};
8500#endif
8501
8502static int
Cornelia Huck66aea232005-08-08 09:22:36 -07008503__qeth_reboot_event_card(struct device *dev, void *data)
8504{
8505 struct qeth_card *card;
8506
8507 card = (struct qeth_card *) dev->driver_data;
8508 qeth_clear_ip_list(card, 0, 0);
8509 qeth_qdio_clear_card(card, 0);
Ursula Braun1f8bdae2007-05-02 15:18:07 +02008510 qeth_clear_qdio_buffers(card);
Cornelia Huck66aea232005-08-08 09:22:36 -07008511 return 0;
8512}
8513
8514static int
Linus Torvalds1da177e2005-04-16 15:20:36 -07008515qeth_reboot_event(struct notifier_block *this, unsigned long event, void *ptr)
8516{
Heiko Carstensd7cf0d52006-07-18 13:46:58 +02008517 int ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07008518
Heiko Carstensd7cf0d52006-07-18 13:46:58 +02008519 ret = driver_for_each_device(&qeth_ccwgroup_driver.driver, NULL, NULL,
8520 __qeth_reboot_event_card);
8521 return ret ? NOTIFY_BAD : NOTIFY_DONE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07008522}
8523
8524
8525static struct notifier_block qeth_reboot_notifier = {
8526 qeth_reboot_event,
Heiko Carstensd2c993d2006-07-12 16:41:55 +02008527 NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07008528};
8529
8530static int
8531qeth_register_notifiers(void)
8532{
8533 int r;
8534
8535 QETH_DBF_TEXT(trace,5,"regnotif");
8536 if ((r = register_reboot_notifier(&qeth_reboot_notifier)))
8537 return r;
8538 if ((r = register_inetaddr_notifier(&qeth_ip_notifier)))
8539 goto out_reboot;
8540#ifdef CONFIG_QETH_IPV6
8541 if ((r = register_inet6addr_notifier(&qeth_ip6_notifier)))
8542 goto out_ipv4;
8543#endif
8544 return 0;
8545
8546#ifdef CONFIG_QETH_IPV6
8547out_ipv4:
8548 unregister_inetaddr_notifier(&qeth_ip_notifier);
8549#endif
8550out_reboot:
8551 unregister_reboot_notifier(&qeth_reboot_notifier);
8552 return r;
8553}
8554
8555/**
8556 * unregister all event notifiers
8557 */
8558static void
8559qeth_unregister_notifiers(void)
8560{
8561
8562 QETH_DBF_TEXT(trace,5,"unregnot");
8563 BUG_ON(unregister_reboot_notifier(&qeth_reboot_notifier));
8564 BUG_ON(unregister_inetaddr_notifier(&qeth_ip_notifier));
8565#ifdef CONFIG_QETH_IPV6
8566 BUG_ON(unregister_inet6addr_notifier(&qeth_ip6_notifier));
8567#endif /* QETH_IPV6 */
8568
8569}
8570
8571#ifdef CONFIG_QETH_IPV6
8572static int
8573qeth_ipv6_init(void)
8574{
8575 qeth_old_arp_constructor = arp_tbl.constructor;
Heiko Carstens3d8f3f32006-08-14 23:00:27 -07008576 write_lock_bh(&arp_tbl.lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07008577 arp_tbl.constructor = qeth_arp_constructor;
Heiko Carstens3d8f3f32006-08-14 23:00:27 -07008578 write_unlock_bh(&arp_tbl.lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07008579
8580 arp_direct_ops = (struct neigh_ops*)
8581 kmalloc(sizeof(struct neigh_ops), GFP_KERNEL);
8582 if (!arp_direct_ops)
8583 return -ENOMEM;
8584
8585 memcpy(arp_direct_ops, &arp_direct_ops_template,
8586 sizeof(struct neigh_ops));
8587
8588 return 0;
8589}
8590
8591static void
8592qeth_ipv6_uninit(void)
8593{
Heiko Carstens3d8f3f32006-08-14 23:00:27 -07008594 write_lock_bh(&arp_tbl.lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07008595 arp_tbl.constructor = qeth_old_arp_constructor;
Heiko Carstens3d8f3f32006-08-14 23:00:27 -07008596 write_unlock_bh(&arp_tbl.lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07008597 kfree(arp_direct_ops);
8598}
8599#endif /* CONFIG_QETH_IPV6 */
8600
8601static void
8602qeth_sysfs_unregister(void)
8603{
Frank Pavlic8b98a372006-09-15 16:27:02 +02008604 s390_root_dev_unregister(qeth_root_dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07008605 qeth_remove_driver_attributes();
8606 ccw_driver_unregister(&qeth_ccw_driver);
8607 ccwgroup_driver_unregister(&qeth_ccwgroup_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -07008608}
Frank Pavlic8b98a372006-09-15 16:27:02 +02008609
Linus Torvalds1da177e2005-04-16 15:20:36 -07008610/**
8611 * register qeth at sysfs
8612 */
8613static int
8614qeth_sysfs_register(void)
8615{
Frank Pavlic8b98a372006-09-15 16:27:02 +02008616 int rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07008617
8618 rc = ccwgroup_driver_register(&qeth_ccwgroup_driver);
8619 if (rc)
Frank Pavlic8b98a372006-09-15 16:27:02 +02008620 goto out;
8621
Linus Torvalds1da177e2005-04-16 15:20:36 -07008622 rc = ccw_driver_register(&qeth_ccw_driver);
8623 if (rc)
Frank Pavlic8b98a372006-09-15 16:27:02 +02008624 goto out_ccw_driver;
8625
Linus Torvalds1da177e2005-04-16 15:20:36 -07008626 rc = qeth_create_driver_attributes();
8627 if (rc)
Frank Pavlic8b98a372006-09-15 16:27:02 +02008628 goto out_qeth_attr;
8629
Linus Torvalds1da177e2005-04-16 15:20:36 -07008630 qeth_root_dev = s390_root_dev_register("qeth");
Frank Pavlic8b98a372006-09-15 16:27:02 +02008631 rc = IS_ERR(qeth_root_dev) ? PTR_ERR(qeth_root_dev) : 0;
8632 if (!rc)
8633 goto out;
8634
8635 qeth_remove_driver_attributes();
8636out_qeth_attr:
8637 ccw_driver_unregister(&qeth_ccw_driver);
8638out_ccw_driver:
8639 ccwgroup_driver_unregister(&qeth_ccwgroup_driver);
8640out:
8641 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07008642}
8643
8644/***
8645 * init function
8646 */
8647static int __init
8648qeth_init(void)
8649{
Frank Pavlic8b98a372006-09-15 16:27:02 +02008650 int rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07008651
Heiko Carstense018ba12006-02-01 03:06:31 -08008652 PRINT_INFO("loading %s\n", version);
Linus Torvalds1da177e2005-04-16 15:20:36 -07008653
8654 INIT_LIST_HEAD(&qeth_card_list.list);
8655 INIT_LIST_HEAD(&qeth_notify_list);
8656 spin_lock_init(&qeth_notify_lock);
8657 rwlock_init(&qeth_card_list.rwlock);
8658
Frank Pavlic8b98a372006-09-15 16:27:02 +02008659 rc = qeth_register_dbf_views();
8660 if (rc)
Linus Torvalds1da177e2005-04-16 15:20:36 -07008661 goto out_err;
Frank Pavlic8b98a372006-09-15 16:27:02 +02008662
8663 rc = qeth_sysfs_register();
8664 if (rc)
8665 goto out_dbf;
Linus Torvalds1da177e2005-04-16 15:20:36 -07008666
8667#ifdef CONFIG_QETH_IPV6
Frank Pavlic8b98a372006-09-15 16:27:02 +02008668 rc = qeth_ipv6_init();
8669 if (rc) {
8670 PRINT_ERR("Out of memory during ipv6 init code = %d\n", rc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07008671 goto out_sysfs;
8672 }
8673#endif /* QETH_IPV6 */
Frank Pavlic8b98a372006-09-15 16:27:02 +02008674 rc = qeth_register_notifiers();
8675 if (rc)
Linus Torvalds1da177e2005-04-16 15:20:36 -07008676 goto out_ipv6;
Frank Pavlic8b98a372006-09-15 16:27:02 +02008677 rc = qeth_create_procfs_entries();
8678 if (rc)
Linus Torvalds1da177e2005-04-16 15:20:36 -07008679 goto out_notifiers;
8680
8681 return rc;
8682
8683out_notifiers:
8684 qeth_unregister_notifiers();
8685out_ipv6:
8686#ifdef CONFIG_QETH_IPV6
8687 qeth_ipv6_uninit();
Linus Torvalds1da177e2005-04-16 15:20:36 -07008688out_sysfs:
Frank Pavlic8b98a372006-09-15 16:27:02 +02008689#endif /* QETH_IPV6 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07008690 qeth_sysfs_unregister();
Frank Pavlic8b98a372006-09-15 16:27:02 +02008691out_dbf:
Linus Torvalds1da177e2005-04-16 15:20:36 -07008692 qeth_unregister_dbf_views();
8693out_err:
Frank Pavlic8b98a372006-09-15 16:27:02 +02008694 PRINT_ERR("Initialization failed with code %d\n", rc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07008695 return rc;
8696}
8697
8698static void
8699__exit qeth_exit(void)
8700{
8701 struct qeth_card *card, *tmp;
8702 unsigned long flags;
8703
8704 QETH_DBF_TEXT(trace,1, "cleanup.");
8705
8706 /*
8707 * Weed would not need to clean up our devices here, because the
8708 * common device layer calls qeth_remove_device for each device
8709 * as soon as we unregister our driver (done in qeth_sysfs_unregister).
8710 * But we do cleanup here so we can do a "soft" shutdown of our cards.
8711 * qeth_remove_device called by the common device layer would otherwise
8712 * do a "hard" shutdown (card->use_hard_stop is set to one in
8713 * qeth_remove_device).
8714 */
8715again:
8716 read_lock_irqsave(&qeth_card_list.rwlock, flags);
8717 list_for_each_entry_safe(card, tmp, &qeth_card_list.list, list){
8718 read_unlock_irqrestore(&qeth_card_list.rwlock, flags);
8719 qeth_set_offline(card->gdev);
8720 qeth_remove_device(card->gdev);
8721 goto again;
8722 }
8723 read_unlock_irqrestore(&qeth_card_list.rwlock, flags);
8724#ifdef CONFIG_QETH_IPV6
8725 qeth_ipv6_uninit();
8726#endif
8727 qeth_unregister_notifiers();
8728 qeth_remove_procfs_entries();
8729 qeth_sysfs_unregister();
8730 qeth_unregister_dbf_views();
8731 printk("qeth: removed\n");
8732}
8733
Ursula Braun500f83a2005-09-30 10:19:19 +02008734EXPORT_SYMBOL(qeth_osn_register);
8735EXPORT_SYMBOL(qeth_osn_deregister);
8736EXPORT_SYMBOL(qeth_osn_assist);
Linus Torvalds1da177e2005-04-16 15:20:36 -07008737module_init(qeth_init);
8738module_exit(qeth_exit);
Frank Pavlic1387780f2005-11-10 13:51:42 +01008739MODULE_AUTHOR("Frank Pavlic <fpavlic@de.ibm.com>");
Linus Torvalds1da177e2005-04-16 15:20:36 -07008740MODULE_DESCRIPTION("Linux on zSeries OSA Express and HiperSockets support\n" \
8741 "Copyright 2000,2003 IBM Corporation\n");
8742
8743MODULE_LICENSE("GPL");