blob: 50a313806dde2a03137451390cc1358b10634bf5 [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>
Frank Blaschka4a71df52008-02-15 09:19:42 +010020#include <linux/ip.h>
Jiri Pirkoccffad252009-05-22 23:22:17 +000021#include <linux/list.h>
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +020022#include <linux/hash.h>
23#include <linux/hashtable.h>
24#include <linux/string.h>
Julian Wiedmannec61bd22017-06-20 16:00:34 +020025#include <asm/setup.h>
Frank Blaschka4a71df52008-02-15 09:19:42 +010026#include "qeth_core.h"
Eugene Crosserb4d72c02014-01-14 15:54:11 +010027#include "qeth_l2.h"
Frank Blaschka4a71df52008-02-15 09:19:42 +010028
Frank Blaschka4a71df52008-02-15 09:19:42 +010029static int qeth_l2_set_offline(struct ccwgroup_device *);
30static int qeth_l2_stop(struct net_device *);
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +020031static void qeth_l2_set_rx_mode(struct net_device *);
Eugene Crosserc044dc22014-01-29 09:23:48 +010032static void qeth_bridgeport_query_support(struct qeth_card *card);
33static void qeth_bridge_state_change(struct qeth_card *card,
34 struct qeth_ipa_cmd *cmd);
35static void qeth_bridge_host_event(struct qeth_card *card,
36 struct qeth_ipa_cmd *cmd);
Hans Wippelcaa1f0b2017-09-18 21:18:15 +020037static void qeth_l2_vnicc_set_defaults(struct qeth_card *card);
Hans Wippela45b3fa2017-09-18 21:18:14 +020038static void qeth_l2_vnicc_init(struct qeth_card *card);
Hans Wippel349d13d2017-09-18 21:18:16 +020039static bool qeth_l2_vnicc_recover_timeout(struct qeth_card *card, u32 vnicc,
40 u32 *timeout);
Frank Blaschka4a71df52008-02-15 09:19:42 +010041
Frank Blaschka4a71df52008-02-15 09:19:42 +010042static struct net_device *qeth_l2_netdev_by_devno(unsigned char *read_dev_no)
43{
44 struct qeth_card *card;
45 struct net_device *ndev;
Cornelia Huckf06f6f32008-06-06 12:37:45 +020046 __u16 temp_dev_no;
Frank Blaschka4a71df52008-02-15 09:19:42 +010047 unsigned long flags;
Cornelia Huckf06f6f32008-06-06 12:37:45 +020048 struct ccw_dev_id read_devid;
Frank Blaschka4a71df52008-02-15 09:19:42 +010049
50 ndev = NULL;
51 memcpy(&temp_dev_no, read_dev_no, 2);
52 read_lock_irqsave(&qeth_core_card_list.rwlock, flags);
53 list_for_each_entry(card, &qeth_core_card_list.list, list) {
Cornelia Huckf06f6f32008-06-06 12:37:45 +020054 ccw_device_get_id(CARD_RDEV(card), &read_devid);
55 if (read_devid.devno == temp_dev_no) {
Frank Blaschka4a71df52008-02-15 09:19:42 +010056 ndev = card->dev;
57 break;
58 }
59 }
60 read_unlock_irqrestore(&qeth_core_card_list.rwlock, flags);
61 return ndev;
62}
63
Julian Wiedmann2aa48672017-09-18 21:18:20 +020064static int qeth_setdelmac_makerc(struct qeth_card *card, int retcode)
Frank Blaschka4a71df52008-02-15 09:19:42 +010065{
Eugene Crosserefbbc1d2015-01-21 13:39:09 +010066 int rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +010067
Eugene Crosserefbbc1d2015-01-21 13:39:09 +010068 if (retcode)
Thomas Richter1aec42b2015-01-21 13:39:10 +010069 QETH_CARD_TEXT_(card, 2, "err%04x", retcode);
Eugene Crosserefbbc1d2015-01-21 13:39:09 +010070 switch (retcode) {
71 case IPA_RC_SUCCESS:
72 rc = 0;
73 break;
74 case IPA_RC_L2_UNSUPPORTED_CMD:
Eugene Crosserffb95252015-05-18 14:27:58 +020075 rc = -EOPNOTSUPP;
Eugene Crosserefbbc1d2015-01-21 13:39:09 +010076 break;
77 case IPA_RC_L2_ADDR_TABLE_FULL:
78 rc = -ENOSPC;
79 break;
80 case IPA_RC_L2_DUP_MAC:
81 case IPA_RC_L2_DUP_LAYER3_MAC:
82 rc = -EEXIST;
83 break;
84 case IPA_RC_L2_MAC_NOT_AUTH_BY_HYP:
85 case IPA_RC_L2_MAC_NOT_AUTH_BY_ADP:
86 rc = -EPERM;
87 break;
88 case IPA_RC_L2_MAC_NOT_FOUND:
89 rc = -ENOENT;
90 break;
Thomas Richter1aec42b2015-01-21 13:39:10 +010091 case -ENOMEM:
92 rc = -ENOMEM;
93 break;
Eugene Crosserefbbc1d2015-01-21 13:39:09 +010094 default:
95 rc = -EIO;
96 break;
Frank Blaschka4a71df52008-02-15 09:19:42 +010097 }
Eugene Crosserefbbc1d2015-01-21 13:39:09 +010098 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +010099}
100
Julian Wiedmannac988d72017-01-12 15:48:41 +0100101static int qeth_l2_send_setdelmac(struct qeth_card *card, __u8 *mac,
102 enum qeth_ipa_cmds ipacmd)
103{
104 struct qeth_ipa_cmd *cmd;
105 struct qeth_cmd_buffer *iob;
106
107 QETH_CARD_TEXT(card, 2, "L2sdmac");
108 iob = qeth_get_ipacmd_buffer(card, ipacmd, QETH_PROT_IPV4);
109 if (!iob)
110 return -ENOMEM;
Julian Wiedmannff5caa72018-03-09 18:12:52 +0100111 cmd = __ipa_cmd(iob);
Julian Wiedmann99f0b852017-12-20 20:11:01 +0100112 cmd->data.setdelmac.mac_length = ETH_ALEN;
113 ether_addr_copy(cmd->data.setdelmac.mac, mac);
Julian Wiedmann2aa48672017-09-18 21:18:20 +0200114 return qeth_setdelmac_makerc(card, qeth_send_ipa_cmd(card, iob,
115 NULL, NULL));
Julian Wiedmannac988d72017-01-12 15:48:41 +0100116}
117
118static int qeth_l2_send_setmac(struct qeth_card *card, __u8 *mac)
119{
120 int rc;
121
122 QETH_CARD_TEXT(card, 2, "L2Setmac");
123 rc = qeth_l2_send_setdelmac(card, mac, IPA_CMD_SETVMAC);
124 if (rc == 0) {
125 card->info.mac_bits |= QETH_LAYER2_MAC_REGISTERED;
Julian Wiedmann99f0b852017-12-20 20:11:01 +0100126 ether_addr_copy(card->dev->dev_addr, mac);
Julian Wiedmannac988d72017-01-12 15:48:41 +0100127 dev_info(&card->gdev->dev,
128 "MAC address %pM successfully registered on device %s\n",
129 card->dev->dev_addr, card->dev->name);
130 } else {
131 card->info.mac_bits &= ~QETH_LAYER2_MAC_REGISTERED;
132 switch (rc) {
133 case -EEXIST:
134 dev_warn(&card->gdev->dev,
135 "MAC address %pM already exists\n", mac);
136 break;
137 case -EPERM:
138 dev_warn(&card->gdev->dev,
139 "MAC address %pM is not authorized\n", mac);
140 break;
141 }
142 }
143 return rc;
144}
145
146static int qeth_l2_send_delmac(struct qeth_card *card, __u8 *mac)
147{
148 int rc;
149
150 QETH_CARD_TEXT(card, 2, "L2Delmac");
151 if (!(card->info.mac_bits & QETH_LAYER2_MAC_REGISTERED))
152 return 0;
153 rc = qeth_l2_send_setdelmac(card, mac, IPA_CMD_DELVMAC);
154 if (rc == 0)
155 card->info.mac_bits &= ~QETH_LAYER2_MAC_REGISTERED;
156 return rc;
157}
158
Julian Wiedmann8174aa82017-12-20 20:11:00 +0100159static int qeth_l2_write_mac(struct qeth_card *card, u8 *mac)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100160{
Julian Wiedmann8174aa82017-12-20 20:11:00 +0100161 enum qeth_ipa_cmds cmd = is_multicast_ether_addr_64bits(mac) ?
162 IPA_CMD_SETGMAC : IPA_CMD_SETVMAC;
Eugene Crosserefbbc1d2015-01-21 13:39:09 +0100163 int rc;
164
Julian Wiedmann8174aa82017-12-20 20:11:00 +0100165 QETH_CARD_TEXT(card, 2, "L2Wmac");
166 rc = qeth_l2_send_setdelmac(card, mac, cmd);
Eugene Crosserefbbc1d2015-01-21 13:39:09 +0100167 if (rc == -EEXIST)
Julian Wiedmann8174aa82017-12-20 20:11:00 +0100168 QETH_DBF_MESSAGE(2, "MAC %pM already registered on %s\n",
169 mac, QETH_CARD_IFNAME(card));
Eugene Crosserefbbc1d2015-01-21 13:39:09 +0100170 else if (rc)
Julian Wiedmann8174aa82017-12-20 20:11:00 +0100171 QETH_DBF_MESSAGE(2, "Failed to register MAC %pM on %s: %d\n",
172 mac, QETH_CARD_IFNAME(card), rc);
Eugene Crosserefbbc1d2015-01-21 13:39:09 +0100173 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100174}
175
Julian Wiedmann8174aa82017-12-20 20:11:00 +0100176static int qeth_l2_remove_mac(struct qeth_card *card, u8 *mac)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100177{
Julian Wiedmann8174aa82017-12-20 20:11:00 +0100178 enum qeth_ipa_cmds cmd = is_multicast_ether_addr_64bits(mac) ?
179 IPA_CMD_DELGMAC : IPA_CMD_DELVMAC;
Eugene Crosserefbbc1d2015-01-21 13:39:09 +0100180 int rc;
181
Julian Wiedmann8174aa82017-12-20 20:11:00 +0100182 QETH_CARD_TEXT(card, 2, "L2Rmac");
183 rc = qeth_l2_send_setdelmac(card, mac, cmd);
Eugene Crosserefbbc1d2015-01-21 13:39:09 +0100184 if (rc)
Julian Wiedmann8174aa82017-12-20 20:11:00 +0100185 QETH_DBF_MESSAGE(2, "Failed to delete MAC %pM on %s: %d\n",
186 mac, QETH_CARD_IFNAME(card), rc);
Eugene Crosserefbbc1d2015-01-21 13:39:09 +0100187 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100188}
189
Julian Wiedmannc07cbf22017-01-12 15:48:37 +0100190static void qeth_l2_del_all_macs(struct qeth_card *card)
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200191{
192 struct qeth_mac *mac;
193 struct hlist_node *tmp;
194 int i;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100195
196 spin_lock_bh(&card->mclock);
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200197 hash_for_each_safe(card->mac_htable, i, tmp, mac, hnode) {
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200198 hash_del(&mac->hnode);
199 kfree(mac);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100200 }
201 spin_unlock_bh(&card->mclock);
202}
203
Julian Wiedmanncef6ff222017-08-15 17:02:46 +0200204static int qeth_l2_get_cast_type(struct qeth_card *card, struct sk_buff *skb)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100205{
Klaus-Dieter Wackerce73e102009-08-26 02:01:08 +0000206 if (card->info.type == QETH_CARD_TYPE_OSN)
207 return RTN_UNSPEC;
208 if (is_broadcast_ether_addr(skb->data))
209 return RTN_BROADCAST;
210 if (is_multicast_ether_addr(skb->data))
211 return RTN_MULTICAST;
212 return RTN_UNSPEC;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100213}
214
Julian Wiedmanncef6ff222017-08-15 17:02:46 +0200215static void qeth_l2_hdr_csum(struct qeth_card *card, struct qeth_hdr *hdr,
216 struct sk_buff *skb)
Thomas Richter4d7def22015-09-18 16:06:51 +0200217{
218 struct iphdr *iph = ip_hdr(skb);
219
220 /* tcph->check contains already the pseudo hdr checksum
221 * so just set the header flags
222 */
223 if (iph->protocol == IPPROTO_UDP)
224 hdr->hdr.l2.flags[1] |= QETH_HDR_EXT_UDP;
225 hdr->hdr.l2.flags[1] |= QETH_HDR_EXT_CSUM_TRANSP_REQ |
226 QETH_HDR_EXT_CSUM_HDR_REQ;
227 iph->check = 0;
228 if (card->options.performance_stats)
229 card->perf_stats.tx_csum++;
230}
231
Julian Wiedmannae79fe02017-08-18 10:19:05 +0200232static void qeth_l2_fill_header(struct qeth_hdr *hdr, struct sk_buff *skb,
233 int cast_type, unsigned int data_len)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100234{
Frank Blaschka683d7182008-08-01 16:39:13 +0200235 struct vlan_ethhdr *veth = (struct vlan_ethhdr *)skb_mac_header(skb);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100236
237 memset(hdr, 0, sizeof(struct qeth_hdr));
238 hdr->hdr.l2.id = QETH_HEADER_TYPE_LAYER2;
Julian Wiedmannae79fe02017-08-18 10:19:05 +0200239 hdr->hdr.l2.pkt_length = data_len;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100240
241 /* set byte byte 3 to casting flags */
242 if (cast_type == RTN_MULTICAST)
243 hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_MULTICAST;
244 else if (cast_type == RTN_BROADCAST)
245 hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_BROADCAST;
246 else
Klaus-Dieter Wackerce73e102009-08-26 02:01:08 +0000247 hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_UNICAST;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100248
Frank Blaschka4a71df52008-02-15 09:19:42 +0100249 /* VSWITCH relies on the VLAN
250 * information to be present in
251 * the QDIO header */
252 if (veth->h_vlan_proto == __constant_htons(ETH_P_8021Q)) {
253 hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_VLAN;
254 hdr->hdr.l2.vlan_id = ntohs(veth->h_vlan_TCI);
255 }
256}
257
Julian Wiedmann2aa48672017-09-18 21:18:20 +0200258static int qeth_setdelvlan_makerc(struct qeth_card *card, int retcode)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100259{
Julian Wiedmann2aa48672017-09-18 21:18:20 +0200260 if (retcode)
261 QETH_CARD_TEXT_(card, 2, "err%04x", retcode);
262
263 switch (retcode) {
264 case IPA_RC_SUCCESS:
265 return 0;
266 case IPA_RC_L2_INVALID_VLAN_ID:
267 return -EINVAL;
268 case IPA_RC_L2_DUP_VLAN_ID:
269 return -EEXIST;
270 case IPA_RC_L2_VLAN_ID_NOT_FOUND:
271 return -ENOENT;
272 case IPA_RC_L2_VLAN_ID_NOT_ALLOWED:
273 return -EPERM;
274 case -ENOMEM:
275 return -ENOMEM;
276 default:
277 return -EIO;
278 }
279}
280
281static int qeth_l2_send_setdelvlan_cb(struct qeth_card *card,
282 struct qeth_reply *reply,
283 unsigned long data)
284{
285 struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *) data;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100286
Carsten Otte847a50f2010-06-21 22:57:05 +0000287 QETH_CARD_TEXT(card, 2, "L2sdvcb");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100288 if (cmd->hdr.return_code) {
Julian Wiedmann2aa48672017-09-18 21:18:20 +0200289 QETH_DBF_MESSAGE(2, "Error in processing VLAN %i on %s: 0x%x.\n",
290 cmd->data.setdelvlan.vlan_id,
291 QETH_CARD_IFNAME(card), cmd->hdr.return_code);
Carsten Otte847a50f2010-06-21 22:57:05 +0000292 QETH_CARD_TEXT_(card, 2, "L2VL%4x", cmd->hdr.command);
293 QETH_CARD_TEXT_(card, 2, "err%d", cmd->hdr.return_code);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100294 }
295 return 0;
296}
297
298static int qeth_l2_send_setdelvlan(struct qeth_card *card, __u16 i,
Julian Wiedmann2aa48672017-09-18 21:18:20 +0200299 enum qeth_ipa_cmds ipacmd)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100300{
301 struct qeth_ipa_cmd *cmd;
302 struct qeth_cmd_buffer *iob;
303
Carsten Otte847a50f2010-06-21 22:57:05 +0000304 QETH_CARD_TEXT_(card, 4, "L2sdv%x", ipacmd);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100305 iob = qeth_get_ipacmd_buffer(card, ipacmd, QETH_PROT_IPV4);
Thomas Richter1aec42b2015-01-21 13:39:10 +0100306 if (!iob)
307 return -ENOMEM;
Julian Wiedmannff5caa72018-03-09 18:12:52 +0100308 cmd = __ipa_cmd(iob);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100309 cmd->data.setdelvlan.vlan_id = i;
Julian Wiedmann2aa48672017-09-18 21:18:20 +0200310 return qeth_setdelvlan_makerc(card, qeth_send_ipa_cmd(card, iob,
311 qeth_l2_send_setdelvlan_cb, NULL));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100312}
313
Ursula Braun70919e22011-02-26 22:41:36 -0800314static void qeth_l2_process_vlans(struct qeth_card *card)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100315{
316 struct qeth_vlan_vid *id;
Carsten Otte847a50f2010-06-21 22:57:05 +0000317 QETH_CARD_TEXT(card, 3, "L2prcvln");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100318 spin_lock_bh(&card->vlanlock);
319 list_for_each_entry(id, &card->vid_list, list) {
Ursula Braun70919e22011-02-26 22:41:36 -0800320 qeth_l2_send_setdelvlan(card, id->vid, IPA_CMD_SETVLAN);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100321 }
322 spin_unlock_bh(&card->vlanlock);
323}
324
Patrick McHardy80d5c362013-04-19 02:04:28 +0000325static int qeth_l2_vlan_rx_add_vid(struct net_device *dev,
326 __be16 proto, u16 vid)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100327{
Heiko Carstens509e2562008-07-26 02:24:10 -0700328 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100329 struct qeth_vlan_vid *id;
Thomas Richter1aec42b2015-01-21 13:39:10 +0100330 int rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100331
Carsten Otte847a50f2010-06-21 22:57:05 +0000332 QETH_CARD_TEXT_(card, 4, "aid:%d", vid);
Ursula Braun10651db2010-10-01 02:51:13 +0000333 if (!vid)
Jiri Pirko8e586132011-12-08 19:52:37 -0500334 return 0;
Ursula Braun8e98ac42009-03-24 20:57:18 +0000335 if (qeth_wait_for_threads(card, QETH_RECOVER_THREAD)) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000336 QETH_CARD_TEXT(card, 3, "aidREC");
Jiri Pirko8e586132011-12-08 19:52:37 -0500337 return 0;
Ursula Braun8e98ac42009-03-24 20:57:18 +0000338 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100339 id = kmalloc(sizeof(struct qeth_vlan_vid), GFP_ATOMIC);
340 if (id) {
341 id->vid = vid;
Thomas Richter1aec42b2015-01-21 13:39:10 +0100342 rc = qeth_l2_send_setdelvlan(card, vid, IPA_CMD_SETVLAN);
343 if (rc) {
344 kfree(id);
345 return rc;
346 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100347 spin_lock_bh(&card->vlanlock);
348 list_add_tail(&id->list, &card->vid_list);
349 spin_unlock_bh(&card->vlanlock);
Jiri Pirko8e586132011-12-08 19:52:37 -0500350 } else {
351 return -ENOMEM;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100352 }
Jiri Pirko8e586132011-12-08 19:52:37 -0500353 return 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100354}
355
Patrick McHardy80d5c362013-04-19 02:04:28 +0000356static int qeth_l2_vlan_rx_kill_vid(struct net_device *dev,
357 __be16 proto, u16 vid)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100358{
359 struct qeth_vlan_vid *id, *tmpid = NULL;
Heiko Carstens509e2562008-07-26 02:24:10 -0700360 struct qeth_card *card = dev->ml_priv;
Thomas Richter1aec42b2015-01-21 13:39:10 +0100361 int rc = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100362
Carsten Otte847a50f2010-06-21 22:57:05 +0000363 QETH_CARD_TEXT_(card, 4, "kid:%d", vid);
Ursula Braun8e98ac42009-03-24 20:57:18 +0000364 if (qeth_wait_for_threads(card, QETH_RECOVER_THREAD)) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000365 QETH_CARD_TEXT(card, 3, "kidREC");
Jiri Pirko8e586132011-12-08 19:52:37 -0500366 return 0;
Ursula Braun8e98ac42009-03-24 20:57:18 +0000367 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100368 spin_lock_bh(&card->vlanlock);
369 list_for_each_entry(id, &card->vid_list, list) {
370 if (id->vid == vid) {
371 list_del(&id->list);
372 tmpid = id;
373 break;
374 }
375 }
376 spin_unlock_bh(&card->vlanlock);
377 if (tmpid) {
Thomas Richter1aec42b2015-01-21 13:39:10 +0100378 rc = qeth_l2_send_setdelvlan(card, vid, IPA_CMD_DELVLAN);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100379 kfree(tmpid);
380 }
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200381 qeth_l2_set_rx_mode(card->dev);
Thomas Richter1aec42b2015-01-21 13:39:10 +0100382 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100383}
384
Peter Senna Tschudinb2f4de82015-08-04 17:11:47 +0200385static void qeth_l2_stop_card(struct qeth_card *card, int recovery_mode)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100386{
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200387 QETH_DBF_TEXT(SETUP , 2, "stopcard");
388 QETH_DBF_HEX(SETUP, 2, &card, sizeof(void *));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100389
390 qeth_set_allowed_threads(card, 0, 1);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100391 if (card->read.state == CH_STATE_UP &&
392 card->write.state == CH_STATE_UP &&
393 (card->state == CARD_STATE_UP)) {
394 if (recovery_mode &&
395 card->info.type != QETH_CARD_TYPE_OSN) {
396 qeth_l2_stop(card->dev);
397 } else {
398 rtnl_lock();
399 dev_close(card->dev);
400 rtnl_unlock();
401 }
Ursula Braun70919e22011-02-26 22:41:36 -0800402 card->info.mac_bits &= ~QETH_LAYER2_MAC_REGISTERED;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100403 card->state = CARD_STATE_SOFTSETUP;
404 }
405 if (card->state == CARD_STATE_SOFTSETUP) {
Julian Wiedmannc07cbf22017-01-12 15:48:37 +0100406 qeth_l2_del_all_macs(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100407 qeth_clear_ipacmd_list(card);
408 card->state = CARD_STATE_HARDSETUP;
409 }
410 if (card->state == CARD_STATE_HARDSETUP) {
411 qeth_qdio_clear_card(card, 0);
412 qeth_clear_qdio_buffers(card);
413 qeth_clear_working_pool_list(card);
414 card->state = CARD_STATE_DOWN;
415 }
416 if (card->state == CARD_STATE_DOWN) {
417 qeth_clear_cmd_buffers(&card->read);
418 qeth_clear_cmd_buffers(&card->write);
419 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100420}
421
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000422static int qeth_l2_process_inbound_buffer(struct qeth_card *card,
423 int budget, int *done)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100424{
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000425 int work_done = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100426 struct sk_buff *skb;
427 struct qeth_hdr *hdr;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100428 unsigned int len;
429
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000430 *done = 0;
Stefan Raspl18af5c12012-11-19 02:46:50 +0000431 WARN_ON_ONCE(!budget);
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000432 while (budget) {
433 skb = qeth_core_get_next_skb(card,
Frank Blaschkab3332932011-08-08 01:33:59 +0000434 &card->qdio.in_q->bufs[card->rx.b_index],
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000435 &card->rx.b_element, &card->rx.e_offset, &hdr);
436 if (!skb) {
437 *done = 1;
438 break;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100439 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100440 switch (hdr->hdr.l2.id) {
441 case QETH_HEADER_TYPE_LAYER2:
Frank Blaschka4a71df52008-02-15 09:19:42 +0100442 skb->protocol = eth_type_trans(skb, skb->dev);
Thomas Richter4d7def22015-09-18 16:06:51 +0200443 if ((card->dev->features & NETIF_F_RXCSUM)
444 && ((hdr->hdr.l2.flags[1] &
445 (QETH_HDR_EXT_CSUM_HDR_REQ |
446 QETH_HDR_EXT_CSUM_TRANSP_REQ)) ==
447 (QETH_HDR_EXT_CSUM_HDR_REQ |
448 QETH_HDR_EXT_CSUM_TRANSP_REQ)))
449 skb->ip_summed = CHECKSUM_UNNECESSARY;
450 else
451 skb->ip_summed = CHECKSUM_NONE;
Ursula Braun12883722008-04-01 10:26:56 +0200452 if (skb->protocol == htons(ETH_P_802_2))
453 *((__u32 *)skb->cb) = ++card->seqno.pkt_seqno;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100454 len = skb->len;
Thomas Richter9abfa8cb2015-10-06 15:12:27 +0200455 napi_gro_receive(&card->napi, skb);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100456 break;
457 case QETH_HEADER_TYPE_OSN:
Ursula Braun2d488c22008-10-24 11:16:55 +0200458 if (card->info.type == QETH_CARD_TYPE_OSN) {
459 skb_push(skb, sizeof(struct qeth_hdr));
460 skb_copy_to_linear_data(skb, hdr,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100461 sizeof(struct qeth_hdr));
Ursula Braun2d488c22008-10-24 11:16:55 +0200462 len = skb->len;
463 card->osn_info.data_cb(skb);
464 break;
465 }
466 /* else unknown */
Frank Blaschka4a71df52008-02-15 09:19:42 +0100467 default:
468 dev_kfree_skb_any(skb);
Carsten Otte847a50f2010-06-21 22:57:05 +0000469 QETH_CARD_TEXT(card, 3, "inbunkno");
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200470 QETH_DBF_HEX(CTRL, 3, hdr, QETH_DBF_CTRL_LEN);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100471 continue;
472 }
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000473 work_done++;
474 budget--;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100475 card->stats.rx_packets++;
476 card->stats.rx_bytes += len;
477 }
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000478 return work_done;
479}
480
Frank Blaschka4a71df52008-02-15 09:19:42 +0100481static int qeth_l2_request_initial_mac(struct qeth_card *card)
482{
483 int rc = 0;
484 char vendor_pre[] = {0x02, 0x00, 0x00};
485
Julian Wiedmannec61bd22017-06-20 16:00:34 +0200486 QETH_DBF_TEXT(SETUP, 2, "l2reqmac");
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200487 QETH_DBF_TEXT_(SETUP, 2, "doL2%s", CARD_BUS_ID(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100488
Julian Wiedmannec61bd22017-06-20 16:00:34 +0200489 if (MACHINE_IS_VM) {
490 rc = qeth_vm_request_mac(card);
491 if (!rc)
492 goto out;
493 QETH_DBF_MESSAGE(2, "z/VM MAC Service failed on device %s: x%x\n",
494 CARD_BUS_ID(card), rc);
495 QETH_DBF_TEXT_(SETUP, 2, "err%04x", rc);
496 /* fall back to alternative mechanism: */
497 }
498
Ursula Braun5113fec2010-05-16 21:15:14 +0000499 if (card->info.type == QETH_CARD_TYPE_IQD ||
500 card->info.type == QETH_CARD_TYPE_OSM ||
501 card->info.type == QETH_CARD_TYPE_OSX ||
502 card->info.guestlan) {
Frank Blaschka4a71df52008-02-15 09:19:42 +0100503 rc = qeth_setadpparms_change_macaddr(card);
504 if (rc) {
Frank Blaschka14cc21b2008-06-06 12:37:46 +0200505 QETH_DBF_MESSAGE(2, "couldn't get MAC address on "
506 "device %s: x%x\n", CARD_BUS_ID(card), rc);
Thomas Richter1aec42b2015-01-21 13:39:10 +0100507 QETH_DBF_TEXT_(SETUP, 2, "1err%04x", rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100508 return rc;
509 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100510 } else {
Joe Perches18336112012-07-12 22:33:10 -0700511 eth_random_addr(card->dev->dev_addr);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100512 memcpy(card->dev->dev_addr, vendor_pre, 3);
513 }
Julian Wiedmannec61bd22017-06-20 16:00:34 +0200514out:
515 QETH_DBF_HEX(SETUP, 2, card->dev->dev_addr, card->dev->addr_len);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100516 return 0;
517}
518
519static int qeth_l2_set_mac_address(struct net_device *dev, void *p)
520{
521 struct sockaddr *addr = p;
Heiko Carstens509e2562008-07-26 02:24:10 -0700522 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100523 int rc = 0;
524
Carsten Otte847a50f2010-06-21 22:57:05 +0000525 QETH_CARD_TEXT(card, 3, "setmac");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100526
Ursula Braun5113fec2010-05-16 21:15:14 +0000527 if (card->info.type == QETH_CARD_TYPE_OSN ||
528 card->info.type == QETH_CARD_TYPE_OSM ||
529 card->info.type == QETH_CARD_TYPE_OSX) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000530 QETH_CARD_TEXT(card, 3, "setmcTYP");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100531 return -EOPNOTSUPP;
532 }
Julian Wiedmann99f0b852017-12-20 20:11:01 +0100533 QETH_CARD_HEX(card, 3, addr->sa_data, ETH_ALEN);
Ursula Braun8e98ac42009-03-24 20:57:18 +0000534 if (qeth_wait_for_threads(card, QETH_RECOVER_THREAD)) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000535 QETH_CARD_TEXT(card, 3, "setmcREC");
Ursula Braun8e98ac42009-03-24 20:57:18 +0000536 return -ERESTARTSYS;
537 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100538 rc = qeth_l2_send_delmac(card, &card->dev->dev_addr[0]);
Eugene Crosserefbbc1d2015-01-21 13:39:09 +0100539 if (!rc || (rc == -ENOENT))
Frank Blaschka4a71df52008-02-15 09:19:42 +0100540 rc = qeth_l2_send_setmac(card, addr->sa_data);
Ursula Braune0a81142012-03-07 02:06:28 +0000541 return rc ? -EINVAL : 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100542}
543
Eugene Crosser0db587b2015-05-18 14:27:55 +0200544static void qeth_promisc_to_bridge(struct qeth_card *card)
545{
546 struct net_device *dev = card->dev;
547 enum qeth_ipa_promisc_modes promisc_mode;
548 int role;
549 int rc;
550
551 QETH_CARD_TEXT(card, 3, "pmisc2br");
552
553 if (!card->options.sbp.reflect_promisc)
554 return;
555 promisc_mode = (dev->flags & IFF_PROMISC) ? SET_PROMISC_MODE_ON
556 : SET_PROMISC_MODE_OFF;
557 if (promisc_mode == card->info.promisc_mode)
558 return;
559
560 if (promisc_mode == SET_PROMISC_MODE_ON) {
561 if (card->options.sbp.reflect_promisc_primary)
562 role = QETH_SBP_ROLE_PRIMARY;
563 else
564 role = QETH_SBP_ROLE_SECONDARY;
565 } else
566 role = QETH_SBP_ROLE_NONE;
567
568 rc = qeth_bridgeport_setrole(card, role);
569 QETH_DBF_TEXT_(SETUP, 2, "bpm%c%04x",
570 (promisc_mode == SET_PROMISC_MODE_ON) ? '+' : '-', rc);
571 if (!rc) {
572 card->options.sbp.role = role;
573 card->info.promisc_mode = promisc_mode;
574 }
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200575
576}
577/* New MAC address is added to the hash table and marked to be written on card
578 * only if there is not in the hash table storage already
579 *
580*/
Julian Wiedmann4641b022017-12-20 20:10:59 +0100581static void qeth_l2_add_mac(struct qeth_card *card, struct netdev_hw_addr *ha)
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200582{
Julian Wiedmanncef6ff222017-08-15 17:02:46 +0200583 u32 mac_hash = get_unaligned((u32 *)(&ha->addr[2]));
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200584 struct qeth_mac *mac;
585
Julian Wiedmanncef6ff222017-08-15 17:02:46 +0200586 hash_for_each_possible(card->mac_htable, mac, hnode, mac_hash) {
Julian Wiedmann99f0b852017-12-20 20:11:01 +0100587 if (ether_addr_equal_64bits(ha->addr, mac->mac_addr)) {
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200588 mac->disp_flag = QETH_DISP_ADDR_DO_NOTHING;
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200589 return;
590 }
591 }
592
593 mac = kzalloc(sizeof(struct qeth_mac), GFP_ATOMIC);
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200594 if (!mac)
595 return;
596
Julian Wiedmann99f0b852017-12-20 20:11:01 +0100597 ether_addr_copy(mac->mac_addr, ha->addr);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200598 mac->disp_flag = QETH_DISP_ADDR_ADD;
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200599
Julian Wiedmanncef6ff222017-08-15 17:02:46 +0200600 hash_add(card->mac_htable, &mac->hnode, mac_hash);
Eugene Crosser0db587b2015-05-18 14:27:55 +0200601}
602
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200603static void qeth_l2_set_rx_mode(struct net_device *dev)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100604{
Heiko Carstens509e2562008-07-26 02:24:10 -0700605 struct qeth_card *card = dev->ml_priv;
Jiri Pirkoccffad252009-05-22 23:22:17 +0000606 struct netdev_hw_addr *ha;
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200607 struct qeth_mac *mac;
608 struct hlist_node *tmp;
609 int i;
610 int rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100611
612 if (card->info.type == QETH_CARD_TYPE_OSN)
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200613 return;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100614
Carsten Otte847a50f2010-06-21 22:57:05 +0000615 QETH_CARD_TEXT(card, 3, "setmulti");
Ursula Braun8e98ac42009-03-24 20:57:18 +0000616 if (qeth_threads_running(card, QETH_RECOVER_THREAD) &&
617 (card->state != CARD_STATE_UP))
618 return;
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200619
Frank Blaschka4a71df52008-02-15 09:19:42 +0100620 spin_lock_bh(&card->mclock);
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200621
Jiri Pirko22bedad32010-04-01 21:22:57 +0000622 netdev_for_each_mc_addr(ha, dev)
Julian Wiedmann4641b022017-12-20 20:10:59 +0100623 qeth_l2_add_mac(card, ha);
Jiri Pirko32e7bfc2010-01-25 13:36:10 -0800624 netdev_for_each_uc_addr(ha, dev)
Julian Wiedmann4641b022017-12-20 20:10:59 +0100625 qeth_l2_add_mac(card, ha);
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200626
627 hash_for_each_safe(card->mac_htable, i, tmp, mac, hnode) {
Julian Wiedmann00c163f2017-12-20 20:11:02 +0100628 switch (mac->disp_flag) {
629 case QETH_DISP_ADDR_DELETE:
Julian Wiedmann8174aa82017-12-20 20:11:00 +0100630 qeth_l2_remove_mac(card, mac->mac_addr);
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200631 hash_del(&mac->hnode);
632 kfree(mac);
Julian Wiedmann00c163f2017-12-20 20:11:02 +0100633 break;
634 case QETH_DISP_ADDR_ADD:
Julian Wiedmann8174aa82017-12-20 20:11:00 +0100635 rc = qeth_l2_write_mac(card, mac->mac_addr);
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200636 if (rc) {
637 hash_del(&mac->hnode);
638 kfree(mac);
Julian Wiedmann00c163f2017-12-20 20:11:02 +0100639 break;
640 }
641 /* fall through */
642 default:
643 /* for next call to set_rx_mode(): */
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200644 mac->disp_flag = QETH_DISP_ADDR_DELETE;
Julian Wiedmann00c163f2017-12-20 20:11:02 +0100645 }
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200646 }
Frank Blaschka7db22662008-08-15 08:02:59 +0200647
Frank Blaschka4a71df52008-02-15 09:19:42 +0100648 spin_unlock_bh(&card->mclock);
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200649
Eugene Crosser0db587b2015-05-18 14:27:55 +0200650 if (qeth_adp_supported(card, IPA_SETADP_SET_PROMISC_MODE))
651 qeth_setadp_promisc_mode(card);
652 else
653 qeth_promisc_to_bridge(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100654}
655
Julian Wiedmann72863842017-08-18 10:19:04 +0200656static int qeth_l2_xmit_iqd(struct qeth_card *card, struct sk_buff *skb,
657 struct qeth_qdio_out_q *queue, int cast_type)
658{
659 unsigned int data_offset = ETH_HLEN;
660 struct qeth_hdr *hdr;
661 int rc;
662
663 hdr = kmem_cache_alloc(qeth_core_header_cache, GFP_ATOMIC);
664 if (!hdr)
665 return -ENOMEM;
Julian Wiedmannae79fe02017-08-18 10:19:05 +0200666 qeth_l2_fill_header(hdr, skb, cast_type, skb->len);
Julian Wiedmann72863842017-08-18 10:19:04 +0200667 skb_copy_from_linear_data(skb, ((char *)hdr) + sizeof(*hdr),
668 data_offset);
669
670 if (!qeth_get_elements_no(card, skb, 1, data_offset)) {
671 rc = -E2BIG;
672 goto out;
673 }
Julian Wiedmann7c2e9ba2017-09-18 21:18:18 +0200674 rc = qeth_do_send_packet_fast(queue, skb, hdr, data_offset,
Julian Wiedmannf1588172017-08-18 10:19:08 +0200675 sizeof(*hdr) + data_offset);
Julian Wiedmann72863842017-08-18 10:19:04 +0200676out:
677 if (rc)
678 kmem_cache_free(qeth_core_header_cache, hdr);
679 return rc;
680}
681
682static int qeth_l2_xmit_osa(struct qeth_card *card, struct sk_buff *skb,
683 struct qeth_qdio_out_q *queue, int cast_type)
684{
Julian Wiedmann0d6f02d2017-08-18 10:19:10 +0200685 int push_len = sizeof(struct qeth_hdr);
Julian Wiedmann72863842017-08-18 10:19:04 +0200686 unsigned int elements, nr_frags;
Julian Wiedmann0d6f02d2017-08-18 10:19:10 +0200687 unsigned int hdr_elements = 0;
688 struct qeth_hdr *hdr = NULL;
689 unsigned int hd_len = 0;
Julian Wiedmann72863842017-08-18 10:19:04 +0200690 int rc;
691
692 /* fix hardware limitation: as long as we do not have sbal
693 * chaining we can not send long frag lists
694 */
695 if (!qeth_get_elements_no(card, skb, 0, 0)) {
696 rc = skb_linearize(skb);
697
698 if (card->options.performance_stats) {
699 if (rc)
700 card->perf_stats.tx_linfail++;
701 else
702 card->perf_stats.tx_lin++;
703 }
704 if (rc)
705 return rc;
706 }
707 nr_frags = skb_shinfo(skb)->nr_frags;
708
Julian Wiedmann0d6f02d2017-08-18 10:19:10 +0200709 rc = skb_cow_head(skb, push_len);
710 if (rc)
711 return rc;
712 push_len = qeth_push_hdr(skb, &hdr, push_len);
713 if (push_len < 0)
714 return push_len;
715 if (!push_len) {
716 /* hdr was allocated from cache */
717 hd_len = sizeof(*hdr);
718 hdr_elements = 1;
719 }
720 qeth_l2_fill_header(hdr, skb, cast_type, skb->len - push_len);
721 if (skb->ip_summed == CHECKSUM_PARTIAL)
722 qeth_l2_hdr_csum(card, hdr, skb);
Julian Wiedmann72863842017-08-18 10:19:04 +0200723
Julian Wiedmann0d6f02d2017-08-18 10:19:10 +0200724 elements = qeth_get_elements_no(card, skb, hdr_elements, 0);
Julian Wiedmann72863842017-08-18 10:19:04 +0200725 if (!elements) {
726 rc = -E2BIG;
727 goto out;
728 }
Julian Wiedmann0d6f02d2017-08-18 10:19:10 +0200729 elements += hdr_elements;
730
731 /* TODO: remove the skb_orphan() once TX completion is fast enough */
732 skb_orphan(skb);
733 rc = qeth_do_send_packet(card, queue, skb, hdr, 0, hd_len, elements);
Julian Wiedmann72863842017-08-18 10:19:04 +0200734out:
735 if (!rc) {
Julian Wiedmann72863842017-08-18 10:19:04 +0200736 if (card->options.performance_stats && nr_frags) {
737 card->perf_stats.sg_skbs_sent++;
738 /* nr_frags + skb->data */
739 card->perf_stats.sg_frags_sent += nr_frags + 1;
740 }
741 } else {
Julian Wiedmann0d6f02d2017-08-18 10:19:10 +0200742 if (hd_len)
743 kmem_cache_free(qeth_core_header_cache, hdr);
744 if (rc == -EBUSY)
745 /* roll back to ETH header */
746 skb_pull(skb, push_len);
Julian Wiedmann72863842017-08-18 10:19:04 +0200747 }
748 return rc;
749}
750
751static int qeth_l2_xmit_osn(struct qeth_card *card, struct sk_buff *skb,
752 struct qeth_qdio_out_q *queue)
753{
754 unsigned int elements;
755 struct qeth_hdr *hdr;
756
757 if (skb->protocol == htons(ETH_P_IPV6))
758 return -EPROTONOSUPPORT;
759
760 hdr = (struct qeth_hdr *)skb->data;
761 elements = qeth_get_elements_no(card, skb, 0, 0);
762 if (!elements)
763 return -E2BIG;
764 if (qeth_hdr_chk_and_bounce(skb, &hdr, sizeof(*hdr)))
765 return -EINVAL;
Julian Wiedmann9c3bfda2017-08-18 10:19:07 +0200766 return qeth_do_send_packet(card, queue, skb, hdr, 0, 0, elements);
Julian Wiedmann72863842017-08-18 10:19:04 +0200767}
768
Julian Wiedmanne38db6b2017-04-11 16:11:14 +0200769static netdev_tx_t qeth_l2_hard_start_xmit(struct sk_buff *skb,
770 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;
Klaus-Dieter Wackerce73e102009-08-26 02:01:08 +0000773 int cast_type = qeth_l2_get_cast_type(card, skb);
Stefan Raspl290b8342014-04-28 10:05:08 +0200774 struct qeth_qdio_out_q *queue;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100775 int tx_bytes = skb->len;
Julian Wiedmann72863842017-08-18 10:19:04 +0200776 int rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100777
Stefan Raspl290b8342014-04-28 10:05:08 +0200778 if (card->qdio.do_prio_queueing || (cast_type &&
779 card->info.is_multicast_different))
780 queue = card->qdio.out_qs[qeth_get_priority_queue(card, skb,
781 qeth_get_ip_version(skb), cast_type)];
782 else
783 queue = card->qdio.out_qs[card->qdio.default_out_queue];
784
Frank Blaschka4a71df52008-02-15 09:19:42 +0100785 if ((card->state != CARD_STATE_UP) || !card->lan_online) {
786 card->stats.tx_carrier_errors++;
787 goto tx_drop;
788 }
789
Frank Blaschka4a71df52008-02-15 09:19:42 +0100790 if (card->options.performance_stats) {
791 card->perf_stats.outbound_cnt++;
792 card->perf_stats.outbound_start_time = qeth_get_micros();
793 }
794 netif_stop_queue(dev);
795
Julian Wiedmann72863842017-08-18 10:19:04 +0200796 switch (card->info.type) {
797 case QETH_CARD_TYPE_OSN:
798 rc = qeth_l2_xmit_osn(card, skb, queue);
799 break;
800 case QETH_CARD_TYPE_IQD:
801 rc = qeth_l2_xmit_iqd(card, skb, queue, cast_type);
802 break;
803 default:
804 rc = qeth_l2_xmit_osa(card, skb, queue, cast_type);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100805 }
806
Frank Blaschka4a71df52008-02-15 09:19:42 +0100807 if (!rc) {
808 card->stats.tx_packets++;
809 card->stats.tx_bytes += tx_bytes;
Julian Wiedmann72863842017-08-18 10:19:04 +0200810 if (card->options.performance_stats)
811 card->perf_stats.outbound_time += qeth_get_micros() -
812 card->perf_stats.outbound_start_time;
813 netif_wake_queue(dev);
814 return NETDEV_TX_OK;
815 } else if (rc == -EBUSY) {
816 return NETDEV_TX_BUSY;
817 } /* else fall through */
Frank Blaschka4a71df52008-02-15 09:19:42 +0100818
819tx_drop:
820 card->stats.tx_dropped++;
821 card->stats.tx_errors++;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100822 dev_kfree_skb_any(skb);
Frank Blaschkad0ec0f52008-06-06 12:37:48 +0200823 netif_wake_queue(dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100824 return NETDEV_TX_OK;
825}
826
Ursula Braun39423442011-01-12 20:42:24 +0000827static int __qeth_l2_open(struct net_device *dev)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100828{
Heiko Carstens509e2562008-07-26 02:24:10 -0700829 struct qeth_card *card = dev->ml_priv;
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000830 int rc = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100831
Carsten Otte847a50f2010-06-21 22:57:05 +0000832 QETH_CARD_TEXT(card, 4, "qethopen");
Ursula Braun39423442011-01-12 20:42:24 +0000833 if (card->state == CARD_STATE_UP)
834 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100835 if (card->state != CARD_STATE_SOFTSETUP)
836 return -ENODEV;
837
838 if ((card->info.type != QETH_CARD_TYPE_OSN) &&
839 (!(card->info.mac_bits & QETH_LAYER2_MAC_REGISTERED))) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000840 QETH_CARD_TEXT(card, 4, "nomacadr");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100841 return -EPERM;
842 }
843 card->data.state = CH_STATE_UP;
844 card->state = CARD_STATE_UP;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100845 netif_start_queue(dev);
846
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000847 if (qdio_stop_irq(card->data.ccwdev, 0) >= 0) {
848 napi_enable(&card->napi);
849 napi_schedule(&card->napi);
850 } else
851 rc = -EIO;
852 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100853}
854
Ursula Braun39423442011-01-12 20:42:24 +0000855static int qeth_l2_open(struct net_device *dev)
856{
857 struct qeth_card *card = dev->ml_priv;
858
859 QETH_CARD_TEXT(card, 5, "qethope_");
860 if (qeth_wait_for_threads(card, QETH_RECOVER_THREAD)) {
861 QETH_CARD_TEXT(card, 3, "openREC");
862 return -ERESTARTSYS;
863 }
864 return __qeth_l2_open(dev);
865}
866
Frank Blaschka4a71df52008-02-15 09:19:42 +0100867static int qeth_l2_stop(struct net_device *dev)
868{
Heiko Carstens509e2562008-07-26 02:24:10 -0700869 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100870
Carsten Otte847a50f2010-06-21 22:57:05 +0000871 QETH_CARD_TEXT(card, 4, "qethstop");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100872 netif_tx_disable(dev);
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000873 if (card->state == CARD_STATE_UP) {
Frank Blaschka4a71df52008-02-15 09:19:42 +0100874 card->state = CARD_STATE_SOFTSETUP;
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000875 napi_disable(&card->napi);
876 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100877 return 0;
878}
879
Julian Wiedmann2d2ebb32017-05-10 19:07:52 +0200880static const struct device_type qeth_l2_devtype = {
881 .name = "qeth_layer2",
882 .groups = qeth_l2_attr_groups,
883};
884
Frank Blaschka4a71df52008-02-15 09:19:42 +0100885static int qeth_l2_probe_device(struct ccwgroup_device *gdev)
886{
887 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
Ursula Braun9111e782017-05-10 19:07:51 +0200888 int rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100889
Julian Wiedmann2d2ebb32017-05-10 19:07:52 +0200890 if (gdev->dev.type == &qeth_generic_devtype) {
891 rc = qeth_l2_create_device_attributes(&gdev->dev);
892 if (rc)
893 return rc;
894 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100895 INIT_LIST_HEAD(&card->vid_list);
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200896 hash_init(card->mac_htable);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100897 card->options.layer2 = 1;
Frank Blaschka1da74b12011-05-12 18:45:02 +0000898 card->info.hwtrap = 0;
Hans Wippelcaa1f0b2017-09-18 21:18:15 +0200899 qeth_l2_vnicc_set_defaults(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100900 return 0;
901}
902
903static void qeth_l2_remove_device(struct ccwgroup_device *cgdev)
904{
905 struct qeth_card *card = dev_get_drvdata(&cgdev->dev);
906
Julian Wiedmann2d2ebb32017-05-10 19:07:52 +0200907 if (cgdev->dev.type == &qeth_generic_devtype)
908 qeth_l2_remove_device_attributes(&cgdev->dev);
Ursula Braunf2148562009-05-19 21:38:37 +0000909 qeth_set_allowed_threads(card, 0, 1);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100910 wait_event(card->wait_q, qeth_threads_running(card, 0xffffffff) == 0);
911
Ursula Braun70919e22011-02-26 22:41:36 -0800912 if (cgdev->state == CCWGROUP_ONLINE)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100913 qeth_l2_set_offline(cgdev);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100914
915 if (card->dev) {
916 unregister_netdev(card->dev);
Julian Wiedmann6be68732018-03-20 07:59:12 +0100917 free_netdev(card->dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100918 card->dev = NULL;
919 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100920 return;
921}
922
Stephen Hemminger0fc0b732009-09-02 01:03:33 -0700923static const struct ethtool_ops qeth_l2_ethtool_ops = {
Frank Blaschka4a71df52008-02-15 09:19:42 +0100924 .get_link = ethtool_op_get_link,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100925 .get_strings = qeth_core_get_strings,
926 .get_ethtool_stats = qeth_core_get_ethtool_stats,
Ben Hutchingsdf8b4ec2009-10-01 11:24:32 +0000927 .get_sset_count = qeth_core_get_sset_count,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100928 .get_drvinfo = qeth_core_get_drvinfo,
Julian Wiedmann993e19c2017-04-11 16:11:17 +0200929 .get_link_ksettings = qeth_core_ethtool_get_link_ksettings,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100930};
931
Stephen Hemminger0fc0b732009-09-02 01:03:33 -0700932static const struct ethtool_ops qeth_l2_osn_ops = {
Frank Blaschka4a71df52008-02-15 09:19:42 +0100933 .get_strings = qeth_core_get_strings,
934 .get_ethtool_stats = qeth_core_get_ethtool_stats,
Ben Hutchingsdf8b4ec2009-10-01 11:24:32 +0000935 .get_sset_count = qeth_core_get_sset_count,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100936 .get_drvinfo = qeth_core_get_drvinfo,
937};
938
Frank Blaschka3d58cef2009-01-09 03:44:00 +0000939static const struct net_device_ops qeth_l2_netdev_ops = {
Frank Blaschka8403b132009-01-08 10:50:55 -0800940 .ndo_open = qeth_l2_open,
941 .ndo_stop = qeth_l2_stop,
942 .ndo_get_stats = qeth_get_stats,
943 .ndo_start_xmit = qeth_l2_hard_start_xmit,
Julian Wiedmann6d69b1f2017-12-01 10:14:50 +0100944 .ndo_features_check = qeth_features_check,
Frank Blaschka8403b132009-01-08 10:50:55 -0800945 .ndo_validate_addr = eth_validate_addr,
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200946 .ndo_set_rx_mode = qeth_l2_set_rx_mode,
Julian Wiedmann942d6982017-04-11 16:11:10 +0200947 .ndo_do_ioctl = qeth_do_ioctl,
Frank Blaschka8403b132009-01-08 10:50:55 -0800948 .ndo_set_mac_address = qeth_l2_set_mac_address,
949 .ndo_change_mtu = qeth_change_mtu,
950 .ndo_vlan_rx_add_vid = qeth_l2_vlan_rx_add_vid,
951 .ndo_vlan_rx_kill_vid = qeth_l2_vlan_rx_kill_vid,
952 .ndo_tx_timeout = qeth_tx_timeout,
Thomas Richter8f43fb02016-06-16 16:18:59 +0200953 .ndo_fix_features = qeth_fix_features,
954 .ndo_set_features = qeth_set_features
Frank Blaschka8403b132009-01-08 10:50:55 -0800955};
956
Frank Blaschka4a71df52008-02-15 09:19:42 +0100957static int qeth_l2_setup_netdev(struct qeth_card *card)
958{
959 switch (card->info.type) {
Frank Blaschka4a71df52008-02-15 09:19:42 +0100960 case QETH_CARD_TYPE_IQD:
Tom Gundersenc835a672014-07-14 16:37:24 +0200961 card->dev = alloc_netdev(0, "hsi%d", NET_NAME_UNKNOWN,
962 ether_setup);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100963 break;
964 case QETH_CARD_TYPE_OSN:
Tom Gundersenc835a672014-07-14 16:37:24 +0200965 card->dev = alloc_netdev(0, "osn%d", NET_NAME_UNKNOWN,
966 ether_setup);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100967 break;
968 default:
969 card->dev = alloc_etherdev(0);
970 }
971
972 if (!card->dev)
973 return -ENODEV;
974
Heiko Carstens509e2562008-07-26 02:24:10 -0700975 card->dev->ml_priv = card;
Julian Wiedmannd3aacac2018-03-09 18:12:55 +0100976 card->dev->priv_flags |= IFF_UNICAST_FLT;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100977 card->dev->watchdog_timeo = QETH_TX_TIMEOUT;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100978 card->dev->mtu = card->info.initial_mtu;
Jarod Wilson46b3ef42016-10-20 13:55:23 -0400979 card->dev->min_mtu = 64;
980 card->dev->max_mtu = ETH_MAX_MTU;
Frank Blaschka8403b132009-01-08 10:50:55 -0800981 card->dev->netdev_ops = &qeth_l2_netdev_ops;
Julian Wiedmann25e2c342017-05-10 19:07:53 +0200982 if (card->info.type == QETH_CARD_TYPE_OSN) {
983 card->dev->ethtool_ops = &qeth_l2_osn_ops;
984 card->dev->flags |= IFF_NOARP;
985 } else {
986 card->dev->ethtool_ops = &qeth_l2_ethtool_ops;
987 }
Julian Wiedmann9400c532017-10-18 17:40:20 +0200988
989 if (card->info.type == QETH_CARD_TYPE_OSM)
990 card->dev->features |= NETIF_F_VLAN_CHALLENGED;
991 else
992 card->dev->features |= NETIF_F_HW_VLAN_CTAG_FILTER;
Julian Wiedmann0f342942018-03-09 18:12:54 +0100993
994 if (card->info.type != QETH_CARD_TYPE_OSN &&
995 card->info.type != QETH_CARD_TYPE_IQD) {
996 card->dev->priv_flags &= ~IFF_TX_SKB_SHARING;
997 card->dev->needed_headroom = sizeof(struct qeth_hdr);
998 card->dev->hw_features |= NETIF_F_SG;
999 card->dev->vlan_features |= NETIF_F_SG;
1000 }
1001
Thomas Richter4d7def22015-09-18 16:06:51 +02001002 if (card->info.type == QETH_CARD_TYPE_OSD && !card->info.guestlan) {
Julian Wiedmann6d69b1f2017-12-01 10:14:50 +01001003 card->dev->features |= NETIF_F_SG;
Thomas Richter8f43fb02016-06-16 16:18:59 +02001004 /* OSA 3S and earlier has no RX/TX support */
Hans Wippel9bdc4412016-06-16 16:19:00 +02001005 if (qeth_is_supported(card, IPA_OUTBOUND_CHECKSUM)) {
Thomas Richter8f43fb02016-06-16 16:18:59 +02001006 card->dev->hw_features |= NETIF_F_IP_CSUM;
Hans Wippel9bdc4412016-06-16 16:19:00 +02001007 card->dev->vlan_features |= NETIF_F_IP_CSUM;
1008 }
1009 if (qeth_is_supported(card, IPA_INBOUND_CHECKSUM)) {
Thomas Richter8f43fb02016-06-16 16:18:59 +02001010 card->dev->hw_features |= NETIF_F_RXCSUM;
Hans Wippel9bdc4412016-06-16 16:19:00 +02001011 card->dev->vlan_features |= NETIF_F_RXCSUM;
1012 }
Thomas Richter4d7def22015-09-18 16:06:51 +02001013 }
Julian Wiedmann0d6f02d2017-08-18 10:19:10 +02001014
Frank Blaschka4a71df52008-02-15 09:19:42 +01001015 card->info.broadcast_capable = 1;
1016 qeth_l2_request_initial_mac(card);
1017 SET_NETDEV_DEV(card->dev, &card->gdev->dev);
Julian Wiedmannd73ef322017-04-11 16:11:11 +02001018 netif_napi_add(card->dev, &card->napi, qeth_poll, QETH_NAPI_WEIGHT);
Ursula Braune5ebe632015-12-11 12:27:55 +01001019 netif_carrier_off(card->dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001020 return register_netdev(card->dev);
1021}
1022
Thomas Richter4d7def22015-09-18 16:06:51 +02001023static int qeth_l2_start_ipassists(struct qeth_card *card)
1024{
1025 /* configure isolation level */
1026 if (qeth_set_access_ctrl_online(card, 0))
1027 return -ENODEV;
Thomas Richter4d7def22015-09-18 16:06:51 +02001028 return 0;
1029}
1030
Julian Wiedmann521c10e2017-06-06 14:33:45 +02001031static void qeth_l2_trace_features(struct qeth_card *card)
1032{
Hans Wippela45b3fa2017-09-18 21:18:14 +02001033 /* Set BridgePort features */
1034 QETH_CARD_TEXT(card, 2, "featuSBP");
Julian Wiedmann521c10e2017-06-06 14:33:45 +02001035 QETH_CARD_HEX(card, 2, &card->options.sbp.supported_funcs,
1036 sizeof(card->options.sbp.supported_funcs));
Hans Wippela45b3fa2017-09-18 21:18:14 +02001037 /* VNIC Characteristics features */
1038 QETH_CARD_TEXT(card, 2, "feaVNICC");
1039 QETH_CARD_HEX(card, 2, &card->options.vnicc.sup_chars,
1040 sizeof(card->options.vnicc.sup_chars));
Julian Wiedmann521c10e2017-06-06 14:33:45 +02001041}
1042
Frank Blaschka4a71df52008-02-15 09:19:42 +01001043static int __qeth_l2_set_online(struct ccwgroup_device *gdev, int recovery_mode)
1044{
1045 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
1046 int rc = 0;
1047 enum qeth_card_states recover_flag;
1048
Ursula Braun9dc48cc2010-07-22 23:15:05 +00001049 mutex_lock(&card->discipline_mutex);
Frank Blaschkac4949f02010-05-11 19:34:47 +00001050 mutex_lock(&card->conf_mutex);
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001051 QETH_DBF_TEXT(SETUP, 2, "setonlin");
1052 QETH_DBF_HEX(SETUP, 2, &card, sizeof(void *));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001053
Frank Blaschka4a71df52008-02-15 09:19:42 +01001054 recover_flag = card->state;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001055 rc = qeth_core_hardsetup_card(card);
1056 if (rc) {
Thomas Richter1aec42b2015-01-21 13:39:10 +01001057 QETH_DBF_TEXT_(SETUP, 2, "2err%04x", rc);
Ursula Braunaa909222009-11-12 00:11:43 +00001058 rc = -ENODEV;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001059 goto out_remove;
1060 }
Eugene Crosserc044dc22014-01-29 09:23:48 +01001061 qeth_bridgeport_query_support(card);
1062 if (card->options.sbp.supported_funcs)
1063 dev_info(&card->gdev->dev,
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001064 "The device represents a Bridge Capable Port\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001065
Ursula Braunaa909222009-11-12 00:11:43 +00001066 if (!card->dev && qeth_l2_setup_netdev(card)) {
1067 rc = -ENODEV;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001068 goto out_remove;
Ursula Braunaa909222009-11-12 00:11:43 +00001069 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01001070
1071 if (card->info.type != QETH_CARD_TYPE_OSN)
1072 qeth_l2_send_setmac(card, &card->dev->dev_addr[0]);
1073
Frank Blaschka1da74b12011-05-12 18:45:02 +00001074 if (qeth_is_diagass_supported(card, QETH_DIAGS_CMD_TRAP)) {
1075 if (card->info.hwtrap &&
1076 qeth_hw_trap(card, QETH_DIAGS_TRAP_ARM))
1077 card->info.hwtrap = 0;
1078 } else
1079 card->info.hwtrap = 0;
1080
Hans Wippela45b3fa2017-09-18 21:18:14 +02001081 /* for the rx_bcast characteristic, init VNICC after setmac */
1082 qeth_l2_vnicc_init(card);
1083
1084 qeth_trace_features(card);
1085 qeth_l2_trace_features(card);
1086
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001087 qeth_l2_setup_bridgeport_attrs(card);
1088
Frank Blaschka4a71df52008-02-15 09:19:42 +01001089 card->state = CARD_STATE_HARDSETUP;
1090 qeth_print_status_message(card);
1091
1092 /* softsetup */
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001093 QETH_DBF_TEXT(SETUP, 2, "softsetp");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001094
Ursula Braun5113fec2010-05-16 21:15:14 +00001095 if ((card->info.type == QETH_CARD_TYPE_OSD) ||
Stefan Raspl0f547612013-01-21 02:30:20 +00001096 (card->info.type == QETH_CARD_TYPE_OSX)) {
Thomas Richter8f43fb02016-06-16 16:18:59 +02001097 rc = qeth_l2_start_ipassists(card);
1098 if (rc)
Stefan Raspl0f547612013-01-21 02:30:20 +00001099 goto out_remove;
Stefan Raspl0f547612013-01-21 02:30:20 +00001100 }
Ursula Braun5113fec2010-05-16 21:15:14 +00001101
Julian Wiedmann9400c532017-10-18 17:40:20 +02001102 if (card->info.type != QETH_CARD_TYPE_OSN)
Ursula Braun70919e22011-02-26 22:41:36 -08001103 qeth_l2_process_vlans(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001104
1105 netif_tx_disable(card->dev);
1106
1107 rc = qeth_init_qdio_queues(card);
1108 if (rc) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001109 QETH_DBF_TEXT_(SETUP, 2, "6err%d", rc);
Ursula Braunaa909222009-11-12 00:11:43 +00001110 rc = -ENODEV;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001111 goto out_remove;
1112 }
1113 card->state = CARD_STATE_SOFTSETUP;
Ursula Braun2b6203b2010-11-26 02:41:19 +00001114 if (card->lan_online)
1115 netif_carrier_on(card->dev);
1116 else
1117 netif_carrier_off(card->dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001118
1119 qeth_set_allowed_threads(card, 0xffffffff, 0);
1120 if (recover_flag == CARD_STATE_RECOVER) {
1121 if (recovery_mode &&
1122 card->info.type != QETH_CARD_TYPE_OSN) {
Ursula Braun39423442011-01-12 20:42:24 +00001123 __qeth_l2_open(card->dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001124 } else {
1125 rtnl_lock();
1126 dev_open(card->dev);
1127 rtnl_unlock();
1128 }
1129 /* this also sets saved unicast addresses */
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +02001130 qeth_l2_set_rx_mode(card->dev);
Hans Wippele830baa2016-09-15 14:39:21 +02001131 rtnl_lock();
1132 qeth_recover_features(card->dev);
1133 rtnl_unlock();
Frank Blaschka4a71df52008-02-15 09:19:42 +01001134 }
1135 /* let user_space know that device is online */
1136 kobject_uevent(&gdev->dev.kobj, KOBJ_CHANGE);
Frank Blaschkac4949f02010-05-11 19:34:47 +00001137 mutex_unlock(&card->conf_mutex);
Ursula Braun9dc48cc2010-07-22 23:15:05 +00001138 mutex_unlock(&card->discipline_mutex);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001139 return 0;
Ursula Braunaa909222009-11-12 00:11:43 +00001140
Frank Blaschka4a71df52008-02-15 09:19:42 +01001141out_remove:
Frank Blaschka4a71df52008-02-15 09:19:42 +01001142 qeth_l2_stop_card(card, 0);
1143 ccw_device_set_offline(CARD_DDEV(card));
1144 ccw_device_set_offline(CARD_WDEV(card));
1145 ccw_device_set_offline(CARD_RDEV(card));
Ursula Braun22ae2792014-02-24 13:12:06 +01001146 qdio_free(CARD_DDEV(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001147 if (recover_flag == CARD_STATE_RECOVER)
1148 card->state = CARD_STATE_RECOVER;
1149 else
1150 card->state = CARD_STATE_DOWN;
Frank Blaschkac4949f02010-05-11 19:34:47 +00001151 mutex_unlock(&card->conf_mutex);
Ursula Braun9dc48cc2010-07-22 23:15:05 +00001152 mutex_unlock(&card->discipline_mutex);
Ursula Braunaa909222009-11-12 00:11:43 +00001153 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001154}
1155
1156static int qeth_l2_set_online(struct ccwgroup_device *gdev)
1157{
1158 return __qeth_l2_set_online(gdev, 0);
1159}
1160
1161static int __qeth_l2_set_offline(struct ccwgroup_device *cgdev,
1162 int recovery_mode)
1163{
1164 struct qeth_card *card = dev_get_drvdata(&cgdev->dev);
1165 int rc = 0, rc2 = 0, rc3 = 0;
1166 enum qeth_card_states recover_flag;
1167
Ursula Braun9dc48cc2010-07-22 23:15:05 +00001168 mutex_lock(&card->discipline_mutex);
Frank Blaschkac4949f02010-05-11 19:34:47 +00001169 mutex_lock(&card->conf_mutex);
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001170 QETH_DBF_TEXT(SETUP, 3, "setoffl");
1171 QETH_DBF_HEX(SETUP, 3, &card, sizeof(void *));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001172
1173 if (card->dev && netif_carrier_ok(card->dev))
1174 netif_carrier_off(card->dev);
1175 recover_flag = card->state;
Frank Blaschka1da74b12011-05-12 18:45:02 +00001176 if ((!recovery_mode && card->info.hwtrap) || card->info.hwtrap == 2) {
1177 qeth_hw_trap(card, QETH_DIAGS_TRAP_DISARM);
1178 card->info.hwtrap = 1;
1179 }
Ursula Braun0f5623c2008-10-24 11:16:52 +02001180 qeth_l2_stop_card(card, recovery_mode);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001181 rc = ccw_device_set_offline(CARD_DDEV(card));
1182 rc2 = ccw_device_set_offline(CARD_WDEV(card));
1183 rc3 = ccw_device_set_offline(CARD_RDEV(card));
1184 if (!rc)
1185 rc = (rc2) ? rc2 : rc3;
1186 if (rc)
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001187 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
Ursula Braun22ae2792014-02-24 13:12:06 +01001188 qdio_free(CARD_DDEV(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001189 if (recover_flag == CARD_STATE_UP)
1190 card->state = CARD_STATE_RECOVER;
1191 /* let user_space know that device is offline */
1192 kobject_uevent(&cgdev->dev.kobj, KOBJ_CHANGE);
Frank Blaschkac4949f02010-05-11 19:34:47 +00001193 mutex_unlock(&card->conf_mutex);
Ursula Braun9dc48cc2010-07-22 23:15:05 +00001194 mutex_unlock(&card->discipline_mutex);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001195 return 0;
1196}
1197
1198static int qeth_l2_set_offline(struct ccwgroup_device *cgdev)
1199{
1200 return __qeth_l2_set_offline(cgdev, 0);
1201}
1202
1203static int qeth_l2_recover(void *ptr)
1204{
1205 struct qeth_card *card;
1206 int rc = 0;
1207
1208 card = (struct qeth_card *) ptr;
Carsten Otte847a50f2010-06-21 22:57:05 +00001209 QETH_CARD_TEXT(card, 2, "recover1");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001210 if (!qeth_do_run_thread(card, QETH_RECOVER_THREAD))
1211 return 0;
Carsten Otte847a50f2010-06-21 22:57:05 +00001212 QETH_CARD_TEXT(card, 2, "recover2");
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001213 dev_warn(&card->gdev->dev,
1214 "A recovery process has been started for the device\n");
Stefan Raspl65d80132013-04-07 22:19:27 +00001215 qeth_set_recovery_task(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001216 __qeth_l2_set_offline(card->gdev, 1);
1217 rc = __qeth_l2_set_online(card->gdev, 1);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001218 if (!rc)
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001219 dev_info(&card->gdev->dev,
1220 "Device successfully recovered!\n");
Ursula Braun28a7e4c2008-09-19 12:56:03 +02001221 else {
Stefan Raspl0f547612013-01-21 02:30:20 +00001222 qeth_close_dev(card);
1223 dev_warn(&card->gdev->dev, "The qeth device driver "
Stefan Raspl2efaf5f2012-10-15 19:21:18 +00001224 "failed to recover an error on the device\n");
Ursula Braun28a7e4c2008-09-19 12:56:03 +02001225 }
Stefan Raspl65d80132013-04-07 22:19:27 +00001226 qeth_clear_recovery_task(card);
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00001227 qeth_clear_thread_start_bit(card, QETH_RECOVER_THREAD);
1228 qeth_clear_thread_running_bit(card, QETH_RECOVER_THREAD);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001229 return 0;
1230}
1231
1232static int __init qeth_l2_init(void)
1233{
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001234 pr_info("register layer 2 discipline\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001235 return 0;
1236}
1237
1238static void __exit qeth_l2_exit(void)
1239{
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001240 pr_info("unregister layer 2 discipline\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001241}
1242
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02001243static int qeth_l2_pm_suspend(struct ccwgroup_device *gdev)
1244{
1245 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
1246
1247 if (card->dev)
1248 netif_device_detach(card->dev);
1249 qeth_set_allowed_threads(card, 0, 1);
1250 wait_event(card->wait_q, qeth_threads_running(card, 0xffffffff) == 0);
1251 if (gdev->state == CCWGROUP_OFFLINE)
1252 return 0;
1253 if (card->state == CARD_STATE_UP) {
Frank Blaschka1da74b12011-05-12 18:45:02 +00001254 if (card->info.hwtrap)
1255 qeth_hw_trap(card, QETH_DIAGS_TRAP_DISARM);
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02001256 __qeth_l2_set_offline(card->gdev, 1);
1257 } else
1258 __qeth_l2_set_offline(card->gdev, 0);
1259 return 0;
1260}
1261
1262static int qeth_l2_pm_resume(struct ccwgroup_device *gdev)
1263{
1264 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
1265 int rc = 0;
1266
1267 if (gdev->state == CCWGROUP_OFFLINE)
1268 goto out;
1269
1270 if (card->state == CARD_STATE_RECOVER) {
1271 rc = __qeth_l2_set_online(card->gdev, 1);
1272 if (rc) {
Ursula Braun869da902010-03-08 20:36:56 +00001273 rtnl_lock();
1274 dev_close(card->dev);
1275 rtnl_unlock();
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02001276 }
1277 } else
1278 rc = __qeth_l2_set_online(card->gdev, 0);
1279out:
1280 qeth_set_allowed_threads(card, 0xffffffff, 0);
1281 if (card->dev)
1282 netif_device_attach(card->dev);
1283 if (rc)
1284 dev_warn(&card->gdev->dev, "The qeth device driver "
1285 "failed to recover an error on the device\n");
1286 return rc;
1287}
1288
Eugene Crosserc044dc22014-01-29 09:23:48 +01001289/* Returns zero if the command is successfully "consumed" */
1290static int qeth_l2_control_event(struct qeth_card *card,
1291 struct qeth_ipa_cmd *cmd)
1292{
1293 switch (cmd->hdr.command) {
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001294 case IPA_CMD_SETBRIDGEPORT_OSA:
1295 case IPA_CMD_SETBRIDGEPORT_IQD:
Eugene Crosserc044dc22014-01-29 09:23:48 +01001296 if (cmd->data.sbp.hdr.command_code ==
1297 IPA_SBP_BRIDGE_PORT_STATE_CHANGE) {
1298 qeth_bridge_state_change(card, cmd);
1299 return 0;
1300 } else
1301 return 1;
1302 case IPA_CMD_ADDRESS_CHANGE_NOTIF:
1303 qeth_bridge_host_event(card, cmd);
1304 return 0;
1305 default:
1306 return 1;
1307 }
1308}
1309
Sebastian Ottc041f2d4872012-05-15 18:02:21 +02001310struct qeth_discipline qeth_l2_discipline = {
Julian Wiedmann2d2ebb32017-05-10 19:07:52 +02001311 .devtype = &qeth_l2_devtype,
Sebastian Ottc041f2d4872012-05-15 18:02:21 +02001312 .start_poll = qeth_qdio_start_poll,
1313 .input_handler = (qdio_handler_t *) qeth_qdio_input_handler,
1314 .output_handler = (qdio_handler_t *) qeth_qdio_output_handler,
Julian Wiedmannd73ef322017-04-11 16:11:11 +02001315 .process_rx_buffer = qeth_l2_process_inbound_buffer,
Sebastian Ottc041f2d4872012-05-15 18:02:21 +02001316 .recover = qeth_l2_recover,
1317 .setup = qeth_l2_probe_device,
Frank Blaschka4a71df52008-02-15 09:19:42 +01001318 .remove = qeth_l2_remove_device,
1319 .set_online = qeth_l2_set_online,
1320 .set_offline = qeth_l2_set_offline,
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02001321 .freeze = qeth_l2_pm_suspend,
1322 .thaw = qeth_l2_pm_resume,
1323 .restore = qeth_l2_pm_resume,
Julian Wiedmann942d6982017-04-11 16:11:10 +02001324 .do_ioctl = NULL,
Eugene Crosserc044dc22014-01-29 09:23:48 +01001325 .control_event_handler = qeth_l2_control_event,
Frank Blaschka4a71df52008-02-15 09:19:42 +01001326};
Sebastian Ottc041f2d4872012-05-15 18:02:21 +02001327EXPORT_SYMBOL_GPL(qeth_l2_discipline);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001328
1329static int qeth_osn_send_control_data(struct qeth_card *card, int len,
1330 struct qeth_cmd_buffer *iob)
1331{
1332 unsigned long flags;
1333 int rc = 0;
1334
Carsten Otte847a50f2010-06-21 22:57:05 +00001335 QETH_CARD_TEXT(card, 5, "osndctrd");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001336
1337 wait_event(card->wait_q,
1338 atomic_cmpxchg(&card->write.irq_pending, 0, 1) == 0);
1339 qeth_prepare_control_data(card, len, iob);
Carsten Otte847a50f2010-06-21 22:57:05 +00001340 QETH_CARD_TEXT(card, 6, "osnoirqp");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001341 spin_lock_irqsave(get_ccwdev_lock(card->write.ccwdev), flags);
1342 rc = ccw_device_start(card->write.ccwdev, &card->write.ccw,
1343 (addr_t) iob, 0, 0);
1344 spin_unlock_irqrestore(get_ccwdev_lock(card->write.ccwdev), flags);
1345 if (rc) {
Frank Blaschka14cc21b2008-06-06 12:37:46 +02001346 QETH_DBF_MESSAGE(2, "qeth_osn_send_control_data: "
Frank Blaschka4a71df52008-02-15 09:19:42 +01001347 "ccw_device_start rc = %i\n", rc);
Carsten Otte847a50f2010-06-21 22:57:05 +00001348 QETH_CARD_TEXT_(card, 2, " err%d", rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001349 qeth_release_buffer(iob->channel, iob);
1350 atomic_set(&card->write.irq_pending, 0);
1351 wake_up(&card->wait_q);
1352 }
1353 return rc;
1354}
1355
1356static int qeth_osn_send_ipa_cmd(struct qeth_card *card,
1357 struct qeth_cmd_buffer *iob, int data_len)
1358{
1359 u16 s1, s2;
1360
Carsten Otte847a50f2010-06-21 22:57:05 +00001361 QETH_CARD_TEXT(card, 4, "osndipa");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001362
1363 qeth_prepare_ipa_cmd(card, iob, QETH_PROT_OSN2);
1364 s1 = (u16)(IPA_PDU_HEADER_SIZE + data_len);
1365 s2 = (u16)data_len;
1366 memcpy(QETH_IPA_PDU_LEN_TOTAL(iob->data), &s1, 2);
1367 memcpy(QETH_IPA_PDU_LEN_PDU1(iob->data), &s2, 2);
1368 memcpy(QETH_IPA_PDU_LEN_PDU2(iob->data), &s2, 2);
1369 memcpy(QETH_IPA_PDU_LEN_PDU3(iob->data), &s2, 2);
1370 return qeth_osn_send_control_data(card, s1, iob);
1371}
1372
1373int qeth_osn_assist(struct net_device *dev, void *data, int data_len)
1374{
1375 struct qeth_cmd_buffer *iob;
1376 struct qeth_card *card;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001377
Frank Blaschka4a71df52008-02-15 09:19:42 +01001378 if (!dev)
1379 return -ENODEV;
Heiko Carstens509e2562008-07-26 02:24:10 -07001380 card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001381 if (!card)
1382 return -ENODEV;
Carsten Otte847a50f2010-06-21 22:57:05 +00001383 QETH_CARD_TEXT(card, 2, "osnsdmc");
Eugene Crosserc3521252015-01-16 14:05:47 +01001384 if (!qeth_card_hw_is_reachable(card))
Frank Blaschka4a71df52008-02-15 09:19:42 +01001385 return -ENODEV;
1386 iob = qeth_wait_for_buffer(&card->write);
Julian Wiedmannff5caa72018-03-09 18:12:52 +01001387 memcpy(__ipa_cmd(iob), data, data_len);
1388 return qeth_osn_send_ipa_cmd(card, iob, data_len);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001389}
1390EXPORT_SYMBOL(qeth_osn_assist);
1391
1392int qeth_osn_register(unsigned char *read_dev_no, struct net_device **dev,
1393 int (*assist_cb)(struct net_device *, void *),
1394 int (*data_cb)(struct sk_buff *))
1395{
1396 struct qeth_card *card;
1397
Frank Blaschka4a71df52008-02-15 09:19:42 +01001398 *dev = qeth_l2_netdev_by_devno(read_dev_no);
1399 if (*dev == NULL)
1400 return -ENODEV;
Heiko Carstens509e2562008-07-26 02:24:10 -07001401 card = (*dev)->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001402 if (!card)
1403 return -ENODEV;
Carsten Otte847a50f2010-06-21 22:57:05 +00001404 QETH_CARD_TEXT(card, 2, "osnreg");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001405 if ((assist_cb == NULL) || (data_cb == NULL))
1406 return -EINVAL;
1407 card->osn_info.assist_cb = assist_cb;
1408 card->osn_info.data_cb = data_cb;
1409 return 0;
1410}
1411EXPORT_SYMBOL(qeth_osn_register);
1412
1413void qeth_osn_deregister(struct net_device *dev)
1414{
1415 struct qeth_card *card;
1416
Frank Blaschka4a71df52008-02-15 09:19:42 +01001417 if (!dev)
1418 return;
Heiko Carstens509e2562008-07-26 02:24:10 -07001419 card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001420 if (!card)
1421 return;
Carsten Otte847a50f2010-06-21 22:57:05 +00001422 QETH_CARD_TEXT(card, 2, "osndereg");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001423 card->osn_info.assist_cb = NULL;
1424 card->osn_info.data_cb = NULL;
1425 return;
1426}
1427EXPORT_SYMBOL(qeth_osn_deregister);
1428
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001429/* SETBRIDGEPORT support, async notifications */
1430
Eugene Crosser9f48b9d2014-01-14 15:54:13 +01001431enum qeth_an_event_type {anev_reg_unreg, anev_abort, anev_reset};
1432
1433/**
1434 * qeth_bridge_emit_host_event() - bridgeport address change notification
1435 * @card: qeth_card structure pointer, for udev events.
1436 * @evtype: "normal" register/unregister, or abort, or reset. For abort
1437 * and reset token and addr_lnid are unused and may be NULL.
1438 * @code: event bitmask: high order bit 0x80 value 1 means removal of an
1439 * object, 0 - addition of an object.
1440 * 0x01 - VLAN, 0x02 - MAC, 0x03 - VLAN and MAC.
1441 * @token: "network token" structure identifying physical address of the port.
1442 * @addr_lnid: pointer to structure with MAC address and VLAN ID.
1443 *
1444 * This function is called when registrations and deregistrations are
1445 * reported by the hardware, and also when notifications are enabled -
1446 * for all currently registered addresses.
1447 */
1448static void qeth_bridge_emit_host_event(struct qeth_card *card,
1449 enum qeth_an_event_type evtype,
1450 u8 code, struct net_if_token *token, struct mac_addr_lnid *addr_lnid)
1451{
1452 char str[7][32];
1453 char *env[8];
1454 int i = 0;
1455
1456 switch (evtype) {
1457 case anev_reg_unreg:
1458 snprintf(str[i], sizeof(str[i]), "BRIDGEDHOST=%s",
1459 (code & IPA_ADDR_CHANGE_CODE_REMOVAL)
1460 ? "deregister" : "register");
1461 env[i] = str[i]; i++;
1462 if (code & IPA_ADDR_CHANGE_CODE_VLANID) {
1463 snprintf(str[i], sizeof(str[i]), "VLAN=%d",
1464 addr_lnid->lnid);
1465 env[i] = str[i]; i++;
1466 }
1467 if (code & IPA_ADDR_CHANGE_CODE_MACADDR) {
Eugene Crosser9846e702015-09-18 16:06:48 +02001468 snprintf(str[i], sizeof(str[i]), "MAC=%pM",
Thomas Richter4d7def22015-09-18 16:06:51 +02001469 addr_lnid->mac);
Eugene Crosser9f48b9d2014-01-14 15:54:13 +01001470 env[i] = str[i]; i++;
1471 }
1472 snprintf(str[i], sizeof(str[i]), "NTOK_BUSID=%x.%x.%04x",
1473 token->cssid, token->ssid, token->devnum);
1474 env[i] = str[i]; i++;
1475 snprintf(str[i], sizeof(str[i]), "NTOK_IID=%02x", token->iid);
1476 env[i] = str[i]; i++;
1477 snprintf(str[i], sizeof(str[i]), "NTOK_CHPID=%02x",
1478 token->chpid);
1479 env[i] = str[i]; i++;
1480 snprintf(str[i], sizeof(str[i]), "NTOK_CHID=%04x", token->chid);
1481 env[i] = str[i]; i++;
1482 break;
1483 case anev_abort:
1484 snprintf(str[i], sizeof(str[i]), "BRIDGEDHOST=abort");
1485 env[i] = str[i]; i++;
1486 break;
1487 case anev_reset:
1488 snprintf(str[i], sizeof(str[i]), "BRIDGEDHOST=reset");
1489 env[i] = str[i]; i++;
1490 break;
1491 }
1492 env[i] = NULL;
1493 kobject_uevent_env(&card->gdev->dev.kobj, KOBJ_CHANGE, env);
1494}
1495
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001496struct qeth_bridge_state_data {
1497 struct work_struct worker;
1498 struct qeth_card *card;
1499 struct qeth_sbp_state_change qports;
1500};
1501
1502static void qeth_bridge_state_change_worker(struct work_struct *work)
1503{
1504 struct qeth_bridge_state_data *data =
1505 container_of(work, struct qeth_bridge_state_data, worker);
1506 /* We are only interested in the first entry - local port */
1507 struct qeth_sbp_port_entry *entry = &data->qports.entry[0];
1508 char env_locrem[32];
1509 char env_role[32];
1510 char env_state[32];
1511 char *env[] = {
1512 env_locrem,
1513 env_role,
1514 env_state,
1515 NULL
1516 };
1517
1518 /* Role should not change by itself, but if it did, */
1519 /* information from the hardware is authoritative. */
1520 mutex_lock(&data->card->conf_mutex);
1521 data->card->options.sbp.role = entry->role;
1522 mutex_unlock(&data->card->conf_mutex);
1523
1524 snprintf(env_locrem, sizeof(env_locrem), "BRIDGEPORT=statechange");
1525 snprintf(env_role, sizeof(env_role), "ROLE=%s",
1526 (entry->role == QETH_SBP_ROLE_NONE) ? "none" :
1527 (entry->role == QETH_SBP_ROLE_PRIMARY) ? "primary" :
1528 (entry->role == QETH_SBP_ROLE_SECONDARY) ? "secondary" :
1529 "<INVALID>");
1530 snprintf(env_state, sizeof(env_state), "STATE=%s",
1531 (entry->state == QETH_SBP_STATE_INACTIVE) ? "inactive" :
1532 (entry->state == QETH_SBP_STATE_STANDBY) ? "standby" :
1533 (entry->state == QETH_SBP_STATE_ACTIVE) ? "active" :
1534 "<INVALID>");
1535 kobject_uevent_env(&data->card->gdev->dev.kobj,
1536 KOBJ_CHANGE, env);
1537 kfree(data);
1538}
1539
Eugene Crosserc044dc22014-01-29 09:23:48 +01001540static void qeth_bridge_state_change(struct qeth_card *card,
1541 struct qeth_ipa_cmd *cmd)
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001542{
1543 struct qeth_sbp_state_change *qports =
1544 &cmd->data.sbp.data.state_change;
1545 struct qeth_bridge_state_data *data;
1546 int extrasize;
1547
1548 QETH_CARD_TEXT(card, 2, "brstchng");
1549 if (qports->entry_length != sizeof(struct qeth_sbp_port_entry)) {
Thomas Richter8a593142014-10-22 12:18:03 +02001550 QETH_CARD_TEXT_(card, 2, "BPsz%04x", qports->entry_length);
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001551 return;
1552 }
1553 extrasize = sizeof(struct qeth_sbp_port_entry) * qports->num_entries;
1554 data = kzalloc(sizeof(struct qeth_bridge_state_data) + extrasize,
1555 GFP_ATOMIC);
1556 if (!data) {
1557 QETH_CARD_TEXT(card, 2, "BPSalloc");
1558 return;
1559 }
1560 INIT_WORK(&data->worker, qeth_bridge_state_change_worker);
1561 data->card = card;
1562 memcpy(&data->qports, qports,
1563 sizeof(struct qeth_sbp_state_change) + extrasize);
1564 queue_work(qeth_wq, &data->worker);
1565}
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001566
Eugene Crosser9f48b9d2014-01-14 15:54:13 +01001567struct qeth_bridge_host_data {
1568 struct work_struct worker;
1569 struct qeth_card *card;
1570 struct qeth_ipacmd_addr_change hostevs;
1571};
1572
1573static void qeth_bridge_host_event_worker(struct work_struct *work)
1574{
1575 struct qeth_bridge_host_data *data =
1576 container_of(work, struct qeth_bridge_host_data, worker);
1577 int i;
1578
1579 if (data->hostevs.lost_event_mask) {
1580 dev_info(&data->card->gdev->dev,
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001581"Address notification from the Bridge Port stopped %s (%s)\n",
Eugene Crosser9f48b9d2014-01-14 15:54:13 +01001582 data->card->dev->name,
1583 (data->hostevs.lost_event_mask == 0x01)
1584 ? "Overflow"
1585 : (data->hostevs.lost_event_mask == 0x02)
1586 ? "Bridge port state change"
1587 : "Unknown reason");
1588 mutex_lock(&data->card->conf_mutex);
1589 data->card->options.sbp.hostnotification = 0;
1590 mutex_unlock(&data->card->conf_mutex);
1591 qeth_bridge_emit_host_event(data->card, anev_abort,
1592 0, NULL, NULL);
1593 } else
1594 for (i = 0; i < data->hostevs.num_entries; i++) {
1595 struct qeth_ipacmd_addr_change_entry *entry =
1596 &data->hostevs.entry[i];
1597 qeth_bridge_emit_host_event(data->card,
1598 anev_reg_unreg,
1599 entry->change_code,
1600 &entry->token, &entry->addr_lnid);
1601 }
1602 kfree(data);
1603}
1604
Eugene Crosserc044dc22014-01-29 09:23:48 +01001605static void qeth_bridge_host_event(struct qeth_card *card,
1606 struct qeth_ipa_cmd *cmd)
Eugene Crosser9f48b9d2014-01-14 15:54:13 +01001607{
1608 struct qeth_ipacmd_addr_change *hostevs =
1609 &cmd->data.addrchange;
1610 struct qeth_bridge_host_data *data;
1611 int extrasize;
1612
1613 QETH_CARD_TEXT(card, 2, "brhostev");
1614 if (cmd->hdr.return_code != 0x0000) {
1615 if (cmd->hdr.return_code == 0x0010) {
1616 if (hostevs->lost_event_mask == 0x00)
1617 hostevs->lost_event_mask = 0xff;
1618 } else {
1619 QETH_CARD_TEXT_(card, 2, "BPHe%04x",
1620 cmd->hdr.return_code);
1621 return;
1622 }
1623 }
1624 extrasize = sizeof(struct qeth_ipacmd_addr_change_entry) *
1625 hostevs->num_entries;
1626 data = kzalloc(sizeof(struct qeth_bridge_host_data) + extrasize,
1627 GFP_ATOMIC);
1628 if (!data) {
1629 QETH_CARD_TEXT(card, 2, "BPHalloc");
1630 return;
1631 }
1632 INIT_WORK(&data->worker, qeth_bridge_host_event_worker);
1633 data->card = card;
1634 memcpy(&data->hostevs, hostevs,
1635 sizeof(struct qeth_ipacmd_addr_change) + extrasize);
1636 queue_work(qeth_wq, &data->worker);
1637}
Eugene Crosser9f48b9d2014-01-14 15:54:13 +01001638
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001639/* SETBRIDGEPORT support; sending commands */
1640
1641struct _qeth_sbp_cbctl {
1642 u16 ipa_rc;
1643 u16 cmd_rc;
1644 union {
1645 u32 supported;
1646 struct {
1647 enum qeth_sbp_roles *role;
1648 enum qeth_sbp_states *state;
1649 } qports;
1650 } data;
1651};
1652
1653/**
1654 * qeth_bridgeport_makerc() - derive "traditional" error from hardware codes.
1655 * @card: qeth_card structure pointer, for debug messages.
1656 * @cbctl: state structure with hardware return codes.
1657 * @setcmd: IPA command code
1658 *
1659 * Returns negative errno-compatible error indication or 0 on success.
1660 */
1661static int qeth_bridgeport_makerc(struct qeth_card *card,
1662 struct _qeth_sbp_cbctl *cbctl, enum qeth_ipa_sbp_cmd setcmd)
1663{
1664 int rc;
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001665 int is_iqd = (card->info.type == QETH_CARD_TYPE_IQD);
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001666
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001667 if ((is_iqd && (cbctl->ipa_rc == IPA_RC_SUCCESS)) ||
1668 (!is_iqd && (cbctl->ipa_rc == cbctl->cmd_rc)))
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001669 switch (cbctl->cmd_rc) {
Kittipon Meesompop2063a5f2017-06-20 16:00:31 +02001670 case IPA_RC_SUCCESS:
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001671 rc = 0;
1672 break;
Kittipon Meesompop2063a5f2017-06-20 16:00:31 +02001673 case IPA_RC_L2_UNSUPPORTED_CMD:
1674 case IPA_RC_UNSUPPORTED_COMMAND:
Eugene Crosserffb95252015-05-18 14:27:58 +02001675 rc = -EOPNOTSUPP;
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001676 break;
Kittipon Meesompop2063a5f2017-06-20 16:00:31 +02001677 case IPA_RC_SBP_OSA_NOT_CONFIGURED:
1678 case IPA_RC_SBP_IQD_NOT_CONFIGURED:
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001679 rc = -ENODEV; /* maybe not the best code here? */
1680 dev_err(&card->gdev->dev,
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001681 "The device is not configured as a Bridge Port\n");
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001682 break;
Kittipon Meesompop2063a5f2017-06-20 16:00:31 +02001683 case IPA_RC_SBP_OSA_OS_MISMATCH:
1684 case IPA_RC_SBP_IQD_OS_MISMATCH:
Eugene Crosser1b05cf62016-06-16 16:18:51 +02001685 rc = -EPERM;
1686 dev_err(&card->gdev->dev,
1687 "A Bridge Port is already configured by a different operating system\n");
1688 break;
Kittipon Meesompop2063a5f2017-06-20 16:00:31 +02001689 case IPA_RC_SBP_OSA_ANO_DEV_PRIMARY:
1690 case IPA_RC_SBP_IQD_ANO_DEV_PRIMARY:
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001691 switch (setcmd) {
1692 case IPA_SBP_SET_PRIMARY_BRIDGE_PORT:
1693 rc = -EEXIST;
1694 dev_err(&card->gdev->dev,
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001695 "The LAN already has a primary Bridge Port\n");
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001696 break;
1697 case IPA_SBP_SET_SECONDARY_BRIDGE_PORT:
1698 rc = -EBUSY;
1699 dev_err(&card->gdev->dev,
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001700 "The device is already a primary Bridge Port\n");
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001701 break;
1702 default:
1703 rc = -EIO;
1704 }
1705 break;
Kittipon Meesompop2063a5f2017-06-20 16:00:31 +02001706 case IPA_RC_SBP_OSA_CURRENT_SECOND:
1707 case IPA_RC_SBP_IQD_CURRENT_SECOND:
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001708 rc = -EBUSY;
1709 dev_err(&card->gdev->dev,
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001710 "The device is already a secondary Bridge Port\n");
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001711 break;
Kittipon Meesompop2063a5f2017-06-20 16:00:31 +02001712 case IPA_RC_SBP_OSA_LIMIT_SECOND:
1713 case IPA_RC_SBP_IQD_LIMIT_SECOND:
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001714 rc = -EEXIST;
1715 dev_err(&card->gdev->dev,
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001716 "The LAN cannot have more secondary Bridge Ports\n");
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001717 break;
Kittipon Meesompop2063a5f2017-06-20 16:00:31 +02001718 case IPA_RC_SBP_OSA_CURRENT_PRIMARY:
1719 case IPA_RC_SBP_IQD_CURRENT_PRIMARY:
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001720 rc = -EBUSY;
1721 dev_err(&card->gdev->dev,
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001722 "The device is already a primary Bridge Port\n");
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001723 break;
Kittipon Meesompop2063a5f2017-06-20 16:00:31 +02001724 case IPA_RC_SBP_OSA_NOT_AUTHD_BY_ZMAN:
1725 case IPA_RC_SBP_IQD_NOT_AUTHD_BY_ZMAN:
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001726 rc = -EACCES;
1727 dev_err(&card->gdev->dev,
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001728 "The device is not authorized to be a Bridge Port\n");
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001729 break;
1730 default:
1731 rc = -EIO;
1732 }
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001733 else
1734 switch (cbctl->ipa_rc) {
1735 case IPA_RC_NOTSUPP:
Eugene Crosserffb95252015-05-18 14:27:58 +02001736 rc = -EOPNOTSUPP;
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001737 break;
1738 case IPA_RC_UNSUPPORTED_COMMAND:
Eugene Crosserffb95252015-05-18 14:27:58 +02001739 rc = -EOPNOTSUPP;
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001740 break;
1741 default:
1742 rc = -EIO;
1743 }
1744
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001745 if (rc) {
1746 QETH_CARD_TEXT_(card, 2, "SBPi%04x", cbctl->ipa_rc);
1747 QETH_CARD_TEXT_(card, 2, "SBPc%04x", cbctl->cmd_rc);
1748 }
1749 return rc;
1750}
1751
Julian Wiedmannd65626a2017-08-15 17:02:47 +02001752static struct qeth_cmd_buffer *qeth_sbp_build_cmd(struct qeth_card *card,
1753 enum qeth_ipa_sbp_cmd sbp_cmd,
1754 unsigned int cmd_length)
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001755{
Julian Wiedmannd65626a2017-08-15 17:02:47 +02001756 enum qeth_ipa_cmds ipa_cmd = (card->info.type == QETH_CARD_TYPE_IQD) ?
1757 IPA_CMD_SETBRIDGEPORT_IQD :
1758 IPA_CMD_SETBRIDGEPORT_OSA;
1759 struct qeth_cmd_buffer *iob;
1760 struct qeth_ipa_cmd *cmd;
1761
1762 iob = qeth_get_ipacmd_buffer(card, ipa_cmd, 0);
1763 if (!iob)
1764 return iob;
Julian Wiedmannff5caa72018-03-09 18:12:52 +01001765 cmd = __ipa_cmd(iob);
Julian Wiedmannd65626a2017-08-15 17:02:47 +02001766 cmd->data.sbp.hdr.cmdlength = sizeof(struct qeth_ipacmd_sbp_hdr) +
1767 cmd_length;
1768 cmd->data.sbp.hdr.command_code = sbp_cmd;
1769 cmd->data.sbp.hdr.used_total = 1;
1770 cmd->data.sbp.hdr.seq_no = 1;
1771 return iob;
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001772}
1773
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001774static int qeth_bridgeport_query_support_cb(struct qeth_card *card,
1775 struct qeth_reply *reply, unsigned long data)
1776{
1777 struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *) data;
1778 struct _qeth_sbp_cbctl *cbctl = (struct _qeth_sbp_cbctl *)reply->param;
1779 QETH_CARD_TEXT(card, 2, "brqsupcb");
1780 cbctl->ipa_rc = cmd->hdr.return_code;
1781 cbctl->cmd_rc = cmd->data.sbp.hdr.return_code;
1782 if ((cbctl->ipa_rc == 0) && (cbctl->cmd_rc == 0)) {
1783 cbctl->data.supported =
1784 cmd->data.sbp.data.query_cmds_supp.supported_cmds;
1785 } else {
1786 cbctl->data.supported = 0;
1787 }
1788 return 0;
1789}
1790
1791/**
1792 * qeth_bridgeport_query_support() - store bitmask of supported subfunctions.
1793 * @card: qeth_card structure pointer.
1794 *
1795 * Sets bitmask of supported setbridgeport subfunctions in the qeth_card
1796 * strucutre: card->options.sbp.supported_funcs.
1797 */
Eugene Crosserc044dc22014-01-29 09:23:48 +01001798static void qeth_bridgeport_query_support(struct qeth_card *card)
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001799{
1800 struct qeth_cmd_buffer *iob;
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001801 struct _qeth_sbp_cbctl cbctl;
1802
1803 QETH_CARD_TEXT(card, 2, "brqsuppo");
Julian Wiedmannd65626a2017-08-15 17:02:47 +02001804 iob = qeth_sbp_build_cmd(card, IPA_SBP_QUERY_COMMANDS_SUPPORTED,
1805 sizeof(struct qeth_sbp_query_cmds_supp));
Thomas Richter1aec42b2015-01-21 13:39:10 +01001806 if (!iob)
1807 return;
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001808 if (qeth_send_ipa_cmd(card, iob, qeth_bridgeport_query_support_cb,
1809 (void *)&cbctl) ||
1810 qeth_bridgeport_makerc(card, &cbctl,
1811 IPA_SBP_QUERY_COMMANDS_SUPPORTED)) {
1812 /* non-zero makerc signifies failure, and produce messages */
1813 card->options.sbp.role = QETH_SBP_ROLE_NONE;
1814 return;
1815 }
1816 card->options.sbp.supported_funcs = cbctl.data.supported;
1817}
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001818
1819static int qeth_bridgeport_query_ports_cb(struct qeth_card *card,
1820 struct qeth_reply *reply, unsigned long data)
1821{
1822 struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *) data;
1823 struct qeth_sbp_query_ports *qports = &cmd->data.sbp.data.query_ports;
1824 struct _qeth_sbp_cbctl *cbctl = (struct _qeth_sbp_cbctl *)reply->param;
1825
1826 QETH_CARD_TEXT(card, 2, "brqprtcb");
1827 cbctl->ipa_rc = cmd->hdr.return_code;
1828 cbctl->cmd_rc = cmd->data.sbp.hdr.return_code;
1829 if ((cbctl->ipa_rc != 0) || (cbctl->cmd_rc != 0))
1830 return 0;
1831 if (qports->entry_length != sizeof(struct qeth_sbp_port_entry)) {
1832 cbctl->cmd_rc = 0xffff;
1833 QETH_CARD_TEXT_(card, 2, "SBPs%04x", qports->entry_length);
1834 return 0;
1835 }
1836 /* first entry contains the state of the local port */
1837 if (qports->num_entries > 0) {
1838 if (cbctl->data.qports.role)
1839 *cbctl->data.qports.role = qports->entry[0].role;
1840 if (cbctl->data.qports.state)
1841 *cbctl->data.qports.state = qports->entry[0].state;
1842 }
1843 return 0;
1844}
1845
1846/**
1847 * qeth_bridgeport_query_ports() - query local bridgeport status.
1848 * @card: qeth_card structure pointer.
1849 * @role: Role of the port: 0-none, 1-primary, 2-secondary.
1850 * @state: State of the port: 0-inactive, 1-standby, 2-active.
1851 *
1852 * Returns negative errno-compatible error indication or 0 on success.
1853 *
1854 * 'role' and 'state' are not updated in case of hardware operation failure.
1855 */
1856int qeth_bridgeport_query_ports(struct qeth_card *card,
1857 enum qeth_sbp_roles *role, enum qeth_sbp_states *state)
1858{
1859 int rc = 0;
1860 struct qeth_cmd_buffer *iob;
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001861 struct _qeth_sbp_cbctl cbctl = {
1862 .data = {
1863 .qports = {
1864 .role = role,
1865 .state = state,
1866 },
1867 },
1868 };
1869
1870 QETH_CARD_TEXT(card, 2, "brqports");
1871 if (!(card->options.sbp.supported_funcs & IPA_SBP_QUERY_BRIDGE_PORTS))
1872 return -EOPNOTSUPP;
Julian Wiedmannd65626a2017-08-15 17:02:47 +02001873 iob = qeth_sbp_build_cmd(card, IPA_SBP_QUERY_BRIDGE_PORTS, 0);
Thomas Richter1aec42b2015-01-21 13:39:10 +01001874 if (!iob)
1875 return -ENOMEM;
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001876 rc = qeth_send_ipa_cmd(card, iob, qeth_bridgeport_query_ports_cb,
1877 (void *)&cbctl);
Eugene Crosserc88394e2015-05-18 14:27:53 +02001878 if (rc < 0)
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001879 return rc;
Eugene Crosserc88394e2015-05-18 14:27:53 +02001880 return qeth_bridgeport_makerc(card, &cbctl, IPA_SBP_QUERY_BRIDGE_PORTS);
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001881}
1882EXPORT_SYMBOL_GPL(qeth_bridgeport_query_ports);
1883
1884static int qeth_bridgeport_set_cb(struct qeth_card *card,
1885 struct qeth_reply *reply, unsigned long data)
1886{
1887 struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *)data;
1888 struct _qeth_sbp_cbctl *cbctl = (struct _qeth_sbp_cbctl *)reply->param;
1889 QETH_CARD_TEXT(card, 2, "brsetrcb");
1890 cbctl->ipa_rc = cmd->hdr.return_code;
1891 cbctl->cmd_rc = cmd->data.sbp.hdr.return_code;
1892 return 0;
1893}
1894
1895/**
1896 * qeth_bridgeport_setrole() - Assign primary role to the port.
1897 * @card: qeth_card structure pointer.
1898 * @role: Role to assign.
1899 *
1900 * Returns negative errno-compatible error indication or 0 on success.
1901 */
1902int qeth_bridgeport_setrole(struct qeth_card *card, enum qeth_sbp_roles role)
1903{
1904 int rc = 0;
1905 int cmdlength;
1906 struct qeth_cmd_buffer *iob;
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001907 struct _qeth_sbp_cbctl cbctl;
1908 enum qeth_ipa_sbp_cmd setcmd;
1909
1910 QETH_CARD_TEXT(card, 2, "brsetrol");
1911 switch (role) {
1912 case QETH_SBP_ROLE_NONE:
1913 setcmd = IPA_SBP_RESET_BRIDGE_PORT_ROLE;
Julian Wiedmannd65626a2017-08-15 17:02:47 +02001914 cmdlength = sizeof(struct qeth_sbp_reset_role);
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001915 break;
1916 case QETH_SBP_ROLE_PRIMARY:
1917 setcmd = IPA_SBP_SET_PRIMARY_BRIDGE_PORT;
Julian Wiedmannd65626a2017-08-15 17:02:47 +02001918 cmdlength = sizeof(struct qeth_sbp_set_primary);
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001919 break;
1920 case QETH_SBP_ROLE_SECONDARY:
1921 setcmd = IPA_SBP_SET_SECONDARY_BRIDGE_PORT;
Julian Wiedmannd65626a2017-08-15 17:02:47 +02001922 cmdlength = sizeof(struct qeth_sbp_set_secondary);
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001923 break;
1924 default:
1925 return -EINVAL;
1926 }
1927 if (!(card->options.sbp.supported_funcs & setcmd))
1928 return -EOPNOTSUPP;
Julian Wiedmannd65626a2017-08-15 17:02:47 +02001929 iob = qeth_sbp_build_cmd(card, setcmd, cmdlength);
Thomas Richter1aec42b2015-01-21 13:39:10 +01001930 if (!iob)
1931 return -ENOMEM;
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001932 rc = qeth_send_ipa_cmd(card, iob, qeth_bridgeport_set_cb,
1933 (void *)&cbctl);
Eugene Crosserc88394e2015-05-18 14:27:53 +02001934 if (rc < 0)
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001935 return rc;
Eugene Crosserc88394e2015-05-18 14:27:53 +02001936 return qeth_bridgeport_makerc(card, &cbctl, setcmd);
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001937}
1938
Eugene Crosser9f48b9d2014-01-14 15:54:13 +01001939/**
1940 * qeth_anset_makerc() - derive "traditional" error from hardware codes.
1941 * @card: qeth_card structure pointer, for debug messages.
1942 *
1943 * Returns negative errno-compatible error indication or 0 on success.
1944 */
1945static int qeth_anset_makerc(struct qeth_card *card, int pnso_rc, u16 response)
1946{
1947 int rc;
1948
1949 if (pnso_rc == 0)
1950 switch (response) {
1951 case 0x0001:
1952 rc = 0;
1953 break;
1954 case 0x0004:
1955 case 0x0100:
1956 case 0x0106:
Eugene Crosserffb95252015-05-18 14:27:58 +02001957 rc = -EOPNOTSUPP;
Eugene Crosser9f48b9d2014-01-14 15:54:13 +01001958 dev_err(&card->gdev->dev,
1959 "Setting address notification failed\n");
1960 break;
1961 case 0x0107:
1962 rc = -EAGAIN;
1963 break;
1964 default:
1965 rc = -EIO;
1966 }
1967 else
1968 rc = -EIO;
1969
1970 if (rc) {
1971 QETH_CARD_TEXT_(card, 2, "SBPp%04x", pnso_rc);
1972 QETH_CARD_TEXT_(card, 2, "SBPr%04x", response);
1973 }
1974 return rc;
1975}
1976
1977static void qeth_bridgeport_an_set_cb(void *priv,
1978 enum qdio_brinfo_entry_type type, void *entry)
1979{
1980 struct qeth_card *card = (struct qeth_card *)priv;
1981 struct qdio_brinfo_entry_l2 *l2entry;
1982 u8 code;
1983
1984 if (type != l2_addr_lnid) {
1985 WARN_ON_ONCE(1);
1986 return;
1987 }
1988
1989 l2entry = (struct qdio_brinfo_entry_l2 *)entry;
1990 code = IPA_ADDR_CHANGE_CODE_MACADDR;
1991 if (l2entry->addr_lnid.lnid)
1992 code |= IPA_ADDR_CHANGE_CODE_VLANID;
1993 qeth_bridge_emit_host_event(card, anev_reg_unreg, code,
1994 (struct net_if_token *)&l2entry->nit,
1995 (struct mac_addr_lnid *)&l2entry->addr_lnid);
1996}
1997
1998/**
1999 * qeth_bridgeport_an_set() - Enable or disable bridgeport address notification
2000 * @card: qeth_card structure pointer.
2001 * @enable: 0 - disable, non-zero - enable notifications
2002 *
2003 * Returns negative errno-compatible error indication or 0 on success.
2004 *
2005 * On enable, emits a series of address notifications udev events for all
2006 * currently registered hosts.
2007 */
2008int qeth_bridgeport_an_set(struct qeth_card *card, int enable)
2009{
2010 int rc;
2011 u16 response;
2012 struct ccw_device *ddev;
2013 struct subchannel_id schid;
2014
2015 if (!card)
2016 return -EINVAL;
2017 if (!card->options.sbp.supported_funcs)
2018 return -EOPNOTSUPP;
2019 ddev = CARD_DDEV(card);
2020 ccw_device_get_schid(ddev, &schid);
2021
2022 if (enable) {
2023 qeth_bridge_emit_host_event(card, anev_reset, 0, NULL, NULL);
2024 rc = qdio_pnso_brinfo(schid, 1, &response,
2025 qeth_bridgeport_an_set_cb, card);
2026 } else
2027 rc = qdio_pnso_brinfo(schid, 0, &response, NULL, NULL);
2028 return qeth_anset_makerc(card, rc, response);
2029}
2030EXPORT_SYMBOL_GPL(qeth_bridgeport_an_set);
2031
Hans Wippelcaa1f0b2017-09-18 21:18:15 +02002032static bool qeth_bridgeport_is_in_use(struct qeth_card *card)
2033{
2034 return (card->options.sbp.role || card->options.sbp.reflect_promisc ||
2035 card->options.sbp.hostnotification);
2036}
2037
Hans Wippela45b3fa2017-09-18 21:18:14 +02002038/* VNIC Characteristics support */
2039
2040/* handle VNICC IPA command return codes; convert to error codes */
2041static int qeth_l2_vnicc_makerc(struct qeth_card *card, int ipa_rc)
2042{
2043 int rc;
2044
2045 switch (ipa_rc) {
2046 case IPA_RC_SUCCESS:
2047 return ipa_rc;
2048 case IPA_RC_L2_UNSUPPORTED_CMD:
2049 case IPA_RC_NOTSUPP:
2050 rc = -EOPNOTSUPP;
2051 break;
2052 case IPA_RC_VNICC_OOSEQ:
2053 rc = -EALREADY;
2054 break;
2055 case IPA_RC_VNICC_VNICBP:
2056 rc = -EBUSY;
2057 break;
2058 case IPA_RC_L2_ADDR_TABLE_FULL:
2059 rc = -ENOSPC;
2060 break;
2061 case IPA_RC_L2_MAC_NOT_AUTH_BY_ADP:
2062 rc = -EACCES;
2063 break;
2064 default:
2065 rc = -EIO;
2066 }
2067
2068 QETH_CARD_TEXT_(card, 2, "err%04x", ipa_rc);
2069 return rc;
2070}
2071
2072/* generic VNICC request call back control */
2073struct _qeth_l2_vnicc_request_cbctl {
2074 u32 sub_cmd;
Hans Wippelcaa1f0b2017-09-18 21:18:15 +02002075 struct {
2076 u32 vnic_char;
Hans Wippel349d13d2017-09-18 21:18:16 +02002077 u32 timeout;
Hans Wippelcaa1f0b2017-09-18 21:18:15 +02002078 } param;
2079 struct {
Hans Wippel349d13d2017-09-18 21:18:16 +02002080 union{
2081 u32 *sup_cmds;
2082 u32 *timeout;
2083 };
Hans Wippelcaa1f0b2017-09-18 21:18:15 +02002084 } result;
Hans Wippela45b3fa2017-09-18 21:18:14 +02002085};
2086
2087/* generic VNICC request call back */
2088static int qeth_l2_vnicc_request_cb(struct qeth_card *card,
2089 struct qeth_reply *reply,
2090 unsigned long data)
2091{
Hans Wippelcaa1f0b2017-09-18 21:18:15 +02002092 struct _qeth_l2_vnicc_request_cbctl *cbctl =
2093 (struct _qeth_l2_vnicc_request_cbctl *) reply->param;
Hans Wippela45b3fa2017-09-18 21:18:14 +02002094 struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *) data;
2095 struct qeth_ipacmd_vnicc *rep = &cmd->data.vnicc;
2096
2097 QETH_CARD_TEXT(card, 2, "vniccrcb");
2098 if (cmd->hdr.return_code)
2099 return 0;
2100 /* return results to caller */
2101 card->options.vnicc.sup_chars = rep->hdr.sup;
2102 card->options.vnicc.cur_chars = rep->hdr.cur;
2103
Hans Wippelcaa1f0b2017-09-18 21:18:15 +02002104 if (cbctl->sub_cmd == IPA_VNICC_QUERY_CMDS)
2105 *cbctl->result.sup_cmds = rep->query_cmds.sup_cmds;
2106
Hans Wippel349d13d2017-09-18 21:18:16 +02002107 if (cbctl->sub_cmd == IPA_VNICC_GET_TIMEOUT)
2108 *cbctl->result.timeout = rep->getset_timeout.timeout;
2109
Hans Wippela45b3fa2017-09-18 21:18:14 +02002110 return 0;
2111}
2112
2113/* generic VNICC request */
2114static int qeth_l2_vnicc_request(struct qeth_card *card,
2115 struct _qeth_l2_vnicc_request_cbctl *cbctl)
2116{
2117 struct qeth_ipacmd_vnicc *req;
2118 struct qeth_cmd_buffer *iob;
2119 struct qeth_ipa_cmd *cmd;
2120 int rc;
2121
2122 QETH_CARD_TEXT(card, 2, "vniccreq");
2123
2124 /* get new buffer for request */
2125 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_VNICC, 0);
2126 if (!iob)
2127 return -ENOMEM;
2128
2129 /* create header for request */
Julian Wiedmannff5caa72018-03-09 18:12:52 +01002130 cmd = __ipa_cmd(iob);
Hans Wippela45b3fa2017-09-18 21:18:14 +02002131 req = &cmd->data.vnicc;
2132
2133 /* create sub command header for request */
2134 req->sub_hdr.data_length = sizeof(req->sub_hdr);
2135 req->sub_hdr.sub_command = cbctl->sub_cmd;
2136
2137 /* create sub command specific request fields */
2138 switch (cbctl->sub_cmd) {
2139 case IPA_VNICC_QUERY_CHARS:
2140 break;
Hans Wippelcaa1f0b2017-09-18 21:18:15 +02002141 case IPA_VNICC_QUERY_CMDS:
2142 req->sub_hdr.data_length += sizeof(req->query_cmds);
2143 req->query_cmds.vnic_char = cbctl->param.vnic_char;
2144 break;
2145 case IPA_VNICC_ENABLE:
2146 case IPA_VNICC_DISABLE:
2147 req->sub_hdr.data_length += sizeof(req->set_char);
2148 req->set_char.vnic_char = cbctl->param.vnic_char;
2149 break;
Hans Wippel349d13d2017-09-18 21:18:16 +02002150 case IPA_VNICC_SET_TIMEOUT:
2151 req->getset_timeout.timeout = cbctl->param.timeout;
2152 /* fallthrough */
2153 case IPA_VNICC_GET_TIMEOUT:
2154 req->sub_hdr.data_length += sizeof(req->getset_timeout);
2155 req->getset_timeout.vnic_char = cbctl->param.vnic_char;
2156 break;
Hans Wippela45b3fa2017-09-18 21:18:14 +02002157 default:
2158 qeth_release_buffer(iob->channel, iob);
2159 return -EOPNOTSUPP;
2160 }
2161
2162 /* send request */
2163 rc = qeth_send_ipa_cmd(card, iob, qeth_l2_vnicc_request_cb,
2164 (void *) cbctl);
2165
2166 return qeth_l2_vnicc_makerc(card, rc);
2167}
2168
2169/* VNICC query VNIC characteristics request */
2170static int qeth_l2_vnicc_query_chars(struct qeth_card *card)
2171{
2172 struct _qeth_l2_vnicc_request_cbctl cbctl;
2173
2174 /* prepare callback control */
2175 cbctl.sub_cmd = IPA_VNICC_QUERY_CHARS;
2176
2177 QETH_CARD_TEXT(card, 2, "vniccqch");
2178 return qeth_l2_vnicc_request(card, &cbctl);
2179}
2180
Hans Wippelcaa1f0b2017-09-18 21:18:15 +02002181/* VNICC query sub commands request */
2182static int qeth_l2_vnicc_query_cmds(struct qeth_card *card, u32 vnic_char,
2183 u32 *sup_cmds)
2184{
2185 struct _qeth_l2_vnicc_request_cbctl cbctl;
2186
2187 /* prepare callback control */
2188 cbctl.sub_cmd = IPA_VNICC_QUERY_CMDS;
2189 cbctl.param.vnic_char = vnic_char;
2190 cbctl.result.sup_cmds = sup_cmds;
2191
2192 QETH_CARD_TEXT(card, 2, "vniccqcm");
2193 return qeth_l2_vnicc_request(card, &cbctl);
2194}
2195
2196/* VNICC enable/disable characteristic request */
2197static int qeth_l2_vnicc_set_char(struct qeth_card *card, u32 vnic_char,
2198 u32 cmd)
2199{
2200 struct _qeth_l2_vnicc_request_cbctl cbctl;
2201
2202 /* prepare callback control */
2203 cbctl.sub_cmd = cmd;
2204 cbctl.param.vnic_char = vnic_char;
2205
2206 QETH_CARD_TEXT(card, 2, "vniccedc");
2207 return qeth_l2_vnicc_request(card, &cbctl);
2208}
2209
Hans Wippel349d13d2017-09-18 21:18:16 +02002210/* VNICC get/set timeout for characteristic request */
2211static int qeth_l2_vnicc_getset_timeout(struct qeth_card *card, u32 vnicc,
2212 u32 cmd, u32 *timeout)
2213{
2214 struct _qeth_l2_vnicc_request_cbctl cbctl;
2215
2216 /* prepare callback control */
2217 cbctl.sub_cmd = cmd;
2218 cbctl.param.vnic_char = vnicc;
2219 if (cmd == IPA_VNICC_SET_TIMEOUT)
2220 cbctl.param.timeout = *timeout;
2221 if (cmd == IPA_VNICC_GET_TIMEOUT)
2222 cbctl.result.timeout = timeout;
2223
2224 QETH_CARD_TEXT(card, 2, "vniccgst");
2225 return qeth_l2_vnicc_request(card, &cbctl);
2226}
2227
Hans Wippelcaa1f0b2017-09-18 21:18:15 +02002228/* set current VNICC flag state; called from sysfs store function */
2229int qeth_l2_vnicc_set_state(struct qeth_card *card, u32 vnicc, bool state)
2230{
2231 int rc = 0;
2232 u32 cmd;
2233
2234 QETH_CARD_TEXT(card, 2, "vniccsch");
2235
2236 /* do not change anything if BridgePort is enabled */
2237 if (qeth_bridgeport_is_in_use(card))
2238 return -EBUSY;
2239
2240 /* check if characteristic and enable/disable are supported */
2241 if (!(card->options.vnicc.sup_chars & vnicc) ||
2242 !(card->options.vnicc.set_char_sup & vnicc))
2243 return -EOPNOTSUPP;
2244
2245 /* set enable/disable command and store wanted characteristic */
2246 if (state) {
2247 cmd = IPA_VNICC_ENABLE;
2248 card->options.vnicc.wanted_chars |= vnicc;
2249 } else {
2250 cmd = IPA_VNICC_DISABLE;
2251 card->options.vnicc.wanted_chars &= ~vnicc;
2252 }
2253
2254 /* do we need to do anything? */
2255 if (card->options.vnicc.cur_chars == card->options.vnicc.wanted_chars)
2256 return rc;
2257
2258 /* if card is not ready, simply stop here */
2259 if (!qeth_card_hw_is_reachable(card)) {
2260 if (state)
2261 card->options.vnicc.cur_chars |= vnicc;
2262 else
2263 card->options.vnicc.cur_chars &= ~vnicc;
2264 return rc;
2265 }
2266
2267 rc = qeth_l2_vnicc_set_char(card, vnicc, cmd);
2268 if (rc)
2269 card->options.vnicc.wanted_chars =
2270 card->options.vnicc.cur_chars;
Hans Wippel349d13d2017-09-18 21:18:16 +02002271 else {
2272 /* successful online VNICC change; handle special cases */
2273 if (state && vnicc == QETH_VNICC_RX_BCAST)
2274 card->options.vnicc.rx_bcast_enabled = true;
2275 if (!state && vnicc == QETH_VNICC_LEARNING)
2276 qeth_l2_vnicc_recover_timeout(card, vnicc,
2277 &card->options.vnicc.learning_timeout);
2278 }
Hans Wippelcaa1f0b2017-09-18 21:18:15 +02002279
2280 return rc;
2281}
2282
2283/* get current VNICC flag state; called from sysfs show function */
2284int qeth_l2_vnicc_get_state(struct qeth_card *card, u32 vnicc, bool *state)
2285{
2286 int rc = 0;
2287
2288 QETH_CARD_TEXT(card, 2, "vniccgch");
2289
2290 /* do not get anything if BridgePort is enabled */
2291 if (qeth_bridgeport_is_in_use(card))
2292 return -EBUSY;
2293
2294 /* check if characteristic is supported */
2295 if (!(card->options.vnicc.sup_chars & vnicc))
2296 return -EOPNOTSUPP;
2297
2298 /* if card is ready, query current VNICC state */
2299 if (qeth_card_hw_is_reachable(card))
2300 rc = qeth_l2_vnicc_query_chars(card);
2301
2302 *state = (card->options.vnicc.cur_chars & vnicc) ? true : false;
2303 return rc;
2304}
2305
Hans Wippel349d13d2017-09-18 21:18:16 +02002306/* set VNICC timeout; called from sysfs store function. Currently, only learning
2307 * supports timeout
2308 */
2309int qeth_l2_vnicc_set_timeout(struct qeth_card *card, u32 timeout)
2310{
2311 int rc = 0;
2312
2313 QETH_CARD_TEXT(card, 2, "vniccsto");
2314
2315 /* do not change anything if BridgePort is enabled */
2316 if (qeth_bridgeport_is_in_use(card))
2317 return -EBUSY;
2318
2319 /* check if characteristic and set_timeout are supported */
2320 if (!(card->options.vnicc.sup_chars & QETH_VNICC_LEARNING) ||
2321 !(card->options.vnicc.getset_timeout_sup & QETH_VNICC_LEARNING))
2322 return -EOPNOTSUPP;
2323
2324 /* do we need to do anything? */
2325 if (card->options.vnicc.learning_timeout == timeout)
2326 return rc;
2327
2328 /* if card is not ready, simply store the value internally and return */
2329 if (!qeth_card_hw_is_reachable(card)) {
2330 card->options.vnicc.learning_timeout = timeout;
2331 return rc;
2332 }
2333
2334 /* send timeout value to card; if successful, store value internally */
2335 rc = qeth_l2_vnicc_getset_timeout(card, QETH_VNICC_LEARNING,
2336 IPA_VNICC_SET_TIMEOUT, &timeout);
2337 if (!rc)
2338 card->options.vnicc.learning_timeout = timeout;
2339
2340 return rc;
2341}
2342
2343/* get current VNICC timeout; called from sysfs show function. Currently, only
2344 * learning supports timeout
2345 */
2346int qeth_l2_vnicc_get_timeout(struct qeth_card *card, u32 *timeout)
2347{
2348 int rc = 0;
2349
2350 QETH_CARD_TEXT(card, 2, "vniccgto");
2351
2352 /* do not get anything if BridgePort is enabled */
2353 if (qeth_bridgeport_is_in_use(card))
2354 return -EBUSY;
2355
2356 /* check if characteristic and get_timeout are supported */
2357 if (!(card->options.vnicc.sup_chars & QETH_VNICC_LEARNING) ||
2358 !(card->options.vnicc.getset_timeout_sup & QETH_VNICC_LEARNING))
2359 return -EOPNOTSUPP;
2360 /* if card is ready, get timeout. Otherwise, just return stored value */
2361 *timeout = card->options.vnicc.learning_timeout;
2362 if (qeth_card_hw_is_reachable(card))
2363 rc = qeth_l2_vnicc_getset_timeout(card, QETH_VNICC_LEARNING,
2364 IPA_VNICC_GET_TIMEOUT,
2365 timeout);
2366
2367 return rc;
2368}
2369
Hans Wippelcaa1f0b2017-09-18 21:18:15 +02002370/* check if VNICC is currently enabled */
2371bool qeth_l2_vnicc_is_in_use(struct qeth_card *card)
2372{
2373 /* if everything is turned off, VNICC is not active */
2374 if (!card->options.vnicc.cur_chars)
2375 return false;
2376 /* default values are only OK if rx_bcast was not enabled by user
2377 * or the card is offline.
2378 */
2379 if (card->options.vnicc.cur_chars == QETH_VNICC_DEFAULT) {
2380 if (!card->options.vnicc.rx_bcast_enabled ||
2381 !qeth_card_hw_is_reachable(card))
2382 return false;
2383 }
2384 return true;
2385}
2386
Hans Wippel349d13d2017-09-18 21:18:16 +02002387/* recover user timeout setting */
2388static bool qeth_l2_vnicc_recover_timeout(struct qeth_card *card, u32 vnicc,
2389 u32 *timeout)
2390{
2391 if (card->options.vnicc.sup_chars & vnicc &&
2392 card->options.vnicc.getset_timeout_sup & vnicc &&
2393 !qeth_l2_vnicc_getset_timeout(card, vnicc, IPA_VNICC_SET_TIMEOUT,
2394 timeout))
2395 return false;
2396 *timeout = QETH_VNICC_DEFAULT_TIMEOUT;
2397 return true;
2398}
2399
Hans Wippelcaa1f0b2017-09-18 21:18:15 +02002400/* recover user characteristic setting */
2401static bool qeth_l2_vnicc_recover_char(struct qeth_card *card, u32 vnicc,
2402 bool enable)
2403{
2404 u32 cmd = enable ? IPA_VNICC_ENABLE : IPA_VNICC_DISABLE;
2405
2406 if (card->options.vnicc.sup_chars & vnicc &&
2407 card->options.vnicc.set_char_sup & vnicc &&
2408 !qeth_l2_vnicc_set_char(card, vnicc, cmd))
2409 return false;
2410 card->options.vnicc.wanted_chars &= ~vnicc;
2411 card->options.vnicc.wanted_chars |= QETH_VNICC_DEFAULT & vnicc;
2412 return true;
2413}
2414
Hans Wippela45b3fa2017-09-18 21:18:14 +02002415/* (re-)initialize VNICC */
2416static void qeth_l2_vnicc_init(struct qeth_card *card)
2417{
Hans Wippel349d13d2017-09-18 21:18:16 +02002418 u32 *timeout = &card->options.vnicc.learning_timeout;
Hans Wippelcaa1f0b2017-09-18 21:18:15 +02002419 unsigned int chars_len, i;
2420 unsigned long chars_tmp;
2421 u32 sup_cmds, vnicc;
2422 bool enable, error;
2423
Hans Wippela45b3fa2017-09-18 21:18:14 +02002424 QETH_CARD_TEXT(card, 2, "vniccini");
Hans Wippelcaa1f0b2017-09-18 21:18:15 +02002425 /* reset rx_bcast */
2426 card->options.vnicc.rx_bcast_enabled = 0;
Hans Wippela45b3fa2017-09-18 21:18:14 +02002427 /* initial query and storage of VNIC characteristics */
2428 if (qeth_l2_vnicc_query_chars(card)) {
Hans Wippel349d13d2017-09-18 21:18:16 +02002429 if (card->options.vnicc.wanted_chars != QETH_VNICC_DEFAULT ||
2430 *timeout != QETH_VNICC_DEFAULT_TIMEOUT)
Hans Wippelcaa1f0b2017-09-18 21:18:15 +02002431 dev_err(&card->gdev->dev, "Configuring the VNIC characteristics failed\n");
2432 /* fail quietly if user didn't change the default config */
Hans Wippela45b3fa2017-09-18 21:18:14 +02002433 card->options.vnicc.sup_chars = 0;
2434 card->options.vnicc.cur_chars = 0;
Hans Wippelcaa1f0b2017-09-18 21:18:15 +02002435 card->options.vnicc.wanted_chars = QETH_VNICC_DEFAULT;
2436 return;
Hans Wippela45b3fa2017-09-18 21:18:14 +02002437 }
Hans Wippelcaa1f0b2017-09-18 21:18:15 +02002438 /* get supported commands for each supported characteristic */
2439 chars_tmp = card->options.vnicc.sup_chars;
2440 chars_len = sizeof(card->options.vnicc.sup_chars) * BITS_PER_BYTE;
2441 for_each_set_bit(i, &chars_tmp, chars_len) {
2442 vnicc = BIT(i);
2443 qeth_l2_vnicc_query_cmds(card, vnicc, &sup_cmds);
Hans Wippel349d13d2017-09-18 21:18:16 +02002444 if (!(sup_cmds & IPA_VNICC_SET_TIMEOUT) ||
2445 !(sup_cmds & IPA_VNICC_GET_TIMEOUT))
2446 card->options.vnicc.getset_timeout_sup &= ~vnicc;
Hans Wippelcaa1f0b2017-09-18 21:18:15 +02002447 if (!(sup_cmds & IPA_VNICC_ENABLE) ||
2448 !(sup_cmds & IPA_VNICC_DISABLE))
2449 card->options.vnicc.set_char_sup &= ~vnicc;
2450 }
2451 /* enforce assumed default values and recover settings, if changed */
Hans Wippel349d13d2017-09-18 21:18:16 +02002452 error = qeth_l2_vnicc_recover_timeout(card, QETH_VNICC_LEARNING,
2453 timeout);
Hans Wippelcaa1f0b2017-09-18 21:18:15 +02002454 chars_tmp = card->options.vnicc.wanted_chars ^ QETH_VNICC_DEFAULT;
2455 chars_tmp |= QETH_VNICC_BRIDGE_INVISIBLE;
2456 chars_len = sizeof(card->options.vnicc.wanted_chars) * BITS_PER_BYTE;
2457 for_each_set_bit(i, &chars_tmp, chars_len) {
2458 vnicc = BIT(i);
2459 enable = card->options.vnicc.wanted_chars & vnicc;
2460 error |= qeth_l2_vnicc_recover_char(card, vnicc, enable);
2461 }
2462 if (error)
2463 dev_err(&card->gdev->dev, "Configuring the VNIC characteristics failed\n");
2464}
2465
2466/* configure default values of VNIC characteristics */
2467static void qeth_l2_vnicc_set_defaults(struct qeth_card *card)
2468{
2469 /* characteristics values */
2470 card->options.vnicc.sup_chars = QETH_VNICC_ALL;
2471 card->options.vnicc.cur_chars = QETH_VNICC_DEFAULT;
Hans Wippel349d13d2017-09-18 21:18:16 +02002472 card->options.vnicc.learning_timeout = QETH_VNICC_DEFAULT_TIMEOUT;
Hans Wippelcaa1f0b2017-09-18 21:18:15 +02002473 /* supported commands */
2474 card->options.vnicc.set_char_sup = QETH_VNICC_ALL;
Hans Wippel349d13d2017-09-18 21:18:16 +02002475 card->options.vnicc.getset_timeout_sup = QETH_VNICC_LEARNING;
Hans Wippelcaa1f0b2017-09-18 21:18:15 +02002476 /* settings wanted by users */
2477 card->options.vnicc.wanted_chars = QETH_VNICC_DEFAULT;
Hans Wippela45b3fa2017-09-18 21:18:14 +02002478}
2479
Frank Blaschka4a71df52008-02-15 09:19:42 +01002480module_init(qeth_l2_init);
2481module_exit(qeth_l2_exit);
2482MODULE_AUTHOR("Frank Blaschka <frank.blaschka@de.ibm.com>");
2483MODULE_DESCRIPTION("qeth layer 2 discipline");
2484MODULE_LICENSE("GPL");