/* * drivers/s390/net/claw.c * ESCON CLAW network driver * * Linux for zSeries version * Copyright IBM Corp. 2002, 2009 * Author(s) Original code written by: * Kazuo Iimura * Rewritten by * Andy Richter * Marc Price * * sysfs parms: * group x.x.rrrr,x.x.wwww * read_buffer nnnnnnn * write_buffer nnnnnn * host_name aaaaaaaa * adapter_name aaaaaaaa * api_type aaaaaaaa * * eg. * group 0.0.0200 0.0.0201 * read_buffer 25 * write_buffer 20 * host_name LINUX390 * adapter_name RS6K * api_type TCPIP * * where * * The device id is decided by the order entries * are added to the group the first is claw0 the second claw1 * up to CLAW_MAX_DEV * * rrrr - the first of 2 consecutive device addresses used for the * CLAW protocol. * The specified address is always used as the input (Read) * channel and the next address is used as the output channel. * * wwww - the second of 2 consecutive device addresses used for * the CLAW protocol. * The specified address is always used as the output * channel and the previous address is used as the input channel. * * read_buffer - specifies number of input buffers to allocate. * write_buffer - specifies number of output buffers to allocate. * host_name - host name * adaptor_name - adaptor name * api_type - API type TCPIP or API will be sent and expected * as ws_name * * Note the following requirements: * 1) host_name must match the configured adapter_name on the remote side * 2) adaptor_name must match the configured host name on the remote side * * Change History * 1.00 Initial release shipped * 1.10 Changes for Buffer allocation * 1.15 Changed for 2.6 Kernel No longer compiles on 2.4 or lower * 1.25 Added Packing support * 1.5 */ #define KMSG_COMPONENT "claw" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "claw.h" /* CLAW uses the s390dbf file system see claw_trace and claw_setup */ static char version[] __initdata = "CLAW driver"; static char debug_buffer[255]; /** * Debug Facility Stuff */ static debug_info_t *claw_dbf_setup; static debug_info_t *claw_dbf_trace; /** * CLAW Debug Facility functions */ static void claw_unregister_debug_facility(void) { if (claw_dbf_setup) debug_unregister(claw_dbf_setup); if (claw_dbf_trace) debug_unregister(claw_dbf_trace); } static int claw_register_debug_facility(void) { claw_dbf_setup = debug_register("claw_setup", 2, 1, 8); claw_dbf_trace = debug_register("claw_trace", 2, 2, 8); if (claw_dbf_setup == NULL || claw_dbf_trace == NULL) { claw_unregister_debug_facility(); return -ENOMEM; } debug_register_view(claw_dbf_setup, &debug_hex_ascii_view); debug_set_level(claw_dbf_setup, 2); debug_register_view(claw_dbf_trace, &debug_hex_ascii_view); debug_set_level(claw_dbf_trace, 2); return 0; } static inline void claw_set_busy(struct net_device *dev) { ((struct claw_privbk *)dev->ml_priv)->tbusy = 1; } static inline void claw_clear_busy(struct net_device *dev) { clear_bit(0, &(((struct claw_privbk *) dev->ml_priv)->tbusy)); netif_wake_queue(dev); } static inline int claw_check_busy(struct net_device *dev) { return ((struct claw_privbk *) dev->ml_priv)->tbusy; } static inline void claw_setbit_busy(int nr,struct net_device *dev) { netif_stop_queue(dev); set_bit(nr, (void *)&(((struct claw_privbk *)dev->ml_priv)->tbusy)); } static inline void claw_clearbit_busy(int nr,struct net_device *dev) { clear_bit(nr, (void *)&(((struct claw_privbk *)dev->ml_priv)->tbusy)); netif_wake_queue(dev); } static inline int claw_test_and_setbit_busy(int nr,struct net_device *dev) { netif_stop_queue(dev); return test_and_set_bit(nr, (void *)&(((struct claw_privbk *) dev->ml_priv)->tbusy)); } /* Functions for the DEV methods */ static int claw_probe(struct ccwgroup_device *cgdev); static void claw_remove_device(struct ccwgroup_device *cgdev); static void claw_purge_skb_queue(struct sk_buff_head *q); static int claw_new_device(struct ccwgroup_device *cgdev); static int claw_shutdown_device(struct ccwgroup_device *cgdev); static int claw_tx(struct sk_buff *skb, struct net_device *dev); static int claw_change_mtu( struct net_device *dev, int new_mtu); static int claw_open(struct net_device *dev); static void claw_irq_handler(struct ccw_device *cdev, unsigned long intparm, struct irb *irb); static void claw_irq_tasklet ( unsigned long data ); static int claw_release(struct net_device *dev); static void claw_write_retry ( struct chbk * p_ch ); static void claw_write_next ( struct chbk * p_ch ); static void claw_timer ( struct chbk * p_ch ); /* Functions */ static int add_claw_reads(struct net_device *dev, struct ccwbk* p_first, struct ccwbk* p_last); static void ccw_check_return_code (struct ccw_device *cdev, int return_code); static void ccw_check_unit_check (struct chbk * p_ch, unsigned char sense ); static int find_link(struct net_device *dev, char *host_name, char *ws_name ); static int claw_hw_tx(struct sk_buff *skb, struct net_device *dev, long linkid); static int init_ccw_bk(struct net_device *dev); static void probe_error( struct ccwgroup_device *cgdev); static struct net_device_stats *claw_stats(struct net_device *dev); static int pages_to_order_of_mag(int num_of_pages); static struct sk_buff *claw_pack_skb(struct claw_privbk *privptr); /* sysfs Functions */ static ssize_t claw_hname_show(struct device *dev, struct device_attribute *attr, char *buf); static ssize_t claw_hname_write(struct device *dev, struct device_attribute *attr, const char *buf, size_t count); static ssize_t claw_adname_show(struct device *dev, struct device_attribute *attr, char *buf); static ssize_t claw_adname_write(struct device *dev, struct device_attribute *attr, const char *buf, size_t count); static ssize_t claw_apname_show(struct device *dev, struct device_attribute *attr, char *buf); static ssize_t claw_apname_write(struct device *dev, struct device_attribute *attr, const char *buf, size_t count); static ssize_t claw_wbuff_show(struct device *dev, struct device_attribute *attr, char *buf); static ssize_t claw_wbuff_write(struct device *dev, struct device_attribute *attr, const char *buf, size_t count); static ssize_t claw_rbuff_show(struct device *dev, struct device_attribute *attr, char *buf); static ssize_t claw_rbuff_write(struct device *dev, struct device_attribute *attr, const char *buf, size_t count); /* Functions for System Validate */ static int claw_process_control( struct net_device *dev, struct ccwbk * p_ccw); static int claw_send_control(struct net_device *dev, __u8 type, __u8 link, __u8 correlator, __u8 rc , char *local_name, char *remote_name); static int claw_snd_conn_req(struct net_device *dev, __u8 link); static int claw_snd_disc(struct net_device *dev, struct clawctl * p_ctl); static int claw_snd_sys_validate_rsp(struct net_device *dev, struct clawctl * p_ctl, __u32 return_code); static int claw_strt_conn_req(struct net_device *dev ); static void claw_strt_read(struct net_device *dev, int lock); static void claw_strt_out_IO(struct net_device *dev); static void claw_free_wrt_buf(struct net_device *dev); /* Functions for unpack reads */ static void unpack_read(struct net_device *dev); static int claw_pm_prepare(struct ccwgroup_device *gdev) { return -EPERM; } /* the root device for claw group devices */ static struct device *claw_root_dev; /* ccwgroup table */ static struct ccwgroup_driver claw_group_driver = { .driver = { .owner = THIS_MODULE, .name = "claw", }, .setup = claw_probe, .remove = claw_remove_device, .set_online = claw_new_device, .set_offline = claw_shutdown_device, .prepare = claw_pm_prepare, }; static struct ccw_device_id claw_ids[] = { {CCW_DEVICE(0x3088, 0x61), .driver_info = claw_channel_type_claw}, {}, }; MODULE_DEVICE_TABLE(ccw, claw_ids); static struct ccw_driver claw_ccw_driver = { .driver = { .owner = THIS_MODULE, .name = "claw", }, .ids = claw_ids, .probe = ccwgroup_probe_ccwdev, .remove = ccwgroup_remove_ccwdev, .int_class = IOINT_CLW, }; static ssize_t claw_driver_group_store(struct device_driver *ddrv, const char *buf, size_t count) { int err; err = ccwgroup_create_dev(claw_root_dev, &claw_group_driver, 2, buf); return err ? err : count; } static DRIVER_ATTR(group, 0200, NULL, claw_driver_group_store); static struct attribute *claw_drv_attrs[] = { &driver_attr_group.attr, NULL, }; static struct attribute_group claw_drv_attr_group = { .attrs = claw_drv_attrs, }; static const struct attribute_group *claw_drv_attr_groups[] = { &claw_drv_attr_group, NULL, }; /* * Key functions */ /*-------------------------------------------------------------------* * claw_tx * *-------------------------------------------------------------------*/ static int claw_tx(struct sk_buff *skb, struct net_device *dev) { int rc; struct claw_privbk *privptr = dev->ml_priv; unsigned long saveflags; struct chbk *p_ch; CLAW_DBF_TEXT(4, trace, "claw_tx"); p_ch = &privptr->channel[WRITE_CHANNEL]; spin_lock_irqsave(get_ccwdev_lock(p_ch->cdev), saveflags); rc=claw_hw_tx( skb, dev, 1 ); spin_unlock_irqrestore(get_ccwdev_lock(p_ch->cdev), saveflags); CLAW_DBF_TEXT_(4, trace, "clawtx%d", rc); if (rc) rc = NETDEV_TX_BUSY; else rc = NETDEV_TX_OK; return rc; } /* end of claw_tx */ /*------------------------------------------------------------------* * pack the collect queue into an skb and return it * * If not packing just return the top skb from the queue * *------------------------------------------------------------------*/ static struct sk_buff * claw_pack_skb(struct claw_privbk *privptr) { struct sk_buff *new_skb,*held_skb; struct chbk *p_ch = &privptr->channel[WRITE_CHANNEL]; struct claw_env *p_env = privptr->p_env; int pkt_cnt,pk_ind,so_far; new_skb = NULL; /* assume no dice */ pkt_cnt = 0; CLAW_DBF_TEXT(4, trace, "PackSKBe"); if (!skb_queue_empty(&p_ch->collect_queue)) { /* some data */ held_skb = skb_dequeue(&p_ch->collect_queue); if (held_skb) dev_kfree_skb_any(held_skb); else return NULL; if (p_env->packing != DO_PACKED) return held_skb; /* get a new SKB we will pack at least one */ new_skb = dev_alloc_skb(p_env->write_size); if (new_skb == NULL) { atomic_inc(&held_skb->users); skb_queue_head(&p_ch->collect_queue,held_skb); return NULL; } /* we have packed packet and a place to put it */ pk_ind = 1; so_far = 0; new_skb->cb[1] = 'P'; /* every skb on queue has pack header */ while ((pk_ind) && (held_skb != NULL)) { if (held_skb->len+so_far <= p_env->write_size-8) { memcpy(skb_put(new_skb,held_skb->len), held_skb->data,held_skb->len); privptr->stats.tx_packets++; so_far += held_skb->len; pkt_cnt++; dev_kfree_skb_any(held_skb); held_skb = skb_dequeue(&p_ch->collect_queue); if (held_skb) atomic_dec(&held_skb->users); } else { pk_ind = 0; atomic_inc(&held_skb->users); skb_queue_head(&p_ch->collect_queue,held_skb); } } } CLAW_DBF_TEXT(4, trace, "PackSKBx"); return new_skb; } /*-------------------------------------------------------------------* * claw_change_mtu * * * *-------------------------------------------------------------------*/ static int claw_change_mtu(struct net_device *dev, int new_mtu) { struct claw_privbk *privptr = dev->ml_priv; int buff_size; CLAW_DBF_TEXT(4, trace, "setmtu"); buff_size = privptr->p_env->write_size; if ((new_mtu < 60) || (new_mtu > buff_size)) { return -EINVAL; } dev->mtu = new_mtu; return 0; } /* end of claw_change_mtu */ /*-------------------------------------------------------------------* * claw_open * * * *-------------------------------------------------------------------*/ static int claw_open(struct net_device *dev) { int rc; int i; unsigned long saveflags=0; unsigned long parm; struct claw_privbk *privptr; DECLARE_WAITQUEUE(wait, current); struct timer_list timer; struct ccwbk *p_buf; CLAW_DBF_TEXT(4, trace, "open"); privptr = (struct claw_privbk *)dev->ml_priv; /* allocate and initialize CCW blocks */ if (privptr->buffs_alloc == 0) { rc=init_ccw_bk(dev); if (rc) { CLAW_DBF_TEXT(2, trace, "openmem"); return -ENOMEM; } } privptr->system_validate_comp=0; privptr->release_pend=0; if(strncmp(privptr->p_env->api_type,WS_APPL_NAME_PACKED,6) == 0) { privptr->p_env->read_size=DEF_PACK_BUFSIZE; privptr->p_env->write_size=DEF_PACK_BUFSIZE; privptr->p_env->packing=PACKING_ASK; } else { privptr->p_env->packing=0; privptr->p_env->read_size=CLAW_FRAME_SIZE; privptr->p_env->write_size=CLAW_FRAME_SIZE; } claw_set_busy(dev); tasklet_init(&privptr->channel[READ_CHANNEL].tasklet, claw_irq_tasklet, (unsigned long) &privptr->channel[READ_CHANNEL]); for ( i = 0; i < 2; i++) { CLAW_DBF_TEXT_(2, trace, "opn_ch%d", i); init_waitqueue_head(&privptr->channel[i].wait); /* skb_queue_head_init(&p_ch->io_queue); */ if (i == WRITE_CHANNEL) skb_queue_head_init( &privptr->channel[WRITE_CHANNEL].collect_queue); privptr->channel[i].flag_a = 0; privptr->channel[i].IO_active = 0; privptr->channel[i].flag &= ~CLAW_TIMER; init_timer(&timer); timer.function = (void *)claw_timer; timer.data = (unsigned long)(&privptr->channel[i]); timer.expires = jiffies + 15*HZ; add_timer(&timer); spin_lock_irqsave(get_ccwdev_lock( privptr->channel[i].cdev), saveflags); parm = (unsigned long) &privptr->channel[i]; privptr->channel[i].claw_state = CLAW_START_HALT_IO; rc = 0; add_wait_queue(&privptr->channel[i].wait, &wait); rc = ccw_device_halt( (struct ccw_device *)privptr->channel[i].cdev,parm); set_current_state(TASK_INTERRUPTIBLE); spin_unlock_irqrestore( get_ccwdev_lock(privptr->channel[i].cdev), saveflags); schedule(); set_current_state(TASK_RUNNING); remove_wait_queue(&privptr->channel[i].wait, &wait); if(rc != 0) ccw_check_return_code(privptr->channel[i].cdev, rc); if((privptr->channel[i].flag & CLAW_TIMER) == 0x00) del_timer(&timer); } if ((((privptr->channel[READ_CHANNEL].last_dstat | privptr->channel[WRITE_CHANNEL].last_dstat) & ~(DEV_STAT_CHN_END | DEV_STAT_DEV_END)) != 0x00) || (((privptr->channel[READ_CHANNEL].flag | privptr->channel[WRITE_CHANNEL].flag) & CLAW_TIMER) != 0x00)) { dev_info(&privptr->channel[READ_CHANNEL].cdev->dev, "%s: remote side is not ready\n", dev->name); CLAW_DBF_TEXT(2, trace, "notrdy"); for ( i = 0; i < 2; i++) { spin_lock_irqsave( get_ccwdev_lock(privptr->channel[i].cdev), saveflags); parm = (unsigned long) &privptr->channel[i]; privptr->channel[i].claw_state = CLAW_STOP; rc = ccw_device_halt( (struct ccw_device *)&privptr->channel[i].cdev, parm); spin_unlock_irqrestore( get_ccwdev_lock(privptr->channel[i].cdev), saveflags); if (rc != 0) { ccw_check_return_code( privptr->channel[i].cdev, rc); } } free_pages((unsigned long)privptr->p_buff_ccw, (int)pages_to_order_of_mag(privptr->p_buff_ccw_num)); if (privptr->p_env->read_size < PAGE_SIZE) { free_pages((unsigned long)privptr->p_buff_read, (int)pages_to_order_of_mag( privptr->p_buff_read_num)); } else { p_buf=privptr->p_read_active_first; while (p_buf!=NULL) { free_pages((unsigned long)p_buf->p_buffer, (int)pages_to_order_of_mag( privptr->p_buff_pages_perread )); p_buf=p_buf->next; } } if (privptr->p_env->write_size < PAGE_SIZE ) { free_pages((unsigned long)privptr->p_buff_write, (int)pages_to_order_of_mag( privptr->p_buff_write_num)); } else { p_buf=privptr->p_write_active_first; while (p_buf!=NULL) { free_pages((unsigned long)p_buf->p_buffer, (int)pages_to_order_of_mag( privptr->p_buff_pages_perwrite )); p_buf=p_buf->next; } } privptr->buffs_alloc = 0; privptr->channel[READ_CHANNEL].flag = 0x00; privptr->channel[WRITE_CHANNEL].flag = 0x00; privptr->p_buff_ccw=NULL; privptr->p_buff_read=NULL; privptr->p_buff_write=NULL; claw_clear_busy(dev); CLAW_DBF_TEXT(2, trace, "open EIO"); return -EIO; } /* Send SystemValidate command */ claw_clear_busy(dev); CLAW_DBF_TEXT(4, trace, "openok"); return 0; } /* end of claw_open */ /*-------------------------------------------------------------------* * * * claw_irq_handler * * * *--------------------------------------------------------------------*/ static void claw_irq_handler(struct ccw_device *cdev, unsigned long intparm, struct irb *irb) { struct chbk *p_ch = NULL; struct claw_privbk *privptr = NULL; struct net_device *dev = NULL; struct claw_env *p_env; struct chbk *p_ch_r=NULL; CLAW_DBF_TEXT(4, trace, "clawirq"); /* Bypass all 'unsolicited interrupts' */ privptr = dev_get_drvdata(&cdev->dev); if (!privptr) { dev_warn(&cdev->dev, "An uninitialized CLAW device received an" " IRQ, c-%02x d-%02x\n", irb->scsw.cmd.cstat, irb->scsw.cmd.dstat); CLAW_DBF_TEXT(2, trace, "badirq"); return; } /* Try to extract channel from driver data. */ if (privptr->channel[READ_CHANNEL].cdev == cdev) p_ch = &privptr->channel[READ_CHANNEL]; else if (privptr->channel[WRITE_CHANNEL].cdev == cdev) p_ch = &privptr->channel[WRITE_CHANNEL]; else { dev_warn(&cdev->dev, "The device is not a CLAW device\n"); CLAW_DBF_TEXT(2, trace, "badchan"); return; } CLAW_DBF_TEXT_(4, trace, "IRQCH=%d", p_ch->flag); dev = (struct net_device *) (p_ch->ndev); p_env=privptr->p_env; /* Copy interruption response block. */ memcpy(p_ch->irb, irb, sizeof(struct irb)); /* Check for good subchannel return code, otherwise info message */ if (irb->scsw.cmd.cstat && !(irb->scsw.cmd.cstat & SCHN_STAT_PCI)) { dev_info(&cdev->dev, "%s: subchannel check for device: %04x -" " Sch Stat %02x Dev Stat %02x CPA - %04x\n", dev->name, p_ch->devno, irb->scsw.cmd.cstat, irb->scsw.cmd.dstat, irb->scsw.cmd.cpa); CLAW_DBF_TEXT(2, trace, "chanchk"); /* return; */ } /* Check the reason-code of a unit check */ if (irb->scsw.cmd.dstat & DEV_STAT_UNIT_CHECK) ccw_check_unit_check(p_ch, irb->ecw[0]); /* State machine to bring the connection up, down and to restart */ p_ch->last_dstat = irb->scsw.cmd.dstat; switch (p_ch->claw_state) { case CLAW_STOP:/* HALT_IO by claw_release (halt sequence) */ if (!((p_ch->irb->scsw.cmd.stctl & SCSW_STCTL_SEC_STATUS) || (p_ch->irb->scsw.cmd.stctl == SCSW_STCTL_STATUS_PEND) || (p_ch->irb->scsw.cmd.stctl == (SCSW_STCTL_ALERT_STATUS | SCSW_STCTL_STATUS_PEND)))) return; wake_up(&p_ch->wait); /* wake up claw_release */ CLAW_DBF_TEXT(4, trace, "stop"); return; case CLAW_START_HALT_IO: /* HALT_IO issued by claw_open */ if (!((p_ch->irb->scsw.cmd.stctl & SCSW_STCTL_SEC_STATUS) || (p_ch->irb->scsw.cmd.stctl == SCSW_STCTL_STATUS_PEND) || (p_ch->irb->scsw.cmd.stctl == (SCSW_STCTL_ALERT_STATUS | SCSW_STCTL_STATUS_PEND)))) { CLAW_DBF_TEXT(4, trace, "haltio"); return; } if (p_ch->flag == CLAW_READ) { p_ch->claw_state = CLAW_START_READ; wake_up(&p_ch->wait); /* wake claw_open (READ)*/ } else if (p_ch->flag == CLAW_WRITE) { p_ch->claw_state = CLAW_START_WRITE; /* send SYSTEM_VALIDATE */ claw_strt_read(dev, LOCK_NO); claw_send_control(dev, SYSTEM_VALIDATE_REQUEST, 0, 0, 0, p_env->host_name, p_env->adapter_name); } else { dev_warn(&cdev->dev, "The CLAW device received" " an unexpected IRQ, " "c-%02x d-%02x\n", irb->scsw.cmd.cstat, irb->scsw.cmd.dstat); return; } CLAW_DBF_TEXT(4, trace, "haltio"); return; case CLAW_START_READ: CLAW_DBF_TEXT(4, trace, "ReadIRQ"); if (p_ch->irb->scsw.cmd.dstat & DEV_STAT_UNIT_CHECK) { clear_bit(0, (void *)&p_ch->IO_active); if ((p_ch->irb->ecw[0] & 0x41) == 0x41 || (p_ch->irb->ecw[0] & 0x40) == 0x40 || (p_ch->irb->ecw[0]) == 0) { privptr->stats.rx_errors++; dev_info(&cdev->dev, "%s: Restart is required after remote " "side recovers \n", dev->name); } CLAW_DBF_TEXT(4, trace, "notrdy"); return; } if ((p_ch->irb->scsw.cmd.cstat & SCHN_STAT_PCI) && (p_ch->irb->scsw.cmd.dstat == 0)) { if (test_and_set_bit(CLAW_BH_ACTIVE, (void *)&p_ch->flag_a) == 0) tasklet_schedule(&p_ch->tasklet); else CLAW_DBF_TEXT(4, trace, "PCINoBH"); CLAW_DBF_TEXT(4, trace, "PCI_read"); return; } if (!((p_ch->irb->scsw.cmd.stctl & SCSW_STCTL_SEC_STATUS) || (p_ch->irb->scsw.cmd.stctl == SCSW_STCTL_STATUS_PEND) || (p_ch->irb->scsw.cmd.stctl == (SCSW_STCTL_ALERT_STATUS | SCSW_STCTL_STATUS_PEND)))) { CLAW_DBF_TEXT(4, trace, "SPend_rd"); return; } clear_bit(0, (void *)&p_ch->IO_active); claw_clearbit_busy(TB_RETRY, dev); if (test_and_set_bit(CLAW_BH_ACTIVE, (void *)&p_ch->flag_a) == 0) tasklet_schedule(&p_ch->tasklet); else CLAW_DBF_TEXT(4, trace, "RdBHAct"); CLAW_DBF_TEXT(4, trace, "RdIRQXit"); return; case CLAW_START_WRITE: if (p_ch->irb->scsw.cmd.dstat & DEV_STAT_UNIT_CHECK) { dev_info(&cdev->dev, "%s: Unit Check Occurred in " "write channel\n", dev->name); clear_bit(0, (void *)&p_ch->IO_active); if (p_ch->irb->ecw[0] & 0x80) { dev_info(&cdev->dev, "%s: Resetting Event " "occurred:\n", dev->name); init_timer(&p_ch->timer); p_ch->timer.function = (void *)claw_write_retry; p_ch->timer.data = (unsigned long)p_ch; p_ch->timer.expires = jiffies + 10*HZ; add_timer(&p_ch->timer); dev_info(&cdev->dev, "%s: write connection " "restarting\n", dev->name); } CLAW_DBF_TEXT(4, trace, "rstrtwrt"); return; } if (p_ch->irb->scsw.cmd.dstat & DEV_STAT_UNIT_EXCEP) { clear_bit(0, (void *)&p_ch->IO_active); dev_info(&cdev->dev, "%s: Unit Exception " "occurred in write channel\n", dev->name); } if (!((p_ch->irb->scsw.cmd.stctl & SCSW_STCTL_SEC_STATUS) || (p_ch->irb->scsw.cmd.stctl == SCSW_STCTL_STATUS_PEND) || (p_ch->irb->scsw.cmd.stctl == (SCSW_STCTL_ALERT_STATUS | SCSW_STCTL_STATUS_PEND)))) { CLAW_DBF_TEXT(4, trace, "writeUE"); return; } clear_bit(0, (void *)&p_ch->IO_active); if (claw_test_and_setbit_busy(TB_TX, dev) == 0) { claw_write_next(p_ch); claw_clearbit_busy(TB_TX, dev); claw_clear_busy(dev); } p_ch_r = (struct chbk *)&privptr->channel[READ_CHANNEL]; if (test_and_set_bit(CLAW_BH_ACTIVE, (void *)&p_ch_r->flag_a) == 0) tasklet_schedule(&p_ch_r->tasklet); CLAW_DBF_TEXT(4, trace, "StWtExit"); return; default: dev_warn(&cdev->dev, "The CLAW device for %s received an unexpected IRQ\n", dev->name); CLAW_DBF_TEXT(2, trace, "badIRQ"); return; } } /* end of claw_irq_handler */ /*-------------------------------------------------------------------* * claw_irq_tasklet * * * *--------------------------------------------------------------------*/ static void claw_irq_tasklet ( unsigned long data ) { struct chbk * p_ch; struct net_device *dev; p_ch = (struct chbk *) data; dev = (struct net_device *)p_ch->ndev; CLAW_DBF_TEXT(4, trace, "IRQtask"); unpack_read(dev); clear_bit(CLAW_BH_ACTIVE, (void *)&p_ch->flag_a); CLAW_DBF_TEXT(4, trace, "TskletXt"); return; } /* end of claw_irq_bh */ /*-------------------------------------------------------------------* * claw_release * * * *--------------------------------------------------------------------*/ static int claw_release(struct net_device *dev) { int rc; int i; unsigned long saveflags; unsigned long parm; struct claw_privbk *privptr; DECLARE_WAITQUEUE(wait, current); struct ccwbk* p_this_ccw; struct ccwbk* p_buf; if (!dev) return 0; privptr = (struct claw_privbk *)dev->ml_priv; if (!privptr) return 0; CLAW_DBF_TEXT(4, trace, "release"); privptr->release_pend=1; claw_setbit_busy(TB_STOP,dev); for ( i = 1; i >=0 ; i--) { spin_lock_irqsave( get_ccwdev_lock(privptr->channel[i].cdev), saveflags); /* del_timer(&privptr->channel[READ_CHANNEL].timer); */ privptr->channel[i].claw_state = CLAW_STOP; privptr->channel[i].IO_active = 0; parm = (unsigned long) &privptr->channel[i]; if (i == WRITE_CHANNEL) claw_purge_skb_queue( &privptr->channel[WRITE_CHANNEL].collect_queue); rc = ccw_device_halt (privptr->channel[i].cdev, parm); if (privptr->system_validate_comp==0x00) /* never opened? */ init_waitqueue_head(&privptr->channel[i].wait); add_wait_queue(&privptr->channel[i].wait, &wait); set_current_state(TASK_INTERRUPTIBLE); spin_unlock_irqrestore( get_ccwdev_lock(privptr->channel[i].cdev), saveflags); schedule(); set_current_state(TASK_RUNNING); remove_wait_queue(&privptr->channel[i].wait, &wait); if (rc != 0) { ccw_check_return_code(privptr->channel[i].cdev, rc); } } if (privptr->pk_skb != NULL) { dev_kfree_skb_any(privptr->pk_skb); privptr->pk_skb = NULL; } if(privptr->buffs_alloc != 1) { CLAW_DBF_TEXT(4, trace, "none2fre"); return 0; } CLAW_DBF_TEXT(4, trace, "freebufs"); if (privptr->p_buff_ccw != NULL) { free_pages((unsigned long)privptr->p_buff_ccw, (int)pages_to_order_of_mag(privptr->p_buff_ccw_num)); } CLAW_DBF_TEXT(4, trace, "freeread"); if (privptr->p_env->read_size < PAGE_SIZE) { if (privptr->p_buff_read != NULL) { free_pages((unsigned long)privptr->p_buff_read, (int)pages_to_order_of_mag(privptr->p_buff_read_num)); } } else { p_buf=privptr->p_read_active_first; while (p_buf!=NULL) { free_pages((unsigned long)p_buf->p_buffer, (int)pages_to_order_of_mag( privptr->p_buff_pages_perread )); p_buf=p_buf->next; } } CLAW_DBF_TEXT(4, trace, "freewrit"); if (privptr->p_env->write_size < PAGE_SIZE ) { free_pages((unsigned long)privptr->p_buff_write, (int)pages_to_order_of_mag(privptr->p_buff_write_num)); } else { p_buf=privptr->p_write_active_first; while (p_buf!=NULL) { free_pages((unsigned long)p_buf->p_buffer, (int)pages_to_order_of_mag( privptr->p_buff_pages_perwrite )); p_buf=p_buf->next; } } CLAW_DBF_TEXT(4, trace, "clearptr"); privptr->buffs_alloc = 0; privptr->p_buff_ccw=NULL; privptr->p_buff_read=NULL; privptr->p_buff_write=NULL; privptr->system_validate_comp=0; privptr->release_pend=0; /* Remove any writes that were pending and reset all reads */ p_this_ccw=privptr->p_read_active_first; while (p_this_ccw!=NULL) { p_this_ccw->header.length=0xffff; p_this_ccw->header.opcode=0xff; p_this_ccw->header.flag=0x00; p_this_ccw=p_this_ccw->next; } while (privptr->p_write_active_first!=NULL) { p_this_ccw=privptr->p_write_active_first; p_this_ccw->header.flag=CLAW_PENDING; privptr->p_write_active_first=p_this_ccw->next; p_this_ccw->next=privptr->p_write_free_chain; privptr->p_write_free_chain=p_this_ccw; ++privptr->write_free_count; } privptr->p_write_active_last=NULL; privptr->mtc_logical_link = -1; privptr->mtc_skipping = 1; privptr->mtc_offset=0; if (((privptr->channel[READ_CHANNEL].last_dstat | privptr->channel[WRITE_CHANNEL].last_dstat) & ~(DEV_STAT_CHN_END | DEV_STAT_DEV_END)) != 0x00) { dev_warn(&privptr->channel[READ_CHANNEL].cdev->dev, "Deactivating %s completed with incorrect" " subchannel status " "(read %02x, write %02x)\n", dev->name, privptr->channel[READ_CHANNEL].last_dstat, privptr->channel[WRITE_CHANNEL].last_dstat); CLAW_DBF_TEXT(2, trace, "badclose"); } CLAW_DBF_TEXT(4, trace, "rlsexit"); return 0; } /* end of claw_release */ /*-------------------------------------------------------------------* * claw_write_retry * * * *--------------------------------------------------------------------*/ static void claw_write_retry ( struct chbk *p_ch ) { struct net_device *dev=p_ch->ndev; CLAW_DBF_TEXT(4, trace, "w_retry"); if (p_ch->claw_state == CLAW_STOP) { return; } claw_strt_out_IO( dev ); CLAW_DBF_TEXT(4, trace, "rtry_xit"); return; } /* end of claw_write_retry */ /*-------------------------------------------------------------------* * claw_write_next * * * *--------------------------------------------------------------------*/ static void claw_write_next ( struct chbk * p_ch ) { struct net_device *dev; struct claw_privbk *privptr=NULL; struct sk_buff *pk_skb; CLAW_DBF_TEXT(4, trace, "claw_wrt"); if (p_ch->claw_state == CLAW_STOP) return; dev = (struct net_device *) p_ch->ndev; privptr = (struct claw_privbk *) dev->ml_priv; claw_free_wrt_buf( dev ); if ((privptr->write_free_count > 0) && !skb_queue_empty(&p_ch->collect_queue)) { pk_skb = claw_pack_skb(privptr); while (pk_skb != NULL) { claw_hw_tx(pk_skb, dev, 1); if (privptr->write_free_count > 0) { pk_skb = claw_pack_skb(privptr); } else pk_skb = NULL; } } if (privptr->p_write_active_first!=NULL) { claw_strt_out_IO(dev); } return; } /* end of claw_write_next */ /*-------------------------------------------------------------------* * * * claw_timer * *--------------------------------------------------------------------*/ static void claw_timer ( struct chbk * p_ch ) { CLAW_DBF_TEXT(4, trace, "timer"); p_ch->flag |= CLAW_TIMER; wake_up(&p_ch->wait); return; } /* end of claw_timer */ /* * * functions */ /*-------------------------------------------------------------------* * * * pages_to_order_of_mag * * * * takes a number of pages from 1 to 512 and returns the * * log(num_pages)/log(2) get_free_pages() needs a base 2 order * * of magnitude get_free_pages() has an upper order of 9 * *--------------------------------------------------------------------*/ static int pages_to_order_of_mag(int num_of_pages) { int order_of_mag=1; /* assume 2 pages */ int nump; CLAW_DBF_TEXT_(5, trace, "pages%d", num_of_pages); if (num_of_pages == 1) {return 0; } /* magnitude of 0 = 1 page */ /* 512 pages = 2Meg on 4k page systems */ if (num_of_pages >= 512) {return 9; } /* we have two or more pages order is at least 1 */ for (nump=2 ;nump <= 512;nump*=2) { if (num_of_pages <= nump) break; order_of_mag +=1; } if (order_of_mag > 9) { order_of_mag = 9; } /* I know it's paranoid */ CLAW_DBF_TEXT_(5, trace, "mag%d", order_of_mag); return order_of_mag; } /*-------------------------------------------------------------------* * * * add_claw_reads * * * *--------------------------------------------------------------------*/ static int add_claw_reads(struct net_device *dev, struct ccwbk* p_first, struct ccwbk* p_last) { struct claw_privbk *privptr; struct ccw1 temp_ccw; struct endccw * p_end; CLAW_DBF_TEXT(4, trace, "addreads"); privptr = dev->ml_priv; p_end = privptr->p_end_ccw; /* first CCW and last CCW contains a new set of read channel programs * to apend the running channel programs */ if ( p_first==NULL) { CLAW_DBF_TEXT(4, trace, "addexit"); return 0; } /* set up ending CCW sequence for this segment */ if (p_end->read1) { p_end->read1=0x00; /* second ending CCW is now active */ /* reset ending CCWs and setup TIC CCWs */ p_end->read2_nop2.cmd_code = CCW_CLAW_CMD_READFF; p_end->read2_nop2.flags = CCW_FLAG_SLI | CCW_FLAG_SKIP; p_last->r_TIC_1.cda =(__u32)__pa(&p_end->read2_nop1); p_last->r_TIC_2.cda =(__u32)__pa(&p_end->read2_nop1); p_end->read2_nop2.cda=0; p_end->read2_nop2.count=1; } else { p_end->read1=0x01; /* first ending CCW is now active */ /* reset ending CCWs and setup TIC CCWs */ p_end->read1_nop2.cmd_code = CCW_CLAW_CMD_READFF; p_end->read1_nop2.flags = CCW_FLAG_SLI | CCW_FLAG_SKIP; p_last->r_TIC_1.cda = (__u32)__pa(&p_end->read1_nop1); p_last->r_TIC_2.cda = (__u32)__pa(&p_end->read1_nop1); p_end->read1_nop2.cda=0; p_end->read1_nop2.count=1; } if ( privptr-> p_read_active_first ==NULL ) { privptr->p_read_active_first = p_first; /* set new first */ privptr->p_read_active_last = p_last; /* set new last */ } else { /* set up TIC ccw */ temp_ccw.cda= (__u32)__pa(&p_first->read); temp_ccw.count=0; temp_ccw.flags=0; temp_ccw.cmd_code = CCW_CLAW_CMD_TIC; if (p_end->read1) { /* first set of CCW's is chained to the new read */ /* chain, so the second set is chained to the active chain. */ /* Therefore modify the second set to point to the new */ /* read chain set up TIC CCWs */ /* make sure we update the CCW so channel doesn't fetch it */ /* when it's only half done */ memcpy( &p_end->read2_nop2, &temp_ccw , sizeof(struct ccw1)); privptr->p_read_active_last->r_TIC_1.cda= (__u32)__pa(&p_first->read); privptr->p_read_active_last->r_TIC_2.cda= (__u32)__pa(&p_first->read); } else { /* make sure we update the CCW so channel doesn't */ /* fetch it when it is only half done */ memcpy( &p_end->read1_nop2, &temp_ccw , sizeof(struct ccw1)); privptr->p_read_active_last->r_TIC_1.cda= (__u32)__pa(&p_first->read); privptr->p_read_active_last->r_TIC_2.cda= (__u32)__pa(&p_first->read); } /* chain in new set of blocks */ privptr->p_read_active_last->next = p_first; privptr->p_read_active_last=p_last; } /* end of if ( privptr-> p_read_active_first ==NULL) */ CLAW_DBF_TEXT(4, trace, "addexit"); return 0; } /* end of add_claw_reads */ /*-------------------------------------------------------------------* * ccw_check_return_code * * * *-------------------------------------------------------------------*/ static void ccw_check_return_code(struct ccw_device *cdev, int return_code) { CLAW_DBF_TEXT(4, trace, "ccwret"); if (return_code != 0) { switch (return_code) { case -EBUSY: /* BUSY is a transient state no action needed */ break; case -ENODEV: dev_err(&cdev->dev, "The remote channel adapter is not" " available\n"); break; case -EINVAL: dev_err(&cdev->dev, "The status of the remote channel adapter" " is not valid\n"); break; default: dev_err(&cdev->dev, "The common device layer" " returned error code %d\n", return_code); } } CLAW_DBF_TEXT(4, trace, "ccwret"); } /* end of ccw_check_return_code */ /*-------------------------------------------------------------------* * ccw_check_unit_check * *--------------------------------------------------------------------*/ static void ccw_check_unit_check(struct chbk * p_ch, unsigned char sense ) { struct net_device *ndev = p_ch->ndev; struct device *dev = &p_ch->cdev->dev; CLAW_DBF_TEXT(4, trace, "unitchek"); dev_warn(dev, "The communication peer of %s disconnected\n", ndev->name); if (sense & 0x40) { if (sense & 0x01) { dev_warn(dev, "The remote channel adapter for" " %s has been reset\n", ndev->name); } } else if (sense & 0x20) { if (sense & 0x04) { dev_warn(dev, "A data streaming timeout occurred" " for %s\n", ndev->name); } else if (sense & 0x10) { dev_warn(dev, "The remote channel adapter for %s" " is faulty\n", ndev->name); } else { dev_warn(dev, "A data transfer parity error occurred" " for %s\n", ndev->name); } } else if (sense & 0x10) { dev_warn(dev, "A read data parity error occurred" " for %s\n", ndev->name); } } /* end of ccw_check_unit_check */ /*-------------------------------------------------------------------* * find_link * *--------------------------------------------------------------------*/ static int find_link(struct net_device *dev, char *host_name, char *ws_name ) { struct claw_privbk *privptr; struct claw_env *p_env; int rc=0; CLAW_DBF_TEXT(2, setup, "findlink"); privptr = dev->ml_priv; p_env=privptr->p_env; switch (p_env->packing) { case PACKING_ASK: if ((memcmp(WS_APPL_NAME_PACKED, host_name, 8)!=0) || (memcmp(WS_APPL_NAME_PACKED, ws_name, 8)!=0 )) rc = EINVAL; break; case DO_PACKED: case PACK_SEND: if ((memcmp(WS_APPL_NAME_IP_NAME, host_name, 8)!=0) || (memcmp(WS_APPL_NAME_IP_NAME, ws_name, 8)!=0 )) rc = EINVAL; break; default: if ((memcmp(HOST_APPL_NAME, host_name, 8)!=0) || (memcmp(p_env->api_type , ws_name, 8)!=0)) rc = EINVAL; break; } return rc; } /* end of find_link */ /*-------------------------------------------------------------------* * claw_hw_tx * * * * * *-------------------------------------------------------------------*/ static int claw_hw_tx(struct sk_buff *skb, struct net_device *dev, long linkid) { int rc=0; struct claw_privbk *privptr; struct ccwbk *p_this_ccw; struct ccwbk *p_first_ccw; struct ccwbk *p_last_ccw; __u32 numBuffers; signed long len_of_data; unsigned long bytesInThisBuffer; unsigned char *pDataAddress; struct endccw *pEnd; struct ccw1 tempCCW; struct claw_env *p_env; struct clawph *pk_head; struct chbk *ch; CLAW_DBF_TEXT(4, trace, "hw_tx"); privptr = (struct claw_privbk *)(dev->ml_priv); p_env =privptr->p_env; claw_free_wrt_buf(dev); /* Clean up free chain if posible */ /* scan the write queue to free any completed write packets */ p_first_ccw=NULL; p_last_ccw=NULL; if ((p_env->packing >= PACK_SEND) && (skb->cb[1] != 'P')) { skb_push(skb,sizeof(struct clawph)); pk_head=(struct clawph *)skb->data; pk_head->len=skb->len-sizeof(struct clawph); if (pk_head->len%4) { pk_head->len+= 4-(pk_head->len%4); skb_pad(skb,4-(pk_head->len%4)); skb_put(skb,4-(pk_head->len%4)); } if (p_env->packing == DO_PACKED) pk_head->link_num = linkid; else pk_head->link_num = 0; pk_head->flag = 0x00; skb_pad(skb,4); skb->cb[1] = 'P'; } if (linkid == 0) { if (claw_check_busy(dev)) { if (privptr->write_free_count!=0) { claw_clear_busy(dev); } else { claw_strt_out_IO(dev ); claw_free_wrt_buf( dev ); if (privptr->write_free_count==0) { ch = &privptr->channel[WRITE_CHANNEL]; atomic_inc(&skb->users); skb_queue_tail(&ch->collect_queue, skb); goto Done; } else { claw_clear_busy(dev); } } } /* tx lock */ if (claw_test_and_setbit_busy(TB_TX,dev)) { /* set to busy */ ch = &privptr->channel[WRITE_CHANNEL]; atomic_inc(&skb->users); skb_queue_tail(&ch->collect_queue, skb); claw_strt_out_IO(dev ); rc=-EBUSY; goto Done2; } } /* See how many write buffers are required to hold this data */ numBuffers = DIV_ROUND_UP(skb->len, privptr->p_env->write_size); /* If that number of buffers isn't available, give up for now */ if (privptr->write_free_count < numBuffers || privptr->p_write_free_chain == NULL ) { claw_setbit_busy(TB_NOBUFFER,dev); ch = &privptr->channel[WRITE_CHANNEL]; atomic_inc(&skb->users); skb_queue_tail(&ch->collect_queue, skb); CLAW_DBF_TEXT(2, trace, "clawbusy"); goto Done2; } pDataAddress=skb->data; len_of_data=skb->len; while (len_of_data > 0) { p_this_ccw=privptr->p_write_free_chain; /* get a block */ if (p_this_ccw == NULL) { /* lost the race */ ch = &privptr->channel[WRITE_CHANNEL]; atomic_inc(&skb->users); skb_queue_tail(&ch->collect_queue, skb); goto Done2; } privptr->p_write_free_chain=p_this_ccw->next; p_this_ccw->next=NULL; --privptr->write_free_count; /* -1 */ if (len_of_data >= privptr->p_env->write_size) bytesInThisBuffer = privptr->p_env->write_size; else bytesInThisBuffer = len_of_data; memcpy( p_this_ccw->p_buffer,pDataAddress, bytesInThisBuffer); len_of_data-=bytesInThisBuffer; pDataAddress+=(unsigned long)bytesInThisBuffer; /* setup write CCW */ p_this_ccw->write.cmd_code = (linkid * 8) +1; if (len_of_data>0) { p_this_ccw->write.cmd_code+=MORE_to_COME_FLAG; } p_this_ccw->write.count=bytesInThisBuffer; /* now add to end of this chain */ if (p_first_ccw==NULL) { p_first_ccw=p_this_ccw; } if (p_last_ccw!=NULL) { p_last_ccw->next=p_this_ccw; /* set up TIC ccws */ p_last_ccw->w_TIC_1.cda= (__u32)__pa(&p_this_ccw->write); } p_last_ccw=p_this_ccw; /* save new last block */ } /* FirstCCW and LastCCW now contain a new set of write channel * programs to append to the running channel program */ if (p_first_ccw!=NULL) { /* setup ending ccw sequence for this segment */ pEnd=privptr->p_end_ccw; if (pEnd->write1) { pEnd->write1=0x00; /* second end ccw is now active */ /* set up Tic CCWs */ p_last_ccw->w_TIC_1.cda= (__u32)__pa(&pEnd->write2_nop1); pEnd->write2_nop2.cmd_code = CCW_CLAW_CMD_READFF; pEnd->write2_nop2.flags = CCW_FLAG_SLI | CCW_FLAG_SKIP; pEnd->write2_nop2.cda=0; pEnd->write2_nop2.count=1; } else { /* end of if (pEnd->write1)*/ pEnd->write1=0x01; /* first end ccw is now active */ /* set up Tic CCWs */ p_last_ccw->w_TIC_1.cda= (__u32)__pa(&pEnd->write1_nop1); pEnd->write1_nop2.cmd_code = CCW_CLAW_CMD_READFF; pEnd->write1_nop2.flags = CCW_FLAG_SLI | CCW_FLAG_SKIP; pEnd->write1_nop2.cda=0; pEnd->write1_nop2.count=1; } /* end if if (pEnd->write1) */ if (privptr->p_write_active_first==NULL ) { privptr->p_write_active_first=p_first_ccw; privptr->p_write_active_last=p_last_ccw; } else { /* set up Tic CCWs */ tempCCW.cda=(__u32)__pa(&p_first_ccw->write); tempCCW.count=0; tempCCW.flags=0; tempCCW.cmd_code=CCW_CLAW_CMD_TIC; if (pEnd->write1) { /* * first set of ending CCW's is chained to the new write * chain, so the second set is chained to the active chain * Therefore modify the second set to point the new write chain. * make sure we update the CCW atomically * so channel does not fetch it when it's only half done */ memcpy( &pEnd->write2_nop2, &tempCCW , sizeof(struct ccw1)); privptr->p_write_active_last->w_TIC_1.cda= (__u32)__pa(&p_first_ccw->write); } else { /*make sure we update the CCW atomically *so channel does not fetch it when it's only half done */ memcpy(&pEnd->write1_nop2, &tempCCW , sizeof(struct ccw1)); privptr->p_write_active_last->w_TIC_1.cda= (__u32)__pa(&p_first_ccw->write); } /* end if if (pEnd->write1) */ privptr->p_write_active_last->next=p_first_ccw; privptr->p_write_active_last=p_last_ccw; } } /* endif (p_first_ccw!=NULL) */ dev_kfree_skb_any(skb); claw_strt_out_IO(dev ); /* if write free count is zero , set NOBUFFER */ if (privptr->write_free_count==0) { claw_setbit_busy(TB_NOBUFFER,dev); } Done2: claw_clearbit_busy(TB_TX,dev); Done: return(rc); } /* end of claw_hw_tx */ /*-------------------------------------------------------------------* * * * init_ccw_bk * * * *--------------------------------------------------------------------*/ static int init_ccw_bk(struct net_device *dev) { __u32 ccw_blocks_required; __u32 ccw_blocks_perpage; __u32 ccw_pages_required; __u32 claw_reads_perpage=1; __u32 claw_read_pages; __u32 claw_writes_perpage=1; __u32 claw_write_pages; void *p_buff=NULL; struct ccwbk*p_free_chain; struct ccwbk*p_buf; struct ccwbk*p_last_CCWB; struct ccwbk*p_first_CCWB; struct endccw *p_endccw=NULL; addr_t real_address; struct claw_privbk *privptr = dev->ml_priv; struct clawh *pClawH=NULL; addr_t real_TIC_address; int i,j; CLAW_DBF_TEXT(4, trace, "init_ccw"); /* initialize statistics field */ privptr->active_link_ID=0; /* initialize ccwbk pointers */ privptr->p_write_free_chain=NULL; /* pointer to free ccw chain*/ privptr->p_write_active_first=NULL; /* pointer to the first write ccw*/ privptr->p_write_active_last=NULL; /* pointer to the last write ccw*/ privptr->p_read_active_first=NULL; /* pointer to the first read ccw*/ privptr->p_read_active_last=NULL; /* pointer to the last read ccw */ privptr->p_end_ccw=NULL; /* pointer to ending ccw */ privptr->p_claw_signal_blk=NULL; /* pointer to signal block */ privptr->buffs_alloc = 0; memset(&privptr->end_ccw, 0x00, sizeof(struct endccw)); memset(&privptr->ctl_bk, 0x00, sizeof(struct clawctl)); /* initialize free write ccwbk counter */ privptr->write_free_count=0; /* number of free bufs on write chain */ p_last_CCWB = NULL; p_first_CCWB= NULL; /* * We need 1 CCW block for each read buffer, 1 for each * write buffer, plus 1 for ClawSignalBlock */ ccw_blocks_required = privptr->p_env->read_buffers+privptr->p_env->write_buffers+1; /* * compute number of CCW blocks that will fit in a page */ ccw_blocks_perpage= PAGE_SIZE / CCWBK_SIZE; ccw_pages_required= DIV_ROUND_UP(ccw_blocks_required, ccw_blocks_perpage); /* * read and write sizes are set by 2 constants in claw.h * 4k and 32k. Unpacked values other than 4k are not going to * provide good performance. With packing buffers support 32k * buffers are used. */ if (privptr->p_env->read_size < PAGE_SIZE) { claw_reads_perpage = PAGE_SIZE / privptr->p_env->read_size; claw_read_pages = DIV_ROUND_UP(privptr->p_env->read_buffers, claw_reads_perpage); } else { /* > or equal */ privptr->p_buff_pages_perread = DIV_ROUND_UP(privptr->p_env->read_size, PAGE_SIZE); claw_read_pages = privptr->p_env->read_buffers * privptr->p_buff_pages_perread; } if (privptr->p_env->write_size < PAGE_SIZE) { claw_writes_perpage = PAGE_SIZE / privptr->p_env->write_size; claw_write_pages = DIV_ROUND_UP(privptr->p_env->write_buffers, claw_writes_perpage); } else { /* > or equal */ privptr->p_buff_pages_perwrite = DIV_ROUND_UP(privptr->p_env->read_size, PAGE_SIZE); claw_write_pages = privptr->p_env->write_buffers * privptr->p_buff_pages_perwrite; } /* * allocate ccw_pages_required */ if (privptr->p_buff_ccw==NULL) { privptr->p_buff_ccw= (void *)__get_free_pages(__GFP_DMA, (int)pages_to_order_of_mag(ccw_pages_required )); if (privptr->p_buff_ccw==NULL) { return -ENOMEM; } privptr->p_buff_ccw_num=ccw_pages_required; } memset(privptr->p_buff_ccw, 0x00, privptr->p_buff_ccw_num * PAGE_SIZE); /* * obtain ending ccw block address * */ privptr->p_end_ccw = (struct endccw *)&privptr->end_ccw; real_address = (__u32)__pa(privptr->p_end_ccw); /* Initialize ending CCW block */ p_endccw=privptr->p_end_ccw; p_endccw->real=real_address; p_endccw->write1=0x00; p_endccw->read1=0x00; /* write1_nop1 */ p_endccw->write1_nop1.cmd_code = CCW_CLAW_CMD_NOP; p_endccw->write1_nop1.flags = CCW_FLAG_SLI | CCW_FLAG_CC; p_endccw->write1_nop1.count = 1; p_endccw->write1_nop1.cda = 0; /* write1_nop2 */ p_endccw->write1_nop2.cmd_code = CCW_CLAW_CMD_READFF; p_endccw->write1_nop2.flags = CCW_FLAG_SLI | CCW_FLAG_SKIP; p_endccw->write1_nop2.count = 1; p_endccw->write1_nop2.cda = 0; /* write2_nop1 */ p_endccw->write2_nop1.cmd_code = CCW_CLAW_CMD_NOP; p_endccw->write2_nop1.flags = CCW_FLAG_SLI | CCW_FLAG_CC; p_endccw->write2_nop1.count = 1; p_endccw->write2_nop1.cda = 0; /* write2_nop2 */ p_endccw->write2_nop2.cmd_code = CCW_CLAW_CMD_READFF; p_endccw->write2_nop2.flags = CCW_FLAG_SLI | CCW_FLAG_SKIP; p_endccw->write2_nop2.count = 1; p_endccw->write2_nop2.cda = 0; /* read1_nop1 */ p_endccw->read1_nop1.cmd_code = CCW_CLAW_CMD_NOP; p_endccw->read1_nop1.flags = CCW_FLAG_SLI | CCW_FLAG_CC; p_endccw->read1_nop1.count = 1; p_endccw->read1_nop1.cda = 0; /* read1_nop2 */ p_endccw->read1_nop2.cmd_code = CCW_CLAW_CMD_READFF; p_endccw->read1_nop2.flags = CCW_FLAG_SLI | CCW_FLAG_SKIP; p_endccw->read1_nop2.count = 1; p_endccw->read1_nop2.cda = 0; /* read2_nop1 */ p_endccw->read2_nop1.cmd_code = CCW_CLAW_CMD_NOP; p_endccw->read2_nop1.flags = CCW_FLAG_SLI | CCW_FLAG_CC; p_endccw->read2_nop1.count = 1; p_endccw->read2_nop1.cda = 0; /* read2_nop2 */ p_endccw->read2_nop2.cmd_code = CCW_CLAW_CMD_READFF; p_endccw->read2_nop2.flags = CCW_FLAG_SLI | CCW_FLAG_SKIP; p_endccw->read2_nop2.count = 1; p_endccw->read2_nop2.cda = 0; /* * Build a chain of CCWs * */ p_buff=privptr->p_buff_ccw; p_free_chain=NULL; for (i=0 ; i < ccw_pages_required; i++ ) { real_address = (__u32)__pa(p_buff); p_buf=p_buff; for (j=0 ; j < ccw_blocks_perpage ; j++) { p_buf->next = p_free_chain; p_free_chain = p_buf; p_buf->real=(__u32)__pa(p_buf); ++p_buf; } p_buff+=PAGE_SIZE; } /* * Initialize ClawSignalBlock * */ if (privptr->p_claw_signal_blk==NULL) { privptr->p_claw_signal_blk=p_free_chain; p_free_chain=p_free_chain->next; pClawH=(struct clawh *)privptr->p_claw_signal_blk; pClawH->length=0xffff; pClawH->opcode=0xff; pClawH->flag=CLAW_BUSY; } /* * allocate write_pages_required and add to free chain */ if (privptr->p_buff_write==NULL) { if (privptr->p_env->write_size < PAGE_SIZE) { privptr->p_buff_write= (void *)__get_free_pages(__GFP_DMA, (int)pages_to_order_of_mag(claw_write_pages )); if (privptr->p_buff_write==NULL) { privptr->p_buff_ccw=NULL; return -ENOMEM; } /* * Build CLAW write free chain * */ memset(privptr->p_buff_write, 0x00, ccw_pages_required * PAGE_SIZE); privptr->p_write_free_chain=NULL; p_buff=privptr->p_buff_write; for (i=0 ; i< privptr->p_env->write_buffers ; i++) { p_buf = p_free_chain; /* get a CCW */ p_free_chain = p_buf->next; p_buf->next =privptr->p_write_free_chain; privptr->p_write_free_chain = p_buf; p_buf-> p_buffer = (struct clawbuf *)p_buff; p_buf-> write.cda = (__u32)__pa(p_buff); p_buf-> write.flags = CCW_FLAG_SLI | CCW_FLAG_CC; p_buf-> w_read_FF.cmd_code = CCW_CLAW_CMD_READFF; p_buf-> w_read_FF.flags = CCW_FLAG_SLI | CCW_FLAG_CC; p_buf-> w_read_FF.count = 1; p_buf-> w_read_FF.cda = (__u32)__pa(&p_buf-> header.flag); p_buf-> w_TIC_1.cmd_code = CCW_CLAW_CMD_TIC; p_buf-> w_TIC_1.flags = 0; p_buf-> w_TIC_1.count = 0; if (((unsigned long)p_buff + privptr->p_env->write_size) >= ((unsigned long)(p_buff+2* (privptr->p_env->write_size) - 1) & PAGE_MASK)) { p_buff = p_buff+privptr->p_env->write_size; } } } else /* Buffers are => PAGE_SIZE. 1 buff per get_free_pages */ { privptr->p_write_free_chain=NULL; for (i = 0; i< privptr->p_env->write_buffers ; i++) { p_buff=(void *)__get_free_pages(__GFP_DMA, (int)pages_to_order_of_mag( privptr->p_buff_pages_perwrite) ); if (p_buff==NULL) { free_pages((unsigned long)privptr->p_buff_ccw, (int)pages_to_order_of_mag( privptr->p_buff_ccw_num)); privptr->p_buff_ccw=NULL; p_buf=privptr->p_buff_write; while (p_buf!=NULL) { free_pages((unsigned long) p_buf->p_buffer, (int)pages_to_order_of_mag( privptr->p_buff_pages_perwrite)); p_buf=p_buf->next; } return -ENOMEM; } /* Error on get_pages */ memset(p_buff, 0x00, privptr->p_env->write_size ); p_buf = p_free_chain; p_free_chain = p_buf->next; p_buf->next = privptr->p_write_free_chain; privptr->p_write_free_chain = p_buf; privptr->p_buff_write = p_buf; p_buf->p_buffer=(struct clawbuf *)p_buff; p_buf-> write.cda = (__u32)__pa(p_buff); p_buf-> write.flags = CCW_FLAG_SLI | CCW_FLAG_CC; p_buf-> w_read_FF.cmd_code = CCW_CLAW_CMD_READFF; p_buf-> w_read_FF.flags = CCW_FLAG_SLI | CCW_FLAG_CC; p_buf-> w_read_FF.count = 1; p_buf-> w_read_FF.cda = (__u32)__pa(&p_buf-> header.flag); p_buf-> w_TIC_1.cmd_code = CCW_CLAW_CMD_TIC; p_buf-> w_TIC_1.flags = 0; p_buf-> w_TIC_1.count = 0; } /* for all write_buffers */ } /* else buffers are PAGE_SIZE or bigger */ } privptr->p_buff_write_num=claw_write_pages; privptr->write_free_count=privptr->p_env->write_buffers; /* * allocate read_pages_required and chain to free chain */ if (privptr->p_buff_read==NULL) { if (privptr->p_env->read_size < PAGE_SIZE) { privptr->p_buff_read= (void *)__get_free_pages(__GFP_DMA, (int)pages_to_order_of_mag(claw_read_pages) ); if (privptr->p_buff_read==NULL) { free_pages((unsigned long)privptr->p_buff_ccw, (int)pages_to_order_of_mag( privptr->p_buff_ccw_num)); /* free the write pages size is < page size */ free_pages((unsigned long)privptr->p_buff_write, (int)pages_to_order_of_mag( privptr->p_buff_write_num)); privptr->p_buff_ccw=NULL; privptr->p_buff_write=NULL; return -ENOMEM; } memset(privptr->p_buff_read, 0x00, claw_read_pages * PAGE_SIZE); privptr->p_buff_read_num=claw_read_pages; /* * Build CLAW read free chain * */ p_buff=privptr->p_buff_read; for (i=0 ; i< privptr->p_env->read_buffers ; i++) { p_buf = p_free_chain; p_free_chain = p_buf->next; if (p_last_CCWB==NULL) { p_buf->next=NULL; real_TIC_address=0; p_last_CCWB=p_buf; } else { p_buf->next=p_first_CCWB; real_TIC_address= (__u32)__pa(&p_first_CCWB -> read ); }