Merge branch 'for-2.6.30' into for-2.6.31
[linux-2.6] / drivers / s390 / net / qeth_l2_main.c
1 /*
2  *  drivers/s390/net/qeth_l2_main.c
3  *
4  *    Copyright IBM Corp. 2007
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  */
10
11 #define KMSG_COMPONENT "qeth"
12 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
13
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
23 #include "qeth_core.h"
24
25 static int qeth_l2_set_offline(struct ccwgroup_device *);
26 static int qeth_l2_stop(struct net_device *);
27 static int qeth_l2_send_delmac(struct qeth_card *, __u8 *);
28 static int qeth_l2_send_setdelmac(struct qeth_card *, __u8 *,
29                            enum qeth_ipa_cmds,
30                            int (*reply_cb) (struct qeth_card *,
31                                             struct qeth_reply*,
32                                             unsigned long));
33 static void qeth_l2_set_multicast_list(struct net_device *);
34 static int qeth_l2_recover(void *);
35
36 static int qeth_l2_do_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
37 {
38         struct qeth_card *card = dev->ml_priv;
39         struct mii_ioctl_data *mii_data;
40         int rc = 0;
41
42         if (!card)
43                 return -ENODEV;
44
45         if ((card->state != CARD_STATE_UP) &&
46                 (card->state != CARD_STATE_SOFTSETUP))
47                 return -ENODEV;
48
49         if (card->info.type == QETH_CARD_TYPE_OSN)
50                 return -EPERM;
51
52         switch (cmd) {
53         case SIOC_QETH_ADP_SET_SNMP_CONTROL:
54                 rc = qeth_snmp_command(card, rq->ifr_ifru.ifru_data);
55                 break;
56         case SIOC_QETH_GET_CARD_TYPE:
57                 if ((card->info.type == QETH_CARD_TYPE_OSAE) &&
58                     !card->info.guestlan)
59                         return 1;
60                 return 0;
61                 break;
62         case SIOCGMIIPHY:
63                 mii_data = if_mii(rq);
64                 mii_data->phy_id = 0;
65                 break;
66         case SIOCGMIIREG:
67                 mii_data = if_mii(rq);
68                 if (mii_data->phy_id != 0)
69                         rc = -EINVAL;
70                 else
71                         mii_data->val_out = qeth_mdio_read(dev,
72                                 mii_data->phy_id, mii_data->reg_num);
73                 break;
74         default:
75                 rc = -EOPNOTSUPP;
76         }
77         if (rc)
78                 QETH_DBF_TEXT_(TRACE, 2, "ioce%d", rc);
79         return rc;
80 }
81
82 static int qeth_l2_verify_dev(struct net_device *dev)
83 {
84         struct qeth_card *card;
85         unsigned long flags;
86         int rc = 0;
87
88         read_lock_irqsave(&qeth_core_card_list.rwlock, flags);
89         list_for_each_entry(card, &qeth_core_card_list.list, list) {
90                 if (card->dev == dev) {
91                         rc = QETH_REAL_CARD;
92                         break;
93                 }
94         }
95         read_unlock_irqrestore(&qeth_core_card_list.rwlock, flags);
96
97         return rc;
98 }
99
100 static struct net_device *qeth_l2_netdev_by_devno(unsigned char *read_dev_no)
101 {
102         struct qeth_card *card;
103         struct net_device *ndev;
104         __u16 temp_dev_no;
105         unsigned long flags;
106         struct ccw_dev_id read_devid;
107
108         ndev = NULL;
109         memcpy(&temp_dev_no, read_dev_no, 2);
110         read_lock_irqsave(&qeth_core_card_list.rwlock, flags);
111         list_for_each_entry(card, &qeth_core_card_list.list, list) {
112                 ccw_device_get_id(CARD_RDEV(card), &read_devid);
113                 if (read_devid.devno == temp_dev_no) {
114                         ndev = card->dev;
115                         break;
116                 }
117         }
118         read_unlock_irqrestore(&qeth_core_card_list.rwlock, flags);
119         return ndev;
120 }
121
122 static int qeth_l2_send_setgroupmac_cb(struct qeth_card *card,
123                                 struct qeth_reply *reply,
124                                 unsigned long data)
125 {
126         struct qeth_ipa_cmd *cmd;
127         __u8 *mac;
128
129         QETH_DBF_TEXT(TRACE, 2, "L2Sgmacb");
130         cmd = (struct qeth_ipa_cmd *) data;
131         mac = &cmd->data.setdelmac.mac[0];
132         /* MAC already registered, needed in couple/uncouple case */
133         if (cmd->hdr.return_code == 0x2005) {
134                 QETH_DBF_MESSAGE(2, "Group MAC %pM already existing on %s \n",
135                           mac, QETH_CARD_IFNAME(card));
136                 cmd->hdr.return_code = 0;
137         }
138         if (cmd->hdr.return_code)
139                 QETH_DBF_MESSAGE(2, "Could not set group MAC %pM on %s: %x\n",
140                           mac, QETH_CARD_IFNAME(card), cmd->hdr.return_code);
141         return 0;
142 }
143
144 static int qeth_l2_send_setgroupmac(struct qeth_card *card, __u8 *mac)
145 {
146         QETH_DBF_TEXT(TRACE, 2, "L2Sgmac");
147         return qeth_l2_send_setdelmac(card, mac, IPA_CMD_SETGMAC,
148                                           qeth_l2_send_setgroupmac_cb);
149 }
150
151 static int qeth_l2_send_delgroupmac_cb(struct qeth_card *card,
152                                 struct qeth_reply *reply,
153                                 unsigned long data)
154 {
155         struct qeth_ipa_cmd *cmd;
156         __u8 *mac;
157
158         QETH_DBF_TEXT(TRACE, 2, "L2Dgmacb");
159         cmd = (struct qeth_ipa_cmd *) data;
160         mac = &cmd->data.setdelmac.mac[0];
161         if (cmd->hdr.return_code)
162                 QETH_DBF_MESSAGE(2, "Could not delete group MAC %pM on %s: %x\n",
163                           mac, QETH_CARD_IFNAME(card), cmd->hdr.return_code);
164         return 0;
165 }
166
167 static int qeth_l2_send_delgroupmac(struct qeth_card *card, __u8 *mac)
168 {
169         QETH_DBF_TEXT(TRACE, 2, "L2Dgmac");
170         return qeth_l2_send_setdelmac(card, mac, IPA_CMD_DELGMAC,
171                                           qeth_l2_send_delgroupmac_cb);
172 }
173
174 static void qeth_l2_add_mc(struct qeth_card *card, __u8 *mac, int vmac)
175 {
176         struct qeth_mc_mac *mc;
177         int rc;
178
179         mc = kmalloc(sizeof(struct qeth_mc_mac), GFP_ATOMIC);
180
181         if (!mc)
182                 return;
183
184         memcpy(mc->mc_addr, mac, OSA_ADDR_LEN);
185         mc->mc_addrlen = OSA_ADDR_LEN;
186         mc->is_vmac = vmac;
187
188         if (vmac) {
189                 rc = qeth_l2_send_setdelmac(card, mac, IPA_CMD_SETVMAC,
190                                         NULL);
191         } else {
192                 rc = qeth_l2_send_setgroupmac(card, mac);
193         }
194
195         if (!rc)
196                 list_add_tail(&mc->list, &card->mc_list);
197         else
198                 kfree(mc);
199 }
200
201 static void qeth_l2_del_all_mc(struct qeth_card *card)
202 {
203         struct qeth_mc_mac *mc, *tmp;
204
205         spin_lock_bh(&card->mclock);
206         list_for_each_entry_safe(mc, tmp, &card->mc_list, list) {
207                 if (mc->is_vmac)
208                         qeth_l2_send_setdelmac(card, mc->mc_addr,
209                                         IPA_CMD_DELVMAC, NULL);
210                 else
211                         qeth_l2_send_delgroupmac(card, mc->mc_addr);
212                 list_del(&mc->list);
213                 kfree(mc);
214         }
215         spin_unlock_bh(&card->mclock);
216 }
217
218 static void qeth_l2_get_packet_type(struct qeth_card *card,
219                         struct qeth_hdr *hdr, struct sk_buff *skb)
220 {
221         __u16 hdr_mac;
222
223         if (!memcmp(skb->data + QETH_HEADER_SIZE,
224                     skb->dev->broadcast, 6)) {
225                 /* broadcast? */
226                 hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_BROADCAST;
227                 return;
228         }
229         hdr_mac = *((__u16 *)skb->data);
230         /* tr multicast? */
231         switch (card->info.link_type) {
232         case QETH_LINK_TYPE_HSTR:
233         case QETH_LINK_TYPE_LANE_TR:
234                 if ((hdr_mac == QETH_TR_MAC_NC) ||
235                     (hdr_mac == QETH_TR_MAC_C))
236                         hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_MULTICAST;
237                 else
238                         hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_UNICAST;
239                 break;
240                 /* eth or so multicast? */
241         default:
242                 if ((hdr_mac == QETH_ETH_MAC_V4) ||
243                      (hdr_mac == QETH_ETH_MAC_V6))
244                         hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_MULTICAST;
245                 else
246                         hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_UNICAST;
247         }
248 }
249
250 static void qeth_l2_fill_header(struct qeth_card *card, struct qeth_hdr *hdr,
251                         struct sk_buff *skb, int ipv, int cast_type)
252 {
253         struct vlan_ethhdr *veth = (struct vlan_ethhdr *)skb_mac_header(skb);
254
255         memset(hdr, 0, sizeof(struct qeth_hdr));
256         hdr->hdr.l2.id = QETH_HEADER_TYPE_LAYER2;
257
258         /* set byte byte 3 to casting flags */
259         if (cast_type == RTN_MULTICAST)
260                 hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_MULTICAST;
261         else if (cast_type == RTN_BROADCAST)
262                 hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_BROADCAST;
263         else
264                 qeth_l2_get_packet_type(card, hdr, skb);
265
266         hdr->hdr.l2.pkt_length = skb->len-QETH_HEADER_SIZE;
267         /* VSWITCH relies on the VLAN
268          * information to be present in
269          * the QDIO header */
270         if (veth->h_vlan_proto == __constant_htons(ETH_P_8021Q)) {
271                 hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_VLAN;
272                 hdr->hdr.l2.vlan_id = ntohs(veth->h_vlan_TCI);
273         }
274 }
275
276 static int qeth_l2_send_setdelvlan_cb(struct qeth_card *card,
277                         struct qeth_reply *reply, unsigned long data)
278 {
279         struct qeth_ipa_cmd *cmd;
280
281         QETH_DBF_TEXT(TRACE, 2, "L2sdvcb");
282         cmd = (struct qeth_ipa_cmd *) data;
283         if (cmd->hdr.return_code) {
284                 QETH_DBF_MESSAGE(2, "Error in processing VLAN %i on %s: 0x%x. "
285                           "Continuing\n", cmd->data.setdelvlan.vlan_id,
286                           QETH_CARD_IFNAME(card), cmd->hdr.return_code);
287                 QETH_DBF_TEXT_(TRACE, 2, "L2VL%4x", cmd->hdr.command);
288                 QETH_DBF_TEXT_(TRACE, 2, "L2%s", CARD_BUS_ID(card));
289                 QETH_DBF_TEXT_(TRACE, 2, "err%d", cmd->hdr.return_code);
290         }
291         return 0;
292 }
293
294 static int qeth_l2_send_setdelvlan(struct qeth_card *card, __u16 i,
295                                 enum qeth_ipa_cmds ipacmd)
296 {
297         struct qeth_ipa_cmd *cmd;
298         struct qeth_cmd_buffer *iob;
299
300         QETH_DBF_TEXT_(TRACE, 4, "L2sdv%x", ipacmd);
301         iob = qeth_get_ipacmd_buffer(card, ipacmd, QETH_PROT_IPV4);
302         cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
303         cmd->data.setdelvlan.vlan_id = i;
304         return qeth_send_ipa_cmd(card, iob,
305                                  qeth_l2_send_setdelvlan_cb, NULL);
306 }
307
308 static void qeth_l2_process_vlans(struct qeth_card *card, int clear)
309 {
310         struct qeth_vlan_vid *id;
311         QETH_DBF_TEXT(TRACE, 3, "L2prcvln");
312         spin_lock_bh(&card->vlanlock);
313         list_for_each_entry(id, &card->vid_list, list) {
314                 if (clear)
315                         qeth_l2_send_setdelvlan(card, id->vid,
316                                 IPA_CMD_DELVLAN);
317                 else
318                         qeth_l2_send_setdelvlan(card, id->vid,
319                                 IPA_CMD_SETVLAN);
320         }
321         spin_unlock_bh(&card->vlanlock);
322 }
323
324 static void qeth_l2_vlan_rx_add_vid(struct net_device *dev, unsigned short vid)
325 {
326         struct qeth_card *card = dev->ml_priv;
327         struct qeth_vlan_vid *id;
328
329         QETH_DBF_TEXT_(TRACE, 4, "aid:%d", vid);
330         if (qeth_wait_for_threads(card, QETH_RECOVER_THREAD)) {
331                 QETH_DBF_TEXT(TRACE, 3, "aidREC");
332                 return;
333         }
334         id = kmalloc(sizeof(struct qeth_vlan_vid), GFP_ATOMIC);
335         if (id) {
336                 id->vid = vid;
337                 qeth_l2_send_setdelvlan(card, vid, IPA_CMD_SETVLAN);
338                 spin_lock_bh(&card->vlanlock);
339                 list_add_tail(&id->list, &card->vid_list);
340                 spin_unlock_bh(&card->vlanlock);
341         }
342 }
343
344 static void qeth_l2_vlan_rx_kill_vid(struct net_device *dev, unsigned short vid)
345 {
346         struct qeth_vlan_vid *id, *tmpid = NULL;
347         struct qeth_card *card = dev->ml_priv;
348
349         QETH_DBF_TEXT_(TRACE, 4, "kid:%d", vid);
350         if (qeth_wait_for_threads(card, QETH_RECOVER_THREAD)) {
351                 QETH_DBF_TEXT(TRACE, 3, "kidREC");
352                 return;
353         }
354         spin_lock_bh(&card->vlanlock);
355         list_for_each_entry(id, &card->vid_list, list) {
356                 if (id->vid == vid) {
357                         list_del(&id->list);
358                         tmpid = id;
359                         break;
360                 }
361         }
362         spin_unlock_bh(&card->vlanlock);
363         if (tmpid) {
364                 qeth_l2_send_setdelvlan(card, vid, IPA_CMD_DELVLAN);
365                 kfree(tmpid);
366         }
367         qeth_l2_set_multicast_list(card->dev);
368 }
369
370 static int qeth_l2_stop_card(struct qeth_card *card, int recovery_mode)
371 {
372         int rc = 0;
373
374         QETH_DBF_TEXT(SETUP , 2, "stopcard");
375         QETH_DBF_HEX(SETUP, 2, &card, sizeof(void *));
376
377         qeth_set_allowed_threads(card, 0, 1);
378         if (card->read.state == CH_STATE_UP &&
379             card->write.state == CH_STATE_UP &&
380             (card->state == CARD_STATE_UP)) {
381                 if (recovery_mode &&
382                     card->info.type != QETH_CARD_TYPE_OSN) {
383                         qeth_l2_stop(card->dev);
384                 } else {
385                         rtnl_lock();
386                         dev_close(card->dev);
387                         rtnl_unlock();
388                 }
389                 if (!card->use_hard_stop ||
390                         recovery_mode) {
391                         __u8 *mac = &card->dev->dev_addr[0];
392                         rc = qeth_l2_send_delmac(card, mac);
393                         QETH_DBF_TEXT_(SETUP, 2, "Lerr%d", rc);
394                 }
395                 card->state = CARD_STATE_SOFTSETUP;
396         }
397         if (card->state == CARD_STATE_SOFTSETUP) {
398                 qeth_l2_process_vlans(card, 1);
399                 if (!card->use_hard_stop ||
400                         recovery_mode)
401                         qeth_l2_del_all_mc(card);
402                 qeth_clear_ipacmd_list(card);
403                 card->state = CARD_STATE_HARDSETUP;
404         }
405         if (card->state == CARD_STATE_HARDSETUP) {
406                 qeth_qdio_clear_card(card, 0);
407                 qeth_clear_qdio_buffers(card);
408                 qeth_clear_working_pool_list(card);
409                 card->state = CARD_STATE_DOWN;
410         }
411         if (card->state == CARD_STATE_DOWN) {
412                 qeth_clear_cmd_buffers(&card->read);
413                 qeth_clear_cmd_buffers(&card->write);
414         }
415         card->use_hard_stop = 0;
416         return rc;
417 }
418
419 static void qeth_l2_process_inbound_buffer(struct qeth_card *card,
420                             struct qeth_qdio_buffer *buf, int index)
421 {
422         struct qdio_buffer_element *element;
423         struct sk_buff *skb;
424         struct qeth_hdr *hdr;
425         int offset;
426         unsigned int len;
427
428         /* get first element of current buffer */
429         element = (struct qdio_buffer_element *)&buf->buffer->element[0];
430         offset = 0;
431         if (card->options.performance_stats)
432                 card->perf_stats.bufs_rec++;
433         while ((skb = qeth_core_get_next_skb(card, buf->buffer, &element,
434                                        &offset, &hdr))) {
435                 skb->dev = card->dev;
436                 /* is device UP ? */
437                 if (!(card->dev->flags & IFF_UP)) {
438                         dev_kfree_skb_any(skb);
439                         continue;
440                 }
441
442                 switch (hdr->hdr.l2.id) {
443                 case QETH_HEADER_TYPE_LAYER2:
444                         skb->pkt_type = PACKET_HOST;
445                         skb->protocol = eth_type_trans(skb, skb->dev);
446                         if (card->options.checksum_type == NO_CHECKSUMMING)
447                                 skb->ip_summed = CHECKSUM_UNNECESSARY;
448                         else
449                                 skb->ip_summed = CHECKSUM_NONE;
450                         if (skb->protocol == htons(ETH_P_802_2))
451                                 *((__u32 *)skb->cb) = ++card->seqno.pkt_seqno;
452                         len = skb->len;
453                         netif_rx(skb);
454                         break;
455                 case QETH_HEADER_TYPE_OSN:
456                         if (card->info.type == QETH_CARD_TYPE_OSN) {
457                                 skb_push(skb, sizeof(struct qeth_hdr));
458                                 skb_copy_to_linear_data(skb, hdr,
459                                                 sizeof(struct qeth_hdr));
460                                 len = skb->len;
461                                 card->osn_info.data_cb(skb);
462                                 break;
463                         }
464                         /* else unknown */
465                 default:
466                         dev_kfree_skb_any(skb);
467                         QETH_DBF_TEXT(TRACE, 3, "inbunkno");
468                         QETH_DBF_HEX(CTRL, 3, hdr, QETH_DBF_CTRL_LEN);
469                         continue;
470                 }
471                 card->dev->last_rx = jiffies;
472                 card->stats.rx_packets++;
473                 card->stats.rx_bytes += len;
474         }
475 }
476
477 static int qeth_l2_send_setdelmac(struct qeth_card *card, __u8 *mac,
478                            enum qeth_ipa_cmds ipacmd,
479                            int (*reply_cb) (struct qeth_card *,
480                                             struct qeth_reply*,
481                                             unsigned long))
482 {
483         struct qeth_ipa_cmd *cmd;
484         struct qeth_cmd_buffer *iob;
485
486         QETH_DBF_TEXT(TRACE, 2, "L2sdmac");
487         iob = qeth_get_ipacmd_buffer(card, ipacmd, QETH_PROT_IPV4);
488         cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
489         cmd->data.setdelmac.mac_length = OSA_ADDR_LEN;
490         memcpy(&cmd->data.setdelmac.mac, mac, OSA_ADDR_LEN);
491         return qeth_send_ipa_cmd(card, iob, reply_cb, NULL);
492 }
493
494 static int qeth_l2_send_setmac_cb(struct qeth_card *card,
495                            struct qeth_reply *reply,
496                            unsigned long data)
497 {
498         struct qeth_ipa_cmd *cmd;
499
500         QETH_DBF_TEXT(TRACE, 2, "L2Smaccb");
501         cmd = (struct qeth_ipa_cmd *) data;
502         if (cmd->hdr.return_code) {
503                 QETH_DBF_TEXT_(TRACE, 2, "L2er%x", cmd->hdr.return_code);
504                 card->info.mac_bits &= ~QETH_LAYER2_MAC_REGISTERED;
505                 cmd->hdr.return_code = -EIO;
506         } else {
507                 card->info.mac_bits |= QETH_LAYER2_MAC_REGISTERED;
508                 memcpy(card->dev->dev_addr, cmd->data.setdelmac.mac,
509                        OSA_ADDR_LEN);
510                 dev_info(&card->gdev->dev,
511                         "MAC address %2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x "
512                         "successfully registered on device %s\n",
513                         card->dev->dev_addr[0], card->dev->dev_addr[1],
514                         card->dev->dev_addr[2], card->dev->dev_addr[3],
515                         card->dev->dev_addr[4], card->dev->dev_addr[5],
516                         card->dev->name);
517         }
518         return 0;
519 }
520
521 static int qeth_l2_send_setmac(struct qeth_card *card, __u8 *mac)
522 {
523         QETH_DBF_TEXT(TRACE, 2, "L2Setmac");
524         return qeth_l2_send_setdelmac(card, mac, IPA_CMD_SETVMAC,
525                                           qeth_l2_send_setmac_cb);
526 }
527
528 static int qeth_l2_send_delmac_cb(struct qeth_card *card,
529                            struct qeth_reply *reply,
530                            unsigned long data)
531 {
532         struct qeth_ipa_cmd *cmd;
533
534         QETH_DBF_TEXT(TRACE, 2, "L2Dmaccb");
535         cmd = (struct qeth_ipa_cmd *) data;
536         if (cmd->hdr.return_code) {
537                 QETH_DBF_TEXT_(TRACE, 2, "err%d", cmd->hdr.return_code);
538                 cmd->hdr.return_code = -EIO;
539                 return 0;
540         }
541         card->info.mac_bits &= ~QETH_LAYER2_MAC_REGISTERED;
542
543         return 0;
544 }
545
546 static int qeth_l2_send_delmac(struct qeth_card *card, __u8 *mac)
547 {
548         QETH_DBF_TEXT(TRACE, 2, "L2Delmac");
549         if (!(card->info.mac_bits & QETH_LAYER2_MAC_REGISTERED))
550                 return 0;
551         return qeth_l2_send_setdelmac(card, mac, IPA_CMD_DELVMAC,
552                                           qeth_l2_send_delmac_cb);
553 }
554
555 static int qeth_l2_request_initial_mac(struct qeth_card *card)
556 {
557         int rc = 0;
558         char vendor_pre[] = {0x02, 0x00, 0x00};
559
560         QETH_DBF_TEXT(SETUP, 2, "doL2init");
561         QETH_DBF_TEXT_(SETUP, 2, "doL2%s", CARD_BUS_ID(card));
562
563         rc = qeth_query_setadapterparms(card);
564         if (rc) {
565                 QETH_DBF_MESSAGE(2, "could not query adapter parameters on "
566                         "device %s: x%x\n", CARD_BUS_ID(card), rc);
567         }
568
569         if ((card->info.type == QETH_CARD_TYPE_IQD) || 
570             (card->info.guestlan)) {
571                 rc = qeth_setadpparms_change_macaddr(card);
572                 if (rc) {
573                         QETH_DBF_MESSAGE(2, "couldn't get MAC address on "
574                                 "device %s: x%x\n", CARD_BUS_ID(card), rc);
575                         QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
576                         return rc;
577                 }
578                 QETH_DBF_HEX(SETUP, 2, card->dev->dev_addr, OSA_ADDR_LEN);
579         } else {
580                 random_ether_addr(card->dev->dev_addr);
581                 memcpy(card->dev->dev_addr, vendor_pre, 3);
582         }
583         return 0;
584 }
585
586 static int qeth_l2_set_mac_address(struct net_device *dev, void *p)
587 {
588         struct sockaddr *addr = p;
589         struct qeth_card *card = dev->ml_priv;
590         int rc = 0;
591
592         QETH_DBF_TEXT(TRACE, 3, "setmac");
593
594         if (qeth_l2_verify_dev(dev) != QETH_REAL_CARD) {
595                 QETH_DBF_TEXT(TRACE, 3, "setmcINV");
596                 return -EOPNOTSUPP;
597         }
598
599         if (card->info.type == QETH_CARD_TYPE_OSN) {
600                 QETH_DBF_TEXT(TRACE, 3, "setmcOSN");
601                 return -EOPNOTSUPP;
602         }
603         QETH_DBF_TEXT_(TRACE, 3, "%s", CARD_BUS_ID(card));
604         QETH_DBF_HEX(TRACE, 3, addr->sa_data, OSA_ADDR_LEN);
605         if (qeth_wait_for_threads(card, QETH_RECOVER_THREAD)) {
606                 QETH_DBF_TEXT(TRACE, 3, "setmcREC");
607                 return -ERESTARTSYS;
608         }
609         rc = qeth_l2_send_delmac(card, &card->dev->dev_addr[0]);
610         if (!rc)
611                 rc = qeth_l2_send_setmac(card, addr->sa_data);
612         return rc;
613 }
614
615 static void qeth_l2_set_multicast_list(struct net_device *dev)
616 {
617         struct qeth_card *card = dev->ml_priv;
618         struct dev_addr_list *dm;
619
620         if (card->info.type == QETH_CARD_TYPE_OSN)
621                 return ;
622
623         QETH_DBF_TEXT(TRACE, 3, "setmulti");
624         if (qeth_threads_running(card, QETH_RECOVER_THREAD) &&
625             (card->state != CARD_STATE_UP))
626                 return;
627         qeth_l2_del_all_mc(card);
628         spin_lock_bh(&card->mclock);
629         for (dm = dev->mc_list; dm; dm = dm->next)
630                 qeth_l2_add_mc(card, dm->da_addr, 0);
631
632         for (dm = dev->uc_list; dm; dm = dm->next)
633                 qeth_l2_add_mc(card, dm->da_addr, 1);
634
635         spin_unlock_bh(&card->mclock);
636         if (!qeth_adp_supported(card, IPA_SETADP_SET_PROMISC_MODE))
637                 return;
638         qeth_setadp_promisc_mode(card);
639 }
640
641 static int qeth_l2_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
642 {
643         int rc;
644         struct qeth_hdr *hdr = NULL;
645         int elements = 0;
646         struct qeth_card *card = dev->ml_priv;
647         struct sk_buff *new_skb = skb;
648         int ipv = qeth_get_ip_version(skb);
649         int cast_type = qeth_get_cast_type(card, skb);
650         struct qeth_qdio_out_q *queue = card->qdio.out_qs
651                 [qeth_get_priority_queue(card, skb, ipv, cast_type)];
652         int tx_bytes = skb->len;
653         int data_offset = -1;
654         int elements_needed = 0;
655         int hd_len = 0;
656
657         if ((card->state != CARD_STATE_UP) || !card->lan_online) {
658                 card->stats.tx_carrier_errors++;
659                 goto tx_drop;
660         }
661
662         if ((card->info.type == QETH_CARD_TYPE_OSN) &&
663             (skb->protocol == htons(ETH_P_IPV6)))
664                 goto tx_drop;
665
666         if (card->options.performance_stats) {
667                 card->perf_stats.outbound_cnt++;
668                 card->perf_stats.outbound_start_time = qeth_get_micros();
669         }
670         netif_stop_queue(dev);
671
672         if (card->info.type == QETH_CARD_TYPE_OSN)
673                 hdr = (struct qeth_hdr *)skb->data;
674         else {
675                 if (card->info.type == QETH_CARD_TYPE_IQD) {
676                         new_skb = skb;
677                         data_offset = ETH_HLEN;
678                         hd_len = ETH_HLEN;
679                         hdr = kmem_cache_alloc(qeth_core_header_cache,
680                                                 GFP_ATOMIC);
681                         if (!hdr)
682                                 goto tx_drop;
683                         elements_needed++;
684                         skb_reset_mac_header(new_skb);
685                         qeth_l2_fill_header(card, hdr, new_skb, ipv, cast_type);
686                         hdr->hdr.l2.pkt_length = new_skb->len;
687                         memcpy(((char *)hdr) + sizeof(struct qeth_hdr),
688                                 skb_mac_header(new_skb), ETH_HLEN);
689                 } else {
690                         /* create a clone with writeable headroom */
691                         new_skb = skb_realloc_headroom(skb,
692                                                 sizeof(struct qeth_hdr));
693                         if (!new_skb)
694                                 goto tx_drop;
695                         hdr = (struct qeth_hdr *)skb_push(new_skb,
696                                                 sizeof(struct qeth_hdr));
697                         skb_set_mac_header(new_skb, sizeof(struct qeth_hdr));
698                         qeth_l2_fill_header(card, hdr, new_skb, ipv, cast_type);
699                 }
700         }
701
702         elements = qeth_get_elements_no(card, (void *)hdr, new_skb,
703                                                 elements_needed);
704         if (!elements) {
705                 if (data_offset >= 0)
706                         kmem_cache_free(qeth_core_header_cache, hdr);
707                 goto tx_drop;
708         }
709
710         if (card->info.type != QETH_CARD_TYPE_IQD)
711                 rc = qeth_do_send_packet(card, queue, new_skb, hdr,
712                                          elements);
713         else
714                 rc = qeth_do_send_packet_fast(card, queue, new_skb, hdr,
715                                         elements, data_offset, hd_len);
716         if (!rc) {
717                 card->stats.tx_packets++;
718                 card->stats.tx_bytes += tx_bytes;
719                 if (new_skb != skb)
720                         dev_kfree_skb_any(skb);
721         } else {
722                 if (data_offset >= 0)
723                         kmem_cache_free(qeth_core_header_cache, hdr);
724
725                 if (rc == -EBUSY) {
726                         if (new_skb != skb)
727                                 dev_kfree_skb_any(new_skb);
728                         return NETDEV_TX_BUSY;
729                 } else
730                         goto tx_drop;
731         }
732
733         netif_wake_queue(dev);
734         if (card->options.performance_stats)
735                 card->perf_stats.outbound_time += qeth_get_micros() -
736                         card->perf_stats.outbound_start_time;
737         return rc;
738
739 tx_drop:
740         card->stats.tx_dropped++;
741         card->stats.tx_errors++;
742         if ((new_skb != skb) && new_skb)
743                 dev_kfree_skb_any(new_skb);
744         dev_kfree_skb_any(skb);
745         netif_wake_queue(dev);
746         return NETDEV_TX_OK;
747 }
748
749 static void qeth_l2_qdio_input_handler(struct ccw_device *ccwdev,
750                         unsigned int qdio_err, unsigned int queue,
751                         int first_element, int count, unsigned long card_ptr)
752 {
753         struct net_device *net_dev;
754         struct qeth_card *card;
755         struct qeth_qdio_buffer *buffer;
756         int index;
757         int i;
758
759         card = (struct qeth_card *) card_ptr;
760         net_dev = card->dev;
761         if (card->options.performance_stats) {
762                 card->perf_stats.inbound_cnt++;
763                 card->perf_stats.inbound_start_time = qeth_get_micros();
764         }
765         if (qdio_err & QDIO_ERROR_ACTIVATE_CHECK_CONDITION) {
766                 QETH_DBF_TEXT(TRACE, 1, "qdinchk");
767                 QETH_DBF_TEXT_(TRACE, 1, "%s", CARD_BUS_ID(card));
768                 QETH_DBF_TEXT_(TRACE, 1, "%04X%04X", first_element,
769                                 count);
770                 QETH_DBF_TEXT_(TRACE, 1, "%04X", queue);
771                 qeth_schedule_recovery(card);
772                 return;
773         }
774         for (i = first_element; i < (first_element + count); ++i) {
775                 index = i % QDIO_MAX_BUFFERS_PER_Q;
776                 buffer = &card->qdio.in_q->bufs[index];
777                 if (!(qdio_err &&
778                       qeth_check_qdio_errors(buffer->buffer, qdio_err, "qinerr")))
779                         qeth_l2_process_inbound_buffer(card, buffer, index);
780                 /* clear buffer and give back to hardware */
781                 qeth_put_buffer_pool_entry(card, buffer->pool_entry);
782                 qeth_queue_input_buffer(card, index);
783         }
784         if (card->options.performance_stats)
785                 card->perf_stats.inbound_time += qeth_get_micros() -
786                         card->perf_stats.inbound_start_time;
787 }
788
789 static int qeth_l2_open(struct net_device *dev)
790 {
791         struct qeth_card *card = dev->ml_priv;
792
793         QETH_DBF_TEXT(TRACE, 4, "qethopen");
794         if (card->state != CARD_STATE_SOFTSETUP)
795                 return -ENODEV;
796
797         if ((card->info.type != QETH_CARD_TYPE_OSN) &&
798              (!(card->info.mac_bits & QETH_LAYER2_MAC_REGISTERED))) {
799                 QETH_DBF_TEXT(TRACE, 4, "nomacadr");
800                 return -EPERM;
801         }
802         card->data.state = CH_STATE_UP;
803         card->state = CARD_STATE_UP;
804         netif_start_queue(dev);
805
806         if (!card->lan_online && netif_carrier_ok(dev))
807                 netif_carrier_off(dev);
808         return 0;
809 }
810
811
812 static int qeth_l2_stop(struct net_device *dev)
813 {
814         struct qeth_card *card = dev->ml_priv;
815
816         QETH_DBF_TEXT(TRACE, 4, "qethstop");
817         netif_tx_disable(dev);
818         if (card->state == CARD_STATE_UP)
819                 card->state = CARD_STATE_SOFTSETUP;
820         return 0;
821 }
822
823 static int qeth_l2_probe_device(struct ccwgroup_device *gdev)
824 {
825         struct qeth_card *card = dev_get_drvdata(&gdev->dev);
826
827         INIT_LIST_HEAD(&card->vid_list);
828         INIT_LIST_HEAD(&card->mc_list);
829         card->options.layer2 = 1;
830         card->discipline.input_handler = (qdio_handler_t *)
831                 qeth_l2_qdio_input_handler;
832         card->discipline.output_handler = (qdio_handler_t *)
833                 qeth_qdio_output_handler;
834         card->discipline.recover = qeth_l2_recover;
835         return 0;
836 }
837
838 static void qeth_l2_remove_device(struct ccwgroup_device *cgdev)
839 {
840         struct qeth_card *card = dev_get_drvdata(&cgdev->dev);
841
842         wait_event(card->wait_q, qeth_threads_running(card, 0xffffffff) == 0);
843
844         if (cgdev->state == CCWGROUP_ONLINE) {
845                 card->use_hard_stop = 1;
846                 qeth_l2_set_offline(cgdev);
847         }
848
849         if (card->dev) {
850                 unregister_netdev(card->dev);
851                 card->dev = NULL;
852         }
853
854         qeth_l2_del_all_mc(card);
855         return;
856 }
857
858 static struct ethtool_ops qeth_l2_ethtool_ops = {
859         .get_link = ethtool_op_get_link,
860         .get_strings = qeth_core_get_strings,
861         .get_ethtool_stats = qeth_core_get_ethtool_stats,
862         .get_stats_count = qeth_core_get_stats_count,
863         .get_drvinfo = qeth_core_get_drvinfo,
864         .get_settings = qeth_core_ethtool_get_settings,
865 };
866
867 static struct ethtool_ops qeth_l2_osn_ops = {
868         .get_strings = qeth_core_get_strings,
869         .get_ethtool_stats = qeth_core_get_ethtool_stats,
870         .get_stats_count = qeth_core_get_stats_count,
871         .get_drvinfo = qeth_core_get_drvinfo,
872 };
873
874 static const struct net_device_ops qeth_l2_netdev_ops = {
875         .ndo_open               = qeth_l2_open,
876         .ndo_stop               = qeth_l2_stop,
877         .ndo_get_stats          = qeth_get_stats,
878         .ndo_start_xmit         = qeth_l2_hard_start_xmit,
879         .ndo_validate_addr      = eth_validate_addr,
880         .ndo_set_multicast_list = qeth_l2_set_multicast_list,
881         .ndo_do_ioctl           = qeth_l2_do_ioctl,
882         .ndo_set_mac_address    = qeth_l2_set_mac_address,
883         .ndo_change_mtu         = qeth_change_mtu,
884         .ndo_vlan_rx_add_vid    = qeth_l2_vlan_rx_add_vid,
885         .ndo_vlan_rx_kill_vid   = qeth_l2_vlan_rx_kill_vid,
886         .ndo_tx_timeout         = qeth_tx_timeout,
887 };
888
889 static int qeth_l2_setup_netdev(struct qeth_card *card)
890 {
891         switch (card->info.type) {
892         case QETH_CARD_TYPE_OSAE:
893                 card->dev = alloc_etherdev(0);
894                 break;
895         case QETH_CARD_TYPE_IQD:
896                 card->dev = alloc_netdev(0, "hsi%d", ether_setup);
897                 break;
898         case QETH_CARD_TYPE_OSN:
899                 card->dev = alloc_netdev(0, "osn%d", ether_setup);
900                 card->dev->flags |= IFF_NOARP;
901                 break;
902         default:
903                 card->dev = alloc_etherdev(0);
904         }
905
906         if (!card->dev)
907                 return -ENODEV;
908
909         card->dev->ml_priv = card;
910         card->dev->watchdog_timeo = QETH_TX_TIMEOUT;
911         card->dev->mtu = card->info.initial_mtu;
912         card->dev->netdev_ops = &qeth_l2_netdev_ops;
913         if (card->info.type != QETH_CARD_TYPE_OSN)
914                 SET_ETHTOOL_OPS(card->dev, &qeth_l2_ethtool_ops);
915         else
916                 SET_ETHTOOL_OPS(card->dev, &qeth_l2_osn_ops);
917         card->dev->features |= NETIF_F_HW_VLAN_FILTER;
918         card->info.broadcast_capable = 1;
919         qeth_l2_request_initial_mac(card);
920         SET_NETDEV_DEV(card->dev, &card->gdev->dev);
921         return register_netdev(card->dev);
922 }
923
924 static int __qeth_l2_set_online(struct ccwgroup_device *gdev, int recovery_mode)
925 {
926         struct qeth_card *card = dev_get_drvdata(&gdev->dev);
927         int rc = 0;
928         enum qeth_card_states recover_flag;
929
930         BUG_ON(!card);
931         QETH_DBF_TEXT(SETUP, 2, "setonlin");
932         QETH_DBF_HEX(SETUP, 2, &card, sizeof(void *));
933
934         qeth_set_allowed_threads(card, QETH_RECOVER_THREAD, 1);
935         recover_flag = card->state;
936         rc = ccw_device_set_online(CARD_RDEV(card));
937         if (rc) {
938                 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
939                 return -EIO;
940         }
941         rc = ccw_device_set_online(CARD_WDEV(card));
942         if (rc) {
943                 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
944                 return -EIO;
945         }
946         rc = ccw_device_set_online(CARD_DDEV(card));
947         if (rc) {
948                 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
949                 return -EIO;
950         }
951
952         rc = qeth_core_hardsetup_card(card);
953         if (rc) {
954                 QETH_DBF_TEXT_(SETUP, 2, "2err%d", rc);
955                 goto out_remove;
956         }
957
958         if (!card->dev && qeth_l2_setup_netdev(card))
959                 goto out_remove;
960
961         if (card->info.type != QETH_CARD_TYPE_OSN)
962                 qeth_l2_send_setmac(card, &card->dev->dev_addr[0]);
963
964         card->state = CARD_STATE_HARDSETUP;
965         qeth_print_status_message(card);
966
967         /* softsetup */
968         QETH_DBF_TEXT(SETUP, 2, "softsetp");
969
970         rc = qeth_send_startlan(card);
971         if (rc) {
972                 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
973                 if (rc == 0xe080) {
974                         dev_warn(&card->gdev->dev,
975                                 "The LAN is offline\n");
976                         card->lan_online = 0;
977                 }
978                 return rc;
979         } else
980                 card->lan_online = 1;
981
982         if (card->info.type != QETH_CARD_TYPE_OSN) {
983                 qeth_set_large_send(card, card->options.large_send);
984                 qeth_l2_process_vlans(card, 0);
985         }
986
987         netif_tx_disable(card->dev);
988
989         rc = qeth_init_qdio_queues(card);
990         if (rc) {
991                 QETH_DBF_TEXT_(SETUP, 2, "6err%d", rc);
992                 goto out_remove;
993         }
994         card->state = CARD_STATE_SOFTSETUP;
995         netif_carrier_on(card->dev);
996
997         qeth_set_allowed_threads(card, 0xffffffff, 0);
998         if (recover_flag == CARD_STATE_RECOVER) {
999                 if (recovery_mode &&
1000                     card->info.type != QETH_CARD_TYPE_OSN) {
1001                         qeth_l2_open(card->dev);
1002                 } else {
1003                         rtnl_lock();
1004                         dev_open(card->dev);
1005                         rtnl_unlock();
1006                 }
1007                 /* this also sets saved unicast addresses */
1008                 qeth_l2_set_multicast_list(card->dev);
1009         }
1010         /* let user_space know that device is online */
1011         kobject_uevent(&gdev->dev.kobj, KOBJ_CHANGE);
1012         return 0;
1013 out_remove:
1014         card->use_hard_stop = 1;
1015         qeth_l2_stop_card(card, 0);
1016         ccw_device_set_offline(CARD_DDEV(card));
1017         ccw_device_set_offline(CARD_WDEV(card));
1018         ccw_device_set_offline(CARD_RDEV(card));
1019         if (recover_flag == CARD_STATE_RECOVER)
1020                 card->state = CARD_STATE_RECOVER;
1021         else
1022                 card->state = CARD_STATE_DOWN;
1023         return -ENODEV;
1024 }
1025
1026 static int qeth_l2_set_online(struct ccwgroup_device *gdev)
1027 {
1028         return __qeth_l2_set_online(gdev, 0);
1029 }
1030
1031 static int __qeth_l2_set_offline(struct ccwgroup_device *cgdev,
1032                                         int recovery_mode)
1033 {
1034         struct qeth_card *card = dev_get_drvdata(&cgdev->dev);
1035         int rc = 0, rc2 = 0, rc3 = 0;
1036         enum qeth_card_states recover_flag;
1037
1038         QETH_DBF_TEXT(SETUP, 3, "setoffl");
1039         QETH_DBF_HEX(SETUP, 3, &card, sizeof(void *));
1040
1041         if (card->dev && netif_carrier_ok(card->dev))
1042                 netif_carrier_off(card->dev);
1043         recover_flag = card->state;
1044         qeth_l2_stop_card(card, recovery_mode);
1045         rc  = ccw_device_set_offline(CARD_DDEV(card));
1046         rc2 = ccw_device_set_offline(CARD_WDEV(card));
1047         rc3 = ccw_device_set_offline(CARD_RDEV(card));
1048         if (!rc)
1049                 rc = (rc2) ? rc2 : rc3;
1050         if (rc)
1051                 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
1052         if (recover_flag == CARD_STATE_UP)
1053                 card->state = CARD_STATE_RECOVER;
1054         /* let user_space know that device is offline */
1055         kobject_uevent(&cgdev->dev.kobj, KOBJ_CHANGE);
1056         return 0;
1057 }
1058
1059 static int qeth_l2_set_offline(struct ccwgroup_device *cgdev)
1060 {
1061         return __qeth_l2_set_offline(cgdev, 0);
1062 }
1063
1064 static int qeth_l2_recover(void *ptr)
1065 {
1066         struct qeth_card *card;
1067         int rc = 0;
1068
1069         card = (struct qeth_card *) ptr;
1070         QETH_DBF_TEXT(TRACE, 2, "recover1");
1071         QETH_DBF_HEX(TRACE, 2, &card, sizeof(void *));
1072         if (!qeth_do_run_thread(card, QETH_RECOVER_THREAD))
1073                 return 0;
1074         QETH_DBF_TEXT(TRACE, 2, "recover2");
1075         dev_warn(&card->gdev->dev,
1076                 "A recovery process has been started for the device\n");
1077         card->use_hard_stop = 1;
1078         __qeth_l2_set_offline(card->gdev, 1);
1079         rc = __qeth_l2_set_online(card->gdev, 1);
1080         /* don't run another scheduled recovery */
1081         qeth_clear_thread_start_bit(card, QETH_RECOVER_THREAD);
1082         qeth_clear_thread_running_bit(card, QETH_RECOVER_THREAD);
1083         if (!rc)
1084                 dev_info(&card->gdev->dev,
1085                         "Device successfully recovered!\n");
1086         else {
1087                 if (card->dev) {
1088                         rtnl_lock();
1089                         dev_close(card->dev);
1090                         rtnl_unlock();
1091                 }
1092                 dev_warn(&card->gdev->dev, "The qeth device driver "
1093                         "failed to recover an error on the device\n");
1094         }
1095         return 0;
1096 }
1097
1098 static int __init qeth_l2_init(void)
1099 {
1100         pr_info("register layer 2 discipline\n");
1101         return 0;
1102 }
1103
1104 static void __exit qeth_l2_exit(void)
1105 {
1106         pr_info("unregister layer 2 discipline\n");
1107 }
1108
1109 static void qeth_l2_shutdown(struct ccwgroup_device *gdev)
1110 {
1111         struct qeth_card *card = dev_get_drvdata(&gdev->dev);
1112         qeth_qdio_clear_card(card, 0);
1113         qeth_clear_qdio_buffers(card);
1114 }
1115
1116 struct ccwgroup_driver qeth_l2_ccwgroup_driver = {
1117         .probe = qeth_l2_probe_device,
1118         .remove = qeth_l2_remove_device,
1119         .set_online = qeth_l2_set_online,
1120         .set_offline = qeth_l2_set_offline,
1121         .shutdown = qeth_l2_shutdown,
1122 };
1123 EXPORT_SYMBOL_GPL(qeth_l2_ccwgroup_driver);
1124
1125 static int qeth_osn_send_control_data(struct qeth_card *card, int len,
1126                            struct qeth_cmd_buffer *iob)
1127 {
1128         unsigned long flags;
1129         int rc = 0;
1130
1131         QETH_DBF_TEXT(TRACE, 5, "osndctrd");
1132
1133         wait_event(card->wait_q,
1134                    atomic_cmpxchg(&card->write.irq_pending, 0, 1) == 0);
1135         qeth_prepare_control_data(card, len, iob);
1136         QETH_DBF_TEXT(TRACE, 6, "osnoirqp");
1137         spin_lock_irqsave(get_ccwdev_lock(card->write.ccwdev), flags);
1138         rc = ccw_device_start(card->write.ccwdev, &card->write.ccw,
1139                               (addr_t) iob, 0, 0);
1140         spin_unlock_irqrestore(get_ccwdev_lock(card->write.ccwdev), flags);
1141         if (rc) {
1142                 QETH_DBF_MESSAGE(2, "qeth_osn_send_control_data: "
1143                            "ccw_device_start rc = %i\n", rc);
1144                 QETH_DBF_TEXT_(TRACE, 2, " err%d", rc);
1145                 qeth_release_buffer(iob->channel, iob);
1146                 atomic_set(&card->write.irq_pending, 0);
1147                 wake_up(&card->wait_q);
1148         }
1149         return rc;
1150 }
1151
1152 static int qeth_osn_send_ipa_cmd(struct qeth_card *card,
1153                         struct qeth_cmd_buffer *iob, int data_len)
1154 {
1155         u16 s1, s2;
1156
1157         QETH_DBF_TEXT(TRACE, 4, "osndipa");
1158
1159         qeth_prepare_ipa_cmd(card, iob, QETH_PROT_OSN2);
1160         s1 = (u16)(IPA_PDU_HEADER_SIZE + data_len);
1161         s2 = (u16)data_len;
1162         memcpy(QETH_IPA_PDU_LEN_TOTAL(iob->data), &s1, 2);
1163         memcpy(QETH_IPA_PDU_LEN_PDU1(iob->data), &s2, 2);
1164         memcpy(QETH_IPA_PDU_LEN_PDU2(iob->data), &s2, 2);
1165         memcpy(QETH_IPA_PDU_LEN_PDU3(iob->data), &s2, 2);
1166         return qeth_osn_send_control_data(card, s1, iob);
1167 }
1168
1169 int qeth_osn_assist(struct net_device *dev, void *data, int data_len)
1170 {
1171         struct qeth_cmd_buffer *iob;
1172         struct qeth_card *card;
1173         int rc;
1174
1175         QETH_DBF_TEXT(TRACE, 2, "osnsdmc");
1176         if (!dev)
1177                 return -ENODEV;
1178         card = dev->ml_priv;
1179         if (!card)
1180                 return -ENODEV;
1181         if ((card->state != CARD_STATE_UP) &&
1182             (card->state != CARD_STATE_SOFTSETUP))
1183                 return -ENODEV;
1184         iob = qeth_wait_for_buffer(&card->write);
1185         memcpy(iob->data+IPA_PDU_HEADER_SIZE, data, data_len);
1186         rc = qeth_osn_send_ipa_cmd(card, iob, data_len);
1187         return rc;
1188 }
1189 EXPORT_SYMBOL(qeth_osn_assist);
1190
1191 int qeth_osn_register(unsigned char *read_dev_no, struct net_device **dev,
1192                   int (*assist_cb)(struct net_device *, void *),
1193                   int (*data_cb)(struct sk_buff *))
1194 {
1195         struct qeth_card *card;
1196
1197         QETH_DBF_TEXT(TRACE, 2, "osnreg");
1198         *dev = qeth_l2_netdev_by_devno(read_dev_no);
1199         if (*dev == NULL)
1200                 return -ENODEV;
1201         card = (*dev)->ml_priv;
1202         if (!card)
1203                 return -ENODEV;
1204         if ((assist_cb == NULL) || (data_cb == NULL))
1205                 return -EINVAL;
1206         card->osn_info.assist_cb = assist_cb;
1207         card->osn_info.data_cb = data_cb;
1208         return 0;
1209 }
1210 EXPORT_SYMBOL(qeth_osn_register);
1211
1212 void qeth_osn_deregister(struct net_device *dev)
1213 {
1214         struct qeth_card *card;
1215
1216         QETH_DBF_TEXT(TRACE, 2, "osndereg");
1217         if (!dev)
1218                 return;
1219         card = dev->ml_priv;
1220         if (!card)
1221                 return;
1222         card->osn_info.assist_cb = NULL;
1223         card->osn_info.data_cb = NULL;
1224         return;
1225 }
1226 EXPORT_SYMBOL(qeth_osn_deregister);
1227
1228 module_init(qeth_l2_init);
1229 module_exit(qeth_l2_exit);
1230 MODULE_AUTHOR("Frank Blaschka <frank.blaschka@de.ibm.com>");
1231 MODULE_DESCRIPTION("qeth layer 2 discipline");
1232 MODULE_LICENSE("GPL");