blob: 0e7c29d1d7efc5991904a5d54f906a56086d244c [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;
Frank Blaschkac3ab96f2012-02-08 00:19:49 +000078 case SIOC_QETH_QUERY_OAT:
79 rc = qeth_query_oat_command(card, rq->ifr_ifru.ifru_data);
80 break;
Frank Blaschka4a71df52008-02-15 09:19:42 +010081 default:
82 rc = -EOPNOTSUPP;
83 }
84 if (rc)
Carsten Otte847a50f2010-06-21 22:57:05 +000085 QETH_CARD_TEXT_(card, 2, "ioce%d", rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +010086 return rc;
87}
88
89static int qeth_l2_verify_dev(struct net_device *dev)
90{
91 struct qeth_card *card;
92 unsigned long flags;
93 int rc = 0;
94
95 read_lock_irqsave(&qeth_core_card_list.rwlock, flags);
96 list_for_each_entry(card, &qeth_core_card_list.list, list) {
97 if (card->dev == dev) {
98 rc = QETH_REAL_CARD;
99 break;
100 }
101 }
102 read_unlock_irqrestore(&qeth_core_card_list.rwlock, flags);
103
104 return rc;
105}
106
107static struct net_device *qeth_l2_netdev_by_devno(unsigned char *read_dev_no)
108{
109 struct qeth_card *card;
110 struct net_device *ndev;
Cornelia Huckf06f6f32008-06-06 12:37:45 +0200111 __u16 temp_dev_no;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100112 unsigned long flags;
Cornelia Huckf06f6f32008-06-06 12:37:45 +0200113 struct ccw_dev_id read_devid;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100114
115 ndev = NULL;
116 memcpy(&temp_dev_no, read_dev_no, 2);
117 read_lock_irqsave(&qeth_core_card_list.rwlock, flags);
118 list_for_each_entry(card, &qeth_core_card_list.list, list) {
Cornelia Huckf06f6f32008-06-06 12:37:45 +0200119 ccw_device_get_id(CARD_RDEV(card), &read_devid);
120 if (read_devid.devno == temp_dev_no) {
Frank Blaschka4a71df52008-02-15 09:19:42 +0100121 ndev = card->dev;
122 break;
123 }
124 }
125 read_unlock_irqrestore(&qeth_core_card_list.rwlock, flags);
126 return ndev;
127}
128
129static int qeth_l2_send_setgroupmac_cb(struct qeth_card *card,
130 struct qeth_reply *reply,
131 unsigned long data)
132{
133 struct qeth_ipa_cmd *cmd;
134 __u8 *mac;
135
Carsten Otte847a50f2010-06-21 22:57:05 +0000136 QETH_CARD_TEXT(card, 2, "L2Sgmacb");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100137 cmd = (struct qeth_ipa_cmd *) data;
138 mac = &cmd->data.setdelmac.mac[0];
139 /* MAC already registered, needed in couple/uncouple case */
Ursula Braun0666eb062009-05-19 21:38:39 +0000140 if (cmd->hdr.return_code == IPA_RC_L2_DUP_MAC) {
Johannes Berg7c510e42008-10-27 17:47:26 -0700141 QETH_DBF_MESSAGE(2, "Group MAC %pM already existing on %s \n",
142 mac, QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100143 cmd->hdr.return_code = 0;
144 }
145 if (cmd->hdr.return_code)
Johannes Berg7c510e42008-10-27 17:47:26 -0700146 QETH_DBF_MESSAGE(2, "Could not set group MAC %pM on %s: %x\n",
147 mac, QETH_CARD_IFNAME(card), cmd->hdr.return_code);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100148 return 0;
149}
150
151static int qeth_l2_send_setgroupmac(struct qeth_card *card, __u8 *mac)
152{
Carsten Otte847a50f2010-06-21 22:57:05 +0000153 QETH_CARD_TEXT(card, 2, "L2Sgmac");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100154 return qeth_l2_send_setdelmac(card, mac, IPA_CMD_SETGMAC,
155 qeth_l2_send_setgroupmac_cb);
156}
157
158static int qeth_l2_send_delgroupmac_cb(struct qeth_card *card,
159 struct qeth_reply *reply,
160 unsigned long data)
161{
162 struct qeth_ipa_cmd *cmd;
163 __u8 *mac;
164
Carsten Otte847a50f2010-06-21 22:57:05 +0000165 QETH_CARD_TEXT(card, 2, "L2Dgmacb");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100166 cmd = (struct qeth_ipa_cmd *) data;
167 mac = &cmd->data.setdelmac.mac[0];
168 if (cmd->hdr.return_code)
Johannes Berg7c510e42008-10-27 17:47:26 -0700169 QETH_DBF_MESSAGE(2, "Could not delete group MAC %pM on %s: %x\n",
170 mac, QETH_CARD_IFNAME(card), cmd->hdr.return_code);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100171 return 0;
172}
173
174static int qeth_l2_send_delgroupmac(struct qeth_card *card, __u8 *mac)
175{
Carsten Otte847a50f2010-06-21 22:57:05 +0000176 QETH_CARD_TEXT(card, 2, "L2Dgmac");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100177 return qeth_l2_send_setdelmac(card, mac, IPA_CMD_DELGMAC,
178 qeth_l2_send_delgroupmac_cb);
179}
180
Frank Blaschka7db22662008-08-15 08:02:59 +0200181static void qeth_l2_add_mc(struct qeth_card *card, __u8 *mac, int vmac)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100182{
183 struct qeth_mc_mac *mc;
Frank Blaschka7db22662008-08-15 08:02:59 +0200184 int rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100185
186 mc = kmalloc(sizeof(struct qeth_mc_mac), GFP_ATOMIC);
187
Frank Blaschka14cc21b2008-06-06 12:37:46 +0200188 if (!mc)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100189 return;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100190
191 memcpy(mc->mc_addr, mac, OSA_ADDR_LEN);
192 mc->mc_addrlen = OSA_ADDR_LEN;
Frank Blaschka7db22662008-08-15 08:02:59 +0200193 mc->is_vmac = vmac;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100194
Frank Blaschka7db22662008-08-15 08:02:59 +0200195 if (vmac) {
196 rc = qeth_l2_send_setdelmac(card, mac, IPA_CMD_SETVMAC,
197 NULL);
198 } else {
199 rc = qeth_l2_send_setgroupmac(card, mac);
200 }
201
202 if (!rc)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100203 list_add_tail(&mc->list, &card->mc_list);
204 else
205 kfree(mc);
206}
207
Ursula Braun70919e22011-02-26 22:41:36 -0800208static void qeth_l2_del_all_mc(struct qeth_card *card, int del)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100209{
210 struct qeth_mc_mac *mc, *tmp;
211
212 spin_lock_bh(&card->mclock);
213 list_for_each_entry_safe(mc, tmp, &card->mc_list, list) {
Ursula Braun70919e22011-02-26 22:41:36 -0800214 if (del) {
215 if (mc->is_vmac)
216 qeth_l2_send_setdelmac(card, mc->mc_addr,
Frank Blaschka7db22662008-08-15 08:02:59 +0200217 IPA_CMD_DELVMAC, NULL);
Ursula Braun70919e22011-02-26 22:41:36 -0800218 else
219 qeth_l2_send_delgroupmac(card, mc->mc_addr);
220 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100221 list_del(&mc->list);
222 kfree(mc);
223 }
224 spin_unlock_bh(&card->mclock);
225}
226
Klaus-Dieter Wackerce73e102009-08-26 02:01:08 +0000227static inline int qeth_l2_get_cast_type(struct qeth_card *card,
228 struct sk_buff *skb)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100229{
Klaus-Dieter Wackerce73e102009-08-26 02:01:08 +0000230 if (card->info.type == QETH_CARD_TYPE_OSN)
231 return RTN_UNSPEC;
232 if (is_broadcast_ether_addr(skb->data))
233 return RTN_BROADCAST;
234 if (is_multicast_ether_addr(skb->data))
235 return RTN_MULTICAST;
236 return RTN_UNSPEC;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100237}
238
239static void qeth_l2_fill_header(struct qeth_card *card, struct qeth_hdr *hdr,
240 struct sk_buff *skb, int ipv, int cast_type)
241{
Frank Blaschka683d7182008-08-01 16:39:13 +0200242 struct vlan_ethhdr *veth = (struct vlan_ethhdr *)skb_mac_header(skb);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100243
244 memset(hdr, 0, sizeof(struct qeth_hdr));
245 hdr->hdr.l2.id = QETH_HEADER_TYPE_LAYER2;
246
247 /* set byte byte 3 to casting flags */
248 if (cast_type == RTN_MULTICAST)
249 hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_MULTICAST;
250 else if (cast_type == RTN_BROADCAST)
251 hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_BROADCAST;
252 else
Klaus-Dieter Wackerce73e102009-08-26 02:01:08 +0000253 hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_UNICAST;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100254
255 hdr->hdr.l2.pkt_length = skb->len-QETH_HEADER_SIZE;
256 /* VSWITCH relies on the VLAN
257 * information to be present in
258 * the QDIO header */
259 if (veth->h_vlan_proto == __constant_htons(ETH_P_8021Q)) {
260 hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_VLAN;
261 hdr->hdr.l2.vlan_id = ntohs(veth->h_vlan_TCI);
262 }
263}
264
265static int qeth_l2_send_setdelvlan_cb(struct qeth_card *card,
266 struct qeth_reply *reply, unsigned long data)
267{
268 struct qeth_ipa_cmd *cmd;
269
Carsten Otte847a50f2010-06-21 22:57:05 +0000270 QETH_CARD_TEXT(card, 2, "L2sdvcb");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100271 cmd = (struct qeth_ipa_cmd *) data;
272 if (cmd->hdr.return_code) {
Frank Blaschka14cc21b2008-06-06 12:37:46 +0200273 QETH_DBF_MESSAGE(2, "Error in processing VLAN %i on %s: 0x%x. "
Frank Blaschka4a71df52008-02-15 09:19:42 +0100274 "Continuing\n", cmd->data.setdelvlan.vlan_id,
275 QETH_CARD_IFNAME(card), cmd->hdr.return_code);
Carsten Otte847a50f2010-06-21 22:57:05 +0000276 QETH_CARD_TEXT_(card, 2, "L2VL%4x", cmd->hdr.command);
277 QETH_CARD_TEXT_(card, 2, "err%d", cmd->hdr.return_code);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100278 }
279 return 0;
280}
281
282static int qeth_l2_send_setdelvlan(struct qeth_card *card, __u16 i,
283 enum qeth_ipa_cmds ipacmd)
284{
285 struct qeth_ipa_cmd *cmd;
286 struct qeth_cmd_buffer *iob;
287
Carsten Otte847a50f2010-06-21 22:57:05 +0000288 QETH_CARD_TEXT_(card, 4, "L2sdv%x", ipacmd);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100289 iob = qeth_get_ipacmd_buffer(card, ipacmd, QETH_PROT_IPV4);
290 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
291 cmd->data.setdelvlan.vlan_id = i;
292 return qeth_send_ipa_cmd(card, iob,
293 qeth_l2_send_setdelvlan_cb, NULL);
294}
295
Ursula Braun70919e22011-02-26 22:41:36 -0800296static void qeth_l2_process_vlans(struct qeth_card *card)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100297{
298 struct qeth_vlan_vid *id;
Carsten Otte847a50f2010-06-21 22:57:05 +0000299 QETH_CARD_TEXT(card, 3, "L2prcvln");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100300 spin_lock_bh(&card->vlanlock);
301 list_for_each_entry(id, &card->vid_list, list) {
Ursula Braun70919e22011-02-26 22:41:36 -0800302 qeth_l2_send_setdelvlan(card, id->vid, IPA_CMD_SETVLAN);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100303 }
304 spin_unlock_bh(&card->vlanlock);
305}
306
Jiri Pirko8e586132011-12-08 19:52:37 -0500307static int qeth_l2_vlan_rx_add_vid(struct net_device *dev, unsigned short vid)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100308{
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 Braun10651db2010-10-01 02:51:13 +0000313 if (!vid)
Jiri Pirko8e586132011-12-08 19:52:37 -0500314 return 0;
Ursula Braun5113fec2010-05-16 21:15:14 +0000315 if (card->info.type == QETH_CARD_TYPE_OSM) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000316 QETH_CARD_TEXT(card, 3, "aidOSM");
Jiri Pirko8e586132011-12-08 19:52:37 -0500317 return 0;
Ursula Braun5113fec2010-05-16 21:15:14 +0000318 }
Ursula Braun8e98ac42009-03-24 20:57:18 +0000319 if (qeth_wait_for_threads(card, QETH_RECOVER_THREAD)) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000320 QETH_CARD_TEXT(card, 3, "aidREC");
Jiri Pirko8e586132011-12-08 19:52:37 -0500321 return 0;
Ursula Braun8e98ac42009-03-24 20:57:18 +0000322 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100323 id = kmalloc(sizeof(struct qeth_vlan_vid), GFP_ATOMIC);
324 if (id) {
325 id->vid = vid;
326 qeth_l2_send_setdelvlan(card, vid, IPA_CMD_SETVLAN);
327 spin_lock_bh(&card->vlanlock);
328 list_add_tail(&id->list, &card->vid_list);
329 spin_unlock_bh(&card->vlanlock);
Jiri Pirko8e586132011-12-08 19:52:37 -0500330 } else {
331 return -ENOMEM;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100332 }
Jiri Pirko8e586132011-12-08 19:52:37 -0500333 return 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100334}
335
Jiri Pirko8e586132011-12-08 19:52:37 -0500336static int qeth_l2_vlan_rx_kill_vid(struct net_device *dev, unsigned short vid)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100337{
338 struct qeth_vlan_vid *id, *tmpid = NULL;
Heiko Carstens509e2562008-07-26 02:24:10 -0700339 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100340
Carsten Otte847a50f2010-06-21 22:57:05 +0000341 QETH_CARD_TEXT_(card, 4, "kid:%d", vid);
Ursula Braun5113fec2010-05-16 21:15:14 +0000342 if (card->info.type == QETH_CARD_TYPE_OSM) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000343 QETH_CARD_TEXT(card, 3, "kidOSM");
Jiri Pirko8e586132011-12-08 19:52:37 -0500344 return 0;
Ursula Braun5113fec2010-05-16 21:15:14 +0000345 }
Ursula Braun8e98ac42009-03-24 20:57:18 +0000346 if (qeth_wait_for_threads(card, QETH_RECOVER_THREAD)) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000347 QETH_CARD_TEXT(card, 3, "kidREC");
Jiri Pirko8e586132011-12-08 19:52:37 -0500348 return 0;
Ursula Braun8e98ac42009-03-24 20:57:18 +0000349 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100350 spin_lock_bh(&card->vlanlock);
351 list_for_each_entry(id, &card->vid_list, list) {
352 if (id->vid == vid) {
353 list_del(&id->list);
354 tmpid = id;
355 break;
356 }
357 }
358 spin_unlock_bh(&card->vlanlock);
359 if (tmpid) {
360 qeth_l2_send_setdelvlan(card, vid, IPA_CMD_DELVLAN);
361 kfree(tmpid);
362 }
363 qeth_l2_set_multicast_list(card->dev);
Jiri Pirko8e586132011-12-08 19:52:37 -0500364 return 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100365}
366
367static int qeth_l2_stop_card(struct qeth_card *card, int recovery_mode)
368{
369 int rc = 0;
370
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200371 QETH_DBF_TEXT(SETUP , 2, "stopcard");
372 QETH_DBF_HEX(SETUP, 2, &card, sizeof(void *));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100373
374 qeth_set_allowed_threads(card, 0, 1);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100375 if (card->read.state == CH_STATE_UP &&
376 card->write.state == CH_STATE_UP &&
377 (card->state == CARD_STATE_UP)) {
378 if (recovery_mode &&
379 card->info.type != QETH_CARD_TYPE_OSN) {
380 qeth_l2_stop(card->dev);
381 } else {
382 rtnl_lock();
383 dev_close(card->dev);
384 rtnl_unlock();
385 }
Ursula Braun70919e22011-02-26 22:41:36 -0800386 card->info.mac_bits &= ~QETH_LAYER2_MAC_REGISTERED;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100387 card->state = CARD_STATE_SOFTSETUP;
388 }
389 if (card->state == CARD_STATE_SOFTSETUP) {
Ursula Braun70919e22011-02-26 22:41:36 -0800390 qeth_l2_del_all_mc(card, 0);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100391 qeth_clear_ipacmd_list(card);
392 card->state = CARD_STATE_HARDSETUP;
393 }
394 if (card->state == CARD_STATE_HARDSETUP) {
395 qeth_qdio_clear_card(card, 0);
396 qeth_clear_qdio_buffers(card);
397 qeth_clear_working_pool_list(card);
398 card->state = CARD_STATE_DOWN;
399 }
400 if (card->state == CARD_STATE_DOWN) {
401 qeth_clear_cmd_buffers(&card->read);
402 qeth_clear_cmd_buffers(&card->write);
403 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100404 return rc;
405}
406
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000407static int qeth_l2_process_inbound_buffer(struct qeth_card *card,
408 int budget, int *done)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100409{
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000410 int work_done = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100411 struct sk_buff *skb;
412 struct qeth_hdr *hdr;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100413 unsigned int len;
414
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000415 *done = 0;
416 BUG_ON(!budget);
417 while (budget) {
418 skb = qeth_core_get_next_skb(card,
Frank Blaschkab3332932011-08-08 01:33:59 +0000419 &card->qdio.in_q->bufs[card->rx.b_index],
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000420 &card->rx.b_element, &card->rx.e_offset, &hdr);
421 if (!skb) {
422 *done = 1;
423 break;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100424 }
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000425 skb->dev = card->dev;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100426 switch (hdr->hdr.l2.id) {
427 case QETH_HEADER_TYPE_LAYER2:
428 skb->pkt_type = PACKET_HOST;
429 skb->protocol = eth_type_trans(skb, skb->dev);
Frank Blaschkac5e631a2011-05-12 18:45:01 +0000430 skb->ip_summed = CHECKSUM_NONE;
Ursula Braun12883722008-04-01 10:26:56 +0200431 if (skb->protocol == htons(ETH_P_802_2))
432 *((__u32 *)skb->cb) = ++card->seqno.pkt_seqno;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100433 len = skb->len;
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000434 netif_receive_skb(skb);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100435 break;
436 case QETH_HEADER_TYPE_OSN:
Ursula Braun2d488c22008-10-24 11:16:55 +0200437 if (card->info.type == QETH_CARD_TYPE_OSN) {
438 skb_push(skb, sizeof(struct qeth_hdr));
439 skb_copy_to_linear_data(skb, hdr,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100440 sizeof(struct qeth_hdr));
Ursula Braun2d488c22008-10-24 11:16:55 +0200441 len = skb->len;
442 card->osn_info.data_cb(skb);
443 break;
444 }
445 /* else unknown */
Frank Blaschka4a71df52008-02-15 09:19:42 +0100446 default:
447 dev_kfree_skb_any(skb);
Carsten Otte847a50f2010-06-21 22:57:05 +0000448 QETH_CARD_TEXT(card, 3, "inbunkno");
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200449 QETH_DBF_HEX(CTRL, 3, hdr, QETH_DBF_CTRL_LEN);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100450 continue;
451 }
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000452 work_done++;
453 budget--;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100454 card->stats.rx_packets++;
455 card->stats.rx_bytes += len;
456 }
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000457 return work_done;
458}
459
460static int qeth_l2_poll(struct napi_struct *napi, int budget)
461{
462 struct qeth_card *card = container_of(napi, struct qeth_card, napi);
463 int work_done = 0;
464 struct qeth_qdio_buffer *buffer;
465 int done;
466 int new_budget = budget;
467
468 if (card->options.performance_stats) {
469 card->perf_stats.inbound_cnt++;
470 card->perf_stats.inbound_start_time = qeth_get_micros();
471 }
472
473 while (1) {
474 if (!card->rx.b_count) {
475 card->rx.qdio_err = 0;
476 card->rx.b_count = qdio_get_next_buffers(
477 card->data.ccwdev, 0, &card->rx.b_index,
478 &card->rx.qdio_err);
479 if (card->rx.b_count <= 0) {
480 card->rx.b_count = 0;
481 break;
482 }
483 card->rx.b_element =
484 &card->qdio.in_q->bufs[card->rx.b_index]
485 .buffer->element[0];
486 card->rx.e_offset = 0;
487 }
488
489 while (card->rx.b_count) {
490 buffer = &card->qdio.in_q->bufs[card->rx.b_index];
491 if (!(card->rx.qdio_err &&
492 qeth_check_qdio_errors(card, buffer->buffer,
493 card->rx.qdio_err, "qinerr")))
494 work_done += qeth_l2_process_inbound_buffer(
495 card, new_budget, &done);
496 else
497 done = 1;
498
499 if (done) {
500 if (card->options.performance_stats)
501 card->perf_stats.bufs_rec++;
502 qeth_put_buffer_pool_entry(card,
503 buffer->pool_entry);
504 qeth_queue_input_buffer(card, card->rx.b_index);
505 card->rx.b_count--;
506 if (card->rx.b_count) {
507 card->rx.b_index =
508 (card->rx.b_index + 1) %
509 QDIO_MAX_BUFFERS_PER_Q;
510 card->rx.b_element =
511 &card->qdio.in_q
512 ->bufs[card->rx.b_index]
513 .buffer->element[0];
514 card->rx.e_offset = 0;
515 }
516 }
517
518 if (work_done >= budget)
519 goto out;
520 else
521 new_budget = budget - work_done;
522 }
523 }
524
525 napi_complete(napi);
526 if (qdio_start_irq(card->data.ccwdev, 0))
527 napi_schedule(&card->napi);
528out:
529 if (card->options.performance_stats)
530 card->perf_stats.inbound_time += qeth_get_micros() -
531 card->perf_stats.inbound_start_time;
532 return work_done;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100533}
534
535static int qeth_l2_send_setdelmac(struct qeth_card *card, __u8 *mac,
536 enum qeth_ipa_cmds ipacmd,
537 int (*reply_cb) (struct qeth_card *,
538 struct qeth_reply*,
539 unsigned long))
540{
541 struct qeth_ipa_cmd *cmd;
542 struct qeth_cmd_buffer *iob;
543
Carsten Otte847a50f2010-06-21 22:57:05 +0000544 QETH_CARD_TEXT(card, 2, "L2sdmac");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100545 iob = qeth_get_ipacmd_buffer(card, ipacmd, QETH_PROT_IPV4);
546 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
547 cmd->data.setdelmac.mac_length = OSA_ADDR_LEN;
548 memcpy(&cmd->data.setdelmac.mac, mac, OSA_ADDR_LEN);
549 return qeth_send_ipa_cmd(card, iob, reply_cb, NULL);
550}
551
552static int qeth_l2_send_setmac_cb(struct qeth_card *card,
553 struct qeth_reply *reply,
554 unsigned long data)
555{
556 struct qeth_ipa_cmd *cmd;
557
Carsten Otte847a50f2010-06-21 22:57:05 +0000558 QETH_CARD_TEXT(card, 2, "L2Smaccb");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100559 cmd = (struct qeth_ipa_cmd *) data;
560 if (cmd->hdr.return_code) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000561 QETH_CARD_TEXT_(card, 2, "L2er%x", cmd->hdr.return_code);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100562 card->info.mac_bits &= ~QETH_LAYER2_MAC_REGISTERED;
Ursula Braun0666eb062009-05-19 21:38:39 +0000563 switch (cmd->hdr.return_code) {
564 case IPA_RC_L2_DUP_MAC:
565 case IPA_RC_L2_DUP_LAYER3_MAC:
566 dev_warn(&card->gdev->dev,
H Hartley Sweetend998ab02009-12-29 20:05:37 -0800567 "MAC address %pM already exists\n",
Ursula Braun221c17f2011-02-02 06:04:31 +0000568 cmd->data.setdelmac.mac);
Ursula Braun0666eb062009-05-19 21:38:39 +0000569 break;
570 case IPA_RC_L2_MAC_NOT_AUTH_BY_HYP:
571 case IPA_RC_L2_MAC_NOT_AUTH_BY_ADP:
572 dev_warn(&card->gdev->dev,
H Hartley Sweetend998ab02009-12-29 20:05:37 -0800573 "MAC address %pM is not authorized\n",
Ursula Braun221c17f2011-02-02 06:04:31 +0000574 cmd->data.setdelmac.mac);
Ursula Braun0666eb062009-05-19 21:38:39 +0000575 break;
576 default:
577 break;
578 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100579 } else {
580 card->info.mac_bits |= QETH_LAYER2_MAC_REGISTERED;
581 memcpy(card->dev->dev_addr, cmd->data.setdelmac.mac,
582 OSA_ADDR_LEN);
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100583 dev_info(&card->gdev->dev,
H Hartley Sweetend998ab02009-12-29 20:05:37 -0800584 "MAC address %pM successfully registered on device %s\n",
585 card->dev->dev_addr, card->dev->name);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100586 }
587 return 0;
588}
589
590static int qeth_l2_send_setmac(struct qeth_card *card, __u8 *mac)
591{
Carsten Otte847a50f2010-06-21 22:57:05 +0000592 QETH_CARD_TEXT(card, 2, "L2Setmac");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100593 return qeth_l2_send_setdelmac(card, mac, IPA_CMD_SETVMAC,
594 qeth_l2_send_setmac_cb);
595}
596
597static int qeth_l2_send_delmac_cb(struct qeth_card *card,
598 struct qeth_reply *reply,
599 unsigned long data)
600{
601 struct qeth_ipa_cmd *cmd;
602
Carsten Otte847a50f2010-06-21 22:57:05 +0000603 QETH_CARD_TEXT(card, 2, "L2Dmaccb");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100604 cmd = (struct qeth_ipa_cmd *) data;
605 if (cmd->hdr.return_code) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000606 QETH_CARD_TEXT_(card, 2, "err%d", cmd->hdr.return_code);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100607 return 0;
608 }
609 card->info.mac_bits &= ~QETH_LAYER2_MAC_REGISTERED;
610
611 return 0;
612}
613
614static int qeth_l2_send_delmac(struct qeth_card *card, __u8 *mac)
615{
Carsten Otte847a50f2010-06-21 22:57:05 +0000616 QETH_CARD_TEXT(card, 2, "L2Delmac");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100617 if (!(card->info.mac_bits & QETH_LAYER2_MAC_REGISTERED))
618 return 0;
619 return qeth_l2_send_setdelmac(card, mac, IPA_CMD_DELVMAC,
620 qeth_l2_send_delmac_cb);
621}
622
623static int qeth_l2_request_initial_mac(struct qeth_card *card)
624{
625 int rc = 0;
626 char vendor_pre[] = {0x02, 0x00, 0x00};
627
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200628 QETH_DBF_TEXT(SETUP, 2, "doL2init");
629 QETH_DBF_TEXT_(SETUP, 2, "doL2%s", CARD_BUS_ID(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100630
631 rc = qeth_query_setadapterparms(card);
632 if (rc) {
Frank Blaschka14cc21b2008-06-06 12:37:46 +0200633 QETH_DBF_MESSAGE(2, "could not query adapter parameters on "
634 "device %s: x%x\n", CARD_BUS_ID(card), rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100635 }
636
Ursula Braun5113fec2010-05-16 21:15:14 +0000637 if (card->info.type == QETH_CARD_TYPE_IQD ||
638 card->info.type == QETH_CARD_TYPE_OSM ||
639 card->info.type == QETH_CARD_TYPE_OSX ||
640 card->info.guestlan) {
Frank Blaschka4a71df52008-02-15 09:19:42 +0100641 rc = qeth_setadpparms_change_macaddr(card);
642 if (rc) {
Frank Blaschka14cc21b2008-06-06 12:37:46 +0200643 QETH_DBF_MESSAGE(2, "couldn't get MAC address on "
644 "device %s: x%x\n", CARD_BUS_ID(card), rc);
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200645 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100646 return rc;
647 }
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200648 QETH_DBF_HEX(SETUP, 2, card->dev->dev_addr, OSA_ADDR_LEN);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100649 } else {
650 random_ether_addr(card->dev->dev_addr);
651 memcpy(card->dev->dev_addr, vendor_pre, 3);
652 }
653 return 0;
654}
655
656static int qeth_l2_set_mac_address(struct net_device *dev, void *p)
657{
658 struct sockaddr *addr = p;
Heiko Carstens509e2562008-07-26 02:24:10 -0700659 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100660 int rc = 0;
661
Carsten Otte847a50f2010-06-21 22:57:05 +0000662 QETH_CARD_TEXT(card, 3, "setmac");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100663
664 if (qeth_l2_verify_dev(dev) != QETH_REAL_CARD) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000665 QETH_CARD_TEXT(card, 3, "setmcINV");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100666 return -EOPNOTSUPP;
667 }
668
Ursula Braun5113fec2010-05-16 21:15:14 +0000669 if (card->info.type == QETH_CARD_TYPE_OSN ||
670 card->info.type == QETH_CARD_TYPE_OSM ||
671 card->info.type == QETH_CARD_TYPE_OSX) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000672 QETH_CARD_TEXT(card, 3, "setmcTYP");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100673 return -EOPNOTSUPP;
674 }
Carsten Otte847a50f2010-06-21 22:57:05 +0000675 QETH_CARD_HEX(card, 3, addr->sa_data, OSA_ADDR_LEN);
Ursula Braun8e98ac42009-03-24 20:57:18 +0000676 if (qeth_wait_for_threads(card, QETH_RECOVER_THREAD)) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000677 QETH_CARD_TEXT(card, 3, "setmcREC");
Ursula Braun8e98ac42009-03-24 20:57:18 +0000678 return -ERESTARTSYS;
679 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100680 rc = qeth_l2_send_delmac(card, &card->dev->dev_addr[0]);
681 if (!rc)
682 rc = qeth_l2_send_setmac(card, addr->sa_data);
Ursula Braune0a81142012-03-07 02:06:28 +0000683 return rc ? -EINVAL : 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100684}
685
686static void qeth_l2_set_multicast_list(struct net_device *dev)
687{
Heiko Carstens509e2562008-07-26 02:24:10 -0700688 struct qeth_card *card = dev->ml_priv;
Jiri Pirkoccffad252009-05-22 23:22:17 +0000689 struct netdev_hw_addr *ha;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100690
691 if (card->info.type == QETH_CARD_TYPE_OSN)
692 return ;
693
Carsten Otte847a50f2010-06-21 22:57:05 +0000694 QETH_CARD_TEXT(card, 3, "setmulti");
Ursula Braun8e98ac42009-03-24 20:57:18 +0000695 if (qeth_threads_running(card, QETH_RECOVER_THREAD) &&
696 (card->state != CARD_STATE_UP))
697 return;
Ursula Braun70919e22011-02-26 22:41:36 -0800698 qeth_l2_del_all_mc(card, 1);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100699 spin_lock_bh(&card->mclock);
Jiri Pirko22bedad32010-04-01 21:22:57 +0000700 netdev_for_each_mc_addr(ha, dev)
701 qeth_l2_add_mc(card, ha->addr, 0);
Frank Blaschka7db22662008-08-15 08:02:59 +0200702
Jiri Pirko32e7bfc2010-01-25 13:36:10 -0800703 netdev_for_each_uc_addr(ha, dev)
Jiri Pirkoccffad252009-05-22 23:22:17 +0000704 qeth_l2_add_mc(card, ha->addr, 1);
Frank Blaschka7db22662008-08-15 08:02:59 +0200705
Frank Blaschka4a71df52008-02-15 09:19:42 +0100706 spin_unlock_bh(&card->mclock);
707 if (!qeth_adp_supported(card, IPA_SETADP_SET_PROMISC_MODE))
708 return;
709 qeth_setadp_promisc_mode(card);
710}
711
712static int qeth_l2_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
713{
714 int rc;
715 struct qeth_hdr *hdr = NULL;
716 int elements = 0;
Heiko Carstens509e2562008-07-26 02:24:10 -0700717 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100718 struct sk_buff *new_skb = skb;
719 int ipv = qeth_get_ip_version(skb);
Klaus-Dieter Wackerce73e102009-08-26 02:01:08 +0000720 int cast_type = qeth_l2_get_cast_type(card, skb);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100721 struct qeth_qdio_out_q *queue = card->qdio.out_qs
722 [qeth_get_priority_queue(card, skb, ipv, cast_type)];
723 int tx_bytes = skb->len;
Frank Blaschka683d7182008-08-01 16:39:13 +0200724 int data_offset = -1;
725 int elements_needed = 0;
726 int hd_len = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100727
Frank Blaschka4a71df52008-02-15 09:19:42 +0100728 if ((card->state != CARD_STATE_UP) || !card->lan_online) {
729 card->stats.tx_carrier_errors++;
730 goto tx_drop;
731 }
732
733 if ((card->info.type == QETH_CARD_TYPE_OSN) &&
734 (skb->protocol == htons(ETH_P_IPV6)))
735 goto tx_drop;
736
737 if (card->options.performance_stats) {
738 card->perf_stats.outbound_cnt++;
739 card->perf_stats.outbound_start_time = qeth_get_micros();
740 }
741 netif_stop_queue(dev);
742
Frank Blaschka4a71df52008-02-15 09:19:42 +0100743 if (card->info.type == QETH_CARD_TYPE_OSN)
744 hdr = (struct qeth_hdr *)skb->data;
745 else {
Frank Blaschka64ef8952009-03-24 20:57:16 +0000746 if (card->info.type == QETH_CARD_TYPE_IQD) {
Frank Blaschka683d7182008-08-01 16:39:13 +0200747 new_skb = skb;
748 data_offset = ETH_HLEN;
749 hd_len = ETH_HLEN;
750 hdr = kmem_cache_alloc(qeth_core_header_cache,
751 GFP_ATOMIC);
752 if (!hdr)
753 goto tx_drop;
754 elements_needed++;
755 skb_reset_mac_header(new_skb);
756 qeth_l2_fill_header(card, hdr, new_skb, ipv, cast_type);
757 hdr->hdr.l2.pkt_length = new_skb->len;
758 memcpy(((char *)hdr) + sizeof(struct qeth_hdr),
759 skb_mac_header(new_skb), ETH_HLEN);
760 } else {
761 /* create a clone with writeable headroom */
762 new_skb = skb_realloc_headroom(skb,
Frank Blaschkaf90b7442008-04-24 10:15:24 +0200763 sizeof(struct qeth_hdr));
Frank Blaschka683d7182008-08-01 16:39:13 +0200764 if (!new_skb)
765 goto tx_drop;
766 hdr = (struct qeth_hdr *)skb_push(new_skb,
767 sizeof(struct qeth_hdr));
768 skb_set_mac_header(new_skb, sizeof(struct qeth_hdr));
769 qeth_l2_fill_header(card, hdr, new_skb, ipv, cast_type);
770 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100771 }
772
Frank Blaschka64ef8952009-03-24 20:57:16 +0000773 elements = qeth_get_elements_no(card, (void *)hdr, new_skb,
Frank Blaschka683d7182008-08-01 16:39:13 +0200774 elements_needed);
Frank Blaschka64ef8952009-03-24 20:57:16 +0000775 if (!elements) {
776 if (data_offset >= 0)
777 kmem_cache_free(qeth_core_header_cache, hdr);
778 goto tx_drop;
Frank Blaschkaf61a0d02009-03-24 20:57:15 +0000779 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100780
Frank Blaschka51aa1652010-06-21 22:57:10 +0000781 if (card->info.type != QETH_CARD_TYPE_IQD) {
782 if (qeth_hdr_chk_and_bounce(new_skb,
783 sizeof(struct qeth_hdr_layer2)))
784 goto tx_drop;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100785 rc = qeth_do_send_packet(card, queue, new_skb, hdr,
Frank Blaschka64ef8952009-03-24 20:57:16 +0000786 elements);
Frank Blaschka51aa1652010-06-21 22:57:10 +0000787 } else
Frank Blaschka4a71df52008-02-15 09:19:42 +0100788 rc = qeth_do_send_packet_fast(card, queue, new_skb, hdr,
Frank Blaschka64ef8952009-03-24 20:57:16 +0000789 elements, data_offset, hd_len);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100790 if (!rc) {
791 card->stats.tx_packets++;
792 card->stats.tx_bytes += tx_bytes;
793 if (new_skb != skb)
794 dev_kfree_skb_any(skb);
Patrick McHardyec634fe2009-07-05 19:23:38 -0700795 rc = NETDEV_TX_OK;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100796 } else {
Frank Blaschka683d7182008-08-01 16:39:13 +0200797 if (data_offset >= 0)
798 kmem_cache_free(qeth_core_header_cache, hdr);
799
Frank Blaschka4a71df52008-02-15 09:19:42 +0100800 if (rc == -EBUSY) {
801 if (new_skb != skb)
802 dev_kfree_skb_any(new_skb);
803 return NETDEV_TX_BUSY;
804 } else
805 goto tx_drop;
806 }
807
808 netif_wake_queue(dev);
809 if (card->options.performance_stats)
810 card->perf_stats.outbound_time += qeth_get_micros() -
811 card->perf_stats.outbound_start_time;
812 return rc;
813
814tx_drop:
815 card->stats.tx_dropped++;
816 card->stats.tx_errors++;
817 if ((new_skb != skb) && new_skb)
818 dev_kfree_skb_any(new_skb);
819 dev_kfree_skb_any(skb);
Frank Blaschkad0ec0f52008-06-06 12:37:48 +0200820 netif_wake_queue(dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100821 return NETDEV_TX_OK;
822}
823
Ursula Braun39423442011-01-12 20:42:24 +0000824static int __qeth_l2_open(struct net_device *dev)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100825{
Heiko Carstens509e2562008-07-26 02:24:10 -0700826 struct qeth_card *card = dev->ml_priv;
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000827 int rc = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100828
Carsten Otte847a50f2010-06-21 22:57:05 +0000829 QETH_CARD_TEXT(card, 4, "qethopen");
Ursula Braun39423442011-01-12 20:42:24 +0000830 if (card->state == CARD_STATE_UP)
831 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100832 if (card->state != CARD_STATE_SOFTSETUP)
833 return -ENODEV;
834
835 if ((card->info.type != QETH_CARD_TYPE_OSN) &&
836 (!(card->info.mac_bits & QETH_LAYER2_MAC_REGISTERED))) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000837 QETH_CARD_TEXT(card, 4, "nomacadr");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100838 return -EPERM;
839 }
840 card->data.state = CH_STATE_UP;
841 card->state = CARD_STATE_UP;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100842 netif_start_queue(dev);
843
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000844 if (qdio_stop_irq(card->data.ccwdev, 0) >= 0) {
845 napi_enable(&card->napi);
846 napi_schedule(&card->napi);
847 } else
848 rc = -EIO;
849 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100850}
851
Ursula Braun39423442011-01-12 20:42:24 +0000852static int qeth_l2_open(struct net_device *dev)
853{
854 struct qeth_card *card = dev->ml_priv;
855
856 QETH_CARD_TEXT(card, 5, "qethope_");
857 if (qeth_wait_for_threads(card, QETH_RECOVER_THREAD)) {
858 QETH_CARD_TEXT(card, 3, "openREC");
859 return -ERESTARTSYS;
860 }
861 return __qeth_l2_open(dev);
862}
863
Frank Blaschka4a71df52008-02-15 09:19:42 +0100864static int qeth_l2_stop(struct net_device *dev)
865{
Heiko Carstens509e2562008-07-26 02:24:10 -0700866 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100867
Carsten Otte847a50f2010-06-21 22:57:05 +0000868 QETH_CARD_TEXT(card, 4, "qethstop");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100869 netif_tx_disable(dev);
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000870 if (card->state == CARD_STATE_UP) {
Frank Blaschka4a71df52008-02-15 09:19:42 +0100871 card->state = CARD_STATE_SOFTSETUP;
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000872 napi_disable(&card->napi);
873 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100874 return 0;
875}
876
877static int qeth_l2_probe_device(struct ccwgroup_device *gdev)
878{
879 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
880
881 INIT_LIST_HEAD(&card->vid_list);
882 INIT_LIST_HEAD(&card->mc_list);
883 card->options.layer2 = 1;
Frank Blaschka1da74b12011-05-12 18:45:02 +0000884 card->info.hwtrap = 0;
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000885 card->discipline.start_poll = qeth_qdio_start_poll;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100886 card->discipline.input_handler = (qdio_handler_t *)
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000887 qeth_qdio_input_handler;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100888 card->discipline.output_handler = (qdio_handler_t *)
889 qeth_qdio_output_handler;
890 card->discipline.recover = qeth_l2_recover;
891 return 0;
892}
893
894static void qeth_l2_remove_device(struct ccwgroup_device *cgdev)
895{
896 struct qeth_card *card = dev_get_drvdata(&cgdev->dev);
897
Ursula Braunf2148562009-05-19 21:38:37 +0000898 qeth_set_allowed_threads(card, 0, 1);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100899 wait_event(card->wait_q, qeth_threads_running(card, 0xffffffff) == 0);
900
Ursula Braun70919e22011-02-26 22:41:36 -0800901 if (cgdev->state == CCWGROUP_ONLINE)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100902 qeth_l2_set_offline(cgdev);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100903
904 if (card->dev) {
905 unregister_netdev(card->dev);
906 card->dev = NULL;
907 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100908 return;
909}
910
Stephen Hemminger0fc0b732009-09-02 01:03:33 -0700911static const struct ethtool_ops qeth_l2_ethtool_ops = {
Frank Blaschka4a71df52008-02-15 09:19:42 +0100912 .get_link = ethtool_op_get_link,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100913 .get_strings = qeth_core_get_strings,
914 .get_ethtool_stats = qeth_core_get_ethtool_stats,
Ben Hutchingsdf8b4ec2009-10-01 11:24:32 +0000915 .get_sset_count = qeth_core_get_sset_count,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100916 .get_drvinfo = qeth_core_get_drvinfo,
Frank Blaschka3f9975a2008-04-24 10:15:23 +0200917 .get_settings = qeth_core_ethtool_get_settings,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100918};
919
Stephen Hemminger0fc0b732009-09-02 01:03:33 -0700920static const struct ethtool_ops qeth_l2_osn_ops = {
Frank Blaschka4a71df52008-02-15 09:19:42 +0100921 .get_strings = qeth_core_get_strings,
922 .get_ethtool_stats = qeth_core_get_ethtool_stats,
Ben Hutchingsdf8b4ec2009-10-01 11:24:32 +0000923 .get_sset_count = qeth_core_get_sset_count,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100924 .get_drvinfo = qeth_core_get_drvinfo,
925};
926
Frank Blaschka3d58cef2009-01-09 03:44:00 +0000927static const struct net_device_ops qeth_l2_netdev_ops = {
Frank Blaschka8403b132009-01-08 10:50:55 -0800928 .ndo_open = qeth_l2_open,
929 .ndo_stop = qeth_l2_stop,
930 .ndo_get_stats = qeth_get_stats,
931 .ndo_start_xmit = qeth_l2_hard_start_xmit,
932 .ndo_validate_addr = eth_validate_addr,
Jiri Pirkoafc4b132011-08-16 06:29:01 +0000933 .ndo_set_rx_mode = qeth_l2_set_multicast_list,
Frank Blaschka8403b132009-01-08 10:50:55 -0800934 .ndo_do_ioctl = qeth_l2_do_ioctl,
935 .ndo_set_mac_address = qeth_l2_set_mac_address,
936 .ndo_change_mtu = qeth_change_mtu,
937 .ndo_vlan_rx_add_vid = qeth_l2_vlan_rx_add_vid,
938 .ndo_vlan_rx_kill_vid = qeth_l2_vlan_rx_kill_vid,
939 .ndo_tx_timeout = qeth_tx_timeout,
940};
941
Frank Blaschka4a71df52008-02-15 09:19:42 +0100942static int qeth_l2_setup_netdev(struct qeth_card *card)
943{
944 switch (card->info.type) {
Frank Blaschka4a71df52008-02-15 09:19:42 +0100945 case QETH_CARD_TYPE_IQD:
946 card->dev = alloc_netdev(0, "hsi%d", ether_setup);
947 break;
948 case QETH_CARD_TYPE_OSN:
949 card->dev = alloc_netdev(0, "osn%d", ether_setup);
950 card->dev->flags |= IFF_NOARP;
951 break;
952 default:
953 card->dev = alloc_etherdev(0);
954 }
955
956 if (!card->dev)
957 return -ENODEV;
958
Heiko Carstens509e2562008-07-26 02:24:10 -0700959 card->dev->ml_priv = card;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100960 card->dev->watchdog_timeo = QETH_TX_TIMEOUT;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100961 card->dev->mtu = card->info.initial_mtu;
Frank Blaschka8403b132009-01-08 10:50:55 -0800962 card->dev->netdev_ops = &qeth_l2_netdev_ops;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100963 if (card->info.type != QETH_CARD_TYPE_OSN)
964 SET_ETHTOOL_OPS(card->dev, &qeth_l2_ethtool_ops);
965 else
966 SET_ETHTOOL_OPS(card->dev, &qeth_l2_osn_ops);
967 card->dev->features |= NETIF_F_HW_VLAN_FILTER;
968 card->info.broadcast_capable = 1;
969 qeth_l2_request_initial_mac(card);
970 SET_NETDEV_DEV(card->dev, &card->gdev->dev);
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000971 netif_napi_add(card->dev, &card->napi, qeth_l2_poll, QETH_NAPI_WEIGHT);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100972 return register_netdev(card->dev);
973}
974
975static int __qeth_l2_set_online(struct ccwgroup_device *gdev, int recovery_mode)
976{
977 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
978 int rc = 0;
979 enum qeth_card_states recover_flag;
980
981 BUG_ON(!card);
Ursula Braun9dc48cc2010-07-22 23:15:05 +0000982 mutex_lock(&card->discipline_mutex);
Frank Blaschkac4949f02010-05-11 19:34:47 +0000983 mutex_lock(&card->conf_mutex);
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200984 QETH_DBF_TEXT(SETUP, 2, "setonlin");
985 QETH_DBF_HEX(SETUP, 2, &card, sizeof(void *));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100986
Frank Blaschka4a71df52008-02-15 09:19:42 +0100987 recover_flag = card->state;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100988 rc = qeth_core_hardsetup_card(card);
989 if (rc) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200990 QETH_DBF_TEXT_(SETUP, 2, "2err%d", rc);
Ursula Braunaa909222009-11-12 00:11:43 +0000991 rc = -ENODEV;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100992 goto out_remove;
993 }
994
Ursula Braunaa909222009-11-12 00:11:43 +0000995 if (!card->dev && qeth_l2_setup_netdev(card)) {
996 rc = -ENODEV;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100997 goto out_remove;
Ursula Braunaa909222009-11-12 00:11:43 +0000998 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100999
1000 if (card->info.type != QETH_CARD_TYPE_OSN)
1001 qeth_l2_send_setmac(card, &card->dev->dev_addr[0]);
1002
Frank Blaschka1da74b12011-05-12 18:45:02 +00001003 if (qeth_is_diagass_supported(card, QETH_DIAGS_CMD_TRAP)) {
1004 if (card->info.hwtrap &&
1005 qeth_hw_trap(card, QETH_DIAGS_TRAP_ARM))
1006 card->info.hwtrap = 0;
1007 } else
1008 card->info.hwtrap = 0;
1009
Frank Blaschka4a71df52008-02-15 09:19:42 +01001010 card->state = CARD_STATE_HARDSETUP;
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00001011 memset(&card->rx, 0, sizeof(struct qeth_rx));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001012 qeth_print_status_message(card);
1013
1014 /* softsetup */
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001015 QETH_DBF_TEXT(SETUP, 2, "softsetp");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001016
1017 rc = qeth_send_startlan(card);
1018 if (rc) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001019 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001020 if (rc == 0xe080) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001021 dev_warn(&card->gdev->dev,
1022 "The LAN is offline\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001023 card->lan_online = 0;
Ursula Braun2b6203b2010-11-26 02:41:19 +00001024 goto contin;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001025 }
Ursula Braunaa909222009-11-12 00:11:43 +00001026 rc = -ENODEV;
Ursula Braunf2148562009-05-19 21:38:37 +00001027 goto out_remove;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001028 } else
1029 card->lan_online = 1;
1030
Ursula Braun2b6203b2010-11-26 02:41:19 +00001031contin:
Ursula Braun5113fec2010-05-16 21:15:14 +00001032 if ((card->info.type == QETH_CARD_TYPE_OSD) ||
1033 (card->info.type == QETH_CARD_TYPE_OSX))
Einar Lueckd64ecc22009-11-12 00:11:41 +00001034 /* configure isolation level */
1035 qeth_set_access_ctrl_online(card);
Ursula Braun5113fec2010-05-16 21:15:14 +00001036
1037 if (card->info.type != QETH_CARD_TYPE_OSN &&
1038 card->info.type != QETH_CARD_TYPE_OSM)
Ursula Braun70919e22011-02-26 22:41:36 -08001039 qeth_l2_process_vlans(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001040
1041 netif_tx_disable(card->dev);
1042
1043 rc = qeth_init_qdio_queues(card);
1044 if (rc) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001045 QETH_DBF_TEXT_(SETUP, 2, "6err%d", rc);
Ursula Braunaa909222009-11-12 00:11:43 +00001046 rc = -ENODEV;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001047 goto out_remove;
1048 }
1049 card->state = CARD_STATE_SOFTSETUP;
Ursula Braun2b6203b2010-11-26 02:41:19 +00001050 if (card->lan_online)
1051 netif_carrier_on(card->dev);
1052 else
1053 netif_carrier_off(card->dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001054
1055 qeth_set_allowed_threads(card, 0xffffffff, 0);
1056 if (recover_flag == CARD_STATE_RECOVER) {
1057 if (recovery_mode &&
1058 card->info.type != QETH_CARD_TYPE_OSN) {
Ursula Braun39423442011-01-12 20:42:24 +00001059 __qeth_l2_open(card->dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001060 } else {
1061 rtnl_lock();
1062 dev_open(card->dev);
1063 rtnl_unlock();
1064 }
1065 /* this also sets saved unicast addresses */
1066 qeth_l2_set_multicast_list(card->dev);
1067 }
1068 /* let user_space know that device is online */
1069 kobject_uevent(&gdev->dev.kobj, KOBJ_CHANGE);
Frank Blaschkac4949f02010-05-11 19:34:47 +00001070 mutex_unlock(&card->conf_mutex);
Ursula Braun9dc48cc2010-07-22 23:15:05 +00001071 mutex_unlock(&card->discipline_mutex);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001072 return 0;
Ursula Braunaa909222009-11-12 00:11:43 +00001073
Frank Blaschka4a71df52008-02-15 09:19:42 +01001074out_remove:
Frank Blaschka4a71df52008-02-15 09:19:42 +01001075 qeth_l2_stop_card(card, 0);
1076 ccw_device_set_offline(CARD_DDEV(card));
1077 ccw_device_set_offline(CARD_WDEV(card));
1078 ccw_device_set_offline(CARD_RDEV(card));
1079 if (recover_flag == CARD_STATE_RECOVER)
1080 card->state = CARD_STATE_RECOVER;
1081 else
1082 card->state = CARD_STATE_DOWN;
Frank Blaschkac4949f02010-05-11 19:34:47 +00001083 mutex_unlock(&card->conf_mutex);
Ursula Braun9dc48cc2010-07-22 23:15:05 +00001084 mutex_unlock(&card->discipline_mutex);
Ursula Braunaa909222009-11-12 00:11:43 +00001085 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001086}
1087
1088static int qeth_l2_set_online(struct ccwgroup_device *gdev)
1089{
1090 return __qeth_l2_set_online(gdev, 0);
1091}
1092
1093static int __qeth_l2_set_offline(struct ccwgroup_device *cgdev,
1094 int recovery_mode)
1095{
1096 struct qeth_card *card = dev_get_drvdata(&cgdev->dev);
1097 int rc = 0, rc2 = 0, rc3 = 0;
1098 enum qeth_card_states recover_flag;
1099
Ursula Braun9dc48cc2010-07-22 23:15:05 +00001100 mutex_lock(&card->discipline_mutex);
Frank Blaschkac4949f02010-05-11 19:34:47 +00001101 mutex_lock(&card->conf_mutex);
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001102 QETH_DBF_TEXT(SETUP, 3, "setoffl");
1103 QETH_DBF_HEX(SETUP, 3, &card, sizeof(void *));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001104
1105 if (card->dev && netif_carrier_ok(card->dev))
1106 netif_carrier_off(card->dev);
1107 recover_flag = card->state;
Frank Blaschka1da74b12011-05-12 18:45:02 +00001108 if ((!recovery_mode && card->info.hwtrap) || card->info.hwtrap == 2) {
1109 qeth_hw_trap(card, QETH_DIAGS_TRAP_DISARM);
1110 card->info.hwtrap = 1;
1111 }
Ursula Braun0f5623c2008-10-24 11:16:52 +02001112 qeth_l2_stop_card(card, recovery_mode);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001113 rc = ccw_device_set_offline(CARD_DDEV(card));
1114 rc2 = ccw_device_set_offline(CARD_WDEV(card));
1115 rc3 = ccw_device_set_offline(CARD_RDEV(card));
1116 if (!rc)
1117 rc = (rc2) ? rc2 : rc3;
1118 if (rc)
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001119 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001120 if (recover_flag == CARD_STATE_UP)
1121 card->state = CARD_STATE_RECOVER;
1122 /* let user_space know that device is offline */
1123 kobject_uevent(&cgdev->dev.kobj, KOBJ_CHANGE);
Frank Blaschkac4949f02010-05-11 19:34:47 +00001124 mutex_unlock(&card->conf_mutex);
Ursula Braun9dc48cc2010-07-22 23:15:05 +00001125 mutex_unlock(&card->discipline_mutex);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001126 return 0;
1127}
1128
1129static int qeth_l2_set_offline(struct ccwgroup_device *cgdev)
1130{
1131 return __qeth_l2_set_offline(cgdev, 0);
1132}
1133
1134static int qeth_l2_recover(void *ptr)
1135{
1136 struct qeth_card *card;
1137 int rc = 0;
1138
1139 card = (struct qeth_card *) ptr;
Carsten Otte847a50f2010-06-21 22:57:05 +00001140 QETH_CARD_TEXT(card, 2, "recover1");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001141 if (!qeth_do_run_thread(card, QETH_RECOVER_THREAD))
1142 return 0;
Carsten Otte847a50f2010-06-21 22:57:05 +00001143 QETH_CARD_TEXT(card, 2, "recover2");
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001144 dev_warn(&card->gdev->dev,
1145 "A recovery process has been started for the device\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001146 __qeth_l2_set_offline(card->gdev, 1);
1147 rc = __qeth_l2_set_online(card->gdev, 1);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001148 if (!rc)
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001149 dev_info(&card->gdev->dev,
1150 "Device successfully recovered!\n");
Ursula Braun28a7e4c2008-09-19 12:56:03 +02001151 else {
Ursula Braun869da902010-03-08 20:36:56 +00001152 rtnl_lock();
1153 dev_close(card->dev);
1154 rtnl_unlock();
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001155 dev_warn(&card->gdev->dev, "The qeth device driver "
1156 "failed to recover an error on the device\n");
Ursula Braun28a7e4c2008-09-19 12:56:03 +02001157 }
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00001158 qeth_clear_thread_start_bit(card, QETH_RECOVER_THREAD);
1159 qeth_clear_thread_running_bit(card, QETH_RECOVER_THREAD);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001160 return 0;
1161}
1162
1163static int __init qeth_l2_init(void)
1164{
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001165 pr_info("register layer 2 discipline\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001166 return 0;
1167}
1168
1169static void __exit qeth_l2_exit(void)
1170{
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001171 pr_info("unregister layer 2 discipline\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001172}
1173
1174static void qeth_l2_shutdown(struct ccwgroup_device *gdev)
1175{
1176 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
Ursula Braunf78ac2b2011-12-19 22:56:33 +00001177 qeth_set_allowed_threads(card, 0, 1);
Frank Blaschka1da74b12011-05-12 18:45:02 +00001178 if ((gdev->state == CCWGROUP_ONLINE) && card->info.hwtrap)
1179 qeth_hw_trap(card, QETH_DIAGS_TRAP_DISARM);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001180 qeth_qdio_clear_card(card, 0);
1181 qeth_clear_qdio_buffers(card);
1182}
1183
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02001184static int qeth_l2_pm_suspend(struct ccwgroup_device *gdev)
1185{
1186 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
1187
1188 if (card->dev)
1189 netif_device_detach(card->dev);
1190 qeth_set_allowed_threads(card, 0, 1);
1191 wait_event(card->wait_q, qeth_threads_running(card, 0xffffffff) == 0);
1192 if (gdev->state == CCWGROUP_OFFLINE)
1193 return 0;
1194 if (card->state == CARD_STATE_UP) {
Frank Blaschka1da74b12011-05-12 18:45:02 +00001195 if (card->info.hwtrap)
1196 qeth_hw_trap(card, QETH_DIAGS_TRAP_DISARM);
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02001197 __qeth_l2_set_offline(card->gdev, 1);
1198 } else
1199 __qeth_l2_set_offline(card->gdev, 0);
1200 return 0;
1201}
1202
1203static int qeth_l2_pm_resume(struct ccwgroup_device *gdev)
1204{
1205 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
1206 int rc = 0;
1207
1208 if (gdev->state == CCWGROUP_OFFLINE)
1209 goto out;
1210
1211 if (card->state == CARD_STATE_RECOVER) {
1212 rc = __qeth_l2_set_online(card->gdev, 1);
1213 if (rc) {
Ursula Braun869da902010-03-08 20:36:56 +00001214 rtnl_lock();
1215 dev_close(card->dev);
1216 rtnl_unlock();
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02001217 }
1218 } else
1219 rc = __qeth_l2_set_online(card->gdev, 0);
1220out:
1221 qeth_set_allowed_threads(card, 0xffffffff, 0);
1222 if (card->dev)
1223 netif_device_attach(card->dev);
1224 if (rc)
1225 dev_warn(&card->gdev->dev, "The qeth device driver "
1226 "failed to recover an error on the device\n");
1227 return rc;
1228}
1229
Frank Blaschka4a71df52008-02-15 09:19:42 +01001230struct ccwgroup_driver qeth_l2_ccwgroup_driver = {
1231 .probe = qeth_l2_probe_device,
1232 .remove = qeth_l2_remove_device,
1233 .set_online = qeth_l2_set_online,
1234 .set_offline = qeth_l2_set_offline,
1235 .shutdown = qeth_l2_shutdown,
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02001236 .freeze = qeth_l2_pm_suspend,
1237 .thaw = qeth_l2_pm_resume,
1238 .restore = qeth_l2_pm_resume,
Frank Blaschka4a71df52008-02-15 09:19:42 +01001239};
1240EXPORT_SYMBOL_GPL(qeth_l2_ccwgroup_driver);
1241
1242static int qeth_osn_send_control_data(struct qeth_card *card, int len,
1243 struct qeth_cmd_buffer *iob)
1244{
1245 unsigned long flags;
1246 int rc = 0;
1247
Carsten Otte847a50f2010-06-21 22:57:05 +00001248 QETH_CARD_TEXT(card, 5, "osndctrd");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001249
1250 wait_event(card->wait_q,
1251 atomic_cmpxchg(&card->write.irq_pending, 0, 1) == 0);
1252 qeth_prepare_control_data(card, len, iob);
Carsten Otte847a50f2010-06-21 22:57:05 +00001253 QETH_CARD_TEXT(card, 6, "osnoirqp");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001254 spin_lock_irqsave(get_ccwdev_lock(card->write.ccwdev), flags);
1255 rc = ccw_device_start(card->write.ccwdev, &card->write.ccw,
1256 (addr_t) iob, 0, 0);
1257 spin_unlock_irqrestore(get_ccwdev_lock(card->write.ccwdev), flags);
1258 if (rc) {
Frank Blaschka14cc21b2008-06-06 12:37:46 +02001259 QETH_DBF_MESSAGE(2, "qeth_osn_send_control_data: "
Frank Blaschka4a71df52008-02-15 09:19:42 +01001260 "ccw_device_start rc = %i\n", rc);
Carsten Otte847a50f2010-06-21 22:57:05 +00001261 QETH_CARD_TEXT_(card, 2, " err%d", rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001262 qeth_release_buffer(iob->channel, iob);
1263 atomic_set(&card->write.irq_pending, 0);
1264 wake_up(&card->wait_q);
1265 }
1266 return rc;
1267}
1268
1269static int qeth_osn_send_ipa_cmd(struct qeth_card *card,
1270 struct qeth_cmd_buffer *iob, int data_len)
1271{
1272 u16 s1, s2;
1273
Carsten Otte847a50f2010-06-21 22:57:05 +00001274 QETH_CARD_TEXT(card, 4, "osndipa");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001275
1276 qeth_prepare_ipa_cmd(card, iob, QETH_PROT_OSN2);
1277 s1 = (u16)(IPA_PDU_HEADER_SIZE + data_len);
1278 s2 = (u16)data_len;
1279 memcpy(QETH_IPA_PDU_LEN_TOTAL(iob->data), &s1, 2);
1280 memcpy(QETH_IPA_PDU_LEN_PDU1(iob->data), &s2, 2);
1281 memcpy(QETH_IPA_PDU_LEN_PDU2(iob->data), &s2, 2);
1282 memcpy(QETH_IPA_PDU_LEN_PDU3(iob->data), &s2, 2);
1283 return qeth_osn_send_control_data(card, s1, iob);
1284}
1285
1286int qeth_osn_assist(struct net_device *dev, void *data, int data_len)
1287{
1288 struct qeth_cmd_buffer *iob;
1289 struct qeth_card *card;
1290 int rc;
1291
Frank Blaschka4a71df52008-02-15 09:19:42 +01001292 if (!dev)
1293 return -ENODEV;
Heiko Carstens509e2562008-07-26 02:24:10 -07001294 card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001295 if (!card)
1296 return -ENODEV;
Carsten Otte847a50f2010-06-21 22:57:05 +00001297 QETH_CARD_TEXT(card, 2, "osnsdmc");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001298 if ((card->state != CARD_STATE_UP) &&
1299 (card->state != CARD_STATE_SOFTSETUP))
1300 return -ENODEV;
1301 iob = qeth_wait_for_buffer(&card->write);
1302 memcpy(iob->data+IPA_PDU_HEADER_SIZE, data, data_len);
1303 rc = qeth_osn_send_ipa_cmd(card, iob, data_len);
1304 return rc;
1305}
1306EXPORT_SYMBOL(qeth_osn_assist);
1307
1308int qeth_osn_register(unsigned char *read_dev_no, struct net_device **dev,
1309 int (*assist_cb)(struct net_device *, void *),
1310 int (*data_cb)(struct sk_buff *))
1311{
1312 struct qeth_card *card;
1313
Frank Blaschka4a71df52008-02-15 09:19:42 +01001314 *dev = qeth_l2_netdev_by_devno(read_dev_no);
1315 if (*dev == NULL)
1316 return -ENODEV;
Heiko Carstens509e2562008-07-26 02:24:10 -07001317 card = (*dev)->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001318 if (!card)
1319 return -ENODEV;
Carsten Otte847a50f2010-06-21 22:57:05 +00001320 QETH_CARD_TEXT(card, 2, "osnreg");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001321 if ((assist_cb == NULL) || (data_cb == NULL))
1322 return -EINVAL;
1323 card->osn_info.assist_cb = assist_cb;
1324 card->osn_info.data_cb = data_cb;
1325 return 0;
1326}
1327EXPORT_SYMBOL(qeth_osn_register);
1328
1329void qeth_osn_deregister(struct net_device *dev)
1330{
1331 struct qeth_card *card;
1332
Frank Blaschka4a71df52008-02-15 09:19:42 +01001333 if (!dev)
1334 return;
Heiko Carstens509e2562008-07-26 02:24:10 -07001335 card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001336 if (!card)
1337 return;
Carsten Otte847a50f2010-06-21 22:57:05 +00001338 QETH_CARD_TEXT(card, 2, "osndereg");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001339 card->osn_info.assist_cb = NULL;
1340 card->osn_info.data_cb = NULL;
1341 return;
1342}
1343EXPORT_SYMBOL(qeth_osn_deregister);
1344
1345module_init(qeth_l2_init);
1346module_exit(qeth_l2_exit);
1347MODULE_AUTHOR("Frank Blaschka <frank.blaschka@de.ibm.com>");
1348MODULE_DESCRIPTION("qeth layer 2 discipline");
1349MODULE_LICENSE("GPL");