blob: 9e628b322bd30c11fb67c9b437835f0880a8bea1 [file] [log] [blame]
Frank Blaschka4a71df52008-02-15 09:19:42 +01001/*
2 * drivers/s390/net/qeth_l2_main.c
3 *
4 * Copyright IBM Corp. 2007
5 * 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>
22
Frank Blaschka4a71df52008-02-15 09:19:42 +010023#include "qeth_core.h"
Frank Blaschka4a71df52008-02-15 09:19:42 +010024
Frank Blaschka4a71df52008-02-15 09:19:42 +010025static int qeth_l2_set_offline(struct ccwgroup_device *);
26static int qeth_l2_stop(struct net_device *);
27static int qeth_l2_send_delmac(struct qeth_card *, __u8 *);
28static int qeth_l2_send_setdelmac(struct qeth_card *, __u8 *,
29 enum qeth_ipa_cmds,
30 int (*reply_cb) (struct qeth_card *,
31 struct qeth_reply*,
32 unsigned long));
33static void qeth_l2_set_multicast_list(struct net_device *);
34static int qeth_l2_recover(void *);
35
36static int qeth_l2_do_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
37{
Heiko Carstens509e2562008-07-26 02:24:10 -070038 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +010039 struct mii_ioctl_data *mii_data;
40 int rc = 0;
41
42 if (!card)
43 return -ENODEV;
44
45 if ((card->state != CARD_STATE_UP) &&
46 (card->state != CARD_STATE_SOFTSETUP))
47 return -ENODEV;
48
49 if (card->info.type == QETH_CARD_TYPE_OSN)
50 return -EPERM;
51
52 switch (cmd) {
53 case SIOC_QETH_ADP_SET_SNMP_CONTROL:
54 rc = qeth_snmp_command(card, rq->ifr_ifru.ifru_data);
55 break;
56 case SIOC_QETH_GET_CARD_TYPE:
57 if ((card->info.type == QETH_CARD_TYPE_OSAE) &&
58 !card->info.guestlan)
59 return 1;
60 return 0;
61 break;
62 case SIOCGMIIPHY:
63 mii_data = if_mii(rq);
64 mii_data->phy_id = 0;
65 break;
66 case SIOCGMIIREG:
67 mii_data = if_mii(rq);
68 if (mii_data->phy_id != 0)
69 rc = -EINVAL;
70 else
71 mii_data->val_out = qeth_mdio_read(dev,
72 mii_data->phy_id, mii_data->reg_num);
73 break;
74 default:
75 rc = -EOPNOTSUPP;
76 }
77 if (rc)
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +020078 QETH_DBF_TEXT_(TRACE, 2, "ioce%d", rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +010079 return rc;
80}
81
82static int qeth_l2_verify_dev(struct net_device *dev)
83{
84 struct qeth_card *card;
85 unsigned long flags;
86 int rc = 0;
87
88 read_lock_irqsave(&qeth_core_card_list.rwlock, flags);
89 list_for_each_entry(card, &qeth_core_card_list.list, list) {
90 if (card->dev == dev) {
91 rc = QETH_REAL_CARD;
92 break;
93 }
94 }
95 read_unlock_irqrestore(&qeth_core_card_list.rwlock, flags);
96
97 return rc;
98}
99
100static struct net_device *qeth_l2_netdev_by_devno(unsigned char *read_dev_no)
101{
102 struct qeth_card *card;
103 struct net_device *ndev;
Cornelia Huckf06f6f32008-06-06 12:37:45 +0200104 __u16 temp_dev_no;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100105 unsigned long flags;
Cornelia Huckf06f6f32008-06-06 12:37:45 +0200106 struct ccw_dev_id read_devid;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100107
108 ndev = NULL;
109 memcpy(&temp_dev_no, read_dev_no, 2);
110 read_lock_irqsave(&qeth_core_card_list.rwlock, flags);
111 list_for_each_entry(card, &qeth_core_card_list.list, list) {
Cornelia Huckf06f6f32008-06-06 12:37:45 +0200112 ccw_device_get_id(CARD_RDEV(card), &read_devid);
113 if (read_devid.devno == temp_dev_no) {
Frank Blaschka4a71df52008-02-15 09:19:42 +0100114 ndev = card->dev;
115 break;
116 }
117 }
118 read_unlock_irqrestore(&qeth_core_card_list.rwlock, flags);
119 return ndev;
120}
121
122static int qeth_l2_send_setgroupmac_cb(struct qeth_card *card,
123 struct qeth_reply *reply,
124 unsigned long data)
125{
126 struct qeth_ipa_cmd *cmd;
127 __u8 *mac;
128
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200129 QETH_DBF_TEXT(TRACE, 2, "L2Sgmacb");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100130 cmd = (struct qeth_ipa_cmd *) data;
131 mac = &cmd->data.setdelmac.mac[0];
132 /* MAC already registered, needed in couple/uncouple case */
133 if (cmd->hdr.return_code == 0x2005) {
Johannes Berg7c510e42008-10-27 17:47:26 -0700134 QETH_DBF_MESSAGE(2, "Group MAC %pM already existing on %s \n",
135 mac, QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100136 cmd->hdr.return_code = 0;
137 }
138 if (cmd->hdr.return_code)
Johannes Berg7c510e42008-10-27 17:47:26 -0700139 QETH_DBF_MESSAGE(2, "Could not set group MAC %pM on %s: %x\n",
140 mac, QETH_CARD_IFNAME(card), cmd->hdr.return_code);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100141 return 0;
142}
143
144static int qeth_l2_send_setgroupmac(struct qeth_card *card, __u8 *mac)
145{
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200146 QETH_DBF_TEXT(TRACE, 2, "L2Sgmac");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100147 return qeth_l2_send_setdelmac(card, mac, IPA_CMD_SETGMAC,
148 qeth_l2_send_setgroupmac_cb);
149}
150
151static int qeth_l2_send_delgroupmac_cb(struct qeth_card *card,
152 struct qeth_reply *reply,
153 unsigned long data)
154{
155 struct qeth_ipa_cmd *cmd;
156 __u8 *mac;
157
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200158 QETH_DBF_TEXT(TRACE, 2, "L2Dgmacb");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100159 cmd = (struct qeth_ipa_cmd *) data;
160 mac = &cmd->data.setdelmac.mac[0];
161 if (cmd->hdr.return_code)
Johannes Berg7c510e42008-10-27 17:47:26 -0700162 QETH_DBF_MESSAGE(2, "Could not delete group MAC %pM on %s: %x\n",
163 mac, QETH_CARD_IFNAME(card), cmd->hdr.return_code);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100164 return 0;
165}
166
167static int qeth_l2_send_delgroupmac(struct qeth_card *card, __u8 *mac)
168{
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200169 QETH_DBF_TEXT(TRACE, 2, "L2Dgmac");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100170 return qeth_l2_send_setdelmac(card, mac, IPA_CMD_DELGMAC,
171 qeth_l2_send_delgroupmac_cb);
172}
173
Frank Blaschka7db22662008-08-15 08:02:59 +0200174static void qeth_l2_add_mc(struct qeth_card *card, __u8 *mac, int vmac)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100175{
176 struct qeth_mc_mac *mc;
Frank Blaschka7db22662008-08-15 08:02:59 +0200177 int rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100178
179 mc = kmalloc(sizeof(struct qeth_mc_mac), GFP_ATOMIC);
180
Frank Blaschka14cc21b2008-06-06 12:37:46 +0200181 if (!mc)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100182 return;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100183
184 memcpy(mc->mc_addr, mac, OSA_ADDR_LEN);
185 mc->mc_addrlen = OSA_ADDR_LEN;
Frank Blaschka7db22662008-08-15 08:02:59 +0200186 mc->is_vmac = vmac;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100187
Frank Blaschka7db22662008-08-15 08:02:59 +0200188 if (vmac) {
189 rc = qeth_l2_send_setdelmac(card, mac, IPA_CMD_SETVMAC,
190 NULL);
191 } else {
192 rc = qeth_l2_send_setgroupmac(card, mac);
193 }
194
195 if (!rc)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100196 list_add_tail(&mc->list, &card->mc_list);
197 else
198 kfree(mc);
199}
200
201static void qeth_l2_del_all_mc(struct qeth_card *card)
202{
203 struct qeth_mc_mac *mc, *tmp;
204
205 spin_lock_bh(&card->mclock);
206 list_for_each_entry_safe(mc, tmp, &card->mc_list, list) {
Frank Blaschka7db22662008-08-15 08:02:59 +0200207 if (mc->is_vmac)
208 qeth_l2_send_setdelmac(card, mc->mc_addr,
209 IPA_CMD_DELVMAC, NULL);
210 else
211 qeth_l2_send_delgroupmac(card, mc->mc_addr);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100212 list_del(&mc->list);
213 kfree(mc);
214 }
215 spin_unlock_bh(&card->mclock);
216}
217
218static void qeth_l2_get_packet_type(struct qeth_card *card,
219 struct qeth_hdr *hdr, struct sk_buff *skb)
220{
221 __u16 hdr_mac;
222
223 if (!memcmp(skb->data + QETH_HEADER_SIZE,
224 skb->dev->broadcast, 6)) {
225 /* broadcast? */
226 hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_BROADCAST;
227 return;
228 }
229 hdr_mac = *((__u16 *)skb->data);
230 /* tr multicast? */
231 switch (card->info.link_type) {
232 case QETH_LINK_TYPE_HSTR:
233 case QETH_LINK_TYPE_LANE_TR:
234 if ((hdr_mac == QETH_TR_MAC_NC) ||
235 (hdr_mac == QETH_TR_MAC_C))
236 hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_MULTICAST;
237 else
238 hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_UNICAST;
239 break;
240 /* eth or so multicast? */
241 default:
242 if ((hdr_mac == QETH_ETH_MAC_V4) ||
243 (hdr_mac == QETH_ETH_MAC_V6))
244 hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_MULTICAST;
245 else
246 hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_UNICAST;
247 }
248}
249
250static void qeth_l2_fill_header(struct qeth_card *card, struct qeth_hdr *hdr,
251 struct sk_buff *skb, int ipv, int cast_type)
252{
Frank Blaschka683d7182008-08-01 16:39:13 +0200253 struct vlan_ethhdr *veth = (struct vlan_ethhdr *)skb_mac_header(skb);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100254
255 memset(hdr, 0, sizeof(struct qeth_hdr));
256 hdr->hdr.l2.id = QETH_HEADER_TYPE_LAYER2;
257
258 /* set byte byte 3 to casting flags */
259 if (cast_type == RTN_MULTICAST)
260 hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_MULTICAST;
261 else if (cast_type == RTN_BROADCAST)
262 hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_BROADCAST;
263 else
264 qeth_l2_get_packet_type(card, hdr, skb);
265
266 hdr->hdr.l2.pkt_length = skb->len-QETH_HEADER_SIZE;
267 /* VSWITCH relies on the VLAN
268 * information to be present in
269 * the QDIO header */
270 if (veth->h_vlan_proto == __constant_htons(ETH_P_8021Q)) {
271 hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_VLAN;
272 hdr->hdr.l2.vlan_id = ntohs(veth->h_vlan_TCI);
273 }
274}
275
276static int qeth_l2_send_setdelvlan_cb(struct qeth_card *card,
277 struct qeth_reply *reply, unsigned long data)
278{
279 struct qeth_ipa_cmd *cmd;
280
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200281 QETH_DBF_TEXT(TRACE, 2, "L2sdvcb");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100282 cmd = (struct qeth_ipa_cmd *) data;
283 if (cmd->hdr.return_code) {
Frank Blaschka14cc21b2008-06-06 12:37:46 +0200284 QETH_DBF_MESSAGE(2, "Error in processing VLAN %i on %s: 0x%x. "
Frank Blaschka4a71df52008-02-15 09:19:42 +0100285 "Continuing\n", cmd->data.setdelvlan.vlan_id,
286 QETH_CARD_IFNAME(card), cmd->hdr.return_code);
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200287 QETH_DBF_TEXT_(TRACE, 2, "L2VL%4x", cmd->hdr.command);
288 QETH_DBF_TEXT_(TRACE, 2, "L2%s", CARD_BUS_ID(card));
289 QETH_DBF_TEXT_(TRACE, 2, "err%d", cmd->hdr.return_code);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100290 }
291 return 0;
292}
293
294static int qeth_l2_send_setdelvlan(struct qeth_card *card, __u16 i,
295 enum qeth_ipa_cmds ipacmd)
296{
297 struct qeth_ipa_cmd *cmd;
298 struct qeth_cmd_buffer *iob;
299
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200300 QETH_DBF_TEXT_(TRACE, 4, "L2sdv%x", ipacmd);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100301 iob = qeth_get_ipacmd_buffer(card, ipacmd, QETH_PROT_IPV4);
302 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
303 cmd->data.setdelvlan.vlan_id = i;
304 return qeth_send_ipa_cmd(card, iob,
305 qeth_l2_send_setdelvlan_cb, NULL);
306}
307
308static void qeth_l2_process_vlans(struct qeth_card *card, int clear)
309{
310 struct qeth_vlan_vid *id;
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200311 QETH_DBF_TEXT(TRACE, 3, "L2prcvln");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100312 spin_lock_bh(&card->vlanlock);
313 list_for_each_entry(id, &card->vid_list, list) {
314 if (clear)
315 qeth_l2_send_setdelvlan(card, id->vid,
316 IPA_CMD_DELVLAN);
317 else
318 qeth_l2_send_setdelvlan(card, id->vid,
319 IPA_CMD_SETVLAN);
320 }
321 spin_unlock_bh(&card->vlanlock);
322}
323
324static void qeth_l2_vlan_rx_add_vid(struct net_device *dev, unsigned short vid)
325{
Heiko Carstens509e2562008-07-26 02:24:10 -0700326 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100327 struct qeth_vlan_vid *id;
328
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200329 QETH_DBF_TEXT_(TRACE, 4, "aid:%d", vid);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100330 id = kmalloc(sizeof(struct qeth_vlan_vid), GFP_ATOMIC);
331 if (id) {
332 id->vid = vid;
333 qeth_l2_send_setdelvlan(card, vid, IPA_CMD_SETVLAN);
334 spin_lock_bh(&card->vlanlock);
335 list_add_tail(&id->list, &card->vid_list);
336 spin_unlock_bh(&card->vlanlock);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100337 }
338}
339
340static void qeth_l2_vlan_rx_kill_vid(struct net_device *dev, unsigned short vid)
341{
342 struct qeth_vlan_vid *id, *tmpid = NULL;
Heiko Carstens509e2562008-07-26 02:24:10 -0700343 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100344
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200345 QETH_DBF_TEXT_(TRACE, 4, "kid:%d", vid);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100346 spin_lock_bh(&card->vlanlock);
347 list_for_each_entry(id, &card->vid_list, list) {
348 if (id->vid == vid) {
349 list_del(&id->list);
350 tmpid = id;
351 break;
352 }
353 }
354 spin_unlock_bh(&card->vlanlock);
355 if (tmpid) {
356 qeth_l2_send_setdelvlan(card, vid, IPA_CMD_DELVLAN);
357 kfree(tmpid);
358 }
359 qeth_l2_set_multicast_list(card->dev);
360}
361
362static int qeth_l2_stop_card(struct qeth_card *card, int recovery_mode)
363{
364 int rc = 0;
365
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200366 QETH_DBF_TEXT(SETUP , 2, "stopcard");
367 QETH_DBF_HEX(SETUP, 2, &card, sizeof(void *));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100368
369 qeth_set_allowed_threads(card, 0, 1);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100370 if (card->read.state == CH_STATE_UP &&
371 card->write.state == CH_STATE_UP &&
372 (card->state == CARD_STATE_UP)) {
373 if (recovery_mode &&
374 card->info.type != QETH_CARD_TYPE_OSN) {
375 qeth_l2_stop(card->dev);
376 } else {
377 rtnl_lock();
378 dev_close(card->dev);
379 rtnl_unlock();
380 }
381 if (!card->use_hard_stop) {
382 __u8 *mac = &card->dev->dev_addr[0];
383 rc = qeth_l2_send_delmac(card, mac);
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200384 QETH_DBF_TEXT_(SETUP, 2, "Lerr%d", rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100385 }
386 card->state = CARD_STATE_SOFTSETUP;
387 }
388 if (card->state == CARD_STATE_SOFTSETUP) {
389 qeth_l2_process_vlans(card, 1);
Ursula Braun28a7e4c2008-09-19 12:56:03 +0200390 if (!card->use_hard_stop)
391 qeth_l2_del_all_mc(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100392 qeth_clear_ipacmd_list(card);
393 card->state = CARD_STATE_HARDSETUP;
394 }
395 if (card->state == CARD_STATE_HARDSETUP) {
396 qeth_qdio_clear_card(card, 0);
397 qeth_clear_qdio_buffers(card);
398 qeth_clear_working_pool_list(card);
399 card->state = CARD_STATE_DOWN;
400 }
401 if (card->state == CARD_STATE_DOWN) {
402 qeth_clear_cmd_buffers(&card->read);
403 qeth_clear_cmd_buffers(&card->write);
404 }
405 card->use_hard_stop = 0;
406 return rc;
407}
408
409static void qeth_l2_process_inbound_buffer(struct qeth_card *card,
410 struct qeth_qdio_buffer *buf, int index)
411{
412 struct qdio_buffer_element *element;
413 struct sk_buff *skb;
414 struct qeth_hdr *hdr;
415 int offset;
416 unsigned int len;
417
418 /* get first element of current buffer */
419 element = (struct qdio_buffer_element *)&buf->buffer->element[0];
420 offset = 0;
421 if (card->options.performance_stats)
422 card->perf_stats.bufs_rec++;
423 while ((skb = qeth_core_get_next_skb(card, buf->buffer, &element,
424 &offset, &hdr))) {
425 skb->dev = card->dev;
426 /* is device UP ? */
427 if (!(card->dev->flags & IFF_UP)) {
428 dev_kfree_skb_any(skb);
429 continue;
430 }
431
432 switch (hdr->hdr.l2.id) {
433 case QETH_HEADER_TYPE_LAYER2:
434 skb->pkt_type = PACKET_HOST;
435 skb->protocol = eth_type_trans(skb, skb->dev);
436 if (card->options.checksum_type == NO_CHECKSUMMING)
437 skb->ip_summed = CHECKSUM_UNNECESSARY;
438 else
439 skb->ip_summed = CHECKSUM_NONE;
Ursula Braun12883722008-04-01 10:26:56 +0200440 if (skb->protocol == htons(ETH_P_802_2))
441 *((__u32 *)skb->cb) = ++card->seqno.pkt_seqno;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100442 len = skb->len;
443 netif_rx(skb);
444 break;
445 case QETH_HEADER_TYPE_OSN:
Ursula Braun2d488c22008-10-24 11:16:55 +0200446 if (card->info.type == QETH_CARD_TYPE_OSN) {
447 skb_push(skb, sizeof(struct qeth_hdr));
448 skb_copy_to_linear_data(skb, hdr,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100449 sizeof(struct qeth_hdr));
Ursula Braun2d488c22008-10-24 11:16:55 +0200450 len = skb->len;
451 card->osn_info.data_cb(skb);
452 break;
453 }
454 /* else unknown */
Frank Blaschka4a71df52008-02-15 09:19:42 +0100455 default:
456 dev_kfree_skb_any(skb);
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200457 QETH_DBF_TEXT(TRACE, 3, "inbunkno");
458 QETH_DBF_HEX(CTRL, 3, hdr, QETH_DBF_CTRL_LEN);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100459 continue;
460 }
461 card->dev->last_rx = jiffies;
462 card->stats.rx_packets++;
463 card->stats.rx_bytes += len;
464 }
465}
466
467static int qeth_l2_send_setdelmac(struct qeth_card *card, __u8 *mac,
468 enum qeth_ipa_cmds ipacmd,
469 int (*reply_cb) (struct qeth_card *,
470 struct qeth_reply*,
471 unsigned long))
472{
473 struct qeth_ipa_cmd *cmd;
474 struct qeth_cmd_buffer *iob;
475
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200476 QETH_DBF_TEXT(TRACE, 2, "L2sdmac");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100477 iob = qeth_get_ipacmd_buffer(card, ipacmd, QETH_PROT_IPV4);
478 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
479 cmd->data.setdelmac.mac_length = OSA_ADDR_LEN;
480 memcpy(&cmd->data.setdelmac.mac, mac, OSA_ADDR_LEN);
481 return qeth_send_ipa_cmd(card, iob, reply_cb, NULL);
482}
483
484static int qeth_l2_send_setmac_cb(struct qeth_card *card,
485 struct qeth_reply *reply,
486 unsigned long data)
487{
488 struct qeth_ipa_cmd *cmd;
489
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200490 QETH_DBF_TEXT(TRACE, 2, "L2Smaccb");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100491 cmd = (struct qeth_ipa_cmd *) data;
492 if (cmd->hdr.return_code) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200493 QETH_DBF_TEXT_(TRACE, 2, "L2er%x", cmd->hdr.return_code);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100494 card->info.mac_bits &= ~QETH_LAYER2_MAC_REGISTERED;
495 cmd->hdr.return_code = -EIO;
496 } else {
497 card->info.mac_bits |= QETH_LAYER2_MAC_REGISTERED;
498 memcpy(card->dev->dev_addr, cmd->data.setdelmac.mac,
499 OSA_ADDR_LEN);
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100500 dev_info(&card->gdev->dev,
501 "MAC address %2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x "
502 "successfully registered on device %s\n",
503 card->dev->dev_addr[0], card->dev->dev_addr[1],
504 card->dev->dev_addr[2], card->dev->dev_addr[3],
505 card->dev->dev_addr[4], card->dev->dev_addr[5],
506 card->dev->name);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100507 }
508 return 0;
509}
510
511static int qeth_l2_send_setmac(struct qeth_card *card, __u8 *mac)
512{
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200513 QETH_DBF_TEXT(TRACE, 2, "L2Setmac");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100514 return qeth_l2_send_setdelmac(card, mac, IPA_CMD_SETVMAC,
515 qeth_l2_send_setmac_cb);
516}
517
518static int qeth_l2_send_delmac_cb(struct qeth_card *card,
519 struct qeth_reply *reply,
520 unsigned long data)
521{
522 struct qeth_ipa_cmd *cmd;
523
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200524 QETH_DBF_TEXT(TRACE, 2, "L2Dmaccb");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100525 cmd = (struct qeth_ipa_cmd *) data;
526 if (cmd->hdr.return_code) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200527 QETH_DBF_TEXT_(TRACE, 2, "err%d", cmd->hdr.return_code);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100528 cmd->hdr.return_code = -EIO;
529 return 0;
530 }
531 card->info.mac_bits &= ~QETH_LAYER2_MAC_REGISTERED;
532
533 return 0;
534}
535
536static int qeth_l2_send_delmac(struct qeth_card *card, __u8 *mac)
537{
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200538 QETH_DBF_TEXT(TRACE, 2, "L2Delmac");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100539 if (!(card->info.mac_bits & QETH_LAYER2_MAC_REGISTERED))
540 return 0;
541 return qeth_l2_send_setdelmac(card, mac, IPA_CMD_DELVMAC,
542 qeth_l2_send_delmac_cb);
543}
544
545static int qeth_l2_request_initial_mac(struct qeth_card *card)
546{
547 int rc = 0;
548 char vendor_pre[] = {0x02, 0x00, 0x00};
549
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200550 QETH_DBF_TEXT(SETUP, 2, "doL2init");
551 QETH_DBF_TEXT_(SETUP, 2, "doL2%s", CARD_BUS_ID(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100552
553 rc = qeth_query_setadapterparms(card);
554 if (rc) {
Frank Blaschka14cc21b2008-06-06 12:37:46 +0200555 QETH_DBF_MESSAGE(2, "could not query adapter parameters on "
556 "device %s: x%x\n", CARD_BUS_ID(card), rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100557 }
558
Ursula Braunf1d58672008-09-19 12:56:02 +0200559 if ((card->info.type == QETH_CARD_TYPE_IQD) ||
560 (card->info.guestlan)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +0100561 rc = qeth_setadpparms_change_macaddr(card);
562 if (rc) {
Frank Blaschka14cc21b2008-06-06 12:37:46 +0200563 QETH_DBF_MESSAGE(2, "couldn't get MAC address on "
564 "device %s: x%x\n", CARD_BUS_ID(card), rc);
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200565 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100566 return rc;
567 }
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200568 QETH_DBF_HEX(SETUP, 2, card->dev->dev_addr, OSA_ADDR_LEN);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100569 } else {
570 random_ether_addr(card->dev->dev_addr);
571 memcpy(card->dev->dev_addr, vendor_pre, 3);
572 }
573 return 0;
574}
575
576static int qeth_l2_set_mac_address(struct net_device *dev, void *p)
577{
578 struct sockaddr *addr = p;
Heiko Carstens509e2562008-07-26 02:24:10 -0700579 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100580 int rc = 0;
581
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200582 QETH_DBF_TEXT(TRACE, 3, "setmac");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100583
584 if (qeth_l2_verify_dev(dev) != QETH_REAL_CARD) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200585 QETH_DBF_TEXT(TRACE, 3, "setmcINV");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100586 return -EOPNOTSUPP;
587 }
588
589 if (card->info.type == QETH_CARD_TYPE_OSN) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200590 QETH_DBF_TEXT(TRACE, 3, "setmcOSN");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100591 return -EOPNOTSUPP;
592 }
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200593 QETH_DBF_TEXT_(TRACE, 3, "%s", CARD_BUS_ID(card));
594 QETH_DBF_HEX(TRACE, 3, addr->sa_data, OSA_ADDR_LEN);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100595 rc = qeth_l2_send_delmac(card, &card->dev->dev_addr[0]);
596 if (!rc)
597 rc = qeth_l2_send_setmac(card, addr->sa_data);
598 return rc;
599}
600
601static void qeth_l2_set_multicast_list(struct net_device *dev)
602{
Heiko Carstens509e2562008-07-26 02:24:10 -0700603 struct qeth_card *card = dev->ml_priv;
Frank Blaschka7db22662008-08-15 08:02:59 +0200604 struct dev_addr_list *dm;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100605
606 if (card->info.type == QETH_CARD_TYPE_OSN)
607 return ;
608
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200609 QETH_DBF_TEXT(TRACE, 3, "setmulti");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100610 qeth_l2_del_all_mc(card);
611 spin_lock_bh(&card->mclock);
612 for (dm = dev->mc_list; dm; dm = dm->next)
Frank Blaschka7db22662008-08-15 08:02:59 +0200613 qeth_l2_add_mc(card, dm->da_addr, 0);
614
615 for (dm = dev->uc_list; dm; dm = dm->next)
616 qeth_l2_add_mc(card, dm->da_addr, 1);
617
Frank Blaschka4a71df52008-02-15 09:19:42 +0100618 spin_unlock_bh(&card->mclock);
619 if (!qeth_adp_supported(card, IPA_SETADP_SET_PROMISC_MODE))
620 return;
621 qeth_setadp_promisc_mode(card);
622}
623
624static int qeth_l2_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
625{
626 int rc;
627 struct qeth_hdr *hdr = NULL;
628 int elements = 0;
Heiko Carstens509e2562008-07-26 02:24:10 -0700629 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100630 struct sk_buff *new_skb = skb;
631 int ipv = qeth_get_ip_version(skb);
632 int cast_type = qeth_get_cast_type(card, skb);
633 struct qeth_qdio_out_q *queue = card->qdio.out_qs
634 [qeth_get_priority_queue(card, skb, ipv, cast_type)];
635 int tx_bytes = skb->len;
Frank Blaschka683d7182008-08-01 16:39:13 +0200636 int data_offset = -1;
637 int elements_needed = 0;
638 int hd_len = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100639
Frank Blaschka4a71df52008-02-15 09:19:42 +0100640 if ((card->state != CARD_STATE_UP) || !card->lan_online) {
641 card->stats.tx_carrier_errors++;
642 goto tx_drop;
643 }
644
645 if ((card->info.type == QETH_CARD_TYPE_OSN) &&
646 (skb->protocol == htons(ETH_P_IPV6)))
647 goto tx_drop;
648
649 if (card->options.performance_stats) {
650 card->perf_stats.outbound_cnt++;
651 card->perf_stats.outbound_start_time = qeth_get_micros();
652 }
653 netif_stop_queue(dev);
654
Frank Blaschka4a71df52008-02-15 09:19:42 +0100655 if (card->info.type == QETH_CARD_TYPE_OSN)
656 hdr = (struct qeth_hdr *)skb->data;
657 else {
Frank Blaschka64ef8952009-03-24 20:57:16 +0000658 if (card->info.type == QETH_CARD_TYPE_IQD) {
Frank Blaschka683d7182008-08-01 16:39:13 +0200659 new_skb = skb;
660 data_offset = ETH_HLEN;
661 hd_len = ETH_HLEN;
662 hdr = kmem_cache_alloc(qeth_core_header_cache,
663 GFP_ATOMIC);
664 if (!hdr)
665 goto tx_drop;
666 elements_needed++;
667 skb_reset_mac_header(new_skb);
668 qeth_l2_fill_header(card, hdr, new_skb, ipv, cast_type);
669 hdr->hdr.l2.pkt_length = new_skb->len;
670 memcpy(((char *)hdr) + sizeof(struct qeth_hdr),
671 skb_mac_header(new_skb), ETH_HLEN);
672 } else {
673 /* create a clone with writeable headroom */
674 new_skb = skb_realloc_headroom(skb,
Frank Blaschkaf90b7442008-04-24 10:15:24 +0200675 sizeof(struct qeth_hdr));
Frank Blaschka683d7182008-08-01 16:39:13 +0200676 if (!new_skb)
677 goto tx_drop;
678 hdr = (struct qeth_hdr *)skb_push(new_skb,
679 sizeof(struct qeth_hdr));
680 skb_set_mac_header(new_skb, sizeof(struct qeth_hdr));
681 qeth_l2_fill_header(card, hdr, new_skb, ipv, cast_type);
682 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100683 }
684
Frank Blaschka64ef8952009-03-24 20:57:16 +0000685 elements = qeth_get_elements_no(card, (void *)hdr, new_skb,
Frank Blaschka683d7182008-08-01 16:39:13 +0200686 elements_needed);
Frank Blaschka64ef8952009-03-24 20:57:16 +0000687 if (!elements) {
688 if (data_offset >= 0)
689 kmem_cache_free(qeth_core_header_cache, hdr);
690 goto tx_drop;
Frank Blaschkaf61a0d02009-03-24 20:57:15 +0000691 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100692
693 if (card->info.type != QETH_CARD_TYPE_IQD)
694 rc = qeth_do_send_packet(card, queue, new_skb, hdr,
Frank Blaschka64ef8952009-03-24 20:57:16 +0000695 elements);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100696 else
697 rc = qeth_do_send_packet_fast(card, queue, new_skb, hdr,
Frank Blaschka64ef8952009-03-24 20:57:16 +0000698 elements, data_offset, hd_len);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100699 if (!rc) {
700 card->stats.tx_packets++;
701 card->stats.tx_bytes += tx_bytes;
702 if (new_skb != skb)
703 dev_kfree_skb_any(skb);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100704 } else {
Frank Blaschka683d7182008-08-01 16:39:13 +0200705 if (data_offset >= 0)
706 kmem_cache_free(qeth_core_header_cache, hdr);
707
Frank Blaschka4a71df52008-02-15 09:19:42 +0100708 if (rc == -EBUSY) {
709 if (new_skb != skb)
710 dev_kfree_skb_any(new_skb);
711 return NETDEV_TX_BUSY;
712 } else
713 goto tx_drop;
714 }
715
716 netif_wake_queue(dev);
717 if (card->options.performance_stats)
718 card->perf_stats.outbound_time += qeth_get_micros() -
719 card->perf_stats.outbound_start_time;
720 return rc;
721
722tx_drop:
723 card->stats.tx_dropped++;
724 card->stats.tx_errors++;
725 if ((new_skb != skb) && new_skb)
726 dev_kfree_skb_any(new_skb);
727 dev_kfree_skb_any(skb);
Frank Blaschkad0ec0f52008-06-06 12:37:48 +0200728 netif_wake_queue(dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100729 return NETDEV_TX_OK;
730}
731
732static void qeth_l2_qdio_input_handler(struct ccw_device *ccwdev,
Jan Glauber779e6e12008-07-17 17:16:48 +0200733 unsigned int qdio_err, unsigned int queue,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100734 int first_element, int count, unsigned long card_ptr)
735{
736 struct net_device *net_dev;
737 struct qeth_card *card;
738 struct qeth_qdio_buffer *buffer;
739 int index;
740 int i;
741
Frank Blaschka4a71df52008-02-15 09:19:42 +0100742 card = (struct qeth_card *) card_ptr;
743 net_dev = card->dev;
744 if (card->options.performance_stats) {
745 card->perf_stats.inbound_cnt++;
746 card->perf_stats.inbound_start_time = qeth_get_micros();
747 }
Jan Glauber779e6e12008-07-17 17:16:48 +0200748 if (qdio_err & QDIO_ERROR_ACTIVATE_CHECK_CONDITION) {
749 QETH_DBF_TEXT(TRACE, 1, "qdinchk");
750 QETH_DBF_TEXT_(TRACE, 1, "%s", CARD_BUS_ID(card));
751 QETH_DBF_TEXT_(TRACE, 1, "%04X%04X", first_element,
752 count);
753 QETH_DBF_TEXT_(TRACE, 1, "%04X", queue);
754 qeth_schedule_recovery(card);
755 return;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100756 }
757 for (i = first_element; i < (first_element + count); ++i) {
758 index = i % QDIO_MAX_BUFFERS_PER_Q;
759 buffer = &card->qdio.in_q->bufs[index];
Jan Glauber779e6e12008-07-17 17:16:48 +0200760 if (!(qdio_err &&
761 qeth_check_qdio_errors(buffer->buffer, qdio_err, "qinerr")))
Frank Blaschka4a71df52008-02-15 09:19:42 +0100762 qeth_l2_process_inbound_buffer(card, buffer, index);
763 /* clear buffer and give back to hardware */
764 qeth_put_buffer_pool_entry(card, buffer->pool_entry);
765 qeth_queue_input_buffer(card, index);
766 }
767 if (card->options.performance_stats)
768 card->perf_stats.inbound_time += qeth_get_micros() -
769 card->perf_stats.inbound_start_time;
770}
771
772static int qeth_l2_open(struct net_device *dev)
773{
Heiko Carstens509e2562008-07-26 02:24:10 -0700774 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100775
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200776 QETH_DBF_TEXT(TRACE, 4, "qethopen");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100777 if (card->state != CARD_STATE_SOFTSETUP)
778 return -ENODEV;
779
780 if ((card->info.type != QETH_CARD_TYPE_OSN) &&
781 (!(card->info.mac_bits & QETH_LAYER2_MAC_REGISTERED))) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200782 QETH_DBF_TEXT(TRACE, 4, "nomacadr");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100783 return -EPERM;
784 }
785 card->data.state = CH_STATE_UP;
786 card->state = CARD_STATE_UP;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100787 netif_start_queue(dev);
788
789 if (!card->lan_online && netif_carrier_ok(dev))
790 netif_carrier_off(dev);
791 return 0;
792}
793
794
795static int qeth_l2_stop(struct net_device *dev)
796{
Heiko Carstens509e2562008-07-26 02:24:10 -0700797 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100798
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200799 QETH_DBF_TEXT(TRACE, 4, "qethstop");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100800 netif_tx_disable(dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100801 if (card->state == CARD_STATE_UP)
802 card->state = CARD_STATE_SOFTSETUP;
803 return 0;
804}
805
806static int qeth_l2_probe_device(struct ccwgroup_device *gdev)
807{
808 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
809
810 INIT_LIST_HEAD(&card->vid_list);
811 INIT_LIST_HEAD(&card->mc_list);
812 card->options.layer2 = 1;
813 card->discipline.input_handler = (qdio_handler_t *)
814 qeth_l2_qdio_input_handler;
815 card->discipline.output_handler = (qdio_handler_t *)
816 qeth_qdio_output_handler;
817 card->discipline.recover = qeth_l2_recover;
818 return 0;
819}
820
821static void qeth_l2_remove_device(struct ccwgroup_device *cgdev)
822{
823 struct qeth_card *card = dev_get_drvdata(&cgdev->dev);
824
825 wait_event(card->wait_q, qeth_threads_running(card, 0xffffffff) == 0);
826
827 if (cgdev->state == CCWGROUP_ONLINE) {
828 card->use_hard_stop = 1;
829 qeth_l2_set_offline(cgdev);
830 }
831
832 if (card->dev) {
833 unregister_netdev(card->dev);
834 card->dev = NULL;
835 }
836
837 qeth_l2_del_all_mc(card);
838 return;
839}
840
841static struct ethtool_ops qeth_l2_ethtool_ops = {
842 .get_link = ethtool_op_get_link,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100843 .get_strings = qeth_core_get_strings,
844 .get_ethtool_stats = qeth_core_get_ethtool_stats,
845 .get_stats_count = qeth_core_get_stats_count,
846 .get_drvinfo = qeth_core_get_drvinfo,
Frank Blaschka3f9975a2008-04-24 10:15:23 +0200847 .get_settings = qeth_core_ethtool_get_settings,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100848};
849
850static struct ethtool_ops qeth_l2_osn_ops = {
851 .get_strings = qeth_core_get_strings,
852 .get_ethtool_stats = qeth_core_get_ethtool_stats,
853 .get_stats_count = qeth_core_get_stats_count,
854 .get_drvinfo = qeth_core_get_drvinfo,
855};
856
Frank Blaschka3d58cef2009-01-09 03:44:00 +0000857static const struct net_device_ops qeth_l2_netdev_ops = {
Frank Blaschka8403b132009-01-08 10:50:55 -0800858 .ndo_open = qeth_l2_open,
859 .ndo_stop = qeth_l2_stop,
860 .ndo_get_stats = qeth_get_stats,
861 .ndo_start_xmit = qeth_l2_hard_start_xmit,
862 .ndo_validate_addr = eth_validate_addr,
863 .ndo_set_multicast_list = qeth_l2_set_multicast_list,
864 .ndo_do_ioctl = qeth_l2_do_ioctl,
865 .ndo_set_mac_address = qeth_l2_set_mac_address,
866 .ndo_change_mtu = qeth_change_mtu,
867 .ndo_vlan_rx_add_vid = qeth_l2_vlan_rx_add_vid,
868 .ndo_vlan_rx_kill_vid = qeth_l2_vlan_rx_kill_vid,
869 .ndo_tx_timeout = qeth_tx_timeout,
870};
871
Frank Blaschka4a71df52008-02-15 09:19:42 +0100872static int qeth_l2_setup_netdev(struct qeth_card *card)
873{
874 switch (card->info.type) {
875 case QETH_CARD_TYPE_OSAE:
876 card->dev = alloc_etherdev(0);
877 break;
878 case QETH_CARD_TYPE_IQD:
879 card->dev = alloc_netdev(0, "hsi%d", ether_setup);
880 break;
881 case QETH_CARD_TYPE_OSN:
882 card->dev = alloc_netdev(0, "osn%d", ether_setup);
883 card->dev->flags |= IFF_NOARP;
884 break;
885 default:
886 card->dev = alloc_etherdev(0);
887 }
888
889 if (!card->dev)
890 return -ENODEV;
891
Heiko Carstens509e2562008-07-26 02:24:10 -0700892 card->dev->ml_priv = card;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100893 card->dev->watchdog_timeo = QETH_TX_TIMEOUT;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100894 card->dev->mtu = card->info.initial_mtu;
Frank Blaschka8403b132009-01-08 10:50:55 -0800895 card->dev->netdev_ops = &qeth_l2_netdev_ops;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100896 if (card->info.type != QETH_CARD_TYPE_OSN)
897 SET_ETHTOOL_OPS(card->dev, &qeth_l2_ethtool_ops);
898 else
899 SET_ETHTOOL_OPS(card->dev, &qeth_l2_osn_ops);
900 card->dev->features |= NETIF_F_HW_VLAN_FILTER;
901 card->info.broadcast_capable = 1;
902 qeth_l2_request_initial_mac(card);
903 SET_NETDEV_DEV(card->dev, &card->gdev->dev);
904 return register_netdev(card->dev);
905}
906
907static int __qeth_l2_set_online(struct ccwgroup_device *gdev, int recovery_mode)
908{
909 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
910 int rc = 0;
911 enum qeth_card_states recover_flag;
912
913 BUG_ON(!card);
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200914 QETH_DBF_TEXT(SETUP, 2, "setonlin");
915 QETH_DBF_HEX(SETUP, 2, &card, sizeof(void *));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100916
917 qeth_set_allowed_threads(card, QETH_RECOVER_THREAD, 1);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100918 recover_flag = card->state;
919 rc = ccw_device_set_online(CARD_RDEV(card));
920 if (rc) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200921 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100922 return -EIO;
923 }
924 rc = ccw_device_set_online(CARD_WDEV(card));
925 if (rc) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200926 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100927 return -EIO;
928 }
929 rc = ccw_device_set_online(CARD_DDEV(card));
930 if (rc) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200931 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100932 return -EIO;
933 }
934
935 rc = qeth_core_hardsetup_card(card);
936 if (rc) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200937 QETH_DBF_TEXT_(SETUP, 2, "2err%d", rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100938 goto out_remove;
939 }
940
941 if (!card->dev && qeth_l2_setup_netdev(card))
942 goto out_remove;
943
944 if (card->info.type != QETH_CARD_TYPE_OSN)
945 qeth_l2_send_setmac(card, &card->dev->dev_addr[0]);
946
947 card->state = CARD_STATE_HARDSETUP;
948 qeth_print_status_message(card);
949
950 /* softsetup */
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200951 QETH_DBF_TEXT(SETUP, 2, "softsetp");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100952
953 rc = qeth_send_startlan(card);
954 if (rc) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200955 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100956 if (rc == 0xe080) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100957 dev_warn(&card->gdev->dev,
958 "The LAN is offline\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100959 card->lan_online = 0;
960 }
961 return rc;
962 } else
963 card->lan_online = 1;
964
965 if (card->info.type != QETH_CARD_TYPE_OSN) {
966 qeth_set_large_send(card, card->options.large_send);
967 qeth_l2_process_vlans(card, 0);
968 }
969
970 netif_tx_disable(card->dev);
971
972 rc = qeth_init_qdio_queues(card);
973 if (rc) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200974 QETH_DBF_TEXT_(SETUP, 2, "6err%d", rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100975 goto out_remove;
976 }
977 card->state = CARD_STATE_SOFTSETUP;
978 netif_carrier_on(card->dev);
979
980 qeth_set_allowed_threads(card, 0xffffffff, 0);
981 if (recover_flag == CARD_STATE_RECOVER) {
982 if (recovery_mode &&
983 card->info.type != QETH_CARD_TYPE_OSN) {
984 qeth_l2_open(card->dev);
985 } else {
986 rtnl_lock();
987 dev_open(card->dev);
988 rtnl_unlock();
989 }
990 /* this also sets saved unicast addresses */
991 qeth_l2_set_multicast_list(card->dev);
992 }
993 /* let user_space know that device is online */
994 kobject_uevent(&gdev->dev.kobj, KOBJ_CHANGE);
995 return 0;
996out_remove:
997 card->use_hard_stop = 1;
998 qeth_l2_stop_card(card, 0);
999 ccw_device_set_offline(CARD_DDEV(card));
1000 ccw_device_set_offline(CARD_WDEV(card));
1001 ccw_device_set_offline(CARD_RDEV(card));
1002 if (recover_flag == CARD_STATE_RECOVER)
1003 card->state = CARD_STATE_RECOVER;
1004 else
1005 card->state = CARD_STATE_DOWN;
1006 return -ENODEV;
1007}
1008
1009static int qeth_l2_set_online(struct ccwgroup_device *gdev)
1010{
1011 return __qeth_l2_set_online(gdev, 0);
1012}
1013
1014static int __qeth_l2_set_offline(struct ccwgroup_device *cgdev,
1015 int recovery_mode)
1016{
1017 struct qeth_card *card = dev_get_drvdata(&cgdev->dev);
1018 int rc = 0, rc2 = 0, rc3 = 0;
1019 enum qeth_card_states recover_flag;
1020
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001021 QETH_DBF_TEXT(SETUP, 3, "setoffl");
1022 QETH_DBF_HEX(SETUP, 3, &card, sizeof(void *));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001023
1024 if (card->dev && netif_carrier_ok(card->dev))
1025 netif_carrier_off(card->dev);
1026 recover_flag = card->state;
Ursula Braun0f5623c2008-10-24 11:16:52 +02001027 qeth_l2_stop_card(card, recovery_mode);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001028 rc = ccw_device_set_offline(CARD_DDEV(card));
1029 rc2 = ccw_device_set_offline(CARD_WDEV(card));
1030 rc3 = ccw_device_set_offline(CARD_RDEV(card));
1031 if (!rc)
1032 rc = (rc2) ? rc2 : rc3;
1033 if (rc)
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001034 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001035 if (recover_flag == CARD_STATE_UP)
1036 card->state = CARD_STATE_RECOVER;
1037 /* let user_space know that device is offline */
1038 kobject_uevent(&cgdev->dev.kobj, KOBJ_CHANGE);
1039 return 0;
1040}
1041
1042static int qeth_l2_set_offline(struct ccwgroup_device *cgdev)
1043{
1044 return __qeth_l2_set_offline(cgdev, 0);
1045}
1046
1047static int qeth_l2_recover(void *ptr)
1048{
1049 struct qeth_card *card;
1050 int rc = 0;
1051
1052 card = (struct qeth_card *) ptr;
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001053 QETH_DBF_TEXT(TRACE, 2, "recover1");
1054 QETH_DBF_HEX(TRACE, 2, &card, sizeof(void *));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001055 if (!qeth_do_run_thread(card, QETH_RECOVER_THREAD))
1056 return 0;
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001057 QETH_DBF_TEXT(TRACE, 2, "recover2");
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001058 dev_warn(&card->gdev->dev,
1059 "A recovery process has been started for the device\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001060 card->use_hard_stop = 1;
1061 __qeth_l2_set_offline(card->gdev, 1);
1062 rc = __qeth_l2_set_online(card->gdev, 1);
1063 /* don't run another scheduled recovery */
1064 qeth_clear_thread_start_bit(card, QETH_RECOVER_THREAD);
1065 qeth_clear_thread_running_bit(card, QETH_RECOVER_THREAD);
1066 if (!rc)
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001067 dev_info(&card->gdev->dev,
1068 "Device successfully recovered!\n");
Ursula Braun28a7e4c2008-09-19 12:56:03 +02001069 else {
Ursula Braunfc9c2462009-01-04 17:35:18 -08001070 if (card->dev) {
1071 rtnl_lock();
1072 dev_close(card->dev);
1073 rtnl_unlock();
1074 }
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001075 dev_warn(&card->gdev->dev, "The qeth device driver "
1076 "failed to recover an error on the device\n");
Ursula Braun28a7e4c2008-09-19 12:56:03 +02001077 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01001078 return 0;
1079}
1080
1081static int __init qeth_l2_init(void)
1082{
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001083 pr_info("register layer 2 discipline\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001084 return 0;
1085}
1086
1087static void __exit qeth_l2_exit(void)
1088{
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001089 pr_info("unregister layer 2 discipline\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001090}
1091
1092static void qeth_l2_shutdown(struct ccwgroup_device *gdev)
1093{
1094 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
1095 qeth_qdio_clear_card(card, 0);
1096 qeth_clear_qdio_buffers(card);
1097}
1098
1099struct ccwgroup_driver qeth_l2_ccwgroup_driver = {
1100 .probe = qeth_l2_probe_device,
1101 .remove = qeth_l2_remove_device,
1102 .set_online = qeth_l2_set_online,
1103 .set_offline = qeth_l2_set_offline,
1104 .shutdown = qeth_l2_shutdown,
1105};
1106EXPORT_SYMBOL_GPL(qeth_l2_ccwgroup_driver);
1107
1108static int qeth_osn_send_control_data(struct qeth_card *card, int len,
1109 struct qeth_cmd_buffer *iob)
1110{
1111 unsigned long flags;
1112 int rc = 0;
1113
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001114 QETH_DBF_TEXT(TRACE, 5, "osndctrd");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001115
1116 wait_event(card->wait_q,
1117 atomic_cmpxchg(&card->write.irq_pending, 0, 1) == 0);
1118 qeth_prepare_control_data(card, len, iob);
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001119 QETH_DBF_TEXT(TRACE, 6, "osnoirqp");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001120 spin_lock_irqsave(get_ccwdev_lock(card->write.ccwdev), flags);
1121 rc = ccw_device_start(card->write.ccwdev, &card->write.ccw,
1122 (addr_t) iob, 0, 0);
1123 spin_unlock_irqrestore(get_ccwdev_lock(card->write.ccwdev), flags);
1124 if (rc) {
Frank Blaschka14cc21b2008-06-06 12:37:46 +02001125 QETH_DBF_MESSAGE(2, "qeth_osn_send_control_data: "
Frank Blaschka4a71df52008-02-15 09:19:42 +01001126 "ccw_device_start rc = %i\n", rc);
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001127 QETH_DBF_TEXT_(TRACE, 2, " err%d", rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001128 qeth_release_buffer(iob->channel, iob);
1129 atomic_set(&card->write.irq_pending, 0);
1130 wake_up(&card->wait_q);
1131 }
1132 return rc;
1133}
1134
1135static int qeth_osn_send_ipa_cmd(struct qeth_card *card,
1136 struct qeth_cmd_buffer *iob, int data_len)
1137{
1138 u16 s1, s2;
1139
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001140 QETH_DBF_TEXT(TRACE, 4, "osndipa");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001141
1142 qeth_prepare_ipa_cmd(card, iob, QETH_PROT_OSN2);
1143 s1 = (u16)(IPA_PDU_HEADER_SIZE + data_len);
1144 s2 = (u16)data_len;
1145 memcpy(QETH_IPA_PDU_LEN_TOTAL(iob->data), &s1, 2);
1146 memcpy(QETH_IPA_PDU_LEN_PDU1(iob->data), &s2, 2);
1147 memcpy(QETH_IPA_PDU_LEN_PDU2(iob->data), &s2, 2);
1148 memcpy(QETH_IPA_PDU_LEN_PDU3(iob->data), &s2, 2);
1149 return qeth_osn_send_control_data(card, s1, iob);
1150}
1151
1152int qeth_osn_assist(struct net_device *dev, void *data, int data_len)
1153{
1154 struct qeth_cmd_buffer *iob;
1155 struct qeth_card *card;
1156 int rc;
1157
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001158 QETH_DBF_TEXT(TRACE, 2, "osnsdmc");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001159 if (!dev)
1160 return -ENODEV;
Heiko Carstens509e2562008-07-26 02:24:10 -07001161 card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001162 if (!card)
1163 return -ENODEV;
1164 if ((card->state != CARD_STATE_UP) &&
1165 (card->state != CARD_STATE_SOFTSETUP))
1166 return -ENODEV;
1167 iob = qeth_wait_for_buffer(&card->write);
1168 memcpy(iob->data+IPA_PDU_HEADER_SIZE, data, data_len);
1169 rc = qeth_osn_send_ipa_cmd(card, iob, data_len);
1170 return rc;
1171}
1172EXPORT_SYMBOL(qeth_osn_assist);
1173
1174int qeth_osn_register(unsigned char *read_dev_no, struct net_device **dev,
1175 int (*assist_cb)(struct net_device *, void *),
1176 int (*data_cb)(struct sk_buff *))
1177{
1178 struct qeth_card *card;
1179
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001180 QETH_DBF_TEXT(TRACE, 2, "osnreg");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001181 *dev = qeth_l2_netdev_by_devno(read_dev_no);
1182 if (*dev == NULL)
1183 return -ENODEV;
Heiko Carstens509e2562008-07-26 02:24:10 -07001184 card = (*dev)->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001185 if (!card)
1186 return -ENODEV;
1187 if ((assist_cb == NULL) || (data_cb == NULL))
1188 return -EINVAL;
1189 card->osn_info.assist_cb = assist_cb;
1190 card->osn_info.data_cb = data_cb;
1191 return 0;
1192}
1193EXPORT_SYMBOL(qeth_osn_register);
1194
1195void qeth_osn_deregister(struct net_device *dev)
1196{
1197 struct qeth_card *card;
1198
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001199 QETH_DBF_TEXT(TRACE, 2, "osndereg");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001200 if (!dev)
1201 return;
Heiko Carstens509e2562008-07-26 02:24:10 -07001202 card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001203 if (!card)
1204 return;
1205 card->osn_info.assist_cb = NULL;
1206 card->osn_info.data_cb = NULL;
1207 return;
1208}
1209EXPORT_SYMBOL(qeth_osn_deregister);
1210
1211module_init(qeth_l2_init);
1212module_exit(qeth_l2_exit);
1213MODULE_AUTHOR("Frank Blaschka <frank.blaschka@de.ibm.com>");
1214MODULE_DESCRIPTION("qeth layer 2 discipline");
1215MODULE_LICENSE("GPL");