blob: 9fd48de38a4cfdec0a02ab5e1f9d621a7883b918 [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>
19#include <linux/mii.h>
20#include <linux/ip.h>
Jiri Pirkoccffad252009-05-22 23:22:17 +000021#include <linux/list.h>
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +020022#include <linux/hash.h>
23#include <linux/hashtable.h>
24#include <linux/string.h>
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 *);
30static int qeth_l2_send_delmac(struct qeth_card *, __u8 *);
31static int qeth_l2_send_setdelmac(struct qeth_card *, __u8 *,
Eugene Crosserefbbc1d2015-01-21 13:39:09 +010032 enum qeth_ipa_cmds);
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +020033static void qeth_l2_set_rx_mode(struct net_device *);
Frank Blaschka4a71df52008-02-15 09:19:42 +010034static int qeth_l2_recover(void *);
Eugene Crosserc044dc22014-01-29 09:23:48 +010035static void qeth_bridgeport_query_support(struct qeth_card *card);
36static void qeth_bridge_state_change(struct qeth_card *card,
37 struct qeth_ipa_cmd *cmd);
38static void qeth_bridge_host_event(struct qeth_card *card,
39 struct qeth_ipa_cmd *cmd);
Frank Blaschka4a71df52008-02-15 09:19:42 +010040
41static int qeth_l2_do_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
42{
Heiko Carstens509e2562008-07-26 02:24:10 -070043 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +010044 struct mii_ioctl_data *mii_data;
45 int rc = 0;
46
47 if (!card)
48 return -ENODEV;
49
Eugene Crosserc3521252015-01-16 14:05:47 +010050 if (!qeth_card_hw_is_reachable(card))
Frank Blaschka4a71df52008-02-15 09:19:42 +010051 return -ENODEV;
52
53 if (card->info.type == QETH_CARD_TYPE_OSN)
54 return -EPERM;
55
56 switch (cmd) {
57 case SIOC_QETH_ADP_SET_SNMP_CONTROL:
58 rc = qeth_snmp_command(card, rq->ifr_ifru.ifru_data);
59 break;
60 case SIOC_QETH_GET_CARD_TYPE:
Ursula Braun5113fec2010-05-16 21:15:14 +000061 if ((card->info.type == QETH_CARD_TYPE_OSD ||
62 card->info.type == QETH_CARD_TYPE_OSM ||
63 card->info.type == QETH_CARD_TYPE_OSX) &&
Frank Blaschka4a71df52008-02-15 09:19:42 +010064 !card->info.guestlan)
65 return 1;
66 return 0;
67 break;
68 case SIOCGMIIPHY:
69 mii_data = if_mii(rq);
70 mii_data->phy_id = 0;
71 break;
72 case SIOCGMIIREG:
73 mii_data = if_mii(rq);
74 if (mii_data->phy_id != 0)
75 rc = -EINVAL;
76 else
77 mii_data->val_out = qeth_mdio_read(dev,
78 mii_data->phy_id, mii_data->reg_num);
79 break;
Frank Blaschkac3ab96f2012-02-08 00:19:49 +000080 case SIOC_QETH_QUERY_OAT:
81 rc = qeth_query_oat_command(card, rq->ifr_ifru.ifru_data);
82 break;
Frank Blaschka4a71df52008-02-15 09:19:42 +010083 default:
84 rc = -EOPNOTSUPP;
85 }
86 if (rc)
Carsten Otte847a50f2010-06-21 22:57:05 +000087 QETH_CARD_TEXT_(card, 2, "ioce%d", rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +010088 return rc;
89}
90
91static int qeth_l2_verify_dev(struct net_device *dev)
92{
93 struct qeth_card *card;
94 unsigned long flags;
95 int rc = 0;
96
97 read_lock_irqsave(&qeth_core_card_list.rwlock, flags);
98 list_for_each_entry(card, &qeth_core_card_list.list, list) {
99 if (card->dev == dev) {
100 rc = QETH_REAL_CARD;
101 break;
102 }
103 }
104 read_unlock_irqrestore(&qeth_core_card_list.rwlock, flags);
105
106 return rc;
107}
108
109static struct net_device *qeth_l2_netdev_by_devno(unsigned char *read_dev_no)
110{
111 struct qeth_card *card;
112 struct net_device *ndev;
Cornelia Huckf06f6f32008-06-06 12:37:45 +0200113 __u16 temp_dev_no;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100114 unsigned long flags;
Cornelia Huckf06f6f32008-06-06 12:37:45 +0200115 struct ccw_dev_id read_devid;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100116
117 ndev = NULL;
118 memcpy(&temp_dev_no, read_dev_no, 2);
119 read_lock_irqsave(&qeth_core_card_list.rwlock, flags);
120 list_for_each_entry(card, &qeth_core_card_list.list, list) {
Cornelia Huckf06f6f32008-06-06 12:37:45 +0200121 ccw_device_get_id(CARD_RDEV(card), &read_devid);
122 if (read_devid.devno == temp_dev_no) {
Frank Blaschka4a71df52008-02-15 09:19:42 +0100123 ndev = card->dev;
124 break;
125 }
126 }
127 read_unlock_irqrestore(&qeth_core_card_list.rwlock, flags);
128 return ndev;
129}
130
Eugene Crosserefbbc1d2015-01-21 13:39:09 +0100131static int qeth_setdel_makerc(struct qeth_card *card, int retcode)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100132{
Eugene Crosserefbbc1d2015-01-21 13:39:09 +0100133 int rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100134
Eugene Crosserefbbc1d2015-01-21 13:39:09 +0100135 if (retcode)
Thomas Richter1aec42b2015-01-21 13:39:10 +0100136 QETH_CARD_TEXT_(card, 2, "err%04x", retcode);
Eugene Crosserefbbc1d2015-01-21 13:39:09 +0100137 switch (retcode) {
138 case IPA_RC_SUCCESS:
139 rc = 0;
140 break;
141 case IPA_RC_L2_UNSUPPORTED_CMD:
Eugene Crosserffb95252015-05-18 14:27:58 +0200142 rc = -EOPNOTSUPP;
Eugene Crosserefbbc1d2015-01-21 13:39:09 +0100143 break;
144 case IPA_RC_L2_ADDR_TABLE_FULL:
145 rc = -ENOSPC;
146 break;
147 case IPA_RC_L2_DUP_MAC:
148 case IPA_RC_L2_DUP_LAYER3_MAC:
149 rc = -EEXIST;
150 break;
151 case IPA_RC_L2_MAC_NOT_AUTH_BY_HYP:
152 case IPA_RC_L2_MAC_NOT_AUTH_BY_ADP:
153 rc = -EPERM;
154 break;
155 case IPA_RC_L2_MAC_NOT_FOUND:
156 rc = -ENOENT;
157 break;
Thomas Richter1aec42b2015-01-21 13:39:10 +0100158 case -ENOMEM:
159 rc = -ENOMEM;
160 break;
Eugene Crosserefbbc1d2015-01-21 13:39:09 +0100161 default:
162 rc = -EIO;
163 break;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100164 }
Eugene Crosserefbbc1d2015-01-21 13:39:09 +0100165 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100166}
167
168static int qeth_l2_send_setgroupmac(struct qeth_card *card, __u8 *mac)
169{
Eugene Crosserefbbc1d2015-01-21 13:39:09 +0100170 int rc;
171
Carsten Otte847a50f2010-06-21 22:57:05 +0000172 QETH_CARD_TEXT(card, 2, "L2Sgmac");
Eugene Crosserefbbc1d2015-01-21 13:39:09 +0100173 rc = qeth_setdel_makerc(card, qeth_l2_send_setdelmac(card, mac,
174 IPA_CMD_SETGMAC));
175 if (rc == -EEXIST)
176 QETH_DBF_MESSAGE(2, "Group MAC %pM already existing on %s\n",
177 mac, QETH_CARD_IFNAME(card));
178 else if (rc)
179 QETH_DBF_MESSAGE(2, "Could not set group MAC %pM on %s: %d\n",
180 mac, QETH_CARD_IFNAME(card), rc);
181 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100182}
183
184static int qeth_l2_send_delgroupmac(struct qeth_card *card, __u8 *mac)
185{
Eugene Crosserefbbc1d2015-01-21 13:39:09 +0100186 int rc;
187
Carsten Otte847a50f2010-06-21 22:57:05 +0000188 QETH_CARD_TEXT(card, 2, "L2Dgmac");
Eugene Crosserefbbc1d2015-01-21 13:39:09 +0100189 rc = qeth_setdel_makerc(card, qeth_l2_send_setdelmac(card, mac,
190 IPA_CMD_DELGMAC));
191 if (rc)
192 QETH_DBF_MESSAGE(2,
193 "Could not delete group MAC %pM on %s: %d\n",
194 mac, QETH_CARD_IFNAME(card), rc);
195 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100196}
197
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200198static inline u32 qeth_l2_mac_hash(const u8 *addr)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100199{
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200200 return get_unaligned((u32 *)(&addr[2]));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100201}
202
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200203static int qeth_l2_write_mac(struct qeth_card *card, struct qeth_mac *mac)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100204{
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200205
206 int rc;
207
208 if (mac->is_uc) {
209 rc = qeth_setdel_makerc(card,
210 qeth_l2_send_setdelmac(card, mac->mac_addr,
211 IPA_CMD_SETVMAC));
212 } else {
213 rc = qeth_setdel_makerc(card,
214 qeth_l2_send_setgroupmac(card, mac->mac_addr));
215 }
216 return rc;
217}
218
219static void qeth_l2_del_all_macs(struct qeth_card *card, int del)
220{
221 struct qeth_mac *mac;
222 struct hlist_node *tmp;
223 int i;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100224
225 spin_lock_bh(&card->mclock);
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200226 hash_for_each_safe(card->mac_htable, i, tmp, mac, hnode) {
Ursula Braun70919e22011-02-26 22:41:36 -0800227 if (del) {
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200228 if (mac->is_uc)
229 qeth_l2_send_setdelmac(card, mac->mac_addr,
230 IPA_CMD_DELVMAC);
Ursula Braun70919e22011-02-26 22:41:36 -0800231 else
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200232 qeth_l2_send_delgroupmac(card, mac->mac_addr);
Ursula Braun70919e22011-02-26 22:41:36 -0800233 }
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200234 hash_del(&mac->hnode);
235 kfree(mac);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100236 }
237 spin_unlock_bh(&card->mclock);
238}
239
Klaus-Dieter Wackerce73e102009-08-26 02:01:08 +0000240static inline int qeth_l2_get_cast_type(struct qeth_card *card,
241 struct sk_buff *skb)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100242{
Klaus-Dieter Wackerce73e102009-08-26 02:01:08 +0000243 if (card->info.type == QETH_CARD_TYPE_OSN)
244 return RTN_UNSPEC;
245 if (is_broadcast_ether_addr(skb->data))
246 return RTN_BROADCAST;
247 if (is_multicast_ether_addr(skb->data))
248 return RTN_MULTICAST;
249 return RTN_UNSPEC;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100250}
251
Thomas Richter4d7def22015-09-18 16:06:51 +0200252static inline void qeth_l2_hdr_csum(struct qeth_card *card,
253 struct qeth_hdr *hdr, struct sk_buff *skb)
254{
255 struct iphdr *iph = ip_hdr(skb);
256
257 /* tcph->check contains already the pseudo hdr checksum
258 * so just set the header flags
259 */
260 if (iph->protocol == IPPROTO_UDP)
261 hdr->hdr.l2.flags[1] |= QETH_HDR_EXT_UDP;
262 hdr->hdr.l2.flags[1] |= QETH_HDR_EXT_CSUM_TRANSP_REQ |
263 QETH_HDR_EXT_CSUM_HDR_REQ;
264 iph->check = 0;
265 if (card->options.performance_stats)
266 card->perf_stats.tx_csum++;
267}
268
Frank Blaschka4a71df52008-02-15 09:19:42 +0100269static void qeth_l2_fill_header(struct qeth_card *card, struct qeth_hdr *hdr,
Stefan Raspl43934072014-03-19 07:58:01 +0100270 struct sk_buff *skb, int cast_type)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100271{
Frank Blaschka683d7182008-08-01 16:39:13 +0200272 struct vlan_ethhdr *veth = (struct vlan_ethhdr *)skb_mac_header(skb);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100273
274 memset(hdr, 0, sizeof(struct qeth_hdr));
275 hdr->hdr.l2.id = QETH_HEADER_TYPE_LAYER2;
276
277 /* set byte byte 3 to casting flags */
278 if (cast_type == RTN_MULTICAST)
279 hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_MULTICAST;
280 else if (cast_type == RTN_BROADCAST)
281 hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_BROADCAST;
282 else
Klaus-Dieter Wackerce73e102009-08-26 02:01:08 +0000283 hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_UNICAST;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100284
285 hdr->hdr.l2.pkt_length = skb->len-QETH_HEADER_SIZE;
286 /* VSWITCH relies on the VLAN
287 * information to be present in
288 * the QDIO header */
289 if (veth->h_vlan_proto == __constant_htons(ETH_P_8021Q)) {
290 hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_VLAN;
291 hdr->hdr.l2.vlan_id = ntohs(veth->h_vlan_TCI);
292 }
293}
294
295static int qeth_l2_send_setdelvlan_cb(struct qeth_card *card,
296 struct qeth_reply *reply, unsigned long data)
297{
298 struct qeth_ipa_cmd *cmd;
299
Carsten Otte847a50f2010-06-21 22:57:05 +0000300 QETH_CARD_TEXT(card, 2, "L2sdvcb");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100301 cmd = (struct qeth_ipa_cmd *) data;
302 if (cmd->hdr.return_code) {
Frank Blaschka14cc21b2008-06-06 12:37:46 +0200303 QETH_DBF_MESSAGE(2, "Error in processing VLAN %i on %s: 0x%x. "
Frank Blaschka4a71df52008-02-15 09:19:42 +0100304 "Continuing\n", cmd->data.setdelvlan.vlan_id,
305 QETH_CARD_IFNAME(card), cmd->hdr.return_code);
Carsten Otte847a50f2010-06-21 22:57:05 +0000306 QETH_CARD_TEXT_(card, 2, "L2VL%4x", cmd->hdr.command);
307 QETH_CARD_TEXT_(card, 2, "err%d", cmd->hdr.return_code);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100308 }
309 return 0;
310}
311
312static int qeth_l2_send_setdelvlan(struct qeth_card *card, __u16 i,
313 enum qeth_ipa_cmds ipacmd)
314{
315 struct qeth_ipa_cmd *cmd;
316 struct qeth_cmd_buffer *iob;
317
Carsten Otte847a50f2010-06-21 22:57:05 +0000318 QETH_CARD_TEXT_(card, 4, "L2sdv%x", ipacmd);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100319 iob = qeth_get_ipacmd_buffer(card, ipacmd, QETH_PROT_IPV4);
Thomas Richter1aec42b2015-01-21 13:39:10 +0100320 if (!iob)
321 return -ENOMEM;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100322 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
323 cmd->data.setdelvlan.vlan_id = i;
324 return qeth_send_ipa_cmd(card, iob,
325 qeth_l2_send_setdelvlan_cb, NULL);
326}
327
Ursula Braun70919e22011-02-26 22:41:36 -0800328static void qeth_l2_process_vlans(struct qeth_card *card)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100329{
330 struct qeth_vlan_vid *id;
Carsten Otte847a50f2010-06-21 22:57:05 +0000331 QETH_CARD_TEXT(card, 3, "L2prcvln");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100332 spin_lock_bh(&card->vlanlock);
333 list_for_each_entry(id, &card->vid_list, list) {
Ursula Braun70919e22011-02-26 22:41:36 -0800334 qeth_l2_send_setdelvlan(card, id->vid, IPA_CMD_SETVLAN);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100335 }
336 spin_unlock_bh(&card->vlanlock);
337}
338
Patrick McHardy80d5c362013-04-19 02:04:28 +0000339static int qeth_l2_vlan_rx_add_vid(struct net_device *dev,
340 __be16 proto, u16 vid)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100341{
Heiko Carstens509e2562008-07-26 02:24:10 -0700342 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100343 struct qeth_vlan_vid *id;
Thomas Richter1aec42b2015-01-21 13:39:10 +0100344 int rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100345
Carsten Otte847a50f2010-06-21 22:57:05 +0000346 QETH_CARD_TEXT_(card, 4, "aid:%d", vid);
Ursula Braun10651db2010-10-01 02:51:13 +0000347 if (!vid)
Jiri Pirko8e586132011-12-08 19:52:37 -0500348 return 0;
Ursula Braun5113fec2010-05-16 21:15:14 +0000349 if (card->info.type == QETH_CARD_TYPE_OSM) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000350 QETH_CARD_TEXT(card, 3, "aidOSM");
Jiri Pirko8e586132011-12-08 19:52:37 -0500351 return 0;
Ursula Braun5113fec2010-05-16 21:15:14 +0000352 }
Ursula Braun8e98ac42009-03-24 20:57:18 +0000353 if (qeth_wait_for_threads(card, QETH_RECOVER_THREAD)) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000354 QETH_CARD_TEXT(card, 3, "aidREC");
Jiri Pirko8e586132011-12-08 19:52:37 -0500355 return 0;
Ursula Braun8e98ac42009-03-24 20:57:18 +0000356 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100357 id = kmalloc(sizeof(struct qeth_vlan_vid), GFP_ATOMIC);
358 if (id) {
359 id->vid = vid;
Thomas Richter1aec42b2015-01-21 13:39:10 +0100360 rc = qeth_l2_send_setdelvlan(card, vid, IPA_CMD_SETVLAN);
361 if (rc) {
362 kfree(id);
363 return rc;
364 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100365 spin_lock_bh(&card->vlanlock);
366 list_add_tail(&id->list, &card->vid_list);
367 spin_unlock_bh(&card->vlanlock);
Jiri Pirko8e586132011-12-08 19:52:37 -0500368 } else {
369 return -ENOMEM;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100370 }
Jiri Pirko8e586132011-12-08 19:52:37 -0500371 return 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100372}
373
Patrick McHardy80d5c362013-04-19 02:04:28 +0000374static int qeth_l2_vlan_rx_kill_vid(struct net_device *dev,
375 __be16 proto, u16 vid)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100376{
377 struct qeth_vlan_vid *id, *tmpid = NULL;
Heiko Carstens509e2562008-07-26 02:24:10 -0700378 struct qeth_card *card = dev->ml_priv;
Thomas Richter1aec42b2015-01-21 13:39:10 +0100379 int rc = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100380
Carsten Otte847a50f2010-06-21 22:57:05 +0000381 QETH_CARD_TEXT_(card, 4, "kid:%d", vid);
Ursula Braun5113fec2010-05-16 21:15:14 +0000382 if (card->info.type == QETH_CARD_TYPE_OSM) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000383 QETH_CARD_TEXT(card, 3, "kidOSM");
Jiri Pirko8e586132011-12-08 19:52:37 -0500384 return 0;
Ursula Braun5113fec2010-05-16 21:15:14 +0000385 }
Ursula Braun8e98ac42009-03-24 20:57:18 +0000386 if (qeth_wait_for_threads(card, QETH_RECOVER_THREAD)) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000387 QETH_CARD_TEXT(card, 3, "kidREC");
Jiri Pirko8e586132011-12-08 19:52:37 -0500388 return 0;
Ursula Braun8e98ac42009-03-24 20:57:18 +0000389 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100390 spin_lock_bh(&card->vlanlock);
391 list_for_each_entry(id, &card->vid_list, list) {
392 if (id->vid == vid) {
393 list_del(&id->list);
394 tmpid = id;
395 break;
396 }
397 }
398 spin_unlock_bh(&card->vlanlock);
399 if (tmpid) {
Thomas Richter1aec42b2015-01-21 13:39:10 +0100400 rc = qeth_l2_send_setdelvlan(card, vid, IPA_CMD_DELVLAN);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100401 kfree(tmpid);
402 }
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200403 qeth_l2_set_rx_mode(card->dev);
Thomas Richter1aec42b2015-01-21 13:39:10 +0100404 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100405}
406
Peter Senna Tschudinb2f4de82015-08-04 17:11:47 +0200407static void qeth_l2_stop_card(struct qeth_card *card, int recovery_mode)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100408{
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200409 QETH_DBF_TEXT(SETUP , 2, "stopcard");
410 QETH_DBF_HEX(SETUP, 2, &card, sizeof(void *));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100411
412 qeth_set_allowed_threads(card, 0, 1);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100413 if (card->read.state == CH_STATE_UP &&
414 card->write.state == CH_STATE_UP &&
415 (card->state == CARD_STATE_UP)) {
416 if (recovery_mode &&
417 card->info.type != QETH_CARD_TYPE_OSN) {
418 qeth_l2_stop(card->dev);
419 } else {
420 rtnl_lock();
421 dev_close(card->dev);
422 rtnl_unlock();
423 }
Ursula Braun70919e22011-02-26 22:41:36 -0800424 card->info.mac_bits &= ~QETH_LAYER2_MAC_REGISTERED;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100425 card->state = CARD_STATE_SOFTSETUP;
426 }
427 if (card->state == CARD_STATE_SOFTSETUP) {
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200428 qeth_l2_del_all_macs(card, 0);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100429 qeth_clear_ipacmd_list(card);
430 card->state = CARD_STATE_HARDSETUP;
431 }
432 if (card->state == CARD_STATE_HARDSETUP) {
433 qeth_qdio_clear_card(card, 0);
434 qeth_clear_qdio_buffers(card);
435 qeth_clear_working_pool_list(card);
436 card->state = CARD_STATE_DOWN;
437 }
438 if (card->state == CARD_STATE_DOWN) {
439 qeth_clear_cmd_buffers(&card->read);
440 qeth_clear_cmd_buffers(&card->write);
441 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100442}
443
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000444static int qeth_l2_process_inbound_buffer(struct qeth_card *card,
445 int budget, int *done)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100446{
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000447 int work_done = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100448 struct sk_buff *skb;
449 struct qeth_hdr *hdr;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100450 unsigned int len;
451
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000452 *done = 0;
Stefan Raspl18af5c12012-11-19 02:46:50 +0000453 WARN_ON_ONCE(!budget);
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000454 while (budget) {
455 skb = qeth_core_get_next_skb(card,
Frank Blaschkab3332932011-08-08 01:33:59 +0000456 &card->qdio.in_q->bufs[card->rx.b_index],
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000457 &card->rx.b_element, &card->rx.e_offset, &hdr);
458 if (!skb) {
459 *done = 1;
460 break;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100461 }
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000462 skb->dev = card->dev;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100463 switch (hdr->hdr.l2.id) {
464 case QETH_HEADER_TYPE_LAYER2:
465 skb->pkt_type = PACKET_HOST;
466 skb->protocol = eth_type_trans(skb, skb->dev);
Thomas Richter4d7def22015-09-18 16:06:51 +0200467 if ((card->dev->features & NETIF_F_RXCSUM)
468 && ((hdr->hdr.l2.flags[1] &
469 (QETH_HDR_EXT_CSUM_HDR_REQ |
470 QETH_HDR_EXT_CSUM_TRANSP_REQ)) ==
471 (QETH_HDR_EXT_CSUM_HDR_REQ |
472 QETH_HDR_EXT_CSUM_TRANSP_REQ)))
473 skb->ip_summed = CHECKSUM_UNNECESSARY;
474 else
475 skb->ip_summed = CHECKSUM_NONE;
Ursula Braun12883722008-04-01 10:26:56 +0200476 if (skb->protocol == htons(ETH_P_802_2))
477 *((__u32 *)skb->cb) = ++card->seqno.pkt_seqno;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100478 len = skb->len;
Thomas Richter9abfa8c2015-10-06 15:12:27 +0200479 napi_gro_receive(&card->napi, skb);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100480 break;
481 case QETH_HEADER_TYPE_OSN:
Ursula Braun2d488c22008-10-24 11:16:55 +0200482 if (card->info.type == QETH_CARD_TYPE_OSN) {
483 skb_push(skb, sizeof(struct qeth_hdr));
484 skb_copy_to_linear_data(skb, hdr,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100485 sizeof(struct qeth_hdr));
Ursula Braun2d488c22008-10-24 11:16:55 +0200486 len = skb->len;
487 card->osn_info.data_cb(skb);
488 break;
489 }
490 /* else unknown */
Frank Blaschka4a71df52008-02-15 09:19:42 +0100491 default:
492 dev_kfree_skb_any(skb);
Carsten Otte847a50f2010-06-21 22:57:05 +0000493 QETH_CARD_TEXT(card, 3, "inbunkno");
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200494 QETH_DBF_HEX(CTRL, 3, hdr, QETH_DBF_CTRL_LEN);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100495 continue;
496 }
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000497 work_done++;
498 budget--;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100499 card->stats.rx_packets++;
500 card->stats.rx_bytes += len;
501 }
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000502 return work_done;
503}
504
505static int qeth_l2_poll(struct napi_struct *napi, int budget)
506{
507 struct qeth_card *card = container_of(napi, struct qeth_card, napi);
508 int work_done = 0;
509 struct qeth_qdio_buffer *buffer;
510 int done;
511 int new_budget = budget;
512
513 if (card->options.performance_stats) {
514 card->perf_stats.inbound_cnt++;
515 card->perf_stats.inbound_start_time = qeth_get_micros();
516 }
517
518 while (1) {
519 if (!card->rx.b_count) {
520 card->rx.qdio_err = 0;
521 card->rx.b_count = qdio_get_next_buffers(
522 card->data.ccwdev, 0, &card->rx.b_index,
523 &card->rx.qdio_err);
524 if (card->rx.b_count <= 0) {
525 card->rx.b_count = 0;
526 break;
527 }
528 card->rx.b_element =
529 &card->qdio.in_q->bufs[card->rx.b_index]
530 .buffer->element[0];
531 card->rx.e_offset = 0;
532 }
533
534 while (card->rx.b_count) {
535 buffer = &card->qdio.in_q->bufs[card->rx.b_index];
536 if (!(card->rx.qdio_err &&
537 qeth_check_qdio_errors(card, buffer->buffer,
538 card->rx.qdio_err, "qinerr")))
539 work_done += qeth_l2_process_inbound_buffer(
540 card, new_budget, &done);
541 else
542 done = 1;
543
544 if (done) {
545 if (card->options.performance_stats)
546 card->perf_stats.bufs_rec++;
547 qeth_put_buffer_pool_entry(card,
548 buffer->pool_entry);
549 qeth_queue_input_buffer(card, card->rx.b_index);
550 card->rx.b_count--;
551 if (card->rx.b_count) {
552 card->rx.b_index =
553 (card->rx.b_index + 1) %
554 QDIO_MAX_BUFFERS_PER_Q;
555 card->rx.b_element =
556 &card->qdio.in_q
557 ->bufs[card->rx.b_index]
558 .buffer->element[0];
559 card->rx.e_offset = 0;
560 }
561 }
562
563 if (work_done >= budget)
564 goto out;
565 else
566 new_budget = budget - work_done;
567 }
568 }
569
570 napi_complete(napi);
571 if (qdio_start_irq(card->data.ccwdev, 0))
572 napi_schedule(&card->napi);
573out:
574 if (card->options.performance_stats)
575 card->perf_stats.inbound_time += qeth_get_micros() -
576 card->perf_stats.inbound_start_time;
577 return work_done;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100578}
579
580static int qeth_l2_send_setdelmac(struct qeth_card *card, __u8 *mac,
Eugene Crosserefbbc1d2015-01-21 13:39:09 +0100581 enum qeth_ipa_cmds ipacmd)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100582{
583 struct qeth_ipa_cmd *cmd;
584 struct qeth_cmd_buffer *iob;
585
Carsten Otte847a50f2010-06-21 22:57:05 +0000586 QETH_CARD_TEXT(card, 2, "L2sdmac");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100587 iob = qeth_get_ipacmd_buffer(card, ipacmd, QETH_PROT_IPV4);
Thomas Richter1aec42b2015-01-21 13:39:10 +0100588 if (!iob)
589 return -ENOMEM;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100590 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
591 cmd->data.setdelmac.mac_length = OSA_ADDR_LEN;
592 memcpy(&cmd->data.setdelmac.mac, mac, OSA_ADDR_LEN);
Eugene Crosserefbbc1d2015-01-21 13:39:09 +0100593 return qeth_send_ipa_cmd(card, iob, NULL, NULL);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100594}
595
596static int qeth_l2_send_setmac(struct qeth_card *card, __u8 *mac)
597{
Eugene Crosserefbbc1d2015-01-21 13:39:09 +0100598 int rc;
599
Carsten Otte847a50f2010-06-21 22:57:05 +0000600 QETH_CARD_TEXT(card, 2, "L2Setmac");
Eugene Crosserefbbc1d2015-01-21 13:39:09 +0100601 rc = qeth_setdel_makerc(card, qeth_l2_send_setdelmac(card, mac,
602 IPA_CMD_SETVMAC));
603 if (rc == 0) {
604 card->info.mac_bits |= QETH_LAYER2_MAC_REGISTERED;
605 memcpy(card->dev->dev_addr, mac, OSA_ADDR_LEN);
606 dev_info(&card->gdev->dev,
607 "MAC address %pM successfully registered on device %s\n",
608 card->dev->dev_addr, card->dev->name);
609 } else {
610 card->info.mac_bits &= ~QETH_LAYER2_MAC_REGISTERED;
611 switch (rc) {
612 case -EEXIST:
613 dev_warn(&card->gdev->dev,
614 "MAC address %pM already exists\n", mac);
615 break;
616 case -EPERM:
617 dev_warn(&card->gdev->dev,
618 "MAC address %pM is not authorized\n", mac);
619 break;
620 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100621 }
Eugene Crosserefbbc1d2015-01-21 13:39:09 +0100622 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100623}
624
625static int qeth_l2_send_delmac(struct qeth_card *card, __u8 *mac)
626{
Eugene Crosserefbbc1d2015-01-21 13:39:09 +0100627 int rc;
628
Carsten Otte847a50f2010-06-21 22:57:05 +0000629 QETH_CARD_TEXT(card, 2, "L2Delmac");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100630 if (!(card->info.mac_bits & QETH_LAYER2_MAC_REGISTERED))
631 return 0;
Eugene Crosserefbbc1d2015-01-21 13:39:09 +0100632 rc = qeth_setdel_makerc(card, qeth_l2_send_setdelmac(card, mac,
633 IPA_CMD_DELVMAC));
634 if (rc == 0)
635 card->info.mac_bits &= ~QETH_LAYER2_MAC_REGISTERED;
636 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100637}
638
639static int qeth_l2_request_initial_mac(struct qeth_card *card)
640{
641 int rc = 0;
642 char vendor_pre[] = {0x02, 0x00, 0x00};
643
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200644 QETH_DBF_TEXT(SETUP, 2, "doL2init");
645 QETH_DBF_TEXT_(SETUP, 2, "doL2%s", CARD_BUS_ID(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100646
Stefan Raspla1348842012-11-12 23:05:16 +0000647 if (qeth_is_supported(card, IPA_SETADAPTERPARMS)) {
648 rc = qeth_query_setadapterparms(card);
649 if (rc) {
650 QETH_DBF_MESSAGE(2, "could not query adapter "
651 "parameters on device %s: x%x\n",
652 CARD_BUS_ID(card), rc);
653 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100654 }
655
Ursula Braun5113fec2010-05-16 21:15:14 +0000656 if (card->info.type == QETH_CARD_TYPE_IQD ||
657 card->info.type == QETH_CARD_TYPE_OSM ||
658 card->info.type == QETH_CARD_TYPE_OSX ||
659 card->info.guestlan) {
Frank Blaschka4a71df52008-02-15 09:19:42 +0100660 rc = qeth_setadpparms_change_macaddr(card);
661 if (rc) {
Frank Blaschka14cc21b2008-06-06 12:37:46 +0200662 QETH_DBF_MESSAGE(2, "couldn't get MAC address on "
663 "device %s: x%x\n", CARD_BUS_ID(card), rc);
Thomas Richter1aec42b2015-01-21 13:39:10 +0100664 QETH_DBF_TEXT_(SETUP, 2, "1err%04x", rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100665 return rc;
666 }
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200667 QETH_DBF_HEX(SETUP, 2, card->dev->dev_addr, OSA_ADDR_LEN);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100668 } else {
Joe Perches18336112012-07-12 22:33:10 -0700669 eth_random_addr(card->dev->dev_addr);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100670 memcpy(card->dev->dev_addr, vendor_pre, 3);
671 }
672 return 0;
673}
674
675static int qeth_l2_set_mac_address(struct net_device *dev, void *p)
676{
677 struct sockaddr *addr = p;
Heiko Carstens509e2562008-07-26 02:24:10 -0700678 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100679 int rc = 0;
680
Carsten Otte847a50f2010-06-21 22:57:05 +0000681 QETH_CARD_TEXT(card, 3, "setmac");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100682
683 if (qeth_l2_verify_dev(dev) != QETH_REAL_CARD) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000684 QETH_CARD_TEXT(card, 3, "setmcINV");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100685 return -EOPNOTSUPP;
686 }
687
Ursula Braun5113fec2010-05-16 21:15:14 +0000688 if (card->info.type == QETH_CARD_TYPE_OSN ||
689 card->info.type == QETH_CARD_TYPE_OSM ||
690 card->info.type == QETH_CARD_TYPE_OSX) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000691 QETH_CARD_TEXT(card, 3, "setmcTYP");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100692 return -EOPNOTSUPP;
693 }
Carsten Otte847a50f2010-06-21 22:57:05 +0000694 QETH_CARD_HEX(card, 3, addr->sa_data, OSA_ADDR_LEN);
Ursula Braun8e98ac42009-03-24 20:57:18 +0000695 if (qeth_wait_for_threads(card, QETH_RECOVER_THREAD)) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000696 QETH_CARD_TEXT(card, 3, "setmcREC");
Ursula Braun8e98ac42009-03-24 20:57:18 +0000697 return -ERESTARTSYS;
698 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100699 rc = qeth_l2_send_delmac(card, &card->dev->dev_addr[0]);
Eugene Crosserefbbc1d2015-01-21 13:39:09 +0100700 if (!rc || (rc == -ENOENT))
Frank Blaschka4a71df52008-02-15 09:19:42 +0100701 rc = qeth_l2_send_setmac(card, addr->sa_data);
Ursula Braune0a81142012-03-07 02:06:28 +0000702 return rc ? -EINVAL : 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100703}
704
Eugene Crosser0db587b2015-05-18 14:27:55 +0200705static void qeth_promisc_to_bridge(struct qeth_card *card)
706{
707 struct net_device *dev = card->dev;
708 enum qeth_ipa_promisc_modes promisc_mode;
709 int role;
710 int rc;
711
712 QETH_CARD_TEXT(card, 3, "pmisc2br");
713
714 if (!card->options.sbp.reflect_promisc)
715 return;
716 promisc_mode = (dev->flags & IFF_PROMISC) ? SET_PROMISC_MODE_ON
717 : SET_PROMISC_MODE_OFF;
718 if (promisc_mode == card->info.promisc_mode)
719 return;
720
721 if (promisc_mode == SET_PROMISC_MODE_ON) {
722 if (card->options.sbp.reflect_promisc_primary)
723 role = QETH_SBP_ROLE_PRIMARY;
724 else
725 role = QETH_SBP_ROLE_SECONDARY;
726 } else
727 role = QETH_SBP_ROLE_NONE;
728
729 rc = qeth_bridgeport_setrole(card, role);
730 QETH_DBF_TEXT_(SETUP, 2, "bpm%c%04x",
731 (promisc_mode == SET_PROMISC_MODE_ON) ? '+' : '-', rc);
732 if (!rc) {
733 card->options.sbp.role = role;
734 card->info.promisc_mode = promisc_mode;
735 }
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200736
737}
738/* New MAC address is added to the hash table and marked to be written on card
739 * only if there is not in the hash table storage already
740 *
741*/
742static void
743qeth_l2_add_mac(struct qeth_card *card, struct netdev_hw_addr *ha, u8 is_uc)
744{
745 struct qeth_mac *mac;
746
747 hash_for_each_possible(card->mac_htable, mac, hnode,
748 qeth_l2_mac_hash(ha->addr)) {
749 if (is_uc == mac->is_uc &&
750 !memcmp(ha->addr, mac->mac_addr, OSA_ADDR_LEN)) {
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200751 mac->disp_flag = QETH_DISP_ADDR_DO_NOTHING;
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200752 return;
753 }
754 }
755
756 mac = kzalloc(sizeof(struct qeth_mac), GFP_ATOMIC);
757
758 if (!mac)
759 return;
760
761 memcpy(mac->mac_addr, ha->addr, OSA_ADDR_LEN);
762 mac->is_uc = is_uc;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200763 mac->disp_flag = QETH_DISP_ADDR_ADD;
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200764
765 hash_add(card->mac_htable, &mac->hnode,
766 qeth_l2_mac_hash(mac->mac_addr));
767
Eugene Crosser0db587b2015-05-18 14:27:55 +0200768}
769
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200770static void qeth_l2_set_rx_mode(struct net_device *dev)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100771{
Heiko Carstens509e2562008-07-26 02:24:10 -0700772 struct qeth_card *card = dev->ml_priv;
Jiri Pirkoccffad252009-05-22 23:22:17 +0000773 struct netdev_hw_addr *ha;
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200774 struct qeth_mac *mac;
775 struct hlist_node *tmp;
776 int i;
777 int rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100778
779 if (card->info.type == QETH_CARD_TYPE_OSN)
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200780 return;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100781
Carsten Otte847a50f2010-06-21 22:57:05 +0000782 QETH_CARD_TEXT(card, 3, "setmulti");
Ursula Braun8e98ac42009-03-24 20:57:18 +0000783 if (qeth_threads_running(card, QETH_RECOVER_THREAD) &&
784 (card->state != CARD_STATE_UP))
785 return;
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200786
Frank Blaschka4a71df52008-02-15 09:19:42 +0100787 spin_lock_bh(&card->mclock);
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200788
Jiri Pirko22bedad32010-04-01 21:22:57 +0000789 netdev_for_each_mc_addr(ha, dev)
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200790 qeth_l2_add_mac(card, ha, 0);
Frank Blaschka7db22662008-08-15 08:02:59 +0200791
Jiri Pirko32e7bfc2010-01-25 13:36:10 -0800792 netdev_for_each_uc_addr(ha, dev)
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200793 qeth_l2_add_mac(card, ha, 1);
794
795 hash_for_each_safe(card->mac_htable, i, tmp, mac, hnode) {
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200796 if (mac->disp_flag == QETH_DISP_ADDR_DELETE) {
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200797 if (!mac->is_uc)
798 rc = qeth_l2_send_delgroupmac(card,
799 mac->mac_addr);
800 else {
801 rc = qeth_l2_send_setdelmac(card, mac->mac_addr,
802 IPA_CMD_DELVMAC);
803 }
804
805 hash_del(&mac->hnode);
806 kfree(mac);
807
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200808 } else if (mac->disp_flag == QETH_DISP_ADDR_ADD) {
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200809 rc = qeth_l2_write_mac(card, mac);
810 if (rc) {
811 hash_del(&mac->hnode);
812 kfree(mac);
813 } else
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200814 mac->disp_flag = QETH_DISP_ADDR_DELETE;
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200815 } else
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200816 mac->disp_flag = QETH_DISP_ADDR_DELETE;
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200817 }
Frank Blaschka7db22662008-08-15 08:02:59 +0200818
Frank Blaschka4a71df52008-02-15 09:19:42 +0100819 spin_unlock_bh(&card->mclock);
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200820
Eugene Crosser0db587b2015-05-18 14:27:55 +0200821 if (qeth_adp_supported(card, IPA_SETADP_SET_PROMISC_MODE))
822 qeth_setadp_promisc_mode(card);
823 else
824 qeth_promisc_to_bridge(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100825}
826
827static int qeth_l2_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
828{
829 int rc;
830 struct qeth_hdr *hdr = NULL;
831 int elements = 0;
Heiko Carstens509e2562008-07-26 02:24:10 -0700832 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100833 struct sk_buff *new_skb = skb;
Klaus-Dieter Wackerce73e102009-08-26 02:01:08 +0000834 int cast_type = qeth_l2_get_cast_type(card, skb);
Stefan Raspl290b8342014-04-28 10:05:08 +0200835 struct qeth_qdio_out_q *queue;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100836 int tx_bytes = skb->len;
Frank Blaschka683d7182008-08-01 16:39:13 +0200837 int data_offset = -1;
838 int elements_needed = 0;
839 int hd_len = 0;
Eugene Crosserd52aec92016-06-16 16:18:55 +0200840 int nr_frags;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100841
Stefan Raspl290b8342014-04-28 10:05:08 +0200842 if (card->qdio.do_prio_queueing || (cast_type &&
843 card->info.is_multicast_different))
844 queue = card->qdio.out_qs[qeth_get_priority_queue(card, skb,
845 qeth_get_ip_version(skb), cast_type)];
846 else
847 queue = card->qdio.out_qs[card->qdio.default_out_queue];
848
Frank Blaschka4a71df52008-02-15 09:19:42 +0100849 if ((card->state != CARD_STATE_UP) || !card->lan_online) {
850 card->stats.tx_carrier_errors++;
851 goto tx_drop;
852 }
853
854 if ((card->info.type == QETH_CARD_TYPE_OSN) &&
855 (skb->protocol == htons(ETH_P_IPV6)))
856 goto tx_drop;
857
858 if (card->options.performance_stats) {
859 card->perf_stats.outbound_cnt++;
860 card->perf_stats.outbound_start_time = qeth_get_micros();
861 }
862 netif_stop_queue(dev);
863
Eugene Crosserd52aec92016-06-16 16:18:55 +0200864 /* fix hardware limitation: as long as we do not have sbal
865 * chaining we can not send long frag lists
866 */
867 if ((card->info.type != QETH_CARD_TYPE_IQD) &&
868 !qeth_get_elements_no(card, new_skb, 0)) {
Eugene Crosser6059c902016-06-16 16:18:57 +0200869 int lin_rc = skb_linearize(new_skb);
870
871 if (card->options.performance_stats) {
872 if (lin_rc)
873 card->perf_stats.tx_linfail++;
874 else
875 card->perf_stats.tx_lin++;
876 }
877 if (lin_rc)
Eugene Crosserd52aec92016-06-16 16:18:55 +0200878 goto tx_drop;
Eugene Crosserd52aec92016-06-16 16:18:55 +0200879 }
880
Frank Blaschka4a71df52008-02-15 09:19:42 +0100881 if (card->info.type == QETH_CARD_TYPE_OSN)
882 hdr = (struct qeth_hdr *)skb->data;
883 else {
Frank Blaschka64ef8952009-03-24 20:57:16 +0000884 if (card->info.type == QETH_CARD_TYPE_IQD) {
Frank Blaschka683d7182008-08-01 16:39:13 +0200885 new_skb = skb;
886 data_offset = ETH_HLEN;
887 hd_len = ETH_HLEN;
888 hdr = kmem_cache_alloc(qeth_core_header_cache,
889 GFP_ATOMIC);
890 if (!hdr)
891 goto tx_drop;
892 elements_needed++;
893 skb_reset_mac_header(new_skb);
Stefan Raspl43934072014-03-19 07:58:01 +0100894 qeth_l2_fill_header(card, hdr, new_skb, cast_type);
Frank Blaschka683d7182008-08-01 16:39:13 +0200895 hdr->hdr.l2.pkt_length = new_skb->len;
896 memcpy(((char *)hdr) + sizeof(struct qeth_hdr),
897 skb_mac_header(new_skb), ETH_HLEN);
898 } else {
899 /* create a clone with writeable headroom */
900 new_skb = skb_realloc_headroom(skb,
Frank Blaschkaf90b7442008-04-24 10:15:24 +0200901 sizeof(struct qeth_hdr));
Frank Blaschka683d7182008-08-01 16:39:13 +0200902 if (!new_skb)
903 goto tx_drop;
904 hdr = (struct qeth_hdr *)skb_push(new_skb,
905 sizeof(struct qeth_hdr));
906 skb_set_mac_header(new_skb, sizeof(struct qeth_hdr));
Stefan Raspl43934072014-03-19 07:58:01 +0100907 qeth_l2_fill_header(card, hdr, new_skb, cast_type);
Thomas Richter4d7def22015-09-18 16:06:51 +0200908 if (new_skb->ip_summed == CHECKSUM_PARTIAL)
909 qeth_l2_hdr_csum(card, hdr, new_skb);
Frank Blaschka683d7182008-08-01 16:39:13 +0200910 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100911 }
912
Stefan Raspl065cc782013-04-22 01:12:28 +0000913 elements = qeth_get_elements_no(card, new_skb, elements_needed);
Frank Blaschka64ef8952009-03-24 20:57:16 +0000914 if (!elements) {
915 if (data_offset >= 0)
916 kmem_cache_free(qeth_core_header_cache, hdr);
917 goto tx_drop;
Frank Blaschkaf61a0d02009-03-24 20:57:15 +0000918 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100919
Frank Blaschka51aa1652010-06-21 22:57:10 +0000920 if (card->info.type != QETH_CARD_TYPE_IQD) {
Stefan Raspld4ae1f52013-04-22 01:12:29 +0000921 if (qeth_hdr_chk_and_bounce(new_skb, &hdr,
Frank Blaschka51aa1652010-06-21 22:57:10 +0000922 sizeof(struct qeth_hdr_layer2)))
923 goto tx_drop;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100924 rc = qeth_do_send_packet(card, queue, new_skb, hdr,
Frank Blaschka64ef8952009-03-24 20:57:16 +0000925 elements);
Frank Blaschka51aa1652010-06-21 22:57:10 +0000926 } else
Frank Blaschka4a71df52008-02-15 09:19:42 +0100927 rc = qeth_do_send_packet_fast(card, queue, new_skb, hdr,
Frank Blaschka64ef8952009-03-24 20:57:16 +0000928 elements, data_offset, hd_len);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100929 if (!rc) {
930 card->stats.tx_packets++;
931 card->stats.tx_bytes += tx_bytes;
Eugene Crosserd52aec92016-06-16 16:18:55 +0200932 if (card->options.performance_stats) {
933 nr_frags = skb_shinfo(new_skb)->nr_frags;
934 if (nr_frags) {
935 card->perf_stats.sg_skbs_sent++;
936 /* nr_frags + skb->data */
937 card->perf_stats.sg_frags_sent += nr_frags + 1;
938 }
939 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100940 if (new_skb != skb)
941 dev_kfree_skb_any(skb);
Patrick McHardyec634fe2009-07-05 19:23:38 -0700942 rc = NETDEV_TX_OK;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100943 } else {
Frank Blaschka683d7182008-08-01 16:39:13 +0200944 if (data_offset >= 0)
945 kmem_cache_free(qeth_core_header_cache, hdr);
946
Frank Blaschka4a71df52008-02-15 09:19:42 +0100947 if (rc == -EBUSY) {
948 if (new_skb != skb)
949 dev_kfree_skb_any(new_skb);
950 return NETDEV_TX_BUSY;
951 } else
952 goto tx_drop;
953 }
954
955 netif_wake_queue(dev);
956 if (card->options.performance_stats)
957 card->perf_stats.outbound_time += qeth_get_micros() -
958 card->perf_stats.outbound_start_time;
959 return rc;
960
961tx_drop:
962 card->stats.tx_dropped++;
963 card->stats.tx_errors++;
964 if ((new_skb != skb) && new_skb)
965 dev_kfree_skb_any(new_skb);
966 dev_kfree_skb_any(skb);
Frank Blaschkad0ec0f52008-06-06 12:37:48 +0200967 netif_wake_queue(dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100968 return NETDEV_TX_OK;
969}
970
Ursula Braun39423442011-01-12 20:42:24 +0000971static int __qeth_l2_open(struct net_device *dev)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100972{
Heiko Carstens509e2562008-07-26 02:24:10 -0700973 struct qeth_card *card = dev->ml_priv;
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000974 int rc = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100975
Carsten Otte847a50f2010-06-21 22:57:05 +0000976 QETH_CARD_TEXT(card, 4, "qethopen");
Ursula Braun39423442011-01-12 20:42:24 +0000977 if (card->state == CARD_STATE_UP)
978 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100979 if (card->state != CARD_STATE_SOFTSETUP)
980 return -ENODEV;
981
982 if ((card->info.type != QETH_CARD_TYPE_OSN) &&
983 (!(card->info.mac_bits & QETH_LAYER2_MAC_REGISTERED))) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000984 QETH_CARD_TEXT(card, 4, "nomacadr");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100985 return -EPERM;
986 }
987 card->data.state = CH_STATE_UP;
988 card->state = CARD_STATE_UP;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100989 netif_start_queue(dev);
990
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000991 if (qdio_stop_irq(card->data.ccwdev, 0) >= 0) {
992 napi_enable(&card->napi);
993 napi_schedule(&card->napi);
994 } else
995 rc = -EIO;
996 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100997}
998
Ursula Braun39423442011-01-12 20:42:24 +0000999static int qeth_l2_open(struct net_device *dev)
1000{
1001 struct qeth_card *card = dev->ml_priv;
1002
1003 QETH_CARD_TEXT(card, 5, "qethope_");
1004 if (qeth_wait_for_threads(card, QETH_RECOVER_THREAD)) {
1005 QETH_CARD_TEXT(card, 3, "openREC");
1006 return -ERESTARTSYS;
1007 }
1008 return __qeth_l2_open(dev);
1009}
1010
Frank Blaschka4a71df52008-02-15 09:19:42 +01001011static int qeth_l2_stop(struct net_device *dev)
1012{
Heiko Carstens509e2562008-07-26 02:24:10 -07001013 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001014
Carsten Otte847a50f2010-06-21 22:57:05 +00001015 QETH_CARD_TEXT(card, 4, "qethstop");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001016 netif_tx_disable(dev);
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00001017 if (card->state == CARD_STATE_UP) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01001018 card->state = CARD_STATE_SOFTSETUP;
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00001019 napi_disable(&card->napi);
1020 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01001021 return 0;
1022}
1023
1024static int qeth_l2_probe_device(struct ccwgroup_device *gdev)
1025{
1026 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
1027
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001028 qeth_l2_create_device_attributes(&gdev->dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001029 INIT_LIST_HEAD(&card->vid_list);
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +02001030 hash_init(card->mac_htable);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001031 card->options.layer2 = 1;
Frank Blaschka1da74b12011-05-12 18:45:02 +00001032 card->info.hwtrap = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001033 return 0;
1034}
1035
1036static void qeth_l2_remove_device(struct ccwgroup_device *cgdev)
1037{
1038 struct qeth_card *card = dev_get_drvdata(&cgdev->dev);
1039
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001040 qeth_l2_remove_device_attributes(&cgdev->dev);
Ursula Braunf2148562009-05-19 21:38:37 +00001041 qeth_set_allowed_threads(card, 0, 1);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001042 wait_event(card->wait_q, qeth_threads_running(card, 0xffffffff) == 0);
1043
Ursula Braun70919e22011-02-26 22:41:36 -08001044 if (cgdev->state == CCWGROUP_ONLINE)
Frank Blaschka4a71df52008-02-15 09:19:42 +01001045 qeth_l2_set_offline(cgdev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001046
1047 if (card->dev) {
1048 unregister_netdev(card->dev);
1049 card->dev = NULL;
1050 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01001051 return;
1052}
1053
Stephen Hemminger0fc0b732009-09-02 01:03:33 -07001054static const struct ethtool_ops qeth_l2_ethtool_ops = {
Frank Blaschka4a71df52008-02-15 09:19:42 +01001055 .get_link = ethtool_op_get_link,
Frank Blaschka4a71df52008-02-15 09:19:42 +01001056 .get_strings = qeth_core_get_strings,
1057 .get_ethtool_stats = qeth_core_get_ethtool_stats,
Ben Hutchingsdf8b4ec2009-10-01 11:24:32 +00001058 .get_sset_count = qeth_core_get_sset_count,
Frank Blaschka4a71df52008-02-15 09:19:42 +01001059 .get_drvinfo = qeth_core_get_drvinfo,
Frank Blaschka3f9975a2008-04-24 10:15:23 +02001060 .get_settings = qeth_core_ethtool_get_settings,
Frank Blaschka4a71df52008-02-15 09:19:42 +01001061};
1062
Stephen Hemminger0fc0b732009-09-02 01:03:33 -07001063static const struct ethtool_ops qeth_l2_osn_ops = {
Frank Blaschka4a71df52008-02-15 09:19:42 +01001064 .get_strings = qeth_core_get_strings,
1065 .get_ethtool_stats = qeth_core_get_ethtool_stats,
Ben Hutchingsdf8b4ec2009-10-01 11:24:32 +00001066 .get_sset_count = qeth_core_get_sset_count,
Frank Blaschka4a71df52008-02-15 09:19:42 +01001067 .get_drvinfo = qeth_core_get_drvinfo,
1068};
1069
Frank Blaschka3d58cef2009-01-09 03:44:00 +00001070static const struct net_device_ops qeth_l2_netdev_ops = {
Frank Blaschka8403b132009-01-08 10:50:55 -08001071 .ndo_open = qeth_l2_open,
1072 .ndo_stop = qeth_l2_stop,
1073 .ndo_get_stats = qeth_get_stats,
1074 .ndo_start_xmit = qeth_l2_hard_start_xmit,
1075 .ndo_validate_addr = eth_validate_addr,
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +02001076 .ndo_set_rx_mode = qeth_l2_set_rx_mode,
Frank Blaschka8403b132009-01-08 10:50:55 -08001077 .ndo_do_ioctl = qeth_l2_do_ioctl,
1078 .ndo_set_mac_address = qeth_l2_set_mac_address,
1079 .ndo_change_mtu = qeth_change_mtu,
1080 .ndo_vlan_rx_add_vid = qeth_l2_vlan_rx_add_vid,
1081 .ndo_vlan_rx_kill_vid = qeth_l2_vlan_rx_kill_vid,
1082 .ndo_tx_timeout = qeth_tx_timeout,
Thomas Richter8f43fb02016-06-16 16:18:59 +02001083 .ndo_fix_features = qeth_fix_features,
1084 .ndo_set_features = qeth_set_features
Frank Blaschka8403b132009-01-08 10:50:55 -08001085};
1086
Frank Blaschka4a71df52008-02-15 09:19:42 +01001087static int qeth_l2_setup_netdev(struct qeth_card *card)
1088{
1089 switch (card->info.type) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01001090 case QETH_CARD_TYPE_IQD:
Tom Gundersenc835a672014-07-14 16:37:24 +02001091 card->dev = alloc_netdev(0, "hsi%d", NET_NAME_UNKNOWN,
1092 ether_setup);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001093 break;
1094 case QETH_CARD_TYPE_OSN:
Tom Gundersenc835a672014-07-14 16:37:24 +02001095 card->dev = alloc_netdev(0, "osn%d", NET_NAME_UNKNOWN,
1096 ether_setup);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001097 card->dev->flags |= IFF_NOARP;
1098 break;
1099 default:
1100 card->dev = alloc_etherdev(0);
1101 }
1102
1103 if (!card->dev)
1104 return -ENODEV;
1105
Heiko Carstens509e2562008-07-26 02:24:10 -07001106 card->dev->ml_priv = card;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001107 card->dev->watchdog_timeo = QETH_TX_TIMEOUT;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001108 card->dev->mtu = card->info.initial_mtu;
Frank Blaschka8403b132009-01-08 10:50:55 -08001109 card->dev->netdev_ops = &qeth_l2_netdev_ops;
Wilfried Klaebe7ad24ea2014-05-11 00:12:32 +00001110 card->dev->ethtool_ops =
1111 (card->info.type != QETH_CARD_TYPE_OSN) ?
1112 &qeth_l2_ethtool_ops : &qeth_l2_osn_ops;
Patrick McHardyf6469682013-04-19 02:04:27 +00001113 card->dev->features |= NETIF_F_HW_VLAN_CTAG_FILTER;
Thomas Richter4d7def22015-09-18 16:06:51 +02001114 if (card->info.type == QETH_CARD_TYPE_OSD && !card->info.guestlan) {
Thomas Richter8f43fb02016-06-16 16:18:59 +02001115 card->dev->hw_features = NETIF_F_SG;
Hans Wippel9bdc4412016-06-16 16:19:00 +02001116 card->dev->vlan_features = NETIF_F_SG;
Thomas Richter8f43fb02016-06-16 16:18:59 +02001117 /* OSA 3S and earlier has no RX/TX support */
Hans Wippel9bdc4412016-06-16 16:19:00 +02001118 if (qeth_is_supported(card, IPA_OUTBOUND_CHECKSUM)) {
Thomas Richter8f43fb02016-06-16 16:18:59 +02001119 card->dev->hw_features |= NETIF_F_IP_CSUM;
Hans Wippel9bdc4412016-06-16 16:19:00 +02001120 card->dev->vlan_features |= NETIF_F_IP_CSUM;
1121 }
1122 if (qeth_is_supported(card, IPA_INBOUND_CHECKSUM)) {
Thomas Richter8f43fb02016-06-16 16:18:59 +02001123 card->dev->hw_features |= NETIF_F_RXCSUM;
Hans Wippel9bdc4412016-06-16 16:19:00 +02001124 card->dev->vlan_features |= NETIF_F_RXCSUM;
1125 }
Thomas Richter8f43fb02016-06-16 16:18:59 +02001126 /* Turn on SG per default */
1127 card->dev->features |= NETIF_F_SG;
Thomas Richter4d7def22015-09-18 16:06:51 +02001128 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01001129 card->info.broadcast_capable = 1;
1130 qeth_l2_request_initial_mac(card);
Eugene Crosserd52aec92016-06-16 16:18:55 +02001131 card->dev->gso_max_size = (QETH_MAX_BUFFER_ELEMENTS(card) - 1) *
1132 PAGE_SIZE;
1133 card->dev->gso_max_segs = (QETH_MAX_BUFFER_ELEMENTS(card) - 1);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001134 SET_NETDEV_DEV(card->dev, &card->gdev->dev);
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00001135 netif_napi_add(card->dev, &card->napi, qeth_l2_poll, QETH_NAPI_WEIGHT);
Ursula Braune5ebe632015-12-11 12:27:55 +01001136 netif_carrier_off(card->dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001137 return register_netdev(card->dev);
1138}
1139
Thomas Richter4d7def22015-09-18 16:06:51 +02001140static int qeth_l2_start_ipassists(struct qeth_card *card)
1141{
1142 /* configure isolation level */
1143 if (qeth_set_access_ctrl_online(card, 0))
1144 return -ENODEV;
Thomas Richter4d7def22015-09-18 16:06:51 +02001145 return 0;
1146}
1147
Frank Blaschka4a71df52008-02-15 09:19:42 +01001148static int __qeth_l2_set_online(struct ccwgroup_device *gdev, int recovery_mode)
1149{
1150 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
1151 int rc = 0;
1152 enum qeth_card_states recover_flag;
1153
Ursula Braun9dc48cc2010-07-22 23:15:05 +00001154 mutex_lock(&card->discipline_mutex);
Frank Blaschkac4949f02010-05-11 19:34:47 +00001155 mutex_lock(&card->conf_mutex);
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001156 QETH_DBF_TEXT(SETUP, 2, "setonlin");
1157 QETH_DBF_HEX(SETUP, 2, &card, sizeof(void *));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001158
Frank Blaschka4a71df52008-02-15 09:19:42 +01001159 recover_flag = card->state;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001160 rc = qeth_core_hardsetup_card(card);
1161 if (rc) {
Thomas Richter1aec42b2015-01-21 13:39:10 +01001162 QETH_DBF_TEXT_(SETUP, 2, "2err%04x", rc);
Ursula Braunaa909222009-11-12 00:11:43 +00001163 rc = -ENODEV;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001164 goto out_remove;
1165 }
Eugene Crosserc044dc22014-01-29 09:23:48 +01001166 qeth_bridgeport_query_support(card);
1167 if (card->options.sbp.supported_funcs)
1168 dev_info(&card->gdev->dev,
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001169 "The device represents a Bridge Capable Port\n");
Stefan Raspl395672e02012-11-19 02:46:49 +00001170 qeth_trace_features(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001171
Ursula Braunaa909222009-11-12 00:11:43 +00001172 if (!card->dev && qeth_l2_setup_netdev(card)) {
1173 rc = -ENODEV;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001174 goto out_remove;
Ursula Braunaa909222009-11-12 00:11:43 +00001175 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01001176
1177 if (card->info.type != QETH_CARD_TYPE_OSN)
1178 qeth_l2_send_setmac(card, &card->dev->dev_addr[0]);
1179
Frank Blaschka1da74b12011-05-12 18:45:02 +00001180 if (qeth_is_diagass_supported(card, QETH_DIAGS_CMD_TRAP)) {
1181 if (card->info.hwtrap &&
1182 qeth_hw_trap(card, QETH_DIAGS_TRAP_ARM))
1183 card->info.hwtrap = 0;
1184 } else
1185 card->info.hwtrap = 0;
1186
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001187 qeth_l2_setup_bridgeport_attrs(card);
1188
Frank Blaschka4a71df52008-02-15 09:19:42 +01001189 card->state = CARD_STATE_HARDSETUP;
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00001190 memset(&card->rx, 0, sizeof(struct qeth_rx));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001191 qeth_print_status_message(card);
1192
1193 /* softsetup */
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001194 QETH_DBF_TEXT(SETUP, 2, "softsetp");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001195
1196 rc = qeth_send_startlan(card);
1197 if (rc) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001198 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001199 if (rc == 0xe080) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001200 dev_warn(&card->gdev->dev,
1201 "The LAN is offline\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001202 card->lan_online = 0;
Ursula Braun2b6203b2010-11-26 02:41:19 +00001203 goto contin;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001204 }
Ursula Braunaa909222009-11-12 00:11:43 +00001205 rc = -ENODEV;
Ursula Braunf2148562009-05-19 21:38:37 +00001206 goto out_remove;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001207 } else
1208 card->lan_online = 1;
1209
Ursula Braun2b6203b2010-11-26 02:41:19 +00001210contin:
Ursula Braun5113fec2010-05-16 21:15:14 +00001211 if ((card->info.type == QETH_CARD_TYPE_OSD) ||
Stefan Raspl0f547612013-01-21 02:30:20 +00001212 (card->info.type == QETH_CARD_TYPE_OSX)) {
Thomas Richter8f43fb02016-06-16 16:18:59 +02001213 rc = qeth_l2_start_ipassists(card);
1214 if (rc)
Stefan Raspl0f547612013-01-21 02:30:20 +00001215 goto out_remove;
Stefan Raspl0f547612013-01-21 02:30:20 +00001216 }
Ursula Braun5113fec2010-05-16 21:15:14 +00001217
1218 if (card->info.type != QETH_CARD_TYPE_OSN &&
1219 card->info.type != QETH_CARD_TYPE_OSM)
Ursula Braun70919e22011-02-26 22:41:36 -08001220 qeth_l2_process_vlans(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001221
1222 netif_tx_disable(card->dev);
1223
1224 rc = qeth_init_qdio_queues(card);
1225 if (rc) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001226 QETH_DBF_TEXT_(SETUP, 2, "6err%d", rc);
Ursula Braunaa909222009-11-12 00:11:43 +00001227 rc = -ENODEV;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001228 goto out_remove;
1229 }
1230 card->state = CARD_STATE_SOFTSETUP;
Ursula Braun2b6203b2010-11-26 02:41:19 +00001231 if (card->lan_online)
1232 netif_carrier_on(card->dev);
1233 else
1234 netif_carrier_off(card->dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001235
1236 qeth_set_allowed_threads(card, 0xffffffff, 0);
1237 if (recover_flag == CARD_STATE_RECOVER) {
1238 if (recovery_mode &&
1239 card->info.type != QETH_CARD_TYPE_OSN) {
Ursula Braun39423442011-01-12 20:42:24 +00001240 __qeth_l2_open(card->dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001241 } else {
1242 rtnl_lock();
1243 dev_open(card->dev);
1244 rtnl_unlock();
1245 }
1246 /* this also sets saved unicast addresses */
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +02001247 qeth_l2_set_rx_mode(card->dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001248 }
1249 /* let user_space know that device is online */
1250 kobject_uevent(&gdev->dev.kobj, KOBJ_CHANGE);
Frank Blaschkac4949f02010-05-11 19:34:47 +00001251 mutex_unlock(&card->conf_mutex);
Ursula Braun9dc48cc2010-07-22 23:15:05 +00001252 mutex_unlock(&card->discipline_mutex);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001253 return 0;
Ursula Braunaa909222009-11-12 00:11:43 +00001254
Frank Blaschka4a71df52008-02-15 09:19:42 +01001255out_remove:
Frank Blaschka4a71df52008-02-15 09:19:42 +01001256 qeth_l2_stop_card(card, 0);
1257 ccw_device_set_offline(CARD_DDEV(card));
1258 ccw_device_set_offline(CARD_WDEV(card));
1259 ccw_device_set_offline(CARD_RDEV(card));
Ursula Braun22ae2792014-02-24 13:12:06 +01001260 qdio_free(CARD_DDEV(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001261 if (recover_flag == CARD_STATE_RECOVER)
1262 card->state = CARD_STATE_RECOVER;
1263 else
1264 card->state = CARD_STATE_DOWN;
Frank Blaschkac4949f02010-05-11 19:34:47 +00001265 mutex_unlock(&card->conf_mutex);
Ursula Braun9dc48cc2010-07-22 23:15:05 +00001266 mutex_unlock(&card->discipline_mutex);
Ursula Braunaa909222009-11-12 00:11:43 +00001267 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001268}
1269
1270static int qeth_l2_set_online(struct ccwgroup_device *gdev)
1271{
1272 return __qeth_l2_set_online(gdev, 0);
1273}
1274
1275static int __qeth_l2_set_offline(struct ccwgroup_device *cgdev,
1276 int recovery_mode)
1277{
1278 struct qeth_card *card = dev_get_drvdata(&cgdev->dev);
1279 int rc = 0, rc2 = 0, rc3 = 0;
1280 enum qeth_card_states recover_flag;
1281
Ursula Braun9dc48cc2010-07-22 23:15:05 +00001282 mutex_lock(&card->discipline_mutex);
Frank Blaschkac4949f02010-05-11 19:34:47 +00001283 mutex_lock(&card->conf_mutex);
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001284 QETH_DBF_TEXT(SETUP, 3, "setoffl");
1285 QETH_DBF_HEX(SETUP, 3, &card, sizeof(void *));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001286
1287 if (card->dev && netif_carrier_ok(card->dev))
1288 netif_carrier_off(card->dev);
1289 recover_flag = card->state;
Frank Blaschka1da74b12011-05-12 18:45:02 +00001290 if ((!recovery_mode && card->info.hwtrap) || card->info.hwtrap == 2) {
1291 qeth_hw_trap(card, QETH_DIAGS_TRAP_DISARM);
1292 card->info.hwtrap = 1;
1293 }
Ursula Braun0f5623c2008-10-24 11:16:52 +02001294 qeth_l2_stop_card(card, recovery_mode);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001295 rc = ccw_device_set_offline(CARD_DDEV(card));
1296 rc2 = ccw_device_set_offline(CARD_WDEV(card));
1297 rc3 = ccw_device_set_offline(CARD_RDEV(card));
1298 if (!rc)
1299 rc = (rc2) ? rc2 : rc3;
1300 if (rc)
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001301 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
Ursula Braun22ae2792014-02-24 13:12:06 +01001302 qdio_free(CARD_DDEV(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001303 if (recover_flag == CARD_STATE_UP)
1304 card->state = CARD_STATE_RECOVER;
1305 /* let user_space know that device is offline */
1306 kobject_uevent(&cgdev->dev.kobj, KOBJ_CHANGE);
Frank Blaschkac4949f02010-05-11 19:34:47 +00001307 mutex_unlock(&card->conf_mutex);
Ursula Braun9dc48cc2010-07-22 23:15:05 +00001308 mutex_unlock(&card->discipline_mutex);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001309 return 0;
1310}
1311
1312static int qeth_l2_set_offline(struct ccwgroup_device *cgdev)
1313{
1314 return __qeth_l2_set_offline(cgdev, 0);
1315}
1316
1317static int qeth_l2_recover(void *ptr)
1318{
1319 struct qeth_card *card;
1320 int rc = 0;
1321
1322 card = (struct qeth_card *) ptr;
Carsten Otte847a50f2010-06-21 22:57:05 +00001323 QETH_CARD_TEXT(card, 2, "recover1");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001324 if (!qeth_do_run_thread(card, QETH_RECOVER_THREAD))
1325 return 0;
Carsten Otte847a50f2010-06-21 22:57:05 +00001326 QETH_CARD_TEXT(card, 2, "recover2");
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001327 dev_warn(&card->gdev->dev,
1328 "A recovery process has been started for the device\n");
Stefan Raspl65d80132013-04-07 22:19:27 +00001329 qeth_set_recovery_task(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001330 __qeth_l2_set_offline(card->gdev, 1);
1331 rc = __qeth_l2_set_online(card->gdev, 1);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001332 if (!rc)
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001333 dev_info(&card->gdev->dev,
1334 "Device successfully recovered!\n");
Ursula Braun28a7e4c2008-09-19 12:56:03 +02001335 else {
Stefan Raspl0f547612013-01-21 02:30:20 +00001336 qeth_close_dev(card);
1337 dev_warn(&card->gdev->dev, "The qeth device driver "
Stefan Raspl2efaf5f2012-10-15 19:21:18 +00001338 "failed to recover an error on the device\n");
Ursula Braun28a7e4c2008-09-19 12:56:03 +02001339 }
Stefan Raspl65d80132013-04-07 22:19:27 +00001340 qeth_clear_recovery_task(card);
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00001341 qeth_clear_thread_start_bit(card, QETH_RECOVER_THREAD);
1342 qeth_clear_thread_running_bit(card, QETH_RECOVER_THREAD);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001343 return 0;
1344}
1345
1346static int __init qeth_l2_init(void)
1347{
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001348 pr_info("register layer 2 discipline\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001349 return 0;
1350}
1351
1352static void __exit qeth_l2_exit(void)
1353{
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001354 pr_info("unregister layer 2 discipline\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001355}
1356
1357static void qeth_l2_shutdown(struct ccwgroup_device *gdev)
1358{
1359 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
Ursula Braunf78ac2b2011-12-19 22:56:33 +00001360 qeth_set_allowed_threads(card, 0, 1);
Frank Blaschka1da74b12011-05-12 18:45:02 +00001361 if ((gdev->state == CCWGROUP_ONLINE) && card->info.hwtrap)
1362 qeth_hw_trap(card, QETH_DIAGS_TRAP_DISARM);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001363 qeth_qdio_clear_card(card, 0);
1364 qeth_clear_qdio_buffers(card);
Ursula Braun22ae2792014-02-24 13:12:06 +01001365 qdio_free(CARD_DDEV(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001366}
1367
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02001368static int qeth_l2_pm_suspend(struct ccwgroup_device *gdev)
1369{
1370 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
1371
1372 if (card->dev)
1373 netif_device_detach(card->dev);
1374 qeth_set_allowed_threads(card, 0, 1);
1375 wait_event(card->wait_q, qeth_threads_running(card, 0xffffffff) == 0);
1376 if (gdev->state == CCWGROUP_OFFLINE)
1377 return 0;
1378 if (card->state == CARD_STATE_UP) {
Frank Blaschka1da74b12011-05-12 18:45:02 +00001379 if (card->info.hwtrap)
1380 qeth_hw_trap(card, QETH_DIAGS_TRAP_DISARM);
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02001381 __qeth_l2_set_offline(card->gdev, 1);
1382 } else
1383 __qeth_l2_set_offline(card->gdev, 0);
1384 return 0;
1385}
1386
1387static int qeth_l2_pm_resume(struct ccwgroup_device *gdev)
1388{
1389 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
1390 int rc = 0;
1391
1392 if (gdev->state == CCWGROUP_OFFLINE)
1393 goto out;
1394
1395 if (card->state == CARD_STATE_RECOVER) {
1396 rc = __qeth_l2_set_online(card->gdev, 1);
1397 if (rc) {
Ursula Braun869da902010-03-08 20:36:56 +00001398 rtnl_lock();
1399 dev_close(card->dev);
1400 rtnl_unlock();
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02001401 }
1402 } else
1403 rc = __qeth_l2_set_online(card->gdev, 0);
1404out:
1405 qeth_set_allowed_threads(card, 0xffffffff, 0);
1406 if (card->dev)
1407 netif_device_attach(card->dev);
1408 if (rc)
1409 dev_warn(&card->gdev->dev, "The qeth device driver "
1410 "failed to recover an error on the device\n");
1411 return rc;
1412}
1413
Eugene Crosserc044dc22014-01-29 09:23:48 +01001414/* Returns zero if the command is successfully "consumed" */
1415static int qeth_l2_control_event(struct qeth_card *card,
1416 struct qeth_ipa_cmd *cmd)
1417{
1418 switch (cmd->hdr.command) {
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001419 case IPA_CMD_SETBRIDGEPORT_OSA:
1420 case IPA_CMD_SETBRIDGEPORT_IQD:
Eugene Crosserc044dc22014-01-29 09:23:48 +01001421 if (cmd->data.sbp.hdr.command_code ==
1422 IPA_SBP_BRIDGE_PORT_STATE_CHANGE) {
1423 qeth_bridge_state_change(card, cmd);
1424 return 0;
1425 } else
1426 return 1;
1427 case IPA_CMD_ADDRESS_CHANGE_NOTIF:
1428 qeth_bridge_host_event(card, cmd);
1429 return 0;
1430 default:
1431 return 1;
1432 }
1433}
1434
Sebastian Ottc041f2d4872012-05-15 18:02:21 +02001435struct qeth_discipline qeth_l2_discipline = {
1436 .start_poll = qeth_qdio_start_poll,
1437 .input_handler = (qdio_handler_t *) qeth_qdio_input_handler,
1438 .output_handler = (qdio_handler_t *) qeth_qdio_output_handler,
1439 .recover = qeth_l2_recover,
1440 .setup = qeth_l2_probe_device,
Frank Blaschka4a71df52008-02-15 09:19:42 +01001441 .remove = qeth_l2_remove_device,
1442 .set_online = qeth_l2_set_online,
1443 .set_offline = qeth_l2_set_offline,
1444 .shutdown = qeth_l2_shutdown,
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02001445 .freeze = qeth_l2_pm_suspend,
1446 .thaw = qeth_l2_pm_resume,
1447 .restore = qeth_l2_pm_resume,
Eugene Crosserc044dc22014-01-29 09:23:48 +01001448 .control_event_handler = qeth_l2_control_event,
Frank Blaschka4a71df52008-02-15 09:19:42 +01001449};
Sebastian Ottc041f2d4872012-05-15 18:02:21 +02001450EXPORT_SYMBOL_GPL(qeth_l2_discipline);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001451
1452static int qeth_osn_send_control_data(struct qeth_card *card, int len,
1453 struct qeth_cmd_buffer *iob)
1454{
1455 unsigned long flags;
1456 int rc = 0;
1457
Carsten Otte847a50f2010-06-21 22:57:05 +00001458 QETH_CARD_TEXT(card, 5, "osndctrd");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001459
1460 wait_event(card->wait_q,
1461 atomic_cmpxchg(&card->write.irq_pending, 0, 1) == 0);
1462 qeth_prepare_control_data(card, len, iob);
Carsten Otte847a50f2010-06-21 22:57:05 +00001463 QETH_CARD_TEXT(card, 6, "osnoirqp");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001464 spin_lock_irqsave(get_ccwdev_lock(card->write.ccwdev), flags);
1465 rc = ccw_device_start(card->write.ccwdev, &card->write.ccw,
1466 (addr_t) iob, 0, 0);
1467 spin_unlock_irqrestore(get_ccwdev_lock(card->write.ccwdev), flags);
1468 if (rc) {
Frank Blaschka14cc21b2008-06-06 12:37:46 +02001469 QETH_DBF_MESSAGE(2, "qeth_osn_send_control_data: "
Frank Blaschka4a71df52008-02-15 09:19:42 +01001470 "ccw_device_start rc = %i\n", rc);
Carsten Otte847a50f2010-06-21 22:57:05 +00001471 QETH_CARD_TEXT_(card, 2, " err%d", rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001472 qeth_release_buffer(iob->channel, iob);
1473 atomic_set(&card->write.irq_pending, 0);
1474 wake_up(&card->wait_q);
1475 }
1476 return rc;
1477}
1478
1479static int qeth_osn_send_ipa_cmd(struct qeth_card *card,
1480 struct qeth_cmd_buffer *iob, int data_len)
1481{
1482 u16 s1, s2;
1483
Carsten Otte847a50f2010-06-21 22:57:05 +00001484 QETH_CARD_TEXT(card, 4, "osndipa");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001485
1486 qeth_prepare_ipa_cmd(card, iob, QETH_PROT_OSN2);
1487 s1 = (u16)(IPA_PDU_HEADER_SIZE + data_len);
1488 s2 = (u16)data_len;
1489 memcpy(QETH_IPA_PDU_LEN_TOTAL(iob->data), &s1, 2);
1490 memcpy(QETH_IPA_PDU_LEN_PDU1(iob->data), &s2, 2);
1491 memcpy(QETH_IPA_PDU_LEN_PDU2(iob->data), &s2, 2);
1492 memcpy(QETH_IPA_PDU_LEN_PDU3(iob->data), &s2, 2);
1493 return qeth_osn_send_control_data(card, s1, iob);
1494}
1495
1496int qeth_osn_assist(struct net_device *dev, void *data, int data_len)
1497{
1498 struct qeth_cmd_buffer *iob;
1499 struct qeth_card *card;
1500 int rc;
1501
Frank Blaschka4a71df52008-02-15 09:19:42 +01001502 if (!dev)
1503 return -ENODEV;
Heiko Carstens509e2562008-07-26 02:24:10 -07001504 card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001505 if (!card)
1506 return -ENODEV;
Carsten Otte847a50f2010-06-21 22:57:05 +00001507 QETH_CARD_TEXT(card, 2, "osnsdmc");
Eugene Crosserc3521252015-01-16 14:05:47 +01001508 if (!qeth_card_hw_is_reachable(card))
Frank Blaschka4a71df52008-02-15 09:19:42 +01001509 return -ENODEV;
1510 iob = qeth_wait_for_buffer(&card->write);
1511 memcpy(iob->data+IPA_PDU_HEADER_SIZE, data, data_len);
1512 rc = qeth_osn_send_ipa_cmd(card, iob, data_len);
1513 return rc;
1514}
1515EXPORT_SYMBOL(qeth_osn_assist);
1516
1517int qeth_osn_register(unsigned char *read_dev_no, struct net_device **dev,
1518 int (*assist_cb)(struct net_device *, void *),
1519 int (*data_cb)(struct sk_buff *))
1520{
1521 struct qeth_card *card;
1522
Frank Blaschka4a71df52008-02-15 09:19:42 +01001523 *dev = qeth_l2_netdev_by_devno(read_dev_no);
1524 if (*dev == NULL)
1525 return -ENODEV;
Heiko Carstens509e2562008-07-26 02:24:10 -07001526 card = (*dev)->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001527 if (!card)
1528 return -ENODEV;
Carsten Otte847a50f2010-06-21 22:57:05 +00001529 QETH_CARD_TEXT(card, 2, "osnreg");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001530 if ((assist_cb == NULL) || (data_cb == NULL))
1531 return -EINVAL;
1532 card->osn_info.assist_cb = assist_cb;
1533 card->osn_info.data_cb = data_cb;
1534 return 0;
1535}
1536EXPORT_SYMBOL(qeth_osn_register);
1537
1538void qeth_osn_deregister(struct net_device *dev)
1539{
1540 struct qeth_card *card;
1541
Frank Blaschka4a71df52008-02-15 09:19:42 +01001542 if (!dev)
1543 return;
Heiko Carstens509e2562008-07-26 02:24:10 -07001544 card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001545 if (!card)
1546 return;
Carsten Otte847a50f2010-06-21 22:57:05 +00001547 QETH_CARD_TEXT(card, 2, "osndereg");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001548 card->osn_info.assist_cb = NULL;
1549 card->osn_info.data_cb = NULL;
1550 return;
1551}
1552EXPORT_SYMBOL(qeth_osn_deregister);
1553
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001554/* SETBRIDGEPORT support, async notifications */
1555
Eugene Crosser9f48b9d2014-01-14 15:54:13 +01001556enum qeth_an_event_type {anev_reg_unreg, anev_abort, anev_reset};
1557
1558/**
1559 * qeth_bridge_emit_host_event() - bridgeport address change notification
1560 * @card: qeth_card structure pointer, for udev events.
1561 * @evtype: "normal" register/unregister, or abort, or reset. For abort
1562 * and reset token and addr_lnid are unused and may be NULL.
1563 * @code: event bitmask: high order bit 0x80 value 1 means removal of an
1564 * object, 0 - addition of an object.
1565 * 0x01 - VLAN, 0x02 - MAC, 0x03 - VLAN and MAC.
1566 * @token: "network token" structure identifying physical address of the port.
1567 * @addr_lnid: pointer to structure with MAC address and VLAN ID.
1568 *
1569 * This function is called when registrations and deregistrations are
1570 * reported by the hardware, and also when notifications are enabled -
1571 * for all currently registered addresses.
1572 */
1573static void qeth_bridge_emit_host_event(struct qeth_card *card,
1574 enum qeth_an_event_type evtype,
1575 u8 code, struct net_if_token *token, struct mac_addr_lnid *addr_lnid)
1576{
1577 char str[7][32];
1578 char *env[8];
1579 int i = 0;
1580
1581 switch (evtype) {
1582 case anev_reg_unreg:
1583 snprintf(str[i], sizeof(str[i]), "BRIDGEDHOST=%s",
1584 (code & IPA_ADDR_CHANGE_CODE_REMOVAL)
1585 ? "deregister" : "register");
1586 env[i] = str[i]; i++;
1587 if (code & IPA_ADDR_CHANGE_CODE_VLANID) {
1588 snprintf(str[i], sizeof(str[i]), "VLAN=%d",
1589 addr_lnid->lnid);
1590 env[i] = str[i]; i++;
1591 }
1592 if (code & IPA_ADDR_CHANGE_CODE_MACADDR) {
Eugene Crosser9846e702015-09-18 16:06:48 +02001593 snprintf(str[i], sizeof(str[i]), "MAC=%pM",
Thomas Richter4d7def22015-09-18 16:06:51 +02001594 addr_lnid->mac);
Eugene Crosser9f48b9d2014-01-14 15:54:13 +01001595 env[i] = str[i]; i++;
1596 }
1597 snprintf(str[i], sizeof(str[i]), "NTOK_BUSID=%x.%x.%04x",
1598 token->cssid, token->ssid, token->devnum);
1599 env[i] = str[i]; i++;
1600 snprintf(str[i], sizeof(str[i]), "NTOK_IID=%02x", token->iid);
1601 env[i] = str[i]; i++;
1602 snprintf(str[i], sizeof(str[i]), "NTOK_CHPID=%02x",
1603 token->chpid);
1604 env[i] = str[i]; i++;
1605 snprintf(str[i], sizeof(str[i]), "NTOK_CHID=%04x", token->chid);
1606 env[i] = str[i]; i++;
1607 break;
1608 case anev_abort:
1609 snprintf(str[i], sizeof(str[i]), "BRIDGEDHOST=abort");
1610 env[i] = str[i]; i++;
1611 break;
1612 case anev_reset:
1613 snprintf(str[i], sizeof(str[i]), "BRIDGEDHOST=reset");
1614 env[i] = str[i]; i++;
1615 break;
1616 }
1617 env[i] = NULL;
1618 kobject_uevent_env(&card->gdev->dev.kobj, KOBJ_CHANGE, env);
1619}
1620
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001621struct qeth_bridge_state_data {
1622 struct work_struct worker;
1623 struct qeth_card *card;
1624 struct qeth_sbp_state_change qports;
1625};
1626
1627static void qeth_bridge_state_change_worker(struct work_struct *work)
1628{
1629 struct qeth_bridge_state_data *data =
1630 container_of(work, struct qeth_bridge_state_data, worker);
1631 /* We are only interested in the first entry - local port */
1632 struct qeth_sbp_port_entry *entry = &data->qports.entry[0];
1633 char env_locrem[32];
1634 char env_role[32];
1635 char env_state[32];
1636 char *env[] = {
1637 env_locrem,
1638 env_role,
1639 env_state,
1640 NULL
1641 };
1642
1643 /* Role should not change by itself, but if it did, */
1644 /* information from the hardware is authoritative. */
1645 mutex_lock(&data->card->conf_mutex);
1646 data->card->options.sbp.role = entry->role;
1647 mutex_unlock(&data->card->conf_mutex);
1648
1649 snprintf(env_locrem, sizeof(env_locrem), "BRIDGEPORT=statechange");
1650 snprintf(env_role, sizeof(env_role), "ROLE=%s",
1651 (entry->role == QETH_SBP_ROLE_NONE) ? "none" :
1652 (entry->role == QETH_SBP_ROLE_PRIMARY) ? "primary" :
1653 (entry->role == QETH_SBP_ROLE_SECONDARY) ? "secondary" :
1654 "<INVALID>");
1655 snprintf(env_state, sizeof(env_state), "STATE=%s",
1656 (entry->state == QETH_SBP_STATE_INACTIVE) ? "inactive" :
1657 (entry->state == QETH_SBP_STATE_STANDBY) ? "standby" :
1658 (entry->state == QETH_SBP_STATE_ACTIVE) ? "active" :
1659 "<INVALID>");
1660 kobject_uevent_env(&data->card->gdev->dev.kobj,
1661 KOBJ_CHANGE, env);
1662 kfree(data);
1663}
1664
Eugene Crosserc044dc22014-01-29 09:23:48 +01001665static void qeth_bridge_state_change(struct qeth_card *card,
1666 struct qeth_ipa_cmd *cmd)
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001667{
1668 struct qeth_sbp_state_change *qports =
1669 &cmd->data.sbp.data.state_change;
1670 struct qeth_bridge_state_data *data;
1671 int extrasize;
1672
1673 QETH_CARD_TEXT(card, 2, "brstchng");
1674 if (qports->entry_length != sizeof(struct qeth_sbp_port_entry)) {
Thomas Richter8a593142014-10-22 12:18:03 +02001675 QETH_CARD_TEXT_(card, 2, "BPsz%04x", qports->entry_length);
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001676 return;
1677 }
1678 extrasize = sizeof(struct qeth_sbp_port_entry) * qports->num_entries;
1679 data = kzalloc(sizeof(struct qeth_bridge_state_data) + extrasize,
1680 GFP_ATOMIC);
1681 if (!data) {
1682 QETH_CARD_TEXT(card, 2, "BPSalloc");
1683 return;
1684 }
1685 INIT_WORK(&data->worker, qeth_bridge_state_change_worker);
1686 data->card = card;
1687 memcpy(&data->qports, qports,
1688 sizeof(struct qeth_sbp_state_change) + extrasize);
1689 queue_work(qeth_wq, &data->worker);
1690}
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001691
Eugene Crosser9f48b9d2014-01-14 15:54:13 +01001692struct qeth_bridge_host_data {
1693 struct work_struct worker;
1694 struct qeth_card *card;
1695 struct qeth_ipacmd_addr_change hostevs;
1696};
1697
1698static void qeth_bridge_host_event_worker(struct work_struct *work)
1699{
1700 struct qeth_bridge_host_data *data =
1701 container_of(work, struct qeth_bridge_host_data, worker);
1702 int i;
1703
1704 if (data->hostevs.lost_event_mask) {
1705 dev_info(&data->card->gdev->dev,
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001706"Address notification from the Bridge Port stopped %s (%s)\n",
Eugene Crosser9f48b9d2014-01-14 15:54:13 +01001707 data->card->dev->name,
1708 (data->hostevs.lost_event_mask == 0x01)
1709 ? "Overflow"
1710 : (data->hostevs.lost_event_mask == 0x02)
1711 ? "Bridge port state change"
1712 : "Unknown reason");
1713 mutex_lock(&data->card->conf_mutex);
1714 data->card->options.sbp.hostnotification = 0;
1715 mutex_unlock(&data->card->conf_mutex);
1716 qeth_bridge_emit_host_event(data->card, anev_abort,
1717 0, NULL, NULL);
1718 } else
1719 for (i = 0; i < data->hostevs.num_entries; i++) {
1720 struct qeth_ipacmd_addr_change_entry *entry =
1721 &data->hostevs.entry[i];
1722 qeth_bridge_emit_host_event(data->card,
1723 anev_reg_unreg,
1724 entry->change_code,
1725 &entry->token, &entry->addr_lnid);
1726 }
1727 kfree(data);
1728}
1729
Eugene Crosserc044dc22014-01-29 09:23:48 +01001730static void qeth_bridge_host_event(struct qeth_card *card,
1731 struct qeth_ipa_cmd *cmd)
Eugene Crosser9f48b9d2014-01-14 15:54:13 +01001732{
1733 struct qeth_ipacmd_addr_change *hostevs =
1734 &cmd->data.addrchange;
1735 struct qeth_bridge_host_data *data;
1736 int extrasize;
1737
1738 QETH_CARD_TEXT(card, 2, "brhostev");
1739 if (cmd->hdr.return_code != 0x0000) {
1740 if (cmd->hdr.return_code == 0x0010) {
1741 if (hostevs->lost_event_mask == 0x00)
1742 hostevs->lost_event_mask = 0xff;
1743 } else {
1744 QETH_CARD_TEXT_(card, 2, "BPHe%04x",
1745 cmd->hdr.return_code);
1746 return;
1747 }
1748 }
1749 extrasize = sizeof(struct qeth_ipacmd_addr_change_entry) *
1750 hostevs->num_entries;
1751 data = kzalloc(sizeof(struct qeth_bridge_host_data) + extrasize,
1752 GFP_ATOMIC);
1753 if (!data) {
1754 QETH_CARD_TEXT(card, 2, "BPHalloc");
1755 return;
1756 }
1757 INIT_WORK(&data->worker, qeth_bridge_host_event_worker);
1758 data->card = card;
1759 memcpy(&data->hostevs, hostevs,
1760 sizeof(struct qeth_ipacmd_addr_change) + extrasize);
1761 queue_work(qeth_wq, &data->worker);
1762}
Eugene Crosser9f48b9d2014-01-14 15:54:13 +01001763
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001764/* SETBRIDGEPORT support; sending commands */
1765
1766struct _qeth_sbp_cbctl {
1767 u16 ipa_rc;
1768 u16 cmd_rc;
1769 union {
1770 u32 supported;
1771 struct {
1772 enum qeth_sbp_roles *role;
1773 enum qeth_sbp_states *state;
1774 } qports;
1775 } data;
1776};
1777
1778/**
1779 * qeth_bridgeport_makerc() - derive "traditional" error from hardware codes.
1780 * @card: qeth_card structure pointer, for debug messages.
1781 * @cbctl: state structure with hardware return codes.
1782 * @setcmd: IPA command code
1783 *
1784 * Returns negative errno-compatible error indication or 0 on success.
1785 */
1786static int qeth_bridgeport_makerc(struct qeth_card *card,
1787 struct _qeth_sbp_cbctl *cbctl, enum qeth_ipa_sbp_cmd setcmd)
1788{
1789 int rc;
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001790 int is_iqd = (card->info.type == QETH_CARD_TYPE_IQD);
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001791
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001792 if ((is_iqd && (cbctl->ipa_rc == IPA_RC_SUCCESS)) ||
1793 (!is_iqd && (cbctl->ipa_rc == cbctl->cmd_rc)))
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001794 switch (cbctl->cmd_rc) {
1795 case 0x0000:
1796 rc = 0;
1797 break;
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001798 case 0x2B04:
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001799 case 0x0004:
Eugene Crosserffb95252015-05-18 14:27:58 +02001800 rc = -EOPNOTSUPP;
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001801 break;
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001802 case 0x2B0C:
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001803 case 0x000C: /* Not configured as bridge Port */
1804 rc = -ENODEV; /* maybe not the best code here? */
1805 dev_err(&card->gdev->dev,
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001806 "The device is not configured as a Bridge Port\n");
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001807 break;
Eugene Crosser1b05cf62016-06-16 16:18:51 +02001808 case 0x2B10:
1809 case 0x0010: /* OS mismatch */
1810 rc = -EPERM;
1811 dev_err(&card->gdev->dev,
1812 "A Bridge Port is already configured by a different operating system\n");
1813 break;
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001814 case 0x2B14:
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001815 case 0x0014: /* Another device is Primary */
1816 switch (setcmd) {
1817 case IPA_SBP_SET_PRIMARY_BRIDGE_PORT:
1818 rc = -EEXIST;
1819 dev_err(&card->gdev->dev,
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001820 "The LAN already has a primary Bridge Port\n");
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001821 break;
1822 case IPA_SBP_SET_SECONDARY_BRIDGE_PORT:
1823 rc = -EBUSY;
1824 dev_err(&card->gdev->dev,
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001825 "The device is already a primary Bridge Port\n");
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001826 break;
1827 default:
1828 rc = -EIO;
1829 }
1830 break;
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001831 case 0x2B18:
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001832 case 0x0018: /* This device is currently Secondary */
1833 rc = -EBUSY;
1834 dev_err(&card->gdev->dev,
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001835 "The device is already a secondary Bridge Port\n");
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001836 break;
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001837 case 0x2B1C:
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001838 case 0x001C: /* Limit for Secondary devices reached */
1839 rc = -EEXIST;
1840 dev_err(&card->gdev->dev,
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001841 "The LAN cannot have more secondary Bridge Ports\n");
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001842 break;
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001843 case 0x2B24:
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001844 case 0x0024: /* This device is currently Primary */
1845 rc = -EBUSY;
1846 dev_err(&card->gdev->dev,
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001847 "The device is already a primary Bridge Port\n");
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001848 break;
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001849 case 0x2B20:
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001850 case 0x0020: /* Not authorized by zManager */
1851 rc = -EACCES;
1852 dev_err(&card->gdev->dev,
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001853 "The device is not authorized to be a Bridge Port\n");
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001854 break;
1855 default:
1856 rc = -EIO;
1857 }
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001858 else
1859 switch (cbctl->ipa_rc) {
1860 case IPA_RC_NOTSUPP:
Eugene Crosserffb95252015-05-18 14:27:58 +02001861 rc = -EOPNOTSUPP;
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001862 break;
1863 case IPA_RC_UNSUPPORTED_COMMAND:
Eugene Crosserffb95252015-05-18 14:27:58 +02001864 rc = -EOPNOTSUPP;
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001865 break;
1866 default:
1867 rc = -EIO;
1868 }
1869
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001870 if (rc) {
1871 QETH_CARD_TEXT_(card, 2, "SBPi%04x", cbctl->ipa_rc);
1872 QETH_CARD_TEXT_(card, 2, "SBPc%04x", cbctl->cmd_rc);
1873 }
1874 return rc;
1875}
1876
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001877static inline int ipa_cmd_sbp(struct qeth_card *card)
1878{
1879 return (card->info.type == QETH_CARD_TYPE_IQD) ?
1880 IPA_CMD_SETBRIDGEPORT_IQD :
1881 IPA_CMD_SETBRIDGEPORT_OSA;
1882}
1883
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001884static int qeth_bridgeport_query_support_cb(struct qeth_card *card,
1885 struct qeth_reply *reply, unsigned long data)
1886{
1887 struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *) data;
1888 struct _qeth_sbp_cbctl *cbctl = (struct _qeth_sbp_cbctl *)reply->param;
1889 QETH_CARD_TEXT(card, 2, "brqsupcb");
1890 cbctl->ipa_rc = cmd->hdr.return_code;
1891 cbctl->cmd_rc = cmd->data.sbp.hdr.return_code;
1892 if ((cbctl->ipa_rc == 0) && (cbctl->cmd_rc == 0)) {
1893 cbctl->data.supported =
1894 cmd->data.sbp.data.query_cmds_supp.supported_cmds;
1895 } else {
1896 cbctl->data.supported = 0;
1897 }
1898 return 0;
1899}
1900
1901/**
1902 * qeth_bridgeport_query_support() - store bitmask of supported subfunctions.
1903 * @card: qeth_card structure pointer.
1904 *
1905 * Sets bitmask of supported setbridgeport subfunctions in the qeth_card
1906 * strucutre: card->options.sbp.supported_funcs.
1907 */
Eugene Crosserc044dc22014-01-29 09:23:48 +01001908static void qeth_bridgeport_query_support(struct qeth_card *card)
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001909{
1910 struct qeth_cmd_buffer *iob;
1911 struct qeth_ipa_cmd *cmd;
1912 struct _qeth_sbp_cbctl cbctl;
1913
1914 QETH_CARD_TEXT(card, 2, "brqsuppo");
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001915 iob = qeth_get_ipacmd_buffer(card, ipa_cmd_sbp(card), 0);
Thomas Richter1aec42b2015-01-21 13:39:10 +01001916 if (!iob)
1917 return;
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001918 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
1919 cmd->data.sbp.hdr.cmdlength =
1920 sizeof(struct qeth_ipacmd_sbp_hdr) +
1921 sizeof(struct qeth_sbp_query_cmds_supp);
1922 cmd->data.sbp.hdr.command_code =
1923 IPA_SBP_QUERY_COMMANDS_SUPPORTED;
1924 cmd->data.sbp.hdr.used_total = 1;
1925 cmd->data.sbp.hdr.seq_no = 1;
1926 if (qeth_send_ipa_cmd(card, iob, qeth_bridgeport_query_support_cb,
1927 (void *)&cbctl) ||
1928 qeth_bridgeport_makerc(card, &cbctl,
1929 IPA_SBP_QUERY_COMMANDS_SUPPORTED)) {
1930 /* non-zero makerc signifies failure, and produce messages */
1931 card->options.sbp.role = QETH_SBP_ROLE_NONE;
1932 return;
1933 }
1934 card->options.sbp.supported_funcs = cbctl.data.supported;
1935}
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001936
1937static int qeth_bridgeport_query_ports_cb(struct qeth_card *card,
1938 struct qeth_reply *reply, unsigned long data)
1939{
1940 struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *) data;
1941 struct qeth_sbp_query_ports *qports = &cmd->data.sbp.data.query_ports;
1942 struct _qeth_sbp_cbctl *cbctl = (struct _qeth_sbp_cbctl *)reply->param;
1943
1944 QETH_CARD_TEXT(card, 2, "brqprtcb");
1945 cbctl->ipa_rc = cmd->hdr.return_code;
1946 cbctl->cmd_rc = cmd->data.sbp.hdr.return_code;
1947 if ((cbctl->ipa_rc != 0) || (cbctl->cmd_rc != 0))
1948 return 0;
1949 if (qports->entry_length != sizeof(struct qeth_sbp_port_entry)) {
1950 cbctl->cmd_rc = 0xffff;
1951 QETH_CARD_TEXT_(card, 2, "SBPs%04x", qports->entry_length);
1952 return 0;
1953 }
1954 /* first entry contains the state of the local port */
1955 if (qports->num_entries > 0) {
1956 if (cbctl->data.qports.role)
1957 *cbctl->data.qports.role = qports->entry[0].role;
1958 if (cbctl->data.qports.state)
1959 *cbctl->data.qports.state = qports->entry[0].state;
1960 }
1961 return 0;
1962}
1963
1964/**
1965 * qeth_bridgeport_query_ports() - query local bridgeport status.
1966 * @card: qeth_card structure pointer.
1967 * @role: Role of the port: 0-none, 1-primary, 2-secondary.
1968 * @state: State of the port: 0-inactive, 1-standby, 2-active.
1969 *
1970 * Returns negative errno-compatible error indication or 0 on success.
1971 *
1972 * 'role' and 'state' are not updated in case of hardware operation failure.
1973 */
1974int qeth_bridgeport_query_ports(struct qeth_card *card,
1975 enum qeth_sbp_roles *role, enum qeth_sbp_states *state)
1976{
1977 int rc = 0;
1978 struct qeth_cmd_buffer *iob;
1979 struct qeth_ipa_cmd *cmd;
1980 struct _qeth_sbp_cbctl cbctl = {
1981 .data = {
1982 .qports = {
1983 .role = role,
1984 .state = state,
1985 },
1986 },
1987 };
1988
1989 QETH_CARD_TEXT(card, 2, "brqports");
1990 if (!(card->options.sbp.supported_funcs & IPA_SBP_QUERY_BRIDGE_PORTS))
1991 return -EOPNOTSUPP;
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001992 iob = qeth_get_ipacmd_buffer(card, ipa_cmd_sbp(card), 0);
Thomas Richter1aec42b2015-01-21 13:39:10 +01001993 if (!iob)
1994 return -ENOMEM;
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001995 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
1996 cmd->data.sbp.hdr.cmdlength =
1997 sizeof(struct qeth_ipacmd_sbp_hdr);
1998 cmd->data.sbp.hdr.command_code =
1999 IPA_SBP_QUERY_BRIDGE_PORTS;
2000 cmd->data.sbp.hdr.used_total = 1;
2001 cmd->data.sbp.hdr.seq_no = 1;
2002 rc = qeth_send_ipa_cmd(card, iob, qeth_bridgeport_query_ports_cb,
2003 (void *)&cbctl);
Eugene Crosserc88394e2015-05-18 14:27:53 +02002004 if (rc < 0)
Eugene Crosserb4d72c02014-01-14 15:54:11 +01002005 return rc;
Eugene Crosserc88394e2015-05-18 14:27:53 +02002006 return qeth_bridgeport_makerc(card, &cbctl, IPA_SBP_QUERY_BRIDGE_PORTS);
Eugene Crosserb4d72c02014-01-14 15:54:11 +01002007}
2008EXPORT_SYMBOL_GPL(qeth_bridgeport_query_ports);
2009
2010static int qeth_bridgeport_set_cb(struct qeth_card *card,
2011 struct qeth_reply *reply, unsigned long data)
2012{
2013 struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *)data;
2014 struct _qeth_sbp_cbctl *cbctl = (struct _qeth_sbp_cbctl *)reply->param;
2015 QETH_CARD_TEXT(card, 2, "brsetrcb");
2016 cbctl->ipa_rc = cmd->hdr.return_code;
2017 cbctl->cmd_rc = cmd->data.sbp.hdr.return_code;
2018 return 0;
2019}
2020
2021/**
2022 * qeth_bridgeport_setrole() - Assign primary role to the port.
2023 * @card: qeth_card structure pointer.
2024 * @role: Role to assign.
2025 *
2026 * Returns negative errno-compatible error indication or 0 on success.
2027 */
2028int qeth_bridgeport_setrole(struct qeth_card *card, enum qeth_sbp_roles role)
2029{
2030 int rc = 0;
2031 int cmdlength;
2032 struct qeth_cmd_buffer *iob;
2033 struct qeth_ipa_cmd *cmd;
2034 struct _qeth_sbp_cbctl cbctl;
2035 enum qeth_ipa_sbp_cmd setcmd;
2036
2037 QETH_CARD_TEXT(card, 2, "brsetrol");
2038 switch (role) {
2039 case QETH_SBP_ROLE_NONE:
2040 setcmd = IPA_SBP_RESET_BRIDGE_PORT_ROLE;
2041 cmdlength = sizeof(struct qeth_ipacmd_sbp_hdr) +
2042 sizeof(struct qeth_sbp_reset_role);
2043 break;
2044 case QETH_SBP_ROLE_PRIMARY:
2045 setcmd = IPA_SBP_SET_PRIMARY_BRIDGE_PORT;
2046 cmdlength = sizeof(struct qeth_ipacmd_sbp_hdr) +
2047 sizeof(struct qeth_sbp_set_primary);
2048 break;
2049 case QETH_SBP_ROLE_SECONDARY:
2050 setcmd = IPA_SBP_SET_SECONDARY_BRIDGE_PORT;
2051 cmdlength = sizeof(struct qeth_ipacmd_sbp_hdr) +
2052 sizeof(struct qeth_sbp_set_secondary);
2053 break;
2054 default:
2055 return -EINVAL;
2056 }
2057 if (!(card->options.sbp.supported_funcs & setcmd))
2058 return -EOPNOTSUPP;
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02002059 iob = qeth_get_ipacmd_buffer(card, ipa_cmd_sbp(card), 0);
Thomas Richter1aec42b2015-01-21 13:39:10 +01002060 if (!iob)
2061 return -ENOMEM;
Eugene Crosserb4d72c02014-01-14 15:54:11 +01002062 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
2063 cmd->data.sbp.hdr.cmdlength = cmdlength;
2064 cmd->data.sbp.hdr.command_code = setcmd;
2065 cmd->data.sbp.hdr.used_total = 1;
2066 cmd->data.sbp.hdr.seq_no = 1;
2067 rc = qeth_send_ipa_cmd(card, iob, qeth_bridgeport_set_cb,
2068 (void *)&cbctl);
Eugene Crosserc88394e2015-05-18 14:27:53 +02002069 if (rc < 0)
Eugene Crosserb4d72c02014-01-14 15:54:11 +01002070 return rc;
Eugene Crosserc88394e2015-05-18 14:27:53 +02002071 return qeth_bridgeport_makerc(card, &cbctl, setcmd);
Eugene Crosserb4d72c02014-01-14 15:54:11 +01002072}
2073
Eugene Crosser9f48b9d2014-01-14 15:54:13 +01002074/**
2075 * qeth_anset_makerc() - derive "traditional" error from hardware codes.
2076 * @card: qeth_card structure pointer, for debug messages.
2077 *
2078 * Returns negative errno-compatible error indication or 0 on success.
2079 */
2080static int qeth_anset_makerc(struct qeth_card *card, int pnso_rc, u16 response)
2081{
2082 int rc;
2083
2084 if (pnso_rc == 0)
2085 switch (response) {
2086 case 0x0001:
2087 rc = 0;
2088 break;
2089 case 0x0004:
2090 case 0x0100:
2091 case 0x0106:
Eugene Crosserffb95252015-05-18 14:27:58 +02002092 rc = -EOPNOTSUPP;
Eugene Crosser9f48b9d2014-01-14 15:54:13 +01002093 dev_err(&card->gdev->dev,
2094 "Setting address notification failed\n");
2095 break;
2096 case 0x0107:
2097 rc = -EAGAIN;
2098 break;
2099 default:
2100 rc = -EIO;
2101 }
2102 else
2103 rc = -EIO;
2104
2105 if (rc) {
2106 QETH_CARD_TEXT_(card, 2, "SBPp%04x", pnso_rc);
2107 QETH_CARD_TEXT_(card, 2, "SBPr%04x", response);
2108 }
2109 return rc;
2110}
2111
2112static void qeth_bridgeport_an_set_cb(void *priv,
2113 enum qdio_brinfo_entry_type type, void *entry)
2114{
2115 struct qeth_card *card = (struct qeth_card *)priv;
2116 struct qdio_brinfo_entry_l2 *l2entry;
2117 u8 code;
2118
2119 if (type != l2_addr_lnid) {
2120 WARN_ON_ONCE(1);
2121 return;
2122 }
2123
2124 l2entry = (struct qdio_brinfo_entry_l2 *)entry;
2125 code = IPA_ADDR_CHANGE_CODE_MACADDR;
2126 if (l2entry->addr_lnid.lnid)
2127 code |= IPA_ADDR_CHANGE_CODE_VLANID;
2128 qeth_bridge_emit_host_event(card, anev_reg_unreg, code,
2129 (struct net_if_token *)&l2entry->nit,
2130 (struct mac_addr_lnid *)&l2entry->addr_lnid);
2131}
2132
2133/**
2134 * qeth_bridgeport_an_set() - Enable or disable bridgeport address notification
2135 * @card: qeth_card structure pointer.
2136 * @enable: 0 - disable, non-zero - enable notifications
2137 *
2138 * Returns negative errno-compatible error indication or 0 on success.
2139 *
2140 * On enable, emits a series of address notifications udev events for all
2141 * currently registered hosts.
2142 */
2143int qeth_bridgeport_an_set(struct qeth_card *card, int enable)
2144{
2145 int rc;
2146 u16 response;
2147 struct ccw_device *ddev;
2148 struct subchannel_id schid;
2149
2150 if (!card)
2151 return -EINVAL;
2152 if (!card->options.sbp.supported_funcs)
2153 return -EOPNOTSUPP;
2154 ddev = CARD_DDEV(card);
2155 ccw_device_get_schid(ddev, &schid);
2156
2157 if (enable) {
2158 qeth_bridge_emit_host_event(card, anev_reset, 0, NULL, NULL);
2159 rc = qdio_pnso_brinfo(schid, 1, &response,
2160 qeth_bridgeport_an_set_cb, card);
2161 } else
2162 rc = qdio_pnso_brinfo(schid, 0, &response, NULL, NULL);
2163 return qeth_anset_makerc(card, rc, response);
2164}
2165EXPORT_SYMBOL_GPL(qeth_bridgeport_an_set);
2166
Frank Blaschka4a71df52008-02-15 09:19:42 +01002167module_init(qeth_l2_init);
2168module_exit(qeth_l2_exit);
2169MODULE_AUTHOR("Frank Blaschka <frank.blaschka@de.ibm.com>");
2170MODULE_DESCRIPTION("qeth layer 2 discipline");
2171MODULE_LICENSE("GPL");