22 #define KMSG_COMPONENT "ctcm"
23 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
25 #include <linux/module.h>
27 #include <linux/kernel.h>
28 #include <linux/slab.h>
29 #include <linux/errno.h>
30 #include <linux/types.h>
33 #include <linux/bitops.h>
35 #include <linux/signal.h>
36 #include <linux/string.h>
39 #include <linux/if_arp.h>
40 #include <linux/tcp.h>
42 #include <linux/ctype.h>
60 static struct device *ctcm_root_dev;
101 "%s(%s): Illegal packet type 0x%04x"
105 priv->
stats.rx_dropped++;
106 priv->
stats.rx_frame_errors++;
114 "%s(%s): Illegal packet size %d(%d,%d)"
121 priv->
stats.rx_dropped++;
122 priv->
stats.rx_length_errors++;
127 if ((header->
length > skb_tailroom(pskb)) ||
131 "%s(%s): Packet size %d (overrun)"
137 priv->
stats.rx_dropped++;
138 priv->
stats.rx_length_errors++;
142 skb_reset_mac_header(pskb);
144 skb = dev_alloc_skb(pskb->
len);
148 "%s(%s): MEMORY allocation error",
152 priv->
stats.rx_dropped++;
155 skb_copy_from_linear_data(pskb,
skb_put(skb, pskb->
len),
157 skb_reset_mac_header(skb);
166 priv->
stats.rx_packets++;
167 priv->
stats.rx_bytes += skblen;
173 "Overrun in ctcm_unpack_skb");
187 static void channel_free(
struct channel *ch)
199 static void channel_remove(
struct channel *ch)
219 clear_normalized_cda(&ch->
ccw[4]);
221 clear_normalized_cda(&ch->
ccw[1]);
239 chid, ok ?
"OK" :
"failed");
260 "%s(%d, %s, %d) not found in channel list\n",
282 "irb error %ld on device %s\n",
283 PTR_ERR(irb), dev_name(&cdev->
dev));
285 switch (PTR_ERR(irb)) {
288 "An I/O-error occurred on the CTCM device\n");
292 "An adapter hardware operation timed out\n");
296 "An error occurred on the adapter hardware\n");
318 "%s: The communication peer has "
319 "disconnected\n", ch->
id);
324 if (ch->
sense_rc != SNS0_INTERVENTION_REQ) {
326 "%s: The remote operating system is "
327 "not available\n", ch->
id);
334 if (ch->
sense_rc != SNS0_BUS_OUT_CHECK) {
336 "%s(%s): remote HW error %02x",
342 if (ch->
sense_rc != SNS0_EQUIPMENT_CHECK) {
344 "%s(%s): remote read parity error %02x",
350 }
else if (sense & SNS0_BUS_OUT_CHECK) {
351 if (ch->
sense_rc != SNS0_BUS_OUT_CHECK) {
353 "%s(%s): BUS OUT error %02x",
362 if (ch->
sense_rc != SNS0_CMD_REJECT) {
364 "%s(%s): Command rejected",
368 }
else if (sense == 0) {
370 "%s(%s): Unit check ZERO",
375 "%s(%s): Unit check code %02x unknown",
383 clear_normalized_cda(&ch->
ccw[1]);
387 "%s(%s): %s trans_skb allocation error",
395 if (set_normalized_cda(&ch->
ccw[1], ch->
trans_skb->data)) {
399 "%s(%s): %s set norm_cda failed",
406 ch->
ccw[1].count = 0;
466 unsigned long saveflags;
509 block_len = skb->
len + 2;
522 ctcm_clear_busy(ch->
netdev);
533 ch->
ccw[4].count = block_len;
534 if (set_normalized_cda(&ch->
ccw[4], skb->
data)) {
540 if (ctcm_checkalloc_buffer(ch)) {
547 ctcm_clear_busy(ch->
netdev);
553 ch->
ccw[1].count = skb->
len;
554 skb_copy_from_linear_data(skb,
564 ctcmpc_dumpit((
char *)&ch->
ccw[ccw_idx],
565 sizeof(
struct ccw1) * 3);
572 (
unsigned long)ch, 0xff, 0);
575 ch->
prof.doios_single++;
586 }
else if (ccw_idx == 0) {
589 priv->
stats.tx_packets++;
593 ctcm_clear_busy(ch->
netdev);
597 static void ctcmpc_send_sweep_req(
struct channel *rch)
621 if (sweep_skb ==
NULL) {
634 header->
th.th_seg = 0x00 ;
636 header->
th.th_blk_flag = 0x00;
637 header->
th.th_is_xid = 0x00;
638 header->
th.th_seq_num = 0x00;
654 ctcm_clear_busy(dev);
663 static int ctcmpc_transmit_skb(
struct channel *ch,
struct sk_buff *skb)
674 unsigned long saveflags = 0;
676 CTCM_PR_DEBUG(
"Enter %s: %s, cp=%i ch=0x%p id=%s state=%s\n",
703 "pdu header and data for up to 32 bytes:\n",
704 __func__, dev->
name, skb->
len);
766 p_header = (
struct pdu *)skb->
data;
791 "up to 32 bytes sent to vtam:\n",
792 __func__, dev->
name, skb->
len);
795 ch->
ccw[4].count = skb->
len;
796 if (set_normalized_cda(&ch->
ccw[4], skb->
data)) {
801 if (ctcm_checkalloc_buffer(ch)) {
811 ch->
ccw[1].count = skb->
len;
817 "up to 32 bytes sent to vtam:\n",
830 ctcmpc_dumpit((
char *)&ch->
ccw[ccw_idx],
831 sizeof(
struct ccw1) * 3);
836 (
unsigned long)ch, 0xff, 0);
839 ch->
prof.doios_single++;
845 }
else if (ccw_idx == 0) {
846 priv->
stats.tx_packets++;
850 ctcmpc_send_sweep_req(ch);
855 "%s(%s): MEMORY allocation ERROR\n",
884 "%s(%s): NULL sk_buff passed",
886 priv->
stats.tx_dropped++;
891 "%s(%s): Got sk_buff with head room < %ld bytes",
894 priv->
stats.tx_dropped++;
905 priv->
stats.tx_dropped++;
906 priv->
stats.tx_errors++;
907 priv->
stats.tx_carrier_errors++;
911 if (ctcm_test_and_set_busy(dev))
933 "%s(%s): NULL sk_buff passed",
935 priv->
stats.tx_dropped++;
940 "%s(%s): Got sk_buff with head room < %ld bytes",
947 newskb = __dev_alloc_skb(len, gfp_type() |
GFP_DMA);
951 "%s: %s: __dev_alloc_skb failed",
952 __func__, dev->
name);
955 priv->
stats.tx_dropped++;
956 priv->
stats.tx_errors++;
957 priv->
stats.tx_carrier_errors++;
977 "%s(%s): inactive MPCGROUP - dropped",
979 priv->
stats.tx_dropped++;
980 priv->
stats.tx_errors++;
981 priv->
stats.tx_carrier_errors++;
985 if (ctcm_test_and_set_busy(dev)) {
987 "%s(%s): device busy - dropped",
990 priv->
stats.tx_dropped++;
991 priv->
stats.tx_errors++;
992 priv->
stats.tx_carrier_errors++;
1000 "%s(%s): device error - dropped",
1003 priv->
stats.tx_dropped++;
1004 priv->
stats.tx_errors++;
1005 priv->
stats.tx_carrier_errors++;
1006 ctcm_clear_busy(dev);
1010 ctcm_clear_busy(dev);
1030 static int ctcm_change_mtu(
struct net_device *dev,
int new_mtu)
1035 if (new_mtu < 576 || new_mtu > 65527)
1066 static void ctcm_free_netdevice(
struct net_device *dev)
1108 .ndo_get_stats = ctcm_stats,
1109 .ndo_change_mtu = ctcm_change_mtu,
1110 .ndo_start_xmit = ctcm_tx,
1116 .ndo_get_stats = ctcm_stats,
1117 .ndo_change_mtu = ctcm_change_mtu,
1118 .ndo_start_xmit = ctcmpc_tx,
1121 void static ctcm_dev_setup(
struct net_device *dev)
1146 "%s: MEMORY allocation ERROR",
1196 static void ctcm_irq_handler(
struct ccw_device *cdev,
1197 unsigned long intparm,
struct irb *irb)
1209 if (ctcm_check_irb_error(cdev, irb))
1218 if (cgdev ==
NULL) {
1220 "%s(%s) unsolicited irq: c-%02x d-%02x\n",
1223 "The adapter received a non-specific IRQ\n");
1236 "%s: Internal error: Can't determine channel for "
1237 "interrupt device %s\n",
1238 __func__, dev_name(&cdev->
dev));
1246 "%s Internal error: net_device is NULL, ch = 0x%p\n",
1253 memcpy(ch->
irb, irb,
sizeof(
struct irb));
1259 "%s(%s): sub-ch check %s: cs=%02x ds=%02x",
1262 "A check occurred on the subchannel\n");
1271 "%s(%s): sense=%02x, ds=%02x",
1273 ccw_unit_check(ch, irb->
ecw[0]);
1324 "%s: memory allocation failure",
1330 cgdev->
cdev[0]->handler = ctcm_irq_handler;
1331 cgdev->
cdev[1]->handler = ctcm_irq_handler;
1333 cgdev->
dev.type = &ctcm_devtype;
1357 "%s(%s), type %d, proto %d",
1358 __func__, dev_name(&cdev->
dev), type, priv->
protocol);
1465 while (*c && ctcm_less_than((*c)->id, ch->
id))
1470 "%s (%s) already in list, using old entry",
1471 __func__, (*c)->id);
1479 skb_queue_head_init(&ch->
io_queue);
1542 goto out_err_result;
1545 cdev0 = cgdev->
cdev[0];
1546 cdev1 = cgdev->
cdev[1];
1548 type = get_channel_type(&cdev0->
id);
1553 ret = add_channel(cdev0, type, priv);
1556 goto out_err_result;
1558 ret = add_channel(cdev1, type, priv);
1561 goto out_remove_channel1;
1567 "%s(%s) set_online rc=%d",
1570 goto out_remove_channel2;
1576 "%s(%s) set_online rc=%d",
1583 dev = ctcm_init_netdevice(priv);
1591 channel_get(type, direction ==
CTCM_READ ?
1592 read_id : write_id, direction);
1613 "setup OK : r/w = %s/%s, protocol : %d\n",
1618 "setup(%s) OK : r/w = %s/%s, protocol : %d", dev->
name,
1624 ctcm_free_netdevice(dev);
1629 out_remove_channel2:
1630 readc = channel_get(type, read_id,
CTCM_READ);
1631 channel_remove(readc);
1632 out_remove_channel1:
1633 writec = channel_get(type, write_id,
CTCM_WRITE);
1634 channel_remove(writec);
1670 ctcm_free_netdevice(dev);
1697 "removing device %p, proto : %d",
1700 if (cgdev->
state == CCWGROUP_ONLINE)
1701 ctcm_shutdown_device(cgdev);
1711 if (gdev->
state == CCWGROUP_OFFLINE)
1730 if (gdev->
state == CCWGROUP_OFFLINE)
1768 .setup = ctcm_probe_device,
1769 .remove = ctcm_remove_device,
1770 .set_online = ctcm_new_device,
1771 .set_offline = ctcm_shutdown_device,
1772 .freeze = ctcm_pm_suspend,
1773 .thaw = ctcm_pm_resume,
1774 .restore = ctcm_pm_resume,
1783 return err ? err :
count;
1787 static struct attribute *ctcm_drv_attrs[] = {
1788 &driver_attr_group.attr,
1792 .attrs = ctcm_drv_attrs,
1795 &ctcm_drv_attr_group,
1809 static void __exit ctcm_exit(
void)
1815 pr_info(
"CTCM driver unloaded\n");
1821 static void print_banner(
void)
1823 pr_info(
"CTCM driver initialized\n");
1832 static int __init ctcm_init(
void)
1842 ret = IS_ERR(ctcm_root_dev) ? PTR_ERR(ctcm_root_dev) : 0;
1848 ctcm_group_driver.
driver.groups = ctcm_drv_attr_groups;
1862 pr_err(
"%s / Initializing the ctcm device driver failed, ret = %d\n",