blob: 01c3c1f7787941c415d2c5e2367d72b756ec3591 [file] [log] [blame]
Frank Blaschka4a71df52008-02-15 09:19:42 +01001/*
2 * drivers/s390/net/qeth_l2_main.c
3 *
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02004 * Copyright IBM Corp. 2007, 2009
Frank Blaschka4a71df52008-02-15 09:19:42 +01005 * 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
Frank Blaschka74eacdb2008-12-25 13:39:49 +010011#define KMSG_COMPONENT "qeth"
12#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
13
Frank Blaschka4a71df52008-02-15 09:19:42 +010014#include <linux/module.h>
15#include <linux/moduleparam.h>
16#include <linux/string.h>
17#include <linux/errno.h>
18#include <linux/kernel.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090019#include <linux/slab.h>
Frank Blaschka4a71df52008-02-15 09:19:42 +010020#include <linux/etherdevice.h>
21#include <linux/mii.h>
22#include <linux/ip.h>
Jiri Pirkoccffad252009-05-22 23:22:17 +000023#include <linux/list.h>
Frank Blaschka4a71df52008-02-15 09:19:42 +010024
Frank Blaschka4a71df52008-02-15 09:19:42 +010025#include "qeth_core.h"
Frank Blaschka4a71df52008-02-15 09:19:42 +010026
Frank Blaschka4a71df52008-02-15 09:19:42 +010027static int qeth_l2_set_offline(struct ccwgroup_device *);
28static int qeth_l2_stop(struct net_device *);
29static int qeth_l2_send_delmac(struct qeth_card *, __u8 *);
30static int qeth_l2_send_setdelmac(struct qeth_card *, __u8 *,
31 enum qeth_ipa_cmds,
32 int (*reply_cb) (struct qeth_card *,
33 struct qeth_reply*,
34 unsigned long));
35static void qeth_l2_set_multicast_list(struct net_device *);
36static int qeth_l2_recover(void *);
37
38static int qeth_l2_do_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
39{
Heiko Carstens509e2562008-07-26 02:24:10 -070040 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +010041 struct mii_ioctl_data *mii_data;
42 int rc = 0;
43
44 if (!card)
45 return -ENODEV;
46
47 if ((card->state != CARD_STATE_UP) &&
48 (card->state != CARD_STATE_SOFTSETUP))
49 return -ENODEV;
50
51 if (card->info.type == QETH_CARD_TYPE_OSN)
52 return -EPERM;
53
54 switch (cmd) {
55 case SIOC_QETH_ADP_SET_SNMP_CONTROL:
56 rc = qeth_snmp_command(card, rq->ifr_ifru.ifru_data);
57 break;
58 case SIOC_QETH_GET_CARD_TYPE:
Ursula Braun5113fec2010-05-16 21:15:14 +000059 if ((card->info.type == QETH_CARD_TYPE_OSD ||
60 card->info.type == QETH_CARD_TYPE_OSM ||
61 card->info.type == QETH_CARD_TYPE_OSX) &&
Frank Blaschka4a71df52008-02-15 09:19:42 +010062 !card->info.guestlan)
63 return 1;
64 return 0;
65 break;
66 case SIOCGMIIPHY:
67 mii_data = if_mii(rq);
68 mii_data->phy_id = 0;
69 break;
70 case SIOCGMIIREG:
71 mii_data = if_mii(rq);
72 if (mii_data->phy_id != 0)
73 rc = -EINVAL;
74 else
75 mii_data->val_out = qeth_mdio_read(dev,
76 mii_data->phy_id, mii_data->reg_num);
77 break;
78 default:
79 rc = -EOPNOTSUPP;
80 }
81 if (rc)
Carsten Otte847a50f2010-06-21 22:57:05 +000082 QETH_CARD_TEXT_(card, 2, "ioce%d", rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +010083 return rc;
84}
85
86static int qeth_l2_verify_dev(struct net_device *dev)
87{
88 struct qeth_card *card;
89 unsigned long flags;
90 int rc = 0;
91
92 read_lock_irqsave(&qeth_core_card_list.rwlock, flags);
93 list_for_each_entry(card, &qeth_core_card_list.list, list) {
94 if (card->dev == dev) {
95 rc = QETH_REAL_CARD;
96 break;
97 }
98 }
99 read_unlock_irqrestore(&qeth_core_card_list.rwlock, flags);
100
101 return rc;
102}
103
104static struct net_device *qeth_l2_netdev_by_devno(unsigned char *read_dev_no)
105{
106 struct qeth_card *card;
107 struct net_device *ndev;
Cornelia Huckf06f6f32008-06-06 12:37:45 +0200108 __u16 temp_dev_no;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100109 unsigned long flags;
Cornelia Huckf06f6f32008-06-06 12:37:45 +0200110 struct ccw_dev_id read_devid;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100111
112 ndev = NULL;
113 memcpy(&temp_dev_no, read_dev_no, 2);
114 read_lock_irqsave(&qeth_core_card_list.rwlock, flags);
115 list_for_each_entry(card, &qeth_core_card_list.list, list) {
Cornelia Huckf06f6f32008-06-06 12:37:45 +0200116 ccw_device_get_id(CARD_RDEV(card), &read_devid);
117 if (read_devid.devno == temp_dev_no) {
Frank Blaschka4a71df52008-02-15 09:19:42 +0100118 ndev = card->dev;
119 break;
120 }
121 }
122 read_unlock_irqrestore(&qeth_core_card_list.rwlock, flags);
123 return ndev;
124}
125
126static int qeth_l2_send_setgroupmac_cb(struct qeth_card *card,
127 struct qeth_reply *reply,
128 unsigned long data)
129{
130 struct qeth_ipa_cmd *cmd;
131 __u8 *mac;
132
Carsten Otte847a50f2010-06-21 22:57:05 +0000133 QETH_CARD_TEXT(card, 2, "L2Sgmacb");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100134 cmd = (struct qeth_ipa_cmd *) data;
135 mac = &cmd->data.setdelmac.mac[0];
136 /* MAC already registered, needed in couple/uncouple case */
Ursula Braun0666eb062009-05-19 21:38:39 +0000137 if (cmd->hdr.return_code == IPA_RC_L2_DUP_MAC) {
Johannes Berg7c510e42008-10-27 17:47:26 -0700138 QETH_DBF_MESSAGE(2, "Group MAC %pM already existing on %s \n",
139 mac, QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100140 cmd->hdr.return_code = 0;
141 }
142 if (cmd->hdr.return_code)
Johannes Berg7c510e42008-10-27 17:47:26 -0700143 QETH_DBF_MESSAGE(2, "Could not set group MAC %pM on %s: %x\n",
144 mac, QETH_CARD_IFNAME(card), cmd->hdr.return_code);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100145 return 0;
146}
147
148static int qeth_l2_send_setgroupmac(struct qeth_card *card, __u8 *mac)
149{
Carsten Otte847a50f2010-06-21 22:57:05 +0000150 QETH_CARD_TEXT(card, 2, "L2Sgmac");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100151 return qeth_l2_send_setdelmac(card, mac, IPA_CMD_SETGMAC,
152 qeth_l2_send_setgroupmac_cb);
153}
154
155static 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
Carsten Otte847a50f2010-06-21 22:57:05 +0000162 QETH_CARD_TEXT(card, 2, "L2Dgmacb");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100163 cmd = (struct qeth_ipa_cmd *) data;
164 mac = &cmd->data.setdelmac.mac[0];
165 if (cmd->hdr.return_code)
Johannes Berg7c510e42008-10-27 17:47:26 -0700166 QETH_DBF_MESSAGE(2, "Could not delete group MAC %pM on %s: %x\n",
167 mac, QETH_CARD_IFNAME(card), cmd->hdr.return_code);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100168 return 0;
169}
170
171static int qeth_l2_send_delgroupmac(struct qeth_card *card, __u8 *mac)
172{
Carsten Otte847a50f2010-06-21 22:57:05 +0000173 QETH_CARD_TEXT(card, 2, "L2Dgmac");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100174 return qeth_l2_send_setdelmac(card, mac, IPA_CMD_DELGMAC,
175 qeth_l2_send_delgroupmac_cb);
176}
177
Frank Blaschka7db22662008-08-15 08:02:59 +0200178static void qeth_l2_add_mc(struct qeth_card *card, __u8 *mac, int vmac)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100179{
180 struct qeth_mc_mac *mc;
Frank Blaschka7db22662008-08-15 08:02:59 +0200181 int rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100182
183 mc = kmalloc(sizeof(struct qeth_mc_mac), GFP_ATOMIC);
184
Frank Blaschka14cc21b2008-06-06 12:37:46 +0200185 if (!mc)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100186 return;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100187
188 memcpy(mc->mc_addr, mac, OSA_ADDR_LEN);
189 mc->mc_addrlen = OSA_ADDR_LEN;
Frank Blaschka7db22662008-08-15 08:02:59 +0200190 mc->is_vmac = vmac;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100191
Frank Blaschka7db22662008-08-15 08:02:59 +0200192 if (vmac) {
193 rc = qeth_l2_send_setdelmac(card, mac, IPA_CMD_SETVMAC,
194 NULL);
195 } else {
196 rc = qeth_l2_send_setgroupmac(card, mac);
197 }
198
199 if (!rc)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100200 list_add_tail(&mc->list, &card->mc_list);
201 else
202 kfree(mc);
203}
204
205static void qeth_l2_del_all_mc(struct qeth_card *card)
206{
207 struct qeth_mc_mac *mc, *tmp;
208
209 spin_lock_bh(&card->mclock);
210 list_for_each_entry_safe(mc, tmp, &card->mc_list, list) {
Frank Blaschka7db22662008-08-15 08:02:59 +0200211 if (mc->is_vmac)
212 qeth_l2_send_setdelmac(card, mc->mc_addr,
213 IPA_CMD_DELVMAC, NULL);
214 else
215 qeth_l2_send_delgroupmac(card, mc->mc_addr);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100216 list_del(&mc->list);
217 kfree(mc);
218 }
219 spin_unlock_bh(&card->mclock);
220}
221
Klaus-Dieter Wackerce73e102009-08-26 02:01:08 +0000222static inline int qeth_l2_get_cast_type(struct qeth_card *card,
223 struct sk_buff *skb)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100224{
Klaus-Dieter Wackerce73e102009-08-26 02:01:08 +0000225 if (card->info.type == QETH_CARD_TYPE_OSN)
226 return RTN_UNSPEC;
227 if (is_broadcast_ether_addr(skb->data))
228 return RTN_BROADCAST;
229 if (is_multicast_ether_addr(skb->data))
230 return RTN_MULTICAST;
231 return RTN_UNSPEC;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100232}
233
234static void qeth_l2_fill_header(struct qeth_card *card, struct qeth_hdr *hdr,
235 struct sk_buff *skb, int ipv, int cast_type)
236{
Frank Blaschka683d7182008-08-01 16:39:13 +0200237 struct vlan_ethhdr *veth = (struct vlan_ethhdr *)skb_mac_header(skb);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100238
239 memset(hdr, 0, sizeof(struct qeth_hdr));
240 hdr->hdr.l2.id = QETH_HEADER_TYPE_LAYER2;
241
242 /* set byte byte 3 to casting flags */
243 if (cast_type == RTN_MULTICAST)
244 hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_MULTICAST;
245 else if (cast_type == RTN_BROADCAST)
246 hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_BROADCAST;
247 else
Klaus-Dieter Wackerce73e102009-08-26 02:01:08 +0000248 hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_UNICAST;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100249
250 hdr->hdr.l2.pkt_length = skb->len-QETH_HEADER_SIZE;
251 /* VSWITCH relies on the VLAN
252 * information to be present in
253 * the QDIO header */
254 if (veth->h_vlan_proto == __constant_htons(ETH_P_8021Q)) {
255 hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_VLAN;
256 hdr->hdr.l2.vlan_id = ntohs(veth->h_vlan_TCI);
257 }
258}
259
260static int qeth_l2_send_setdelvlan_cb(struct qeth_card *card,
261 struct qeth_reply *reply, unsigned long data)
262{
263 struct qeth_ipa_cmd *cmd;
264
Carsten Otte847a50f2010-06-21 22:57:05 +0000265 QETH_CARD_TEXT(card, 2, "L2sdvcb");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100266 cmd = (struct qeth_ipa_cmd *) data;
267 if (cmd->hdr.return_code) {
Frank Blaschka14cc21b2008-06-06 12:37:46 +0200268 QETH_DBF_MESSAGE(2, "Error in processing VLAN %i on %s: 0x%x. "
Frank Blaschka4a71df52008-02-15 09:19:42 +0100269 "Continuing\n", cmd->data.setdelvlan.vlan_id,
270 QETH_CARD_IFNAME(card), cmd->hdr.return_code);
Carsten Otte847a50f2010-06-21 22:57:05 +0000271 QETH_CARD_TEXT_(card, 2, "L2VL%4x", cmd->hdr.command);
272 QETH_CARD_TEXT_(card, 2, "err%d", cmd->hdr.return_code);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100273 }
274 return 0;
275}
276
277static int qeth_l2_send_setdelvlan(struct qeth_card *card, __u16 i,
278 enum qeth_ipa_cmds ipacmd)
279{
280 struct qeth_ipa_cmd *cmd;
281 struct qeth_cmd_buffer *iob;
282
Carsten Otte847a50f2010-06-21 22:57:05 +0000283 QETH_CARD_TEXT_(card, 4, "L2sdv%x", ipacmd);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100284 iob = qeth_get_ipacmd_buffer(card, ipacmd, QETH_PROT_IPV4);
285 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
286 cmd->data.setdelvlan.vlan_id = i;
287 return qeth_send_ipa_cmd(card, iob,
288 qeth_l2_send_setdelvlan_cb, NULL);
289}
290
291static void qeth_l2_process_vlans(struct qeth_card *card, int clear)
292{
293 struct qeth_vlan_vid *id;
Carsten Otte847a50f2010-06-21 22:57:05 +0000294 QETH_CARD_TEXT(card, 3, "L2prcvln");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100295 spin_lock_bh(&card->vlanlock);
296 list_for_each_entry(id, &card->vid_list, list) {
297 if (clear)
298 qeth_l2_send_setdelvlan(card, id->vid,
299 IPA_CMD_DELVLAN);
300 else
301 qeth_l2_send_setdelvlan(card, id->vid,
302 IPA_CMD_SETVLAN);
303 }
304 spin_unlock_bh(&card->vlanlock);
305}
306
307static void qeth_l2_vlan_rx_add_vid(struct net_device *dev, unsigned short vid)
308{
Heiko Carstens509e2562008-07-26 02:24:10 -0700309 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100310 struct qeth_vlan_vid *id;
311
Carsten Otte847a50f2010-06-21 22:57:05 +0000312 QETH_CARD_TEXT_(card, 4, "aid:%d", vid);
Ursula Braun5113fec2010-05-16 21:15:14 +0000313 if (card->info.type == QETH_CARD_TYPE_OSM) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000314 QETH_CARD_TEXT(card, 3, "aidOSM");
Ursula Braun5113fec2010-05-16 21:15:14 +0000315 return;
316 }
Ursula Braun8e98ac42009-03-24 20:57:18 +0000317 if (qeth_wait_for_threads(card, QETH_RECOVER_THREAD)) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000318 QETH_CARD_TEXT(card, 3, "aidREC");
Ursula Braun8e98ac42009-03-24 20:57:18 +0000319 return;
320 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100321 id = kmalloc(sizeof(struct qeth_vlan_vid), GFP_ATOMIC);
322 if (id) {
323 id->vid = vid;
324 qeth_l2_send_setdelvlan(card, vid, IPA_CMD_SETVLAN);
325 spin_lock_bh(&card->vlanlock);
326 list_add_tail(&id->list, &card->vid_list);
327 spin_unlock_bh(&card->vlanlock);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100328 }
329}
330
331static void qeth_l2_vlan_rx_kill_vid(struct net_device *dev, unsigned short vid)
332{
333 struct qeth_vlan_vid *id, *tmpid = NULL;
Heiko Carstens509e2562008-07-26 02:24:10 -0700334 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100335
Carsten Otte847a50f2010-06-21 22:57:05 +0000336 QETH_CARD_TEXT_(card, 4, "kid:%d", vid);
Ursula Braun5113fec2010-05-16 21:15:14 +0000337 if (card->info.type == QETH_CARD_TYPE_OSM) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000338 QETH_CARD_TEXT(card, 3, "kidOSM");
Ursula Braun5113fec2010-05-16 21:15:14 +0000339 return;
340 }
Ursula Braun8e98ac42009-03-24 20:57:18 +0000341 if (qeth_wait_for_threads(card, QETH_RECOVER_THREAD)) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000342 QETH_CARD_TEXT(card, 3, "kidREC");
Ursula Braun8e98ac42009-03-24 20:57:18 +0000343 return;
344 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100345 spin_lock_bh(&card->vlanlock);
346 list_for_each_entry(id, &card->vid_list, list) {
347 if (id->vid == vid) {
348 list_del(&id->list);
349 tmpid = id;
350 break;
351 }
352 }
353 spin_unlock_bh(&card->vlanlock);
354 if (tmpid) {
355 qeth_l2_send_setdelvlan(card, vid, IPA_CMD_DELVLAN);
356 kfree(tmpid);
357 }
358 qeth_l2_set_multicast_list(card->dev);
359}
360
361static int qeth_l2_stop_card(struct qeth_card *card, int recovery_mode)
362{
363 int rc = 0;
364
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200365 QETH_DBF_TEXT(SETUP , 2, "stopcard");
366 QETH_DBF_HEX(SETUP, 2, &card, sizeof(void *));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100367
368 qeth_set_allowed_threads(card, 0, 1);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100369 if (card->read.state == CH_STATE_UP &&
370 card->write.state == CH_STATE_UP &&
371 (card->state == CARD_STATE_UP)) {
372 if (recovery_mode &&
373 card->info.type != QETH_CARD_TYPE_OSN) {
374 qeth_l2_stop(card->dev);
375 } else {
376 rtnl_lock();
377 dev_close(card->dev);
378 rtnl_unlock();
379 }
Klaus-Dieter Wacker932e15832009-03-24 20:57:17 +0000380 if (!card->use_hard_stop ||
381 recovery_mode) {
Frank Blaschka4a71df52008-02-15 09:19:42 +0100382 __u8 *mac = &card->dev->dev_addr[0];
383 rc = qeth_l2_send_delmac(card, mac);
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200384 QETH_DBF_TEXT_(SETUP, 2, "Lerr%d", rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100385 }
386 card->state = CARD_STATE_SOFTSETUP;
387 }
388 if (card->state == CARD_STATE_SOFTSETUP) {
389 qeth_l2_process_vlans(card, 1);
Klaus-Dieter Wacker932e15832009-03-24 20:57:17 +0000390 if (!card->use_hard_stop ||
391 recovery_mode)
Ursula Braun28a7e4c2008-09-19 12:56:03 +0200392 qeth_l2_del_all_mc(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100393 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
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000410static int qeth_l2_process_inbound_buffer(struct qeth_card *card,
411 int budget, int *done)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100412{
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000413 int work_done = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100414 struct sk_buff *skb;
415 struct qeth_hdr *hdr;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100416 unsigned int len;
417
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000418 *done = 0;
419 BUG_ON(!budget);
420 while (budget) {
421 skb = qeth_core_get_next_skb(card,
422 card->qdio.in_q->bufs[card->rx.b_index].buffer,
423 &card->rx.b_element, &card->rx.e_offset, &hdr);
424 if (!skb) {
425 *done = 1;
426 break;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100427 }
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000428 skb->dev = card->dev;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100429 switch (hdr->hdr.l2.id) {
430 case QETH_HEADER_TYPE_LAYER2:
431 skb->pkt_type = PACKET_HOST;
432 skb->protocol = eth_type_trans(skb, skb->dev);
433 if (card->options.checksum_type == NO_CHECKSUMMING)
434 skb->ip_summed = CHECKSUM_UNNECESSARY;
435 else
436 skb->ip_summed = CHECKSUM_NONE;
Ursula Braun12883722008-04-01 10:26:56 +0200437 if (skb->protocol == htons(ETH_P_802_2))
438 *((__u32 *)skb->cb) = ++card->seqno.pkt_seqno;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100439 len = skb->len;
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000440 netif_receive_skb(skb);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100441 break;
442 case QETH_HEADER_TYPE_OSN:
Ursula Braun2d488c22008-10-24 11:16:55 +0200443 if (card->info.type == QETH_CARD_TYPE_OSN) {
444 skb_push(skb, sizeof(struct qeth_hdr));
445 skb_copy_to_linear_data(skb, hdr,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100446 sizeof(struct qeth_hdr));
Ursula Braun2d488c22008-10-24 11:16:55 +0200447 len = skb->len;
448 card->osn_info.data_cb(skb);
449 break;
450 }
451 /* else unknown */
Frank Blaschka4a71df52008-02-15 09:19:42 +0100452 default:
453 dev_kfree_skb_any(skb);
Carsten Otte847a50f2010-06-21 22:57:05 +0000454 QETH_CARD_TEXT(card, 3, "inbunkno");
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200455 QETH_DBF_HEX(CTRL, 3, hdr, QETH_DBF_CTRL_LEN);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100456 continue;
457 }
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000458 work_done++;
459 budget--;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100460 card->stats.rx_packets++;
461 card->stats.rx_bytes += len;
462 }
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000463 return work_done;
464}
465
466static int qeth_l2_poll(struct napi_struct *napi, int budget)
467{
468 struct qeth_card *card = container_of(napi, struct qeth_card, napi);
469 int work_done = 0;
470 struct qeth_qdio_buffer *buffer;
471 int done;
472 int new_budget = budget;
473
474 if (card->options.performance_stats) {
475 card->perf_stats.inbound_cnt++;
476 card->perf_stats.inbound_start_time = qeth_get_micros();
477 }
478
479 while (1) {
480 if (!card->rx.b_count) {
481 card->rx.qdio_err = 0;
482 card->rx.b_count = qdio_get_next_buffers(
483 card->data.ccwdev, 0, &card->rx.b_index,
484 &card->rx.qdio_err);
485 if (card->rx.b_count <= 0) {
486 card->rx.b_count = 0;
487 break;
488 }
489 card->rx.b_element =
490 &card->qdio.in_q->bufs[card->rx.b_index]
491 .buffer->element[0];
492 card->rx.e_offset = 0;
493 }
494
495 while (card->rx.b_count) {
496 buffer = &card->qdio.in_q->bufs[card->rx.b_index];
497 if (!(card->rx.qdio_err &&
498 qeth_check_qdio_errors(card, buffer->buffer,
499 card->rx.qdio_err, "qinerr")))
500 work_done += qeth_l2_process_inbound_buffer(
501 card, new_budget, &done);
502 else
503 done = 1;
504
505 if (done) {
506 if (card->options.performance_stats)
507 card->perf_stats.bufs_rec++;
508 qeth_put_buffer_pool_entry(card,
509 buffer->pool_entry);
510 qeth_queue_input_buffer(card, card->rx.b_index);
511 card->rx.b_count--;
512 if (card->rx.b_count) {
513 card->rx.b_index =
514 (card->rx.b_index + 1) %
515 QDIO_MAX_BUFFERS_PER_Q;
516 card->rx.b_element =
517 &card->qdio.in_q
518 ->bufs[card->rx.b_index]
519 .buffer->element[0];
520 card->rx.e_offset = 0;
521 }
522 }
523
524 if (work_done >= budget)
525 goto out;
526 else
527 new_budget = budget - work_done;
528 }
529 }
530
531 napi_complete(napi);
532 if (qdio_start_irq(card->data.ccwdev, 0))
533 napi_schedule(&card->napi);
534out:
535 if (card->options.performance_stats)
536 card->perf_stats.inbound_time += qeth_get_micros() -
537 card->perf_stats.inbound_start_time;
538 return work_done;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100539}
540
541static int qeth_l2_send_setdelmac(struct qeth_card *card, __u8 *mac,
542 enum qeth_ipa_cmds ipacmd,
543 int (*reply_cb) (struct qeth_card *,
544 struct qeth_reply*,
545 unsigned long))
546{
547 struct qeth_ipa_cmd *cmd;
548 struct qeth_cmd_buffer *iob;
549
Carsten Otte847a50f2010-06-21 22:57:05 +0000550 QETH_CARD_TEXT(card, 2, "L2sdmac");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100551 iob = qeth_get_ipacmd_buffer(card, ipacmd, QETH_PROT_IPV4);
552 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
553 cmd->data.setdelmac.mac_length = OSA_ADDR_LEN;
554 memcpy(&cmd->data.setdelmac.mac, mac, OSA_ADDR_LEN);
555 return qeth_send_ipa_cmd(card, iob, reply_cb, NULL);
556}
557
558static int qeth_l2_send_setmac_cb(struct qeth_card *card,
559 struct qeth_reply *reply,
560 unsigned long data)
561{
562 struct qeth_ipa_cmd *cmd;
563
Carsten Otte847a50f2010-06-21 22:57:05 +0000564 QETH_CARD_TEXT(card, 2, "L2Smaccb");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100565 cmd = (struct qeth_ipa_cmd *) data;
566 if (cmd->hdr.return_code) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000567 QETH_CARD_TEXT_(card, 2, "L2er%x", cmd->hdr.return_code);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100568 card->info.mac_bits &= ~QETH_LAYER2_MAC_REGISTERED;
Ursula Braun0666eb062009-05-19 21:38:39 +0000569 switch (cmd->hdr.return_code) {
570 case IPA_RC_L2_DUP_MAC:
571 case IPA_RC_L2_DUP_LAYER3_MAC:
572 dev_warn(&card->gdev->dev,
H Hartley Sweetend998ab02009-12-29 20:05:37 -0800573 "MAC address %pM already exists\n",
574 card->dev->dev_addr);
Ursula Braun0666eb062009-05-19 21:38:39 +0000575 break;
576 case IPA_RC_L2_MAC_NOT_AUTH_BY_HYP:
577 case IPA_RC_L2_MAC_NOT_AUTH_BY_ADP:
578 dev_warn(&card->gdev->dev,
H Hartley Sweetend998ab02009-12-29 20:05:37 -0800579 "MAC address %pM is not authorized\n",
580 card->dev->dev_addr);
Ursula Braun0666eb062009-05-19 21:38:39 +0000581 break;
582 default:
583 break;
584 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100585 cmd->hdr.return_code = -EIO;
586 } else {
587 card->info.mac_bits |= QETH_LAYER2_MAC_REGISTERED;
588 memcpy(card->dev->dev_addr, cmd->data.setdelmac.mac,
589 OSA_ADDR_LEN);
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100590 dev_info(&card->gdev->dev,
H Hartley Sweetend998ab02009-12-29 20:05:37 -0800591 "MAC address %pM successfully registered on device %s\n",
592 card->dev->dev_addr, card->dev->name);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100593 }
594 return 0;
595}
596
597static int qeth_l2_send_setmac(struct qeth_card *card, __u8 *mac)
598{
Carsten Otte847a50f2010-06-21 22:57:05 +0000599 QETH_CARD_TEXT(card, 2, "L2Setmac");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100600 return qeth_l2_send_setdelmac(card, mac, IPA_CMD_SETVMAC,
601 qeth_l2_send_setmac_cb);
602}
603
604static int qeth_l2_send_delmac_cb(struct qeth_card *card,
605 struct qeth_reply *reply,
606 unsigned long data)
607{
608 struct qeth_ipa_cmd *cmd;
609
Carsten Otte847a50f2010-06-21 22:57:05 +0000610 QETH_CARD_TEXT(card, 2, "L2Dmaccb");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100611 cmd = (struct qeth_ipa_cmd *) data;
612 if (cmd->hdr.return_code) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000613 QETH_CARD_TEXT_(card, 2, "err%d", cmd->hdr.return_code);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100614 cmd->hdr.return_code = -EIO;
615 return 0;
616 }
617 card->info.mac_bits &= ~QETH_LAYER2_MAC_REGISTERED;
618
619 return 0;
620}
621
622static int qeth_l2_send_delmac(struct qeth_card *card, __u8 *mac)
623{
Carsten Otte847a50f2010-06-21 22:57:05 +0000624 QETH_CARD_TEXT(card, 2, "L2Delmac");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100625 if (!(card->info.mac_bits & QETH_LAYER2_MAC_REGISTERED))
626 return 0;
627 return qeth_l2_send_setdelmac(card, mac, IPA_CMD_DELVMAC,
628 qeth_l2_send_delmac_cb);
629}
630
631static int qeth_l2_request_initial_mac(struct qeth_card *card)
632{
633 int rc = 0;
634 char vendor_pre[] = {0x02, 0x00, 0x00};
635
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200636 QETH_DBF_TEXT(SETUP, 2, "doL2init");
637 QETH_DBF_TEXT_(SETUP, 2, "doL2%s", CARD_BUS_ID(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100638
639 rc = qeth_query_setadapterparms(card);
640 if (rc) {
Frank Blaschka14cc21b2008-06-06 12:37:46 +0200641 QETH_DBF_MESSAGE(2, "could not query adapter parameters on "
642 "device %s: x%x\n", CARD_BUS_ID(card), rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100643 }
644
Ursula Braun5113fec2010-05-16 21:15:14 +0000645 if (card->info.type == QETH_CARD_TYPE_IQD ||
646 card->info.type == QETH_CARD_TYPE_OSM ||
647 card->info.type == QETH_CARD_TYPE_OSX ||
648 card->info.guestlan) {
Frank Blaschka4a71df52008-02-15 09:19:42 +0100649 rc = qeth_setadpparms_change_macaddr(card);
650 if (rc) {
Frank Blaschka14cc21b2008-06-06 12:37:46 +0200651 QETH_DBF_MESSAGE(2, "couldn't get MAC address on "
652 "device %s: x%x\n", CARD_BUS_ID(card), rc);
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200653 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100654 return rc;
655 }
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200656 QETH_DBF_HEX(SETUP, 2, card->dev->dev_addr, OSA_ADDR_LEN);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100657 } else {
658 random_ether_addr(card->dev->dev_addr);
659 memcpy(card->dev->dev_addr, vendor_pre, 3);
660 }
661 return 0;
662}
663
664static int qeth_l2_set_mac_address(struct net_device *dev, void *p)
665{
666 struct sockaddr *addr = p;
Heiko Carstens509e2562008-07-26 02:24:10 -0700667 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100668 int rc = 0;
669
Carsten Otte847a50f2010-06-21 22:57:05 +0000670 QETH_CARD_TEXT(card, 3, "setmac");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100671
672 if (qeth_l2_verify_dev(dev) != QETH_REAL_CARD) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000673 QETH_CARD_TEXT(card, 3, "setmcINV");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100674 return -EOPNOTSUPP;
675 }
676
Ursula Braun5113fec2010-05-16 21:15:14 +0000677 if (card->info.type == QETH_CARD_TYPE_OSN ||
678 card->info.type == QETH_CARD_TYPE_OSM ||
679 card->info.type == QETH_CARD_TYPE_OSX) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000680 QETH_CARD_TEXT(card, 3, "setmcTYP");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100681 return -EOPNOTSUPP;
682 }
Carsten Otte847a50f2010-06-21 22:57:05 +0000683 QETH_CARD_HEX(card, 3, addr->sa_data, OSA_ADDR_LEN);
Ursula Braun8e98ac42009-03-24 20:57:18 +0000684 if (qeth_wait_for_threads(card, QETH_RECOVER_THREAD)) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000685 QETH_CARD_TEXT(card, 3, "setmcREC");
Ursula Braun8e98ac42009-03-24 20:57:18 +0000686 return -ERESTARTSYS;
687 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100688 rc = qeth_l2_send_delmac(card, &card->dev->dev_addr[0]);
689 if (!rc)
690 rc = qeth_l2_send_setmac(card, addr->sa_data);
691 return rc;
692}
693
694static void qeth_l2_set_multicast_list(struct net_device *dev)
695{
Heiko Carstens509e2562008-07-26 02:24:10 -0700696 struct qeth_card *card = dev->ml_priv;
Jiri Pirkoccffad252009-05-22 23:22:17 +0000697 struct netdev_hw_addr *ha;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100698
699 if (card->info.type == QETH_CARD_TYPE_OSN)
700 return ;
701
Carsten Otte847a50f2010-06-21 22:57:05 +0000702 QETH_CARD_TEXT(card, 3, "setmulti");
Ursula Braun8e98ac42009-03-24 20:57:18 +0000703 if (qeth_threads_running(card, QETH_RECOVER_THREAD) &&
704 (card->state != CARD_STATE_UP))
705 return;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100706 qeth_l2_del_all_mc(card);
707 spin_lock_bh(&card->mclock);
Jiri Pirko22bedad32010-04-01 21:22:57 +0000708 netdev_for_each_mc_addr(ha, dev)
709 qeth_l2_add_mc(card, ha->addr, 0);
Frank Blaschka7db22662008-08-15 08:02:59 +0200710
Jiri Pirko32e7bfc2010-01-25 13:36:10 -0800711 netdev_for_each_uc_addr(ha, dev)
Jiri Pirkoccffad252009-05-22 23:22:17 +0000712 qeth_l2_add_mc(card, ha->addr, 1);
Frank Blaschka7db22662008-08-15 08:02:59 +0200713
Frank Blaschka4a71df52008-02-15 09:19:42 +0100714 spin_unlock_bh(&card->mclock);
715 if (!qeth_adp_supported(card, IPA_SETADP_SET_PROMISC_MODE))
716 return;
717 qeth_setadp_promisc_mode(card);
718}
719
720static int qeth_l2_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
721{
722 int rc;
723 struct qeth_hdr *hdr = NULL;
724 int elements = 0;
Heiko Carstens509e2562008-07-26 02:24:10 -0700725 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100726 struct sk_buff *new_skb = skb;
727 int ipv = qeth_get_ip_version(skb);
Klaus-Dieter Wackerce73e102009-08-26 02:01:08 +0000728 int cast_type = qeth_l2_get_cast_type(card, skb);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100729 struct qeth_qdio_out_q *queue = card->qdio.out_qs
730 [qeth_get_priority_queue(card, skb, ipv, cast_type)];
731 int tx_bytes = skb->len;
Frank Blaschka683d7182008-08-01 16:39:13 +0200732 int data_offset = -1;
733 int elements_needed = 0;
734 int hd_len = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100735
Frank Blaschka4a71df52008-02-15 09:19:42 +0100736 if ((card->state != CARD_STATE_UP) || !card->lan_online) {
737 card->stats.tx_carrier_errors++;
738 goto tx_drop;
739 }
740
741 if ((card->info.type == QETH_CARD_TYPE_OSN) &&
742 (skb->protocol == htons(ETH_P_IPV6)))
743 goto tx_drop;
744
745 if (card->options.performance_stats) {
746 card->perf_stats.outbound_cnt++;
747 card->perf_stats.outbound_start_time = qeth_get_micros();
748 }
749 netif_stop_queue(dev);
750
Frank Blaschka4a71df52008-02-15 09:19:42 +0100751 if (card->info.type == QETH_CARD_TYPE_OSN)
752 hdr = (struct qeth_hdr *)skb->data;
753 else {
Frank Blaschka64ef8952009-03-24 20:57:16 +0000754 if (card->info.type == QETH_CARD_TYPE_IQD) {
Frank Blaschka683d7182008-08-01 16:39:13 +0200755 new_skb = skb;
756 data_offset = ETH_HLEN;
757 hd_len = ETH_HLEN;
758 hdr = kmem_cache_alloc(qeth_core_header_cache,
759 GFP_ATOMIC);
760 if (!hdr)
761 goto tx_drop;
762 elements_needed++;
763 skb_reset_mac_header(new_skb);
764 qeth_l2_fill_header(card, hdr, new_skb, ipv, cast_type);
765 hdr->hdr.l2.pkt_length = new_skb->len;
766 memcpy(((char *)hdr) + sizeof(struct qeth_hdr),
767 skb_mac_header(new_skb), ETH_HLEN);
768 } else {
769 /* create a clone with writeable headroom */
770 new_skb = skb_realloc_headroom(skb,
Frank Blaschkaf90b7442008-04-24 10:15:24 +0200771 sizeof(struct qeth_hdr));
Frank Blaschka683d7182008-08-01 16:39:13 +0200772 if (!new_skb)
773 goto tx_drop;
774 hdr = (struct qeth_hdr *)skb_push(new_skb,
775 sizeof(struct qeth_hdr));
776 skb_set_mac_header(new_skb, sizeof(struct qeth_hdr));
777 qeth_l2_fill_header(card, hdr, new_skb, ipv, cast_type);
778 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100779 }
780
Frank Blaschka64ef8952009-03-24 20:57:16 +0000781 elements = qeth_get_elements_no(card, (void *)hdr, new_skb,
Frank Blaschka683d7182008-08-01 16:39:13 +0200782 elements_needed);
Frank Blaschka64ef8952009-03-24 20:57:16 +0000783 if (!elements) {
784 if (data_offset >= 0)
785 kmem_cache_free(qeth_core_header_cache, hdr);
786 goto tx_drop;
Frank Blaschkaf61a0d02009-03-24 20:57:15 +0000787 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100788
Frank Blaschka51aa1652010-06-21 22:57:10 +0000789 if (card->info.type != QETH_CARD_TYPE_IQD) {
790 if (qeth_hdr_chk_and_bounce(new_skb,
791 sizeof(struct qeth_hdr_layer2)))
792 goto tx_drop;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100793 rc = qeth_do_send_packet(card, queue, new_skb, hdr,
Frank Blaschka64ef8952009-03-24 20:57:16 +0000794 elements);
Frank Blaschka51aa1652010-06-21 22:57:10 +0000795 } else
Frank Blaschka4a71df52008-02-15 09:19:42 +0100796 rc = qeth_do_send_packet_fast(card, queue, new_skb, hdr,
Frank Blaschka64ef8952009-03-24 20:57:16 +0000797 elements, data_offset, hd_len);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100798 if (!rc) {
799 card->stats.tx_packets++;
800 card->stats.tx_bytes += tx_bytes;
801 if (new_skb != skb)
802 dev_kfree_skb_any(skb);
Patrick McHardyec634fe2009-07-05 19:23:38 -0700803 rc = NETDEV_TX_OK;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100804 } else {
Frank Blaschka683d7182008-08-01 16:39:13 +0200805 if (data_offset >= 0)
806 kmem_cache_free(qeth_core_header_cache, hdr);
807
Frank Blaschka4a71df52008-02-15 09:19:42 +0100808 if (rc == -EBUSY) {
809 if (new_skb != skb)
810 dev_kfree_skb_any(new_skb);
811 return NETDEV_TX_BUSY;
812 } else
813 goto tx_drop;
814 }
815
816 netif_wake_queue(dev);
817 if (card->options.performance_stats)
818 card->perf_stats.outbound_time += qeth_get_micros() -
819 card->perf_stats.outbound_start_time;
820 return rc;
821
822tx_drop:
823 card->stats.tx_dropped++;
824 card->stats.tx_errors++;
825 if ((new_skb != skb) && new_skb)
826 dev_kfree_skb_any(new_skb);
827 dev_kfree_skb_any(skb);
Frank Blaschkad0ec0f52008-06-06 12:37:48 +0200828 netif_wake_queue(dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100829 return NETDEV_TX_OK;
830}
831
Frank Blaschka4a71df52008-02-15 09:19:42 +0100832static int qeth_l2_open(struct net_device *dev)
833{
Heiko Carstens509e2562008-07-26 02:24:10 -0700834 struct qeth_card *card = dev->ml_priv;
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000835 int rc = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100836
Carsten Otte847a50f2010-06-21 22:57:05 +0000837 QETH_CARD_TEXT(card, 4, "qethopen");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100838 if (card->state != CARD_STATE_SOFTSETUP)
839 return -ENODEV;
840
841 if ((card->info.type != QETH_CARD_TYPE_OSN) &&
842 (!(card->info.mac_bits & QETH_LAYER2_MAC_REGISTERED))) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000843 QETH_CARD_TEXT(card, 4, "nomacadr");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100844 return -EPERM;
845 }
846 card->data.state = CH_STATE_UP;
847 card->state = CARD_STATE_UP;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100848 netif_start_queue(dev);
849
850 if (!card->lan_online && netif_carrier_ok(dev))
851 netif_carrier_off(dev);
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000852 if (qdio_stop_irq(card->data.ccwdev, 0) >= 0) {
853 napi_enable(&card->napi);
854 napi_schedule(&card->napi);
855 } else
856 rc = -EIO;
857 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100858}
859
Frank Blaschka4a71df52008-02-15 09:19:42 +0100860static int qeth_l2_stop(struct net_device *dev)
861{
Heiko Carstens509e2562008-07-26 02:24:10 -0700862 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100863
Carsten Otte847a50f2010-06-21 22:57:05 +0000864 QETH_CARD_TEXT(card, 4, "qethstop");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100865 netif_tx_disable(dev);
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000866 if (card->state == CARD_STATE_UP) {
Frank Blaschka4a71df52008-02-15 09:19:42 +0100867 card->state = CARD_STATE_SOFTSETUP;
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000868 napi_disable(&card->napi);
869 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100870 return 0;
871}
872
873static int qeth_l2_probe_device(struct ccwgroup_device *gdev)
874{
875 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
876
877 INIT_LIST_HEAD(&card->vid_list);
878 INIT_LIST_HEAD(&card->mc_list);
879 card->options.layer2 = 1;
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000880 card->discipline.start_poll = qeth_qdio_start_poll;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100881 card->discipline.input_handler = (qdio_handler_t *)
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000882 qeth_qdio_input_handler;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100883 card->discipline.output_handler = (qdio_handler_t *)
884 qeth_qdio_output_handler;
885 card->discipline.recover = qeth_l2_recover;
886 return 0;
887}
888
889static void qeth_l2_remove_device(struct ccwgroup_device *cgdev)
890{
891 struct qeth_card *card = dev_get_drvdata(&cgdev->dev);
892
Ursula Braunf2148562009-05-19 21:38:37 +0000893 qeth_set_allowed_threads(card, 0, 1);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100894 wait_event(card->wait_q, qeth_threads_running(card, 0xffffffff) == 0);
895
896 if (cgdev->state == CCWGROUP_ONLINE) {
897 card->use_hard_stop = 1;
898 qeth_l2_set_offline(cgdev);
899 }
900
901 if (card->dev) {
902 unregister_netdev(card->dev);
903 card->dev = NULL;
904 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100905 return;
906}
907
Stephen Hemminger0fc0b732009-09-02 01:03:33 -0700908static const struct ethtool_ops qeth_l2_ethtool_ops = {
Frank Blaschka4a71df52008-02-15 09:19:42 +0100909 .get_link = ethtool_op_get_link,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100910 .get_strings = qeth_core_get_strings,
911 .get_ethtool_stats = qeth_core_get_ethtool_stats,
Ben Hutchingsdf8b4ec2009-10-01 11:24:32 +0000912 .get_sset_count = qeth_core_get_sset_count,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100913 .get_drvinfo = qeth_core_get_drvinfo,
Frank Blaschka3f9975a2008-04-24 10:15:23 +0200914 .get_settings = qeth_core_ethtool_get_settings,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100915};
916
Stephen Hemminger0fc0b732009-09-02 01:03:33 -0700917static const struct ethtool_ops qeth_l2_osn_ops = {
Frank Blaschka4a71df52008-02-15 09:19:42 +0100918 .get_strings = qeth_core_get_strings,
919 .get_ethtool_stats = qeth_core_get_ethtool_stats,
Ben Hutchingsdf8b4ec2009-10-01 11:24:32 +0000920 .get_sset_count = qeth_core_get_sset_count,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100921 .get_drvinfo = qeth_core_get_drvinfo,
922};
923
Frank Blaschka3d58cef2009-01-09 03:44:00 +0000924static const struct net_device_ops qeth_l2_netdev_ops = {
Frank Blaschka8403b132009-01-08 10:50:55 -0800925 .ndo_open = qeth_l2_open,
926 .ndo_stop = qeth_l2_stop,
927 .ndo_get_stats = qeth_get_stats,
928 .ndo_start_xmit = qeth_l2_hard_start_xmit,
929 .ndo_validate_addr = eth_validate_addr,
930 .ndo_set_multicast_list = qeth_l2_set_multicast_list,
931 .ndo_do_ioctl = qeth_l2_do_ioctl,
932 .ndo_set_mac_address = qeth_l2_set_mac_address,
933 .ndo_change_mtu = qeth_change_mtu,
934 .ndo_vlan_rx_add_vid = qeth_l2_vlan_rx_add_vid,
935 .ndo_vlan_rx_kill_vid = qeth_l2_vlan_rx_kill_vid,
936 .ndo_tx_timeout = qeth_tx_timeout,
937};
938
Frank Blaschka4a71df52008-02-15 09:19:42 +0100939static int qeth_l2_setup_netdev(struct qeth_card *card)
940{
941 switch (card->info.type) {
Frank Blaschka4a71df52008-02-15 09:19:42 +0100942 case QETH_CARD_TYPE_IQD:
943 card->dev = alloc_netdev(0, "hsi%d", ether_setup);
944 break;
945 case QETH_CARD_TYPE_OSN:
946 card->dev = alloc_netdev(0, "osn%d", ether_setup);
947 card->dev->flags |= IFF_NOARP;
948 break;
949 default:
950 card->dev = alloc_etherdev(0);
951 }
952
953 if (!card->dev)
954 return -ENODEV;
955
Heiko Carstens509e2562008-07-26 02:24:10 -0700956 card->dev->ml_priv = card;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100957 card->dev->watchdog_timeo = QETH_TX_TIMEOUT;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100958 card->dev->mtu = card->info.initial_mtu;
Frank Blaschka8403b132009-01-08 10:50:55 -0800959 card->dev->netdev_ops = &qeth_l2_netdev_ops;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100960 if (card->info.type != QETH_CARD_TYPE_OSN)
961 SET_ETHTOOL_OPS(card->dev, &qeth_l2_ethtool_ops);
962 else
963 SET_ETHTOOL_OPS(card->dev, &qeth_l2_osn_ops);
964 card->dev->features |= NETIF_F_HW_VLAN_FILTER;
965 card->info.broadcast_capable = 1;
966 qeth_l2_request_initial_mac(card);
967 SET_NETDEV_DEV(card->dev, &card->gdev->dev);
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000968 netif_napi_add(card->dev, &card->napi, qeth_l2_poll, QETH_NAPI_WEIGHT);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100969 return register_netdev(card->dev);
970}
971
972static int __qeth_l2_set_online(struct ccwgroup_device *gdev, int recovery_mode)
973{
974 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
975 int rc = 0;
976 enum qeth_card_states recover_flag;
977
978 BUG_ON(!card);
Ursula Braun9dc48cc2010-07-22 23:15:05 +0000979 mutex_lock(&card->discipline_mutex);
Frank Blaschkac4949f02010-05-11 19:34:47 +0000980 mutex_lock(&card->conf_mutex);
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200981 QETH_DBF_TEXT(SETUP, 2, "setonlin");
982 QETH_DBF_HEX(SETUP, 2, &card, sizeof(void *));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100983
Frank Blaschka4a71df52008-02-15 09:19:42 +0100984 recover_flag = card->state;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100985 rc = qeth_core_hardsetup_card(card);
986 if (rc) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200987 QETH_DBF_TEXT_(SETUP, 2, "2err%d", rc);
Ursula Braunaa909222009-11-12 00:11:43 +0000988 rc = -ENODEV;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100989 goto out_remove;
990 }
991
Ursula Braunaa909222009-11-12 00:11:43 +0000992 if (!card->dev && qeth_l2_setup_netdev(card)) {
993 rc = -ENODEV;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100994 goto out_remove;
Ursula Braunaa909222009-11-12 00:11:43 +0000995 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100996
997 if (card->info.type != QETH_CARD_TYPE_OSN)
998 qeth_l2_send_setmac(card, &card->dev->dev_addr[0]);
999
1000 card->state = CARD_STATE_HARDSETUP;
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00001001 memset(&card->rx, 0, sizeof(struct qeth_rx));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001002 qeth_print_status_message(card);
1003
1004 /* softsetup */
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001005 QETH_DBF_TEXT(SETUP, 2, "softsetp");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001006
1007 rc = qeth_send_startlan(card);
1008 if (rc) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001009 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001010 if (rc == 0xe080) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001011 dev_warn(&card->gdev->dev,
1012 "The LAN is offline\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001013 card->lan_online = 0;
Frank Blaschkac4949f02010-05-11 19:34:47 +00001014 goto out;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001015 }
Ursula Braunaa909222009-11-12 00:11:43 +00001016 rc = -ENODEV;
Ursula Braunf2148562009-05-19 21:38:37 +00001017 goto out_remove;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001018 } else
1019 card->lan_online = 1;
1020
Ursula Braun5113fec2010-05-16 21:15:14 +00001021 if ((card->info.type == QETH_CARD_TYPE_OSD) ||
1022 (card->info.type == QETH_CARD_TYPE_OSX))
Einar Lueckd64ecc22009-11-12 00:11:41 +00001023 /* configure isolation level */
1024 qeth_set_access_ctrl_online(card);
Ursula Braun5113fec2010-05-16 21:15:14 +00001025
1026 if (card->info.type != QETH_CARD_TYPE_OSN &&
1027 card->info.type != QETH_CARD_TYPE_OSM)
Frank Blaschka4a71df52008-02-15 09:19:42 +01001028 qeth_l2_process_vlans(card, 0);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001029
1030 netif_tx_disable(card->dev);
1031
1032 rc = qeth_init_qdio_queues(card);
1033 if (rc) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001034 QETH_DBF_TEXT_(SETUP, 2, "6err%d", rc);
Ursula Braunaa909222009-11-12 00:11:43 +00001035 rc = -ENODEV;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001036 goto out_remove;
1037 }
1038 card->state = CARD_STATE_SOFTSETUP;
1039 netif_carrier_on(card->dev);
1040
1041 qeth_set_allowed_threads(card, 0xffffffff, 0);
1042 if (recover_flag == CARD_STATE_RECOVER) {
1043 if (recovery_mode &&
1044 card->info.type != QETH_CARD_TYPE_OSN) {
1045 qeth_l2_open(card->dev);
1046 } else {
1047 rtnl_lock();
1048 dev_open(card->dev);
1049 rtnl_unlock();
1050 }
1051 /* this also sets saved unicast addresses */
1052 qeth_l2_set_multicast_list(card->dev);
1053 }
1054 /* let user_space know that device is online */
1055 kobject_uevent(&gdev->dev.kobj, KOBJ_CHANGE);
Frank Blaschkac4949f02010-05-11 19:34:47 +00001056out:
1057 mutex_unlock(&card->conf_mutex);
Ursula Braun9dc48cc2010-07-22 23:15:05 +00001058 mutex_unlock(&card->discipline_mutex);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001059 return 0;
Ursula Braunaa909222009-11-12 00:11:43 +00001060
Frank Blaschka4a71df52008-02-15 09:19:42 +01001061out_remove:
1062 card->use_hard_stop = 1;
1063 qeth_l2_stop_card(card, 0);
1064 ccw_device_set_offline(CARD_DDEV(card));
1065 ccw_device_set_offline(CARD_WDEV(card));
1066 ccw_device_set_offline(CARD_RDEV(card));
1067 if (recover_flag == CARD_STATE_RECOVER)
1068 card->state = CARD_STATE_RECOVER;
1069 else
1070 card->state = CARD_STATE_DOWN;
Frank Blaschkac4949f02010-05-11 19:34:47 +00001071 mutex_unlock(&card->conf_mutex);
Ursula Braun9dc48cc2010-07-22 23:15:05 +00001072 mutex_unlock(&card->discipline_mutex);
Ursula Braunaa909222009-11-12 00:11:43 +00001073 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001074}
1075
1076static int qeth_l2_set_online(struct ccwgroup_device *gdev)
1077{
1078 return __qeth_l2_set_online(gdev, 0);
1079}
1080
1081static int __qeth_l2_set_offline(struct ccwgroup_device *cgdev,
1082 int recovery_mode)
1083{
1084 struct qeth_card *card = dev_get_drvdata(&cgdev->dev);
1085 int rc = 0, rc2 = 0, rc3 = 0;
1086 enum qeth_card_states recover_flag;
1087
Ursula Braun9dc48cc2010-07-22 23:15:05 +00001088 mutex_lock(&card->discipline_mutex);
Frank Blaschkac4949f02010-05-11 19:34:47 +00001089 mutex_lock(&card->conf_mutex);
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001090 QETH_DBF_TEXT(SETUP, 3, "setoffl");
1091 QETH_DBF_HEX(SETUP, 3, &card, sizeof(void *));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001092
1093 if (card->dev && netif_carrier_ok(card->dev))
1094 netif_carrier_off(card->dev);
1095 recover_flag = card->state;
Ursula Braun0f5623c2008-10-24 11:16:52 +02001096 qeth_l2_stop_card(card, recovery_mode);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001097 rc = ccw_device_set_offline(CARD_DDEV(card));
1098 rc2 = ccw_device_set_offline(CARD_WDEV(card));
1099 rc3 = ccw_device_set_offline(CARD_RDEV(card));
1100 if (!rc)
1101 rc = (rc2) ? rc2 : rc3;
1102 if (rc)
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001103 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001104 if (recover_flag == CARD_STATE_UP)
1105 card->state = CARD_STATE_RECOVER;
1106 /* let user_space know that device is offline */
1107 kobject_uevent(&cgdev->dev.kobj, KOBJ_CHANGE);
Frank Blaschkac4949f02010-05-11 19:34:47 +00001108 mutex_unlock(&card->conf_mutex);
Ursula Braun9dc48cc2010-07-22 23:15:05 +00001109 mutex_unlock(&card->discipline_mutex);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001110 return 0;
1111}
1112
1113static int qeth_l2_set_offline(struct ccwgroup_device *cgdev)
1114{
1115 return __qeth_l2_set_offline(cgdev, 0);
1116}
1117
1118static int qeth_l2_recover(void *ptr)
1119{
1120 struct qeth_card *card;
1121 int rc = 0;
1122
1123 card = (struct qeth_card *) ptr;
Carsten Otte847a50f2010-06-21 22:57:05 +00001124 QETH_CARD_TEXT(card, 2, "recover1");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001125 if (!qeth_do_run_thread(card, QETH_RECOVER_THREAD))
1126 return 0;
Carsten Otte847a50f2010-06-21 22:57:05 +00001127 QETH_CARD_TEXT(card, 2, "recover2");
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001128 dev_warn(&card->gdev->dev,
1129 "A recovery process has been started for the device\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001130 card->use_hard_stop = 1;
1131 __qeth_l2_set_offline(card->gdev, 1);
1132 rc = __qeth_l2_set_online(card->gdev, 1);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001133 if (!rc)
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001134 dev_info(&card->gdev->dev,
1135 "Device successfully recovered!\n");
Ursula Braun28a7e4c2008-09-19 12:56:03 +02001136 else {
Ursula Braun869da902010-03-08 20:36:56 +00001137 rtnl_lock();
1138 dev_close(card->dev);
1139 rtnl_unlock();
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001140 dev_warn(&card->gdev->dev, "The qeth device driver "
1141 "failed to recover an error on the device\n");
Ursula Braun28a7e4c2008-09-19 12:56:03 +02001142 }
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00001143 qeth_clear_thread_start_bit(card, QETH_RECOVER_THREAD);
1144 qeth_clear_thread_running_bit(card, QETH_RECOVER_THREAD);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001145 return 0;
1146}
1147
1148static int __init qeth_l2_init(void)
1149{
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001150 pr_info("register layer 2 discipline\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001151 return 0;
1152}
1153
1154static void __exit qeth_l2_exit(void)
1155{
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001156 pr_info("unregister layer 2 discipline\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001157}
1158
1159static void qeth_l2_shutdown(struct ccwgroup_device *gdev)
1160{
1161 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
1162 qeth_qdio_clear_card(card, 0);
1163 qeth_clear_qdio_buffers(card);
1164}
1165
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02001166static int qeth_l2_pm_suspend(struct ccwgroup_device *gdev)
1167{
1168 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
1169
1170 if (card->dev)
1171 netif_device_detach(card->dev);
1172 qeth_set_allowed_threads(card, 0, 1);
1173 wait_event(card->wait_q, qeth_threads_running(card, 0xffffffff) == 0);
1174 if (gdev->state == CCWGROUP_OFFLINE)
1175 return 0;
1176 if (card->state == CARD_STATE_UP) {
1177 card->use_hard_stop = 1;
1178 __qeth_l2_set_offline(card->gdev, 1);
1179 } else
1180 __qeth_l2_set_offline(card->gdev, 0);
1181 return 0;
1182}
1183
1184static int qeth_l2_pm_resume(struct ccwgroup_device *gdev)
1185{
1186 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
1187 int rc = 0;
1188
1189 if (gdev->state == CCWGROUP_OFFLINE)
1190 goto out;
1191
1192 if (card->state == CARD_STATE_RECOVER) {
1193 rc = __qeth_l2_set_online(card->gdev, 1);
1194 if (rc) {
Ursula Braun869da902010-03-08 20:36:56 +00001195 rtnl_lock();
1196 dev_close(card->dev);
1197 rtnl_unlock();
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02001198 }
1199 } else
1200 rc = __qeth_l2_set_online(card->gdev, 0);
1201out:
1202 qeth_set_allowed_threads(card, 0xffffffff, 0);
1203 if (card->dev)
1204 netif_device_attach(card->dev);
1205 if (rc)
1206 dev_warn(&card->gdev->dev, "The qeth device driver "
1207 "failed to recover an error on the device\n");
1208 return rc;
1209}
1210
Frank Blaschka4a71df52008-02-15 09:19:42 +01001211struct ccwgroup_driver qeth_l2_ccwgroup_driver = {
1212 .probe = qeth_l2_probe_device,
1213 .remove = qeth_l2_remove_device,
1214 .set_online = qeth_l2_set_online,
1215 .set_offline = qeth_l2_set_offline,
1216 .shutdown = qeth_l2_shutdown,
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02001217 .freeze = qeth_l2_pm_suspend,
1218 .thaw = qeth_l2_pm_resume,
1219 .restore = qeth_l2_pm_resume,
Frank Blaschka4a71df52008-02-15 09:19:42 +01001220};
1221EXPORT_SYMBOL_GPL(qeth_l2_ccwgroup_driver);
1222
1223static int qeth_osn_send_control_data(struct qeth_card *card, int len,
1224 struct qeth_cmd_buffer *iob)
1225{
1226 unsigned long flags;
1227 int rc = 0;
1228
Carsten Otte847a50f2010-06-21 22:57:05 +00001229 QETH_CARD_TEXT(card, 5, "osndctrd");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001230
1231 wait_event(card->wait_q,
1232 atomic_cmpxchg(&card->write.irq_pending, 0, 1) == 0);
1233 qeth_prepare_control_data(card, len, iob);
Carsten Otte847a50f2010-06-21 22:57:05 +00001234 QETH_CARD_TEXT(card, 6, "osnoirqp");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001235 spin_lock_irqsave(get_ccwdev_lock(card->write.ccwdev), flags);
1236 rc = ccw_device_start(card->write.ccwdev, &card->write.ccw,
1237 (addr_t) iob, 0, 0);
1238 spin_unlock_irqrestore(get_ccwdev_lock(card->write.ccwdev), flags);
1239 if (rc) {
Frank Blaschka14cc21b2008-06-06 12:37:46 +02001240 QETH_DBF_MESSAGE(2, "qeth_osn_send_control_data: "
Frank Blaschka4a71df52008-02-15 09:19:42 +01001241 "ccw_device_start rc = %i\n", rc);
Carsten Otte847a50f2010-06-21 22:57:05 +00001242 QETH_CARD_TEXT_(card, 2, " err%d", rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001243 qeth_release_buffer(iob->channel, iob);
1244 atomic_set(&card->write.irq_pending, 0);
1245 wake_up(&card->wait_q);
1246 }
1247 return rc;
1248}
1249
1250static int qeth_osn_send_ipa_cmd(struct qeth_card *card,
1251 struct qeth_cmd_buffer *iob, int data_len)
1252{
1253 u16 s1, s2;
1254
Carsten Otte847a50f2010-06-21 22:57:05 +00001255 QETH_CARD_TEXT(card, 4, "osndipa");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001256
1257 qeth_prepare_ipa_cmd(card, iob, QETH_PROT_OSN2);
1258 s1 = (u16)(IPA_PDU_HEADER_SIZE + data_len);
1259 s2 = (u16)data_len;
1260 memcpy(QETH_IPA_PDU_LEN_TOTAL(iob->data), &s1, 2);
1261 memcpy(QETH_IPA_PDU_LEN_PDU1(iob->data), &s2, 2);
1262 memcpy(QETH_IPA_PDU_LEN_PDU2(iob->data), &s2, 2);
1263 memcpy(QETH_IPA_PDU_LEN_PDU3(iob->data), &s2, 2);
1264 return qeth_osn_send_control_data(card, s1, iob);
1265}
1266
1267int qeth_osn_assist(struct net_device *dev, void *data, int data_len)
1268{
1269 struct qeth_cmd_buffer *iob;
1270 struct qeth_card *card;
1271 int rc;
1272
Frank Blaschka4a71df52008-02-15 09:19:42 +01001273 if (!dev)
1274 return -ENODEV;
Heiko Carstens509e2562008-07-26 02:24:10 -07001275 card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001276 if (!card)
1277 return -ENODEV;
Carsten Otte847a50f2010-06-21 22:57:05 +00001278 QETH_CARD_TEXT(card, 2, "osnsdmc");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001279 if ((card->state != CARD_STATE_UP) &&
1280 (card->state != CARD_STATE_SOFTSETUP))
1281 return -ENODEV;
1282 iob = qeth_wait_for_buffer(&card->write);
1283 memcpy(iob->data+IPA_PDU_HEADER_SIZE, data, data_len);
1284 rc = qeth_osn_send_ipa_cmd(card, iob, data_len);
1285 return rc;
1286}
1287EXPORT_SYMBOL(qeth_osn_assist);
1288
1289int qeth_osn_register(unsigned char *read_dev_no, struct net_device **dev,
1290 int (*assist_cb)(struct net_device *, void *),
1291 int (*data_cb)(struct sk_buff *))
1292{
1293 struct qeth_card *card;
1294
Frank Blaschka4a71df52008-02-15 09:19:42 +01001295 *dev = qeth_l2_netdev_by_devno(read_dev_no);
1296 if (*dev == NULL)
1297 return -ENODEV;
Heiko Carstens509e2562008-07-26 02:24:10 -07001298 card = (*dev)->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001299 if (!card)
1300 return -ENODEV;
Carsten Otte847a50f2010-06-21 22:57:05 +00001301 QETH_CARD_TEXT(card, 2, "osnreg");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001302 if ((assist_cb == NULL) || (data_cb == NULL))
1303 return -EINVAL;
1304 card->osn_info.assist_cb = assist_cb;
1305 card->osn_info.data_cb = data_cb;
1306 return 0;
1307}
1308EXPORT_SYMBOL(qeth_osn_register);
1309
1310void qeth_osn_deregister(struct net_device *dev)
1311{
1312 struct qeth_card *card;
1313
Frank Blaschka4a71df52008-02-15 09:19:42 +01001314 if (!dev)
1315 return;
Heiko Carstens509e2562008-07-26 02:24:10 -07001316 card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001317 if (!card)
1318 return;
Carsten Otte847a50f2010-06-21 22:57:05 +00001319 QETH_CARD_TEXT(card, 2, "osndereg");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001320 card->osn_info.assist_cb = NULL;
1321 card->osn_info.data_cb = NULL;
1322 return;
1323}
1324EXPORT_SYMBOL(qeth_osn_deregister);
1325
1326module_init(qeth_l2_init);
1327module_exit(qeth_l2_exit);
1328MODULE_AUTHOR("Frank Blaschka <frank.blaschka@de.ibm.com>");
1329MODULE_DESCRIPTION("qeth layer 2 discipline");
1330MODULE_LICENSE("GPL");