blob: 368fb85d88514a9b2079b4a243dbd0246336c290 [file] [log] [blame]
Frank Blaschka4a71df52008-02-15 09:19:42 +01001/*
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02002 * Copyright IBM Corp. 2007, 2009
Frank Blaschka4a71df52008-02-15 09:19:42 +01003 * Author(s): Utz Bacher <utz.bacher@de.ibm.com>,
4 * Frank Pavlic <fpavlic@de.ibm.com>,
5 * Thomas Spatzier <tspat@de.ibm.com>,
6 * Frank Blaschka <frank.blaschka@de.ibm.com>
7 */
8
Frank Blaschka74eacdb2008-12-25 13:39:49 +01009#define KMSG_COMPONENT "qeth"
10#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
11
Frank Blaschka4a71df52008-02-15 09:19:42 +010012#include <linux/module.h>
13#include <linux/moduleparam.h>
14#include <linux/string.h>
15#include <linux/errno.h>
16#include <linux/kernel.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090017#include <linux/slab.h>
Frank Blaschka4a71df52008-02-15 09:19:42 +010018#include <linux/etherdevice.h>
Frank Blaschka4a71df52008-02-15 09:19:42 +010019#include <linux/ip.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>
23#include <linux/string.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
Frank Blaschka4a71df52008-02-15 09:19:42 +010028static int qeth_l2_set_offline(struct ccwgroup_device *);
29static int qeth_l2_stop(struct net_device *);
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +020030static void qeth_l2_set_rx_mode(struct net_device *);
Eugene Crosserc044dc22014-01-29 09:23:48 +010031static void qeth_bridgeport_query_support(struct qeth_card *card);
32static void qeth_bridge_state_change(struct qeth_card *card,
33 struct qeth_ipa_cmd *cmd);
34static void qeth_bridge_host_event(struct qeth_card *card,
35 struct qeth_ipa_cmd *cmd);
Frank Blaschka4a71df52008-02-15 09:19:42 +010036
Frank Blaschka4a71df52008-02-15 09:19:42 +010037static int qeth_l2_verify_dev(struct net_device *dev)
38{
39 struct qeth_card *card;
40 unsigned long flags;
41 int rc = 0;
42
43 read_lock_irqsave(&qeth_core_card_list.rwlock, flags);
44 list_for_each_entry(card, &qeth_core_card_list.list, list) {
45 if (card->dev == dev) {
46 rc = QETH_REAL_CARD;
47 break;
48 }
49 }
50 read_unlock_irqrestore(&qeth_core_card_list.rwlock, flags);
51
52 return rc;
53}
54
55static struct net_device *qeth_l2_netdev_by_devno(unsigned char *read_dev_no)
56{
57 struct qeth_card *card;
58 struct net_device *ndev;
Cornelia Huckf06f6f32008-06-06 12:37:45 +020059 __u16 temp_dev_no;
Frank Blaschka4a71df52008-02-15 09:19:42 +010060 unsigned long flags;
Cornelia Huckf06f6f32008-06-06 12:37:45 +020061 struct ccw_dev_id read_devid;
Frank Blaschka4a71df52008-02-15 09:19:42 +010062
63 ndev = NULL;
64 memcpy(&temp_dev_no, read_dev_no, 2);
65 read_lock_irqsave(&qeth_core_card_list.rwlock, flags);
66 list_for_each_entry(card, &qeth_core_card_list.list, list) {
Cornelia Huckf06f6f32008-06-06 12:37:45 +020067 ccw_device_get_id(CARD_RDEV(card), &read_devid);
68 if (read_devid.devno == temp_dev_no) {
Frank Blaschka4a71df52008-02-15 09:19:42 +010069 ndev = card->dev;
70 break;
71 }
72 }
73 read_unlock_irqrestore(&qeth_core_card_list.rwlock, flags);
74 return ndev;
75}
76
Eugene Crosserefbbc1d2015-01-21 13:39:09 +010077static int qeth_setdel_makerc(struct qeth_card *card, int retcode)
Frank Blaschka4a71df52008-02-15 09:19:42 +010078{
Eugene Crosserefbbc1d2015-01-21 13:39:09 +010079 int rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +010080
Eugene Crosserefbbc1d2015-01-21 13:39:09 +010081 if (retcode)
Thomas Richter1aec42b2015-01-21 13:39:10 +010082 QETH_CARD_TEXT_(card, 2, "err%04x", retcode);
Eugene Crosserefbbc1d2015-01-21 13:39:09 +010083 switch (retcode) {
84 case IPA_RC_SUCCESS:
85 rc = 0;
86 break;
87 case IPA_RC_L2_UNSUPPORTED_CMD:
Eugene Crosserffb95252015-05-18 14:27:58 +020088 rc = -EOPNOTSUPP;
Eugene Crosserefbbc1d2015-01-21 13:39:09 +010089 break;
90 case IPA_RC_L2_ADDR_TABLE_FULL:
91 rc = -ENOSPC;
92 break;
93 case IPA_RC_L2_DUP_MAC:
94 case IPA_RC_L2_DUP_LAYER3_MAC:
95 rc = -EEXIST;
96 break;
97 case IPA_RC_L2_MAC_NOT_AUTH_BY_HYP:
98 case IPA_RC_L2_MAC_NOT_AUTH_BY_ADP:
99 rc = -EPERM;
100 break;
101 case IPA_RC_L2_MAC_NOT_FOUND:
102 rc = -ENOENT;
103 break;
Thomas Richter1aec42b2015-01-21 13:39:10 +0100104 case -ENOMEM:
105 rc = -ENOMEM;
106 break;
Eugene Crosserefbbc1d2015-01-21 13:39:09 +0100107 default:
108 rc = -EIO;
109 break;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100110 }
Eugene Crosserefbbc1d2015-01-21 13:39:09 +0100111 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100112}
113
Julian Wiedmannac988d72017-01-12 15:48:41 +0100114static int qeth_l2_send_setdelmac(struct qeth_card *card, __u8 *mac,
115 enum qeth_ipa_cmds ipacmd)
116{
117 struct qeth_ipa_cmd *cmd;
118 struct qeth_cmd_buffer *iob;
119
120 QETH_CARD_TEXT(card, 2, "L2sdmac");
121 iob = qeth_get_ipacmd_buffer(card, ipacmd, QETH_PROT_IPV4);
122 if (!iob)
123 return -ENOMEM;
124 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
125 cmd->data.setdelmac.mac_length = OSA_ADDR_LEN;
126 memcpy(&cmd->data.setdelmac.mac, mac, OSA_ADDR_LEN);
127 return qeth_setdel_makerc(card, qeth_send_ipa_cmd(card, iob,
128 NULL, NULL));
129}
130
131static int qeth_l2_send_setmac(struct qeth_card *card, __u8 *mac)
132{
133 int rc;
134
135 QETH_CARD_TEXT(card, 2, "L2Setmac");
136 rc = qeth_l2_send_setdelmac(card, mac, IPA_CMD_SETVMAC);
137 if (rc == 0) {
138 card->info.mac_bits |= QETH_LAYER2_MAC_REGISTERED;
139 memcpy(card->dev->dev_addr, mac, OSA_ADDR_LEN);
140 dev_info(&card->gdev->dev,
141 "MAC address %pM successfully registered on device %s\n",
142 card->dev->dev_addr, card->dev->name);
143 } else {
144 card->info.mac_bits &= ~QETH_LAYER2_MAC_REGISTERED;
145 switch (rc) {
146 case -EEXIST:
147 dev_warn(&card->gdev->dev,
148 "MAC address %pM already exists\n", mac);
149 break;
150 case -EPERM:
151 dev_warn(&card->gdev->dev,
152 "MAC address %pM is not authorized\n", mac);
153 break;
154 }
155 }
156 return rc;
157}
158
159static int qeth_l2_send_delmac(struct qeth_card *card, __u8 *mac)
160{
161 int rc;
162
163 QETH_CARD_TEXT(card, 2, "L2Delmac");
164 if (!(card->info.mac_bits & QETH_LAYER2_MAC_REGISTERED))
165 return 0;
166 rc = qeth_l2_send_setdelmac(card, mac, IPA_CMD_DELVMAC);
167 if (rc == 0)
168 card->info.mac_bits &= ~QETH_LAYER2_MAC_REGISTERED;
169 return rc;
170}
171
Frank Blaschka4a71df52008-02-15 09:19:42 +0100172static int qeth_l2_send_setgroupmac(struct qeth_card *card, __u8 *mac)
173{
Eugene Crosserefbbc1d2015-01-21 13:39:09 +0100174 int rc;
175
Carsten Otte847a50f2010-06-21 22:57:05 +0000176 QETH_CARD_TEXT(card, 2, "L2Sgmac");
Julian Wiedmann754e0b82017-01-12 15:48:39 +0100177 rc = qeth_l2_send_setdelmac(card, mac, IPA_CMD_SETGMAC);
Eugene Crosserefbbc1d2015-01-21 13:39:09 +0100178 if (rc == -EEXIST)
179 QETH_DBF_MESSAGE(2, "Group MAC %pM already existing on %s\n",
180 mac, QETH_CARD_IFNAME(card));
181 else if (rc)
182 QETH_DBF_MESSAGE(2, "Could not set group MAC %pM on %s: %d\n",
183 mac, QETH_CARD_IFNAME(card), rc);
184 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100185}
186
187static int qeth_l2_send_delgroupmac(struct qeth_card *card, __u8 *mac)
188{
Eugene Crosserefbbc1d2015-01-21 13:39:09 +0100189 int rc;
190
Carsten Otte847a50f2010-06-21 22:57:05 +0000191 QETH_CARD_TEXT(card, 2, "L2Dgmac");
Julian Wiedmann754e0b82017-01-12 15:48:39 +0100192 rc = qeth_l2_send_setdelmac(card, mac, IPA_CMD_DELGMAC);
Eugene Crosserefbbc1d2015-01-21 13:39:09 +0100193 if (rc)
194 QETH_DBF_MESSAGE(2,
195 "Could not delete group MAC %pM on %s: %d\n",
196 mac, QETH_CARD_IFNAME(card), rc);
197 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100198}
199
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200200static int qeth_l2_write_mac(struct qeth_card *card, struct qeth_mac *mac)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100201{
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200202 if (mac->is_uc) {
Julian Wiedmann979d7922017-01-12 15:48:40 +0100203 return qeth_l2_send_setdelmac(card, mac->mac_addr,
Julian Wiedmann754e0b82017-01-12 15:48:39 +0100204 IPA_CMD_SETVMAC);
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200205 } else {
Julian Wiedmann979d7922017-01-12 15:48:40 +0100206 return qeth_l2_send_setgroupmac(card, mac->mac_addr);
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200207 }
Julian Wiedmann979d7922017-01-12 15:48:40 +0100208}
209
210static int qeth_l2_remove_mac(struct qeth_card *card, struct qeth_mac *mac)
211{
212 if (mac->is_uc) {
213 return qeth_l2_send_setdelmac(card, mac->mac_addr,
214 IPA_CMD_DELVMAC);
215 } else {
216 return qeth_l2_send_delgroupmac(card, mac->mac_addr);
217 }
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200218}
219
Julian Wiedmannc07cbf22017-01-12 15:48:37 +0100220static void qeth_l2_del_all_macs(struct qeth_card *card)
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200221{
222 struct qeth_mac *mac;
223 struct hlist_node *tmp;
224 int i;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100225
226 spin_lock_bh(&card->mclock);
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200227 hash_for_each_safe(card->mac_htable, i, tmp, mac, hnode) {
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200228 hash_del(&mac->hnode);
229 kfree(mac);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100230 }
231 spin_unlock_bh(&card->mclock);
232}
233
Julian Wiedmanncef6ff222017-08-15 17:02:46 +0200234static int qeth_l2_get_cast_type(struct qeth_card *card, struct sk_buff *skb)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100235{
Klaus-Dieter Wackerce73e102009-08-26 02:01:08 +0000236 if (card->info.type == QETH_CARD_TYPE_OSN)
237 return RTN_UNSPEC;
238 if (is_broadcast_ether_addr(skb->data))
239 return RTN_BROADCAST;
240 if (is_multicast_ether_addr(skb->data))
241 return RTN_MULTICAST;
242 return RTN_UNSPEC;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100243}
244
Julian Wiedmanncef6ff222017-08-15 17:02:46 +0200245static void qeth_l2_hdr_csum(struct qeth_card *card, struct qeth_hdr *hdr,
246 struct sk_buff *skb)
Thomas Richter4d7def22015-09-18 16:06:51 +0200247{
248 struct iphdr *iph = ip_hdr(skb);
249
250 /* tcph->check contains already the pseudo hdr checksum
251 * so just set the header flags
252 */
253 if (iph->protocol == IPPROTO_UDP)
254 hdr->hdr.l2.flags[1] |= QETH_HDR_EXT_UDP;
255 hdr->hdr.l2.flags[1] |= QETH_HDR_EXT_CSUM_TRANSP_REQ |
256 QETH_HDR_EXT_CSUM_HDR_REQ;
257 iph->check = 0;
258 if (card->options.performance_stats)
259 card->perf_stats.tx_csum++;
260}
261
Frank Blaschka4a71df52008-02-15 09:19:42 +0100262static void qeth_l2_fill_header(struct qeth_card *card, struct qeth_hdr *hdr,
Stefan Raspl43934072014-03-19 07:58:01 +0100263 struct sk_buff *skb, int cast_type)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100264{
Frank Blaschka683d7182008-08-01 16:39:13 +0200265 struct vlan_ethhdr *veth = (struct vlan_ethhdr *)skb_mac_header(skb);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100266
267 memset(hdr, 0, sizeof(struct qeth_hdr));
268 hdr->hdr.l2.id = QETH_HEADER_TYPE_LAYER2;
269
270 /* set byte byte 3 to casting flags */
271 if (cast_type == RTN_MULTICAST)
272 hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_MULTICAST;
273 else if (cast_type == RTN_BROADCAST)
274 hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_BROADCAST;
275 else
Klaus-Dieter Wackerce73e102009-08-26 02:01:08 +0000276 hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_UNICAST;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100277
Julian Wiedmann2aedd562017-04-11 16:11:15 +0200278 hdr->hdr.l2.pkt_length = skb->len - sizeof(struct qeth_hdr);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100279 /* VSWITCH relies on the VLAN
280 * information to be present in
281 * the QDIO header */
282 if (veth->h_vlan_proto == __constant_htons(ETH_P_8021Q)) {
283 hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_VLAN;
284 hdr->hdr.l2.vlan_id = ntohs(veth->h_vlan_TCI);
285 }
286}
287
288static int qeth_l2_send_setdelvlan_cb(struct qeth_card *card,
289 struct qeth_reply *reply, unsigned long data)
290{
291 struct qeth_ipa_cmd *cmd;
292
Carsten Otte847a50f2010-06-21 22:57:05 +0000293 QETH_CARD_TEXT(card, 2, "L2sdvcb");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100294 cmd = (struct qeth_ipa_cmd *) data;
295 if (cmd->hdr.return_code) {
Frank Blaschka14cc21b2008-06-06 12:37:46 +0200296 QETH_DBF_MESSAGE(2, "Error in processing VLAN %i on %s: 0x%x. "
Frank Blaschka4a71df52008-02-15 09:19:42 +0100297 "Continuing\n", cmd->data.setdelvlan.vlan_id,
298 QETH_CARD_IFNAME(card), cmd->hdr.return_code);
Carsten Otte847a50f2010-06-21 22:57:05 +0000299 QETH_CARD_TEXT_(card, 2, "L2VL%4x", cmd->hdr.command);
300 QETH_CARD_TEXT_(card, 2, "err%d", cmd->hdr.return_code);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100301 }
302 return 0;
303}
304
305static int qeth_l2_send_setdelvlan(struct qeth_card *card, __u16 i,
306 enum qeth_ipa_cmds ipacmd)
307{
308 struct qeth_ipa_cmd *cmd;
309 struct qeth_cmd_buffer *iob;
310
Carsten Otte847a50f2010-06-21 22:57:05 +0000311 QETH_CARD_TEXT_(card, 4, "L2sdv%x", ipacmd);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100312 iob = qeth_get_ipacmd_buffer(card, ipacmd, QETH_PROT_IPV4);
Thomas Richter1aec42b2015-01-21 13:39:10 +0100313 if (!iob)
314 return -ENOMEM;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100315 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
316 cmd->data.setdelvlan.vlan_id = i;
317 return qeth_send_ipa_cmd(card, iob,
318 qeth_l2_send_setdelvlan_cb, NULL);
319}
320
Ursula Braun70919e22011-02-26 22:41:36 -0800321static void qeth_l2_process_vlans(struct qeth_card *card)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100322{
323 struct qeth_vlan_vid *id;
Carsten Otte847a50f2010-06-21 22:57:05 +0000324 QETH_CARD_TEXT(card, 3, "L2prcvln");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100325 spin_lock_bh(&card->vlanlock);
326 list_for_each_entry(id, &card->vid_list, list) {
Ursula Braun70919e22011-02-26 22:41:36 -0800327 qeth_l2_send_setdelvlan(card, id->vid, IPA_CMD_SETVLAN);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100328 }
329 spin_unlock_bh(&card->vlanlock);
330}
331
Patrick McHardy80d5c362013-04-19 02:04:28 +0000332static int qeth_l2_vlan_rx_add_vid(struct net_device *dev,
333 __be16 proto, u16 vid)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100334{
Heiko Carstens509e2562008-07-26 02:24:10 -0700335 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100336 struct qeth_vlan_vid *id;
Thomas Richter1aec42b2015-01-21 13:39:10 +0100337 int rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100338
Carsten Otte847a50f2010-06-21 22:57:05 +0000339 QETH_CARD_TEXT_(card, 4, "aid:%d", vid);
Ursula Braun10651db2010-10-01 02:51:13 +0000340 if (!vid)
Jiri Pirko8e586132011-12-08 19:52:37 -0500341 return 0;
Ursula Braun5113fec2010-05-16 21:15:14 +0000342 if (card->info.type == QETH_CARD_TYPE_OSM) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000343 QETH_CARD_TEXT(card, 3, "aidOSM");
Jiri Pirko8e586132011-12-08 19:52:37 -0500344 return 0;
Ursula Braun5113fec2010-05-16 21:15:14 +0000345 }
Ursula Braun8e98ac42009-03-24 20:57:18 +0000346 if (qeth_wait_for_threads(card, QETH_RECOVER_THREAD)) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000347 QETH_CARD_TEXT(card, 3, "aidREC");
Jiri Pirko8e586132011-12-08 19:52:37 -0500348 return 0;
Ursula Braun8e98ac42009-03-24 20:57:18 +0000349 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100350 id = kmalloc(sizeof(struct qeth_vlan_vid), GFP_ATOMIC);
351 if (id) {
352 id->vid = vid;
Thomas Richter1aec42b2015-01-21 13:39:10 +0100353 rc = qeth_l2_send_setdelvlan(card, vid, IPA_CMD_SETVLAN);
354 if (rc) {
355 kfree(id);
356 return rc;
357 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100358 spin_lock_bh(&card->vlanlock);
359 list_add_tail(&id->list, &card->vid_list);
360 spin_unlock_bh(&card->vlanlock);
Jiri Pirko8e586132011-12-08 19:52:37 -0500361 } else {
362 return -ENOMEM;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100363 }
Jiri Pirko8e586132011-12-08 19:52:37 -0500364 return 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100365}
366
Patrick McHardy80d5c362013-04-19 02:04:28 +0000367static int qeth_l2_vlan_rx_kill_vid(struct net_device *dev,
368 __be16 proto, u16 vid)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100369{
370 struct qeth_vlan_vid *id, *tmpid = NULL;
Heiko Carstens509e2562008-07-26 02:24:10 -0700371 struct qeth_card *card = dev->ml_priv;
Thomas Richter1aec42b2015-01-21 13:39:10 +0100372 int rc = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100373
Carsten Otte847a50f2010-06-21 22:57:05 +0000374 QETH_CARD_TEXT_(card, 4, "kid:%d", vid);
Ursula Braun5113fec2010-05-16 21:15:14 +0000375 if (card->info.type == QETH_CARD_TYPE_OSM) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000376 QETH_CARD_TEXT(card, 3, "kidOSM");
Jiri Pirko8e586132011-12-08 19:52:37 -0500377 return 0;
Ursula Braun5113fec2010-05-16 21:15:14 +0000378 }
Ursula Braun8e98ac42009-03-24 20:57:18 +0000379 if (qeth_wait_for_threads(card, QETH_RECOVER_THREAD)) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000380 QETH_CARD_TEXT(card, 3, "kidREC");
Jiri Pirko8e586132011-12-08 19:52:37 -0500381 return 0;
Ursula Braun8e98ac42009-03-24 20:57:18 +0000382 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100383 spin_lock_bh(&card->vlanlock);
384 list_for_each_entry(id, &card->vid_list, list) {
385 if (id->vid == vid) {
386 list_del(&id->list);
387 tmpid = id;
388 break;
389 }
390 }
391 spin_unlock_bh(&card->vlanlock);
392 if (tmpid) {
Thomas Richter1aec42b2015-01-21 13:39:10 +0100393 rc = qeth_l2_send_setdelvlan(card, vid, IPA_CMD_DELVLAN);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100394 kfree(tmpid);
395 }
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200396 qeth_l2_set_rx_mode(card->dev);
Thomas Richter1aec42b2015-01-21 13:39:10 +0100397 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100398}
399
Peter Senna Tschudinb2f4de82015-08-04 17:11:47 +0200400static void qeth_l2_stop_card(struct qeth_card *card, int recovery_mode)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100401{
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200402 QETH_DBF_TEXT(SETUP , 2, "stopcard");
403 QETH_DBF_HEX(SETUP, 2, &card, sizeof(void *));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100404
405 qeth_set_allowed_threads(card, 0, 1);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100406 if (card->read.state == CH_STATE_UP &&
407 card->write.state == CH_STATE_UP &&
408 (card->state == CARD_STATE_UP)) {
409 if (recovery_mode &&
410 card->info.type != QETH_CARD_TYPE_OSN) {
411 qeth_l2_stop(card->dev);
412 } else {
413 rtnl_lock();
414 dev_close(card->dev);
415 rtnl_unlock();
416 }
Ursula Braun70919e22011-02-26 22:41:36 -0800417 card->info.mac_bits &= ~QETH_LAYER2_MAC_REGISTERED;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100418 card->state = CARD_STATE_SOFTSETUP;
419 }
420 if (card->state == CARD_STATE_SOFTSETUP) {
Julian Wiedmannc07cbf22017-01-12 15:48:37 +0100421 qeth_l2_del_all_macs(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100422 qeth_clear_ipacmd_list(card);
423 card->state = CARD_STATE_HARDSETUP;
424 }
425 if (card->state == CARD_STATE_HARDSETUP) {
426 qeth_qdio_clear_card(card, 0);
427 qeth_clear_qdio_buffers(card);
428 qeth_clear_working_pool_list(card);
429 card->state = CARD_STATE_DOWN;
430 }
431 if (card->state == CARD_STATE_DOWN) {
432 qeth_clear_cmd_buffers(&card->read);
433 qeth_clear_cmd_buffers(&card->write);
434 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100435}
436
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000437static int qeth_l2_process_inbound_buffer(struct qeth_card *card,
438 int budget, int *done)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100439{
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000440 int work_done = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100441 struct sk_buff *skb;
442 struct qeth_hdr *hdr;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100443 unsigned int len;
444
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000445 *done = 0;
Stefan Raspl18af5c12012-11-19 02:46:50 +0000446 WARN_ON_ONCE(!budget);
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000447 while (budget) {
448 skb = qeth_core_get_next_skb(card,
Frank Blaschkab3332932011-08-08 01:33:59 +0000449 &card->qdio.in_q->bufs[card->rx.b_index],
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000450 &card->rx.b_element, &card->rx.e_offset, &hdr);
451 if (!skb) {
452 *done = 1;
453 break;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100454 }
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000455 skb->dev = card->dev;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100456 switch (hdr->hdr.l2.id) {
457 case QETH_HEADER_TYPE_LAYER2:
458 skb->pkt_type = PACKET_HOST;
459 skb->protocol = eth_type_trans(skb, skb->dev);
Thomas Richter4d7def22015-09-18 16:06:51 +0200460 if ((card->dev->features & NETIF_F_RXCSUM)
461 && ((hdr->hdr.l2.flags[1] &
462 (QETH_HDR_EXT_CSUM_HDR_REQ |
463 QETH_HDR_EXT_CSUM_TRANSP_REQ)) ==
464 (QETH_HDR_EXT_CSUM_HDR_REQ |
465 QETH_HDR_EXT_CSUM_TRANSP_REQ)))
466 skb->ip_summed = CHECKSUM_UNNECESSARY;
467 else
468 skb->ip_summed = CHECKSUM_NONE;
Ursula Braun12883722008-04-01 10:26:56 +0200469 if (skb->protocol == htons(ETH_P_802_2))
470 *((__u32 *)skb->cb) = ++card->seqno.pkt_seqno;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100471 len = skb->len;
Thomas Richter9abfa8c2015-10-06 15:12:27 +0200472 napi_gro_receive(&card->napi, skb);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100473 break;
474 case QETH_HEADER_TYPE_OSN:
Ursula Braun2d488c22008-10-24 11:16:55 +0200475 if (card->info.type == QETH_CARD_TYPE_OSN) {
476 skb_push(skb, sizeof(struct qeth_hdr));
477 skb_copy_to_linear_data(skb, hdr,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100478 sizeof(struct qeth_hdr));
Ursula Braun2d488c22008-10-24 11:16:55 +0200479 len = skb->len;
480 card->osn_info.data_cb(skb);
481 break;
482 }
483 /* else unknown */
Frank Blaschka4a71df52008-02-15 09:19:42 +0100484 default:
485 dev_kfree_skb_any(skb);
Carsten Otte847a50f2010-06-21 22:57:05 +0000486 QETH_CARD_TEXT(card, 3, "inbunkno");
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200487 QETH_DBF_HEX(CTRL, 3, hdr, QETH_DBF_CTRL_LEN);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100488 continue;
489 }
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000490 work_done++;
491 budget--;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100492 card->stats.rx_packets++;
493 card->stats.rx_bytes += len;
494 }
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000495 return work_done;
496}
497
Frank Blaschka4a71df52008-02-15 09:19:42 +0100498static int qeth_l2_request_initial_mac(struct qeth_card *card)
499{
500 int rc = 0;
501 char vendor_pre[] = {0x02, 0x00, 0x00};
502
Julian Wiedmannec61bd22017-06-20 16:00:34 +0200503 QETH_DBF_TEXT(SETUP, 2, "l2reqmac");
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200504 QETH_DBF_TEXT_(SETUP, 2, "doL2%s", CARD_BUS_ID(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100505
Julian Wiedmannec61bd22017-06-20 16:00:34 +0200506 if (MACHINE_IS_VM) {
507 rc = qeth_vm_request_mac(card);
508 if (!rc)
509 goto out;
510 QETH_DBF_MESSAGE(2, "z/VM MAC Service failed on device %s: x%x\n",
511 CARD_BUS_ID(card), rc);
512 QETH_DBF_TEXT_(SETUP, 2, "err%04x", rc);
513 /* fall back to alternative mechanism: */
514 }
515
Ursula Braun5113fec2010-05-16 21:15:14 +0000516 if (card->info.type == QETH_CARD_TYPE_IQD ||
517 card->info.type == QETH_CARD_TYPE_OSM ||
518 card->info.type == QETH_CARD_TYPE_OSX ||
519 card->info.guestlan) {
Frank Blaschka4a71df52008-02-15 09:19:42 +0100520 rc = qeth_setadpparms_change_macaddr(card);
521 if (rc) {
Frank Blaschka14cc21b2008-06-06 12:37:46 +0200522 QETH_DBF_MESSAGE(2, "couldn't get MAC address on "
523 "device %s: x%x\n", CARD_BUS_ID(card), rc);
Thomas Richter1aec42b2015-01-21 13:39:10 +0100524 QETH_DBF_TEXT_(SETUP, 2, "1err%04x", rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100525 return rc;
526 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100527 } else {
Joe Perches18336112012-07-12 22:33:10 -0700528 eth_random_addr(card->dev->dev_addr);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100529 memcpy(card->dev->dev_addr, vendor_pre, 3);
530 }
Julian Wiedmannec61bd22017-06-20 16:00:34 +0200531out:
532 QETH_DBF_HEX(SETUP, 2, card->dev->dev_addr, card->dev->addr_len);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100533 return 0;
534}
535
536static int qeth_l2_set_mac_address(struct net_device *dev, void *p)
537{
538 struct sockaddr *addr = p;
Heiko Carstens509e2562008-07-26 02:24:10 -0700539 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100540 int rc = 0;
541
Carsten Otte847a50f2010-06-21 22:57:05 +0000542 QETH_CARD_TEXT(card, 3, "setmac");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100543
544 if (qeth_l2_verify_dev(dev) != QETH_REAL_CARD) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000545 QETH_CARD_TEXT(card, 3, "setmcINV");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100546 return -EOPNOTSUPP;
547 }
548
Ursula Braun5113fec2010-05-16 21:15:14 +0000549 if (card->info.type == QETH_CARD_TYPE_OSN ||
550 card->info.type == QETH_CARD_TYPE_OSM ||
551 card->info.type == QETH_CARD_TYPE_OSX) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000552 QETH_CARD_TEXT(card, 3, "setmcTYP");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100553 return -EOPNOTSUPP;
554 }
Carsten Otte847a50f2010-06-21 22:57:05 +0000555 QETH_CARD_HEX(card, 3, addr->sa_data, OSA_ADDR_LEN);
Ursula Braun8e98ac42009-03-24 20:57:18 +0000556 if (qeth_wait_for_threads(card, QETH_RECOVER_THREAD)) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000557 QETH_CARD_TEXT(card, 3, "setmcREC");
Ursula Braun8e98ac42009-03-24 20:57:18 +0000558 return -ERESTARTSYS;
559 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100560 rc = qeth_l2_send_delmac(card, &card->dev->dev_addr[0]);
Eugene Crosserefbbc1d2015-01-21 13:39:09 +0100561 if (!rc || (rc == -ENOENT))
Frank Blaschka4a71df52008-02-15 09:19:42 +0100562 rc = qeth_l2_send_setmac(card, addr->sa_data);
Ursula Braune0a81142012-03-07 02:06:28 +0000563 return rc ? -EINVAL : 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100564}
565
Eugene Crosser0db587b2015-05-18 14:27:55 +0200566static void qeth_promisc_to_bridge(struct qeth_card *card)
567{
568 struct net_device *dev = card->dev;
569 enum qeth_ipa_promisc_modes promisc_mode;
570 int role;
571 int rc;
572
573 QETH_CARD_TEXT(card, 3, "pmisc2br");
574
575 if (!card->options.sbp.reflect_promisc)
576 return;
577 promisc_mode = (dev->flags & IFF_PROMISC) ? SET_PROMISC_MODE_ON
578 : SET_PROMISC_MODE_OFF;
579 if (promisc_mode == card->info.promisc_mode)
580 return;
581
582 if (promisc_mode == SET_PROMISC_MODE_ON) {
583 if (card->options.sbp.reflect_promisc_primary)
584 role = QETH_SBP_ROLE_PRIMARY;
585 else
586 role = QETH_SBP_ROLE_SECONDARY;
587 } else
588 role = QETH_SBP_ROLE_NONE;
589
590 rc = qeth_bridgeport_setrole(card, role);
591 QETH_DBF_TEXT_(SETUP, 2, "bpm%c%04x",
592 (promisc_mode == SET_PROMISC_MODE_ON) ? '+' : '-', rc);
593 if (!rc) {
594 card->options.sbp.role = role;
595 card->info.promisc_mode = promisc_mode;
596 }
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200597
598}
599/* New MAC address is added to the hash table and marked to be written on card
600 * only if there is not in the hash table storage already
601 *
602*/
Julian Wiedmanncef6ff222017-08-15 17:02:46 +0200603static void qeth_l2_add_mac(struct qeth_card *card, struct netdev_hw_addr *ha,
604 u8 is_uc)
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200605{
Julian Wiedmanncef6ff222017-08-15 17:02:46 +0200606 u32 mac_hash = get_unaligned((u32 *)(&ha->addr[2]));
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200607 struct qeth_mac *mac;
608
Julian Wiedmanncef6ff222017-08-15 17:02:46 +0200609 hash_for_each_possible(card->mac_htable, mac, hnode, mac_hash) {
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200610 if (is_uc == mac->is_uc &&
611 !memcmp(ha->addr, mac->mac_addr, OSA_ADDR_LEN)) {
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200612 mac->disp_flag = QETH_DISP_ADDR_DO_NOTHING;
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200613 return;
614 }
615 }
616
617 mac = kzalloc(sizeof(struct qeth_mac), GFP_ATOMIC);
618
619 if (!mac)
620 return;
621
622 memcpy(mac->mac_addr, ha->addr, OSA_ADDR_LEN);
623 mac->is_uc = is_uc;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200624 mac->disp_flag = QETH_DISP_ADDR_ADD;
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200625
Julian Wiedmanncef6ff222017-08-15 17:02:46 +0200626 hash_add(card->mac_htable, &mac->hnode, mac_hash);
Eugene Crosser0db587b2015-05-18 14:27:55 +0200627}
628
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200629static void qeth_l2_set_rx_mode(struct net_device *dev)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100630{
Heiko Carstens509e2562008-07-26 02:24:10 -0700631 struct qeth_card *card = dev->ml_priv;
Jiri Pirkoccffad252009-05-22 23:22:17 +0000632 struct netdev_hw_addr *ha;
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200633 struct qeth_mac *mac;
634 struct hlist_node *tmp;
635 int i;
636 int rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100637
638 if (card->info.type == QETH_CARD_TYPE_OSN)
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200639 return;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100640
Carsten Otte847a50f2010-06-21 22:57:05 +0000641 QETH_CARD_TEXT(card, 3, "setmulti");
Ursula Braun8e98ac42009-03-24 20:57:18 +0000642 if (qeth_threads_running(card, QETH_RECOVER_THREAD) &&
643 (card->state != CARD_STATE_UP))
644 return;
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200645
Frank Blaschka4a71df52008-02-15 09:19:42 +0100646 spin_lock_bh(&card->mclock);
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200647
Jiri Pirko22bedad32010-04-01 21:22:57 +0000648 netdev_for_each_mc_addr(ha, dev)
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200649 qeth_l2_add_mac(card, ha, 0);
Frank Blaschka7db22662008-08-15 08:02:59 +0200650
Jiri Pirko32e7bfc2010-01-25 13:36:10 -0800651 netdev_for_each_uc_addr(ha, dev)
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200652 qeth_l2_add_mac(card, ha, 1);
653
654 hash_for_each_safe(card->mac_htable, i, tmp, mac, hnode) {
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200655 if (mac->disp_flag == QETH_DISP_ADDR_DELETE) {
Julian Wiedmann979d7922017-01-12 15:48:40 +0100656 qeth_l2_remove_mac(card, mac);
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200657 hash_del(&mac->hnode);
658 kfree(mac);
659
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200660 } else if (mac->disp_flag == QETH_DISP_ADDR_ADD) {
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200661 rc = qeth_l2_write_mac(card, mac);
662 if (rc) {
663 hash_del(&mac->hnode);
664 kfree(mac);
665 } else
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200666 mac->disp_flag = QETH_DISP_ADDR_DELETE;
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200667 } else
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200668 mac->disp_flag = QETH_DISP_ADDR_DELETE;
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200669 }
Frank Blaschka7db22662008-08-15 08:02:59 +0200670
Frank Blaschka4a71df52008-02-15 09:19:42 +0100671 spin_unlock_bh(&card->mclock);
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200672
Eugene Crosser0db587b2015-05-18 14:27:55 +0200673 if (qeth_adp_supported(card, IPA_SETADP_SET_PROMISC_MODE))
674 qeth_setadp_promisc_mode(card);
675 else
676 qeth_promisc_to_bridge(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100677}
678
Julian Wiedmanne38db6b2017-04-11 16:11:14 +0200679static netdev_tx_t qeth_l2_hard_start_xmit(struct sk_buff *skb,
680 struct net_device *dev)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100681{
682 int rc;
683 struct qeth_hdr *hdr = NULL;
684 int elements = 0;
Heiko Carstens509e2562008-07-26 02:24:10 -0700685 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100686 struct sk_buff *new_skb = skb;
Klaus-Dieter Wackerce73e102009-08-26 02:01:08 +0000687 int cast_type = qeth_l2_get_cast_type(card, skb);
Stefan Raspl290b8342014-04-28 10:05:08 +0200688 struct qeth_qdio_out_q *queue;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100689 int tx_bytes = skb->len;
Frank Blaschka683d7182008-08-01 16:39:13 +0200690 int data_offset = -1;
691 int elements_needed = 0;
692 int hd_len = 0;
Julian Wiedmann886e1972017-08-15 17:02:39 +0200693 unsigned int nr_frags;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100694
Stefan Raspl290b8342014-04-28 10:05:08 +0200695 if (card->qdio.do_prio_queueing || (cast_type &&
696 card->info.is_multicast_different))
697 queue = card->qdio.out_qs[qeth_get_priority_queue(card, skb,
698 qeth_get_ip_version(skb), cast_type)];
699 else
700 queue = card->qdio.out_qs[card->qdio.default_out_queue];
701
Frank Blaschka4a71df52008-02-15 09:19:42 +0100702 if ((card->state != CARD_STATE_UP) || !card->lan_online) {
703 card->stats.tx_carrier_errors++;
704 goto tx_drop;
705 }
706
707 if ((card->info.type == QETH_CARD_TYPE_OSN) &&
708 (skb->protocol == htons(ETH_P_IPV6)))
709 goto tx_drop;
710
711 if (card->options.performance_stats) {
712 card->perf_stats.outbound_cnt++;
713 card->perf_stats.outbound_start_time = qeth_get_micros();
714 }
715 netif_stop_queue(dev);
716
Eugene Crosserd52aec92016-06-16 16:18:55 +0200717 /* fix hardware limitation: as long as we do not have sbal
718 * chaining we can not send long frag lists
719 */
720 if ((card->info.type != QETH_CARD_TYPE_IQD) &&
Julian Wiedmann7d969d22017-03-23 14:55:08 +0100721 !qeth_get_elements_no(card, new_skb, 0, 0)) {
Eugene Crosser6059c902016-06-16 16:18:57 +0200722 int lin_rc = skb_linearize(new_skb);
723
724 if (card->options.performance_stats) {
725 if (lin_rc)
726 card->perf_stats.tx_linfail++;
727 else
728 card->perf_stats.tx_lin++;
729 }
730 if (lin_rc)
Eugene Crosserd52aec92016-06-16 16:18:55 +0200731 goto tx_drop;
Eugene Crosserd52aec92016-06-16 16:18:55 +0200732 }
Julian Wiedmann886e1972017-08-15 17:02:39 +0200733 nr_frags = skb_shinfo(new_skb)->nr_frags;
Eugene Crosserd52aec92016-06-16 16:18:55 +0200734
Frank Blaschka4a71df52008-02-15 09:19:42 +0100735 if (card->info.type == QETH_CARD_TYPE_OSN)
736 hdr = (struct qeth_hdr *)skb->data;
737 else {
Frank Blaschka64ef8952009-03-24 20:57:16 +0000738 if (card->info.type == QETH_CARD_TYPE_IQD) {
Frank Blaschka683d7182008-08-01 16:39:13 +0200739 new_skb = skb;
740 data_offset = ETH_HLEN;
741 hd_len = ETH_HLEN;
742 hdr = kmem_cache_alloc(qeth_core_header_cache,
743 GFP_ATOMIC);
744 if (!hdr)
745 goto tx_drop;
746 elements_needed++;
Stefan Raspl43934072014-03-19 07:58:01 +0100747 qeth_l2_fill_header(card, hdr, new_skb, cast_type);
Frank Blaschka683d7182008-08-01 16:39:13 +0200748 hdr->hdr.l2.pkt_length = new_skb->len;
Julian Wiedmannf8eb4932017-08-15 17:02:45 +0200749 skb_copy_from_linear_data(new_skb,
750 ((char *)hdr) + sizeof(*hdr),
751 ETH_HLEN);
Frank Blaschka683d7182008-08-01 16:39:13 +0200752 } else {
753 /* create a clone with writeable headroom */
754 new_skb = skb_realloc_headroom(skb,
Frank Blaschkaf90b7442008-04-24 10:15:24 +0200755 sizeof(struct qeth_hdr));
Frank Blaschka683d7182008-08-01 16:39:13 +0200756 if (!new_skb)
757 goto tx_drop;
Johannes Bergd58ff352017-06-16 14:29:23 +0200758 hdr = skb_push(new_skb, sizeof(struct qeth_hdr));
Stefan Raspl43934072014-03-19 07:58:01 +0100759 qeth_l2_fill_header(card, hdr, new_skb, cast_type);
Thomas Richter4d7def22015-09-18 16:06:51 +0200760 if (new_skb->ip_summed == CHECKSUM_PARTIAL)
761 qeth_l2_hdr_csum(card, hdr, new_skb);
Frank Blaschka683d7182008-08-01 16:39:13 +0200762 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100763 }
764
Julian Wiedmann7d969d22017-03-23 14:55:08 +0100765 elements = qeth_get_elements_no(card, new_skb, elements_needed,
766 (data_offset > 0) ? data_offset : 0);
Frank Blaschka64ef8952009-03-24 20:57:16 +0000767 if (!elements) {
768 if (data_offset >= 0)
769 kmem_cache_free(qeth_core_header_cache, hdr);
770 goto tx_drop;
Frank Blaschkaf61a0d02009-03-24 20:57:15 +0000771 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100772
Frank Blaschka51aa1652010-06-21 22:57:10 +0000773 if (card->info.type != QETH_CARD_TYPE_IQD) {
Stefan Raspld4ae1f52013-04-22 01:12:29 +0000774 if (qeth_hdr_chk_and_bounce(new_skb, &hdr,
Frank Blaschka51aa1652010-06-21 22:57:10 +0000775 sizeof(struct qeth_hdr_layer2)))
776 goto tx_drop;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100777 rc = qeth_do_send_packet(card, queue, new_skb, hdr,
Frank Blaschka64ef8952009-03-24 20:57:16 +0000778 elements);
Frank Blaschka51aa1652010-06-21 22:57:10 +0000779 } else
Frank Blaschka4a71df52008-02-15 09:19:42 +0100780 rc = qeth_do_send_packet_fast(card, queue, new_skb, hdr,
Julian Wiedmann4e8d7e62017-04-11 16:11:13 +0200781 data_offset, hd_len);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100782 if (!rc) {
783 card->stats.tx_packets++;
784 card->stats.tx_bytes += tx_bytes;
Julian Wiedmann886e1972017-08-15 17:02:39 +0200785 if (card->options.performance_stats && nr_frags) {
786 card->perf_stats.sg_skbs_sent++;
787 /* nr_frags + skb->data */
788 card->perf_stats.sg_frags_sent += nr_frags + 1;
Eugene Crosserd52aec92016-06-16 16:18:55 +0200789 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100790 if (new_skb != skb)
791 dev_kfree_skb_any(skb);
Patrick McHardyec634fe2009-07-05 19:23:38 -0700792 rc = NETDEV_TX_OK;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100793 } else {
Frank Blaschka683d7182008-08-01 16:39:13 +0200794 if (data_offset >= 0)
795 kmem_cache_free(qeth_core_header_cache, hdr);
796
Frank Blaschka4a71df52008-02-15 09:19:42 +0100797 if (rc == -EBUSY) {
798 if (new_skb != skb)
799 dev_kfree_skb_any(new_skb);
800 return NETDEV_TX_BUSY;
801 } else
802 goto tx_drop;
803 }
804
805 netif_wake_queue(dev);
806 if (card->options.performance_stats)
807 card->perf_stats.outbound_time += qeth_get_micros() -
808 card->perf_stats.outbound_start_time;
809 return rc;
810
811tx_drop:
812 card->stats.tx_dropped++;
813 card->stats.tx_errors++;
814 if ((new_skb != skb) && new_skb)
815 dev_kfree_skb_any(new_skb);
816 dev_kfree_skb_any(skb);
Frank Blaschkad0ec0f52008-06-06 12:37:48 +0200817 netif_wake_queue(dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100818 return NETDEV_TX_OK;
819}
820
Ursula Braun39423442011-01-12 20:42:24 +0000821static int __qeth_l2_open(struct net_device *dev)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100822{
Heiko Carstens509e2562008-07-26 02:24:10 -0700823 struct qeth_card *card = dev->ml_priv;
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000824 int rc = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100825
Carsten Otte847a50f2010-06-21 22:57:05 +0000826 QETH_CARD_TEXT(card, 4, "qethopen");
Ursula Braun39423442011-01-12 20:42:24 +0000827 if (card->state == CARD_STATE_UP)
828 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100829 if (card->state != CARD_STATE_SOFTSETUP)
830 return -ENODEV;
831
832 if ((card->info.type != QETH_CARD_TYPE_OSN) &&
833 (!(card->info.mac_bits & QETH_LAYER2_MAC_REGISTERED))) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000834 QETH_CARD_TEXT(card, 4, "nomacadr");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100835 return -EPERM;
836 }
837 card->data.state = CH_STATE_UP;
838 card->state = CARD_STATE_UP;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100839 netif_start_queue(dev);
840
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000841 if (qdio_stop_irq(card->data.ccwdev, 0) >= 0) {
842 napi_enable(&card->napi);
843 napi_schedule(&card->napi);
844 } else
845 rc = -EIO;
846 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100847}
848
Ursula Braun39423442011-01-12 20:42:24 +0000849static int qeth_l2_open(struct net_device *dev)
850{
851 struct qeth_card *card = dev->ml_priv;
852
853 QETH_CARD_TEXT(card, 5, "qethope_");
854 if (qeth_wait_for_threads(card, QETH_RECOVER_THREAD)) {
855 QETH_CARD_TEXT(card, 3, "openREC");
856 return -ERESTARTSYS;
857 }
858 return __qeth_l2_open(dev);
859}
860
Frank Blaschka4a71df52008-02-15 09:19:42 +0100861static int qeth_l2_stop(struct net_device *dev)
862{
Heiko Carstens509e2562008-07-26 02:24:10 -0700863 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100864
Carsten Otte847a50f2010-06-21 22:57:05 +0000865 QETH_CARD_TEXT(card, 4, "qethstop");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100866 netif_tx_disable(dev);
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000867 if (card->state == CARD_STATE_UP) {
Frank Blaschka4a71df52008-02-15 09:19:42 +0100868 card->state = CARD_STATE_SOFTSETUP;
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000869 napi_disable(&card->napi);
870 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100871 return 0;
872}
873
Julian Wiedmann2d2ebb32017-05-10 19:07:52 +0200874static const struct device_type qeth_l2_devtype = {
875 .name = "qeth_layer2",
876 .groups = qeth_l2_attr_groups,
877};
878
Frank Blaschka4a71df52008-02-15 09:19:42 +0100879static int qeth_l2_probe_device(struct ccwgroup_device *gdev)
880{
881 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
Ursula Braun9111e782017-05-10 19:07:51 +0200882 int rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100883
Julian Wiedmann2d2ebb32017-05-10 19:07:52 +0200884 if (gdev->dev.type == &qeth_generic_devtype) {
885 rc = qeth_l2_create_device_attributes(&gdev->dev);
886 if (rc)
887 return rc;
888 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100889 INIT_LIST_HEAD(&card->vid_list);
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200890 hash_init(card->mac_htable);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100891 card->options.layer2 = 1;
Frank Blaschka1da74b12011-05-12 18:45:02 +0000892 card->info.hwtrap = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100893 return 0;
894}
895
896static void qeth_l2_remove_device(struct ccwgroup_device *cgdev)
897{
898 struct qeth_card *card = dev_get_drvdata(&cgdev->dev);
899
Julian Wiedmann2d2ebb32017-05-10 19:07:52 +0200900 if (cgdev->dev.type == &qeth_generic_devtype)
901 qeth_l2_remove_device_attributes(&cgdev->dev);
Ursula Braunf2148562009-05-19 21:38:37 +0000902 qeth_set_allowed_threads(card, 0, 1);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100903 wait_event(card->wait_q, qeth_threads_running(card, 0xffffffff) == 0);
904
Ursula Braun70919e22011-02-26 22:41:36 -0800905 if (cgdev->state == CCWGROUP_ONLINE)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100906 qeth_l2_set_offline(cgdev);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100907
908 if (card->dev) {
Ursula Braun7831b4f2016-07-04 14:07:16 +0200909 netif_napi_del(&card->napi);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100910 unregister_netdev(card->dev);
911 card->dev = NULL;
912 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100913 return;
914}
915
Stephen Hemminger0fc0b732009-09-02 01:03:33 -0700916static const struct ethtool_ops qeth_l2_ethtool_ops = {
Frank Blaschka4a71df52008-02-15 09:19:42 +0100917 .get_link = ethtool_op_get_link,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100918 .get_strings = qeth_core_get_strings,
919 .get_ethtool_stats = qeth_core_get_ethtool_stats,
Ben Hutchingsdf8b4ec2009-10-01 11:24:32 +0000920 .get_sset_count = qeth_core_get_sset_count,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100921 .get_drvinfo = qeth_core_get_drvinfo,
Julian Wiedmann993e19c2017-04-11 16:11:17 +0200922 .get_link_ksettings = qeth_core_ethtool_get_link_ksettings,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100923};
924
Stephen Hemminger0fc0b732009-09-02 01:03:33 -0700925static const struct ethtool_ops qeth_l2_osn_ops = {
Frank Blaschka4a71df52008-02-15 09:19:42 +0100926 .get_strings = qeth_core_get_strings,
927 .get_ethtool_stats = qeth_core_get_ethtool_stats,
Ben Hutchingsdf8b4ec2009-10-01 11:24:32 +0000928 .get_sset_count = qeth_core_get_sset_count,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100929 .get_drvinfo = qeth_core_get_drvinfo,
930};
931
Frank Blaschka3d58cef2009-01-09 03:44:00 +0000932static const struct net_device_ops qeth_l2_netdev_ops = {
Frank Blaschka8403b132009-01-08 10:50:55 -0800933 .ndo_open = qeth_l2_open,
934 .ndo_stop = qeth_l2_stop,
935 .ndo_get_stats = qeth_get_stats,
936 .ndo_start_xmit = qeth_l2_hard_start_xmit,
937 .ndo_validate_addr = eth_validate_addr,
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200938 .ndo_set_rx_mode = qeth_l2_set_rx_mode,
Julian Wiedmann942d6982017-04-11 16:11:10 +0200939 .ndo_do_ioctl = qeth_do_ioctl,
Frank Blaschka8403b132009-01-08 10:50:55 -0800940 .ndo_set_mac_address = qeth_l2_set_mac_address,
941 .ndo_change_mtu = qeth_change_mtu,
942 .ndo_vlan_rx_add_vid = qeth_l2_vlan_rx_add_vid,
943 .ndo_vlan_rx_kill_vid = qeth_l2_vlan_rx_kill_vid,
944 .ndo_tx_timeout = qeth_tx_timeout,
Thomas Richter8f43fb02016-06-16 16:18:59 +0200945 .ndo_fix_features = qeth_fix_features,
946 .ndo_set_features = qeth_set_features
Frank Blaschka8403b132009-01-08 10:50:55 -0800947};
948
Frank Blaschka4a71df52008-02-15 09:19:42 +0100949static int qeth_l2_setup_netdev(struct qeth_card *card)
950{
951 switch (card->info.type) {
Frank Blaschka4a71df52008-02-15 09:19:42 +0100952 case QETH_CARD_TYPE_IQD:
Tom Gundersenc835a672014-07-14 16:37:24 +0200953 card->dev = alloc_netdev(0, "hsi%d", NET_NAME_UNKNOWN,
954 ether_setup);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100955 break;
956 case QETH_CARD_TYPE_OSN:
Tom Gundersenc835a672014-07-14 16:37:24 +0200957 card->dev = alloc_netdev(0, "osn%d", NET_NAME_UNKNOWN,
958 ether_setup);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100959 break;
960 default:
961 card->dev = alloc_etherdev(0);
962 }
963
964 if (!card->dev)
965 return -ENODEV;
966
Heiko Carstens509e2562008-07-26 02:24:10 -0700967 card->dev->ml_priv = card;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100968 card->dev->watchdog_timeo = QETH_TX_TIMEOUT;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100969 card->dev->mtu = card->info.initial_mtu;
Jarod Wilson46b3ef42016-10-20 13:55:23 -0400970 card->dev->min_mtu = 64;
971 card->dev->max_mtu = ETH_MAX_MTU;
Frank Blaschka8403b132009-01-08 10:50:55 -0800972 card->dev->netdev_ops = &qeth_l2_netdev_ops;
Julian Wiedmann25e2c342017-05-10 19:07:53 +0200973 if (card->info.type == QETH_CARD_TYPE_OSN) {
974 card->dev->ethtool_ops = &qeth_l2_osn_ops;
975 card->dev->flags |= IFF_NOARP;
976 } else {
977 card->dev->ethtool_ops = &qeth_l2_ethtool_ops;
978 }
Patrick McHardyf6469682013-04-19 02:04:27 +0000979 card->dev->features |= NETIF_F_HW_VLAN_CTAG_FILTER;
Thomas Richter4d7def22015-09-18 16:06:51 +0200980 if (card->info.type == QETH_CARD_TYPE_OSD && !card->info.guestlan) {
Thomas Richter8f43fb02016-06-16 16:18:59 +0200981 card->dev->hw_features = NETIF_F_SG;
Hans Wippel9bdc4412016-06-16 16:19:00 +0200982 card->dev->vlan_features = NETIF_F_SG;
Thomas Richter8f43fb02016-06-16 16:18:59 +0200983 /* OSA 3S and earlier has no RX/TX support */
Hans Wippel9bdc4412016-06-16 16:19:00 +0200984 if (qeth_is_supported(card, IPA_OUTBOUND_CHECKSUM)) {
Thomas Richter8f43fb02016-06-16 16:18:59 +0200985 card->dev->hw_features |= NETIF_F_IP_CSUM;
Hans Wippel9bdc4412016-06-16 16:19:00 +0200986 card->dev->vlan_features |= NETIF_F_IP_CSUM;
987 }
988 if (qeth_is_supported(card, IPA_INBOUND_CHECKSUM)) {
Thomas Richter8f43fb02016-06-16 16:18:59 +0200989 card->dev->hw_features |= NETIF_F_RXCSUM;
Hans Wippel9bdc4412016-06-16 16:19:00 +0200990 card->dev->vlan_features |= NETIF_F_RXCSUM;
991 }
Thomas Richter4d7def22015-09-18 16:06:51 +0200992 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100993 card->info.broadcast_capable = 1;
994 qeth_l2_request_initial_mac(card);
Eugene Crosserd52aec92016-06-16 16:18:55 +0200995 card->dev->gso_max_size = (QETH_MAX_BUFFER_ELEMENTS(card) - 1) *
996 PAGE_SIZE;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100997 SET_NETDEV_DEV(card->dev, &card->gdev->dev);
Julian Wiedmannd73ef322017-04-11 16:11:11 +0200998 netif_napi_add(card->dev, &card->napi, qeth_poll, QETH_NAPI_WEIGHT);
Ursula Braune5ebe632015-12-11 12:27:55 +0100999 netif_carrier_off(card->dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001000 return register_netdev(card->dev);
1001}
1002
Thomas Richter4d7def22015-09-18 16:06:51 +02001003static int qeth_l2_start_ipassists(struct qeth_card *card)
1004{
1005 /* configure isolation level */
1006 if (qeth_set_access_ctrl_online(card, 0))
1007 return -ENODEV;
Thomas Richter4d7def22015-09-18 16:06:51 +02001008 return 0;
1009}
1010
Julian Wiedmann521c10e2017-06-06 14:33:45 +02001011static void qeth_l2_trace_features(struct qeth_card *card)
1012{
1013 QETH_CARD_TEXT(card, 2, "l2featur");
1014 QETH_CARD_HEX(card, 2, &card->options.sbp.supported_funcs,
1015 sizeof(card->options.sbp.supported_funcs));
1016}
1017
Frank Blaschka4a71df52008-02-15 09:19:42 +01001018static int __qeth_l2_set_online(struct ccwgroup_device *gdev, int recovery_mode)
1019{
1020 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
1021 int rc = 0;
1022 enum qeth_card_states recover_flag;
1023
Ursula Braun9dc48cc2010-07-22 23:15:05 +00001024 mutex_lock(&card->discipline_mutex);
Frank Blaschkac4949f02010-05-11 19:34:47 +00001025 mutex_lock(&card->conf_mutex);
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001026 QETH_DBF_TEXT(SETUP, 2, "setonlin");
1027 QETH_DBF_HEX(SETUP, 2, &card, sizeof(void *));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001028
Frank Blaschka4a71df52008-02-15 09:19:42 +01001029 recover_flag = card->state;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001030 rc = qeth_core_hardsetup_card(card);
1031 if (rc) {
Thomas Richter1aec42b2015-01-21 13:39:10 +01001032 QETH_DBF_TEXT_(SETUP, 2, "2err%04x", rc);
Ursula Braunaa909222009-11-12 00:11:43 +00001033 rc = -ENODEV;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001034 goto out_remove;
1035 }
Eugene Crosserc044dc22014-01-29 09:23:48 +01001036 qeth_bridgeport_query_support(card);
1037 if (card->options.sbp.supported_funcs)
1038 dev_info(&card->gdev->dev,
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001039 "The device represents a Bridge Capable Port\n");
Stefan Raspl395672e02012-11-19 02:46:49 +00001040 qeth_trace_features(card);
Julian Wiedmann521c10e2017-06-06 14:33:45 +02001041 qeth_l2_trace_features(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001042
Ursula Braunaa909222009-11-12 00:11:43 +00001043 if (!card->dev && qeth_l2_setup_netdev(card)) {
1044 rc = -ENODEV;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001045 goto out_remove;
Ursula Braunaa909222009-11-12 00:11:43 +00001046 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01001047
1048 if (card->info.type != QETH_CARD_TYPE_OSN)
1049 qeth_l2_send_setmac(card, &card->dev->dev_addr[0]);
1050
Frank Blaschka1da74b12011-05-12 18:45:02 +00001051 if (qeth_is_diagass_supported(card, QETH_DIAGS_CMD_TRAP)) {
1052 if (card->info.hwtrap &&
1053 qeth_hw_trap(card, QETH_DIAGS_TRAP_ARM))
1054 card->info.hwtrap = 0;
1055 } else
1056 card->info.hwtrap = 0;
1057
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001058 qeth_l2_setup_bridgeport_attrs(card);
1059
Frank Blaschka4a71df52008-02-15 09:19:42 +01001060 card->state = CARD_STATE_HARDSETUP;
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00001061 memset(&card->rx, 0, sizeof(struct qeth_rx));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001062 qeth_print_status_message(card);
1063
1064 /* softsetup */
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001065 QETH_DBF_TEXT(SETUP, 2, "softsetp");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001066
Ursula Braun5113fec2010-05-16 21:15:14 +00001067 if ((card->info.type == QETH_CARD_TYPE_OSD) ||
Stefan Raspl0f547612013-01-21 02:30:20 +00001068 (card->info.type == QETH_CARD_TYPE_OSX)) {
Thomas Richter8f43fb02016-06-16 16:18:59 +02001069 rc = qeth_l2_start_ipassists(card);
1070 if (rc)
Stefan Raspl0f547612013-01-21 02:30:20 +00001071 goto out_remove;
Stefan Raspl0f547612013-01-21 02:30:20 +00001072 }
Ursula Braun5113fec2010-05-16 21:15:14 +00001073
1074 if (card->info.type != QETH_CARD_TYPE_OSN &&
1075 card->info.type != QETH_CARD_TYPE_OSM)
Ursula Braun70919e22011-02-26 22:41:36 -08001076 qeth_l2_process_vlans(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001077
1078 netif_tx_disable(card->dev);
1079
1080 rc = qeth_init_qdio_queues(card);
1081 if (rc) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001082 QETH_DBF_TEXT_(SETUP, 2, "6err%d", rc);
Ursula Braunaa909222009-11-12 00:11:43 +00001083 rc = -ENODEV;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001084 goto out_remove;
1085 }
1086 card->state = CARD_STATE_SOFTSETUP;
Ursula Braun2b6203b2010-11-26 02:41:19 +00001087 if (card->lan_online)
1088 netif_carrier_on(card->dev);
1089 else
1090 netif_carrier_off(card->dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001091
1092 qeth_set_allowed_threads(card, 0xffffffff, 0);
1093 if (recover_flag == CARD_STATE_RECOVER) {
1094 if (recovery_mode &&
1095 card->info.type != QETH_CARD_TYPE_OSN) {
Ursula Braun39423442011-01-12 20:42:24 +00001096 __qeth_l2_open(card->dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001097 } else {
1098 rtnl_lock();
1099 dev_open(card->dev);
1100 rtnl_unlock();
1101 }
1102 /* this also sets saved unicast addresses */
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +02001103 qeth_l2_set_rx_mode(card->dev);
Hans Wippele830baa2016-09-15 14:39:21 +02001104 rtnl_lock();
1105 qeth_recover_features(card->dev);
1106 rtnl_unlock();
Frank Blaschka4a71df52008-02-15 09:19:42 +01001107 }
1108 /* let user_space know that device is online */
1109 kobject_uevent(&gdev->dev.kobj, KOBJ_CHANGE);
Frank Blaschkac4949f02010-05-11 19:34:47 +00001110 mutex_unlock(&card->conf_mutex);
Ursula Braun9dc48cc2010-07-22 23:15:05 +00001111 mutex_unlock(&card->discipline_mutex);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001112 return 0;
Ursula Braunaa909222009-11-12 00:11:43 +00001113
Frank Blaschka4a71df52008-02-15 09:19:42 +01001114out_remove:
Frank Blaschka4a71df52008-02-15 09:19:42 +01001115 qeth_l2_stop_card(card, 0);
1116 ccw_device_set_offline(CARD_DDEV(card));
1117 ccw_device_set_offline(CARD_WDEV(card));
1118 ccw_device_set_offline(CARD_RDEV(card));
Ursula Braun22ae2792014-02-24 13:12:06 +01001119 qdio_free(CARD_DDEV(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001120 if (recover_flag == CARD_STATE_RECOVER)
1121 card->state = CARD_STATE_RECOVER;
1122 else
1123 card->state = CARD_STATE_DOWN;
Frank Blaschkac4949f02010-05-11 19:34:47 +00001124 mutex_unlock(&card->conf_mutex);
Ursula Braun9dc48cc2010-07-22 23:15:05 +00001125 mutex_unlock(&card->discipline_mutex);
Ursula Braunaa909222009-11-12 00:11:43 +00001126 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001127}
1128
1129static int qeth_l2_set_online(struct ccwgroup_device *gdev)
1130{
1131 return __qeth_l2_set_online(gdev, 0);
1132}
1133
1134static int __qeth_l2_set_offline(struct ccwgroup_device *cgdev,
1135 int recovery_mode)
1136{
1137 struct qeth_card *card = dev_get_drvdata(&cgdev->dev);
1138 int rc = 0, rc2 = 0, rc3 = 0;
1139 enum qeth_card_states recover_flag;
1140
Ursula Braun9dc48cc2010-07-22 23:15:05 +00001141 mutex_lock(&card->discipline_mutex);
Frank Blaschkac4949f02010-05-11 19:34:47 +00001142 mutex_lock(&card->conf_mutex);
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001143 QETH_DBF_TEXT(SETUP, 3, "setoffl");
1144 QETH_DBF_HEX(SETUP, 3, &card, sizeof(void *));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001145
1146 if (card->dev && netif_carrier_ok(card->dev))
1147 netif_carrier_off(card->dev);
1148 recover_flag = card->state;
Frank Blaschka1da74b12011-05-12 18:45:02 +00001149 if ((!recovery_mode && card->info.hwtrap) || card->info.hwtrap == 2) {
1150 qeth_hw_trap(card, QETH_DIAGS_TRAP_DISARM);
1151 card->info.hwtrap = 1;
1152 }
Ursula Braun0f5623c2008-10-24 11:16:52 +02001153 qeth_l2_stop_card(card, recovery_mode);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001154 rc = ccw_device_set_offline(CARD_DDEV(card));
1155 rc2 = ccw_device_set_offline(CARD_WDEV(card));
1156 rc3 = ccw_device_set_offline(CARD_RDEV(card));
1157 if (!rc)
1158 rc = (rc2) ? rc2 : rc3;
1159 if (rc)
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001160 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
Ursula Braun22ae2792014-02-24 13:12:06 +01001161 qdio_free(CARD_DDEV(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001162 if (recover_flag == CARD_STATE_UP)
1163 card->state = CARD_STATE_RECOVER;
1164 /* let user_space know that device is offline */
1165 kobject_uevent(&cgdev->dev.kobj, KOBJ_CHANGE);
Frank Blaschkac4949f02010-05-11 19:34:47 +00001166 mutex_unlock(&card->conf_mutex);
Ursula Braun9dc48cc2010-07-22 23:15:05 +00001167 mutex_unlock(&card->discipline_mutex);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001168 return 0;
1169}
1170
1171static int qeth_l2_set_offline(struct ccwgroup_device *cgdev)
1172{
1173 return __qeth_l2_set_offline(cgdev, 0);
1174}
1175
1176static int qeth_l2_recover(void *ptr)
1177{
1178 struct qeth_card *card;
1179 int rc = 0;
1180
1181 card = (struct qeth_card *) ptr;
Carsten Otte847a50f2010-06-21 22:57:05 +00001182 QETH_CARD_TEXT(card, 2, "recover1");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001183 if (!qeth_do_run_thread(card, QETH_RECOVER_THREAD))
1184 return 0;
Carsten Otte847a50f2010-06-21 22:57:05 +00001185 QETH_CARD_TEXT(card, 2, "recover2");
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001186 dev_warn(&card->gdev->dev,
1187 "A recovery process has been started for the device\n");
Stefan Raspl65d80132013-04-07 22:19:27 +00001188 qeth_set_recovery_task(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001189 __qeth_l2_set_offline(card->gdev, 1);
1190 rc = __qeth_l2_set_online(card->gdev, 1);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001191 if (!rc)
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001192 dev_info(&card->gdev->dev,
1193 "Device successfully recovered!\n");
Ursula Braun28a7e4c2008-09-19 12:56:03 +02001194 else {
Stefan Raspl0f547612013-01-21 02:30:20 +00001195 qeth_close_dev(card);
1196 dev_warn(&card->gdev->dev, "The qeth device driver "
Stefan Raspl2efaf5f2012-10-15 19:21:18 +00001197 "failed to recover an error on the device\n");
Ursula Braun28a7e4c2008-09-19 12:56:03 +02001198 }
Stefan Raspl65d80132013-04-07 22:19:27 +00001199 qeth_clear_recovery_task(card);
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00001200 qeth_clear_thread_start_bit(card, QETH_RECOVER_THREAD);
1201 qeth_clear_thread_running_bit(card, QETH_RECOVER_THREAD);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001202 return 0;
1203}
1204
1205static int __init qeth_l2_init(void)
1206{
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001207 pr_info("register layer 2 discipline\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001208 return 0;
1209}
1210
1211static void __exit qeth_l2_exit(void)
1212{
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001213 pr_info("unregister layer 2 discipline\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001214}
1215
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02001216static int qeth_l2_pm_suspend(struct ccwgroup_device *gdev)
1217{
1218 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
1219
1220 if (card->dev)
1221 netif_device_detach(card->dev);
1222 qeth_set_allowed_threads(card, 0, 1);
1223 wait_event(card->wait_q, qeth_threads_running(card, 0xffffffff) == 0);
1224 if (gdev->state == CCWGROUP_OFFLINE)
1225 return 0;
1226 if (card->state == CARD_STATE_UP) {
Frank Blaschka1da74b12011-05-12 18:45:02 +00001227 if (card->info.hwtrap)
1228 qeth_hw_trap(card, QETH_DIAGS_TRAP_DISARM);
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02001229 __qeth_l2_set_offline(card->gdev, 1);
1230 } else
1231 __qeth_l2_set_offline(card->gdev, 0);
1232 return 0;
1233}
1234
1235static int qeth_l2_pm_resume(struct ccwgroup_device *gdev)
1236{
1237 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
1238 int rc = 0;
1239
1240 if (gdev->state == CCWGROUP_OFFLINE)
1241 goto out;
1242
1243 if (card->state == CARD_STATE_RECOVER) {
1244 rc = __qeth_l2_set_online(card->gdev, 1);
1245 if (rc) {
Ursula Braun869da902010-03-08 20:36:56 +00001246 rtnl_lock();
1247 dev_close(card->dev);
1248 rtnl_unlock();
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02001249 }
1250 } else
1251 rc = __qeth_l2_set_online(card->gdev, 0);
1252out:
1253 qeth_set_allowed_threads(card, 0xffffffff, 0);
1254 if (card->dev)
1255 netif_device_attach(card->dev);
1256 if (rc)
1257 dev_warn(&card->gdev->dev, "The qeth device driver "
1258 "failed to recover an error on the device\n");
1259 return rc;
1260}
1261
Eugene Crosserc044dc22014-01-29 09:23:48 +01001262/* Returns zero if the command is successfully "consumed" */
1263static int qeth_l2_control_event(struct qeth_card *card,
1264 struct qeth_ipa_cmd *cmd)
1265{
1266 switch (cmd->hdr.command) {
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001267 case IPA_CMD_SETBRIDGEPORT_OSA:
1268 case IPA_CMD_SETBRIDGEPORT_IQD:
Eugene Crosserc044dc22014-01-29 09:23:48 +01001269 if (cmd->data.sbp.hdr.command_code ==
1270 IPA_SBP_BRIDGE_PORT_STATE_CHANGE) {
1271 qeth_bridge_state_change(card, cmd);
1272 return 0;
1273 } else
1274 return 1;
1275 case IPA_CMD_ADDRESS_CHANGE_NOTIF:
1276 qeth_bridge_host_event(card, cmd);
1277 return 0;
1278 default:
1279 return 1;
1280 }
1281}
1282
Sebastian Ottc041f2d4872012-05-15 18:02:21 +02001283struct qeth_discipline qeth_l2_discipline = {
Julian Wiedmann2d2ebb32017-05-10 19:07:52 +02001284 .devtype = &qeth_l2_devtype,
Sebastian Ottc041f2d4872012-05-15 18:02:21 +02001285 .start_poll = qeth_qdio_start_poll,
1286 .input_handler = (qdio_handler_t *) qeth_qdio_input_handler,
1287 .output_handler = (qdio_handler_t *) qeth_qdio_output_handler,
Julian Wiedmannd73ef322017-04-11 16:11:11 +02001288 .process_rx_buffer = qeth_l2_process_inbound_buffer,
Sebastian Ottc041f2d4872012-05-15 18:02:21 +02001289 .recover = qeth_l2_recover,
1290 .setup = qeth_l2_probe_device,
Frank Blaschka4a71df52008-02-15 09:19:42 +01001291 .remove = qeth_l2_remove_device,
1292 .set_online = qeth_l2_set_online,
1293 .set_offline = qeth_l2_set_offline,
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02001294 .freeze = qeth_l2_pm_suspend,
1295 .thaw = qeth_l2_pm_resume,
1296 .restore = qeth_l2_pm_resume,
Julian Wiedmann942d6982017-04-11 16:11:10 +02001297 .do_ioctl = NULL,
Eugene Crosserc044dc22014-01-29 09:23:48 +01001298 .control_event_handler = qeth_l2_control_event,
Frank Blaschka4a71df52008-02-15 09:19:42 +01001299};
Sebastian Ottc041f2d4872012-05-15 18:02:21 +02001300EXPORT_SYMBOL_GPL(qeth_l2_discipline);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001301
1302static int qeth_osn_send_control_data(struct qeth_card *card, int len,
1303 struct qeth_cmd_buffer *iob)
1304{
1305 unsigned long flags;
1306 int rc = 0;
1307
Carsten Otte847a50f2010-06-21 22:57:05 +00001308 QETH_CARD_TEXT(card, 5, "osndctrd");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001309
1310 wait_event(card->wait_q,
1311 atomic_cmpxchg(&card->write.irq_pending, 0, 1) == 0);
1312 qeth_prepare_control_data(card, len, iob);
Carsten Otte847a50f2010-06-21 22:57:05 +00001313 QETH_CARD_TEXT(card, 6, "osnoirqp");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001314 spin_lock_irqsave(get_ccwdev_lock(card->write.ccwdev), flags);
1315 rc = ccw_device_start(card->write.ccwdev, &card->write.ccw,
1316 (addr_t) iob, 0, 0);
1317 spin_unlock_irqrestore(get_ccwdev_lock(card->write.ccwdev), flags);
1318 if (rc) {
Frank Blaschka14cc21b2008-06-06 12:37:46 +02001319 QETH_DBF_MESSAGE(2, "qeth_osn_send_control_data: "
Frank Blaschka4a71df52008-02-15 09:19:42 +01001320 "ccw_device_start rc = %i\n", rc);
Carsten Otte847a50f2010-06-21 22:57:05 +00001321 QETH_CARD_TEXT_(card, 2, " err%d", rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001322 qeth_release_buffer(iob->channel, iob);
1323 atomic_set(&card->write.irq_pending, 0);
1324 wake_up(&card->wait_q);
1325 }
1326 return rc;
1327}
1328
1329static int qeth_osn_send_ipa_cmd(struct qeth_card *card,
1330 struct qeth_cmd_buffer *iob, int data_len)
1331{
1332 u16 s1, s2;
1333
Carsten Otte847a50f2010-06-21 22:57:05 +00001334 QETH_CARD_TEXT(card, 4, "osndipa");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001335
1336 qeth_prepare_ipa_cmd(card, iob, QETH_PROT_OSN2);
1337 s1 = (u16)(IPA_PDU_HEADER_SIZE + data_len);
1338 s2 = (u16)data_len;
1339 memcpy(QETH_IPA_PDU_LEN_TOTAL(iob->data), &s1, 2);
1340 memcpy(QETH_IPA_PDU_LEN_PDU1(iob->data), &s2, 2);
1341 memcpy(QETH_IPA_PDU_LEN_PDU2(iob->data), &s2, 2);
1342 memcpy(QETH_IPA_PDU_LEN_PDU3(iob->data), &s2, 2);
1343 return qeth_osn_send_control_data(card, s1, iob);
1344}
1345
1346int qeth_osn_assist(struct net_device *dev, void *data, int data_len)
1347{
1348 struct qeth_cmd_buffer *iob;
1349 struct qeth_card *card;
1350 int rc;
1351
Frank Blaschka4a71df52008-02-15 09:19:42 +01001352 if (!dev)
1353 return -ENODEV;
Heiko Carstens509e2562008-07-26 02:24:10 -07001354 card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001355 if (!card)
1356 return -ENODEV;
Carsten Otte847a50f2010-06-21 22:57:05 +00001357 QETH_CARD_TEXT(card, 2, "osnsdmc");
Eugene Crosserc3521252015-01-16 14:05:47 +01001358 if (!qeth_card_hw_is_reachable(card))
Frank Blaschka4a71df52008-02-15 09:19:42 +01001359 return -ENODEV;
1360 iob = qeth_wait_for_buffer(&card->write);
1361 memcpy(iob->data+IPA_PDU_HEADER_SIZE, data, data_len);
1362 rc = qeth_osn_send_ipa_cmd(card, iob, data_len);
1363 return rc;
1364}
1365EXPORT_SYMBOL(qeth_osn_assist);
1366
1367int qeth_osn_register(unsigned char *read_dev_no, struct net_device **dev,
1368 int (*assist_cb)(struct net_device *, void *),
1369 int (*data_cb)(struct sk_buff *))
1370{
1371 struct qeth_card *card;
1372
Frank Blaschka4a71df52008-02-15 09:19:42 +01001373 *dev = qeth_l2_netdev_by_devno(read_dev_no);
1374 if (*dev == NULL)
1375 return -ENODEV;
Heiko Carstens509e2562008-07-26 02:24:10 -07001376 card = (*dev)->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001377 if (!card)
1378 return -ENODEV;
Carsten Otte847a50f2010-06-21 22:57:05 +00001379 QETH_CARD_TEXT(card, 2, "osnreg");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001380 if ((assist_cb == NULL) || (data_cb == NULL))
1381 return -EINVAL;
1382 card->osn_info.assist_cb = assist_cb;
1383 card->osn_info.data_cb = data_cb;
1384 return 0;
1385}
1386EXPORT_SYMBOL(qeth_osn_register);
1387
1388void qeth_osn_deregister(struct net_device *dev)
1389{
1390 struct qeth_card *card;
1391
Frank Blaschka4a71df52008-02-15 09:19:42 +01001392 if (!dev)
1393 return;
Heiko Carstens509e2562008-07-26 02:24:10 -07001394 card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001395 if (!card)
1396 return;
Carsten Otte847a50f2010-06-21 22:57:05 +00001397 QETH_CARD_TEXT(card, 2, "osndereg");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001398 card->osn_info.assist_cb = NULL;
1399 card->osn_info.data_cb = NULL;
1400 return;
1401}
1402EXPORT_SYMBOL(qeth_osn_deregister);
1403
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001404/* SETBRIDGEPORT support, async notifications */
1405
Eugene Crosser9f48b9d2014-01-14 15:54:13 +01001406enum qeth_an_event_type {anev_reg_unreg, anev_abort, anev_reset};
1407
1408/**
1409 * qeth_bridge_emit_host_event() - bridgeport address change notification
1410 * @card: qeth_card structure pointer, for udev events.
1411 * @evtype: "normal" register/unregister, or abort, or reset. For abort
1412 * and reset token and addr_lnid are unused and may be NULL.
1413 * @code: event bitmask: high order bit 0x80 value 1 means removal of an
1414 * object, 0 - addition of an object.
1415 * 0x01 - VLAN, 0x02 - MAC, 0x03 - VLAN and MAC.
1416 * @token: "network token" structure identifying physical address of the port.
1417 * @addr_lnid: pointer to structure with MAC address and VLAN ID.
1418 *
1419 * This function is called when registrations and deregistrations are
1420 * reported by the hardware, and also when notifications are enabled -
1421 * for all currently registered addresses.
1422 */
1423static void qeth_bridge_emit_host_event(struct qeth_card *card,
1424 enum qeth_an_event_type evtype,
1425 u8 code, struct net_if_token *token, struct mac_addr_lnid *addr_lnid)
1426{
1427 char str[7][32];
1428 char *env[8];
1429 int i = 0;
1430
1431 switch (evtype) {
1432 case anev_reg_unreg:
1433 snprintf(str[i], sizeof(str[i]), "BRIDGEDHOST=%s",
1434 (code & IPA_ADDR_CHANGE_CODE_REMOVAL)
1435 ? "deregister" : "register");
1436 env[i] = str[i]; i++;
1437 if (code & IPA_ADDR_CHANGE_CODE_VLANID) {
1438 snprintf(str[i], sizeof(str[i]), "VLAN=%d",
1439 addr_lnid->lnid);
1440 env[i] = str[i]; i++;
1441 }
1442 if (code & IPA_ADDR_CHANGE_CODE_MACADDR) {
Eugene Crosser9846e702015-09-18 16:06:48 +02001443 snprintf(str[i], sizeof(str[i]), "MAC=%pM",
Thomas Richter4d7def22015-09-18 16:06:51 +02001444 addr_lnid->mac);
Eugene Crosser9f48b9d2014-01-14 15:54:13 +01001445 env[i] = str[i]; i++;
1446 }
1447 snprintf(str[i], sizeof(str[i]), "NTOK_BUSID=%x.%x.%04x",
1448 token->cssid, token->ssid, token->devnum);
1449 env[i] = str[i]; i++;
1450 snprintf(str[i], sizeof(str[i]), "NTOK_IID=%02x", token->iid);
1451 env[i] = str[i]; i++;
1452 snprintf(str[i], sizeof(str[i]), "NTOK_CHPID=%02x",
1453 token->chpid);
1454 env[i] = str[i]; i++;
1455 snprintf(str[i], sizeof(str[i]), "NTOK_CHID=%04x", token->chid);
1456 env[i] = str[i]; i++;
1457 break;
1458 case anev_abort:
1459 snprintf(str[i], sizeof(str[i]), "BRIDGEDHOST=abort");
1460 env[i] = str[i]; i++;
1461 break;
1462 case anev_reset:
1463 snprintf(str[i], sizeof(str[i]), "BRIDGEDHOST=reset");
1464 env[i] = str[i]; i++;
1465 break;
1466 }
1467 env[i] = NULL;
1468 kobject_uevent_env(&card->gdev->dev.kobj, KOBJ_CHANGE, env);
1469}
1470
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001471struct qeth_bridge_state_data {
1472 struct work_struct worker;
1473 struct qeth_card *card;
1474 struct qeth_sbp_state_change qports;
1475};
1476
1477static void qeth_bridge_state_change_worker(struct work_struct *work)
1478{
1479 struct qeth_bridge_state_data *data =
1480 container_of(work, struct qeth_bridge_state_data, worker);
1481 /* We are only interested in the first entry - local port */
1482 struct qeth_sbp_port_entry *entry = &data->qports.entry[0];
1483 char env_locrem[32];
1484 char env_role[32];
1485 char env_state[32];
1486 char *env[] = {
1487 env_locrem,
1488 env_role,
1489 env_state,
1490 NULL
1491 };
1492
1493 /* Role should not change by itself, but if it did, */
1494 /* information from the hardware is authoritative. */
1495 mutex_lock(&data->card->conf_mutex);
1496 data->card->options.sbp.role = entry->role;
1497 mutex_unlock(&data->card->conf_mutex);
1498
1499 snprintf(env_locrem, sizeof(env_locrem), "BRIDGEPORT=statechange");
1500 snprintf(env_role, sizeof(env_role), "ROLE=%s",
1501 (entry->role == QETH_SBP_ROLE_NONE) ? "none" :
1502 (entry->role == QETH_SBP_ROLE_PRIMARY) ? "primary" :
1503 (entry->role == QETH_SBP_ROLE_SECONDARY) ? "secondary" :
1504 "<INVALID>");
1505 snprintf(env_state, sizeof(env_state), "STATE=%s",
1506 (entry->state == QETH_SBP_STATE_INACTIVE) ? "inactive" :
1507 (entry->state == QETH_SBP_STATE_STANDBY) ? "standby" :
1508 (entry->state == QETH_SBP_STATE_ACTIVE) ? "active" :
1509 "<INVALID>");
1510 kobject_uevent_env(&data->card->gdev->dev.kobj,
1511 KOBJ_CHANGE, env);
1512 kfree(data);
1513}
1514
Eugene Crosserc044dc22014-01-29 09:23:48 +01001515static void qeth_bridge_state_change(struct qeth_card *card,
1516 struct qeth_ipa_cmd *cmd)
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001517{
1518 struct qeth_sbp_state_change *qports =
1519 &cmd->data.sbp.data.state_change;
1520 struct qeth_bridge_state_data *data;
1521 int extrasize;
1522
1523 QETH_CARD_TEXT(card, 2, "brstchng");
1524 if (qports->entry_length != sizeof(struct qeth_sbp_port_entry)) {
Thomas Richter8a593142014-10-22 12:18:03 +02001525 QETH_CARD_TEXT_(card, 2, "BPsz%04x", qports->entry_length);
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001526 return;
1527 }
1528 extrasize = sizeof(struct qeth_sbp_port_entry) * qports->num_entries;
1529 data = kzalloc(sizeof(struct qeth_bridge_state_data) + extrasize,
1530 GFP_ATOMIC);
1531 if (!data) {
1532 QETH_CARD_TEXT(card, 2, "BPSalloc");
1533 return;
1534 }
1535 INIT_WORK(&data->worker, qeth_bridge_state_change_worker);
1536 data->card = card;
1537 memcpy(&data->qports, qports,
1538 sizeof(struct qeth_sbp_state_change) + extrasize);
1539 queue_work(qeth_wq, &data->worker);
1540}
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001541
Eugene Crosser9f48b9d2014-01-14 15:54:13 +01001542struct qeth_bridge_host_data {
1543 struct work_struct worker;
1544 struct qeth_card *card;
1545 struct qeth_ipacmd_addr_change hostevs;
1546};
1547
1548static void qeth_bridge_host_event_worker(struct work_struct *work)
1549{
1550 struct qeth_bridge_host_data *data =
1551 container_of(work, struct qeth_bridge_host_data, worker);
1552 int i;
1553
1554 if (data->hostevs.lost_event_mask) {
1555 dev_info(&data->card->gdev->dev,
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001556"Address notification from the Bridge Port stopped %s (%s)\n",
Eugene Crosser9f48b9d2014-01-14 15:54:13 +01001557 data->card->dev->name,
1558 (data->hostevs.lost_event_mask == 0x01)
1559 ? "Overflow"
1560 : (data->hostevs.lost_event_mask == 0x02)
1561 ? "Bridge port state change"
1562 : "Unknown reason");
1563 mutex_lock(&data->card->conf_mutex);
1564 data->card->options.sbp.hostnotification = 0;
1565 mutex_unlock(&data->card->conf_mutex);
1566 qeth_bridge_emit_host_event(data->card, anev_abort,
1567 0, NULL, NULL);
1568 } else
1569 for (i = 0; i < data->hostevs.num_entries; i++) {
1570 struct qeth_ipacmd_addr_change_entry *entry =
1571 &data->hostevs.entry[i];
1572 qeth_bridge_emit_host_event(data->card,
1573 anev_reg_unreg,
1574 entry->change_code,
1575 &entry->token, &entry->addr_lnid);
1576 }
1577 kfree(data);
1578}
1579
Eugene Crosserc044dc22014-01-29 09:23:48 +01001580static void qeth_bridge_host_event(struct qeth_card *card,
1581 struct qeth_ipa_cmd *cmd)
Eugene Crosser9f48b9d2014-01-14 15:54:13 +01001582{
1583 struct qeth_ipacmd_addr_change *hostevs =
1584 &cmd->data.addrchange;
1585 struct qeth_bridge_host_data *data;
1586 int extrasize;
1587
1588 QETH_CARD_TEXT(card, 2, "brhostev");
1589 if (cmd->hdr.return_code != 0x0000) {
1590 if (cmd->hdr.return_code == 0x0010) {
1591 if (hostevs->lost_event_mask == 0x00)
1592 hostevs->lost_event_mask = 0xff;
1593 } else {
1594 QETH_CARD_TEXT_(card, 2, "BPHe%04x",
1595 cmd->hdr.return_code);
1596 return;
1597 }
1598 }
1599 extrasize = sizeof(struct qeth_ipacmd_addr_change_entry) *
1600 hostevs->num_entries;
1601 data = kzalloc(sizeof(struct qeth_bridge_host_data) + extrasize,
1602 GFP_ATOMIC);
1603 if (!data) {
1604 QETH_CARD_TEXT(card, 2, "BPHalloc");
1605 return;
1606 }
1607 INIT_WORK(&data->worker, qeth_bridge_host_event_worker);
1608 data->card = card;
1609 memcpy(&data->hostevs, hostevs,
1610 sizeof(struct qeth_ipacmd_addr_change) + extrasize);
1611 queue_work(qeth_wq, &data->worker);
1612}
Eugene Crosser9f48b9d2014-01-14 15:54:13 +01001613
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001614/* SETBRIDGEPORT support; sending commands */
1615
1616struct _qeth_sbp_cbctl {
1617 u16 ipa_rc;
1618 u16 cmd_rc;
1619 union {
1620 u32 supported;
1621 struct {
1622 enum qeth_sbp_roles *role;
1623 enum qeth_sbp_states *state;
1624 } qports;
1625 } data;
1626};
1627
1628/**
1629 * qeth_bridgeport_makerc() - derive "traditional" error from hardware codes.
1630 * @card: qeth_card structure pointer, for debug messages.
1631 * @cbctl: state structure with hardware return codes.
1632 * @setcmd: IPA command code
1633 *
1634 * Returns negative errno-compatible error indication or 0 on success.
1635 */
1636static int qeth_bridgeport_makerc(struct qeth_card *card,
1637 struct _qeth_sbp_cbctl *cbctl, enum qeth_ipa_sbp_cmd setcmd)
1638{
1639 int rc;
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001640 int is_iqd = (card->info.type == QETH_CARD_TYPE_IQD);
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001641
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001642 if ((is_iqd && (cbctl->ipa_rc == IPA_RC_SUCCESS)) ||
1643 (!is_iqd && (cbctl->ipa_rc == cbctl->cmd_rc)))
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001644 switch (cbctl->cmd_rc) {
Kittipon Meesompop2063a5f2017-06-20 16:00:31 +02001645 case IPA_RC_SUCCESS:
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001646 rc = 0;
1647 break;
Kittipon Meesompop2063a5f2017-06-20 16:00:31 +02001648 case IPA_RC_L2_UNSUPPORTED_CMD:
1649 case IPA_RC_UNSUPPORTED_COMMAND:
Eugene Crosserffb95252015-05-18 14:27:58 +02001650 rc = -EOPNOTSUPP;
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001651 break;
Kittipon Meesompop2063a5f2017-06-20 16:00:31 +02001652 case IPA_RC_SBP_OSA_NOT_CONFIGURED:
1653 case IPA_RC_SBP_IQD_NOT_CONFIGURED:
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001654 rc = -ENODEV; /* maybe not the best code here? */
1655 dev_err(&card->gdev->dev,
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001656 "The device is not configured as a Bridge Port\n");
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001657 break;
Kittipon Meesompop2063a5f2017-06-20 16:00:31 +02001658 case IPA_RC_SBP_OSA_OS_MISMATCH:
1659 case IPA_RC_SBP_IQD_OS_MISMATCH:
Eugene Crosser1b05cf62016-06-16 16:18:51 +02001660 rc = -EPERM;
1661 dev_err(&card->gdev->dev,
1662 "A Bridge Port is already configured by a different operating system\n");
1663 break;
Kittipon Meesompop2063a5f2017-06-20 16:00:31 +02001664 case IPA_RC_SBP_OSA_ANO_DEV_PRIMARY:
1665 case IPA_RC_SBP_IQD_ANO_DEV_PRIMARY:
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001666 switch (setcmd) {
1667 case IPA_SBP_SET_PRIMARY_BRIDGE_PORT:
1668 rc = -EEXIST;
1669 dev_err(&card->gdev->dev,
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001670 "The LAN already has a primary Bridge Port\n");
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001671 break;
1672 case IPA_SBP_SET_SECONDARY_BRIDGE_PORT:
1673 rc = -EBUSY;
1674 dev_err(&card->gdev->dev,
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001675 "The device is already a primary Bridge Port\n");
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001676 break;
1677 default:
1678 rc = -EIO;
1679 }
1680 break;
Kittipon Meesompop2063a5f2017-06-20 16:00:31 +02001681 case IPA_RC_SBP_OSA_CURRENT_SECOND:
1682 case IPA_RC_SBP_IQD_CURRENT_SECOND:
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001683 rc = -EBUSY;
1684 dev_err(&card->gdev->dev,
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001685 "The device is already a secondary Bridge Port\n");
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001686 break;
Kittipon Meesompop2063a5f2017-06-20 16:00:31 +02001687 case IPA_RC_SBP_OSA_LIMIT_SECOND:
1688 case IPA_RC_SBP_IQD_LIMIT_SECOND:
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001689 rc = -EEXIST;
1690 dev_err(&card->gdev->dev,
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001691 "The LAN cannot have more secondary Bridge Ports\n");
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001692 break;
Kittipon Meesompop2063a5f2017-06-20 16:00:31 +02001693 case IPA_RC_SBP_OSA_CURRENT_PRIMARY:
1694 case IPA_RC_SBP_IQD_CURRENT_PRIMARY:
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001695 rc = -EBUSY;
1696 dev_err(&card->gdev->dev,
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001697 "The device is already a primary Bridge Port\n");
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001698 break;
Kittipon Meesompop2063a5f2017-06-20 16:00:31 +02001699 case IPA_RC_SBP_OSA_NOT_AUTHD_BY_ZMAN:
1700 case IPA_RC_SBP_IQD_NOT_AUTHD_BY_ZMAN:
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001701 rc = -EACCES;
1702 dev_err(&card->gdev->dev,
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001703 "The device is not authorized to be a Bridge Port\n");
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001704 break;
1705 default:
1706 rc = -EIO;
1707 }
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001708 else
1709 switch (cbctl->ipa_rc) {
1710 case IPA_RC_NOTSUPP:
Eugene Crosserffb95252015-05-18 14:27:58 +02001711 rc = -EOPNOTSUPP;
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001712 break;
1713 case IPA_RC_UNSUPPORTED_COMMAND:
Eugene Crosserffb95252015-05-18 14:27:58 +02001714 rc = -EOPNOTSUPP;
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001715 break;
1716 default:
1717 rc = -EIO;
1718 }
1719
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001720 if (rc) {
1721 QETH_CARD_TEXT_(card, 2, "SBPi%04x", cbctl->ipa_rc);
1722 QETH_CARD_TEXT_(card, 2, "SBPc%04x", cbctl->cmd_rc);
1723 }
1724 return rc;
1725}
1726
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001727static inline int ipa_cmd_sbp(struct qeth_card *card)
1728{
1729 return (card->info.type == QETH_CARD_TYPE_IQD) ?
1730 IPA_CMD_SETBRIDGEPORT_IQD :
1731 IPA_CMD_SETBRIDGEPORT_OSA;
1732}
1733
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001734static int qeth_bridgeport_query_support_cb(struct qeth_card *card,
1735 struct qeth_reply *reply, unsigned long data)
1736{
1737 struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *) data;
1738 struct _qeth_sbp_cbctl *cbctl = (struct _qeth_sbp_cbctl *)reply->param;
1739 QETH_CARD_TEXT(card, 2, "brqsupcb");
1740 cbctl->ipa_rc = cmd->hdr.return_code;
1741 cbctl->cmd_rc = cmd->data.sbp.hdr.return_code;
1742 if ((cbctl->ipa_rc == 0) && (cbctl->cmd_rc == 0)) {
1743 cbctl->data.supported =
1744 cmd->data.sbp.data.query_cmds_supp.supported_cmds;
1745 } else {
1746 cbctl->data.supported = 0;
1747 }
1748 return 0;
1749}
1750
1751/**
1752 * qeth_bridgeport_query_support() - store bitmask of supported subfunctions.
1753 * @card: qeth_card structure pointer.
1754 *
1755 * Sets bitmask of supported setbridgeport subfunctions in the qeth_card
1756 * strucutre: card->options.sbp.supported_funcs.
1757 */
Eugene Crosserc044dc22014-01-29 09:23:48 +01001758static void qeth_bridgeport_query_support(struct qeth_card *card)
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001759{
1760 struct qeth_cmd_buffer *iob;
1761 struct qeth_ipa_cmd *cmd;
1762 struct _qeth_sbp_cbctl cbctl;
1763
1764 QETH_CARD_TEXT(card, 2, "brqsuppo");
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001765 iob = qeth_get_ipacmd_buffer(card, ipa_cmd_sbp(card), 0);
Thomas Richter1aec42b2015-01-21 13:39:10 +01001766 if (!iob)
1767 return;
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001768 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
1769 cmd->data.sbp.hdr.cmdlength =
1770 sizeof(struct qeth_ipacmd_sbp_hdr) +
1771 sizeof(struct qeth_sbp_query_cmds_supp);
1772 cmd->data.sbp.hdr.command_code =
1773 IPA_SBP_QUERY_COMMANDS_SUPPORTED;
1774 cmd->data.sbp.hdr.used_total = 1;
1775 cmd->data.sbp.hdr.seq_no = 1;
1776 if (qeth_send_ipa_cmd(card, iob, qeth_bridgeport_query_support_cb,
1777 (void *)&cbctl) ||
1778 qeth_bridgeport_makerc(card, &cbctl,
1779 IPA_SBP_QUERY_COMMANDS_SUPPORTED)) {
1780 /* non-zero makerc signifies failure, and produce messages */
1781 card->options.sbp.role = QETH_SBP_ROLE_NONE;
1782 return;
1783 }
1784 card->options.sbp.supported_funcs = cbctl.data.supported;
1785}
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001786
1787static int qeth_bridgeport_query_ports_cb(struct qeth_card *card,
1788 struct qeth_reply *reply, unsigned long data)
1789{
1790 struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *) data;
1791 struct qeth_sbp_query_ports *qports = &cmd->data.sbp.data.query_ports;
1792 struct _qeth_sbp_cbctl *cbctl = (struct _qeth_sbp_cbctl *)reply->param;
1793
1794 QETH_CARD_TEXT(card, 2, "brqprtcb");
1795 cbctl->ipa_rc = cmd->hdr.return_code;
1796 cbctl->cmd_rc = cmd->data.sbp.hdr.return_code;
1797 if ((cbctl->ipa_rc != 0) || (cbctl->cmd_rc != 0))
1798 return 0;
1799 if (qports->entry_length != sizeof(struct qeth_sbp_port_entry)) {
1800 cbctl->cmd_rc = 0xffff;
1801 QETH_CARD_TEXT_(card, 2, "SBPs%04x", qports->entry_length);
1802 return 0;
1803 }
1804 /* first entry contains the state of the local port */
1805 if (qports->num_entries > 0) {
1806 if (cbctl->data.qports.role)
1807 *cbctl->data.qports.role = qports->entry[0].role;
1808 if (cbctl->data.qports.state)
1809 *cbctl->data.qports.state = qports->entry[0].state;
1810 }
1811 return 0;
1812}
1813
1814/**
1815 * qeth_bridgeport_query_ports() - query local bridgeport status.
1816 * @card: qeth_card structure pointer.
1817 * @role: Role of the port: 0-none, 1-primary, 2-secondary.
1818 * @state: State of the port: 0-inactive, 1-standby, 2-active.
1819 *
1820 * Returns negative errno-compatible error indication or 0 on success.
1821 *
1822 * 'role' and 'state' are not updated in case of hardware operation failure.
1823 */
1824int qeth_bridgeport_query_ports(struct qeth_card *card,
1825 enum qeth_sbp_roles *role, enum qeth_sbp_states *state)
1826{
1827 int rc = 0;
1828 struct qeth_cmd_buffer *iob;
1829 struct qeth_ipa_cmd *cmd;
1830 struct _qeth_sbp_cbctl cbctl = {
1831 .data = {
1832 .qports = {
1833 .role = role,
1834 .state = state,
1835 },
1836 },
1837 };
1838
1839 QETH_CARD_TEXT(card, 2, "brqports");
1840 if (!(card->options.sbp.supported_funcs & IPA_SBP_QUERY_BRIDGE_PORTS))
1841 return -EOPNOTSUPP;
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001842 iob = qeth_get_ipacmd_buffer(card, ipa_cmd_sbp(card), 0);
Thomas Richter1aec42b2015-01-21 13:39:10 +01001843 if (!iob)
1844 return -ENOMEM;
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001845 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
1846 cmd->data.sbp.hdr.cmdlength =
1847 sizeof(struct qeth_ipacmd_sbp_hdr);
1848 cmd->data.sbp.hdr.command_code =
1849 IPA_SBP_QUERY_BRIDGE_PORTS;
1850 cmd->data.sbp.hdr.used_total = 1;
1851 cmd->data.sbp.hdr.seq_no = 1;
1852 rc = qeth_send_ipa_cmd(card, iob, qeth_bridgeport_query_ports_cb,
1853 (void *)&cbctl);
Eugene Crosserc88394e2015-05-18 14:27:53 +02001854 if (rc < 0)
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001855 return rc;
Eugene Crosserc88394e2015-05-18 14:27:53 +02001856 return qeth_bridgeport_makerc(card, &cbctl, IPA_SBP_QUERY_BRIDGE_PORTS);
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001857}
1858EXPORT_SYMBOL_GPL(qeth_bridgeport_query_ports);
1859
1860static int qeth_bridgeport_set_cb(struct qeth_card *card,
1861 struct qeth_reply *reply, unsigned long data)
1862{
1863 struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *)data;
1864 struct _qeth_sbp_cbctl *cbctl = (struct _qeth_sbp_cbctl *)reply->param;
1865 QETH_CARD_TEXT(card, 2, "brsetrcb");
1866 cbctl->ipa_rc = cmd->hdr.return_code;
1867 cbctl->cmd_rc = cmd->data.sbp.hdr.return_code;
1868 return 0;
1869}
1870
1871/**
1872 * qeth_bridgeport_setrole() - Assign primary role to the port.
1873 * @card: qeth_card structure pointer.
1874 * @role: Role to assign.
1875 *
1876 * Returns negative errno-compatible error indication or 0 on success.
1877 */
1878int qeth_bridgeport_setrole(struct qeth_card *card, enum qeth_sbp_roles role)
1879{
1880 int rc = 0;
1881 int cmdlength;
1882 struct qeth_cmd_buffer *iob;
1883 struct qeth_ipa_cmd *cmd;
1884 struct _qeth_sbp_cbctl cbctl;
1885 enum qeth_ipa_sbp_cmd setcmd;
1886
1887 QETH_CARD_TEXT(card, 2, "brsetrol");
1888 switch (role) {
1889 case QETH_SBP_ROLE_NONE:
1890 setcmd = IPA_SBP_RESET_BRIDGE_PORT_ROLE;
1891 cmdlength = sizeof(struct qeth_ipacmd_sbp_hdr) +
1892 sizeof(struct qeth_sbp_reset_role);
1893 break;
1894 case QETH_SBP_ROLE_PRIMARY:
1895 setcmd = IPA_SBP_SET_PRIMARY_BRIDGE_PORT;
1896 cmdlength = sizeof(struct qeth_ipacmd_sbp_hdr) +
1897 sizeof(struct qeth_sbp_set_primary);
1898 break;
1899 case QETH_SBP_ROLE_SECONDARY:
1900 setcmd = IPA_SBP_SET_SECONDARY_BRIDGE_PORT;
1901 cmdlength = sizeof(struct qeth_ipacmd_sbp_hdr) +
1902 sizeof(struct qeth_sbp_set_secondary);
1903 break;
1904 default:
1905 return -EINVAL;
1906 }
1907 if (!(card->options.sbp.supported_funcs & setcmd))
1908 return -EOPNOTSUPP;
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001909 iob = qeth_get_ipacmd_buffer(card, ipa_cmd_sbp(card), 0);
Thomas Richter1aec42b2015-01-21 13:39:10 +01001910 if (!iob)
1911 return -ENOMEM;
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001912 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
1913 cmd->data.sbp.hdr.cmdlength = cmdlength;
1914 cmd->data.sbp.hdr.command_code = setcmd;
1915 cmd->data.sbp.hdr.used_total = 1;
1916 cmd->data.sbp.hdr.seq_no = 1;
1917 rc = qeth_send_ipa_cmd(card, iob, qeth_bridgeport_set_cb,
1918 (void *)&cbctl);
Eugene Crosserc88394e2015-05-18 14:27:53 +02001919 if (rc < 0)
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001920 return rc;
Eugene Crosserc88394e2015-05-18 14:27:53 +02001921 return qeth_bridgeport_makerc(card, &cbctl, setcmd);
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001922}
1923
Eugene Crosser9f48b9d2014-01-14 15:54:13 +01001924/**
1925 * qeth_anset_makerc() - derive "traditional" error from hardware codes.
1926 * @card: qeth_card structure pointer, for debug messages.
1927 *
1928 * Returns negative errno-compatible error indication or 0 on success.
1929 */
1930static int qeth_anset_makerc(struct qeth_card *card, int pnso_rc, u16 response)
1931{
1932 int rc;
1933
1934 if (pnso_rc == 0)
1935 switch (response) {
1936 case 0x0001:
1937 rc = 0;
1938 break;
1939 case 0x0004:
1940 case 0x0100:
1941 case 0x0106:
Eugene Crosserffb95252015-05-18 14:27:58 +02001942 rc = -EOPNOTSUPP;
Eugene Crosser9f48b9d2014-01-14 15:54:13 +01001943 dev_err(&card->gdev->dev,
1944 "Setting address notification failed\n");
1945 break;
1946 case 0x0107:
1947 rc = -EAGAIN;
1948 break;
1949 default:
1950 rc = -EIO;
1951 }
1952 else
1953 rc = -EIO;
1954
1955 if (rc) {
1956 QETH_CARD_TEXT_(card, 2, "SBPp%04x", pnso_rc);
1957 QETH_CARD_TEXT_(card, 2, "SBPr%04x", response);
1958 }
1959 return rc;
1960}
1961
1962static void qeth_bridgeport_an_set_cb(void *priv,
1963 enum qdio_brinfo_entry_type type, void *entry)
1964{
1965 struct qeth_card *card = (struct qeth_card *)priv;
1966 struct qdio_brinfo_entry_l2 *l2entry;
1967 u8 code;
1968
1969 if (type != l2_addr_lnid) {
1970 WARN_ON_ONCE(1);
1971 return;
1972 }
1973
1974 l2entry = (struct qdio_brinfo_entry_l2 *)entry;
1975 code = IPA_ADDR_CHANGE_CODE_MACADDR;
1976 if (l2entry->addr_lnid.lnid)
1977 code |= IPA_ADDR_CHANGE_CODE_VLANID;
1978 qeth_bridge_emit_host_event(card, anev_reg_unreg, code,
1979 (struct net_if_token *)&l2entry->nit,
1980 (struct mac_addr_lnid *)&l2entry->addr_lnid);
1981}
1982
1983/**
1984 * qeth_bridgeport_an_set() - Enable or disable bridgeport address notification
1985 * @card: qeth_card structure pointer.
1986 * @enable: 0 - disable, non-zero - enable notifications
1987 *
1988 * Returns negative errno-compatible error indication or 0 on success.
1989 *
1990 * On enable, emits a series of address notifications udev events for all
1991 * currently registered hosts.
1992 */
1993int qeth_bridgeport_an_set(struct qeth_card *card, int enable)
1994{
1995 int rc;
1996 u16 response;
1997 struct ccw_device *ddev;
1998 struct subchannel_id schid;
1999
2000 if (!card)
2001 return -EINVAL;
2002 if (!card->options.sbp.supported_funcs)
2003 return -EOPNOTSUPP;
2004 ddev = CARD_DDEV(card);
2005 ccw_device_get_schid(ddev, &schid);
2006
2007 if (enable) {
2008 qeth_bridge_emit_host_event(card, anev_reset, 0, NULL, NULL);
2009 rc = qdio_pnso_brinfo(schid, 1, &response,
2010 qeth_bridgeport_an_set_cb, card);
2011 } else
2012 rc = qdio_pnso_brinfo(schid, 0, &response, NULL, NULL);
2013 return qeth_anset_makerc(card, rc, response);
2014}
2015EXPORT_SYMBOL_GPL(qeth_bridgeport_an_set);
2016
Frank Blaschka4a71df52008-02-15 09:19:42 +01002017module_init(qeth_l2_init);
2018module_exit(qeth_l2_exit);
2019MODULE_AUTHOR("Frank Blaschka <frank.blaschka@de.ibm.com>");
2020MODULE_DESCRIPTION("qeth layer 2 discipline");
2021MODULE_LICENSE("GPL");