blob: 945f3e0a9f065949428d4226234e5b2c700eb9fa [file] [log] [blame]
Frank Blaschka4a71df52008-02-15 09:19:42 +01001/*
2 * drivers/s390/net/qeth_l2_main.c
3 *
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02004 * Copyright IBM Corp. 2007, 2009
Frank Blaschka4a71df52008-02-15 09:19:42 +01005 * Author(s): Utz Bacher <utz.bacher@de.ibm.com>,
6 * Frank Pavlic <fpavlic@de.ibm.com>,
7 * Thomas Spatzier <tspat@de.ibm.com>,
8 * Frank Blaschka <frank.blaschka@de.ibm.com>
9 */
10
Frank Blaschka74eacdb2008-12-25 13:39:49 +010011#define KMSG_COMPONENT "qeth"
12#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
13
Frank Blaschka4a71df52008-02-15 09:19:42 +010014#include <linux/module.h>
15#include <linux/moduleparam.h>
16#include <linux/string.h>
17#include <linux/errno.h>
18#include <linux/kernel.h>
19#include <linux/etherdevice.h>
20#include <linux/mii.h>
21#include <linux/ip.h>
Jiri Pirkoccffad252009-05-22 23:22:17 +000022#include <linux/list.h>
Frank Blaschka4a71df52008-02-15 09:19:42 +010023
Frank Blaschka4a71df52008-02-15 09:19:42 +010024#include "qeth_core.h"
Frank Blaschka4a71df52008-02-15 09:19:42 +010025
Frank Blaschka4a71df52008-02-15 09:19:42 +010026static int qeth_l2_set_offline(struct ccwgroup_device *);
27static int qeth_l2_stop(struct net_device *);
28static int qeth_l2_send_delmac(struct qeth_card *, __u8 *);
29static int qeth_l2_send_setdelmac(struct qeth_card *, __u8 *,
30 enum qeth_ipa_cmds,
31 int (*reply_cb) (struct qeth_card *,
32 struct qeth_reply*,
33 unsigned long));
34static void qeth_l2_set_multicast_list(struct net_device *);
35static int qeth_l2_recover(void *);
36
37static int qeth_l2_do_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
38{
Heiko Carstens509e2562008-07-26 02:24:10 -070039 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +010040 struct mii_ioctl_data *mii_data;
41 int rc = 0;
42
43 if (!card)
44 return -ENODEV;
45
46 if ((card->state != CARD_STATE_UP) &&
47 (card->state != CARD_STATE_SOFTSETUP))
48 return -ENODEV;
49
50 if (card->info.type == QETH_CARD_TYPE_OSN)
51 return -EPERM;
52
53 switch (cmd) {
54 case SIOC_QETH_ADP_SET_SNMP_CONTROL:
55 rc = qeth_snmp_command(card, rq->ifr_ifru.ifru_data);
56 break;
57 case SIOC_QETH_GET_CARD_TYPE:
58 if ((card->info.type == QETH_CARD_TYPE_OSAE) &&
59 !card->info.guestlan)
60 return 1;
61 return 0;
62 break;
63 case SIOCGMIIPHY:
64 mii_data = if_mii(rq);
65 mii_data->phy_id = 0;
66 break;
67 case SIOCGMIIREG:
68 mii_data = if_mii(rq);
69 if (mii_data->phy_id != 0)
70 rc = -EINVAL;
71 else
72 mii_data->val_out = qeth_mdio_read(dev,
73 mii_data->phy_id, mii_data->reg_num);
74 break;
75 default:
76 rc = -EOPNOTSUPP;
77 }
78 if (rc)
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +020079 QETH_DBF_TEXT_(TRACE, 2, "ioce%d", rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +010080 return rc;
81}
82
83static int qeth_l2_verify_dev(struct net_device *dev)
84{
85 struct qeth_card *card;
86 unsigned long flags;
87 int rc = 0;
88
89 read_lock_irqsave(&qeth_core_card_list.rwlock, flags);
90 list_for_each_entry(card, &qeth_core_card_list.list, list) {
91 if (card->dev == dev) {
92 rc = QETH_REAL_CARD;
93 break;
94 }
95 }
96 read_unlock_irqrestore(&qeth_core_card_list.rwlock, flags);
97
98 return rc;
99}
100
101static struct net_device *qeth_l2_netdev_by_devno(unsigned char *read_dev_no)
102{
103 struct qeth_card *card;
104 struct net_device *ndev;
Cornelia Huckf06f6f32008-06-06 12:37:45 +0200105 __u16 temp_dev_no;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100106 unsigned long flags;
Cornelia Huckf06f6f32008-06-06 12:37:45 +0200107 struct ccw_dev_id read_devid;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100108
109 ndev = NULL;
110 memcpy(&temp_dev_no, read_dev_no, 2);
111 read_lock_irqsave(&qeth_core_card_list.rwlock, flags);
112 list_for_each_entry(card, &qeth_core_card_list.list, list) {
Cornelia Huckf06f6f32008-06-06 12:37:45 +0200113 ccw_device_get_id(CARD_RDEV(card), &read_devid);
114 if (read_devid.devno == temp_dev_no) {
Frank Blaschka4a71df52008-02-15 09:19:42 +0100115 ndev = card->dev;
116 break;
117 }
118 }
119 read_unlock_irqrestore(&qeth_core_card_list.rwlock, flags);
120 return ndev;
121}
122
123static int qeth_l2_send_setgroupmac_cb(struct qeth_card *card,
124 struct qeth_reply *reply,
125 unsigned long data)
126{
127 struct qeth_ipa_cmd *cmd;
128 __u8 *mac;
129
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200130 QETH_DBF_TEXT(TRACE, 2, "L2Sgmacb");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100131 cmd = (struct qeth_ipa_cmd *) data;
132 mac = &cmd->data.setdelmac.mac[0];
133 /* MAC already registered, needed in couple/uncouple case */
Ursula Braun0666eb062009-05-19 21:38:39 +0000134 if (cmd->hdr.return_code == IPA_RC_L2_DUP_MAC) {
Johannes Berg7c510e42008-10-27 17:47:26 -0700135 QETH_DBF_MESSAGE(2, "Group MAC %pM already existing on %s \n",
136 mac, QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100137 cmd->hdr.return_code = 0;
138 }
139 if (cmd->hdr.return_code)
Johannes Berg7c510e42008-10-27 17:47:26 -0700140 QETH_DBF_MESSAGE(2, "Could not set group MAC %pM on %s: %x\n",
141 mac, QETH_CARD_IFNAME(card), cmd->hdr.return_code);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100142 return 0;
143}
144
145static int qeth_l2_send_setgroupmac(struct qeth_card *card, __u8 *mac)
146{
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200147 QETH_DBF_TEXT(TRACE, 2, "L2Sgmac");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100148 return qeth_l2_send_setdelmac(card, mac, IPA_CMD_SETGMAC,
149 qeth_l2_send_setgroupmac_cb);
150}
151
152static int qeth_l2_send_delgroupmac_cb(struct qeth_card *card,
153 struct qeth_reply *reply,
154 unsigned long data)
155{
156 struct qeth_ipa_cmd *cmd;
157 __u8 *mac;
158
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200159 QETH_DBF_TEXT(TRACE, 2, "L2Dgmacb");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100160 cmd = (struct qeth_ipa_cmd *) data;
161 mac = &cmd->data.setdelmac.mac[0];
162 if (cmd->hdr.return_code)
Johannes Berg7c510e42008-10-27 17:47:26 -0700163 QETH_DBF_MESSAGE(2, "Could not delete group MAC %pM on %s: %x\n",
164 mac, QETH_CARD_IFNAME(card), cmd->hdr.return_code);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100165 return 0;
166}
167
168static int qeth_l2_send_delgroupmac(struct qeth_card *card, __u8 *mac)
169{
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200170 QETH_DBF_TEXT(TRACE, 2, "L2Dgmac");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100171 return qeth_l2_send_setdelmac(card, mac, IPA_CMD_DELGMAC,
172 qeth_l2_send_delgroupmac_cb);
173}
174
Frank Blaschka7db22662008-08-15 08:02:59 +0200175static void qeth_l2_add_mc(struct qeth_card *card, __u8 *mac, int vmac)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100176{
177 struct qeth_mc_mac *mc;
Frank Blaschka7db22662008-08-15 08:02:59 +0200178 int rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100179
180 mc = kmalloc(sizeof(struct qeth_mc_mac), GFP_ATOMIC);
181
Frank Blaschka14cc21b2008-06-06 12:37:46 +0200182 if (!mc)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100183 return;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100184
185 memcpy(mc->mc_addr, mac, OSA_ADDR_LEN);
186 mc->mc_addrlen = OSA_ADDR_LEN;
Frank Blaschka7db22662008-08-15 08:02:59 +0200187 mc->is_vmac = vmac;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100188
Frank Blaschka7db22662008-08-15 08:02:59 +0200189 if (vmac) {
190 rc = qeth_l2_send_setdelmac(card, mac, IPA_CMD_SETVMAC,
191 NULL);
192 } else {
193 rc = qeth_l2_send_setgroupmac(card, mac);
194 }
195
196 if (!rc)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100197 list_add_tail(&mc->list, &card->mc_list);
198 else
199 kfree(mc);
200}
201
202static void qeth_l2_del_all_mc(struct qeth_card *card)
203{
204 struct qeth_mc_mac *mc, *tmp;
205
206 spin_lock_bh(&card->mclock);
207 list_for_each_entry_safe(mc, tmp, &card->mc_list, list) {
Frank Blaschka7db22662008-08-15 08:02:59 +0200208 if (mc->is_vmac)
209 qeth_l2_send_setdelmac(card, mc->mc_addr,
210 IPA_CMD_DELVMAC, NULL);
211 else
212 qeth_l2_send_delgroupmac(card, mc->mc_addr);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100213 list_del(&mc->list);
214 kfree(mc);
215 }
216 spin_unlock_bh(&card->mclock);
217}
218
Klaus-Dieter Wackerce73e102009-08-26 02:01:08 +0000219static inline int qeth_l2_get_cast_type(struct qeth_card *card,
220 struct sk_buff *skb)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100221{
Klaus-Dieter Wackerce73e102009-08-26 02:01:08 +0000222 if (card->info.type == QETH_CARD_TYPE_OSN)
223 return RTN_UNSPEC;
224 if (is_broadcast_ether_addr(skb->data))
225 return RTN_BROADCAST;
226 if (is_multicast_ether_addr(skb->data))
227 return RTN_MULTICAST;
228 return RTN_UNSPEC;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100229}
230
231static void qeth_l2_fill_header(struct qeth_card *card, struct qeth_hdr *hdr,
232 struct sk_buff *skb, int ipv, int cast_type)
233{
Frank Blaschka683d7182008-08-01 16:39:13 +0200234 struct vlan_ethhdr *veth = (struct vlan_ethhdr *)skb_mac_header(skb);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100235
236 memset(hdr, 0, sizeof(struct qeth_hdr));
237 hdr->hdr.l2.id = QETH_HEADER_TYPE_LAYER2;
238
239 /* set byte byte 3 to casting flags */
240 if (cast_type == RTN_MULTICAST)
241 hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_MULTICAST;
242 else if (cast_type == RTN_BROADCAST)
243 hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_BROADCAST;
244 else
Klaus-Dieter Wackerce73e102009-08-26 02:01:08 +0000245 hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_UNICAST;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100246
247 hdr->hdr.l2.pkt_length = skb->len-QETH_HEADER_SIZE;
248 /* VSWITCH relies on the VLAN
249 * information to be present in
250 * the QDIO header */
251 if (veth->h_vlan_proto == __constant_htons(ETH_P_8021Q)) {
252 hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_VLAN;
253 hdr->hdr.l2.vlan_id = ntohs(veth->h_vlan_TCI);
254 }
255}
256
257static int qeth_l2_send_setdelvlan_cb(struct qeth_card *card,
258 struct qeth_reply *reply, unsigned long data)
259{
260 struct qeth_ipa_cmd *cmd;
261
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200262 QETH_DBF_TEXT(TRACE, 2, "L2sdvcb");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100263 cmd = (struct qeth_ipa_cmd *) data;
264 if (cmd->hdr.return_code) {
Frank Blaschka14cc21b2008-06-06 12:37:46 +0200265 QETH_DBF_MESSAGE(2, "Error in processing VLAN %i on %s: 0x%x. "
Frank Blaschka4a71df52008-02-15 09:19:42 +0100266 "Continuing\n", cmd->data.setdelvlan.vlan_id,
267 QETH_CARD_IFNAME(card), cmd->hdr.return_code);
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200268 QETH_DBF_TEXT_(TRACE, 2, "L2VL%4x", cmd->hdr.command);
269 QETH_DBF_TEXT_(TRACE, 2, "L2%s", CARD_BUS_ID(card));
270 QETH_DBF_TEXT_(TRACE, 2, "err%d", cmd->hdr.return_code);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100271 }
272 return 0;
273}
274
275static int qeth_l2_send_setdelvlan(struct qeth_card *card, __u16 i,
276 enum qeth_ipa_cmds ipacmd)
277{
278 struct qeth_ipa_cmd *cmd;
279 struct qeth_cmd_buffer *iob;
280
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200281 QETH_DBF_TEXT_(TRACE, 4, "L2sdv%x", ipacmd);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100282 iob = qeth_get_ipacmd_buffer(card, ipacmd, QETH_PROT_IPV4);
283 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
284 cmd->data.setdelvlan.vlan_id = i;
285 return qeth_send_ipa_cmd(card, iob,
286 qeth_l2_send_setdelvlan_cb, NULL);
287}
288
289static void qeth_l2_process_vlans(struct qeth_card *card, int clear)
290{
291 struct qeth_vlan_vid *id;
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200292 QETH_DBF_TEXT(TRACE, 3, "L2prcvln");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100293 spin_lock_bh(&card->vlanlock);
294 list_for_each_entry(id, &card->vid_list, list) {
295 if (clear)
296 qeth_l2_send_setdelvlan(card, id->vid,
297 IPA_CMD_DELVLAN);
298 else
299 qeth_l2_send_setdelvlan(card, id->vid,
300 IPA_CMD_SETVLAN);
301 }
302 spin_unlock_bh(&card->vlanlock);
303}
304
305static void qeth_l2_vlan_rx_add_vid(struct net_device *dev, unsigned short vid)
306{
Heiko Carstens509e2562008-07-26 02:24:10 -0700307 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100308 struct qeth_vlan_vid *id;
309
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200310 QETH_DBF_TEXT_(TRACE, 4, "aid:%d", vid);
Ursula Braun8e98ac42009-03-24 20:57:18 +0000311 if (qeth_wait_for_threads(card, QETH_RECOVER_THREAD)) {
312 QETH_DBF_TEXT(TRACE, 3, "aidREC");
313 return;
314 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100315 id = kmalloc(sizeof(struct qeth_vlan_vid), GFP_ATOMIC);
316 if (id) {
317 id->vid = vid;
318 qeth_l2_send_setdelvlan(card, vid, IPA_CMD_SETVLAN);
319 spin_lock_bh(&card->vlanlock);
320 list_add_tail(&id->list, &card->vid_list);
321 spin_unlock_bh(&card->vlanlock);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100322 }
323}
324
325static void qeth_l2_vlan_rx_kill_vid(struct net_device *dev, unsigned short vid)
326{
327 struct qeth_vlan_vid *id, *tmpid = NULL;
Heiko Carstens509e2562008-07-26 02:24:10 -0700328 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100329
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200330 QETH_DBF_TEXT_(TRACE, 4, "kid:%d", vid);
Ursula Braun8e98ac42009-03-24 20:57:18 +0000331 if (qeth_wait_for_threads(card, QETH_RECOVER_THREAD)) {
332 QETH_DBF_TEXT(TRACE, 3, "kidREC");
333 return;
334 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100335 spin_lock_bh(&card->vlanlock);
336 list_for_each_entry(id, &card->vid_list, list) {
337 if (id->vid == vid) {
338 list_del(&id->list);
339 tmpid = id;
340 break;
341 }
342 }
343 spin_unlock_bh(&card->vlanlock);
344 if (tmpid) {
345 qeth_l2_send_setdelvlan(card, vid, IPA_CMD_DELVLAN);
346 kfree(tmpid);
347 }
348 qeth_l2_set_multicast_list(card->dev);
349}
350
351static int qeth_l2_stop_card(struct qeth_card *card, int recovery_mode)
352{
353 int rc = 0;
354
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200355 QETH_DBF_TEXT(SETUP , 2, "stopcard");
356 QETH_DBF_HEX(SETUP, 2, &card, sizeof(void *));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100357
358 qeth_set_allowed_threads(card, 0, 1);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100359 if (card->read.state == CH_STATE_UP &&
360 card->write.state == CH_STATE_UP &&
361 (card->state == CARD_STATE_UP)) {
362 if (recovery_mode &&
363 card->info.type != QETH_CARD_TYPE_OSN) {
364 qeth_l2_stop(card->dev);
365 } else {
366 rtnl_lock();
367 dev_close(card->dev);
368 rtnl_unlock();
369 }
Klaus-Dieter Wacker932e15832009-03-24 20:57:17 +0000370 if (!card->use_hard_stop ||
371 recovery_mode) {
Frank Blaschka4a71df52008-02-15 09:19:42 +0100372 __u8 *mac = &card->dev->dev_addr[0];
373 rc = qeth_l2_send_delmac(card, mac);
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200374 QETH_DBF_TEXT_(SETUP, 2, "Lerr%d", rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100375 }
376 card->state = CARD_STATE_SOFTSETUP;
377 }
378 if (card->state == CARD_STATE_SOFTSETUP) {
379 qeth_l2_process_vlans(card, 1);
Klaus-Dieter Wacker932e15832009-03-24 20:57:17 +0000380 if (!card->use_hard_stop ||
381 recovery_mode)
Ursula Braun28a7e4c2008-09-19 12:56:03 +0200382 qeth_l2_del_all_mc(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100383 qeth_clear_ipacmd_list(card);
384 card->state = CARD_STATE_HARDSETUP;
385 }
386 if (card->state == CARD_STATE_HARDSETUP) {
387 qeth_qdio_clear_card(card, 0);
388 qeth_clear_qdio_buffers(card);
389 qeth_clear_working_pool_list(card);
390 card->state = CARD_STATE_DOWN;
391 }
392 if (card->state == CARD_STATE_DOWN) {
393 qeth_clear_cmd_buffers(&card->read);
394 qeth_clear_cmd_buffers(&card->write);
395 }
396 card->use_hard_stop = 0;
397 return rc;
398}
399
400static void qeth_l2_process_inbound_buffer(struct qeth_card *card,
401 struct qeth_qdio_buffer *buf, int index)
402{
403 struct qdio_buffer_element *element;
404 struct sk_buff *skb;
405 struct qeth_hdr *hdr;
406 int offset;
407 unsigned int len;
408
409 /* get first element of current buffer */
410 element = (struct qdio_buffer_element *)&buf->buffer->element[0];
411 offset = 0;
412 if (card->options.performance_stats)
413 card->perf_stats.bufs_rec++;
414 while ((skb = qeth_core_get_next_skb(card, buf->buffer, &element,
415 &offset, &hdr))) {
416 skb->dev = card->dev;
417 /* is device UP ? */
418 if (!(card->dev->flags & IFF_UP)) {
419 dev_kfree_skb_any(skb);
420 continue;
421 }
422
423 switch (hdr->hdr.l2.id) {
424 case QETH_HEADER_TYPE_LAYER2:
425 skb->pkt_type = PACKET_HOST;
426 skb->protocol = eth_type_trans(skb, skb->dev);
427 if (card->options.checksum_type == NO_CHECKSUMMING)
428 skb->ip_summed = CHECKSUM_UNNECESSARY;
429 else
430 skb->ip_summed = CHECKSUM_NONE;
Ursula Braun12883722008-04-01 10:26:56 +0200431 if (skb->protocol == htons(ETH_P_802_2))
432 *((__u32 *)skb->cb) = ++card->seqno.pkt_seqno;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100433 len = skb->len;
434 netif_rx(skb);
435 break;
436 case QETH_HEADER_TYPE_OSN:
Ursula Braun2d488c22008-10-24 11:16:55 +0200437 if (card->info.type == QETH_CARD_TYPE_OSN) {
438 skb_push(skb, sizeof(struct qeth_hdr));
439 skb_copy_to_linear_data(skb, hdr,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100440 sizeof(struct qeth_hdr));
Ursula Braun2d488c22008-10-24 11:16:55 +0200441 len = skb->len;
442 card->osn_info.data_cb(skb);
443 break;
444 }
445 /* else unknown */
Frank Blaschka4a71df52008-02-15 09:19:42 +0100446 default:
447 dev_kfree_skb_any(skb);
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200448 QETH_DBF_TEXT(TRACE, 3, "inbunkno");
449 QETH_DBF_HEX(CTRL, 3, hdr, QETH_DBF_CTRL_LEN);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100450 continue;
451 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100452 card->stats.rx_packets++;
453 card->stats.rx_bytes += len;
454 }
455}
456
457static int qeth_l2_send_setdelmac(struct qeth_card *card, __u8 *mac,
458 enum qeth_ipa_cmds ipacmd,
459 int (*reply_cb) (struct qeth_card *,
460 struct qeth_reply*,
461 unsigned long))
462{
463 struct qeth_ipa_cmd *cmd;
464 struct qeth_cmd_buffer *iob;
465
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200466 QETH_DBF_TEXT(TRACE, 2, "L2sdmac");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100467 iob = qeth_get_ipacmd_buffer(card, ipacmd, QETH_PROT_IPV4);
468 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
469 cmd->data.setdelmac.mac_length = OSA_ADDR_LEN;
470 memcpy(&cmd->data.setdelmac.mac, mac, OSA_ADDR_LEN);
471 return qeth_send_ipa_cmd(card, iob, reply_cb, NULL);
472}
473
474static int qeth_l2_send_setmac_cb(struct qeth_card *card,
475 struct qeth_reply *reply,
476 unsigned long data)
477{
478 struct qeth_ipa_cmd *cmd;
479
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200480 QETH_DBF_TEXT(TRACE, 2, "L2Smaccb");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100481 cmd = (struct qeth_ipa_cmd *) data;
482 if (cmd->hdr.return_code) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200483 QETH_DBF_TEXT_(TRACE, 2, "L2er%x", cmd->hdr.return_code);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100484 card->info.mac_bits &= ~QETH_LAYER2_MAC_REGISTERED;
Ursula Braun0666eb062009-05-19 21:38:39 +0000485 switch (cmd->hdr.return_code) {
486 case IPA_RC_L2_DUP_MAC:
487 case IPA_RC_L2_DUP_LAYER3_MAC:
488 dev_warn(&card->gdev->dev,
H Hartley Sweetend998ab02009-12-29 20:05:37 -0800489 "MAC address %pM already exists\n",
490 card->dev->dev_addr);
Ursula Braun0666eb062009-05-19 21:38:39 +0000491 break;
492 case IPA_RC_L2_MAC_NOT_AUTH_BY_HYP:
493 case IPA_RC_L2_MAC_NOT_AUTH_BY_ADP:
494 dev_warn(&card->gdev->dev,
H Hartley Sweetend998ab02009-12-29 20:05:37 -0800495 "MAC address %pM is not authorized\n",
496 card->dev->dev_addr);
Ursula Braun0666eb062009-05-19 21:38:39 +0000497 break;
498 default:
499 break;
500 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100501 cmd->hdr.return_code = -EIO;
502 } else {
503 card->info.mac_bits |= QETH_LAYER2_MAC_REGISTERED;
504 memcpy(card->dev->dev_addr, cmd->data.setdelmac.mac,
505 OSA_ADDR_LEN);
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100506 dev_info(&card->gdev->dev,
H Hartley Sweetend998ab02009-12-29 20:05:37 -0800507 "MAC address %pM successfully registered on device %s\n",
508 card->dev->dev_addr, card->dev->name);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100509 }
510 return 0;
511}
512
513static int qeth_l2_send_setmac(struct qeth_card *card, __u8 *mac)
514{
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200515 QETH_DBF_TEXT(TRACE, 2, "L2Setmac");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100516 return qeth_l2_send_setdelmac(card, mac, IPA_CMD_SETVMAC,
517 qeth_l2_send_setmac_cb);
518}
519
520static int qeth_l2_send_delmac_cb(struct qeth_card *card,
521 struct qeth_reply *reply,
522 unsigned long data)
523{
524 struct qeth_ipa_cmd *cmd;
525
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200526 QETH_DBF_TEXT(TRACE, 2, "L2Dmaccb");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100527 cmd = (struct qeth_ipa_cmd *) data;
528 if (cmd->hdr.return_code) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200529 QETH_DBF_TEXT_(TRACE, 2, "err%d", cmd->hdr.return_code);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100530 cmd->hdr.return_code = -EIO;
531 return 0;
532 }
533 card->info.mac_bits &= ~QETH_LAYER2_MAC_REGISTERED;
534
535 return 0;
536}
537
538static int qeth_l2_send_delmac(struct qeth_card *card, __u8 *mac)
539{
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200540 QETH_DBF_TEXT(TRACE, 2, "L2Delmac");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100541 if (!(card->info.mac_bits & QETH_LAYER2_MAC_REGISTERED))
542 return 0;
543 return qeth_l2_send_setdelmac(card, mac, IPA_CMD_DELVMAC,
544 qeth_l2_send_delmac_cb);
545}
546
547static int qeth_l2_request_initial_mac(struct qeth_card *card)
548{
549 int rc = 0;
550 char vendor_pre[] = {0x02, 0x00, 0x00};
551
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200552 QETH_DBF_TEXT(SETUP, 2, "doL2init");
553 QETH_DBF_TEXT_(SETUP, 2, "doL2%s", CARD_BUS_ID(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100554
555 rc = qeth_query_setadapterparms(card);
556 if (rc) {
Frank Blaschka14cc21b2008-06-06 12:37:46 +0200557 QETH_DBF_MESSAGE(2, "could not query adapter parameters on "
558 "device %s: x%x\n", CARD_BUS_ID(card), rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100559 }
560
Ursula Braunf1d58672008-09-19 12:56:02 +0200561 if ((card->info.type == QETH_CARD_TYPE_IQD) ||
562 (card->info.guestlan)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +0100563 rc = qeth_setadpparms_change_macaddr(card);
564 if (rc) {
Frank Blaschka14cc21b2008-06-06 12:37:46 +0200565 QETH_DBF_MESSAGE(2, "couldn't get MAC address on "
566 "device %s: x%x\n", CARD_BUS_ID(card), rc);
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200567 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100568 return rc;
569 }
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200570 QETH_DBF_HEX(SETUP, 2, card->dev->dev_addr, OSA_ADDR_LEN);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100571 } else {
572 random_ether_addr(card->dev->dev_addr);
573 memcpy(card->dev->dev_addr, vendor_pre, 3);
574 }
575 return 0;
576}
577
578static int qeth_l2_set_mac_address(struct net_device *dev, void *p)
579{
580 struct sockaddr *addr = p;
Heiko Carstens509e2562008-07-26 02:24:10 -0700581 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100582 int rc = 0;
583
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200584 QETH_DBF_TEXT(TRACE, 3, "setmac");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100585
586 if (qeth_l2_verify_dev(dev) != QETH_REAL_CARD) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200587 QETH_DBF_TEXT(TRACE, 3, "setmcINV");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100588 return -EOPNOTSUPP;
589 }
590
591 if (card->info.type == QETH_CARD_TYPE_OSN) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200592 QETH_DBF_TEXT(TRACE, 3, "setmcOSN");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100593 return -EOPNOTSUPP;
594 }
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200595 QETH_DBF_TEXT_(TRACE, 3, "%s", CARD_BUS_ID(card));
596 QETH_DBF_HEX(TRACE, 3, addr->sa_data, OSA_ADDR_LEN);
Ursula Braun8e98ac42009-03-24 20:57:18 +0000597 if (qeth_wait_for_threads(card, QETH_RECOVER_THREAD)) {
598 QETH_DBF_TEXT(TRACE, 3, "setmcREC");
599 return -ERESTARTSYS;
600 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100601 rc = qeth_l2_send_delmac(card, &card->dev->dev_addr[0]);
602 if (!rc)
603 rc = qeth_l2_send_setmac(card, addr->sa_data);
604 return rc;
605}
606
607static void qeth_l2_set_multicast_list(struct net_device *dev)
608{
Heiko Carstens509e2562008-07-26 02:24:10 -0700609 struct qeth_card *card = dev->ml_priv;
Jiri Pirkoccffad252009-05-22 23:22:17 +0000610 struct netdev_hw_addr *ha;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100611
612 if (card->info.type == QETH_CARD_TYPE_OSN)
613 return ;
614
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200615 QETH_DBF_TEXT(TRACE, 3, "setmulti");
Ursula Braun8e98ac42009-03-24 20:57:18 +0000616 if (qeth_threads_running(card, QETH_RECOVER_THREAD) &&
617 (card->state != CARD_STATE_UP))
618 return;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100619 qeth_l2_del_all_mc(card);
620 spin_lock_bh(&card->mclock);
Jiri Pirko22bedad32010-04-01 21:22:57 +0000621 netdev_for_each_mc_addr(ha, dev)
622 qeth_l2_add_mc(card, ha->addr, 0);
Frank Blaschka7db22662008-08-15 08:02:59 +0200623
Jiri Pirko32e7bfc2010-01-25 13:36:10 -0800624 netdev_for_each_uc_addr(ha, dev)
Jiri Pirkoccffad252009-05-22 23:22:17 +0000625 qeth_l2_add_mc(card, ha->addr, 1);
Frank Blaschka7db22662008-08-15 08:02:59 +0200626
Frank Blaschka4a71df52008-02-15 09:19:42 +0100627 spin_unlock_bh(&card->mclock);
628 if (!qeth_adp_supported(card, IPA_SETADP_SET_PROMISC_MODE))
629 return;
630 qeth_setadp_promisc_mode(card);
631}
632
633static int qeth_l2_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
634{
635 int rc;
636 struct qeth_hdr *hdr = NULL;
637 int elements = 0;
Heiko Carstens509e2562008-07-26 02:24:10 -0700638 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100639 struct sk_buff *new_skb = skb;
640 int ipv = qeth_get_ip_version(skb);
Klaus-Dieter Wackerce73e102009-08-26 02:01:08 +0000641 int cast_type = qeth_l2_get_cast_type(card, skb);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100642 struct qeth_qdio_out_q *queue = card->qdio.out_qs
643 [qeth_get_priority_queue(card, skb, ipv, cast_type)];
644 int tx_bytes = skb->len;
Frank Blaschka683d7182008-08-01 16:39:13 +0200645 int data_offset = -1;
646 int elements_needed = 0;
647 int hd_len = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100648
Frank Blaschka4a71df52008-02-15 09:19:42 +0100649 if ((card->state != CARD_STATE_UP) || !card->lan_online) {
650 card->stats.tx_carrier_errors++;
651 goto tx_drop;
652 }
653
654 if ((card->info.type == QETH_CARD_TYPE_OSN) &&
655 (skb->protocol == htons(ETH_P_IPV6)))
656 goto tx_drop;
657
658 if (card->options.performance_stats) {
659 card->perf_stats.outbound_cnt++;
660 card->perf_stats.outbound_start_time = qeth_get_micros();
661 }
662 netif_stop_queue(dev);
663
Frank Blaschka4a71df52008-02-15 09:19:42 +0100664 if (card->info.type == QETH_CARD_TYPE_OSN)
665 hdr = (struct qeth_hdr *)skb->data;
666 else {
Frank Blaschka64ef8952009-03-24 20:57:16 +0000667 if (card->info.type == QETH_CARD_TYPE_IQD) {
Frank Blaschka683d7182008-08-01 16:39:13 +0200668 new_skb = skb;
669 data_offset = ETH_HLEN;
670 hd_len = ETH_HLEN;
671 hdr = kmem_cache_alloc(qeth_core_header_cache,
672 GFP_ATOMIC);
673 if (!hdr)
674 goto tx_drop;
675 elements_needed++;
676 skb_reset_mac_header(new_skb);
677 qeth_l2_fill_header(card, hdr, new_skb, ipv, cast_type);
678 hdr->hdr.l2.pkt_length = new_skb->len;
679 memcpy(((char *)hdr) + sizeof(struct qeth_hdr),
680 skb_mac_header(new_skb), ETH_HLEN);
681 } else {
682 /* create a clone with writeable headroom */
683 new_skb = skb_realloc_headroom(skb,
Frank Blaschkaf90b7442008-04-24 10:15:24 +0200684 sizeof(struct qeth_hdr));
Frank Blaschka683d7182008-08-01 16:39:13 +0200685 if (!new_skb)
686 goto tx_drop;
687 hdr = (struct qeth_hdr *)skb_push(new_skb,
688 sizeof(struct qeth_hdr));
689 skb_set_mac_header(new_skb, sizeof(struct qeth_hdr));
690 qeth_l2_fill_header(card, hdr, new_skb, ipv, cast_type);
691 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100692 }
693
Frank Blaschka64ef8952009-03-24 20:57:16 +0000694 elements = qeth_get_elements_no(card, (void *)hdr, new_skb,
Frank Blaschka683d7182008-08-01 16:39:13 +0200695 elements_needed);
Frank Blaschka64ef8952009-03-24 20:57:16 +0000696 if (!elements) {
697 if (data_offset >= 0)
698 kmem_cache_free(qeth_core_header_cache, hdr);
699 goto tx_drop;
Frank Blaschkaf61a0d02009-03-24 20:57:15 +0000700 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100701
702 if (card->info.type != QETH_CARD_TYPE_IQD)
703 rc = qeth_do_send_packet(card, queue, new_skb, hdr,
Frank Blaschka64ef8952009-03-24 20:57:16 +0000704 elements);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100705 else
706 rc = qeth_do_send_packet_fast(card, queue, new_skb, hdr,
Frank Blaschka64ef8952009-03-24 20:57:16 +0000707 elements, data_offset, hd_len);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100708 if (!rc) {
709 card->stats.tx_packets++;
710 card->stats.tx_bytes += tx_bytes;
711 if (new_skb != skb)
712 dev_kfree_skb_any(skb);
Patrick McHardyec634fe2009-07-05 19:23:38 -0700713 rc = NETDEV_TX_OK;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100714 } else {
Frank Blaschka683d7182008-08-01 16:39:13 +0200715 if (data_offset >= 0)
716 kmem_cache_free(qeth_core_header_cache, hdr);
717
Frank Blaschka4a71df52008-02-15 09:19:42 +0100718 if (rc == -EBUSY) {
719 if (new_skb != skb)
720 dev_kfree_skb_any(new_skb);
721 return NETDEV_TX_BUSY;
722 } else
723 goto tx_drop;
724 }
725
726 netif_wake_queue(dev);
727 if (card->options.performance_stats)
728 card->perf_stats.outbound_time += qeth_get_micros() -
729 card->perf_stats.outbound_start_time;
730 return rc;
731
732tx_drop:
733 card->stats.tx_dropped++;
734 card->stats.tx_errors++;
735 if ((new_skb != skb) && new_skb)
736 dev_kfree_skb_any(new_skb);
737 dev_kfree_skb_any(skb);
Frank Blaschkad0ec0f52008-06-06 12:37:48 +0200738 netif_wake_queue(dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100739 return NETDEV_TX_OK;
740}
741
742static void qeth_l2_qdio_input_handler(struct ccw_device *ccwdev,
Jan Glauber779e6e12008-07-17 17:16:48 +0200743 unsigned int qdio_err, unsigned int queue,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100744 int first_element, int count, unsigned long card_ptr)
745{
746 struct net_device *net_dev;
747 struct qeth_card *card;
748 struct qeth_qdio_buffer *buffer;
749 int index;
750 int i;
751
Frank Blaschka4a71df52008-02-15 09:19:42 +0100752 card = (struct qeth_card *) card_ptr;
753 net_dev = card->dev;
754 if (card->options.performance_stats) {
755 card->perf_stats.inbound_cnt++;
756 card->perf_stats.inbound_start_time = qeth_get_micros();
757 }
Jan Glauber779e6e12008-07-17 17:16:48 +0200758 if (qdio_err & QDIO_ERROR_ACTIVATE_CHECK_CONDITION) {
759 QETH_DBF_TEXT(TRACE, 1, "qdinchk");
760 QETH_DBF_TEXT_(TRACE, 1, "%s", CARD_BUS_ID(card));
761 QETH_DBF_TEXT_(TRACE, 1, "%04X%04X", first_element,
762 count);
763 QETH_DBF_TEXT_(TRACE, 1, "%04X", queue);
764 qeth_schedule_recovery(card);
765 return;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100766 }
767 for (i = first_element; i < (first_element + count); ++i) {
768 index = i % QDIO_MAX_BUFFERS_PER_Q;
769 buffer = &card->qdio.in_q->bufs[index];
Jan Glauber779e6e12008-07-17 17:16:48 +0200770 if (!(qdio_err &&
Ursula Braun76b11f82010-01-11 02:50:50 +0000771 qeth_check_qdio_errors(card, buffer->buffer, qdio_err,
772 "qinerr")))
Frank Blaschka4a71df52008-02-15 09:19:42 +0100773 qeth_l2_process_inbound_buffer(card, buffer, index);
774 /* clear buffer and give back to hardware */
775 qeth_put_buffer_pool_entry(card, buffer->pool_entry);
776 qeth_queue_input_buffer(card, index);
777 }
778 if (card->options.performance_stats)
779 card->perf_stats.inbound_time += qeth_get_micros() -
780 card->perf_stats.inbound_start_time;
781}
782
783static int qeth_l2_open(struct net_device *dev)
784{
Heiko Carstens509e2562008-07-26 02:24:10 -0700785 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100786
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200787 QETH_DBF_TEXT(TRACE, 4, "qethopen");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100788 if (card->state != CARD_STATE_SOFTSETUP)
789 return -ENODEV;
790
791 if ((card->info.type != QETH_CARD_TYPE_OSN) &&
792 (!(card->info.mac_bits & QETH_LAYER2_MAC_REGISTERED))) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200793 QETH_DBF_TEXT(TRACE, 4, "nomacadr");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100794 return -EPERM;
795 }
796 card->data.state = CH_STATE_UP;
797 card->state = CARD_STATE_UP;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100798 netif_start_queue(dev);
799
800 if (!card->lan_online && netif_carrier_ok(dev))
801 netif_carrier_off(dev);
802 return 0;
803}
804
805
806static int qeth_l2_stop(struct net_device *dev)
807{
Heiko Carstens509e2562008-07-26 02:24:10 -0700808 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100809
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200810 QETH_DBF_TEXT(TRACE, 4, "qethstop");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100811 netif_tx_disable(dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100812 if (card->state == CARD_STATE_UP)
813 card->state = CARD_STATE_SOFTSETUP;
814 return 0;
815}
816
817static int qeth_l2_probe_device(struct ccwgroup_device *gdev)
818{
819 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
820
821 INIT_LIST_HEAD(&card->vid_list);
822 INIT_LIST_HEAD(&card->mc_list);
823 card->options.layer2 = 1;
824 card->discipline.input_handler = (qdio_handler_t *)
825 qeth_l2_qdio_input_handler;
826 card->discipline.output_handler = (qdio_handler_t *)
827 qeth_qdio_output_handler;
828 card->discipline.recover = qeth_l2_recover;
829 return 0;
830}
831
832static void qeth_l2_remove_device(struct ccwgroup_device *cgdev)
833{
834 struct qeth_card *card = dev_get_drvdata(&cgdev->dev);
835
Ursula Braunf2148562009-05-19 21:38:37 +0000836 qeth_set_allowed_threads(card, 0, 1);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100837 wait_event(card->wait_q, qeth_threads_running(card, 0xffffffff) == 0);
838
839 if (cgdev->state == CCWGROUP_ONLINE) {
840 card->use_hard_stop = 1;
841 qeth_l2_set_offline(cgdev);
842 }
843
844 if (card->dev) {
845 unregister_netdev(card->dev);
846 card->dev = NULL;
847 }
848
849 qeth_l2_del_all_mc(card);
850 return;
851}
852
Stephen Hemminger0fc0b732009-09-02 01:03:33 -0700853static const struct ethtool_ops qeth_l2_ethtool_ops = {
Frank Blaschka4a71df52008-02-15 09:19:42 +0100854 .get_link = ethtool_op_get_link,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100855 .get_strings = qeth_core_get_strings,
856 .get_ethtool_stats = qeth_core_get_ethtool_stats,
Ben Hutchingsdf8b4ec2009-10-01 11:24:32 +0000857 .get_sset_count = qeth_core_get_sset_count,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100858 .get_drvinfo = qeth_core_get_drvinfo,
Frank Blaschka3f9975a2008-04-24 10:15:23 +0200859 .get_settings = qeth_core_ethtool_get_settings,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100860};
861
Stephen Hemminger0fc0b732009-09-02 01:03:33 -0700862static const struct ethtool_ops qeth_l2_osn_ops = {
Frank Blaschka4a71df52008-02-15 09:19:42 +0100863 .get_strings = qeth_core_get_strings,
864 .get_ethtool_stats = qeth_core_get_ethtool_stats,
Ben Hutchingsdf8b4ec2009-10-01 11:24:32 +0000865 .get_sset_count = qeth_core_get_sset_count,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100866 .get_drvinfo = qeth_core_get_drvinfo,
867};
868
Frank Blaschka3d58cef2009-01-09 03:44:00 +0000869static const struct net_device_ops qeth_l2_netdev_ops = {
Frank Blaschka8403b132009-01-08 10:50:55 -0800870 .ndo_open = qeth_l2_open,
871 .ndo_stop = qeth_l2_stop,
872 .ndo_get_stats = qeth_get_stats,
873 .ndo_start_xmit = qeth_l2_hard_start_xmit,
874 .ndo_validate_addr = eth_validate_addr,
875 .ndo_set_multicast_list = qeth_l2_set_multicast_list,
876 .ndo_do_ioctl = qeth_l2_do_ioctl,
877 .ndo_set_mac_address = qeth_l2_set_mac_address,
878 .ndo_change_mtu = qeth_change_mtu,
879 .ndo_vlan_rx_add_vid = qeth_l2_vlan_rx_add_vid,
880 .ndo_vlan_rx_kill_vid = qeth_l2_vlan_rx_kill_vid,
881 .ndo_tx_timeout = qeth_tx_timeout,
882};
883
Frank Blaschka4a71df52008-02-15 09:19:42 +0100884static int qeth_l2_setup_netdev(struct qeth_card *card)
885{
886 switch (card->info.type) {
887 case QETH_CARD_TYPE_OSAE:
888 card->dev = alloc_etherdev(0);
889 break;
890 case QETH_CARD_TYPE_IQD:
891 card->dev = alloc_netdev(0, "hsi%d", ether_setup);
892 break;
893 case QETH_CARD_TYPE_OSN:
894 card->dev = alloc_netdev(0, "osn%d", ether_setup);
895 card->dev->flags |= IFF_NOARP;
896 break;
897 default:
898 card->dev = alloc_etherdev(0);
899 }
900
901 if (!card->dev)
902 return -ENODEV;
903
Heiko Carstens509e2562008-07-26 02:24:10 -0700904 card->dev->ml_priv = card;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100905 card->dev->watchdog_timeo = QETH_TX_TIMEOUT;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100906 card->dev->mtu = card->info.initial_mtu;
Frank Blaschka8403b132009-01-08 10:50:55 -0800907 card->dev->netdev_ops = &qeth_l2_netdev_ops;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100908 if (card->info.type != QETH_CARD_TYPE_OSN)
909 SET_ETHTOOL_OPS(card->dev, &qeth_l2_ethtool_ops);
910 else
911 SET_ETHTOOL_OPS(card->dev, &qeth_l2_osn_ops);
912 card->dev->features |= NETIF_F_HW_VLAN_FILTER;
913 card->info.broadcast_capable = 1;
914 qeth_l2_request_initial_mac(card);
915 SET_NETDEV_DEV(card->dev, &card->gdev->dev);
916 return register_netdev(card->dev);
917}
918
919static int __qeth_l2_set_online(struct ccwgroup_device *gdev, int recovery_mode)
920{
921 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
922 int rc = 0;
923 enum qeth_card_states recover_flag;
924
925 BUG_ON(!card);
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200926 QETH_DBF_TEXT(SETUP, 2, "setonlin");
927 QETH_DBF_HEX(SETUP, 2, &card, sizeof(void *));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100928
Frank Blaschka4a71df52008-02-15 09:19:42 +0100929 recover_flag = card->state;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100930 rc = qeth_core_hardsetup_card(card);
931 if (rc) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200932 QETH_DBF_TEXT_(SETUP, 2, "2err%d", rc);
Ursula Braunaa909222009-11-12 00:11:43 +0000933 rc = -ENODEV;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100934 goto out_remove;
935 }
936
Ursula Braunaa909222009-11-12 00:11:43 +0000937 if (!card->dev && qeth_l2_setup_netdev(card)) {
938 rc = -ENODEV;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100939 goto out_remove;
Ursula Braunaa909222009-11-12 00:11:43 +0000940 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100941
942 if (card->info.type != QETH_CARD_TYPE_OSN)
943 qeth_l2_send_setmac(card, &card->dev->dev_addr[0]);
944
945 card->state = CARD_STATE_HARDSETUP;
946 qeth_print_status_message(card);
947
948 /* softsetup */
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200949 QETH_DBF_TEXT(SETUP, 2, "softsetp");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100950
951 rc = qeth_send_startlan(card);
952 if (rc) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200953 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100954 if (rc == 0xe080) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100955 dev_warn(&card->gdev->dev,
956 "The LAN is offline\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100957 card->lan_online = 0;
Ursula Braunf2148562009-05-19 21:38:37 +0000958 return 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100959 }
Ursula Braunaa909222009-11-12 00:11:43 +0000960 rc = -ENODEV;
Ursula Braunf2148562009-05-19 21:38:37 +0000961 goto out_remove;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100962 } else
963 card->lan_online = 1;
964
965 if (card->info.type != QETH_CARD_TYPE_OSN) {
Einar Lueckd64ecc22009-11-12 00:11:41 +0000966 /* configure isolation level */
967 qeth_set_access_ctrl_online(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100968 qeth_l2_process_vlans(card, 0);
969 }
970
971 netif_tx_disable(card->dev);
972
973 rc = qeth_init_qdio_queues(card);
974 if (rc) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200975 QETH_DBF_TEXT_(SETUP, 2, "6err%d", rc);
Ursula Braunaa909222009-11-12 00:11:43 +0000976 rc = -ENODEV;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100977 goto out_remove;
978 }
979 card->state = CARD_STATE_SOFTSETUP;
980 netif_carrier_on(card->dev);
981
982 qeth_set_allowed_threads(card, 0xffffffff, 0);
983 if (recover_flag == CARD_STATE_RECOVER) {
984 if (recovery_mode &&
985 card->info.type != QETH_CARD_TYPE_OSN) {
986 qeth_l2_open(card->dev);
987 } else {
988 rtnl_lock();
989 dev_open(card->dev);
990 rtnl_unlock();
991 }
992 /* this also sets saved unicast addresses */
993 qeth_l2_set_multicast_list(card->dev);
994 }
995 /* let user_space know that device is online */
996 kobject_uevent(&gdev->dev.kobj, KOBJ_CHANGE);
997 return 0;
Ursula Braunaa909222009-11-12 00:11:43 +0000998
Frank Blaschka4a71df52008-02-15 09:19:42 +0100999out_remove:
1000 card->use_hard_stop = 1;
1001 qeth_l2_stop_card(card, 0);
1002 ccw_device_set_offline(CARD_DDEV(card));
1003 ccw_device_set_offline(CARD_WDEV(card));
1004 ccw_device_set_offline(CARD_RDEV(card));
1005 if (recover_flag == CARD_STATE_RECOVER)
1006 card->state = CARD_STATE_RECOVER;
1007 else
1008 card->state = CARD_STATE_DOWN;
Ursula Braunaa909222009-11-12 00:11:43 +00001009 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001010}
1011
1012static int qeth_l2_set_online(struct ccwgroup_device *gdev)
1013{
1014 return __qeth_l2_set_online(gdev, 0);
1015}
1016
1017static int __qeth_l2_set_offline(struct ccwgroup_device *cgdev,
1018 int recovery_mode)
1019{
1020 struct qeth_card *card = dev_get_drvdata(&cgdev->dev);
1021 int rc = 0, rc2 = 0, rc3 = 0;
1022 enum qeth_card_states recover_flag;
1023
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001024 QETH_DBF_TEXT(SETUP, 3, "setoffl");
1025 QETH_DBF_HEX(SETUP, 3, &card, sizeof(void *));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001026
1027 if (card->dev && netif_carrier_ok(card->dev))
1028 netif_carrier_off(card->dev);
1029 recover_flag = card->state;
Ursula Braun0f5623c2008-10-24 11:16:52 +02001030 qeth_l2_stop_card(card, recovery_mode);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001031 rc = ccw_device_set_offline(CARD_DDEV(card));
1032 rc2 = ccw_device_set_offline(CARD_WDEV(card));
1033 rc3 = ccw_device_set_offline(CARD_RDEV(card));
1034 if (!rc)
1035 rc = (rc2) ? rc2 : rc3;
1036 if (rc)
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001037 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001038 if (recover_flag == CARD_STATE_UP)
1039 card->state = CARD_STATE_RECOVER;
1040 /* let user_space know that device is offline */
1041 kobject_uevent(&cgdev->dev.kobj, KOBJ_CHANGE);
1042 return 0;
1043}
1044
1045static int qeth_l2_set_offline(struct ccwgroup_device *cgdev)
1046{
1047 return __qeth_l2_set_offline(cgdev, 0);
1048}
1049
1050static int qeth_l2_recover(void *ptr)
1051{
1052 struct qeth_card *card;
1053 int rc = 0;
1054
1055 card = (struct qeth_card *) ptr;
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001056 QETH_DBF_TEXT(TRACE, 2, "recover1");
1057 QETH_DBF_HEX(TRACE, 2, &card, sizeof(void *));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001058 if (!qeth_do_run_thread(card, QETH_RECOVER_THREAD))
1059 return 0;
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001060 QETH_DBF_TEXT(TRACE, 2, "recover2");
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001061 dev_warn(&card->gdev->dev,
1062 "A recovery process has been started for the device\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001063 card->use_hard_stop = 1;
1064 __qeth_l2_set_offline(card->gdev, 1);
1065 rc = __qeth_l2_set_online(card->gdev, 1);
1066 /* don't run another scheduled recovery */
1067 qeth_clear_thread_start_bit(card, QETH_RECOVER_THREAD);
1068 qeth_clear_thread_running_bit(card, QETH_RECOVER_THREAD);
1069 if (!rc)
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001070 dev_info(&card->gdev->dev,
1071 "Device successfully recovered!\n");
Ursula Braun28a7e4c2008-09-19 12:56:03 +02001072 else {
Ursula Braun869da902010-03-08 20:36:56 +00001073 rtnl_lock();
1074 dev_close(card->dev);
1075 rtnl_unlock();
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001076 dev_warn(&card->gdev->dev, "The qeth device driver "
1077 "failed to recover an error on the device\n");
Ursula Braun28a7e4c2008-09-19 12:56:03 +02001078 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01001079 return 0;
1080}
1081
1082static int __init qeth_l2_init(void)
1083{
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001084 pr_info("register layer 2 discipline\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001085 return 0;
1086}
1087
1088static void __exit qeth_l2_exit(void)
1089{
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001090 pr_info("unregister layer 2 discipline\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001091}
1092
1093static void qeth_l2_shutdown(struct ccwgroup_device *gdev)
1094{
1095 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
1096 qeth_qdio_clear_card(card, 0);
1097 qeth_clear_qdio_buffers(card);
1098}
1099
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02001100static int qeth_l2_pm_suspend(struct ccwgroup_device *gdev)
1101{
1102 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
1103
1104 if (card->dev)
1105 netif_device_detach(card->dev);
1106 qeth_set_allowed_threads(card, 0, 1);
1107 wait_event(card->wait_q, qeth_threads_running(card, 0xffffffff) == 0);
1108 if (gdev->state == CCWGROUP_OFFLINE)
1109 return 0;
1110 if (card->state == CARD_STATE_UP) {
1111 card->use_hard_stop = 1;
1112 __qeth_l2_set_offline(card->gdev, 1);
1113 } else
1114 __qeth_l2_set_offline(card->gdev, 0);
1115 return 0;
1116}
1117
1118static int qeth_l2_pm_resume(struct ccwgroup_device *gdev)
1119{
1120 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
1121 int rc = 0;
1122
1123 if (gdev->state == CCWGROUP_OFFLINE)
1124 goto out;
1125
1126 if (card->state == CARD_STATE_RECOVER) {
1127 rc = __qeth_l2_set_online(card->gdev, 1);
1128 if (rc) {
Ursula Braun869da902010-03-08 20:36:56 +00001129 rtnl_lock();
1130 dev_close(card->dev);
1131 rtnl_unlock();
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02001132 }
1133 } else
1134 rc = __qeth_l2_set_online(card->gdev, 0);
1135out:
1136 qeth_set_allowed_threads(card, 0xffffffff, 0);
1137 if (card->dev)
1138 netif_device_attach(card->dev);
1139 if (rc)
1140 dev_warn(&card->gdev->dev, "The qeth device driver "
1141 "failed to recover an error on the device\n");
1142 return rc;
1143}
1144
Frank Blaschka4a71df52008-02-15 09:19:42 +01001145struct ccwgroup_driver qeth_l2_ccwgroup_driver = {
1146 .probe = qeth_l2_probe_device,
1147 .remove = qeth_l2_remove_device,
1148 .set_online = qeth_l2_set_online,
1149 .set_offline = qeth_l2_set_offline,
1150 .shutdown = qeth_l2_shutdown,
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02001151 .freeze = qeth_l2_pm_suspend,
1152 .thaw = qeth_l2_pm_resume,
1153 .restore = qeth_l2_pm_resume,
Frank Blaschka4a71df52008-02-15 09:19:42 +01001154};
1155EXPORT_SYMBOL_GPL(qeth_l2_ccwgroup_driver);
1156
1157static int qeth_osn_send_control_data(struct qeth_card *card, int len,
1158 struct qeth_cmd_buffer *iob)
1159{
1160 unsigned long flags;
1161 int rc = 0;
1162
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001163 QETH_DBF_TEXT(TRACE, 5, "osndctrd");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001164
1165 wait_event(card->wait_q,
1166 atomic_cmpxchg(&card->write.irq_pending, 0, 1) == 0);
1167 qeth_prepare_control_data(card, len, iob);
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001168 QETH_DBF_TEXT(TRACE, 6, "osnoirqp");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001169 spin_lock_irqsave(get_ccwdev_lock(card->write.ccwdev), flags);
1170 rc = ccw_device_start(card->write.ccwdev, &card->write.ccw,
1171 (addr_t) iob, 0, 0);
1172 spin_unlock_irqrestore(get_ccwdev_lock(card->write.ccwdev), flags);
1173 if (rc) {
Frank Blaschka14cc21b2008-06-06 12:37:46 +02001174 QETH_DBF_MESSAGE(2, "qeth_osn_send_control_data: "
Frank Blaschka4a71df52008-02-15 09:19:42 +01001175 "ccw_device_start rc = %i\n", rc);
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001176 QETH_DBF_TEXT_(TRACE, 2, " err%d", rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001177 qeth_release_buffer(iob->channel, iob);
1178 atomic_set(&card->write.irq_pending, 0);
1179 wake_up(&card->wait_q);
1180 }
1181 return rc;
1182}
1183
1184static int qeth_osn_send_ipa_cmd(struct qeth_card *card,
1185 struct qeth_cmd_buffer *iob, int data_len)
1186{
1187 u16 s1, s2;
1188
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001189 QETH_DBF_TEXT(TRACE, 4, "osndipa");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001190
1191 qeth_prepare_ipa_cmd(card, iob, QETH_PROT_OSN2);
1192 s1 = (u16)(IPA_PDU_HEADER_SIZE + data_len);
1193 s2 = (u16)data_len;
1194 memcpy(QETH_IPA_PDU_LEN_TOTAL(iob->data), &s1, 2);
1195 memcpy(QETH_IPA_PDU_LEN_PDU1(iob->data), &s2, 2);
1196 memcpy(QETH_IPA_PDU_LEN_PDU2(iob->data), &s2, 2);
1197 memcpy(QETH_IPA_PDU_LEN_PDU3(iob->data), &s2, 2);
1198 return qeth_osn_send_control_data(card, s1, iob);
1199}
1200
1201int qeth_osn_assist(struct net_device *dev, void *data, int data_len)
1202{
1203 struct qeth_cmd_buffer *iob;
1204 struct qeth_card *card;
1205 int rc;
1206
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001207 QETH_DBF_TEXT(TRACE, 2, "osnsdmc");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001208 if (!dev)
1209 return -ENODEV;
Heiko Carstens509e2562008-07-26 02:24:10 -07001210 card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001211 if (!card)
1212 return -ENODEV;
1213 if ((card->state != CARD_STATE_UP) &&
1214 (card->state != CARD_STATE_SOFTSETUP))
1215 return -ENODEV;
1216 iob = qeth_wait_for_buffer(&card->write);
1217 memcpy(iob->data+IPA_PDU_HEADER_SIZE, data, data_len);
1218 rc = qeth_osn_send_ipa_cmd(card, iob, data_len);
1219 return rc;
1220}
1221EXPORT_SYMBOL(qeth_osn_assist);
1222
1223int qeth_osn_register(unsigned char *read_dev_no, struct net_device **dev,
1224 int (*assist_cb)(struct net_device *, void *),
1225 int (*data_cb)(struct sk_buff *))
1226{
1227 struct qeth_card *card;
1228
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001229 QETH_DBF_TEXT(TRACE, 2, "osnreg");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001230 *dev = qeth_l2_netdev_by_devno(read_dev_no);
1231 if (*dev == NULL)
1232 return -ENODEV;
Heiko Carstens509e2562008-07-26 02:24:10 -07001233 card = (*dev)->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001234 if (!card)
1235 return -ENODEV;
1236 if ((assist_cb == NULL) || (data_cb == NULL))
1237 return -EINVAL;
1238 card->osn_info.assist_cb = assist_cb;
1239 card->osn_info.data_cb = data_cb;
1240 return 0;
1241}
1242EXPORT_SYMBOL(qeth_osn_register);
1243
1244void qeth_osn_deregister(struct net_device *dev)
1245{
1246 struct qeth_card *card;
1247
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001248 QETH_DBF_TEXT(TRACE, 2, "osndereg");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001249 if (!dev)
1250 return;
Heiko Carstens509e2562008-07-26 02:24:10 -07001251 card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001252 if (!card)
1253 return;
1254 card->osn_info.assist_cb = NULL;
1255 card->osn_info.data_cb = NULL;
1256 return;
1257}
1258EXPORT_SYMBOL(qeth_osn_deregister);
1259
1260module_init(qeth_l2_init);
1261module_exit(qeth_l2_exit);
1262MODULE_AUTHOR("Frank Blaschka <frank.blaschka@de.ibm.com>");
1263MODULE_DESCRIPTION("qeth layer 2 discipline");
1264MODULE_LICENSE("GPL");