blob: d690166efeaffbd4d47f1d39d3111af232876e66 [file] [log] [blame]
Frank Blaschka4a71df52008-02-15 09:19:42 +01001/*
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02002 * Copyright IBM Corp. 2007, 2009
Frank Blaschka4a71df52008-02-15 09:19:42 +01003 * Author(s): Utz Bacher <utz.bacher@de.ibm.com>,
4 * Frank Pavlic <fpavlic@de.ibm.com>,
5 * Thomas Spatzier <tspat@de.ibm.com>,
6 * Frank Blaschka <frank.blaschka@de.ibm.com>
7 */
8
Frank Blaschka74eacdb2008-12-25 13:39:49 +01009#define KMSG_COMPONENT "qeth"
10#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
11
Frank Blaschka4a71df52008-02-15 09:19:42 +010012#include <linux/module.h>
13#include <linux/moduleparam.h>
14#include <linux/string.h>
15#include <linux/errno.h>
16#include <linux/kernel.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090017#include <linux/slab.h>
Frank Blaschka4a71df52008-02-15 09:19:42 +010018#include <linux/etherdevice.h>
19#include <linux/mii.h>
20#include <linux/ip.h>
Jiri Pirkoccffad252009-05-22 23:22:17 +000021#include <linux/list.h>
Frank Blaschka4a71df52008-02-15 09:19:42 +010022
Frank Blaschka4a71df52008-02-15 09:19:42 +010023#include "qeth_core.h"
Frank Blaschka4a71df52008-02-15 09:19:42 +010024
Frank Blaschka4a71df52008-02-15 09:19:42 +010025static int qeth_l2_set_offline(struct ccwgroup_device *);
26static int qeth_l2_stop(struct net_device *);
27static int qeth_l2_send_delmac(struct qeth_card *, __u8 *);
28static int qeth_l2_send_setdelmac(struct qeth_card *, __u8 *,
29 enum qeth_ipa_cmds,
30 int (*reply_cb) (struct qeth_card *,
31 struct qeth_reply*,
32 unsigned long));
33static void qeth_l2_set_multicast_list(struct net_device *);
34static int qeth_l2_recover(void *);
35
36static int qeth_l2_do_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
37{
Heiko Carstens509e2562008-07-26 02:24:10 -070038 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +010039 struct mii_ioctl_data *mii_data;
40 int rc = 0;
41
42 if (!card)
43 return -ENODEV;
44
45 if ((card->state != CARD_STATE_UP) &&
46 (card->state != CARD_STATE_SOFTSETUP))
47 return -ENODEV;
48
49 if (card->info.type == QETH_CARD_TYPE_OSN)
50 return -EPERM;
51
52 switch (cmd) {
53 case SIOC_QETH_ADP_SET_SNMP_CONTROL:
54 rc = qeth_snmp_command(card, rq->ifr_ifru.ifru_data);
55 break;
56 case SIOC_QETH_GET_CARD_TYPE:
Ursula Braun5113fec2010-05-16 21:15:14 +000057 if ((card->info.type == QETH_CARD_TYPE_OSD ||
58 card->info.type == QETH_CARD_TYPE_OSM ||
59 card->info.type == QETH_CARD_TYPE_OSX) &&
Frank Blaschka4a71df52008-02-15 09:19:42 +010060 !card->info.guestlan)
61 return 1;
62 return 0;
63 break;
64 case SIOCGMIIPHY:
65 mii_data = if_mii(rq);
66 mii_data->phy_id = 0;
67 break;
68 case SIOCGMIIREG:
69 mii_data = if_mii(rq);
70 if (mii_data->phy_id != 0)
71 rc = -EINVAL;
72 else
73 mii_data->val_out = qeth_mdio_read(dev,
74 mii_data->phy_id, mii_data->reg_num);
75 break;
Frank Blaschkac3ab96f2012-02-08 00:19:49 +000076 case SIOC_QETH_QUERY_OAT:
77 rc = qeth_query_oat_command(card, rq->ifr_ifru.ifru_data);
78 break;
Frank Blaschka4a71df52008-02-15 09:19:42 +010079 default:
80 rc = -EOPNOTSUPP;
81 }
82 if (rc)
Carsten Otte847a50f2010-06-21 22:57:05 +000083 QETH_CARD_TEXT_(card, 2, "ioce%d", rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +010084 return rc;
85}
86
87static int qeth_l2_verify_dev(struct net_device *dev)
88{
89 struct qeth_card *card;
90 unsigned long flags;
91 int rc = 0;
92
93 read_lock_irqsave(&qeth_core_card_list.rwlock, flags);
94 list_for_each_entry(card, &qeth_core_card_list.list, list) {
95 if (card->dev == dev) {
96 rc = QETH_REAL_CARD;
97 break;
98 }
99 }
100 read_unlock_irqrestore(&qeth_core_card_list.rwlock, flags);
101
102 return rc;
103}
104
105static struct net_device *qeth_l2_netdev_by_devno(unsigned char *read_dev_no)
106{
107 struct qeth_card *card;
108 struct net_device *ndev;
Cornelia Huckf06f6f32008-06-06 12:37:45 +0200109 __u16 temp_dev_no;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100110 unsigned long flags;
Cornelia Huckf06f6f32008-06-06 12:37:45 +0200111 struct ccw_dev_id read_devid;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100112
113 ndev = NULL;
114 memcpy(&temp_dev_no, read_dev_no, 2);
115 read_lock_irqsave(&qeth_core_card_list.rwlock, flags);
116 list_for_each_entry(card, &qeth_core_card_list.list, list) {
Cornelia Huckf06f6f32008-06-06 12:37:45 +0200117 ccw_device_get_id(CARD_RDEV(card), &read_devid);
118 if (read_devid.devno == temp_dev_no) {
Frank Blaschka4a71df52008-02-15 09:19:42 +0100119 ndev = card->dev;
120 break;
121 }
122 }
123 read_unlock_irqrestore(&qeth_core_card_list.rwlock, flags);
124 return ndev;
125}
126
127static int qeth_l2_send_setgroupmac_cb(struct qeth_card *card,
128 struct qeth_reply *reply,
129 unsigned long data)
130{
131 struct qeth_ipa_cmd *cmd;
132 __u8 *mac;
133
Carsten Otte847a50f2010-06-21 22:57:05 +0000134 QETH_CARD_TEXT(card, 2, "L2Sgmacb");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100135 cmd = (struct qeth_ipa_cmd *) data;
136 mac = &cmd->data.setdelmac.mac[0];
137 /* MAC already registered, needed in couple/uncouple case */
Ursula Braun0666eb062009-05-19 21:38:39 +0000138 if (cmd->hdr.return_code == IPA_RC_L2_DUP_MAC) {
Johannes Berg7c510e42008-10-27 17:47:26 -0700139 QETH_DBF_MESSAGE(2, "Group MAC %pM already existing on %s \n",
140 mac, QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100141 cmd->hdr.return_code = 0;
142 }
143 if (cmd->hdr.return_code)
Johannes Berg7c510e42008-10-27 17:47:26 -0700144 QETH_DBF_MESSAGE(2, "Could not set group MAC %pM on %s: %x\n",
145 mac, QETH_CARD_IFNAME(card), cmd->hdr.return_code);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100146 return 0;
147}
148
149static int qeth_l2_send_setgroupmac(struct qeth_card *card, __u8 *mac)
150{
Carsten Otte847a50f2010-06-21 22:57:05 +0000151 QETH_CARD_TEXT(card, 2, "L2Sgmac");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100152 return qeth_l2_send_setdelmac(card, mac, IPA_CMD_SETGMAC,
153 qeth_l2_send_setgroupmac_cb);
154}
155
156static int qeth_l2_send_delgroupmac_cb(struct qeth_card *card,
157 struct qeth_reply *reply,
158 unsigned long data)
159{
160 struct qeth_ipa_cmd *cmd;
161 __u8 *mac;
162
Carsten Otte847a50f2010-06-21 22:57:05 +0000163 QETH_CARD_TEXT(card, 2, "L2Dgmacb");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100164 cmd = (struct qeth_ipa_cmd *) data;
165 mac = &cmd->data.setdelmac.mac[0];
166 if (cmd->hdr.return_code)
Johannes Berg7c510e42008-10-27 17:47:26 -0700167 QETH_DBF_MESSAGE(2, "Could not delete group MAC %pM on %s: %x\n",
168 mac, QETH_CARD_IFNAME(card), cmd->hdr.return_code);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100169 return 0;
170}
171
172static int qeth_l2_send_delgroupmac(struct qeth_card *card, __u8 *mac)
173{
Carsten Otte847a50f2010-06-21 22:57:05 +0000174 QETH_CARD_TEXT(card, 2, "L2Dgmac");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100175 return qeth_l2_send_setdelmac(card, mac, IPA_CMD_DELGMAC,
176 qeth_l2_send_delgroupmac_cb);
177}
178
Frank Blaschka7db22662008-08-15 08:02:59 +0200179static void qeth_l2_add_mc(struct qeth_card *card, __u8 *mac, int vmac)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100180{
181 struct qeth_mc_mac *mc;
Frank Blaschka7db22662008-08-15 08:02:59 +0200182 int rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100183
184 mc = kmalloc(sizeof(struct qeth_mc_mac), GFP_ATOMIC);
185
Frank Blaschka14cc21b2008-06-06 12:37:46 +0200186 if (!mc)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100187 return;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100188
189 memcpy(mc->mc_addr, mac, OSA_ADDR_LEN);
190 mc->mc_addrlen = OSA_ADDR_LEN;
Frank Blaschka7db22662008-08-15 08:02:59 +0200191 mc->is_vmac = vmac;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100192
Frank Blaschka7db22662008-08-15 08:02:59 +0200193 if (vmac) {
194 rc = qeth_l2_send_setdelmac(card, mac, IPA_CMD_SETVMAC,
195 NULL);
196 } else {
197 rc = qeth_l2_send_setgroupmac(card, mac);
198 }
199
200 if (!rc)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100201 list_add_tail(&mc->list, &card->mc_list);
202 else
203 kfree(mc);
204}
205
Ursula Braun70919e22011-02-26 22:41:36 -0800206static void qeth_l2_del_all_mc(struct qeth_card *card, int del)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100207{
208 struct qeth_mc_mac *mc, *tmp;
209
210 spin_lock_bh(&card->mclock);
211 list_for_each_entry_safe(mc, tmp, &card->mc_list, list) {
Ursula Braun70919e22011-02-26 22:41:36 -0800212 if (del) {
213 if (mc->is_vmac)
214 qeth_l2_send_setdelmac(card, mc->mc_addr,
Frank Blaschka7db22662008-08-15 08:02:59 +0200215 IPA_CMD_DELVMAC, NULL);
Ursula Braun70919e22011-02-26 22:41:36 -0800216 else
217 qeth_l2_send_delgroupmac(card, mc->mc_addr);
218 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100219 list_del(&mc->list);
220 kfree(mc);
221 }
222 spin_unlock_bh(&card->mclock);
223}
224
Klaus-Dieter Wackerce73e102009-08-26 02:01:08 +0000225static inline int qeth_l2_get_cast_type(struct qeth_card *card,
226 struct sk_buff *skb)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100227{
Klaus-Dieter Wackerce73e102009-08-26 02:01:08 +0000228 if (card->info.type == QETH_CARD_TYPE_OSN)
229 return RTN_UNSPEC;
230 if (is_broadcast_ether_addr(skb->data))
231 return RTN_BROADCAST;
232 if (is_multicast_ether_addr(skb->data))
233 return RTN_MULTICAST;
234 return RTN_UNSPEC;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100235}
236
237static void qeth_l2_fill_header(struct qeth_card *card, struct qeth_hdr *hdr,
238 struct sk_buff *skb, int ipv, int cast_type)
239{
Frank Blaschka683d7182008-08-01 16:39:13 +0200240 struct vlan_ethhdr *veth = (struct vlan_ethhdr *)skb_mac_header(skb);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100241
242 memset(hdr, 0, sizeof(struct qeth_hdr));
243 hdr->hdr.l2.id = QETH_HEADER_TYPE_LAYER2;
244
245 /* set byte byte 3 to casting flags */
246 if (cast_type == RTN_MULTICAST)
247 hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_MULTICAST;
248 else if (cast_type == RTN_BROADCAST)
249 hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_BROADCAST;
250 else
Klaus-Dieter Wackerce73e102009-08-26 02:01:08 +0000251 hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_UNICAST;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100252
253 hdr->hdr.l2.pkt_length = skb->len-QETH_HEADER_SIZE;
254 /* VSWITCH relies on the VLAN
255 * information to be present in
256 * the QDIO header */
257 if (veth->h_vlan_proto == __constant_htons(ETH_P_8021Q)) {
258 hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_VLAN;
259 hdr->hdr.l2.vlan_id = ntohs(veth->h_vlan_TCI);
260 }
261}
262
263static int qeth_l2_send_setdelvlan_cb(struct qeth_card *card,
264 struct qeth_reply *reply, unsigned long data)
265{
266 struct qeth_ipa_cmd *cmd;
267
Carsten Otte847a50f2010-06-21 22:57:05 +0000268 QETH_CARD_TEXT(card, 2, "L2sdvcb");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100269 cmd = (struct qeth_ipa_cmd *) data;
270 if (cmd->hdr.return_code) {
Frank Blaschka14cc21b2008-06-06 12:37:46 +0200271 QETH_DBF_MESSAGE(2, "Error in processing VLAN %i on %s: 0x%x. "
Frank Blaschka4a71df52008-02-15 09:19:42 +0100272 "Continuing\n", cmd->data.setdelvlan.vlan_id,
273 QETH_CARD_IFNAME(card), cmd->hdr.return_code);
Carsten Otte847a50f2010-06-21 22:57:05 +0000274 QETH_CARD_TEXT_(card, 2, "L2VL%4x", cmd->hdr.command);
275 QETH_CARD_TEXT_(card, 2, "err%d", cmd->hdr.return_code);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100276 }
277 return 0;
278}
279
280static int qeth_l2_send_setdelvlan(struct qeth_card *card, __u16 i,
281 enum qeth_ipa_cmds ipacmd)
282{
283 struct qeth_ipa_cmd *cmd;
284 struct qeth_cmd_buffer *iob;
285
Carsten Otte847a50f2010-06-21 22:57:05 +0000286 QETH_CARD_TEXT_(card, 4, "L2sdv%x", ipacmd);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100287 iob = qeth_get_ipacmd_buffer(card, ipacmd, QETH_PROT_IPV4);
288 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
289 cmd->data.setdelvlan.vlan_id = i;
290 return qeth_send_ipa_cmd(card, iob,
291 qeth_l2_send_setdelvlan_cb, NULL);
292}
293
Ursula Braun70919e22011-02-26 22:41:36 -0800294static void qeth_l2_process_vlans(struct qeth_card *card)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100295{
296 struct qeth_vlan_vid *id;
Carsten Otte847a50f2010-06-21 22:57:05 +0000297 QETH_CARD_TEXT(card, 3, "L2prcvln");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100298 spin_lock_bh(&card->vlanlock);
299 list_for_each_entry(id, &card->vid_list, list) {
Ursula Braun70919e22011-02-26 22:41:36 -0800300 qeth_l2_send_setdelvlan(card, id->vid, IPA_CMD_SETVLAN);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100301 }
302 spin_unlock_bh(&card->vlanlock);
303}
304
Jiri Pirko8e586132011-12-08 19:52:37 -0500305static int qeth_l2_vlan_rx_add_vid(struct net_device *dev, unsigned short vid)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100306{
Heiko Carstens509e2562008-07-26 02:24:10 -0700307 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100308 struct qeth_vlan_vid *id;
309
Carsten Otte847a50f2010-06-21 22:57:05 +0000310 QETH_CARD_TEXT_(card, 4, "aid:%d", vid);
Ursula Braun10651db2010-10-01 02:51:13 +0000311 if (!vid)
Jiri Pirko8e586132011-12-08 19:52:37 -0500312 return 0;
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");
Jiri Pirko8e586132011-12-08 19:52:37 -0500315 return 0;
Ursula Braun5113fec2010-05-16 21:15:14 +0000316 }
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");
Jiri Pirko8e586132011-12-08 19:52:37 -0500319 return 0;
Ursula Braun8e98ac42009-03-24 20:57:18 +0000320 }
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);
Jiri Pirko8e586132011-12-08 19:52:37 -0500328 } else {
329 return -ENOMEM;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100330 }
Jiri Pirko8e586132011-12-08 19:52:37 -0500331 return 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100332}
333
Jiri Pirko8e586132011-12-08 19:52:37 -0500334static int qeth_l2_vlan_rx_kill_vid(struct net_device *dev, unsigned short vid)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100335{
336 struct qeth_vlan_vid *id, *tmpid = NULL;
Heiko Carstens509e2562008-07-26 02:24:10 -0700337 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100338
Carsten Otte847a50f2010-06-21 22:57:05 +0000339 QETH_CARD_TEXT_(card, 4, "kid:%d", vid);
Ursula Braun5113fec2010-05-16 21:15:14 +0000340 if (card->info.type == QETH_CARD_TYPE_OSM) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000341 QETH_CARD_TEXT(card, 3, "kidOSM");
Jiri Pirko8e586132011-12-08 19:52:37 -0500342 return 0;
Ursula Braun5113fec2010-05-16 21:15:14 +0000343 }
Ursula Braun8e98ac42009-03-24 20:57:18 +0000344 if (qeth_wait_for_threads(card, QETH_RECOVER_THREAD)) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000345 QETH_CARD_TEXT(card, 3, "kidREC");
Jiri Pirko8e586132011-12-08 19:52:37 -0500346 return 0;
Ursula Braun8e98ac42009-03-24 20:57:18 +0000347 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100348 spin_lock_bh(&card->vlanlock);
349 list_for_each_entry(id, &card->vid_list, list) {
350 if (id->vid == vid) {
351 list_del(&id->list);
352 tmpid = id;
353 break;
354 }
355 }
356 spin_unlock_bh(&card->vlanlock);
357 if (tmpid) {
358 qeth_l2_send_setdelvlan(card, vid, IPA_CMD_DELVLAN);
359 kfree(tmpid);
360 }
361 qeth_l2_set_multicast_list(card->dev);
Jiri Pirko8e586132011-12-08 19:52:37 -0500362 return 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100363}
364
365static int qeth_l2_stop_card(struct qeth_card *card, int recovery_mode)
366{
367 int rc = 0;
368
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200369 QETH_DBF_TEXT(SETUP , 2, "stopcard");
370 QETH_DBF_HEX(SETUP, 2, &card, sizeof(void *));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100371
372 qeth_set_allowed_threads(card, 0, 1);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100373 if (card->read.state == CH_STATE_UP &&
374 card->write.state == CH_STATE_UP &&
375 (card->state == CARD_STATE_UP)) {
376 if (recovery_mode &&
377 card->info.type != QETH_CARD_TYPE_OSN) {
378 qeth_l2_stop(card->dev);
379 } else {
380 rtnl_lock();
381 dev_close(card->dev);
382 rtnl_unlock();
383 }
Ursula Braun70919e22011-02-26 22:41:36 -0800384 card->info.mac_bits &= ~QETH_LAYER2_MAC_REGISTERED;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100385 card->state = CARD_STATE_SOFTSETUP;
386 }
387 if (card->state == CARD_STATE_SOFTSETUP) {
Ursula Braun70919e22011-02-26 22:41:36 -0800388 qeth_l2_del_all_mc(card, 0);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100389 qeth_clear_ipacmd_list(card);
390 card->state = CARD_STATE_HARDSETUP;
391 }
392 if (card->state == CARD_STATE_HARDSETUP) {
393 qeth_qdio_clear_card(card, 0);
394 qeth_clear_qdio_buffers(card);
395 qeth_clear_working_pool_list(card);
396 card->state = CARD_STATE_DOWN;
397 }
398 if (card->state == CARD_STATE_DOWN) {
399 qeth_clear_cmd_buffers(&card->read);
400 qeth_clear_cmd_buffers(&card->write);
401 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100402 return rc;
403}
404
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000405static int qeth_l2_process_inbound_buffer(struct qeth_card *card,
406 int budget, int *done)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100407{
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000408 int work_done = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100409 struct sk_buff *skb;
410 struct qeth_hdr *hdr;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100411 unsigned int len;
412
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000413 *done = 0;
Stefan Raspl18af5c12012-11-19 02:46:50 +0000414 WARN_ON_ONCE(!budget);
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000415 while (budget) {
416 skb = qeth_core_get_next_skb(card,
Frank Blaschkab3332932011-08-08 01:33:59 +0000417 &card->qdio.in_q->bufs[card->rx.b_index],
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000418 &card->rx.b_element, &card->rx.e_offset, &hdr);
419 if (!skb) {
420 *done = 1;
421 break;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100422 }
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000423 skb->dev = card->dev;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100424 switch (hdr->hdr.l2.id) {
425 case QETH_HEADER_TYPE_LAYER2:
426 skb->pkt_type = PACKET_HOST;
427 skb->protocol = eth_type_trans(skb, skb->dev);
Frank Blaschkac5e631a2011-05-12 18:45:01 +0000428 skb->ip_summed = CHECKSUM_NONE;
Ursula Braun12883722008-04-01 10:26:56 +0200429 if (skb->protocol == htons(ETH_P_802_2))
430 *((__u32 *)skb->cb) = ++card->seqno.pkt_seqno;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100431 len = skb->len;
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000432 netif_receive_skb(skb);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100433 break;
434 case QETH_HEADER_TYPE_OSN:
Ursula Braun2d488c22008-10-24 11:16:55 +0200435 if (card->info.type == QETH_CARD_TYPE_OSN) {
436 skb_push(skb, sizeof(struct qeth_hdr));
437 skb_copy_to_linear_data(skb, hdr,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100438 sizeof(struct qeth_hdr));
Ursula Braun2d488c22008-10-24 11:16:55 +0200439 len = skb->len;
440 card->osn_info.data_cb(skb);
441 break;
442 }
443 /* else unknown */
Frank Blaschka4a71df52008-02-15 09:19:42 +0100444 default:
445 dev_kfree_skb_any(skb);
Carsten Otte847a50f2010-06-21 22:57:05 +0000446 QETH_CARD_TEXT(card, 3, "inbunkno");
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200447 QETH_DBF_HEX(CTRL, 3, hdr, QETH_DBF_CTRL_LEN);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100448 continue;
449 }
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000450 work_done++;
451 budget--;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100452 card->stats.rx_packets++;
453 card->stats.rx_bytes += len;
454 }
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000455 return work_done;
456}
457
458static int qeth_l2_poll(struct napi_struct *napi, int budget)
459{
460 struct qeth_card *card = container_of(napi, struct qeth_card, napi);
461 int work_done = 0;
462 struct qeth_qdio_buffer *buffer;
463 int done;
464 int new_budget = budget;
465
466 if (card->options.performance_stats) {
467 card->perf_stats.inbound_cnt++;
468 card->perf_stats.inbound_start_time = qeth_get_micros();
469 }
470
471 while (1) {
472 if (!card->rx.b_count) {
473 card->rx.qdio_err = 0;
474 card->rx.b_count = qdio_get_next_buffers(
475 card->data.ccwdev, 0, &card->rx.b_index,
476 &card->rx.qdio_err);
477 if (card->rx.b_count <= 0) {
478 card->rx.b_count = 0;
479 break;
480 }
481 card->rx.b_element =
482 &card->qdio.in_q->bufs[card->rx.b_index]
483 .buffer->element[0];
484 card->rx.e_offset = 0;
485 }
486
487 while (card->rx.b_count) {
488 buffer = &card->qdio.in_q->bufs[card->rx.b_index];
489 if (!(card->rx.qdio_err &&
490 qeth_check_qdio_errors(card, buffer->buffer,
491 card->rx.qdio_err, "qinerr")))
492 work_done += qeth_l2_process_inbound_buffer(
493 card, new_budget, &done);
494 else
495 done = 1;
496
497 if (done) {
498 if (card->options.performance_stats)
499 card->perf_stats.bufs_rec++;
500 qeth_put_buffer_pool_entry(card,
501 buffer->pool_entry);
502 qeth_queue_input_buffer(card, card->rx.b_index);
503 card->rx.b_count--;
504 if (card->rx.b_count) {
505 card->rx.b_index =
506 (card->rx.b_index + 1) %
507 QDIO_MAX_BUFFERS_PER_Q;
508 card->rx.b_element =
509 &card->qdio.in_q
510 ->bufs[card->rx.b_index]
511 .buffer->element[0];
512 card->rx.e_offset = 0;
513 }
514 }
515
516 if (work_done >= budget)
517 goto out;
518 else
519 new_budget = budget - work_done;
520 }
521 }
522
523 napi_complete(napi);
524 if (qdio_start_irq(card->data.ccwdev, 0))
525 napi_schedule(&card->napi);
526out:
527 if (card->options.performance_stats)
528 card->perf_stats.inbound_time += qeth_get_micros() -
529 card->perf_stats.inbound_start_time;
530 return work_done;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100531}
532
533static int qeth_l2_send_setdelmac(struct qeth_card *card, __u8 *mac,
534 enum qeth_ipa_cmds ipacmd,
535 int (*reply_cb) (struct qeth_card *,
536 struct qeth_reply*,
537 unsigned long))
538{
539 struct qeth_ipa_cmd *cmd;
540 struct qeth_cmd_buffer *iob;
541
Carsten Otte847a50f2010-06-21 22:57:05 +0000542 QETH_CARD_TEXT(card, 2, "L2sdmac");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100543 iob = qeth_get_ipacmd_buffer(card, ipacmd, QETH_PROT_IPV4);
544 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
545 cmd->data.setdelmac.mac_length = OSA_ADDR_LEN;
546 memcpy(&cmd->data.setdelmac.mac, mac, OSA_ADDR_LEN);
547 return qeth_send_ipa_cmd(card, iob, reply_cb, NULL);
548}
549
550static int qeth_l2_send_setmac_cb(struct qeth_card *card,
551 struct qeth_reply *reply,
552 unsigned long data)
553{
554 struct qeth_ipa_cmd *cmd;
555
Carsten Otte847a50f2010-06-21 22:57:05 +0000556 QETH_CARD_TEXT(card, 2, "L2Smaccb");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100557 cmd = (struct qeth_ipa_cmd *) data;
558 if (cmd->hdr.return_code) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000559 QETH_CARD_TEXT_(card, 2, "L2er%x", cmd->hdr.return_code);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100560 card->info.mac_bits &= ~QETH_LAYER2_MAC_REGISTERED;
Ursula Braun0666eb062009-05-19 21:38:39 +0000561 switch (cmd->hdr.return_code) {
562 case IPA_RC_L2_DUP_MAC:
563 case IPA_RC_L2_DUP_LAYER3_MAC:
564 dev_warn(&card->gdev->dev,
H Hartley Sweetend998ab02009-12-29 20:05:37 -0800565 "MAC address %pM already exists\n",
Ursula Braun221c17f2011-02-02 06:04:31 +0000566 cmd->data.setdelmac.mac);
Ursula Braun0666eb062009-05-19 21:38:39 +0000567 break;
568 case IPA_RC_L2_MAC_NOT_AUTH_BY_HYP:
569 case IPA_RC_L2_MAC_NOT_AUTH_BY_ADP:
570 dev_warn(&card->gdev->dev,
H Hartley Sweetend998ab02009-12-29 20:05:37 -0800571 "MAC address %pM is not authorized\n",
Ursula Braun221c17f2011-02-02 06:04:31 +0000572 cmd->data.setdelmac.mac);
Ursula Braun0666eb062009-05-19 21:38:39 +0000573 break;
574 default:
575 break;
576 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100577 } else {
578 card->info.mac_bits |= QETH_LAYER2_MAC_REGISTERED;
579 memcpy(card->dev->dev_addr, cmd->data.setdelmac.mac,
580 OSA_ADDR_LEN);
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100581 dev_info(&card->gdev->dev,
H Hartley Sweetend998ab02009-12-29 20:05:37 -0800582 "MAC address %pM successfully registered on device %s\n",
583 card->dev->dev_addr, card->dev->name);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100584 }
585 return 0;
586}
587
588static int qeth_l2_send_setmac(struct qeth_card *card, __u8 *mac)
589{
Carsten Otte847a50f2010-06-21 22:57:05 +0000590 QETH_CARD_TEXT(card, 2, "L2Setmac");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100591 return qeth_l2_send_setdelmac(card, mac, IPA_CMD_SETVMAC,
592 qeth_l2_send_setmac_cb);
593}
594
595static int qeth_l2_send_delmac_cb(struct qeth_card *card,
596 struct qeth_reply *reply,
597 unsigned long data)
598{
599 struct qeth_ipa_cmd *cmd;
600
Carsten Otte847a50f2010-06-21 22:57:05 +0000601 QETH_CARD_TEXT(card, 2, "L2Dmaccb");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100602 cmd = (struct qeth_ipa_cmd *) data;
603 if (cmd->hdr.return_code) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000604 QETH_CARD_TEXT_(card, 2, "err%d", cmd->hdr.return_code);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100605 return 0;
606 }
607 card->info.mac_bits &= ~QETH_LAYER2_MAC_REGISTERED;
608
609 return 0;
610}
611
612static int qeth_l2_send_delmac(struct qeth_card *card, __u8 *mac)
613{
Carsten Otte847a50f2010-06-21 22:57:05 +0000614 QETH_CARD_TEXT(card, 2, "L2Delmac");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100615 if (!(card->info.mac_bits & QETH_LAYER2_MAC_REGISTERED))
616 return 0;
617 return qeth_l2_send_setdelmac(card, mac, IPA_CMD_DELVMAC,
618 qeth_l2_send_delmac_cb);
619}
620
621static int qeth_l2_request_initial_mac(struct qeth_card *card)
622{
623 int rc = 0;
624 char vendor_pre[] = {0x02, 0x00, 0x00};
625
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200626 QETH_DBF_TEXT(SETUP, 2, "doL2init");
627 QETH_DBF_TEXT_(SETUP, 2, "doL2%s", CARD_BUS_ID(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100628
Stefan Raspla1348842012-11-12 23:05:16 +0000629 if (qeth_is_supported(card, IPA_SETADAPTERPARMS)) {
630 rc = qeth_query_setadapterparms(card);
631 if (rc) {
632 QETH_DBF_MESSAGE(2, "could not query adapter "
633 "parameters on device %s: x%x\n",
634 CARD_BUS_ID(card), rc);
635 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100636 }
637
Ursula Braun5113fec2010-05-16 21:15:14 +0000638 if (card->info.type == QETH_CARD_TYPE_IQD ||
639 card->info.type == QETH_CARD_TYPE_OSM ||
640 card->info.type == QETH_CARD_TYPE_OSX ||
641 card->info.guestlan) {
Frank Blaschka4a71df52008-02-15 09:19:42 +0100642 rc = qeth_setadpparms_change_macaddr(card);
643 if (rc) {
Frank Blaschka14cc21b2008-06-06 12:37:46 +0200644 QETH_DBF_MESSAGE(2, "couldn't get MAC address on "
645 "device %s: x%x\n", CARD_BUS_ID(card), rc);
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200646 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100647 return rc;
648 }
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200649 QETH_DBF_HEX(SETUP, 2, card->dev->dev_addr, OSA_ADDR_LEN);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100650 } else {
Joe Perches18336112012-07-12 22:33:10 -0700651 eth_random_addr(card->dev->dev_addr);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100652 memcpy(card->dev->dev_addr, vendor_pre, 3);
653 }
654 return 0;
655}
656
657static int qeth_l2_set_mac_address(struct net_device *dev, void *p)
658{
659 struct sockaddr *addr = p;
Heiko Carstens509e2562008-07-26 02:24:10 -0700660 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100661 int rc = 0;
662
Carsten Otte847a50f2010-06-21 22:57:05 +0000663 QETH_CARD_TEXT(card, 3, "setmac");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100664
665 if (qeth_l2_verify_dev(dev) != QETH_REAL_CARD) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000666 QETH_CARD_TEXT(card, 3, "setmcINV");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100667 return -EOPNOTSUPP;
668 }
669
Ursula Braun5113fec2010-05-16 21:15:14 +0000670 if (card->info.type == QETH_CARD_TYPE_OSN ||
671 card->info.type == QETH_CARD_TYPE_OSM ||
672 card->info.type == QETH_CARD_TYPE_OSX) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000673 QETH_CARD_TEXT(card, 3, "setmcTYP");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100674 return -EOPNOTSUPP;
675 }
Carsten Otte847a50f2010-06-21 22:57:05 +0000676 QETH_CARD_HEX(card, 3, addr->sa_data, OSA_ADDR_LEN);
Ursula Braun8e98ac42009-03-24 20:57:18 +0000677 if (qeth_wait_for_threads(card, QETH_RECOVER_THREAD)) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000678 QETH_CARD_TEXT(card, 3, "setmcREC");
Ursula Braun8e98ac42009-03-24 20:57:18 +0000679 return -ERESTARTSYS;
680 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100681 rc = qeth_l2_send_delmac(card, &card->dev->dev_addr[0]);
Ursula Braun77027452012-11-12 23:05:17 +0000682 if (!rc || (rc == IPA_RC_L2_MAC_NOT_FOUND))
Frank Blaschka4a71df52008-02-15 09:19:42 +0100683 rc = qeth_l2_send_setmac(card, addr->sa_data);
Ursula Braune0a81142012-03-07 02:06:28 +0000684 return rc ? -EINVAL : 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100685}
686
687static void qeth_l2_set_multicast_list(struct net_device *dev)
688{
Heiko Carstens509e2562008-07-26 02:24:10 -0700689 struct qeth_card *card = dev->ml_priv;
Jiri Pirkoccffad252009-05-22 23:22:17 +0000690 struct netdev_hw_addr *ha;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100691
692 if (card->info.type == QETH_CARD_TYPE_OSN)
693 return ;
694
Carsten Otte847a50f2010-06-21 22:57:05 +0000695 QETH_CARD_TEXT(card, 3, "setmulti");
Ursula Braun8e98ac42009-03-24 20:57:18 +0000696 if (qeth_threads_running(card, QETH_RECOVER_THREAD) &&
697 (card->state != CARD_STATE_UP))
698 return;
Ursula Braun70919e22011-02-26 22:41:36 -0800699 qeth_l2_del_all_mc(card, 1);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100700 spin_lock_bh(&card->mclock);
Jiri Pirko22bedad32010-04-01 21:22:57 +0000701 netdev_for_each_mc_addr(ha, dev)
702 qeth_l2_add_mc(card, ha->addr, 0);
Frank Blaschka7db22662008-08-15 08:02:59 +0200703
Jiri Pirko32e7bfc2010-01-25 13:36:10 -0800704 netdev_for_each_uc_addr(ha, dev)
Jiri Pirkoccffad252009-05-22 23:22:17 +0000705 qeth_l2_add_mc(card, ha->addr, 1);
Frank Blaschka7db22662008-08-15 08:02:59 +0200706
Frank Blaschka4a71df52008-02-15 09:19:42 +0100707 spin_unlock_bh(&card->mclock);
708 if (!qeth_adp_supported(card, IPA_SETADP_SET_PROMISC_MODE))
709 return;
710 qeth_setadp_promisc_mode(card);
711}
712
713static int qeth_l2_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
714{
715 int rc;
716 struct qeth_hdr *hdr = NULL;
717 int elements = 0;
Heiko Carstens509e2562008-07-26 02:24:10 -0700718 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100719 struct sk_buff *new_skb = skb;
720 int ipv = qeth_get_ip_version(skb);
Klaus-Dieter Wackerce73e102009-08-26 02:01:08 +0000721 int cast_type = qeth_l2_get_cast_type(card, skb);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100722 struct qeth_qdio_out_q *queue = card->qdio.out_qs
723 [qeth_get_priority_queue(card, skb, ipv, cast_type)];
724 int tx_bytes = skb->len;
Frank Blaschka683d7182008-08-01 16:39:13 +0200725 int data_offset = -1;
726 int elements_needed = 0;
727 int hd_len = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100728
Frank Blaschka4a71df52008-02-15 09:19:42 +0100729 if ((card->state != CARD_STATE_UP) || !card->lan_online) {
730 card->stats.tx_carrier_errors++;
731 goto tx_drop;
732 }
733
734 if ((card->info.type == QETH_CARD_TYPE_OSN) &&
735 (skb->protocol == htons(ETH_P_IPV6)))
736 goto tx_drop;
737
738 if (card->options.performance_stats) {
739 card->perf_stats.outbound_cnt++;
740 card->perf_stats.outbound_start_time = qeth_get_micros();
741 }
742 netif_stop_queue(dev);
743
Frank Blaschka4a71df52008-02-15 09:19:42 +0100744 if (card->info.type == QETH_CARD_TYPE_OSN)
745 hdr = (struct qeth_hdr *)skb->data;
746 else {
Frank Blaschka64ef8952009-03-24 20:57:16 +0000747 if (card->info.type == QETH_CARD_TYPE_IQD) {
Frank Blaschka683d7182008-08-01 16:39:13 +0200748 new_skb = skb;
749 data_offset = ETH_HLEN;
750 hd_len = ETH_HLEN;
751 hdr = kmem_cache_alloc(qeth_core_header_cache,
752 GFP_ATOMIC);
753 if (!hdr)
754 goto tx_drop;
755 elements_needed++;
756 skb_reset_mac_header(new_skb);
757 qeth_l2_fill_header(card, hdr, new_skb, ipv, cast_type);
758 hdr->hdr.l2.pkt_length = new_skb->len;
759 memcpy(((char *)hdr) + sizeof(struct qeth_hdr),
760 skb_mac_header(new_skb), ETH_HLEN);
761 } else {
762 /* create a clone with writeable headroom */
763 new_skb = skb_realloc_headroom(skb,
Frank Blaschkaf90b7442008-04-24 10:15:24 +0200764 sizeof(struct qeth_hdr));
Frank Blaschka683d7182008-08-01 16:39:13 +0200765 if (!new_skb)
766 goto tx_drop;
767 hdr = (struct qeth_hdr *)skb_push(new_skb,
768 sizeof(struct qeth_hdr));
769 skb_set_mac_header(new_skb, sizeof(struct qeth_hdr));
770 qeth_l2_fill_header(card, hdr, new_skb, ipv, cast_type);
771 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100772 }
773
Frank Blaschka64ef8952009-03-24 20:57:16 +0000774 elements = qeth_get_elements_no(card, (void *)hdr, new_skb,
Frank Blaschka683d7182008-08-01 16:39:13 +0200775 elements_needed);
Frank Blaschka64ef8952009-03-24 20:57:16 +0000776 if (!elements) {
777 if (data_offset >= 0)
778 kmem_cache_free(qeth_core_header_cache, hdr);
779 goto tx_drop;
Frank Blaschkaf61a0d02009-03-24 20:57:15 +0000780 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100781
Frank Blaschka51aa1652010-06-21 22:57:10 +0000782 if (card->info.type != QETH_CARD_TYPE_IQD) {
783 if (qeth_hdr_chk_and_bounce(new_skb,
784 sizeof(struct qeth_hdr_layer2)))
785 goto tx_drop;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100786 rc = qeth_do_send_packet(card, queue, new_skb, hdr,
Frank Blaschka64ef8952009-03-24 20:57:16 +0000787 elements);
Frank Blaschka51aa1652010-06-21 22:57:10 +0000788 } else
Frank Blaschka4a71df52008-02-15 09:19:42 +0100789 rc = qeth_do_send_packet_fast(card, queue, new_skb, hdr,
Frank Blaschka64ef8952009-03-24 20:57:16 +0000790 elements, data_offset, hd_len);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100791 if (!rc) {
792 card->stats.tx_packets++;
793 card->stats.tx_bytes += tx_bytes;
794 if (new_skb != skb)
795 dev_kfree_skb_any(skb);
Patrick McHardyec634fe2009-07-05 19:23:38 -0700796 rc = NETDEV_TX_OK;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100797 } else {
Frank Blaschka683d7182008-08-01 16:39:13 +0200798 if (data_offset >= 0)
799 kmem_cache_free(qeth_core_header_cache, hdr);
800
Frank Blaschka4a71df52008-02-15 09:19:42 +0100801 if (rc == -EBUSY) {
802 if (new_skb != skb)
803 dev_kfree_skb_any(new_skb);
804 return NETDEV_TX_BUSY;
805 } else
806 goto tx_drop;
807 }
808
809 netif_wake_queue(dev);
810 if (card->options.performance_stats)
811 card->perf_stats.outbound_time += qeth_get_micros() -
812 card->perf_stats.outbound_start_time;
813 return rc;
814
815tx_drop:
816 card->stats.tx_dropped++;
817 card->stats.tx_errors++;
818 if ((new_skb != skb) && new_skb)
819 dev_kfree_skb_any(new_skb);
820 dev_kfree_skb_any(skb);
Frank Blaschkad0ec0f52008-06-06 12:37:48 +0200821 netif_wake_queue(dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100822 return NETDEV_TX_OK;
823}
824
Ursula Braun39423442011-01-12 20:42:24 +0000825static int __qeth_l2_open(struct net_device *dev)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100826{
Heiko Carstens509e2562008-07-26 02:24:10 -0700827 struct qeth_card *card = dev->ml_priv;
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000828 int rc = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100829
Carsten Otte847a50f2010-06-21 22:57:05 +0000830 QETH_CARD_TEXT(card, 4, "qethopen");
Ursula Braun39423442011-01-12 20:42:24 +0000831 if (card->state == CARD_STATE_UP)
832 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100833 if (card->state != CARD_STATE_SOFTSETUP)
834 return -ENODEV;
835
836 if ((card->info.type != QETH_CARD_TYPE_OSN) &&
837 (!(card->info.mac_bits & QETH_LAYER2_MAC_REGISTERED))) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000838 QETH_CARD_TEXT(card, 4, "nomacadr");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100839 return -EPERM;
840 }
841 card->data.state = CH_STATE_UP;
842 card->state = CARD_STATE_UP;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100843 netif_start_queue(dev);
844
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000845 if (qdio_stop_irq(card->data.ccwdev, 0) >= 0) {
846 napi_enable(&card->napi);
847 napi_schedule(&card->napi);
848 } else
849 rc = -EIO;
850 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100851}
852
Ursula Braun39423442011-01-12 20:42:24 +0000853static int qeth_l2_open(struct net_device *dev)
854{
855 struct qeth_card *card = dev->ml_priv;
856
857 QETH_CARD_TEXT(card, 5, "qethope_");
858 if (qeth_wait_for_threads(card, QETH_RECOVER_THREAD)) {
859 QETH_CARD_TEXT(card, 3, "openREC");
860 return -ERESTARTSYS;
861 }
862 return __qeth_l2_open(dev);
863}
864
Frank Blaschka4a71df52008-02-15 09:19:42 +0100865static int qeth_l2_stop(struct net_device *dev)
866{
Heiko Carstens509e2562008-07-26 02:24:10 -0700867 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100868
Carsten Otte847a50f2010-06-21 22:57:05 +0000869 QETH_CARD_TEXT(card, 4, "qethstop");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100870 netif_tx_disable(dev);
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000871 if (card->state == CARD_STATE_UP) {
Frank Blaschka4a71df52008-02-15 09:19:42 +0100872 card->state = CARD_STATE_SOFTSETUP;
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000873 napi_disable(&card->napi);
874 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100875 return 0;
876}
877
878static int qeth_l2_probe_device(struct ccwgroup_device *gdev)
879{
880 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
881
882 INIT_LIST_HEAD(&card->vid_list);
883 INIT_LIST_HEAD(&card->mc_list);
884 card->options.layer2 = 1;
Frank Blaschka1da74b12011-05-12 18:45:02 +0000885 card->info.hwtrap = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100886 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
Ursula Braun70919e22011-02-26 22:41:36 -0800896 if (cgdev->state == CCWGROUP_ONLINE)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100897 qeth_l2_set_offline(cgdev);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100898
899 if (card->dev) {
900 unregister_netdev(card->dev);
901 card->dev = NULL;
902 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100903 return;
904}
905
Stephen Hemminger0fc0b732009-09-02 01:03:33 -0700906static const struct ethtool_ops qeth_l2_ethtool_ops = {
Frank Blaschka4a71df52008-02-15 09:19:42 +0100907 .get_link = ethtool_op_get_link,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100908 .get_strings = qeth_core_get_strings,
909 .get_ethtool_stats = qeth_core_get_ethtool_stats,
Ben Hutchingsdf8b4ec2009-10-01 11:24:32 +0000910 .get_sset_count = qeth_core_get_sset_count,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100911 .get_drvinfo = qeth_core_get_drvinfo,
Frank Blaschka3f9975a2008-04-24 10:15:23 +0200912 .get_settings = qeth_core_ethtool_get_settings,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100913};
914
Stephen Hemminger0fc0b732009-09-02 01:03:33 -0700915static const struct ethtool_ops qeth_l2_osn_ops = {
Frank Blaschka4a71df52008-02-15 09:19:42 +0100916 .get_strings = qeth_core_get_strings,
917 .get_ethtool_stats = qeth_core_get_ethtool_stats,
Ben Hutchingsdf8b4ec2009-10-01 11:24:32 +0000918 .get_sset_count = qeth_core_get_sset_count,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100919 .get_drvinfo = qeth_core_get_drvinfo,
920};
921
Frank Blaschka3d58cef2009-01-09 03:44:00 +0000922static const struct net_device_ops qeth_l2_netdev_ops = {
Frank Blaschka8403b132009-01-08 10:50:55 -0800923 .ndo_open = qeth_l2_open,
924 .ndo_stop = qeth_l2_stop,
925 .ndo_get_stats = qeth_get_stats,
926 .ndo_start_xmit = qeth_l2_hard_start_xmit,
927 .ndo_validate_addr = eth_validate_addr,
Jiri Pirkoafc4b132011-08-16 06:29:01 +0000928 .ndo_set_rx_mode = qeth_l2_set_multicast_list,
Frank Blaschka8403b132009-01-08 10:50:55 -0800929 .ndo_do_ioctl = qeth_l2_do_ioctl,
930 .ndo_set_mac_address = qeth_l2_set_mac_address,
931 .ndo_change_mtu = qeth_change_mtu,
932 .ndo_vlan_rx_add_vid = qeth_l2_vlan_rx_add_vid,
933 .ndo_vlan_rx_kill_vid = qeth_l2_vlan_rx_kill_vid,
934 .ndo_tx_timeout = qeth_tx_timeout,
935};
936
Frank Blaschka4a71df52008-02-15 09:19:42 +0100937static int qeth_l2_setup_netdev(struct qeth_card *card)
938{
939 switch (card->info.type) {
Frank Blaschka4a71df52008-02-15 09:19:42 +0100940 case QETH_CARD_TYPE_IQD:
941 card->dev = alloc_netdev(0, "hsi%d", ether_setup);
942 break;
943 case QETH_CARD_TYPE_OSN:
944 card->dev = alloc_netdev(0, "osn%d", ether_setup);
945 card->dev->flags |= IFF_NOARP;
946 break;
947 default:
948 card->dev = alloc_etherdev(0);
949 }
950
951 if (!card->dev)
952 return -ENODEV;
953
Heiko Carstens509e2562008-07-26 02:24:10 -0700954 card->dev->ml_priv = card;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100955 card->dev->watchdog_timeo = QETH_TX_TIMEOUT;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100956 card->dev->mtu = card->info.initial_mtu;
Frank Blaschka8403b132009-01-08 10:50:55 -0800957 card->dev->netdev_ops = &qeth_l2_netdev_ops;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100958 if (card->info.type != QETH_CARD_TYPE_OSN)
959 SET_ETHTOOL_OPS(card->dev, &qeth_l2_ethtool_ops);
960 else
961 SET_ETHTOOL_OPS(card->dev, &qeth_l2_osn_ops);
962 card->dev->features |= NETIF_F_HW_VLAN_FILTER;
963 card->info.broadcast_capable = 1;
964 qeth_l2_request_initial_mac(card);
965 SET_NETDEV_DEV(card->dev, &card->gdev->dev);
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000966 netif_napi_add(card->dev, &card->napi, qeth_l2_poll, QETH_NAPI_WEIGHT);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100967 return register_netdev(card->dev);
968}
969
970static int __qeth_l2_set_online(struct ccwgroup_device *gdev, int recovery_mode)
971{
972 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
973 int rc = 0;
974 enum qeth_card_states recover_flag;
975
Ursula Braun9dc48cc2010-07-22 23:15:05 +0000976 mutex_lock(&card->discipline_mutex);
Frank Blaschkac4949f02010-05-11 19:34:47 +0000977 mutex_lock(&card->conf_mutex);
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200978 QETH_DBF_TEXT(SETUP, 2, "setonlin");
979 QETH_DBF_HEX(SETUP, 2, &card, sizeof(void *));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100980
Frank Blaschka4a71df52008-02-15 09:19:42 +0100981 recover_flag = card->state;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100982 rc = qeth_core_hardsetup_card(card);
983 if (rc) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200984 QETH_DBF_TEXT_(SETUP, 2, "2err%d", rc);
Ursula Braunaa909222009-11-12 00:11:43 +0000985 rc = -ENODEV;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100986 goto out_remove;
987 }
Stefan Raspl395672e02012-11-19 02:46:49 +0000988 qeth_trace_features(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100989
Ursula Braunaa909222009-11-12 00:11:43 +0000990 if (!card->dev && qeth_l2_setup_netdev(card)) {
991 rc = -ENODEV;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100992 goto out_remove;
Ursula Braunaa909222009-11-12 00:11:43 +0000993 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100994
995 if (card->info.type != QETH_CARD_TYPE_OSN)
996 qeth_l2_send_setmac(card, &card->dev->dev_addr[0]);
997
Frank Blaschka1da74b12011-05-12 18:45:02 +0000998 if (qeth_is_diagass_supported(card, QETH_DIAGS_CMD_TRAP)) {
999 if (card->info.hwtrap &&
1000 qeth_hw_trap(card, QETH_DIAGS_TRAP_ARM))
1001 card->info.hwtrap = 0;
1002 } else
1003 card->info.hwtrap = 0;
1004
Frank Blaschka4a71df52008-02-15 09:19:42 +01001005 card->state = CARD_STATE_HARDSETUP;
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00001006 memset(&card->rx, 0, sizeof(struct qeth_rx));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001007 qeth_print_status_message(card);
1008
1009 /* softsetup */
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001010 QETH_DBF_TEXT(SETUP, 2, "softsetp");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001011
1012 rc = qeth_send_startlan(card);
1013 if (rc) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001014 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001015 if (rc == 0xe080) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001016 dev_warn(&card->gdev->dev,
1017 "The LAN is offline\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001018 card->lan_online = 0;
Ursula Braun2b6203b2010-11-26 02:41:19 +00001019 goto contin;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001020 }
Ursula Braunaa909222009-11-12 00:11:43 +00001021 rc = -ENODEV;
Ursula Braunf2148562009-05-19 21:38:37 +00001022 goto out_remove;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001023 } else
1024 card->lan_online = 1;
1025
Ursula Braun2b6203b2010-11-26 02:41:19 +00001026contin:
Ursula Braun5113fec2010-05-16 21:15:14 +00001027 if ((card->info.type == QETH_CARD_TYPE_OSD) ||
Stefan Raspl0f547612013-01-21 02:30:20 +00001028 (card->info.type == QETH_CARD_TYPE_OSX)) {
Einar Lueckd64ecc22009-11-12 00:11:41 +00001029 /* configure isolation level */
Stefan Raspl0f547612013-01-21 02:30:20 +00001030 rc = qeth_set_access_ctrl_online(card, 0);
1031 if (rc) {
1032 rc = -ENODEV;
1033 goto out_remove;
1034 }
1035 }
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 {
Stefan Raspl0f547612013-01-21 02:30:20 +00001152 qeth_close_dev(card);
1153 dev_warn(&card->gdev->dev, "The qeth device driver "
Stefan Raspl2efaf5f2012-10-15 19:21:18 +00001154 "failed to recover an error on the device\n");
Ursula Braun28a7e4c2008-09-19 12:56:03 +02001155 }
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00001156 qeth_clear_thread_start_bit(card, QETH_RECOVER_THREAD);
1157 qeth_clear_thread_running_bit(card, QETH_RECOVER_THREAD);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001158 return 0;
1159}
1160
1161static int __init qeth_l2_init(void)
1162{
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001163 pr_info("register layer 2 discipline\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001164 return 0;
1165}
1166
1167static void __exit qeth_l2_exit(void)
1168{
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001169 pr_info("unregister layer 2 discipline\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001170}
1171
1172static void qeth_l2_shutdown(struct ccwgroup_device *gdev)
1173{
1174 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
Ursula Braunf78ac2b2011-12-19 22:56:33 +00001175 qeth_set_allowed_threads(card, 0, 1);
Frank Blaschka1da74b12011-05-12 18:45:02 +00001176 if ((gdev->state == CCWGROUP_ONLINE) && card->info.hwtrap)
1177 qeth_hw_trap(card, QETH_DIAGS_TRAP_DISARM);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001178 qeth_qdio_clear_card(card, 0);
1179 qeth_clear_qdio_buffers(card);
1180}
1181
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02001182static int qeth_l2_pm_suspend(struct ccwgroup_device *gdev)
1183{
1184 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
1185
1186 if (card->dev)
1187 netif_device_detach(card->dev);
1188 qeth_set_allowed_threads(card, 0, 1);
1189 wait_event(card->wait_q, qeth_threads_running(card, 0xffffffff) == 0);
1190 if (gdev->state == CCWGROUP_OFFLINE)
1191 return 0;
1192 if (card->state == CARD_STATE_UP) {
Frank Blaschka1da74b12011-05-12 18:45:02 +00001193 if (card->info.hwtrap)
1194 qeth_hw_trap(card, QETH_DIAGS_TRAP_DISARM);
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02001195 __qeth_l2_set_offline(card->gdev, 1);
1196 } else
1197 __qeth_l2_set_offline(card->gdev, 0);
1198 return 0;
1199}
1200
1201static int qeth_l2_pm_resume(struct ccwgroup_device *gdev)
1202{
1203 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
1204 int rc = 0;
1205
1206 if (gdev->state == CCWGROUP_OFFLINE)
1207 goto out;
1208
1209 if (card->state == CARD_STATE_RECOVER) {
1210 rc = __qeth_l2_set_online(card->gdev, 1);
1211 if (rc) {
Ursula Braun869da902010-03-08 20:36:56 +00001212 rtnl_lock();
1213 dev_close(card->dev);
1214 rtnl_unlock();
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02001215 }
1216 } else
1217 rc = __qeth_l2_set_online(card->gdev, 0);
1218out:
1219 qeth_set_allowed_threads(card, 0xffffffff, 0);
1220 if (card->dev)
1221 netif_device_attach(card->dev);
1222 if (rc)
1223 dev_warn(&card->gdev->dev, "The qeth device driver "
1224 "failed to recover an error on the device\n");
1225 return rc;
1226}
1227
Sebastian Ottc041f2d4872012-05-15 18:02:21 +02001228struct qeth_discipline qeth_l2_discipline = {
1229 .start_poll = qeth_qdio_start_poll,
1230 .input_handler = (qdio_handler_t *) qeth_qdio_input_handler,
1231 .output_handler = (qdio_handler_t *) qeth_qdio_output_handler,
1232 .recover = qeth_l2_recover,
1233 .setup = qeth_l2_probe_device,
Frank Blaschka4a71df52008-02-15 09:19:42 +01001234 .remove = qeth_l2_remove_device,
1235 .set_online = qeth_l2_set_online,
1236 .set_offline = qeth_l2_set_offline,
1237 .shutdown = qeth_l2_shutdown,
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02001238 .freeze = qeth_l2_pm_suspend,
1239 .thaw = qeth_l2_pm_resume,
1240 .restore = qeth_l2_pm_resume,
Frank Blaschka4a71df52008-02-15 09:19:42 +01001241};
Sebastian Ottc041f2d4872012-05-15 18:02:21 +02001242EXPORT_SYMBOL_GPL(qeth_l2_discipline);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001243
1244static int qeth_osn_send_control_data(struct qeth_card *card, int len,
1245 struct qeth_cmd_buffer *iob)
1246{
1247 unsigned long flags;
1248 int rc = 0;
1249
Carsten Otte847a50f2010-06-21 22:57:05 +00001250 QETH_CARD_TEXT(card, 5, "osndctrd");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001251
1252 wait_event(card->wait_q,
1253 atomic_cmpxchg(&card->write.irq_pending, 0, 1) == 0);
1254 qeth_prepare_control_data(card, len, iob);
Carsten Otte847a50f2010-06-21 22:57:05 +00001255 QETH_CARD_TEXT(card, 6, "osnoirqp");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001256 spin_lock_irqsave(get_ccwdev_lock(card->write.ccwdev), flags);
1257 rc = ccw_device_start(card->write.ccwdev, &card->write.ccw,
1258 (addr_t) iob, 0, 0);
1259 spin_unlock_irqrestore(get_ccwdev_lock(card->write.ccwdev), flags);
1260 if (rc) {
Frank Blaschka14cc21b2008-06-06 12:37:46 +02001261 QETH_DBF_MESSAGE(2, "qeth_osn_send_control_data: "
Frank Blaschka4a71df52008-02-15 09:19:42 +01001262 "ccw_device_start rc = %i\n", rc);
Carsten Otte847a50f2010-06-21 22:57:05 +00001263 QETH_CARD_TEXT_(card, 2, " err%d", rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001264 qeth_release_buffer(iob->channel, iob);
1265 atomic_set(&card->write.irq_pending, 0);
1266 wake_up(&card->wait_q);
1267 }
1268 return rc;
1269}
1270
1271static int qeth_osn_send_ipa_cmd(struct qeth_card *card,
1272 struct qeth_cmd_buffer *iob, int data_len)
1273{
1274 u16 s1, s2;
1275
Carsten Otte847a50f2010-06-21 22:57:05 +00001276 QETH_CARD_TEXT(card, 4, "osndipa");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001277
1278 qeth_prepare_ipa_cmd(card, iob, QETH_PROT_OSN2);
1279 s1 = (u16)(IPA_PDU_HEADER_SIZE + data_len);
1280 s2 = (u16)data_len;
1281 memcpy(QETH_IPA_PDU_LEN_TOTAL(iob->data), &s1, 2);
1282 memcpy(QETH_IPA_PDU_LEN_PDU1(iob->data), &s2, 2);
1283 memcpy(QETH_IPA_PDU_LEN_PDU2(iob->data), &s2, 2);
1284 memcpy(QETH_IPA_PDU_LEN_PDU3(iob->data), &s2, 2);
1285 return qeth_osn_send_control_data(card, s1, iob);
1286}
1287
1288int qeth_osn_assist(struct net_device *dev, void *data, int data_len)
1289{
1290 struct qeth_cmd_buffer *iob;
1291 struct qeth_card *card;
1292 int rc;
1293
Frank Blaschka4a71df52008-02-15 09:19:42 +01001294 if (!dev)
1295 return -ENODEV;
Heiko Carstens509e2562008-07-26 02:24:10 -07001296 card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001297 if (!card)
1298 return -ENODEV;
Carsten Otte847a50f2010-06-21 22:57:05 +00001299 QETH_CARD_TEXT(card, 2, "osnsdmc");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001300 if ((card->state != CARD_STATE_UP) &&
1301 (card->state != CARD_STATE_SOFTSETUP))
1302 return -ENODEV;
1303 iob = qeth_wait_for_buffer(&card->write);
1304 memcpy(iob->data+IPA_PDU_HEADER_SIZE, data, data_len);
1305 rc = qeth_osn_send_ipa_cmd(card, iob, data_len);
1306 return rc;
1307}
1308EXPORT_SYMBOL(qeth_osn_assist);
1309
1310int qeth_osn_register(unsigned char *read_dev_no, struct net_device **dev,
1311 int (*assist_cb)(struct net_device *, void *),
1312 int (*data_cb)(struct sk_buff *))
1313{
1314 struct qeth_card *card;
1315
Frank Blaschka4a71df52008-02-15 09:19:42 +01001316 *dev = qeth_l2_netdev_by_devno(read_dev_no);
1317 if (*dev == NULL)
1318 return -ENODEV;
Heiko Carstens509e2562008-07-26 02:24:10 -07001319 card = (*dev)->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001320 if (!card)
1321 return -ENODEV;
Carsten Otte847a50f2010-06-21 22:57:05 +00001322 QETH_CARD_TEXT(card, 2, "osnreg");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001323 if ((assist_cb == NULL) || (data_cb == NULL))
1324 return -EINVAL;
1325 card->osn_info.assist_cb = assist_cb;
1326 card->osn_info.data_cb = data_cb;
1327 return 0;
1328}
1329EXPORT_SYMBOL(qeth_osn_register);
1330
1331void qeth_osn_deregister(struct net_device *dev)
1332{
1333 struct qeth_card *card;
1334
Frank Blaschka4a71df52008-02-15 09:19:42 +01001335 if (!dev)
1336 return;
Heiko Carstens509e2562008-07-26 02:24:10 -07001337 card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001338 if (!card)
1339 return;
Carsten Otte847a50f2010-06-21 22:57:05 +00001340 QETH_CARD_TEXT(card, 2, "osndereg");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001341 card->osn_info.assist_cb = NULL;
1342 card->osn_info.data_cb = NULL;
1343 return;
1344}
1345EXPORT_SYMBOL(qeth_osn_deregister);
1346
1347module_init(qeth_l2_init);
1348module_exit(qeth_l2_exit);
1349MODULE_AUTHOR("Frank Blaschka <frank.blaschka@de.ibm.com>");
1350MODULE_DESCRIPTION("qeth layer 2 discipline");
1351MODULE_LICENSE("GPL");