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