[ARM] pxa: update defconfig for Verdex Pro
[linux-2.6/verdex.git] / drivers / s390 / net / qeth_l2_main.c
blobf4f3ca1393b2cfff609b9797b85f1769fa64e21a
1 /*
2 * drivers/s390/net/qeth_l2_main.c
4 * Copyright IBM Corp. 2007, 2009
5 * Author(s): Utz Bacher <utz.bacher@de.ibm.com>,
6 * Frank Pavlic <fpavlic@de.ibm.com>,
7 * Thomas Spatzier <tspat@de.ibm.com>,
8 * Frank Blaschka <frank.blaschka@de.ibm.com>
9 */
11 #define KMSG_COMPONENT "qeth"
12 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
14 #include <linux/module.h>
15 #include <linux/moduleparam.h>
16 #include <linux/string.h>
17 #include <linux/errno.h>
18 #include <linux/kernel.h>
19 #include <linux/etherdevice.h>
20 #include <linux/mii.h>
21 #include <linux/ip.h>
22 #include <linux/list.h>
24 #include "qeth_core.h"
26 static int qeth_l2_set_offline(struct ccwgroup_device *);
27 static int qeth_l2_stop(struct net_device *);
28 static int qeth_l2_send_delmac(struct qeth_card *, __u8 *);
29 static int qeth_l2_send_setdelmac(struct qeth_card *, __u8 *,
30 enum qeth_ipa_cmds,
31 int (*reply_cb) (struct qeth_card *,
32 struct qeth_reply*,
33 unsigned long));
34 static void qeth_l2_set_multicast_list(struct net_device *);
35 static int qeth_l2_recover(void *);
37 static int qeth_l2_do_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
39 struct qeth_card *card = dev->ml_priv;
40 struct mii_ioctl_data *mii_data;
41 int rc = 0;
43 if (!card)
44 return -ENODEV;
46 if ((card->state != CARD_STATE_UP) &&
47 (card->state != CARD_STATE_SOFTSETUP))
48 return -ENODEV;
50 if (card->info.type == QETH_CARD_TYPE_OSN)
51 return -EPERM;
53 switch (cmd) {
54 case SIOC_QETH_ADP_SET_SNMP_CONTROL:
55 rc = qeth_snmp_command(card, rq->ifr_ifru.ifru_data);
56 break;
57 case SIOC_QETH_GET_CARD_TYPE:
58 if ((card->info.type == QETH_CARD_TYPE_OSAE) &&
59 !card->info.guestlan)
60 return 1;
61 return 0;
62 break;
63 case SIOCGMIIPHY:
64 mii_data = if_mii(rq);
65 mii_data->phy_id = 0;
66 break;
67 case SIOCGMIIREG:
68 mii_data = if_mii(rq);
69 if (mii_data->phy_id != 0)
70 rc = -EINVAL;
71 else
72 mii_data->val_out = qeth_mdio_read(dev,
73 mii_data->phy_id, mii_data->reg_num);
74 break;
75 default:
76 rc = -EOPNOTSUPP;
78 if (rc)
79 QETH_DBF_TEXT_(TRACE, 2, "ioce%d", rc);
80 return rc;
83 static int qeth_l2_verify_dev(struct net_device *dev)
85 struct qeth_card *card;
86 unsigned long flags;
87 int rc = 0;
89 read_lock_irqsave(&qeth_core_card_list.rwlock, flags);
90 list_for_each_entry(card, &qeth_core_card_list.list, list) {
91 if (card->dev == dev) {
92 rc = QETH_REAL_CARD;
93 break;
96 read_unlock_irqrestore(&qeth_core_card_list.rwlock, flags);
98 return rc;
101 static struct net_device *qeth_l2_netdev_by_devno(unsigned char *read_dev_no)
103 struct qeth_card *card;
104 struct net_device *ndev;
105 __u16 temp_dev_no;
106 unsigned long flags;
107 struct ccw_dev_id read_devid;
109 ndev = NULL;
110 memcpy(&temp_dev_no, read_dev_no, 2);
111 read_lock_irqsave(&qeth_core_card_list.rwlock, flags);
112 list_for_each_entry(card, &qeth_core_card_list.list, list) {
113 ccw_device_get_id(CARD_RDEV(card), &read_devid);
114 if (read_devid.devno == temp_dev_no) {
115 ndev = card->dev;
116 break;
119 read_unlock_irqrestore(&qeth_core_card_list.rwlock, flags);
120 return ndev;
123 static int qeth_l2_send_setgroupmac_cb(struct qeth_card *card,
124 struct qeth_reply *reply,
125 unsigned long data)
127 struct qeth_ipa_cmd *cmd;
128 __u8 *mac;
130 QETH_DBF_TEXT(TRACE, 2, "L2Sgmacb");
131 cmd = (struct qeth_ipa_cmd *) data;
132 mac = &cmd->data.setdelmac.mac[0];
133 /* MAC already registered, needed in couple/uncouple case */
134 if (cmd->hdr.return_code == IPA_RC_L2_DUP_MAC) {
135 QETH_DBF_MESSAGE(2, "Group MAC %pM already existing on %s \n",
136 mac, QETH_CARD_IFNAME(card));
137 cmd->hdr.return_code = 0;
139 if (cmd->hdr.return_code)
140 QETH_DBF_MESSAGE(2, "Could not set group MAC %pM on %s: %x\n",
141 mac, QETH_CARD_IFNAME(card), cmd->hdr.return_code);
142 return 0;
145 static int qeth_l2_send_setgroupmac(struct qeth_card *card, __u8 *mac)
147 QETH_DBF_TEXT(TRACE, 2, "L2Sgmac");
148 return qeth_l2_send_setdelmac(card, mac, IPA_CMD_SETGMAC,
149 qeth_l2_send_setgroupmac_cb);
152 static int qeth_l2_send_delgroupmac_cb(struct qeth_card *card,
153 struct qeth_reply *reply,
154 unsigned long data)
156 struct qeth_ipa_cmd *cmd;
157 __u8 *mac;
159 QETH_DBF_TEXT(TRACE, 2, "L2Dgmacb");
160 cmd = (struct qeth_ipa_cmd *) data;
161 mac = &cmd->data.setdelmac.mac[0];
162 if (cmd->hdr.return_code)
163 QETH_DBF_MESSAGE(2, "Could not delete group MAC %pM on %s: %x\n",
164 mac, QETH_CARD_IFNAME(card), cmd->hdr.return_code);
165 return 0;
168 static int qeth_l2_send_delgroupmac(struct qeth_card *card, __u8 *mac)
170 QETH_DBF_TEXT(TRACE, 2, "L2Dgmac");
171 return qeth_l2_send_setdelmac(card, mac, IPA_CMD_DELGMAC,
172 qeth_l2_send_delgroupmac_cb);
175 static void qeth_l2_add_mc(struct qeth_card *card, __u8 *mac, int vmac)
177 struct qeth_mc_mac *mc;
178 int rc;
180 mc = kmalloc(sizeof(struct qeth_mc_mac), GFP_ATOMIC);
182 if (!mc)
183 return;
185 memcpy(mc->mc_addr, mac, OSA_ADDR_LEN);
186 mc->mc_addrlen = OSA_ADDR_LEN;
187 mc->is_vmac = vmac;
189 if (vmac) {
190 rc = qeth_l2_send_setdelmac(card, mac, IPA_CMD_SETVMAC,
191 NULL);
192 } else {
193 rc = qeth_l2_send_setgroupmac(card, mac);
196 if (!rc)
197 list_add_tail(&mc->list, &card->mc_list);
198 else
199 kfree(mc);
202 static void qeth_l2_del_all_mc(struct qeth_card *card)
204 struct qeth_mc_mac *mc, *tmp;
206 spin_lock_bh(&card->mclock);
207 list_for_each_entry_safe(mc, tmp, &card->mc_list, list) {
208 if (mc->is_vmac)
209 qeth_l2_send_setdelmac(card, mc->mc_addr,
210 IPA_CMD_DELVMAC, NULL);
211 else
212 qeth_l2_send_delgroupmac(card, mc->mc_addr);
213 list_del(&mc->list);
214 kfree(mc);
216 spin_unlock_bh(&card->mclock);
219 static inline int qeth_l2_get_cast_type(struct qeth_card *card,
220 struct sk_buff *skb)
222 if (card->info.type == QETH_CARD_TYPE_OSN)
223 return RTN_UNSPEC;
224 if (is_broadcast_ether_addr(skb->data))
225 return RTN_BROADCAST;
226 if (is_multicast_ether_addr(skb->data))
227 return RTN_MULTICAST;
228 return RTN_UNSPEC;
231 static void qeth_l2_fill_header(struct qeth_card *card, struct qeth_hdr *hdr,
232 struct sk_buff *skb, int ipv, int cast_type)
234 struct vlan_ethhdr *veth = (struct vlan_ethhdr *)skb_mac_header(skb);
236 memset(hdr, 0, sizeof(struct qeth_hdr));
237 hdr->hdr.l2.id = QETH_HEADER_TYPE_LAYER2;
239 /* set byte byte 3 to casting flags */
240 if (cast_type == RTN_MULTICAST)
241 hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_MULTICAST;
242 else if (cast_type == RTN_BROADCAST)
243 hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_BROADCAST;
244 else
245 hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_UNICAST;
247 hdr->hdr.l2.pkt_length = skb->len-QETH_HEADER_SIZE;
248 /* VSWITCH relies on the VLAN
249 * information to be present in
250 * the QDIO header */
251 if (veth->h_vlan_proto == __constant_htons(ETH_P_8021Q)) {
252 hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_VLAN;
253 hdr->hdr.l2.vlan_id = ntohs(veth->h_vlan_TCI);
257 static int qeth_l2_send_setdelvlan_cb(struct qeth_card *card,
258 struct qeth_reply *reply, unsigned long data)
260 struct qeth_ipa_cmd *cmd;
262 QETH_DBF_TEXT(TRACE, 2, "L2sdvcb");
263 cmd = (struct qeth_ipa_cmd *) data;
264 if (cmd->hdr.return_code) {
265 QETH_DBF_MESSAGE(2, "Error in processing VLAN %i on %s: 0x%x. "
266 "Continuing\n", cmd->data.setdelvlan.vlan_id,
267 QETH_CARD_IFNAME(card), cmd->hdr.return_code);
268 QETH_DBF_TEXT_(TRACE, 2, "L2VL%4x", cmd->hdr.command);
269 QETH_DBF_TEXT_(TRACE, 2, "L2%s", CARD_BUS_ID(card));
270 QETH_DBF_TEXT_(TRACE, 2, "err%d", cmd->hdr.return_code);
272 return 0;
275 static int qeth_l2_send_setdelvlan(struct qeth_card *card, __u16 i,
276 enum qeth_ipa_cmds ipacmd)
278 struct qeth_ipa_cmd *cmd;
279 struct qeth_cmd_buffer *iob;
281 QETH_DBF_TEXT_(TRACE, 4, "L2sdv%x", ipacmd);
282 iob = qeth_get_ipacmd_buffer(card, ipacmd, QETH_PROT_IPV4);
283 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
284 cmd->data.setdelvlan.vlan_id = i;
285 return qeth_send_ipa_cmd(card, iob,
286 qeth_l2_send_setdelvlan_cb, NULL);
289 static void qeth_l2_process_vlans(struct qeth_card *card, int clear)
291 struct qeth_vlan_vid *id;
292 QETH_DBF_TEXT(TRACE, 3, "L2prcvln");
293 spin_lock_bh(&card->vlanlock);
294 list_for_each_entry(id, &card->vid_list, list) {
295 if (clear)
296 qeth_l2_send_setdelvlan(card, id->vid,
297 IPA_CMD_DELVLAN);
298 else
299 qeth_l2_send_setdelvlan(card, id->vid,
300 IPA_CMD_SETVLAN);
302 spin_unlock_bh(&card->vlanlock);
305 static void qeth_l2_vlan_rx_add_vid(struct net_device *dev, unsigned short vid)
307 struct qeth_card *card = dev->ml_priv;
308 struct qeth_vlan_vid *id;
310 QETH_DBF_TEXT_(TRACE, 4, "aid:%d", vid);
311 if (qeth_wait_for_threads(card, QETH_RECOVER_THREAD)) {
312 QETH_DBF_TEXT(TRACE, 3, "aidREC");
313 return;
315 id = kmalloc(sizeof(struct qeth_vlan_vid), GFP_ATOMIC);
316 if (id) {
317 id->vid = vid;
318 qeth_l2_send_setdelvlan(card, vid, IPA_CMD_SETVLAN);
319 spin_lock_bh(&card->vlanlock);
320 list_add_tail(&id->list, &card->vid_list);
321 spin_unlock_bh(&card->vlanlock);
325 static void qeth_l2_vlan_rx_kill_vid(struct net_device *dev, unsigned short vid)
327 struct qeth_vlan_vid *id, *tmpid = NULL;
328 struct qeth_card *card = dev->ml_priv;
330 QETH_DBF_TEXT_(TRACE, 4, "kid:%d", vid);
331 if (qeth_wait_for_threads(card, QETH_RECOVER_THREAD)) {
332 QETH_DBF_TEXT(TRACE, 3, "kidREC");
333 return;
335 spin_lock_bh(&card->vlanlock);
336 list_for_each_entry(id, &card->vid_list, list) {
337 if (id->vid == vid) {
338 list_del(&id->list);
339 tmpid = id;
340 break;
343 spin_unlock_bh(&card->vlanlock);
344 if (tmpid) {
345 qeth_l2_send_setdelvlan(card, vid, IPA_CMD_DELVLAN);
346 kfree(tmpid);
348 qeth_l2_set_multicast_list(card->dev);
351 static int qeth_l2_stop_card(struct qeth_card *card, int recovery_mode)
353 int rc = 0;
355 QETH_DBF_TEXT(SETUP , 2, "stopcard");
356 QETH_DBF_HEX(SETUP, 2, &card, sizeof(void *));
358 qeth_set_allowed_threads(card, 0, 1);
359 if (card->read.state == CH_STATE_UP &&
360 card->write.state == CH_STATE_UP &&
361 (card->state == CARD_STATE_UP)) {
362 if (recovery_mode &&
363 card->info.type != QETH_CARD_TYPE_OSN) {
364 qeth_l2_stop(card->dev);
365 } else {
366 rtnl_lock();
367 dev_close(card->dev);
368 rtnl_unlock();
370 if (!card->use_hard_stop ||
371 recovery_mode) {
372 __u8 *mac = &card->dev->dev_addr[0];
373 rc = qeth_l2_send_delmac(card, mac);
374 QETH_DBF_TEXT_(SETUP, 2, "Lerr%d", rc);
376 card->state = CARD_STATE_SOFTSETUP;
378 if (card->state == CARD_STATE_SOFTSETUP) {
379 qeth_l2_process_vlans(card, 1);
380 if (!card->use_hard_stop ||
381 recovery_mode)
382 qeth_l2_del_all_mc(card);
383 qeth_clear_ipacmd_list(card);
384 card->state = CARD_STATE_HARDSETUP;
386 if (card->state == CARD_STATE_HARDSETUP) {
387 qeth_qdio_clear_card(card, 0);
388 qeth_clear_qdio_buffers(card);
389 qeth_clear_working_pool_list(card);
390 card->state = CARD_STATE_DOWN;
392 if (card->state == CARD_STATE_DOWN) {
393 qeth_clear_cmd_buffers(&card->read);
394 qeth_clear_cmd_buffers(&card->write);
396 card->use_hard_stop = 0;
397 return rc;
400 static void qeth_l2_process_inbound_buffer(struct qeth_card *card,
401 struct qeth_qdio_buffer *buf, int index)
403 struct qdio_buffer_element *element;
404 struct sk_buff *skb;
405 struct qeth_hdr *hdr;
406 int offset;
407 unsigned int len;
409 /* get first element of current buffer */
410 element = (struct qdio_buffer_element *)&buf->buffer->element[0];
411 offset = 0;
412 if (card->options.performance_stats)
413 card->perf_stats.bufs_rec++;
414 while ((skb = qeth_core_get_next_skb(card, buf->buffer, &element,
415 &offset, &hdr))) {
416 skb->dev = card->dev;
417 /* is device UP ? */
418 if (!(card->dev->flags & IFF_UP)) {
419 dev_kfree_skb_any(skb);
420 continue;
423 switch (hdr->hdr.l2.id) {
424 case QETH_HEADER_TYPE_LAYER2:
425 skb->pkt_type = PACKET_HOST;
426 skb->protocol = eth_type_trans(skb, skb->dev);
427 if (card->options.checksum_type == NO_CHECKSUMMING)
428 skb->ip_summed = CHECKSUM_UNNECESSARY;
429 else
430 skb->ip_summed = CHECKSUM_NONE;
431 if (skb->protocol == htons(ETH_P_802_2))
432 *((__u32 *)skb->cb) = ++card->seqno.pkt_seqno;
433 len = skb->len;
434 netif_rx(skb);
435 break;
436 case QETH_HEADER_TYPE_OSN:
437 if (card->info.type == QETH_CARD_TYPE_OSN) {
438 skb_push(skb, sizeof(struct qeth_hdr));
439 skb_copy_to_linear_data(skb, hdr,
440 sizeof(struct qeth_hdr));
441 len = skb->len;
442 card->osn_info.data_cb(skb);
443 break;
445 /* else unknown */
446 default:
447 dev_kfree_skb_any(skb);
448 QETH_DBF_TEXT(TRACE, 3, "inbunkno");
449 QETH_DBF_HEX(CTRL, 3, hdr, QETH_DBF_CTRL_LEN);
450 continue;
452 card->stats.rx_packets++;
453 card->stats.rx_bytes += len;
457 static int qeth_l2_send_setdelmac(struct qeth_card *card, __u8 *mac,
458 enum qeth_ipa_cmds ipacmd,
459 int (*reply_cb) (struct qeth_card *,
460 struct qeth_reply*,
461 unsigned long))
463 struct qeth_ipa_cmd *cmd;
464 struct qeth_cmd_buffer *iob;
466 QETH_DBF_TEXT(TRACE, 2, "L2sdmac");
467 iob = qeth_get_ipacmd_buffer(card, ipacmd, QETH_PROT_IPV4);
468 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
469 cmd->data.setdelmac.mac_length = OSA_ADDR_LEN;
470 memcpy(&cmd->data.setdelmac.mac, mac, OSA_ADDR_LEN);
471 return qeth_send_ipa_cmd(card, iob, reply_cb, NULL);
474 static int qeth_l2_send_setmac_cb(struct qeth_card *card,
475 struct qeth_reply *reply,
476 unsigned long data)
478 struct qeth_ipa_cmd *cmd;
480 QETH_DBF_TEXT(TRACE, 2, "L2Smaccb");
481 cmd = (struct qeth_ipa_cmd *) data;
482 if (cmd->hdr.return_code) {
483 QETH_DBF_TEXT_(TRACE, 2, "L2er%x", cmd->hdr.return_code);
484 card->info.mac_bits &= ~QETH_LAYER2_MAC_REGISTERED;
485 switch (cmd->hdr.return_code) {
486 case IPA_RC_L2_DUP_MAC:
487 case IPA_RC_L2_DUP_LAYER3_MAC:
488 dev_warn(&card->gdev->dev,
489 "MAC address "
490 "%2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x "
491 "already exists\n",
492 card->dev->dev_addr[0], card->dev->dev_addr[1],
493 card->dev->dev_addr[2], card->dev->dev_addr[3],
494 card->dev->dev_addr[4], card->dev->dev_addr[5]);
495 break;
496 case IPA_RC_L2_MAC_NOT_AUTH_BY_HYP:
497 case IPA_RC_L2_MAC_NOT_AUTH_BY_ADP:
498 dev_warn(&card->gdev->dev,
499 "MAC address "
500 "%2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x "
501 "is not authorized\n",
502 card->dev->dev_addr[0], card->dev->dev_addr[1],
503 card->dev->dev_addr[2], card->dev->dev_addr[3],
504 card->dev->dev_addr[4], card->dev->dev_addr[5]);
505 break;
506 default:
507 break;
509 cmd->hdr.return_code = -EIO;
510 } else {
511 card->info.mac_bits |= QETH_LAYER2_MAC_REGISTERED;
512 memcpy(card->dev->dev_addr, cmd->data.setdelmac.mac,
513 OSA_ADDR_LEN);
514 dev_info(&card->gdev->dev,
515 "MAC address %2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x "
516 "successfully registered on device %s\n",
517 card->dev->dev_addr[0], card->dev->dev_addr[1],
518 card->dev->dev_addr[2], card->dev->dev_addr[3],
519 card->dev->dev_addr[4], card->dev->dev_addr[5],
520 card->dev->name);
522 return 0;
525 static int qeth_l2_send_setmac(struct qeth_card *card, __u8 *mac)
527 QETH_DBF_TEXT(TRACE, 2, "L2Setmac");
528 return qeth_l2_send_setdelmac(card, mac, IPA_CMD_SETVMAC,
529 qeth_l2_send_setmac_cb);
532 static int qeth_l2_send_delmac_cb(struct qeth_card *card,
533 struct qeth_reply *reply,
534 unsigned long data)
536 struct qeth_ipa_cmd *cmd;
538 QETH_DBF_TEXT(TRACE, 2, "L2Dmaccb");
539 cmd = (struct qeth_ipa_cmd *) data;
540 if (cmd->hdr.return_code) {
541 QETH_DBF_TEXT_(TRACE, 2, "err%d", cmd->hdr.return_code);
542 cmd->hdr.return_code = -EIO;
543 return 0;
545 card->info.mac_bits &= ~QETH_LAYER2_MAC_REGISTERED;
547 return 0;
550 static int qeth_l2_send_delmac(struct qeth_card *card, __u8 *mac)
552 QETH_DBF_TEXT(TRACE, 2, "L2Delmac");
553 if (!(card->info.mac_bits & QETH_LAYER2_MAC_REGISTERED))
554 return 0;
555 return qeth_l2_send_setdelmac(card, mac, IPA_CMD_DELVMAC,
556 qeth_l2_send_delmac_cb);
559 static int qeth_l2_request_initial_mac(struct qeth_card *card)
561 int rc = 0;
562 char vendor_pre[] = {0x02, 0x00, 0x00};
564 QETH_DBF_TEXT(SETUP, 2, "doL2init");
565 QETH_DBF_TEXT_(SETUP, 2, "doL2%s", CARD_BUS_ID(card));
567 rc = qeth_query_setadapterparms(card);
568 if (rc) {
569 QETH_DBF_MESSAGE(2, "could not query adapter parameters on "
570 "device %s: x%x\n", CARD_BUS_ID(card), rc);
573 if ((card->info.type == QETH_CARD_TYPE_IQD) ||
574 (card->info.guestlan)) {
575 rc = qeth_setadpparms_change_macaddr(card);
576 if (rc) {
577 QETH_DBF_MESSAGE(2, "couldn't get MAC address on "
578 "device %s: x%x\n", CARD_BUS_ID(card), rc);
579 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
580 return rc;
582 QETH_DBF_HEX(SETUP, 2, card->dev->dev_addr, OSA_ADDR_LEN);
583 } else {
584 random_ether_addr(card->dev->dev_addr);
585 memcpy(card->dev->dev_addr, vendor_pre, 3);
587 return 0;
590 static int qeth_l2_set_mac_address(struct net_device *dev, void *p)
592 struct sockaddr *addr = p;
593 struct qeth_card *card = dev->ml_priv;
594 int rc = 0;
596 QETH_DBF_TEXT(TRACE, 3, "setmac");
598 if (qeth_l2_verify_dev(dev) != QETH_REAL_CARD) {
599 QETH_DBF_TEXT(TRACE, 3, "setmcINV");
600 return -EOPNOTSUPP;
603 if (card->info.type == QETH_CARD_TYPE_OSN) {
604 QETH_DBF_TEXT(TRACE, 3, "setmcOSN");
605 return -EOPNOTSUPP;
607 QETH_DBF_TEXT_(TRACE, 3, "%s", CARD_BUS_ID(card));
608 QETH_DBF_HEX(TRACE, 3, addr->sa_data, OSA_ADDR_LEN);
609 if (qeth_wait_for_threads(card, QETH_RECOVER_THREAD)) {
610 QETH_DBF_TEXT(TRACE, 3, "setmcREC");
611 return -ERESTARTSYS;
613 rc = qeth_l2_send_delmac(card, &card->dev->dev_addr[0]);
614 if (!rc)
615 rc = qeth_l2_send_setmac(card, addr->sa_data);
616 return rc;
619 static void qeth_l2_set_multicast_list(struct net_device *dev)
621 struct qeth_card *card = dev->ml_priv;
622 struct dev_addr_list *dm;
623 struct netdev_hw_addr *ha;
625 if (card->info.type == QETH_CARD_TYPE_OSN)
626 return ;
628 QETH_DBF_TEXT(TRACE, 3, "setmulti");
629 if (qeth_threads_running(card, QETH_RECOVER_THREAD) &&
630 (card->state != CARD_STATE_UP))
631 return;
632 qeth_l2_del_all_mc(card);
633 spin_lock_bh(&card->mclock);
634 for (dm = dev->mc_list; dm; dm = dm->next)
635 qeth_l2_add_mc(card, dm->da_addr, 0);
637 list_for_each_entry(ha, &dev->uc.list, list)
638 qeth_l2_add_mc(card, ha->addr, 1);
640 spin_unlock_bh(&card->mclock);
641 if (!qeth_adp_supported(card, IPA_SETADP_SET_PROMISC_MODE))
642 return;
643 qeth_setadp_promisc_mode(card);
646 static int qeth_l2_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
648 int rc;
649 struct qeth_hdr *hdr = NULL;
650 int elements = 0;
651 struct qeth_card *card = dev->ml_priv;
652 struct sk_buff *new_skb = skb;
653 int ipv = qeth_get_ip_version(skb);
654 int cast_type = qeth_l2_get_cast_type(card, skb);
655 struct qeth_qdio_out_q *queue = card->qdio.out_qs
656 [qeth_get_priority_queue(card, skb, ipv, cast_type)];
657 int tx_bytes = skb->len;
658 int data_offset = -1;
659 int elements_needed = 0;
660 int hd_len = 0;
662 if ((card->state != CARD_STATE_UP) || !card->lan_online) {
663 card->stats.tx_carrier_errors++;
664 goto tx_drop;
667 if ((card->info.type == QETH_CARD_TYPE_OSN) &&
668 (skb->protocol == htons(ETH_P_IPV6)))
669 goto tx_drop;
671 if (card->options.performance_stats) {
672 card->perf_stats.outbound_cnt++;
673 card->perf_stats.outbound_start_time = qeth_get_micros();
675 netif_stop_queue(dev);
677 if (card->info.type == QETH_CARD_TYPE_OSN)
678 hdr = (struct qeth_hdr *)skb->data;
679 else {
680 if (card->info.type == QETH_CARD_TYPE_IQD) {
681 new_skb = skb;
682 data_offset = ETH_HLEN;
683 hd_len = ETH_HLEN;
684 hdr = kmem_cache_alloc(qeth_core_header_cache,
685 GFP_ATOMIC);
686 if (!hdr)
687 goto tx_drop;
688 elements_needed++;
689 skb_reset_mac_header(new_skb);
690 qeth_l2_fill_header(card, hdr, new_skb, ipv, cast_type);
691 hdr->hdr.l2.pkt_length = new_skb->len;
692 memcpy(((char *)hdr) + sizeof(struct qeth_hdr),
693 skb_mac_header(new_skb), ETH_HLEN);
694 } else {
695 /* create a clone with writeable headroom */
696 new_skb = skb_realloc_headroom(skb,
697 sizeof(struct qeth_hdr));
698 if (!new_skb)
699 goto tx_drop;
700 hdr = (struct qeth_hdr *)skb_push(new_skb,
701 sizeof(struct qeth_hdr));
702 skb_set_mac_header(new_skb, sizeof(struct qeth_hdr));
703 qeth_l2_fill_header(card, hdr, new_skb, ipv, cast_type);
707 elements = qeth_get_elements_no(card, (void *)hdr, new_skb,
708 elements_needed);
709 if (!elements) {
710 if (data_offset >= 0)
711 kmem_cache_free(qeth_core_header_cache, hdr);
712 goto tx_drop;
715 if (card->info.type != QETH_CARD_TYPE_IQD)
716 rc = qeth_do_send_packet(card, queue, new_skb, hdr,
717 elements);
718 else
719 rc = qeth_do_send_packet_fast(card, queue, new_skb, hdr,
720 elements, data_offset, hd_len);
721 if (!rc) {
722 card->stats.tx_packets++;
723 card->stats.tx_bytes += tx_bytes;
724 if (new_skb != skb)
725 dev_kfree_skb_any(skb);
726 rc = NETDEV_TX_OK;
727 } else {
728 if (data_offset >= 0)
729 kmem_cache_free(qeth_core_header_cache, hdr);
731 if (rc == -EBUSY) {
732 if (new_skb != skb)
733 dev_kfree_skb_any(new_skb);
734 return NETDEV_TX_BUSY;
735 } else
736 goto tx_drop;
739 netif_wake_queue(dev);
740 if (card->options.performance_stats)
741 card->perf_stats.outbound_time += qeth_get_micros() -
742 card->perf_stats.outbound_start_time;
743 return rc;
745 tx_drop:
746 card->stats.tx_dropped++;
747 card->stats.tx_errors++;
748 if ((new_skb != skb) && new_skb)
749 dev_kfree_skb_any(new_skb);
750 dev_kfree_skb_any(skb);
751 netif_wake_queue(dev);
752 return NETDEV_TX_OK;
755 static void qeth_l2_qdio_input_handler(struct ccw_device *ccwdev,
756 unsigned int qdio_err, unsigned int queue,
757 int first_element, int count, unsigned long card_ptr)
759 struct net_device *net_dev;
760 struct qeth_card *card;
761 struct qeth_qdio_buffer *buffer;
762 int index;
763 int i;
765 card = (struct qeth_card *) card_ptr;
766 net_dev = card->dev;
767 if (card->options.performance_stats) {
768 card->perf_stats.inbound_cnt++;
769 card->perf_stats.inbound_start_time = qeth_get_micros();
771 if (qdio_err & QDIO_ERROR_ACTIVATE_CHECK_CONDITION) {
772 QETH_DBF_TEXT(TRACE, 1, "qdinchk");
773 QETH_DBF_TEXT_(TRACE, 1, "%s", CARD_BUS_ID(card));
774 QETH_DBF_TEXT_(TRACE, 1, "%04X%04X", first_element,
775 count);
776 QETH_DBF_TEXT_(TRACE, 1, "%04X", queue);
777 qeth_schedule_recovery(card);
778 return;
780 for (i = first_element; i < (first_element + count); ++i) {
781 index = i % QDIO_MAX_BUFFERS_PER_Q;
782 buffer = &card->qdio.in_q->bufs[index];
783 if (!(qdio_err &&
784 qeth_check_qdio_errors(buffer->buffer, qdio_err, "qinerr")))
785 qeth_l2_process_inbound_buffer(card, buffer, index);
786 /* clear buffer and give back to hardware */
787 qeth_put_buffer_pool_entry(card, buffer->pool_entry);
788 qeth_queue_input_buffer(card, index);
790 if (card->options.performance_stats)
791 card->perf_stats.inbound_time += qeth_get_micros() -
792 card->perf_stats.inbound_start_time;
795 static int qeth_l2_open(struct net_device *dev)
797 struct qeth_card *card = dev->ml_priv;
799 QETH_DBF_TEXT(TRACE, 4, "qethopen");
800 if (card->state != CARD_STATE_SOFTSETUP)
801 return -ENODEV;
803 if ((card->info.type != QETH_CARD_TYPE_OSN) &&
804 (!(card->info.mac_bits & QETH_LAYER2_MAC_REGISTERED))) {
805 QETH_DBF_TEXT(TRACE, 4, "nomacadr");
806 return -EPERM;
808 card->data.state = CH_STATE_UP;
809 card->state = CARD_STATE_UP;
810 netif_start_queue(dev);
812 if (!card->lan_online && netif_carrier_ok(dev))
813 netif_carrier_off(dev);
814 return 0;
818 static int qeth_l2_stop(struct net_device *dev)
820 struct qeth_card *card = dev->ml_priv;
822 QETH_DBF_TEXT(TRACE, 4, "qethstop");
823 netif_tx_disable(dev);
824 if (card->state == CARD_STATE_UP)
825 card->state = CARD_STATE_SOFTSETUP;
826 return 0;
829 static int qeth_l2_probe_device(struct ccwgroup_device *gdev)
831 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
833 INIT_LIST_HEAD(&card->vid_list);
834 INIT_LIST_HEAD(&card->mc_list);
835 card->options.layer2 = 1;
836 card->discipline.input_handler = (qdio_handler_t *)
837 qeth_l2_qdio_input_handler;
838 card->discipline.output_handler = (qdio_handler_t *)
839 qeth_qdio_output_handler;
840 card->discipline.recover = qeth_l2_recover;
841 return 0;
844 static void qeth_l2_remove_device(struct ccwgroup_device *cgdev)
846 struct qeth_card *card = dev_get_drvdata(&cgdev->dev);
848 qeth_set_allowed_threads(card, 0, 1);
849 wait_event(card->wait_q, qeth_threads_running(card, 0xffffffff) == 0);
851 if (cgdev->state == CCWGROUP_ONLINE) {
852 card->use_hard_stop = 1;
853 qeth_l2_set_offline(cgdev);
856 if (card->dev) {
857 unregister_netdev(card->dev);
858 card->dev = NULL;
861 qeth_l2_del_all_mc(card);
862 return;
865 static const struct ethtool_ops qeth_l2_ethtool_ops = {
866 .get_link = ethtool_op_get_link,
867 .get_strings = qeth_core_get_strings,
868 .get_ethtool_stats = qeth_core_get_ethtool_stats,
869 .get_stats_count = qeth_core_get_stats_count,
870 .get_drvinfo = qeth_core_get_drvinfo,
871 .get_settings = qeth_core_ethtool_get_settings,
874 static const struct ethtool_ops qeth_l2_osn_ops = {
875 .get_strings = qeth_core_get_strings,
876 .get_ethtool_stats = qeth_core_get_ethtool_stats,
877 .get_stats_count = qeth_core_get_stats_count,
878 .get_drvinfo = qeth_core_get_drvinfo,
881 static const struct net_device_ops qeth_l2_netdev_ops = {
882 .ndo_open = qeth_l2_open,
883 .ndo_stop = qeth_l2_stop,
884 .ndo_get_stats = qeth_get_stats,
885 .ndo_start_xmit = qeth_l2_hard_start_xmit,
886 .ndo_validate_addr = eth_validate_addr,
887 .ndo_set_multicast_list = qeth_l2_set_multicast_list,
888 .ndo_do_ioctl = qeth_l2_do_ioctl,
889 .ndo_set_mac_address = qeth_l2_set_mac_address,
890 .ndo_change_mtu = qeth_change_mtu,
891 .ndo_vlan_rx_add_vid = qeth_l2_vlan_rx_add_vid,
892 .ndo_vlan_rx_kill_vid = qeth_l2_vlan_rx_kill_vid,
893 .ndo_tx_timeout = qeth_tx_timeout,
896 static int qeth_l2_setup_netdev(struct qeth_card *card)
898 switch (card->info.type) {
899 case QETH_CARD_TYPE_OSAE:
900 card->dev = alloc_etherdev(0);
901 break;
902 case QETH_CARD_TYPE_IQD:
903 card->dev = alloc_netdev(0, "hsi%d", ether_setup);
904 break;
905 case QETH_CARD_TYPE_OSN:
906 card->dev = alloc_netdev(0, "osn%d", ether_setup);
907 card->dev->flags |= IFF_NOARP;
908 break;
909 default:
910 card->dev = alloc_etherdev(0);
913 if (!card->dev)
914 return -ENODEV;
916 card->dev->ml_priv = card;
917 card->dev->watchdog_timeo = QETH_TX_TIMEOUT;
918 card->dev->mtu = card->info.initial_mtu;
919 card->dev->netdev_ops = &qeth_l2_netdev_ops;
920 if (card->info.type != QETH_CARD_TYPE_OSN)
921 SET_ETHTOOL_OPS(card->dev, &qeth_l2_ethtool_ops);
922 else
923 SET_ETHTOOL_OPS(card->dev, &qeth_l2_osn_ops);
924 card->dev->features |= NETIF_F_HW_VLAN_FILTER;
925 card->info.broadcast_capable = 1;
926 qeth_l2_request_initial_mac(card);
927 SET_NETDEV_DEV(card->dev, &card->gdev->dev);
928 return register_netdev(card->dev);
931 static int __qeth_l2_set_online(struct ccwgroup_device *gdev, int recovery_mode)
933 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
934 int rc = 0;
935 enum qeth_card_states recover_flag;
937 BUG_ON(!card);
938 QETH_DBF_TEXT(SETUP, 2, "setonlin");
939 QETH_DBF_HEX(SETUP, 2, &card, sizeof(void *));
941 qeth_set_allowed_threads(card, QETH_RECOVER_THREAD, 1);
942 recover_flag = card->state;
943 rc = ccw_device_set_online(CARD_RDEV(card));
944 if (rc) {
945 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
946 return -EIO;
948 rc = ccw_device_set_online(CARD_WDEV(card));
949 if (rc) {
950 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
951 return -EIO;
953 rc = ccw_device_set_online(CARD_DDEV(card));
954 if (rc) {
955 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
956 return -EIO;
959 rc = qeth_core_hardsetup_card(card);
960 if (rc) {
961 QETH_DBF_TEXT_(SETUP, 2, "2err%d", rc);
962 goto out_remove;
965 if (!card->dev && qeth_l2_setup_netdev(card))
966 goto out_remove;
968 if (card->info.type != QETH_CARD_TYPE_OSN)
969 qeth_l2_send_setmac(card, &card->dev->dev_addr[0]);
971 card->state = CARD_STATE_HARDSETUP;
972 qeth_print_status_message(card);
974 /* softsetup */
975 QETH_DBF_TEXT(SETUP, 2, "softsetp");
977 rc = qeth_send_startlan(card);
978 if (rc) {
979 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
980 if (rc == 0xe080) {
981 dev_warn(&card->gdev->dev,
982 "The LAN is offline\n");
983 card->lan_online = 0;
984 return 0;
986 goto out_remove;
987 } else
988 card->lan_online = 1;
990 if (card->info.type != QETH_CARD_TYPE_OSN) {
991 qeth_set_large_send(card, card->options.large_send);
992 qeth_l2_process_vlans(card, 0);
995 netif_tx_disable(card->dev);
997 rc = qeth_init_qdio_queues(card);
998 if (rc) {
999 QETH_DBF_TEXT_(SETUP, 2, "6err%d", rc);
1000 goto out_remove;
1002 card->state = CARD_STATE_SOFTSETUP;
1003 netif_carrier_on(card->dev);
1005 qeth_set_allowed_threads(card, 0xffffffff, 0);
1006 if (recover_flag == CARD_STATE_RECOVER) {
1007 if (recovery_mode &&
1008 card->info.type != QETH_CARD_TYPE_OSN) {
1009 qeth_l2_open(card->dev);
1010 } else {
1011 rtnl_lock();
1012 dev_open(card->dev);
1013 rtnl_unlock();
1015 /* this also sets saved unicast addresses */
1016 qeth_l2_set_multicast_list(card->dev);
1018 /* let user_space know that device is online */
1019 kobject_uevent(&gdev->dev.kobj, KOBJ_CHANGE);
1020 return 0;
1021 out_remove:
1022 card->use_hard_stop = 1;
1023 qeth_l2_stop_card(card, 0);
1024 ccw_device_set_offline(CARD_DDEV(card));
1025 ccw_device_set_offline(CARD_WDEV(card));
1026 ccw_device_set_offline(CARD_RDEV(card));
1027 if (recover_flag == CARD_STATE_RECOVER)
1028 card->state = CARD_STATE_RECOVER;
1029 else
1030 card->state = CARD_STATE_DOWN;
1031 return -ENODEV;
1034 static int qeth_l2_set_online(struct ccwgroup_device *gdev)
1036 return __qeth_l2_set_online(gdev, 0);
1039 static int __qeth_l2_set_offline(struct ccwgroup_device *cgdev,
1040 int recovery_mode)
1042 struct qeth_card *card = dev_get_drvdata(&cgdev->dev);
1043 int rc = 0, rc2 = 0, rc3 = 0;
1044 enum qeth_card_states recover_flag;
1046 QETH_DBF_TEXT(SETUP, 3, "setoffl");
1047 QETH_DBF_HEX(SETUP, 3, &card, sizeof(void *));
1049 if (card->dev && netif_carrier_ok(card->dev))
1050 netif_carrier_off(card->dev);
1051 recover_flag = card->state;
1052 qeth_l2_stop_card(card, recovery_mode);
1053 rc = ccw_device_set_offline(CARD_DDEV(card));
1054 rc2 = ccw_device_set_offline(CARD_WDEV(card));
1055 rc3 = ccw_device_set_offline(CARD_RDEV(card));
1056 if (!rc)
1057 rc = (rc2) ? rc2 : rc3;
1058 if (rc)
1059 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
1060 if (recover_flag == CARD_STATE_UP)
1061 card->state = CARD_STATE_RECOVER;
1062 /* let user_space know that device is offline */
1063 kobject_uevent(&cgdev->dev.kobj, KOBJ_CHANGE);
1064 return 0;
1067 static int qeth_l2_set_offline(struct ccwgroup_device *cgdev)
1069 return __qeth_l2_set_offline(cgdev, 0);
1072 static int qeth_l2_recover(void *ptr)
1074 struct qeth_card *card;
1075 int rc = 0;
1077 card = (struct qeth_card *) ptr;
1078 QETH_DBF_TEXT(TRACE, 2, "recover1");
1079 QETH_DBF_HEX(TRACE, 2, &card, sizeof(void *));
1080 if (!qeth_do_run_thread(card, QETH_RECOVER_THREAD))
1081 return 0;
1082 QETH_DBF_TEXT(TRACE, 2, "recover2");
1083 dev_warn(&card->gdev->dev,
1084 "A recovery process has been started for the device\n");
1085 card->use_hard_stop = 1;
1086 __qeth_l2_set_offline(card->gdev, 1);
1087 rc = __qeth_l2_set_online(card->gdev, 1);
1088 /* don't run another scheduled recovery */
1089 qeth_clear_thread_start_bit(card, QETH_RECOVER_THREAD);
1090 qeth_clear_thread_running_bit(card, QETH_RECOVER_THREAD);
1091 if (!rc)
1092 dev_info(&card->gdev->dev,
1093 "Device successfully recovered!\n");
1094 else {
1095 if (card->dev) {
1096 rtnl_lock();
1097 dev_close(card->dev);
1098 rtnl_unlock();
1100 dev_warn(&card->gdev->dev, "The qeth device driver "
1101 "failed to recover an error on the device\n");
1103 return 0;
1106 static int __init qeth_l2_init(void)
1108 pr_info("register layer 2 discipline\n");
1109 return 0;
1112 static void __exit qeth_l2_exit(void)
1114 pr_info("unregister layer 2 discipline\n");
1117 static void qeth_l2_shutdown(struct ccwgroup_device *gdev)
1119 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
1120 qeth_qdio_clear_card(card, 0);
1121 qeth_clear_qdio_buffers(card);
1124 static int qeth_l2_pm_suspend(struct ccwgroup_device *gdev)
1126 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
1128 if (card->dev)
1129 netif_device_detach(card->dev);
1130 qeth_set_allowed_threads(card, 0, 1);
1131 wait_event(card->wait_q, qeth_threads_running(card, 0xffffffff) == 0);
1132 if (gdev->state == CCWGROUP_OFFLINE)
1133 return 0;
1134 if (card->state == CARD_STATE_UP) {
1135 card->use_hard_stop = 1;
1136 __qeth_l2_set_offline(card->gdev, 1);
1137 } else
1138 __qeth_l2_set_offline(card->gdev, 0);
1139 return 0;
1142 static int qeth_l2_pm_resume(struct ccwgroup_device *gdev)
1144 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
1145 int rc = 0;
1147 if (gdev->state == CCWGROUP_OFFLINE)
1148 goto out;
1150 if (card->state == CARD_STATE_RECOVER) {
1151 rc = __qeth_l2_set_online(card->gdev, 1);
1152 if (rc) {
1153 if (card->dev) {
1154 rtnl_lock();
1155 dev_close(card->dev);
1156 rtnl_unlock();
1159 } else
1160 rc = __qeth_l2_set_online(card->gdev, 0);
1161 out:
1162 qeth_set_allowed_threads(card, 0xffffffff, 0);
1163 if (card->dev)
1164 netif_device_attach(card->dev);
1165 if (rc)
1166 dev_warn(&card->gdev->dev, "The qeth device driver "
1167 "failed to recover an error on the device\n");
1168 return rc;
1171 struct ccwgroup_driver qeth_l2_ccwgroup_driver = {
1172 .probe = qeth_l2_probe_device,
1173 .remove = qeth_l2_remove_device,
1174 .set_online = qeth_l2_set_online,
1175 .set_offline = qeth_l2_set_offline,
1176 .shutdown = qeth_l2_shutdown,
1177 .freeze = qeth_l2_pm_suspend,
1178 .thaw = qeth_l2_pm_resume,
1179 .restore = qeth_l2_pm_resume,
1181 EXPORT_SYMBOL_GPL(qeth_l2_ccwgroup_driver);
1183 static int qeth_osn_send_control_data(struct qeth_card *card, int len,
1184 struct qeth_cmd_buffer *iob)
1186 unsigned long flags;
1187 int rc = 0;
1189 QETH_DBF_TEXT(TRACE, 5, "osndctrd");
1191 wait_event(card->wait_q,
1192 atomic_cmpxchg(&card->write.irq_pending, 0, 1) == 0);
1193 qeth_prepare_control_data(card, len, iob);
1194 QETH_DBF_TEXT(TRACE, 6, "osnoirqp");
1195 spin_lock_irqsave(get_ccwdev_lock(card->write.ccwdev), flags);
1196 rc = ccw_device_start(card->write.ccwdev, &card->write.ccw,
1197 (addr_t) iob, 0, 0);
1198 spin_unlock_irqrestore(get_ccwdev_lock(card->write.ccwdev), flags);
1199 if (rc) {
1200 QETH_DBF_MESSAGE(2, "qeth_osn_send_control_data: "
1201 "ccw_device_start rc = %i\n", rc);
1202 QETH_DBF_TEXT_(TRACE, 2, " err%d", rc);
1203 qeth_release_buffer(iob->channel, iob);
1204 atomic_set(&card->write.irq_pending, 0);
1205 wake_up(&card->wait_q);
1207 return rc;
1210 static int qeth_osn_send_ipa_cmd(struct qeth_card *card,
1211 struct qeth_cmd_buffer *iob, int data_len)
1213 u16 s1, s2;
1215 QETH_DBF_TEXT(TRACE, 4, "osndipa");
1217 qeth_prepare_ipa_cmd(card, iob, QETH_PROT_OSN2);
1218 s1 = (u16)(IPA_PDU_HEADER_SIZE + data_len);
1219 s2 = (u16)data_len;
1220 memcpy(QETH_IPA_PDU_LEN_TOTAL(iob->data), &s1, 2);
1221 memcpy(QETH_IPA_PDU_LEN_PDU1(iob->data), &s2, 2);
1222 memcpy(QETH_IPA_PDU_LEN_PDU2(iob->data), &s2, 2);
1223 memcpy(QETH_IPA_PDU_LEN_PDU3(iob->data), &s2, 2);
1224 return qeth_osn_send_control_data(card, s1, iob);
1227 int qeth_osn_assist(struct net_device *dev, void *data, int data_len)
1229 struct qeth_cmd_buffer *iob;
1230 struct qeth_card *card;
1231 int rc;
1233 QETH_DBF_TEXT(TRACE, 2, "osnsdmc");
1234 if (!dev)
1235 return -ENODEV;
1236 card = dev->ml_priv;
1237 if (!card)
1238 return -ENODEV;
1239 if ((card->state != CARD_STATE_UP) &&
1240 (card->state != CARD_STATE_SOFTSETUP))
1241 return -ENODEV;
1242 iob = qeth_wait_for_buffer(&card->write);
1243 memcpy(iob->data+IPA_PDU_HEADER_SIZE, data, data_len);
1244 rc = qeth_osn_send_ipa_cmd(card, iob, data_len);
1245 return rc;
1247 EXPORT_SYMBOL(qeth_osn_assist);
1249 int qeth_osn_register(unsigned char *read_dev_no, struct net_device **dev,
1250 int (*assist_cb)(struct net_device *, void *),
1251 int (*data_cb)(struct sk_buff *))
1253 struct qeth_card *card;
1255 QETH_DBF_TEXT(TRACE, 2, "osnreg");
1256 *dev = qeth_l2_netdev_by_devno(read_dev_no);
1257 if (*dev == NULL)
1258 return -ENODEV;
1259 card = (*dev)->ml_priv;
1260 if (!card)
1261 return -ENODEV;
1262 if ((assist_cb == NULL) || (data_cb == NULL))
1263 return -EINVAL;
1264 card->osn_info.assist_cb = assist_cb;
1265 card->osn_info.data_cb = data_cb;
1266 return 0;
1268 EXPORT_SYMBOL(qeth_osn_register);
1270 void qeth_osn_deregister(struct net_device *dev)
1272 struct qeth_card *card;
1274 QETH_DBF_TEXT(TRACE, 2, "osndereg");
1275 if (!dev)
1276 return;
1277 card = dev->ml_priv;
1278 if (!card)
1279 return;
1280 card->osn_info.assist_cb = NULL;
1281 card->osn_info.data_cb = NULL;
1282 return;
1284 EXPORT_SYMBOL(qeth_osn_deregister);
1286 module_init(qeth_l2_init);
1287 module_exit(qeth_l2_exit);
1288 MODULE_AUTHOR("Frank Blaschka <frank.blaschka@de.ibm.com>");
1289 MODULE_DESCRIPTION("qeth layer 2 discipline");
1290 MODULE_LICENSE("GPL");