blob: 2d3bca3c0141fabc2abca2c39f44f515356a37ad [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>
Alexandra Wintera0138f52020-04-16 15:08:41 +020023#include <asm/chsc.h>
Julian Wiedmannec61bd22017-06-20 16:00:34 +020024#include <asm/setup.h>
Frank Blaschka4a71df52008-02-15 09:19:42 +010025#include "qeth_core.h"
Eugene Crosserb4d72c02014-01-14 15:54:11 +010026#include "qeth_l2.h"
Frank Blaschka4a71df52008-02-15 09:19:42 +010027
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);
Alexandra Wintera0138f52020-04-16 15:08:41 +020031static void qeth_addr_change_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:
Julian Wiedmannbdb0cc12020-03-25 10:35:05 +010056 rc = -EADDRINUSE;
Eugene Crosserefbbc1d2015-01-21 13:39:09 +010057 break;
58 case IPA_RC_L2_MAC_NOT_AUTH_BY_HYP:
59 case IPA_RC_L2_MAC_NOT_AUTH_BY_ADP:
Julian Wiedmannbdb0cc12020-03-25 10:35:05 +010060 rc = -EADDRNOTAVAIL;
Eugene Crosserefbbc1d2015-01-21 13:39:09 +010061 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");
Julian Wiedmanna59d1212019-06-27 17:01:22 +020088 iob = qeth_ipa_alloc_cmd(card, ipacmd, QETH_PROT_IPV4,
89 IPA_DATA_SIZEOF(setdelmac));
Julian Wiedmannac988d72017-01-12 15:48:41 +010090 if (!iob)
91 return -ENOMEM;
Julian Wiedmannff5caa72018-03-09 18:12:52 +010092 cmd = __ipa_cmd(iob);
Julian Wiedmann99f0b852017-12-20 20:11:01 +010093 cmd->data.setdelmac.mac_length = ETH_ALEN;
94 ether_addr_copy(cmd->data.setdelmac.mac, mac);
Julian Wiedmann742d4d42019-02-12 18:33:25 +010095 return qeth_send_ipa_cmd(card, iob, qeth_l2_send_setdelmac_cb, NULL);
Julian Wiedmannac988d72017-01-12 15:48:41 +010096}
97
98static int qeth_l2_send_setmac(struct qeth_card *card, __u8 *mac)
99{
100 int rc;
101
102 QETH_CARD_TEXT(card, 2, "L2Setmac");
103 rc = qeth_l2_send_setdelmac(card, mac, IPA_CMD_SETVMAC);
104 if (rc == 0) {
Julian Wiedmannac988d72017-01-12 15:48:41 +0100105 dev_info(&card->gdev->dev,
Julian Wiedmann654e3d42019-01-25 15:44:19 +0100106 "MAC address %pM successfully registered\n", mac);
Julian Wiedmannac988d72017-01-12 15:48:41 +0100107 } else {
Julian Wiedmannac988d72017-01-12 15:48:41 +0100108 switch (rc) {
Julian Wiedmannbdb0cc12020-03-25 10:35:05 +0100109 case -EADDRINUSE:
Julian Wiedmannac988d72017-01-12 15:48:41 +0100110 dev_warn(&card->gdev->dev,
111 "MAC address %pM already exists\n", mac);
112 break;
Julian Wiedmannbdb0cc12020-03-25 10:35:05 +0100113 case -EADDRNOTAVAIL:
Julian Wiedmannac988d72017-01-12 15:48:41 +0100114 dev_warn(&card->gdev->dev,
115 "MAC address %pM is not authorized\n", mac);
116 break;
117 }
118 }
119 return rc;
120}
121
Julian Wiedmann8174aa82017-12-20 20:11:00 +0100122static int qeth_l2_write_mac(struct qeth_card *card, u8 *mac)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100123{
Vasily Gorbik9d0a58f2018-06-29 19:45:52 +0200124 enum qeth_ipa_cmds cmd = is_multicast_ether_addr(mac) ?
Julian Wiedmann8174aa82017-12-20 20:11:00 +0100125 IPA_CMD_SETGMAC : IPA_CMD_SETVMAC;
Eugene Crosserefbbc1d2015-01-21 13:39:09 +0100126 int rc;
127
Julian Wiedmann8174aa82017-12-20 20:11:00 +0100128 QETH_CARD_TEXT(card, 2, "L2Wmac");
129 rc = qeth_l2_send_setdelmac(card, mac, cmd);
Julian Wiedmannbdb0cc12020-03-25 10:35:05 +0100130 if (rc == -EADDRINUSE)
Julian Wiedmanne19e5be2018-11-02 19:04:08 +0100131 QETH_DBF_MESSAGE(2, "MAC already registered on device %x\n",
132 CARD_DEVID(card));
Eugene Crosserefbbc1d2015-01-21 13:39:09 +0100133 else if (rc)
Julian Wiedmanne19e5be2018-11-02 19:04:08 +0100134 QETH_DBF_MESSAGE(2, "Failed to register MAC on device %x: %d\n",
135 CARD_DEVID(card), rc);
Eugene Crosserefbbc1d2015-01-21 13:39:09 +0100136 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100137}
138
Julian Wiedmann8174aa82017-12-20 20:11:00 +0100139static int qeth_l2_remove_mac(struct qeth_card *card, u8 *mac)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100140{
Vasily Gorbik9d0a58f2018-06-29 19:45:52 +0200141 enum qeth_ipa_cmds cmd = is_multicast_ether_addr(mac) ?
Julian Wiedmann8174aa82017-12-20 20:11:00 +0100142 IPA_CMD_DELGMAC : IPA_CMD_DELVMAC;
Eugene Crosserefbbc1d2015-01-21 13:39:09 +0100143 int rc;
144
Julian Wiedmann8174aa82017-12-20 20:11:00 +0100145 QETH_CARD_TEXT(card, 2, "L2Rmac");
146 rc = qeth_l2_send_setdelmac(card, mac, cmd);
Eugene Crosserefbbc1d2015-01-21 13:39:09 +0100147 if (rc)
Julian Wiedmanne19e5be2018-11-02 19:04:08 +0100148 QETH_DBF_MESSAGE(2, "Failed to delete MAC on device %u: %d\n",
149 CARD_DEVID(card), rc);
Eugene Crosserefbbc1d2015-01-21 13:39:09 +0100150 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100151}
152
Julian Wiedmannd0c74822019-03-28 16:39:19 +0100153static void qeth_l2_drain_rx_mode_cache(struct qeth_card *card)
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200154{
155 struct qeth_mac *mac;
156 struct hlist_node *tmp;
157 int i;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100158
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 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100163}
164
Julian Wiedmannb0abc4f2019-02-15 19:22:29 +0100165static void qeth_l2_fill_header(struct qeth_qdio_out_q *queue,
166 struct qeth_hdr *hdr, struct sk_buff *skb,
Julian Wiedmanneca1d5c2019-06-27 17:01:33 +0200167 int ipv, unsigned int data_len)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100168{
Julian Wiedmanneca1d5c2019-06-27 17:01:33 +0200169 int cast_type = qeth_get_ether_cast_type(skb);
Julian Wiedmann0aef8392018-10-12 17:27:15 +0200170 struct vlan_ethhdr *veth = vlan_eth_hdr(skb);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100171
Julian Wiedmannae79fe02017-08-18 10:19:05 +0200172 hdr->hdr.l2.pkt_length = data_len;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100173
Julian Wiedmann0aef8392018-10-12 17:27:15 +0200174 if (skb_is_gso(skb)) {
175 hdr->hdr.l2.id = QETH_HEADER_TYPE_L2_TSO;
176 } else {
177 hdr->hdr.l2.id = QETH_HEADER_TYPE_LAYER2;
Julian Wiedmanneeac0e22019-08-23 11:48:49 +0200178 if (skb->ip_summed == CHECKSUM_PARTIAL)
Julian Wiedmann0aef8392018-10-12 17:27:15 +0200179 qeth_tx_csum(skb, &hdr->hdr.l2.flags[1], ipv);
Julian Wiedmannfc696602018-09-17 17:35:55 +0200180 }
181
Frank Blaschka4a71df52008-02-15 09:19:42 +0100182 /* set byte byte 3 to casting flags */
183 if (cast_type == RTN_MULTICAST)
184 hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_MULTICAST;
185 else if (cast_type == RTN_BROADCAST)
186 hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_BROADCAST;
187 else
Klaus-Dieter Wackerce73e102009-08-26 02:01:08 +0000188 hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_UNICAST;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100189
Frank Blaschka4a71df52008-02-15 09:19:42 +0100190 /* VSWITCH relies on the VLAN
191 * information to be present in
192 * the QDIO header */
193 if (veth->h_vlan_proto == __constant_htons(ETH_P_8021Q)) {
194 hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_VLAN;
195 hdr->hdr.l2.vlan_id = ntohs(veth->h_vlan_TCI);
196 }
197}
198
Julian Wiedmann742d4d42019-02-12 18:33:25 +0100199static int qeth_l2_setdelvlan_makerc(struct qeth_card *card, u16 retcode)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100200{
Julian Wiedmann2aa48672017-09-18 21:18:20 +0200201 if (retcode)
202 QETH_CARD_TEXT_(card, 2, "err%04x", retcode);
203
204 switch (retcode) {
205 case IPA_RC_SUCCESS:
206 return 0;
207 case IPA_RC_L2_INVALID_VLAN_ID:
208 return -EINVAL;
209 case IPA_RC_L2_DUP_VLAN_ID:
210 return -EEXIST;
211 case IPA_RC_L2_VLAN_ID_NOT_FOUND:
212 return -ENOENT;
213 case IPA_RC_L2_VLAN_ID_NOT_ALLOWED:
214 return -EPERM;
Julian Wiedmann2aa48672017-09-18 21:18:20 +0200215 default:
216 return -EIO;
217 }
218}
219
220static int qeth_l2_send_setdelvlan_cb(struct qeth_card *card,
221 struct qeth_reply *reply,
222 unsigned long data)
223{
224 struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *) data;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100225
Carsten Otte847a50f2010-06-21 22:57:05 +0000226 QETH_CARD_TEXT(card, 2, "L2sdvcb");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100227 if (cmd->hdr.return_code) {
Julian Wiedmanne19e5be2018-11-02 19:04:08 +0100228 QETH_DBF_MESSAGE(2, "Error in processing VLAN %u on device %x: %#x.\n",
Julian Wiedmann2aa48672017-09-18 21:18:20 +0200229 cmd->data.setdelvlan.vlan_id,
Julian Wiedmanne19e5be2018-11-02 19:04:08 +0100230 CARD_DEVID(card), cmd->hdr.return_code);
Carsten Otte847a50f2010-06-21 22:57:05 +0000231 QETH_CARD_TEXT_(card, 2, "L2VL%4x", cmd->hdr.command);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100232 }
Julian Wiedmann742d4d42019-02-12 18:33:25 +0100233 return qeth_l2_setdelvlan_makerc(card, cmd->hdr.return_code);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100234}
235
236static int qeth_l2_send_setdelvlan(struct qeth_card *card, __u16 i,
Julian Wiedmann2aa48672017-09-18 21:18:20 +0200237 enum qeth_ipa_cmds ipacmd)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100238{
239 struct qeth_ipa_cmd *cmd;
240 struct qeth_cmd_buffer *iob;
241
Carsten Otte847a50f2010-06-21 22:57:05 +0000242 QETH_CARD_TEXT_(card, 4, "L2sdv%x", ipacmd);
Julian Wiedmanna59d1212019-06-27 17:01:22 +0200243 iob = qeth_ipa_alloc_cmd(card, ipacmd, QETH_PROT_IPV4,
244 IPA_DATA_SIZEOF(setdelvlan));
Thomas Richter1aec42b2015-01-21 13:39:10 +0100245 if (!iob)
246 return -ENOMEM;
Julian Wiedmannff5caa72018-03-09 18:12:52 +0100247 cmd = __ipa_cmd(iob);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100248 cmd->data.setdelvlan.vlan_id = i;
Julian Wiedmann742d4d42019-02-12 18:33:25 +0100249 return qeth_send_ipa_cmd(card, iob, qeth_l2_send_setdelvlan_cb, NULL);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100250}
251
Patrick McHardy80d5c362013-04-19 02:04:28 +0000252static int qeth_l2_vlan_rx_add_vid(struct net_device *dev,
253 __be16 proto, u16 vid)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100254{
Heiko Carstens509e2562008-07-26 02:24:10 -0700255 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100256
Carsten Otte847a50f2010-06-21 22:57:05 +0000257 QETH_CARD_TEXT_(card, 4, "aid:%d", vid);
Ursula Braun10651db2010-10-01 02:51:13 +0000258 if (!vid)
Jiri Pirko8e586132011-12-08 19:52:37 -0500259 return 0;
Julian Wiedmanne6e771b2019-01-25 15:44:22 +0100260
Julian Wiedmann5fc692a2019-01-25 15:44:23 +0100261 return qeth_l2_send_setdelvlan(card, vid, IPA_CMD_SETVLAN);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100262}
263
Patrick McHardy80d5c362013-04-19 02:04:28 +0000264static int qeth_l2_vlan_rx_kill_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, "kid:%d", vid);
Julian Wiedmann5fc692a2019-01-25 15:44:23 +0100270 if (!vid)
271 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_DELVLAN);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100274}
275
Julian Wiedmannd4560152019-02-28 18:59:39 +0100276static void qeth_l2_stop_card(struct qeth_card *card)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100277{
Julian Wiedmann57a688aa2019-06-11 18:37:55 +0200278 QETH_CARD_TEXT(card, 2, "stopcard");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100279
280 qeth_set_allowed_threads(card, 0, 1);
Julian Wiedmann0f7aedbd2019-02-28 18:59:44 +0100281
Julian Wiedmannd0c74822019-03-28 16:39:19 +0100282 cancel_work_sync(&card->rx_mode_work);
283 qeth_l2_drain_rx_mode_cache(card);
284
Frank Blaschka4a71df52008-02-15 09:19:42 +0100285 if (card->state == CARD_STATE_SOFTSETUP) {
Frank Blaschka4a71df52008-02-15 09:19:42 +0100286 qeth_clear_ipacmd_list(card);
Julian Wiedmann41c47da2019-04-17 18:17:28 +0200287 qeth_drain_output_queues(card);
Julian Wiedmann0e635c22020-03-10 18:38:03 +0100288 cancel_delayed_work_sync(&card->buffer_reclaim_work);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100289 card->state = CARD_STATE_DOWN;
290 }
Julian Wiedmannc0a2e4d2019-02-04 17:40:09 +0100291
Julian Wiedmann8b5026b2019-12-23 15:03:21 +0100292 qeth_qdio_clear_card(card, 0);
Julian Wiedmannaa3ad3922020-01-25 16:53:00 +0100293 qeth_clear_working_pool_list(card);
Julian Wiedmannc0a2e4d2019-02-04 17:40:09 +0100294 flush_workqueue(card->event_wq);
Julian Wiedmann0d49c062020-05-06 10:09:41 +0200295 qeth_flush_local_addrs(card);
Julian Wiedmann0f399302019-12-18 16:32:27 +0100296 card->info.promisc_mode = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100297}
298
Frank Blaschka4a71df52008-02-15 09:19:42 +0100299static int qeth_l2_request_initial_mac(struct qeth_card *card)
300{
301 int rc = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100302
Julian Wiedmann57a688aa2019-06-11 18:37:55 +0200303 QETH_CARD_TEXT(card, 2, "l2reqmac");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100304
Julian Wiedmannec61bd22017-06-20 16:00:34 +0200305 if (MACHINE_IS_VM) {
306 rc = qeth_vm_request_mac(card);
307 if (!rc)
308 goto out;
Julian Wiedmanne19e5be2018-11-02 19:04:08 +0100309 QETH_DBF_MESSAGE(2, "z/VM MAC Service failed on device %x: %#x\n",
310 CARD_DEVID(card), rc);
Julian Wiedmann57a688aa2019-06-11 18:37:55 +0200311 QETH_CARD_TEXT_(card, 2, "err%04x", rc);
Julian Wiedmannec61bd22017-06-20 16:00:34 +0200312 /* fall back to alternative mechanism: */
313 }
314
Julian Wiedmannb144b992018-11-08 15:06:15 +0100315 if (!IS_OSN(card)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +0100316 rc = qeth_setadpparms_change_macaddr(card);
Julian Wiedmann4b7ae122019-02-12 18:33:23 +0100317 if (!rc)
Julian Wiedmann21b17022018-04-26 09:42:24 +0200318 goto out;
Julian Wiedmanne19e5be2018-11-02 19:04:08 +0100319 QETH_DBF_MESSAGE(2, "READ_MAC Assist failed on device %x: %#x\n",
320 CARD_DEVID(card), rc);
Julian Wiedmann57a688aa2019-06-11 18:37:55 +0200321 QETH_CARD_TEXT_(card, 2, "1err%04x", rc);
Julian Wiedmann21b17022018-04-26 09:42:24 +0200322 /* fall back once more: */
Frank Blaschka4a71df52008-02-15 09:19:42 +0100323 }
Julian Wiedmann21b17022018-04-26 09:42:24 +0200324
325 /* some devices don't support a custom MAC address: */
Julian Wiedmann379ac992019-04-25 18:25:57 +0200326 if (IS_OSM(card) || IS_OSX(card))
Julian Wiedmann21b17022018-04-26 09:42:24 +0200327 return (rc) ? rc : -EADDRNOTAVAIL;
328 eth_hw_addr_random(card->dev);
329
Julian Wiedmannec61bd22017-06-20 16:00:34 +0200330out:
Julian Wiedmann57a688aa2019-06-11 18:37:55 +0200331 QETH_CARD_HEX(card, 2, card->dev->dev_addr, card->dev->addr_len);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100332 return 0;
333}
334
Julian Wiedmann654e3d42019-01-25 15:44:19 +0100335static void qeth_l2_register_dev_addr(struct qeth_card *card)
336{
337 if (!is_valid_ether_addr(card->dev->dev_addr))
338 qeth_l2_request_initial_mac(card);
339
340 if (!IS_OSN(card) && !qeth_l2_send_setmac(card, card->dev->dev_addr))
Julian Wiedmann9de15112020-03-25 10:35:02 +0100341 card->info.dev_addr_is_registered = 1;
342 else
343 card->info.dev_addr_is_registered = 0;
Julian Wiedmann654e3d42019-01-25 15:44:19 +0100344}
345
Julian Wiedmanne22355e2019-01-25 15:44:18 +0100346static int qeth_l2_validate_addr(struct net_device *dev)
347{
348 struct qeth_card *card = dev->ml_priv;
349
Julian Wiedmann9de15112020-03-25 10:35:02 +0100350 if (card->info.dev_addr_is_registered)
Julian Wiedmanne22355e2019-01-25 15:44:18 +0100351 return eth_validate_addr(dev);
352
353 QETH_CARD_TEXT(card, 4, "nomacadr");
354 return -EPERM;
355}
356
Frank Blaschka4a71df52008-02-15 09:19:42 +0100357static int qeth_l2_set_mac_address(struct net_device *dev, void *p)
358{
359 struct sockaddr *addr = p;
Heiko Carstens509e2562008-07-26 02:24:10 -0700360 struct qeth_card *card = dev->ml_priv;
Julian Wiedmannbcacfcb2018-04-19 12:52:09 +0200361 u8 old_addr[ETH_ALEN];
Frank Blaschka4a71df52008-02-15 09:19:42 +0100362 int rc = 0;
363
Carsten Otte847a50f2010-06-21 22:57:05 +0000364 QETH_CARD_TEXT(card, 3, "setmac");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100365
Julian Wiedmann8024cc92019-02-15 19:22:31 +0100366 if (IS_OSM(card) || IS_OSX(card)) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000367 QETH_CARD_TEXT(card, 3, "setmcTYP");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100368 return -EOPNOTSUPP;
369 }
Julian Wiedmann99f0b852017-12-20 20:11:01 +0100370 QETH_CARD_HEX(card, 3, addr->sa_data, ETH_ALEN);
Julian Wiedmannbcacfcb2018-04-19 12:52:09 +0200371 if (!is_valid_ether_addr(addr->sa_data))
372 return -EADDRNOTAVAIL;
373
Julian Wiedmannbcacfcb2018-04-19 12:52:09 +0200374 /* don't register the same address twice */
375 if (ether_addr_equal_64bits(dev->dev_addr, addr->sa_data) &&
Julian Wiedmann9de15112020-03-25 10:35:02 +0100376 card->info.dev_addr_is_registered)
Julian Wiedmanne6e771b2019-01-25 15:44:22 +0100377 return 0;
Julian Wiedmannbcacfcb2018-04-19 12:52:09 +0200378
379 /* add the new address, switch over, drop the old */
380 rc = qeth_l2_send_setmac(card, addr->sa_data);
381 if (rc)
Julian Wiedmanne6e771b2019-01-25 15:44:22 +0100382 return rc;
Julian Wiedmannbcacfcb2018-04-19 12:52:09 +0200383 ether_addr_copy(old_addr, dev->dev_addr);
384 ether_addr_copy(dev->dev_addr, addr->sa_data);
385
Julian Wiedmann9de15112020-03-25 10:35:02 +0100386 if (card->info.dev_addr_is_registered)
Julian Wiedmannbcacfcb2018-04-19 12:52:09 +0200387 qeth_l2_remove_mac(card, old_addr);
Julian Wiedmann9de15112020-03-25 10:35:02 +0100388 card->info.dev_addr_is_registered = 1;
Julian Wiedmanne6e771b2019-01-25 15:44:22 +0100389 return 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100390}
391
Julian Wiedmann59b757a2019-08-20 16:46:41 +0200392static void qeth_l2_promisc_to_bridge(struct qeth_card *card, bool enable)
Eugene Crosser0db587b2015-05-18 14:27:55 +0200393{
Eugene Crosser0db587b2015-05-18 14:27:55 +0200394 int role;
395 int rc;
396
397 QETH_CARD_TEXT(card, 3, "pmisc2br");
398
Julian Wiedmann59b757a2019-08-20 16:46:41 +0200399 if (enable) {
Eugene Crosser0db587b2015-05-18 14:27:55 +0200400 if (card->options.sbp.reflect_promisc_primary)
401 role = QETH_SBP_ROLE_PRIMARY;
402 else
403 role = QETH_SBP_ROLE_SECONDARY;
404 } else
405 role = QETH_SBP_ROLE_NONE;
406
407 rc = qeth_bridgeport_setrole(card, role);
Julian Wiedmann59b757a2019-08-20 16:46:41 +0200408 QETH_CARD_TEXT_(card, 2, "bpm%c%04x", enable ? '+' : '-', rc);
Eugene Crosser0db587b2015-05-18 14:27:55 +0200409 if (!rc) {
410 card->options.sbp.role = role;
Julian Wiedmann59b757a2019-08-20 16:46:41 +0200411 card->info.promisc_mode = enable;
Eugene Crosser0db587b2015-05-18 14:27:55 +0200412 }
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200413}
Julian Wiedmann59b757a2019-08-20 16:46:41 +0200414
415static void qeth_l2_set_promisc_mode(struct qeth_card *card)
416{
417 bool enable = card->dev->flags & IFF_PROMISC;
418
419 if (card->info.promisc_mode == enable)
420 return;
421
Julian Wiedmannc8183f52019-11-20 14:20:56 +0100422 if (qeth_adp_supported(card, IPA_SETADP_SET_PROMISC_MODE)) {
Julian Wiedmann59b757a2019-08-20 16:46:41 +0200423 qeth_setadp_promisc_mode(card, enable);
Julian Wiedmannc8183f52019-11-20 14:20:56 +0100424 } else {
425 mutex_lock(&card->sbp_lock);
426 if (card->options.sbp.reflect_promisc)
427 qeth_l2_promisc_to_bridge(card, enable);
428 mutex_unlock(&card->sbp_lock);
429 }
Julian Wiedmann59b757a2019-08-20 16:46:41 +0200430}
431
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200432/* New MAC address is added to the hash table and marked to be written on card
433 * only if there is not in the hash table storage already
434 *
435*/
Julian Wiedmann4641b022017-12-20 20:10:59 +0100436static void qeth_l2_add_mac(struct qeth_card *card, struct netdev_hw_addr *ha)
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200437{
Julian Wiedmanncef6ff222017-08-15 17:02:46 +0200438 u32 mac_hash = get_unaligned((u32 *)(&ha->addr[2]));
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200439 struct qeth_mac *mac;
440
Julian Wiedmanncef6ff222017-08-15 17:02:46 +0200441 hash_for_each_possible(card->mac_htable, mac, hnode, mac_hash) {
Julian Wiedmann99f0b852017-12-20 20:11:01 +0100442 if (ether_addr_equal_64bits(ha->addr, mac->mac_addr)) {
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200443 mac->disp_flag = QETH_DISP_ADDR_DO_NOTHING;
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200444 return;
445 }
446 }
447
448 mac = kzalloc(sizeof(struct qeth_mac), GFP_ATOMIC);
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200449 if (!mac)
450 return;
451
Julian Wiedmann99f0b852017-12-20 20:11:01 +0100452 ether_addr_copy(mac->mac_addr, ha->addr);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200453 mac->disp_flag = QETH_DISP_ADDR_ADD;
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200454
Julian Wiedmanncef6ff222017-08-15 17:02:46 +0200455 hash_add(card->mac_htable, &mac->hnode, mac_hash);
Eugene Crosser0db587b2015-05-18 14:27:55 +0200456}
457
Julian Wiedmannd0c74822019-03-28 16:39:19 +0100458static void qeth_l2_rx_mode_work(struct work_struct *work)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100459{
Julian Wiedmannd0c74822019-03-28 16:39:19 +0100460 struct qeth_card *card = container_of(work, struct qeth_card,
461 rx_mode_work);
462 struct net_device *dev = card->dev;
Jiri Pirkoccffad252009-05-22 23:22:17 +0000463 struct netdev_hw_addr *ha;
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200464 struct qeth_mac *mac;
465 struct hlist_node *tmp;
466 int i;
467 int rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100468
Carsten Otte847a50f2010-06-21 22:57:05 +0000469 QETH_CARD_TEXT(card, 3, "setmulti");
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200470
Julian Wiedmannd0c74822019-03-28 16:39:19 +0100471 netif_addr_lock_bh(dev);
Jiri Pirko22bedad32010-04-01 21:22:57 +0000472 netdev_for_each_mc_addr(ha, dev)
Julian Wiedmann4641b022017-12-20 20:10:59 +0100473 qeth_l2_add_mac(card, ha);
Jiri Pirko32e7bfc2010-01-25 13:36:10 -0800474 netdev_for_each_uc_addr(ha, dev)
Julian Wiedmann4641b022017-12-20 20:10:59 +0100475 qeth_l2_add_mac(card, ha);
Julian Wiedmannd0c74822019-03-28 16:39:19 +0100476 netif_addr_unlock_bh(dev);
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200477
478 hash_for_each_safe(card->mac_htable, i, tmp, mac, hnode) {
Julian Wiedmann00c163f2017-12-20 20:11:02 +0100479 switch (mac->disp_flag) {
480 case QETH_DISP_ADDR_DELETE:
Julian Wiedmann8174aa82017-12-20 20:11:00 +0100481 qeth_l2_remove_mac(card, mac->mac_addr);
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200482 hash_del(&mac->hnode);
483 kfree(mac);
Julian Wiedmann00c163f2017-12-20 20:11:02 +0100484 break;
485 case QETH_DISP_ADDR_ADD:
Julian Wiedmann8174aa82017-12-20 20:11:00 +0100486 rc = qeth_l2_write_mac(card, mac->mac_addr);
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200487 if (rc) {
488 hash_del(&mac->hnode);
489 kfree(mac);
Julian Wiedmann00c163f2017-12-20 20:11:02 +0100490 break;
491 }
492 /* fall through */
493 default:
494 /* for next call to set_rx_mode(): */
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200495 mac->disp_flag = QETH_DISP_ADDR_DELETE;
Julian Wiedmann00c163f2017-12-20 20:11:02 +0100496 }
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200497 }
Frank Blaschka7db22662008-08-15 08:02:59 +0200498
Julian Wiedmann59b757a2019-08-20 16:46:41 +0200499 qeth_l2_set_promisc_mode(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100500}
501
Julian Wiedmann72863842017-08-18 10:19:04 +0200502static int qeth_l2_xmit_osn(struct qeth_card *card, struct sk_buff *skb,
503 struct qeth_qdio_out_q *queue)
504{
Julian Wiedmannb413ff82020-03-18 13:54:46 +0100505 gfp_t gfp = GFP_ATOMIC | (skb_pfmemalloc(skb) ? __GFP_MEMALLOC : 0);
Julian Wiedmann69d7ce82018-09-17 17:36:04 +0200506 struct qeth_hdr *hdr = (struct qeth_hdr *)skb->data;
507 addr_t end = (addr_t)(skb->data + sizeof(*hdr));
508 addr_t start = (addr_t)skb->data;
509 unsigned int elements = 0;
510 unsigned int hd_len = 0;
511 int rc;
Julian Wiedmann72863842017-08-18 10:19:04 +0200512
513 if (skb->protocol == htons(ETH_P_IPV6))
514 return -EPROTONOSUPPORT;
515
Julian Wiedmann69d7ce82018-09-17 17:36:04 +0200516 if (qeth_get_elements_for_range(start, end) > 1) {
517 /* Misaligned HW header, move it to its own buffer element. */
Julian Wiedmannb413ff82020-03-18 13:54:46 +0100518 hdr = kmem_cache_alloc(qeth_core_header_cache, gfp);
Julian Wiedmann69d7ce82018-09-17 17:36:04 +0200519 if (!hdr)
520 return -ENOMEM;
521 hd_len = sizeof(*hdr);
522 skb_copy_from_linear_data(skb, (char *)hdr, hd_len);
523 elements++;
524 }
525
526 elements += qeth_count_elements(skb, hd_len);
Julian Wiedmann4e26c5f2019-04-25 18:25:59 +0200527 if (elements > queue->max_elements) {
Julian Wiedmann69d7ce82018-09-17 17:36:04 +0200528 rc = -E2BIG;
529 goto out;
530 }
531
532 rc = qeth_do_send_packet(card, queue, skb, hdr, hd_len, hd_len,
533 elements);
534out:
535 if (rc && hd_len)
536 kmem_cache_free(qeth_core_header_cache, hdr);
537 return rc;
Julian Wiedmann72863842017-08-18 10:19:04 +0200538}
539
Julian Wiedmanne38db6b2017-04-11 16:11:14 +0200540static netdev_tx_t qeth_l2_hard_start_xmit(struct sk_buff *skb,
541 struct net_device *dev)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100542{
Heiko Carstens509e2562008-07-26 02:24:10 -0700543 struct qeth_card *card = dev->ml_priv;
Julian Wiedmann3a18d752019-04-17 18:17:32 +0200544 u16 txq = skb_get_queue_mapping(skb);
Stefan Raspl290b8342014-04-28 10:05:08 +0200545 struct qeth_qdio_out_q *queue;
Julian Wiedmann72863842017-08-18 10:19:04 +0200546 int rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100547
Julian Wiedmanneeac0e22019-08-23 11:48:49 +0200548 if (!skb_is_gso(skb))
549 qdisc_skb_cb(skb)->pkt_len = skb->len;
Julian Wiedmann3a18d752019-04-17 18:17:32 +0200550 if (IS_IQD(card))
Julian Wiedmann54a50942019-04-17 18:17:35 +0200551 txq = qeth_iqd_translate_txq(dev, txq);
552 queue = card->qdio.out_qs[txq];
Frank Blaschka4a71df52008-02-15 09:19:42 +0100553
Julian Wiedmann5f89eca2018-07-19 12:43:58 +0200554 if (IS_OSN(card))
Julian Wiedmann72863842017-08-18 10:19:04 +0200555 rc = qeth_l2_xmit_osn(card, skb, queue);
Julian Wiedmann5f89eca2018-07-19 12:43:58 +0200556 else
Julian Wiedmann73dc2da2019-04-17 18:17:33 +0200557 rc = qeth_xmit(card, skb, queue, qeth_get_ip_version(skb),
Julian Wiedmann58aa2492019-04-25 18:26:00 +0200558 qeth_l2_fill_header);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100559
Julian Wiedmanneeac0e22019-08-23 11:48:49 +0200560 if (!rc)
Julian Wiedmann72863842017-08-18 10:19:04 +0200561 return NETDEV_TX_OK;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100562
Julian Wiedmannb0abc4f2019-02-15 19:22:29 +0100563 QETH_TXQ_STAT_INC(queue, tx_dropped);
Julian Wiedmann104b4852019-03-18 16:40:56 +0100564 kfree_skb(skb);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100565 return NETDEV_TX_OK;
566}
567
Julian Wiedmann3a18d752019-04-17 18:17:32 +0200568static u16 qeth_l2_select_queue(struct net_device *dev, struct sk_buff *skb,
569 struct net_device *sb_dev)
570{
Julian Wiedmann73dc2da2019-04-17 18:17:33 +0200571 struct qeth_card *card = dev->ml_priv;
572
573 if (IS_IQD(card))
574 return qeth_iqd_select_queue(dev, skb,
Julian Wiedmann58aa2492019-04-25 18:26:00 +0200575 qeth_get_ether_cast_type(skb),
Julian Wiedmann73dc2da2019-04-17 18:17:33 +0200576 sb_dev);
Julian Wiedmann1c103cf2020-03-18 13:54:47 +0100577
578 return IS_VM_NIC(card) ? netdev_pick_tx(dev, skb, sb_dev) :
579 qeth_get_priority_queue(card, skb);
Julian Wiedmann3a18d752019-04-17 18:17:32 +0200580}
581
Julian Wiedmann2d2ebb32017-05-10 19:07:52 +0200582static const struct device_type qeth_l2_devtype = {
583 .name = "qeth_layer2",
584 .groups = qeth_l2_attr_groups,
585};
586
Frank Blaschka4a71df52008-02-15 09:19:42 +0100587static int qeth_l2_probe_device(struct ccwgroup_device *gdev)
588{
589 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
Ursula Braun9111e782017-05-10 19:07:51 +0200590 int rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100591
Julian Wiedmannfb64de12020-03-27 11:19:34 +0100592 if (IS_OSN(card))
593 dev_notice(&gdev->dev, "OSN support will be dropped in 2021\n");
594
Julian Wiedmann12b409d2019-03-18 16:40:54 +0100595 qeth_l2_vnicc_set_defaults(card);
Julian Wiedmannc8183f52019-11-20 14:20:56 +0100596 mutex_init(&card->sbp_lock);
Julian Wiedmann12b409d2019-03-18 16:40:54 +0100597
Julian Wiedmann2d2ebb32017-05-10 19:07:52 +0200598 if (gdev->dev.type == &qeth_generic_devtype) {
599 rc = qeth_l2_create_device_attributes(&gdev->dev);
600 if (rc)
601 return rc;
602 }
Julian Wiedmann5fc692a2019-01-25 15:44:23 +0100603
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200604 hash_init(card->mac_htable);
Julian Wiedmannd0c74822019-03-28 16:39:19 +0100605 INIT_WORK(&card->rx_mode_work, qeth_l2_rx_mode_work);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100606 return 0;
607}
608
609static void qeth_l2_remove_device(struct ccwgroup_device *cgdev)
610{
611 struct qeth_card *card = dev_get_drvdata(&cgdev->dev);
612
Julian Wiedmann2d2ebb32017-05-10 19:07:52 +0200613 if (cgdev->dev.type == &qeth_generic_devtype)
614 qeth_l2_remove_device_attributes(&cgdev->dev);
Ursula Braunf2148562009-05-19 21:38:37 +0000615 qeth_set_allowed_threads(card, 0, 1);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100616 wait_event(card->wait_q, qeth_threads_running(card, 0xffffffff) == 0);
617
Ursula Braun70919e22011-02-26 22:41:36 -0800618 if (cgdev->state == CCWGROUP_ONLINE)
Julian Wiedmann91003f32020-01-25 16:53:01 +0100619 qeth_set_offline(card, false);
Julian Wiedmannc2780c12019-02-04 17:40:08 +0100620
621 cancel_work_sync(&card->close_dev_work);
Julian Wiedmanncd652be2020-03-18 13:54:55 +0100622 if (card->dev->reg_state == NETREG_REGISTERED)
Julian Wiedmann30356d02018-11-02 19:04:10 +0100623 unregister_netdev(card->dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100624}
625
Julian Wiedmannd0c74822019-03-28 16:39:19 +0100626static void qeth_l2_set_rx_mode(struct net_device *dev)
627{
628 struct qeth_card *card = dev->ml_priv;
629
630 schedule_work(&card->rx_mode_work);
631}
632
Alexandra Wintera0138f52020-04-16 15:08:41 +0200633/**
634 * qeth_l2_pnso() - perform network subchannel operation
635 * @card: qeth_card structure pointer
636 * @cnc: Boolean Change-Notification Control
637 * @cb: Callback function will be executed for each element
638 * of the address list
639 * @priv: Pointer to pass to the callback function.
640 *
641 * Collects network information in a network address list and calls the
642 * callback function for every entry in the list. If "change-notification-
643 * control" is set, further changes in the address list will be reported
644 * via the IPA command.
645 */
646static int qeth_l2_pnso(struct qeth_card *card, int cnc,
647 void (*cb)(void *priv, struct chsc_pnso_naid_l2 *entry),
648 void *priv)
649{
650 struct ccw_device *ddev = CARD_DDEV(card);
651 struct chsc_pnso_area *rr;
652 u32 prev_instance = 0;
653 int isfirstblock = 1;
654 int i, size, elems;
655 int rc;
656
657 QETH_CARD_TEXT(card, 2, "PNSO");
658 rr = (struct chsc_pnso_area *)get_zeroed_page(GFP_KERNEL);
659 if (rr == NULL)
660 return -ENOMEM;
661 do {
662 /* on the first iteration, naihdr.resume_token will be zero */
663 rc = ccw_device_pnso(ddev, rr, rr->naihdr.resume_token, cnc);
664 if (rc)
665 continue;
666 if (cb == NULL)
667 continue;
668
669 size = rr->naihdr.naids;
670 if (size != sizeof(struct chsc_pnso_naid_l2)) {
671 WARN_ON_ONCE(1);
672 continue;
673 }
674
675 elems = (rr->response.length - sizeof(struct chsc_header) -
676 sizeof(struct chsc_pnso_naihdr)) / size;
677
678 if (!isfirstblock && (rr->naihdr.instance != prev_instance)) {
679 /* Inform the caller that they need to scrap */
680 /* the data that was already reported via cb */
681 rc = -EAGAIN;
682 break;
683 }
684 isfirstblock = 0;
685 prev_instance = rr->naihdr.instance;
686 for (i = 0; i < elems; i++)
687 (*cb)(priv, &rr->entries[i]);
688 } while ((rc == -EBUSY) || (!rc && /* list stored */
689 /* resume token is non-zero => list incomplete */
690 (rr->naihdr.resume_token.t1 || rr->naihdr.resume_token.t2)));
691
692 if (rc)
693 QETH_CARD_TEXT_(card, 2, "PNrp%04x", rr->response.code);
694
695 free_page((unsigned long)rr);
696 return rc;
697}
698
Frank Blaschka3d58cef2009-01-09 03:44:00 +0000699static const struct net_device_ops qeth_l2_netdev_ops = {
Julian Wiedmanne22355e2019-01-25 15:44:18 +0100700 .ndo_open = qeth_open,
701 .ndo_stop = qeth_stop,
Julian Wiedmannb0abc4f2019-02-15 19:22:29 +0100702 .ndo_get_stats64 = qeth_get_stats64,
Frank Blaschka8403b132009-01-08 10:50:55 -0800703 .ndo_start_xmit = qeth_l2_hard_start_xmit,
Julian Wiedmann6d69b1f2017-12-01 10:14:50 +0100704 .ndo_features_check = qeth_features_check,
Julian Wiedmann3a18d752019-04-17 18:17:32 +0200705 .ndo_select_queue = qeth_l2_select_queue,
Julian Wiedmanne22355e2019-01-25 15:44:18 +0100706 .ndo_validate_addr = qeth_l2_validate_addr,
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200707 .ndo_set_rx_mode = qeth_l2_set_rx_mode,
Julian Wiedmann942d6982017-04-11 16:11:10 +0200708 .ndo_do_ioctl = qeth_do_ioctl,
Frank Blaschka8403b132009-01-08 10:50:55 -0800709 .ndo_set_mac_address = qeth_l2_set_mac_address,
Frank Blaschka8403b132009-01-08 10:50:55 -0800710 .ndo_vlan_rx_add_vid = qeth_l2_vlan_rx_add_vid,
711 .ndo_vlan_rx_kill_vid = qeth_l2_vlan_rx_kill_vid,
712 .ndo_tx_timeout = qeth_tx_timeout,
Thomas Richter8f43fb02016-06-16 16:18:59 +0200713 .ndo_fix_features = qeth_fix_features,
714 .ndo_set_features = qeth_set_features
Frank Blaschka8403b132009-01-08 10:50:55 -0800715};
716
Julian Wiedmann8024cc92019-02-15 19:22:31 +0100717static const struct net_device_ops qeth_osn_netdev_ops = {
718 .ndo_open = qeth_open,
719 .ndo_stop = qeth_stop,
720 .ndo_get_stats64 = qeth_get_stats64,
721 .ndo_start_xmit = qeth_l2_hard_start_xmit,
722 .ndo_validate_addr = eth_validate_addr,
723 .ndo_tx_timeout = qeth_tx_timeout,
724};
725
Julian Wiedmanncd652be2020-03-18 13:54:55 +0100726static int qeth_l2_setup_netdev(struct qeth_card *card)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100727{
Julian Wiedmannd3d1b202018-07-19 12:43:51 +0200728 int rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100729
Julian Wiedmann8024cc92019-02-15 19:22:31 +0100730 if (IS_OSN(card)) {
731 card->dev->netdev_ops = &qeth_osn_netdev_ops;
Julian Wiedmann25e2c342017-05-10 19:07:53 +0200732 card->dev->flags |= IFF_NOARP;
Julian Wiedmann8024cc92019-02-15 19:22:31 +0100733 goto add_napi;
734 }
735
Julian Wiedmann1c103cf2020-03-18 13:54:47 +0100736 rc = qeth_setup_netdev(card);
737 if (rc)
738 return rc;
739
Julian Wiedmann8024cc92019-02-15 19:22:31 +0100740 card->dev->needed_headroom = sizeof(struct qeth_hdr);
741 card->dev->netdev_ops = &qeth_l2_netdev_ops;
742 card->dev->priv_flags |= IFF_UNICAST_FLT;
Julian Wiedmann9400c532017-10-18 17:40:20 +0200743
Julian Wiedmann5fc692a2019-01-25 15:44:23 +0100744 if (IS_OSM(card)) {
Julian Wiedmann9400c532017-10-18 17:40:20 +0200745 card->dev->features |= NETIF_F_VLAN_CHALLENGED;
Julian Wiedmann5fc692a2019-01-25 15:44:23 +0100746 } else {
747 if (!IS_VM_NIC(card))
748 card->dev->hw_features |= NETIF_F_HW_VLAN_CTAG_FILTER;
Julian Wiedmann9400c532017-10-18 17:40:20 +0200749 card->dev->features |= NETIF_F_HW_VLAN_CTAG_FILTER;
Julian Wiedmann5fc692a2019-01-25 15:44:23 +0100750 }
Julian Wiedmann0f342942018-03-09 18:12:54 +0100751
Julian Wiedmann379ac992019-04-25 18:25:57 +0200752 if (IS_OSD(card) && !IS_VM_NIC(card)) {
Julian Wiedmann6d69b1f2017-12-01 10:14:50 +0100753 card->dev->features |= NETIF_F_SG;
Thomas Richter8f43fb02016-06-16 16:18:59 +0200754 /* OSA 3S and earlier has no RX/TX support */
Hans Wippel9bdc4412016-06-16 16:19:00 +0200755 if (qeth_is_supported(card, IPA_OUTBOUND_CHECKSUM)) {
Thomas Richter8f43fb02016-06-16 16:18:59 +0200756 card->dev->hw_features |= NETIF_F_IP_CSUM;
Hans Wippel9bdc4412016-06-16 16:19:00 +0200757 card->dev->vlan_features |= NETIF_F_IP_CSUM;
758 }
Thomas Richter4d7def22015-09-18 16:06:51 +0200759 }
Kittipon Meesompop571f9dd82018-04-26 09:42:22 +0200760 if (qeth_is_supported6(card, IPA_OUTBOUND_CHECKSUM_V6)) {
761 card->dev->hw_features |= NETIF_F_IPV6_CSUM;
762 card->dev->vlan_features |= NETIF_F_IPV6_CSUM;
763 }
Kittipon Meesompopd7e6ed92018-04-26 09:42:23 +0200764 if (qeth_is_supported(card, IPA_INBOUND_CHECKSUM) ||
765 qeth_is_supported6(card, IPA_INBOUND_CHECKSUM_V6)) {
766 card->dev->hw_features |= NETIF_F_RXCSUM;
767 card->dev->vlan_features |= NETIF_F_RXCSUM;
768 }
Julian Wiedmann0aef8392018-10-12 17:27:15 +0200769 if (qeth_is_supported(card, IPA_OUTBOUND_TSO)) {
770 card->dev->hw_features |= NETIF_F_TSO;
771 card->dev->vlan_features |= NETIF_F_TSO;
772 }
773 if (qeth_is_supported6(card, IPA_OUTBOUND_TSO)) {
774 card->dev->hw_features |= NETIF_F_TSO6;
775 card->dev->vlan_features |= NETIF_F_TSO6;
776 }
777
778 if (card->dev->hw_features & (NETIF_F_TSO | NETIF_F_TSO6)) {
779 card->dev->needed_headroom = sizeof(struct qeth_hdr_tso);
Julian Wiedmannc619e9a2020-05-06 10:09:44 +0200780 netif_keep_dst(card->dev);
Julian Wiedmann0aef8392018-10-12 17:27:15 +0200781 netif_set_gso_max_size(card->dev,
782 PAGE_SIZE * (QDIO_MAX_ELEMENTS_PER_BUFFER - 1));
783 }
Julian Wiedmann0d6f02d2017-08-18 10:19:10 +0200784
Julian Wiedmann8024cc92019-02-15 19:22:31 +0100785add_napi:
Julian Wiedmannd73ef322017-04-11 16:11:11 +0200786 netif_napi_add(card->dev, &card->napi, qeth_poll, QETH_NAPI_WEIGHT);
Julian Wiedmanncd652be2020-03-18 13:54:55 +0100787 return register_netdev(card->dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100788}
789
Julian Wiedmann521c10e2017-06-06 14:33:45 +0200790static void qeth_l2_trace_features(struct qeth_card *card)
791{
Hans Wippela45b3fa2017-09-18 21:18:14 +0200792 /* Set BridgePort features */
793 QETH_CARD_TEXT(card, 2, "featuSBP");
Julian Wiedmann521c10e2017-06-06 14:33:45 +0200794 QETH_CARD_HEX(card, 2, &card->options.sbp.supported_funcs,
795 sizeof(card->options.sbp.supported_funcs));
Hans Wippela45b3fa2017-09-18 21:18:14 +0200796 /* VNIC Characteristics features */
797 QETH_CARD_TEXT(card, 2, "feaVNICC");
798 QETH_CARD_HEX(card, 2, &card->options.vnicc.sup_chars,
799 sizeof(card->options.vnicc.sup_chars));
Julian Wiedmann521c10e2017-06-06 14:33:45 +0200800}
801
Julian Wiedmann8ca769e2020-01-25 16:52:59 +0100802static void qeth_l2_setup_bridgeport_attrs(struct qeth_card *card)
803{
804 if (!card->options.sbp.reflect_promisc &&
805 card->options.sbp.role != QETH_SBP_ROLE_NONE) {
806 /* Conditional to avoid spurious error messages */
807 qeth_bridgeport_setrole(card, card->options.sbp.role);
808 /* Let the callback function refresh the stored role value. */
809 qeth_bridgeport_query_ports(card, &card->options.sbp.role,
810 NULL);
811 }
812 if (card->options.sbp.hostnotification) {
813 if (qeth_bridgeport_an_set(card, 1))
814 card->options.sbp.hostnotification = 0;
815 } else {
816 qeth_bridgeport_an_set(card, 0);
817 }
818}
819
Julian Wiedmann91003f32020-01-25 16:53:01 +0100820static int qeth_l2_set_online(struct qeth_card *card)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100821{
Julian Wiedmann91003f32020-01-25 16:53:01 +0100822 struct ccwgroup_device *gdev = card->gdev;
Julian Wiedmannfa3d2e62019-01-25 15:44:21 +0100823 struct net_device *dev = card->dev;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100824 int rc = 0;
Julian Wiedmann9fae5c32018-11-02 19:04:11 +0100825 bool carrier_ok;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100826
Julian Wiedmann9fae5c32018-11-02 19:04:11 +0100827 rc = qeth_core_hardsetup_card(card, &carrier_ok);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100828 if (rc) {
Julian Wiedmann57a688aa2019-06-11 18:37:55 +0200829 QETH_CARD_TEXT_(card, 2, "2err%04x", rc);
Ursula Braunaa909222009-11-12 00:11:43 +0000830 rc = -ENODEV;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100831 goto out_remove;
832 }
Julian Wiedmann654e3d42019-01-25 15:44:19 +0100833
Julian Wiedmannc8183f52019-11-20 14:20:56 +0100834 mutex_lock(&card->sbp_lock);
Julian Wiedmannd7ef489f2019-02-28 18:59:37 +0100835 qeth_bridgeport_query_support(card);
Julian Wiedmann8ca769e2020-01-25 16:52:59 +0100836 if (card->options.sbp.supported_funcs) {
837 qeth_l2_setup_bridgeport_attrs(card);
Julian Wiedmannd7ef489f2019-02-28 18:59:37 +0100838 dev_info(&card->gdev->dev,
Julian Wiedmann8ca769e2020-01-25 16:52:59 +0100839 "The device represents a Bridge Capable Port\n");
840 }
Julian Wiedmannc8183f52019-11-20 14:20:56 +0100841 mutex_unlock(&card->sbp_lock);
Julian Wiedmannd7ef489f2019-02-28 18:59:37 +0100842
843 qeth_l2_register_dev_addr(card);
844
Hans Wippela45b3fa2017-09-18 21:18:14 +0200845 /* for the rx_bcast characteristic, init VNICC after setmac */
846 qeth_l2_vnicc_init(card);
847
848 qeth_trace_features(card);
849 qeth_l2_trace_features(card);
850
Frank Blaschka4a71df52008-02-15 09:19:42 +0100851 qeth_print_status_message(card);
852
853 /* softsetup */
Julian Wiedmann57a688aa2019-06-11 18:37:55 +0200854 QETH_CARD_TEXT(card, 2, "softsetp");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100855
Frank Blaschka4a71df52008-02-15 09:19:42 +0100856 card->state = CARD_STATE_SOFTSETUP;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100857
858 qeth_set_allowed_threads(card, 0xffffffff, 0);
Julian Wiedmannd025da92018-06-29 19:45:54 +0200859
Julian Wiedmanncd652be2020-03-18 13:54:55 +0100860 if (dev->reg_state != NETREG_REGISTERED) {
861 rc = qeth_l2_setup_netdev(card);
Julian Wiedmannfa3d2e62019-01-25 15:44:21 +0100862 if (rc)
863 goto out_remove;
Julian Wiedmanncd652be2020-03-18 13:54:55 +0100864
865 if (carrier_ok)
866 netif_carrier_on(dev);
Julian Wiedmannfa3d2e62019-01-25 15:44:21 +0100867 } else {
868 rtnl_lock();
869 if (carrier_ok)
870 netif_carrier_on(dev);
871 else
872 netif_carrier_off(dev);
873
Julian Wiedmanne6e771b2019-01-25 15:44:22 +0100874 netif_device_attach(dev);
Julian Wiedmannfa3d2e62019-01-25 15:44:21 +0100875 qeth_enable_hw_features(dev);
876
Julian Wiedmannd7d543f2019-02-28 18:59:36 +0100877 if (card->info.open_when_online) {
878 card->info.open_when_online = 0;
Julian Wiedmannd4560152019-02-28 18:59:39 +0100879 dev_open(dev, NULL);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100880 }
Julian Wiedmannfa3d2e62019-01-25 15:44:21 +0100881 rtnl_unlock();
Frank Blaschka4a71df52008-02-15 09:19:42 +0100882 }
883 /* let user_space know that device is online */
884 kobject_uevent(&gdev->dev.kobj, KOBJ_CHANGE);
885 return 0;
Ursula Braunaa909222009-11-12 00:11:43 +0000886
Frank Blaschka4a71df52008-02-15 09:19:42 +0100887out_remove:
Julian Wiedmannd4560152019-02-28 18:59:39 +0100888 qeth_l2_stop_card(card);
Julian Wiedmannf9e50b02019-12-05 14:33:04 +0100889 qeth_stop_channel(&card->data);
890 qeth_stop_channel(&card->write);
891 qeth_stop_channel(&card->read);
Ursula Braun22ae2792014-02-24 13:12:06 +0100892 qdio_free(CARD_DDEV(card));
Ursula Braunaa909222009-11-12 00:11:43 +0000893 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100894}
895
Julian Wiedmann91003f32020-01-25 16:53:01 +0100896static void qeth_l2_set_offline(struct qeth_card *card)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100897{
Julian Wiedmannd4560152019-02-28 18:59:39 +0100898 qeth_l2_stop_card(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100899}
900
901static int __init qeth_l2_init(void)
902{
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100903 pr_info("register layer 2 discipline\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100904 return 0;
905}
906
907static void __exit qeth_l2_exit(void)
908{
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100909 pr_info("unregister layer 2 discipline\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100910}
911
Eugene Crosserc044dc22014-01-29 09:23:48 +0100912/* Returns zero if the command is successfully "consumed" */
913static int qeth_l2_control_event(struct qeth_card *card,
914 struct qeth_ipa_cmd *cmd)
915{
916 switch (cmd->hdr.command) {
Eugene Crosser9c23f4da2015-05-18 14:27:56 +0200917 case IPA_CMD_SETBRIDGEPORT_OSA:
918 case IPA_CMD_SETBRIDGEPORT_IQD:
Eugene Crosserc044dc22014-01-29 09:23:48 +0100919 if (cmd->data.sbp.hdr.command_code ==
920 IPA_SBP_BRIDGE_PORT_STATE_CHANGE) {
921 qeth_bridge_state_change(card, cmd);
922 return 0;
923 } else
924 return 1;
925 case IPA_CMD_ADDRESS_CHANGE_NOTIF:
Alexandra Wintera0138f52020-04-16 15:08:41 +0200926 qeth_addr_change_event(card, cmd);
Eugene Crosserc044dc22014-01-29 09:23:48 +0100927 return 0;
928 default:
929 return 1;
930 }
931}
932
Sebastian Ottc041f2d4872012-05-15 18:02:21 +0200933struct qeth_discipline qeth_l2_discipline = {
Julian Wiedmann2d2ebb32017-05-10 19:07:52 +0200934 .devtype = &qeth_l2_devtype,
Sebastian Ottc041f2d4872012-05-15 18:02:21 +0200935 .setup = qeth_l2_probe_device,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100936 .remove = qeth_l2_remove_device,
937 .set_online = qeth_l2_set_online,
938 .set_offline = qeth_l2_set_offline,
Julian Wiedmann942d6982017-04-11 16:11:10 +0200939 .do_ioctl = NULL,
Eugene Crosserc044dc22014-01-29 09:23:48 +0100940 .control_event_handler = qeth_l2_control_event,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100941};
Sebastian Ottc041f2d4872012-05-15 18:02:21 +0200942EXPORT_SYMBOL_GPL(qeth_l2_discipline);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100943
Julian Wiedmann4e2b5aa2020-03-27 11:19:33 +0100944#ifdef CONFIG_QETH_OSN
Julian Wiedmann0ce37ec2019-06-11 18:37:54 +0200945static void qeth_osn_assist_cb(struct qeth_card *card,
Julian Wiedmann12fc2862019-08-20 16:46:36 +0200946 struct qeth_cmd_buffer *iob,
947 unsigned int data_length)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100948{
Julian Wiedmann308946b2019-08-20 16:46:39 +0200949 qeth_notify_cmd(iob, 0);
Julian Wiedmannc3b22182019-06-27 17:01:28 +0200950 qeth_put_cmd(iob);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100951}
952
953int qeth_osn_assist(struct net_device *dev, void *data, int data_len)
954{
955 struct qeth_cmd_buffer *iob;
956 struct qeth_card *card;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100957
Julian Wiedmanna59d1212019-06-27 17:01:22 +0200958 if (data_len < 0)
959 return -EINVAL;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100960 if (!dev)
961 return -ENODEV;
Heiko Carstens509e2562008-07-26 02:24:10 -0700962 card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100963 if (!card)
964 return -ENODEV;
Carsten Otte847a50f2010-06-21 22:57:05 +0000965 QETH_CARD_TEXT(card, 2, "osnsdmc");
Eugene Crosserc3521252015-01-16 14:05:47 +0100966 if (!qeth_card_hw_is_reachable(card))
Frank Blaschka4a71df52008-02-15 09:19:42 +0100967 return -ENODEV;
Julian Wiedmanna59d1212019-06-27 17:01:22 +0200968
969 iob = qeth_alloc_cmd(&card->write, IPA_PDU_HEADER_SIZE + data_len, 1,
970 QETH_IPA_TIMEOUT);
Julian Wiedmann1273a802019-06-11 18:37:53 +0200971 if (!iob)
972 return -ENOMEM;
973
Julian Wiedmann7f92316c2020-01-25 16:53:02 +0100974 qeth_prepare_ipa_cmd(card, iob, (u16) data_len, NULL);
975
Julian Wiedmannff5caa72018-03-09 18:12:52 +0100976 memcpy(__ipa_cmd(iob), data, data_len);
Julian Wiedmann0ce37ec2019-06-11 18:37:54 +0200977 iob->callback = qeth_osn_assist_cb;
978 return qeth_send_ipa_cmd(card, iob, NULL, NULL);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100979}
980EXPORT_SYMBOL(qeth_osn_assist);
981
982int qeth_osn_register(unsigned char *read_dev_no, struct net_device **dev,
983 int (*assist_cb)(struct net_device *, void *),
984 int (*data_cb)(struct sk_buff *))
985{
986 struct qeth_card *card;
Julian Wiedmannd7d18da2018-11-08 15:06:18 +0100987 char bus_id[16];
988 u16 devno;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100989
Julian Wiedmannd7d18da2018-11-08 15:06:18 +0100990 memcpy(&devno, read_dev_no, 2);
991 sprintf(bus_id, "0.0.%04x", devno);
992 card = qeth_get_card_by_busid(bus_id);
993 if (!card || !IS_OSN(card))
Frank Blaschka4a71df52008-02-15 09:19:42 +0100994 return -ENODEV;
Julian Wiedmannd7d18da2018-11-08 15:06:18 +0100995 *dev = card->dev;
996
Carsten Otte847a50f2010-06-21 22:57:05 +0000997 QETH_CARD_TEXT(card, 2, "osnreg");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100998 if ((assist_cb == NULL) || (data_cb == NULL))
999 return -EINVAL;
1000 card->osn_info.assist_cb = assist_cb;
1001 card->osn_info.data_cb = data_cb;
1002 return 0;
1003}
1004EXPORT_SYMBOL(qeth_osn_register);
1005
1006void qeth_osn_deregister(struct net_device *dev)
1007{
1008 struct qeth_card *card;
1009
Frank Blaschka4a71df52008-02-15 09:19:42 +01001010 if (!dev)
1011 return;
Heiko Carstens509e2562008-07-26 02:24:10 -07001012 card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001013 if (!card)
1014 return;
Carsten Otte847a50f2010-06-21 22:57:05 +00001015 QETH_CARD_TEXT(card, 2, "osndereg");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001016 card->osn_info.assist_cb = NULL;
1017 card->osn_info.data_cb = NULL;
1018 return;
1019}
1020EXPORT_SYMBOL(qeth_osn_deregister);
Julian Wiedmann4e2b5aa2020-03-27 11:19:33 +01001021#endif
Frank Blaschka4a71df52008-02-15 09:19:42 +01001022
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001023/* SETBRIDGEPORT support, async notifications */
1024
Eugene Crosser9f48b9d2014-01-14 15:54:13 +01001025enum qeth_an_event_type {anev_reg_unreg, anev_abort, anev_reset};
1026
1027/**
1028 * qeth_bridge_emit_host_event() - bridgeport address change notification
1029 * @card: qeth_card structure pointer, for udev events.
1030 * @evtype: "normal" register/unregister, or abort, or reset. For abort
1031 * and reset token and addr_lnid are unused and may be NULL.
1032 * @code: event bitmask: high order bit 0x80 value 1 means removal of an
1033 * object, 0 - addition of an object.
1034 * 0x01 - VLAN, 0x02 - MAC, 0x03 - VLAN and MAC.
1035 * @token: "network token" structure identifying physical address of the port.
1036 * @addr_lnid: pointer to structure with MAC address and VLAN ID.
1037 *
1038 * This function is called when registrations and deregistrations are
1039 * reported by the hardware, and also when notifications are enabled -
1040 * for all currently registered addresses.
1041 */
1042static void qeth_bridge_emit_host_event(struct qeth_card *card,
Alexandra Wintera0138f52020-04-16 15:08:41 +02001043 enum qeth_an_event_type evtype,
1044 u8 code,
1045 struct net_if_token *token,
1046 struct mac_addr_lnid *addr_lnid)
Eugene Crosser9f48b9d2014-01-14 15:54:13 +01001047{
1048 char str[7][32];
1049 char *env[8];
1050 int i = 0;
1051
1052 switch (evtype) {
1053 case anev_reg_unreg:
1054 snprintf(str[i], sizeof(str[i]), "BRIDGEDHOST=%s",
1055 (code & IPA_ADDR_CHANGE_CODE_REMOVAL)
1056 ? "deregister" : "register");
1057 env[i] = str[i]; i++;
1058 if (code & IPA_ADDR_CHANGE_CODE_VLANID) {
1059 snprintf(str[i], sizeof(str[i]), "VLAN=%d",
1060 addr_lnid->lnid);
1061 env[i] = str[i]; i++;
1062 }
1063 if (code & IPA_ADDR_CHANGE_CODE_MACADDR) {
Eugene Crosser9846e702015-09-18 16:06:48 +02001064 snprintf(str[i], sizeof(str[i]), "MAC=%pM",
Thomas Richter4d7def22015-09-18 16:06:51 +02001065 addr_lnid->mac);
Eugene Crosser9f48b9d2014-01-14 15:54:13 +01001066 env[i] = str[i]; i++;
1067 }
1068 snprintf(str[i], sizeof(str[i]), "NTOK_BUSID=%x.%x.%04x",
1069 token->cssid, token->ssid, token->devnum);
1070 env[i] = str[i]; i++;
1071 snprintf(str[i], sizeof(str[i]), "NTOK_IID=%02x", token->iid);
1072 env[i] = str[i]; i++;
1073 snprintf(str[i], sizeof(str[i]), "NTOK_CHPID=%02x",
1074 token->chpid);
1075 env[i] = str[i]; i++;
1076 snprintf(str[i], sizeof(str[i]), "NTOK_CHID=%04x", token->chid);
1077 env[i] = str[i]; i++;
1078 break;
1079 case anev_abort:
1080 snprintf(str[i], sizeof(str[i]), "BRIDGEDHOST=abort");
1081 env[i] = str[i]; i++;
1082 break;
1083 case anev_reset:
1084 snprintf(str[i], sizeof(str[i]), "BRIDGEDHOST=reset");
1085 env[i] = str[i]; i++;
1086 break;
1087 }
1088 env[i] = NULL;
1089 kobject_uevent_env(&card->gdev->dev.kobj, KOBJ_CHANGE, env);
1090}
1091
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001092struct qeth_bridge_state_data {
1093 struct work_struct worker;
1094 struct qeth_card *card;
1095 struct qeth_sbp_state_change qports;
1096};
1097
1098static void qeth_bridge_state_change_worker(struct work_struct *work)
1099{
1100 struct qeth_bridge_state_data *data =
1101 container_of(work, struct qeth_bridge_state_data, worker);
1102 /* We are only interested in the first entry - local port */
1103 struct qeth_sbp_port_entry *entry = &data->qports.entry[0];
1104 char env_locrem[32];
1105 char env_role[32];
1106 char env_state[32];
1107 char *env[] = {
1108 env_locrem,
1109 env_role,
1110 env_state,
1111 NULL
1112 };
1113
1114 /* Role should not change by itself, but if it did, */
1115 /* information from the hardware is authoritative. */
Julian Wiedmannc8183f52019-11-20 14:20:56 +01001116 mutex_lock(&data->card->sbp_lock);
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001117 data->card->options.sbp.role = entry->role;
Julian Wiedmannc8183f52019-11-20 14:20:56 +01001118 mutex_unlock(&data->card->sbp_lock);
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001119
1120 snprintf(env_locrem, sizeof(env_locrem), "BRIDGEPORT=statechange");
1121 snprintf(env_role, sizeof(env_role), "ROLE=%s",
1122 (entry->role == QETH_SBP_ROLE_NONE) ? "none" :
1123 (entry->role == QETH_SBP_ROLE_PRIMARY) ? "primary" :
1124 (entry->role == QETH_SBP_ROLE_SECONDARY) ? "secondary" :
1125 "<INVALID>");
1126 snprintf(env_state, sizeof(env_state), "STATE=%s",
1127 (entry->state == QETH_SBP_STATE_INACTIVE) ? "inactive" :
1128 (entry->state == QETH_SBP_STATE_STANDBY) ? "standby" :
1129 (entry->state == QETH_SBP_STATE_ACTIVE) ? "active" :
1130 "<INVALID>");
1131 kobject_uevent_env(&data->card->gdev->dev.kobj,
1132 KOBJ_CHANGE, env);
1133 kfree(data);
1134}
1135
Eugene Crosserc044dc22014-01-29 09:23:48 +01001136static void qeth_bridge_state_change(struct qeth_card *card,
1137 struct qeth_ipa_cmd *cmd)
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001138{
1139 struct qeth_sbp_state_change *qports =
1140 &cmd->data.sbp.data.state_change;
1141 struct qeth_bridge_state_data *data;
1142 int extrasize;
1143
1144 QETH_CARD_TEXT(card, 2, "brstchng");
1145 if (qports->entry_length != sizeof(struct qeth_sbp_port_entry)) {
Thomas Richter8a593142014-10-22 12:18:03 +02001146 QETH_CARD_TEXT_(card, 2, "BPsz%04x", qports->entry_length);
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001147 return;
1148 }
1149 extrasize = sizeof(struct qeth_sbp_port_entry) * qports->num_entries;
1150 data = kzalloc(sizeof(struct qeth_bridge_state_data) + extrasize,
1151 GFP_ATOMIC);
1152 if (!data) {
1153 QETH_CARD_TEXT(card, 2, "BPSalloc");
1154 return;
1155 }
1156 INIT_WORK(&data->worker, qeth_bridge_state_change_worker);
1157 data->card = card;
1158 memcpy(&data->qports, qports,
1159 sizeof(struct qeth_sbp_state_change) + extrasize);
Julian Wiedmannc0a2e4d2019-02-04 17:40:09 +01001160 queue_work(card->event_wq, &data->worker);
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001161}
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001162
Alexandra Wintera0138f52020-04-16 15:08:41 +02001163struct qeth_addr_change_data {
Eugene Crosser9f48b9d2014-01-14 15:54:13 +01001164 struct work_struct worker;
1165 struct qeth_card *card;
Alexandra Wintera0138f52020-04-16 15:08:41 +02001166 struct qeth_ipacmd_addr_change ac_event;
Eugene Crosser9f48b9d2014-01-14 15:54:13 +01001167};
1168
Alexandra Wintera0138f52020-04-16 15:08:41 +02001169static void qeth_addr_change_event_worker(struct work_struct *work)
Eugene Crosser9f48b9d2014-01-14 15:54:13 +01001170{
Alexandra Wintera0138f52020-04-16 15:08:41 +02001171 struct qeth_addr_change_data *data =
1172 container_of(work, struct qeth_addr_change_data, worker);
Eugene Crosser9f48b9d2014-01-14 15:54:13 +01001173 int i;
1174
Alexandra Wintera0138f52020-04-16 15:08:41 +02001175 QETH_CARD_TEXT(data->card, 4, "adrchgew");
1176 if (data->ac_event.lost_event_mask) {
Eugene Crosser9f48b9d2014-01-14 15:54:13 +01001177 dev_info(&data->card->gdev->dev,
Alexandra Wintera0138f52020-04-16 15:08:41 +02001178 "Address change notification stopped on %s (%s)\n",
1179 data->card->dev->name,
1180 (data->ac_event.lost_event_mask == 0x01)
Eugene Crosser9f48b9d2014-01-14 15:54:13 +01001181 ? "Overflow"
Alexandra Wintera0138f52020-04-16 15:08:41 +02001182 : (data->ac_event.lost_event_mask == 0x02)
Eugene Crosser9f48b9d2014-01-14 15:54:13 +01001183 ? "Bridge port state change"
1184 : "Unknown reason");
Julian Wiedmannc8183f52019-11-20 14:20:56 +01001185 mutex_lock(&data->card->sbp_lock);
Eugene Crosser9f48b9d2014-01-14 15:54:13 +01001186 data->card->options.sbp.hostnotification = 0;
Julian Wiedmannc8183f52019-11-20 14:20:56 +01001187 mutex_unlock(&data->card->sbp_lock);
Eugene Crosser9f48b9d2014-01-14 15:54:13 +01001188 qeth_bridge_emit_host_event(data->card, anev_abort,
Alexandra Wintera0138f52020-04-16 15:08:41 +02001189 0, NULL, NULL);
Eugene Crosser9f48b9d2014-01-14 15:54:13 +01001190 } else
Alexandra Wintera0138f52020-04-16 15:08:41 +02001191 for (i = 0; i < data->ac_event.num_entries; i++) {
Eugene Crosser9f48b9d2014-01-14 15:54:13 +01001192 struct qeth_ipacmd_addr_change_entry *entry =
Alexandra Wintera0138f52020-04-16 15:08:41 +02001193 &data->ac_event.entry[i];
Eugene Crosser9f48b9d2014-01-14 15:54:13 +01001194 qeth_bridge_emit_host_event(data->card,
Alexandra Wintera0138f52020-04-16 15:08:41 +02001195 anev_reg_unreg,
1196 entry->change_code,
1197 &entry->token,
1198 &entry->addr_lnid);
Eugene Crosser9f48b9d2014-01-14 15:54:13 +01001199 }
1200 kfree(data);
1201}
1202
Alexandra Wintera0138f52020-04-16 15:08:41 +02001203static void qeth_addr_change_event(struct qeth_card *card,
1204 struct qeth_ipa_cmd *cmd)
Eugene Crosser9f48b9d2014-01-14 15:54:13 +01001205{
1206 struct qeth_ipacmd_addr_change *hostevs =
1207 &cmd->data.addrchange;
Alexandra Wintera0138f52020-04-16 15:08:41 +02001208 struct qeth_addr_change_data *data;
Eugene Crosser9f48b9d2014-01-14 15:54:13 +01001209 int extrasize;
1210
Alexandra Wintera0138f52020-04-16 15:08:41 +02001211 QETH_CARD_TEXT(card, 4, "adrchgev");
Eugene Crosser9f48b9d2014-01-14 15:54:13 +01001212 if (cmd->hdr.return_code != 0x0000) {
1213 if (cmd->hdr.return_code == 0x0010) {
1214 if (hostevs->lost_event_mask == 0x00)
1215 hostevs->lost_event_mask = 0xff;
1216 } else {
Alexandra Wintera0138f52020-04-16 15:08:41 +02001217 QETH_CARD_TEXT_(card, 2, "ACHN%04x",
Eugene Crosser9f48b9d2014-01-14 15:54:13 +01001218 cmd->hdr.return_code);
1219 return;
1220 }
1221 }
1222 extrasize = sizeof(struct qeth_ipacmd_addr_change_entry) *
1223 hostevs->num_entries;
Alexandra Wintera0138f52020-04-16 15:08:41 +02001224 data = kzalloc(sizeof(struct qeth_addr_change_data) + extrasize,
1225 GFP_ATOMIC);
Eugene Crosser9f48b9d2014-01-14 15:54:13 +01001226 if (!data) {
Alexandra Wintera0138f52020-04-16 15:08:41 +02001227 QETH_CARD_TEXT(card, 2, "ACNalloc");
Eugene Crosser9f48b9d2014-01-14 15:54:13 +01001228 return;
1229 }
Alexandra Wintera0138f52020-04-16 15:08:41 +02001230 INIT_WORK(&data->worker, qeth_addr_change_event_worker);
Eugene Crosser9f48b9d2014-01-14 15:54:13 +01001231 data->card = card;
Alexandra Wintera0138f52020-04-16 15:08:41 +02001232 memcpy(&data->ac_event, hostevs,
Eugene Crosser9f48b9d2014-01-14 15:54:13 +01001233 sizeof(struct qeth_ipacmd_addr_change) + extrasize);
Julian Wiedmannc0a2e4d2019-02-04 17:40:09 +01001234 queue_work(card->event_wq, &data->worker);
Eugene Crosser9f48b9d2014-01-14 15:54:13 +01001235}
Eugene Crosser9f48b9d2014-01-14 15:54:13 +01001236
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001237/* SETBRIDGEPORT support; sending commands */
1238
1239struct _qeth_sbp_cbctl {
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001240 union {
1241 u32 supported;
1242 struct {
1243 enum qeth_sbp_roles *role;
1244 enum qeth_sbp_states *state;
1245 } qports;
1246 } data;
1247};
1248
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001249static int qeth_bridgeport_makerc(struct qeth_card *card,
Julian Wiedmann1709ff82019-02-12 18:33:24 +01001250 struct qeth_ipa_cmd *cmd)
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001251{
Julian Wiedmann1709ff82019-02-12 18:33:24 +01001252 struct qeth_ipacmd_setbridgeport *sbp = &cmd->data.sbp;
1253 enum qeth_ipa_sbp_cmd setcmd = sbp->hdr.command_code;
1254 u16 ipa_rc = cmd->hdr.return_code;
1255 u16 sbp_rc = sbp->hdr.return_code;
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001256 int rc;
1257
Julian Wiedmann1709ff82019-02-12 18:33:24 +01001258 if (ipa_rc == IPA_RC_SUCCESS && sbp_rc == IPA_RC_SUCCESS)
1259 return 0;
1260
1261 if ((IS_IQD(card) && ipa_rc == IPA_RC_SUCCESS) ||
1262 (!IS_IQD(card) && ipa_rc == sbp_rc)) {
1263 switch (sbp_rc) {
Kittipon Meesompop2063a5f2017-06-20 16:00:31 +02001264 case IPA_RC_SUCCESS:
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001265 rc = 0;
1266 break;
Kittipon Meesompop2063a5f2017-06-20 16:00:31 +02001267 case IPA_RC_L2_UNSUPPORTED_CMD:
1268 case IPA_RC_UNSUPPORTED_COMMAND:
Eugene Crosserffb95252015-05-18 14:27:58 +02001269 rc = -EOPNOTSUPP;
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001270 break;
Kittipon Meesompop2063a5f2017-06-20 16:00:31 +02001271 case IPA_RC_SBP_OSA_NOT_CONFIGURED:
1272 case IPA_RC_SBP_IQD_NOT_CONFIGURED:
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001273 rc = -ENODEV; /* maybe not the best code here? */
1274 dev_err(&card->gdev->dev,
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001275 "The device is not configured as a Bridge Port\n");
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001276 break;
Kittipon Meesompop2063a5f2017-06-20 16:00:31 +02001277 case IPA_RC_SBP_OSA_OS_MISMATCH:
1278 case IPA_RC_SBP_IQD_OS_MISMATCH:
Eugene Crosser1b05cf62016-06-16 16:18:51 +02001279 rc = -EPERM;
1280 dev_err(&card->gdev->dev,
1281 "A Bridge Port is already configured by a different operating system\n");
1282 break;
Kittipon Meesompop2063a5f2017-06-20 16:00:31 +02001283 case IPA_RC_SBP_OSA_ANO_DEV_PRIMARY:
1284 case IPA_RC_SBP_IQD_ANO_DEV_PRIMARY:
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001285 switch (setcmd) {
1286 case IPA_SBP_SET_PRIMARY_BRIDGE_PORT:
1287 rc = -EEXIST;
1288 dev_err(&card->gdev->dev,
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001289 "The LAN already has a primary Bridge Port\n");
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001290 break;
1291 case IPA_SBP_SET_SECONDARY_BRIDGE_PORT:
1292 rc = -EBUSY;
1293 dev_err(&card->gdev->dev,
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001294 "The device is already a primary Bridge Port\n");
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001295 break;
1296 default:
1297 rc = -EIO;
1298 }
1299 break;
Kittipon Meesompop2063a5f2017-06-20 16:00:31 +02001300 case IPA_RC_SBP_OSA_CURRENT_SECOND:
1301 case IPA_RC_SBP_IQD_CURRENT_SECOND:
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001302 rc = -EBUSY;
1303 dev_err(&card->gdev->dev,
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001304 "The device is already a secondary Bridge Port\n");
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001305 break;
Kittipon Meesompop2063a5f2017-06-20 16:00:31 +02001306 case IPA_RC_SBP_OSA_LIMIT_SECOND:
1307 case IPA_RC_SBP_IQD_LIMIT_SECOND:
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001308 rc = -EEXIST;
1309 dev_err(&card->gdev->dev,
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001310 "The LAN cannot have more secondary Bridge Ports\n");
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001311 break;
Kittipon Meesompop2063a5f2017-06-20 16:00:31 +02001312 case IPA_RC_SBP_OSA_CURRENT_PRIMARY:
1313 case IPA_RC_SBP_IQD_CURRENT_PRIMARY:
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001314 rc = -EBUSY;
1315 dev_err(&card->gdev->dev,
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001316 "The device is already a primary Bridge Port\n");
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001317 break;
Kittipon Meesompop2063a5f2017-06-20 16:00:31 +02001318 case IPA_RC_SBP_OSA_NOT_AUTHD_BY_ZMAN:
1319 case IPA_RC_SBP_IQD_NOT_AUTHD_BY_ZMAN:
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001320 rc = -EACCES;
1321 dev_err(&card->gdev->dev,
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001322 "The device is not authorized to be a Bridge Port\n");
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001323 break;
1324 default:
1325 rc = -EIO;
1326 }
Julian Wiedmann1709ff82019-02-12 18:33:24 +01001327 } else {
1328 switch (ipa_rc) {
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001329 case IPA_RC_NOTSUPP:
Eugene Crosserffb95252015-05-18 14:27:58 +02001330 rc = -EOPNOTSUPP;
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001331 break;
1332 case IPA_RC_UNSUPPORTED_COMMAND:
Eugene Crosserffb95252015-05-18 14:27:58 +02001333 rc = -EOPNOTSUPP;
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001334 break;
1335 default:
1336 rc = -EIO;
1337 }
Julian Wiedmann1709ff82019-02-12 18:33:24 +01001338 }
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001339
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001340 if (rc) {
Julian Wiedmann1709ff82019-02-12 18:33:24 +01001341 QETH_CARD_TEXT_(card, 2, "SBPi%04x", ipa_rc);
1342 QETH_CARD_TEXT_(card, 2, "SBPc%04x", sbp_rc);
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001343 }
1344 return rc;
1345}
1346
Julian Wiedmannd65626a2017-08-15 17:02:47 +02001347static struct qeth_cmd_buffer *qeth_sbp_build_cmd(struct qeth_card *card,
1348 enum qeth_ipa_sbp_cmd sbp_cmd,
Julian Wiedmannb9150462019-06-27 17:01:24 +02001349 unsigned int data_length)
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001350{
Julian Wiedmann379ac992019-04-25 18:25:57 +02001351 enum qeth_ipa_cmds ipa_cmd = IS_IQD(card) ? IPA_CMD_SETBRIDGEPORT_IQD :
1352 IPA_CMD_SETBRIDGEPORT_OSA;
Julian Wiedmannb9150462019-06-27 17:01:24 +02001353 struct qeth_ipacmd_sbp_hdr *hdr;
Julian Wiedmannd65626a2017-08-15 17:02:47 +02001354 struct qeth_cmd_buffer *iob;
Julian Wiedmannd65626a2017-08-15 17:02:47 +02001355
Julian Wiedmannb9150462019-06-27 17:01:24 +02001356 iob = qeth_ipa_alloc_cmd(card, ipa_cmd, QETH_PROT_NONE,
1357 data_length +
1358 offsetof(struct qeth_ipacmd_setbridgeport,
1359 data));
Julian Wiedmannd65626a2017-08-15 17:02:47 +02001360 if (!iob)
1361 return iob;
Julian Wiedmannb9150462019-06-27 17:01:24 +02001362
1363 hdr = &__ipa_cmd(iob)->data.sbp.hdr;
1364 hdr->cmdlength = sizeof(*hdr) + data_length;
1365 hdr->command_code = sbp_cmd;
1366 hdr->used_total = 1;
1367 hdr->seq_no = 1;
Julian Wiedmannd65626a2017-08-15 17:02:47 +02001368 return iob;
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001369}
1370
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001371static int qeth_bridgeport_query_support_cb(struct qeth_card *card,
1372 struct qeth_reply *reply, unsigned long data)
1373{
1374 struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *) data;
1375 struct _qeth_sbp_cbctl *cbctl = (struct _qeth_sbp_cbctl *)reply->param;
Julian Wiedmann1709ff82019-02-12 18:33:24 +01001376 int rc;
1377
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001378 QETH_CARD_TEXT(card, 2, "brqsupcb");
Julian Wiedmann1709ff82019-02-12 18:33:24 +01001379 rc = qeth_bridgeport_makerc(card, cmd);
1380 if (rc)
1381 return rc;
1382
1383 cbctl->data.supported =
1384 cmd->data.sbp.data.query_cmds_supp.supported_cmds;
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001385 return 0;
1386}
1387
1388/**
1389 * qeth_bridgeport_query_support() - store bitmask of supported subfunctions.
1390 * @card: qeth_card structure pointer.
1391 *
1392 * Sets bitmask of supported setbridgeport subfunctions in the qeth_card
1393 * strucutre: card->options.sbp.supported_funcs.
1394 */
Eugene Crosserc044dc22014-01-29 09:23:48 +01001395static void qeth_bridgeport_query_support(struct qeth_card *card)
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001396{
1397 struct qeth_cmd_buffer *iob;
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001398 struct _qeth_sbp_cbctl cbctl;
1399
1400 QETH_CARD_TEXT(card, 2, "brqsuppo");
Julian Wiedmannd65626a2017-08-15 17:02:47 +02001401 iob = qeth_sbp_build_cmd(card, IPA_SBP_QUERY_COMMANDS_SUPPORTED,
Julian Wiedmannb9150462019-06-27 17:01:24 +02001402 SBP_DATA_SIZEOF(query_cmds_supp));
Thomas Richter1aec42b2015-01-21 13:39:10 +01001403 if (!iob)
1404 return;
Julian Wiedmann1709ff82019-02-12 18:33:24 +01001405
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001406 if (qeth_send_ipa_cmd(card, iob, qeth_bridgeport_query_support_cb,
Julian Wiedmann1709ff82019-02-12 18:33:24 +01001407 &cbctl)) {
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001408 card->options.sbp.role = QETH_SBP_ROLE_NONE;
Julian Wiedmann1709ff82019-02-12 18:33:24 +01001409 card->options.sbp.supported_funcs = 0;
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001410 return;
1411 }
1412 card->options.sbp.supported_funcs = cbctl.data.supported;
1413}
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001414
1415static int qeth_bridgeport_query_ports_cb(struct qeth_card *card,
1416 struct qeth_reply *reply, unsigned long data)
1417{
1418 struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *) data;
1419 struct qeth_sbp_query_ports *qports = &cmd->data.sbp.data.query_ports;
1420 struct _qeth_sbp_cbctl *cbctl = (struct _qeth_sbp_cbctl *)reply->param;
Julian Wiedmann1709ff82019-02-12 18:33:24 +01001421 int rc;
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001422
1423 QETH_CARD_TEXT(card, 2, "brqprtcb");
Julian Wiedmann1709ff82019-02-12 18:33:24 +01001424 rc = qeth_bridgeport_makerc(card, cmd);
1425 if (rc)
1426 return rc;
1427
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001428 if (qports->entry_length != sizeof(struct qeth_sbp_port_entry)) {
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001429 QETH_CARD_TEXT_(card, 2, "SBPs%04x", qports->entry_length);
Julian Wiedmann1709ff82019-02-12 18:33:24 +01001430 return -EINVAL;
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001431 }
1432 /* first entry contains the state of the local port */
1433 if (qports->num_entries > 0) {
1434 if (cbctl->data.qports.role)
1435 *cbctl->data.qports.role = qports->entry[0].role;
1436 if (cbctl->data.qports.state)
1437 *cbctl->data.qports.state = qports->entry[0].state;
1438 }
1439 return 0;
1440}
1441
1442/**
1443 * qeth_bridgeport_query_ports() - query local bridgeport status.
1444 * @card: qeth_card structure pointer.
1445 * @role: Role of the port: 0-none, 1-primary, 2-secondary.
1446 * @state: State of the port: 0-inactive, 1-standby, 2-active.
1447 *
1448 * Returns negative errno-compatible error indication or 0 on success.
1449 *
1450 * 'role' and 'state' are not updated in case of hardware operation failure.
1451 */
1452int qeth_bridgeport_query_ports(struct qeth_card *card,
1453 enum qeth_sbp_roles *role, enum qeth_sbp_states *state)
1454{
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001455 struct qeth_cmd_buffer *iob;
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001456 struct _qeth_sbp_cbctl cbctl = {
1457 .data = {
1458 .qports = {
1459 .role = role,
1460 .state = state,
1461 },
1462 },
1463 };
1464
1465 QETH_CARD_TEXT(card, 2, "brqports");
1466 if (!(card->options.sbp.supported_funcs & IPA_SBP_QUERY_BRIDGE_PORTS))
1467 return -EOPNOTSUPP;
Julian Wiedmannd65626a2017-08-15 17:02:47 +02001468 iob = qeth_sbp_build_cmd(card, IPA_SBP_QUERY_BRIDGE_PORTS, 0);
Thomas Richter1aec42b2015-01-21 13:39:10 +01001469 if (!iob)
1470 return -ENOMEM;
Julian Wiedmann1709ff82019-02-12 18:33:24 +01001471
1472 return qeth_send_ipa_cmd(card, iob, qeth_bridgeport_query_ports_cb,
1473 &cbctl);
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001474}
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001475
1476static int qeth_bridgeport_set_cb(struct qeth_card *card,
1477 struct qeth_reply *reply, unsigned long data)
1478{
1479 struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *)data;
Julian Wiedmann1709ff82019-02-12 18:33:24 +01001480
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001481 QETH_CARD_TEXT(card, 2, "brsetrcb");
Julian Wiedmann1709ff82019-02-12 18:33:24 +01001482 return qeth_bridgeport_makerc(card, cmd);
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001483}
1484
1485/**
1486 * qeth_bridgeport_setrole() - Assign primary role to the port.
1487 * @card: qeth_card structure pointer.
1488 * @role: Role to assign.
1489 *
1490 * Returns negative errno-compatible error indication or 0 on success.
1491 */
1492int qeth_bridgeport_setrole(struct qeth_card *card, enum qeth_sbp_roles role)
1493{
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001494 struct qeth_cmd_buffer *iob;
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001495 enum qeth_ipa_sbp_cmd setcmd;
Julian Wiedmannb9150462019-06-27 17:01:24 +02001496 unsigned int cmdlength = 0;
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001497
1498 QETH_CARD_TEXT(card, 2, "brsetrol");
1499 switch (role) {
1500 case QETH_SBP_ROLE_NONE:
1501 setcmd = IPA_SBP_RESET_BRIDGE_PORT_ROLE;
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001502 break;
1503 case QETH_SBP_ROLE_PRIMARY:
1504 setcmd = IPA_SBP_SET_PRIMARY_BRIDGE_PORT;
Julian Wiedmannb9150462019-06-27 17:01:24 +02001505 cmdlength = SBP_DATA_SIZEOF(set_primary);
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001506 break;
1507 case QETH_SBP_ROLE_SECONDARY:
1508 setcmd = IPA_SBP_SET_SECONDARY_BRIDGE_PORT;
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001509 break;
1510 default:
1511 return -EINVAL;
1512 }
1513 if (!(card->options.sbp.supported_funcs & setcmd))
1514 return -EOPNOTSUPP;
Julian Wiedmannd65626a2017-08-15 17:02:47 +02001515 iob = qeth_sbp_build_cmd(card, setcmd, cmdlength);
Thomas Richter1aec42b2015-01-21 13:39:10 +01001516 if (!iob)
1517 return -ENOMEM;
Julian Wiedmann1709ff82019-02-12 18:33:24 +01001518
1519 return qeth_send_ipa_cmd(card, iob, qeth_bridgeport_set_cb, NULL);
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001520}
1521
Eugene Crosser9f48b9d2014-01-14 15:54:13 +01001522static void qeth_bridgeport_an_set_cb(void *priv,
Alexandra Wintera0138f52020-04-16 15:08:41 +02001523 struct chsc_pnso_naid_l2 *entry)
Eugene Crosser9f48b9d2014-01-14 15:54:13 +01001524{
1525 struct qeth_card *card = (struct qeth_card *)priv;
Eugene Crosser9f48b9d2014-01-14 15:54:13 +01001526 u8 code;
1527
Eugene Crosser9f48b9d2014-01-14 15:54:13 +01001528 code = IPA_ADDR_CHANGE_CODE_MACADDR;
Alexandra Wintera0138f52020-04-16 15:08:41 +02001529 if (entry->addr_lnid.lnid < VLAN_N_VID)
Eugene Crosser9f48b9d2014-01-14 15:54:13 +01001530 code |= IPA_ADDR_CHANGE_CODE_VLANID;
1531 qeth_bridge_emit_host_event(card, anev_reg_unreg, code,
Alexandra Wintera0138f52020-04-16 15:08:41 +02001532 (struct net_if_token *)&entry->nit,
1533 (struct mac_addr_lnid *)&entry->addr_lnid);
Eugene Crosser9f48b9d2014-01-14 15:54:13 +01001534}
1535
1536/**
1537 * qeth_bridgeport_an_set() - Enable or disable bridgeport address notification
1538 * @card: qeth_card structure pointer.
1539 * @enable: 0 - disable, non-zero - enable notifications
1540 *
1541 * Returns negative errno-compatible error indication or 0 on success.
1542 *
1543 * On enable, emits a series of address notifications udev events for all
1544 * currently registered hosts.
1545 */
1546int qeth_bridgeport_an_set(struct qeth_card *card, int enable)
1547{
1548 int rc;
Eugene Crosser9f48b9d2014-01-14 15:54:13 +01001549
Eugene Crosser9f48b9d2014-01-14 15:54:13 +01001550 if (!card->options.sbp.supported_funcs)
1551 return -EOPNOTSUPP;
Eugene Crosser9f48b9d2014-01-14 15:54:13 +01001552
1553 if (enable) {
1554 qeth_bridge_emit_host_event(card, anev_reset, 0, NULL, NULL);
Alexandra Wintera0138f52020-04-16 15:08:41 +02001555 rc = qeth_l2_pnso(card, 1, qeth_bridgeport_an_set_cb, card);
Eugene Crosser9f48b9d2014-01-14 15:54:13 +01001556 } else
Alexandra Wintera0138f52020-04-16 15:08:41 +02001557 rc = qeth_l2_pnso(card, 0, NULL, NULL);
1558 return rc;
Eugene Crosser9f48b9d2014-01-14 15:54:13 +01001559}
Eugene Crosser9f48b9d2014-01-14 15:54:13 +01001560
Hans Wippelcaa1f0b2017-09-18 21:18:15 +02001561static bool qeth_bridgeport_is_in_use(struct qeth_card *card)
1562{
1563 return (card->options.sbp.role || card->options.sbp.reflect_promisc ||
1564 card->options.sbp.hostnotification);
1565}
1566
Hans Wippela45b3fa2017-09-18 21:18:14 +02001567/* VNIC Characteristics support */
1568
1569/* handle VNICC IPA command return codes; convert to error codes */
Julian Wiedmann742d4d42019-02-12 18:33:25 +01001570static int qeth_l2_vnicc_makerc(struct qeth_card *card, u16 ipa_rc)
Hans Wippela45b3fa2017-09-18 21:18:14 +02001571{
1572 int rc;
1573
1574 switch (ipa_rc) {
1575 case IPA_RC_SUCCESS:
1576 return ipa_rc;
1577 case IPA_RC_L2_UNSUPPORTED_CMD:
1578 case IPA_RC_NOTSUPP:
1579 rc = -EOPNOTSUPP;
1580 break;
1581 case IPA_RC_VNICC_OOSEQ:
1582 rc = -EALREADY;
1583 break;
1584 case IPA_RC_VNICC_VNICBP:
1585 rc = -EBUSY;
1586 break;
1587 case IPA_RC_L2_ADDR_TABLE_FULL:
1588 rc = -ENOSPC;
1589 break;
1590 case IPA_RC_L2_MAC_NOT_AUTH_BY_ADP:
1591 rc = -EACCES;
1592 break;
1593 default:
1594 rc = -EIO;
1595 }
1596
1597 QETH_CARD_TEXT_(card, 2, "err%04x", ipa_rc);
1598 return rc;
1599}
1600
Hans Wippela45b3fa2017-09-18 21:18:14 +02001601/* generic VNICC request call back */
1602static int qeth_l2_vnicc_request_cb(struct qeth_card *card,
1603 struct qeth_reply *reply,
1604 unsigned long data)
1605{
1606 struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *) data;
1607 struct qeth_ipacmd_vnicc *rep = &cmd->data.vnicc;
Julian Wiedmann2744d812019-08-20 16:46:40 +02001608 u32 sub_cmd = cmd->data.vnicc.hdr.sub_command;
Hans Wippela45b3fa2017-09-18 21:18:14 +02001609
1610 QETH_CARD_TEXT(card, 2, "vniccrcb");
1611 if (cmd->hdr.return_code)
Julian Wiedmann742d4d42019-02-12 18:33:25 +01001612 return qeth_l2_vnicc_makerc(card, cmd->hdr.return_code);
Hans Wippela45b3fa2017-09-18 21:18:14 +02001613 /* return results to caller */
Julian Wiedmann2cfb4812019-06-27 17:01:26 +02001614 card->options.vnicc.sup_chars = rep->vnicc_cmds.supported;
1615 card->options.vnicc.cur_chars = rep->vnicc_cmds.enabled;
Hans Wippela45b3fa2017-09-18 21:18:14 +02001616
Julian Wiedmann2744d812019-08-20 16:46:40 +02001617 if (sub_cmd == IPA_VNICC_QUERY_CMDS)
Julian Wiedmann49f42f52020-03-06 09:13:11 +01001618 *(u32 *)reply->param = rep->data.query_cmds.sup_cmds;
Julian Wiedmann2744d812019-08-20 16:46:40 +02001619 else if (sub_cmd == IPA_VNICC_GET_TIMEOUT)
Julian Wiedmann49f42f52020-03-06 09:13:11 +01001620 *(u32 *)reply->param = rep->data.getset_timeout.timeout;
Hans Wippel349d13d2017-09-18 21:18:16 +02001621
Hans Wippela45b3fa2017-09-18 21:18:14 +02001622 return 0;
1623}
1624
Julian Wiedmann2cfb4812019-06-27 17:01:26 +02001625static struct qeth_cmd_buffer *qeth_l2_vnicc_build_cmd(struct qeth_card *card,
1626 u32 vnicc_cmd,
1627 unsigned int data_length)
Hans Wippela45b3fa2017-09-18 21:18:14 +02001628{
Julian Wiedmann2cfb4812019-06-27 17:01:26 +02001629 struct qeth_ipacmd_vnicc_hdr *hdr;
Hans Wippela45b3fa2017-09-18 21:18:14 +02001630 struct qeth_cmd_buffer *iob;
Hans Wippela45b3fa2017-09-18 21:18:14 +02001631
Julian Wiedmann2cfb4812019-06-27 17:01:26 +02001632 iob = qeth_ipa_alloc_cmd(card, IPA_CMD_VNICC, QETH_PROT_NONE,
1633 data_length +
1634 offsetof(struct qeth_ipacmd_vnicc, data));
Hans Wippela45b3fa2017-09-18 21:18:14 +02001635 if (!iob)
Julian Wiedmann2cfb4812019-06-27 17:01:26 +02001636 return NULL;
Hans Wippela45b3fa2017-09-18 21:18:14 +02001637
Julian Wiedmann2cfb4812019-06-27 17:01:26 +02001638 hdr = &__ipa_cmd(iob)->data.vnicc.hdr;
1639 hdr->data_length = sizeof(*hdr) + data_length;
1640 hdr->sub_command = vnicc_cmd;
1641 return iob;
Hans Wippela45b3fa2017-09-18 21:18:14 +02001642}
1643
1644/* VNICC query VNIC characteristics request */
1645static int qeth_l2_vnicc_query_chars(struct qeth_card *card)
1646{
Julian Wiedmann2cfb4812019-06-27 17:01:26 +02001647 struct qeth_cmd_buffer *iob;
1648
1649 QETH_CARD_TEXT(card, 2, "vniccqch");
1650 iob = qeth_l2_vnicc_build_cmd(card, IPA_VNICC_QUERY_CHARS, 0);
1651 if (!iob)
1652 return -ENOMEM;
Hans Wippela45b3fa2017-09-18 21:18:14 +02001653
Julian Wiedmann2744d812019-08-20 16:46:40 +02001654 return qeth_send_ipa_cmd(card, iob, qeth_l2_vnicc_request_cb, NULL);
Hans Wippela45b3fa2017-09-18 21:18:14 +02001655}
1656
Hans Wippelcaa1f0b2017-09-18 21:18:15 +02001657/* VNICC query sub commands request */
1658static int qeth_l2_vnicc_query_cmds(struct qeth_card *card, u32 vnic_char,
1659 u32 *sup_cmds)
1660{
Julian Wiedmann2cfb4812019-06-27 17:01:26 +02001661 struct qeth_cmd_buffer *iob;
1662
1663 QETH_CARD_TEXT(card, 2, "vniccqcm");
1664 iob = qeth_l2_vnicc_build_cmd(card, IPA_VNICC_QUERY_CMDS,
1665 VNICC_DATA_SIZEOF(query_cmds));
1666 if (!iob)
1667 return -ENOMEM;
1668
1669 __ipa_cmd(iob)->data.vnicc.data.query_cmds.vnic_char = vnic_char;
Hans Wippelcaa1f0b2017-09-18 21:18:15 +02001670
Julian Wiedmann49f42f52020-03-06 09:13:11 +01001671 return qeth_send_ipa_cmd(card, iob, qeth_l2_vnicc_request_cb, sup_cmds);
Hans Wippelcaa1f0b2017-09-18 21:18:15 +02001672}
1673
1674/* VNICC enable/disable characteristic request */
1675static int qeth_l2_vnicc_set_char(struct qeth_card *card, u32 vnic_char,
1676 u32 cmd)
1677{
Julian Wiedmann2cfb4812019-06-27 17:01:26 +02001678 struct qeth_cmd_buffer *iob;
1679
1680 QETH_CARD_TEXT(card, 2, "vniccedc");
1681 iob = qeth_l2_vnicc_build_cmd(card, cmd, VNICC_DATA_SIZEOF(set_char));
1682 if (!iob)
1683 return -ENOMEM;
1684
1685 __ipa_cmd(iob)->data.vnicc.data.set_char.vnic_char = vnic_char;
Hans Wippelcaa1f0b2017-09-18 21:18:15 +02001686
Julian Wiedmann2744d812019-08-20 16:46:40 +02001687 return qeth_send_ipa_cmd(card, iob, qeth_l2_vnicc_request_cb, NULL);
Hans Wippelcaa1f0b2017-09-18 21:18:15 +02001688}
1689
Hans Wippel349d13d2017-09-18 21:18:16 +02001690/* VNICC get/set timeout for characteristic request */
1691static int qeth_l2_vnicc_getset_timeout(struct qeth_card *card, u32 vnicc,
1692 u32 cmd, u32 *timeout)
1693{
Julian Wiedmann2cfb4812019-06-27 17:01:26 +02001694 struct qeth_vnicc_getset_timeout *getset_timeout;
Julian Wiedmann2cfb4812019-06-27 17:01:26 +02001695 struct qeth_cmd_buffer *iob;
1696
1697 QETH_CARD_TEXT(card, 2, "vniccgst");
1698 iob = qeth_l2_vnicc_build_cmd(card, cmd,
1699 VNICC_DATA_SIZEOF(getset_timeout));
1700 if (!iob)
1701 return -ENOMEM;
1702
1703 getset_timeout = &__ipa_cmd(iob)->data.vnicc.data.getset_timeout;
1704 getset_timeout->vnic_char = vnicc;
1705
1706 if (cmd == IPA_VNICC_SET_TIMEOUT)
1707 getset_timeout->timeout = *timeout;
Hans Wippel349d13d2017-09-18 21:18:16 +02001708
Julian Wiedmann49f42f52020-03-06 09:13:11 +01001709 return qeth_send_ipa_cmd(card, iob, qeth_l2_vnicc_request_cb, timeout);
Hans Wippel349d13d2017-09-18 21:18:16 +02001710}
1711
Hans Wippelcaa1f0b2017-09-18 21:18:15 +02001712/* set current VNICC flag state; called from sysfs store function */
1713int qeth_l2_vnicc_set_state(struct qeth_card *card, u32 vnicc, bool state)
1714{
1715 int rc = 0;
1716 u32 cmd;
1717
1718 QETH_CARD_TEXT(card, 2, "vniccsch");
1719
Hans Wippelcaa1f0b2017-09-18 21:18:15 +02001720 /* check if characteristic and enable/disable are supported */
1721 if (!(card->options.vnicc.sup_chars & vnicc) ||
1722 !(card->options.vnicc.set_char_sup & vnicc))
1723 return -EOPNOTSUPP;
1724
Alexandra Winter6f3846f2020-02-20 15:54:54 +01001725 if (qeth_bridgeport_is_in_use(card))
1726 return -EBUSY;
1727
Hans Wippelcaa1f0b2017-09-18 21:18:15 +02001728 /* set enable/disable command and store wanted characteristic */
1729 if (state) {
1730 cmd = IPA_VNICC_ENABLE;
1731 card->options.vnicc.wanted_chars |= vnicc;
1732 } else {
1733 cmd = IPA_VNICC_DISABLE;
1734 card->options.vnicc.wanted_chars &= ~vnicc;
1735 }
1736
1737 /* do we need to do anything? */
1738 if (card->options.vnicc.cur_chars == card->options.vnicc.wanted_chars)
1739 return rc;
1740
1741 /* if card is not ready, simply stop here */
1742 if (!qeth_card_hw_is_reachable(card)) {
1743 if (state)
1744 card->options.vnicc.cur_chars |= vnicc;
1745 else
1746 card->options.vnicc.cur_chars &= ~vnicc;
1747 return rc;
1748 }
1749
1750 rc = qeth_l2_vnicc_set_char(card, vnicc, cmd);
1751 if (rc)
1752 card->options.vnicc.wanted_chars =
1753 card->options.vnicc.cur_chars;
Hans Wippel349d13d2017-09-18 21:18:16 +02001754 else {
1755 /* successful online VNICC change; handle special cases */
1756 if (state && vnicc == QETH_VNICC_RX_BCAST)
1757 card->options.vnicc.rx_bcast_enabled = true;
1758 if (!state && vnicc == QETH_VNICC_LEARNING)
1759 qeth_l2_vnicc_recover_timeout(card, vnicc,
1760 &card->options.vnicc.learning_timeout);
1761 }
Hans Wippelcaa1f0b2017-09-18 21:18:15 +02001762
1763 return rc;
1764}
1765
1766/* get current VNICC flag state; called from sysfs show function */
1767int qeth_l2_vnicc_get_state(struct qeth_card *card, u32 vnicc, bool *state)
1768{
1769 int rc = 0;
1770
1771 QETH_CARD_TEXT(card, 2, "vniccgch");
1772
Hans Wippelcaa1f0b2017-09-18 21:18:15 +02001773 /* check if characteristic is supported */
1774 if (!(card->options.vnicc.sup_chars & vnicc))
1775 return -EOPNOTSUPP;
1776
Alexandra Winter6f3846f2020-02-20 15:54:54 +01001777 if (qeth_bridgeport_is_in_use(card))
1778 return -EBUSY;
1779
Hans Wippelcaa1f0b2017-09-18 21:18:15 +02001780 /* if card is ready, query current VNICC state */
1781 if (qeth_card_hw_is_reachable(card))
1782 rc = qeth_l2_vnicc_query_chars(card);
1783
1784 *state = (card->options.vnicc.cur_chars & vnicc) ? true : false;
1785 return rc;
1786}
1787
Hans Wippel349d13d2017-09-18 21:18:16 +02001788/* set VNICC timeout; called from sysfs store function. Currently, only learning
1789 * supports timeout
1790 */
1791int qeth_l2_vnicc_set_timeout(struct qeth_card *card, u32 timeout)
1792{
1793 int rc = 0;
1794
1795 QETH_CARD_TEXT(card, 2, "vniccsto");
1796
Hans Wippel349d13d2017-09-18 21:18:16 +02001797 /* check if characteristic and set_timeout are supported */
1798 if (!(card->options.vnicc.sup_chars & QETH_VNICC_LEARNING) ||
1799 !(card->options.vnicc.getset_timeout_sup & QETH_VNICC_LEARNING))
1800 return -EOPNOTSUPP;
1801
Alexandra Winter6f3846f2020-02-20 15:54:54 +01001802 if (qeth_bridgeport_is_in_use(card))
1803 return -EBUSY;
1804
Hans Wippel349d13d2017-09-18 21:18:16 +02001805 /* do we need to do anything? */
1806 if (card->options.vnicc.learning_timeout == timeout)
1807 return rc;
1808
1809 /* if card is not ready, simply store the value internally and return */
1810 if (!qeth_card_hw_is_reachable(card)) {
1811 card->options.vnicc.learning_timeout = timeout;
1812 return rc;
1813 }
1814
1815 /* send timeout value to card; if successful, store value internally */
1816 rc = qeth_l2_vnicc_getset_timeout(card, QETH_VNICC_LEARNING,
1817 IPA_VNICC_SET_TIMEOUT, &timeout);
1818 if (!rc)
1819 card->options.vnicc.learning_timeout = timeout;
1820
1821 return rc;
1822}
1823
1824/* get current VNICC timeout; called from sysfs show function. Currently, only
1825 * learning supports timeout
1826 */
1827int qeth_l2_vnicc_get_timeout(struct qeth_card *card, u32 *timeout)
1828{
1829 int rc = 0;
1830
1831 QETH_CARD_TEXT(card, 2, "vniccgto");
1832
Hans Wippel349d13d2017-09-18 21:18:16 +02001833 /* check if characteristic and get_timeout are supported */
1834 if (!(card->options.vnicc.sup_chars & QETH_VNICC_LEARNING) ||
1835 !(card->options.vnicc.getset_timeout_sup & QETH_VNICC_LEARNING))
1836 return -EOPNOTSUPP;
Alexandra Winter6f3846f2020-02-20 15:54:54 +01001837
1838 if (qeth_bridgeport_is_in_use(card))
1839 return -EBUSY;
1840
Hans Wippel349d13d2017-09-18 21:18:16 +02001841 /* if card is ready, get timeout. Otherwise, just return stored value */
1842 *timeout = card->options.vnicc.learning_timeout;
1843 if (qeth_card_hw_is_reachable(card))
1844 rc = qeth_l2_vnicc_getset_timeout(card, QETH_VNICC_LEARNING,
1845 IPA_VNICC_GET_TIMEOUT,
1846 timeout);
1847
1848 return rc;
1849}
1850
Hans Wippelcaa1f0b2017-09-18 21:18:15 +02001851/* check if VNICC is currently enabled */
1852bool qeth_l2_vnicc_is_in_use(struct qeth_card *card)
1853{
Alexandra Wintere8a66d82019-12-23 15:03:24 +01001854 if (!card->options.vnicc.sup_chars)
Hans Wippelcaa1f0b2017-09-18 21:18:15 +02001855 return false;
1856 /* default values are only OK if rx_bcast was not enabled by user
1857 * or the card is offline.
1858 */
1859 if (card->options.vnicc.cur_chars == QETH_VNICC_DEFAULT) {
1860 if (!card->options.vnicc.rx_bcast_enabled ||
1861 !qeth_card_hw_is_reachable(card))
1862 return false;
1863 }
1864 return true;
1865}
1866
Hans Wippel349d13d2017-09-18 21:18:16 +02001867/* recover user timeout setting */
1868static bool qeth_l2_vnicc_recover_timeout(struct qeth_card *card, u32 vnicc,
1869 u32 *timeout)
1870{
1871 if (card->options.vnicc.sup_chars & vnicc &&
1872 card->options.vnicc.getset_timeout_sup & vnicc &&
1873 !qeth_l2_vnicc_getset_timeout(card, vnicc, IPA_VNICC_SET_TIMEOUT,
1874 timeout))
1875 return false;
1876 *timeout = QETH_VNICC_DEFAULT_TIMEOUT;
1877 return true;
1878}
1879
Hans Wippelcaa1f0b2017-09-18 21:18:15 +02001880/* recover user characteristic setting */
1881static bool qeth_l2_vnicc_recover_char(struct qeth_card *card, u32 vnicc,
1882 bool enable)
1883{
1884 u32 cmd = enable ? IPA_VNICC_ENABLE : IPA_VNICC_DISABLE;
1885
1886 if (card->options.vnicc.sup_chars & vnicc &&
1887 card->options.vnicc.set_char_sup & vnicc &&
1888 !qeth_l2_vnicc_set_char(card, vnicc, cmd))
1889 return false;
1890 card->options.vnicc.wanted_chars &= ~vnicc;
1891 card->options.vnicc.wanted_chars |= QETH_VNICC_DEFAULT & vnicc;
1892 return true;
1893}
1894
Hans Wippela45b3fa2017-09-18 21:18:14 +02001895/* (re-)initialize VNICC */
1896static void qeth_l2_vnicc_init(struct qeth_card *card)
1897{
Hans Wippel349d13d2017-09-18 21:18:16 +02001898 u32 *timeout = &card->options.vnicc.learning_timeout;
Alexandra Winterb5289652019-10-08 18:21:06 +02001899 bool enable, error = false;
Hans Wippelcaa1f0b2017-09-18 21:18:15 +02001900 unsigned int chars_len, i;
1901 unsigned long chars_tmp;
1902 u32 sup_cmds, vnicc;
Hans Wippelcaa1f0b2017-09-18 21:18:15 +02001903
Hans Wippela45b3fa2017-09-18 21:18:14 +02001904 QETH_CARD_TEXT(card, 2, "vniccini");
Hans Wippelcaa1f0b2017-09-18 21:18:15 +02001905 /* reset rx_bcast */
1906 card->options.vnicc.rx_bcast_enabled = 0;
Hans Wippela45b3fa2017-09-18 21:18:14 +02001907 /* initial query and storage of VNIC characteristics */
1908 if (qeth_l2_vnicc_query_chars(card)) {
Hans Wippel349d13d2017-09-18 21:18:16 +02001909 if (card->options.vnicc.wanted_chars != QETH_VNICC_DEFAULT ||
1910 *timeout != QETH_VNICC_DEFAULT_TIMEOUT)
Hans Wippelcaa1f0b2017-09-18 21:18:15 +02001911 dev_err(&card->gdev->dev, "Configuring the VNIC characteristics failed\n");
1912 /* fail quietly if user didn't change the default config */
Hans Wippela45b3fa2017-09-18 21:18:14 +02001913 card->options.vnicc.sup_chars = 0;
1914 card->options.vnicc.cur_chars = 0;
Hans Wippelcaa1f0b2017-09-18 21:18:15 +02001915 card->options.vnicc.wanted_chars = QETH_VNICC_DEFAULT;
1916 return;
Hans Wippela45b3fa2017-09-18 21:18:14 +02001917 }
Hans Wippelcaa1f0b2017-09-18 21:18:15 +02001918 /* get supported commands for each supported characteristic */
1919 chars_tmp = card->options.vnicc.sup_chars;
1920 chars_len = sizeof(card->options.vnicc.sup_chars) * BITS_PER_BYTE;
1921 for_each_set_bit(i, &chars_tmp, chars_len) {
1922 vnicc = BIT(i);
Alexandra Winterb5289652019-10-08 18:21:06 +02001923 if (qeth_l2_vnicc_query_cmds(card, vnicc, &sup_cmds)) {
1924 sup_cmds = 0;
1925 error = true;
1926 }
Alexandra Winterbe40a862019-10-08 18:21:07 +02001927 if ((sup_cmds & IPA_VNICC_SET_TIMEOUT) &&
1928 (sup_cmds & IPA_VNICC_GET_TIMEOUT))
1929 card->options.vnicc.getset_timeout_sup |= vnicc;
1930 else
Hans Wippel349d13d2017-09-18 21:18:16 +02001931 card->options.vnicc.getset_timeout_sup &= ~vnicc;
Alexandra Winterbe40a862019-10-08 18:21:07 +02001932 if ((sup_cmds & IPA_VNICC_ENABLE) &&
1933 (sup_cmds & IPA_VNICC_DISABLE))
1934 card->options.vnicc.set_char_sup |= vnicc;
1935 else
Hans Wippelcaa1f0b2017-09-18 21:18:15 +02001936 card->options.vnicc.set_char_sup &= ~vnicc;
1937 }
1938 /* enforce assumed default values and recover settings, if changed */
Alexandra Winterb5289652019-10-08 18:21:06 +02001939 error |= qeth_l2_vnicc_recover_timeout(card, QETH_VNICC_LEARNING,
1940 timeout);
Alexandra Winterd1b9ae12019-12-23 15:03:25 +01001941 /* Change chars, if necessary */
1942 chars_tmp = card->options.vnicc.wanted_chars ^
1943 card->options.vnicc.cur_chars;
Hans Wippelcaa1f0b2017-09-18 21:18:15 +02001944 chars_len = sizeof(card->options.vnicc.wanted_chars) * BITS_PER_BYTE;
1945 for_each_set_bit(i, &chars_tmp, chars_len) {
1946 vnicc = BIT(i);
1947 enable = card->options.vnicc.wanted_chars & vnicc;
1948 error |= qeth_l2_vnicc_recover_char(card, vnicc, enable);
1949 }
1950 if (error)
1951 dev_err(&card->gdev->dev, "Configuring the VNIC characteristics failed\n");
1952}
1953
1954/* configure default values of VNIC characteristics */
1955static void qeth_l2_vnicc_set_defaults(struct qeth_card *card)
1956{
1957 /* characteristics values */
1958 card->options.vnicc.sup_chars = QETH_VNICC_ALL;
1959 card->options.vnicc.cur_chars = QETH_VNICC_DEFAULT;
Hans Wippel349d13d2017-09-18 21:18:16 +02001960 card->options.vnicc.learning_timeout = QETH_VNICC_DEFAULT_TIMEOUT;
Hans Wippelcaa1f0b2017-09-18 21:18:15 +02001961 /* supported commands */
1962 card->options.vnicc.set_char_sup = QETH_VNICC_ALL;
Hans Wippel349d13d2017-09-18 21:18:16 +02001963 card->options.vnicc.getset_timeout_sup = QETH_VNICC_LEARNING;
Hans Wippelcaa1f0b2017-09-18 21:18:15 +02001964 /* settings wanted by users */
1965 card->options.vnicc.wanted_chars = QETH_VNICC_DEFAULT;
Hans Wippela45b3fa2017-09-18 21:18:14 +02001966}
1967
Frank Blaschka4a71df52008-02-15 09:19:42 +01001968module_init(qeth_l2_init);
1969module_exit(qeth_l2_exit);
1970MODULE_AUTHOR("Frank Blaschka <frank.blaschka@de.ibm.com>");
1971MODULE_DESCRIPTION("qeth layer 2 discipline");
1972MODULE_LICENSE("GPL");