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