/*1* Copyright (C) 1992-1997, 2000-2003 Silicon Graphics, Inc.2* Copyright (C) 2004 Christoph Hellwig.3* Released under GPL v2.4*5* Support functions for the HUB ASIC - mostly PIO mapping related.6*/78#include <linux/bitops.h>9#include <linux/string.h>10#include <linux/mmzone.h>11#include <asm/sn/addrs.h>12#include <asm/sn/arch.h>13#include <asm/sn/hub.h>141516static int force_fire_and_forget = 1;1718/**19* hub_pio_map - establish a HUB PIO mapping20*21* @hub: hub to perform PIO mapping on22* @widget: widget ID to perform PIO mapping for23* @xtalk_addr: xtalk_address that needs to be mapped24* @size: size of the PIO mapping25*26**/27unsigned long hub_pio_map(cnodeid_t cnode, xwidgetnum_t widget,28unsigned long xtalk_addr, size_t size)29{30nasid_t nasid = COMPACT_TO_NASID_NODEID(cnode);31unsigned i;3233/* use small-window mapping if possible */34if ((xtalk_addr % SWIN_SIZE) + size <= SWIN_SIZE)35return NODE_SWIN_BASE(nasid, widget) + (xtalk_addr % SWIN_SIZE);3637if ((xtalk_addr % BWIN_SIZE) + size > BWIN_SIZE) {38printk(KERN_WARNING "PIO mapping at hub %d widget %d addr 0x%lx"39" too big (%ld)\n",40nasid, widget, xtalk_addr, size);41return 0;42}4344xtalk_addr &= ~(BWIN_SIZE-1);45for (i = 0; i < HUB_NUM_BIG_WINDOW; i++) {46if (test_and_set_bit(i, hub_data(cnode)->h_bigwin_used))47continue;4849/*50* The code below does a PIO write to setup an ITTE entry.51*52* We need to prevent other CPUs from seeing our updated53* memory shadow of the ITTE (in the piomap) until the ITTE54* entry is actually set up; otherwise, another CPU might55* attempt a PIO prematurely.56*57* Also, the only way we can know that an entry has been58* received by the hub and can be used by future PIO reads/59* writes is by reading back the ITTE entry after writing it.60*61* For these two reasons, we PIO read back the ITTE entry62* after we write it.63*/64IIO_ITTE_PUT(nasid, i, HUB_PIO_MAP_TO_MEM, widget, xtalk_addr);65(void) HUB_L(IIO_ITTE_GET(nasid, i));6667return NODE_BWIN_BASE(nasid, widget) + (xtalk_addr % BWIN_SIZE);68}6970printk(KERN_WARNING "unable to establish PIO mapping for at"71" hub %d widget %d addr 0x%lx\n",72nasid, widget, xtalk_addr);73return 0;74}757677/*78* hub_setup_prb(nasid, prbnum, credits, conveyor)79*80* Put a PRB into fire-and-forget mode if conveyor isn't set. Otherwise,81* put it into conveyor belt mode with the specified number of credits.82*/83static void hub_setup_prb(nasid_t nasid, int prbnum, int credits)84{85iprb_t prb;86int prb_offset;8788/*89* Get the current register value.90*/91prb_offset = IIO_IOPRB(prbnum);92prb.iprb_regval = REMOTE_HUB_L(nasid, prb_offset);9394/*95* Clear out some fields.96*/97prb.iprb_ovflow = 1;98prb.iprb_bnakctr = 0;99prb.iprb_anakctr = 0;100101/*102* Enable or disable fire-and-forget mode.103*/104prb.iprb_ff = force_fire_and_forget ? 1 : 0;105106/*107* Set the appropriate number of PIO cresits for the widget.108*/109prb.iprb_xtalkctr = credits;110111/*112* Store the new value to the register.113*/114REMOTE_HUB_S(nasid, prb_offset, prb.iprb_regval);115}116117/**118* hub_set_piomode - set pio mode for a given hub119*120* @nasid: physical node ID for the hub in question121*122* Put the hub into either "PIO conveyor belt" mode or "fire-and-forget" mode.123* To do this, we have to make absolutely sure that no PIOs are in progress124* so we turn off access to all widgets for the duration of the function.125*126* XXX - This code should really check what kind of widget we're talking127* to. Bridges can only handle three requests, but XG will do more.128* How many can crossbow handle to widget 0? We're assuming 1.129*130* XXX - There is a bug in the crossbow that link reset PIOs do not131* return write responses. The easiest solution to this problem is to132* leave widget 0 (xbow) in fire-and-forget mode at all times. This133* only affects pio's to xbow registers, which should be rare.134**/135static void hub_set_piomode(nasid_t nasid)136{137hubreg_t ii_iowa;138hubii_wcr_t ii_wcr;139unsigned i;140141ii_iowa = REMOTE_HUB_L(nasid, IIO_OUTWIDGET_ACCESS);142REMOTE_HUB_S(nasid, IIO_OUTWIDGET_ACCESS, 0);143144ii_wcr.wcr_reg_value = REMOTE_HUB_L(nasid, IIO_WCR);145146if (ii_wcr.iwcr_dir_con) {147/*148* Assume a bridge here.149*/150hub_setup_prb(nasid, 0, 3);151} else {152/*153* Assume a crossbow here.154*/155hub_setup_prb(nasid, 0, 1);156}157158/*159* XXX - Here's where we should take the widget type into160* when account assigning credits.161*/162for (i = HUB_WIDGET_ID_MIN; i <= HUB_WIDGET_ID_MAX; i++)163hub_setup_prb(nasid, i, 3);164165REMOTE_HUB_S(nasid, IIO_OUTWIDGET_ACCESS, ii_iowa);166}167168/*169* hub_pio_init - PIO-related hub initialization170*171* @hub: hubinfo structure for our hub172*/173void hub_pio_init(cnodeid_t cnode)174{175nasid_t nasid = COMPACT_TO_NASID_NODEID(cnode);176unsigned i;177178/* initialize big window piomaps for this hub */179bitmap_zero(hub_data(cnode)->h_bigwin_used, HUB_NUM_BIG_WINDOW);180for (i = 0; i < HUB_NUM_BIG_WINDOW; i++)181IIO_ITTE_DISABLE(nasid, i);182183hub_set_piomode(nasid);184}185186187