blob: 8d3601891c62db3a58175d645a1ae30933a1520c [file] [log] [blame]
Greg Kroah-Hartmanab9953f2017-11-14 18:38:04 +01001// SPDX-License-Identifier: GPL-2.0
Frank Blaschka4a71df52008-02-15 09:19:42 +01002/*
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02003 * Copyright IBM Corp. 2007, 2009
Frank Blaschka4a71df52008-02-15 09:19:42 +01004 * Author(s): Utz Bacher <utz.bacher@de.ibm.com>,
5 * Frank Pavlic <fpavlic@de.ibm.com>,
6 * Thomas Spatzier <tspat@de.ibm.com>,
7 * Frank Blaschka <frank.blaschka@de.ibm.com>
8 */
9
Frank Blaschka74eacdb2008-12-25 13:39:49 +010010#define KMSG_COMPONENT "qeth"
11#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
12
Frank Blaschka4a71df52008-02-15 09:19:42 +010013#include <linux/module.h>
14#include <linux/moduleparam.h>
15#include <linux/string.h>
16#include <linux/errno.h>
17#include <linux/kernel.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090018#include <linux/slab.h>
Frank Blaschka4a71df52008-02-15 09:19:42 +010019#include <linux/etherdevice.h>
Jiri Pirkoccffad252009-05-22 23:22:17 +000020#include <linux/list.h>
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +020021#include <linux/hash.h>
22#include <linux/hashtable.h>
Julian Wiedmannec61bd22017-06-20 16:00:34 +020023#include <asm/setup.h>
Frank Blaschka4a71df52008-02-15 09:19:42 +010024#include "qeth_core.h"
Eugene Crosserb4d72c02014-01-14 15:54:11 +010025#include "qeth_l2.h"
Frank Blaschka4a71df52008-02-15 09:19:42 +010026
Frank Blaschka4a71df52008-02-15 09:19:42 +010027static int qeth_l2_set_offline(struct ccwgroup_device *);
28static int qeth_l2_stop(struct net_device *);
Eugene Crosserc044dc22014-01-29 09:23:48 +010029static void qeth_bridgeport_query_support(struct qeth_card *card);
30static void qeth_bridge_state_change(struct qeth_card *card,
31 struct qeth_ipa_cmd *cmd);
32static void qeth_bridge_host_event(struct qeth_card *card,
33 struct qeth_ipa_cmd *cmd);
Hans Wippelcaa1f0b2017-09-18 21:18:15 +020034static void qeth_l2_vnicc_set_defaults(struct qeth_card *card);
Hans Wippela45b3fa2017-09-18 21:18:14 +020035static void qeth_l2_vnicc_init(struct qeth_card *card);
Hans Wippel349d13d2017-09-18 21:18:16 +020036static bool qeth_l2_vnicc_recover_timeout(struct qeth_card *card, u32 vnicc,
37 u32 *timeout);
Frank Blaschka4a71df52008-02-15 09:19:42 +010038
Frank Blaschka4a71df52008-02-15 09:19:42 +010039static struct net_device *qeth_l2_netdev_by_devno(unsigned char *read_dev_no)
40{
41 struct qeth_card *card;
42 struct net_device *ndev;
Cornelia Huckf06f6f32008-06-06 12:37:45 +020043 __u16 temp_dev_no;
Frank Blaschka4a71df52008-02-15 09:19:42 +010044 unsigned long flags;
Cornelia Huckf06f6f32008-06-06 12:37:45 +020045 struct ccw_dev_id read_devid;
Frank Blaschka4a71df52008-02-15 09:19:42 +010046
47 ndev = NULL;
48 memcpy(&temp_dev_no, read_dev_no, 2);
49 read_lock_irqsave(&qeth_core_card_list.rwlock, flags);
50 list_for_each_entry(card, &qeth_core_card_list.list, list) {
Cornelia Huckf06f6f32008-06-06 12:37:45 +020051 ccw_device_get_id(CARD_RDEV(card), &read_devid);
52 if (read_devid.devno == temp_dev_no) {
Frank Blaschka4a71df52008-02-15 09:19:42 +010053 ndev = card->dev;
54 break;
55 }
56 }
57 read_unlock_irqrestore(&qeth_core_card_list.rwlock, flags);
58 return ndev;
59}
60
Julian Wiedmann2aa48672017-09-18 21:18:20 +020061static int qeth_setdelmac_makerc(struct qeth_card *card, int retcode)
Frank Blaschka4a71df52008-02-15 09:19:42 +010062{
Eugene Crosserefbbc1d2015-01-21 13:39:09 +010063 int rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +010064
Eugene Crosserefbbc1d2015-01-21 13:39:09 +010065 if (retcode)
Thomas Richter1aec42b2015-01-21 13:39:10 +010066 QETH_CARD_TEXT_(card, 2, "err%04x", retcode);
Eugene Crosserefbbc1d2015-01-21 13:39:09 +010067 switch (retcode) {
68 case IPA_RC_SUCCESS:
69 rc = 0;
70 break;
71 case IPA_RC_L2_UNSUPPORTED_CMD:
Eugene Crosserffb95252015-05-18 14:27:58 +020072 rc = -EOPNOTSUPP;
Eugene Crosserefbbc1d2015-01-21 13:39:09 +010073 break;
74 case IPA_RC_L2_ADDR_TABLE_FULL:
75 rc = -ENOSPC;
76 break;
77 case IPA_RC_L2_DUP_MAC:
78 case IPA_RC_L2_DUP_LAYER3_MAC:
79 rc = -EEXIST;
80 break;
81 case IPA_RC_L2_MAC_NOT_AUTH_BY_HYP:
82 case IPA_RC_L2_MAC_NOT_AUTH_BY_ADP:
83 rc = -EPERM;
84 break;
85 case IPA_RC_L2_MAC_NOT_FOUND:
86 rc = -ENOENT;
87 break;
Thomas Richter1aec42b2015-01-21 13:39:10 +010088 case -ENOMEM:
89 rc = -ENOMEM;
90 break;
Eugene Crosserefbbc1d2015-01-21 13:39:09 +010091 default:
92 rc = -EIO;
93 break;
Frank Blaschka4a71df52008-02-15 09:19:42 +010094 }
Eugene Crosserefbbc1d2015-01-21 13:39:09 +010095 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +010096}
97
Julian Wiedmannac988d72017-01-12 15:48:41 +010098static int qeth_l2_send_setdelmac(struct qeth_card *card, __u8 *mac,
99 enum qeth_ipa_cmds ipacmd)
100{
101 struct qeth_ipa_cmd *cmd;
102 struct qeth_cmd_buffer *iob;
103
104 QETH_CARD_TEXT(card, 2, "L2sdmac");
105 iob = qeth_get_ipacmd_buffer(card, ipacmd, QETH_PROT_IPV4);
106 if (!iob)
107 return -ENOMEM;
Julian Wiedmannff5caa72018-03-09 18:12:52 +0100108 cmd = __ipa_cmd(iob);
Julian Wiedmann99f0b852017-12-20 20:11:01 +0100109 cmd->data.setdelmac.mac_length = ETH_ALEN;
110 ether_addr_copy(cmd->data.setdelmac.mac, mac);
Julian Wiedmann2aa48672017-09-18 21:18:20 +0200111 return qeth_setdelmac_makerc(card, qeth_send_ipa_cmd(card, iob,
112 NULL, NULL));
Julian Wiedmannac988d72017-01-12 15:48:41 +0100113}
114
115static int qeth_l2_send_setmac(struct qeth_card *card, __u8 *mac)
116{
117 int rc;
118
119 QETH_CARD_TEXT(card, 2, "L2Setmac");
120 rc = qeth_l2_send_setdelmac(card, mac, IPA_CMD_SETVMAC);
121 if (rc == 0) {
Julian Wiedmannac988d72017-01-12 15:48:41 +0100122 dev_info(&card->gdev->dev,
Julian Wiedmannbcacfcb2018-04-19 12:52:09 +0200123 "MAC address %pM successfully registered on device %s\n",
124 mac, card->dev->name);
Julian Wiedmannac988d72017-01-12 15:48:41 +0100125 } else {
Julian Wiedmannac988d72017-01-12 15:48:41 +0100126 switch (rc) {
127 case -EEXIST:
128 dev_warn(&card->gdev->dev,
129 "MAC address %pM already exists\n", mac);
130 break;
131 case -EPERM:
132 dev_warn(&card->gdev->dev,
133 "MAC address %pM is not authorized\n", mac);
134 break;
135 }
136 }
137 return rc;
138}
139
Julian Wiedmann8174aa82017-12-20 20:11:00 +0100140static int qeth_l2_write_mac(struct qeth_card *card, u8 *mac)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100141{
Vasily Gorbik9d0a58f2018-06-29 19:45:52 +0200142 enum qeth_ipa_cmds cmd = is_multicast_ether_addr(mac) ?
Julian Wiedmann8174aa82017-12-20 20:11:00 +0100143 IPA_CMD_SETGMAC : IPA_CMD_SETVMAC;
Eugene Crosserefbbc1d2015-01-21 13:39:09 +0100144 int rc;
145
Julian Wiedmann8174aa82017-12-20 20:11:00 +0100146 QETH_CARD_TEXT(card, 2, "L2Wmac");
147 rc = qeth_l2_send_setdelmac(card, mac, cmd);
Eugene Crosserefbbc1d2015-01-21 13:39:09 +0100148 if (rc == -EEXIST)
Julian Wiedmanne19e5be2018-11-02 19:04:08 +0100149 QETH_DBF_MESSAGE(2, "MAC already registered on device %x\n",
150 CARD_DEVID(card));
Eugene Crosserefbbc1d2015-01-21 13:39:09 +0100151 else if (rc)
Julian Wiedmanne19e5be2018-11-02 19:04:08 +0100152 QETH_DBF_MESSAGE(2, "Failed to register MAC on device %x: %d\n",
153 CARD_DEVID(card), rc);
Eugene Crosserefbbc1d2015-01-21 13:39:09 +0100154 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100155}
156
Julian Wiedmann8174aa82017-12-20 20:11:00 +0100157static int qeth_l2_remove_mac(struct qeth_card *card, u8 *mac)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100158{
Vasily Gorbik9d0a58f2018-06-29 19:45:52 +0200159 enum qeth_ipa_cmds cmd = is_multicast_ether_addr(mac) ?
Julian Wiedmann8174aa82017-12-20 20:11:00 +0100160 IPA_CMD_DELGMAC : IPA_CMD_DELVMAC;
Eugene Crosserefbbc1d2015-01-21 13:39:09 +0100161 int rc;
162
Julian Wiedmann8174aa82017-12-20 20:11:00 +0100163 QETH_CARD_TEXT(card, 2, "L2Rmac");
164 rc = qeth_l2_send_setdelmac(card, mac, cmd);
Eugene Crosserefbbc1d2015-01-21 13:39:09 +0100165 if (rc)
Julian Wiedmanne19e5be2018-11-02 19:04:08 +0100166 QETH_DBF_MESSAGE(2, "Failed to delete MAC on device %u: %d\n",
167 CARD_DEVID(card), rc);
Eugene Crosserefbbc1d2015-01-21 13:39:09 +0100168 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100169}
170
Julian Wiedmannc07cbf22017-01-12 15:48:37 +0100171static void qeth_l2_del_all_macs(struct qeth_card *card)
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200172{
173 struct qeth_mac *mac;
174 struct hlist_node *tmp;
175 int i;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100176
177 spin_lock_bh(&card->mclock);
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200178 hash_for_each_safe(card->mac_htable, i, tmp, mac, hnode) {
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200179 hash_del(&mac->hnode);
180 kfree(mac);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100181 }
182 spin_unlock_bh(&card->mclock);
183}
184
Julian Wiedmanncef6ff222017-08-15 17:02:46 +0200185static int qeth_l2_get_cast_type(struct qeth_card *card, struct sk_buff *skb)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100186{
Klaus-Dieter Wackerce73e102009-08-26 02:01:08 +0000187 if (card->info.type == QETH_CARD_TYPE_OSN)
Julian Wiedmann86c0cdb2018-07-11 17:42:41 +0200188 return RTN_UNICAST;
Klaus-Dieter Wackerce73e102009-08-26 02:01:08 +0000189 if (is_broadcast_ether_addr(skb->data))
190 return RTN_BROADCAST;
191 if (is_multicast_ether_addr(skb->data))
192 return RTN_MULTICAST;
Julian Wiedmann86c0cdb2018-07-11 17:42:41 +0200193 return RTN_UNICAST;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100194}
195
Julian Wiedmannfc696602018-09-17 17:35:55 +0200196static void qeth_l2_fill_header(struct qeth_card *card, struct qeth_hdr *hdr,
197 struct sk_buff *skb, int ipv, int cast_type,
198 unsigned int data_len)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100199{
Julian Wiedmann0aef8392018-10-12 17:27:15 +0200200 struct vlan_ethhdr *veth = vlan_eth_hdr(skb);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100201
Julian Wiedmannae79fe02017-08-18 10:19:05 +0200202 hdr->hdr.l2.pkt_length = data_len;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100203
Julian Wiedmann0aef8392018-10-12 17:27:15 +0200204 if (skb_is_gso(skb)) {
205 hdr->hdr.l2.id = QETH_HEADER_TYPE_L2_TSO;
206 } else {
207 hdr->hdr.l2.id = QETH_HEADER_TYPE_LAYER2;
208 if (skb->ip_summed == CHECKSUM_PARTIAL) {
209 qeth_tx_csum(skb, &hdr->hdr.l2.flags[1], ipv);
210 if (card->options.performance_stats)
211 card->perf_stats.tx_csum++;
212 }
Julian Wiedmannfc696602018-09-17 17:35:55 +0200213 }
214
Frank Blaschka4a71df52008-02-15 09:19:42 +0100215 /* set byte byte 3 to casting flags */
216 if (cast_type == RTN_MULTICAST)
217 hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_MULTICAST;
218 else if (cast_type == RTN_BROADCAST)
219 hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_BROADCAST;
220 else
Klaus-Dieter Wackerce73e102009-08-26 02:01:08 +0000221 hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_UNICAST;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100222
Frank Blaschka4a71df52008-02-15 09:19:42 +0100223 /* VSWITCH relies on the VLAN
224 * information to be present in
225 * the QDIO header */
226 if (veth->h_vlan_proto == __constant_htons(ETH_P_8021Q)) {
227 hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_VLAN;
228 hdr->hdr.l2.vlan_id = ntohs(veth->h_vlan_TCI);
229 }
230}
231
Julian Wiedmann2aa48672017-09-18 21:18:20 +0200232static int qeth_setdelvlan_makerc(struct qeth_card *card, int retcode)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100233{
Julian Wiedmann2aa48672017-09-18 21:18:20 +0200234 if (retcode)
235 QETH_CARD_TEXT_(card, 2, "err%04x", retcode);
236
237 switch (retcode) {
238 case IPA_RC_SUCCESS:
239 return 0;
240 case IPA_RC_L2_INVALID_VLAN_ID:
241 return -EINVAL;
242 case IPA_RC_L2_DUP_VLAN_ID:
243 return -EEXIST;
244 case IPA_RC_L2_VLAN_ID_NOT_FOUND:
245 return -ENOENT;
246 case IPA_RC_L2_VLAN_ID_NOT_ALLOWED:
247 return -EPERM;
248 case -ENOMEM:
249 return -ENOMEM;
250 default:
251 return -EIO;
252 }
253}
254
255static int qeth_l2_send_setdelvlan_cb(struct qeth_card *card,
256 struct qeth_reply *reply,
257 unsigned long data)
258{
259 struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *) data;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100260
Carsten Otte847a50f2010-06-21 22:57:05 +0000261 QETH_CARD_TEXT(card, 2, "L2sdvcb");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100262 if (cmd->hdr.return_code) {
Julian Wiedmanne19e5be2018-11-02 19:04:08 +0100263 QETH_DBF_MESSAGE(2, "Error in processing VLAN %u on device %x: %#x.\n",
Julian Wiedmann2aa48672017-09-18 21:18:20 +0200264 cmd->data.setdelvlan.vlan_id,
Julian Wiedmanne19e5be2018-11-02 19:04:08 +0100265 CARD_DEVID(card), cmd->hdr.return_code);
Carsten Otte847a50f2010-06-21 22:57:05 +0000266 QETH_CARD_TEXT_(card, 2, "L2VL%4x", cmd->hdr.command);
267 QETH_CARD_TEXT_(card, 2, "err%d", cmd->hdr.return_code);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100268 }
269 return 0;
270}
271
272static int qeth_l2_send_setdelvlan(struct qeth_card *card, __u16 i,
Julian Wiedmann2aa48672017-09-18 21:18:20 +0200273 enum qeth_ipa_cmds ipacmd)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100274{
275 struct qeth_ipa_cmd *cmd;
276 struct qeth_cmd_buffer *iob;
277
Carsten Otte847a50f2010-06-21 22:57:05 +0000278 QETH_CARD_TEXT_(card, 4, "L2sdv%x", ipacmd);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100279 iob = qeth_get_ipacmd_buffer(card, ipacmd, QETH_PROT_IPV4);
Thomas Richter1aec42b2015-01-21 13:39:10 +0100280 if (!iob)
281 return -ENOMEM;
Julian Wiedmannff5caa72018-03-09 18:12:52 +0100282 cmd = __ipa_cmd(iob);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100283 cmd->data.setdelvlan.vlan_id = i;
Julian Wiedmann2aa48672017-09-18 21:18:20 +0200284 return qeth_setdelvlan_makerc(card, qeth_send_ipa_cmd(card, iob,
285 qeth_l2_send_setdelvlan_cb, NULL));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100286}
287
Ursula Braun70919e22011-02-26 22:41:36 -0800288static void qeth_l2_process_vlans(struct qeth_card *card)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100289{
290 struct qeth_vlan_vid *id;
Julian Wiedmannd4ac0242018-04-26 09:42:13 +0200291
Carsten Otte847a50f2010-06-21 22:57:05 +0000292 QETH_CARD_TEXT(card, 3, "L2prcvln");
Julian Wiedmannd4ac0242018-04-26 09:42:13 +0200293 mutex_lock(&card->vid_list_mutex);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100294 list_for_each_entry(id, &card->vid_list, list) {
Ursula Braun70919e22011-02-26 22:41:36 -0800295 qeth_l2_send_setdelvlan(card, id->vid, IPA_CMD_SETVLAN);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100296 }
Julian Wiedmannd4ac0242018-04-26 09:42:13 +0200297 mutex_unlock(&card->vid_list_mutex);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100298}
299
Patrick McHardy80d5c362013-04-19 02:04:28 +0000300static int qeth_l2_vlan_rx_add_vid(struct net_device *dev,
301 __be16 proto, u16 vid)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100302{
Heiko Carstens509e2562008-07-26 02:24:10 -0700303 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100304 struct qeth_vlan_vid *id;
Thomas Richter1aec42b2015-01-21 13:39:10 +0100305 int rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100306
Carsten Otte847a50f2010-06-21 22:57:05 +0000307 QETH_CARD_TEXT_(card, 4, "aid:%d", vid);
Ursula Braun10651db2010-10-01 02:51:13 +0000308 if (!vid)
Jiri Pirko8e586132011-12-08 19:52:37 -0500309 return 0;
Ursula Braun8e98ac42009-03-24 20:57:18 +0000310 if (qeth_wait_for_threads(card, QETH_RECOVER_THREAD)) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000311 QETH_CARD_TEXT(card, 3, "aidREC");
Jiri Pirko8e586132011-12-08 19:52:37 -0500312 return 0;
Ursula Braun8e98ac42009-03-24 20:57:18 +0000313 }
Julian Wiedmannd4ac0242018-04-26 09:42:13 +0200314 id = kmalloc(sizeof(*id), GFP_KERNEL);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100315 if (id) {
316 id->vid = vid;
Thomas Richter1aec42b2015-01-21 13:39:10 +0100317 rc = qeth_l2_send_setdelvlan(card, vid, IPA_CMD_SETVLAN);
318 if (rc) {
319 kfree(id);
320 return rc;
321 }
Julian Wiedmannd4ac0242018-04-26 09:42:13 +0200322 mutex_lock(&card->vid_list_mutex);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100323 list_add_tail(&id->list, &card->vid_list);
Julian Wiedmannd4ac0242018-04-26 09:42:13 +0200324 mutex_unlock(&card->vid_list_mutex);
Jiri Pirko8e586132011-12-08 19:52:37 -0500325 } else {
326 return -ENOMEM;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100327 }
Jiri Pirko8e586132011-12-08 19:52:37 -0500328 return 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100329}
330
Patrick McHardy80d5c362013-04-19 02:04:28 +0000331static int qeth_l2_vlan_rx_kill_vid(struct net_device *dev,
332 __be16 proto, u16 vid)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100333{
334 struct qeth_vlan_vid *id, *tmpid = NULL;
Heiko Carstens509e2562008-07-26 02:24:10 -0700335 struct qeth_card *card = dev->ml_priv;
Thomas Richter1aec42b2015-01-21 13:39:10 +0100336 int rc = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100337
Carsten Otte847a50f2010-06-21 22:57:05 +0000338 QETH_CARD_TEXT_(card, 4, "kid:%d", vid);
Ursula Braun8e98ac42009-03-24 20:57:18 +0000339 if (qeth_wait_for_threads(card, QETH_RECOVER_THREAD)) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000340 QETH_CARD_TEXT(card, 3, "kidREC");
Jiri Pirko8e586132011-12-08 19:52:37 -0500341 return 0;
Ursula Braun8e98ac42009-03-24 20:57:18 +0000342 }
Julian Wiedmannd4ac0242018-04-26 09:42:13 +0200343 mutex_lock(&card->vid_list_mutex);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100344 list_for_each_entry(id, &card->vid_list, list) {
345 if (id->vid == vid) {
346 list_del(&id->list);
347 tmpid = id;
348 break;
349 }
350 }
Julian Wiedmannd4ac0242018-04-26 09:42:13 +0200351 mutex_unlock(&card->vid_list_mutex);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100352 if (tmpid) {
Thomas Richter1aec42b2015-01-21 13:39:10 +0100353 rc = qeth_l2_send_setdelvlan(card, vid, IPA_CMD_DELVLAN);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100354 kfree(tmpid);
355 }
Thomas Richter1aec42b2015-01-21 13:39:10 +0100356 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100357}
358
Peter Senna Tschudinb2f4de82015-08-04 17:11:47 +0200359static void qeth_l2_stop_card(struct qeth_card *card, int recovery_mode)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100360{
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200361 QETH_DBF_TEXT(SETUP , 2, "stopcard");
362 QETH_DBF_HEX(SETUP, 2, &card, sizeof(void *));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100363
364 qeth_set_allowed_threads(card, 0, 1);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100365 if (card->read.state == CH_STATE_UP &&
366 card->write.state == CH_STATE_UP &&
367 (card->state == CARD_STATE_UP)) {
368 if (recovery_mode &&
369 card->info.type != QETH_CARD_TYPE_OSN) {
370 qeth_l2_stop(card->dev);
371 } else {
372 rtnl_lock();
373 dev_close(card->dev);
374 rtnl_unlock();
375 }
Ursula Braun70919e22011-02-26 22:41:36 -0800376 card->info.mac_bits &= ~QETH_LAYER2_MAC_REGISTERED;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100377 card->state = CARD_STATE_SOFTSETUP;
378 }
379 if (card->state == CARD_STATE_SOFTSETUP) {
Julian Wiedmannc07cbf22017-01-12 15:48:37 +0100380 qeth_l2_del_all_macs(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100381 qeth_clear_ipacmd_list(card);
382 card->state = CARD_STATE_HARDSETUP;
383 }
384 if (card->state == CARD_STATE_HARDSETUP) {
385 qeth_qdio_clear_card(card, 0);
386 qeth_clear_qdio_buffers(card);
387 qeth_clear_working_pool_list(card);
388 card->state = CARD_STATE_DOWN;
389 }
390 if (card->state == CARD_STATE_DOWN) {
391 qeth_clear_cmd_buffers(&card->read);
392 qeth_clear_cmd_buffers(&card->write);
393 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100394}
395
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000396static int qeth_l2_process_inbound_buffer(struct qeth_card *card,
397 int budget, int *done)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100398{
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000399 int work_done = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100400 struct sk_buff *skb;
401 struct qeth_hdr *hdr;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100402 unsigned int len;
403
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000404 *done = 0;
Stefan Raspl18af5c12012-11-19 02:46:50 +0000405 WARN_ON_ONCE(!budget);
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000406 while (budget) {
407 skb = qeth_core_get_next_skb(card,
Frank Blaschkab3332932011-08-08 01:33:59 +0000408 &card->qdio.in_q->bufs[card->rx.b_index],
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000409 &card->rx.b_element, &card->rx.e_offset, &hdr);
410 if (!skb) {
411 *done = 1;
412 break;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100413 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100414 switch (hdr->hdr.l2.id) {
415 case QETH_HEADER_TYPE_LAYER2:
Frank Blaschka4a71df52008-02-15 09:19:42 +0100416 skb->protocol = eth_type_trans(skb, skb->dev);
Julian Wiedmann6195b932018-04-26 09:42:17 +0200417 qeth_rx_csum(card, skb, hdr->hdr.l2.flags[1]);
Ursula Braun12883722008-04-01 10:26:56 +0200418 if (skb->protocol == htons(ETH_P_802_2))
419 *((__u32 *)skb->cb) = ++card->seqno.pkt_seqno;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100420 len = skb->len;
Thomas Richter9abfa8c2015-10-06 15:12:27 +0200421 napi_gro_receive(&card->napi, skb);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100422 break;
423 case QETH_HEADER_TYPE_OSN:
Ursula Braun2d488c22008-10-24 11:16:55 +0200424 if (card->info.type == QETH_CARD_TYPE_OSN) {
425 skb_push(skb, sizeof(struct qeth_hdr));
426 skb_copy_to_linear_data(skb, hdr,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100427 sizeof(struct qeth_hdr));
Ursula Braun2d488c22008-10-24 11:16:55 +0200428 len = skb->len;
429 card->osn_info.data_cb(skb);
430 break;
431 }
432 /* else unknown */
Frank Blaschka4a71df52008-02-15 09:19:42 +0100433 default:
434 dev_kfree_skb_any(skb);
Carsten Otte847a50f2010-06-21 22:57:05 +0000435 QETH_CARD_TEXT(card, 3, "inbunkno");
Julian Wiedmann0ac14872018-09-12 15:31:35 +0200436 QETH_DBF_HEX(CTRL, 3, hdr, sizeof(*hdr));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100437 continue;
438 }
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000439 work_done++;
440 budget--;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100441 card->stats.rx_packets++;
442 card->stats.rx_bytes += len;
443 }
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000444 return work_done;
445}
446
Frank Blaschka4a71df52008-02-15 09:19:42 +0100447static int qeth_l2_request_initial_mac(struct qeth_card *card)
448{
449 int rc = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100450
Julian Wiedmannec61bd22017-06-20 16:00:34 +0200451 QETH_DBF_TEXT(SETUP, 2, "l2reqmac");
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200452 QETH_DBF_TEXT_(SETUP, 2, "doL2%s", CARD_BUS_ID(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100453
Julian Wiedmannec61bd22017-06-20 16:00:34 +0200454 if (MACHINE_IS_VM) {
455 rc = qeth_vm_request_mac(card);
456 if (!rc)
457 goto out;
Julian Wiedmanne19e5be2018-11-02 19:04:08 +0100458 QETH_DBF_MESSAGE(2, "z/VM MAC Service failed on device %x: %#x\n",
459 CARD_DEVID(card), rc);
Julian Wiedmannec61bd22017-06-20 16:00:34 +0200460 QETH_DBF_TEXT_(SETUP, 2, "err%04x", rc);
461 /* fall back to alternative mechanism: */
462 }
463
Julian Wiedmannb144b992018-11-08 15:06:15 +0100464 if (!IS_OSN(card)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +0100465 rc = qeth_setadpparms_change_macaddr(card);
Julian Wiedmannb144b992018-11-08 15:06:15 +0100466 if (!rc && is_valid_ether_addr(card->dev->dev_addr))
Julian Wiedmann21b17022018-04-26 09:42:24 +0200467 goto out;
Julian Wiedmanne19e5be2018-11-02 19:04:08 +0100468 QETH_DBF_MESSAGE(2, "READ_MAC Assist failed on device %x: %#x\n",
469 CARD_DEVID(card), rc);
Julian Wiedmann21b17022018-04-26 09:42:24 +0200470 QETH_DBF_TEXT_(SETUP, 2, "1err%04x", rc);
471 /* fall back once more: */
Frank Blaschka4a71df52008-02-15 09:19:42 +0100472 }
Julian Wiedmann21b17022018-04-26 09:42:24 +0200473
474 /* some devices don't support a custom MAC address: */
475 if (card->info.type == QETH_CARD_TYPE_OSM ||
476 card->info.type == QETH_CARD_TYPE_OSX)
477 return (rc) ? rc : -EADDRNOTAVAIL;
478 eth_hw_addr_random(card->dev);
479
Julian Wiedmannec61bd22017-06-20 16:00:34 +0200480out:
481 QETH_DBF_HEX(SETUP, 2, card->dev->dev_addr, card->dev->addr_len);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100482 return 0;
483}
484
485static int qeth_l2_set_mac_address(struct net_device *dev, void *p)
486{
487 struct sockaddr *addr = p;
Heiko Carstens509e2562008-07-26 02:24:10 -0700488 struct qeth_card *card = dev->ml_priv;
Julian Wiedmannbcacfcb2018-04-19 12:52:09 +0200489 u8 old_addr[ETH_ALEN];
Frank Blaschka4a71df52008-02-15 09:19:42 +0100490 int rc = 0;
491
Carsten Otte847a50f2010-06-21 22:57:05 +0000492 QETH_CARD_TEXT(card, 3, "setmac");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100493
Ursula Braun5113fec2010-05-16 21:15:14 +0000494 if (card->info.type == QETH_CARD_TYPE_OSN ||
495 card->info.type == QETH_CARD_TYPE_OSM ||
496 card->info.type == QETH_CARD_TYPE_OSX) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000497 QETH_CARD_TEXT(card, 3, "setmcTYP");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100498 return -EOPNOTSUPP;
499 }
Julian Wiedmann99f0b852017-12-20 20:11:01 +0100500 QETH_CARD_HEX(card, 3, addr->sa_data, ETH_ALEN);
Julian Wiedmannbcacfcb2018-04-19 12:52:09 +0200501 if (!is_valid_ether_addr(addr->sa_data))
502 return -EADDRNOTAVAIL;
503
Ursula Braun8e98ac42009-03-24 20:57:18 +0000504 if (qeth_wait_for_threads(card, QETH_RECOVER_THREAD)) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000505 QETH_CARD_TEXT(card, 3, "setmcREC");
Ursula Braun8e98ac42009-03-24 20:57:18 +0000506 return -ERESTARTSYS;
507 }
Julian Wiedmannbcacfcb2018-04-19 12:52:09 +0200508
Julian Wiedmann4789a212018-06-29 19:45:51 +0200509 /* avoid racing against concurrent state change: */
510 if (!mutex_trylock(&card->conf_mutex))
511 return -EAGAIN;
512
Julian Wiedmannbcacfcb2018-04-19 12:52:09 +0200513 if (!qeth_card_hw_is_reachable(card)) {
514 ether_addr_copy(dev->dev_addr, addr->sa_data);
Julian Wiedmann4789a212018-06-29 19:45:51 +0200515 goto out_unlock;
Julian Wiedmannbcacfcb2018-04-19 12:52:09 +0200516 }
517
518 /* don't register the same address twice */
519 if (ether_addr_equal_64bits(dev->dev_addr, addr->sa_data) &&
520 (card->info.mac_bits & QETH_LAYER2_MAC_REGISTERED))
Julian Wiedmann4789a212018-06-29 19:45:51 +0200521 goto out_unlock;
Julian Wiedmannbcacfcb2018-04-19 12:52:09 +0200522
523 /* add the new address, switch over, drop the old */
524 rc = qeth_l2_send_setmac(card, addr->sa_data);
525 if (rc)
Julian Wiedmann4789a212018-06-29 19:45:51 +0200526 goto out_unlock;
Julian Wiedmannbcacfcb2018-04-19 12:52:09 +0200527 ether_addr_copy(old_addr, dev->dev_addr);
528 ether_addr_copy(dev->dev_addr, addr->sa_data);
529
530 if (card->info.mac_bits & QETH_LAYER2_MAC_REGISTERED)
531 qeth_l2_remove_mac(card, old_addr);
532 card->info.mac_bits |= QETH_LAYER2_MAC_REGISTERED;
Julian Wiedmann4789a212018-06-29 19:45:51 +0200533
534out_unlock:
535 mutex_unlock(&card->conf_mutex);
536 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100537}
538
Eugene Crosser0db587b2015-05-18 14:27:55 +0200539static void qeth_promisc_to_bridge(struct qeth_card *card)
540{
541 struct net_device *dev = card->dev;
542 enum qeth_ipa_promisc_modes promisc_mode;
543 int role;
544 int rc;
545
546 QETH_CARD_TEXT(card, 3, "pmisc2br");
547
548 if (!card->options.sbp.reflect_promisc)
549 return;
550 promisc_mode = (dev->flags & IFF_PROMISC) ? SET_PROMISC_MODE_ON
551 : SET_PROMISC_MODE_OFF;
552 if (promisc_mode == card->info.promisc_mode)
553 return;
554
555 if (promisc_mode == SET_PROMISC_MODE_ON) {
556 if (card->options.sbp.reflect_promisc_primary)
557 role = QETH_SBP_ROLE_PRIMARY;
558 else
559 role = QETH_SBP_ROLE_SECONDARY;
560 } else
561 role = QETH_SBP_ROLE_NONE;
562
563 rc = qeth_bridgeport_setrole(card, role);
564 QETH_DBF_TEXT_(SETUP, 2, "bpm%c%04x",
565 (promisc_mode == SET_PROMISC_MODE_ON) ? '+' : '-', rc);
566 if (!rc) {
567 card->options.sbp.role = role;
568 card->info.promisc_mode = promisc_mode;
569 }
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200570
571}
572/* New MAC address is added to the hash table and marked to be written on card
573 * only if there is not in the hash table storage already
574 *
575*/
Julian Wiedmann4641b022017-12-20 20:10:59 +0100576static void qeth_l2_add_mac(struct qeth_card *card, struct netdev_hw_addr *ha)
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200577{
Julian Wiedmanncef6ff222017-08-15 17:02:46 +0200578 u32 mac_hash = get_unaligned((u32 *)(&ha->addr[2]));
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200579 struct qeth_mac *mac;
580
Julian Wiedmanncef6ff222017-08-15 17:02:46 +0200581 hash_for_each_possible(card->mac_htable, mac, hnode, mac_hash) {
Julian Wiedmann99f0b852017-12-20 20:11:01 +0100582 if (ether_addr_equal_64bits(ha->addr, mac->mac_addr)) {
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200583 mac->disp_flag = QETH_DISP_ADDR_DO_NOTHING;
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200584 return;
585 }
586 }
587
588 mac = kzalloc(sizeof(struct qeth_mac), GFP_ATOMIC);
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200589 if (!mac)
590 return;
591
Julian Wiedmann99f0b852017-12-20 20:11:01 +0100592 ether_addr_copy(mac->mac_addr, ha->addr);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200593 mac->disp_flag = QETH_DISP_ADDR_ADD;
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200594
Julian Wiedmanncef6ff222017-08-15 17:02:46 +0200595 hash_add(card->mac_htable, &mac->hnode, mac_hash);
Eugene Crosser0db587b2015-05-18 14:27:55 +0200596}
597
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200598static void qeth_l2_set_rx_mode(struct net_device *dev)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100599{
Heiko Carstens509e2562008-07-26 02:24:10 -0700600 struct qeth_card *card = dev->ml_priv;
Jiri Pirkoccffad252009-05-22 23:22:17 +0000601 struct netdev_hw_addr *ha;
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200602 struct qeth_mac *mac;
603 struct hlist_node *tmp;
604 int i;
605 int rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100606
607 if (card->info.type == QETH_CARD_TYPE_OSN)
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200608 return;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100609
Carsten Otte847a50f2010-06-21 22:57:05 +0000610 QETH_CARD_TEXT(card, 3, "setmulti");
Ursula Braun8e98ac42009-03-24 20:57:18 +0000611 if (qeth_threads_running(card, QETH_RECOVER_THREAD) &&
612 (card->state != CARD_STATE_UP))
613 return;
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200614
Frank Blaschka4a71df52008-02-15 09:19:42 +0100615 spin_lock_bh(&card->mclock);
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200616
Jiri Pirko22bedad32010-04-01 21:22:57 +0000617 netdev_for_each_mc_addr(ha, dev)
Julian Wiedmann4641b022017-12-20 20:10:59 +0100618 qeth_l2_add_mac(card, ha);
Jiri Pirko32e7bfc2010-01-25 13:36:10 -0800619 netdev_for_each_uc_addr(ha, dev)
Julian Wiedmann4641b022017-12-20 20:10:59 +0100620 qeth_l2_add_mac(card, ha);
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200621
622 hash_for_each_safe(card->mac_htable, i, tmp, mac, hnode) {
Julian Wiedmann00c163f2017-12-20 20:11:02 +0100623 switch (mac->disp_flag) {
624 case QETH_DISP_ADDR_DELETE:
Julian Wiedmann8174aa82017-12-20 20:11:00 +0100625 qeth_l2_remove_mac(card, mac->mac_addr);
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200626 hash_del(&mac->hnode);
627 kfree(mac);
Julian Wiedmann00c163f2017-12-20 20:11:02 +0100628 break;
629 case QETH_DISP_ADDR_ADD:
Julian Wiedmann8174aa82017-12-20 20:11:00 +0100630 rc = qeth_l2_write_mac(card, mac->mac_addr);
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200631 if (rc) {
632 hash_del(&mac->hnode);
633 kfree(mac);
Julian Wiedmann00c163f2017-12-20 20:11:02 +0100634 break;
635 }
636 /* fall through */
637 default:
638 /* for next call to set_rx_mode(): */
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200639 mac->disp_flag = QETH_DISP_ADDR_DELETE;
Julian Wiedmann00c163f2017-12-20 20:11:02 +0100640 }
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200641 }
Frank Blaschka7db22662008-08-15 08:02:59 +0200642
Frank Blaschka4a71df52008-02-15 09:19:42 +0100643 spin_unlock_bh(&card->mclock);
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200644
Eugene Crosser0db587b2015-05-18 14:27:55 +0200645 if (qeth_adp_supported(card, IPA_SETADP_SET_PROMISC_MODE))
646 qeth_setadp_promisc_mode(card);
647 else
648 qeth_promisc_to_bridge(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100649}
650
Julian Wiedmann72863842017-08-18 10:19:04 +0200651static int qeth_l2_xmit_osn(struct qeth_card *card, struct sk_buff *skb,
652 struct qeth_qdio_out_q *queue)
653{
Julian Wiedmann69d7ce82018-09-17 17:36:04 +0200654 struct qeth_hdr *hdr = (struct qeth_hdr *)skb->data;
655 addr_t end = (addr_t)(skb->data + sizeof(*hdr));
656 addr_t start = (addr_t)skb->data;
657 unsigned int elements = 0;
658 unsigned int hd_len = 0;
659 int rc;
Julian Wiedmann72863842017-08-18 10:19:04 +0200660
661 if (skb->protocol == htons(ETH_P_IPV6))
662 return -EPROTONOSUPPORT;
663
Julian Wiedmann69d7ce82018-09-17 17:36:04 +0200664 if (qeth_get_elements_for_range(start, end) > 1) {
665 /* Misaligned HW header, move it to its own buffer element. */
666 hdr = kmem_cache_alloc(qeth_core_header_cache, GFP_ATOMIC);
667 if (!hdr)
668 return -ENOMEM;
669 hd_len = sizeof(*hdr);
670 skb_copy_from_linear_data(skb, (char *)hdr, hd_len);
671 elements++;
672 }
673
674 elements += qeth_count_elements(skb, hd_len);
675 if (elements > QETH_MAX_BUFFER_ELEMENTS(card)) {
676 rc = -E2BIG;
677 goto out;
678 }
679
680 rc = qeth_do_send_packet(card, queue, skb, hdr, hd_len, hd_len,
681 elements);
682out:
683 if (rc && hd_len)
684 kmem_cache_free(qeth_core_header_cache, hdr);
685 return rc;
Julian Wiedmann72863842017-08-18 10:19:04 +0200686}
687
Julian Wiedmanne38db6b2017-04-11 16:11:14 +0200688static netdev_tx_t qeth_l2_hard_start_xmit(struct sk_buff *skb,
689 struct net_device *dev)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100690{
Heiko Carstens509e2562008-07-26 02:24:10 -0700691 struct qeth_card *card = dev->ml_priv;
Klaus-Dieter Wackerce73e102009-08-26 02:01:08 +0000692 int cast_type = qeth_l2_get_cast_type(card, skb);
Kittipon Meesompop571f9dd82018-04-26 09:42:22 +0200693 int ipv = qeth_get_ip_version(skb);
Stefan Raspl290b8342014-04-28 10:05:08 +0200694 struct qeth_qdio_out_q *queue;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100695 int tx_bytes = skb->len;
Julian Wiedmann72863842017-08-18 10:19:04 +0200696 int rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100697
Julian Wiedmann91cc98f2018-09-26 18:29:16 +0200698 if (card->state != CARD_STATE_UP) {
Frank Blaschka4a71df52008-02-15 09:19:42 +0100699 card->stats.tx_carrier_errors++;
700 goto tx_drop;
701 }
702
Julian Wiedmann86c0cdb2018-07-11 17:42:41 +0200703 queue = qeth_get_tx_queue(card, skb, ipv, cast_type);
704
Frank Blaschka4a71df52008-02-15 09:19:42 +0100705 if (card->options.performance_stats) {
706 card->perf_stats.outbound_cnt++;
707 card->perf_stats.outbound_start_time = qeth_get_micros();
708 }
709 netif_stop_queue(dev);
710
Julian Wiedmann5f89eca2018-07-19 12:43:58 +0200711 if (IS_OSN(card))
Julian Wiedmann72863842017-08-18 10:19:04 +0200712 rc = qeth_l2_xmit_osn(card, skb, queue);
Julian Wiedmann5f89eca2018-07-19 12:43:58 +0200713 else
Julian Wiedmannfc696602018-09-17 17:35:55 +0200714 rc = qeth_xmit(card, skb, queue, ipv, cast_type,
715 qeth_l2_fill_header);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100716
Frank Blaschka4a71df52008-02-15 09:19:42 +0100717 if (!rc) {
718 card->stats.tx_packets++;
719 card->stats.tx_bytes += tx_bytes;
Julian Wiedmann72863842017-08-18 10:19:04 +0200720 if (card->options.performance_stats)
721 card->perf_stats.outbound_time += qeth_get_micros() -
722 card->perf_stats.outbound_start_time;
723 netif_wake_queue(dev);
724 return NETDEV_TX_OK;
725 } else if (rc == -EBUSY) {
726 return NETDEV_TX_BUSY;
727 } /* else fall through */
Frank Blaschka4a71df52008-02-15 09:19:42 +0100728
729tx_drop:
730 card->stats.tx_dropped++;
731 card->stats.tx_errors++;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100732 dev_kfree_skb_any(skb);
Frank Blaschkad0ec0f52008-06-06 12:37:48 +0200733 netif_wake_queue(dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100734 return NETDEV_TX_OK;
735}
736
Ursula Braun39423442011-01-12 20:42:24 +0000737static int __qeth_l2_open(struct net_device *dev)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100738{
Heiko Carstens509e2562008-07-26 02:24:10 -0700739 struct qeth_card *card = dev->ml_priv;
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000740 int rc = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100741
Carsten Otte847a50f2010-06-21 22:57:05 +0000742 QETH_CARD_TEXT(card, 4, "qethopen");
Ursula Braun39423442011-01-12 20:42:24 +0000743 if (card->state == CARD_STATE_UP)
744 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100745 if (card->state != CARD_STATE_SOFTSETUP)
746 return -ENODEV;
747
748 if ((card->info.type != QETH_CARD_TYPE_OSN) &&
749 (!(card->info.mac_bits & QETH_LAYER2_MAC_REGISTERED))) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000750 QETH_CARD_TEXT(card, 4, "nomacadr");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100751 return -EPERM;
752 }
753 card->data.state = CH_STATE_UP;
754 card->state = CARD_STATE_UP;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100755 netif_start_queue(dev);
756
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000757 if (qdio_stop_irq(card->data.ccwdev, 0) >= 0) {
758 napi_enable(&card->napi);
Julian Wiedmann4d19db72018-09-17 17:36:06 +0200759 local_bh_disable();
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000760 napi_schedule(&card->napi);
Julian Wiedmann4d19db72018-09-17 17:36:06 +0200761 /* kick-start the NAPI softirq: */
762 local_bh_enable();
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000763 } else
764 rc = -EIO;
765 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100766}
767
Ursula Braun39423442011-01-12 20:42:24 +0000768static int qeth_l2_open(struct net_device *dev)
769{
770 struct qeth_card *card = dev->ml_priv;
771
772 QETH_CARD_TEXT(card, 5, "qethope_");
773 if (qeth_wait_for_threads(card, QETH_RECOVER_THREAD)) {
774 QETH_CARD_TEXT(card, 3, "openREC");
775 return -ERESTARTSYS;
776 }
777 return __qeth_l2_open(dev);
778}
779
Frank Blaschka4a71df52008-02-15 09:19:42 +0100780static int qeth_l2_stop(struct net_device *dev)
781{
Heiko Carstens509e2562008-07-26 02:24:10 -0700782 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100783
Carsten Otte847a50f2010-06-21 22:57:05 +0000784 QETH_CARD_TEXT(card, 4, "qethstop");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100785 netif_tx_disable(dev);
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000786 if (card->state == CARD_STATE_UP) {
Frank Blaschka4a71df52008-02-15 09:19:42 +0100787 card->state = CARD_STATE_SOFTSETUP;
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000788 napi_disable(&card->napi);
789 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100790 return 0;
791}
792
Julian Wiedmann2d2ebb32017-05-10 19:07:52 +0200793static const struct device_type qeth_l2_devtype = {
794 .name = "qeth_layer2",
795 .groups = qeth_l2_attr_groups,
796};
797
Frank Blaschka4a71df52008-02-15 09:19:42 +0100798static int qeth_l2_probe_device(struct ccwgroup_device *gdev)
799{
800 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
Ursula Braun9111e782017-05-10 19:07:51 +0200801 int rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100802
Julian Wiedmann2d2ebb32017-05-10 19:07:52 +0200803 if (gdev->dev.type == &qeth_generic_devtype) {
804 rc = qeth_l2_create_device_attributes(&gdev->dev);
805 if (rc)
806 return rc;
807 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100808 INIT_LIST_HEAD(&card->vid_list);
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200809 hash_init(card->mac_htable);
Frank Blaschka1da74b12011-05-12 18:45:02 +0000810 card->info.hwtrap = 0;
Hans Wippelcaa1f0b2017-09-18 21:18:15 +0200811 qeth_l2_vnicc_set_defaults(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100812 return 0;
813}
814
815static void qeth_l2_remove_device(struct ccwgroup_device *cgdev)
816{
817 struct qeth_card *card = dev_get_drvdata(&cgdev->dev);
818
Julian Wiedmann2d2ebb32017-05-10 19:07:52 +0200819 if (cgdev->dev.type == &qeth_generic_devtype)
820 qeth_l2_remove_device_attributes(&cgdev->dev);
Ursula Braunf2148562009-05-19 21:38:37 +0000821 qeth_set_allowed_threads(card, 0, 1);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100822 wait_event(card->wait_q, qeth_threads_running(card, 0xffffffff) == 0);
823
Ursula Braun70919e22011-02-26 22:41:36 -0800824 if (cgdev->state == CCWGROUP_ONLINE)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100825 qeth_l2_set_offline(cgdev);
Julian Wiedmann30356d02018-11-02 19:04:10 +0100826 if (qeth_netdev_is_registered(card->dev))
827 unregister_netdev(card->dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100828}
829
Stephen Hemminger0fc0b732009-09-02 01:03:33 -0700830static const struct ethtool_ops qeth_l2_ethtool_ops = {
Frank Blaschka4a71df52008-02-15 09:19:42 +0100831 .get_link = ethtool_op_get_link,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100832 .get_strings = qeth_core_get_strings,
833 .get_ethtool_stats = qeth_core_get_ethtool_stats,
Ben Hutchingsdf8b4ec2009-10-01 11:24:32 +0000834 .get_sset_count = qeth_core_get_sset_count,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100835 .get_drvinfo = qeth_core_get_drvinfo,
Julian Wiedmann993e19c2017-04-11 16:11:17 +0200836 .get_link_ksettings = qeth_core_ethtool_get_link_ksettings,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100837};
838
Stephen Hemminger0fc0b732009-09-02 01:03:33 -0700839static const struct ethtool_ops qeth_l2_osn_ops = {
Frank Blaschka4a71df52008-02-15 09:19:42 +0100840 .get_strings = qeth_core_get_strings,
841 .get_ethtool_stats = qeth_core_get_ethtool_stats,
Ben Hutchingsdf8b4ec2009-10-01 11:24:32 +0000842 .get_sset_count = qeth_core_get_sset_count,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100843 .get_drvinfo = qeth_core_get_drvinfo,
844};
845
Frank Blaschka3d58cef2009-01-09 03:44:00 +0000846static const struct net_device_ops qeth_l2_netdev_ops = {
Frank Blaschka8403b132009-01-08 10:50:55 -0800847 .ndo_open = qeth_l2_open,
848 .ndo_stop = qeth_l2_stop,
849 .ndo_get_stats = qeth_get_stats,
850 .ndo_start_xmit = qeth_l2_hard_start_xmit,
Julian Wiedmann6d69b1f2017-12-01 10:14:50 +0100851 .ndo_features_check = qeth_features_check,
Frank Blaschka8403b132009-01-08 10:50:55 -0800852 .ndo_validate_addr = eth_validate_addr,
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200853 .ndo_set_rx_mode = qeth_l2_set_rx_mode,
Julian Wiedmann942d6982017-04-11 16:11:10 +0200854 .ndo_do_ioctl = qeth_do_ioctl,
Frank Blaschka8403b132009-01-08 10:50:55 -0800855 .ndo_set_mac_address = qeth_l2_set_mac_address,
Frank Blaschka8403b132009-01-08 10:50:55 -0800856 .ndo_vlan_rx_add_vid = qeth_l2_vlan_rx_add_vid,
857 .ndo_vlan_rx_kill_vid = qeth_l2_vlan_rx_kill_vid,
858 .ndo_tx_timeout = qeth_tx_timeout,
Thomas Richter8f43fb02016-06-16 16:18:59 +0200859 .ndo_fix_features = qeth_fix_features,
860 .ndo_set_features = qeth_set_features
Frank Blaschka8403b132009-01-08 10:50:55 -0800861};
862
Julian Wiedmann9fae5c32018-11-02 19:04:11 +0100863static int qeth_l2_setup_netdev(struct qeth_card *card, bool carrier_ok)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100864{
Julian Wiedmannd3d1b202018-07-19 12:43:51 +0200865 int rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100866
Julian Wiedmann30356d02018-11-02 19:04:10 +0100867 if (qeth_netdev_is_registered(card->dev))
Julian Wiedmannd3d1b202018-07-19 12:43:51 +0200868 return 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100869
Julian Wiedmannd3aacac2018-03-09 18:12:55 +0100870 card->dev->priv_flags |= IFF_UNICAST_FLT;
Frank Blaschka8403b132009-01-08 10:50:55 -0800871 card->dev->netdev_ops = &qeth_l2_netdev_ops;
Julian Wiedmann25e2c342017-05-10 19:07:53 +0200872 if (card->info.type == QETH_CARD_TYPE_OSN) {
873 card->dev->ethtool_ops = &qeth_l2_osn_ops;
874 card->dev->flags |= IFF_NOARP;
875 } else {
876 card->dev->ethtool_ops = &qeth_l2_ethtool_ops;
Julian Wiedmann5f89eca2018-07-19 12:43:58 +0200877 card->dev->needed_headroom = sizeof(struct qeth_hdr);
Julian Wiedmann25e2c342017-05-10 19:07:53 +0200878 }
Julian Wiedmann9400c532017-10-18 17:40:20 +0200879
880 if (card->info.type == QETH_CARD_TYPE_OSM)
881 card->dev->features |= NETIF_F_VLAN_CHALLENGED;
882 else
883 card->dev->features |= NETIF_F_HW_VLAN_CTAG_FILTER;
Julian Wiedmann0f342942018-03-09 18:12:54 +0100884
Thomas Richter4d7def22015-09-18 16:06:51 +0200885 if (card->info.type == QETH_CARD_TYPE_OSD && !card->info.guestlan) {
Julian Wiedmann6d69b1f2017-12-01 10:14:50 +0100886 card->dev->features |= NETIF_F_SG;
Thomas Richter8f43fb02016-06-16 16:18:59 +0200887 /* OSA 3S and earlier has no RX/TX support */
Hans Wippel9bdc4412016-06-16 16:19:00 +0200888 if (qeth_is_supported(card, IPA_OUTBOUND_CHECKSUM)) {
Thomas Richter8f43fb02016-06-16 16:18:59 +0200889 card->dev->hw_features |= NETIF_F_IP_CSUM;
Hans Wippel9bdc4412016-06-16 16:19:00 +0200890 card->dev->vlan_features |= NETIF_F_IP_CSUM;
891 }
Thomas Richter4d7def22015-09-18 16:06:51 +0200892 }
Kittipon Meesompop571f9dd82018-04-26 09:42:22 +0200893 if (qeth_is_supported6(card, IPA_OUTBOUND_CHECKSUM_V6)) {
894 card->dev->hw_features |= NETIF_F_IPV6_CSUM;
895 card->dev->vlan_features |= NETIF_F_IPV6_CSUM;
896 }
Kittipon Meesompopd7e6ed92018-04-26 09:42:23 +0200897 if (qeth_is_supported(card, IPA_INBOUND_CHECKSUM) ||
898 qeth_is_supported6(card, IPA_INBOUND_CHECKSUM_V6)) {
899 card->dev->hw_features |= NETIF_F_RXCSUM;
900 card->dev->vlan_features |= NETIF_F_RXCSUM;
901 }
Julian Wiedmann0aef8392018-10-12 17:27:15 +0200902 if (qeth_is_supported(card, IPA_OUTBOUND_TSO)) {
903 card->dev->hw_features |= NETIF_F_TSO;
904 card->dev->vlan_features |= NETIF_F_TSO;
905 }
906 if (qeth_is_supported6(card, IPA_OUTBOUND_TSO)) {
907 card->dev->hw_features |= NETIF_F_TSO6;
908 card->dev->vlan_features |= NETIF_F_TSO6;
909 }
910
911 if (card->dev->hw_features & (NETIF_F_TSO | NETIF_F_TSO6)) {
912 card->dev->needed_headroom = sizeof(struct qeth_hdr_tso);
913 netif_set_gso_max_size(card->dev,
914 PAGE_SIZE * (QDIO_MAX_ELEMENTS_PER_BUFFER - 1));
915 }
Julian Wiedmann0d6f02d2017-08-18 10:19:10 +0200916
Julian Wiedmannb144b992018-11-08 15:06:15 +0100917 if (!is_valid_ether_addr(card->dev->dev_addr))
918 qeth_l2_request_initial_mac(card);
Julian Wiedmannd73ef322017-04-11 16:11:11 +0200919 netif_napi_add(card->dev, &card->napi, qeth_poll, QETH_NAPI_WEIGHT);
Julian Wiedmannd3d1b202018-07-19 12:43:51 +0200920 rc = register_netdev(card->dev);
Julian Wiedmann9fae5c32018-11-02 19:04:11 +0100921 if (!rc && carrier_ok)
922 netif_carrier_on(card->dev);
923
Julian Wiedmannd3d1b202018-07-19 12:43:51 +0200924 if (rc)
925 card->dev->netdev_ops = NULL;
926 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100927}
928
Thomas Richter4d7def22015-09-18 16:06:51 +0200929static int qeth_l2_start_ipassists(struct qeth_card *card)
930{
931 /* configure isolation level */
932 if (qeth_set_access_ctrl_online(card, 0))
933 return -ENODEV;
Thomas Richter4d7def22015-09-18 16:06:51 +0200934 return 0;
935}
936
Julian Wiedmann521c10e2017-06-06 14:33:45 +0200937static void qeth_l2_trace_features(struct qeth_card *card)
938{
Hans Wippela45b3fa2017-09-18 21:18:14 +0200939 /* Set BridgePort features */
940 QETH_CARD_TEXT(card, 2, "featuSBP");
Julian Wiedmann521c10e2017-06-06 14:33:45 +0200941 QETH_CARD_HEX(card, 2, &card->options.sbp.supported_funcs,
942 sizeof(card->options.sbp.supported_funcs));
Hans Wippela45b3fa2017-09-18 21:18:14 +0200943 /* VNIC Characteristics features */
944 QETH_CARD_TEXT(card, 2, "feaVNICC");
945 QETH_CARD_HEX(card, 2, &card->options.vnicc.sup_chars,
946 sizeof(card->options.vnicc.sup_chars));
Julian Wiedmann521c10e2017-06-06 14:33:45 +0200947}
948
Frank Blaschka4a71df52008-02-15 09:19:42 +0100949static int __qeth_l2_set_online(struct ccwgroup_device *gdev, int recovery_mode)
950{
951 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
952 int rc = 0;
953 enum qeth_card_states recover_flag;
Julian Wiedmann9fae5c32018-11-02 19:04:11 +0100954 bool carrier_ok;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100955
Ursula Braun9dc48cc2010-07-22 23:15:05 +0000956 mutex_lock(&card->discipline_mutex);
Frank Blaschkac4949f02010-05-11 19:34:47 +0000957 mutex_lock(&card->conf_mutex);
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200958 QETH_DBF_TEXT(SETUP, 2, "setonlin");
959 QETH_DBF_HEX(SETUP, 2, &card, sizeof(void *));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100960
Frank Blaschka4a71df52008-02-15 09:19:42 +0100961 recover_flag = card->state;
Julian Wiedmann9fae5c32018-11-02 19:04:11 +0100962 rc = qeth_core_hardsetup_card(card, &carrier_ok);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100963 if (rc) {
Thomas Richter1aec42b2015-01-21 13:39:10 +0100964 QETH_DBF_TEXT_(SETUP, 2, "2err%04x", rc);
Ursula Braunaa909222009-11-12 00:11:43 +0000965 rc = -ENODEV;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100966 goto out_remove;
967 }
Eugene Crosserc044dc22014-01-29 09:23:48 +0100968 qeth_bridgeport_query_support(card);
969 if (card->options.sbp.supported_funcs)
970 dev_info(&card->gdev->dev,
Eugene Crosser9c23f4da2015-05-18 14:27:56 +0200971 "The device represents a Bridge Capable Port\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100972
Julian Wiedmann9fae5c32018-11-02 19:04:11 +0100973 rc = qeth_l2_setup_netdev(card, carrier_ok);
Julian Wiedmannd3d1b202018-07-19 12:43:51 +0200974 if (rc)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100975 goto out_remove;
976
Julian Wiedmannbcacfcb2018-04-19 12:52:09 +0200977 if (card->info.type != QETH_CARD_TYPE_OSN &&
978 !qeth_l2_send_setmac(card, card->dev->dev_addr))
979 card->info.mac_bits |= QETH_LAYER2_MAC_REGISTERED;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100980
Frank Blaschka1da74b12011-05-12 18:45:02 +0000981 if (qeth_is_diagass_supported(card, QETH_DIAGS_CMD_TRAP)) {
982 if (card->info.hwtrap &&
983 qeth_hw_trap(card, QETH_DIAGS_TRAP_ARM))
984 card->info.hwtrap = 0;
985 } else
986 card->info.hwtrap = 0;
987
Hans Wippela45b3fa2017-09-18 21:18:14 +0200988 /* for the rx_bcast characteristic, init VNICC after setmac */
989 qeth_l2_vnicc_init(card);
990
991 qeth_trace_features(card);
992 qeth_l2_trace_features(card);
993
Eugene Crosserb4d72c02014-01-14 15:54:11 +0100994 qeth_l2_setup_bridgeport_attrs(card);
995
Frank Blaschka4a71df52008-02-15 09:19:42 +0100996 card->state = CARD_STATE_HARDSETUP;
997 qeth_print_status_message(card);
998
999 /* softsetup */
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001000 QETH_DBF_TEXT(SETUP, 2, "softsetp");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001001
Ursula Braun5113fec2010-05-16 21:15:14 +00001002 if ((card->info.type == QETH_CARD_TYPE_OSD) ||
Stefan Raspl0f547612013-01-21 02:30:20 +00001003 (card->info.type == QETH_CARD_TYPE_OSX)) {
Thomas Richter8f43fb02016-06-16 16:18:59 +02001004 rc = qeth_l2_start_ipassists(card);
1005 if (rc)
Stefan Raspl0f547612013-01-21 02:30:20 +00001006 goto out_remove;
Stefan Raspl0f547612013-01-21 02:30:20 +00001007 }
Ursula Braun5113fec2010-05-16 21:15:14 +00001008
Julian Wiedmann9400c532017-10-18 17:40:20 +02001009 if (card->info.type != QETH_CARD_TYPE_OSN)
Ursula Braun70919e22011-02-26 22:41:36 -08001010 qeth_l2_process_vlans(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001011
1012 netif_tx_disable(card->dev);
1013
1014 rc = qeth_init_qdio_queues(card);
1015 if (rc) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001016 QETH_DBF_TEXT_(SETUP, 2, "6err%d", rc);
Ursula Braunaa909222009-11-12 00:11:43 +00001017 rc = -ENODEV;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001018 goto out_remove;
1019 }
1020 card->state = CARD_STATE_SOFTSETUP;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001021
1022 qeth_set_allowed_threads(card, 0xffffffff, 0);
Julian Wiedmannd025da92018-06-29 19:45:54 +02001023
1024 qeth_enable_hw_features(card->dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001025 if (recover_flag == CARD_STATE_RECOVER) {
1026 if (recovery_mode &&
1027 card->info.type != QETH_CARD_TYPE_OSN) {
Ursula Braun39423442011-01-12 20:42:24 +00001028 __qeth_l2_open(card->dev);
Julian Wiedmann9aa17df2018-07-11 17:42:40 +02001029 qeth_l2_set_rx_mode(card->dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001030 } else {
1031 rtnl_lock();
1032 dev_open(card->dev);
1033 rtnl_unlock();
1034 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01001035 }
1036 /* let user_space know that device is online */
1037 kobject_uevent(&gdev->dev.kobj, KOBJ_CHANGE);
Frank Blaschkac4949f02010-05-11 19:34:47 +00001038 mutex_unlock(&card->conf_mutex);
Ursula Braun9dc48cc2010-07-22 23:15:05 +00001039 mutex_unlock(&card->discipline_mutex);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001040 return 0;
Ursula Braunaa909222009-11-12 00:11:43 +00001041
Frank Blaschka4a71df52008-02-15 09:19:42 +01001042out_remove:
Frank Blaschka4a71df52008-02-15 09:19:42 +01001043 qeth_l2_stop_card(card, 0);
1044 ccw_device_set_offline(CARD_DDEV(card));
1045 ccw_device_set_offline(CARD_WDEV(card));
1046 ccw_device_set_offline(CARD_RDEV(card));
Ursula Braun22ae2792014-02-24 13:12:06 +01001047 qdio_free(CARD_DDEV(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001048 if (recover_flag == CARD_STATE_RECOVER)
1049 card->state = CARD_STATE_RECOVER;
1050 else
1051 card->state = CARD_STATE_DOWN;
Frank Blaschkac4949f02010-05-11 19:34:47 +00001052 mutex_unlock(&card->conf_mutex);
Ursula Braun9dc48cc2010-07-22 23:15:05 +00001053 mutex_unlock(&card->discipline_mutex);
Ursula Braunaa909222009-11-12 00:11:43 +00001054 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001055}
1056
1057static int qeth_l2_set_online(struct ccwgroup_device *gdev)
1058{
1059 return __qeth_l2_set_online(gdev, 0);
1060}
1061
1062static int __qeth_l2_set_offline(struct ccwgroup_device *cgdev,
1063 int recovery_mode)
1064{
1065 struct qeth_card *card = dev_get_drvdata(&cgdev->dev);
1066 int rc = 0, rc2 = 0, rc3 = 0;
1067 enum qeth_card_states recover_flag;
1068
Ursula Braun9dc48cc2010-07-22 23:15:05 +00001069 mutex_lock(&card->discipline_mutex);
Frank Blaschkac4949f02010-05-11 19:34:47 +00001070 mutex_lock(&card->conf_mutex);
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001071 QETH_DBF_TEXT(SETUP, 3, "setoffl");
1072 QETH_DBF_HEX(SETUP, 3, &card, sizeof(void *));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001073
Julian Wiedmannd3d1b202018-07-19 12:43:51 +02001074 netif_carrier_off(card->dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001075 recover_flag = card->state;
Frank Blaschka1da74b12011-05-12 18:45:02 +00001076 if ((!recovery_mode && card->info.hwtrap) || card->info.hwtrap == 2) {
1077 qeth_hw_trap(card, QETH_DIAGS_TRAP_DISARM);
1078 card->info.hwtrap = 1;
1079 }
Ursula Braun0f5623c2008-10-24 11:16:52 +02001080 qeth_l2_stop_card(card, recovery_mode);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001081 rc = ccw_device_set_offline(CARD_DDEV(card));
1082 rc2 = ccw_device_set_offline(CARD_WDEV(card));
1083 rc3 = ccw_device_set_offline(CARD_RDEV(card));
1084 if (!rc)
1085 rc = (rc2) ? rc2 : rc3;
1086 if (rc)
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001087 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
Ursula Braun22ae2792014-02-24 13:12:06 +01001088 qdio_free(CARD_DDEV(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001089 if (recover_flag == CARD_STATE_UP)
1090 card->state = CARD_STATE_RECOVER;
1091 /* let user_space know that device is offline */
1092 kobject_uevent(&cgdev->dev.kobj, KOBJ_CHANGE);
Frank Blaschkac4949f02010-05-11 19:34:47 +00001093 mutex_unlock(&card->conf_mutex);
Ursula Braun9dc48cc2010-07-22 23:15:05 +00001094 mutex_unlock(&card->discipline_mutex);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001095 return 0;
1096}
1097
1098static int qeth_l2_set_offline(struct ccwgroup_device *cgdev)
1099{
1100 return __qeth_l2_set_offline(cgdev, 0);
1101}
1102
1103static int qeth_l2_recover(void *ptr)
1104{
1105 struct qeth_card *card;
1106 int rc = 0;
1107
1108 card = (struct qeth_card *) ptr;
Carsten Otte847a50f2010-06-21 22:57:05 +00001109 QETH_CARD_TEXT(card, 2, "recover1");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001110 if (!qeth_do_run_thread(card, QETH_RECOVER_THREAD))
1111 return 0;
Carsten Otte847a50f2010-06-21 22:57:05 +00001112 QETH_CARD_TEXT(card, 2, "recover2");
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001113 dev_warn(&card->gdev->dev,
1114 "A recovery process has been started for the device\n");
Stefan Raspl65d80132013-04-07 22:19:27 +00001115 qeth_set_recovery_task(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001116 __qeth_l2_set_offline(card->gdev, 1);
1117 rc = __qeth_l2_set_online(card->gdev, 1);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001118 if (!rc)
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001119 dev_info(&card->gdev->dev,
1120 "Device successfully recovered!\n");
Ursula Braun28a7e4c2008-09-19 12:56:03 +02001121 else {
Stefan Raspl0f547612013-01-21 02:30:20 +00001122 qeth_close_dev(card);
1123 dev_warn(&card->gdev->dev, "The qeth device driver "
Stefan Raspl2efaf5f2012-10-15 19:21:18 +00001124 "failed to recover an error on the device\n");
Ursula Braun28a7e4c2008-09-19 12:56:03 +02001125 }
Stefan Raspl65d80132013-04-07 22:19:27 +00001126 qeth_clear_recovery_task(card);
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00001127 qeth_clear_thread_start_bit(card, QETH_RECOVER_THREAD);
1128 qeth_clear_thread_running_bit(card, QETH_RECOVER_THREAD);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001129 return 0;
1130}
1131
1132static int __init qeth_l2_init(void)
1133{
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001134 pr_info("register layer 2 discipline\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001135 return 0;
1136}
1137
1138static void __exit qeth_l2_exit(void)
1139{
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001140 pr_info("unregister layer 2 discipline\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001141}
1142
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02001143static int qeth_l2_pm_suspend(struct ccwgroup_device *gdev)
1144{
1145 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
1146
Julian Wiedmannd3d1b202018-07-19 12:43:51 +02001147 netif_device_detach(card->dev);
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02001148 qeth_set_allowed_threads(card, 0, 1);
1149 wait_event(card->wait_q, qeth_threads_running(card, 0xffffffff) == 0);
1150 if (gdev->state == CCWGROUP_OFFLINE)
1151 return 0;
1152 if (card->state == CARD_STATE_UP) {
Frank Blaschka1da74b12011-05-12 18:45:02 +00001153 if (card->info.hwtrap)
1154 qeth_hw_trap(card, QETH_DIAGS_TRAP_DISARM);
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02001155 __qeth_l2_set_offline(card->gdev, 1);
1156 } else
1157 __qeth_l2_set_offline(card->gdev, 0);
1158 return 0;
1159}
1160
1161static int qeth_l2_pm_resume(struct ccwgroup_device *gdev)
1162{
1163 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
1164 int rc = 0;
1165
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02001166 if (card->state == CARD_STATE_RECOVER) {
1167 rc = __qeth_l2_set_online(card->gdev, 1);
1168 if (rc) {
Ursula Braun869da902010-03-08 20:36:56 +00001169 rtnl_lock();
1170 dev_close(card->dev);
1171 rtnl_unlock();
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02001172 }
1173 } else
1174 rc = __qeth_l2_set_online(card->gdev, 0);
Julian Wiedmann6585ac42018-09-26 18:29:12 +02001175
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02001176 qeth_set_allowed_threads(card, 0xffffffff, 0);
Julian Wiedmannd3d1b202018-07-19 12:43:51 +02001177 netif_device_attach(card->dev);
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02001178 if (rc)
1179 dev_warn(&card->gdev->dev, "The qeth device driver "
1180 "failed to recover an error on the device\n");
1181 return rc;
1182}
1183
Eugene Crosserc044dc22014-01-29 09:23:48 +01001184/* Returns zero if the command is successfully "consumed" */
1185static int qeth_l2_control_event(struct qeth_card *card,
1186 struct qeth_ipa_cmd *cmd)
1187{
1188 switch (cmd->hdr.command) {
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001189 case IPA_CMD_SETBRIDGEPORT_OSA:
1190 case IPA_CMD_SETBRIDGEPORT_IQD:
Eugene Crosserc044dc22014-01-29 09:23:48 +01001191 if (cmd->data.sbp.hdr.command_code ==
1192 IPA_SBP_BRIDGE_PORT_STATE_CHANGE) {
1193 qeth_bridge_state_change(card, cmd);
1194 return 0;
1195 } else
1196 return 1;
1197 case IPA_CMD_ADDRESS_CHANGE_NOTIF:
1198 qeth_bridge_host_event(card, cmd);
1199 return 0;
1200 default:
1201 return 1;
1202 }
1203}
1204
Sebastian Ottc041f2d4872012-05-15 18:02:21 +02001205struct qeth_discipline qeth_l2_discipline = {
Julian Wiedmann2d2ebb32017-05-10 19:07:52 +02001206 .devtype = &qeth_l2_devtype,
Julian Wiedmannd73ef322017-04-11 16:11:11 +02001207 .process_rx_buffer = qeth_l2_process_inbound_buffer,
Sebastian Ottc041f2d4872012-05-15 18:02:21 +02001208 .recover = qeth_l2_recover,
1209 .setup = qeth_l2_probe_device,
Frank Blaschka4a71df52008-02-15 09:19:42 +01001210 .remove = qeth_l2_remove_device,
1211 .set_online = qeth_l2_set_online,
1212 .set_offline = qeth_l2_set_offline,
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02001213 .freeze = qeth_l2_pm_suspend,
1214 .thaw = qeth_l2_pm_resume,
1215 .restore = qeth_l2_pm_resume,
Julian Wiedmann942d6982017-04-11 16:11:10 +02001216 .do_ioctl = NULL,
Eugene Crosserc044dc22014-01-29 09:23:48 +01001217 .control_event_handler = qeth_l2_control_event,
Frank Blaschka4a71df52008-02-15 09:19:42 +01001218};
Sebastian Ottc041f2d4872012-05-15 18:02:21 +02001219EXPORT_SYMBOL_GPL(qeth_l2_discipline);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001220
1221static int qeth_osn_send_control_data(struct qeth_card *card, int len,
1222 struct qeth_cmd_buffer *iob)
1223{
Julian Wiedmann750b1622018-08-09 14:47:59 +02001224 struct qeth_channel *channel = iob->channel;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001225 int rc = 0;
1226
Carsten Otte847a50f2010-06-21 22:57:05 +00001227 QETH_CARD_TEXT(card, 5, "osndctrd");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001228
1229 wait_event(card->wait_q,
Julian Wiedmann750b1622018-08-09 14:47:59 +02001230 atomic_cmpxchg(&channel->irq_pending, 0, 1) == 0);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001231 qeth_prepare_control_data(card, len, iob);
Carsten Otte847a50f2010-06-21 22:57:05 +00001232 QETH_CARD_TEXT(card, 6, "osnoirqp");
Julian Wiedmanned471552018-09-17 17:36:08 +02001233 spin_lock_irq(get_ccwdev_lock(channel->ccwdev));
Julian Wiedmannf15cdaf2018-08-09 14:48:03 +02001234 rc = ccw_device_start_timeout(channel->ccwdev, channel->ccw,
Julian Wiedmanndb71bbb2018-04-19 12:52:10 +02001235 (addr_t) iob, 0, 0, QETH_IPA_TIMEOUT);
Julian Wiedmanned471552018-09-17 17:36:08 +02001236 spin_unlock_irq(get_ccwdev_lock(channel->ccwdev));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001237 if (rc) {
Frank Blaschka14cc21b2008-06-06 12:37:46 +02001238 QETH_DBF_MESSAGE(2, "qeth_osn_send_control_data: "
Frank Blaschka4a71df52008-02-15 09:19:42 +01001239 "ccw_device_start rc = %i\n", rc);
Carsten Otte847a50f2010-06-21 22:57:05 +00001240 QETH_CARD_TEXT_(card, 2, " err%d", rc);
Julian Wiedmann750b1622018-08-09 14:47:59 +02001241 qeth_release_buffer(channel, iob);
1242 atomic_set(&channel->irq_pending, 0);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001243 wake_up(&card->wait_q);
1244 }
1245 return rc;
1246}
1247
1248static int qeth_osn_send_ipa_cmd(struct qeth_card *card,
1249 struct qeth_cmd_buffer *iob, int data_len)
1250{
1251 u16 s1, s2;
1252
Carsten Otte847a50f2010-06-21 22:57:05 +00001253 QETH_CARD_TEXT(card, 4, "osndipa");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001254
Julian Wiedmann73657a32018-08-09 14:47:58 +02001255 qeth_prepare_ipa_cmd(card, iob);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001256 s1 = (u16)(IPA_PDU_HEADER_SIZE + data_len);
1257 s2 = (u16)data_len;
1258 memcpy(QETH_IPA_PDU_LEN_TOTAL(iob->data), &s1, 2);
1259 memcpy(QETH_IPA_PDU_LEN_PDU1(iob->data), &s2, 2);
1260 memcpy(QETH_IPA_PDU_LEN_PDU2(iob->data), &s2, 2);
1261 memcpy(QETH_IPA_PDU_LEN_PDU3(iob->data), &s2, 2);
1262 return qeth_osn_send_control_data(card, s1, iob);
1263}
1264
1265int qeth_osn_assist(struct net_device *dev, void *data, int data_len)
1266{
1267 struct qeth_cmd_buffer *iob;
1268 struct qeth_card *card;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001269
Frank Blaschka4a71df52008-02-15 09:19:42 +01001270 if (!dev)
1271 return -ENODEV;
Heiko Carstens509e2562008-07-26 02:24:10 -07001272 card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001273 if (!card)
1274 return -ENODEV;
Carsten Otte847a50f2010-06-21 22:57:05 +00001275 QETH_CARD_TEXT(card, 2, "osnsdmc");
Eugene Crosserc3521252015-01-16 14:05:47 +01001276 if (!qeth_card_hw_is_reachable(card))
Frank Blaschka4a71df52008-02-15 09:19:42 +01001277 return -ENODEV;
1278 iob = qeth_wait_for_buffer(&card->write);
Julian Wiedmannff5caa72018-03-09 18:12:52 +01001279 memcpy(__ipa_cmd(iob), data, data_len);
1280 return qeth_osn_send_ipa_cmd(card, iob, data_len);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001281}
1282EXPORT_SYMBOL(qeth_osn_assist);
1283
1284int qeth_osn_register(unsigned char *read_dev_no, struct net_device **dev,
1285 int (*assist_cb)(struct net_device *, void *),
1286 int (*data_cb)(struct sk_buff *))
1287{
1288 struct qeth_card *card;
1289
Frank Blaschka4a71df52008-02-15 09:19:42 +01001290 *dev = qeth_l2_netdev_by_devno(read_dev_no);
1291 if (*dev == NULL)
1292 return -ENODEV;
Heiko Carstens509e2562008-07-26 02:24:10 -07001293 card = (*dev)->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001294 if (!card)
1295 return -ENODEV;
Carsten Otte847a50f2010-06-21 22:57:05 +00001296 QETH_CARD_TEXT(card, 2, "osnreg");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001297 if ((assist_cb == NULL) || (data_cb == NULL))
1298 return -EINVAL;
1299 card->osn_info.assist_cb = assist_cb;
1300 card->osn_info.data_cb = data_cb;
1301 return 0;
1302}
1303EXPORT_SYMBOL(qeth_osn_register);
1304
1305void qeth_osn_deregister(struct net_device *dev)
1306{
1307 struct qeth_card *card;
1308
Frank Blaschka4a71df52008-02-15 09:19:42 +01001309 if (!dev)
1310 return;
Heiko Carstens509e2562008-07-26 02:24:10 -07001311 card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001312 if (!card)
1313 return;
Carsten Otte847a50f2010-06-21 22:57:05 +00001314 QETH_CARD_TEXT(card, 2, "osndereg");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001315 card->osn_info.assist_cb = NULL;
1316 card->osn_info.data_cb = NULL;
1317 return;
1318}
1319EXPORT_SYMBOL(qeth_osn_deregister);
1320
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001321/* SETBRIDGEPORT support, async notifications */
1322
Eugene Crosser9f48b9d2014-01-14 15:54:13 +01001323enum qeth_an_event_type {anev_reg_unreg, anev_abort, anev_reset};
1324
1325/**
1326 * qeth_bridge_emit_host_event() - bridgeport address change notification
1327 * @card: qeth_card structure pointer, for udev events.
1328 * @evtype: "normal" register/unregister, or abort, or reset. For abort
1329 * and reset token and addr_lnid are unused and may be NULL.
1330 * @code: event bitmask: high order bit 0x80 value 1 means removal of an
1331 * object, 0 - addition of an object.
1332 * 0x01 - VLAN, 0x02 - MAC, 0x03 - VLAN and MAC.
1333 * @token: "network token" structure identifying physical address of the port.
1334 * @addr_lnid: pointer to structure with MAC address and VLAN ID.
1335 *
1336 * This function is called when registrations and deregistrations are
1337 * reported by the hardware, and also when notifications are enabled -
1338 * for all currently registered addresses.
1339 */
1340static void qeth_bridge_emit_host_event(struct qeth_card *card,
1341 enum qeth_an_event_type evtype,
1342 u8 code, struct net_if_token *token, struct mac_addr_lnid *addr_lnid)
1343{
1344 char str[7][32];
1345 char *env[8];
1346 int i = 0;
1347
1348 switch (evtype) {
1349 case anev_reg_unreg:
1350 snprintf(str[i], sizeof(str[i]), "BRIDGEDHOST=%s",
1351 (code & IPA_ADDR_CHANGE_CODE_REMOVAL)
1352 ? "deregister" : "register");
1353 env[i] = str[i]; i++;
1354 if (code & IPA_ADDR_CHANGE_CODE_VLANID) {
1355 snprintf(str[i], sizeof(str[i]), "VLAN=%d",
1356 addr_lnid->lnid);
1357 env[i] = str[i]; i++;
1358 }
1359 if (code & IPA_ADDR_CHANGE_CODE_MACADDR) {
Eugene Crosser9846e702015-09-18 16:06:48 +02001360 snprintf(str[i], sizeof(str[i]), "MAC=%pM",
Thomas Richter4d7def22015-09-18 16:06:51 +02001361 addr_lnid->mac);
Eugene Crosser9f48b9d2014-01-14 15:54:13 +01001362 env[i] = str[i]; i++;
1363 }
1364 snprintf(str[i], sizeof(str[i]), "NTOK_BUSID=%x.%x.%04x",
1365 token->cssid, token->ssid, token->devnum);
1366 env[i] = str[i]; i++;
1367 snprintf(str[i], sizeof(str[i]), "NTOK_IID=%02x", token->iid);
1368 env[i] = str[i]; i++;
1369 snprintf(str[i], sizeof(str[i]), "NTOK_CHPID=%02x",
1370 token->chpid);
1371 env[i] = str[i]; i++;
1372 snprintf(str[i], sizeof(str[i]), "NTOK_CHID=%04x", token->chid);
1373 env[i] = str[i]; i++;
1374 break;
1375 case anev_abort:
1376 snprintf(str[i], sizeof(str[i]), "BRIDGEDHOST=abort");
1377 env[i] = str[i]; i++;
1378 break;
1379 case anev_reset:
1380 snprintf(str[i], sizeof(str[i]), "BRIDGEDHOST=reset");
1381 env[i] = str[i]; i++;
1382 break;
1383 }
1384 env[i] = NULL;
1385 kobject_uevent_env(&card->gdev->dev.kobj, KOBJ_CHANGE, env);
1386}
1387
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001388struct qeth_bridge_state_data {
1389 struct work_struct worker;
1390 struct qeth_card *card;
1391 struct qeth_sbp_state_change qports;
1392};
1393
1394static void qeth_bridge_state_change_worker(struct work_struct *work)
1395{
1396 struct qeth_bridge_state_data *data =
1397 container_of(work, struct qeth_bridge_state_data, worker);
1398 /* We are only interested in the first entry - local port */
1399 struct qeth_sbp_port_entry *entry = &data->qports.entry[0];
1400 char env_locrem[32];
1401 char env_role[32];
1402 char env_state[32];
1403 char *env[] = {
1404 env_locrem,
1405 env_role,
1406 env_state,
1407 NULL
1408 };
1409
1410 /* Role should not change by itself, but if it did, */
1411 /* information from the hardware is authoritative. */
1412 mutex_lock(&data->card->conf_mutex);
1413 data->card->options.sbp.role = entry->role;
1414 mutex_unlock(&data->card->conf_mutex);
1415
1416 snprintf(env_locrem, sizeof(env_locrem), "BRIDGEPORT=statechange");
1417 snprintf(env_role, sizeof(env_role), "ROLE=%s",
1418 (entry->role == QETH_SBP_ROLE_NONE) ? "none" :
1419 (entry->role == QETH_SBP_ROLE_PRIMARY) ? "primary" :
1420 (entry->role == QETH_SBP_ROLE_SECONDARY) ? "secondary" :
1421 "<INVALID>");
1422 snprintf(env_state, sizeof(env_state), "STATE=%s",
1423 (entry->state == QETH_SBP_STATE_INACTIVE) ? "inactive" :
1424 (entry->state == QETH_SBP_STATE_STANDBY) ? "standby" :
1425 (entry->state == QETH_SBP_STATE_ACTIVE) ? "active" :
1426 "<INVALID>");
1427 kobject_uevent_env(&data->card->gdev->dev.kobj,
1428 KOBJ_CHANGE, env);
1429 kfree(data);
1430}
1431
Eugene Crosserc044dc22014-01-29 09:23:48 +01001432static void qeth_bridge_state_change(struct qeth_card *card,
1433 struct qeth_ipa_cmd *cmd)
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001434{
1435 struct qeth_sbp_state_change *qports =
1436 &cmd->data.sbp.data.state_change;
1437 struct qeth_bridge_state_data *data;
1438 int extrasize;
1439
1440 QETH_CARD_TEXT(card, 2, "brstchng");
1441 if (qports->entry_length != sizeof(struct qeth_sbp_port_entry)) {
Thomas Richter8a593142014-10-22 12:18:03 +02001442 QETH_CARD_TEXT_(card, 2, "BPsz%04x", qports->entry_length);
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001443 return;
1444 }
1445 extrasize = sizeof(struct qeth_sbp_port_entry) * qports->num_entries;
1446 data = kzalloc(sizeof(struct qeth_bridge_state_data) + extrasize,
1447 GFP_ATOMIC);
1448 if (!data) {
1449 QETH_CARD_TEXT(card, 2, "BPSalloc");
1450 return;
1451 }
1452 INIT_WORK(&data->worker, qeth_bridge_state_change_worker);
1453 data->card = card;
1454 memcpy(&data->qports, qports,
1455 sizeof(struct qeth_sbp_state_change) + extrasize);
1456 queue_work(qeth_wq, &data->worker);
1457}
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001458
Eugene Crosser9f48b9d2014-01-14 15:54:13 +01001459struct qeth_bridge_host_data {
1460 struct work_struct worker;
1461 struct qeth_card *card;
1462 struct qeth_ipacmd_addr_change hostevs;
1463};
1464
1465static void qeth_bridge_host_event_worker(struct work_struct *work)
1466{
1467 struct qeth_bridge_host_data *data =
1468 container_of(work, struct qeth_bridge_host_data, worker);
1469 int i;
1470
1471 if (data->hostevs.lost_event_mask) {
1472 dev_info(&data->card->gdev->dev,
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001473"Address notification from the Bridge Port stopped %s (%s)\n",
Eugene Crosser9f48b9d2014-01-14 15:54:13 +01001474 data->card->dev->name,
1475 (data->hostevs.lost_event_mask == 0x01)
1476 ? "Overflow"
1477 : (data->hostevs.lost_event_mask == 0x02)
1478 ? "Bridge port state change"
1479 : "Unknown reason");
1480 mutex_lock(&data->card->conf_mutex);
1481 data->card->options.sbp.hostnotification = 0;
1482 mutex_unlock(&data->card->conf_mutex);
1483 qeth_bridge_emit_host_event(data->card, anev_abort,
1484 0, NULL, NULL);
1485 } else
1486 for (i = 0; i < data->hostevs.num_entries; i++) {
1487 struct qeth_ipacmd_addr_change_entry *entry =
1488 &data->hostevs.entry[i];
1489 qeth_bridge_emit_host_event(data->card,
1490 anev_reg_unreg,
1491 entry->change_code,
1492 &entry->token, &entry->addr_lnid);
1493 }
1494 kfree(data);
1495}
1496
Eugene Crosserc044dc22014-01-29 09:23:48 +01001497static void qeth_bridge_host_event(struct qeth_card *card,
1498 struct qeth_ipa_cmd *cmd)
Eugene Crosser9f48b9d2014-01-14 15:54:13 +01001499{
1500 struct qeth_ipacmd_addr_change *hostevs =
1501 &cmd->data.addrchange;
1502 struct qeth_bridge_host_data *data;
1503 int extrasize;
1504
1505 QETH_CARD_TEXT(card, 2, "brhostev");
1506 if (cmd->hdr.return_code != 0x0000) {
1507 if (cmd->hdr.return_code == 0x0010) {
1508 if (hostevs->lost_event_mask == 0x00)
1509 hostevs->lost_event_mask = 0xff;
1510 } else {
1511 QETH_CARD_TEXT_(card, 2, "BPHe%04x",
1512 cmd->hdr.return_code);
1513 return;
1514 }
1515 }
1516 extrasize = sizeof(struct qeth_ipacmd_addr_change_entry) *
1517 hostevs->num_entries;
1518 data = kzalloc(sizeof(struct qeth_bridge_host_data) + extrasize,
1519 GFP_ATOMIC);
1520 if (!data) {
1521 QETH_CARD_TEXT(card, 2, "BPHalloc");
1522 return;
1523 }
1524 INIT_WORK(&data->worker, qeth_bridge_host_event_worker);
1525 data->card = card;
1526 memcpy(&data->hostevs, hostevs,
1527 sizeof(struct qeth_ipacmd_addr_change) + extrasize);
1528 queue_work(qeth_wq, &data->worker);
1529}
Eugene Crosser9f48b9d2014-01-14 15:54:13 +01001530
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001531/* SETBRIDGEPORT support; sending commands */
1532
1533struct _qeth_sbp_cbctl {
1534 u16 ipa_rc;
1535 u16 cmd_rc;
1536 union {
1537 u32 supported;
1538 struct {
1539 enum qeth_sbp_roles *role;
1540 enum qeth_sbp_states *state;
1541 } qports;
1542 } data;
1543};
1544
1545/**
1546 * qeth_bridgeport_makerc() - derive "traditional" error from hardware codes.
1547 * @card: qeth_card structure pointer, for debug messages.
1548 * @cbctl: state structure with hardware return codes.
1549 * @setcmd: IPA command code
1550 *
1551 * Returns negative errno-compatible error indication or 0 on success.
1552 */
1553static int qeth_bridgeport_makerc(struct qeth_card *card,
1554 struct _qeth_sbp_cbctl *cbctl, enum qeth_ipa_sbp_cmd setcmd)
1555{
1556 int rc;
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001557 int is_iqd = (card->info.type == QETH_CARD_TYPE_IQD);
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001558
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001559 if ((is_iqd && (cbctl->ipa_rc == IPA_RC_SUCCESS)) ||
1560 (!is_iqd && (cbctl->ipa_rc == cbctl->cmd_rc)))
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001561 switch (cbctl->cmd_rc) {
Kittipon Meesompop2063a5f2017-06-20 16:00:31 +02001562 case IPA_RC_SUCCESS:
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001563 rc = 0;
1564 break;
Kittipon Meesompop2063a5f2017-06-20 16:00:31 +02001565 case IPA_RC_L2_UNSUPPORTED_CMD:
1566 case IPA_RC_UNSUPPORTED_COMMAND:
Eugene Crosserffb95252015-05-18 14:27:58 +02001567 rc = -EOPNOTSUPP;
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001568 break;
Kittipon Meesompop2063a5f2017-06-20 16:00:31 +02001569 case IPA_RC_SBP_OSA_NOT_CONFIGURED:
1570 case IPA_RC_SBP_IQD_NOT_CONFIGURED:
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001571 rc = -ENODEV; /* maybe not the best code here? */
1572 dev_err(&card->gdev->dev,
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001573 "The device is not configured as a Bridge Port\n");
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001574 break;
Kittipon Meesompop2063a5f2017-06-20 16:00:31 +02001575 case IPA_RC_SBP_OSA_OS_MISMATCH:
1576 case IPA_RC_SBP_IQD_OS_MISMATCH:
Eugene Crosser1b05cf62016-06-16 16:18:51 +02001577 rc = -EPERM;
1578 dev_err(&card->gdev->dev,
1579 "A Bridge Port is already configured by a different operating system\n");
1580 break;
Kittipon Meesompop2063a5f2017-06-20 16:00:31 +02001581 case IPA_RC_SBP_OSA_ANO_DEV_PRIMARY:
1582 case IPA_RC_SBP_IQD_ANO_DEV_PRIMARY:
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001583 switch (setcmd) {
1584 case IPA_SBP_SET_PRIMARY_BRIDGE_PORT:
1585 rc = -EEXIST;
1586 dev_err(&card->gdev->dev,
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001587 "The LAN already has a primary Bridge Port\n");
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001588 break;
1589 case IPA_SBP_SET_SECONDARY_BRIDGE_PORT:
1590 rc = -EBUSY;
1591 dev_err(&card->gdev->dev,
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001592 "The device is already a primary Bridge Port\n");
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001593 break;
1594 default:
1595 rc = -EIO;
1596 }
1597 break;
Kittipon Meesompop2063a5f2017-06-20 16:00:31 +02001598 case IPA_RC_SBP_OSA_CURRENT_SECOND:
1599 case IPA_RC_SBP_IQD_CURRENT_SECOND:
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001600 rc = -EBUSY;
1601 dev_err(&card->gdev->dev,
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001602 "The device is already a secondary Bridge Port\n");
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001603 break;
Kittipon Meesompop2063a5f2017-06-20 16:00:31 +02001604 case IPA_RC_SBP_OSA_LIMIT_SECOND:
1605 case IPA_RC_SBP_IQD_LIMIT_SECOND:
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001606 rc = -EEXIST;
1607 dev_err(&card->gdev->dev,
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001608 "The LAN cannot have more secondary Bridge Ports\n");
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001609 break;
Kittipon Meesompop2063a5f2017-06-20 16:00:31 +02001610 case IPA_RC_SBP_OSA_CURRENT_PRIMARY:
1611 case IPA_RC_SBP_IQD_CURRENT_PRIMARY:
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001612 rc = -EBUSY;
1613 dev_err(&card->gdev->dev,
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001614 "The device is already a primary Bridge Port\n");
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001615 break;
Kittipon Meesompop2063a5f2017-06-20 16:00:31 +02001616 case IPA_RC_SBP_OSA_NOT_AUTHD_BY_ZMAN:
1617 case IPA_RC_SBP_IQD_NOT_AUTHD_BY_ZMAN:
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001618 rc = -EACCES;
1619 dev_err(&card->gdev->dev,
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001620 "The device is not authorized to be a Bridge Port\n");
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001621 break;
1622 default:
1623 rc = -EIO;
1624 }
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001625 else
1626 switch (cbctl->ipa_rc) {
1627 case IPA_RC_NOTSUPP:
Eugene Crosserffb95252015-05-18 14:27:58 +02001628 rc = -EOPNOTSUPP;
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001629 break;
1630 case IPA_RC_UNSUPPORTED_COMMAND:
Eugene Crosserffb95252015-05-18 14:27:58 +02001631 rc = -EOPNOTSUPP;
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001632 break;
1633 default:
1634 rc = -EIO;
1635 }
1636
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001637 if (rc) {
1638 QETH_CARD_TEXT_(card, 2, "SBPi%04x", cbctl->ipa_rc);
1639 QETH_CARD_TEXT_(card, 2, "SBPc%04x", cbctl->cmd_rc);
1640 }
1641 return rc;
1642}
1643
Julian Wiedmannd65626a2017-08-15 17:02:47 +02001644static struct qeth_cmd_buffer *qeth_sbp_build_cmd(struct qeth_card *card,
1645 enum qeth_ipa_sbp_cmd sbp_cmd,
1646 unsigned int cmd_length)
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001647{
Julian Wiedmannd65626a2017-08-15 17:02:47 +02001648 enum qeth_ipa_cmds ipa_cmd = (card->info.type == QETH_CARD_TYPE_IQD) ?
1649 IPA_CMD_SETBRIDGEPORT_IQD :
1650 IPA_CMD_SETBRIDGEPORT_OSA;
1651 struct qeth_cmd_buffer *iob;
1652 struct qeth_ipa_cmd *cmd;
1653
1654 iob = qeth_get_ipacmd_buffer(card, ipa_cmd, 0);
1655 if (!iob)
1656 return iob;
Julian Wiedmannff5caa72018-03-09 18:12:52 +01001657 cmd = __ipa_cmd(iob);
Julian Wiedmannd65626a2017-08-15 17:02:47 +02001658 cmd->data.sbp.hdr.cmdlength = sizeof(struct qeth_ipacmd_sbp_hdr) +
1659 cmd_length;
1660 cmd->data.sbp.hdr.command_code = sbp_cmd;
1661 cmd->data.sbp.hdr.used_total = 1;
1662 cmd->data.sbp.hdr.seq_no = 1;
1663 return iob;
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001664}
1665
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001666static int qeth_bridgeport_query_support_cb(struct qeth_card *card,
1667 struct qeth_reply *reply, unsigned long data)
1668{
1669 struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *) data;
1670 struct _qeth_sbp_cbctl *cbctl = (struct _qeth_sbp_cbctl *)reply->param;
1671 QETH_CARD_TEXT(card, 2, "brqsupcb");
1672 cbctl->ipa_rc = cmd->hdr.return_code;
1673 cbctl->cmd_rc = cmd->data.sbp.hdr.return_code;
1674 if ((cbctl->ipa_rc == 0) && (cbctl->cmd_rc == 0)) {
1675 cbctl->data.supported =
1676 cmd->data.sbp.data.query_cmds_supp.supported_cmds;
1677 } else {
1678 cbctl->data.supported = 0;
1679 }
1680 return 0;
1681}
1682
1683/**
1684 * qeth_bridgeport_query_support() - store bitmask of supported subfunctions.
1685 * @card: qeth_card structure pointer.
1686 *
1687 * Sets bitmask of supported setbridgeport subfunctions in the qeth_card
1688 * strucutre: card->options.sbp.supported_funcs.
1689 */
Eugene Crosserc044dc22014-01-29 09:23:48 +01001690static void qeth_bridgeport_query_support(struct qeth_card *card)
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001691{
1692 struct qeth_cmd_buffer *iob;
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001693 struct _qeth_sbp_cbctl cbctl;
1694
1695 QETH_CARD_TEXT(card, 2, "brqsuppo");
Julian Wiedmannd65626a2017-08-15 17:02:47 +02001696 iob = qeth_sbp_build_cmd(card, IPA_SBP_QUERY_COMMANDS_SUPPORTED,
1697 sizeof(struct qeth_sbp_query_cmds_supp));
Thomas Richter1aec42b2015-01-21 13:39:10 +01001698 if (!iob)
1699 return;
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001700 if (qeth_send_ipa_cmd(card, iob, qeth_bridgeport_query_support_cb,
1701 (void *)&cbctl) ||
1702 qeth_bridgeport_makerc(card, &cbctl,
1703 IPA_SBP_QUERY_COMMANDS_SUPPORTED)) {
1704 /* non-zero makerc signifies failure, and produce messages */
1705 card->options.sbp.role = QETH_SBP_ROLE_NONE;
1706 return;
1707 }
1708 card->options.sbp.supported_funcs = cbctl.data.supported;
1709}
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001710
1711static int qeth_bridgeport_query_ports_cb(struct qeth_card *card,
1712 struct qeth_reply *reply, unsigned long data)
1713{
1714 struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *) data;
1715 struct qeth_sbp_query_ports *qports = &cmd->data.sbp.data.query_ports;
1716 struct _qeth_sbp_cbctl *cbctl = (struct _qeth_sbp_cbctl *)reply->param;
1717
1718 QETH_CARD_TEXT(card, 2, "brqprtcb");
1719 cbctl->ipa_rc = cmd->hdr.return_code;
1720 cbctl->cmd_rc = cmd->data.sbp.hdr.return_code;
1721 if ((cbctl->ipa_rc != 0) || (cbctl->cmd_rc != 0))
1722 return 0;
1723 if (qports->entry_length != sizeof(struct qeth_sbp_port_entry)) {
1724 cbctl->cmd_rc = 0xffff;
1725 QETH_CARD_TEXT_(card, 2, "SBPs%04x", qports->entry_length);
1726 return 0;
1727 }
1728 /* first entry contains the state of the local port */
1729 if (qports->num_entries > 0) {
1730 if (cbctl->data.qports.role)
1731 *cbctl->data.qports.role = qports->entry[0].role;
1732 if (cbctl->data.qports.state)
1733 *cbctl->data.qports.state = qports->entry[0].state;
1734 }
1735 return 0;
1736}
1737
1738/**
1739 * qeth_bridgeport_query_ports() - query local bridgeport status.
1740 * @card: qeth_card structure pointer.
1741 * @role: Role of the port: 0-none, 1-primary, 2-secondary.
1742 * @state: State of the port: 0-inactive, 1-standby, 2-active.
1743 *
1744 * Returns negative errno-compatible error indication or 0 on success.
1745 *
1746 * 'role' and 'state' are not updated in case of hardware operation failure.
1747 */
1748int qeth_bridgeport_query_ports(struct qeth_card *card,
1749 enum qeth_sbp_roles *role, enum qeth_sbp_states *state)
1750{
1751 int rc = 0;
1752 struct qeth_cmd_buffer *iob;
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001753 struct _qeth_sbp_cbctl cbctl = {
1754 .data = {
1755 .qports = {
1756 .role = role,
1757 .state = state,
1758 },
1759 },
1760 };
1761
1762 QETH_CARD_TEXT(card, 2, "brqports");
1763 if (!(card->options.sbp.supported_funcs & IPA_SBP_QUERY_BRIDGE_PORTS))
1764 return -EOPNOTSUPP;
Julian Wiedmannd65626a2017-08-15 17:02:47 +02001765 iob = qeth_sbp_build_cmd(card, IPA_SBP_QUERY_BRIDGE_PORTS, 0);
Thomas Richter1aec42b2015-01-21 13:39:10 +01001766 if (!iob)
1767 return -ENOMEM;
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001768 rc = qeth_send_ipa_cmd(card, iob, qeth_bridgeport_query_ports_cb,
1769 (void *)&cbctl);
Eugene Crosserc88394e2015-05-18 14:27:53 +02001770 if (rc < 0)
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001771 return rc;
Eugene Crosserc88394e2015-05-18 14:27:53 +02001772 return qeth_bridgeport_makerc(card, &cbctl, IPA_SBP_QUERY_BRIDGE_PORTS);
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001773}
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001774
1775static int qeth_bridgeport_set_cb(struct qeth_card *card,
1776 struct qeth_reply *reply, unsigned long data)
1777{
1778 struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *)data;
1779 struct _qeth_sbp_cbctl *cbctl = (struct _qeth_sbp_cbctl *)reply->param;
1780 QETH_CARD_TEXT(card, 2, "brsetrcb");
1781 cbctl->ipa_rc = cmd->hdr.return_code;
1782 cbctl->cmd_rc = cmd->data.sbp.hdr.return_code;
1783 return 0;
1784}
1785
1786/**
1787 * qeth_bridgeport_setrole() - Assign primary role to the port.
1788 * @card: qeth_card structure pointer.
1789 * @role: Role to assign.
1790 *
1791 * Returns negative errno-compatible error indication or 0 on success.
1792 */
1793int qeth_bridgeport_setrole(struct qeth_card *card, enum qeth_sbp_roles role)
1794{
1795 int rc = 0;
1796 int cmdlength;
1797 struct qeth_cmd_buffer *iob;
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001798 struct _qeth_sbp_cbctl cbctl;
1799 enum qeth_ipa_sbp_cmd setcmd;
1800
1801 QETH_CARD_TEXT(card, 2, "brsetrol");
1802 switch (role) {
1803 case QETH_SBP_ROLE_NONE:
1804 setcmd = IPA_SBP_RESET_BRIDGE_PORT_ROLE;
Julian Wiedmannd65626a2017-08-15 17:02:47 +02001805 cmdlength = sizeof(struct qeth_sbp_reset_role);
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001806 break;
1807 case QETH_SBP_ROLE_PRIMARY:
1808 setcmd = IPA_SBP_SET_PRIMARY_BRIDGE_PORT;
Julian Wiedmannd65626a2017-08-15 17:02:47 +02001809 cmdlength = sizeof(struct qeth_sbp_set_primary);
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001810 break;
1811 case QETH_SBP_ROLE_SECONDARY:
1812 setcmd = IPA_SBP_SET_SECONDARY_BRIDGE_PORT;
Julian Wiedmannd65626a2017-08-15 17:02:47 +02001813 cmdlength = sizeof(struct qeth_sbp_set_secondary);
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001814 break;
1815 default:
1816 return -EINVAL;
1817 }
1818 if (!(card->options.sbp.supported_funcs & setcmd))
1819 return -EOPNOTSUPP;
Julian Wiedmannd65626a2017-08-15 17:02:47 +02001820 iob = qeth_sbp_build_cmd(card, setcmd, cmdlength);
Thomas Richter1aec42b2015-01-21 13:39:10 +01001821 if (!iob)
1822 return -ENOMEM;
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001823 rc = qeth_send_ipa_cmd(card, iob, qeth_bridgeport_set_cb,
1824 (void *)&cbctl);
Eugene Crosserc88394e2015-05-18 14:27:53 +02001825 if (rc < 0)
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001826 return rc;
Eugene Crosserc88394e2015-05-18 14:27:53 +02001827 return qeth_bridgeport_makerc(card, &cbctl, setcmd);
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001828}
1829
Eugene Crosser9f48b9d2014-01-14 15:54:13 +01001830/**
1831 * qeth_anset_makerc() - derive "traditional" error from hardware codes.
1832 * @card: qeth_card structure pointer, for debug messages.
1833 *
1834 * Returns negative errno-compatible error indication or 0 on success.
1835 */
1836static int qeth_anset_makerc(struct qeth_card *card, int pnso_rc, u16 response)
1837{
1838 int rc;
1839
1840 if (pnso_rc == 0)
1841 switch (response) {
1842 case 0x0001:
1843 rc = 0;
1844 break;
1845 case 0x0004:
1846 case 0x0100:
1847 case 0x0106:
Eugene Crosserffb95252015-05-18 14:27:58 +02001848 rc = -EOPNOTSUPP;
Eugene Crosser9f48b9d2014-01-14 15:54:13 +01001849 dev_err(&card->gdev->dev,
1850 "Setting address notification failed\n");
1851 break;
1852 case 0x0107:
1853 rc = -EAGAIN;
1854 break;
1855 default:
1856 rc = -EIO;
1857 }
1858 else
1859 rc = -EIO;
1860
1861 if (rc) {
1862 QETH_CARD_TEXT_(card, 2, "SBPp%04x", pnso_rc);
1863 QETH_CARD_TEXT_(card, 2, "SBPr%04x", response);
1864 }
1865 return rc;
1866}
1867
1868static void qeth_bridgeport_an_set_cb(void *priv,
1869 enum qdio_brinfo_entry_type type, void *entry)
1870{
1871 struct qeth_card *card = (struct qeth_card *)priv;
1872 struct qdio_brinfo_entry_l2 *l2entry;
1873 u8 code;
1874
1875 if (type != l2_addr_lnid) {
1876 WARN_ON_ONCE(1);
1877 return;
1878 }
1879
1880 l2entry = (struct qdio_brinfo_entry_l2 *)entry;
1881 code = IPA_ADDR_CHANGE_CODE_MACADDR;
1882 if (l2entry->addr_lnid.lnid)
1883 code |= IPA_ADDR_CHANGE_CODE_VLANID;
1884 qeth_bridge_emit_host_event(card, anev_reg_unreg, code,
1885 (struct net_if_token *)&l2entry->nit,
1886 (struct mac_addr_lnid *)&l2entry->addr_lnid);
1887}
1888
1889/**
1890 * qeth_bridgeport_an_set() - Enable or disable bridgeport address notification
1891 * @card: qeth_card structure pointer.
1892 * @enable: 0 - disable, non-zero - enable notifications
1893 *
1894 * Returns negative errno-compatible error indication or 0 on success.
1895 *
1896 * On enable, emits a series of address notifications udev events for all
1897 * currently registered hosts.
1898 */
1899int qeth_bridgeport_an_set(struct qeth_card *card, int enable)
1900{
1901 int rc;
1902 u16 response;
1903 struct ccw_device *ddev;
1904 struct subchannel_id schid;
1905
1906 if (!card)
1907 return -EINVAL;
1908 if (!card->options.sbp.supported_funcs)
1909 return -EOPNOTSUPP;
1910 ddev = CARD_DDEV(card);
1911 ccw_device_get_schid(ddev, &schid);
1912
1913 if (enable) {
1914 qeth_bridge_emit_host_event(card, anev_reset, 0, NULL, NULL);
1915 rc = qdio_pnso_brinfo(schid, 1, &response,
1916 qeth_bridgeport_an_set_cb, card);
1917 } else
1918 rc = qdio_pnso_brinfo(schid, 0, &response, NULL, NULL);
1919 return qeth_anset_makerc(card, rc, response);
1920}
Eugene Crosser9f48b9d2014-01-14 15:54:13 +01001921
Hans Wippelcaa1f0b2017-09-18 21:18:15 +02001922static bool qeth_bridgeport_is_in_use(struct qeth_card *card)
1923{
1924 return (card->options.sbp.role || card->options.sbp.reflect_promisc ||
1925 card->options.sbp.hostnotification);
1926}
1927
Hans Wippela45b3fa2017-09-18 21:18:14 +02001928/* VNIC Characteristics support */
1929
1930/* handle VNICC IPA command return codes; convert to error codes */
1931static int qeth_l2_vnicc_makerc(struct qeth_card *card, int ipa_rc)
1932{
1933 int rc;
1934
1935 switch (ipa_rc) {
1936 case IPA_RC_SUCCESS:
1937 return ipa_rc;
1938 case IPA_RC_L2_UNSUPPORTED_CMD:
1939 case IPA_RC_NOTSUPP:
1940 rc = -EOPNOTSUPP;
1941 break;
1942 case IPA_RC_VNICC_OOSEQ:
1943 rc = -EALREADY;
1944 break;
1945 case IPA_RC_VNICC_VNICBP:
1946 rc = -EBUSY;
1947 break;
1948 case IPA_RC_L2_ADDR_TABLE_FULL:
1949 rc = -ENOSPC;
1950 break;
1951 case IPA_RC_L2_MAC_NOT_AUTH_BY_ADP:
1952 rc = -EACCES;
1953 break;
1954 default:
1955 rc = -EIO;
1956 }
1957
1958 QETH_CARD_TEXT_(card, 2, "err%04x", ipa_rc);
1959 return rc;
1960}
1961
1962/* generic VNICC request call back control */
1963struct _qeth_l2_vnicc_request_cbctl {
1964 u32 sub_cmd;
Hans Wippelcaa1f0b2017-09-18 21:18:15 +02001965 struct {
1966 u32 vnic_char;
Hans Wippel349d13d2017-09-18 21:18:16 +02001967 u32 timeout;
Hans Wippelcaa1f0b2017-09-18 21:18:15 +02001968 } param;
1969 struct {
Hans Wippel349d13d2017-09-18 21:18:16 +02001970 union{
1971 u32 *sup_cmds;
1972 u32 *timeout;
1973 };
Hans Wippelcaa1f0b2017-09-18 21:18:15 +02001974 } result;
Hans Wippela45b3fa2017-09-18 21:18:14 +02001975};
1976
1977/* generic VNICC request call back */
1978static int qeth_l2_vnicc_request_cb(struct qeth_card *card,
1979 struct qeth_reply *reply,
1980 unsigned long data)
1981{
Hans Wippelcaa1f0b2017-09-18 21:18:15 +02001982 struct _qeth_l2_vnicc_request_cbctl *cbctl =
1983 (struct _qeth_l2_vnicc_request_cbctl *) reply->param;
Hans Wippela45b3fa2017-09-18 21:18:14 +02001984 struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *) data;
1985 struct qeth_ipacmd_vnicc *rep = &cmd->data.vnicc;
1986
1987 QETH_CARD_TEXT(card, 2, "vniccrcb");
1988 if (cmd->hdr.return_code)
1989 return 0;
1990 /* return results to caller */
1991 card->options.vnicc.sup_chars = rep->hdr.sup;
1992 card->options.vnicc.cur_chars = rep->hdr.cur;
1993
Hans Wippelcaa1f0b2017-09-18 21:18:15 +02001994 if (cbctl->sub_cmd == IPA_VNICC_QUERY_CMDS)
1995 *cbctl->result.sup_cmds = rep->query_cmds.sup_cmds;
1996
Hans Wippel349d13d2017-09-18 21:18:16 +02001997 if (cbctl->sub_cmd == IPA_VNICC_GET_TIMEOUT)
1998 *cbctl->result.timeout = rep->getset_timeout.timeout;
1999
Hans Wippela45b3fa2017-09-18 21:18:14 +02002000 return 0;
2001}
2002
2003/* generic VNICC request */
2004static int qeth_l2_vnicc_request(struct qeth_card *card,
2005 struct _qeth_l2_vnicc_request_cbctl *cbctl)
2006{
2007 struct qeth_ipacmd_vnicc *req;
2008 struct qeth_cmd_buffer *iob;
2009 struct qeth_ipa_cmd *cmd;
2010 int rc;
2011
2012 QETH_CARD_TEXT(card, 2, "vniccreq");
2013
2014 /* get new buffer for request */
2015 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_VNICC, 0);
2016 if (!iob)
2017 return -ENOMEM;
2018
2019 /* create header for request */
Julian Wiedmannff5caa72018-03-09 18:12:52 +01002020 cmd = __ipa_cmd(iob);
Hans Wippela45b3fa2017-09-18 21:18:14 +02002021 req = &cmd->data.vnicc;
2022
2023 /* create sub command header for request */
2024 req->sub_hdr.data_length = sizeof(req->sub_hdr);
2025 req->sub_hdr.sub_command = cbctl->sub_cmd;
2026
2027 /* create sub command specific request fields */
2028 switch (cbctl->sub_cmd) {
2029 case IPA_VNICC_QUERY_CHARS:
2030 break;
Hans Wippelcaa1f0b2017-09-18 21:18:15 +02002031 case IPA_VNICC_QUERY_CMDS:
2032 req->sub_hdr.data_length += sizeof(req->query_cmds);
2033 req->query_cmds.vnic_char = cbctl->param.vnic_char;
2034 break;
2035 case IPA_VNICC_ENABLE:
2036 case IPA_VNICC_DISABLE:
2037 req->sub_hdr.data_length += sizeof(req->set_char);
2038 req->set_char.vnic_char = cbctl->param.vnic_char;
2039 break;
Hans Wippel349d13d2017-09-18 21:18:16 +02002040 case IPA_VNICC_SET_TIMEOUT:
2041 req->getset_timeout.timeout = cbctl->param.timeout;
2042 /* fallthrough */
2043 case IPA_VNICC_GET_TIMEOUT:
2044 req->sub_hdr.data_length += sizeof(req->getset_timeout);
2045 req->getset_timeout.vnic_char = cbctl->param.vnic_char;
2046 break;
Hans Wippela45b3fa2017-09-18 21:18:14 +02002047 default:
2048 qeth_release_buffer(iob->channel, iob);
2049 return -EOPNOTSUPP;
2050 }
2051
2052 /* send request */
2053 rc = qeth_send_ipa_cmd(card, iob, qeth_l2_vnicc_request_cb,
2054 (void *) cbctl);
2055
2056 return qeth_l2_vnicc_makerc(card, rc);
2057}
2058
2059/* VNICC query VNIC characteristics request */
2060static int qeth_l2_vnicc_query_chars(struct qeth_card *card)
2061{
2062 struct _qeth_l2_vnicc_request_cbctl cbctl;
2063
2064 /* prepare callback control */
2065 cbctl.sub_cmd = IPA_VNICC_QUERY_CHARS;
2066
2067 QETH_CARD_TEXT(card, 2, "vniccqch");
2068 return qeth_l2_vnicc_request(card, &cbctl);
2069}
2070
Hans Wippelcaa1f0b2017-09-18 21:18:15 +02002071/* VNICC query sub commands request */
2072static int qeth_l2_vnicc_query_cmds(struct qeth_card *card, u32 vnic_char,
2073 u32 *sup_cmds)
2074{
2075 struct _qeth_l2_vnicc_request_cbctl cbctl;
2076
2077 /* prepare callback control */
2078 cbctl.sub_cmd = IPA_VNICC_QUERY_CMDS;
2079 cbctl.param.vnic_char = vnic_char;
2080 cbctl.result.sup_cmds = sup_cmds;
2081
2082 QETH_CARD_TEXT(card, 2, "vniccqcm");
2083 return qeth_l2_vnicc_request(card, &cbctl);
2084}
2085
2086/* VNICC enable/disable characteristic request */
2087static int qeth_l2_vnicc_set_char(struct qeth_card *card, u32 vnic_char,
2088 u32 cmd)
2089{
2090 struct _qeth_l2_vnicc_request_cbctl cbctl;
2091
2092 /* prepare callback control */
2093 cbctl.sub_cmd = cmd;
2094 cbctl.param.vnic_char = vnic_char;
2095
2096 QETH_CARD_TEXT(card, 2, "vniccedc");
2097 return qeth_l2_vnicc_request(card, &cbctl);
2098}
2099
Hans Wippel349d13d2017-09-18 21:18:16 +02002100/* VNICC get/set timeout for characteristic request */
2101static int qeth_l2_vnicc_getset_timeout(struct qeth_card *card, u32 vnicc,
2102 u32 cmd, u32 *timeout)
2103{
2104 struct _qeth_l2_vnicc_request_cbctl cbctl;
2105
2106 /* prepare callback control */
2107 cbctl.sub_cmd = cmd;
2108 cbctl.param.vnic_char = vnicc;
2109 if (cmd == IPA_VNICC_SET_TIMEOUT)
2110 cbctl.param.timeout = *timeout;
2111 if (cmd == IPA_VNICC_GET_TIMEOUT)
2112 cbctl.result.timeout = timeout;
2113
2114 QETH_CARD_TEXT(card, 2, "vniccgst");
2115 return qeth_l2_vnicc_request(card, &cbctl);
2116}
2117
Hans Wippelcaa1f0b2017-09-18 21:18:15 +02002118/* set current VNICC flag state; called from sysfs store function */
2119int qeth_l2_vnicc_set_state(struct qeth_card *card, u32 vnicc, bool state)
2120{
2121 int rc = 0;
2122 u32 cmd;
2123
2124 QETH_CARD_TEXT(card, 2, "vniccsch");
2125
2126 /* do not change anything if BridgePort is enabled */
2127 if (qeth_bridgeport_is_in_use(card))
2128 return -EBUSY;
2129
2130 /* check if characteristic and enable/disable are supported */
2131 if (!(card->options.vnicc.sup_chars & vnicc) ||
2132 !(card->options.vnicc.set_char_sup & vnicc))
2133 return -EOPNOTSUPP;
2134
2135 /* set enable/disable command and store wanted characteristic */
2136 if (state) {
2137 cmd = IPA_VNICC_ENABLE;
2138 card->options.vnicc.wanted_chars |= vnicc;
2139 } else {
2140 cmd = IPA_VNICC_DISABLE;
2141 card->options.vnicc.wanted_chars &= ~vnicc;
2142 }
2143
2144 /* do we need to do anything? */
2145 if (card->options.vnicc.cur_chars == card->options.vnicc.wanted_chars)
2146 return rc;
2147
2148 /* if card is not ready, simply stop here */
2149 if (!qeth_card_hw_is_reachable(card)) {
2150 if (state)
2151 card->options.vnicc.cur_chars |= vnicc;
2152 else
2153 card->options.vnicc.cur_chars &= ~vnicc;
2154 return rc;
2155 }
2156
2157 rc = qeth_l2_vnicc_set_char(card, vnicc, cmd);
2158 if (rc)
2159 card->options.vnicc.wanted_chars =
2160 card->options.vnicc.cur_chars;
Hans Wippel349d13d2017-09-18 21:18:16 +02002161 else {
2162 /* successful online VNICC change; handle special cases */
2163 if (state && vnicc == QETH_VNICC_RX_BCAST)
2164 card->options.vnicc.rx_bcast_enabled = true;
2165 if (!state && vnicc == QETH_VNICC_LEARNING)
2166 qeth_l2_vnicc_recover_timeout(card, vnicc,
2167 &card->options.vnicc.learning_timeout);
2168 }
Hans Wippelcaa1f0b2017-09-18 21:18:15 +02002169
2170 return rc;
2171}
2172
2173/* get current VNICC flag state; called from sysfs show function */
2174int qeth_l2_vnicc_get_state(struct qeth_card *card, u32 vnicc, bool *state)
2175{
2176 int rc = 0;
2177
2178 QETH_CARD_TEXT(card, 2, "vniccgch");
2179
2180 /* do not get anything if BridgePort is enabled */
2181 if (qeth_bridgeport_is_in_use(card))
2182 return -EBUSY;
2183
2184 /* check if characteristic is supported */
2185 if (!(card->options.vnicc.sup_chars & vnicc))
2186 return -EOPNOTSUPP;
2187
2188 /* if card is ready, query current VNICC state */
2189 if (qeth_card_hw_is_reachable(card))
2190 rc = qeth_l2_vnicc_query_chars(card);
2191
2192 *state = (card->options.vnicc.cur_chars & vnicc) ? true : false;
2193 return rc;
2194}
2195
Hans Wippel349d13d2017-09-18 21:18:16 +02002196/* set VNICC timeout; called from sysfs store function. Currently, only learning
2197 * supports timeout
2198 */
2199int qeth_l2_vnicc_set_timeout(struct qeth_card *card, u32 timeout)
2200{
2201 int rc = 0;
2202
2203 QETH_CARD_TEXT(card, 2, "vniccsto");
2204
2205 /* do not change anything if BridgePort is enabled */
2206 if (qeth_bridgeport_is_in_use(card))
2207 return -EBUSY;
2208
2209 /* check if characteristic and set_timeout are supported */
2210 if (!(card->options.vnicc.sup_chars & QETH_VNICC_LEARNING) ||
2211 !(card->options.vnicc.getset_timeout_sup & QETH_VNICC_LEARNING))
2212 return -EOPNOTSUPP;
2213
2214 /* do we need to do anything? */
2215 if (card->options.vnicc.learning_timeout == timeout)
2216 return rc;
2217
2218 /* if card is not ready, simply store the value internally and return */
2219 if (!qeth_card_hw_is_reachable(card)) {
2220 card->options.vnicc.learning_timeout = timeout;
2221 return rc;
2222 }
2223
2224 /* send timeout value to card; if successful, store value internally */
2225 rc = qeth_l2_vnicc_getset_timeout(card, QETH_VNICC_LEARNING,
2226 IPA_VNICC_SET_TIMEOUT, &timeout);
2227 if (!rc)
2228 card->options.vnicc.learning_timeout = timeout;
2229
2230 return rc;
2231}
2232
2233/* get current VNICC timeout; called from sysfs show function. Currently, only
2234 * learning supports timeout
2235 */
2236int qeth_l2_vnicc_get_timeout(struct qeth_card *card, u32 *timeout)
2237{
2238 int rc = 0;
2239
2240 QETH_CARD_TEXT(card, 2, "vniccgto");
2241
2242 /* do not get anything if BridgePort is enabled */
2243 if (qeth_bridgeport_is_in_use(card))
2244 return -EBUSY;
2245
2246 /* check if characteristic and get_timeout are supported */
2247 if (!(card->options.vnicc.sup_chars & QETH_VNICC_LEARNING) ||
2248 !(card->options.vnicc.getset_timeout_sup & QETH_VNICC_LEARNING))
2249 return -EOPNOTSUPP;
2250 /* if card is ready, get timeout. Otherwise, just return stored value */
2251 *timeout = card->options.vnicc.learning_timeout;
2252 if (qeth_card_hw_is_reachable(card))
2253 rc = qeth_l2_vnicc_getset_timeout(card, QETH_VNICC_LEARNING,
2254 IPA_VNICC_GET_TIMEOUT,
2255 timeout);
2256
2257 return rc;
2258}
2259
Hans Wippelcaa1f0b2017-09-18 21:18:15 +02002260/* check if VNICC is currently enabled */
2261bool qeth_l2_vnicc_is_in_use(struct qeth_card *card)
2262{
2263 /* if everything is turned off, VNICC is not active */
2264 if (!card->options.vnicc.cur_chars)
2265 return false;
2266 /* default values are only OK if rx_bcast was not enabled by user
2267 * or the card is offline.
2268 */
2269 if (card->options.vnicc.cur_chars == QETH_VNICC_DEFAULT) {
2270 if (!card->options.vnicc.rx_bcast_enabled ||
2271 !qeth_card_hw_is_reachable(card))
2272 return false;
2273 }
2274 return true;
2275}
2276
Hans Wippel349d13d2017-09-18 21:18:16 +02002277/* recover user timeout setting */
2278static bool qeth_l2_vnicc_recover_timeout(struct qeth_card *card, u32 vnicc,
2279 u32 *timeout)
2280{
2281 if (card->options.vnicc.sup_chars & vnicc &&
2282 card->options.vnicc.getset_timeout_sup & vnicc &&
2283 !qeth_l2_vnicc_getset_timeout(card, vnicc, IPA_VNICC_SET_TIMEOUT,
2284 timeout))
2285 return false;
2286 *timeout = QETH_VNICC_DEFAULT_TIMEOUT;
2287 return true;
2288}
2289
Hans Wippelcaa1f0b2017-09-18 21:18:15 +02002290/* recover user characteristic setting */
2291static bool qeth_l2_vnicc_recover_char(struct qeth_card *card, u32 vnicc,
2292 bool enable)
2293{
2294 u32 cmd = enable ? IPA_VNICC_ENABLE : IPA_VNICC_DISABLE;
2295
2296 if (card->options.vnicc.sup_chars & vnicc &&
2297 card->options.vnicc.set_char_sup & vnicc &&
2298 !qeth_l2_vnicc_set_char(card, vnicc, cmd))
2299 return false;
2300 card->options.vnicc.wanted_chars &= ~vnicc;
2301 card->options.vnicc.wanted_chars |= QETH_VNICC_DEFAULT & vnicc;
2302 return true;
2303}
2304
Hans Wippela45b3fa2017-09-18 21:18:14 +02002305/* (re-)initialize VNICC */
2306static void qeth_l2_vnicc_init(struct qeth_card *card)
2307{
Hans Wippel349d13d2017-09-18 21:18:16 +02002308 u32 *timeout = &card->options.vnicc.learning_timeout;
Hans Wippelcaa1f0b2017-09-18 21:18:15 +02002309 unsigned int chars_len, i;
2310 unsigned long chars_tmp;
2311 u32 sup_cmds, vnicc;
2312 bool enable, error;
2313
Hans Wippela45b3fa2017-09-18 21:18:14 +02002314 QETH_CARD_TEXT(card, 2, "vniccini");
Hans Wippelcaa1f0b2017-09-18 21:18:15 +02002315 /* reset rx_bcast */
2316 card->options.vnicc.rx_bcast_enabled = 0;
Hans Wippela45b3fa2017-09-18 21:18:14 +02002317 /* initial query and storage of VNIC characteristics */
2318 if (qeth_l2_vnicc_query_chars(card)) {
Hans Wippel349d13d2017-09-18 21:18:16 +02002319 if (card->options.vnicc.wanted_chars != QETH_VNICC_DEFAULT ||
2320 *timeout != QETH_VNICC_DEFAULT_TIMEOUT)
Hans Wippelcaa1f0b2017-09-18 21:18:15 +02002321 dev_err(&card->gdev->dev, "Configuring the VNIC characteristics failed\n");
2322 /* fail quietly if user didn't change the default config */
Hans Wippela45b3fa2017-09-18 21:18:14 +02002323 card->options.vnicc.sup_chars = 0;
2324 card->options.vnicc.cur_chars = 0;
Hans Wippelcaa1f0b2017-09-18 21:18:15 +02002325 card->options.vnicc.wanted_chars = QETH_VNICC_DEFAULT;
2326 return;
Hans Wippela45b3fa2017-09-18 21:18:14 +02002327 }
Hans Wippelcaa1f0b2017-09-18 21:18:15 +02002328 /* get supported commands for each supported characteristic */
2329 chars_tmp = card->options.vnicc.sup_chars;
2330 chars_len = sizeof(card->options.vnicc.sup_chars) * BITS_PER_BYTE;
2331 for_each_set_bit(i, &chars_tmp, chars_len) {
2332 vnicc = BIT(i);
2333 qeth_l2_vnicc_query_cmds(card, vnicc, &sup_cmds);
Hans Wippel349d13d2017-09-18 21:18:16 +02002334 if (!(sup_cmds & IPA_VNICC_SET_TIMEOUT) ||
2335 !(sup_cmds & IPA_VNICC_GET_TIMEOUT))
2336 card->options.vnicc.getset_timeout_sup &= ~vnicc;
Hans Wippelcaa1f0b2017-09-18 21:18:15 +02002337 if (!(sup_cmds & IPA_VNICC_ENABLE) ||
2338 !(sup_cmds & IPA_VNICC_DISABLE))
2339 card->options.vnicc.set_char_sup &= ~vnicc;
2340 }
2341 /* enforce assumed default values and recover settings, if changed */
Hans Wippel349d13d2017-09-18 21:18:16 +02002342 error = qeth_l2_vnicc_recover_timeout(card, QETH_VNICC_LEARNING,
2343 timeout);
Hans Wippelcaa1f0b2017-09-18 21:18:15 +02002344 chars_tmp = card->options.vnicc.wanted_chars ^ QETH_VNICC_DEFAULT;
2345 chars_tmp |= QETH_VNICC_BRIDGE_INVISIBLE;
2346 chars_len = sizeof(card->options.vnicc.wanted_chars) * BITS_PER_BYTE;
2347 for_each_set_bit(i, &chars_tmp, chars_len) {
2348 vnicc = BIT(i);
2349 enable = card->options.vnicc.wanted_chars & vnicc;
2350 error |= qeth_l2_vnicc_recover_char(card, vnicc, enable);
2351 }
2352 if (error)
2353 dev_err(&card->gdev->dev, "Configuring the VNIC characteristics failed\n");
2354}
2355
2356/* configure default values of VNIC characteristics */
2357static void qeth_l2_vnicc_set_defaults(struct qeth_card *card)
2358{
2359 /* characteristics values */
2360 card->options.vnicc.sup_chars = QETH_VNICC_ALL;
2361 card->options.vnicc.cur_chars = QETH_VNICC_DEFAULT;
Hans Wippel349d13d2017-09-18 21:18:16 +02002362 card->options.vnicc.learning_timeout = QETH_VNICC_DEFAULT_TIMEOUT;
Hans Wippelcaa1f0b2017-09-18 21:18:15 +02002363 /* supported commands */
2364 card->options.vnicc.set_char_sup = QETH_VNICC_ALL;
Hans Wippel349d13d2017-09-18 21:18:16 +02002365 card->options.vnicc.getset_timeout_sup = QETH_VNICC_LEARNING;
Hans Wippelcaa1f0b2017-09-18 21:18:15 +02002366 /* settings wanted by users */
2367 card->options.vnicc.wanted_chars = QETH_VNICC_DEFAULT;
Hans Wippela45b3fa2017-09-18 21:18:14 +02002368}
2369
Frank Blaschka4a71df52008-02-15 09:19:42 +01002370module_init(qeth_l2_init);
2371module_exit(qeth_l2_exit);
2372MODULE_AUTHOR("Frank Blaschka <frank.blaschka@de.ibm.com>");
2373MODULE_DESCRIPTION("qeth layer 2 discipline");
2374MODULE_LICENSE("GPL");