blob: 0ff926d4d63d278d84a37047c59ebbbbf9ac1897 [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 *,
Eugene Crosserefbbc1d2015-01-21 13:39:09 +010030 enum qeth_ipa_cmds);
Frank Blaschka4a71df52008-02-15 09:19:42 +010031static void qeth_l2_set_multicast_list(struct net_device *);
32static int qeth_l2_recover(void *);
Eugene Crosserc044dc22014-01-29 09:23:48 +010033static void qeth_bridgeport_query_support(struct qeth_card *card);
34static void qeth_bridge_state_change(struct qeth_card *card,
35 struct qeth_ipa_cmd *cmd);
36static void qeth_bridge_host_event(struct qeth_card *card,
37 struct qeth_ipa_cmd *cmd);
Frank Blaschka4a71df52008-02-15 09:19:42 +010038
39static int qeth_l2_do_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
40{
Heiko Carstens509e2562008-07-26 02:24:10 -070041 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +010042 struct mii_ioctl_data *mii_data;
43 int rc = 0;
44
45 if (!card)
46 return -ENODEV;
47
Eugene Crosserc3521252015-01-16 14:05:47 +010048 if (!qeth_card_hw_is_reachable(card))
Frank Blaschka4a71df52008-02-15 09:19:42 +010049 return -ENODEV;
50
51 if (card->info.type == QETH_CARD_TYPE_OSN)
52 return -EPERM;
53
54 switch (cmd) {
55 case SIOC_QETH_ADP_SET_SNMP_CONTROL:
56 rc = qeth_snmp_command(card, rq->ifr_ifru.ifru_data);
57 break;
58 case SIOC_QETH_GET_CARD_TYPE:
Ursula Braun5113fec2010-05-16 21:15:14 +000059 if ((card->info.type == QETH_CARD_TYPE_OSD ||
60 card->info.type == QETH_CARD_TYPE_OSM ||
61 card->info.type == QETH_CARD_TYPE_OSX) &&
Frank Blaschka4a71df52008-02-15 09:19:42 +010062 !card->info.guestlan)
63 return 1;
64 return 0;
65 break;
66 case SIOCGMIIPHY:
67 mii_data = if_mii(rq);
68 mii_data->phy_id = 0;
69 break;
70 case SIOCGMIIREG:
71 mii_data = if_mii(rq);
72 if (mii_data->phy_id != 0)
73 rc = -EINVAL;
74 else
75 mii_data->val_out = qeth_mdio_read(dev,
76 mii_data->phy_id, mii_data->reg_num);
77 break;
Frank Blaschkac3ab96f2012-02-08 00:19:49 +000078 case SIOC_QETH_QUERY_OAT:
79 rc = qeth_query_oat_command(card, rq->ifr_ifru.ifru_data);
80 break;
Frank Blaschka4a71df52008-02-15 09:19:42 +010081 default:
82 rc = -EOPNOTSUPP;
83 }
84 if (rc)
Carsten Otte847a50f2010-06-21 22:57:05 +000085 QETH_CARD_TEXT_(card, 2, "ioce%d", rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +010086 return rc;
87}
88
89static int qeth_l2_verify_dev(struct net_device *dev)
90{
91 struct qeth_card *card;
92 unsigned long flags;
93 int rc = 0;
94
95 read_lock_irqsave(&qeth_core_card_list.rwlock, flags);
96 list_for_each_entry(card, &qeth_core_card_list.list, list) {
97 if (card->dev == dev) {
98 rc = QETH_REAL_CARD;
99 break;
100 }
101 }
102 read_unlock_irqrestore(&qeth_core_card_list.rwlock, flags);
103
104 return rc;
105}
106
107static struct net_device *qeth_l2_netdev_by_devno(unsigned char *read_dev_no)
108{
109 struct qeth_card *card;
110 struct net_device *ndev;
Cornelia Huckf06f6f32008-06-06 12:37:45 +0200111 __u16 temp_dev_no;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100112 unsigned long flags;
Cornelia Huckf06f6f32008-06-06 12:37:45 +0200113 struct ccw_dev_id read_devid;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100114
115 ndev = NULL;
116 memcpy(&temp_dev_no, read_dev_no, 2);
117 read_lock_irqsave(&qeth_core_card_list.rwlock, flags);
118 list_for_each_entry(card, &qeth_core_card_list.list, list) {
Cornelia Huckf06f6f32008-06-06 12:37:45 +0200119 ccw_device_get_id(CARD_RDEV(card), &read_devid);
120 if (read_devid.devno == temp_dev_no) {
Frank Blaschka4a71df52008-02-15 09:19:42 +0100121 ndev = card->dev;
122 break;
123 }
124 }
125 read_unlock_irqrestore(&qeth_core_card_list.rwlock, flags);
126 return ndev;
127}
128
Eugene Crosserefbbc1d2015-01-21 13:39:09 +0100129static int qeth_setdel_makerc(struct qeth_card *card, int retcode)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100130{
Eugene Crosserefbbc1d2015-01-21 13:39:09 +0100131 int rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100132
Eugene Crosserefbbc1d2015-01-21 13:39:09 +0100133 if (retcode)
Thomas Richter1aec42b2015-01-21 13:39:10 +0100134 QETH_CARD_TEXT_(card, 2, "err%04x", retcode);
Eugene Crosserefbbc1d2015-01-21 13:39:09 +0100135 switch (retcode) {
136 case IPA_RC_SUCCESS:
137 rc = 0;
138 break;
139 case IPA_RC_L2_UNSUPPORTED_CMD:
140 rc = -ENOSYS;
141 break;
142 case IPA_RC_L2_ADDR_TABLE_FULL:
143 rc = -ENOSPC;
144 break;
145 case IPA_RC_L2_DUP_MAC:
146 case IPA_RC_L2_DUP_LAYER3_MAC:
147 rc = -EEXIST;
148 break;
149 case IPA_RC_L2_MAC_NOT_AUTH_BY_HYP:
150 case IPA_RC_L2_MAC_NOT_AUTH_BY_ADP:
151 rc = -EPERM;
152 break;
153 case IPA_RC_L2_MAC_NOT_FOUND:
154 rc = -ENOENT;
155 break;
Thomas Richter1aec42b2015-01-21 13:39:10 +0100156 case -ENOMEM:
157 rc = -ENOMEM;
158 break;
Eugene Crosserefbbc1d2015-01-21 13:39:09 +0100159 default:
160 rc = -EIO;
161 break;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100162 }
Eugene Crosserefbbc1d2015-01-21 13:39:09 +0100163 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100164}
165
166static int qeth_l2_send_setgroupmac(struct qeth_card *card, __u8 *mac)
167{
Eugene Crosserefbbc1d2015-01-21 13:39:09 +0100168 int rc;
169
Carsten Otte847a50f2010-06-21 22:57:05 +0000170 QETH_CARD_TEXT(card, 2, "L2Sgmac");
Eugene Crosserefbbc1d2015-01-21 13:39:09 +0100171 rc = qeth_setdel_makerc(card, qeth_l2_send_setdelmac(card, mac,
172 IPA_CMD_SETGMAC));
173 if (rc == -EEXIST)
174 QETH_DBF_MESSAGE(2, "Group MAC %pM already existing on %s\n",
175 mac, QETH_CARD_IFNAME(card));
176 else if (rc)
177 QETH_DBF_MESSAGE(2, "Could not set group MAC %pM on %s: %d\n",
178 mac, QETH_CARD_IFNAME(card), rc);
179 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100180}
181
182static int qeth_l2_send_delgroupmac(struct qeth_card *card, __u8 *mac)
183{
Eugene Crosserefbbc1d2015-01-21 13:39:09 +0100184 int rc;
185
Carsten Otte847a50f2010-06-21 22:57:05 +0000186 QETH_CARD_TEXT(card, 2, "L2Dgmac");
Eugene Crosserefbbc1d2015-01-21 13:39:09 +0100187 rc = qeth_setdel_makerc(card, qeth_l2_send_setdelmac(card, mac,
188 IPA_CMD_DELGMAC));
189 if (rc)
190 QETH_DBF_MESSAGE(2,
191 "Could not delete group MAC %pM on %s: %d\n",
192 mac, QETH_CARD_IFNAME(card), rc);
193 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100194}
195
Frank Blaschka7db22662008-08-15 08:02:59 +0200196static void qeth_l2_add_mc(struct qeth_card *card, __u8 *mac, int vmac)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100197{
198 struct qeth_mc_mac *mc;
Frank Blaschka7db22662008-08-15 08:02:59 +0200199 int rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100200
201 mc = kmalloc(sizeof(struct qeth_mc_mac), GFP_ATOMIC);
202
Frank Blaschka14cc21b2008-06-06 12:37:46 +0200203 if (!mc)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100204 return;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100205
206 memcpy(mc->mc_addr, mac, OSA_ADDR_LEN);
207 mc->mc_addrlen = OSA_ADDR_LEN;
Frank Blaschka7db22662008-08-15 08:02:59 +0200208 mc->is_vmac = vmac;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100209
Frank Blaschka7db22662008-08-15 08:02:59 +0200210 if (vmac) {
Eugene Crosserefbbc1d2015-01-21 13:39:09 +0100211 rc = qeth_setdel_makerc(card,
212 qeth_l2_send_setdelmac(card, mac, IPA_CMD_SETVMAC));
Frank Blaschka7db22662008-08-15 08:02:59 +0200213 } else {
Eugene Crosserefbbc1d2015-01-21 13:39:09 +0100214 rc = qeth_setdel_makerc(card,
215 qeth_l2_send_setgroupmac(card, mac));
Frank Blaschka7db22662008-08-15 08:02:59 +0200216 }
217
218 if (!rc)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100219 list_add_tail(&mc->list, &card->mc_list);
220 else
221 kfree(mc);
222}
223
Ursula Braun70919e22011-02-26 22:41:36 -0800224static void qeth_l2_del_all_mc(struct qeth_card *card, int del)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100225{
226 struct qeth_mc_mac *mc, *tmp;
227
228 spin_lock_bh(&card->mclock);
229 list_for_each_entry_safe(mc, tmp, &card->mc_list, list) {
Ursula Braun70919e22011-02-26 22:41:36 -0800230 if (del) {
231 if (mc->is_vmac)
232 qeth_l2_send_setdelmac(card, mc->mc_addr,
Eugene Crosserefbbc1d2015-01-21 13:39:09 +0100233 IPA_CMD_DELVMAC);
Ursula Braun70919e22011-02-26 22:41:36 -0800234 else
235 qeth_l2_send_delgroupmac(card, mc->mc_addr);
236 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100237 list_del(&mc->list);
238 kfree(mc);
239 }
240 spin_unlock_bh(&card->mclock);
241}
242
Klaus-Dieter Wackerce73e102009-08-26 02:01:08 +0000243static inline int qeth_l2_get_cast_type(struct qeth_card *card,
244 struct sk_buff *skb)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100245{
Klaus-Dieter Wackerce73e102009-08-26 02:01:08 +0000246 if (card->info.type == QETH_CARD_TYPE_OSN)
247 return RTN_UNSPEC;
248 if (is_broadcast_ether_addr(skb->data))
249 return RTN_BROADCAST;
250 if (is_multicast_ether_addr(skb->data))
251 return RTN_MULTICAST;
252 return RTN_UNSPEC;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100253}
254
255static void qeth_l2_fill_header(struct qeth_card *card, struct qeth_hdr *hdr,
Stefan Raspl43934072014-03-19 07:58:01 +0100256 struct sk_buff *skb, int cast_type)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100257{
Frank Blaschka683d7182008-08-01 16:39:13 +0200258 struct vlan_ethhdr *veth = (struct vlan_ethhdr *)skb_mac_header(skb);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100259
260 memset(hdr, 0, sizeof(struct qeth_hdr));
261 hdr->hdr.l2.id = QETH_HEADER_TYPE_LAYER2;
262
263 /* set byte byte 3 to casting flags */
264 if (cast_type == RTN_MULTICAST)
265 hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_MULTICAST;
266 else if (cast_type == RTN_BROADCAST)
267 hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_BROADCAST;
268 else
Klaus-Dieter Wackerce73e102009-08-26 02:01:08 +0000269 hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_UNICAST;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100270
271 hdr->hdr.l2.pkt_length = skb->len-QETH_HEADER_SIZE;
272 /* VSWITCH relies on the VLAN
273 * information to be present in
274 * the QDIO header */
275 if (veth->h_vlan_proto == __constant_htons(ETH_P_8021Q)) {
276 hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_VLAN;
277 hdr->hdr.l2.vlan_id = ntohs(veth->h_vlan_TCI);
278 }
279}
280
281static int qeth_l2_send_setdelvlan_cb(struct qeth_card *card,
282 struct qeth_reply *reply, unsigned long data)
283{
284 struct qeth_ipa_cmd *cmd;
285
Carsten Otte847a50f2010-06-21 22:57:05 +0000286 QETH_CARD_TEXT(card, 2, "L2sdvcb");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100287 cmd = (struct qeth_ipa_cmd *) data;
288 if (cmd->hdr.return_code) {
Frank Blaschka14cc21b2008-06-06 12:37:46 +0200289 QETH_DBF_MESSAGE(2, "Error in processing VLAN %i on %s: 0x%x. "
Frank Blaschka4a71df52008-02-15 09:19:42 +0100290 "Continuing\n", cmd->data.setdelvlan.vlan_id,
291 QETH_CARD_IFNAME(card), cmd->hdr.return_code);
Carsten Otte847a50f2010-06-21 22:57:05 +0000292 QETH_CARD_TEXT_(card, 2, "L2VL%4x", cmd->hdr.command);
293 QETH_CARD_TEXT_(card, 2, "err%d", cmd->hdr.return_code);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100294 }
295 return 0;
296}
297
298static int qeth_l2_send_setdelvlan(struct qeth_card *card, __u16 i,
299 enum qeth_ipa_cmds ipacmd)
300{
301 struct qeth_ipa_cmd *cmd;
302 struct qeth_cmd_buffer *iob;
303
Carsten Otte847a50f2010-06-21 22:57:05 +0000304 QETH_CARD_TEXT_(card, 4, "L2sdv%x", ipacmd);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100305 iob = qeth_get_ipacmd_buffer(card, ipacmd, QETH_PROT_IPV4);
Thomas Richter1aec42b2015-01-21 13:39:10 +0100306 if (!iob)
307 return -ENOMEM;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100308 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
309 cmd->data.setdelvlan.vlan_id = i;
310 return qeth_send_ipa_cmd(card, iob,
311 qeth_l2_send_setdelvlan_cb, NULL);
312}
313
Ursula Braun70919e22011-02-26 22:41:36 -0800314static void qeth_l2_process_vlans(struct qeth_card *card)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100315{
316 struct qeth_vlan_vid *id;
Carsten Otte847a50f2010-06-21 22:57:05 +0000317 QETH_CARD_TEXT(card, 3, "L2prcvln");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100318 spin_lock_bh(&card->vlanlock);
319 list_for_each_entry(id, &card->vid_list, list) {
Ursula Braun70919e22011-02-26 22:41:36 -0800320 qeth_l2_send_setdelvlan(card, id->vid, IPA_CMD_SETVLAN);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100321 }
322 spin_unlock_bh(&card->vlanlock);
323}
324
Patrick McHardy80d5c362013-04-19 02:04:28 +0000325static int qeth_l2_vlan_rx_add_vid(struct net_device *dev,
326 __be16 proto, u16 vid)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100327{
Heiko Carstens509e2562008-07-26 02:24:10 -0700328 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100329 struct qeth_vlan_vid *id;
Thomas Richter1aec42b2015-01-21 13:39:10 +0100330 int rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100331
Carsten Otte847a50f2010-06-21 22:57:05 +0000332 QETH_CARD_TEXT_(card, 4, "aid:%d", vid);
Ursula Braun10651db2010-10-01 02:51:13 +0000333 if (!vid)
Jiri Pirko8e586132011-12-08 19:52:37 -0500334 return 0;
Ursula Braun5113fec2010-05-16 21:15:14 +0000335 if (card->info.type == QETH_CARD_TYPE_OSM) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000336 QETH_CARD_TEXT(card, 3, "aidOSM");
Jiri Pirko8e586132011-12-08 19:52:37 -0500337 return 0;
Ursula Braun5113fec2010-05-16 21:15:14 +0000338 }
Ursula Braun8e98ac42009-03-24 20:57:18 +0000339 if (qeth_wait_for_threads(card, QETH_RECOVER_THREAD)) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000340 QETH_CARD_TEXT(card, 3, "aidREC");
Jiri Pirko8e586132011-12-08 19:52:37 -0500341 return 0;
Ursula Braun8e98ac42009-03-24 20:57:18 +0000342 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100343 id = kmalloc(sizeof(struct qeth_vlan_vid), GFP_ATOMIC);
344 if (id) {
345 id->vid = vid;
Thomas Richter1aec42b2015-01-21 13:39:10 +0100346 rc = qeth_l2_send_setdelvlan(card, vid, IPA_CMD_SETVLAN);
347 if (rc) {
348 kfree(id);
349 return rc;
350 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100351 spin_lock_bh(&card->vlanlock);
352 list_add_tail(&id->list, &card->vid_list);
353 spin_unlock_bh(&card->vlanlock);
Jiri Pirko8e586132011-12-08 19:52:37 -0500354 } else {
355 return -ENOMEM;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100356 }
Jiri Pirko8e586132011-12-08 19:52:37 -0500357 return 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100358}
359
Patrick McHardy80d5c362013-04-19 02:04:28 +0000360static int qeth_l2_vlan_rx_kill_vid(struct net_device *dev,
361 __be16 proto, u16 vid)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100362{
363 struct qeth_vlan_vid *id, *tmpid = NULL;
Heiko Carstens509e2562008-07-26 02:24:10 -0700364 struct qeth_card *card = dev->ml_priv;
Thomas Richter1aec42b2015-01-21 13:39:10 +0100365 int rc = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100366
Carsten Otte847a50f2010-06-21 22:57:05 +0000367 QETH_CARD_TEXT_(card, 4, "kid:%d", vid);
Ursula Braun5113fec2010-05-16 21:15:14 +0000368 if (card->info.type == QETH_CARD_TYPE_OSM) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000369 QETH_CARD_TEXT(card, 3, "kidOSM");
Jiri Pirko8e586132011-12-08 19:52:37 -0500370 return 0;
Ursula Braun5113fec2010-05-16 21:15:14 +0000371 }
Ursula Braun8e98ac42009-03-24 20:57:18 +0000372 if (qeth_wait_for_threads(card, QETH_RECOVER_THREAD)) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000373 QETH_CARD_TEXT(card, 3, "kidREC");
Jiri Pirko8e586132011-12-08 19:52:37 -0500374 return 0;
Ursula Braun8e98ac42009-03-24 20:57:18 +0000375 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100376 spin_lock_bh(&card->vlanlock);
377 list_for_each_entry(id, &card->vid_list, list) {
378 if (id->vid == vid) {
379 list_del(&id->list);
380 tmpid = id;
381 break;
382 }
383 }
384 spin_unlock_bh(&card->vlanlock);
385 if (tmpid) {
Thomas Richter1aec42b2015-01-21 13:39:10 +0100386 rc = qeth_l2_send_setdelvlan(card, vid, IPA_CMD_DELVLAN);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100387 kfree(tmpid);
388 }
389 qeth_l2_set_multicast_list(card->dev);
Thomas Richter1aec42b2015-01-21 13:39:10 +0100390 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100391}
392
393static int qeth_l2_stop_card(struct qeth_card *card, int recovery_mode)
394{
395 int rc = 0;
396
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200397 QETH_DBF_TEXT(SETUP , 2, "stopcard");
398 QETH_DBF_HEX(SETUP, 2, &card, sizeof(void *));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100399
400 qeth_set_allowed_threads(card, 0, 1);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100401 if (card->read.state == CH_STATE_UP &&
402 card->write.state == CH_STATE_UP &&
403 (card->state == CARD_STATE_UP)) {
404 if (recovery_mode &&
405 card->info.type != QETH_CARD_TYPE_OSN) {
406 qeth_l2_stop(card->dev);
407 } else {
408 rtnl_lock();
409 dev_close(card->dev);
410 rtnl_unlock();
411 }
Ursula Braun70919e22011-02-26 22:41:36 -0800412 card->info.mac_bits &= ~QETH_LAYER2_MAC_REGISTERED;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100413 card->state = CARD_STATE_SOFTSETUP;
414 }
415 if (card->state == CARD_STATE_SOFTSETUP) {
Ursula Braun70919e22011-02-26 22:41:36 -0800416 qeth_l2_del_all_mc(card, 0);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100417 qeth_clear_ipacmd_list(card);
418 card->state = CARD_STATE_HARDSETUP;
419 }
420 if (card->state == CARD_STATE_HARDSETUP) {
421 qeth_qdio_clear_card(card, 0);
422 qeth_clear_qdio_buffers(card);
423 qeth_clear_working_pool_list(card);
424 card->state = CARD_STATE_DOWN;
425 }
426 if (card->state == CARD_STATE_DOWN) {
427 qeth_clear_cmd_buffers(&card->read);
428 qeth_clear_cmd_buffers(&card->write);
429 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100430 return rc;
431}
432
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000433static int qeth_l2_process_inbound_buffer(struct qeth_card *card,
434 int budget, int *done)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100435{
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000436 int work_done = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100437 struct sk_buff *skb;
438 struct qeth_hdr *hdr;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100439 unsigned int len;
440
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000441 *done = 0;
Stefan Raspl18af5c12012-11-19 02:46:50 +0000442 WARN_ON_ONCE(!budget);
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000443 while (budget) {
444 skb = qeth_core_get_next_skb(card,
Frank Blaschkab3332932011-08-08 01:33:59 +0000445 &card->qdio.in_q->bufs[card->rx.b_index],
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000446 &card->rx.b_element, &card->rx.e_offset, &hdr);
447 if (!skb) {
448 *done = 1;
449 break;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100450 }
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000451 skb->dev = card->dev;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100452 switch (hdr->hdr.l2.id) {
453 case QETH_HEADER_TYPE_LAYER2:
454 skb->pkt_type = PACKET_HOST;
455 skb->protocol = eth_type_trans(skb, skb->dev);
Frank Blaschkac5e631a2011-05-12 18:45:01 +0000456 skb->ip_summed = CHECKSUM_NONE;
Ursula Braun12883722008-04-01 10:26:56 +0200457 if (skb->protocol == htons(ETH_P_802_2))
458 *((__u32 *)skb->cb) = ++card->seqno.pkt_seqno;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100459 len = skb->len;
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000460 netif_receive_skb(skb);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100461 break;
462 case QETH_HEADER_TYPE_OSN:
Ursula Braun2d488c22008-10-24 11:16:55 +0200463 if (card->info.type == QETH_CARD_TYPE_OSN) {
464 skb_push(skb, sizeof(struct qeth_hdr));
465 skb_copy_to_linear_data(skb, hdr,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100466 sizeof(struct qeth_hdr));
Ursula Braun2d488c22008-10-24 11:16:55 +0200467 len = skb->len;
468 card->osn_info.data_cb(skb);
469 break;
470 }
471 /* else unknown */
Frank Blaschka4a71df52008-02-15 09:19:42 +0100472 default:
473 dev_kfree_skb_any(skb);
Carsten Otte847a50f2010-06-21 22:57:05 +0000474 QETH_CARD_TEXT(card, 3, "inbunkno");
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200475 QETH_DBF_HEX(CTRL, 3, hdr, QETH_DBF_CTRL_LEN);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100476 continue;
477 }
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000478 work_done++;
479 budget--;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100480 card->stats.rx_packets++;
481 card->stats.rx_bytes += len;
482 }
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000483 return work_done;
484}
485
486static int qeth_l2_poll(struct napi_struct *napi, int budget)
487{
488 struct qeth_card *card = container_of(napi, struct qeth_card, napi);
489 int work_done = 0;
490 struct qeth_qdio_buffer *buffer;
491 int done;
492 int new_budget = budget;
493
494 if (card->options.performance_stats) {
495 card->perf_stats.inbound_cnt++;
496 card->perf_stats.inbound_start_time = qeth_get_micros();
497 }
498
499 while (1) {
500 if (!card->rx.b_count) {
501 card->rx.qdio_err = 0;
502 card->rx.b_count = qdio_get_next_buffers(
503 card->data.ccwdev, 0, &card->rx.b_index,
504 &card->rx.qdio_err);
505 if (card->rx.b_count <= 0) {
506 card->rx.b_count = 0;
507 break;
508 }
509 card->rx.b_element =
510 &card->qdio.in_q->bufs[card->rx.b_index]
511 .buffer->element[0];
512 card->rx.e_offset = 0;
513 }
514
515 while (card->rx.b_count) {
516 buffer = &card->qdio.in_q->bufs[card->rx.b_index];
517 if (!(card->rx.qdio_err &&
518 qeth_check_qdio_errors(card, buffer->buffer,
519 card->rx.qdio_err, "qinerr")))
520 work_done += qeth_l2_process_inbound_buffer(
521 card, new_budget, &done);
522 else
523 done = 1;
524
525 if (done) {
526 if (card->options.performance_stats)
527 card->perf_stats.bufs_rec++;
528 qeth_put_buffer_pool_entry(card,
529 buffer->pool_entry);
530 qeth_queue_input_buffer(card, card->rx.b_index);
531 card->rx.b_count--;
532 if (card->rx.b_count) {
533 card->rx.b_index =
534 (card->rx.b_index + 1) %
535 QDIO_MAX_BUFFERS_PER_Q;
536 card->rx.b_element =
537 &card->qdio.in_q
538 ->bufs[card->rx.b_index]
539 .buffer->element[0];
540 card->rx.e_offset = 0;
541 }
542 }
543
544 if (work_done >= budget)
545 goto out;
546 else
547 new_budget = budget - work_done;
548 }
549 }
550
551 napi_complete(napi);
552 if (qdio_start_irq(card->data.ccwdev, 0))
553 napi_schedule(&card->napi);
554out:
555 if (card->options.performance_stats)
556 card->perf_stats.inbound_time += qeth_get_micros() -
557 card->perf_stats.inbound_start_time;
558 return work_done;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100559}
560
561static int qeth_l2_send_setdelmac(struct qeth_card *card, __u8 *mac,
Eugene Crosserefbbc1d2015-01-21 13:39:09 +0100562 enum qeth_ipa_cmds ipacmd)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100563{
564 struct qeth_ipa_cmd *cmd;
565 struct qeth_cmd_buffer *iob;
566
Carsten Otte847a50f2010-06-21 22:57:05 +0000567 QETH_CARD_TEXT(card, 2, "L2sdmac");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100568 iob = qeth_get_ipacmd_buffer(card, ipacmd, QETH_PROT_IPV4);
Thomas Richter1aec42b2015-01-21 13:39:10 +0100569 if (!iob)
570 return -ENOMEM;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100571 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
572 cmd->data.setdelmac.mac_length = OSA_ADDR_LEN;
573 memcpy(&cmd->data.setdelmac.mac, mac, OSA_ADDR_LEN);
Eugene Crosserefbbc1d2015-01-21 13:39:09 +0100574 return qeth_send_ipa_cmd(card, iob, NULL, NULL);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100575}
576
577static int qeth_l2_send_setmac(struct qeth_card *card, __u8 *mac)
578{
Eugene Crosserefbbc1d2015-01-21 13:39:09 +0100579 int rc;
580
Carsten Otte847a50f2010-06-21 22:57:05 +0000581 QETH_CARD_TEXT(card, 2, "L2Setmac");
Eugene Crosserefbbc1d2015-01-21 13:39:09 +0100582 rc = qeth_setdel_makerc(card, qeth_l2_send_setdelmac(card, mac,
583 IPA_CMD_SETVMAC));
584 if (rc == 0) {
585 card->info.mac_bits |= QETH_LAYER2_MAC_REGISTERED;
586 memcpy(card->dev->dev_addr, mac, OSA_ADDR_LEN);
587 dev_info(&card->gdev->dev,
588 "MAC address %pM successfully registered on device %s\n",
589 card->dev->dev_addr, card->dev->name);
590 } else {
591 card->info.mac_bits &= ~QETH_LAYER2_MAC_REGISTERED;
592 switch (rc) {
593 case -EEXIST:
594 dev_warn(&card->gdev->dev,
595 "MAC address %pM already exists\n", mac);
596 break;
597 case -EPERM:
598 dev_warn(&card->gdev->dev,
599 "MAC address %pM is not authorized\n", mac);
600 break;
601 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100602 }
Eugene Crosserefbbc1d2015-01-21 13:39:09 +0100603 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100604}
605
606static int qeth_l2_send_delmac(struct qeth_card *card, __u8 *mac)
607{
Eugene Crosserefbbc1d2015-01-21 13:39:09 +0100608 int rc;
609
Carsten Otte847a50f2010-06-21 22:57:05 +0000610 QETH_CARD_TEXT(card, 2, "L2Delmac");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100611 if (!(card->info.mac_bits & QETH_LAYER2_MAC_REGISTERED))
612 return 0;
Eugene Crosserefbbc1d2015-01-21 13:39:09 +0100613 rc = qeth_setdel_makerc(card, qeth_l2_send_setdelmac(card, mac,
614 IPA_CMD_DELVMAC));
615 if (rc == 0)
616 card->info.mac_bits &= ~QETH_LAYER2_MAC_REGISTERED;
617 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100618}
619
620static int qeth_l2_request_initial_mac(struct qeth_card *card)
621{
622 int rc = 0;
623 char vendor_pre[] = {0x02, 0x00, 0x00};
624
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200625 QETH_DBF_TEXT(SETUP, 2, "doL2init");
626 QETH_DBF_TEXT_(SETUP, 2, "doL2%s", CARD_BUS_ID(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100627
Stefan Raspla1348842012-11-12 23:05:16 +0000628 if (qeth_is_supported(card, IPA_SETADAPTERPARMS)) {
629 rc = qeth_query_setadapterparms(card);
630 if (rc) {
631 QETH_DBF_MESSAGE(2, "could not query adapter "
632 "parameters on device %s: x%x\n",
633 CARD_BUS_ID(card), rc);
634 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100635 }
636
Ursula Braun5113fec2010-05-16 21:15:14 +0000637 if (card->info.type == QETH_CARD_TYPE_IQD ||
638 card->info.type == QETH_CARD_TYPE_OSM ||
639 card->info.type == QETH_CARD_TYPE_OSX ||
640 card->info.guestlan) {
Frank Blaschka4a71df52008-02-15 09:19:42 +0100641 rc = qeth_setadpparms_change_macaddr(card);
642 if (rc) {
Frank Blaschka14cc21b2008-06-06 12:37:46 +0200643 QETH_DBF_MESSAGE(2, "couldn't get MAC address on "
644 "device %s: x%x\n", CARD_BUS_ID(card), rc);
Thomas Richter1aec42b2015-01-21 13:39:10 +0100645 QETH_DBF_TEXT_(SETUP, 2, "1err%04x", rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100646 return rc;
647 }
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200648 QETH_DBF_HEX(SETUP, 2, card->dev->dev_addr, OSA_ADDR_LEN);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100649 } else {
Joe Perches18336112012-07-12 22:33:10 -0700650 eth_random_addr(card->dev->dev_addr);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100651 memcpy(card->dev->dev_addr, vendor_pre, 3);
652 }
653 return 0;
654}
655
656static int qeth_l2_set_mac_address(struct net_device *dev, void *p)
657{
658 struct sockaddr *addr = p;
Heiko Carstens509e2562008-07-26 02:24:10 -0700659 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100660 int rc = 0;
661
Carsten Otte847a50f2010-06-21 22:57:05 +0000662 QETH_CARD_TEXT(card, 3, "setmac");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100663
664 if (qeth_l2_verify_dev(dev) != QETH_REAL_CARD) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000665 QETH_CARD_TEXT(card, 3, "setmcINV");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100666 return -EOPNOTSUPP;
667 }
668
Ursula Braun5113fec2010-05-16 21:15:14 +0000669 if (card->info.type == QETH_CARD_TYPE_OSN ||
670 card->info.type == QETH_CARD_TYPE_OSM ||
671 card->info.type == QETH_CARD_TYPE_OSX) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000672 QETH_CARD_TEXT(card, 3, "setmcTYP");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100673 return -EOPNOTSUPP;
674 }
Carsten Otte847a50f2010-06-21 22:57:05 +0000675 QETH_CARD_HEX(card, 3, addr->sa_data, OSA_ADDR_LEN);
Ursula Braun8e98ac42009-03-24 20:57:18 +0000676 if (qeth_wait_for_threads(card, QETH_RECOVER_THREAD)) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000677 QETH_CARD_TEXT(card, 3, "setmcREC");
Ursula Braun8e98ac42009-03-24 20:57:18 +0000678 return -ERESTARTSYS;
679 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100680 rc = qeth_l2_send_delmac(card, &card->dev->dev_addr[0]);
Eugene Crosserefbbc1d2015-01-21 13:39:09 +0100681 if (!rc || (rc == -ENOENT))
Frank Blaschka4a71df52008-02-15 09:19:42 +0100682 rc = qeth_l2_send_setmac(card, addr->sa_data);
Ursula Braune0a81142012-03-07 02:06:28 +0000683 return rc ? -EINVAL : 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100684}
685
Eugene Crosser0db587b2015-05-18 14:27:55 +0200686static void qeth_promisc_to_bridge(struct qeth_card *card)
687{
688 struct net_device *dev = card->dev;
689 enum qeth_ipa_promisc_modes promisc_mode;
690 int role;
691 int rc;
692
693 QETH_CARD_TEXT(card, 3, "pmisc2br");
694
695 if (!card->options.sbp.reflect_promisc)
696 return;
697 promisc_mode = (dev->flags & IFF_PROMISC) ? SET_PROMISC_MODE_ON
698 : SET_PROMISC_MODE_OFF;
699 if (promisc_mode == card->info.promisc_mode)
700 return;
701
702 if (promisc_mode == SET_PROMISC_MODE_ON) {
703 if (card->options.sbp.reflect_promisc_primary)
704 role = QETH_SBP_ROLE_PRIMARY;
705 else
706 role = QETH_SBP_ROLE_SECONDARY;
707 } else
708 role = QETH_SBP_ROLE_NONE;
709
710 rc = qeth_bridgeport_setrole(card, role);
711 QETH_DBF_TEXT_(SETUP, 2, "bpm%c%04x",
712 (promisc_mode == SET_PROMISC_MODE_ON) ? '+' : '-', rc);
713 if (!rc) {
714 card->options.sbp.role = role;
715 card->info.promisc_mode = promisc_mode;
716 }
717}
718
Frank Blaschka4a71df52008-02-15 09:19:42 +0100719static void qeth_l2_set_multicast_list(struct net_device *dev)
720{
Heiko Carstens509e2562008-07-26 02:24:10 -0700721 struct qeth_card *card = dev->ml_priv;
Jiri Pirkoccffad252009-05-22 23:22:17 +0000722 struct netdev_hw_addr *ha;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100723
724 if (card->info.type == QETH_CARD_TYPE_OSN)
725 return ;
726
Carsten Otte847a50f2010-06-21 22:57:05 +0000727 QETH_CARD_TEXT(card, 3, "setmulti");
Ursula Braun8e98ac42009-03-24 20:57:18 +0000728 if (qeth_threads_running(card, QETH_RECOVER_THREAD) &&
729 (card->state != CARD_STATE_UP))
730 return;
Ursula Braun70919e22011-02-26 22:41:36 -0800731 qeth_l2_del_all_mc(card, 1);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100732 spin_lock_bh(&card->mclock);
Jiri Pirko22bedad32010-04-01 21:22:57 +0000733 netdev_for_each_mc_addr(ha, dev)
734 qeth_l2_add_mc(card, ha->addr, 0);
Frank Blaschka7db22662008-08-15 08:02:59 +0200735
Jiri Pirko32e7bfc2010-01-25 13:36:10 -0800736 netdev_for_each_uc_addr(ha, dev)
Jiri Pirkoccffad252009-05-22 23:22:17 +0000737 qeth_l2_add_mc(card, ha->addr, 1);
Frank Blaschka7db22662008-08-15 08:02:59 +0200738
Frank Blaschka4a71df52008-02-15 09:19:42 +0100739 spin_unlock_bh(&card->mclock);
Eugene Crosser0db587b2015-05-18 14:27:55 +0200740 if (qeth_adp_supported(card, IPA_SETADP_SET_PROMISC_MODE))
741 qeth_setadp_promisc_mode(card);
742 else
743 qeth_promisc_to_bridge(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100744}
745
746static int qeth_l2_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
747{
748 int rc;
749 struct qeth_hdr *hdr = NULL;
750 int elements = 0;
Heiko Carstens509e2562008-07-26 02:24:10 -0700751 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100752 struct sk_buff *new_skb = skb;
Klaus-Dieter Wackerce73e102009-08-26 02:01:08 +0000753 int cast_type = qeth_l2_get_cast_type(card, skb);
Stefan Raspl290b8342014-04-28 10:05:08 +0200754 struct qeth_qdio_out_q *queue;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100755 int tx_bytes = skb->len;
Frank Blaschka683d7182008-08-01 16:39:13 +0200756 int data_offset = -1;
757 int elements_needed = 0;
758 int hd_len = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100759
Stefan Raspl290b8342014-04-28 10:05:08 +0200760 if (card->qdio.do_prio_queueing || (cast_type &&
761 card->info.is_multicast_different))
762 queue = card->qdio.out_qs[qeth_get_priority_queue(card, skb,
763 qeth_get_ip_version(skb), cast_type)];
764 else
765 queue = card->qdio.out_qs[card->qdio.default_out_queue];
766
Frank Blaschka4a71df52008-02-15 09:19:42 +0100767 if ((card->state != CARD_STATE_UP) || !card->lan_online) {
768 card->stats.tx_carrier_errors++;
769 goto tx_drop;
770 }
771
772 if ((card->info.type == QETH_CARD_TYPE_OSN) &&
773 (skb->protocol == htons(ETH_P_IPV6)))
774 goto tx_drop;
775
776 if (card->options.performance_stats) {
777 card->perf_stats.outbound_cnt++;
778 card->perf_stats.outbound_start_time = qeth_get_micros();
779 }
780 netif_stop_queue(dev);
781
Frank Blaschka4a71df52008-02-15 09:19:42 +0100782 if (card->info.type == QETH_CARD_TYPE_OSN)
783 hdr = (struct qeth_hdr *)skb->data;
784 else {
Frank Blaschka64ef8952009-03-24 20:57:16 +0000785 if (card->info.type == QETH_CARD_TYPE_IQD) {
Frank Blaschka683d7182008-08-01 16:39:13 +0200786 new_skb = skb;
787 data_offset = ETH_HLEN;
788 hd_len = ETH_HLEN;
789 hdr = kmem_cache_alloc(qeth_core_header_cache,
790 GFP_ATOMIC);
791 if (!hdr)
792 goto tx_drop;
793 elements_needed++;
794 skb_reset_mac_header(new_skb);
Stefan Raspl43934072014-03-19 07:58:01 +0100795 qeth_l2_fill_header(card, hdr, new_skb, cast_type);
Frank Blaschka683d7182008-08-01 16:39:13 +0200796 hdr->hdr.l2.pkt_length = new_skb->len;
797 memcpy(((char *)hdr) + sizeof(struct qeth_hdr),
798 skb_mac_header(new_skb), ETH_HLEN);
799 } else {
800 /* create a clone with writeable headroom */
801 new_skb = skb_realloc_headroom(skb,
Frank Blaschkaf90b7442008-04-24 10:15:24 +0200802 sizeof(struct qeth_hdr));
Frank Blaschka683d7182008-08-01 16:39:13 +0200803 if (!new_skb)
804 goto tx_drop;
805 hdr = (struct qeth_hdr *)skb_push(new_skb,
806 sizeof(struct qeth_hdr));
807 skb_set_mac_header(new_skb, sizeof(struct qeth_hdr));
Stefan Raspl43934072014-03-19 07:58:01 +0100808 qeth_l2_fill_header(card, hdr, new_skb, cast_type);
Frank Blaschka683d7182008-08-01 16:39:13 +0200809 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100810 }
811
Stefan Raspl065cc782013-04-22 01:12:28 +0000812 elements = qeth_get_elements_no(card, new_skb, elements_needed);
Frank Blaschka64ef8952009-03-24 20:57:16 +0000813 if (!elements) {
814 if (data_offset >= 0)
815 kmem_cache_free(qeth_core_header_cache, hdr);
816 goto tx_drop;
Frank Blaschkaf61a0d02009-03-24 20:57:15 +0000817 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100818
Frank Blaschka51aa1652010-06-21 22:57:10 +0000819 if (card->info.type != QETH_CARD_TYPE_IQD) {
Stefan Raspld4ae1f52013-04-22 01:12:29 +0000820 if (qeth_hdr_chk_and_bounce(new_skb, &hdr,
Frank Blaschka51aa1652010-06-21 22:57:10 +0000821 sizeof(struct qeth_hdr_layer2)))
822 goto tx_drop;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100823 rc = qeth_do_send_packet(card, queue, new_skb, hdr,
Frank Blaschka64ef8952009-03-24 20:57:16 +0000824 elements);
Frank Blaschka51aa1652010-06-21 22:57:10 +0000825 } else
Frank Blaschka4a71df52008-02-15 09:19:42 +0100826 rc = qeth_do_send_packet_fast(card, queue, new_skb, hdr,
Frank Blaschka64ef8952009-03-24 20:57:16 +0000827 elements, data_offset, hd_len);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100828 if (!rc) {
829 card->stats.tx_packets++;
830 card->stats.tx_bytes += tx_bytes;
831 if (new_skb != skb)
832 dev_kfree_skb_any(skb);
Patrick McHardyec634fe2009-07-05 19:23:38 -0700833 rc = NETDEV_TX_OK;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100834 } else {
Frank Blaschka683d7182008-08-01 16:39:13 +0200835 if (data_offset >= 0)
836 kmem_cache_free(qeth_core_header_cache, hdr);
837
Frank Blaschka4a71df52008-02-15 09:19:42 +0100838 if (rc == -EBUSY) {
839 if (new_skb != skb)
840 dev_kfree_skb_any(new_skb);
841 return NETDEV_TX_BUSY;
842 } else
843 goto tx_drop;
844 }
845
846 netif_wake_queue(dev);
847 if (card->options.performance_stats)
848 card->perf_stats.outbound_time += qeth_get_micros() -
849 card->perf_stats.outbound_start_time;
850 return rc;
851
852tx_drop:
853 card->stats.tx_dropped++;
854 card->stats.tx_errors++;
855 if ((new_skb != skb) && new_skb)
856 dev_kfree_skb_any(new_skb);
857 dev_kfree_skb_any(skb);
Frank Blaschkad0ec0f52008-06-06 12:37:48 +0200858 netif_wake_queue(dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100859 return NETDEV_TX_OK;
860}
861
Ursula Braun39423442011-01-12 20:42:24 +0000862static int __qeth_l2_open(struct net_device *dev)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100863{
Heiko Carstens509e2562008-07-26 02:24:10 -0700864 struct qeth_card *card = dev->ml_priv;
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000865 int rc = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100866
Carsten Otte847a50f2010-06-21 22:57:05 +0000867 QETH_CARD_TEXT(card, 4, "qethopen");
Ursula Braun39423442011-01-12 20:42:24 +0000868 if (card->state == CARD_STATE_UP)
869 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100870 if (card->state != CARD_STATE_SOFTSETUP)
871 return -ENODEV;
872
873 if ((card->info.type != QETH_CARD_TYPE_OSN) &&
874 (!(card->info.mac_bits & QETH_LAYER2_MAC_REGISTERED))) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000875 QETH_CARD_TEXT(card, 4, "nomacadr");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100876 return -EPERM;
877 }
878 card->data.state = CH_STATE_UP;
879 card->state = CARD_STATE_UP;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100880 netif_start_queue(dev);
881
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000882 if (qdio_stop_irq(card->data.ccwdev, 0) >= 0) {
883 napi_enable(&card->napi);
884 napi_schedule(&card->napi);
885 } else
886 rc = -EIO;
887 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100888}
889
Ursula Braun39423442011-01-12 20:42:24 +0000890static int qeth_l2_open(struct net_device *dev)
891{
892 struct qeth_card *card = dev->ml_priv;
893
894 QETH_CARD_TEXT(card, 5, "qethope_");
895 if (qeth_wait_for_threads(card, QETH_RECOVER_THREAD)) {
896 QETH_CARD_TEXT(card, 3, "openREC");
897 return -ERESTARTSYS;
898 }
899 return __qeth_l2_open(dev);
900}
901
Frank Blaschka4a71df52008-02-15 09:19:42 +0100902static int qeth_l2_stop(struct net_device *dev)
903{
Heiko Carstens509e2562008-07-26 02:24:10 -0700904 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100905
Carsten Otte847a50f2010-06-21 22:57:05 +0000906 QETH_CARD_TEXT(card, 4, "qethstop");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100907 netif_tx_disable(dev);
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000908 if (card->state == CARD_STATE_UP) {
Frank Blaschka4a71df52008-02-15 09:19:42 +0100909 card->state = CARD_STATE_SOFTSETUP;
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000910 napi_disable(&card->napi);
911 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100912 return 0;
913}
914
915static int qeth_l2_probe_device(struct ccwgroup_device *gdev)
916{
917 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
918
Eugene Crosserb4d72c02014-01-14 15:54:11 +0100919 qeth_l2_create_device_attributes(&gdev->dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100920 INIT_LIST_HEAD(&card->vid_list);
921 INIT_LIST_HEAD(&card->mc_list);
922 card->options.layer2 = 1;
Frank Blaschka1da74b12011-05-12 18:45:02 +0000923 card->info.hwtrap = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100924 return 0;
925}
926
927static void qeth_l2_remove_device(struct ccwgroup_device *cgdev)
928{
929 struct qeth_card *card = dev_get_drvdata(&cgdev->dev);
930
Eugene Crosserb4d72c02014-01-14 15:54:11 +0100931 qeth_l2_remove_device_attributes(&cgdev->dev);
Ursula Braunf2148562009-05-19 21:38:37 +0000932 qeth_set_allowed_threads(card, 0, 1);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100933 wait_event(card->wait_q, qeth_threads_running(card, 0xffffffff) == 0);
934
Ursula Braun70919e22011-02-26 22:41:36 -0800935 if (cgdev->state == CCWGROUP_ONLINE)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100936 qeth_l2_set_offline(cgdev);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100937
938 if (card->dev) {
939 unregister_netdev(card->dev);
940 card->dev = NULL;
941 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100942 return;
943}
944
Stephen Hemminger0fc0b732009-09-02 01:03:33 -0700945static const struct ethtool_ops qeth_l2_ethtool_ops = {
Frank Blaschka4a71df52008-02-15 09:19:42 +0100946 .get_link = ethtool_op_get_link,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100947 .get_strings = qeth_core_get_strings,
948 .get_ethtool_stats = qeth_core_get_ethtool_stats,
Ben Hutchingsdf8b4ec2009-10-01 11:24:32 +0000949 .get_sset_count = qeth_core_get_sset_count,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100950 .get_drvinfo = qeth_core_get_drvinfo,
Frank Blaschka3f9975a2008-04-24 10:15:23 +0200951 .get_settings = qeth_core_ethtool_get_settings,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100952};
953
Stephen Hemminger0fc0b732009-09-02 01:03:33 -0700954static const struct ethtool_ops qeth_l2_osn_ops = {
Frank Blaschka4a71df52008-02-15 09:19:42 +0100955 .get_strings = qeth_core_get_strings,
956 .get_ethtool_stats = qeth_core_get_ethtool_stats,
Ben Hutchingsdf8b4ec2009-10-01 11:24:32 +0000957 .get_sset_count = qeth_core_get_sset_count,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100958 .get_drvinfo = qeth_core_get_drvinfo,
959};
960
Frank Blaschka3d58cef2009-01-09 03:44:00 +0000961static const struct net_device_ops qeth_l2_netdev_ops = {
Frank Blaschka8403b132009-01-08 10:50:55 -0800962 .ndo_open = qeth_l2_open,
963 .ndo_stop = qeth_l2_stop,
964 .ndo_get_stats = qeth_get_stats,
965 .ndo_start_xmit = qeth_l2_hard_start_xmit,
966 .ndo_validate_addr = eth_validate_addr,
Jiri Pirkoafc4b132011-08-16 06:29:01 +0000967 .ndo_set_rx_mode = qeth_l2_set_multicast_list,
Frank Blaschka8403b132009-01-08 10:50:55 -0800968 .ndo_do_ioctl = qeth_l2_do_ioctl,
969 .ndo_set_mac_address = qeth_l2_set_mac_address,
970 .ndo_change_mtu = qeth_change_mtu,
971 .ndo_vlan_rx_add_vid = qeth_l2_vlan_rx_add_vid,
972 .ndo_vlan_rx_kill_vid = qeth_l2_vlan_rx_kill_vid,
973 .ndo_tx_timeout = qeth_tx_timeout,
974};
975
Frank Blaschka4a71df52008-02-15 09:19:42 +0100976static int qeth_l2_setup_netdev(struct qeth_card *card)
977{
978 switch (card->info.type) {
Frank Blaschka4a71df52008-02-15 09:19:42 +0100979 case QETH_CARD_TYPE_IQD:
Tom Gundersenc835a672014-07-14 16:37:24 +0200980 card->dev = alloc_netdev(0, "hsi%d", NET_NAME_UNKNOWN,
981 ether_setup);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100982 break;
983 case QETH_CARD_TYPE_OSN:
Tom Gundersenc835a672014-07-14 16:37:24 +0200984 card->dev = alloc_netdev(0, "osn%d", NET_NAME_UNKNOWN,
985 ether_setup);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100986 card->dev->flags |= IFF_NOARP;
987 break;
988 default:
989 card->dev = alloc_etherdev(0);
990 }
991
992 if (!card->dev)
993 return -ENODEV;
994
Heiko Carstens509e2562008-07-26 02:24:10 -0700995 card->dev->ml_priv = card;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100996 card->dev->watchdog_timeo = QETH_TX_TIMEOUT;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100997 card->dev->mtu = card->info.initial_mtu;
Frank Blaschka8403b132009-01-08 10:50:55 -0800998 card->dev->netdev_ops = &qeth_l2_netdev_ops;
Wilfried Klaebe7ad24ea2014-05-11 00:12:32 +0000999 card->dev->ethtool_ops =
1000 (card->info.type != QETH_CARD_TYPE_OSN) ?
1001 &qeth_l2_ethtool_ops : &qeth_l2_osn_ops;
Patrick McHardyf6469682013-04-19 02:04:27 +00001002 card->dev->features |= NETIF_F_HW_VLAN_CTAG_FILTER;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001003 card->info.broadcast_capable = 1;
1004 qeth_l2_request_initial_mac(card);
1005 SET_NETDEV_DEV(card->dev, &card->gdev->dev);
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00001006 netif_napi_add(card->dev, &card->napi, qeth_l2_poll, QETH_NAPI_WEIGHT);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001007 return register_netdev(card->dev);
1008}
1009
1010static int __qeth_l2_set_online(struct ccwgroup_device *gdev, int recovery_mode)
1011{
1012 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
1013 int rc = 0;
1014 enum qeth_card_states recover_flag;
1015
Ursula Braun9dc48cc2010-07-22 23:15:05 +00001016 mutex_lock(&card->discipline_mutex);
Frank Blaschkac4949f02010-05-11 19:34:47 +00001017 mutex_lock(&card->conf_mutex);
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001018 QETH_DBF_TEXT(SETUP, 2, "setonlin");
1019 QETH_DBF_HEX(SETUP, 2, &card, sizeof(void *));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001020
Frank Blaschka4a71df52008-02-15 09:19:42 +01001021 recover_flag = card->state;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001022 rc = qeth_core_hardsetup_card(card);
1023 if (rc) {
Thomas Richter1aec42b2015-01-21 13:39:10 +01001024 QETH_DBF_TEXT_(SETUP, 2, "2err%04x", rc);
Ursula Braunaa909222009-11-12 00:11:43 +00001025 rc = -ENODEV;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001026 goto out_remove;
1027 }
Eugene Crosserc044dc22014-01-29 09:23:48 +01001028 qeth_bridgeport_query_support(card);
1029 if (card->options.sbp.supported_funcs)
1030 dev_info(&card->gdev->dev,
1031 "The device represents a HiperSockets Bridge Capable Port\n");
Stefan Raspl395672e02012-11-19 02:46:49 +00001032 qeth_trace_features(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001033
Ursula Braunaa909222009-11-12 00:11:43 +00001034 if (!card->dev && qeth_l2_setup_netdev(card)) {
1035 rc = -ENODEV;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001036 goto out_remove;
Ursula Braunaa909222009-11-12 00:11:43 +00001037 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01001038
1039 if (card->info.type != QETH_CARD_TYPE_OSN)
1040 qeth_l2_send_setmac(card, &card->dev->dev_addr[0]);
1041
Frank Blaschka1da74b12011-05-12 18:45:02 +00001042 if (qeth_is_diagass_supported(card, QETH_DIAGS_CMD_TRAP)) {
1043 if (card->info.hwtrap &&
1044 qeth_hw_trap(card, QETH_DIAGS_TRAP_ARM))
1045 card->info.hwtrap = 0;
1046 } else
1047 card->info.hwtrap = 0;
1048
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001049 qeth_l2_setup_bridgeport_attrs(card);
1050
Frank Blaschka4a71df52008-02-15 09:19:42 +01001051 card->state = CARD_STATE_HARDSETUP;
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00001052 memset(&card->rx, 0, sizeof(struct qeth_rx));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001053 qeth_print_status_message(card);
1054
1055 /* softsetup */
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001056 QETH_DBF_TEXT(SETUP, 2, "softsetp");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001057
1058 rc = qeth_send_startlan(card);
1059 if (rc) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001060 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001061 if (rc == 0xe080) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001062 dev_warn(&card->gdev->dev,
1063 "The LAN is offline\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001064 card->lan_online = 0;
Ursula Braun2b6203b2010-11-26 02:41:19 +00001065 goto contin;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001066 }
Ursula Braunaa909222009-11-12 00:11:43 +00001067 rc = -ENODEV;
Ursula Braunf2148562009-05-19 21:38:37 +00001068 goto out_remove;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001069 } else
1070 card->lan_online = 1;
1071
Ursula Braun2b6203b2010-11-26 02:41:19 +00001072contin:
Ursula Braun5113fec2010-05-16 21:15:14 +00001073 if ((card->info.type == QETH_CARD_TYPE_OSD) ||
Stefan Raspl0f547612013-01-21 02:30:20 +00001074 (card->info.type == QETH_CARD_TYPE_OSX)) {
Einar Lueckd64ecc22009-11-12 00:11:41 +00001075 /* configure isolation level */
Stefan Raspl0f547612013-01-21 02:30:20 +00001076 rc = qeth_set_access_ctrl_online(card, 0);
1077 if (rc) {
1078 rc = -ENODEV;
1079 goto out_remove;
1080 }
1081 }
Ursula Braun5113fec2010-05-16 21:15:14 +00001082
1083 if (card->info.type != QETH_CARD_TYPE_OSN &&
1084 card->info.type != QETH_CARD_TYPE_OSM)
Ursula Braun70919e22011-02-26 22:41:36 -08001085 qeth_l2_process_vlans(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001086
1087 netif_tx_disable(card->dev);
1088
1089 rc = qeth_init_qdio_queues(card);
1090 if (rc) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001091 QETH_DBF_TEXT_(SETUP, 2, "6err%d", rc);
Ursula Braunaa909222009-11-12 00:11:43 +00001092 rc = -ENODEV;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001093 goto out_remove;
1094 }
1095 card->state = CARD_STATE_SOFTSETUP;
Ursula Braun2b6203b2010-11-26 02:41:19 +00001096 if (card->lan_online)
1097 netif_carrier_on(card->dev);
1098 else
1099 netif_carrier_off(card->dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001100
1101 qeth_set_allowed_threads(card, 0xffffffff, 0);
1102 if (recover_flag == CARD_STATE_RECOVER) {
1103 if (recovery_mode &&
1104 card->info.type != QETH_CARD_TYPE_OSN) {
Ursula Braun39423442011-01-12 20:42:24 +00001105 __qeth_l2_open(card->dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001106 } else {
1107 rtnl_lock();
1108 dev_open(card->dev);
1109 rtnl_unlock();
1110 }
1111 /* this also sets saved unicast addresses */
1112 qeth_l2_set_multicast_list(card->dev);
1113 }
1114 /* let user_space know that device is online */
1115 kobject_uevent(&gdev->dev.kobj, KOBJ_CHANGE);
Frank Blaschkac4949f02010-05-11 19:34:47 +00001116 mutex_unlock(&card->conf_mutex);
Ursula Braun9dc48cc2010-07-22 23:15:05 +00001117 mutex_unlock(&card->discipline_mutex);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001118 return 0;
Ursula Braunaa909222009-11-12 00:11:43 +00001119
Frank Blaschka4a71df52008-02-15 09:19:42 +01001120out_remove:
Frank Blaschka4a71df52008-02-15 09:19:42 +01001121 qeth_l2_stop_card(card, 0);
1122 ccw_device_set_offline(CARD_DDEV(card));
1123 ccw_device_set_offline(CARD_WDEV(card));
1124 ccw_device_set_offline(CARD_RDEV(card));
Ursula Braun22ae2792014-02-24 13:12:06 +01001125 qdio_free(CARD_DDEV(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001126 if (recover_flag == CARD_STATE_RECOVER)
1127 card->state = CARD_STATE_RECOVER;
1128 else
1129 card->state = CARD_STATE_DOWN;
Frank Blaschkac4949f02010-05-11 19:34:47 +00001130 mutex_unlock(&card->conf_mutex);
Ursula Braun9dc48cc2010-07-22 23:15:05 +00001131 mutex_unlock(&card->discipline_mutex);
Ursula Braunaa909222009-11-12 00:11:43 +00001132 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001133}
1134
1135static int qeth_l2_set_online(struct ccwgroup_device *gdev)
1136{
1137 return __qeth_l2_set_online(gdev, 0);
1138}
1139
1140static int __qeth_l2_set_offline(struct ccwgroup_device *cgdev,
1141 int recovery_mode)
1142{
1143 struct qeth_card *card = dev_get_drvdata(&cgdev->dev);
1144 int rc = 0, rc2 = 0, rc3 = 0;
1145 enum qeth_card_states recover_flag;
1146
Ursula Braun9dc48cc2010-07-22 23:15:05 +00001147 mutex_lock(&card->discipline_mutex);
Frank Blaschkac4949f02010-05-11 19:34:47 +00001148 mutex_lock(&card->conf_mutex);
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001149 QETH_DBF_TEXT(SETUP, 3, "setoffl");
1150 QETH_DBF_HEX(SETUP, 3, &card, sizeof(void *));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001151
1152 if (card->dev && netif_carrier_ok(card->dev))
1153 netif_carrier_off(card->dev);
1154 recover_flag = card->state;
Frank Blaschka1da74b12011-05-12 18:45:02 +00001155 if ((!recovery_mode && card->info.hwtrap) || card->info.hwtrap == 2) {
1156 qeth_hw_trap(card, QETH_DIAGS_TRAP_DISARM);
1157 card->info.hwtrap = 1;
1158 }
Ursula Braun0f5623c2008-10-24 11:16:52 +02001159 qeth_l2_stop_card(card, recovery_mode);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001160 rc = ccw_device_set_offline(CARD_DDEV(card));
1161 rc2 = ccw_device_set_offline(CARD_WDEV(card));
1162 rc3 = ccw_device_set_offline(CARD_RDEV(card));
1163 if (!rc)
1164 rc = (rc2) ? rc2 : rc3;
1165 if (rc)
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001166 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
Ursula Braun22ae2792014-02-24 13:12:06 +01001167 qdio_free(CARD_DDEV(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001168 if (recover_flag == CARD_STATE_UP)
1169 card->state = CARD_STATE_RECOVER;
1170 /* let user_space know that device is offline */
1171 kobject_uevent(&cgdev->dev.kobj, KOBJ_CHANGE);
Frank Blaschkac4949f02010-05-11 19:34:47 +00001172 mutex_unlock(&card->conf_mutex);
Ursula Braun9dc48cc2010-07-22 23:15:05 +00001173 mutex_unlock(&card->discipline_mutex);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001174 return 0;
1175}
1176
1177static int qeth_l2_set_offline(struct ccwgroup_device *cgdev)
1178{
1179 return __qeth_l2_set_offline(cgdev, 0);
1180}
1181
1182static int qeth_l2_recover(void *ptr)
1183{
1184 struct qeth_card *card;
1185 int rc = 0;
1186
1187 card = (struct qeth_card *) ptr;
Carsten Otte847a50f2010-06-21 22:57:05 +00001188 QETH_CARD_TEXT(card, 2, "recover1");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001189 if (!qeth_do_run_thread(card, QETH_RECOVER_THREAD))
1190 return 0;
Carsten Otte847a50f2010-06-21 22:57:05 +00001191 QETH_CARD_TEXT(card, 2, "recover2");
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001192 dev_warn(&card->gdev->dev,
1193 "A recovery process has been started for the device\n");
Stefan Raspl65d80132013-04-07 22:19:27 +00001194 qeth_set_recovery_task(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001195 __qeth_l2_set_offline(card->gdev, 1);
1196 rc = __qeth_l2_set_online(card->gdev, 1);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001197 if (!rc)
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001198 dev_info(&card->gdev->dev,
1199 "Device successfully recovered!\n");
Ursula Braun28a7e4c2008-09-19 12:56:03 +02001200 else {
Stefan Raspl0f547612013-01-21 02:30:20 +00001201 qeth_close_dev(card);
1202 dev_warn(&card->gdev->dev, "The qeth device driver "
Stefan Raspl2efaf5f2012-10-15 19:21:18 +00001203 "failed to recover an error on the device\n");
Ursula Braun28a7e4c2008-09-19 12:56:03 +02001204 }
Stefan Raspl65d80132013-04-07 22:19:27 +00001205 qeth_clear_recovery_task(card);
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00001206 qeth_clear_thread_start_bit(card, QETH_RECOVER_THREAD);
1207 qeth_clear_thread_running_bit(card, QETH_RECOVER_THREAD);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001208 return 0;
1209}
1210
1211static int __init qeth_l2_init(void)
1212{
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001213 pr_info("register layer 2 discipline\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001214 return 0;
1215}
1216
1217static void __exit qeth_l2_exit(void)
1218{
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001219 pr_info("unregister layer 2 discipline\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001220}
1221
1222static void qeth_l2_shutdown(struct ccwgroup_device *gdev)
1223{
1224 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
Ursula Braunf78ac2b2011-12-19 22:56:33 +00001225 qeth_set_allowed_threads(card, 0, 1);
Frank Blaschka1da74b12011-05-12 18:45:02 +00001226 if ((gdev->state == CCWGROUP_ONLINE) && card->info.hwtrap)
1227 qeth_hw_trap(card, QETH_DIAGS_TRAP_DISARM);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001228 qeth_qdio_clear_card(card, 0);
1229 qeth_clear_qdio_buffers(card);
Ursula Braun22ae2792014-02-24 13:12:06 +01001230 qdio_free(CARD_DDEV(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001231}
1232
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02001233static int qeth_l2_pm_suspend(struct ccwgroup_device *gdev)
1234{
1235 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
1236
1237 if (card->dev)
1238 netif_device_detach(card->dev);
1239 qeth_set_allowed_threads(card, 0, 1);
1240 wait_event(card->wait_q, qeth_threads_running(card, 0xffffffff) == 0);
1241 if (gdev->state == CCWGROUP_OFFLINE)
1242 return 0;
1243 if (card->state == CARD_STATE_UP) {
Frank Blaschka1da74b12011-05-12 18:45:02 +00001244 if (card->info.hwtrap)
1245 qeth_hw_trap(card, QETH_DIAGS_TRAP_DISARM);
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02001246 __qeth_l2_set_offline(card->gdev, 1);
1247 } else
1248 __qeth_l2_set_offline(card->gdev, 0);
1249 return 0;
1250}
1251
1252static int qeth_l2_pm_resume(struct ccwgroup_device *gdev)
1253{
1254 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
1255 int rc = 0;
1256
1257 if (gdev->state == CCWGROUP_OFFLINE)
1258 goto out;
1259
1260 if (card->state == CARD_STATE_RECOVER) {
1261 rc = __qeth_l2_set_online(card->gdev, 1);
1262 if (rc) {
Ursula Braun869da902010-03-08 20:36:56 +00001263 rtnl_lock();
1264 dev_close(card->dev);
1265 rtnl_unlock();
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02001266 }
1267 } else
1268 rc = __qeth_l2_set_online(card->gdev, 0);
1269out:
1270 qeth_set_allowed_threads(card, 0xffffffff, 0);
1271 if (card->dev)
1272 netif_device_attach(card->dev);
1273 if (rc)
1274 dev_warn(&card->gdev->dev, "The qeth device driver "
1275 "failed to recover an error on the device\n");
1276 return rc;
1277}
1278
Eugene Crosserc044dc22014-01-29 09:23:48 +01001279/* Returns zero if the command is successfully "consumed" */
1280static int qeth_l2_control_event(struct qeth_card *card,
1281 struct qeth_ipa_cmd *cmd)
1282{
1283 switch (cmd->hdr.command) {
1284 case IPA_CMD_SETBRIDGEPORT:
1285 if (cmd->data.sbp.hdr.command_code ==
1286 IPA_SBP_BRIDGE_PORT_STATE_CHANGE) {
1287 qeth_bridge_state_change(card, cmd);
1288 return 0;
1289 } else
1290 return 1;
1291 case IPA_CMD_ADDRESS_CHANGE_NOTIF:
1292 qeth_bridge_host_event(card, cmd);
1293 return 0;
1294 default:
1295 return 1;
1296 }
1297}
1298
Sebastian Ottc041f2d4872012-05-15 18:02:21 +02001299struct qeth_discipline qeth_l2_discipline = {
1300 .start_poll = qeth_qdio_start_poll,
1301 .input_handler = (qdio_handler_t *) qeth_qdio_input_handler,
1302 .output_handler = (qdio_handler_t *) qeth_qdio_output_handler,
1303 .recover = qeth_l2_recover,
1304 .setup = qeth_l2_probe_device,
Frank Blaschka4a71df52008-02-15 09:19:42 +01001305 .remove = qeth_l2_remove_device,
1306 .set_online = qeth_l2_set_online,
1307 .set_offline = qeth_l2_set_offline,
1308 .shutdown = qeth_l2_shutdown,
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02001309 .freeze = qeth_l2_pm_suspend,
1310 .thaw = qeth_l2_pm_resume,
1311 .restore = qeth_l2_pm_resume,
Eugene Crosserc044dc22014-01-29 09:23:48 +01001312 .control_event_handler = qeth_l2_control_event,
Frank Blaschka4a71df52008-02-15 09:19:42 +01001313};
Sebastian Ottc041f2d4872012-05-15 18:02:21 +02001314EXPORT_SYMBOL_GPL(qeth_l2_discipline);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001315
1316static int qeth_osn_send_control_data(struct qeth_card *card, int len,
1317 struct qeth_cmd_buffer *iob)
1318{
1319 unsigned long flags;
1320 int rc = 0;
1321
Carsten Otte847a50f2010-06-21 22:57:05 +00001322 QETH_CARD_TEXT(card, 5, "osndctrd");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001323
1324 wait_event(card->wait_q,
1325 atomic_cmpxchg(&card->write.irq_pending, 0, 1) == 0);
1326 qeth_prepare_control_data(card, len, iob);
Carsten Otte847a50f2010-06-21 22:57:05 +00001327 QETH_CARD_TEXT(card, 6, "osnoirqp");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001328 spin_lock_irqsave(get_ccwdev_lock(card->write.ccwdev), flags);
1329 rc = ccw_device_start(card->write.ccwdev, &card->write.ccw,
1330 (addr_t) iob, 0, 0);
1331 spin_unlock_irqrestore(get_ccwdev_lock(card->write.ccwdev), flags);
1332 if (rc) {
Frank Blaschka14cc21b2008-06-06 12:37:46 +02001333 QETH_DBF_MESSAGE(2, "qeth_osn_send_control_data: "
Frank Blaschka4a71df52008-02-15 09:19:42 +01001334 "ccw_device_start rc = %i\n", rc);
Carsten Otte847a50f2010-06-21 22:57:05 +00001335 QETH_CARD_TEXT_(card, 2, " err%d", rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001336 qeth_release_buffer(iob->channel, iob);
1337 atomic_set(&card->write.irq_pending, 0);
1338 wake_up(&card->wait_q);
1339 }
1340 return rc;
1341}
1342
1343static int qeth_osn_send_ipa_cmd(struct qeth_card *card,
1344 struct qeth_cmd_buffer *iob, int data_len)
1345{
1346 u16 s1, s2;
1347
Carsten Otte847a50f2010-06-21 22:57:05 +00001348 QETH_CARD_TEXT(card, 4, "osndipa");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001349
1350 qeth_prepare_ipa_cmd(card, iob, QETH_PROT_OSN2);
1351 s1 = (u16)(IPA_PDU_HEADER_SIZE + data_len);
1352 s2 = (u16)data_len;
1353 memcpy(QETH_IPA_PDU_LEN_TOTAL(iob->data), &s1, 2);
1354 memcpy(QETH_IPA_PDU_LEN_PDU1(iob->data), &s2, 2);
1355 memcpy(QETH_IPA_PDU_LEN_PDU2(iob->data), &s2, 2);
1356 memcpy(QETH_IPA_PDU_LEN_PDU3(iob->data), &s2, 2);
1357 return qeth_osn_send_control_data(card, s1, iob);
1358}
1359
1360int qeth_osn_assist(struct net_device *dev, void *data, int data_len)
1361{
1362 struct qeth_cmd_buffer *iob;
1363 struct qeth_card *card;
1364 int rc;
1365
Frank Blaschka4a71df52008-02-15 09:19:42 +01001366 if (!dev)
1367 return -ENODEV;
Heiko Carstens509e2562008-07-26 02:24:10 -07001368 card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001369 if (!card)
1370 return -ENODEV;
Carsten Otte847a50f2010-06-21 22:57:05 +00001371 QETH_CARD_TEXT(card, 2, "osnsdmc");
Eugene Crosserc3521252015-01-16 14:05:47 +01001372 if (!qeth_card_hw_is_reachable(card))
Frank Blaschka4a71df52008-02-15 09:19:42 +01001373 return -ENODEV;
1374 iob = qeth_wait_for_buffer(&card->write);
1375 memcpy(iob->data+IPA_PDU_HEADER_SIZE, data, data_len);
1376 rc = qeth_osn_send_ipa_cmd(card, iob, data_len);
1377 return rc;
1378}
1379EXPORT_SYMBOL(qeth_osn_assist);
1380
1381int qeth_osn_register(unsigned char *read_dev_no, struct net_device **dev,
1382 int (*assist_cb)(struct net_device *, void *),
1383 int (*data_cb)(struct sk_buff *))
1384{
1385 struct qeth_card *card;
1386
Frank Blaschka4a71df52008-02-15 09:19:42 +01001387 *dev = qeth_l2_netdev_by_devno(read_dev_no);
1388 if (*dev == NULL)
1389 return -ENODEV;
Heiko Carstens509e2562008-07-26 02:24:10 -07001390 card = (*dev)->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001391 if (!card)
1392 return -ENODEV;
Carsten Otte847a50f2010-06-21 22:57:05 +00001393 QETH_CARD_TEXT(card, 2, "osnreg");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001394 if ((assist_cb == NULL) || (data_cb == NULL))
1395 return -EINVAL;
1396 card->osn_info.assist_cb = assist_cb;
1397 card->osn_info.data_cb = data_cb;
1398 return 0;
1399}
1400EXPORT_SYMBOL(qeth_osn_register);
1401
1402void qeth_osn_deregister(struct net_device *dev)
1403{
1404 struct qeth_card *card;
1405
Frank Blaschka4a71df52008-02-15 09:19:42 +01001406 if (!dev)
1407 return;
Heiko Carstens509e2562008-07-26 02:24:10 -07001408 card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001409 if (!card)
1410 return;
Carsten Otte847a50f2010-06-21 22:57:05 +00001411 QETH_CARD_TEXT(card, 2, "osndereg");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001412 card->osn_info.assist_cb = NULL;
1413 card->osn_info.data_cb = NULL;
1414 return;
1415}
1416EXPORT_SYMBOL(qeth_osn_deregister);
1417
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001418/* SETBRIDGEPORT support, async notifications */
1419
Eugene Crosser9f48b9d2014-01-14 15:54:13 +01001420enum qeth_an_event_type {anev_reg_unreg, anev_abort, anev_reset};
1421
1422/**
1423 * qeth_bridge_emit_host_event() - bridgeport address change notification
1424 * @card: qeth_card structure pointer, for udev events.
1425 * @evtype: "normal" register/unregister, or abort, or reset. For abort
1426 * and reset token and addr_lnid are unused and may be NULL.
1427 * @code: event bitmask: high order bit 0x80 value 1 means removal of an
1428 * object, 0 - addition of an object.
1429 * 0x01 - VLAN, 0x02 - MAC, 0x03 - VLAN and MAC.
1430 * @token: "network token" structure identifying physical address of the port.
1431 * @addr_lnid: pointer to structure with MAC address and VLAN ID.
1432 *
1433 * This function is called when registrations and deregistrations are
1434 * reported by the hardware, and also when notifications are enabled -
1435 * for all currently registered addresses.
1436 */
1437static void qeth_bridge_emit_host_event(struct qeth_card *card,
1438 enum qeth_an_event_type evtype,
1439 u8 code, struct net_if_token *token, struct mac_addr_lnid *addr_lnid)
1440{
1441 char str[7][32];
1442 char *env[8];
1443 int i = 0;
1444
1445 switch (evtype) {
1446 case anev_reg_unreg:
1447 snprintf(str[i], sizeof(str[i]), "BRIDGEDHOST=%s",
1448 (code & IPA_ADDR_CHANGE_CODE_REMOVAL)
1449 ? "deregister" : "register");
1450 env[i] = str[i]; i++;
1451 if (code & IPA_ADDR_CHANGE_CODE_VLANID) {
1452 snprintf(str[i], sizeof(str[i]), "VLAN=%d",
1453 addr_lnid->lnid);
1454 env[i] = str[i]; i++;
1455 }
1456 if (code & IPA_ADDR_CHANGE_CODE_MACADDR) {
1457 snprintf(str[i], sizeof(str[i]), "MAC=%pM6",
1458 &addr_lnid->mac);
1459 env[i] = str[i]; i++;
1460 }
1461 snprintf(str[i], sizeof(str[i]), "NTOK_BUSID=%x.%x.%04x",
1462 token->cssid, token->ssid, token->devnum);
1463 env[i] = str[i]; i++;
1464 snprintf(str[i], sizeof(str[i]), "NTOK_IID=%02x", token->iid);
1465 env[i] = str[i]; i++;
1466 snprintf(str[i], sizeof(str[i]), "NTOK_CHPID=%02x",
1467 token->chpid);
1468 env[i] = str[i]; i++;
1469 snprintf(str[i], sizeof(str[i]), "NTOK_CHID=%04x", token->chid);
1470 env[i] = str[i]; i++;
1471 break;
1472 case anev_abort:
1473 snprintf(str[i], sizeof(str[i]), "BRIDGEDHOST=abort");
1474 env[i] = str[i]; i++;
1475 break;
1476 case anev_reset:
1477 snprintf(str[i], sizeof(str[i]), "BRIDGEDHOST=reset");
1478 env[i] = str[i]; i++;
1479 break;
1480 }
1481 env[i] = NULL;
1482 kobject_uevent_env(&card->gdev->dev.kobj, KOBJ_CHANGE, env);
1483}
1484
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001485struct qeth_bridge_state_data {
1486 struct work_struct worker;
1487 struct qeth_card *card;
1488 struct qeth_sbp_state_change qports;
1489};
1490
1491static void qeth_bridge_state_change_worker(struct work_struct *work)
1492{
1493 struct qeth_bridge_state_data *data =
1494 container_of(work, struct qeth_bridge_state_data, worker);
1495 /* We are only interested in the first entry - local port */
1496 struct qeth_sbp_port_entry *entry = &data->qports.entry[0];
1497 char env_locrem[32];
1498 char env_role[32];
1499 char env_state[32];
1500 char *env[] = {
1501 env_locrem,
1502 env_role,
1503 env_state,
1504 NULL
1505 };
1506
1507 /* Role should not change by itself, but if it did, */
1508 /* information from the hardware is authoritative. */
1509 mutex_lock(&data->card->conf_mutex);
1510 data->card->options.sbp.role = entry->role;
1511 mutex_unlock(&data->card->conf_mutex);
1512
1513 snprintf(env_locrem, sizeof(env_locrem), "BRIDGEPORT=statechange");
1514 snprintf(env_role, sizeof(env_role), "ROLE=%s",
1515 (entry->role == QETH_SBP_ROLE_NONE) ? "none" :
1516 (entry->role == QETH_SBP_ROLE_PRIMARY) ? "primary" :
1517 (entry->role == QETH_SBP_ROLE_SECONDARY) ? "secondary" :
1518 "<INVALID>");
1519 snprintf(env_state, sizeof(env_state), "STATE=%s",
1520 (entry->state == QETH_SBP_STATE_INACTIVE) ? "inactive" :
1521 (entry->state == QETH_SBP_STATE_STANDBY) ? "standby" :
1522 (entry->state == QETH_SBP_STATE_ACTIVE) ? "active" :
1523 "<INVALID>");
1524 kobject_uevent_env(&data->card->gdev->dev.kobj,
1525 KOBJ_CHANGE, env);
1526 kfree(data);
1527}
1528
Eugene Crosserc044dc22014-01-29 09:23:48 +01001529static void qeth_bridge_state_change(struct qeth_card *card,
1530 struct qeth_ipa_cmd *cmd)
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001531{
1532 struct qeth_sbp_state_change *qports =
1533 &cmd->data.sbp.data.state_change;
1534 struct qeth_bridge_state_data *data;
1535 int extrasize;
1536
1537 QETH_CARD_TEXT(card, 2, "brstchng");
1538 if (qports->entry_length != sizeof(struct qeth_sbp_port_entry)) {
Thomas Richter8a593142014-10-22 12:18:03 +02001539 QETH_CARD_TEXT_(card, 2, "BPsz%04x", qports->entry_length);
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001540 return;
1541 }
1542 extrasize = sizeof(struct qeth_sbp_port_entry) * qports->num_entries;
1543 data = kzalloc(sizeof(struct qeth_bridge_state_data) + extrasize,
1544 GFP_ATOMIC);
1545 if (!data) {
1546 QETH_CARD_TEXT(card, 2, "BPSalloc");
1547 return;
1548 }
1549 INIT_WORK(&data->worker, qeth_bridge_state_change_worker);
1550 data->card = card;
1551 memcpy(&data->qports, qports,
1552 sizeof(struct qeth_sbp_state_change) + extrasize);
1553 queue_work(qeth_wq, &data->worker);
1554}
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001555
Eugene Crosser9f48b9d2014-01-14 15:54:13 +01001556struct qeth_bridge_host_data {
1557 struct work_struct worker;
1558 struct qeth_card *card;
1559 struct qeth_ipacmd_addr_change hostevs;
1560};
1561
1562static void qeth_bridge_host_event_worker(struct work_struct *work)
1563{
1564 struct qeth_bridge_host_data *data =
1565 container_of(work, struct qeth_bridge_host_data, worker);
1566 int i;
1567
1568 if (data->hostevs.lost_event_mask) {
1569 dev_info(&data->card->gdev->dev,
1570"Address notification from the HiperSockets Bridge Port stopped %s (%s)\n",
1571 data->card->dev->name,
1572 (data->hostevs.lost_event_mask == 0x01)
1573 ? "Overflow"
1574 : (data->hostevs.lost_event_mask == 0x02)
1575 ? "Bridge port state change"
1576 : "Unknown reason");
1577 mutex_lock(&data->card->conf_mutex);
1578 data->card->options.sbp.hostnotification = 0;
1579 mutex_unlock(&data->card->conf_mutex);
1580 qeth_bridge_emit_host_event(data->card, anev_abort,
1581 0, NULL, NULL);
1582 } else
1583 for (i = 0; i < data->hostevs.num_entries; i++) {
1584 struct qeth_ipacmd_addr_change_entry *entry =
1585 &data->hostevs.entry[i];
1586 qeth_bridge_emit_host_event(data->card,
1587 anev_reg_unreg,
1588 entry->change_code,
1589 &entry->token, &entry->addr_lnid);
1590 }
1591 kfree(data);
1592}
1593
Eugene Crosserc044dc22014-01-29 09:23:48 +01001594static void qeth_bridge_host_event(struct qeth_card *card,
1595 struct qeth_ipa_cmd *cmd)
Eugene Crosser9f48b9d2014-01-14 15:54:13 +01001596{
1597 struct qeth_ipacmd_addr_change *hostevs =
1598 &cmd->data.addrchange;
1599 struct qeth_bridge_host_data *data;
1600 int extrasize;
1601
1602 QETH_CARD_TEXT(card, 2, "brhostev");
1603 if (cmd->hdr.return_code != 0x0000) {
1604 if (cmd->hdr.return_code == 0x0010) {
1605 if (hostevs->lost_event_mask == 0x00)
1606 hostevs->lost_event_mask = 0xff;
1607 } else {
1608 QETH_CARD_TEXT_(card, 2, "BPHe%04x",
1609 cmd->hdr.return_code);
1610 return;
1611 }
1612 }
1613 extrasize = sizeof(struct qeth_ipacmd_addr_change_entry) *
1614 hostevs->num_entries;
1615 data = kzalloc(sizeof(struct qeth_bridge_host_data) + extrasize,
1616 GFP_ATOMIC);
1617 if (!data) {
1618 QETH_CARD_TEXT(card, 2, "BPHalloc");
1619 return;
1620 }
1621 INIT_WORK(&data->worker, qeth_bridge_host_event_worker);
1622 data->card = card;
1623 memcpy(&data->hostevs, hostevs,
1624 sizeof(struct qeth_ipacmd_addr_change) + extrasize);
1625 queue_work(qeth_wq, &data->worker);
1626}
Eugene Crosser9f48b9d2014-01-14 15:54:13 +01001627
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001628/* SETBRIDGEPORT support; sending commands */
1629
1630struct _qeth_sbp_cbctl {
1631 u16 ipa_rc;
1632 u16 cmd_rc;
1633 union {
1634 u32 supported;
1635 struct {
1636 enum qeth_sbp_roles *role;
1637 enum qeth_sbp_states *state;
1638 } qports;
1639 } data;
1640};
1641
1642/**
1643 * qeth_bridgeport_makerc() - derive "traditional" error from hardware codes.
1644 * @card: qeth_card structure pointer, for debug messages.
1645 * @cbctl: state structure with hardware return codes.
1646 * @setcmd: IPA command code
1647 *
1648 * Returns negative errno-compatible error indication or 0 on success.
1649 */
1650static int qeth_bridgeport_makerc(struct qeth_card *card,
1651 struct _qeth_sbp_cbctl *cbctl, enum qeth_ipa_sbp_cmd setcmd)
1652{
1653 int rc;
1654
1655 switch (cbctl->ipa_rc) {
1656 case IPA_RC_SUCCESS:
1657 switch (cbctl->cmd_rc) {
1658 case 0x0000:
1659 rc = 0;
1660 break;
1661 case 0x0004:
1662 rc = -ENOSYS;
1663 break;
1664 case 0x000C: /* Not configured as bridge Port */
1665 rc = -ENODEV; /* maybe not the best code here? */
1666 dev_err(&card->gdev->dev,
1667 "The HiperSockets device is not configured as a Bridge Port\n");
1668 break;
1669 case 0x0014: /* Another device is Primary */
1670 switch (setcmd) {
1671 case IPA_SBP_SET_PRIMARY_BRIDGE_PORT:
1672 rc = -EEXIST;
1673 dev_err(&card->gdev->dev,
1674 "The HiperSockets LAN already has a primary Bridge Port\n");
1675 break;
1676 case IPA_SBP_SET_SECONDARY_BRIDGE_PORT:
1677 rc = -EBUSY;
1678 dev_err(&card->gdev->dev,
1679 "The HiperSockets device is already a primary Bridge Port\n");
1680 break;
1681 default:
1682 rc = -EIO;
1683 }
1684 break;
1685 case 0x0018: /* This device is currently Secondary */
1686 rc = -EBUSY;
1687 dev_err(&card->gdev->dev,
1688 "The HiperSockets device is already a secondary Bridge Port\n");
1689 break;
1690 case 0x001C: /* Limit for Secondary devices reached */
1691 rc = -EEXIST;
1692 dev_err(&card->gdev->dev,
1693 "The HiperSockets LAN cannot have more secondary Bridge Ports\n");
1694 break;
1695 case 0x0024: /* This device is currently Primary */
1696 rc = -EBUSY;
1697 dev_err(&card->gdev->dev,
1698 "The HiperSockets device is already a primary Bridge Port\n");
1699 break;
1700 case 0x0020: /* Not authorized by zManager */
1701 rc = -EACCES;
1702 dev_err(&card->gdev->dev,
1703 "The HiperSockets device is not authorized to be a Bridge Port\n");
1704 break;
1705 default:
1706 rc = -EIO;
1707 }
1708 break;
1709 case IPA_RC_NOTSUPP:
1710 rc = -ENOSYS;
1711 break;
1712 case IPA_RC_UNSUPPORTED_COMMAND:
1713 rc = -ENOSYS;
1714 break;
1715 default:
1716 rc = -EIO;
1717 }
1718 if (rc) {
1719 QETH_CARD_TEXT_(card, 2, "SBPi%04x", cbctl->ipa_rc);
1720 QETH_CARD_TEXT_(card, 2, "SBPc%04x", cbctl->cmd_rc);
1721 }
1722 return rc;
1723}
1724
1725static int qeth_bridgeport_query_support_cb(struct qeth_card *card,
1726 struct qeth_reply *reply, unsigned long data)
1727{
1728 struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *) data;
1729 struct _qeth_sbp_cbctl *cbctl = (struct _qeth_sbp_cbctl *)reply->param;
1730 QETH_CARD_TEXT(card, 2, "brqsupcb");
1731 cbctl->ipa_rc = cmd->hdr.return_code;
1732 cbctl->cmd_rc = cmd->data.sbp.hdr.return_code;
1733 if ((cbctl->ipa_rc == 0) && (cbctl->cmd_rc == 0)) {
1734 cbctl->data.supported =
1735 cmd->data.sbp.data.query_cmds_supp.supported_cmds;
1736 } else {
1737 cbctl->data.supported = 0;
1738 }
1739 return 0;
1740}
1741
1742/**
1743 * qeth_bridgeport_query_support() - store bitmask of supported subfunctions.
1744 * @card: qeth_card structure pointer.
1745 *
1746 * Sets bitmask of supported setbridgeport subfunctions in the qeth_card
1747 * strucutre: card->options.sbp.supported_funcs.
1748 */
Eugene Crosserc044dc22014-01-29 09:23:48 +01001749static void qeth_bridgeport_query_support(struct qeth_card *card)
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001750{
1751 struct qeth_cmd_buffer *iob;
1752 struct qeth_ipa_cmd *cmd;
1753 struct _qeth_sbp_cbctl cbctl;
1754
1755 QETH_CARD_TEXT(card, 2, "brqsuppo");
1756 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_SETBRIDGEPORT, 0);
Thomas Richter1aec42b2015-01-21 13:39:10 +01001757 if (!iob)
1758 return;
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001759 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
1760 cmd->data.sbp.hdr.cmdlength =
1761 sizeof(struct qeth_ipacmd_sbp_hdr) +
1762 sizeof(struct qeth_sbp_query_cmds_supp);
1763 cmd->data.sbp.hdr.command_code =
1764 IPA_SBP_QUERY_COMMANDS_SUPPORTED;
1765 cmd->data.sbp.hdr.used_total = 1;
1766 cmd->data.sbp.hdr.seq_no = 1;
1767 if (qeth_send_ipa_cmd(card, iob, qeth_bridgeport_query_support_cb,
1768 (void *)&cbctl) ||
1769 qeth_bridgeport_makerc(card, &cbctl,
1770 IPA_SBP_QUERY_COMMANDS_SUPPORTED)) {
1771 /* non-zero makerc signifies failure, and produce messages */
1772 card->options.sbp.role = QETH_SBP_ROLE_NONE;
1773 return;
1774 }
1775 card->options.sbp.supported_funcs = cbctl.data.supported;
1776}
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001777
1778static int qeth_bridgeport_query_ports_cb(struct qeth_card *card,
1779 struct qeth_reply *reply, unsigned long data)
1780{
1781 struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *) data;
1782 struct qeth_sbp_query_ports *qports = &cmd->data.sbp.data.query_ports;
1783 struct _qeth_sbp_cbctl *cbctl = (struct _qeth_sbp_cbctl *)reply->param;
1784
1785 QETH_CARD_TEXT(card, 2, "brqprtcb");
1786 cbctl->ipa_rc = cmd->hdr.return_code;
1787 cbctl->cmd_rc = cmd->data.sbp.hdr.return_code;
1788 if ((cbctl->ipa_rc != 0) || (cbctl->cmd_rc != 0))
1789 return 0;
1790 if (qports->entry_length != sizeof(struct qeth_sbp_port_entry)) {
1791 cbctl->cmd_rc = 0xffff;
1792 QETH_CARD_TEXT_(card, 2, "SBPs%04x", qports->entry_length);
1793 return 0;
1794 }
1795 /* first entry contains the state of the local port */
1796 if (qports->num_entries > 0) {
1797 if (cbctl->data.qports.role)
1798 *cbctl->data.qports.role = qports->entry[0].role;
1799 if (cbctl->data.qports.state)
1800 *cbctl->data.qports.state = qports->entry[0].state;
1801 }
1802 return 0;
1803}
1804
1805/**
1806 * qeth_bridgeport_query_ports() - query local bridgeport status.
1807 * @card: qeth_card structure pointer.
1808 * @role: Role of the port: 0-none, 1-primary, 2-secondary.
1809 * @state: State of the port: 0-inactive, 1-standby, 2-active.
1810 *
1811 * Returns negative errno-compatible error indication or 0 on success.
1812 *
1813 * 'role' and 'state' are not updated in case of hardware operation failure.
1814 */
1815int qeth_bridgeport_query_ports(struct qeth_card *card,
1816 enum qeth_sbp_roles *role, enum qeth_sbp_states *state)
1817{
1818 int rc = 0;
1819 struct qeth_cmd_buffer *iob;
1820 struct qeth_ipa_cmd *cmd;
1821 struct _qeth_sbp_cbctl cbctl = {
1822 .data = {
1823 .qports = {
1824 .role = role,
1825 .state = state,
1826 },
1827 },
1828 };
1829
1830 QETH_CARD_TEXT(card, 2, "brqports");
1831 if (!(card->options.sbp.supported_funcs & IPA_SBP_QUERY_BRIDGE_PORTS))
1832 return -EOPNOTSUPP;
1833 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_SETBRIDGEPORT, 0);
Thomas Richter1aec42b2015-01-21 13:39:10 +01001834 if (!iob)
1835 return -ENOMEM;
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001836 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
1837 cmd->data.sbp.hdr.cmdlength =
1838 sizeof(struct qeth_ipacmd_sbp_hdr);
1839 cmd->data.sbp.hdr.command_code =
1840 IPA_SBP_QUERY_BRIDGE_PORTS;
1841 cmd->data.sbp.hdr.used_total = 1;
1842 cmd->data.sbp.hdr.seq_no = 1;
1843 rc = qeth_send_ipa_cmd(card, iob, qeth_bridgeport_query_ports_cb,
1844 (void *)&cbctl);
Eugene Crosserc88394e2015-05-18 14:27:53 +02001845 if (rc < 0)
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001846 return rc;
Eugene Crosserc88394e2015-05-18 14:27:53 +02001847 return qeth_bridgeport_makerc(card, &cbctl, IPA_SBP_QUERY_BRIDGE_PORTS);
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001848}
1849EXPORT_SYMBOL_GPL(qeth_bridgeport_query_ports);
1850
1851static int qeth_bridgeport_set_cb(struct qeth_card *card,
1852 struct qeth_reply *reply, unsigned long data)
1853{
1854 struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *)data;
1855 struct _qeth_sbp_cbctl *cbctl = (struct _qeth_sbp_cbctl *)reply->param;
1856 QETH_CARD_TEXT(card, 2, "brsetrcb");
1857 cbctl->ipa_rc = cmd->hdr.return_code;
1858 cbctl->cmd_rc = cmd->data.sbp.hdr.return_code;
1859 return 0;
1860}
1861
1862/**
1863 * qeth_bridgeport_setrole() - Assign primary role to the port.
1864 * @card: qeth_card structure pointer.
1865 * @role: Role to assign.
1866 *
1867 * Returns negative errno-compatible error indication or 0 on success.
1868 */
1869int qeth_bridgeport_setrole(struct qeth_card *card, enum qeth_sbp_roles role)
1870{
1871 int rc = 0;
1872 int cmdlength;
1873 struct qeth_cmd_buffer *iob;
1874 struct qeth_ipa_cmd *cmd;
1875 struct _qeth_sbp_cbctl cbctl;
1876 enum qeth_ipa_sbp_cmd setcmd;
1877
1878 QETH_CARD_TEXT(card, 2, "brsetrol");
1879 switch (role) {
1880 case QETH_SBP_ROLE_NONE:
1881 setcmd = IPA_SBP_RESET_BRIDGE_PORT_ROLE;
1882 cmdlength = sizeof(struct qeth_ipacmd_sbp_hdr) +
1883 sizeof(struct qeth_sbp_reset_role);
1884 break;
1885 case QETH_SBP_ROLE_PRIMARY:
1886 setcmd = IPA_SBP_SET_PRIMARY_BRIDGE_PORT;
1887 cmdlength = sizeof(struct qeth_ipacmd_sbp_hdr) +
1888 sizeof(struct qeth_sbp_set_primary);
1889 break;
1890 case QETH_SBP_ROLE_SECONDARY:
1891 setcmd = IPA_SBP_SET_SECONDARY_BRIDGE_PORT;
1892 cmdlength = sizeof(struct qeth_ipacmd_sbp_hdr) +
1893 sizeof(struct qeth_sbp_set_secondary);
1894 break;
1895 default:
1896 return -EINVAL;
1897 }
1898 if (!(card->options.sbp.supported_funcs & setcmd))
1899 return -EOPNOTSUPP;
1900 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_SETBRIDGEPORT, 0);
Thomas Richter1aec42b2015-01-21 13:39:10 +01001901 if (!iob)
1902 return -ENOMEM;
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001903 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
1904 cmd->data.sbp.hdr.cmdlength = cmdlength;
1905 cmd->data.sbp.hdr.command_code = setcmd;
1906 cmd->data.sbp.hdr.used_total = 1;
1907 cmd->data.sbp.hdr.seq_no = 1;
1908 rc = qeth_send_ipa_cmd(card, iob, qeth_bridgeport_set_cb,
1909 (void *)&cbctl);
Eugene Crosserc88394e2015-05-18 14:27:53 +02001910 if (rc < 0)
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001911 return rc;
Eugene Crosserc88394e2015-05-18 14:27:53 +02001912 return qeth_bridgeport_makerc(card, &cbctl, setcmd);
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001913}
1914
Eugene Crosser9f48b9d2014-01-14 15:54:13 +01001915/**
1916 * qeth_anset_makerc() - derive "traditional" error from hardware codes.
1917 * @card: qeth_card structure pointer, for debug messages.
1918 *
1919 * Returns negative errno-compatible error indication or 0 on success.
1920 */
1921static int qeth_anset_makerc(struct qeth_card *card, int pnso_rc, u16 response)
1922{
1923 int rc;
1924
1925 if (pnso_rc == 0)
1926 switch (response) {
1927 case 0x0001:
1928 rc = 0;
1929 break;
1930 case 0x0004:
1931 case 0x0100:
1932 case 0x0106:
1933 rc = -ENOSYS;
1934 dev_err(&card->gdev->dev,
1935 "Setting address notification failed\n");
1936 break;
1937 case 0x0107:
1938 rc = -EAGAIN;
1939 break;
1940 default:
1941 rc = -EIO;
1942 }
1943 else
1944 rc = -EIO;
1945
1946 if (rc) {
1947 QETH_CARD_TEXT_(card, 2, "SBPp%04x", pnso_rc);
1948 QETH_CARD_TEXT_(card, 2, "SBPr%04x", response);
1949 }
1950 return rc;
1951}
1952
1953static void qeth_bridgeport_an_set_cb(void *priv,
1954 enum qdio_brinfo_entry_type type, void *entry)
1955{
1956 struct qeth_card *card = (struct qeth_card *)priv;
1957 struct qdio_brinfo_entry_l2 *l2entry;
1958 u8 code;
1959
1960 if (type != l2_addr_lnid) {
1961 WARN_ON_ONCE(1);
1962 return;
1963 }
1964
1965 l2entry = (struct qdio_brinfo_entry_l2 *)entry;
1966 code = IPA_ADDR_CHANGE_CODE_MACADDR;
1967 if (l2entry->addr_lnid.lnid)
1968 code |= IPA_ADDR_CHANGE_CODE_VLANID;
1969 qeth_bridge_emit_host_event(card, anev_reg_unreg, code,
1970 (struct net_if_token *)&l2entry->nit,
1971 (struct mac_addr_lnid *)&l2entry->addr_lnid);
1972}
1973
1974/**
1975 * qeth_bridgeport_an_set() - Enable or disable bridgeport address notification
1976 * @card: qeth_card structure pointer.
1977 * @enable: 0 - disable, non-zero - enable notifications
1978 *
1979 * Returns negative errno-compatible error indication or 0 on success.
1980 *
1981 * On enable, emits a series of address notifications udev events for all
1982 * currently registered hosts.
1983 */
1984int qeth_bridgeport_an_set(struct qeth_card *card, int enable)
1985{
1986 int rc;
1987 u16 response;
1988 struct ccw_device *ddev;
1989 struct subchannel_id schid;
1990
1991 if (!card)
1992 return -EINVAL;
1993 if (!card->options.sbp.supported_funcs)
1994 return -EOPNOTSUPP;
1995 ddev = CARD_DDEV(card);
1996 ccw_device_get_schid(ddev, &schid);
1997
1998 if (enable) {
1999 qeth_bridge_emit_host_event(card, anev_reset, 0, NULL, NULL);
2000 rc = qdio_pnso_brinfo(schid, 1, &response,
2001 qeth_bridgeport_an_set_cb, card);
2002 } else
2003 rc = qdio_pnso_brinfo(schid, 0, &response, NULL, NULL);
2004 return qeth_anset_makerc(card, rc, response);
2005}
2006EXPORT_SYMBOL_GPL(qeth_bridgeport_an_set);
2007
Frank Blaschka4a71df52008-02-15 09:19:42 +01002008module_init(qeth_l2_init);
2009module_exit(qeth_l2_exit);
2010MODULE_AUTHOR("Frank Blaschka <frank.blaschka@de.ibm.com>");
2011MODULE_DESCRIPTION("qeth layer 2 discipline");
2012MODULE_LICENSE("GPL");