Kconfig: fix copy/paste-ism for dell-wmi-aio driver
[zen-stable.git] / drivers / s390 / net / qeth_l2_main.c
blob6fbaacb2194398c806b3180cf87e8625de5ee6be
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/slab.h>
20 #include <linux/etherdevice.h>
21 #include <linux/mii.h>
22 #include <linux/ip.h>
23 #include <linux/list.h>
25 #include "qeth_core.h"
27 static int qeth_l2_set_offline(struct ccwgroup_device *);
28 static int qeth_l2_stop(struct net_device *);
29 static int qeth_l2_send_delmac(struct qeth_card *, __u8 *);
30 static int qeth_l2_send_setdelmac(struct qeth_card *, __u8 *,
31 enum qeth_ipa_cmds,
32 int (*reply_cb) (struct qeth_card *,
33 struct qeth_reply*,
34 unsigned long));
35 static void qeth_l2_set_multicast_list(struct net_device *);
36 static int qeth_l2_recover(void *);
38 static int qeth_l2_do_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
40 struct qeth_card *card = dev->ml_priv;
41 struct mii_ioctl_data *mii_data;
42 int rc = 0;
44 if (!card)
45 return -ENODEV;
47 if ((card->state != CARD_STATE_UP) &&
48 (card->state != CARD_STATE_SOFTSETUP))
49 return -ENODEV;
51 if (card->info.type == QETH_CARD_TYPE_OSN)
52 return -EPERM;
54 switch (cmd) {
55 case SIOC_QETH_ADP_SET_SNMP_CONTROL:
56 rc = qeth_snmp_command(card, rq->ifr_ifru.ifru_data);
57 break;
58 case SIOC_QETH_GET_CARD_TYPE:
59 if ((card->info.type == QETH_CARD_TYPE_OSD ||
60 card->info.type == QETH_CARD_TYPE_OSM ||
61 card->info.type == QETH_CARD_TYPE_OSX) &&
62 !card->info.guestlan)
63 return 1;
64 return 0;
65 break;
66 case SIOCGMIIPHY:
67 mii_data = if_mii(rq);
68 mii_data->phy_id = 0;
69 break;
70 case SIOCGMIIREG:
71 mii_data = if_mii(rq);
72 if (mii_data->phy_id != 0)
73 rc = -EINVAL;
74 else
75 mii_data->val_out = qeth_mdio_read(dev,
76 mii_data->phy_id, mii_data->reg_num);
77 break;
78 default:
79 rc = -EOPNOTSUPP;
81 if (rc)
82 QETH_CARD_TEXT_(card, 2, "ioce%d", rc);
83 return rc;
86 static int qeth_l2_verify_dev(struct net_device *dev)
88 struct qeth_card *card;
89 unsigned long flags;
90 int rc = 0;
92 read_lock_irqsave(&qeth_core_card_list.rwlock, flags);
93 list_for_each_entry(card, &qeth_core_card_list.list, list) {
94 if (card->dev == dev) {
95 rc = QETH_REAL_CARD;
96 break;
99 read_unlock_irqrestore(&qeth_core_card_list.rwlock, flags);
101 return rc;
104 static struct net_device *qeth_l2_netdev_by_devno(unsigned char *read_dev_no)
106 struct qeth_card *card;
107 struct net_device *ndev;
108 __u16 temp_dev_no;
109 unsigned long flags;
110 struct ccw_dev_id read_devid;
112 ndev = NULL;
113 memcpy(&temp_dev_no, read_dev_no, 2);
114 read_lock_irqsave(&qeth_core_card_list.rwlock, flags);
115 list_for_each_entry(card, &qeth_core_card_list.list, list) {
116 ccw_device_get_id(CARD_RDEV(card), &read_devid);
117 if (read_devid.devno == temp_dev_no) {
118 ndev = card->dev;
119 break;
122 read_unlock_irqrestore(&qeth_core_card_list.rwlock, flags);
123 return ndev;
126 static int qeth_l2_send_setgroupmac_cb(struct qeth_card *card,
127 struct qeth_reply *reply,
128 unsigned long data)
130 struct qeth_ipa_cmd *cmd;
131 __u8 *mac;
133 QETH_CARD_TEXT(card, 2, "L2Sgmacb");
134 cmd = (struct qeth_ipa_cmd *) data;
135 mac = &cmd->data.setdelmac.mac[0];
136 /* MAC already registered, needed in couple/uncouple case */
137 if (cmd->hdr.return_code == IPA_RC_L2_DUP_MAC) {
138 QETH_DBF_MESSAGE(2, "Group MAC %pM already existing on %s \n",
139 mac, QETH_CARD_IFNAME(card));
140 cmd->hdr.return_code = 0;
142 if (cmd->hdr.return_code)
143 QETH_DBF_MESSAGE(2, "Could not set group MAC %pM on %s: %x\n",
144 mac, QETH_CARD_IFNAME(card), cmd->hdr.return_code);
145 return 0;
148 static int qeth_l2_send_setgroupmac(struct qeth_card *card, __u8 *mac)
150 QETH_CARD_TEXT(card, 2, "L2Sgmac");
151 return qeth_l2_send_setdelmac(card, mac, IPA_CMD_SETGMAC,
152 qeth_l2_send_setgroupmac_cb);
155 static int qeth_l2_send_delgroupmac_cb(struct qeth_card *card,
156 struct qeth_reply *reply,
157 unsigned long data)
159 struct qeth_ipa_cmd *cmd;
160 __u8 *mac;
162 QETH_CARD_TEXT(card, 2, "L2Dgmacb");
163 cmd = (struct qeth_ipa_cmd *) data;
164 mac = &cmd->data.setdelmac.mac[0];
165 if (cmd->hdr.return_code)
166 QETH_DBF_MESSAGE(2, "Could not delete group MAC %pM on %s: %x\n",
167 mac, QETH_CARD_IFNAME(card), cmd->hdr.return_code);
168 return 0;
171 static int qeth_l2_send_delgroupmac(struct qeth_card *card, __u8 *mac)
173 QETH_CARD_TEXT(card, 2, "L2Dgmac");
174 return qeth_l2_send_setdelmac(card, mac, IPA_CMD_DELGMAC,
175 qeth_l2_send_delgroupmac_cb);
178 static void qeth_l2_add_mc(struct qeth_card *card, __u8 *mac, int vmac)
180 struct qeth_mc_mac *mc;
181 int rc;
183 mc = kmalloc(sizeof(struct qeth_mc_mac), GFP_ATOMIC);
185 if (!mc)
186 return;
188 memcpy(mc->mc_addr, mac, OSA_ADDR_LEN);
189 mc->mc_addrlen = OSA_ADDR_LEN;
190 mc->is_vmac = vmac;
192 if (vmac) {
193 rc = qeth_l2_send_setdelmac(card, mac, IPA_CMD_SETVMAC,
194 NULL);
195 } else {
196 rc = qeth_l2_send_setgroupmac(card, mac);
199 if (!rc)
200 list_add_tail(&mc->list, &card->mc_list);
201 else
202 kfree(mc);
205 static void qeth_l2_del_all_mc(struct qeth_card *card, int del)
207 struct qeth_mc_mac *mc, *tmp;
209 spin_lock_bh(&card->mclock);
210 list_for_each_entry_safe(mc, tmp, &card->mc_list, list) {
211 if (del) {
212 if (mc->is_vmac)
213 qeth_l2_send_setdelmac(card, mc->mc_addr,
214 IPA_CMD_DELVMAC, NULL);
215 else
216 qeth_l2_send_delgroupmac(card, mc->mc_addr);
218 list_del(&mc->list);
219 kfree(mc);
221 spin_unlock_bh(&card->mclock);
224 static inline int qeth_l2_get_cast_type(struct qeth_card *card,
225 struct sk_buff *skb)
227 if (card->info.type == QETH_CARD_TYPE_OSN)
228 return RTN_UNSPEC;
229 if (is_broadcast_ether_addr(skb->data))
230 return RTN_BROADCAST;
231 if (is_multicast_ether_addr(skb->data))
232 return RTN_MULTICAST;
233 return RTN_UNSPEC;
236 static void qeth_l2_fill_header(struct qeth_card *card, struct qeth_hdr *hdr,
237 struct sk_buff *skb, int ipv, int cast_type)
239 struct vlan_ethhdr *veth = (struct vlan_ethhdr *)skb_mac_header(skb);
241 memset(hdr, 0, sizeof(struct qeth_hdr));
242 hdr->hdr.l2.id = QETH_HEADER_TYPE_LAYER2;
244 /* set byte byte 3 to casting flags */
245 if (cast_type == RTN_MULTICAST)
246 hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_MULTICAST;
247 else if (cast_type == RTN_BROADCAST)
248 hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_BROADCAST;
249 else
250 hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_UNICAST;
252 hdr->hdr.l2.pkt_length = skb->len-QETH_HEADER_SIZE;
253 /* VSWITCH relies on the VLAN
254 * information to be present in
255 * the QDIO header */
256 if (veth->h_vlan_proto == __constant_htons(ETH_P_8021Q)) {
257 hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_VLAN;
258 hdr->hdr.l2.vlan_id = ntohs(veth->h_vlan_TCI);
262 static int qeth_l2_send_setdelvlan_cb(struct qeth_card *card,
263 struct qeth_reply *reply, unsigned long data)
265 struct qeth_ipa_cmd *cmd;
267 QETH_CARD_TEXT(card, 2, "L2sdvcb");
268 cmd = (struct qeth_ipa_cmd *) data;
269 if (cmd->hdr.return_code) {
270 QETH_DBF_MESSAGE(2, "Error in processing VLAN %i on %s: 0x%x. "
271 "Continuing\n", cmd->data.setdelvlan.vlan_id,
272 QETH_CARD_IFNAME(card), cmd->hdr.return_code);
273 QETH_CARD_TEXT_(card, 2, "L2VL%4x", cmd->hdr.command);
274 QETH_CARD_TEXT_(card, 2, "err%d", cmd->hdr.return_code);
276 return 0;
279 static int qeth_l2_send_setdelvlan(struct qeth_card *card, __u16 i,
280 enum qeth_ipa_cmds ipacmd)
282 struct qeth_ipa_cmd *cmd;
283 struct qeth_cmd_buffer *iob;
285 QETH_CARD_TEXT_(card, 4, "L2sdv%x", ipacmd);
286 iob = qeth_get_ipacmd_buffer(card, ipacmd, QETH_PROT_IPV4);
287 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
288 cmd->data.setdelvlan.vlan_id = i;
289 return qeth_send_ipa_cmd(card, iob,
290 qeth_l2_send_setdelvlan_cb, NULL);
293 static void qeth_l2_process_vlans(struct qeth_card *card)
295 struct qeth_vlan_vid *id;
296 QETH_CARD_TEXT(card, 3, "L2prcvln");
297 spin_lock_bh(&card->vlanlock);
298 list_for_each_entry(id, &card->vid_list, list) {
299 qeth_l2_send_setdelvlan(card, id->vid, IPA_CMD_SETVLAN);
301 spin_unlock_bh(&card->vlanlock);
304 static void qeth_l2_vlan_rx_add_vid(struct net_device *dev, unsigned short vid)
306 struct qeth_card *card = dev->ml_priv;
307 struct qeth_vlan_vid *id;
309 QETH_CARD_TEXT_(card, 4, "aid:%d", vid);
310 if (!vid)
311 return;
312 if (card->info.type == QETH_CARD_TYPE_OSM) {
313 QETH_CARD_TEXT(card, 3, "aidOSM");
314 return;
316 if (qeth_wait_for_threads(card, QETH_RECOVER_THREAD)) {
317 QETH_CARD_TEXT(card, 3, "aidREC");
318 return;
320 id = kmalloc(sizeof(struct qeth_vlan_vid), GFP_ATOMIC);
321 if (id) {
322 id->vid = vid;
323 qeth_l2_send_setdelvlan(card, vid, IPA_CMD_SETVLAN);
324 spin_lock_bh(&card->vlanlock);
325 list_add_tail(&id->list, &card->vid_list);
326 spin_unlock_bh(&card->vlanlock);
330 static void qeth_l2_vlan_rx_kill_vid(struct net_device *dev, unsigned short vid)
332 struct qeth_vlan_vid *id, *tmpid = NULL;
333 struct qeth_card *card = dev->ml_priv;
335 QETH_CARD_TEXT_(card, 4, "kid:%d", vid);
336 if (card->info.type == QETH_CARD_TYPE_OSM) {
337 QETH_CARD_TEXT(card, 3, "kidOSM");
338 return;
340 if (qeth_wait_for_threads(card, QETH_RECOVER_THREAD)) {
341 QETH_CARD_TEXT(card, 3, "kidREC");
342 return;
344 spin_lock_bh(&card->vlanlock);
345 list_for_each_entry(id, &card->vid_list, list) {
346 if (id->vid == vid) {
347 list_del(&id->list);
348 tmpid = id;
349 break;
352 spin_unlock_bh(&card->vlanlock);
353 if (tmpid) {
354 qeth_l2_send_setdelvlan(card, vid, IPA_CMD_DELVLAN);
355 kfree(tmpid);
357 qeth_l2_set_multicast_list(card->dev);
360 static int qeth_l2_stop_card(struct qeth_card *card, int recovery_mode)
362 int rc = 0;
364 QETH_DBF_TEXT(SETUP , 2, "stopcard");
365 QETH_DBF_HEX(SETUP, 2, &card, sizeof(void *));
367 qeth_set_allowed_threads(card, 0, 1);
368 if (card->read.state == CH_STATE_UP &&
369 card->write.state == CH_STATE_UP &&
370 (card->state == CARD_STATE_UP)) {
371 if (recovery_mode &&
372 card->info.type != QETH_CARD_TYPE_OSN) {
373 qeth_l2_stop(card->dev);
374 } else {
375 rtnl_lock();
376 dev_close(card->dev);
377 rtnl_unlock();
379 card->info.mac_bits &= ~QETH_LAYER2_MAC_REGISTERED;
380 card->state = CARD_STATE_SOFTSETUP;
382 if (card->state == CARD_STATE_SOFTSETUP) {
383 qeth_l2_del_all_mc(card, 0);
384 qeth_clear_ipacmd_list(card);
385 card->state = CARD_STATE_HARDSETUP;
387 if (card->state == CARD_STATE_HARDSETUP) {
388 qeth_qdio_clear_card(card, 0);
389 qeth_clear_qdio_buffers(card);
390 qeth_clear_working_pool_list(card);
391 card->state = CARD_STATE_DOWN;
393 if (card->state == CARD_STATE_DOWN) {
394 qeth_clear_cmd_buffers(&card->read);
395 qeth_clear_cmd_buffers(&card->write);
397 return rc;
400 static int qeth_l2_process_inbound_buffer(struct qeth_card *card,
401 int budget, int *done)
403 int work_done = 0;
404 struct sk_buff *skb;
405 struct qeth_hdr *hdr;
406 unsigned int len;
408 *done = 0;
409 BUG_ON(!budget);
410 while (budget) {
411 skb = qeth_core_get_next_skb(card,
412 card->qdio.in_q->bufs[card->rx.b_index].buffer,
413 &card->rx.b_element, &card->rx.e_offset, &hdr);
414 if (!skb) {
415 *done = 1;
416 break;
418 skb->dev = card->dev;
419 switch (hdr->hdr.l2.id) {
420 case QETH_HEADER_TYPE_LAYER2:
421 skb->pkt_type = PACKET_HOST;
422 skb->protocol = eth_type_trans(skb, skb->dev);
423 if (card->options.checksum_type == NO_CHECKSUMMING)
424 skb->ip_summed = CHECKSUM_UNNECESSARY;
425 else
426 skb->ip_summed = CHECKSUM_NONE;
427 if (skb->protocol == htons(ETH_P_802_2))
428 *((__u32 *)skb->cb) = ++card->seqno.pkt_seqno;
429 len = skb->len;
430 netif_receive_skb(skb);
431 break;
432 case QETH_HEADER_TYPE_OSN:
433 if (card->info.type == QETH_CARD_TYPE_OSN) {
434 skb_push(skb, sizeof(struct qeth_hdr));
435 skb_copy_to_linear_data(skb, hdr,
436 sizeof(struct qeth_hdr));
437 len = skb->len;
438 card->osn_info.data_cb(skb);
439 break;
441 /* else unknown */
442 default:
443 dev_kfree_skb_any(skb);
444 QETH_CARD_TEXT(card, 3, "inbunkno");
445 QETH_DBF_HEX(CTRL, 3, hdr, QETH_DBF_CTRL_LEN);
446 continue;
448 work_done++;
449 budget--;
450 card->stats.rx_packets++;
451 card->stats.rx_bytes += len;
453 return work_done;
456 static int qeth_l2_poll(struct napi_struct *napi, int budget)
458 struct qeth_card *card = container_of(napi, struct qeth_card, napi);
459 int work_done = 0;
460 struct qeth_qdio_buffer *buffer;
461 int done;
462 int new_budget = budget;
464 if (card->options.performance_stats) {
465 card->perf_stats.inbound_cnt++;
466 card->perf_stats.inbound_start_time = qeth_get_micros();
469 while (1) {
470 if (!card->rx.b_count) {
471 card->rx.qdio_err = 0;
472 card->rx.b_count = qdio_get_next_buffers(
473 card->data.ccwdev, 0, &card->rx.b_index,
474 &card->rx.qdio_err);
475 if (card->rx.b_count <= 0) {
476 card->rx.b_count = 0;
477 break;
479 card->rx.b_element =
480 &card->qdio.in_q->bufs[card->rx.b_index]
481 .buffer->element[0];
482 card->rx.e_offset = 0;
485 while (card->rx.b_count) {
486 buffer = &card->qdio.in_q->bufs[card->rx.b_index];
487 if (!(card->rx.qdio_err &&
488 qeth_check_qdio_errors(card, buffer->buffer,
489 card->rx.qdio_err, "qinerr")))
490 work_done += qeth_l2_process_inbound_buffer(
491 card, new_budget, &done);
492 else
493 done = 1;
495 if (done) {
496 if (card->options.performance_stats)
497 card->perf_stats.bufs_rec++;
498 qeth_put_buffer_pool_entry(card,
499 buffer->pool_entry);
500 qeth_queue_input_buffer(card, card->rx.b_index);
501 card->rx.b_count--;
502 if (card->rx.b_count) {
503 card->rx.b_index =
504 (card->rx.b_index + 1) %
505 QDIO_MAX_BUFFERS_PER_Q;
506 card->rx.b_element =
507 &card->qdio.in_q
508 ->bufs[card->rx.b_index]
509 .buffer->element[0];
510 card->rx.e_offset = 0;
514 if (work_done >= budget)
515 goto out;
516 else
517 new_budget = budget - work_done;
521 napi_complete(napi);
522 if (qdio_start_irq(card->data.ccwdev, 0))
523 napi_schedule(&card->napi);
524 out:
525 if (card->options.performance_stats)
526 card->perf_stats.inbound_time += qeth_get_micros() -
527 card->perf_stats.inbound_start_time;
528 return work_done;
531 static int qeth_l2_send_setdelmac(struct qeth_card *card, __u8 *mac,
532 enum qeth_ipa_cmds ipacmd,
533 int (*reply_cb) (struct qeth_card *,
534 struct qeth_reply*,
535 unsigned long))
537 struct qeth_ipa_cmd *cmd;
538 struct qeth_cmd_buffer *iob;
540 QETH_CARD_TEXT(card, 2, "L2sdmac");
541 iob = qeth_get_ipacmd_buffer(card, ipacmd, QETH_PROT_IPV4);
542 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
543 cmd->data.setdelmac.mac_length = OSA_ADDR_LEN;
544 memcpy(&cmd->data.setdelmac.mac, mac, OSA_ADDR_LEN);
545 return qeth_send_ipa_cmd(card, iob, reply_cb, NULL);
548 static int qeth_l2_send_setmac_cb(struct qeth_card *card,
549 struct qeth_reply *reply,
550 unsigned long data)
552 struct qeth_ipa_cmd *cmd;
554 QETH_CARD_TEXT(card, 2, "L2Smaccb");
555 cmd = (struct qeth_ipa_cmd *) data;
556 if (cmd->hdr.return_code) {
557 QETH_CARD_TEXT_(card, 2, "L2er%x", cmd->hdr.return_code);
558 card->info.mac_bits &= ~QETH_LAYER2_MAC_REGISTERED;
559 switch (cmd->hdr.return_code) {
560 case IPA_RC_L2_DUP_MAC:
561 case IPA_RC_L2_DUP_LAYER3_MAC:
562 dev_warn(&card->gdev->dev,
563 "MAC address %pM already exists\n",
564 cmd->data.setdelmac.mac);
565 break;
566 case IPA_RC_L2_MAC_NOT_AUTH_BY_HYP:
567 case IPA_RC_L2_MAC_NOT_AUTH_BY_ADP:
568 dev_warn(&card->gdev->dev,
569 "MAC address %pM is not authorized\n",
570 cmd->data.setdelmac.mac);
571 break;
572 default:
573 break;
575 cmd->hdr.return_code = -EIO;
576 } else {
577 card->info.mac_bits |= QETH_LAYER2_MAC_REGISTERED;
578 memcpy(card->dev->dev_addr, cmd->data.setdelmac.mac,
579 OSA_ADDR_LEN);
580 dev_info(&card->gdev->dev,
581 "MAC address %pM successfully registered on device %s\n",
582 card->dev->dev_addr, card->dev->name);
584 return 0;
587 static int qeth_l2_send_setmac(struct qeth_card *card, __u8 *mac)
589 QETH_CARD_TEXT(card, 2, "L2Setmac");
590 return qeth_l2_send_setdelmac(card, mac, IPA_CMD_SETVMAC,
591 qeth_l2_send_setmac_cb);
594 static int qeth_l2_send_delmac_cb(struct qeth_card *card,
595 struct qeth_reply *reply,
596 unsigned long data)
598 struct qeth_ipa_cmd *cmd;
600 QETH_CARD_TEXT(card, 2, "L2Dmaccb");
601 cmd = (struct qeth_ipa_cmd *) data;
602 if (cmd->hdr.return_code) {
603 QETH_CARD_TEXT_(card, 2, "err%d", cmd->hdr.return_code);
604 cmd->hdr.return_code = -EIO;
605 return 0;
607 card->info.mac_bits &= ~QETH_LAYER2_MAC_REGISTERED;
609 return 0;
612 static int qeth_l2_send_delmac(struct qeth_card *card, __u8 *mac)
614 QETH_CARD_TEXT(card, 2, "L2Delmac");
615 if (!(card->info.mac_bits & QETH_LAYER2_MAC_REGISTERED))
616 return 0;
617 return qeth_l2_send_setdelmac(card, mac, IPA_CMD_DELVMAC,
618 qeth_l2_send_delmac_cb);
621 static int qeth_l2_request_initial_mac(struct qeth_card *card)
623 int rc = 0;
624 char vendor_pre[] = {0x02, 0x00, 0x00};
626 QETH_DBF_TEXT(SETUP, 2, "doL2init");
627 QETH_DBF_TEXT_(SETUP, 2, "doL2%s", CARD_BUS_ID(card));
629 rc = qeth_query_setadapterparms(card);
630 if (rc) {
631 QETH_DBF_MESSAGE(2, "could not query adapter parameters on "
632 "device %s: x%x\n", CARD_BUS_ID(card), rc);
635 if (card->info.type == QETH_CARD_TYPE_IQD ||
636 card->info.type == QETH_CARD_TYPE_OSM ||
637 card->info.type == QETH_CARD_TYPE_OSX ||
638 card->info.guestlan) {
639 rc = qeth_setadpparms_change_macaddr(card);
640 if (rc) {
641 QETH_DBF_MESSAGE(2, "couldn't get MAC address on "
642 "device %s: x%x\n", CARD_BUS_ID(card), rc);
643 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
644 return rc;
646 QETH_DBF_HEX(SETUP, 2, card->dev->dev_addr, OSA_ADDR_LEN);
647 } else {
648 random_ether_addr(card->dev->dev_addr);
649 memcpy(card->dev->dev_addr, vendor_pre, 3);
651 return 0;
654 static int qeth_l2_set_mac_address(struct net_device *dev, void *p)
656 struct sockaddr *addr = p;
657 struct qeth_card *card = dev->ml_priv;
658 int rc = 0;
660 QETH_CARD_TEXT(card, 3, "setmac");
662 if (qeth_l2_verify_dev(dev) != QETH_REAL_CARD) {
663 QETH_CARD_TEXT(card, 3, "setmcINV");
664 return -EOPNOTSUPP;
667 if (card->info.type == QETH_CARD_TYPE_OSN ||
668 card->info.type == QETH_CARD_TYPE_OSM ||
669 card->info.type == QETH_CARD_TYPE_OSX) {
670 QETH_CARD_TEXT(card, 3, "setmcTYP");
671 return -EOPNOTSUPP;
673 QETH_CARD_HEX(card, 3, addr->sa_data, OSA_ADDR_LEN);
674 if (qeth_wait_for_threads(card, QETH_RECOVER_THREAD)) {
675 QETH_CARD_TEXT(card, 3, "setmcREC");
676 return -ERESTARTSYS;
678 rc = qeth_l2_send_delmac(card, &card->dev->dev_addr[0]);
679 if (!rc)
680 rc = qeth_l2_send_setmac(card, addr->sa_data);
681 return rc;
684 static void qeth_l2_set_multicast_list(struct net_device *dev)
686 struct qeth_card *card = dev->ml_priv;
687 struct netdev_hw_addr *ha;
689 if (card->info.type == QETH_CARD_TYPE_OSN)
690 return ;
692 QETH_CARD_TEXT(card, 3, "setmulti");
693 if (qeth_threads_running(card, QETH_RECOVER_THREAD) &&
694 (card->state != CARD_STATE_UP))
695 return;
696 qeth_l2_del_all_mc(card, 1);
697 spin_lock_bh(&card->mclock);
698 netdev_for_each_mc_addr(ha, dev)
699 qeth_l2_add_mc(card, ha->addr, 0);
701 netdev_for_each_uc_addr(ha, dev)
702 qeth_l2_add_mc(card, ha->addr, 1);
704 spin_unlock_bh(&card->mclock);
705 if (!qeth_adp_supported(card, IPA_SETADP_SET_PROMISC_MODE))
706 return;
707 qeth_setadp_promisc_mode(card);
710 static int qeth_l2_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
712 int rc;
713 struct qeth_hdr *hdr = NULL;
714 int elements = 0;
715 struct qeth_card *card = dev->ml_priv;
716 struct sk_buff *new_skb = skb;
717 int ipv = qeth_get_ip_version(skb);
718 int cast_type = qeth_l2_get_cast_type(card, skb);
719 struct qeth_qdio_out_q *queue = card->qdio.out_qs
720 [qeth_get_priority_queue(card, skb, ipv, cast_type)];
721 int tx_bytes = skb->len;
722 int data_offset = -1;
723 int elements_needed = 0;
724 int hd_len = 0;
726 if ((card->state != CARD_STATE_UP) || !card->lan_online) {
727 card->stats.tx_carrier_errors++;
728 goto tx_drop;
731 if ((card->info.type == QETH_CARD_TYPE_OSN) &&
732 (skb->protocol == htons(ETH_P_IPV6)))
733 goto tx_drop;
735 if (card->options.performance_stats) {
736 card->perf_stats.outbound_cnt++;
737 card->perf_stats.outbound_start_time = qeth_get_micros();
739 netif_stop_queue(dev);
741 if (card->info.type == QETH_CARD_TYPE_OSN)
742 hdr = (struct qeth_hdr *)skb->data;
743 else {
744 if (card->info.type == QETH_CARD_TYPE_IQD) {
745 new_skb = skb;
746 data_offset = ETH_HLEN;
747 hd_len = ETH_HLEN;
748 hdr = kmem_cache_alloc(qeth_core_header_cache,
749 GFP_ATOMIC);
750 if (!hdr)
751 goto tx_drop;
752 elements_needed++;
753 skb_reset_mac_header(new_skb);
754 qeth_l2_fill_header(card, hdr, new_skb, ipv, cast_type);
755 hdr->hdr.l2.pkt_length = new_skb->len;
756 memcpy(((char *)hdr) + sizeof(struct qeth_hdr),
757 skb_mac_header(new_skb), ETH_HLEN);
758 } else {
759 /* create a clone with writeable headroom */
760 new_skb = skb_realloc_headroom(skb,
761 sizeof(struct qeth_hdr));
762 if (!new_skb)
763 goto tx_drop;
764 hdr = (struct qeth_hdr *)skb_push(new_skb,
765 sizeof(struct qeth_hdr));
766 skb_set_mac_header(new_skb, sizeof(struct qeth_hdr));
767 qeth_l2_fill_header(card, hdr, new_skb, ipv, cast_type);
771 elements = qeth_get_elements_no(card, (void *)hdr, new_skb,
772 elements_needed);
773 if (!elements) {
774 if (data_offset >= 0)
775 kmem_cache_free(qeth_core_header_cache, hdr);
776 goto tx_drop;
779 if (card->info.type != QETH_CARD_TYPE_IQD) {
780 if (qeth_hdr_chk_and_bounce(new_skb,
781 sizeof(struct qeth_hdr_layer2)))
782 goto tx_drop;
783 rc = qeth_do_send_packet(card, queue, new_skb, hdr,
784 elements);
785 } else
786 rc = qeth_do_send_packet_fast(card, queue, new_skb, hdr,
787 elements, data_offset, hd_len);
788 if (!rc) {
789 card->stats.tx_packets++;
790 card->stats.tx_bytes += tx_bytes;
791 if (new_skb != skb)
792 dev_kfree_skb_any(skb);
793 rc = NETDEV_TX_OK;
794 } else {
795 if (data_offset >= 0)
796 kmem_cache_free(qeth_core_header_cache, hdr);
798 if (rc == -EBUSY) {
799 if (new_skb != skb)
800 dev_kfree_skb_any(new_skb);
801 return NETDEV_TX_BUSY;
802 } else
803 goto tx_drop;
806 netif_wake_queue(dev);
807 if (card->options.performance_stats)
808 card->perf_stats.outbound_time += qeth_get_micros() -
809 card->perf_stats.outbound_start_time;
810 return rc;
812 tx_drop:
813 card->stats.tx_dropped++;
814 card->stats.tx_errors++;
815 if ((new_skb != skb) && new_skb)
816 dev_kfree_skb_any(new_skb);
817 dev_kfree_skb_any(skb);
818 netif_wake_queue(dev);
819 return NETDEV_TX_OK;
822 static int __qeth_l2_open(struct net_device *dev)
824 struct qeth_card *card = dev->ml_priv;
825 int rc = 0;
827 QETH_CARD_TEXT(card, 4, "qethopen");
828 if (card->state == CARD_STATE_UP)
829 return rc;
830 if (card->state != CARD_STATE_SOFTSETUP)
831 return -ENODEV;
833 if ((card->info.type != QETH_CARD_TYPE_OSN) &&
834 (!(card->info.mac_bits & QETH_LAYER2_MAC_REGISTERED))) {
835 QETH_CARD_TEXT(card, 4, "nomacadr");
836 return -EPERM;
838 card->data.state = CH_STATE_UP;
839 card->state = CARD_STATE_UP;
840 netif_start_queue(dev);
842 if (qdio_stop_irq(card->data.ccwdev, 0) >= 0) {
843 napi_enable(&card->napi);
844 napi_schedule(&card->napi);
845 } else
846 rc = -EIO;
847 return rc;
850 static int qeth_l2_open(struct net_device *dev)
852 struct qeth_card *card = dev->ml_priv;
854 QETH_CARD_TEXT(card, 5, "qethope_");
855 if (qeth_wait_for_threads(card, QETH_RECOVER_THREAD)) {
856 QETH_CARD_TEXT(card, 3, "openREC");
857 return -ERESTARTSYS;
859 return __qeth_l2_open(dev);
862 static int qeth_l2_stop(struct net_device *dev)
864 struct qeth_card *card = dev->ml_priv;
866 QETH_CARD_TEXT(card, 4, "qethstop");
867 netif_tx_disable(dev);
868 if (card->state == CARD_STATE_UP) {
869 card->state = CARD_STATE_SOFTSETUP;
870 napi_disable(&card->napi);
872 return 0;
875 static int qeth_l2_probe_device(struct ccwgroup_device *gdev)
877 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
879 INIT_LIST_HEAD(&card->vid_list);
880 INIT_LIST_HEAD(&card->mc_list);
881 card->options.layer2 = 1;
882 card->discipline.start_poll = qeth_qdio_start_poll;
883 card->discipline.input_handler = (qdio_handler_t *)
884 qeth_qdio_input_handler;
885 card->discipline.output_handler = (qdio_handler_t *)
886 qeth_qdio_output_handler;
887 card->discipline.recover = qeth_l2_recover;
888 return 0;
891 static void qeth_l2_remove_device(struct ccwgroup_device *cgdev)
893 struct qeth_card *card = dev_get_drvdata(&cgdev->dev);
895 qeth_set_allowed_threads(card, 0, 1);
896 wait_event(card->wait_q, qeth_threads_running(card, 0xffffffff) == 0);
898 if (cgdev->state == CCWGROUP_ONLINE)
899 qeth_l2_set_offline(cgdev);
901 if (card->dev) {
902 unregister_netdev(card->dev);
903 card->dev = NULL;
905 return;
908 static const struct ethtool_ops qeth_l2_ethtool_ops = {
909 .get_link = ethtool_op_get_link,
910 .get_strings = qeth_core_get_strings,
911 .get_ethtool_stats = qeth_core_get_ethtool_stats,
912 .get_sset_count = qeth_core_get_sset_count,
913 .get_drvinfo = qeth_core_get_drvinfo,
914 .get_settings = qeth_core_ethtool_get_settings,
917 static const struct ethtool_ops qeth_l2_osn_ops = {
918 .get_strings = qeth_core_get_strings,
919 .get_ethtool_stats = qeth_core_get_ethtool_stats,
920 .get_sset_count = qeth_core_get_sset_count,
921 .get_drvinfo = qeth_core_get_drvinfo,
924 static const struct net_device_ops qeth_l2_netdev_ops = {
925 .ndo_open = qeth_l2_open,
926 .ndo_stop = qeth_l2_stop,
927 .ndo_get_stats = qeth_get_stats,
928 .ndo_start_xmit = qeth_l2_hard_start_xmit,
929 .ndo_validate_addr = eth_validate_addr,
930 .ndo_set_multicast_list = qeth_l2_set_multicast_list,
931 .ndo_do_ioctl = qeth_l2_do_ioctl,
932 .ndo_set_mac_address = qeth_l2_set_mac_address,
933 .ndo_change_mtu = qeth_change_mtu,
934 .ndo_vlan_rx_add_vid = qeth_l2_vlan_rx_add_vid,
935 .ndo_vlan_rx_kill_vid = qeth_l2_vlan_rx_kill_vid,
936 .ndo_tx_timeout = qeth_tx_timeout,
939 static int qeth_l2_setup_netdev(struct qeth_card *card)
941 switch (card->info.type) {
942 case QETH_CARD_TYPE_IQD:
943 card->dev = alloc_netdev(0, "hsi%d", ether_setup);
944 break;
945 case QETH_CARD_TYPE_OSN:
946 card->dev = alloc_netdev(0, "osn%d", ether_setup);
947 card->dev->flags |= IFF_NOARP;
948 break;
949 default:
950 card->dev = alloc_etherdev(0);
953 if (!card->dev)
954 return -ENODEV;
956 card->dev->ml_priv = card;
957 card->dev->watchdog_timeo = QETH_TX_TIMEOUT;
958 card->dev->mtu = card->info.initial_mtu;
959 card->dev->netdev_ops = &qeth_l2_netdev_ops;
960 if (card->info.type != QETH_CARD_TYPE_OSN)
961 SET_ETHTOOL_OPS(card->dev, &qeth_l2_ethtool_ops);
962 else
963 SET_ETHTOOL_OPS(card->dev, &qeth_l2_osn_ops);
964 card->dev->features |= NETIF_F_HW_VLAN_FILTER;
965 card->info.broadcast_capable = 1;
966 qeth_l2_request_initial_mac(card);
967 SET_NETDEV_DEV(card->dev, &card->gdev->dev);
968 netif_napi_add(card->dev, &card->napi, qeth_l2_poll, QETH_NAPI_WEIGHT);
969 return register_netdev(card->dev);
972 static int __qeth_l2_set_online(struct ccwgroup_device *gdev, int recovery_mode)
974 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
975 int rc = 0;
976 enum qeth_card_states recover_flag;
978 BUG_ON(!card);
979 mutex_lock(&card->discipline_mutex);
980 mutex_lock(&card->conf_mutex);
981 QETH_DBF_TEXT(SETUP, 2, "setonlin");
982 QETH_DBF_HEX(SETUP, 2, &card, sizeof(void *));
984 recover_flag = card->state;
985 rc = qeth_core_hardsetup_card(card);
986 if (rc) {
987 QETH_DBF_TEXT_(SETUP, 2, "2err%d", rc);
988 rc = -ENODEV;
989 goto out_remove;
992 if (!card->dev && qeth_l2_setup_netdev(card)) {
993 rc = -ENODEV;
994 goto out_remove;
997 if (card->info.type != QETH_CARD_TYPE_OSN)
998 qeth_l2_send_setmac(card, &card->dev->dev_addr[0]);
1000 card->state = CARD_STATE_HARDSETUP;
1001 memset(&card->rx, 0, sizeof(struct qeth_rx));
1002 qeth_print_status_message(card);
1004 /* softsetup */
1005 QETH_DBF_TEXT(SETUP, 2, "softsetp");
1007 rc = qeth_send_startlan(card);
1008 if (rc) {
1009 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
1010 if (rc == 0xe080) {
1011 dev_warn(&card->gdev->dev,
1012 "The LAN is offline\n");
1013 card->lan_online = 0;
1014 goto contin;
1016 rc = -ENODEV;
1017 goto out_remove;
1018 } else
1019 card->lan_online = 1;
1021 contin:
1022 if ((card->info.type == QETH_CARD_TYPE_OSD) ||
1023 (card->info.type == QETH_CARD_TYPE_OSX))
1024 /* configure isolation level */
1025 qeth_set_access_ctrl_online(card);
1027 if (card->info.type != QETH_CARD_TYPE_OSN &&
1028 card->info.type != QETH_CARD_TYPE_OSM)
1029 qeth_l2_process_vlans(card);
1031 netif_tx_disable(card->dev);
1033 rc = qeth_init_qdio_queues(card);
1034 if (rc) {
1035 QETH_DBF_TEXT_(SETUP, 2, "6err%d", rc);
1036 rc = -ENODEV;
1037 goto out_remove;
1039 card->state = CARD_STATE_SOFTSETUP;
1040 if (card->lan_online)
1041 netif_carrier_on(card->dev);
1042 else
1043 netif_carrier_off(card->dev);
1045 qeth_set_allowed_threads(card, 0xffffffff, 0);
1046 if (recover_flag == CARD_STATE_RECOVER) {
1047 if (recovery_mode &&
1048 card->info.type != QETH_CARD_TYPE_OSN) {
1049 __qeth_l2_open(card->dev);
1050 } else {
1051 rtnl_lock();
1052 dev_open(card->dev);
1053 rtnl_unlock();
1055 /* this also sets saved unicast addresses */
1056 qeth_l2_set_multicast_list(card->dev);
1058 /* let user_space know that device is online */
1059 kobject_uevent(&gdev->dev.kobj, KOBJ_CHANGE);
1060 mutex_unlock(&card->conf_mutex);
1061 mutex_unlock(&card->discipline_mutex);
1062 return 0;
1064 out_remove:
1065 qeth_l2_stop_card(card, 0);
1066 ccw_device_set_offline(CARD_DDEV(card));
1067 ccw_device_set_offline(CARD_WDEV(card));
1068 ccw_device_set_offline(CARD_RDEV(card));
1069 if (recover_flag == CARD_STATE_RECOVER)
1070 card->state = CARD_STATE_RECOVER;
1071 else
1072 card->state = CARD_STATE_DOWN;
1073 mutex_unlock(&card->conf_mutex);
1074 mutex_unlock(&card->discipline_mutex);
1075 return rc;
1078 static int qeth_l2_set_online(struct ccwgroup_device *gdev)
1080 return __qeth_l2_set_online(gdev, 0);
1083 static int __qeth_l2_set_offline(struct ccwgroup_device *cgdev,
1084 int recovery_mode)
1086 struct qeth_card *card = dev_get_drvdata(&cgdev->dev);
1087 int rc = 0, rc2 = 0, rc3 = 0;
1088 enum qeth_card_states recover_flag;
1090 mutex_lock(&card->discipline_mutex);
1091 mutex_lock(&card->conf_mutex);
1092 QETH_DBF_TEXT(SETUP, 3, "setoffl");
1093 QETH_DBF_HEX(SETUP, 3, &card, sizeof(void *));
1095 if (card->dev && netif_carrier_ok(card->dev))
1096 netif_carrier_off(card->dev);
1097 recover_flag = card->state;
1098 qeth_l2_stop_card(card, recovery_mode);
1099 rc = ccw_device_set_offline(CARD_DDEV(card));
1100 rc2 = ccw_device_set_offline(CARD_WDEV(card));
1101 rc3 = ccw_device_set_offline(CARD_RDEV(card));
1102 if (!rc)
1103 rc = (rc2) ? rc2 : rc3;
1104 if (rc)
1105 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
1106 if (recover_flag == CARD_STATE_UP)
1107 card->state = CARD_STATE_RECOVER;
1108 /* let user_space know that device is offline */
1109 kobject_uevent(&cgdev->dev.kobj, KOBJ_CHANGE);
1110 mutex_unlock(&card->conf_mutex);
1111 mutex_unlock(&card->discipline_mutex);
1112 return 0;
1115 static int qeth_l2_set_offline(struct ccwgroup_device *cgdev)
1117 return __qeth_l2_set_offline(cgdev, 0);
1120 static int qeth_l2_recover(void *ptr)
1122 struct qeth_card *card;
1123 int rc = 0;
1125 card = (struct qeth_card *) ptr;
1126 QETH_CARD_TEXT(card, 2, "recover1");
1127 if (!qeth_do_run_thread(card, QETH_RECOVER_THREAD))
1128 return 0;
1129 QETH_CARD_TEXT(card, 2, "recover2");
1130 dev_warn(&card->gdev->dev,
1131 "A recovery process has been started for the device\n");
1132 __qeth_l2_set_offline(card->gdev, 1);
1133 rc = __qeth_l2_set_online(card->gdev, 1);
1134 if (!rc)
1135 dev_info(&card->gdev->dev,
1136 "Device successfully recovered!\n");
1137 else {
1138 rtnl_lock();
1139 dev_close(card->dev);
1140 rtnl_unlock();
1141 dev_warn(&card->gdev->dev, "The qeth device driver "
1142 "failed to recover an error on the device\n");
1144 qeth_clear_thread_start_bit(card, QETH_RECOVER_THREAD);
1145 qeth_clear_thread_running_bit(card, QETH_RECOVER_THREAD);
1146 return 0;
1149 static int __init qeth_l2_init(void)
1151 pr_info("register layer 2 discipline\n");
1152 return 0;
1155 static void __exit qeth_l2_exit(void)
1157 pr_info("unregister layer 2 discipline\n");
1160 static void qeth_l2_shutdown(struct ccwgroup_device *gdev)
1162 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
1163 qeth_qdio_clear_card(card, 0);
1164 qeth_clear_qdio_buffers(card);
1167 static int qeth_l2_pm_suspend(struct ccwgroup_device *gdev)
1169 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
1171 if (card->dev)
1172 netif_device_detach(card->dev);
1173 qeth_set_allowed_threads(card, 0, 1);
1174 wait_event(card->wait_q, qeth_threads_running(card, 0xffffffff) == 0);
1175 if (gdev->state == CCWGROUP_OFFLINE)
1176 return 0;
1177 if (card->state == CARD_STATE_UP) {
1178 __qeth_l2_set_offline(card->gdev, 1);
1179 } else
1180 __qeth_l2_set_offline(card->gdev, 0);
1181 return 0;
1184 static int qeth_l2_pm_resume(struct ccwgroup_device *gdev)
1186 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
1187 int rc = 0;
1189 if (gdev->state == CCWGROUP_OFFLINE)
1190 goto out;
1192 if (card->state == CARD_STATE_RECOVER) {
1193 rc = __qeth_l2_set_online(card->gdev, 1);
1194 if (rc) {
1195 rtnl_lock();
1196 dev_close(card->dev);
1197 rtnl_unlock();
1199 } else
1200 rc = __qeth_l2_set_online(card->gdev, 0);
1201 out:
1202 qeth_set_allowed_threads(card, 0xffffffff, 0);
1203 if (card->dev)
1204 netif_device_attach(card->dev);
1205 if (rc)
1206 dev_warn(&card->gdev->dev, "The qeth device driver "
1207 "failed to recover an error on the device\n");
1208 return rc;
1211 struct ccwgroup_driver qeth_l2_ccwgroup_driver = {
1212 .probe = qeth_l2_probe_device,
1213 .remove = qeth_l2_remove_device,
1214 .set_online = qeth_l2_set_online,
1215 .set_offline = qeth_l2_set_offline,
1216 .shutdown = qeth_l2_shutdown,
1217 .freeze = qeth_l2_pm_suspend,
1218 .thaw = qeth_l2_pm_resume,
1219 .restore = qeth_l2_pm_resume,
1221 EXPORT_SYMBOL_GPL(qeth_l2_ccwgroup_driver);
1223 static int qeth_osn_send_control_data(struct qeth_card *card, int len,
1224 struct qeth_cmd_buffer *iob)
1226 unsigned long flags;
1227 int rc = 0;
1229 QETH_CARD_TEXT(card, 5, "osndctrd");
1231 wait_event(card->wait_q,
1232 atomic_cmpxchg(&card->write.irq_pending, 0, 1) == 0);
1233 qeth_prepare_control_data(card, len, iob);
1234 QETH_CARD_TEXT(card, 6, "osnoirqp");
1235 spin_lock_irqsave(get_ccwdev_lock(card->write.ccwdev), flags);
1236 rc = ccw_device_start(card->write.ccwdev, &card->write.ccw,
1237 (addr_t) iob, 0, 0);
1238 spin_unlock_irqrestore(get_ccwdev_lock(card->write.ccwdev), flags);
1239 if (rc) {
1240 QETH_DBF_MESSAGE(2, "qeth_osn_send_control_data: "
1241 "ccw_device_start rc = %i\n", rc);
1242 QETH_CARD_TEXT_(card, 2, " err%d", rc);
1243 qeth_release_buffer(iob->channel, iob);
1244 atomic_set(&card->write.irq_pending, 0);
1245 wake_up(&card->wait_q);
1247 return rc;
1250 static int qeth_osn_send_ipa_cmd(struct qeth_card *card,
1251 struct qeth_cmd_buffer *iob, int data_len)
1253 u16 s1, s2;
1255 QETH_CARD_TEXT(card, 4, "osndipa");
1257 qeth_prepare_ipa_cmd(card, iob, QETH_PROT_OSN2);
1258 s1 = (u16)(IPA_PDU_HEADER_SIZE + data_len);
1259 s2 = (u16)data_len;
1260 memcpy(QETH_IPA_PDU_LEN_TOTAL(iob->data), &s1, 2);
1261 memcpy(QETH_IPA_PDU_LEN_PDU1(iob->data), &s2, 2);
1262 memcpy(QETH_IPA_PDU_LEN_PDU2(iob->data), &s2, 2);
1263 memcpy(QETH_IPA_PDU_LEN_PDU3(iob->data), &s2, 2);
1264 return qeth_osn_send_control_data(card, s1, iob);
1267 int qeth_osn_assist(struct net_device *dev, void *data, int data_len)
1269 struct qeth_cmd_buffer *iob;
1270 struct qeth_card *card;
1271 int rc;
1273 if (!dev)
1274 return -ENODEV;
1275 card = dev->ml_priv;
1276 if (!card)
1277 return -ENODEV;
1278 QETH_CARD_TEXT(card, 2, "osnsdmc");
1279 if ((card->state != CARD_STATE_UP) &&
1280 (card->state != CARD_STATE_SOFTSETUP))
1281 return -ENODEV;
1282 iob = qeth_wait_for_buffer(&card->write);
1283 memcpy(iob->data+IPA_PDU_HEADER_SIZE, data, data_len);
1284 rc = qeth_osn_send_ipa_cmd(card, iob, data_len);
1285 return rc;
1287 EXPORT_SYMBOL(qeth_osn_assist);
1289 int qeth_osn_register(unsigned char *read_dev_no, struct net_device **dev,
1290 int (*assist_cb)(struct net_device *, void *),
1291 int (*data_cb)(struct sk_buff *))
1293 struct qeth_card *card;
1295 *dev = qeth_l2_netdev_by_devno(read_dev_no);
1296 if (*dev == NULL)
1297 return -ENODEV;
1298 card = (*dev)->ml_priv;
1299 if (!card)
1300 return -ENODEV;
1301 QETH_CARD_TEXT(card, 2, "osnreg");
1302 if ((assist_cb == NULL) || (data_cb == NULL))
1303 return -EINVAL;
1304 card->osn_info.assist_cb = assist_cb;
1305 card->osn_info.data_cb = data_cb;
1306 return 0;
1308 EXPORT_SYMBOL(qeth_osn_register);
1310 void qeth_osn_deregister(struct net_device *dev)
1312 struct qeth_card *card;
1314 if (!dev)
1315 return;
1316 card = dev->ml_priv;
1317 if (!card)
1318 return;
1319 QETH_CARD_TEXT(card, 2, "osndereg");
1320 card->osn_info.assist_cb = NULL;
1321 card->osn_info.data_cb = NULL;
1322 return;
1324 EXPORT_SYMBOL(qeth_osn_deregister);
1326 module_init(qeth_l2_init);
1327 module_exit(qeth_l2_exit);
1328 MODULE_AUTHOR("Frank Blaschka <frank.blaschka@de.ibm.com>");
1329 MODULE_DESCRIPTION("qeth layer 2 discipline");
1330 MODULE_LICENSE("GPL");