blob: f5f409d85295212ebb29c06ee4fd315c81ae2d63 [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"
Eugene Crosserb4d72c02014-01-14 15:54:11 +010024#include "qeth_l2.h"
Frank Blaschka4a71df52008-02-15 09:19:42 +010025
Frank Blaschka4a71df52008-02-15 09:19:42 +010026static int qeth_l2_set_offline(struct ccwgroup_device *);
27static int qeth_l2_stop(struct net_device *);
28static int qeth_l2_send_delmac(struct qeth_card *, __u8 *);
29static int qeth_l2_send_setdelmac(struct qeth_card *, __u8 *,
30 enum qeth_ipa_cmds,
31 int (*reply_cb) (struct qeth_card *,
32 struct qeth_reply*,
33 unsigned long));
34static void qeth_l2_set_multicast_list(struct net_device *);
35static int qeth_l2_recover(void *);
Eugene Crosserc044dc22014-01-29 09:23:48 +010036static void qeth_bridgeport_query_support(struct qeth_card *card);
37static void qeth_bridge_state_change(struct qeth_card *card,
38 struct qeth_ipa_cmd *cmd);
39static void qeth_bridge_host_event(struct qeth_card *card,
40 struct qeth_ipa_cmd *cmd);
Frank Blaschka4a71df52008-02-15 09:19:42 +010041
42static int qeth_l2_do_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
43{
Heiko Carstens509e2562008-07-26 02:24:10 -070044 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +010045 struct mii_ioctl_data *mii_data;
46 int rc = 0;
47
48 if (!card)
49 return -ENODEV;
50
Eugene Crosserc3521252015-01-16 14:05:47 +010051 if (!qeth_card_hw_is_reachable(card))
Frank Blaschka4a71df52008-02-15 09:19:42 +010052 return -ENODEV;
53
54 if (card->info.type == QETH_CARD_TYPE_OSN)
55 return -EPERM;
56
57 switch (cmd) {
58 case SIOC_QETH_ADP_SET_SNMP_CONTROL:
59 rc = qeth_snmp_command(card, rq->ifr_ifru.ifru_data);
60 break;
61 case SIOC_QETH_GET_CARD_TYPE:
Ursula Braun5113fec2010-05-16 21:15:14 +000062 if ((card->info.type == QETH_CARD_TYPE_OSD ||
63 card->info.type == QETH_CARD_TYPE_OSM ||
64 card->info.type == QETH_CARD_TYPE_OSX) &&
Frank Blaschka4a71df52008-02-15 09:19:42 +010065 !card->info.guestlan)
66 return 1;
67 return 0;
68 break;
69 case SIOCGMIIPHY:
70 mii_data = if_mii(rq);
71 mii_data->phy_id = 0;
72 break;
73 case SIOCGMIIREG:
74 mii_data = if_mii(rq);
75 if (mii_data->phy_id != 0)
76 rc = -EINVAL;
77 else
78 mii_data->val_out = qeth_mdio_read(dev,
79 mii_data->phy_id, mii_data->reg_num);
80 break;
Frank Blaschkac3ab96f2012-02-08 00:19:49 +000081 case SIOC_QETH_QUERY_OAT:
82 rc = qeth_query_oat_command(card, rq->ifr_ifru.ifru_data);
83 break;
Frank Blaschka4a71df52008-02-15 09:19:42 +010084 default:
85 rc = -EOPNOTSUPP;
86 }
87 if (rc)
Carsten Otte847a50f2010-06-21 22:57:05 +000088 QETH_CARD_TEXT_(card, 2, "ioce%d", rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +010089 return rc;
90}
91
92static int qeth_l2_verify_dev(struct net_device *dev)
93{
94 struct qeth_card *card;
95 unsigned long flags;
96 int rc = 0;
97
98 read_lock_irqsave(&qeth_core_card_list.rwlock, flags);
99 list_for_each_entry(card, &qeth_core_card_list.list, list) {
100 if (card->dev == dev) {
101 rc = QETH_REAL_CARD;
102 break;
103 }
104 }
105 read_unlock_irqrestore(&qeth_core_card_list.rwlock, flags);
106
107 return rc;
108}
109
110static struct net_device *qeth_l2_netdev_by_devno(unsigned char *read_dev_no)
111{
112 struct qeth_card *card;
113 struct net_device *ndev;
Cornelia Huckf06f6f32008-06-06 12:37:45 +0200114 __u16 temp_dev_no;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100115 unsigned long flags;
Cornelia Huckf06f6f32008-06-06 12:37:45 +0200116 struct ccw_dev_id read_devid;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100117
118 ndev = NULL;
119 memcpy(&temp_dev_no, read_dev_no, 2);
120 read_lock_irqsave(&qeth_core_card_list.rwlock, flags);
121 list_for_each_entry(card, &qeth_core_card_list.list, list) {
Cornelia Huckf06f6f32008-06-06 12:37:45 +0200122 ccw_device_get_id(CARD_RDEV(card), &read_devid);
123 if (read_devid.devno == temp_dev_no) {
Frank Blaschka4a71df52008-02-15 09:19:42 +0100124 ndev = card->dev;
125 break;
126 }
127 }
128 read_unlock_irqrestore(&qeth_core_card_list.rwlock, flags);
129 return ndev;
130}
131
132static int qeth_l2_send_setgroupmac_cb(struct qeth_card *card,
133 struct qeth_reply *reply,
134 unsigned long data)
135{
136 struct qeth_ipa_cmd *cmd;
137 __u8 *mac;
138
Carsten Otte847a50f2010-06-21 22:57:05 +0000139 QETH_CARD_TEXT(card, 2, "L2Sgmacb");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100140 cmd = (struct qeth_ipa_cmd *) data;
141 mac = &cmd->data.setdelmac.mac[0];
142 /* MAC already registered, needed in couple/uncouple case */
Ursula Braun0666eb062009-05-19 21:38:39 +0000143 if (cmd->hdr.return_code == IPA_RC_L2_DUP_MAC) {
Johannes Berg7c510e42008-10-27 17:47:26 -0700144 QETH_DBF_MESSAGE(2, "Group MAC %pM already existing on %s \n",
145 mac, QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100146 cmd->hdr.return_code = 0;
147 }
148 if (cmd->hdr.return_code)
Johannes Berg7c510e42008-10-27 17:47:26 -0700149 QETH_DBF_MESSAGE(2, "Could not set group MAC %pM on %s: %x\n",
150 mac, QETH_CARD_IFNAME(card), cmd->hdr.return_code);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100151 return 0;
152}
153
154static int qeth_l2_send_setgroupmac(struct qeth_card *card, __u8 *mac)
155{
Carsten Otte847a50f2010-06-21 22:57:05 +0000156 QETH_CARD_TEXT(card, 2, "L2Sgmac");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100157 return qeth_l2_send_setdelmac(card, mac, IPA_CMD_SETGMAC,
158 qeth_l2_send_setgroupmac_cb);
159}
160
161static int qeth_l2_send_delgroupmac_cb(struct qeth_card *card,
162 struct qeth_reply *reply,
163 unsigned long data)
164{
165 struct qeth_ipa_cmd *cmd;
166 __u8 *mac;
167
Carsten Otte847a50f2010-06-21 22:57:05 +0000168 QETH_CARD_TEXT(card, 2, "L2Dgmacb");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100169 cmd = (struct qeth_ipa_cmd *) data;
170 mac = &cmd->data.setdelmac.mac[0];
171 if (cmd->hdr.return_code)
Johannes Berg7c510e42008-10-27 17:47:26 -0700172 QETH_DBF_MESSAGE(2, "Could not delete group MAC %pM on %s: %x\n",
173 mac, QETH_CARD_IFNAME(card), cmd->hdr.return_code);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100174 return 0;
175}
176
177static int qeth_l2_send_delgroupmac(struct qeth_card *card, __u8 *mac)
178{
Carsten Otte847a50f2010-06-21 22:57:05 +0000179 QETH_CARD_TEXT(card, 2, "L2Dgmac");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100180 return qeth_l2_send_setdelmac(card, mac, IPA_CMD_DELGMAC,
181 qeth_l2_send_delgroupmac_cb);
182}
183
Frank Blaschka7db22662008-08-15 08:02:59 +0200184static void qeth_l2_add_mc(struct qeth_card *card, __u8 *mac, int vmac)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100185{
186 struct qeth_mc_mac *mc;
Frank Blaschka7db22662008-08-15 08:02:59 +0200187 int rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100188
189 mc = kmalloc(sizeof(struct qeth_mc_mac), GFP_ATOMIC);
190
Frank Blaschka14cc21b2008-06-06 12:37:46 +0200191 if (!mc)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100192 return;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100193
194 memcpy(mc->mc_addr, mac, OSA_ADDR_LEN);
195 mc->mc_addrlen = OSA_ADDR_LEN;
Frank Blaschka7db22662008-08-15 08:02:59 +0200196 mc->is_vmac = vmac;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100197
Frank Blaschka7db22662008-08-15 08:02:59 +0200198 if (vmac) {
199 rc = qeth_l2_send_setdelmac(card, mac, IPA_CMD_SETVMAC,
200 NULL);
201 } else {
202 rc = qeth_l2_send_setgroupmac(card, mac);
203 }
204
205 if (!rc)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100206 list_add_tail(&mc->list, &card->mc_list);
207 else
208 kfree(mc);
209}
210
Ursula Braun70919e22011-02-26 22:41:36 -0800211static void qeth_l2_del_all_mc(struct qeth_card *card, int del)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100212{
213 struct qeth_mc_mac *mc, *tmp;
214
215 spin_lock_bh(&card->mclock);
216 list_for_each_entry_safe(mc, tmp, &card->mc_list, list) {
Ursula Braun70919e22011-02-26 22:41:36 -0800217 if (del) {
218 if (mc->is_vmac)
219 qeth_l2_send_setdelmac(card, mc->mc_addr,
Frank Blaschka7db22662008-08-15 08:02:59 +0200220 IPA_CMD_DELVMAC, NULL);
Ursula Braun70919e22011-02-26 22:41:36 -0800221 else
222 qeth_l2_send_delgroupmac(card, mc->mc_addr);
223 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100224 list_del(&mc->list);
225 kfree(mc);
226 }
227 spin_unlock_bh(&card->mclock);
228}
229
Klaus-Dieter Wackerce73e102009-08-26 02:01:08 +0000230static inline int qeth_l2_get_cast_type(struct qeth_card *card,
231 struct sk_buff *skb)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100232{
Klaus-Dieter Wackerce73e102009-08-26 02:01:08 +0000233 if (card->info.type == QETH_CARD_TYPE_OSN)
234 return RTN_UNSPEC;
235 if (is_broadcast_ether_addr(skb->data))
236 return RTN_BROADCAST;
237 if (is_multicast_ether_addr(skb->data))
238 return RTN_MULTICAST;
239 return RTN_UNSPEC;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100240}
241
242static void qeth_l2_fill_header(struct qeth_card *card, struct qeth_hdr *hdr,
Stefan Raspl43934072014-03-19 07:58:01 +0100243 struct sk_buff *skb, int cast_type)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100244{
Frank Blaschka683d7182008-08-01 16:39:13 +0200245 struct vlan_ethhdr *veth = (struct vlan_ethhdr *)skb_mac_header(skb);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100246
247 memset(hdr, 0, sizeof(struct qeth_hdr));
248 hdr->hdr.l2.id = QETH_HEADER_TYPE_LAYER2;
249
250 /* set byte byte 3 to casting flags */
251 if (cast_type == RTN_MULTICAST)
252 hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_MULTICAST;
253 else if (cast_type == RTN_BROADCAST)
254 hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_BROADCAST;
255 else
Klaus-Dieter Wackerce73e102009-08-26 02:01:08 +0000256 hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_UNICAST;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100257
258 hdr->hdr.l2.pkt_length = skb->len-QETH_HEADER_SIZE;
259 /* VSWITCH relies on the VLAN
260 * information to be present in
261 * the QDIO header */
262 if (veth->h_vlan_proto == __constant_htons(ETH_P_8021Q)) {
263 hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_VLAN;
264 hdr->hdr.l2.vlan_id = ntohs(veth->h_vlan_TCI);
265 }
266}
267
268static int qeth_l2_send_setdelvlan_cb(struct qeth_card *card,
269 struct qeth_reply *reply, unsigned long data)
270{
271 struct qeth_ipa_cmd *cmd;
272
Carsten Otte847a50f2010-06-21 22:57:05 +0000273 QETH_CARD_TEXT(card, 2, "L2sdvcb");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100274 cmd = (struct qeth_ipa_cmd *) data;
275 if (cmd->hdr.return_code) {
Frank Blaschka14cc21b2008-06-06 12:37:46 +0200276 QETH_DBF_MESSAGE(2, "Error in processing VLAN %i on %s: 0x%x. "
Frank Blaschka4a71df52008-02-15 09:19:42 +0100277 "Continuing\n", cmd->data.setdelvlan.vlan_id,
278 QETH_CARD_IFNAME(card), cmd->hdr.return_code);
Carsten Otte847a50f2010-06-21 22:57:05 +0000279 QETH_CARD_TEXT_(card, 2, "L2VL%4x", cmd->hdr.command);
280 QETH_CARD_TEXT_(card, 2, "err%d", cmd->hdr.return_code);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100281 }
282 return 0;
283}
284
285static int qeth_l2_send_setdelvlan(struct qeth_card *card, __u16 i,
286 enum qeth_ipa_cmds ipacmd)
287{
288 struct qeth_ipa_cmd *cmd;
289 struct qeth_cmd_buffer *iob;
290
Carsten Otte847a50f2010-06-21 22:57:05 +0000291 QETH_CARD_TEXT_(card, 4, "L2sdv%x", ipacmd);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100292 iob = qeth_get_ipacmd_buffer(card, ipacmd, QETH_PROT_IPV4);
293 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
294 cmd->data.setdelvlan.vlan_id = i;
295 return qeth_send_ipa_cmd(card, iob,
296 qeth_l2_send_setdelvlan_cb, NULL);
297}
298
Ursula Braun70919e22011-02-26 22:41:36 -0800299static void qeth_l2_process_vlans(struct qeth_card *card)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100300{
301 struct qeth_vlan_vid *id;
Carsten Otte847a50f2010-06-21 22:57:05 +0000302 QETH_CARD_TEXT(card, 3, "L2prcvln");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100303 spin_lock_bh(&card->vlanlock);
304 list_for_each_entry(id, &card->vid_list, list) {
Ursula Braun70919e22011-02-26 22:41:36 -0800305 qeth_l2_send_setdelvlan(card, id->vid, IPA_CMD_SETVLAN);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100306 }
307 spin_unlock_bh(&card->vlanlock);
308}
309
Patrick McHardy80d5c362013-04-19 02:04:28 +0000310static int qeth_l2_vlan_rx_add_vid(struct net_device *dev,
311 __be16 proto, u16 vid)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100312{
Heiko Carstens509e2562008-07-26 02:24:10 -0700313 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100314 struct qeth_vlan_vid *id;
315
Carsten Otte847a50f2010-06-21 22:57:05 +0000316 QETH_CARD_TEXT_(card, 4, "aid:%d", vid);
Ursula Braun10651db2010-10-01 02:51:13 +0000317 if (!vid)
Jiri Pirko8e586132011-12-08 19:52:37 -0500318 return 0;
Ursula Braun5113fec2010-05-16 21:15:14 +0000319 if (card->info.type == QETH_CARD_TYPE_OSM) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000320 QETH_CARD_TEXT(card, 3, "aidOSM");
Jiri Pirko8e586132011-12-08 19:52:37 -0500321 return 0;
Ursula Braun5113fec2010-05-16 21:15:14 +0000322 }
Ursula Braun8e98ac42009-03-24 20:57:18 +0000323 if (qeth_wait_for_threads(card, QETH_RECOVER_THREAD)) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000324 QETH_CARD_TEXT(card, 3, "aidREC");
Jiri Pirko8e586132011-12-08 19:52:37 -0500325 return 0;
Ursula Braun8e98ac42009-03-24 20:57:18 +0000326 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100327 id = kmalloc(sizeof(struct qeth_vlan_vid), GFP_ATOMIC);
328 if (id) {
329 id->vid = vid;
330 qeth_l2_send_setdelvlan(card, vid, IPA_CMD_SETVLAN);
331 spin_lock_bh(&card->vlanlock);
332 list_add_tail(&id->list, &card->vid_list);
333 spin_unlock_bh(&card->vlanlock);
Jiri Pirko8e586132011-12-08 19:52:37 -0500334 } else {
335 return -ENOMEM;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100336 }
Jiri Pirko8e586132011-12-08 19:52:37 -0500337 return 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100338}
339
Patrick McHardy80d5c362013-04-19 02:04:28 +0000340static int qeth_l2_vlan_rx_kill_vid(struct net_device *dev,
341 __be16 proto, u16 vid)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100342{
343 struct qeth_vlan_vid *id, *tmpid = NULL;
Heiko Carstens509e2562008-07-26 02:24:10 -0700344 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100345
Carsten Otte847a50f2010-06-21 22:57:05 +0000346 QETH_CARD_TEXT_(card, 4, "kid:%d", vid);
Ursula Braun5113fec2010-05-16 21:15:14 +0000347 if (card->info.type == QETH_CARD_TYPE_OSM) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000348 QETH_CARD_TEXT(card, 3, "kidOSM");
Jiri Pirko8e586132011-12-08 19:52:37 -0500349 return 0;
Ursula Braun5113fec2010-05-16 21:15:14 +0000350 }
Ursula Braun8e98ac42009-03-24 20:57:18 +0000351 if (qeth_wait_for_threads(card, QETH_RECOVER_THREAD)) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000352 QETH_CARD_TEXT(card, 3, "kidREC");
Jiri Pirko8e586132011-12-08 19:52:37 -0500353 return 0;
Ursula Braun8e98ac42009-03-24 20:57:18 +0000354 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100355 spin_lock_bh(&card->vlanlock);
356 list_for_each_entry(id, &card->vid_list, list) {
357 if (id->vid == vid) {
358 list_del(&id->list);
359 tmpid = id;
360 break;
361 }
362 }
363 spin_unlock_bh(&card->vlanlock);
364 if (tmpid) {
365 qeth_l2_send_setdelvlan(card, vid, IPA_CMD_DELVLAN);
366 kfree(tmpid);
367 }
368 qeth_l2_set_multicast_list(card->dev);
Jiri Pirko8e586132011-12-08 19:52:37 -0500369 return 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100370}
371
372static int qeth_l2_stop_card(struct qeth_card *card, int recovery_mode)
373{
374 int rc = 0;
375
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200376 QETH_DBF_TEXT(SETUP , 2, "stopcard");
377 QETH_DBF_HEX(SETUP, 2, &card, sizeof(void *));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100378
379 qeth_set_allowed_threads(card, 0, 1);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100380 if (card->read.state == CH_STATE_UP &&
381 card->write.state == CH_STATE_UP &&
382 (card->state == CARD_STATE_UP)) {
383 if (recovery_mode &&
384 card->info.type != QETH_CARD_TYPE_OSN) {
385 qeth_l2_stop(card->dev);
386 } else {
387 rtnl_lock();
388 dev_close(card->dev);
389 rtnl_unlock();
390 }
Ursula Braun70919e22011-02-26 22:41:36 -0800391 card->info.mac_bits &= ~QETH_LAYER2_MAC_REGISTERED;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100392 card->state = CARD_STATE_SOFTSETUP;
393 }
394 if (card->state == CARD_STATE_SOFTSETUP) {
Ursula Braun70919e22011-02-26 22:41:36 -0800395 qeth_l2_del_all_mc(card, 0);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100396 qeth_clear_ipacmd_list(card);
397 card->state = CARD_STATE_HARDSETUP;
398 }
399 if (card->state == CARD_STATE_HARDSETUP) {
400 qeth_qdio_clear_card(card, 0);
401 qeth_clear_qdio_buffers(card);
402 qeth_clear_working_pool_list(card);
403 card->state = CARD_STATE_DOWN;
404 }
405 if (card->state == CARD_STATE_DOWN) {
406 qeth_clear_cmd_buffers(&card->read);
407 qeth_clear_cmd_buffers(&card->write);
408 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100409 return rc;
410}
411
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000412static int qeth_l2_process_inbound_buffer(struct qeth_card *card,
413 int budget, int *done)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100414{
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000415 int work_done = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100416 struct sk_buff *skb;
417 struct qeth_hdr *hdr;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100418 unsigned int len;
419
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000420 *done = 0;
Stefan Raspl18af5c12012-11-19 02:46:50 +0000421 WARN_ON_ONCE(!budget);
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000422 while (budget) {
423 skb = qeth_core_get_next_skb(card,
Frank Blaschkab3332932011-08-08 01:33:59 +0000424 &card->qdio.in_q->bufs[card->rx.b_index],
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000425 &card->rx.b_element, &card->rx.e_offset, &hdr);
426 if (!skb) {
427 *done = 1;
428 break;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100429 }
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000430 skb->dev = card->dev;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100431 switch (hdr->hdr.l2.id) {
432 case QETH_HEADER_TYPE_LAYER2:
433 skb->pkt_type = PACKET_HOST;
434 skb->protocol = eth_type_trans(skb, skb->dev);
Frank Blaschkac5e631a2011-05-12 18:45:01 +0000435 skb->ip_summed = CHECKSUM_NONE;
Ursula Braun12883722008-04-01 10:26:56 +0200436 if (skb->protocol == htons(ETH_P_802_2))
437 *((__u32 *)skb->cb) = ++card->seqno.pkt_seqno;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100438 len = skb->len;
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000439 netif_receive_skb(skb);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100440 break;
441 case QETH_HEADER_TYPE_OSN:
Ursula Braun2d488c22008-10-24 11:16:55 +0200442 if (card->info.type == QETH_CARD_TYPE_OSN) {
443 skb_push(skb, sizeof(struct qeth_hdr));
444 skb_copy_to_linear_data(skb, hdr,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100445 sizeof(struct qeth_hdr));
Ursula Braun2d488c22008-10-24 11:16:55 +0200446 len = skb->len;
447 card->osn_info.data_cb(skb);
448 break;
449 }
450 /* else unknown */
Frank Blaschka4a71df52008-02-15 09:19:42 +0100451 default:
452 dev_kfree_skb_any(skb);
Carsten Otte847a50f2010-06-21 22:57:05 +0000453 QETH_CARD_TEXT(card, 3, "inbunkno");
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200454 QETH_DBF_HEX(CTRL, 3, hdr, QETH_DBF_CTRL_LEN);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100455 continue;
456 }
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000457 work_done++;
458 budget--;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100459 card->stats.rx_packets++;
460 card->stats.rx_bytes += len;
461 }
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000462 return work_done;
463}
464
465static int qeth_l2_poll(struct napi_struct *napi, int budget)
466{
467 struct qeth_card *card = container_of(napi, struct qeth_card, napi);
468 int work_done = 0;
469 struct qeth_qdio_buffer *buffer;
470 int done;
471 int new_budget = budget;
472
473 if (card->options.performance_stats) {
474 card->perf_stats.inbound_cnt++;
475 card->perf_stats.inbound_start_time = qeth_get_micros();
476 }
477
478 while (1) {
479 if (!card->rx.b_count) {
480 card->rx.qdio_err = 0;
481 card->rx.b_count = qdio_get_next_buffers(
482 card->data.ccwdev, 0, &card->rx.b_index,
483 &card->rx.qdio_err);
484 if (card->rx.b_count <= 0) {
485 card->rx.b_count = 0;
486 break;
487 }
488 card->rx.b_element =
489 &card->qdio.in_q->bufs[card->rx.b_index]
490 .buffer->element[0];
491 card->rx.e_offset = 0;
492 }
493
494 while (card->rx.b_count) {
495 buffer = &card->qdio.in_q->bufs[card->rx.b_index];
496 if (!(card->rx.qdio_err &&
497 qeth_check_qdio_errors(card, buffer->buffer,
498 card->rx.qdio_err, "qinerr")))
499 work_done += qeth_l2_process_inbound_buffer(
500 card, new_budget, &done);
501 else
502 done = 1;
503
504 if (done) {
505 if (card->options.performance_stats)
506 card->perf_stats.bufs_rec++;
507 qeth_put_buffer_pool_entry(card,
508 buffer->pool_entry);
509 qeth_queue_input_buffer(card, card->rx.b_index);
510 card->rx.b_count--;
511 if (card->rx.b_count) {
512 card->rx.b_index =
513 (card->rx.b_index + 1) %
514 QDIO_MAX_BUFFERS_PER_Q;
515 card->rx.b_element =
516 &card->qdio.in_q
517 ->bufs[card->rx.b_index]
518 .buffer->element[0];
519 card->rx.e_offset = 0;
520 }
521 }
522
523 if (work_done >= budget)
524 goto out;
525 else
526 new_budget = budget - work_done;
527 }
528 }
529
530 napi_complete(napi);
531 if (qdio_start_irq(card->data.ccwdev, 0))
532 napi_schedule(&card->napi);
533out:
534 if (card->options.performance_stats)
535 card->perf_stats.inbound_time += qeth_get_micros() -
536 card->perf_stats.inbound_start_time;
537 return work_done;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100538}
539
540static int qeth_l2_send_setdelmac(struct qeth_card *card, __u8 *mac,
541 enum qeth_ipa_cmds ipacmd,
542 int (*reply_cb) (struct qeth_card *,
543 struct qeth_reply*,
544 unsigned long))
545{
546 struct qeth_ipa_cmd *cmd;
547 struct qeth_cmd_buffer *iob;
548
Carsten Otte847a50f2010-06-21 22:57:05 +0000549 QETH_CARD_TEXT(card, 2, "L2sdmac");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100550 iob = qeth_get_ipacmd_buffer(card, ipacmd, QETH_PROT_IPV4);
551 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
552 cmd->data.setdelmac.mac_length = OSA_ADDR_LEN;
553 memcpy(&cmd->data.setdelmac.mac, mac, OSA_ADDR_LEN);
554 return qeth_send_ipa_cmd(card, iob, reply_cb, NULL);
555}
556
557static int qeth_l2_send_setmac_cb(struct qeth_card *card,
558 struct qeth_reply *reply,
559 unsigned long data)
560{
561 struct qeth_ipa_cmd *cmd;
562
Carsten Otte847a50f2010-06-21 22:57:05 +0000563 QETH_CARD_TEXT(card, 2, "L2Smaccb");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100564 cmd = (struct qeth_ipa_cmd *) data;
565 if (cmd->hdr.return_code) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000566 QETH_CARD_TEXT_(card, 2, "L2er%x", cmd->hdr.return_code);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100567 card->info.mac_bits &= ~QETH_LAYER2_MAC_REGISTERED;
Ursula Braun0666eb062009-05-19 21:38:39 +0000568 switch (cmd->hdr.return_code) {
569 case IPA_RC_L2_DUP_MAC:
570 case IPA_RC_L2_DUP_LAYER3_MAC:
571 dev_warn(&card->gdev->dev,
H Hartley Sweetend998ab02009-12-29 20:05:37 -0800572 "MAC address %pM already exists\n",
Ursula Braun221c17f2011-02-02 06:04:31 +0000573 cmd->data.setdelmac.mac);
Ursula Braun0666eb062009-05-19 21:38:39 +0000574 break;
575 case IPA_RC_L2_MAC_NOT_AUTH_BY_HYP:
576 case IPA_RC_L2_MAC_NOT_AUTH_BY_ADP:
577 dev_warn(&card->gdev->dev,
H Hartley Sweetend998ab02009-12-29 20:05:37 -0800578 "MAC address %pM is not authorized\n",
Ursula Braun221c17f2011-02-02 06:04:31 +0000579 cmd->data.setdelmac.mac);
Ursula Braun0666eb062009-05-19 21:38:39 +0000580 break;
581 default:
582 break;
583 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100584 } else {
585 card->info.mac_bits |= QETH_LAYER2_MAC_REGISTERED;
586 memcpy(card->dev->dev_addr, cmd->data.setdelmac.mac,
587 OSA_ADDR_LEN);
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100588 dev_info(&card->gdev->dev,
H Hartley Sweetend998ab02009-12-29 20:05:37 -0800589 "MAC address %pM successfully registered on device %s\n",
590 card->dev->dev_addr, card->dev->name);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100591 }
592 return 0;
593}
594
595static int qeth_l2_send_setmac(struct qeth_card *card, __u8 *mac)
596{
Carsten Otte847a50f2010-06-21 22:57:05 +0000597 QETH_CARD_TEXT(card, 2, "L2Setmac");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100598 return qeth_l2_send_setdelmac(card, mac, IPA_CMD_SETVMAC,
599 qeth_l2_send_setmac_cb);
600}
601
602static int qeth_l2_send_delmac_cb(struct qeth_card *card,
603 struct qeth_reply *reply,
604 unsigned long data)
605{
606 struct qeth_ipa_cmd *cmd;
607
Carsten Otte847a50f2010-06-21 22:57:05 +0000608 QETH_CARD_TEXT(card, 2, "L2Dmaccb");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100609 cmd = (struct qeth_ipa_cmd *) data;
610 if (cmd->hdr.return_code) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000611 QETH_CARD_TEXT_(card, 2, "err%d", cmd->hdr.return_code);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100612 return 0;
613 }
614 card->info.mac_bits &= ~QETH_LAYER2_MAC_REGISTERED;
615
616 return 0;
617}
618
619static int qeth_l2_send_delmac(struct qeth_card *card, __u8 *mac)
620{
Carsten Otte847a50f2010-06-21 22:57:05 +0000621 QETH_CARD_TEXT(card, 2, "L2Delmac");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100622 if (!(card->info.mac_bits & QETH_LAYER2_MAC_REGISTERED))
623 return 0;
624 return qeth_l2_send_setdelmac(card, mac, IPA_CMD_DELVMAC,
625 qeth_l2_send_delmac_cb);
626}
627
628static int qeth_l2_request_initial_mac(struct qeth_card *card)
629{
630 int rc = 0;
631 char vendor_pre[] = {0x02, 0x00, 0x00};
632
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200633 QETH_DBF_TEXT(SETUP, 2, "doL2init");
634 QETH_DBF_TEXT_(SETUP, 2, "doL2%s", CARD_BUS_ID(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100635
Stefan Raspla1348842012-11-12 23:05:16 +0000636 if (qeth_is_supported(card, IPA_SETADAPTERPARMS)) {
637 rc = qeth_query_setadapterparms(card);
638 if (rc) {
639 QETH_DBF_MESSAGE(2, "could not query adapter "
640 "parameters on device %s: x%x\n",
641 CARD_BUS_ID(card), rc);
642 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100643 }
644
Ursula Braun5113fec2010-05-16 21:15:14 +0000645 if (card->info.type == QETH_CARD_TYPE_IQD ||
646 card->info.type == QETH_CARD_TYPE_OSM ||
647 card->info.type == QETH_CARD_TYPE_OSX ||
648 card->info.guestlan) {
Frank Blaschka4a71df52008-02-15 09:19:42 +0100649 rc = qeth_setadpparms_change_macaddr(card);
650 if (rc) {
Frank Blaschka14cc21b2008-06-06 12:37:46 +0200651 QETH_DBF_MESSAGE(2, "couldn't get MAC address on "
652 "device %s: x%x\n", CARD_BUS_ID(card), rc);
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200653 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100654 return rc;
655 }
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200656 QETH_DBF_HEX(SETUP, 2, card->dev->dev_addr, OSA_ADDR_LEN);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100657 } else {
Joe Perches18336112012-07-12 22:33:10 -0700658 eth_random_addr(card->dev->dev_addr);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100659 memcpy(card->dev->dev_addr, vendor_pre, 3);
660 }
661 return 0;
662}
663
664static int qeth_l2_set_mac_address(struct net_device *dev, void *p)
665{
666 struct sockaddr *addr = p;
Heiko Carstens509e2562008-07-26 02:24:10 -0700667 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100668 int rc = 0;
669
Carsten Otte847a50f2010-06-21 22:57:05 +0000670 QETH_CARD_TEXT(card, 3, "setmac");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100671
672 if (qeth_l2_verify_dev(dev) != QETH_REAL_CARD) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000673 QETH_CARD_TEXT(card, 3, "setmcINV");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100674 return -EOPNOTSUPP;
675 }
676
Ursula Braun5113fec2010-05-16 21:15:14 +0000677 if (card->info.type == QETH_CARD_TYPE_OSN ||
678 card->info.type == QETH_CARD_TYPE_OSM ||
679 card->info.type == QETH_CARD_TYPE_OSX) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000680 QETH_CARD_TEXT(card, 3, "setmcTYP");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100681 return -EOPNOTSUPP;
682 }
Carsten Otte847a50f2010-06-21 22:57:05 +0000683 QETH_CARD_HEX(card, 3, addr->sa_data, OSA_ADDR_LEN);
Ursula Braun8e98ac42009-03-24 20:57:18 +0000684 if (qeth_wait_for_threads(card, QETH_RECOVER_THREAD)) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000685 QETH_CARD_TEXT(card, 3, "setmcREC");
Ursula Braun8e98ac42009-03-24 20:57:18 +0000686 return -ERESTARTSYS;
687 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100688 rc = qeth_l2_send_delmac(card, &card->dev->dev_addr[0]);
Ursula Braun77027452012-11-12 23:05:17 +0000689 if (!rc || (rc == IPA_RC_L2_MAC_NOT_FOUND))
Frank Blaschka4a71df52008-02-15 09:19:42 +0100690 rc = qeth_l2_send_setmac(card, addr->sa_data);
Ursula Braune0a81142012-03-07 02:06:28 +0000691 return rc ? -EINVAL : 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100692}
693
694static void qeth_l2_set_multicast_list(struct net_device *dev)
695{
Heiko Carstens509e2562008-07-26 02:24:10 -0700696 struct qeth_card *card = dev->ml_priv;
Jiri Pirkoccffad252009-05-22 23:22:17 +0000697 struct netdev_hw_addr *ha;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100698
699 if (card->info.type == QETH_CARD_TYPE_OSN)
700 return ;
701
Carsten Otte847a50f2010-06-21 22:57:05 +0000702 QETH_CARD_TEXT(card, 3, "setmulti");
Ursula Braun8e98ac42009-03-24 20:57:18 +0000703 if (qeth_threads_running(card, QETH_RECOVER_THREAD) &&
704 (card->state != CARD_STATE_UP))
705 return;
Ursula Braun70919e22011-02-26 22:41:36 -0800706 qeth_l2_del_all_mc(card, 1);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100707 spin_lock_bh(&card->mclock);
Jiri Pirko22bedad32010-04-01 21:22:57 +0000708 netdev_for_each_mc_addr(ha, dev)
709 qeth_l2_add_mc(card, ha->addr, 0);
Frank Blaschka7db22662008-08-15 08:02:59 +0200710
Jiri Pirko32e7bfc2010-01-25 13:36:10 -0800711 netdev_for_each_uc_addr(ha, dev)
Jiri Pirkoccffad252009-05-22 23:22:17 +0000712 qeth_l2_add_mc(card, ha->addr, 1);
Frank Blaschka7db22662008-08-15 08:02:59 +0200713
Frank Blaschka4a71df52008-02-15 09:19:42 +0100714 spin_unlock_bh(&card->mclock);
715 if (!qeth_adp_supported(card, IPA_SETADP_SET_PROMISC_MODE))
716 return;
717 qeth_setadp_promisc_mode(card);
718}
719
720static int qeth_l2_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
721{
722 int rc;
723 struct qeth_hdr *hdr = NULL;
724 int elements = 0;
Heiko Carstens509e2562008-07-26 02:24:10 -0700725 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100726 struct sk_buff *new_skb = skb;
Klaus-Dieter Wackerce73e102009-08-26 02:01:08 +0000727 int cast_type = qeth_l2_get_cast_type(card, skb);
Stefan Raspl290b8342014-04-28 10:05:08 +0200728 struct qeth_qdio_out_q *queue;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100729 int tx_bytes = skb->len;
Frank Blaschka683d7182008-08-01 16:39:13 +0200730 int data_offset = -1;
731 int elements_needed = 0;
732 int hd_len = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100733
Stefan Raspl290b8342014-04-28 10:05:08 +0200734 if (card->qdio.do_prio_queueing || (cast_type &&
735 card->info.is_multicast_different))
736 queue = card->qdio.out_qs[qeth_get_priority_queue(card, skb,
737 qeth_get_ip_version(skb), cast_type)];
738 else
739 queue = card->qdio.out_qs[card->qdio.default_out_queue];
740
Frank Blaschka4a71df52008-02-15 09:19:42 +0100741 if ((card->state != CARD_STATE_UP) || !card->lan_online) {
742 card->stats.tx_carrier_errors++;
743 goto tx_drop;
744 }
745
746 if ((card->info.type == QETH_CARD_TYPE_OSN) &&
747 (skb->protocol == htons(ETH_P_IPV6)))
748 goto tx_drop;
749
750 if (card->options.performance_stats) {
751 card->perf_stats.outbound_cnt++;
752 card->perf_stats.outbound_start_time = qeth_get_micros();
753 }
754 netif_stop_queue(dev);
755
Frank Blaschka4a71df52008-02-15 09:19:42 +0100756 if (card->info.type == QETH_CARD_TYPE_OSN)
757 hdr = (struct qeth_hdr *)skb->data;
758 else {
Frank Blaschka64ef8952009-03-24 20:57:16 +0000759 if (card->info.type == QETH_CARD_TYPE_IQD) {
Frank Blaschka683d7182008-08-01 16:39:13 +0200760 new_skb = skb;
761 data_offset = ETH_HLEN;
762 hd_len = ETH_HLEN;
763 hdr = kmem_cache_alloc(qeth_core_header_cache,
764 GFP_ATOMIC);
765 if (!hdr)
766 goto tx_drop;
767 elements_needed++;
768 skb_reset_mac_header(new_skb);
Stefan Raspl43934072014-03-19 07:58:01 +0100769 qeth_l2_fill_header(card, hdr, new_skb, cast_type);
Frank Blaschka683d7182008-08-01 16:39:13 +0200770 hdr->hdr.l2.pkt_length = new_skb->len;
771 memcpy(((char *)hdr) + sizeof(struct qeth_hdr),
772 skb_mac_header(new_skb), ETH_HLEN);
773 } else {
774 /* create a clone with writeable headroom */
775 new_skb = skb_realloc_headroom(skb,
Frank Blaschkaf90b7442008-04-24 10:15:24 +0200776 sizeof(struct qeth_hdr));
Frank Blaschka683d7182008-08-01 16:39:13 +0200777 if (!new_skb)
778 goto tx_drop;
779 hdr = (struct qeth_hdr *)skb_push(new_skb,
780 sizeof(struct qeth_hdr));
781 skb_set_mac_header(new_skb, sizeof(struct qeth_hdr));
Stefan Raspl43934072014-03-19 07:58:01 +0100782 qeth_l2_fill_header(card, hdr, new_skb, cast_type);
Frank Blaschka683d7182008-08-01 16:39:13 +0200783 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100784 }
785
Stefan Raspl065cc782013-04-22 01:12:28 +0000786 elements = qeth_get_elements_no(card, new_skb, elements_needed);
Frank Blaschka64ef8952009-03-24 20:57:16 +0000787 if (!elements) {
788 if (data_offset >= 0)
789 kmem_cache_free(qeth_core_header_cache, hdr);
790 goto tx_drop;
Frank Blaschkaf61a0d02009-03-24 20:57:15 +0000791 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100792
Frank Blaschka51aa1652010-06-21 22:57:10 +0000793 if (card->info.type != QETH_CARD_TYPE_IQD) {
Stefan Raspld4ae1f52013-04-22 01:12:29 +0000794 if (qeth_hdr_chk_and_bounce(new_skb, &hdr,
Frank Blaschka51aa1652010-06-21 22:57:10 +0000795 sizeof(struct qeth_hdr_layer2)))
796 goto tx_drop;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100797 rc = qeth_do_send_packet(card, queue, new_skb, hdr,
Frank Blaschka64ef8952009-03-24 20:57:16 +0000798 elements);
Frank Blaschka51aa1652010-06-21 22:57:10 +0000799 } else
Frank Blaschka4a71df52008-02-15 09:19:42 +0100800 rc = qeth_do_send_packet_fast(card, queue, new_skb, hdr,
Frank Blaschka64ef8952009-03-24 20:57:16 +0000801 elements, data_offset, hd_len);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100802 if (!rc) {
803 card->stats.tx_packets++;
804 card->stats.tx_bytes += tx_bytes;
805 if (new_skb != skb)
806 dev_kfree_skb_any(skb);
Patrick McHardyec634fe2009-07-05 19:23:38 -0700807 rc = NETDEV_TX_OK;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100808 } else {
Frank Blaschka683d7182008-08-01 16:39:13 +0200809 if (data_offset >= 0)
810 kmem_cache_free(qeth_core_header_cache, hdr);
811
Frank Blaschka4a71df52008-02-15 09:19:42 +0100812 if (rc == -EBUSY) {
813 if (new_skb != skb)
814 dev_kfree_skb_any(new_skb);
815 return NETDEV_TX_BUSY;
816 } else
817 goto tx_drop;
818 }
819
820 netif_wake_queue(dev);
821 if (card->options.performance_stats)
822 card->perf_stats.outbound_time += qeth_get_micros() -
823 card->perf_stats.outbound_start_time;
824 return rc;
825
826tx_drop:
827 card->stats.tx_dropped++;
828 card->stats.tx_errors++;
829 if ((new_skb != skb) && new_skb)
830 dev_kfree_skb_any(new_skb);
831 dev_kfree_skb_any(skb);
Frank Blaschkad0ec0f52008-06-06 12:37:48 +0200832 netif_wake_queue(dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100833 return NETDEV_TX_OK;
834}
835
Ursula Braun39423442011-01-12 20:42:24 +0000836static int __qeth_l2_open(struct net_device *dev)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100837{
Heiko Carstens509e2562008-07-26 02:24:10 -0700838 struct qeth_card *card = dev->ml_priv;
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000839 int rc = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100840
Carsten Otte847a50f2010-06-21 22:57:05 +0000841 QETH_CARD_TEXT(card, 4, "qethopen");
Ursula Braun39423442011-01-12 20:42:24 +0000842 if (card->state == CARD_STATE_UP)
843 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100844 if (card->state != CARD_STATE_SOFTSETUP)
845 return -ENODEV;
846
847 if ((card->info.type != QETH_CARD_TYPE_OSN) &&
848 (!(card->info.mac_bits & QETH_LAYER2_MAC_REGISTERED))) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000849 QETH_CARD_TEXT(card, 4, "nomacadr");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100850 return -EPERM;
851 }
852 card->data.state = CH_STATE_UP;
853 card->state = CARD_STATE_UP;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100854 netif_start_queue(dev);
855
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000856 if (qdio_stop_irq(card->data.ccwdev, 0) >= 0) {
857 napi_enable(&card->napi);
858 napi_schedule(&card->napi);
859 } else
860 rc = -EIO;
861 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100862}
863
Ursula Braun39423442011-01-12 20:42:24 +0000864static int qeth_l2_open(struct net_device *dev)
865{
866 struct qeth_card *card = dev->ml_priv;
867
868 QETH_CARD_TEXT(card, 5, "qethope_");
869 if (qeth_wait_for_threads(card, QETH_RECOVER_THREAD)) {
870 QETH_CARD_TEXT(card, 3, "openREC");
871 return -ERESTARTSYS;
872 }
873 return __qeth_l2_open(dev);
874}
875
Frank Blaschka4a71df52008-02-15 09:19:42 +0100876static int qeth_l2_stop(struct net_device *dev)
877{
Heiko Carstens509e2562008-07-26 02:24:10 -0700878 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100879
Carsten Otte847a50f2010-06-21 22:57:05 +0000880 QETH_CARD_TEXT(card, 4, "qethstop");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100881 netif_tx_disable(dev);
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000882 if (card->state == CARD_STATE_UP) {
Frank Blaschka4a71df52008-02-15 09:19:42 +0100883 card->state = CARD_STATE_SOFTSETUP;
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000884 napi_disable(&card->napi);
885 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100886 return 0;
887}
888
889static int qeth_l2_probe_device(struct ccwgroup_device *gdev)
890{
891 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
892
Eugene Crosserb4d72c02014-01-14 15:54:11 +0100893 qeth_l2_create_device_attributes(&gdev->dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100894 INIT_LIST_HEAD(&card->vid_list);
895 INIT_LIST_HEAD(&card->mc_list);
896 card->options.layer2 = 1;
Frank Blaschka1da74b12011-05-12 18:45:02 +0000897 card->info.hwtrap = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100898 return 0;
899}
900
901static void qeth_l2_remove_device(struct ccwgroup_device *cgdev)
902{
903 struct qeth_card *card = dev_get_drvdata(&cgdev->dev);
904
Eugene Crosserb4d72c02014-01-14 15:54:11 +0100905 qeth_l2_remove_device_attributes(&cgdev->dev);
Ursula Braunf2148562009-05-19 21:38:37 +0000906 qeth_set_allowed_threads(card, 0, 1);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100907 wait_event(card->wait_q, qeth_threads_running(card, 0xffffffff) == 0);
908
Ursula Braun70919e22011-02-26 22:41:36 -0800909 if (cgdev->state == CCWGROUP_ONLINE)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100910 qeth_l2_set_offline(cgdev);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100911
912 if (card->dev) {
913 unregister_netdev(card->dev);
914 card->dev = NULL;
915 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100916 return;
917}
918
Stephen Hemminger0fc0b732009-09-02 01:03:33 -0700919static const struct ethtool_ops qeth_l2_ethtool_ops = {
Frank Blaschka4a71df52008-02-15 09:19:42 +0100920 .get_link = ethtool_op_get_link,
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,
Frank Blaschka3f9975a2008-04-24 10:15:23 +0200925 .get_settings = qeth_core_ethtool_get_settings,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100926};
927
Stephen Hemminger0fc0b732009-09-02 01:03:33 -0700928static const struct ethtool_ops qeth_l2_osn_ops = {
Frank Blaschka4a71df52008-02-15 09:19:42 +0100929 .get_strings = qeth_core_get_strings,
930 .get_ethtool_stats = qeth_core_get_ethtool_stats,
Ben Hutchingsdf8b4ec2009-10-01 11:24:32 +0000931 .get_sset_count = qeth_core_get_sset_count,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100932 .get_drvinfo = qeth_core_get_drvinfo,
933};
934
Frank Blaschka3d58cef2009-01-09 03:44:00 +0000935static const struct net_device_ops qeth_l2_netdev_ops = {
Frank Blaschka8403b132009-01-08 10:50:55 -0800936 .ndo_open = qeth_l2_open,
937 .ndo_stop = qeth_l2_stop,
938 .ndo_get_stats = qeth_get_stats,
939 .ndo_start_xmit = qeth_l2_hard_start_xmit,
940 .ndo_validate_addr = eth_validate_addr,
Jiri Pirkoafc4b132011-08-16 06:29:01 +0000941 .ndo_set_rx_mode = qeth_l2_set_multicast_list,
Frank Blaschka8403b132009-01-08 10:50:55 -0800942 .ndo_do_ioctl = qeth_l2_do_ioctl,
943 .ndo_set_mac_address = qeth_l2_set_mac_address,
944 .ndo_change_mtu = qeth_change_mtu,
945 .ndo_vlan_rx_add_vid = qeth_l2_vlan_rx_add_vid,
946 .ndo_vlan_rx_kill_vid = qeth_l2_vlan_rx_kill_vid,
947 .ndo_tx_timeout = qeth_tx_timeout,
948};
949
Frank Blaschka4a71df52008-02-15 09:19:42 +0100950static int qeth_l2_setup_netdev(struct qeth_card *card)
951{
952 switch (card->info.type) {
Frank Blaschka4a71df52008-02-15 09:19:42 +0100953 case QETH_CARD_TYPE_IQD:
Tom Gundersenc835a672014-07-14 16:37:24 +0200954 card->dev = alloc_netdev(0, "hsi%d", NET_NAME_UNKNOWN,
955 ether_setup);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100956 break;
957 case QETH_CARD_TYPE_OSN:
Tom Gundersenc835a672014-07-14 16:37:24 +0200958 card->dev = alloc_netdev(0, "osn%d", NET_NAME_UNKNOWN,
959 ether_setup);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100960 card->dev->flags |= IFF_NOARP;
961 break;
962 default:
963 card->dev = alloc_etherdev(0);
964 }
965
966 if (!card->dev)
967 return -ENODEV;
968
Heiko Carstens509e2562008-07-26 02:24:10 -0700969 card->dev->ml_priv = card;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100970 card->dev->watchdog_timeo = QETH_TX_TIMEOUT;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100971 card->dev->mtu = card->info.initial_mtu;
Frank Blaschka8403b132009-01-08 10:50:55 -0800972 card->dev->netdev_ops = &qeth_l2_netdev_ops;
Wilfried Klaebe7ad24ea2014-05-11 00:12:32 +0000973 card->dev->ethtool_ops =
974 (card->info.type != QETH_CARD_TYPE_OSN) ?
975 &qeth_l2_ethtool_ops : &qeth_l2_osn_ops;
Patrick McHardyf6469682013-04-19 02:04:27 +0000976 card->dev->features |= NETIF_F_HW_VLAN_CTAG_FILTER;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100977 card->info.broadcast_capable = 1;
978 qeth_l2_request_initial_mac(card);
979 SET_NETDEV_DEV(card->dev, &card->gdev->dev);
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000980 netif_napi_add(card->dev, &card->napi, qeth_l2_poll, QETH_NAPI_WEIGHT);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100981 return register_netdev(card->dev);
982}
983
984static int __qeth_l2_set_online(struct ccwgroup_device *gdev, int recovery_mode)
985{
986 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
987 int rc = 0;
988 enum qeth_card_states recover_flag;
989
Ursula Braun9dc48cc2010-07-22 23:15:05 +0000990 mutex_lock(&card->discipline_mutex);
Frank Blaschkac4949f02010-05-11 19:34:47 +0000991 mutex_lock(&card->conf_mutex);
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200992 QETH_DBF_TEXT(SETUP, 2, "setonlin");
993 QETH_DBF_HEX(SETUP, 2, &card, sizeof(void *));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100994
Frank Blaschka4a71df52008-02-15 09:19:42 +0100995 recover_flag = card->state;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100996 rc = qeth_core_hardsetup_card(card);
997 if (rc) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200998 QETH_DBF_TEXT_(SETUP, 2, "2err%d", rc);
Ursula Braunaa909222009-11-12 00:11:43 +0000999 rc = -ENODEV;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001000 goto out_remove;
1001 }
Eugene Crosserc044dc22014-01-29 09:23:48 +01001002 qeth_bridgeport_query_support(card);
1003 if (card->options.sbp.supported_funcs)
1004 dev_info(&card->gdev->dev,
1005 "The device represents a HiperSockets Bridge Capable Port\n");
Stefan Raspl395672e02012-11-19 02:46:49 +00001006 qeth_trace_features(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001007
Ursula Braunaa909222009-11-12 00:11:43 +00001008 if (!card->dev && qeth_l2_setup_netdev(card)) {
1009 rc = -ENODEV;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001010 goto out_remove;
Ursula Braunaa909222009-11-12 00:11:43 +00001011 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01001012
1013 if (card->info.type != QETH_CARD_TYPE_OSN)
1014 qeth_l2_send_setmac(card, &card->dev->dev_addr[0]);
1015
Frank Blaschka1da74b12011-05-12 18:45:02 +00001016 if (qeth_is_diagass_supported(card, QETH_DIAGS_CMD_TRAP)) {
1017 if (card->info.hwtrap &&
1018 qeth_hw_trap(card, QETH_DIAGS_TRAP_ARM))
1019 card->info.hwtrap = 0;
1020 } else
1021 card->info.hwtrap = 0;
1022
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001023 qeth_l2_setup_bridgeport_attrs(card);
1024
Frank Blaschka4a71df52008-02-15 09:19:42 +01001025 card->state = CARD_STATE_HARDSETUP;
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00001026 memset(&card->rx, 0, sizeof(struct qeth_rx));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001027 qeth_print_status_message(card);
1028
1029 /* softsetup */
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001030 QETH_DBF_TEXT(SETUP, 2, "softsetp");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001031
1032 rc = qeth_send_startlan(card);
1033 if (rc) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001034 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001035 if (rc == 0xe080) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001036 dev_warn(&card->gdev->dev,
1037 "The LAN is offline\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001038 card->lan_online = 0;
Ursula Braun2b6203b2010-11-26 02:41:19 +00001039 goto contin;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001040 }
Ursula Braunaa909222009-11-12 00:11:43 +00001041 rc = -ENODEV;
Ursula Braunf2148562009-05-19 21:38:37 +00001042 goto out_remove;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001043 } else
1044 card->lan_online = 1;
1045
Ursula Braun2b6203b2010-11-26 02:41:19 +00001046contin:
Ursula Braun5113fec2010-05-16 21:15:14 +00001047 if ((card->info.type == QETH_CARD_TYPE_OSD) ||
Stefan Raspl0f547612013-01-21 02:30:20 +00001048 (card->info.type == QETH_CARD_TYPE_OSX)) {
Einar Lueckd64ecc22009-11-12 00:11:41 +00001049 /* configure isolation level */
Stefan Raspl0f547612013-01-21 02:30:20 +00001050 rc = qeth_set_access_ctrl_online(card, 0);
1051 if (rc) {
1052 rc = -ENODEV;
1053 goto out_remove;
1054 }
1055 }
Ursula Braun5113fec2010-05-16 21:15:14 +00001056
1057 if (card->info.type != QETH_CARD_TYPE_OSN &&
1058 card->info.type != QETH_CARD_TYPE_OSM)
Ursula Braun70919e22011-02-26 22:41:36 -08001059 qeth_l2_process_vlans(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001060
1061 netif_tx_disable(card->dev);
1062
1063 rc = qeth_init_qdio_queues(card);
1064 if (rc) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001065 QETH_DBF_TEXT_(SETUP, 2, "6err%d", rc);
Ursula Braunaa909222009-11-12 00:11:43 +00001066 rc = -ENODEV;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001067 goto out_remove;
1068 }
1069 card->state = CARD_STATE_SOFTSETUP;
Ursula Braun2b6203b2010-11-26 02:41:19 +00001070 if (card->lan_online)
1071 netif_carrier_on(card->dev);
1072 else
1073 netif_carrier_off(card->dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001074
1075 qeth_set_allowed_threads(card, 0xffffffff, 0);
1076 if (recover_flag == CARD_STATE_RECOVER) {
1077 if (recovery_mode &&
1078 card->info.type != QETH_CARD_TYPE_OSN) {
Ursula Braun39423442011-01-12 20:42:24 +00001079 __qeth_l2_open(card->dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001080 } else {
1081 rtnl_lock();
1082 dev_open(card->dev);
1083 rtnl_unlock();
1084 }
1085 /* this also sets saved unicast addresses */
1086 qeth_l2_set_multicast_list(card->dev);
1087 }
1088 /* let user_space know that device is online */
1089 kobject_uevent(&gdev->dev.kobj, KOBJ_CHANGE);
Frank Blaschkac4949f02010-05-11 19:34:47 +00001090 mutex_unlock(&card->conf_mutex);
Ursula Braun9dc48cc2010-07-22 23:15:05 +00001091 mutex_unlock(&card->discipline_mutex);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001092 return 0;
Ursula Braunaa909222009-11-12 00:11:43 +00001093
Frank Blaschka4a71df52008-02-15 09:19:42 +01001094out_remove:
Frank Blaschka4a71df52008-02-15 09:19:42 +01001095 qeth_l2_stop_card(card, 0);
1096 ccw_device_set_offline(CARD_DDEV(card));
1097 ccw_device_set_offline(CARD_WDEV(card));
1098 ccw_device_set_offline(CARD_RDEV(card));
Ursula Braun22ae2792014-02-24 13:12:06 +01001099 qdio_free(CARD_DDEV(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001100 if (recover_flag == CARD_STATE_RECOVER)
1101 card->state = CARD_STATE_RECOVER;
1102 else
1103 card->state = CARD_STATE_DOWN;
Frank Blaschkac4949f02010-05-11 19:34:47 +00001104 mutex_unlock(&card->conf_mutex);
Ursula Braun9dc48cc2010-07-22 23:15:05 +00001105 mutex_unlock(&card->discipline_mutex);
Ursula Braunaa909222009-11-12 00:11:43 +00001106 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001107}
1108
1109static int qeth_l2_set_online(struct ccwgroup_device *gdev)
1110{
1111 return __qeth_l2_set_online(gdev, 0);
1112}
1113
1114static int __qeth_l2_set_offline(struct ccwgroup_device *cgdev,
1115 int recovery_mode)
1116{
1117 struct qeth_card *card = dev_get_drvdata(&cgdev->dev);
1118 int rc = 0, rc2 = 0, rc3 = 0;
1119 enum qeth_card_states recover_flag;
1120
Ursula Braun9dc48cc2010-07-22 23:15:05 +00001121 mutex_lock(&card->discipline_mutex);
Frank Blaschkac4949f02010-05-11 19:34:47 +00001122 mutex_lock(&card->conf_mutex);
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001123 QETH_DBF_TEXT(SETUP, 3, "setoffl");
1124 QETH_DBF_HEX(SETUP, 3, &card, sizeof(void *));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001125
1126 if (card->dev && netif_carrier_ok(card->dev))
1127 netif_carrier_off(card->dev);
1128 recover_flag = card->state;
Frank Blaschka1da74b12011-05-12 18:45:02 +00001129 if ((!recovery_mode && card->info.hwtrap) || card->info.hwtrap == 2) {
1130 qeth_hw_trap(card, QETH_DIAGS_TRAP_DISARM);
1131 card->info.hwtrap = 1;
1132 }
Ursula Braun0f5623c2008-10-24 11:16:52 +02001133 qeth_l2_stop_card(card, recovery_mode);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001134 rc = ccw_device_set_offline(CARD_DDEV(card));
1135 rc2 = ccw_device_set_offline(CARD_WDEV(card));
1136 rc3 = ccw_device_set_offline(CARD_RDEV(card));
1137 if (!rc)
1138 rc = (rc2) ? rc2 : rc3;
1139 if (rc)
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001140 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
Ursula Braun22ae2792014-02-24 13:12:06 +01001141 qdio_free(CARD_DDEV(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001142 if (recover_flag == CARD_STATE_UP)
1143 card->state = CARD_STATE_RECOVER;
1144 /* let user_space know that device is offline */
1145 kobject_uevent(&cgdev->dev.kobj, KOBJ_CHANGE);
Frank Blaschkac4949f02010-05-11 19:34:47 +00001146 mutex_unlock(&card->conf_mutex);
Ursula Braun9dc48cc2010-07-22 23:15:05 +00001147 mutex_unlock(&card->discipline_mutex);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001148 return 0;
1149}
1150
1151static int qeth_l2_set_offline(struct ccwgroup_device *cgdev)
1152{
1153 return __qeth_l2_set_offline(cgdev, 0);
1154}
1155
1156static int qeth_l2_recover(void *ptr)
1157{
1158 struct qeth_card *card;
1159 int rc = 0;
1160
1161 card = (struct qeth_card *) ptr;
Carsten Otte847a50f2010-06-21 22:57:05 +00001162 QETH_CARD_TEXT(card, 2, "recover1");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001163 if (!qeth_do_run_thread(card, QETH_RECOVER_THREAD))
1164 return 0;
Carsten Otte847a50f2010-06-21 22:57:05 +00001165 QETH_CARD_TEXT(card, 2, "recover2");
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001166 dev_warn(&card->gdev->dev,
1167 "A recovery process has been started for the device\n");
Stefan Raspl65d80132013-04-07 22:19:27 +00001168 qeth_set_recovery_task(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001169 __qeth_l2_set_offline(card->gdev, 1);
1170 rc = __qeth_l2_set_online(card->gdev, 1);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001171 if (!rc)
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001172 dev_info(&card->gdev->dev,
1173 "Device successfully recovered!\n");
Ursula Braun28a7e4c2008-09-19 12:56:03 +02001174 else {
Stefan Raspl0f547612013-01-21 02:30:20 +00001175 qeth_close_dev(card);
1176 dev_warn(&card->gdev->dev, "The qeth device driver "
Stefan Raspl2efaf5f2012-10-15 19:21:18 +00001177 "failed to recover an error on the device\n");
Ursula Braun28a7e4c2008-09-19 12:56:03 +02001178 }
Stefan Raspl65d80132013-04-07 22:19:27 +00001179 qeth_clear_recovery_task(card);
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00001180 qeth_clear_thread_start_bit(card, QETH_RECOVER_THREAD);
1181 qeth_clear_thread_running_bit(card, QETH_RECOVER_THREAD);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001182 return 0;
1183}
1184
1185static int __init qeth_l2_init(void)
1186{
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001187 pr_info("register layer 2 discipline\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001188 return 0;
1189}
1190
1191static void __exit qeth_l2_exit(void)
1192{
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001193 pr_info("unregister layer 2 discipline\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001194}
1195
1196static void qeth_l2_shutdown(struct ccwgroup_device *gdev)
1197{
1198 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
Ursula Braunf78ac2b2011-12-19 22:56:33 +00001199 qeth_set_allowed_threads(card, 0, 1);
Frank Blaschka1da74b12011-05-12 18:45:02 +00001200 if ((gdev->state == CCWGROUP_ONLINE) && card->info.hwtrap)
1201 qeth_hw_trap(card, QETH_DIAGS_TRAP_DISARM);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001202 qeth_qdio_clear_card(card, 0);
1203 qeth_clear_qdio_buffers(card);
Ursula Braun22ae2792014-02-24 13:12:06 +01001204 qdio_free(CARD_DDEV(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001205}
1206
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02001207static int qeth_l2_pm_suspend(struct ccwgroup_device *gdev)
1208{
1209 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
1210
1211 if (card->dev)
1212 netif_device_detach(card->dev);
1213 qeth_set_allowed_threads(card, 0, 1);
1214 wait_event(card->wait_q, qeth_threads_running(card, 0xffffffff) == 0);
1215 if (gdev->state == CCWGROUP_OFFLINE)
1216 return 0;
1217 if (card->state == CARD_STATE_UP) {
Frank Blaschka1da74b12011-05-12 18:45:02 +00001218 if (card->info.hwtrap)
1219 qeth_hw_trap(card, QETH_DIAGS_TRAP_DISARM);
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02001220 __qeth_l2_set_offline(card->gdev, 1);
1221 } else
1222 __qeth_l2_set_offline(card->gdev, 0);
1223 return 0;
1224}
1225
1226static int qeth_l2_pm_resume(struct ccwgroup_device *gdev)
1227{
1228 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
1229 int rc = 0;
1230
1231 if (gdev->state == CCWGROUP_OFFLINE)
1232 goto out;
1233
1234 if (card->state == CARD_STATE_RECOVER) {
1235 rc = __qeth_l2_set_online(card->gdev, 1);
1236 if (rc) {
Ursula Braun869da902010-03-08 20:36:56 +00001237 rtnl_lock();
1238 dev_close(card->dev);
1239 rtnl_unlock();
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02001240 }
1241 } else
1242 rc = __qeth_l2_set_online(card->gdev, 0);
1243out:
1244 qeth_set_allowed_threads(card, 0xffffffff, 0);
1245 if (card->dev)
1246 netif_device_attach(card->dev);
1247 if (rc)
1248 dev_warn(&card->gdev->dev, "The qeth device driver "
1249 "failed to recover an error on the device\n");
1250 return rc;
1251}
1252
Eugene Crosserc044dc22014-01-29 09:23:48 +01001253/* Returns zero if the command is successfully "consumed" */
1254static int qeth_l2_control_event(struct qeth_card *card,
1255 struct qeth_ipa_cmd *cmd)
1256{
1257 switch (cmd->hdr.command) {
1258 case IPA_CMD_SETBRIDGEPORT:
1259 if (cmd->data.sbp.hdr.command_code ==
1260 IPA_SBP_BRIDGE_PORT_STATE_CHANGE) {
1261 qeth_bridge_state_change(card, cmd);
1262 return 0;
1263 } else
1264 return 1;
1265 case IPA_CMD_ADDRESS_CHANGE_NOTIF:
1266 qeth_bridge_host_event(card, cmd);
1267 return 0;
1268 default:
1269 return 1;
1270 }
1271}
1272
Sebastian Ottc041f2d4872012-05-15 18:02:21 +02001273struct qeth_discipline qeth_l2_discipline = {
1274 .start_poll = qeth_qdio_start_poll,
1275 .input_handler = (qdio_handler_t *) qeth_qdio_input_handler,
1276 .output_handler = (qdio_handler_t *) qeth_qdio_output_handler,
1277 .recover = qeth_l2_recover,
1278 .setup = qeth_l2_probe_device,
Frank Blaschka4a71df52008-02-15 09:19:42 +01001279 .remove = qeth_l2_remove_device,
1280 .set_online = qeth_l2_set_online,
1281 .set_offline = qeth_l2_set_offline,
1282 .shutdown = qeth_l2_shutdown,
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02001283 .freeze = qeth_l2_pm_suspend,
1284 .thaw = qeth_l2_pm_resume,
1285 .restore = qeth_l2_pm_resume,
Eugene Crosserc044dc22014-01-29 09:23:48 +01001286 .control_event_handler = qeth_l2_control_event,
Frank Blaschka4a71df52008-02-15 09:19:42 +01001287};
Sebastian Ottc041f2d4872012-05-15 18:02:21 +02001288EXPORT_SYMBOL_GPL(qeth_l2_discipline);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001289
1290static int qeth_osn_send_control_data(struct qeth_card *card, int len,
1291 struct qeth_cmd_buffer *iob)
1292{
1293 unsigned long flags;
1294 int rc = 0;
1295
Carsten Otte847a50f2010-06-21 22:57:05 +00001296 QETH_CARD_TEXT(card, 5, "osndctrd");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001297
1298 wait_event(card->wait_q,
1299 atomic_cmpxchg(&card->write.irq_pending, 0, 1) == 0);
1300 qeth_prepare_control_data(card, len, iob);
Carsten Otte847a50f2010-06-21 22:57:05 +00001301 QETH_CARD_TEXT(card, 6, "osnoirqp");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001302 spin_lock_irqsave(get_ccwdev_lock(card->write.ccwdev), flags);
1303 rc = ccw_device_start(card->write.ccwdev, &card->write.ccw,
1304 (addr_t) iob, 0, 0);
1305 spin_unlock_irqrestore(get_ccwdev_lock(card->write.ccwdev), flags);
1306 if (rc) {
Frank Blaschka14cc21b2008-06-06 12:37:46 +02001307 QETH_DBF_MESSAGE(2, "qeth_osn_send_control_data: "
Frank Blaschka4a71df52008-02-15 09:19:42 +01001308 "ccw_device_start rc = %i\n", rc);
Carsten Otte847a50f2010-06-21 22:57:05 +00001309 QETH_CARD_TEXT_(card, 2, " err%d", rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001310 qeth_release_buffer(iob->channel, iob);
1311 atomic_set(&card->write.irq_pending, 0);
1312 wake_up(&card->wait_q);
1313 }
1314 return rc;
1315}
1316
1317static int qeth_osn_send_ipa_cmd(struct qeth_card *card,
1318 struct qeth_cmd_buffer *iob, int data_len)
1319{
1320 u16 s1, s2;
1321
Carsten Otte847a50f2010-06-21 22:57:05 +00001322 QETH_CARD_TEXT(card, 4, "osndipa");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001323
1324 qeth_prepare_ipa_cmd(card, iob, QETH_PROT_OSN2);
1325 s1 = (u16)(IPA_PDU_HEADER_SIZE + data_len);
1326 s2 = (u16)data_len;
1327 memcpy(QETH_IPA_PDU_LEN_TOTAL(iob->data), &s1, 2);
1328 memcpy(QETH_IPA_PDU_LEN_PDU1(iob->data), &s2, 2);
1329 memcpy(QETH_IPA_PDU_LEN_PDU2(iob->data), &s2, 2);
1330 memcpy(QETH_IPA_PDU_LEN_PDU3(iob->data), &s2, 2);
1331 return qeth_osn_send_control_data(card, s1, iob);
1332}
1333
1334int qeth_osn_assist(struct net_device *dev, void *data, int data_len)
1335{
1336 struct qeth_cmd_buffer *iob;
1337 struct qeth_card *card;
1338 int rc;
1339
Frank Blaschka4a71df52008-02-15 09:19:42 +01001340 if (!dev)
1341 return -ENODEV;
Heiko Carstens509e2562008-07-26 02:24:10 -07001342 card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001343 if (!card)
1344 return -ENODEV;
Carsten Otte847a50f2010-06-21 22:57:05 +00001345 QETH_CARD_TEXT(card, 2, "osnsdmc");
Eugene Crosserc3521252015-01-16 14:05:47 +01001346 if (!qeth_card_hw_is_reachable(card))
Frank Blaschka4a71df52008-02-15 09:19:42 +01001347 return -ENODEV;
1348 iob = qeth_wait_for_buffer(&card->write);
1349 memcpy(iob->data+IPA_PDU_HEADER_SIZE, data, data_len);
1350 rc = qeth_osn_send_ipa_cmd(card, iob, data_len);
1351 return rc;
1352}
1353EXPORT_SYMBOL(qeth_osn_assist);
1354
1355int qeth_osn_register(unsigned char *read_dev_no, struct net_device **dev,
1356 int (*assist_cb)(struct net_device *, void *),
1357 int (*data_cb)(struct sk_buff *))
1358{
1359 struct qeth_card *card;
1360
Frank Blaschka4a71df52008-02-15 09:19:42 +01001361 *dev = qeth_l2_netdev_by_devno(read_dev_no);
1362 if (*dev == NULL)
1363 return -ENODEV;
Heiko Carstens509e2562008-07-26 02:24:10 -07001364 card = (*dev)->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001365 if (!card)
1366 return -ENODEV;
Carsten Otte847a50f2010-06-21 22:57:05 +00001367 QETH_CARD_TEXT(card, 2, "osnreg");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001368 if ((assist_cb == NULL) || (data_cb == NULL))
1369 return -EINVAL;
1370 card->osn_info.assist_cb = assist_cb;
1371 card->osn_info.data_cb = data_cb;
1372 return 0;
1373}
1374EXPORT_SYMBOL(qeth_osn_register);
1375
1376void qeth_osn_deregister(struct net_device *dev)
1377{
1378 struct qeth_card *card;
1379
Frank Blaschka4a71df52008-02-15 09:19:42 +01001380 if (!dev)
1381 return;
Heiko Carstens509e2562008-07-26 02:24:10 -07001382 card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001383 if (!card)
1384 return;
Carsten Otte847a50f2010-06-21 22:57:05 +00001385 QETH_CARD_TEXT(card, 2, "osndereg");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001386 card->osn_info.assist_cb = NULL;
1387 card->osn_info.data_cb = NULL;
1388 return;
1389}
1390EXPORT_SYMBOL(qeth_osn_deregister);
1391
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001392/* SETBRIDGEPORT support, async notifications */
1393
Eugene Crosser9f48b9d2014-01-14 15:54:13 +01001394enum qeth_an_event_type {anev_reg_unreg, anev_abort, anev_reset};
1395
1396/**
1397 * qeth_bridge_emit_host_event() - bridgeport address change notification
1398 * @card: qeth_card structure pointer, for udev events.
1399 * @evtype: "normal" register/unregister, or abort, or reset. For abort
1400 * and reset token and addr_lnid are unused and may be NULL.
1401 * @code: event bitmask: high order bit 0x80 value 1 means removal of an
1402 * object, 0 - addition of an object.
1403 * 0x01 - VLAN, 0x02 - MAC, 0x03 - VLAN and MAC.
1404 * @token: "network token" structure identifying physical address of the port.
1405 * @addr_lnid: pointer to structure with MAC address and VLAN ID.
1406 *
1407 * This function is called when registrations and deregistrations are
1408 * reported by the hardware, and also when notifications are enabled -
1409 * for all currently registered addresses.
1410 */
1411static void qeth_bridge_emit_host_event(struct qeth_card *card,
1412 enum qeth_an_event_type evtype,
1413 u8 code, struct net_if_token *token, struct mac_addr_lnid *addr_lnid)
1414{
1415 char str[7][32];
1416 char *env[8];
1417 int i = 0;
1418
1419 switch (evtype) {
1420 case anev_reg_unreg:
1421 snprintf(str[i], sizeof(str[i]), "BRIDGEDHOST=%s",
1422 (code & IPA_ADDR_CHANGE_CODE_REMOVAL)
1423 ? "deregister" : "register");
1424 env[i] = str[i]; i++;
1425 if (code & IPA_ADDR_CHANGE_CODE_VLANID) {
1426 snprintf(str[i], sizeof(str[i]), "VLAN=%d",
1427 addr_lnid->lnid);
1428 env[i] = str[i]; i++;
1429 }
1430 if (code & IPA_ADDR_CHANGE_CODE_MACADDR) {
1431 snprintf(str[i], sizeof(str[i]), "MAC=%pM6",
1432 &addr_lnid->mac);
1433 env[i] = str[i]; i++;
1434 }
1435 snprintf(str[i], sizeof(str[i]), "NTOK_BUSID=%x.%x.%04x",
1436 token->cssid, token->ssid, token->devnum);
1437 env[i] = str[i]; i++;
1438 snprintf(str[i], sizeof(str[i]), "NTOK_IID=%02x", token->iid);
1439 env[i] = str[i]; i++;
1440 snprintf(str[i], sizeof(str[i]), "NTOK_CHPID=%02x",
1441 token->chpid);
1442 env[i] = str[i]; i++;
1443 snprintf(str[i], sizeof(str[i]), "NTOK_CHID=%04x", token->chid);
1444 env[i] = str[i]; i++;
1445 break;
1446 case anev_abort:
1447 snprintf(str[i], sizeof(str[i]), "BRIDGEDHOST=abort");
1448 env[i] = str[i]; i++;
1449 break;
1450 case anev_reset:
1451 snprintf(str[i], sizeof(str[i]), "BRIDGEDHOST=reset");
1452 env[i] = str[i]; i++;
1453 break;
1454 }
1455 env[i] = NULL;
1456 kobject_uevent_env(&card->gdev->dev.kobj, KOBJ_CHANGE, env);
1457}
1458
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001459struct qeth_bridge_state_data {
1460 struct work_struct worker;
1461 struct qeth_card *card;
1462 struct qeth_sbp_state_change qports;
1463};
1464
1465static void qeth_bridge_state_change_worker(struct work_struct *work)
1466{
1467 struct qeth_bridge_state_data *data =
1468 container_of(work, struct qeth_bridge_state_data, worker);
1469 /* We are only interested in the first entry - local port */
1470 struct qeth_sbp_port_entry *entry = &data->qports.entry[0];
1471 char env_locrem[32];
1472 char env_role[32];
1473 char env_state[32];
1474 char *env[] = {
1475 env_locrem,
1476 env_role,
1477 env_state,
1478 NULL
1479 };
1480
1481 /* Role should not change by itself, but if it did, */
1482 /* information from the hardware is authoritative. */
1483 mutex_lock(&data->card->conf_mutex);
1484 data->card->options.sbp.role = entry->role;
1485 mutex_unlock(&data->card->conf_mutex);
1486
1487 snprintf(env_locrem, sizeof(env_locrem), "BRIDGEPORT=statechange");
1488 snprintf(env_role, sizeof(env_role), "ROLE=%s",
1489 (entry->role == QETH_SBP_ROLE_NONE) ? "none" :
1490 (entry->role == QETH_SBP_ROLE_PRIMARY) ? "primary" :
1491 (entry->role == QETH_SBP_ROLE_SECONDARY) ? "secondary" :
1492 "<INVALID>");
1493 snprintf(env_state, sizeof(env_state), "STATE=%s",
1494 (entry->state == QETH_SBP_STATE_INACTIVE) ? "inactive" :
1495 (entry->state == QETH_SBP_STATE_STANDBY) ? "standby" :
1496 (entry->state == QETH_SBP_STATE_ACTIVE) ? "active" :
1497 "<INVALID>");
1498 kobject_uevent_env(&data->card->gdev->dev.kobj,
1499 KOBJ_CHANGE, env);
1500 kfree(data);
1501}
1502
Eugene Crosserc044dc22014-01-29 09:23:48 +01001503static void qeth_bridge_state_change(struct qeth_card *card,
1504 struct qeth_ipa_cmd *cmd)
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001505{
1506 struct qeth_sbp_state_change *qports =
1507 &cmd->data.sbp.data.state_change;
1508 struct qeth_bridge_state_data *data;
1509 int extrasize;
1510
1511 QETH_CARD_TEXT(card, 2, "brstchng");
1512 if (qports->entry_length != sizeof(struct qeth_sbp_port_entry)) {
Thomas Richter8a593142014-10-22 12:18:03 +02001513 QETH_CARD_TEXT_(card, 2, "BPsz%04x", qports->entry_length);
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001514 return;
1515 }
1516 extrasize = sizeof(struct qeth_sbp_port_entry) * qports->num_entries;
1517 data = kzalloc(sizeof(struct qeth_bridge_state_data) + extrasize,
1518 GFP_ATOMIC);
1519 if (!data) {
1520 QETH_CARD_TEXT(card, 2, "BPSalloc");
1521 return;
1522 }
1523 INIT_WORK(&data->worker, qeth_bridge_state_change_worker);
1524 data->card = card;
1525 memcpy(&data->qports, qports,
1526 sizeof(struct qeth_sbp_state_change) + extrasize);
1527 queue_work(qeth_wq, &data->worker);
1528}
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001529
Eugene Crosser9f48b9d2014-01-14 15:54:13 +01001530struct qeth_bridge_host_data {
1531 struct work_struct worker;
1532 struct qeth_card *card;
1533 struct qeth_ipacmd_addr_change hostevs;
1534};
1535
1536static void qeth_bridge_host_event_worker(struct work_struct *work)
1537{
1538 struct qeth_bridge_host_data *data =
1539 container_of(work, struct qeth_bridge_host_data, worker);
1540 int i;
1541
1542 if (data->hostevs.lost_event_mask) {
1543 dev_info(&data->card->gdev->dev,
1544"Address notification from the HiperSockets Bridge Port stopped %s (%s)\n",
1545 data->card->dev->name,
1546 (data->hostevs.lost_event_mask == 0x01)
1547 ? "Overflow"
1548 : (data->hostevs.lost_event_mask == 0x02)
1549 ? "Bridge port state change"
1550 : "Unknown reason");
1551 mutex_lock(&data->card->conf_mutex);
1552 data->card->options.sbp.hostnotification = 0;
1553 mutex_unlock(&data->card->conf_mutex);
1554 qeth_bridge_emit_host_event(data->card, anev_abort,
1555 0, NULL, NULL);
1556 } else
1557 for (i = 0; i < data->hostevs.num_entries; i++) {
1558 struct qeth_ipacmd_addr_change_entry *entry =
1559 &data->hostevs.entry[i];
1560 qeth_bridge_emit_host_event(data->card,
1561 anev_reg_unreg,
1562 entry->change_code,
1563 &entry->token, &entry->addr_lnid);
1564 }
1565 kfree(data);
1566}
1567
Eugene Crosserc044dc22014-01-29 09:23:48 +01001568static void qeth_bridge_host_event(struct qeth_card *card,
1569 struct qeth_ipa_cmd *cmd)
Eugene Crosser9f48b9d2014-01-14 15:54:13 +01001570{
1571 struct qeth_ipacmd_addr_change *hostevs =
1572 &cmd->data.addrchange;
1573 struct qeth_bridge_host_data *data;
1574 int extrasize;
1575
1576 QETH_CARD_TEXT(card, 2, "brhostev");
1577 if (cmd->hdr.return_code != 0x0000) {
1578 if (cmd->hdr.return_code == 0x0010) {
1579 if (hostevs->lost_event_mask == 0x00)
1580 hostevs->lost_event_mask = 0xff;
1581 } else {
1582 QETH_CARD_TEXT_(card, 2, "BPHe%04x",
1583 cmd->hdr.return_code);
1584 return;
1585 }
1586 }
1587 extrasize = sizeof(struct qeth_ipacmd_addr_change_entry) *
1588 hostevs->num_entries;
1589 data = kzalloc(sizeof(struct qeth_bridge_host_data) + extrasize,
1590 GFP_ATOMIC);
1591 if (!data) {
1592 QETH_CARD_TEXT(card, 2, "BPHalloc");
1593 return;
1594 }
1595 INIT_WORK(&data->worker, qeth_bridge_host_event_worker);
1596 data->card = card;
1597 memcpy(&data->hostevs, hostevs,
1598 sizeof(struct qeth_ipacmd_addr_change) + extrasize);
1599 queue_work(qeth_wq, &data->worker);
1600}
Eugene Crosser9f48b9d2014-01-14 15:54:13 +01001601
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001602/* SETBRIDGEPORT support; sending commands */
1603
1604struct _qeth_sbp_cbctl {
1605 u16 ipa_rc;
1606 u16 cmd_rc;
1607 union {
1608 u32 supported;
1609 struct {
1610 enum qeth_sbp_roles *role;
1611 enum qeth_sbp_states *state;
1612 } qports;
1613 } data;
1614};
1615
1616/**
1617 * qeth_bridgeport_makerc() - derive "traditional" error from hardware codes.
1618 * @card: qeth_card structure pointer, for debug messages.
1619 * @cbctl: state structure with hardware return codes.
1620 * @setcmd: IPA command code
1621 *
1622 * Returns negative errno-compatible error indication or 0 on success.
1623 */
1624static int qeth_bridgeport_makerc(struct qeth_card *card,
1625 struct _qeth_sbp_cbctl *cbctl, enum qeth_ipa_sbp_cmd setcmd)
1626{
1627 int rc;
1628
1629 switch (cbctl->ipa_rc) {
1630 case IPA_RC_SUCCESS:
1631 switch (cbctl->cmd_rc) {
1632 case 0x0000:
1633 rc = 0;
1634 break;
1635 case 0x0004:
1636 rc = -ENOSYS;
1637 break;
1638 case 0x000C: /* Not configured as bridge Port */
1639 rc = -ENODEV; /* maybe not the best code here? */
1640 dev_err(&card->gdev->dev,
1641 "The HiperSockets device is not configured as a Bridge Port\n");
1642 break;
1643 case 0x0014: /* Another device is Primary */
1644 switch (setcmd) {
1645 case IPA_SBP_SET_PRIMARY_BRIDGE_PORT:
1646 rc = -EEXIST;
1647 dev_err(&card->gdev->dev,
1648 "The HiperSockets LAN already has a primary Bridge Port\n");
1649 break;
1650 case IPA_SBP_SET_SECONDARY_BRIDGE_PORT:
1651 rc = -EBUSY;
1652 dev_err(&card->gdev->dev,
1653 "The HiperSockets device is already a primary Bridge Port\n");
1654 break;
1655 default:
1656 rc = -EIO;
1657 }
1658 break;
1659 case 0x0018: /* This device is currently Secondary */
1660 rc = -EBUSY;
1661 dev_err(&card->gdev->dev,
1662 "The HiperSockets device is already a secondary Bridge Port\n");
1663 break;
1664 case 0x001C: /* Limit for Secondary devices reached */
1665 rc = -EEXIST;
1666 dev_err(&card->gdev->dev,
1667 "The HiperSockets LAN cannot have more secondary Bridge Ports\n");
1668 break;
1669 case 0x0024: /* This device is currently Primary */
1670 rc = -EBUSY;
1671 dev_err(&card->gdev->dev,
1672 "The HiperSockets device is already a primary Bridge Port\n");
1673 break;
1674 case 0x0020: /* Not authorized by zManager */
1675 rc = -EACCES;
1676 dev_err(&card->gdev->dev,
1677 "The HiperSockets device is not authorized to be a Bridge Port\n");
1678 break;
1679 default:
1680 rc = -EIO;
1681 }
1682 break;
1683 case IPA_RC_NOTSUPP:
1684 rc = -ENOSYS;
1685 break;
1686 case IPA_RC_UNSUPPORTED_COMMAND:
1687 rc = -ENOSYS;
1688 break;
1689 default:
1690 rc = -EIO;
1691 }
1692 if (rc) {
1693 QETH_CARD_TEXT_(card, 2, "SBPi%04x", cbctl->ipa_rc);
1694 QETH_CARD_TEXT_(card, 2, "SBPc%04x", cbctl->cmd_rc);
1695 }
1696 return rc;
1697}
1698
1699static int qeth_bridgeport_query_support_cb(struct qeth_card *card,
1700 struct qeth_reply *reply, unsigned long data)
1701{
1702 struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *) data;
1703 struct _qeth_sbp_cbctl *cbctl = (struct _qeth_sbp_cbctl *)reply->param;
1704 QETH_CARD_TEXT(card, 2, "brqsupcb");
1705 cbctl->ipa_rc = cmd->hdr.return_code;
1706 cbctl->cmd_rc = cmd->data.sbp.hdr.return_code;
1707 if ((cbctl->ipa_rc == 0) && (cbctl->cmd_rc == 0)) {
1708 cbctl->data.supported =
1709 cmd->data.sbp.data.query_cmds_supp.supported_cmds;
1710 } else {
1711 cbctl->data.supported = 0;
1712 }
1713 return 0;
1714}
1715
1716/**
1717 * qeth_bridgeport_query_support() - store bitmask of supported subfunctions.
1718 * @card: qeth_card structure pointer.
1719 *
1720 * Sets bitmask of supported setbridgeport subfunctions in the qeth_card
1721 * strucutre: card->options.sbp.supported_funcs.
1722 */
Eugene Crosserc044dc22014-01-29 09:23:48 +01001723static void qeth_bridgeport_query_support(struct qeth_card *card)
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001724{
1725 struct qeth_cmd_buffer *iob;
1726 struct qeth_ipa_cmd *cmd;
1727 struct _qeth_sbp_cbctl cbctl;
1728
1729 QETH_CARD_TEXT(card, 2, "brqsuppo");
1730 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_SETBRIDGEPORT, 0);
1731 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
1732 cmd->data.sbp.hdr.cmdlength =
1733 sizeof(struct qeth_ipacmd_sbp_hdr) +
1734 sizeof(struct qeth_sbp_query_cmds_supp);
1735 cmd->data.sbp.hdr.command_code =
1736 IPA_SBP_QUERY_COMMANDS_SUPPORTED;
1737 cmd->data.sbp.hdr.used_total = 1;
1738 cmd->data.sbp.hdr.seq_no = 1;
1739 if (qeth_send_ipa_cmd(card, iob, qeth_bridgeport_query_support_cb,
1740 (void *)&cbctl) ||
1741 qeth_bridgeport_makerc(card, &cbctl,
1742 IPA_SBP_QUERY_COMMANDS_SUPPORTED)) {
1743 /* non-zero makerc signifies failure, and produce messages */
1744 card->options.sbp.role = QETH_SBP_ROLE_NONE;
1745 return;
1746 }
1747 card->options.sbp.supported_funcs = cbctl.data.supported;
1748}
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001749
1750static int qeth_bridgeport_query_ports_cb(struct qeth_card *card,
1751 struct qeth_reply *reply, unsigned long data)
1752{
1753 struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *) data;
1754 struct qeth_sbp_query_ports *qports = &cmd->data.sbp.data.query_ports;
1755 struct _qeth_sbp_cbctl *cbctl = (struct _qeth_sbp_cbctl *)reply->param;
1756
1757 QETH_CARD_TEXT(card, 2, "brqprtcb");
1758 cbctl->ipa_rc = cmd->hdr.return_code;
1759 cbctl->cmd_rc = cmd->data.sbp.hdr.return_code;
1760 if ((cbctl->ipa_rc != 0) || (cbctl->cmd_rc != 0))
1761 return 0;
1762 if (qports->entry_length != sizeof(struct qeth_sbp_port_entry)) {
1763 cbctl->cmd_rc = 0xffff;
1764 QETH_CARD_TEXT_(card, 2, "SBPs%04x", qports->entry_length);
1765 return 0;
1766 }
1767 /* first entry contains the state of the local port */
1768 if (qports->num_entries > 0) {
1769 if (cbctl->data.qports.role)
1770 *cbctl->data.qports.role = qports->entry[0].role;
1771 if (cbctl->data.qports.state)
1772 *cbctl->data.qports.state = qports->entry[0].state;
1773 }
1774 return 0;
1775}
1776
1777/**
1778 * qeth_bridgeport_query_ports() - query local bridgeport status.
1779 * @card: qeth_card structure pointer.
1780 * @role: Role of the port: 0-none, 1-primary, 2-secondary.
1781 * @state: State of the port: 0-inactive, 1-standby, 2-active.
1782 *
1783 * Returns negative errno-compatible error indication or 0 on success.
1784 *
1785 * 'role' and 'state' are not updated in case of hardware operation failure.
1786 */
1787int qeth_bridgeport_query_ports(struct qeth_card *card,
1788 enum qeth_sbp_roles *role, enum qeth_sbp_states *state)
1789{
1790 int rc = 0;
1791 struct qeth_cmd_buffer *iob;
1792 struct qeth_ipa_cmd *cmd;
1793 struct _qeth_sbp_cbctl cbctl = {
1794 .data = {
1795 .qports = {
1796 .role = role,
1797 .state = state,
1798 },
1799 },
1800 };
1801
1802 QETH_CARD_TEXT(card, 2, "brqports");
1803 if (!(card->options.sbp.supported_funcs & IPA_SBP_QUERY_BRIDGE_PORTS))
1804 return -EOPNOTSUPP;
1805 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_SETBRIDGEPORT, 0);
1806 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
1807 cmd->data.sbp.hdr.cmdlength =
1808 sizeof(struct qeth_ipacmd_sbp_hdr);
1809 cmd->data.sbp.hdr.command_code =
1810 IPA_SBP_QUERY_BRIDGE_PORTS;
1811 cmd->data.sbp.hdr.used_total = 1;
1812 cmd->data.sbp.hdr.seq_no = 1;
1813 rc = qeth_send_ipa_cmd(card, iob, qeth_bridgeport_query_ports_cb,
1814 (void *)&cbctl);
1815 if (rc)
1816 return rc;
1817 rc = qeth_bridgeport_makerc(card, &cbctl, IPA_SBP_QUERY_BRIDGE_PORTS);
1818 if (rc)
1819 return rc;
1820 return 0;
1821}
1822EXPORT_SYMBOL_GPL(qeth_bridgeport_query_ports);
1823
1824static int qeth_bridgeport_set_cb(struct qeth_card *card,
1825 struct qeth_reply *reply, unsigned long data)
1826{
1827 struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *)data;
1828 struct _qeth_sbp_cbctl *cbctl = (struct _qeth_sbp_cbctl *)reply->param;
1829 QETH_CARD_TEXT(card, 2, "brsetrcb");
1830 cbctl->ipa_rc = cmd->hdr.return_code;
1831 cbctl->cmd_rc = cmd->data.sbp.hdr.return_code;
1832 return 0;
1833}
1834
1835/**
1836 * qeth_bridgeport_setrole() - Assign primary role to the port.
1837 * @card: qeth_card structure pointer.
1838 * @role: Role to assign.
1839 *
1840 * Returns negative errno-compatible error indication or 0 on success.
1841 */
1842int qeth_bridgeport_setrole(struct qeth_card *card, enum qeth_sbp_roles role)
1843{
1844 int rc = 0;
1845 int cmdlength;
1846 struct qeth_cmd_buffer *iob;
1847 struct qeth_ipa_cmd *cmd;
1848 struct _qeth_sbp_cbctl cbctl;
1849 enum qeth_ipa_sbp_cmd setcmd;
1850
1851 QETH_CARD_TEXT(card, 2, "brsetrol");
1852 switch (role) {
1853 case QETH_SBP_ROLE_NONE:
1854 setcmd = IPA_SBP_RESET_BRIDGE_PORT_ROLE;
1855 cmdlength = sizeof(struct qeth_ipacmd_sbp_hdr) +
1856 sizeof(struct qeth_sbp_reset_role);
1857 break;
1858 case QETH_SBP_ROLE_PRIMARY:
1859 setcmd = IPA_SBP_SET_PRIMARY_BRIDGE_PORT;
1860 cmdlength = sizeof(struct qeth_ipacmd_sbp_hdr) +
1861 sizeof(struct qeth_sbp_set_primary);
1862 break;
1863 case QETH_SBP_ROLE_SECONDARY:
1864 setcmd = IPA_SBP_SET_SECONDARY_BRIDGE_PORT;
1865 cmdlength = sizeof(struct qeth_ipacmd_sbp_hdr) +
1866 sizeof(struct qeth_sbp_set_secondary);
1867 break;
1868 default:
1869 return -EINVAL;
1870 }
1871 if (!(card->options.sbp.supported_funcs & setcmd))
1872 return -EOPNOTSUPP;
1873 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_SETBRIDGEPORT, 0);
1874 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
1875 cmd->data.sbp.hdr.cmdlength = cmdlength;
1876 cmd->data.sbp.hdr.command_code = setcmd;
1877 cmd->data.sbp.hdr.used_total = 1;
1878 cmd->data.sbp.hdr.seq_no = 1;
1879 rc = qeth_send_ipa_cmd(card, iob, qeth_bridgeport_set_cb,
1880 (void *)&cbctl);
1881 if (rc)
1882 return rc;
1883 rc = qeth_bridgeport_makerc(card, &cbctl, setcmd);
1884 return rc;
1885}
1886
Eugene Crosser9f48b9d2014-01-14 15:54:13 +01001887/**
1888 * qeth_anset_makerc() - derive "traditional" error from hardware codes.
1889 * @card: qeth_card structure pointer, for debug messages.
1890 *
1891 * Returns negative errno-compatible error indication or 0 on success.
1892 */
1893static int qeth_anset_makerc(struct qeth_card *card, int pnso_rc, u16 response)
1894{
1895 int rc;
1896
1897 if (pnso_rc == 0)
1898 switch (response) {
1899 case 0x0001:
1900 rc = 0;
1901 break;
1902 case 0x0004:
1903 case 0x0100:
1904 case 0x0106:
1905 rc = -ENOSYS;
1906 dev_err(&card->gdev->dev,
1907 "Setting address notification failed\n");
1908 break;
1909 case 0x0107:
1910 rc = -EAGAIN;
1911 break;
1912 default:
1913 rc = -EIO;
1914 }
1915 else
1916 rc = -EIO;
1917
1918 if (rc) {
1919 QETH_CARD_TEXT_(card, 2, "SBPp%04x", pnso_rc);
1920 QETH_CARD_TEXT_(card, 2, "SBPr%04x", response);
1921 }
1922 return rc;
1923}
1924
1925static void qeth_bridgeport_an_set_cb(void *priv,
1926 enum qdio_brinfo_entry_type type, void *entry)
1927{
1928 struct qeth_card *card = (struct qeth_card *)priv;
1929 struct qdio_brinfo_entry_l2 *l2entry;
1930 u8 code;
1931
1932 if (type != l2_addr_lnid) {
1933 WARN_ON_ONCE(1);
1934 return;
1935 }
1936
1937 l2entry = (struct qdio_brinfo_entry_l2 *)entry;
1938 code = IPA_ADDR_CHANGE_CODE_MACADDR;
1939 if (l2entry->addr_lnid.lnid)
1940 code |= IPA_ADDR_CHANGE_CODE_VLANID;
1941 qeth_bridge_emit_host_event(card, anev_reg_unreg, code,
1942 (struct net_if_token *)&l2entry->nit,
1943 (struct mac_addr_lnid *)&l2entry->addr_lnid);
1944}
1945
1946/**
1947 * qeth_bridgeport_an_set() - Enable or disable bridgeport address notification
1948 * @card: qeth_card structure pointer.
1949 * @enable: 0 - disable, non-zero - enable notifications
1950 *
1951 * Returns negative errno-compatible error indication or 0 on success.
1952 *
1953 * On enable, emits a series of address notifications udev events for all
1954 * currently registered hosts.
1955 */
1956int qeth_bridgeport_an_set(struct qeth_card *card, int enable)
1957{
1958 int rc;
1959 u16 response;
1960 struct ccw_device *ddev;
1961 struct subchannel_id schid;
1962
1963 if (!card)
1964 return -EINVAL;
1965 if (!card->options.sbp.supported_funcs)
1966 return -EOPNOTSUPP;
1967 ddev = CARD_DDEV(card);
1968 ccw_device_get_schid(ddev, &schid);
1969
1970 if (enable) {
1971 qeth_bridge_emit_host_event(card, anev_reset, 0, NULL, NULL);
1972 rc = qdio_pnso_brinfo(schid, 1, &response,
1973 qeth_bridgeport_an_set_cb, card);
1974 } else
1975 rc = qdio_pnso_brinfo(schid, 0, &response, NULL, NULL);
1976 return qeth_anset_makerc(card, rc, response);
1977}
1978EXPORT_SYMBOL_GPL(qeth_bridgeport_an_set);
1979
Frank Blaschka4a71df52008-02-15 09:19:42 +01001980module_init(qeth_l2_init);
1981module_exit(qeth_l2_exit);
1982MODULE_AUTHOR("Frank Blaschka <frank.blaschka@de.ibm.com>");
1983MODULE_DESCRIPTION("qeth layer 2 discipline");
1984MODULE_LICENSE("GPL");