blob: b5e38531733f26e49a90158acf481744106dd42f [file] [log] [blame]
Greg Kroah-Hartmanab9953f2017-11-14 18:38:04 +01001// SPDX-License-Identifier: GPL-2.0
Frank Blaschka4a71df52008-02-15 09:19:42 +01002/*
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02003 * Copyright IBM Corp. 2007, 2009
Frank Blaschka4a71df52008-02-15 09:19:42 +01004 * Author(s): Utz Bacher <utz.bacher@de.ibm.com>,
5 * Frank Pavlic <fpavlic@de.ibm.com>,
6 * Thomas Spatzier <tspat@de.ibm.com>,
7 * Frank Blaschka <frank.blaschka@de.ibm.com>
8 */
9
Frank Blaschka74eacdb2008-12-25 13:39:49 +010010#define KMSG_COMPONENT "qeth"
11#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
12
Frank Blaschka4a71df52008-02-15 09:19:42 +010013#include <linux/module.h>
14#include <linux/moduleparam.h>
15#include <linux/string.h>
16#include <linux/errno.h>
17#include <linux/kernel.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090018#include <linux/slab.h>
Frank Blaschka4a71df52008-02-15 09:19:42 +010019#include <linux/etherdevice.h>
Jiri Pirkoccffad252009-05-22 23:22:17 +000020#include <linux/list.h>
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +020021#include <linux/hash.h>
22#include <linux/hashtable.h>
Julian Wiedmannec61bd22017-06-20 16:00:34 +020023#include <asm/setup.h>
Frank Blaschka4a71df52008-02-15 09:19:42 +010024#include "qeth_core.h"
Eugene Crosserb4d72c02014-01-14 15:54:11 +010025#include "qeth_l2.h"
Frank Blaschka4a71df52008-02-15 09:19:42 +010026
Frank Blaschka4a71df52008-02-15 09:19:42 +010027static int qeth_l2_set_offline(struct ccwgroup_device *);
28static int qeth_l2_stop(struct net_device *);
Eugene Crosserc044dc22014-01-29 09:23:48 +010029static void qeth_bridgeport_query_support(struct qeth_card *card);
30static void qeth_bridge_state_change(struct qeth_card *card,
31 struct qeth_ipa_cmd *cmd);
32static void qeth_bridge_host_event(struct qeth_card *card,
33 struct qeth_ipa_cmd *cmd);
Hans Wippelcaa1f0b2017-09-18 21:18:15 +020034static void qeth_l2_vnicc_set_defaults(struct qeth_card *card);
Hans Wippela45b3fa2017-09-18 21:18:14 +020035static void qeth_l2_vnicc_init(struct qeth_card *card);
Hans Wippel349d13d2017-09-18 21:18:16 +020036static bool qeth_l2_vnicc_recover_timeout(struct qeth_card *card, u32 vnicc,
37 u32 *timeout);
Frank Blaschka4a71df52008-02-15 09:19:42 +010038
Frank Blaschka4a71df52008-02-15 09:19:42 +010039static struct net_device *qeth_l2_netdev_by_devno(unsigned char *read_dev_no)
40{
41 struct qeth_card *card;
42 struct net_device *ndev;
Cornelia Huckf06f6f32008-06-06 12:37:45 +020043 __u16 temp_dev_no;
Frank Blaschka4a71df52008-02-15 09:19:42 +010044 unsigned long flags;
Cornelia Huckf06f6f32008-06-06 12:37:45 +020045 struct ccw_dev_id read_devid;
Frank Blaschka4a71df52008-02-15 09:19:42 +010046
47 ndev = NULL;
48 memcpy(&temp_dev_no, read_dev_no, 2);
49 read_lock_irqsave(&qeth_core_card_list.rwlock, flags);
50 list_for_each_entry(card, &qeth_core_card_list.list, list) {
Cornelia Huckf06f6f32008-06-06 12:37:45 +020051 ccw_device_get_id(CARD_RDEV(card), &read_devid);
52 if (read_devid.devno == temp_dev_no) {
Frank Blaschka4a71df52008-02-15 09:19:42 +010053 ndev = card->dev;
54 break;
55 }
56 }
57 read_unlock_irqrestore(&qeth_core_card_list.rwlock, flags);
58 return ndev;
59}
60
Julian Wiedmann2aa48672017-09-18 21:18:20 +020061static int qeth_setdelmac_makerc(struct qeth_card *card, int retcode)
Frank Blaschka4a71df52008-02-15 09:19:42 +010062{
Eugene Crosserefbbc1d2015-01-21 13:39:09 +010063 int rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +010064
Eugene Crosserefbbc1d2015-01-21 13:39:09 +010065 if (retcode)
Thomas Richter1aec42b2015-01-21 13:39:10 +010066 QETH_CARD_TEXT_(card, 2, "err%04x", retcode);
Eugene Crosserefbbc1d2015-01-21 13:39:09 +010067 switch (retcode) {
68 case IPA_RC_SUCCESS:
69 rc = 0;
70 break;
71 case IPA_RC_L2_UNSUPPORTED_CMD:
Eugene Crosserffb95252015-05-18 14:27:58 +020072 rc = -EOPNOTSUPP;
Eugene Crosserefbbc1d2015-01-21 13:39:09 +010073 break;
74 case IPA_RC_L2_ADDR_TABLE_FULL:
75 rc = -ENOSPC;
76 break;
77 case IPA_RC_L2_DUP_MAC:
78 case IPA_RC_L2_DUP_LAYER3_MAC:
79 rc = -EEXIST;
80 break;
81 case IPA_RC_L2_MAC_NOT_AUTH_BY_HYP:
82 case IPA_RC_L2_MAC_NOT_AUTH_BY_ADP:
83 rc = -EPERM;
84 break;
85 case IPA_RC_L2_MAC_NOT_FOUND:
86 rc = -ENOENT;
87 break;
Thomas Richter1aec42b2015-01-21 13:39:10 +010088 case -ENOMEM:
89 rc = -ENOMEM;
90 break;
Eugene Crosserefbbc1d2015-01-21 13:39:09 +010091 default:
92 rc = -EIO;
93 break;
Frank Blaschka4a71df52008-02-15 09:19:42 +010094 }
Eugene Crosserefbbc1d2015-01-21 13:39:09 +010095 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +010096}
97
Julian Wiedmannac988d72017-01-12 15:48:41 +010098static int qeth_l2_send_setdelmac(struct qeth_card *card, __u8 *mac,
99 enum qeth_ipa_cmds ipacmd)
100{
101 struct qeth_ipa_cmd *cmd;
102 struct qeth_cmd_buffer *iob;
103
104 QETH_CARD_TEXT(card, 2, "L2sdmac");
105 iob = qeth_get_ipacmd_buffer(card, ipacmd, QETH_PROT_IPV4);
106 if (!iob)
107 return -ENOMEM;
Julian Wiedmannff5caa72018-03-09 18:12:52 +0100108 cmd = __ipa_cmd(iob);
Julian Wiedmann99f0b852017-12-20 20:11:01 +0100109 cmd->data.setdelmac.mac_length = ETH_ALEN;
110 ether_addr_copy(cmd->data.setdelmac.mac, mac);
Julian Wiedmann2aa48672017-09-18 21:18:20 +0200111 return qeth_setdelmac_makerc(card, qeth_send_ipa_cmd(card, iob,
112 NULL, NULL));
Julian Wiedmannac988d72017-01-12 15:48:41 +0100113}
114
115static int qeth_l2_send_setmac(struct qeth_card *card, __u8 *mac)
116{
117 int rc;
118
119 QETH_CARD_TEXT(card, 2, "L2Setmac");
120 rc = qeth_l2_send_setdelmac(card, mac, IPA_CMD_SETVMAC);
121 if (rc == 0) {
Julian Wiedmannac988d72017-01-12 15:48:41 +0100122 dev_info(&card->gdev->dev,
Julian Wiedmannbcacfcb2018-04-19 12:52:09 +0200123 "MAC address %pM successfully registered on device %s\n",
124 mac, card->dev->name);
Julian Wiedmannac988d72017-01-12 15:48:41 +0100125 } else {
Julian Wiedmannac988d72017-01-12 15:48:41 +0100126 switch (rc) {
127 case -EEXIST:
128 dev_warn(&card->gdev->dev,
129 "MAC address %pM already exists\n", mac);
130 break;
131 case -EPERM:
132 dev_warn(&card->gdev->dev,
133 "MAC address %pM is not authorized\n", mac);
134 break;
135 }
136 }
137 return rc;
138}
139
Julian Wiedmann8174aa82017-12-20 20:11:00 +0100140static int qeth_l2_write_mac(struct qeth_card *card, u8 *mac)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100141{
Vasily Gorbik9d0a58f2018-06-29 19:45:52 +0200142 enum qeth_ipa_cmds cmd = is_multicast_ether_addr(mac) ?
Julian Wiedmann8174aa82017-12-20 20:11:00 +0100143 IPA_CMD_SETGMAC : IPA_CMD_SETVMAC;
Eugene Crosserefbbc1d2015-01-21 13:39:09 +0100144 int rc;
145
Julian Wiedmann8174aa82017-12-20 20:11:00 +0100146 QETH_CARD_TEXT(card, 2, "L2Wmac");
147 rc = qeth_l2_send_setdelmac(card, mac, cmd);
Eugene Crosserefbbc1d2015-01-21 13:39:09 +0100148 if (rc == -EEXIST)
Julian Wiedmann8174aa82017-12-20 20:11:00 +0100149 QETH_DBF_MESSAGE(2, "MAC %pM already registered on %s\n",
150 mac, QETH_CARD_IFNAME(card));
Eugene Crosserefbbc1d2015-01-21 13:39:09 +0100151 else if (rc)
Julian Wiedmann8174aa82017-12-20 20:11:00 +0100152 QETH_DBF_MESSAGE(2, "Failed to register MAC %pM on %s: %d\n",
153 mac, QETH_CARD_IFNAME(card), rc);
Eugene Crosserefbbc1d2015-01-21 13:39:09 +0100154 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100155}
156
Julian Wiedmann8174aa82017-12-20 20:11:00 +0100157static int qeth_l2_remove_mac(struct qeth_card *card, u8 *mac)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100158{
Vasily Gorbik9d0a58f2018-06-29 19:45:52 +0200159 enum qeth_ipa_cmds cmd = is_multicast_ether_addr(mac) ?
Julian Wiedmann8174aa82017-12-20 20:11:00 +0100160 IPA_CMD_DELGMAC : IPA_CMD_DELVMAC;
Eugene Crosserefbbc1d2015-01-21 13:39:09 +0100161 int rc;
162
Julian Wiedmann8174aa82017-12-20 20:11:00 +0100163 QETH_CARD_TEXT(card, 2, "L2Rmac");
164 rc = qeth_l2_send_setdelmac(card, mac, cmd);
Eugene Crosserefbbc1d2015-01-21 13:39:09 +0100165 if (rc)
Julian Wiedmann8174aa82017-12-20 20:11:00 +0100166 QETH_DBF_MESSAGE(2, "Failed to delete MAC %pM on %s: %d\n",
167 mac, QETH_CARD_IFNAME(card), rc);
Eugene Crosserefbbc1d2015-01-21 13:39:09 +0100168 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100169}
170
Julian Wiedmannc07cbf22017-01-12 15:48:37 +0100171static void qeth_l2_del_all_macs(struct qeth_card *card)
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200172{
173 struct qeth_mac *mac;
174 struct hlist_node *tmp;
175 int i;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100176
177 spin_lock_bh(&card->mclock);
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200178 hash_for_each_safe(card->mac_htable, i, tmp, mac, hnode) {
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200179 hash_del(&mac->hnode);
180 kfree(mac);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100181 }
182 spin_unlock_bh(&card->mclock);
183}
184
Julian Wiedmanncef6ff222017-08-15 17:02:46 +0200185static int qeth_l2_get_cast_type(struct qeth_card *card, struct sk_buff *skb)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100186{
Klaus-Dieter Wackerce73e102009-08-26 02:01:08 +0000187 if (card->info.type == QETH_CARD_TYPE_OSN)
Julian Wiedmann86c0cdb2018-07-11 17:42:41 +0200188 return RTN_UNICAST;
Klaus-Dieter Wackerce73e102009-08-26 02:01:08 +0000189 if (is_broadcast_ether_addr(skb->data))
190 return RTN_BROADCAST;
191 if (is_multicast_ether_addr(skb->data))
192 return RTN_MULTICAST;
Julian Wiedmann86c0cdb2018-07-11 17:42:41 +0200193 return RTN_UNICAST;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100194}
195
Julian Wiedmannae79fe02017-08-18 10:19:05 +0200196static void qeth_l2_fill_header(struct qeth_hdr *hdr, struct sk_buff *skb,
197 int cast_type, unsigned int data_len)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100198{
Frank Blaschka683d7182008-08-01 16:39:13 +0200199 struct vlan_ethhdr *veth = (struct vlan_ethhdr *)skb_mac_header(skb);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100200
201 memset(hdr, 0, sizeof(struct qeth_hdr));
202 hdr->hdr.l2.id = QETH_HEADER_TYPE_LAYER2;
Julian Wiedmannae79fe02017-08-18 10:19:05 +0200203 hdr->hdr.l2.pkt_length = data_len;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100204
205 /* set byte byte 3 to casting flags */
206 if (cast_type == RTN_MULTICAST)
207 hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_MULTICAST;
208 else if (cast_type == RTN_BROADCAST)
209 hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_BROADCAST;
210 else
Klaus-Dieter Wackerce73e102009-08-26 02:01:08 +0000211 hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_UNICAST;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100212
Frank Blaschka4a71df52008-02-15 09:19:42 +0100213 /* VSWITCH relies on the VLAN
214 * information to be present in
215 * the QDIO header */
216 if (veth->h_vlan_proto == __constant_htons(ETH_P_8021Q)) {
217 hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_VLAN;
218 hdr->hdr.l2.vlan_id = ntohs(veth->h_vlan_TCI);
219 }
220}
221
Julian Wiedmann2aa48672017-09-18 21:18:20 +0200222static int qeth_setdelvlan_makerc(struct qeth_card *card, int retcode)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100223{
Julian Wiedmann2aa48672017-09-18 21:18:20 +0200224 if (retcode)
225 QETH_CARD_TEXT_(card, 2, "err%04x", retcode);
226
227 switch (retcode) {
228 case IPA_RC_SUCCESS:
229 return 0;
230 case IPA_RC_L2_INVALID_VLAN_ID:
231 return -EINVAL;
232 case IPA_RC_L2_DUP_VLAN_ID:
233 return -EEXIST;
234 case IPA_RC_L2_VLAN_ID_NOT_FOUND:
235 return -ENOENT;
236 case IPA_RC_L2_VLAN_ID_NOT_ALLOWED:
237 return -EPERM;
238 case -ENOMEM:
239 return -ENOMEM;
240 default:
241 return -EIO;
242 }
243}
244
245static int qeth_l2_send_setdelvlan_cb(struct qeth_card *card,
246 struct qeth_reply *reply,
247 unsigned long data)
248{
249 struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *) data;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100250
Carsten Otte847a50f2010-06-21 22:57:05 +0000251 QETH_CARD_TEXT(card, 2, "L2sdvcb");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100252 if (cmd->hdr.return_code) {
Julian Wiedmann2aa48672017-09-18 21:18:20 +0200253 QETH_DBF_MESSAGE(2, "Error in processing VLAN %i on %s: 0x%x.\n",
254 cmd->data.setdelvlan.vlan_id,
255 QETH_CARD_IFNAME(card), cmd->hdr.return_code);
Carsten Otte847a50f2010-06-21 22:57:05 +0000256 QETH_CARD_TEXT_(card, 2, "L2VL%4x", cmd->hdr.command);
257 QETH_CARD_TEXT_(card, 2, "err%d", cmd->hdr.return_code);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100258 }
259 return 0;
260}
261
262static int qeth_l2_send_setdelvlan(struct qeth_card *card, __u16 i,
Julian Wiedmann2aa48672017-09-18 21:18:20 +0200263 enum qeth_ipa_cmds ipacmd)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100264{
265 struct qeth_ipa_cmd *cmd;
266 struct qeth_cmd_buffer *iob;
267
Carsten Otte847a50f2010-06-21 22:57:05 +0000268 QETH_CARD_TEXT_(card, 4, "L2sdv%x", ipacmd);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100269 iob = qeth_get_ipacmd_buffer(card, ipacmd, QETH_PROT_IPV4);
Thomas Richter1aec42b2015-01-21 13:39:10 +0100270 if (!iob)
271 return -ENOMEM;
Julian Wiedmannff5caa72018-03-09 18:12:52 +0100272 cmd = __ipa_cmd(iob);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100273 cmd->data.setdelvlan.vlan_id = i;
Julian Wiedmann2aa48672017-09-18 21:18:20 +0200274 return qeth_setdelvlan_makerc(card, qeth_send_ipa_cmd(card, iob,
275 qeth_l2_send_setdelvlan_cb, NULL));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100276}
277
Ursula Braun70919e22011-02-26 22:41:36 -0800278static void qeth_l2_process_vlans(struct qeth_card *card)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100279{
280 struct qeth_vlan_vid *id;
Julian Wiedmannd4ac0242018-04-26 09:42:13 +0200281
Carsten Otte847a50f2010-06-21 22:57:05 +0000282 QETH_CARD_TEXT(card, 3, "L2prcvln");
Julian Wiedmannd4ac0242018-04-26 09:42:13 +0200283 mutex_lock(&card->vid_list_mutex);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100284 list_for_each_entry(id, &card->vid_list, list) {
Ursula Braun70919e22011-02-26 22:41:36 -0800285 qeth_l2_send_setdelvlan(card, id->vid, IPA_CMD_SETVLAN);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100286 }
Julian Wiedmannd4ac0242018-04-26 09:42:13 +0200287 mutex_unlock(&card->vid_list_mutex);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100288}
289
Patrick McHardy80d5c362013-04-19 02:04:28 +0000290static int qeth_l2_vlan_rx_add_vid(struct net_device *dev,
291 __be16 proto, u16 vid)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100292{
Heiko Carstens509e2562008-07-26 02:24:10 -0700293 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100294 struct qeth_vlan_vid *id;
Thomas Richter1aec42b2015-01-21 13:39:10 +0100295 int rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100296
Carsten Otte847a50f2010-06-21 22:57:05 +0000297 QETH_CARD_TEXT_(card, 4, "aid:%d", vid);
Ursula Braun10651db2010-10-01 02:51:13 +0000298 if (!vid)
Jiri Pirko8e586132011-12-08 19:52:37 -0500299 return 0;
Ursula Braun8e98ac42009-03-24 20:57:18 +0000300 if (qeth_wait_for_threads(card, QETH_RECOVER_THREAD)) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000301 QETH_CARD_TEXT(card, 3, "aidREC");
Jiri Pirko8e586132011-12-08 19:52:37 -0500302 return 0;
Ursula Braun8e98ac42009-03-24 20:57:18 +0000303 }
Julian Wiedmannd4ac0242018-04-26 09:42:13 +0200304 id = kmalloc(sizeof(*id), GFP_KERNEL);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100305 if (id) {
306 id->vid = vid;
Thomas Richter1aec42b2015-01-21 13:39:10 +0100307 rc = qeth_l2_send_setdelvlan(card, vid, IPA_CMD_SETVLAN);
308 if (rc) {
309 kfree(id);
310 return rc;
311 }
Julian Wiedmannd4ac0242018-04-26 09:42:13 +0200312 mutex_lock(&card->vid_list_mutex);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100313 list_add_tail(&id->list, &card->vid_list);
Julian Wiedmannd4ac0242018-04-26 09:42:13 +0200314 mutex_unlock(&card->vid_list_mutex);
Jiri Pirko8e586132011-12-08 19:52:37 -0500315 } else {
316 return -ENOMEM;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100317 }
Jiri Pirko8e586132011-12-08 19:52:37 -0500318 return 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100319}
320
Patrick McHardy80d5c362013-04-19 02:04:28 +0000321static int qeth_l2_vlan_rx_kill_vid(struct net_device *dev,
322 __be16 proto, u16 vid)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100323{
324 struct qeth_vlan_vid *id, *tmpid = NULL;
Heiko Carstens509e2562008-07-26 02:24:10 -0700325 struct qeth_card *card = dev->ml_priv;
Thomas Richter1aec42b2015-01-21 13:39:10 +0100326 int rc = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100327
Carsten Otte847a50f2010-06-21 22:57:05 +0000328 QETH_CARD_TEXT_(card, 4, "kid:%d", vid);
Ursula Braun8e98ac42009-03-24 20:57:18 +0000329 if (qeth_wait_for_threads(card, QETH_RECOVER_THREAD)) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000330 QETH_CARD_TEXT(card, 3, "kidREC");
Jiri Pirko8e586132011-12-08 19:52:37 -0500331 return 0;
Ursula Braun8e98ac42009-03-24 20:57:18 +0000332 }
Julian Wiedmannd4ac0242018-04-26 09:42:13 +0200333 mutex_lock(&card->vid_list_mutex);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100334 list_for_each_entry(id, &card->vid_list, list) {
335 if (id->vid == vid) {
336 list_del(&id->list);
337 tmpid = id;
338 break;
339 }
340 }
Julian Wiedmannd4ac0242018-04-26 09:42:13 +0200341 mutex_unlock(&card->vid_list_mutex);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100342 if (tmpid) {
Thomas Richter1aec42b2015-01-21 13:39:10 +0100343 rc = qeth_l2_send_setdelvlan(card, vid, IPA_CMD_DELVLAN);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100344 kfree(tmpid);
345 }
Thomas Richter1aec42b2015-01-21 13:39:10 +0100346 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100347}
348
Peter Senna Tschudinb2f4de82015-08-04 17:11:47 +0200349static void qeth_l2_stop_card(struct qeth_card *card, int recovery_mode)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100350{
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200351 QETH_DBF_TEXT(SETUP , 2, "stopcard");
352 QETH_DBF_HEX(SETUP, 2, &card, sizeof(void *));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100353
354 qeth_set_allowed_threads(card, 0, 1);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100355 if (card->read.state == CH_STATE_UP &&
356 card->write.state == CH_STATE_UP &&
357 (card->state == CARD_STATE_UP)) {
358 if (recovery_mode &&
359 card->info.type != QETH_CARD_TYPE_OSN) {
360 qeth_l2_stop(card->dev);
361 } else {
362 rtnl_lock();
363 dev_close(card->dev);
364 rtnl_unlock();
365 }
Ursula Braun70919e22011-02-26 22:41:36 -0800366 card->info.mac_bits &= ~QETH_LAYER2_MAC_REGISTERED;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100367 card->state = CARD_STATE_SOFTSETUP;
368 }
369 if (card->state == CARD_STATE_SOFTSETUP) {
Julian Wiedmannc07cbf22017-01-12 15:48:37 +0100370 qeth_l2_del_all_macs(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100371 qeth_clear_ipacmd_list(card);
372 card->state = CARD_STATE_HARDSETUP;
373 }
374 if (card->state == CARD_STATE_HARDSETUP) {
375 qeth_qdio_clear_card(card, 0);
376 qeth_clear_qdio_buffers(card);
377 qeth_clear_working_pool_list(card);
378 card->state = CARD_STATE_DOWN;
379 }
380 if (card->state == CARD_STATE_DOWN) {
381 qeth_clear_cmd_buffers(&card->read);
382 qeth_clear_cmd_buffers(&card->write);
383 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100384}
385
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000386static int qeth_l2_process_inbound_buffer(struct qeth_card *card,
387 int budget, int *done)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100388{
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000389 int work_done = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100390 struct sk_buff *skb;
391 struct qeth_hdr *hdr;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100392 unsigned int len;
393
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000394 *done = 0;
Stefan Raspl18af5c12012-11-19 02:46:50 +0000395 WARN_ON_ONCE(!budget);
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000396 while (budget) {
397 skb = qeth_core_get_next_skb(card,
Frank Blaschkab3332932011-08-08 01:33:59 +0000398 &card->qdio.in_q->bufs[card->rx.b_index],
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000399 &card->rx.b_element, &card->rx.e_offset, &hdr);
400 if (!skb) {
401 *done = 1;
402 break;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100403 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100404 switch (hdr->hdr.l2.id) {
405 case QETH_HEADER_TYPE_LAYER2:
Frank Blaschka4a71df52008-02-15 09:19:42 +0100406 skb->protocol = eth_type_trans(skb, skb->dev);
Julian Wiedmann6195b932018-04-26 09:42:17 +0200407 qeth_rx_csum(card, skb, hdr->hdr.l2.flags[1]);
Ursula Braun12883722008-04-01 10:26:56 +0200408 if (skb->protocol == htons(ETH_P_802_2))
409 *((__u32 *)skb->cb) = ++card->seqno.pkt_seqno;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100410 len = skb->len;
Thomas Richter9abfa8c2015-10-06 15:12:27 +0200411 napi_gro_receive(&card->napi, skb);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100412 break;
413 case QETH_HEADER_TYPE_OSN:
Ursula Braun2d488c22008-10-24 11:16:55 +0200414 if (card->info.type == QETH_CARD_TYPE_OSN) {
415 skb_push(skb, sizeof(struct qeth_hdr));
416 skb_copy_to_linear_data(skb, hdr,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100417 sizeof(struct qeth_hdr));
Ursula Braun2d488c22008-10-24 11:16:55 +0200418 len = skb->len;
419 card->osn_info.data_cb(skb);
420 break;
421 }
422 /* else unknown */
Frank Blaschka4a71df52008-02-15 09:19:42 +0100423 default:
424 dev_kfree_skb_any(skb);
Carsten Otte847a50f2010-06-21 22:57:05 +0000425 QETH_CARD_TEXT(card, 3, "inbunkno");
Julian Wiedmann0ac14872018-09-12 15:31:35 +0200426 QETH_DBF_HEX(CTRL, 3, hdr, sizeof(*hdr));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100427 continue;
428 }
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000429 work_done++;
430 budget--;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100431 card->stats.rx_packets++;
432 card->stats.rx_bytes += len;
433 }
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000434 return work_done;
435}
436
Frank Blaschka4a71df52008-02-15 09:19:42 +0100437static int qeth_l2_request_initial_mac(struct qeth_card *card)
438{
439 int rc = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100440
Julian Wiedmannec61bd22017-06-20 16:00:34 +0200441 QETH_DBF_TEXT(SETUP, 2, "l2reqmac");
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200442 QETH_DBF_TEXT_(SETUP, 2, "doL2%s", CARD_BUS_ID(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100443
Julian Wiedmannec61bd22017-06-20 16:00:34 +0200444 if (MACHINE_IS_VM) {
445 rc = qeth_vm_request_mac(card);
446 if (!rc)
447 goto out;
448 QETH_DBF_MESSAGE(2, "z/VM MAC Service failed on device %s: x%x\n",
449 CARD_BUS_ID(card), rc);
450 QETH_DBF_TEXT_(SETUP, 2, "err%04x", rc);
451 /* fall back to alternative mechanism: */
452 }
453
Ursula Braun5113fec2010-05-16 21:15:14 +0000454 if (card->info.type == QETH_CARD_TYPE_IQD ||
455 card->info.type == QETH_CARD_TYPE_OSM ||
456 card->info.type == QETH_CARD_TYPE_OSX ||
457 card->info.guestlan) {
Frank Blaschka4a71df52008-02-15 09:19:42 +0100458 rc = qeth_setadpparms_change_macaddr(card);
Julian Wiedmann21b17022018-04-26 09:42:24 +0200459 if (!rc)
460 goto out;
461 QETH_DBF_MESSAGE(2, "READ_MAC Assist failed on device %s: x%x\n",
462 CARD_BUS_ID(card), rc);
463 QETH_DBF_TEXT_(SETUP, 2, "1err%04x", rc);
464 /* fall back once more: */
Frank Blaschka4a71df52008-02-15 09:19:42 +0100465 }
Julian Wiedmann21b17022018-04-26 09:42:24 +0200466
467 /* some devices don't support a custom MAC address: */
468 if (card->info.type == QETH_CARD_TYPE_OSM ||
469 card->info.type == QETH_CARD_TYPE_OSX)
470 return (rc) ? rc : -EADDRNOTAVAIL;
471 eth_hw_addr_random(card->dev);
472
Julian Wiedmannec61bd22017-06-20 16:00:34 +0200473out:
474 QETH_DBF_HEX(SETUP, 2, card->dev->dev_addr, card->dev->addr_len);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100475 return 0;
476}
477
478static int qeth_l2_set_mac_address(struct net_device *dev, void *p)
479{
480 struct sockaddr *addr = p;
Heiko Carstens509e2562008-07-26 02:24:10 -0700481 struct qeth_card *card = dev->ml_priv;
Julian Wiedmannbcacfcb2018-04-19 12:52:09 +0200482 u8 old_addr[ETH_ALEN];
Frank Blaschka4a71df52008-02-15 09:19:42 +0100483 int rc = 0;
484
Carsten Otte847a50f2010-06-21 22:57:05 +0000485 QETH_CARD_TEXT(card, 3, "setmac");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100486
Ursula Braun5113fec2010-05-16 21:15:14 +0000487 if (card->info.type == QETH_CARD_TYPE_OSN ||
488 card->info.type == QETH_CARD_TYPE_OSM ||
489 card->info.type == QETH_CARD_TYPE_OSX) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000490 QETH_CARD_TEXT(card, 3, "setmcTYP");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100491 return -EOPNOTSUPP;
492 }
Julian Wiedmann99f0b852017-12-20 20:11:01 +0100493 QETH_CARD_HEX(card, 3, addr->sa_data, ETH_ALEN);
Julian Wiedmannbcacfcb2018-04-19 12:52:09 +0200494 if (!is_valid_ether_addr(addr->sa_data))
495 return -EADDRNOTAVAIL;
496
Ursula Braun8e98ac42009-03-24 20:57:18 +0000497 if (qeth_wait_for_threads(card, QETH_RECOVER_THREAD)) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000498 QETH_CARD_TEXT(card, 3, "setmcREC");
Ursula Braun8e98ac42009-03-24 20:57:18 +0000499 return -ERESTARTSYS;
500 }
Julian Wiedmannbcacfcb2018-04-19 12:52:09 +0200501
Julian Wiedmann4789a212018-06-29 19:45:51 +0200502 /* avoid racing against concurrent state change: */
503 if (!mutex_trylock(&card->conf_mutex))
504 return -EAGAIN;
505
Julian Wiedmannbcacfcb2018-04-19 12:52:09 +0200506 if (!qeth_card_hw_is_reachable(card)) {
507 ether_addr_copy(dev->dev_addr, addr->sa_data);
Julian Wiedmann4789a212018-06-29 19:45:51 +0200508 goto out_unlock;
Julian Wiedmannbcacfcb2018-04-19 12:52:09 +0200509 }
510
511 /* don't register the same address twice */
512 if (ether_addr_equal_64bits(dev->dev_addr, addr->sa_data) &&
513 (card->info.mac_bits & QETH_LAYER2_MAC_REGISTERED))
Julian Wiedmann4789a212018-06-29 19:45:51 +0200514 goto out_unlock;
Julian Wiedmannbcacfcb2018-04-19 12:52:09 +0200515
516 /* add the new address, switch over, drop the old */
517 rc = qeth_l2_send_setmac(card, addr->sa_data);
518 if (rc)
Julian Wiedmann4789a212018-06-29 19:45:51 +0200519 goto out_unlock;
Julian Wiedmannbcacfcb2018-04-19 12:52:09 +0200520 ether_addr_copy(old_addr, dev->dev_addr);
521 ether_addr_copy(dev->dev_addr, addr->sa_data);
522
523 if (card->info.mac_bits & QETH_LAYER2_MAC_REGISTERED)
524 qeth_l2_remove_mac(card, old_addr);
525 card->info.mac_bits |= QETH_LAYER2_MAC_REGISTERED;
Julian Wiedmann4789a212018-06-29 19:45:51 +0200526
527out_unlock:
528 mutex_unlock(&card->conf_mutex);
529 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100530}
531
Eugene Crosser0db587b2015-05-18 14:27:55 +0200532static void qeth_promisc_to_bridge(struct qeth_card *card)
533{
534 struct net_device *dev = card->dev;
535 enum qeth_ipa_promisc_modes promisc_mode;
536 int role;
537 int rc;
538
539 QETH_CARD_TEXT(card, 3, "pmisc2br");
540
541 if (!card->options.sbp.reflect_promisc)
542 return;
543 promisc_mode = (dev->flags & IFF_PROMISC) ? SET_PROMISC_MODE_ON
544 : SET_PROMISC_MODE_OFF;
545 if (promisc_mode == card->info.promisc_mode)
546 return;
547
548 if (promisc_mode == SET_PROMISC_MODE_ON) {
549 if (card->options.sbp.reflect_promisc_primary)
550 role = QETH_SBP_ROLE_PRIMARY;
551 else
552 role = QETH_SBP_ROLE_SECONDARY;
553 } else
554 role = QETH_SBP_ROLE_NONE;
555
556 rc = qeth_bridgeport_setrole(card, role);
557 QETH_DBF_TEXT_(SETUP, 2, "bpm%c%04x",
558 (promisc_mode == SET_PROMISC_MODE_ON) ? '+' : '-', rc);
559 if (!rc) {
560 card->options.sbp.role = role;
561 card->info.promisc_mode = promisc_mode;
562 }
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200563
564}
565/* New MAC address is added to the hash table and marked to be written on card
566 * only if there is not in the hash table storage already
567 *
568*/
Julian Wiedmann4641b022017-12-20 20:10:59 +0100569static void qeth_l2_add_mac(struct qeth_card *card, struct netdev_hw_addr *ha)
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200570{
Julian Wiedmanncef6ff222017-08-15 17:02:46 +0200571 u32 mac_hash = get_unaligned((u32 *)(&ha->addr[2]));
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200572 struct qeth_mac *mac;
573
Julian Wiedmanncef6ff222017-08-15 17:02:46 +0200574 hash_for_each_possible(card->mac_htable, mac, hnode, mac_hash) {
Julian Wiedmann99f0b852017-12-20 20:11:01 +0100575 if (ether_addr_equal_64bits(ha->addr, mac->mac_addr)) {
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200576 mac->disp_flag = QETH_DISP_ADDR_DO_NOTHING;
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200577 return;
578 }
579 }
580
581 mac = kzalloc(sizeof(struct qeth_mac), GFP_ATOMIC);
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200582 if (!mac)
583 return;
584
Julian Wiedmann99f0b852017-12-20 20:11:01 +0100585 ether_addr_copy(mac->mac_addr, ha->addr);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200586 mac->disp_flag = QETH_DISP_ADDR_ADD;
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200587
Julian Wiedmanncef6ff222017-08-15 17:02:46 +0200588 hash_add(card->mac_htable, &mac->hnode, mac_hash);
Eugene Crosser0db587b2015-05-18 14:27:55 +0200589}
590
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200591static void qeth_l2_set_rx_mode(struct net_device *dev)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100592{
Heiko Carstens509e2562008-07-26 02:24:10 -0700593 struct qeth_card *card = dev->ml_priv;
Jiri Pirkoccffad252009-05-22 23:22:17 +0000594 struct netdev_hw_addr *ha;
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200595 struct qeth_mac *mac;
596 struct hlist_node *tmp;
597 int i;
598 int rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100599
600 if (card->info.type == QETH_CARD_TYPE_OSN)
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200601 return;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100602
Carsten Otte847a50f2010-06-21 22:57:05 +0000603 QETH_CARD_TEXT(card, 3, "setmulti");
Ursula Braun8e98ac42009-03-24 20:57:18 +0000604 if (qeth_threads_running(card, QETH_RECOVER_THREAD) &&
605 (card->state != CARD_STATE_UP))
606 return;
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200607
Frank Blaschka4a71df52008-02-15 09:19:42 +0100608 spin_lock_bh(&card->mclock);
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200609
Jiri Pirko22bedad32010-04-01 21:22:57 +0000610 netdev_for_each_mc_addr(ha, dev)
Julian Wiedmann4641b022017-12-20 20:10:59 +0100611 qeth_l2_add_mac(card, ha);
Jiri Pirko32e7bfc2010-01-25 13:36:10 -0800612 netdev_for_each_uc_addr(ha, dev)
Julian Wiedmann4641b022017-12-20 20:10:59 +0100613 qeth_l2_add_mac(card, ha);
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200614
615 hash_for_each_safe(card->mac_htable, i, tmp, mac, hnode) {
Julian Wiedmann00c163f2017-12-20 20:11:02 +0100616 switch (mac->disp_flag) {
617 case QETH_DISP_ADDR_DELETE:
Julian Wiedmann8174aa82017-12-20 20:11:00 +0100618 qeth_l2_remove_mac(card, mac->mac_addr);
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200619 hash_del(&mac->hnode);
620 kfree(mac);
Julian Wiedmann00c163f2017-12-20 20:11:02 +0100621 break;
622 case QETH_DISP_ADDR_ADD:
Julian Wiedmann8174aa82017-12-20 20:11:00 +0100623 rc = qeth_l2_write_mac(card, mac->mac_addr);
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200624 if (rc) {
625 hash_del(&mac->hnode);
626 kfree(mac);
Julian Wiedmann00c163f2017-12-20 20:11:02 +0100627 break;
628 }
629 /* fall through */
630 default:
631 /* for next call to set_rx_mode(): */
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200632 mac->disp_flag = QETH_DISP_ADDR_DELETE;
Julian Wiedmann00c163f2017-12-20 20:11:02 +0100633 }
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200634 }
Frank Blaschka7db22662008-08-15 08:02:59 +0200635
Frank Blaschka4a71df52008-02-15 09:19:42 +0100636 spin_unlock_bh(&card->mclock);
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200637
Eugene Crosser0db587b2015-05-18 14:27:55 +0200638 if (qeth_adp_supported(card, IPA_SETADP_SET_PROMISC_MODE))
639 qeth_setadp_promisc_mode(card);
640 else
641 qeth_promisc_to_bridge(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100642}
643
Julian Wiedmann5f89eca2018-07-19 12:43:58 +0200644static int qeth_l2_xmit(struct qeth_card *card, struct sk_buff *skb,
645 struct qeth_qdio_out_q *queue, int cast_type, int ipv)
Julian Wiedmann72863842017-08-18 10:19:04 +0200646{
Julian Wiedmann5f89eca2018-07-19 12:43:58 +0200647 const unsigned int proto_len = IS_IQD(card) ? ETH_HLEN : 0;
Julian Wiedmanna7c2f4a2018-07-19 12:43:57 +0200648 const unsigned int hw_hdr_len = sizeof(struct qeth_hdr);
Julian Wiedmann5f89eca2018-07-19 12:43:58 +0200649 unsigned int frame_len = skb->len;
650 unsigned int data_offset = 0;
Julian Wiedmann0d6f02d2017-08-18 10:19:10 +0200651 struct qeth_hdr *hdr = NULL;
652 unsigned int hd_len = 0;
Julian Wiedmannd2a274b2018-07-19 12:43:55 +0200653 unsigned int elements;
Julian Wiedmanna7c2f4a2018-07-19 12:43:57 +0200654 int push_len, rc;
Julian Wiedmannd2a274b2018-07-19 12:43:55 +0200655 bool is_sg;
Julian Wiedmann72863842017-08-18 10:19:04 +0200656
Julian Wiedmanna7c2f4a2018-07-19 12:43:57 +0200657 rc = skb_cow_head(skb, hw_hdr_len);
Julian Wiedmann0d6f02d2017-08-18 10:19:10 +0200658 if (rc)
659 return rc;
Julian Wiedmanna7c2f4a2018-07-19 12:43:57 +0200660
Julian Wiedmann5f89eca2018-07-19 12:43:58 +0200661 push_len = qeth_add_hw_header(card, skb, &hdr, hw_hdr_len, proto_len,
Julian Wiedmanna7c2f4a2018-07-19 12:43:57 +0200662 &elements);
Julian Wiedmann0d6f02d2017-08-18 10:19:10 +0200663 if (push_len < 0)
664 return push_len;
665 if (!push_len) {
Julian Wiedmann5f89eca2018-07-19 12:43:58 +0200666 /* HW header needs its own buffer element. */
667 hd_len = hw_hdr_len + proto_len;
668 data_offset = proto_len;
Julian Wiedmann0d6f02d2017-08-18 10:19:10 +0200669 }
Julian Wiedmann5f89eca2018-07-19 12:43:58 +0200670 qeth_l2_fill_header(hdr, skb, cast_type, frame_len);
Julian Wiedmann6195b932018-04-26 09:42:17 +0200671 if (skb->ip_summed == CHECKSUM_PARTIAL) {
Kittipon Meesompop571f9dd82018-04-26 09:42:22 +0200672 qeth_tx_csum(skb, &hdr->hdr.l2.flags[1], ipv);
Julian Wiedmann6195b932018-04-26 09:42:17 +0200673 if (card->options.performance_stats)
674 card->perf_stats.tx_csum++;
675 }
Julian Wiedmann72863842017-08-18 10:19:04 +0200676
Julian Wiedmannd2a274b2018-07-19 12:43:55 +0200677 is_sg = skb_is_nonlinear(skb);
Julian Wiedmann5f89eca2018-07-19 12:43:58 +0200678 if (IS_IQD(card)) {
679 rc = qeth_do_send_packet_fast(queue, skb, hdr, data_offset,
680 hd_len);
681 } else {
682 /* TODO: drop skb_orphan() once TX completion is fast enough */
683 skb_orphan(skb);
684 rc = qeth_do_send_packet(card, queue, skb, hdr, data_offset,
685 hd_len, elements);
686 }
Julian Wiedmannba86ceee2018-07-19 12:43:56 +0200687
Julian Wiedmann72863842017-08-18 10:19:04 +0200688 if (!rc) {
Julian Wiedmannd2a274b2018-07-19 12:43:55 +0200689 if (card->options.performance_stats) {
690 card->perf_stats.buf_elements_sent += elements;
691 if (is_sg)
692 card->perf_stats.sg_skbs_sent++;
Julian Wiedmann72863842017-08-18 10:19:04 +0200693 }
694 } else {
Julian Wiedmanna7c2f4a2018-07-19 12:43:57 +0200695 if (!push_len)
Julian Wiedmann0d6f02d2017-08-18 10:19:10 +0200696 kmem_cache_free(qeth_core_header_cache, hdr);
697 if (rc == -EBUSY)
698 /* roll back to ETH header */
699 skb_pull(skb, push_len);
Julian Wiedmann72863842017-08-18 10:19:04 +0200700 }
701 return rc;
702}
703
704static int qeth_l2_xmit_osn(struct qeth_card *card, struct sk_buff *skb,
705 struct qeth_qdio_out_q *queue)
706{
707 unsigned int elements;
708 struct qeth_hdr *hdr;
709
710 if (skb->protocol == htons(ETH_P_IPV6))
711 return -EPROTONOSUPPORT;
712
713 hdr = (struct qeth_hdr *)skb->data;
714 elements = qeth_get_elements_no(card, skb, 0, 0);
715 if (!elements)
716 return -E2BIG;
717 if (qeth_hdr_chk_and_bounce(skb, &hdr, sizeof(*hdr)))
718 return -EINVAL;
Julian Wiedmann9c3bfda2017-08-18 10:19:07 +0200719 return qeth_do_send_packet(card, queue, skb, hdr, 0, 0, elements);
Julian Wiedmann72863842017-08-18 10:19:04 +0200720}
721
Julian Wiedmanne38db6b2017-04-11 16:11:14 +0200722static netdev_tx_t qeth_l2_hard_start_xmit(struct sk_buff *skb,
723 struct net_device *dev)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100724{
Heiko Carstens509e2562008-07-26 02:24:10 -0700725 struct qeth_card *card = dev->ml_priv;
Klaus-Dieter Wackerce73e102009-08-26 02:01:08 +0000726 int cast_type = qeth_l2_get_cast_type(card, skb);
Kittipon Meesompop571f9dd82018-04-26 09:42:22 +0200727 int ipv = qeth_get_ip_version(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;
Julian Wiedmann72863842017-08-18 10:19:04 +0200730 int rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100731
Frank Blaschka4a71df52008-02-15 09:19:42 +0100732 if ((card->state != CARD_STATE_UP) || !card->lan_online) {
733 card->stats.tx_carrier_errors++;
734 goto tx_drop;
735 }
736
Julian Wiedmann86c0cdb2018-07-11 17:42:41 +0200737 queue = qeth_get_tx_queue(card, skb, ipv, cast_type);
738
Frank Blaschka4a71df52008-02-15 09:19:42 +0100739 if (card->options.performance_stats) {
740 card->perf_stats.outbound_cnt++;
741 card->perf_stats.outbound_start_time = qeth_get_micros();
742 }
743 netif_stop_queue(dev);
744
Julian Wiedmann5f89eca2018-07-19 12:43:58 +0200745 if (IS_OSN(card))
Julian Wiedmann72863842017-08-18 10:19:04 +0200746 rc = qeth_l2_xmit_osn(card, skb, queue);
Julian Wiedmann5f89eca2018-07-19 12:43:58 +0200747 else
748 rc = qeth_l2_xmit(card, skb, queue, cast_type, ipv);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100749
Frank Blaschka4a71df52008-02-15 09:19:42 +0100750 if (!rc) {
751 card->stats.tx_packets++;
752 card->stats.tx_bytes += tx_bytes;
Julian Wiedmann72863842017-08-18 10:19:04 +0200753 if (card->options.performance_stats)
754 card->perf_stats.outbound_time += qeth_get_micros() -
755 card->perf_stats.outbound_start_time;
756 netif_wake_queue(dev);
757 return NETDEV_TX_OK;
758 } else if (rc == -EBUSY) {
759 return NETDEV_TX_BUSY;
760 } /* else fall through */
Frank Blaschka4a71df52008-02-15 09:19:42 +0100761
762tx_drop:
763 card->stats.tx_dropped++;
764 card->stats.tx_errors++;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100765 dev_kfree_skb_any(skb);
Frank Blaschkad0ec0f52008-06-06 12:37:48 +0200766 netif_wake_queue(dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100767 return NETDEV_TX_OK;
768}
769
Ursula Braun39423442011-01-12 20:42:24 +0000770static int __qeth_l2_open(struct net_device *dev)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100771{
Heiko Carstens509e2562008-07-26 02:24:10 -0700772 struct qeth_card *card = dev->ml_priv;
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000773 int rc = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100774
Carsten Otte847a50f2010-06-21 22:57:05 +0000775 QETH_CARD_TEXT(card, 4, "qethopen");
Ursula Braun39423442011-01-12 20:42:24 +0000776 if (card->state == CARD_STATE_UP)
777 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100778 if (card->state != CARD_STATE_SOFTSETUP)
779 return -ENODEV;
780
781 if ((card->info.type != QETH_CARD_TYPE_OSN) &&
782 (!(card->info.mac_bits & QETH_LAYER2_MAC_REGISTERED))) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000783 QETH_CARD_TEXT(card, 4, "nomacadr");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100784 return -EPERM;
785 }
786 card->data.state = CH_STATE_UP;
787 card->state = CARD_STATE_UP;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100788 netif_start_queue(dev);
789
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000790 if (qdio_stop_irq(card->data.ccwdev, 0) >= 0) {
791 napi_enable(&card->napi);
792 napi_schedule(&card->napi);
793 } else
794 rc = -EIO;
795 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100796}
797
Ursula Braun39423442011-01-12 20:42:24 +0000798static int qeth_l2_open(struct net_device *dev)
799{
800 struct qeth_card *card = dev->ml_priv;
801
802 QETH_CARD_TEXT(card, 5, "qethope_");
803 if (qeth_wait_for_threads(card, QETH_RECOVER_THREAD)) {
804 QETH_CARD_TEXT(card, 3, "openREC");
805 return -ERESTARTSYS;
806 }
807 return __qeth_l2_open(dev);
808}
809
Frank Blaschka4a71df52008-02-15 09:19:42 +0100810static int qeth_l2_stop(struct net_device *dev)
811{
Heiko Carstens509e2562008-07-26 02:24:10 -0700812 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100813
Carsten Otte847a50f2010-06-21 22:57:05 +0000814 QETH_CARD_TEXT(card, 4, "qethstop");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100815 netif_tx_disable(dev);
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000816 if (card->state == CARD_STATE_UP) {
Frank Blaschka4a71df52008-02-15 09:19:42 +0100817 card->state = CARD_STATE_SOFTSETUP;
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000818 napi_disable(&card->napi);
819 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100820 return 0;
821}
822
Julian Wiedmann2d2ebb32017-05-10 19:07:52 +0200823static const struct device_type qeth_l2_devtype = {
824 .name = "qeth_layer2",
825 .groups = qeth_l2_attr_groups,
826};
827
Frank Blaschka4a71df52008-02-15 09:19:42 +0100828static int qeth_l2_probe_device(struct ccwgroup_device *gdev)
829{
830 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
Ursula Braun9111e782017-05-10 19:07:51 +0200831 int rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100832
Julian Wiedmann2d2ebb32017-05-10 19:07:52 +0200833 if (gdev->dev.type == &qeth_generic_devtype) {
834 rc = qeth_l2_create_device_attributes(&gdev->dev);
835 if (rc)
836 return rc;
837 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100838 INIT_LIST_HEAD(&card->vid_list);
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200839 hash_init(card->mac_htable);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100840 card->options.layer2 = 1;
Frank Blaschka1da74b12011-05-12 18:45:02 +0000841 card->info.hwtrap = 0;
Hans Wippelcaa1f0b2017-09-18 21:18:15 +0200842 qeth_l2_vnicc_set_defaults(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100843 return 0;
844}
845
846static void qeth_l2_remove_device(struct ccwgroup_device *cgdev)
847{
848 struct qeth_card *card = dev_get_drvdata(&cgdev->dev);
849
Julian Wiedmann2d2ebb32017-05-10 19:07:52 +0200850 if (cgdev->dev.type == &qeth_generic_devtype)
851 qeth_l2_remove_device_attributes(&cgdev->dev);
Ursula Braunf2148562009-05-19 21:38:37 +0000852 qeth_set_allowed_threads(card, 0, 1);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100853 wait_event(card->wait_q, qeth_threads_running(card, 0xffffffff) == 0);
854
Ursula Braun70919e22011-02-26 22:41:36 -0800855 if (cgdev->state == CCWGROUP_ONLINE)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100856 qeth_l2_set_offline(cgdev);
Julian Wiedmannd3d1b202018-07-19 12:43:51 +0200857 unregister_netdev(card->dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100858}
859
Stephen Hemminger0fc0b732009-09-02 01:03:33 -0700860static const struct ethtool_ops qeth_l2_ethtool_ops = {
Frank Blaschka4a71df52008-02-15 09:19:42 +0100861 .get_link = ethtool_op_get_link,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100862 .get_strings = qeth_core_get_strings,
863 .get_ethtool_stats = qeth_core_get_ethtool_stats,
Ben Hutchingsdf8b4ec2009-10-01 11:24:32 +0000864 .get_sset_count = qeth_core_get_sset_count,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100865 .get_drvinfo = qeth_core_get_drvinfo,
Julian Wiedmann993e19c2017-04-11 16:11:17 +0200866 .get_link_ksettings = qeth_core_ethtool_get_link_ksettings,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100867};
868
Stephen Hemminger0fc0b732009-09-02 01:03:33 -0700869static const struct ethtool_ops qeth_l2_osn_ops = {
Frank Blaschka4a71df52008-02-15 09:19:42 +0100870 .get_strings = qeth_core_get_strings,
871 .get_ethtool_stats = qeth_core_get_ethtool_stats,
Ben Hutchingsdf8b4ec2009-10-01 11:24:32 +0000872 .get_sset_count = qeth_core_get_sset_count,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100873 .get_drvinfo = qeth_core_get_drvinfo,
874};
875
Frank Blaschka3d58cef2009-01-09 03:44:00 +0000876static const struct net_device_ops qeth_l2_netdev_ops = {
Frank Blaschka8403b132009-01-08 10:50:55 -0800877 .ndo_open = qeth_l2_open,
878 .ndo_stop = qeth_l2_stop,
879 .ndo_get_stats = qeth_get_stats,
880 .ndo_start_xmit = qeth_l2_hard_start_xmit,
Julian Wiedmann6d69b1f2017-12-01 10:14:50 +0100881 .ndo_features_check = qeth_features_check,
Frank Blaschka8403b132009-01-08 10:50:55 -0800882 .ndo_validate_addr = eth_validate_addr,
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200883 .ndo_set_rx_mode = qeth_l2_set_rx_mode,
Julian Wiedmann942d6982017-04-11 16:11:10 +0200884 .ndo_do_ioctl = qeth_do_ioctl,
Frank Blaschka8403b132009-01-08 10:50:55 -0800885 .ndo_set_mac_address = qeth_l2_set_mac_address,
Frank Blaschka8403b132009-01-08 10:50:55 -0800886 .ndo_vlan_rx_add_vid = qeth_l2_vlan_rx_add_vid,
887 .ndo_vlan_rx_kill_vid = qeth_l2_vlan_rx_kill_vid,
888 .ndo_tx_timeout = qeth_tx_timeout,
Thomas Richter8f43fb02016-06-16 16:18:59 +0200889 .ndo_fix_features = qeth_fix_features,
890 .ndo_set_features = qeth_set_features
Frank Blaschka8403b132009-01-08 10:50:55 -0800891};
892
Frank Blaschka4a71df52008-02-15 09:19:42 +0100893static int qeth_l2_setup_netdev(struct qeth_card *card)
894{
Julian Wiedmannd3d1b202018-07-19 12:43:51 +0200895 int rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100896
Julian Wiedmannd3d1b202018-07-19 12:43:51 +0200897 if (card->dev->netdev_ops)
898 return 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100899
Julian Wiedmannd3aacac2018-03-09 18:12:55 +0100900 card->dev->priv_flags |= IFF_UNICAST_FLT;
Frank Blaschka8403b132009-01-08 10:50:55 -0800901 card->dev->netdev_ops = &qeth_l2_netdev_ops;
Julian Wiedmann25e2c342017-05-10 19:07:53 +0200902 if (card->info.type == QETH_CARD_TYPE_OSN) {
903 card->dev->ethtool_ops = &qeth_l2_osn_ops;
904 card->dev->flags |= IFF_NOARP;
905 } else {
906 card->dev->ethtool_ops = &qeth_l2_ethtool_ops;
Julian Wiedmann5f89eca2018-07-19 12:43:58 +0200907 card->dev->needed_headroom = sizeof(struct qeth_hdr);
Julian Wiedmann25e2c342017-05-10 19:07:53 +0200908 }
Julian Wiedmann9400c532017-10-18 17:40:20 +0200909
910 if (card->info.type == QETH_CARD_TYPE_OSM)
911 card->dev->features |= NETIF_F_VLAN_CHALLENGED;
912 else
913 card->dev->features |= NETIF_F_HW_VLAN_CTAG_FILTER;
Julian Wiedmann0f342942018-03-09 18:12:54 +0100914
Thomas Richter4d7def22015-09-18 16:06:51 +0200915 if (card->info.type == QETH_CARD_TYPE_OSD && !card->info.guestlan) {
Julian Wiedmann6d69b1f2017-12-01 10:14:50 +0100916 card->dev->features |= NETIF_F_SG;
Thomas Richter8f43fb02016-06-16 16:18:59 +0200917 /* OSA 3S and earlier has no RX/TX support */
Hans Wippel9bdc4412016-06-16 16:19:00 +0200918 if (qeth_is_supported(card, IPA_OUTBOUND_CHECKSUM)) {
Thomas Richter8f43fb02016-06-16 16:18:59 +0200919 card->dev->hw_features |= NETIF_F_IP_CSUM;
Hans Wippel9bdc4412016-06-16 16:19:00 +0200920 card->dev->vlan_features |= NETIF_F_IP_CSUM;
921 }
Thomas Richter4d7def22015-09-18 16:06:51 +0200922 }
Kittipon Meesompop571f9dd82018-04-26 09:42:22 +0200923 if (qeth_is_supported6(card, IPA_OUTBOUND_CHECKSUM_V6)) {
924 card->dev->hw_features |= NETIF_F_IPV6_CSUM;
925 card->dev->vlan_features |= NETIF_F_IPV6_CSUM;
926 }
Kittipon Meesompopd7e6ed92018-04-26 09:42:23 +0200927 if (qeth_is_supported(card, IPA_INBOUND_CHECKSUM) ||
928 qeth_is_supported6(card, IPA_INBOUND_CHECKSUM_V6)) {
929 card->dev->hw_features |= NETIF_F_RXCSUM;
930 card->dev->vlan_features |= NETIF_F_RXCSUM;
931 }
Julian Wiedmann0d6f02d2017-08-18 10:19:10 +0200932
Frank Blaschka4a71df52008-02-15 09:19:42 +0100933 qeth_l2_request_initial_mac(card);
Julian Wiedmannd73ef322017-04-11 16:11:11 +0200934 netif_napi_add(card->dev, &card->napi, qeth_poll, QETH_NAPI_WEIGHT);
Julian Wiedmannd3d1b202018-07-19 12:43:51 +0200935 rc = register_netdev(card->dev);
936 if (rc)
937 card->dev->netdev_ops = NULL;
938 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100939}
940
Thomas Richter4d7def22015-09-18 16:06:51 +0200941static int qeth_l2_start_ipassists(struct qeth_card *card)
942{
943 /* configure isolation level */
944 if (qeth_set_access_ctrl_online(card, 0))
945 return -ENODEV;
Thomas Richter4d7def22015-09-18 16:06:51 +0200946 return 0;
947}
948
Julian Wiedmann521c10e2017-06-06 14:33:45 +0200949static void qeth_l2_trace_features(struct qeth_card *card)
950{
Hans Wippela45b3fa2017-09-18 21:18:14 +0200951 /* Set BridgePort features */
952 QETH_CARD_TEXT(card, 2, "featuSBP");
Julian Wiedmann521c10e2017-06-06 14:33:45 +0200953 QETH_CARD_HEX(card, 2, &card->options.sbp.supported_funcs,
954 sizeof(card->options.sbp.supported_funcs));
Hans Wippela45b3fa2017-09-18 21:18:14 +0200955 /* VNIC Characteristics features */
956 QETH_CARD_TEXT(card, 2, "feaVNICC");
957 QETH_CARD_HEX(card, 2, &card->options.vnicc.sup_chars,
958 sizeof(card->options.vnicc.sup_chars));
Julian Wiedmann521c10e2017-06-06 14:33:45 +0200959}
960
Frank Blaschka4a71df52008-02-15 09:19:42 +0100961static int __qeth_l2_set_online(struct ccwgroup_device *gdev, int recovery_mode)
962{
963 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
964 int rc = 0;
965 enum qeth_card_states recover_flag;
966
Ursula Braun9dc48cc2010-07-22 23:15:05 +0000967 mutex_lock(&card->discipline_mutex);
Frank Blaschkac4949f02010-05-11 19:34:47 +0000968 mutex_lock(&card->conf_mutex);
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200969 QETH_DBF_TEXT(SETUP, 2, "setonlin");
970 QETH_DBF_HEX(SETUP, 2, &card, sizeof(void *));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100971
Frank Blaschka4a71df52008-02-15 09:19:42 +0100972 recover_flag = card->state;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100973 rc = qeth_core_hardsetup_card(card);
974 if (rc) {
Thomas Richter1aec42b2015-01-21 13:39:10 +0100975 QETH_DBF_TEXT_(SETUP, 2, "2err%04x", rc);
Ursula Braunaa909222009-11-12 00:11:43 +0000976 rc = -ENODEV;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100977 goto out_remove;
978 }
Eugene Crosserc044dc22014-01-29 09:23:48 +0100979 qeth_bridgeport_query_support(card);
980 if (card->options.sbp.supported_funcs)
981 dev_info(&card->gdev->dev,
Eugene Crosser9c23f4da2015-05-18 14:27:56 +0200982 "The device represents a Bridge Capable Port\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100983
Julian Wiedmannd3d1b202018-07-19 12:43:51 +0200984 rc = qeth_l2_setup_netdev(card);
985 if (rc)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100986 goto out_remove;
987
Julian Wiedmannbcacfcb2018-04-19 12:52:09 +0200988 if (card->info.type != QETH_CARD_TYPE_OSN &&
989 !qeth_l2_send_setmac(card, card->dev->dev_addr))
990 card->info.mac_bits |= QETH_LAYER2_MAC_REGISTERED;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100991
Frank Blaschka1da74b12011-05-12 18:45:02 +0000992 if (qeth_is_diagass_supported(card, QETH_DIAGS_CMD_TRAP)) {
993 if (card->info.hwtrap &&
994 qeth_hw_trap(card, QETH_DIAGS_TRAP_ARM))
995 card->info.hwtrap = 0;
996 } else
997 card->info.hwtrap = 0;
998
Hans Wippela45b3fa2017-09-18 21:18:14 +0200999 /* for the rx_bcast characteristic, init VNICC after setmac */
1000 qeth_l2_vnicc_init(card);
1001
1002 qeth_trace_features(card);
1003 qeth_l2_trace_features(card);
1004
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001005 qeth_l2_setup_bridgeport_attrs(card);
1006
Frank Blaschka4a71df52008-02-15 09:19:42 +01001007 card->state = CARD_STATE_HARDSETUP;
1008 qeth_print_status_message(card);
1009
1010 /* softsetup */
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001011 QETH_DBF_TEXT(SETUP, 2, "softsetp");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001012
Ursula Braun5113fec2010-05-16 21:15:14 +00001013 if ((card->info.type == QETH_CARD_TYPE_OSD) ||
Stefan Raspl0f547612013-01-21 02:30:20 +00001014 (card->info.type == QETH_CARD_TYPE_OSX)) {
Thomas Richter8f43fb02016-06-16 16:18:59 +02001015 rc = qeth_l2_start_ipassists(card);
1016 if (rc)
Stefan Raspl0f547612013-01-21 02:30:20 +00001017 goto out_remove;
Stefan Raspl0f547612013-01-21 02:30:20 +00001018 }
Ursula Braun5113fec2010-05-16 21:15:14 +00001019
Julian Wiedmann9400c532017-10-18 17:40:20 +02001020 if (card->info.type != QETH_CARD_TYPE_OSN)
Ursula Braun70919e22011-02-26 22:41:36 -08001021 qeth_l2_process_vlans(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001022
1023 netif_tx_disable(card->dev);
1024
1025 rc = qeth_init_qdio_queues(card);
1026 if (rc) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001027 QETH_DBF_TEXT_(SETUP, 2, "6err%d", rc);
Ursula Braunaa909222009-11-12 00:11:43 +00001028 rc = -ENODEV;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001029 goto out_remove;
1030 }
1031 card->state = CARD_STATE_SOFTSETUP;
Ursula Braun2b6203b2010-11-26 02:41:19 +00001032 if (card->lan_online)
1033 netif_carrier_on(card->dev);
1034 else
1035 netif_carrier_off(card->dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001036
1037 qeth_set_allowed_threads(card, 0xffffffff, 0);
Julian Wiedmannd025da92018-06-29 19:45:54 +02001038
1039 qeth_enable_hw_features(card->dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001040 if (recover_flag == CARD_STATE_RECOVER) {
1041 if (recovery_mode &&
1042 card->info.type != QETH_CARD_TYPE_OSN) {
Ursula Braun39423442011-01-12 20:42:24 +00001043 __qeth_l2_open(card->dev);
Julian Wiedmann9aa17df2018-07-11 17:42:40 +02001044 qeth_l2_set_rx_mode(card->dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001045 } else {
1046 rtnl_lock();
1047 dev_open(card->dev);
1048 rtnl_unlock();
1049 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01001050 }
1051 /* let user_space know that device is online */
1052 kobject_uevent(&gdev->dev.kobj, KOBJ_CHANGE);
Frank Blaschkac4949f02010-05-11 19:34:47 +00001053 mutex_unlock(&card->conf_mutex);
Ursula Braun9dc48cc2010-07-22 23:15:05 +00001054 mutex_unlock(&card->discipline_mutex);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001055 return 0;
Ursula Braunaa909222009-11-12 00:11:43 +00001056
Frank Blaschka4a71df52008-02-15 09:19:42 +01001057out_remove:
Frank Blaschka4a71df52008-02-15 09:19:42 +01001058 qeth_l2_stop_card(card, 0);
1059 ccw_device_set_offline(CARD_DDEV(card));
1060 ccw_device_set_offline(CARD_WDEV(card));
1061 ccw_device_set_offline(CARD_RDEV(card));
Ursula Braun22ae2792014-02-24 13:12:06 +01001062 qdio_free(CARD_DDEV(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001063 if (recover_flag == CARD_STATE_RECOVER)
1064 card->state = CARD_STATE_RECOVER;
1065 else
1066 card->state = CARD_STATE_DOWN;
Frank Blaschkac4949f02010-05-11 19:34:47 +00001067 mutex_unlock(&card->conf_mutex);
Ursula Braun9dc48cc2010-07-22 23:15:05 +00001068 mutex_unlock(&card->discipline_mutex);
Ursula Braunaa909222009-11-12 00:11:43 +00001069 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001070}
1071
1072static int qeth_l2_set_online(struct ccwgroup_device *gdev)
1073{
1074 return __qeth_l2_set_online(gdev, 0);
1075}
1076
1077static int __qeth_l2_set_offline(struct ccwgroup_device *cgdev,
1078 int recovery_mode)
1079{
1080 struct qeth_card *card = dev_get_drvdata(&cgdev->dev);
1081 int rc = 0, rc2 = 0, rc3 = 0;
1082 enum qeth_card_states recover_flag;
1083
Ursula Braun9dc48cc2010-07-22 23:15:05 +00001084 mutex_lock(&card->discipline_mutex);
Frank Blaschkac4949f02010-05-11 19:34:47 +00001085 mutex_lock(&card->conf_mutex);
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001086 QETH_DBF_TEXT(SETUP, 3, "setoffl");
1087 QETH_DBF_HEX(SETUP, 3, &card, sizeof(void *));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001088
Julian Wiedmannd3d1b202018-07-19 12:43:51 +02001089 netif_carrier_off(card->dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001090 recover_flag = card->state;
Frank Blaschka1da74b12011-05-12 18:45:02 +00001091 if ((!recovery_mode && card->info.hwtrap) || card->info.hwtrap == 2) {
1092 qeth_hw_trap(card, QETH_DIAGS_TRAP_DISARM);
1093 card->info.hwtrap = 1;
1094 }
Ursula Braun0f5623c2008-10-24 11:16:52 +02001095 qeth_l2_stop_card(card, recovery_mode);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001096 rc = ccw_device_set_offline(CARD_DDEV(card));
1097 rc2 = ccw_device_set_offline(CARD_WDEV(card));
1098 rc3 = ccw_device_set_offline(CARD_RDEV(card));
1099 if (!rc)
1100 rc = (rc2) ? rc2 : rc3;
1101 if (rc)
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001102 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
Ursula Braun22ae2792014-02-24 13:12:06 +01001103 qdio_free(CARD_DDEV(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001104 if (recover_flag == CARD_STATE_UP)
1105 card->state = CARD_STATE_RECOVER;
1106 /* let user_space know that device is offline */
1107 kobject_uevent(&cgdev->dev.kobj, KOBJ_CHANGE);
Frank Blaschkac4949f02010-05-11 19:34:47 +00001108 mutex_unlock(&card->conf_mutex);
Ursula Braun9dc48cc2010-07-22 23:15:05 +00001109 mutex_unlock(&card->discipline_mutex);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001110 return 0;
1111}
1112
1113static int qeth_l2_set_offline(struct ccwgroup_device *cgdev)
1114{
1115 return __qeth_l2_set_offline(cgdev, 0);
1116}
1117
1118static int qeth_l2_recover(void *ptr)
1119{
1120 struct qeth_card *card;
1121 int rc = 0;
1122
1123 card = (struct qeth_card *) ptr;
Carsten Otte847a50f2010-06-21 22:57:05 +00001124 QETH_CARD_TEXT(card, 2, "recover1");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001125 if (!qeth_do_run_thread(card, QETH_RECOVER_THREAD))
1126 return 0;
Carsten Otte847a50f2010-06-21 22:57:05 +00001127 QETH_CARD_TEXT(card, 2, "recover2");
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001128 dev_warn(&card->gdev->dev,
1129 "A recovery process has been started for the device\n");
Stefan Raspl65d80132013-04-07 22:19:27 +00001130 qeth_set_recovery_task(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001131 __qeth_l2_set_offline(card->gdev, 1);
1132 rc = __qeth_l2_set_online(card->gdev, 1);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001133 if (!rc)
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001134 dev_info(&card->gdev->dev,
1135 "Device successfully recovered!\n");
Ursula Braun28a7e4c2008-09-19 12:56:03 +02001136 else {
Stefan Raspl0f547612013-01-21 02:30:20 +00001137 qeth_close_dev(card);
1138 dev_warn(&card->gdev->dev, "The qeth device driver "
Stefan Raspl2efaf5f2012-10-15 19:21:18 +00001139 "failed to recover an error on the device\n");
Ursula Braun28a7e4c2008-09-19 12:56:03 +02001140 }
Stefan Raspl65d80132013-04-07 22:19:27 +00001141 qeth_clear_recovery_task(card);
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00001142 qeth_clear_thread_start_bit(card, QETH_RECOVER_THREAD);
1143 qeth_clear_thread_running_bit(card, QETH_RECOVER_THREAD);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001144 return 0;
1145}
1146
1147static int __init qeth_l2_init(void)
1148{
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001149 pr_info("register layer 2 discipline\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001150 return 0;
1151}
1152
1153static void __exit qeth_l2_exit(void)
1154{
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001155 pr_info("unregister layer 2 discipline\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001156}
1157
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02001158static int qeth_l2_pm_suspend(struct ccwgroup_device *gdev)
1159{
1160 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
1161
Julian Wiedmannd3d1b202018-07-19 12:43:51 +02001162 netif_device_detach(card->dev);
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02001163 qeth_set_allowed_threads(card, 0, 1);
1164 wait_event(card->wait_q, qeth_threads_running(card, 0xffffffff) == 0);
1165 if (gdev->state == CCWGROUP_OFFLINE)
1166 return 0;
1167 if (card->state == CARD_STATE_UP) {
Frank Blaschka1da74b12011-05-12 18:45:02 +00001168 if (card->info.hwtrap)
1169 qeth_hw_trap(card, QETH_DIAGS_TRAP_DISARM);
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02001170 __qeth_l2_set_offline(card->gdev, 1);
1171 } else
1172 __qeth_l2_set_offline(card->gdev, 0);
1173 return 0;
1174}
1175
1176static int qeth_l2_pm_resume(struct ccwgroup_device *gdev)
1177{
1178 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
1179 int rc = 0;
1180
1181 if (gdev->state == CCWGROUP_OFFLINE)
1182 goto out;
1183
1184 if (card->state == CARD_STATE_RECOVER) {
1185 rc = __qeth_l2_set_online(card->gdev, 1);
1186 if (rc) {
Ursula Braun869da902010-03-08 20:36:56 +00001187 rtnl_lock();
1188 dev_close(card->dev);
1189 rtnl_unlock();
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02001190 }
1191 } else
1192 rc = __qeth_l2_set_online(card->gdev, 0);
1193out:
1194 qeth_set_allowed_threads(card, 0xffffffff, 0);
Julian Wiedmannd3d1b202018-07-19 12:43:51 +02001195 netif_device_attach(card->dev);
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02001196 if (rc)
1197 dev_warn(&card->gdev->dev, "The qeth device driver "
1198 "failed to recover an error on the device\n");
1199 return rc;
1200}
1201
Eugene Crosserc044dc22014-01-29 09:23:48 +01001202/* Returns zero if the command is successfully "consumed" */
1203static int qeth_l2_control_event(struct qeth_card *card,
1204 struct qeth_ipa_cmd *cmd)
1205{
1206 switch (cmd->hdr.command) {
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001207 case IPA_CMD_SETBRIDGEPORT_OSA:
1208 case IPA_CMD_SETBRIDGEPORT_IQD:
Eugene Crosserc044dc22014-01-29 09:23:48 +01001209 if (cmd->data.sbp.hdr.command_code ==
1210 IPA_SBP_BRIDGE_PORT_STATE_CHANGE) {
1211 qeth_bridge_state_change(card, cmd);
1212 return 0;
1213 } else
1214 return 1;
1215 case IPA_CMD_ADDRESS_CHANGE_NOTIF:
1216 qeth_bridge_host_event(card, cmd);
1217 return 0;
1218 default:
1219 return 1;
1220 }
1221}
1222
Sebastian Ottc041f2d4872012-05-15 18:02:21 +02001223struct qeth_discipline qeth_l2_discipline = {
Julian Wiedmann2d2ebb32017-05-10 19:07:52 +02001224 .devtype = &qeth_l2_devtype,
Julian Wiedmannd73ef322017-04-11 16:11:11 +02001225 .process_rx_buffer = qeth_l2_process_inbound_buffer,
Sebastian Ottc041f2d4872012-05-15 18:02:21 +02001226 .recover = qeth_l2_recover,
1227 .setup = qeth_l2_probe_device,
Frank Blaschka4a71df52008-02-15 09:19:42 +01001228 .remove = qeth_l2_remove_device,
1229 .set_online = qeth_l2_set_online,
1230 .set_offline = qeth_l2_set_offline,
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02001231 .freeze = qeth_l2_pm_suspend,
1232 .thaw = qeth_l2_pm_resume,
1233 .restore = qeth_l2_pm_resume,
Julian Wiedmann942d6982017-04-11 16:11:10 +02001234 .do_ioctl = NULL,
Eugene Crosserc044dc22014-01-29 09:23:48 +01001235 .control_event_handler = qeth_l2_control_event,
Frank Blaschka4a71df52008-02-15 09:19:42 +01001236};
Sebastian Ottc041f2d4872012-05-15 18:02:21 +02001237EXPORT_SYMBOL_GPL(qeth_l2_discipline);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001238
1239static int qeth_osn_send_control_data(struct qeth_card *card, int len,
1240 struct qeth_cmd_buffer *iob)
1241{
Julian Wiedmann750b1622018-08-09 14:47:59 +02001242 struct qeth_channel *channel = iob->channel;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001243 unsigned long flags;
1244 int rc = 0;
1245
Carsten Otte847a50f2010-06-21 22:57:05 +00001246 QETH_CARD_TEXT(card, 5, "osndctrd");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001247
1248 wait_event(card->wait_q,
Julian Wiedmann750b1622018-08-09 14:47:59 +02001249 atomic_cmpxchg(&channel->irq_pending, 0, 1) == 0);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001250 qeth_prepare_control_data(card, len, iob);
Carsten Otte847a50f2010-06-21 22:57:05 +00001251 QETH_CARD_TEXT(card, 6, "osnoirqp");
Julian Wiedmann750b1622018-08-09 14:47:59 +02001252 spin_lock_irqsave(get_ccwdev_lock(channel->ccwdev), flags);
Julian Wiedmannf15cdaf2018-08-09 14:48:03 +02001253 rc = ccw_device_start_timeout(channel->ccwdev, channel->ccw,
Julian Wiedmanndb71bbb2018-04-19 12:52:10 +02001254 (addr_t) iob, 0, 0, QETH_IPA_TIMEOUT);
Julian Wiedmann750b1622018-08-09 14:47:59 +02001255 spin_unlock_irqrestore(get_ccwdev_lock(channel->ccwdev), flags);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001256 if (rc) {
Frank Blaschka14cc21b2008-06-06 12:37:46 +02001257 QETH_DBF_MESSAGE(2, "qeth_osn_send_control_data: "
Frank Blaschka4a71df52008-02-15 09:19:42 +01001258 "ccw_device_start rc = %i\n", rc);
Carsten Otte847a50f2010-06-21 22:57:05 +00001259 QETH_CARD_TEXT_(card, 2, " err%d", rc);
Julian Wiedmann750b1622018-08-09 14:47:59 +02001260 qeth_release_buffer(channel, iob);
1261 atomic_set(&channel->irq_pending, 0);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001262 wake_up(&card->wait_q);
1263 }
1264 return rc;
1265}
1266
1267static int qeth_osn_send_ipa_cmd(struct qeth_card *card,
1268 struct qeth_cmd_buffer *iob, int data_len)
1269{
1270 u16 s1, s2;
1271
Carsten Otte847a50f2010-06-21 22:57:05 +00001272 QETH_CARD_TEXT(card, 4, "osndipa");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001273
Julian Wiedmann73657a32018-08-09 14:47:58 +02001274 qeth_prepare_ipa_cmd(card, iob);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001275 s1 = (u16)(IPA_PDU_HEADER_SIZE + data_len);
1276 s2 = (u16)data_len;
1277 memcpy(QETH_IPA_PDU_LEN_TOTAL(iob->data), &s1, 2);
1278 memcpy(QETH_IPA_PDU_LEN_PDU1(iob->data), &s2, 2);
1279 memcpy(QETH_IPA_PDU_LEN_PDU2(iob->data), &s2, 2);
1280 memcpy(QETH_IPA_PDU_LEN_PDU3(iob->data), &s2, 2);
1281 return qeth_osn_send_control_data(card, s1, iob);
1282}
1283
1284int qeth_osn_assist(struct net_device *dev, void *data, int data_len)
1285{
1286 struct qeth_cmd_buffer *iob;
1287 struct qeth_card *card;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001288
Frank Blaschka4a71df52008-02-15 09:19:42 +01001289 if (!dev)
1290 return -ENODEV;
Heiko Carstens509e2562008-07-26 02:24:10 -07001291 card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001292 if (!card)
1293 return -ENODEV;
Carsten Otte847a50f2010-06-21 22:57:05 +00001294 QETH_CARD_TEXT(card, 2, "osnsdmc");
Eugene Crosserc3521252015-01-16 14:05:47 +01001295 if (!qeth_card_hw_is_reachable(card))
Frank Blaschka4a71df52008-02-15 09:19:42 +01001296 return -ENODEV;
1297 iob = qeth_wait_for_buffer(&card->write);
Julian Wiedmannff5caa72018-03-09 18:12:52 +01001298 memcpy(__ipa_cmd(iob), data, data_len);
1299 return qeth_osn_send_ipa_cmd(card, iob, data_len);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001300}
1301EXPORT_SYMBOL(qeth_osn_assist);
1302
1303int qeth_osn_register(unsigned char *read_dev_no, struct net_device **dev,
1304 int (*assist_cb)(struct net_device *, void *),
1305 int (*data_cb)(struct sk_buff *))
1306{
1307 struct qeth_card *card;
1308
Frank Blaschka4a71df52008-02-15 09:19:42 +01001309 *dev = qeth_l2_netdev_by_devno(read_dev_no);
1310 if (*dev == NULL)
1311 return -ENODEV;
Heiko Carstens509e2562008-07-26 02:24:10 -07001312 card = (*dev)->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001313 if (!card)
1314 return -ENODEV;
Carsten Otte847a50f2010-06-21 22:57:05 +00001315 QETH_CARD_TEXT(card, 2, "osnreg");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001316 if ((assist_cb == NULL) || (data_cb == NULL))
1317 return -EINVAL;
1318 card->osn_info.assist_cb = assist_cb;
1319 card->osn_info.data_cb = data_cb;
1320 return 0;
1321}
1322EXPORT_SYMBOL(qeth_osn_register);
1323
1324void qeth_osn_deregister(struct net_device *dev)
1325{
1326 struct qeth_card *card;
1327
Frank Blaschka4a71df52008-02-15 09:19:42 +01001328 if (!dev)
1329 return;
Heiko Carstens509e2562008-07-26 02:24:10 -07001330 card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001331 if (!card)
1332 return;
Carsten Otte847a50f2010-06-21 22:57:05 +00001333 QETH_CARD_TEXT(card, 2, "osndereg");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001334 card->osn_info.assist_cb = NULL;
1335 card->osn_info.data_cb = NULL;
1336 return;
1337}
1338EXPORT_SYMBOL(qeth_osn_deregister);
1339
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001340/* SETBRIDGEPORT support, async notifications */
1341
Eugene Crosser9f48b9d2014-01-14 15:54:13 +01001342enum qeth_an_event_type {anev_reg_unreg, anev_abort, anev_reset};
1343
1344/**
1345 * qeth_bridge_emit_host_event() - bridgeport address change notification
1346 * @card: qeth_card structure pointer, for udev events.
1347 * @evtype: "normal" register/unregister, or abort, or reset. For abort
1348 * and reset token and addr_lnid are unused and may be NULL.
1349 * @code: event bitmask: high order bit 0x80 value 1 means removal of an
1350 * object, 0 - addition of an object.
1351 * 0x01 - VLAN, 0x02 - MAC, 0x03 - VLAN and MAC.
1352 * @token: "network token" structure identifying physical address of the port.
1353 * @addr_lnid: pointer to structure with MAC address and VLAN ID.
1354 *
1355 * This function is called when registrations and deregistrations are
1356 * reported by the hardware, and also when notifications are enabled -
1357 * for all currently registered addresses.
1358 */
1359static void qeth_bridge_emit_host_event(struct qeth_card *card,
1360 enum qeth_an_event_type evtype,
1361 u8 code, struct net_if_token *token, struct mac_addr_lnid *addr_lnid)
1362{
1363 char str[7][32];
1364 char *env[8];
1365 int i = 0;
1366
1367 switch (evtype) {
1368 case anev_reg_unreg:
1369 snprintf(str[i], sizeof(str[i]), "BRIDGEDHOST=%s",
1370 (code & IPA_ADDR_CHANGE_CODE_REMOVAL)
1371 ? "deregister" : "register");
1372 env[i] = str[i]; i++;
1373 if (code & IPA_ADDR_CHANGE_CODE_VLANID) {
1374 snprintf(str[i], sizeof(str[i]), "VLAN=%d",
1375 addr_lnid->lnid);
1376 env[i] = str[i]; i++;
1377 }
1378 if (code & IPA_ADDR_CHANGE_CODE_MACADDR) {
Eugene Crosser9846e702015-09-18 16:06:48 +02001379 snprintf(str[i], sizeof(str[i]), "MAC=%pM",
Thomas Richter4d7def22015-09-18 16:06:51 +02001380 addr_lnid->mac);
Eugene Crosser9f48b9d2014-01-14 15:54:13 +01001381 env[i] = str[i]; i++;
1382 }
1383 snprintf(str[i], sizeof(str[i]), "NTOK_BUSID=%x.%x.%04x",
1384 token->cssid, token->ssid, token->devnum);
1385 env[i] = str[i]; i++;
1386 snprintf(str[i], sizeof(str[i]), "NTOK_IID=%02x", token->iid);
1387 env[i] = str[i]; i++;
1388 snprintf(str[i], sizeof(str[i]), "NTOK_CHPID=%02x",
1389 token->chpid);
1390 env[i] = str[i]; i++;
1391 snprintf(str[i], sizeof(str[i]), "NTOK_CHID=%04x", token->chid);
1392 env[i] = str[i]; i++;
1393 break;
1394 case anev_abort:
1395 snprintf(str[i], sizeof(str[i]), "BRIDGEDHOST=abort");
1396 env[i] = str[i]; i++;
1397 break;
1398 case anev_reset:
1399 snprintf(str[i], sizeof(str[i]), "BRIDGEDHOST=reset");
1400 env[i] = str[i]; i++;
1401 break;
1402 }
1403 env[i] = NULL;
1404 kobject_uevent_env(&card->gdev->dev.kobj, KOBJ_CHANGE, env);
1405}
1406
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001407struct qeth_bridge_state_data {
1408 struct work_struct worker;
1409 struct qeth_card *card;
1410 struct qeth_sbp_state_change qports;
1411};
1412
1413static void qeth_bridge_state_change_worker(struct work_struct *work)
1414{
1415 struct qeth_bridge_state_data *data =
1416 container_of(work, struct qeth_bridge_state_data, worker);
1417 /* We are only interested in the first entry - local port */
1418 struct qeth_sbp_port_entry *entry = &data->qports.entry[0];
1419 char env_locrem[32];
1420 char env_role[32];
1421 char env_state[32];
1422 char *env[] = {
1423 env_locrem,
1424 env_role,
1425 env_state,
1426 NULL
1427 };
1428
1429 /* Role should not change by itself, but if it did, */
1430 /* information from the hardware is authoritative. */
1431 mutex_lock(&data->card->conf_mutex);
1432 data->card->options.sbp.role = entry->role;
1433 mutex_unlock(&data->card->conf_mutex);
1434
1435 snprintf(env_locrem, sizeof(env_locrem), "BRIDGEPORT=statechange");
1436 snprintf(env_role, sizeof(env_role), "ROLE=%s",
1437 (entry->role == QETH_SBP_ROLE_NONE) ? "none" :
1438 (entry->role == QETH_SBP_ROLE_PRIMARY) ? "primary" :
1439 (entry->role == QETH_SBP_ROLE_SECONDARY) ? "secondary" :
1440 "<INVALID>");
1441 snprintf(env_state, sizeof(env_state), "STATE=%s",
1442 (entry->state == QETH_SBP_STATE_INACTIVE) ? "inactive" :
1443 (entry->state == QETH_SBP_STATE_STANDBY) ? "standby" :
1444 (entry->state == QETH_SBP_STATE_ACTIVE) ? "active" :
1445 "<INVALID>");
1446 kobject_uevent_env(&data->card->gdev->dev.kobj,
1447 KOBJ_CHANGE, env);
1448 kfree(data);
1449}
1450
Eugene Crosserc044dc22014-01-29 09:23:48 +01001451static void qeth_bridge_state_change(struct qeth_card *card,
1452 struct qeth_ipa_cmd *cmd)
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001453{
1454 struct qeth_sbp_state_change *qports =
1455 &cmd->data.sbp.data.state_change;
1456 struct qeth_bridge_state_data *data;
1457 int extrasize;
1458
1459 QETH_CARD_TEXT(card, 2, "brstchng");
1460 if (qports->entry_length != sizeof(struct qeth_sbp_port_entry)) {
Thomas Richter8a593142014-10-22 12:18:03 +02001461 QETH_CARD_TEXT_(card, 2, "BPsz%04x", qports->entry_length);
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001462 return;
1463 }
1464 extrasize = sizeof(struct qeth_sbp_port_entry) * qports->num_entries;
1465 data = kzalloc(sizeof(struct qeth_bridge_state_data) + extrasize,
1466 GFP_ATOMIC);
1467 if (!data) {
1468 QETH_CARD_TEXT(card, 2, "BPSalloc");
1469 return;
1470 }
1471 INIT_WORK(&data->worker, qeth_bridge_state_change_worker);
1472 data->card = card;
1473 memcpy(&data->qports, qports,
1474 sizeof(struct qeth_sbp_state_change) + extrasize);
1475 queue_work(qeth_wq, &data->worker);
1476}
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001477
Eugene Crosser9f48b9d2014-01-14 15:54:13 +01001478struct qeth_bridge_host_data {
1479 struct work_struct worker;
1480 struct qeth_card *card;
1481 struct qeth_ipacmd_addr_change hostevs;
1482};
1483
1484static void qeth_bridge_host_event_worker(struct work_struct *work)
1485{
1486 struct qeth_bridge_host_data *data =
1487 container_of(work, struct qeth_bridge_host_data, worker);
1488 int i;
1489
1490 if (data->hostevs.lost_event_mask) {
1491 dev_info(&data->card->gdev->dev,
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001492"Address notification from the Bridge Port stopped %s (%s)\n",
Eugene Crosser9f48b9d2014-01-14 15:54:13 +01001493 data->card->dev->name,
1494 (data->hostevs.lost_event_mask == 0x01)
1495 ? "Overflow"
1496 : (data->hostevs.lost_event_mask == 0x02)
1497 ? "Bridge port state change"
1498 : "Unknown reason");
1499 mutex_lock(&data->card->conf_mutex);
1500 data->card->options.sbp.hostnotification = 0;
1501 mutex_unlock(&data->card->conf_mutex);
1502 qeth_bridge_emit_host_event(data->card, anev_abort,
1503 0, NULL, NULL);
1504 } else
1505 for (i = 0; i < data->hostevs.num_entries; i++) {
1506 struct qeth_ipacmd_addr_change_entry *entry =
1507 &data->hostevs.entry[i];
1508 qeth_bridge_emit_host_event(data->card,
1509 anev_reg_unreg,
1510 entry->change_code,
1511 &entry->token, &entry->addr_lnid);
1512 }
1513 kfree(data);
1514}
1515
Eugene Crosserc044dc22014-01-29 09:23:48 +01001516static void qeth_bridge_host_event(struct qeth_card *card,
1517 struct qeth_ipa_cmd *cmd)
Eugene Crosser9f48b9d2014-01-14 15:54:13 +01001518{
1519 struct qeth_ipacmd_addr_change *hostevs =
1520 &cmd->data.addrchange;
1521 struct qeth_bridge_host_data *data;
1522 int extrasize;
1523
1524 QETH_CARD_TEXT(card, 2, "brhostev");
1525 if (cmd->hdr.return_code != 0x0000) {
1526 if (cmd->hdr.return_code == 0x0010) {
1527 if (hostevs->lost_event_mask == 0x00)
1528 hostevs->lost_event_mask = 0xff;
1529 } else {
1530 QETH_CARD_TEXT_(card, 2, "BPHe%04x",
1531 cmd->hdr.return_code);
1532 return;
1533 }
1534 }
1535 extrasize = sizeof(struct qeth_ipacmd_addr_change_entry) *
1536 hostevs->num_entries;
1537 data = kzalloc(sizeof(struct qeth_bridge_host_data) + extrasize,
1538 GFP_ATOMIC);
1539 if (!data) {
1540 QETH_CARD_TEXT(card, 2, "BPHalloc");
1541 return;
1542 }
1543 INIT_WORK(&data->worker, qeth_bridge_host_event_worker);
1544 data->card = card;
1545 memcpy(&data->hostevs, hostevs,
1546 sizeof(struct qeth_ipacmd_addr_change) + extrasize);
1547 queue_work(qeth_wq, &data->worker);
1548}
Eugene Crosser9f48b9d2014-01-14 15:54:13 +01001549
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001550/* SETBRIDGEPORT support; sending commands */
1551
1552struct _qeth_sbp_cbctl {
1553 u16 ipa_rc;
1554 u16 cmd_rc;
1555 union {
1556 u32 supported;
1557 struct {
1558 enum qeth_sbp_roles *role;
1559 enum qeth_sbp_states *state;
1560 } qports;
1561 } data;
1562};
1563
1564/**
1565 * qeth_bridgeport_makerc() - derive "traditional" error from hardware codes.
1566 * @card: qeth_card structure pointer, for debug messages.
1567 * @cbctl: state structure with hardware return codes.
1568 * @setcmd: IPA command code
1569 *
1570 * Returns negative errno-compatible error indication or 0 on success.
1571 */
1572static int qeth_bridgeport_makerc(struct qeth_card *card,
1573 struct _qeth_sbp_cbctl *cbctl, enum qeth_ipa_sbp_cmd setcmd)
1574{
1575 int rc;
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001576 int is_iqd = (card->info.type == QETH_CARD_TYPE_IQD);
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001577
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001578 if ((is_iqd && (cbctl->ipa_rc == IPA_RC_SUCCESS)) ||
1579 (!is_iqd && (cbctl->ipa_rc == cbctl->cmd_rc)))
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001580 switch (cbctl->cmd_rc) {
Kittipon Meesompop2063a5f2017-06-20 16:00:31 +02001581 case IPA_RC_SUCCESS:
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001582 rc = 0;
1583 break;
Kittipon Meesompop2063a5f2017-06-20 16:00:31 +02001584 case IPA_RC_L2_UNSUPPORTED_CMD:
1585 case IPA_RC_UNSUPPORTED_COMMAND:
Eugene Crosserffb95252015-05-18 14:27:58 +02001586 rc = -EOPNOTSUPP;
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001587 break;
Kittipon Meesompop2063a5f2017-06-20 16:00:31 +02001588 case IPA_RC_SBP_OSA_NOT_CONFIGURED:
1589 case IPA_RC_SBP_IQD_NOT_CONFIGURED:
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001590 rc = -ENODEV; /* maybe not the best code here? */
1591 dev_err(&card->gdev->dev,
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001592 "The device is not configured as a Bridge Port\n");
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001593 break;
Kittipon Meesompop2063a5f2017-06-20 16:00:31 +02001594 case IPA_RC_SBP_OSA_OS_MISMATCH:
1595 case IPA_RC_SBP_IQD_OS_MISMATCH:
Eugene Crosser1b05cf62016-06-16 16:18:51 +02001596 rc = -EPERM;
1597 dev_err(&card->gdev->dev,
1598 "A Bridge Port is already configured by a different operating system\n");
1599 break;
Kittipon Meesompop2063a5f2017-06-20 16:00:31 +02001600 case IPA_RC_SBP_OSA_ANO_DEV_PRIMARY:
1601 case IPA_RC_SBP_IQD_ANO_DEV_PRIMARY:
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001602 switch (setcmd) {
1603 case IPA_SBP_SET_PRIMARY_BRIDGE_PORT:
1604 rc = -EEXIST;
1605 dev_err(&card->gdev->dev,
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001606 "The LAN already has a primary Bridge Port\n");
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001607 break;
1608 case IPA_SBP_SET_SECONDARY_BRIDGE_PORT:
1609 rc = -EBUSY;
1610 dev_err(&card->gdev->dev,
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001611 "The device is already a primary Bridge Port\n");
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001612 break;
1613 default:
1614 rc = -EIO;
1615 }
1616 break;
Kittipon Meesompop2063a5f2017-06-20 16:00:31 +02001617 case IPA_RC_SBP_OSA_CURRENT_SECOND:
1618 case IPA_RC_SBP_IQD_CURRENT_SECOND:
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001619 rc = -EBUSY;
1620 dev_err(&card->gdev->dev,
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001621 "The device is already a secondary Bridge Port\n");
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001622 break;
Kittipon Meesompop2063a5f2017-06-20 16:00:31 +02001623 case IPA_RC_SBP_OSA_LIMIT_SECOND:
1624 case IPA_RC_SBP_IQD_LIMIT_SECOND:
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001625 rc = -EEXIST;
1626 dev_err(&card->gdev->dev,
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001627 "The LAN cannot have more secondary Bridge Ports\n");
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001628 break;
Kittipon Meesompop2063a5f2017-06-20 16:00:31 +02001629 case IPA_RC_SBP_OSA_CURRENT_PRIMARY:
1630 case IPA_RC_SBP_IQD_CURRENT_PRIMARY:
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001631 rc = -EBUSY;
1632 dev_err(&card->gdev->dev,
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001633 "The device is already a primary Bridge Port\n");
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001634 break;
Kittipon Meesompop2063a5f2017-06-20 16:00:31 +02001635 case IPA_RC_SBP_OSA_NOT_AUTHD_BY_ZMAN:
1636 case IPA_RC_SBP_IQD_NOT_AUTHD_BY_ZMAN:
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001637 rc = -EACCES;
1638 dev_err(&card->gdev->dev,
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001639 "The device is not authorized to be a Bridge Port\n");
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001640 break;
1641 default:
1642 rc = -EIO;
1643 }
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001644 else
1645 switch (cbctl->ipa_rc) {
1646 case IPA_RC_NOTSUPP:
Eugene Crosserffb95252015-05-18 14:27:58 +02001647 rc = -EOPNOTSUPP;
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001648 break;
1649 case IPA_RC_UNSUPPORTED_COMMAND:
Eugene Crosserffb95252015-05-18 14:27:58 +02001650 rc = -EOPNOTSUPP;
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001651 break;
1652 default:
1653 rc = -EIO;
1654 }
1655
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001656 if (rc) {
1657 QETH_CARD_TEXT_(card, 2, "SBPi%04x", cbctl->ipa_rc);
1658 QETH_CARD_TEXT_(card, 2, "SBPc%04x", cbctl->cmd_rc);
1659 }
1660 return rc;
1661}
1662
Julian Wiedmannd65626a2017-08-15 17:02:47 +02001663static struct qeth_cmd_buffer *qeth_sbp_build_cmd(struct qeth_card *card,
1664 enum qeth_ipa_sbp_cmd sbp_cmd,
1665 unsigned int cmd_length)
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001666{
Julian Wiedmannd65626a2017-08-15 17:02:47 +02001667 enum qeth_ipa_cmds ipa_cmd = (card->info.type == QETH_CARD_TYPE_IQD) ?
1668 IPA_CMD_SETBRIDGEPORT_IQD :
1669 IPA_CMD_SETBRIDGEPORT_OSA;
1670 struct qeth_cmd_buffer *iob;
1671 struct qeth_ipa_cmd *cmd;
1672
1673 iob = qeth_get_ipacmd_buffer(card, ipa_cmd, 0);
1674 if (!iob)
1675 return iob;
Julian Wiedmannff5caa72018-03-09 18:12:52 +01001676 cmd = __ipa_cmd(iob);
Julian Wiedmannd65626a2017-08-15 17:02:47 +02001677 cmd->data.sbp.hdr.cmdlength = sizeof(struct qeth_ipacmd_sbp_hdr) +
1678 cmd_length;
1679 cmd->data.sbp.hdr.command_code = sbp_cmd;
1680 cmd->data.sbp.hdr.used_total = 1;
1681 cmd->data.sbp.hdr.seq_no = 1;
1682 return iob;
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001683}
1684
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001685static int qeth_bridgeport_query_support_cb(struct qeth_card *card,
1686 struct qeth_reply *reply, unsigned long data)
1687{
1688 struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *) data;
1689 struct _qeth_sbp_cbctl *cbctl = (struct _qeth_sbp_cbctl *)reply->param;
1690 QETH_CARD_TEXT(card, 2, "brqsupcb");
1691 cbctl->ipa_rc = cmd->hdr.return_code;
1692 cbctl->cmd_rc = cmd->data.sbp.hdr.return_code;
1693 if ((cbctl->ipa_rc == 0) && (cbctl->cmd_rc == 0)) {
1694 cbctl->data.supported =
1695 cmd->data.sbp.data.query_cmds_supp.supported_cmds;
1696 } else {
1697 cbctl->data.supported = 0;
1698 }
1699 return 0;
1700}
1701
1702/**
1703 * qeth_bridgeport_query_support() - store bitmask of supported subfunctions.
1704 * @card: qeth_card structure pointer.
1705 *
1706 * Sets bitmask of supported setbridgeport subfunctions in the qeth_card
1707 * strucutre: card->options.sbp.supported_funcs.
1708 */
Eugene Crosserc044dc22014-01-29 09:23:48 +01001709static void qeth_bridgeport_query_support(struct qeth_card *card)
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001710{
1711 struct qeth_cmd_buffer *iob;
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001712 struct _qeth_sbp_cbctl cbctl;
1713
1714 QETH_CARD_TEXT(card, 2, "brqsuppo");
Julian Wiedmannd65626a2017-08-15 17:02:47 +02001715 iob = qeth_sbp_build_cmd(card, IPA_SBP_QUERY_COMMANDS_SUPPORTED,
1716 sizeof(struct qeth_sbp_query_cmds_supp));
Thomas Richter1aec42b2015-01-21 13:39:10 +01001717 if (!iob)
1718 return;
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001719 if (qeth_send_ipa_cmd(card, iob, qeth_bridgeport_query_support_cb,
1720 (void *)&cbctl) ||
1721 qeth_bridgeport_makerc(card, &cbctl,
1722 IPA_SBP_QUERY_COMMANDS_SUPPORTED)) {
1723 /* non-zero makerc signifies failure, and produce messages */
1724 card->options.sbp.role = QETH_SBP_ROLE_NONE;
1725 return;
1726 }
1727 card->options.sbp.supported_funcs = cbctl.data.supported;
1728}
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001729
1730static int qeth_bridgeport_query_ports_cb(struct qeth_card *card,
1731 struct qeth_reply *reply, unsigned long data)
1732{
1733 struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *) data;
1734 struct qeth_sbp_query_ports *qports = &cmd->data.sbp.data.query_ports;
1735 struct _qeth_sbp_cbctl *cbctl = (struct _qeth_sbp_cbctl *)reply->param;
1736
1737 QETH_CARD_TEXT(card, 2, "brqprtcb");
1738 cbctl->ipa_rc = cmd->hdr.return_code;
1739 cbctl->cmd_rc = cmd->data.sbp.hdr.return_code;
1740 if ((cbctl->ipa_rc != 0) || (cbctl->cmd_rc != 0))
1741 return 0;
1742 if (qports->entry_length != sizeof(struct qeth_sbp_port_entry)) {
1743 cbctl->cmd_rc = 0xffff;
1744 QETH_CARD_TEXT_(card, 2, "SBPs%04x", qports->entry_length);
1745 return 0;
1746 }
1747 /* first entry contains the state of the local port */
1748 if (qports->num_entries > 0) {
1749 if (cbctl->data.qports.role)
1750 *cbctl->data.qports.role = qports->entry[0].role;
1751 if (cbctl->data.qports.state)
1752 *cbctl->data.qports.state = qports->entry[0].state;
1753 }
1754 return 0;
1755}
1756
1757/**
1758 * qeth_bridgeport_query_ports() - query local bridgeport status.
1759 * @card: qeth_card structure pointer.
1760 * @role: Role of the port: 0-none, 1-primary, 2-secondary.
1761 * @state: State of the port: 0-inactive, 1-standby, 2-active.
1762 *
1763 * Returns negative errno-compatible error indication or 0 on success.
1764 *
1765 * 'role' and 'state' are not updated in case of hardware operation failure.
1766 */
1767int qeth_bridgeport_query_ports(struct qeth_card *card,
1768 enum qeth_sbp_roles *role, enum qeth_sbp_states *state)
1769{
1770 int rc = 0;
1771 struct qeth_cmd_buffer *iob;
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001772 struct _qeth_sbp_cbctl cbctl = {
1773 .data = {
1774 .qports = {
1775 .role = role,
1776 .state = state,
1777 },
1778 },
1779 };
1780
1781 QETH_CARD_TEXT(card, 2, "brqports");
1782 if (!(card->options.sbp.supported_funcs & IPA_SBP_QUERY_BRIDGE_PORTS))
1783 return -EOPNOTSUPP;
Julian Wiedmannd65626a2017-08-15 17:02:47 +02001784 iob = qeth_sbp_build_cmd(card, IPA_SBP_QUERY_BRIDGE_PORTS, 0);
Thomas Richter1aec42b2015-01-21 13:39:10 +01001785 if (!iob)
1786 return -ENOMEM;
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001787 rc = qeth_send_ipa_cmd(card, iob, qeth_bridgeport_query_ports_cb,
1788 (void *)&cbctl);
Eugene Crosserc88394e2015-05-18 14:27:53 +02001789 if (rc < 0)
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001790 return rc;
Eugene Crosserc88394e2015-05-18 14:27:53 +02001791 return qeth_bridgeport_makerc(card, &cbctl, IPA_SBP_QUERY_BRIDGE_PORTS);
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001792}
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001793
1794static int qeth_bridgeport_set_cb(struct qeth_card *card,
1795 struct qeth_reply *reply, unsigned long data)
1796{
1797 struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *)data;
1798 struct _qeth_sbp_cbctl *cbctl = (struct _qeth_sbp_cbctl *)reply->param;
1799 QETH_CARD_TEXT(card, 2, "brsetrcb");
1800 cbctl->ipa_rc = cmd->hdr.return_code;
1801 cbctl->cmd_rc = cmd->data.sbp.hdr.return_code;
1802 return 0;
1803}
1804
1805/**
1806 * qeth_bridgeport_setrole() - Assign primary role to the port.
1807 * @card: qeth_card structure pointer.
1808 * @role: Role to assign.
1809 *
1810 * Returns negative errno-compatible error indication or 0 on success.
1811 */
1812int qeth_bridgeport_setrole(struct qeth_card *card, enum qeth_sbp_roles role)
1813{
1814 int rc = 0;
1815 int cmdlength;
1816 struct qeth_cmd_buffer *iob;
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001817 struct _qeth_sbp_cbctl cbctl;
1818 enum qeth_ipa_sbp_cmd setcmd;
1819
1820 QETH_CARD_TEXT(card, 2, "brsetrol");
1821 switch (role) {
1822 case QETH_SBP_ROLE_NONE:
1823 setcmd = IPA_SBP_RESET_BRIDGE_PORT_ROLE;
Julian Wiedmannd65626a2017-08-15 17:02:47 +02001824 cmdlength = sizeof(struct qeth_sbp_reset_role);
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001825 break;
1826 case QETH_SBP_ROLE_PRIMARY:
1827 setcmd = IPA_SBP_SET_PRIMARY_BRIDGE_PORT;
Julian Wiedmannd65626a2017-08-15 17:02:47 +02001828 cmdlength = sizeof(struct qeth_sbp_set_primary);
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001829 break;
1830 case QETH_SBP_ROLE_SECONDARY:
1831 setcmd = IPA_SBP_SET_SECONDARY_BRIDGE_PORT;
Julian Wiedmannd65626a2017-08-15 17:02:47 +02001832 cmdlength = sizeof(struct qeth_sbp_set_secondary);
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001833 break;
1834 default:
1835 return -EINVAL;
1836 }
1837 if (!(card->options.sbp.supported_funcs & setcmd))
1838 return -EOPNOTSUPP;
Julian Wiedmannd65626a2017-08-15 17:02:47 +02001839 iob = qeth_sbp_build_cmd(card, setcmd, cmdlength);
Thomas Richter1aec42b2015-01-21 13:39:10 +01001840 if (!iob)
1841 return -ENOMEM;
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001842 rc = qeth_send_ipa_cmd(card, iob, qeth_bridgeport_set_cb,
1843 (void *)&cbctl);
Eugene Crosserc88394e2015-05-18 14:27:53 +02001844 if (rc < 0)
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001845 return rc;
Eugene Crosserc88394e2015-05-18 14:27:53 +02001846 return qeth_bridgeport_makerc(card, &cbctl, setcmd);
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001847}
1848
Eugene Crosser9f48b9d2014-01-14 15:54:13 +01001849/**
1850 * qeth_anset_makerc() - derive "traditional" error from hardware codes.
1851 * @card: qeth_card structure pointer, for debug messages.
1852 *
1853 * Returns negative errno-compatible error indication or 0 on success.
1854 */
1855static int qeth_anset_makerc(struct qeth_card *card, int pnso_rc, u16 response)
1856{
1857 int rc;
1858
1859 if (pnso_rc == 0)
1860 switch (response) {
1861 case 0x0001:
1862 rc = 0;
1863 break;
1864 case 0x0004:
1865 case 0x0100:
1866 case 0x0106:
Eugene Crosserffb95252015-05-18 14:27:58 +02001867 rc = -EOPNOTSUPP;
Eugene Crosser9f48b9d2014-01-14 15:54:13 +01001868 dev_err(&card->gdev->dev,
1869 "Setting address notification failed\n");
1870 break;
1871 case 0x0107:
1872 rc = -EAGAIN;
1873 break;
1874 default:
1875 rc = -EIO;
1876 }
1877 else
1878 rc = -EIO;
1879
1880 if (rc) {
1881 QETH_CARD_TEXT_(card, 2, "SBPp%04x", pnso_rc);
1882 QETH_CARD_TEXT_(card, 2, "SBPr%04x", response);
1883 }
1884 return rc;
1885}
1886
1887static void qeth_bridgeport_an_set_cb(void *priv,
1888 enum qdio_brinfo_entry_type type, void *entry)
1889{
1890 struct qeth_card *card = (struct qeth_card *)priv;
1891 struct qdio_brinfo_entry_l2 *l2entry;
1892 u8 code;
1893
1894 if (type != l2_addr_lnid) {
1895 WARN_ON_ONCE(1);
1896 return;
1897 }
1898
1899 l2entry = (struct qdio_brinfo_entry_l2 *)entry;
1900 code = IPA_ADDR_CHANGE_CODE_MACADDR;
1901 if (l2entry->addr_lnid.lnid)
1902 code |= IPA_ADDR_CHANGE_CODE_VLANID;
1903 qeth_bridge_emit_host_event(card, anev_reg_unreg, code,
1904 (struct net_if_token *)&l2entry->nit,
1905 (struct mac_addr_lnid *)&l2entry->addr_lnid);
1906}
1907
1908/**
1909 * qeth_bridgeport_an_set() - Enable or disable bridgeport address notification
1910 * @card: qeth_card structure pointer.
1911 * @enable: 0 - disable, non-zero - enable notifications
1912 *
1913 * Returns negative errno-compatible error indication or 0 on success.
1914 *
1915 * On enable, emits a series of address notifications udev events for all
1916 * currently registered hosts.
1917 */
1918int qeth_bridgeport_an_set(struct qeth_card *card, int enable)
1919{
1920 int rc;
1921 u16 response;
1922 struct ccw_device *ddev;
1923 struct subchannel_id schid;
1924
1925 if (!card)
1926 return -EINVAL;
1927 if (!card->options.sbp.supported_funcs)
1928 return -EOPNOTSUPP;
1929 ddev = CARD_DDEV(card);
1930 ccw_device_get_schid(ddev, &schid);
1931
1932 if (enable) {
1933 qeth_bridge_emit_host_event(card, anev_reset, 0, NULL, NULL);
1934 rc = qdio_pnso_brinfo(schid, 1, &response,
1935 qeth_bridgeport_an_set_cb, card);
1936 } else
1937 rc = qdio_pnso_brinfo(schid, 0, &response, NULL, NULL);
1938 return qeth_anset_makerc(card, rc, response);
1939}
Eugene Crosser9f48b9d2014-01-14 15:54:13 +01001940
Hans Wippelcaa1f0b2017-09-18 21:18:15 +02001941static bool qeth_bridgeport_is_in_use(struct qeth_card *card)
1942{
1943 return (card->options.sbp.role || card->options.sbp.reflect_promisc ||
1944 card->options.sbp.hostnotification);
1945}
1946
Hans Wippela45b3fa2017-09-18 21:18:14 +02001947/* VNIC Characteristics support */
1948
1949/* handle VNICC IPA command return codes; convert to error codes */
1950static int qeth_l2_vnicc_makerc(struct qeth_card *card, int ipa_rc)
1951{
1952 int rc;
1953
1954 switch (ipa_rc) {
1955 case IPA_RC_SUCCESS:
1956 return ipa_rc;
1957 case IPA_RC_L2_UNSUPPORTED_CMD:
1958 case IPA_RC_NOTSUPP:
1959 rc = -EOPNOTSUPP;
1960 break;
1961 case IPA_RC_VNICC_OOSEQ:
1962 rc = -EALREADY;
1963 break;
1964 case IPA_RC_VNICC_VNICBP:
1965 rc = -EBUSY;
1966 break;
1967 case IPA_RC_L2_ADDR_TABLE_FULL:
1968 rc = -ENOSPC;
1969 break;
1970 case IPA_RC_L2_MAC_NOT_AUTH_BY_ADP:
1971 rc = -EACCES;
1972 break;
1973 default:
1974 rc = -EIO;
1975 }
1976
1977 QETH_CARD_TEXT_(card, 2, "err%04x", ipa_rc);
1978 return rc;
1979}
1980
1981/* generic VNICC request call back control */
1982struct _qeth_l2_vnicc_request_cbctl {
1983 u32 sub_cmd;
Hans Wippelcaa1f0b2017-09-18 21:18:15 +02001984 struct {
1985 u32 vnic_char;
Hans Wippel349d13d2017-09-18 21:18:16 +02001986 u32 timeout;
Hans Wippelcaa1f0b2017-09-18 21:18:15 +02001987 } param;
1988 struct {
Hans Wippel349d13d2017-09-18 21:18:16 +02001989 union{
1990 u32 *sup_cmds;
1991 u32 *timeout;
1992 };
Hans Wippelcaa1f0b2017-09-18 21:18:15 +02001993 } result;
Hans Wippela45b3fa2017-09-18 21:18:14 +02001994};
1995
1996/* generic VNICC request call back */
1997static int qeth_l2_vnicc_request_cb(struct qeth_card *card,
1998 struct qeth_reply *reply,
1999 unsigned long data)
2000{
Hans Wippelcaa1f0b2017-09-18 21:18:15 +02002001 struct _qeth_l2_vnicc_request_cbctl *cbctl =
2002 (struct _qeth_l2_vnicc_request_cbctl *) reply->param;
Hans Wippela45b3fa2017-09-18 21:18:14 +02002003 struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *) data;
2004 struct qeth_ipacmd_vnicc *rep = &cmd->data.vnicc;
2005
2006 QETH_CARD_TEXT(card, 2, "vniccrcb");
2007 if (cmd->hdr.return_code)
2008 return 0;
2009 /* return results to caller */
2010 card->options.vnicc.sup_chars = rep->hdr.sup;
2011 card->options.vnicc.cur_chars = rep->hdr.cur;
2012
Hans Wippelcaa1f0b2017-09-18 21:18:15 +02002013 if (cbctl->sub_cmd == IPA_VNICC_QUERY_CMDS)
2014 *cbctl->result.sup_cmds = rep->query_cmds.sup_cmds;
2015
Hans Wippel349d13d2017-09-18 21:18:16 +02002016 if (cbctl->sub_cmd == IPA_VNICC_GET_TIMEOUT)
2017 *cbctl->result.timeout = rep->getset_timeout.timeout;
2018
Hans Wippela45b3fa2017-09-18 21:18:14 +02002019 return 0;
2020}
2021
2022/* generic VNICC request */
2023static int qeth_l2_vnicc_request(struct qeth_card *card,
2024 struct _qeth_l2_vnicc_request_cbctl *cbctl)
2025{
2026 struct qeth_ipacmd_vnicc *req;
2027 struct qeth_cmd_buffer *iob;
2028 struct qeth_ipa_cmd *cmd;
2029 int rc;
2030
2031 QETH_CARD_TEXT(card, 2, "vniccreq");
2032
2033 /* get new buffer for request */
2034 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_VNICC, 0);
2035 if (!iob)
2036 return -ENOMEM;
2037
2038 /* create header for request */
Julian Wiedmannff5caa72018-03-09 18:12:52 +01002039 cmd = __ipa_cmd(iob);
Hans Wippela45b3fa2017-09-18 21:18:14 +02002040 req = &cmd->data.vnicc;
2041
2042 /* create sub command header for request */
2043 req->sub_hdr.data_length = sizeof(req->sub_hdr);
2044 req->sub_hdr.sub_command = cbctl->sub_cmd;
2045
2046 /* create sub command specific request fields */
2047 switch (cbctl->sub_cmd) {
2048 case IPA_VNICC_QUERY_CHARS:
2049 break;
Hans Wippelcaa1f0b2017-09-18 21:18:15 +02002050 case IPA_VNICC_QUERY_CMDS:
2051 req->sub_hdr.data_length += sizeof(req->query_cmds);
2052 req->query_cmds.vnic_char = cbctl->param.vnic_char;
2053 break;
2054 case IPA_VNICC_ENABLE:
2055 case IPA_VNICC_DISABLE:
2056 req->sub_hdr.data_length += sizeof(req->set_char);
2057 req->set_char.vnic_char = cbctl->param.vnic_char;
2058 break;
Hans Wippel349d13d2017-09-18 21:18:16 +02002059 case IPA_VNICC_SET_TIMEOUT:
2060 req->getset_timeout.timeout = cbctl->param.timeout;
2061 /* fallthrough */
2062 case IPA_VNICC_GET_TIMEOUT:
2063 req->sub_hdr.data_length += sizeof(req->getset_timeout);
2064 req->getset_timeout.vnic_char = cbctl->param.vnic_char;
2065 break;
Hans Wippela45b3fa2017-09-18 21:18:14 +02002066 default:
2067 qeth_release_buffer(iob->channel, iob);
2068 return -EOPNOTSUPP;
2069 }
2070
2071 /* send request */
2072 rc = qeth_send_ipa_cmd(card, iob, qeth_l2_vnicc_request_cb,
2073 (void *) cbctl);
2074
2075 return qeth_l2_vnicc_makerc(card, rc);
2076}
2077
2078/* VNICC query VNIC characteristics request */
2079static int qeth_l2_vnicc_query_chars(struct qeth_card *card)
2080{
2081 struct _qeth_l2_vnicc_request_cbctl cbctl;
2082
2083 /* prepare callback control */
2084 cbctl.sub_cmd = IPA_VNICC_QUERY_CHARS;
2085
2086 QETH_CARD_TEXT(card, 2, "vniccqch");
2087 return qeth_l2_vnicc_request(card, &cbctl);
2088}
2089
Hans Wippelcaa1f0b2017-09-18 21:18:15 +02002090/* VNICC query sub commands request */
2091static int qeth_l2_vnicc_query_cmds(struct qeth_card *card, u32 vnic_char,
2092 u32 *sup_cmds)
2093{
2094 struct _qeth_l2_vnicc_request_cbctl cbctl;
2095
2096 /* prepare callback control */
2097 cbctl.sub_cmd = IPA_VNICC_QUERY_CMDS;
2098 cbctl.param.vnic_char = vnic_char;
2099 cbctl.result.sup_cmds = sup_cmds;
2100
2101 QETH_CARD_TEXT(card, 2, "vniccqcm");
2102 return qeth_l2_vnicc_request(card, &cbctl);
2103}
2104
2105/* VNICC enable/disable characteristic request */
2106static int qeth_l2_vnicc_set_char(struct qeth_card *card, u32 vnic_char,
2107 u32 cmd)
2108{
2109 struct _qeth_l2_vnicc_request_cbctl cbctl;
2110
2111 /* prepare callback control */
2112 cbctl.sub_cmd = cmd;
2113 cbctl.param.vnic_char = vnic_char;
2114
2115 QETH_CARD_TEXT(card, 2, "vniccedc");
2116 return qeth_l2_vnicc_request(card, &cbctl);
2117}
2118
Hans Wippel349d13d2017-09-18 21:18:16 +02002119/* VNICC get/set timeout for characteristic request */
2120static int qeth_l2_vnicc_getset_timeout(struct qeth_card *card, u32 vnicc,
2121 u32 cmd, u32 *timeout)
2122{
2123 struct _qeth_l2_vnicc_request_cbctl cbctl;
2124
2125 /* prepare callback control */
2126 cbctl.sub_cmd = cmd;
2127 cbctl.param.vnic_char = vnicc;
2128 if (cmd == IPA_VNICC_SET_TIMEOUT)
2129 cbctl.param.timeout = *timeout;
2130 if (cmd == IPA_VNICC_GET_TIMEOUT)
2131 cbctl.result.timeout = timeout;
2132
2133 QETH_CARD_TEXT(card, 2, "vniccgst");
2134 return qeth_l2_vnicc_request(card, &cbctl);
2135}
2136
Hans Wippelcaa1f0b2017-09-18 21:18:15 +02002137/* set current VNICC flag state; called from sysfs store function */
2138int qeth_l2_vnicc_set_state(struct qeth_card *card, u32 vnicc, bool state)
2139{
2140 int rc = 0;
2141 u32 cmd;
2142
2143 QETH_CARD_TEXT(card, 2, "vniccsch");
2144
2145 /* do not change anything if BridgePort is enabled */
2146 if (qeth_bridgeport_is_in_use(card))
2147 return -EBUSY;
2148
2149 /* check if characteristic and enable/disable are supported */
2150 if (!(card->options.vnicc.sup_chars & vnicc) ||
2151 !(card->options.vnicc.set_char_sup & vnicc))
2152 return -EOPNOTSUPP;
2153
2154 /* set enable/disable command and store wanted characteristic */
2155 if (state) {
2156 cmd = IPA_VNICC_ENABLE;
2157 card->options.vnicc.wanted_chars |= vnicc;
2158 } else {
2159 cmd = IPA_VNICC_DISABLE;
2160 card->options.vnicc.wanted_chars &= ~vnicc;
2161 }
2162
2163 /* do we need to do anything? */
2164 if (card->options.vnicc.cur_chars == card->options.vnicc.wanted_chars)
2165 return rc;
2166
2167 /* if card is not ready, simply stop here */
2168 if (!qeth_card_hw_is_reachable(card)) {
2169 if (state)
2170 card->options.vnicc.cur_chars |= vnicc;
2171 else
2172 card->options.vnicc.cur_chars &= ~vnicc;
2173 return rc;
2174 }
2175
2176 rc = qeth_l2_vnicc_set_char(card, vnicc, cmd);
2177 if (rc)
2178 card->options.vnicc.wanted_chars =
2179 card->options.vnicc.cur_chars;
Hans Wippel349d13d2017-09-18 21:18:16 +02002180 else {
2181 /* successful online VNICC change; handle special cases */
2182 if (state && vnicc == QETH_VNICC_RX_BCAST)
2183 card->options.vnicc.rx_bcast_enabled = true;
2184 if (!state && vnicc == QETH_VNICC_LEARNING)
2185 qeth_l2_vnicc_recover_timeout(card, vnicc,
2186 &card->options.vnicc.learning_timeout);
2187 }
Hans Wippelcaa1f0b2017-09-18 21:18:15 +02002188
2189 return rc;
2190}
2191
2192/* get current VNICC flag state; called from sysfs show function */
2193int qeth_l2_vnicc_get_state(struct qeth_card *card, u32 vnicc, bool *state)
2194{
2195 int rc = 0;
2196
2197 QETH_CARD_TEXT(card, 2, "vniccgch");
2198
2199 /* do not get anything if BridgePort is enabled */
2200 if (qeth_bridgeport_is_in_use(card))
2201 return -EBUSY;
2202
2203 /* check if characteristic is supported */
2204 if (!(card->options.vnicc.sup_chars & vnicc))
2205 return -EOPNOTSUPP;
2206
2207 /* if card is ready, query current VNICC state */
2208 if (qeth_card_hw_is_reachable(card))
2209 rc = qeth_l2_vnicc_query_chars(card);
2210
2211 *state = (card->options.vnicc.cur_chars & vnicc) ? true : false;
2212 return rc;
2213}
2214
Hans Wippel349d13d2017-09-18 21:18:16 +02002215/* set VNICC timeout; called from sysfs store function. Currently, only learning
2216 * supports timeout
2217 */
2218int qeth_l2_vnicc_set_timeout(struct qeth_card *card, u32 timeout)
2219{
2220 int rc = 0;
2221
2222 QETH_CARD_TEXT(card, 2, "vniccsto");
2223
2224 /* do not change anything if BridgePort is enabled */
2225 if (qeth_bridgeport_is_in_use(card))
2226 return -EBUSY;
2227
2228 /* check if characteristic and set_timeout are supported */
2229 if (!(card->options.vnicc.sup_chars & QETH_VNICC_LEARNING) ||
2230 !(card->options.vnicc.getset_timeout_sup & QETH_VNICC_LEARNING))
2231 return -EOPNOTSUPP;
2232
2233 /* do we need to do anything? */
2234 if (card->options.vnicc.learning_timeout == timeout)
2235 return rc;
2236
2237 /* if card is not ready, simply store the value internally and return */
2238 if (!qeth_card_hw_is_reachable(card)) {
2239 card->options.vnicc.learning_timeout = timeout;
2240 return rc;
2241 }
2242
2243 /* send timeout value to card; if successful, store value internally */
2244 rc = qeth_l2_vnicc_getset_timeout(card, QETH_VNICC_LEARNING,
2245 IPA_VNICC_SET_TIMEOUT, &timeout);
2246 if (!rc)
2247 card->options.vnicc.learning_timeout = timeout;
2248
2249 return rc;
2250}
2251
2252/* get current VNICC timeout; called from sysfs show function. Currently, only
2253 * learning supports timeout
2254 */
2255int qeth_l2_vnicc_get_timeout(struct qeth_card *card, u32 *timeout)
2256{
2257 int rc = 0;
2258
2259 QETH_CARD_TEXT(card, 2, "vniccgto");
2260
2261 /* do not get anything if BridgePort is enabled */
2262 if (qeth_bridgeport_is_in_use(card))
2263 return -EBUSY;
2264
2265 /* check if characteristic and get_timeout are supported */
2266 if (!(card->options.vnicc.sup_chars & QETH_VNICC_LEARNING) ||
2267 !(card->options.vnicc.getset_timeout_sup & QETH_VNICC_LEARNING))
2268 return -EOPNOTSUPP;
2269 /* if card is ready, get timeout. Otherwise, just return stored value */
2270 *timeout = card->options.vnicc.learning_timeout;
2271 if (qeth_card_hw_is_reachable(card))
2272 rc = qeth_l2_vnicc_getset_timeout(card, QETH_VNICC_LEARNING,
2273 IPA_VNICC_GET_TIMEOUT,
2274 timeout);
2275
2276 return rc;
2277}
2278
Hans Wippelcaa1f0b2017-09-18 21:18:15 +02002279/* check if VNICC is currently enabled */
2280bool qeth_l2_vnicc_is_in_use(struct qeth_card *card)
2281{
2282 /* if everything is turned off, VNICC is not active */
2283 if (!card->options.vnicc.cur_chars)
2284 return false;
2285 /* default values are only OK if rx_bcast was not enabled by user
2286 * or the card is offline.
2287 */
2288 if (card->options.vnicc.cur_chars == QETH_VNICC_DEFAULT) {
2289 if (!card->options.vnicc.rx_bcast_enabled ||
2290 !qeth_card_hw_is_reachable(card))
2291 return false;
2292 }
2293 return true;
2294}
2295
Hans Wippel349d13d2017-09-18 21:18:16 +02002296/* recover user timeout setting */
2297static bool qeth_l2_vnicc_recover_timeout(struct qeth_card *card, u32 vnicc,
2298 u32 *timeout)
2299{
2300 if (card->options.vnicc.sup_chars & vnicc &&
2301 card->options.vnicc.getset_timeout_sup & vnicc &&
2302 !qeth_l2_vnicc_getset_timeout(card, vnicc, IPA_VNICC_SET_TIMEOUT,
2303 timeout))
2304 return false;
2305 *timeout = QETH_VNICC_DEFAULT_TIMEOUT;
2306 return true;
2307}
2308
Hans Wippelcaa1f0b2017-09-18 21:18:15 +02002309/* recover user characteristic setting */
2310static bool qeth_l2_vnicc_recover_char(struct qeth_card *card, u32 vnicc,
2311 bool enable)
2312{
2313 u32 cmd = enable ? IPA_VNICC_ENABLE : IPA_VNICC_DISABLE;
2314
2315 if (card->options.vnicc.sup_chars & vnicc &&
2316 card->options.vnicc.set_char_sup & vnicc &&
2317 !qeth_l2_vnicc_set_char(card, vnicc, cmd))
2318 return false;
2319 card->options.vnicc.wanted_chars &= ~vnicc;
2320 card->options.vnicc.wanted_chars |= QETH_VNICC_DEFAULT & vnicc;
2321 return true;
2322}
2323
Hans Wippela45b3fa2017-09-18 21:18:14 +02002324/* (re-)initialize VNICC */
2325static void qeth_l2_vnicc_init(struct qeth_card *card)
2326{
Hans Wippel349d13d2017-09-18 21:18:16 +02002327 u32 *timeout = &card->options.vnicc.learning_timeout;
Hans Wippelcaa1f0b2017-09-18 21:18:15 +02002328 unsigned int chars_len, i;
2329 unsigned long chars_tmp;
2330 u32 sup_cmds, vnicc;
2331 bool enable, error;
2332
Hans Wippela45b3fa2017-09-18 21:18:14 +02002333 QETH_CARD_TEXT(card, 2, "vniccini");
Hans Wippelcaa1f0b2017-09-18 21:18:15 +02002334 /* reset rx_bcast */
2335 card->options.vnicc.rx_bcast_enabled = 0;
Hans Wippela45b3fa2017-09-18 21:18:14 +02002336 /* initial query and storage of VNIC characteristics */
2337 if (qeth_l2_vnicc_query_chars(card)) {
Hans Wippel349d13d2017-09-18 21:18:16 +02002338 if (card->options.vnicc.wanted_chars != QETH_VNICC_DEFAULT ||
2339 *timeout != QETH_VNICC_DEFAULT_TIMEOUT)
Hans Wippelcaa1f0b2017-09-18 21:18:15 +02002340 dev_err(&card->gdev->dev, "Configuring the VNIC characteristics failed\n");
2341 /* fail quietly if user didn't change the default config */
Hans Wippela45b3fa2017-09-18 21:18:14 +02002342 card->options.vnicc.sup_chars = 0;
2343 card->options.vnicc.cur_chars = 0;
Hans Wippelcaa1f0b2017-09-18 21:18:15 +02002344 card->options.vnicc.wanted_chars = QETH_VNICC_DEFAULT;
2345 return;
Hans Wippela45b3fa2017-09-18 21:18:14 +02002346 }
Hans Wippelcaa1f0b2017-09-18 21:18:15 +02002347 /* get supported commands for each supported characteristic */
2348 chars_tmp = card->options.vnicc.sup_chars;
2349 chars_len = sizeof(card->options.vnicc.sup_chars) * BITS_PER_BYTE;
2350 for_each_set_bit(i, &chars_tmp, chars_len) {
2351 vnicc = BIT(i);
2352 qeth_l2_vnicc_query_cmds(card, vnicc, &sup_cmds);
Hans Wippel349d13d2017-09-18 21:18:16 +02002353 if (!(sup_cmds & IPA_VNICC_SET_TIMEOUT) ||
2354 !(sup_cmds & IPA_VNICC_GET_TIMEOUT))
2355 card->options.vnicc.getset_timeout_sup &= ~vnicc;
Hans Wippelcaa1f0b2017-09-18 21:18:15 +02002356 if (!(sup_cmds & IPA_VNICC_ENABLE) ||
2357 !(sup_cmds & IPA_VNICC_DISABLE))
2358 card->options.vnicc.set_char_sup &= ~vnicc;
2359 }
2360 /* enforce assumed default values and recover settings, if changed */
Hans Wippel349d13d2017-09-18 21:18:16 +02002361 error = qeth_l2_vnicc_recover_timeout(card, QETH_VNICC_LEARNING,
2362 timeout);
Hans Wippelcaa1f0b2017-09-18 21:18:15 +02002363 chars_tmp = card->options.vnicc.wanted_chars ^ QETH_VNICC_DEFAULT;
2364 chars_tmp |= QETH_VNICC_BRIDGE_INVISIBLE;
2365 chars_len = sizeof(card->options.vnicc.wanted_chars) * BITS_PER_BYTE;
2366 for_each_set_bit(i, &chars_tmp, chars_len) {
2367 vnicc = BIT(i);
2368 enable = card->options.vnicc.wanted_chars & vnicc;
2369 error |= qeth_l2_vnicc_recover_char(card, vnicc, enable);
2370 }
2371 if (error)
2372 dev_err(&card->gdev->dev, "Configuring the VNIC characteristics failed\n");
2373}
2374
2375/* configure default values of VNIC characteristics */
2376static void qeth_l2_vnicc_set_defaults(struct qeth_card *card)
2377{
2378 /* characteristics values */
2379 card->options.vnicc.sup_chars = QETH_VNICC_ALL;
2380 card->options.vnicc.cur_chars = QETH_VNICC_DEFAULT;
Hans Wippel349d13d2017-09-18 21:18:16 +02002381 card->options.vnicc.learning_timeout = QETH_VNICC_DEFAULT_TIMEOUT;
Hans Wippelcaa1f0b2017-09-18 21:18:15 +02002382 /* supported commands */
2383 card->options.vnicc.set_char_sup = QETH_VNICC_ALL;
Hans Wippel349d13d2017-09-18 21:18:16 +02002384 card->options.vnicc.getset_timeout_sup = QETH_VNICC_LEARNING;
Hans Wippelcaa1f0b2017-09-18 21:18:15 +02002385 /* settings wanted by users */
2386 card->options.vnicc.wanted_chars = QETH_VNICC_DEFAULT;
Hans Wippela45b3fa2017-09-18 21:18:14 +02002387}
2388
Frank Blaschka4a71df52008-02-15 09:19:42 +01002389module_init(qeth_l2_init);
2390module_exit(qeth_l2_exit);
2391MODULE_AUTHOR("Frank Blaschka <frank.blaschka@de.ibm.com>");
2392MODULE_DESCRIPTION("qeth layer 2 discipline");
2393MODULE_LICENSE("GPL");