blob: f621656f9ea79d0fbf0fec1578b38691132dc0f0 [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 *);
Eugene Crosserc044dc22014-01-29 09:23:48 +010028static void qeth_bridgeport_query_support(struct qeth_card *card);
29static void qeth_bridge_state_change(struct qeth_card *card,
30 struct qeth_ipa_cmd *cmd);
31static void qeth_bridge_host_event(struct qeth_card *card,
32 struct qeth_ipa_cmd *cmd);
Hans Wippelcaa1f0b2017-09-18 21:18:15 +020033static void qeth_l2_vnicc_set_defaults(struct qeth_card *card);
Hans Wippela45b3fa2017-09-18 21:18:14 +020034static void qeth_l2_vnicc_init(struct qeth_card *card);
Hans Wippel349d13d2017-09-18 21:18:16 +020035static bool qeth_l2_vnicc_recover_timeout(struct qeth_card *card, u32 vnicc,
36 u32 *timeout);
Frank Blaschka4a71df52008-02-15 09:19:42 +010037
Julian Wiedmann742d4d42019-02-12 18:33:25 +010038static int qeth_l2_setdelmac_makerc(struct qeth_card *card, u16 retcode)
Frank Blaschka4a71df52008-02-15 09:19:42 +010039{
Eugene Crosserefbbc1d2015-01-21 13:39:09 +010040 int rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +010041
Eugene Crosserefbbc1d2015-01-21 13:39:09 +010042 if (retcode)
Thomas Richter1aec42b2015-01-21 13:39:10 +010043 QETH_CARD_TEXT_(card, 2, "err%04x", retcode);
Eugene Crosserefbbc1d2015-01-21 13:39:09 +010044 switch (retcode) {
45 case IPA_RC_SUCCESS:
46 rc = 0;
47 break;
48 case IPA_RC_L2_UNSUPPORTED_CMD:
Eugene Crosserffb95252015-05-18 14:27:58 +020049 rc = -EOPNOTSUPP;
Eugene Crosserefbbc1d2015-01-21 13:39:09 +010050 break;
51 case IPA_RC_L2_ADDR_TABLE_FULL:
52 rc = -ENOSPC;
53 break;
54 case IPA_RC_L2_DUP_MAC:
55 case IPA_RC_L2_DUP_LAYER3_MAC:
56 rc = -EEXIST;
57 break;
58 case IPA_RC_L2_MAC_NOT_AUTH_BY_HYP:
59 case IPA_RC_L2_MAC_NOT_AUTH_BY_ADP:
60 rc = -EPERM;
61 break;
62 case IPA_RC_L2_MAC_NOT_FOUND:
63 rc = -ENOENT;
64 break;
65 default:
66 rc = -EIO;
67 break;
Frank Blaschka4a71df52008-02-15 09:19:42 +010068 }
Eugene Crosserefbbc1d2015-01-21 13:39:09 +010069 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +010070}
71
Julian Wiedmann742d4d42019-02-12 18:33:25 +010072static int qeth_l2_send_setdelmac_cb(struct qeth_card *card,
73 struct qeth_reply *reply,
74 unsigned long data)
75{
76 struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *) data;
77
78 return qeth_l2_setdelmac_makerc(card, cmd->hdr.return_code);
79}
80
Julian Wiedmannac988d72017-01-12 15:48:41 +010081static int qeth_l2_send_setdelmac(struct qeth_card *card, __u8 *mac,
82 enum qeth_ipa_cmds ipacmd)
83{
84 struct qeth_ipa_cmd *cmd;
85 struct qeth_cmd_buffer *iob;
86
87 QETH_CARD_TEXT(card, 2, "L2sdmac");
88 iob = qeth_get_ipacmd_buffer(card, ipacmd, QETH_PROT_IPV4);
89 if (!iob)
90 return -ENOMEM;
Julian Wiedmannff5caa72018-03-09 18:12:52 +010091 cmd = __ipa_cmd(iob);
Julian Wiedmann99f0b852017-12-20 20:11:01 +010092 cmd->data.setdelmac.mac_length = ETH_ALEN;
93 ether_addr_copy(cmd->data.setdelmac.mac, mac);
Julian Wiedmann742d4d42019-02-12 18:33:25 +010094 return qeth_send_ipa_cmd(card, iob, qeth_l2_send_setdelmac_cb, NULL);
Julian Wiedmannac988d72017-01-12 15:48:41 +010095}
96
97static int qeth_l2_send_setmac(struct qeth_card *card, __u8 *mac)
98{
99 int rc;
100
101 QETH_CARD_TEXT(card, 2, "L2Setmac");
102 rc = qeth_l2_send_setdelmac(card, mac, IPA_CMD_SETVMAC);
103 if (rc == 0) {
Julian Wiedmannac988d72017-01-12 15:48:41 +0100104 dev_info(&card->gdev->dev,
Julian Wiedmann654e3d42019-01-25 15:44:19 +0100105 "MAC address %pM successfully registered\n", mac);
Julian Wiedmannac988d72017-01-12 15:48:41 +0100106 } else {
Julian Wiedmannac988d72017-01-12 15:48:41 +0100107 switch (rc) {
108 case -EEXIST:
109 dev_warn(&card->gdev->dev,
110 "MAC address %pM already exists\n", mac);
111 break;
112 case -EPERM:
113 dev_warn(&card->gdev->dev,
114 "MAC address %pM is not authorized\n", mac);
115 break;
116 }
117 }
118 return rc;
119}
120
Julian Wiedmann8174aa82017-12-20 20:11:00 +0100121static int qeth_l2_write_mac(struct qeth_card *card, u8 *mac)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100122{
Vasily Gorbik9d0a58f2018-06-29 19:45:52 +0200123 enum qeth_ipa_cmds cmd = is_multicast_ether_addr(mac) ?
Julian Wiedmann8174aa82017-12-20 20:11:00 +0100124 IPA_CMD_SETGMAC : IPA_CMD_SETVMAC;
Eugene Crosserefbbc1d2015-01-21 13:39:09 +0100125 int rc;
126
Julian Wiedmann8174aa82017-12-20 20:11:00 +0100127 QETH_CARD_TEXT(card, 2, "L2Wmac");
128 rc = qeth_l2_send_setdelmac(card, mac, cmd);
Eugene Crosserefbbc1d2015-01-21 13:39:09 +0100129 if (rc == -EEXIST)
Julian Wiedmanne19e5be2018-11-02 19:04:08 +0100130 QETH_DBF_MESSAGE(2, "MAC already registered on device %x\n",
131 CARD_DEVID(card));
Eugene Crosserefbbc1d2015-01-21 13:39:09 +0100132 else if (rc)
Julian Wiedmanne19e5be2018-11-02 19:04:08 +0100133 QETH_DBF_MESSAGE(2, "Failed to register MAC on device %x: %d\n",
134 CARD_DEVID(card), rc);
Eugene Crosserefbbc1d2015-01-21 13:39:09 +0100135 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100136}
137
Julian Wiedmann8174aa82017-12-20 20:11:00 +0100138static int qeth_l2_remove_mac(struct qeth_card *card, u8 *mac)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100139{
Vasily Gorbik9d0a58f2018-06-29 19:45:52 +0200140 enum qeth_ipa_cmds cmd = is_multicast_ether_addr(mac) ?
Julian Wiedmann8174aa82017-12-20 20:11:00 +0100141 IPA_CMD_DELGMAC : IPA_CMD_DELVMAC;
Eugene Crosserefbbc1d2015-01-21 13:39:09 +0100142 int rc;
143
Julian Wiedmann8174aa82017-12-20 20:11:00 +0100144 QETH_CARD_TEXT(card, 2, "L2Rmac");
145 rc = qeth_l2_send_setdelmac(card, mac, cmd);
Eugene Crosserefbbc1d2015-01-21 13:39:09 +0100146 if (rc)
Julian Wiedmanne19e5be2018-11-02 19:04:08 +0100147 QETH_DBF_MESSAGE(2, "Failed to delete MAC on device %u: %d\n",
148 CARD_DEVID(card), rc);
Eugene Crosserefbbc1d2015-01-21 13:39:09 +0100149 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100150}
151
Julian Wiedmannc07cbf22017-01-12 15:48:37 +0100152static void qeth_l2_del_all_macs(struct qeth_card *card)
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200153{
154 struct qeth_mac *mac;
155 struct hlist_node *tmp;
156 int i;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100157
158 spin_lock_bh(&card->mclock);
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200159 hash_for_each_safe(card->mac_htable, i, tmp, mac, hnode) {
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200160 hash_del(&mac->hnode);
161 kfree(mac);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100162 }
163 spin_unlock_bh(&card->mclock);
164}
165
Julian Wiedmanncef6ff222017-08-15 17:02:46 +0200166static int qeth_l2_get_cast_type(struct qeth_card *card, struct sk_buff *skb)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100167{
Klaus-Dieter Wackerce73e102009-08-26 02:01:08 +0000168 if (card->info.type == QETH_CARD_TYPE_OSN)
Julian Wiedmann86c0cdb2018-07-11 17:42:41 +0200169 return RTN_UNICAST;
Klaus-Dieter Wackerce73e102009-08-26 02:01:08 +0000170 if (is_broadcast_ether_addr(skb->data))
171 return RTN_BROADCAST;
172 if (is_multicast_ether_addr(skb->data))
173 return RTN_MULTICAST;
Julian Wiedmann86c0cdb2018-07-11 17:42:41 +0200174 return RTN_UNICAST;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100175}
176
Julian Wiedmannb0abc4f2019-02-15 19:22:29 +0100177static void qeth_l2_fill_header(struct qeth_qdio_out_q *queue,
178 struct qeth_hdr *hdr, struct sk_buff *skb,
179 int ipv, int cast_type, unsigned int data_len)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100180{
Julian Wiedmann0aef8392018-10-12 17:27:15 +0200181 struct vlan_ethhdr *veth = vlan_eth_hdr(skb);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100182
Julian Wiedmannae79fe02017-08-18 10:19:05 +0200183 hdr->hdr.l2.pkt_length = data_len;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100184
Julian Wiedmann0aef8392018-10-12 17:27:15 +0200185 if (skb_is_gso(skb)) {
186 hdr->hdr.l2.id = QETH_HEADER_TYPE_L2_TSO;
187 } else {
188 hdr->hdr.l2.id = QETH_HEADER_TYPE_LAYER2;
189 if (skb->ip_summed == CHECKSUM_PARTIAL) {
190 qeth_tx_csum(skb, &hdr->hdr.l2.flags[1], ipv);
Julian Wiedmannb0abc4f2019-02-15 19:22:29 +0100191 QETH_TXQ_STAT_INC(queue, skbs_csum);
Julian Wiedmann0aef8392018-10-12 17:27:15 +0200192 }
Julian Wiedmannfc696602018-09-17 17:35:55 +0200193 }
194
Frank Blaschka4a71df52008-02-15 09:19:42 +0100195 /* set byte byte 3 to casting flags */
196 if (cast_type == RTN_MULTICAST)
197 hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_MULTICAST;
198 else if (cast_type == RTN_BROADCAST)
199 hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_BROADCAST;
200 else
Klaus-Dieter Wackerce73e102009-08-26 02:01:08 +0000201 hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_UNICAST;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100202
Frank Blaschka4a71df52008-02-15 09:19:42 +0100203 /* VSWITCH relies on the VLAN
204 * information to be present in
205 * the QDIO header */
206 if (veth->h_vlan_proto == __constant_htons(ETH_P_8021Q)) {
207 hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_VLAN;
208 hdr->hdr.l2.vlan_id = ntohs(veth->h_vlan_TCI);
209 }
210}
211
Julian Wiedmann742d4d42019-02-12 18:33:25 +0100212static int qeth_l2_setdelvlan_makerc(struct qeth_card *card, u16 retcode)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100213{
Julian Wiedmann2aa48672017-09-18 21:18:20 +0200214 if (retcode)
215 QETH_CARD_TEXT_(card, 2, "err%04x", retcode);
216
217 switch (retcode) {
218 case IPA_RC_SUCCESS:
219 return 0;
220 case IPA_RC_L2_INVALID_VLAN_ID:
221 return -EINVAL;
222 case IPA_RC_L2_DUP_VLAN_ID:
223 return -EEXIST;
224 case IPA_RC_L2_VLAN_ID_NOT_FOUND:
225 return -ENOENT;
226 case IPA_RC_L2_VLAN_ID_NOT_ALLOWED:
227 return -EPERM;
Julian Wiedmann2aa48672017-09-18 21:18:20 +0200228 default:
229 return -EIO;
230 }
231}
232
233static int qeth_l2_send_setdelvlan_cb(struct qeth_card *card,
234 struct qeth_reply *reply,
235 unsigned long data)
236{
237 struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *) data;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100238
Carsten Otte847a50f2010-06-21 22:57:05 +0000239 QETH_CARD_TEXT(card, 2, "L2sdvcb");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100240 if (cmd->hdr.return_code) {
Julian Wiedmanne19e5be2018-11-02 19:04:08 +0100241 QETH_DBF_MESSAGE(2, "Error in processing VLAN %u on device %x: %#x.\n",
Julian Wiedmann2aa48672017-09-18 21:18:20 +0200242 cmd->data.setdelvlan.vlan_id,
Julian Wiedmanne19e5be2018-11-02 19:04:08 +0100243 CARD_DEVID(card), cmd->hdr.return_code);
Carsten Otte847a50f2010-06-21 22:57:05 +0000244 QETH_CARD_TEXT_(card, 2, "L2VL%4x", cmd->hdr.command);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100245 }
Julian Wiedmann742d4d42019-02-12 18:33:25 +0100246 return qeth_l2_setdelvlan_makerc(card, cmd->hdr.return_code);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100247}
248
249static int qeth_l2_send_setdelvlan(struct qeth_card *card, __u16 i,
Julian Wiedmann2aa48672017-09-18 21:18:20 +0200250 enum qeth_ipa_cmds ipacmd)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100251{
252 struct qeth_ipa_cmd *cmd;
253 struct qeth_cmd_buffer *iob;
254
Carsten Otte847a50f2010-06-21 22:57:05 +0000255 QETH_CARD_TEXT_(card, 4, "L2sdv%x", ipacmd);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100256 iob = qeth_get_ipacmd_buffer(card, ipacmd, QETH_PROT_IPV4);
Thomas Richter1aec42b2015-01-21 13:39:10 +0100257 if (!iob)
258 return -ENOMEM;
Julian Wiedmannff5caa72018-03-09 18:12:52 +0100259 cmd = __ipa_cmd(iob);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100260 cmd->data.setdelvlan.vlan_id = i;
Julian Wiedmann742d4d42019-02-12 18:33:25 +0100261 return qeth_send_ipa_cmd(card, iob, qeth_l2_send_setdelvlan_cb, NULL);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100262}
263
Patrick McHardy80d5c362013-04-19 02:04:28 +0000264static int qeth_l2_vlan_rx_add_vid(struct net_device *dev,
265 __be16 proto, u16 vid)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100266{
Heiko Carstens509e2562008-07-26 02:24:10 -0700267 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100268
Carsten Otte847a50f2010-06-21 22:57:05 +0000269 QETH_CARD_TEXT_(card, 4, "aid:%d", vid);
Ursula Braun10651db2010-10-01 02:51:13 +0000270 if (!vid)
Jiri Pirko8e586132011-12-08 19:52:37 -0500271 return 0;
Julian Wiedmanne6e771b2019-01-25 15:44:22 +0100272
Julian Wiedmann5fc692a2019-01-25 15:44:23 +0100273 return qeth_l2_send_setdelvlan(card, vid, IPA_CMD_SETVLAN);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100274}
275
Patrick McHardy80d5c362013-04-19 02:04:28 +0000276static int qeth_l2_vlan_rx_kill_vid(struct net_device *dev,
277 __be16 proto, u16 vid)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100278{
Heiko Carstens509e2562008-07-26 02:24:10 -0700279 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100280
Carsten Otte847a50f2010-06-21 22:57:05 +0000281 QETH_CARD_TEXT_(card, 4, "kid:%d", vid);
Julian Wiedmann5fc692a2019-01-25 15:44:23 +0100282 if (!vid)
283 return 0;
Julian Wiedmanne6e771b2019-01-25 15:44:22 +0100284
Julian Wiedmann5fc692a2019-01-25 15:44:23 +0100285 return qeth_l2_send_setdelvlan(card, vid, IPA_CMD_DELVLAN);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100286}
287
Peter Senna Tschudinb2f4de82015-08-04 17:11:47 +0200288static void qeth_l2_stop_card(struct qeth_card *card, int recovery_mode)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100289{
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200290 QETH_DBF_TEXT(SETUP , 2, "stopcard");
291 QETH_DBF_HEX(SETUP, 2, &card, sizeof(void *));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100292
293 qeth_set_allowed_threads(card, 0, 1);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100294 if (card->read.state == CH_STATE_UP &&
295 card->write.state == CH_STATE_UP &&
296 (card->state == CARD_STATE_UP)) {
Julian Wiedmanne22355e2019-01-25 15:44:18 +0100297 if (recovery_mode && !IS_OSN(card)) {
298 qeth_stop(card->dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100299 } else {
300 rtnl_lock();
301 dev_close(card->dev);
302 rtnl_unlock();
303 }
Ursula Braun70919e22011-02-26 22:41:36 -0800304 card->info.mac_bits &= ~QETH_LAYER2_MAC_REGISTERED;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100305 card->state = CARD_STATE_SOFTSETUP;
306 }
307 if (card->state == CARD_STATE_SOFTSETUP) {
Julian Wiedmannc07cbf22017-01-12 15:48:37 +0100308 qeth_l2_del_all_macs(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100309 qeth_clear_ipacmd_list(card);
310 card->state = CARD_STATE_HARDSETUP;
311 }
312 if (card->state == CARD_STATE_HARDSETUP) {
313 qeth_qdio_clear_card(card, 0);
314 qeth_clear_qdio_buffers(card);
315 qeth_clear_working_pool_list(card);
316 card->state = CARD_STATE_DOWN;
317 }
318 if (card->state == CARD_STATE_DOWN) {
319 qeth_clear_cmd_buffers(&card->read);
320 qeth_clear_cmd_buffers(&card->write);
321 }
Julian Wiedmannc0a2e4d2019-02-04 17:40:09 +0100322
323 flush_workqueue(card->event_wq);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100324}
325
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000326static int qeth_l2_process_inbound_buffer(struct qeth_card *card,
327 int budget, int *done)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100328{
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000329 int work_done = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100330 struct sk_buff *skb;
331 struct qeth_hdr *hdr;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100332 unsigned int len;
333
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000334 *done = 0;
Stefan Raspl18af5c12012-11-19 02:46:50 +0000335 WARN_ON_ONCE(!budget);
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000336 while (budget) {
337 skb = qeth_core_get_next_skb(card,
Frank Blaschkab3332932011-08-08 01:33:59 +0000338 &card->qdio.in_q->bufs[card->rx.b_index],
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000339 &card->rx.b_element, &card->rx.e_offset, &hdr);
340 if (!skb) {
341 *done = 1;
342 break;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100343 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100344 switch (hdr->hdr.l2.id) {
345 case QETH_HEADER_TYPE_LAYER2:
Frank Blaschka4a71df52008-02-15 09:19:42 +0100346 skb->protocol = eth_type_trans(skb, skb->dev);
Julian Wiedmann6195b932018-04-26 09:42:17 +0200347 qeth_rx_csum(card, skb, hdr->hdr.l2.flags[1]);
Ursula Braun12883722008-04-01 10:26:56 +0200348 if (skb->protocol == htons(ETH_P_802_2))
349 *((__u32 *)skb->cb) = ++card->seqno.pkt_seqno;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100350 len = skb->len;
Thomas Richter9abfa8c2015-10-06 15:12:27 +0200351 napi_gro_receive(&card->napi, skb);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100352 break;
353 case QETH_HEADER_TYPE_OSN:
Ursula Braun2d488c22008-10-24 11:16:55 +0200354 if (card->info.type == QETH_CARD_TYPE_OSN) {
355 skb_push(skb, sizeof(struct qeth_hdr));
356 skb_copy_to_linear_data(skb, hdr,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100357 sizeof(struct qeth_hdr));
Ursula Braun2d488c22008-10-24 11:16:55 +0200358 len = skb->len;
359 card->osn_info.data_cb(skb);
360 break;
361 }
362 /* else unknown */
Frank Blaschka4a71df52008-02-15 09:19:42 +0100363 default:
364 dev_kfree_skb_any(skb);
Carsten Otte847a50f2010-06-21 22:57:05 +0000365 QETH_CARD_TEXT(card, 3, "inbunkno");
Julian Wiedmann0ac14872018-09-12 15:31:35 +0200366 QETH_DBF_HEX(CTRL, 3, hdr, sizeof(*hdr));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100367 continue;
368 }
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000369 work_done++;
370 budget--;
Julian Wiedmannb0abc4f2019-02-15 19:22:29 +0100371 QETH_CARD_STAT_INC(card, rx_packets);
372 QETH_CARD_STAT_ADD(card, rx_bytes, len);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100373 }
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000374 return work_done;
375}
376
Frank Blaschka4a71df52008-02-15 09:19:42 +0100377static int qeth_l2_request_initial_mac(struct qeth_card *card)
378{
379 int rc = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100380
Julian Wiedmannec61bd22017-06-20 16:00:34 +0200381 QETH_DBF_TEXT(SETUP, 2, "l2reqmac");
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200382 QETH_DBF_TEXT_(SETUP, 2, "doL2%s", CARD_BUS_ID(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100383
Julian Wiedmannec61bd22017-06-20 16:00:34 +0200384 if (MACHINE_IS_VM) {
385 rc = qeth_vm_request_mac(card);
386 if (!rc)
387 goto out;
Julian Wiedmanne19e5be2018-11-02 19:04:08 +0100388 QETH_DBF_MESSAGE(2, "z/VM MAC Service failed on device %x: %#x\n",
389 CARD_DEVID(card), rc);
Julian Wiedmannec61bd22017-06-20 16:00:34 +0200390 QETH_DBF_TEXT_(SETUP, 2, "err%04x", rc);
391 /* fall back to alternative mechanism: */
392 }
393
Julian Wiedmannb144b992018-11-08 15:06:15 +0100394 if (!IS_OSN(card)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +0100395 rc = qeth_setadpparms_change_macaddr(card);
Julian Wiedmann4b7ae122019-02-12 18:33:23 +0100396 if (!rc)
Julian Wiedmann21b17022018-04-26 09:42:24 +0200397 goto out;
Julian Wiedmanne19e5be2018-11-02 19:04:08 +0100398 QETH_DBF_MESSAGE(2, "READ_MAC Assist failed on device %x: %#x\n",
399 CARD_DEVID(card), rc);
Julian Wiedmann21b17022018-04-26 09:42:24 +0200400 QETH_DBF_TEXT_(SETUP, 2, "1err%04x", rc);
401 /* fall back once more: */
Frank Blaschka4a71df52008-02-15 09:19:42 +0100402 }
Julian Wiedmann21b17022018-04-26 09:42:24 +0200403
404 /* some devices don't support a custom MAC address: */
405 if (card->info.type == QETH_CARD_TYPE_OSM ||
406 card->info.type == QETH_CARD_TYPE_OSX)
407 return (rc) ? rc : -EADDRNOTAVAIL;
408 eth_hw_addr_random(card->dev);
409
Julian Wiedmannec61bd22017-06-20 16:00:34 +0200410out:
411 QETH_DBF_HEX(SETUP, 2, card->dev->dev_addr, card->dev->addr_len);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100412 return 0;
413}
414
Julian Wiedmann654e3d42019-01-25 15:44:19 +0100415static void qeth_l2_register_dev_addr(struct qeth_card *card)
416{
417 if (!is_valid_ether_addr(card->dev->dev_addr))
418 qeth_l2_request_initial_mac(card);
419
420 if (!IS_OSN(card) && !qeth_l2_send_setmac(card, card->dev->dev_addr))
421 card->info.mac_bits |= QETH_LAYER2_MAC_REGISTERED;
422}
423
Julian Wiedmanne22355e2019-01-25 15:44:18 +0100424static int qeth_l2_validate_addr(struct net_device *dev)
425{
426 struct qeth_card *card = dev->ml_priv;
427
Julian Wiedmann8024cc92019-02-15 19:22:31 +0100428 if (card->info.mac_bits & QETH_LAYER2_MAC_REGISTERED)
Julian Wiedmanne22355e2019-01-25 15:44:18 +0100429 return eth_validate_addr(dev);
430
431 QETH_CARD_TEXT(card, 4, "nomacadr");
432 return -EPERM;
433}
434
Frank Blaschka4a71df52008-02-15 09:19:42 +0100435static int qeth_l2_set_mac_address(struct net_device *dev, void *p)
436{
437 struct sockaddr *addr = p;
Heiko Carstens509e2562008-07-26 02:24:10 -0700438 struct qeth_card *card = dev->ml_priv;
Julian Wiedmannbcacfcb2018-04-19 12:52:09 +0200439 u8 old_addr[ETH_ALEN];
Frank Blaschka4a71df52008-02-15 09:19:42 +0100440 int rc = 0;
441
Carsten Otte847a50f2010-06-21 22:57:05 +0000442 QETH_CARD_TEXT(card, 3, "setmac");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100443
Julian Wiedmann8024cc92019-02-15 19:22:31 +0100444 if (IS_OSM(card) || IS_OSX(card)) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000445 QETH_CARD_TEXT(card, 3, "setmcTYP");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100446 return -EOPNOTSUPP;
447 }
Julian Wiedmann99f0b852017-12-20 20:11:01 +0100448 QETH_CARD_HEX(card, 3, addr->sa_data, ETH_ALEN);
Julian Wiedmannbcacfcb2018-04-19 12:52:09 +0200449 if (!is_valid_ether_addr(addr->sa_data))
450 return -EADDRNOTAVAIL;
451
Julian Wiedmannbcacfcb2018-04-19 12:52:09 +0200452 /* don't register the same address twice */
453 if (ether_addr_equal_64bits(dev->dev_addr, addr->sa_data) &&
454 (card->info.mac_bits & QETH_LAYER2_MAC_REGISTERED))
Julian Wiedmanne6e771b2019-01-25 15:44:22 +0100455 return 0;
Julian Wiedmannbcacfcb2018-04-19 12:52:09 +0200456
457 /* add the new address, switch over, drop the old */
458 rc = qeth_l2_send_setmac(card, addr->sa_data);
459 if (rc)
Julian Wiedmanne6e771b2019-01-25 15:44:22 +0100460 return rc;
Julian Wiedmannbcacfcb2018-04-19 12:52:09 +0200461 ether_addr_copy(old_addr, dev->dev_addr);
462 ether_addr_copy(dev->dev_addr, addr->sa_data);
463
464 if (card->info.mac_bits & QETH_LAYER2_MAC_REGISTERED)
465 qeth_l2_remove_mac(card, old_addr);
466 card->info.mac_bits |= QETH_LAYER2_MAC_REGISTERED;
Julian Wiedmanne6e771b2019-01-25 15:44:22 +0100467 return 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100468}
469
Eugene Crosser0db587b2015-05-18 14:27:55 +0200470static void qeth_promisc_to_bridge(struct qeth_card *card)
471{
472 struct net_device *dev = card->dev;
473 enum qeth_ipa_promisc_modes promisc_mode;
474 int role;
475 int rc;
476
477 QETH_CARD_TEXT(card, 3, "pmisc2br");
478
479 if (!card->options.sbp.reflect_promisc)
480 return;
481 promisc_mode = (dev->flags & IFF_PROMISC) ? SET_PROMISC_MODE_ON
482 : SET_PROMISC_MODE_OFF;
483 if (promisc_mode == card->info.promisc_mode)
484 return;
485
486 if (promisc_mode == SET_PROMISC_MODE_ON) {
487 if (card->options.sbp.reflect_promisc_primary)
488 role = QETH_SBP_ROLE_PRIMARY;
489 else
490 role = QETH_SBP_ROLE_SECONDARY;
491 } else
492 role = QETH_SBP_ROLE_NONE;
493
494 rc = qeth_bridgeport_setrole(card, role);
495 QETH_DBF_TEXT_(SETUP, 2, "bpm%c%04x",
496 (promisc_mode == SET_PROMISC_MODE_ON) ? '+' : '-', rc);
497 if (!rc) {
498 card->options.sbp.role = role;
499 card->info.promisc_mode = promisc_mode;
500 }
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200501
502}
503/* New MAC address is added to the hash table and marked to be written on card
504 * only if there is not in the hash table storage already
505 *
506*/
Julian Wiedmann4641b022017-12-20 20:10:59 +0100507static void qeth_l2_add_mac(struct qeth_card *card, struct netdev_hw_addr *ha)
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200508{
Julian Wiedmanncef6ff222017-08-15 17:02:46 +0200509 u32 mac_hash = get_unaligned((u32 *)(&ha->addr[2]));
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200510 struct qeth_mac *mac;
511
Julian Wiedmanncef6ff222017-08-15 17:02:46 +0200512 hash_for_each_possible(card->mac_htable, mac, hnode, mac_hash) {
Julian Wiedmann99f0b852017-12-20 20:11:01 +0100513 if (ether_addr_equal_64bits(ha->addr, mac->mac_addr)) {
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200514 mac->disp_flag = QETH_DISP_ADDR_DO_NOTHING;
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200515 return;
516 }
517 }
518
519 mac = kzalloc(sizeof(struct qeth_mac), GFP_ATOMIC);
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200520 if (!mac)
521 return;
522
Julian Wiedmann99f0b852017-12-20 20:11:01 +0100523 ether_addr_copy(mac->mac_addr, ha->addr);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200524 mac->disp_flag = QETH_DISP_ADDR_ADD;
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200525
Julian Wiedmanncef6ff222017-08-15 17:02:46 +0200526 hash_add(card->mac_htable, &mac->hnode, mac_hash);
Eugene Crosser0db587b2015-05-18 14:27:55 +0200527}
528
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200529static void qeth_l2_set_rx_mode(struct net_device *dev)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100530{
Heiko Carstens509e2562008-07-26 02:24:10 -0700531 struct qeth_card *card = dev->ml_priv;
Jiri Pirkoccffad252009-05-22 23:22:17 +0000532 struct netdev_hw_addr *ha;
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200533 struct qeth_mac *mac;
534 struct hlist_node *tmp;
535 int i;
536 int rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100537
Carsten Otte847a50f2010-06-21 22:57:05 +0000538 QETH_CARD_TEXT(card, 3, "setmulti");
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200539
Frank Blaschka4a71df52008-02-15 09:19:42 +0100540 spin_lock_bh(&card->mclock);
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200541
Jiri Pirko22bedad32010-04-01 21:22:57 +0000542 netdev_for_each_mc_addr(ha, dev)
Julian Wiedmann4641b022017-12-20 20:10:59 +0100543 qeth_l2_add_mac(card, ha);
Jiri Pirko32e7bfc2010-01-25 13:36:10 -0800544 netdev_for_each_uc_addr(ha, dev)
Julian Wiedmann4641b022017-12-20 20:10:59 +0100545 qeth_l2_add_mac(card, ha);
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200546
547 hash_for_each_safe(card->mac_htable, i, tmp, mac, hnode) {
Julian Wiedmann00c163f2017-12-20 20:11:02 +0100548 switch (mac->disp_flag) {
549 case QETH_DISP_ADDR_DELETE:
Julian Wiedmann8174aa82017-12-20 20:11:00 +0100550 qeth_l2_remove_mac(card, mac->mac_addr);
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200551 hash_del(&mac->hnode);
552 kfree(mac);
Julian Wiedmann00c163f2017-12-20 20:11:02 +0100553 break;
554 case QETH_DISP_ADDR_ADD:
Julian Wiedmann8174aa82017-12-20 20:11:00 +0100555 rc = qeth_l2_write_mac(card, mac->mac_addr);
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200556 if (rc) {
557 hash_del(&mac->hnode);
558 kfree(mac);
Julian Wiedmann00c163f2017-12-20 20:11:02 +0100559 break;
560 }
561 /* fall through */
562 default:
563 /* for next call to set_rx_mode(): */
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200564 mac->disp_flag = QETH_DISP_ADDR_DELETE;
Julian Wiedmann00c163f2017-12-20 20:11:02 +0100565 }
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200566 }
Frank Blaschka7db22662008-08-15 08:02:59 +0200567
Frank Blaschka4a71df52008-02-15 09:19:42 +0100568 spin_unlock_bh(&card->mclock);
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200569
Eugene Crosser0db587b2015-05-18 14:27:55 +0200570 if (qeth_adp_supported(card, IPA_SETADP_SET_PROMISC_MODE))
571 qeth_setadp_promisc_mode(card);
572 else
573 qeth_promisc_to_bridge(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100574}
575
Julian Wiedmann72863842017-08-18 10:19:04 +0200576static int qeth_l2_xmit_osn(struct qeth_card *card, struct sk_buff *skb,
577 struct qeth_qdio_out_q *queue)
578{
Julian Wiedmann69d7ce82018-09-17 17:36:04 +0200579 struct qeth_hdr *hdr = (struct qeth_hdr *)skb->data;
580 addr_t end = (addr_t)(skb->data + sizeof(*hdr));
581 addr_t start = (addr_t)skb->data;
582 unsigned int elements = 0;
583 unsigned int hd_len = 0;
584 int rc;
Julian Wiedmann72863842017-08-18 10:19:04 +0200585
586 if (skb->protocol == htons(ETH_P_IPV6))
587 return -EPROTONOSUPPORT;
588
Julian Wiedmann69d7ce82018-09-17 17:36:04 +0200589 if (qeth_get_elements_for_range(start, end) > 1) {
590 /* Misaligned HW header, move it to its own buffer element. */
591 hdr = kmem_cache_alloc(qeth_core_header_cache, GFP_ATOMIC);
592 if (!hdr)
593 return -ENOMEM;
594 hd_len = sizeof(*hdr);
595 skb_copy_from_linear_data(skb, (char *)hdr, hd_len);
596 elements++;
597 }
598
599 elements += qeth_count_elements(skb, hd_len);
600 if (elements > QETH_MAX_BUFFER_ELEMENTS(card)) {
601 rc = -E2BIG;
602 goto out;
603 }
604
605 rc = qeth_do_send_packet(card, queue, skb, hdr, hd_len, hd_len,
606 elements);
607out:
608 if (rc && hd_len)
609 kmem_cache_free(qeth_core_header_cache, hdr);
610 return rc;
Julian Wiedmann72863842017-08-18 10:19:04 +0200611}
612
Julian Wiedmanne38db6b2017-04-11 16:11:14 +0200613static netdev_tx_t qeth_l2_hard_start_xmit(struct sk_buff *skb,
614 struct net_device *dev)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100615{
Heiko Carstens509e2562008-07-26 02:24:10 -0700616 struct qeth_card *card = dev->ml_priv;
Klaus-Dieter Wackerce73e102009-08-26 02:01:08 +0000617 int cast_type = qeth_l2_get_cast_type(card, skb);
Kittipon Meesompop571f9dd82018-04-26 09:42:22 +0200618 int ipv = qeth_get_ip_version(skb);
Stefan Raspl290b8342014-04-28 10:05:08 +0200619 struct qeth_qdio_out_q *queue;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100620 int tx_bytes = skb->len;
Julian Wiedmann72863842017-08-18 10:19:04 +0200621 int rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100622
Julian Wiedmannb0abc4f2019-02-15 19:22:29 +0100623 queue = qeth_get_tx_queue(card, skb, ipv, cast_type);
624
Julian Wiedmann91cc98f2018-09-26 18:29:16 +0200625 if (card->state != CARD_STATE_UP) {
Julian Wiedmannb0abc4f2019-02-15 19:22:29 +0100626 QETH_TXQ_STAT_INC(queue, tx_carrier_errors);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100627 goto tx_drop;
628 }
629
Frank Blaschka4a71df52008-02-15 09:19:42 +0100630 netif_stop_queue(dev);
631
Julian Wiedmann5f89eca2018-07-19 12:43:58 +0200632 if (IS_OSN(card))
Julian Wiedmann72863842017-08-18 10:19:04 +0200633 rc = qeth_l2_xmit_osn(card, skb, queue);
Julian Wiedmann5f89eca2018-07-19 12:43:58 +0200634 else
Julian Wiedmannfc696602018-09-17 17:35:55 +0200635 rc = qeth_xmit(card, skb, queue, ipv, cast_type,
636 qeth_l2_fill_header);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100637
Frank Blaschka4a71df52008-02-15 09:19:42 +0100638 if (!rc) {
Julian Wiedmannb0abc4f2019-02-15 19:22:29 +0100639 QETH_TXQ_STAT_INC(queue, tx_packets);
640 QETH_TXQ_STAT_ADD(queue, tx_bytes, tx_bytes);
Julian Wiedmann72863842017-08-18 10:19:04 +0200641 netif_wake_queue(dev);
642 return NETDEV_TX_OK;
643 } else if (rc == -EBUSY) {
644 return NETDEV_TX_BUSY;
645 } /* else fall through */
Frank Blaschka4a71df52008-02-15 09:19:42 +0100646
647tx_drop:
Julian Wiedmannb0abc4f2019-02-15 19:22:29 +0100648 QETH_TXQ_STAT_INC(queue, tx_dropped);
649 QETH_TXQ_STAT_INC(queue, tx_errors);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100650 dev_kfree_skb_any(skb);
Frank Blaschkad0ec0f52008-06-06 12:37:48 +0200651 netif_wake_queue(dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100652 return NETDEV_TX_OK;
653}
654
Julian Wiedmann2d2ebb32017-05-10 19:07:52 +0200655static const struct device_type qeth_l2_devtype = {
656 .name = "qeth_layer2",
657 .groups = qeth_l2_attr_groups,
658};
659
Frank Blaschka4a71df52008-02-15 09:19:42 +0100660static int qeth_l2_probe_device(struct ccwgroup_device *gdev)
661{
662 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
Ursula Braun9111e782017-05-10 19:07:51 +0200663 int rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100664
Julian Wiedmann2d2ebb32017-05-10 19:07:52 +0200665 if (gdev->dev.type == &qeth_generic_devtype) {
666 rc = qeth_l2_create_device_attributes(&gdev->dev);
667 if (rc)
668 return rc;
669 }
Julian Wiedmann5fc692a2019-01-25 15:44:23 +0100670
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200671 hash_init(card->mac_htable);
Frank Blaschka1da74b12011-05-12 18:45:02 +0000672 card->info.hwtrap = 0;
Hans Wippelcaa1f0b2017-09-18 21:18:15 +0200673 qeth_l2_vnicc_set_defaults(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100674 return 0;
675}
676
677static void qeth_l2_remove_device(struct ccwgroup_device *cgdev)
678{
679 struct qeth_card *card = dev_get_drvdata(&cgdev->dev);
680
Julian Wiedmann2d2ebb32017-05-10 19:07:52 +0200681 if (cgdev->dev.type == &qeth_generic_devtype)
682 qeth_l2_remove_device_attributes(&cgdev->dev);
Ursula Braunf2148562009-05-19 21:38:37 +0000683 qeth_set_allowed_threads(card, 0, 1);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100684 wait_event(card->wait_q, qeth_threads_running(card, 0xffffffff) == 0);
685
Ursula Braun70919e22011-02-26 22:41:36 -0800686 if (cgdev->state == CCWGROUP_ONLINE)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100687 qeth_l2_set_offline(cgdev);
Julian Wiedmannc2780c12019-02-04 17:40:08 +0100688
689 cancel_work_sync(&card->close_dev_work);
Julian Wiedmann30356d02018-11-02 19:04:10 +0100690 if (qeth_netdev_is_registered(card->dev))
691 unregister_netdev(card->dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100692}
693
Frank Blaschka3d58cef2009-01-09 03:44:00 +0000694static const struct net_device_ops qeth_l2_netdev_ops = {
Julian Wiedmanne22355e2019-01-25 15:44:18 +0100695 .ndo_open = qeth_open,
696 .ndo_stop = qeth_stop,
Julian Wiedmannb0abc4f2019-02-15 19:22:29 +0100697 .ndo_get_stats64 = qeth_get_stats64,
Frank Blaschka8403b132009-01-08 10:50:55 -0800698 .ndo_start_xmit = qeth_l2_hard_start_xmit,
Julian Wiedmann6d69b1f2017-12-01 10:14:50 +0100699 .ndo_features_check = qeth_features_check,
Julian Wiedmanne22355e2019-01-25 15:44:18 +0100700 .ndo_validate_addr = qeth_l2_validate_addr,
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200701 .ndo_set_rx_mode = qeth_l2_set_rx_mode,
Julian Wiedmann942d6982017-04-11 16:11:10 +0200702 .ndo_do_ioctl = qeth_do_ioctl,
Frank Blaschka8403b132009-01-08 10:50:55 -0800703 .ndo_set_mac_address = qeth_l2_set_mac_address,
Frank Blaschka8403b132009-01-08 10:50:55 -0800704 .ndo_vlan_rx_add_vid = qeth_l2_vlan_rx_add_vid,
705 .ndo_vlan_rx_kill_vid = qeth_l2_vlan_rx_kill_vid,
706 .ndo_tx_timeout = qeth_tx_timeout,
Thomas Richter8f43fb02016-06-16 16:18:59 +0200707 .ndo_fix_features = qeth_fix_features,
708 .ndo_set_features = qeth_set_features
Frank Blaschka8403b132009-01-08 10:50:55 -0800709};
710
Julian Wiedmann8024cc92019-02-15 19:22:31 +0100711static const struct net_device_ops qeth_osn_netdev_ops = {
712 .ndo_open = qeth_open,
713 .ndo_stop = qeth_stop,
714 .ndo_get_stats64 = qeth_get_stats64,
715 .ndo_start_xmit = qeth_l2_hard_start_xmit,
716 .ndo_validate_addr = eth_validate_addr,
717 .ndo_tx_timeout = qeth_tx_timeout,
718};
719
Julian Wiedmann9fae5c32018-11-02 19:04:11 +0100720static int qeth_l2_setup_netdev(struct qeth_card *card, bool carrier_ok)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100721{
Julian Wiedmannd3d1b202018-07-19 12:43:51 +0200722 int rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100723
Julian Wiedmann8024cc92019-02-15 19:22:31 +0100724 if (IS_OSN(card)) {
725 card->dev->netdev_ops = &qeth_osn_netdev_ops;
Julian Wiedmann25e2c342017-05-10 19:07:53 +0200726 card->dev->flags |= IFF_NOARP;
Julian Wiedmann8024cc92019-02-15 19:22:31 +0100727 goto add_napi;
728 }
729
730 card->dev->needed_headroom = sizeof(struct qeth_hdr);
731 card->dev->netdev_ops = &qeth_l2_netdev_ops;
732 card->dev->priv_flags |= IFF_UNICAST_FLT;
Julian Wiedmann9400c532017-10-18 17:40:20 +0200733
Julian Wiedmann5fc692a2019-01-25 15:44:23 +0100734 if (IS_OSM(card)) {
Julian Wiedmann9400c532017-10-18 17:40:20 +0200735 card->dev->features |= NETIF_F_VLAN_CHALLENGED;
Julian Wiedmann5fc692a2019-01-25 15:44:23 +0100736 } else {
737 if (!IS_VM_NIC(card))
738 card->dev->hw_features |= NETIF_F_HW_VLAN_CTAG_FILTER;
Julian Wiedmann9400c532017-10-18 17:40:20 +0200739 card->dev->features |= NETIF_F_HW_VLAN_CTAG_FILTER;
Julian Wiedmann5fc692a2019-01-25 15:44:23 +0100740 }
Julian Wiedmann0f342942018-03-09 18:12:54 +0100741
Thomas Richter4d7def22015-09-18 16:06:51 +0200742 if (card->info.type == QETH_CARD_TYPE_OSD && !card->info.guestlan) {
Julian Wiedmann6d69b1f2017-12-01 10:14:50 +0100743 card->dev->features |= NETIF_F_SG;
Thomas Richter8f43fb02016-06-16 16:18:59 +0200744 /* OSA 3S and earlier has no RX/TX support */
Hans Wippel9bdc4412016-06-16 16:19:00 +0200745 if (qeth_is_supported(card, IPA_OUTBOUND_CHECKSUM)) {
Thomas Richter8f43fb02016-06-16 16:18:59 +0200746 card->dev->hw_features |= NETIF_F_IP_CSUM;
Hans Wippel9bdc4412016-06-16 16:19:00 +0200747 card->dev->vlan_features |= NETIF_F_IP_CSUM;
748 }
Thomas Richter4d7def22015-09-18 16:06:51 +0200749 }
Kittipon Meesompop571f9dd82018-04-26 09:42:22 +0200750 if (qeth_is_supported6(card, IPA_OUTBOUND_CHECKSUM_V6)) {
751 card->dev->hw_features |= NETIF_F_IPV6_CSUM;
752 card->dev->vlan_features |= NETIF_F_IPV6_CSUM;
753 }
Kittipon Meesompopd7e6ed92018-04-26 09:42:23 +0200754 if (qeth_is_supported(card, IPA_INBOUND_CHECKSUM) ||
755 qeth_is_supported6(card, IPA_INBOUND_CHECKSUM_V6)) {
756 card->dev->hw_features |= NETIF_F_RXCSUM;
757 card->dev->vlan_features |= NETIF_F_RXCSUM;
758 }
Julian Wiedmann0aef8392018-10-12 17:27:15 +0200759 if (qeth_is_supported(card, IPA_OUTBOUND_TSO)) {
760 card->dev->hw_features |= NETIF_F_TSO;
761 card->dev->vlan_features |= NETIF_F_TSO;
762 }
763 if (qeth_is_supported6(card, IPA_OUTBOUND_TSO)) {
764 card->dev->hw_features |= NETIF_F_TSO6;
765 card->dev->vlan_features |= NETIF_F_TSO6;
766 }
767
768 if (card->dev->hw_features & (NETIF_F_TSO | NETIF_F_TSO6)) {
769 card->dev->needed_headroom = sizeof(struct qeth_hdr_tso);
770 netif_set_gso_max_size(card->dev,
771 PAGE_SIZE * (QDIO_MAX_ELEMENTS_PER_BUFFER - 1));
772 }
Julian Wiedmann0d6f02d2017-08-18 10:19:10 +0200773
Julian Wiedmann8024cc92019-02-15 19:22:31 +0100774add_napi:
Julian Wiedmannd73ef322017-04-11 16:11:11 +0200775 netif_napi_add(card->dev, &card->napi, qeth_poll, QETH_NAPI_WEIGHT);
Julian Wiedmannd3d1b202018-07-19 12:43:51 +0200776 rc = register_netdev(card->dev);
Julian Wiedmann9fae5c32018-11-02 19:04:11 +0100777 if (!rc && carrier_ok)
778 netif_carrier_on(card->dev);
779
Julian Wiedmannd3d1b202018-07-19 12:43:51 +0200780 if (rc)
781 card->dev->netdev_ops = NULL;
782 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100783}
784
Thomas Richter4d7def22015-09-18 16:06:51 +0200785static int qeth_l2_start_ipassists(struct qeth_card *card)
786{
787 /* configure isolation level */
788 if (qeth_set_access_ctrl_online(card, 0))
789 return -ENODEV;
Thomas Richter4d7def22015-09-18 16:06:51 +0200790 return 0;
791}
792
Julian Wiedmann521c10e2017-06-06 14:33:45 +0200793static void qeth_l2_trace_features(struct qeth_card *card)
794{
Hans Wippela45b3fa2017-09-18 21:18:14 +0200795 /* Set BridgePort features */
796 QETH_CARD_TEXT(card, 2, "featuSBP");
Julian Wiedmann521c10e2017-06-06 14:33:45 +0200797 QETH_CARD_HEX(card, 2, &card->options.sbp.supported_funcs,
798 sizeof(card->options.sbp.supported_funcs));
Hans Wippela45b3fa2017-09-18 21:18:14 +0200799 /* VNIC Characteristics features */
800 QETH_CARD_TEXT(card, 2, "feaVNICC");
801 QETH_CARD_HEX(card, 2, &card->options.vnicc.sup_chars,
802 sizeof(card->options.vnicc.sup_chars));
Julian Wiedmann521c10e2017-06-06 14:33:45 +0200803}
804
Frank Blaschka4a71df52008-02-15 09:19:42 +0100805static int __qeth_l2_set_online(struct ccwgroup_device *gdev, int recovery_mode)
806{
807 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
Julian Wiedmannfa3d2e62019-01-25 15:44:21 +0100808 struct net_device *dev = card->dev;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100809 int rc = 0;
Julian Wiedmann9fae5c32018-11-02 19:04:11 +0100810 bool carrier_ok;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100811
Ursula Braun9dc48cc2010-07-22 23:15:05 +0000812 mutex_lock(&card->discipline_mutex);
Frank Blaschkac4949f02010-05-11 19:34:47 +0000813 mutex_lock(&card->conf_mutex);
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200814 QETH_DBF_TEXT(SETUP, 2, "setonlin");
815 QETH_DBF_HEX(SETUP, 2, &card, sizeof(void *));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100816
Julian Wiedmann9fae5c32018-11-02 19:04:11 +0100817 rc = qeth_core_hardsetup_card(card, &carrier_ok);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100818 if (rc) {
Thomas Richter1aec42b2015-01-21 13:39:10 +0100819 QETH_DBF_TEXT_(SETUP, 2, "2err%04x", rc);
Ursula Braunaa909222009-11-12 00:11:43 +0000820 rc = -ENODEV;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100821 goto out_remove;
822 }
Eugene Crosserc044dc22014-01-29 09:23:48 +0100823 qeth_bridgeport_query_support(card);
824 if (card->options.sbp.supported_funcs)
825 dev_info(&card->gdev->dev,
Eugene Crosser9c23f4da2015-05-18 14:27:56 +0200826 "The device represents a Bridge Capable Port\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100827
Julian Wiedmann654e3d42019-01-25 15:44:19 +0100828 qeth_l2_register_dev_addr(card);
829
Frank Blaschka1da74b12011-05-12 18:45:02 +0000830 if (qeth_is_diagass_supported(card, QETH_DIAGS_CMD_TRAP)) {
831 if (card->info.hwtrap &&
832 qeth_hw_trap(card, QETH_DIAGS_TRAP_ARM))
833 card->info.hwtrap = 0;
834 } else
835 card->info.hwtrap = 0;
836
Hans Wippela45b3fa2017-09-18 21:18:14 +0200837 /* for the rx_bcast characteristic, init VNICC after setmac */
838 qeth_l2_vnicc_init(card);
839
840 qeth_trace_features(card);
841 qeth_l2_trace_features(card);
842
Eugene Crosserb4d72c02014-01-14 15:54:11 +0100843 qeth_l2_setup_bridgeport_attrs(card);
844
Frank Blaschka4a71df52008-02-15 09:19:42 +0100845 card->state = CARD_STATE_HARDSETUP;
846 qeth_print_status_message(card);
847
848 /* softsetup */
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200849 QETH_DBF_TEXT(SETUP, 2, "softsetp");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100850
Ursula Braun5113fec2010-05-16 21:15:14 +0000851 if ((card->info.type == QETH_CARD_TYPE_OSD) ||
Stefan Raspl0f547612013-01-21 02:30:20 +0000852 (card->info.type == QETH_CARD_TYPE_OSX)) {
Thomas Richter8f43fb02016-06-16 16:18:59 +0200853 rc = qeth_l2_start_ipassists(card);
854 if (rc)
Stefan Raspl0f547612013-01-21 02:30:20 +0000855 goto out_remove;
Stefan Raspl0f547612013-01-21 02:30:20 +0000856 }
Ursula Braun5113fec2010-05-16 21:15:14 +0000857
Frank Blaschka4a71df52008-02-15 09:19:42 +0100858 rc = qeth_init_qdio_queues(card);
859 if (rc) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200860 QETH_DBF_TEXT_(SETUP, 2, "6err%d", rc);
Ursula Braunaa909222009-11-12 00:11:43 +0000861 rc = -ENODEV;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100862 goto out_remove;
863 }
864 card->state = CARD_STATE_SOFTSETUP;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100865
866 qeth_set_allowed_threads(card, 0xffffffff, 0);
Julian Wiedmannd025da92018-06-29 19:45:54 +0200867
Julian Wiedmannfa3d2e62019-01-25 15:44:21 +0100868 if (!qeth_netdev_is_registered(dev)) {
869 rc = qeth_l2_setup_netdev(card, carrier_ok);
870 if (rc)
871 goto out_remove;
872 } else {
873 rtnl_lock();
874 if (carrier_ok)
875 netif_carrier_on(dev);
876 else
877 netif_carrier_off(dev);
878
Julian Wiedmanne6e771b2019-01-25 15:44:22 +0100879 netif_device_attach(dev);
Julian Wiedmannfa3d2e62019-01-25 15:44:21 +0100880 qeth_enable_hw_features(dev);
881
Julian Wiedmannd7d543f2019-02-28 18:59:36 +0100882 if (card->info.open_when_online) {
883 card->info.open_when_online = 0;
Julian Wiedmannfa3d2e62019-01-25 15:44:21 +0100884 if (recovery_mode && !IS_OSN(card)) {
885 if (!qeth_l2_validate_addr(dev)) {
Julian Wiedmanne6e771b2019-01-25 15:44:22 +0100886 qeth_open(dev);
Julian Wiedmannfa3d2e62019-01-25 15:44:21 +0100887 qeth_l2_set_rx_mode(dev);
888 }
889 } else {
890 dev_open(dev, NULL);
Julian Wiedmanne22355e2019-01-25 15:44:18 +0100891 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100892 }
Julian Wiedmannfa3d2e62019-01-25 15:44:21 +0100893 rtnl_unlock();
Frank Blaschka4a71df52008-02-15 09:19:42 +0100894 }
895 /* let user_space know that device is online */
896 kobject_uevent(&gdev->dev.kobj, KOBJ_CHANGE);
Frank Blaschkac4949f02010-05-11 19:34:47 +0000897 mutex_unlock(&card->conf_mutex);
Ursula Braun9dc48cc2010-07-22 23:15:05 +0000898 mutex_unlock(&card->discipline_mutex);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100899 return 0;
Ursula Braunaa909222009-11-12 00:11:43 +0000900
Frank Blaschka4a71df52008-02-15 09:19:42 +0100901out_remove:
Frank Blaschka4a71df52008-02-15 09:19:42 +0100902 qeth_l2_stop_card(card, 0);
903 ccw_device_set_offline(CARD_DDEV(card));
904 ccw_device_set_offline(CARD_WDEV(card));
905 ccw_device_set_offline(CARD_RDEV(card));
Ursula Braun22ae2792014-02-24 13:12:06 +0100906 qdio_free(CARD_DDEV(card));
Julian Wiedmannd7d543f2019-02-28 18:59:36 +0100907 card->state = CARD_STATE_DOWN;
908
Frank Blaschkac4949f02010-05-11 19:34:47 +0000909 mutex_unlock(&card->conf_mutex);
Ursula Braun9dc48cc2010-07-22 23:15:05 +0000910 mutex_unlock(&card->discipline_mutex);
Ursula Braunaa909222009-11-12 00:11:43 +0000911 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100912}
913
914static int qeth_l2_set_online(struct ccwgroup_device *gdev)
915{
916 return __qeth_l2_set_online(gdev, 0);
917}
918
919static int __qeth_l2_set_offline(struct ccwgroup_device *cgdev,
920 int recovery_mode)
921{
922 struct qeth_card *card = dev_get_drvdata(&cgdev->dev);
923 int rc = 0, rc2 = 0, rc3 = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100924
Ursula Braun9dc48cc2010-07-22 23:15:05 +0000925 mutex_lock(&card->discipline_mutex);
Frank Blaschkac4949f02010-05-11 19:34:47 +0000926 mutex_lock(&card->conf_mutex);
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200927 QETH_DBF_TEXT(SETUP, 3, "setoffl");
928 QETH_DBF_HEX(SETUP, 3, &card, sizeof(void *));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100929
Julian Wiedmanne6e771b2019-01-25 15:44:22 +0100930 rtnl_lock();
Julian Wiedmannd7d543f2019-02-28 18:59:36 +0100931 card->info.open_when_online = card->dev->flags & IFF_UP;
Julian Wiedmanne6e771b2019-01-25 15:44:22 +0100932 netif_device_detach(card->dev);
Julian Wiedmannd3d1b202018-07-19 12:43:51 +0200933 netif_carrier_off(card->dev);
Julian Wiedmanne6e771b2019-01-25 15:44:22 +0100934 rtnl_unlock();
935
Frank Blaschka1da74b12011-05-12 18:45:02 +0000936 if ((!recovery_mode && card->info.hwtrap) || card->info.hwtrap == 2) {
937 qeth_hw_trap(card, QETH_DIAGS_TRAP_DISARM);
938 card->info.hwtrap = 1;
939 }
Ursula Braun0f5623c2008-10-24 11:16:52 +0200940 qeth_l2_stop_card(card, recovery_mode);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100941 rc = ccw_device_set_offline(CARD_DDEV(card));
942 rc2 = ccw_device_set_offline(CARD_WDEV(card));
943 rc3 = ccw_device_set_offline(CARD_RDEV(card));
944 if (!rc)
945 rc = (rc2) ? rc2 : rc3;
946 if (rc)
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200947 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
Ursula Braun22ae2792014-02-24 13:12:06 +0100948 qdio_free(CARD_DDEV(card));
Julian Wiedmannd7d543f2019-02-28 18:59:36 +0100949
Frank Blaschka4a71df52008-02-15 09:19:42 +0100950 /* let user_space know that device is offline */
951 kobject_uevent(&cgdev->dev.kobj, KOBJ_CHANGE);
Frank Blaschkac4949f02010-05-11 19:34:47 +0000952 mutex_unlock(&card->conf_mutex);
Ursula Braun9dc48cc2010-07-22 23:15:05 +0000953 mutex_unlock(&card->discipline_mutex);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100954 return 0;
955}
956
957static int qeth_l2_set_offline(struct ccwgroup_device *cgdev)
958{
959 return __qeth_l2_set_offline(cgdev, 0);
960}
961
962static int qeth_l2_recover(void *ptr)
963{
964 struct qeth_card *card;
965 int rc = 0;
966
967 card = (struct qeth_card *) ptr;
Carsten Otte847a50f2010-06-21 22:57:05 +0000968 QETH_CARD_TEXT(card, 2, "recover1");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100969 if (!qeth_do_run_thread(card, QETH_RECOVER_THREAD))
970 return 0;
Carsten Otte847a50f2010-06-21 22:57:05 +0000971 QETH_CARD_TEXT(card, 2, "recover2");
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100972 dev_warn(&card->gdev->dev,
973 "A recovery process has been started for the device\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100974 __qeth_l2_set_offline(card->gdev, 1);
975 rc = __qeth_l2_set_online(card->gdev, 1);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100976 if (!rc)
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100977 dev_info(&card->gdev->dev,
978 "Device successfully recovered!\n");
Ursula Braun28a7e4c2008-09-19 12:56:03 +0200979 else {
Stefan Raspl0f547612013-01-21 02:30:20 +0000980 qeth_close_dev(card);
981 dev_warn(&card->gdev->dev, "The qeth device driver "
Stefan Raspl2efaf5f2012-10-15 19:21:18 +0000982 "failed to recover an error on the device\n");
Ursula Braun28a7e4c2008-09-19 12:56:03 +0200983 }
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000984 qeth_clear_thread_start_bit(card, QETH_RECOVER_THREAD);
985 qeth_clear_thread_running_bit(card, QETH_RECOVER_THREAD);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100986 return 0;
987}
988
989static int __init qeth_l2_init(void)
990{
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100991 pr_info("register layer 2 discipline\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100992 return 0;
993}
994
995static void __exit qeth_l2_exit(void)
996{
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100997 pr_info("unregister layer 2 discipline\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100998}
999
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02001000static int qeth_l2_pm_suspend(struct ccwgroup_device *gdev)
1001{
1002 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
1003
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02001004 qeth_set_allowed_threads(card, 0, 1);
1005 wait_event(card->wait_q, qeth_threads_running(card, 0xffffffff) == 0);
1006 if (gdev->state == CCWGROUP_OFFLINE)
1007 return 0;
1008 if (card->state == CARD_STATE_UP) {
Frank Blaschka1da74b12011-05-12 18:45:02 +00001009 if (card->info.hwtrap)
1010 qeth_hw_trap(card, QETH_DIAGS_TRAP_DISARM);
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02001011 __qeth_l2_set_offline(card->gdev, 1);
1012 } else
1013 __qeth_l2_set_offline(card->gdev, 0);
1014 return 0;
1015}
1016
1017static int qeth_l2_pm_resume(struct ccwgroup_device *gdev)
1018{
1019 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
1020 int rc = 0;
1021
Julian Wiedmannd7d543f2019-02-28 18:59:36 +01001022 if (card->info.open_when_online) {
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02001023 rc = __qeth_l2_set_online(card->gdev, 1);
1024 if (rc) {
Ursula Braun869da902010-03-08 20:36:56 +00001025 rtnl_lock();
1026 dev_close(card->dev);
1027 rtnl_unlock();
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02001028 }
1029 } else
1030 rc = __qeth_l2_set_online(card->gdev, 0);
Julian Wiedmann6585ac42018-09-26 18:29:12 +02001031
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02001032 qeth_set_allowed_threads(card, 0xffffffff, 0);
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02001033 if (rc)
1034 dev_warn(&card->gdev->dev, "The qeth device driver "
1035 "failed to recover an error on the device\n");
1036 return rc;
1037}
1038
Eugene Crosserc044dc22014-01-29 09:23:48 +01001039/* Returns zero if the command is successfully "consumed" */
1040static int qeth_l2_control_event(struct qeth_card *card,
1041 struct qeth_ipa_cmd *cmd)
1042{
1043 switch (cmd->hdr.command) {
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001044 case IPA_CMD_SETBRIDGEPORT_OSA:
1045 case IPA_CMD_SETBRIDGEPORT_IQD:
Eugene Crosserc044dc22014-01-29 09:23:48 +01001046 if (cmd->data.sbp.hdr.command_code ==
1047 IPA_SBP_BRIDGE_PORT_STATE_CHANGE) {
1048 qeth_bridge_state_change(card, cmd);
1049 return 0;
1050 } else
1051 return 1;
1052 case IPA_CMD_ADDRESS_CHANGE_NOTIF:
1053 qeth_bridge_host_event(card, cmd);
1054 return 0;
1055 default:
1056 return 1;
1057 }
1058}
1059
Sebastian Ottc041f2d4872012-05-15 18:02:21 +02001060struct qeth_discipline qeth_l2_discipline = {
Julian Wiedmann2d2ebb32017-05-10 19:07:52 +02001061 .devtype = &qeth_l2_devtype,
Julian Wiedmannd73ef322017-04-11 16:11:11 +02001062 .process_rx_buffer = qeth_l2_process_inbound_buffer,
Sebastian Ottc041f2d4872012-05-15 18:02:21 +02001063 .recover = qeth_l2_recover,
1064 .setup = qeth_l2_probe_device,
Frank Blaschka4a71df52008-02-15 09:19:42 +01001065 .remove = qeth_l2_remove_device,
1066 .set_online = qeth_l2_set_online,
1067 .set_offline = qeth_l2_set_offline,
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02001068 .freeze = qeth_l2_pm_suspend,
1069 .thaw = qeth_l2_pm_resume,
1070 .restore = qeth_l2_pm_resume,
Julian Wiedmann942d6982017-04-11 16:11:10 +02001071 .do_ioctl = NULL,
Eugene Crosserc044dc22014-01-29 09:23:48 +01001072 .control_event_handler = qeth_l2_control_event,
Frank Blaschka4a71df52008-02-15 09:19:42 +01001073};
Sebastian Ottc041f2d4872012-05-15 18:02:21 +02001074EXPORT_SYMBOL_GPL(qeth_l2_discipline);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001075
1076static int qeth_osn_send_control_data(struct qeth_card *card, int len,
1077 struct qeth_cmd_buffer *iob)
1078{
Julian Wiedmann750b1622018-08-09 14:47:59 +02001079 struct qeth_channel *channel = iob->channel;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001080 int rc = 0;
1081
Carsten Otte847a50f2010-06-21 22:57:05 +00001082 QETH_CARD_TEXT(card, 5, "osndctrd");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001083
1084 wait_event(card->wait_q,
Julian Wiedmann750b1622018-08-09 14:47:59 +02001085 atomic_cmpxchg(&channel->irq_pending, 0, 1) == 0);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001086 qeth_prepare_control_data(card, len, iob);
Carsten Otte847a50f2010-06-21 22:57:05 +00001087 QETH_CARD_TEXT(card, 6, "osnoirqp");
Julian Wiedmanned471552018-09-17 17:36:08 +02001088 spin_lock_irq(get_ccwdev_lock(channel->ccwdev));
Julian Wiedmannf15cdaf2018-08-09 14:48:03 +02001089 rc = ccw_device_start_timeout(channel->ccwdev, channel->ccw,
Julian Wiedmanndb71bbb2018-04-19 12:52:10 +02001090 (addr_t) iob, 0, 0, QETH_IPA_TIMEOUT);
Julian Wiedmanned471552018-09-17 17:36:08 +02001091 spin_unlock_irq(get_ccwdev_lock(channel->ccwdev));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001092 if (rc) {
Frank Blaschka14cc21b2008-06-06 12:37:46 +02001093 QETH_DBF_MESSAGE(2, "qeth_osn_send_control_data: "
Frank Blaschka4a71df52008-02-15 09:19:42 +01001094 "ccw_device_start rc = %i\n", rc);
Carsten Otte847a50f2010-06-21 22:57:05 +00001095 QETH_CARD_TEXT_(card, 2, " err%d", rc);
Julian Wiedmann750b1622018-08-09 14:47:59 +02001096 qeth_release_buffer(channel, iob);
1097 atomic_set(&channel->irq_pending, 0);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001098 wake_up(&card->wait_q);
1099 }
1100 return rc;
1101}
1102
1103static int qeth_osn_send_ipa_cmd(struct qeth_card *card,
Julian Wiedmannc2153272019-02-12 18:33:17 +01001104 struct qeth_cmd_buffer *iob)
Frank Blaschka4a71df52008-02-15 09:19:42 +01001105{
Julian Wiedmannc2153272019-02-12 18:33:17 +01001106 u16 length;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001107
Carsten Otte847a50f2010-06-21 22:57:05 +00001108 QETH_CARD_TEXT(card, 4, "osndipa");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001109
Julian Wiedmannc2153272019-02-12 18:33:17 +01001110 memcpy(&length, QETH_IPA_PDU_LEN_TOTAL(iob->data), 2);
1111 return qeth_osn_send_control_data(card, length, iob);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001112}
1113
1114int qeth_osn_assist(struct net_device *dev, void *data, int data_len)
1115{
1116 struct qeth_cmd_buffer *iob;
1117 struct qeth_card *card;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001118
Frank Blaschka4a71df52008-02-15 09:19:42 +01001119 if (!dev)
1120 return -ENODEV;
Heiko Carstens509e2562008-07-26 02:24:10 -07001121 card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001122 if (!card)
1123 return -ENODEV;
Carsten Otte847a50f2010-06-21 22:57:05 +00001124 QETH_CARD_TEXT(card, 2, "osnsdmc");
Eugene Crosserc3521252015-01-16 14:05:47 +01001125 if (!qeth_card_hw_is_reachable(card))
Frank Blaschka4a71df52008-02-15 09:19:42 +01001126 return -ENODEV;
1127 iob = qeth_wait_for_buffer(&card->write);
Julian Wiedmannc2153272019-02-12 18:33:17 +01001128 qeth_prepare_ipa_cmd(card, iob, (u16) data_len);
Julian Wiedmannff5caa72018-03-09 18:12:52 +01001129 memcpy(__ipa_cmd(iob), data, data_len);
Julian Wiedmannc2153272019-02-12 18:33:17 +01001130 return qeth_osn_send_ipa_cmd(card, iob);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001131}
1132EXPORT_SYMBOL(qeth_osn_assist);
1133
1134int qeth_osn_register(unsigned char *read_dev_no, struct net_device **dev,
1135 int (*assist_cb)(struct net_device *, void *),
1136 int (*data_cb)(struct sk_buff *))
1137{
1138 struct qeth_card *card;
Julian Wiedmannd7d18da2018-11-08 15:06:18 +01001139 char bus_id[16];
1140 u16 devno;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001141
Julian Wiedmannd7d18da2018-11-08 15:06:18 +01001142 memcpy(&devno, read_dev_no, 2);
1143 sprintf(bus_id, "0.0.%04x", devno);
1144 card = qeth_get_card_by_busid(bus_id);
1145 if (!card || !IS_OSN(card))
Frank Blaschka4a71df52008-02-15 09:19:42 +01001146 return -ENODEV;
Julian Wiedmannd7d18da2018-11-08 15:06:18 +01001147 *dev = card->dev;
1148
Carsten Otte847a50f2010-06-21 22:57:05 +00001149 QETH_CARD_TEXT(card, 2, "osnreg");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001150 if ((assist_cb == NULL) || (data_cb == NULL))
1151 return -EINVAL;
1152 card->osn_info.assist_cb = assist_cb;
1153 card->osn_info.data_cb = data_cb;
1154 return 0;
1155}
1156EXPORT_SYMBOL(qeth_osn_register);
1157
1158void qeth_osn_deregister(struct net_device *dev)
1159{
1160 struct qeth_card *card;
1161
Frank Blaschka4a71df52008-02-15 09:19:42 +01001162 if (!dev)
1163 return;
Heiko Carstens509e2562008-07-26 02:24:10 -07001164 card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001165 if (!card)
1166 return;
Carsten Otte847a50f2010-06-21 22:57:05 +00001167 QETH_CARD_TEXT(card, 2, "osndereg");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001168 card->osn_info.assist_cb = NULL;
1169 card->osn_info.data_cb = NULL;
1170 return;
1171}
1172EXPORT_SYMBOL(qeth_osn_deregister);
1173
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001174/* SETBRIDGEPORT support, async notifications */
1175
Eugene Crosser9f48b9d2014-01-14 15:54:13 +01001176enum qeth_an_event_type {anev_reg_unreg, anev_abort, anev_reset};
1177
1178/**
1179 * qeth_bridge_emit_host_event() - bridgeport address change notification
1180 * @card: qeth_card structure pointer, for udev events.
1181 * @evtype: "normal" register/unregister, or abort, or reset. For abort
1182 * and reset token and addr_lnid are unused and may be NULL.
1183 * @code: event bitmask: high order bit 0x80 value 1 means removal of an
1184 * object, 0 - addition of an object.
1185 * 0x01 - VLAN, 0x02 - MAC, 0x03 - VLAN and MAC.
1186 * @token: "network token" structure identifying physical address of the port.
1187 * @addr_lnid: pointer to structure with MAC address and VLAN ID.
1188 *
1189 * This function is called when registrations and deregistrations are
1190 * reported by the hardware, and also when notifications are enabled -
1191 * for all currently registered addresses.
1192 */
1193static void qeth_bridge_emit_host_event(struct qeth_card *card,
1194 enum qeth_an_event_type evtype,
1195 u8 code, struct net_if_token *token, struct mac_addr_lnid *addr_lnid)
1196{
1197 char str[7][32];
1198 char *env[8];
1199 int i = 0;
1200
1201 switch (evtype) {
1202 case anev_reg_unreg:
1203 snprintf(str[i], sizeof(str[i]), "BRIDGEDHOST=%s",
1204 (code & IPA_ADDR_CHANGE_CODE_REMOVAL)
1205 ? "deregister" : "register");
1206 env[i] = str[i]; i++;
1207 if (code & IPA_ADDR_CHANGE_CODE_VLANID) {
1208 snprintf(str[i], sizeof(str[i]), "VLAN=%d",
1209 addr_lnid->lnid);
1210 env[i] = str[i]; i++;
1211 }
1212 if (code & IPA_ADDR_CHANGE_CODE_MACADDR) {
Eugene Crosser9846e702015-09-18 16:06:48 +02001213 snprintf(str[i], sizeof(str[i]), "MAC=%pM",
Thomas Richter4d7def22015-09-18 16:06:51 +02001214 addr_lnid->mac);
Eugene Crosser9f48b9d2014-01-14 15:54:13 +01001215 env[i] = str[i]; i++;
1216 }
1217 snprintf(str[i], sizeof(str[i]), "NTOK_BUSID=%x.%x.%04x",
1218 token->cssid, token->ssid, token->devnum);
1219 env[i] = str[i]; i++;
1220 snprintf(str[i], sizeof(str[i]), "NTOK_IID=%02x", token->iid);
1221 env[i] = str[i]; i++;
1222 snprintf(str[i], sizeof(str[i]), "NTOK_CHPID=%02x",
1223 token->chpid);
1224 env[i] = str[i]; i++;
1225 snprintf(str[i], sizeof(str[i]), "NTOK_CHID=%04x", token->chid);
1226 env[i] = str[i]; i++;
1227 break;
1228 case anev_abort:
1229 snprintf(str[i], sizeof(str[i]), "BRIDGEDHOST=abort");
1230 env[i] = str[i]; i++;
1231 break;
1232 case anev_reset:
1233 snprintf(str[i], sizeof(str[i]), "BRIDGEDHOST=reset");
1234 env[i] = str[i]; i++;
1235 break;
1236 }
1237 env[i] = NULL;
1238 kobject_uevent_env(&card->gdev->dev.kobj, KOBJ_CHANGE, env);
1239}
1240
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001241struct qeth_bridge_state_data {
1242 struct work_struct worker;
1243 struct qeth_card *card;
1244 struct qeth_sbp_state_change qports;
1245};
1246
1247static void qeth_bridge_state_change_worker(struct work_struct *work)
1248{
1249 struct qeth_bridge_state_data *data =
1250 container_of(work, struct qeth_bridge_state_data, worker);
1251 /* We are only interested in the first entry - local port */
1252 struct qeth_sbp_port_entry *entry = &data->qports.entry[0];
1253 char env_locrem[32];
1254 char env_role[32];
1255 char env_state[32];
1256 char *env[] = {
1257 env_locrem,
1258 env_role,
1259 env_state,
1260 NULL
1261 };
1262
1263 /* Role should not change by itself, but if it did, */
1264 /* information from the hardware is authoritative. */
1265 mutex_lock(&data->card->conf_mutex);
1266 data->card->options.sbp.role = entry->role;
1267 mutex_unlock(&data->card->conf_mutex);
1268
1269 snprintf(env_locrem, sizeof(env_locrem), "BRIDGEPORT=statechange");
1270 snprintf(env_role, sizeof(env_role), "ROLE=%s",
1271 (entry->role == QETH_SBP_ROLE_NONE) ? "none" :
1272 (entry->role == QETH_SBP_ROLE_PRIMARY) ? "primary" :
1273 (entry->role == QETH_SBP_ROLE_SECONDARY) ? "secondary" :
1274 "<INVALID>");
1275 snprintf(env_state, sizeof(env_state), "STATE=%s",
1276 (entry->state == QETH_SBP_STATE_INACTIVE) ? "inactive" :
1277 (entry->state == QETH_SBP_STATE_STANDBY) ? "standby" :
1278 (entry->state == QETH_SBP_STATE_ACTIVE) ? "active" :
1279 "<INVALID>");
1280 kobject_uevent_env(&data->card->gdev->dev.kobj,
1281 KOBJ_CHANGE, env);
1282 kfree(data);
1283}
1284
Eugene Crosserc044dc22014-01-29 09:23:48 +01001285static void qeth_bridge_state_change(struct qeth_card *card,
1286 struct qeth_ipa_cmd *cmd)
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001287{
1288 struct qeth_sbp_state_change *qports =
1289 &cmd->data.sbp.data.state_change;
1290 struct qeth_bridge_state_data *data;
1291 int extrasize;
1292
1293 QETH_CARD_TEXT(card, 2, "brstchng");
1294 if (qports->entry_length != sizeof(struct qeth_sbp_port_entry)) {
Thomas Richter8a593142014-10-22 12:18:03 +02001295 QETH_CARD_TEXT_(card, 2, "BPsz%04x", qports->entry_length);
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001296 return;
1297 }
1298 extrasize = sizeof(struct qeth_sbp_port_entry) * qports->num_entries;
1299 data = kzalloc(sizeof(struct qeth_bridge_state_data) + extrasize,
1300 GFP_ATOMIC);
1301 if (!data) {
1302 QETH_CARD_TEXT(card, 2, "BPSalloc");
1303 return;
1304 }
1305 INIT_WORK(&data->worker, qeth_bridge_state_change_worker);
1306 data->card = card;
1307 memcpy(&data->qports, qports,
1308 sizeof(struct qeth_sbp_state_change) + extrasize);
Julian Wiedmannc0a2e4d2019-02-04 17:40:09 +01001309 queue_work(card->event_wq, &data->worker);
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001310}
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001311
Eugene Crosser9f48b9d2014-01-14 15:54:13 +01001312struct qeth_bridge_host_data {
1313 struct work_struct worker;
1314 struct qeth_card *card;
1315 struct qeth_ipacmd_addr_change hostevs;
1316};
1317
1318static void qeth_bridge_host_event_worker(struct work_struct *work)
1319{
1320 struct qeth_bridge_host_data *data =
1321 container_of(work, struct qeth_bridge_host_data, worker);
1322 int i;
1323
1324 if (data->hostevs.lost_event_mask) {
1325 dev_info(&data->card->gdev->dev,
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001326"Address notification from the Bridge Port stopped %s (%s)\n",
Eugene Crosser9f48b9d2014-01-14 15:54:13 +01001327 data->card->dev->name,
1328 (data->hostevs.lost_event_mask == 0x01)
1329 ? "Overflow"
1330 : (data->hostevs.lost_event_mask == 0x02)
1331 ? "Bridge port state change"
1332 : "Unknown reason");
1333 mutex_lock(&data->card->conf_mutex);
1334 data->card->options.sbp.hostnotification = 0;
1335 mutex_unlock(&data->card->conf_mutex);
1336 qeth_bridge_emit_host_event(data->card, anev_abort,
1337 0, NULL, NULL);
1338 } else
1339 for (i = 0; i < data->hostevs.num_entries; i++) {
1340 struct qeth_ipacmd_addr_change_entry *entry =
1341 &data->hostevs.entry[i];
1342 qeth_bridge_emit_host_event(data->card,
1343 anev_reg_unreg,
1344 entry->change_code,
1345 &entry->token, &entry->addr_lnid);
1346 }
1347 kfree(data);
1348}
1349
Eugene Crosserc044dc22014-01-29 09:23:48 +01001350static void qeth_bridge_host_event(struct qeth_card *card,
1351 struct qeth_ipa_cmd *cmd)
Eugene Crosser9f48b9d2014-01-14 15:54:13 +01001352{
1353 struct qeth_ipacmd_addr_change *hostevs =
1354 &cmd->data.addrchange;
1355 struct qeth_bridge_host_data *data;
1356 int extrasize;
1357
1358 QETH_CARD_TEXT(card, 2, "brhostev");
1359 if (cmd->hdr.return_code != 0x0000) {
1360 if (cmd->hdr.return_code == 0x0010) {
1361 if (hostevs->lost_event_mask == 0x00)
1362 hostevs->lost_event_mask = 0xff;
1363 } else {
1364 QETH_CARD_TEXT_(card, 2, "BPHe%04x",
1365 cmd->hdr.return_code);
1366 return;
1367 }
1368 }
1369 extrasize = sizeof(struct qeth_ipacmd_addr_change_entry) *
1370 hostevs->num_entries;
1371 data = kzalloc(sizeof(struct qeth_bridge_host_data) + extrasize,
1372 GFP_ATOMIC);
1373 if (!data) {
1374 QETH_CARD_TEXT(card, 2, "BPHalloc");
1375 return;
1376 }
1377 INIT_WORK(&data->worker, qeth_bridge_host_event_worker);
1378 data->card = card;
1379 memcpy(&data->hostevs, hostevs,
1380 sizeof(struct qeth_ipacmd_addr_change) + extrasize);
Julian Wiedmannc0a2e4d2019-02-04 17:40:09 +01001381 queue_work(card->event_wq, &data->worker);
Eugene Crosser9f48b9d2014-01-14 15:54:13 +01001382}
Eugene Crosser9f48b9d2014-01-14 15:54:13 +01001383
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001384/* SETBRIDGEPORT support; sending commands */
1385
1386struct _qeth_sbp_cbctl {
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001387 union {
1388 u32 supported;
1389 struct {
1390 enum qeth_sbp_roles *role;
1391 enum qeth_sbp_states *state;
1392 } qports;
1393 } data;
1394};
1395
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001396static int qeth_bridgeport_makerc(struct qeth_card *card,
Julian Wiedmann1709ff82019-02-12 18:33:24 +01001397 struct qeth_ipa_cmd *cmd)
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001398{
Julian Wiedmann1709ff82019-02-12 18:33:24 +01001399 struct qeth_ipacmd_setbridgeport *sbp = &cmd->data.sbp;
1400 enum qeth_ipa_sbp_cmd setcmd = sbp->hdr.command_code;
1401 u16 ipa_rc = cmd->hdr.return_code;
1402 u16 sbp_rc = sbp->hdr.return_code;
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001403 int rc;
1404
Julian Wiedmann1709ff82019-02-12 18:33:24 +01001405 if (ipa_rc == IPA_RC_SUCCESS && sbp_rc == IPA_RC_SUCCESS)
1406 return 0;
1407
1408 if ((IS_IQD(card) && ipa_rc == IPA_RC_SUCCESS) ||
1409 (!IS_IQD(card) && ipa_rc == sbp_rc)) {
1410 switch (sbp_rc) {
Kittipon Meesompop2063a5f2017-06-20 16:00:31 +02001411 case IPA_RC_SUCCESS:
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001412 rc = 0;
1413 break;
Kittipon Meesompop2063a5f2017-06-20 16:00:31 +02001414 case IPA_RC_L2_UNSUPPORTED_CMD:
1415 case IPA_RC_UNSUPPORTED_COMMAND:
Eugene Crosserffb95252015-05-18 14:27:58 +02001416 rc = -EOPNOTSUPP;
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001417 break;
Kittipon Meesompop2063a5f2017-06-20 16:00:31 +02001418 case IPA_RC_SBP_OSA_NOT_CONFIGURED:
1419 case IPA_RC_SBP_IQD_NOT_CONFIGURED:
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001420 rc = -ENODEV; /* maybe not the best code here? */
1421 dev_err(&card->gdev->dev,
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001422 "The device is not configured as a Bridge Port\n");
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001423 break;
Kittipon Meesompop2063a5f2017-06-20 16:00:31 +02001424 case IPA_RC_SBP_OSA_OS_MISMATCH:
1425 case IPA_RC_SBP_IQD_OS_MISMATCH:
Eugene Crosser1b05cf62016-06-16 16:18:51 +02001426 rc = -EPERM;
1427 dev_err(&card->gdev->dev,
1428 "A Bridge Port is already configured by a different operating system\n");
1429 break;
Kittipon Meesompop2063a5f2017-06-20 16:00:31 +02001430 case IPA_RC_SBP_OSA_ANO_DEV_PRIMARY:
1431 case IPA_RC_SBP_IQD_ANO_DEV_PRIMARY:
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001432 switch (setcmd) {
1433 case IPA_SBP_SET_PRIMARY_BRIDGE_PORT:
1434 rc = -EEXIST;
1435 dev_err(&card->gdev->dev,
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001436 "The LAN already has a primary Bridge Port\n");
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001437 break;
1438 case IPA_SBP_SET_SECONDARY_BRIDGE_PORT:
1439 rc = -EBUSY;
1440 dev_err(&card->gdev->dev,
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001441 "The device is already a primary Bridge Port\n");
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001442 break;
1443 default:
1444 rc = -EIO;
1445 }
1446 break;
Kittipon Meesompop2063a5f2017-06-20 16:00:31 +02001447 case IPA_RC_SBP_OSA_CURRENT_SECOND:
1448 case IPA_RC_SBP_IQD_CURRENT_SECOND:
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001449 rc = -EBUSY;
1450 dev_err(&card->gdev->dev,
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001451 "The device is already a secondary Bridge Port\n");
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001452 break;
Kittipon Meesompop2063a5f2017-06-20 16:00:31 +02001453 case IPA_RC_SBP_OSA_LIMIT_SECOND:
1454 case IPA_RC_SBP_IQD_LIMIT_SECOND:
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001455 rc = -EEXIST;
1456 dev_err(&card->gdev->dev,
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001457 "The LAN cannot have more secondary Bridge Ports\n");
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001458 break;
Kittipon Meesompop2063a5f2017-06-20 16:00:31 +02001459 case IPA_RC_SBP_OSA_CURRENT_PRIMARY:
1460 case IPA_RC_SBP_IQD_CURRENT_PRIMARY:
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001461 rc = -EBUSY;
1462 dev_err(&card->gdev->dev,
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001463 "The device is already a primary Bridge Port\n");
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001464 break;
Kittipon Meesompop2063a5f2017-06-20 16:00:31 +02001465 case IPA_RC_SBP_OSA_NOT_AUTHD_BY_ZMAN:
1466 case IPA_RC_SBP_IQD_NOT_AUTHD_BY_ZMAN:
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001467 rc = -EACCES;
1468 dev_err(&card->gdev->dev,
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001469 "The device is not authorized to be a Bridge Port\n");
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001470 break;
1471 default:
1472 rc = -EIO;
1473 }
Julian Wiedmann1709ff82019-02-12 18:33:24 +01001474 } else {
1475 switch (ipa_rc) {
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001476 case IPA_RC_NOTSUPP:
Eugene Crosserffb95252015-05-18 14:27:58 +02001477 rc = -EOPNOTSUPP;
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001478 break;
1479 case IPA_RC_UNSUPPORTED_COMMAND:
Eugene Crosserffb95252015-05-18 14:27:58 +02001480 rc = -EOPNOTSUPP;
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001481 break;
1482 default:
1483 rc = -EIO;
1484 }
Julian Wiedmann1709ff82019-02-12 18:33:24 +01001485 }
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001486
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001487 if (rc) {
Julian Wiedmann1709ff82019-02-12 18:33:24 +01001488 QETH_CARD_TEXT_(card, 2, "SBPi%04x", ipa_rc);
1489 QETH_CARD_TEXT_(card, 2, "SBPc%04x", sbp_rc);
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001490 }
1491 return rc;
1492}
1493
Julian Wiedmannd65626a2017-08-15 17:02:47 +02001494static struct qeth_cmd_buffer *qeth_sbp_build_cmd(struct qeth_card *card,
1495 enum qeth_ipa_sbp_cmd sbp_cmd,
1496 unsigned int cmd_length)
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001497{
Julian Wiedmannd65626a2017-08-15 17:02:47 +02001498 enum qeth_ipa_cmds ipa_cmd = (card->info.type == QETH_CARD_TYPE_IQD) ?
1499 IPA_CMD_SETBRIDGEPORT_IQD :
1500 IPA_CMD_SETBRIDGEPORT_OSA;
1501 struct qeth_cmd_buffer *iob;
1502 struct qeth_ipa_cmd *cmd;
1503
1504 iob = qeth_get_ipacmd_buffer(card, ipa_cmd, 0);
1505 if (!iob)
1506 return iob;
Julian Wiedmannff5caa72018-03-09 18:12:52 +01001507 cmd = __ipa_cmd(iob);
Julian Wiedmannd65626a2017-08-15 17:02:47 +02001508 cmd->data.sbp.hdr.cmdlength = sizeof(struct qeth_ipacmd_sbp_hdr) +
1509 cmd_length;
1510 cmd->data.sbp.hdr.command_code = sbp_cmd;
1511 cmd->data.sbp.hdr.used_total = 1;
1512 cmd->data.sbp.hdr.seq_no = 1;
1513 return iob;
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001514}
1515
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001516static int qeth_bridgeport_query_support_cb(struct qeth_card *card,
1517 struct qeth_reply *reply, unsigned long data)
1518{
1519 struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *) data;
1520 struct _qeth_sbp_cbctl *cbctl = (struct _qeth_sbp_cbctl *)reply->param;
Julian Wiedmann1709ff82019-02-12 18:33:24 +01001521 int rc;
1522
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001523 QETH_CARD_TEXT(card, 2, "brqsupcb");
Julian Wiedmann1709ff82019-02-12 18:33:24 +01001524 rc = qeth_bridgeport_makerc(card, cmd);
1525 if (rc)
1526 return rc;
1527
1528 cbctl->data.supported =
1529 cmd->data.sbp.data.query_cmds_supp.supported_cmds;
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001530 return 0;
1531}
1532
1533/**
1534 * qeth_bridgeport_query_support() - store bitmask of supported subfunctions.
1535 * @card: qeth_card structure pointer.
1536 *
1537 * Sets bitmask of supported setbridgeport subfunctions in the qeth_card
1538 * strucutre: card->options.sbp.supported_funcs.
1539 */
Eugene Crosserc044dc22014-01-29 09:23:48 +01001540static void qeth_bridgeport_query_support(struct qeth_card *card)
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001541{
1542 struct qeth_cmd_buffer *iob;
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001543 struct _qeth_sbp_cbctl cbctl;
1544
1545 QETH_CARD_TEXT(card, 2, "brqsuppo");
Julian Wiedmannd65626a2017-08-15 17:02:47 +02001546 iob = qeth_sbp_build_cmd(card, IPA_SBP_QUERY_COMMANDS_SUPPORTED,
1547 sizeof(struct qeth_sbp_query_cmds_supp));
Thomas Richter1aec42b2015-01-21 13:39:10 +01001548 if (!iob)
1549 return;
Julian Wiedmann1709ff82019-02-12 18:33:24 +01001550
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001551 if (qeth_send_ipa_cmd(card, iob, qeth_bridgeport_query_support_cb,
Julian Wiedmann1709ff82019-02-12 18:33:24 +01001552 &cbctl)) {
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001553 card->options.sbp.role = QETH_SBP_ROLE_NONE;
Julian Wiedmann1709ff82019-02-12 18:33:24 +01001554 card->options.sbp.supported_funcs = 0;
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001555 return;
1556 }
1557 card->options.sbp.supported_funcs = cbctl.data.supported;
1558}
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001559
1560static int qeth_bridgeport_query_ports_cb(struct qeth_card *card,
1561 struct qeth_reply *reply, unsigned long data)
1562{
1563 struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *) data;
1564 struct qeth_sbp_query_ports *qports = &cmd->data.sbp.data.query_ports;
1565 struct _qeth_sbp_cbctl *cbctl = (struct _qeth_sbp_cbctl *)reply->param;
Julian Wiedmann1709ff82019-02-12 18:33:24 +01001566 int rc;
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001567
1568 QETH_CARD_TEXT(card, 2, "brqprtcb");
Julian Wiedmann1709ff82019-02-12 18:33:24 +01001569 rc = qeth_bridgeport_makerc(card, cmd);
1570 if (rc)
1571 return rc;
1572
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001573 if (qports->entry_length != sizeof(struct qeth_sbp_port_entry)) {
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001574 QETH_CARD_TEXT_(card, 2, "SBPs%04x", qports->entry_length);
Julian Wiedmann1709ff82019-02-12 18:33:24 +01001575 return -EINVAL;
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001576 }
1577 /* first entry contains the state of the local port */
1578 if (qports->num_entries > 0) {
1579 if (cbctl->data.qports.role)
1580 *cbctl->data.qports.role = qports->entry[0].role;
1581 if (cbctl->data.qports.state)
1582 *cbctl->data.qports.state = qports->entry[0].state;
1583 }
1584 return 0;
1585}
1586
1587/**
1588 * qeth_bridgeport_query_ports() - query local bridgeport status.
1589 * @card: qeth_card structure pointer.
1590 * @role: Role of the port: 0-none, 1-primary, 2-secondary.
1591 * @state: State of the port: 0-inactive, 1-standby, 2-active.
1592 *
1593 * Returns negative errno-compatible error indication or 0 on success.
1594 *
1595 * 'role' and 'state' are not updated in case of hardware operation failure.
1596 */
1597int qeth_bridgeport_query_ports(struct qeth_card *card,
1598 enum qeth_sbp_roles *role, enum qeth_sbp_states *state)
1599{
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001600 struct qeth_cmd_buffer *iob;
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001601 struct _qeth_sbp_cbctl cbctl = {
1602 .data = {
1603 .qports = {
1604 .role = role,
1605 .state = state,
1606 },
1607 },
1608 };
1609
1610 QETH_CARD_TEXT(card, 2, "brqports");
1611 if (!(card->options.sbp.supported_funcs & IPA_SBP_QUERY_BRIDGE_PORTS))
1612 return -EOPNOTSUPP;
Julian Wiedmannd65626a2017-08-15 17:02:47 +02001613 iob = qeth_sbp_build_cmd(card, IPA_SBP_QUERY_BRIDGE_PORTS, 0);
Thomas Richter1aec42b2015-01-21 13:39:10 +01001614 if (!iob)
1615 return -ENOMEM;
Julian Wiedmann1709ff82019-02-12 18:33:24 +01001616
1617 return qeth_send_ipa_cmd(card, iob, qeth_bridgeport_query_ports_cb,
1618 &cbctl);
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001619}
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001620
1621static int qeth_bridgeport_set_cb(struct qeth_card *card,
1622 struct qeth_reply *reply, unsigned long data)
1623{
1624 struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *)data;
Julian Wiedmann1709ff82019-02-12 18:33:24 +01001625
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001626 QETH_CARD_TEXT(card, 2, "brsetrcb");
Julian Wiedmann1709ff82019-02-12 18:33:24 +01001627 return qeth_bridgeport_makerc(card, cmd);
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001628}
1629
1630/**
1631 * qeth_bridgeport_setrole() - Assign primary role to the port.
1632 * @card: qeth_card structure pointer.
1633 * @role: Role to assign.
1634 *
1635 * Returns negative errno-compatible error indication or 0 on success.
1636 */
1637int qeth_bridgeport_setrole(struct qeth_card *card, enum qeth_sbp_roles role)
1638{
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001639 int cmdlength;
1640 struct qeth_cmd_buffer *iob;
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001641 enum qeth_ipa_sbp_cmd setcmd;
1642
1643 QETH_CARD_TEXT(card, 2, "brsetrol");
1644 switch (role) {
1645 case QETH_SBP_ROLE_NONE:
1646 setcmd = IPA_SBP_RESET_BRIDGE_PORT_ROLE;
Julian Wiedmannd65626a2017-08-15 17:02:47 +02001647 cmdlength = sizeof(struct qeth_sbp_reset_role);
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001648 break;
1649 case QETH_SBP_ROLE_PRIMARY:
1650 setcmd = IPA_SBP_SET_PRIMARY_BRIDGE_PORT;
Julian Wiedmannd65626a2017-08-15 17:02:47 +02001651 cmdlength = sizeof(struct qeth_sbp_set_primary);
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001652 break;
1653 case QETH_SBP_ROLE_SECONDARY:
1654 setcmd = IPA_SBP_SET_SECONDARY_BRIDGE_PORT;
Julian Wiedmannd65626a2017-08-15 17:02:47 +02001655 cmdlength = sizeof(struct qeth_sbp_set_secondary);
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001656 break;
1657 default:
1658 return -EINVAL;
1659 }
1660 if (!(card->options.sbp.supported_funcs & setcmd))
1661 return -EOPNOTSUPP;
Julian Wiedmannd65626a2017-08-15 17:02:47 +02001662 iob = qeth_sbp_build_cmd(card, setcmd, cmdlength);
Thomas Richter1aec42b2015-01-21 13:39:10 +01001663 if (!iob)
1664 return -ENOMEM;
Julian Wiedmann1709ff82019-02-12 18:33:24 +01001665
1666 return qeth_send_ipa_cmd(card, iob, qeth_bridgeport_set_cb, NULL);
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001667}
1668
Eugene Crosser9f48b9d2014-01-14 15:54:13 +01001669/**
1670 * qeth_anset_makerc() - derive "traditional" error from hardware codes.
1671 * @card: qeth_card structure pointer, for debug messages.
1672 *
1673 * Returns negative errno-compatible error indication or 0 on success.
1674 */
1675static int qeth_anset_makerc(struct qeth_card *card, int pnso_rc, u16 response)
1676{
1677 int rc;
1678
1679 if (pnso_rc == 0)
1680 switch (response) {
1681 case 0x0001:
1682 rc = 0;
1683 break;
1684 case 0x0004:
1685 case 0x0100:
1686 case 0x0106:
Eugene Crosserffb95252015-05-18 14:27:58 +02001687 rc = -EOPNOTSUPP;
Eugene Crosser9f48b9d2014-01-14 15:54:13 +01001688 dev_err(&card->gdev->dev,
1689 "Setting address notification failed\n");
1690 break;
1691 case 0x0107:
1692 rc = -EAGAIN;
1693 break;
1694 default:
1695 rc = -EIO;
1696 }
1697 else
1698 rc = -EIO;
1699
1700 if (rc) {
1701 QETH_CARD_TEXT_(card, 2, "SBPp%04x", pnso_rc);
1702 QETH_CARD_TEXT_(card, 2, "SBPr%04x", response);
1703 }
1704 return rc;
1705}
1706
1707static void qeth_bridgeport_an_set_cb(void *priv,
1708 enum qdio_brinfo_entry_type type, void *entry)
1709{
1710 struct qeth_card *card = (struct qeth_card *)priv;
1711 struct qdio_brinfo_entry_l2 *l2entry;
1712 u8 code;
1713
1714 if (type != l2_addr_lnid) {
1715 WARN_ON_ONCE(1);
1716 return;
1717 }
1718
1719 l2entry = (struct qdio_brinfo_entry_l2 *)entry;
1720 code = IPA_ADDR_CHANGE_CODE_MACADDR;
1721 if (l2entry->addr_lnid.lnid)
1722 code |= IPA_ADDR_CHANGE_CODE_VLANID;
1723 qeth_bridge_emit_host_event(card, anev_reg_unreg, code,
1724 (struct net_if_token *)&l2entry->nit,
1725 (struct mac_addr_lnid *)&l2entry->addr_lnid);
1726}
1727
1728/**
1729 * qeth_bridgeport_an_set() - Enable or disable bridgeport address notification
1730 * @card: qeth_card structure pointer.
1731 * @enable: 0 - disable, non-zero - enable notifications
1732 *
1733 * Returns negative errno-compatible error indication or 0 on success.
1734 *
1735 * On enable, emits a series of address notifications udev events for all
1736 * currently registered hosts.
1737 */
1738int qeth_bridgeport_an_set(struct qeth_card *card, int enable)
1739{
1740 int rc;
1741 u16 response;
1742 struct ccw_device *ddev;
1743 struct subchannel_id schid;
1744
1745 if (!card)
1746 return -EINVAL;
1747 if (!card->options.sbp.supported_funcs)
1748 return -EOPNOTSUPP;
1749 ddev = CARD_DDEV(card);
1750 ccw_device_get_schid(ddev, &schid);
1751
1752 if (enable) {
1753 qeth_bridge_emit_host_event(card, anev_reset, 0, NULL, NULL);
1754 rc = qdio_pnso_brinfo(schid, 1, &response,
1755 qeth_bridgeport_an_set_cb, card);
1756 } else
1757 rc = qdio_pnso_brinfo(schid, 0, &response, NULL, NULL);
1758 return qeth_anset_makerc(card, rc, response);
1759}
Eugene Crosser9f48b9d2014-01-14 15:54:13 +01001760
Hans Wippelcaa1f0b2017-09-18 21:18:15 +02001761static bool qeth_bridgeport_is_in_use(struct qeth_card *card)
1762{
1763 return (card->options.sbp.role || card->options.sbp.reflect_promisc ||
1764 card->options.sbp.hostnotification);
1765}
1766
Hans Wippela45b3fa2017-09-18 21:18:14 +02001767/* VNIC Characteristics support */
1768
1769/* handle VNICC IPA command return codes; convert to error codes */
Julian Wiedmann742d4d42019-02-12 18:33:25 +01001770static int qeth_l2_vnicc_makerc(struct qeth_card *card, u16 ipa_rc)
Hans Wippela45b3fa2017-09-18 21:18:14 +02001771{
1772 int rc;
1773
1774 switch (ipa_rc) {
1775 case IPA_RC_SUCCESS:
1776 return ipa_rc;
1777 case IPA_RC_L2_UNSUPPORTED_CMD:
1778 case IPA_RC_NOTSUPP:
1779 rc = -EOPNOTSUPP;
1780 break;
1781 case IPA_RC_VNICC_OOSEQ:
1782 rc = -EALREADY;
1783 break;
1784 case IPA_RC_VNICC_VNICBP:
1785 rc = -EBUSY;
1786 break;
1787 case IPA_RC_L2_ADDR_TABLE_FULL:
1788 rc = -ENOSPC;
1789 break;
1790 case IPA_RC_L2_MAC_NOT_AUTH_BY_ADP:
1791 rc = -EACCES;
1792 break;
1793 default:
1794 rc = -EIO;
1795 }
1796
1797 QETH_CARD_TEXT_(card, 2, "err%04x", ipa_rc);
1798 return rc;
1799}
1800
1801/* generic VNICC request call back control */
1802struct _qeth_l2_vnicc_request_cbctl {
1803 u32 sub_cmd;
Hans Wippelcaa1f0b2017-09-18 21:18:15 +02001804 struct {
1805 u32 vnic_char;
Hans Wippel349d13d2017-09-18 21:18:16 +02001806 u32 timeout;
Hans Wippelcaa1f0b2017-09-18 21:18:15 +02001807 } param;
1808 struct {
Hans Wippel349d13d2017-09-18 21:18:16 +02001809 union{
1810 u32 *sup_cmds;
1811 u32 *timeout;
1812 };
Hans Wippelcaa1f0b2017-09-18 21:18:15 +02001813 } result;
Hans Wippela45b3fa2017-09-18 21:18:14 +02001814};
1815
1816/* generic VNICC request call back */
1817static int qeth_l2_vnicc_request_cb(struct qeth_card *card,
1818 struct qeth_reply *reply,
1819 unsigned long data)
1820{
Hans Wippelcaa1f0b2017-09-18 21:18:15 +02001821 struct _qeth_l2_vnicc_request_cbctl *cbctl =
1822 (struct _qeth_l2_vnicc_request_cbctl *) reply->param;
Hans Wippela45b3fa2017-09-18 21:18:14 +02001823 struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *) data;
1824 struct qeth_ipacmd_vnicc *rep = &cmd->data.vnicc;
1825
1826 QETH_CARD_TEXT(card, 2, "vniccrcb");
1827 if (cmd->hdr.return_code)
Julian Wiedmann742d4d42019-02-12 18:33:25 +01001828 return qeth_l2_vnicc_makerc(card, cmd->hdr.return_code);
Hans Wippela45b3fa2017-09-18 21:18:14 +02001829 /* return results to caller */
1830 card->options.vnicc.sup_chars = rep->hdr.sup;
1831 card->options.vnicc.cur_chars = rep->hdr.cur;
1832
Hans Wippelcaa1f0b2017-09-18 21:18:15 +02001833 if (cbctl->sub_cmd == IPA_VNICC_QUERY_CMDS)
1834 *cbctl->result.sup_cmds = rep->query_cmds.sup_cmds;
1835
Hans Wippel349d13d2017-09-18 21:18:16 +02001836 if (cbctl->sub_cmd == IPA_VNICC_GET_TIMEOUT)
1837 *cbctl->result.timeout = rep->getset_timeout.timeout;
1838
Hans Wippela45b3fa2017-09-18 21:18:14 +02001839 return 0;
1840}
1841
1842/* generic VNICC request */
1843static int qeth_l2_vnicc_request(struct qeth_card *card,
1844 struct _qeth_l2_vnicc_request_cbctl *cbctl)
1845{
1846 struct qeth_ipacmd_vnicc *req;
1847 struct qeth_cmd_buffer *iob;
1848 struct qeth_ipa_cmd *cmd;
Hans Wippela45b3fa2017-09-18 21:18:14 +02001849
1850 QETH_CARD_TEXT(card, 2, "vniccreq");
1851
1852 /* get new buffer for request */
1853 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_VNICC, 0);
1854 if (!iob)
1855 return -ENOMEM;
1856
1857 /* create header for request */
Julian Wiedmannff5caa72018-03-09 18:12:52 +01001858 cmd = __ipa_cmd(iob);
Hans Wippela45b3fa2017-09-18 21:18:14 +02001859 req = &cmd->data.vnicc;
1860
1861 /* create sub command header for request */
1862 req->sub_hdr.data_length = sizeof(req->sub_hdr);
1863 req->sub_hdr.sub_command = cbctl->sub_cmd;
1864
1865 /* create sub command specific request fields */
1866 switch (cbctl->sub_cmd) {
1867 case IPA_VNICC_QUERY_CHARS:
1868 break;
Hans Wippelcaa1f0b2017-09-18 21:18:15 +02001869 case IPA_VNICC_QUERY_CMDS:
1870 req->sub_hdr.data_length += sizeof(req->query_cmds);
1871 req->query_cmds.vnic_char = cbctl->param.vnic_char;
1872 break;
1873 case IPA_VNICC_ENABLE:
1874 case IPA_VNICC_DISABLE:
1875 req->sub_hdr.data_length += sizeof(req->set_char);
1876 req->set_char.vnic_char = cbctl->param.vnic_char;
1877 break;
Hans Wippel349d13d2017-09-18 21:18:16 +02001878 case IPA_VNICC_SET_TIMEOUT:
1879 req->getset_timeout.timeout = cbctl->param.timeout;
1880 /* fallthrough */
1881 case IPA_VNICC_GET_TIMEOUT:
1882 req->sub_hdr.data_length += sizeof(req->getset_timeout);
1883 req->getset_timeout.vnic_char = cbctl->param.vnic_char;
1884 break;
Hans Wippela45b3fa2017-09-18 21:18:14 +02001885 default:
1886 qeth_release_buffer(iob->channel, iob);
1887 return -EOPNOTSUPP;
1888 }
1889
1890 /* send request */
Julian Wiedmann742d4d42019-02-12 18:33:25 +01001891 return qeth_send_ipa_cmd(card, iob, qeth_l2_vnicc_request_cb, cbctl);
Hans Wippela45b3fa2017-09-18 21:18:14 +02001892}
1893
1894/* VNICC query VNIC characteristics request */
1895static int qeth_l2_vnicc_query_chars(struct qeth_card *card)
1896{
1897 struct _qeth_l2_vnicc_request_cbctl cbctl;
1898
1899 /* prepare callback control */
1900 cbctl.sub_cmd = IPA_VNICC_QUERY_CHARS;
1901
1902 QETH_CARD_TEXT(card, 2, "vniccqch");
1903 return qeth_l2_vnicc_request(card, &cbctl);
1904}
1905
Hans Wippelcaa1f0b2017-09-18 21:18:15 +02001906/* VNICC query sub commands request */
1907static int qeth_l2_vnicc_query_cmds(struct qeth_card *card, u32 vnic_char,
1908 u32 *sup_cmds)
1909{
1910 struct _qeth_l2_vnicc_request_cbctl cbctl;
1911
1912 /* prepare callback control */
1913 cbctl.sub_cmd = IPA_VNICC_QUERY_CMDS;
1914 cbctl.param.vnic_char = vnic_char;
1915 cbctl.result.sup_cmds = sup_cmds;
1916
1917 QETH_CARD_TEXT(card, 2, "vniccqcm");
1918 return qeth_l2_vnicc_request(card, &cbctl);
1919}
1920
1921/* VNICC enable/disable characteristic request */
1922static int qeth_l2_vnicc_set_char(struct qeth_card *card, u32 vnic_char,
1923 u32 cmd)
1924{
1925 struct _qeth_l2_vnicc_request_cbctl cbctl;
1926
1927 /* prepare callback control */
1928 cbctl.sub_cmd = cmd;
1929 cbctl.param.vnic_char = vnic_char;
1930
1931 QETH_CARD_TEXT(card, 2, "vniccedc");
1932 return qeth_l2_vnicc_request(card, &cbctl);
1933}
1934
Hans Wippel349d13d2017-09-18 21:18:16 +02001935/* VNICC get/set timeout for characteristic request */
1936static int qeth_l2_vnicc_getset_timeout(struct qeth_card *card, u32 vnicc,
1937 u32 cmd, u32 *timeout)
1938{
1939 struct _qeth_l2_vnicc_request_cbctl cbctl;
1940
1941 /* prepare callback control */
1942 cbctl.sub_cmd = cmd;
1943 cbctl.param.vnic_char = vnicc;
1944 if (cmd == IPA_VNICC_SET_TIMEOUT)
1945 cbctl.param.timeout = *timeout;
1946 if (cmd == IPA_VNICC_GET_TIMEOUT)
1947 cbctl.result.timeout = timeout;
1948
1949 QETH_CARD_TEXT(card, 2, "vniccgst");
1950 return qeth_l2_vnicc_request(card, &cbctl);
1951}
1952
Hans Wippelcaa1f0b2017-09-18 21:18:15 +02001953/* set current VNICC flag state; called from sysfs store function */
1954int qeth_l2_vnicc_set_state(struct qeth_card *card, u32 vnicc, bool state)
1955{
1956 int rc = 0;
1957 u32 cmd;
1958
1959 QETH_CARD_TEXT(card, 2, "vniccsch");
1960
1961 /* do not change anything if BridgePort is enabled */
1962 if (qeth_bridgeport_is_in_use(card))
1963 return -EBUSY;
1964
1965 /* check if characteristic and enable/disable are supported */
1966 if (!(card->options.vnicc.sup_chars & vnicc) ||
1967 !(card->options.vnicc.set_char_sup & vnicc))
1968 return -EOPNOTSUPP;
1969
1970 /* set enable/disable command and store wanted characteristic */
1971 if (state) {
1972 cmd = IPA_VNICC_ENABLE;
1973 card->options.vnicc.wanted_chars |= vnicc;
1974 } else {
1975 cmd = IPA_VNICC_DISABLE;
1976 card->options.vnicc.wanted_chars &= ~vnicc;
1977 }
1978
1979 /* do we need to do anything? */
1980 if (card->options.vnicc.cur_chars == card->options.vnicc.wanted_chars)
1981 return rc;
1982
1983 /* if card is not ready, simply stop here */
1984 if (!qeth_card_hw_is_reachable(card)) {
1985 if (state)
1986 card->options.vnicc.cur_chars |= vnicc;
1987 else
1988 card->options.vnicc.cur_chars &= ~vnicc;
1989 return rc;
1990 }
1991
1992 rc = qeth_l2_vnicc_set_char(card, vnicc, cmd);
1993 if (rc)
1994 card->options.vnicc.wanted_chars =
1995 card->options.vnicc.cur_chars;
Hans Wippel349d13d2017-09-18 21:18:16 +02001996 else {
1997 /* successful online VNICC change; handle special cases */
1998 if (state && vnicc == QETH_VNICC_RX_BCAST)
1999 card->options.vnicc.rx_bcast_enabled = true;
2000 if (!state && vnicc == QETH_VNICC_LEARNING)
2001 qeth_l2_vnicc_recover_timeout(card, vnicc,
2002 &card->options.vnicc.learning_timeout);
2003 }
Hans Wippelcaa1f0b2017-09-18 21:18:15 +02002004
2005 return rc;
2006}
2007
2008/* get current VNICC flag state; called from sysfs show function */
2009int qeth_l2_vnicc_get_state(struct qeth_card *card, u32 vnicc, bool *state)
2010{
2011 int rc = 0;
2012
2013 QETH_CARD_TEXT(card, 2, "vniccgch");
2014
2015 /* do not get anything if BridgePort is enabled */
2016 if (qeth_bridgeport_is_in_use(card))
2017 return -EBUSY;
2018
2019 /* check if characteristic is supported */
2020 if (!(card->options.vnicc.sup_chars & vnicc))
2021 return -EOPNOTSUPP;
2022
2023 /* if card is ready, query current VNICC state */
2024 if (qeth_card_hw_is_reachable(card))
2025 rc = qeth_l2_vnicc_query_chars(card);
2026
2027 *state = (card->options.vnicc.cur_chars & vnicc) ? true : false;
2028 return rc;
2029}
2030
Hans Wippel349d13d2017-09-18 21:18:16 +02002031/* set VNICC timeout; called from sysfs store function. Currently, only learning
2032 * supports timeout
2033 */
2034int qeth_l2_vnicc_set_timeout(struct qeth_card *card, u32 timeout)
2035{
2036 int rc = 0;
2037
2038 QETH_CARD_TEXT(card, 2, "vniccsto");
2039
2040 /* do not change anything if BridgePort is enabled */
2041 if (qeth_bridgeport_is_in_use(card))
2042 return -EBUSY;
2043
2044 /* check if characteristic and set_timeout are supported */
2045 if (!(card->options.vnicc.sup_chars & QETH_VNICC_LEARNING) ||
2046 !(card->options.vnicc.getset_timeout_sup & QETH_VNICC_LEARNING))
2047 return -EOPNOTSUPP;
2048
2049 /* do we need to do anything? */
2050 if (card->options.vnicc.learning_timeout == timeout)
2051 return rc;
2052
2053 /* if card is not ready, simply store the value internally and return */
2054 if (!qeth_card_hw_is_reachable(card)) {
2055 card->options.vnicc.learning_timeout = timeout;
2056 return rc;
2057 }
2058
2059 /* send timeout value to card; if successful, store value internally */
2060 rc = qeth_l2_vnicc_getset_timeout(card, QETH_VNICC_LEARNING,
2061 IPA_VNICC_SET_TIMEOUT, &timeout);
2062 if (!rc)
2063 card->options.vnicc.learning_timeout = timeout;
2064
2065 return rc;
2066}
2067
2068/* get current VNICC timeout; called from sysfs show function. Currently, only
2069 * learning supports timeout
2070 */
2071int qeth_l2_vnicc_get_timeout(struct qeth_card *card, u32 *timeout)
2072{
2073 int rc = 0;
2074
2075 QETH_CARD_TEXT(card, 2, "vniccgto");
2076
2077 /* do not get anything if BridgePort is enabled */
2078 if (qeth_bridgeport_is_in_use(card))
2079 return -EBUSY;
2080
2081 /* check if characteristic and get_timeout are supported */
2082 if (!(card->options.vnicc.sup_chars & QETH_VNICC_LEARNING) ||
2083 !(card->options.vnicc.getset_timeout_sup & QETH_VNICC_LEARNING))
2084 return -EOPNOTSUPP;
2085 /* if card is ready, get timeout. Otherwise, just return stored value */
2086 *timeout = card->options.vnicc.learning_timeout;
2087 if (qeth_card_hw_is_reachable(card))
2088 rc = qeth_l2_vnicc_getset_timeout(card, QETH_VNICC_LEARNING,
2089 IPA_VNICC_GET_TIMEOUT,
2090 timeout);
2091
2092 return rc;
2093}
2094
Hans Wippelcaa1f0b2017-09-18 21:18:15 +02002095/* check if VNICC is currently enabled */
2096bool qeth_l2_vnicc_is_in_use(struct qeth_card *card)
2097{
2098 /* if everything is turned off, VNICC is not active */
2099 if (!card->options.vnicc.cur_chars)
2100 return false;
2101 /* default values are only OK if rx_bcast was not enabled by user
2102 * or the card is offline.
2103 */
2104 if (card->options.vnicc.cur_chars == QETH_VNICC_DEFAULT) {
2105 if (!card->options.vnicc.rx_bcast_enabled ||
2106 !qeth_card_hw_is_reachable(card))
2107 return false;
2108 }
2109 return true;
2110}
2111
Hans Wippel349d13d2017-09-18 21:18:16 +02002112/* recover user timeout setting */
2113static bool qeth_l2_vnicc_recover_timeout(struct qeth_card *card, u32 vnicc,
2114 u32 *timeout)
2115{
2116 if (card->options.vnicc.sup_chars & vnicc &&
2117 card->options.vnicc.getset_timeout_sup & vnicc &&
2118 !qeth_l2_vnicc_getset_timeout(card, vnicc, IPA_VNICC_SET_TIMEOUT,
2119 timeout))
2120 return false;
2121 *timeout = QETH_VNICC_DEFAULT_TIMEOUT;
2122 return true;
2123}
2124
Hans Wippelcaa1f0b2017-09-18 21:18:15 +02002125/* recover user characteristic setting */
2126static bool qeth_l2_vnicc_recover_char(struct qeth_card *card, u32 vnicc,
2127 bool enable)
2128{
2129 u32 cmd = enable ? IPA_VNICC_ENABLE : IPA_VNICC_DISABLE;
2130
2131 if (card->options.vnicc.sup_chars & vnicc &&
2132 card->options.vnicc.set_char_sup & vnicc &&
2133 !qeth_l2_vnicc_set_char(card, vnicc, cmd))
2134 return false;
2135 card->options.vnicc.wanted_chars &= ~vnicc;
2136 card->options.vnicc.wanted_chars |= QETH_VNICC_DEFAULT & vnicc;
2137 return true;
2138}
2139
Hans Wippela45b3fa2017-09-18 21:18:14 +02002140/* (re-)initialize VNICC */
2141static void qeth_l2_vnicc_init(struct qeth_card *card)
2142{
Hans Wippel349d13d2017-09-18 21:18:16 +02002143 u32 *timeout = &card->options.vnicc.learning_timeout;
Hans Wippelcaa1f0b2017-09-18 21:18:15 +02002144 unsigned int chars_len, i;
2145 unsigned long chars_tmp;
2146 u32 sup_cmds, vnicc;
2147 bool enable, error;
2148
Hans Wippela45b3fa2017-09-18 21:18:14 +02002149 QETH_CARD_TEXT(card, 2, "vniccini");
Hans Wippelcaa1f0b2017-09-18 21:18:15 +02002150 /* reset rx_bcast */
2151 card->options.vnicc.rx_bcast_enabled = 0;
Hans Wippela45b3fa2017-09-18 21:18:14 +02002152 /* initial query and storage of VNIC characteristics */
2153 if (qeth_l2_vnicc_query_chars(card)) {
Hans Wippel349d13d2017-09-18 21:18:16 +02002154 if (card->options.vnicc.wanted_chars != QETH_VNICC_DEFAULT ||
2155 *timeout != QETH_VNICC_DEFAULT_TIMEOUT)
Hans Wippelcaa1f0b2017-09-18 21:18:15 +02002156 dev_err(&card->gdev->dev, "Configuring the VNIC characteristics failed\n");
2157 /* fail quietly if user didn't change the default config */
Hans Wippela45b3fa2017-09-18 21:18:14 +02002158 card->options.vnicc.sup_chars = 0;
2159 card->options.vnicc.cur_chars = 0;
Hans Wippelcaa1f0b2017-09-18 21:18:15 +02002160 card->options.vnicc.wanted_chars = QETH_VNICC_DEFAULT;
2161 return;
Hans Wippela45b3fa2017-09-18 21:18:14 +02002162 }
Hans Wippelcaa1f0b2017-09-18 21:18:15 +02002163 /* get supported commands for each supported characteristic */
2164 chars_tmp = card->options.vnicc.sup_chars;
2165 chars_len = sizeof(card->options.vnicc.sup_chars) * BITS_PER_BYTE;
2166 for_each_set_bit(i, &chars_tmp, chars_len) {
2167 vnicc = BIT(i);
2168 qeth_l2_vnicc_query_cmds(card, vnicc, &sup_cmds);
Hans Wippel349d13d2017-09-18 21:18:16 +02002169 if (!(sup_cmds & IPA_VNICC_SET_TIMEOUT) ||
2170 !(sup_cmds & IPA_VNICC_GET_TIMEOUT))
2171 card->options.vnicc.getset_timeout_sup &= ~vnicc;
Hans Wippelcaa1f0b2017-09-18 21:18:15 +02002172 if (!(sup_cmds & IPA_VNICC_ENABLE) ||
2173 !(sup_cmds & IPA_VNICC_DISABLE))
2174 card->options.vnicc.set_char_sup &= ~vnicc;
2175 }
2176 /* enforce assumed default values and recover settings, if changed */
Hans Wippel349d13d2017-09-18 21:18:16 +02002177 error = qeth_l2_vnicc_recover_timeout(card, QETH_VNICC_LEARNING,
2178 timeout);
Hans Wippelcaa1f0b2017-09-18 21:18:15 +02002179 chars_tmp = card->options.vnicc.wanted_chars ^ QETH_VNICC_DEFAULT;
2180 chars_tmp |= QETH_VNICC_BRIDGE_INVISIBLE;
2181 chars_len = sizeof(card->options.vnicc.wanted_chars) * BITS_PER_BYTE;
2182 for_each_set_bit(i, &chars_tmp, chars_len) {
2183 vnicc = BIT(i);
2184 enable = card->options.vnicc.wanted_chars & vnicc;
2185 error |= qeth_l2_vnicc_recover_char(card, vnicc, enable);
2186 }
2187 if (error)
2188 dev_err(&card->gdev->dev, "Configuring the VNIC characteristics failed\n");
2189}
2190
2191/* configure default values of VNIC characteristics */
2192static void qeth_l2_vnicc_set_defaults(struct qeth_card *card)
2193{
2194 /* characteristics values */
2195 card->options.vnicc.sup_chars = QETH_VNICC_ALL;
2196 card->options.vnicc.cur_chars = QETH_VNICC_DEFAULT;
Hans Wippel349d13d2017-09-18 21:18:16 +02002197 card->options.vnicc.learning_timeout = QETH_VNICC_DEFAULT_TIMEOUT;
Hans Wippelcaa1f0b2017-09-18 21:18:15 +02002198 /* supported commands */
2199 card->options.vnicc.set_char_sup = QETH_VNICC_ALL;
Hans Wippel349d13d2017-09-18 21:18:16 +02002200 card->options.vnicc.getset_timeout_sup = QETH_VNICC_LEARNING;
Hans Wippelcaa1f0b2017-09-18 21:18:15 +02002201 /* settings wanted by users */
2202 card->options.vnicc.wanted_chars = QETH_VNICC_DEFAULT;
Hans Wippela45b3fa2017-09-18 21:18:14 +02002203}
2204
Frank Blaschka4a71df52008-02-15 09:19:42 +01002205module_init(qeth_l2_init);
2206module_exit(qeth_l2_exit);
2207MODULE_AUTHOR("Frank Blaschka <frank.blaschka@de.ibm.com>");
2208MODULE_DESCRIPTION("qeth layer 2 discipline");
2209MODULE_LICENSE("GPL");