11534c382SMartin Schwidefsky /* 275014550SHolger Dengler * Copyright IBM Corp. 2006, 2012 31534c382SMartin Schwidefsky * Author(s): Cornelia Huck <cornelia.huck@de.ibm.com> 41534c382SMartin Schwidefsky * Martin Schwidefsky <schwidefsky@de.ibm.com> 51534c382SMartin Schwidefsky * Ralph Wuerthner <rwuerthn@de.ibm.com> 6cb17a636SFelix Beck * Felix Beck <felix.beck@de.ibm.com> 76bed05bcSHolger Dengler * Holger Dengler <hd@linux.vnet.ibm.com> 81534c382SMartin Schwidefsky * 91534c382SMartin Schwidefsky * Adjunct processor bus header file. 101534c382SMartin Schwidefsky * 111534c382SMartin Schwidefsky * This program is free software; you can redistribute it and/or modify 121534c382SMartin Schwidefsky * it under the terms of the GNU General Public License as published by 131534c382SMartin Schwidefsky * the Free Software Foundation; either version 2, or (at your option) 141534c382SMartin Schwidefsky * any later version. 151534c382SMartin Schwidefsky * 161534c382SMartin Schwidefsky * This program is distributed in the hope that it will be useful, 171534c382SMartin Schwidefsky * but WITHOUT ANY WARRANTY; without even the implied warranty of 181534c382SMartin Schwidefsky * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 191534c382SMartin Schwidefsky * GNU General Public License for more details. 201534c382SMartin Schwidefsky * 211534c382SMartin Schwidefsky * You should have received a copy of the GNU General Public License 221534c382SMartin Schwidefsky * along with this program; if not, write to the Free Software 231534c382SMartin Schwidefsky * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 241534c382SMartin Schwidefsky */ 251534c382SMartin Schwidefsky 261534c382SMartin Schwidefsky #ifndef _AP_BUS_H_ 271534c382SMartin Schwidefsky #define _AP_BUS_H_ 281534c382SMartin Schwidefsky 291534c382SMartin Schwidefsky #include <linux/device.h> 301534c382SMartin Schwidefsky #include <linux/mod_devicetable.h> 311534c382SMartin Schwidefsky #include <linux/types.h> 321534c382SMartin Schwidefsky 331534c382SMartin Schwidefsky #define AP_DEVICES 64 /* Number of AP devices. */ 34170387a8SIngo Tuchscherer #define AP_DOMAINS 256 /* Number of AP domains. */ 3591f3e3eaSIngo Tuchscherer #define AP_RESET_TIMEOUT (HZ*0.7) /* Time in ticks for reset timeouts. */ 361534c382SMartin Schwidefsky #define AP_CONFIG_TIME 30 /* Time in seconds between AP bus rescans. */ 371534c382SMartin Schwidefsky #define AP_POLL_TIME 1 /* Time in ticks between receive polls. */ 381534c382SMartin Schwidefsky 39c50a160cSIngo Tuchscherer #define AP_POLL_IMMEDIATELY 1 /* continue running poll tasklet */ 40c50a160cSIngo Tuchscherer #define AP_POLL_AFTER_TIMEOUT 2 /* run poll tasklet again after timout */ 41c50a160cSIngo Tuchscherer 421534c382SMartin Schwidefsky extern int ap_domain_index; 431534c382SMartin Schwidefsky 441534c382SMartin Schwidefsky /** 451534c382SMartin Schwidefsky * The ap_qid_t identifier of an ap queue. It contains a 461534c382SMartin Schwidefsky * 6 bit device index and a 4 bit queue index (domain). 471534c382SMartin Schwidefsky */ 481534c382SMartin Schwidefsky typedef unsigned int ap_qid_t; 491534c382SMartin Schwidefsky 50170387a8SIngo Tuchscherer #define AP_MKQID(_device, _queue) (((_device) & 63) << 8 | ((_queue) & 255)) 511534c382SMartin Schwidefsky #define AP_QID_DEVICE(_qid) (((_qid) >> 8) & 63) 52170387a8SIngo Tuchscherer #define AP_QID_QUEUE(_qid) ((_qid) & 255) 531534c382SMartin Schwidefsky 541534c382SMartin Schwidefsky /** 551749a81dSFelix Beck * structy ap_queue_status - Holds the AP queue status. 561749a81dSFelix Beck * @queue_empty: Shows if queue is empty 571749a81dSFelix Beck * @replies_waiting: Waiting replies 581749a81dSFelix Beck * @queue_full: Is 1 if the queue is full 591749a81dSFelix Beck * @pad: A 4 bit pad 601749a81dSFelix Beck * @int_enabled: Shows if interrupts are enabled for the AP 611749a81dSFelix Beck * @response_conde: Holds the 8 bit response code 621749a81dSFelix Beck * @pad2: A 16 bit pad 631749a81dSFelix Beck * 641534c382SMartin Schwidefsky * The ap queue status word is returned by all three AP functions 651534c382SMartin Schwidefsky * (PQAP, NQAP and DQAP). There's a set of flags in the first 661534c382SMartin Schwidefsky * byte, followed by a 1 byte response code. 671534c382SMartin Schwidefsky */ 681534c382SMartin Schwidefsky struct ap_queue_status { 691534c382SMartin Schwidefsky unsigned int queue_empty : 1; 701534c382SMartin Schwidefsky unsigned int replies_waiting : 1; 711534c382SMartin Schwidefsky unsigned int queue_full : 1; 72cb17a636SFelix Beck unsigned int pad1 : 4; 73cb17a636SFelix Beck unsigned int int_enabled : 1; 741534c382SMartin Schwidefsky unsigned int response_code : 8; 751534c382SMartin Schwidefsky unsigned int pad2 : 16; 766bed05bcSHolger Dengler } __packed; 776bed05bcSHolger Dengler 786bed05bcSHolger Dengler #define AP_QUEUE_STATUS_INVALID \ 796bed05bcSHolger Dengler { 1, 1, 1, 0xF, 1, 0xFF, 0xFFFF } 806bed05bcSHolger Dengler 816bed05bcSHolger Dengler static inline 826bed05bcSHolger Dengler int ap_queue_status_invalid_test(struct ap_queue_status *status) 836bed05bcSHolger Dengler { 846bed05bcSHolger Dengler struct ap_queue_status invalid = AP_QUEUE_STATUS_INVALID; 856bed05bcSHolger Dengler return !(memcmp(status, &invalid, sizeof(struct ap_queue_status))); 866bed05bcSHolger Dengler } 876bed05bcSHolger Dengler 8875014550SHolger Dengler #define AP_MAX_BITS 31 8975014550SHolger Dengler static inline int ap_test_bit(unsigned int *ptr, unsigned int nr) 906bed05bcSHolger Dengler { 9175014550SHolger Dengler if (nr > AP_MAX_BITS) 926bed05bcSHolger Dengler return 0; 9375014550SHolger Dengler return (*ptr & (0x80000000u >> nr)) != 0; 946bed05bcSHolger Dengler } 951534c382SMartin Schwidefsky 961534c382SMartin Schwidefsky #define AP_RESPONSE_NORMAL 0x00 971534c382SMartin Schwidefsky #define AP_RESPONSE_Q_NOT_AVAIL 0x01 981534c382SMartin Schwidefsky #define AP_RESPONSE_RESET_IN_PROGRESS 0x02 991534c382SMartin Schwidefsky #define AP_RESPONSE_DECONFIGURED 0x03 1001534c382SMartin Schwidefsky #define AP_RESPONSE_CHECKSTOPPED 0x04 1011534c382SMartin Schwidefsky #define AP_RESPONSE_BUSY 0x05 102cb17a636SFelix Beck #define AP_RESPONSE_INVALID_ADDRESS 0x06 103cb17a636SFelix Beck #define AP_RESPONSE_OTHERWISE_CHANGED 0x07 1041534c382SMartin Schwidefsky #define AP_RESPONSE_Q_FULL 0x10 1051534c382SMartin Schwidefsky #define AP_RESPONSE_NO_PENDING_REPLY 0x10 1061534c382SMartin Schwidefsky #define AP_RESPONSE_INDEX_TOO_BIG 0x11 1071534c382SMartin Schwidefsky #define AP_RESPONSE_NO_FIRST_PART 0x13 1081534c382SMartin Schwidefsky #define AP_RESPONSE_MESSAGE_TOO_BIG 0x15 109a6a5d73aSFelix Beck #define AP_RESPONSE_REQ_FAC_NOT_INST 0x16 1101534c382SMartin Schwidefsky 1111749a81dSFelix Beck /* 1121534c382SMartin Schwidefsky * Known device types 1131534c382SMartin Schwidefsky */ 1141534c382SMartin Schwidefsky #define AP_DEVICE_TYPE_PCICC 3 1151534c382SMartin Schwidefsky #define AP_DEVICE_TYPE_PCICA 4 1161534c382SMartin Schwidefsky #define AP_DEVICE_TYPE_PCIXCC 5 1171534c382SMartin Schwidefsky #define AP_DEVICE_TYPE_CEX2A 6 1181534c382SMartin Schwidefsky #define AP_DEVICE_TYPE_CEX2C 7 119ffda4f71SFelix Beck #define AP_DEVICE_TYPE_CEX3A 8 120ffda4f71SFelix Beck #define AP_DEVICE_TYPE_CEX3C 9 1211e2076f4SHolger Dengler #define AP_DEVICE_TYPE_CEX4 10 122bdea1f1bSIngo Tuchscherer #define AP_DEVICE_TYPE_CEX5 11 1231534c382SMartin Schwidefsky 1241749a81dSFelix Beck /* 125b26bd941SHolger Dengler * Known function facilities 126b26bd941SHolger Dengler */ 127b26bd941SHolger Dengler #define AP_FUNC_MEX4K 1 128b26bd941SHolger Dengler #define AP_FUNC_CRT4K 2 129b26bd941SHolger Dengler #define AP_FUNC_COPRO 3 130b26bd941SHolger Dengler #define AP_FUNC_ACCEL 4 13191f3e3eaSIngo Tuchscherer #define AP_FUNC_EP11 5 13291f3e3eaSIngo Tuchscherer #define AP_FUNC_APXA 6 133b26bd941SHolger Dengler 134b26bd941SHolger Dengler /* 135af512ed0SRalph Wuerthner * AP reset flag states 136af512ed0SRalph Wuerthner */ 137af512ed0SRalph Wuerthner #define AP_RESET_IGNORE 0 /* request timeout will be ignored */ 138af512ed0SRalph Wuerthner #define AP_RESET_ARMED 1 /* request timeout timer is active */ 139af512ed0SRalph Wuerthner #define AP_RESET_DO 2 /* AP reset required */ 140c50a160cSIngo Tuchscherer #define AP_RESET_IN_PROGRESS 3 /* AP reset in progress */ 141c50a160cSIngo Tuchscherer 142c50a160cSIngo Tuchscherer /* 143c50a160cSIngo Tuchscherer * AP interrupt states 144c50a160cSIngo Tuchscherer */ 145c50a160cSIngo Tuchscherer #define AP_INTR_DISABLED 0 /* AP interrupt disabled */ 146c50a160cSIngo Tuchscherer #define AP_INTR_ENABLED 1 /* AP interrupt enabled */ 147c50a160cSIngo Tuchscherer #define AP_INTR_IN_PROGRESS 3 /* AP interrupt in progress */ 148af512ed0SRalph Wuerthner 1491534c382SMartin Schwidefsky struct ap_device; 1501534c382SMartin Schwidefsky struct ap_message; 1511534c382SMartin Schwidefsky 1521534c382SMartin Schwidefsky struct ap_driver { 1531534c382SMartin Schwidefsky struct device_driver driver; 1541534c382SMartin Schwidefsky struct ap_device_id *ids; 1551534c382SMartin Schwidefsky 1561534c382SMartin Schwidefsky int (*probe)(struct ap_device *); 1571534c382SMartin Schwidefsky void (*remove)(struct ap_device *); 158af512ed0SRalph Wuerthner int request_timeout; /* request timeout in jiffies */ 1591534c382SMartin Schwidefsky }; 1601534c382SMartin Schwidefsky 1611534c382SMartin Schwidefsky #define to_ap_drv(x) container_of((x), struct ap_driver, driver) 1621534c382SMartin Schwidefsky 1631534c382SMartin Schwidefsky int ap_driver_register(struct ap_driver *, struct module *, char *); 1641534c382SMartin Schwidefsky void ap_driver_unregister(struct ap_driver *); 1651534c382SMartin Schwidefsky 1661534c382SMartin Schwidefsky struct ap_device { 1671534c382SMartin Schwidefsky struct device device; 1681534c382SMartin Schwidefsky struct ap_driver *drv; /* Pointer to AP device driver. */ 1691534c382SMartin Schwidefsky spinlock_t lock; /* Per device lock. */ 170cf352ce0SRalph Wuerthner struct list_head list; /* private list of all AP devices. */ 1711534c382SMartin Schwidefsky 1721534c382SMartin Schwidefsky ap_qid_t qid; /* AP queue id. */ 1731534c382SMartin Schwidefsky int queue_depth; /* AP queue depth.*/ 1741534c382SMartin Schwidefsky int device_type; /* AP device type. */ 17542f4dd61SIngo Tuchscherer int raw_hwtype; /* AP raw hardware type. */ 176b26bd941SHolger Dengler unsigned int functions; /* AP device function bitfield. */ 1771534c382SMartin Schwidefsky int unregistered; /* marks AP device as unregistered */ 178af512ed0SRalph Wuerthner struct timer_list timeout; /* Timer for request timeouts. */ 179af512ed0SRalph Wuerthner int reset; /* Reset required after req. timeout. */ 1801534c382SMartin Schwidefsky 181c50a160cSIngo Tuchscherer int interrupt; /* indicate if interrupts are enabled */ 1821534c382SMartin Schwidefsky int queue_count; /* # messages currently on AP queue. */ 1831534c382SMartin Schwidefsky 1841534c382SMartin Schwidefsky struct list_head pendingq; /* List of message sent to AP queue. */ 1851534c382SMartin Schwidefsky int pendingq_count; /* # requests on pendingq list. */ 1861534c382SMartin Schwidefsky struct list_head requestq; /* List of message yet to be sent. */ 1871534c382SMartin Schwidefsky int requestq_count; /* # requests on requestq list. */ 1881534c382SMartin Schwidefsky int total_request_count; /* # requests ever for this AP device. */ 1891534c382SMartin Schwidefsky 1901534c382SMartin Schwidefsky struct ap_message *reply; /* Per device reply message. */ 1911534c382SMartin Schwidefsky 1921534c382SMartin Schwidefsky void *private; /* ap driver private pointer. */ 1931534c382SMartin Schwidefsky }; 1941534c382SMartin Schwidefsky 1951534c382SMartin Schwidefsky #define to_ap_dev(x) container_of((x), struct ap_device, device) 1961534c382SMartin Schwidefsky 1971534c382SMartin Schwidefsky struct ap_message { 1981534c382SMartin Schwidefsky struct list_head list; /* Request queueing. */ 1991534c382SMartin Schwidefsky unsigned long long psmid; /* Message id. */ 2001534c382SMartin Schwidefsky void *message; /* Pointer to message buffer. */ 2011534c382SMartin Schwidefsky size_t length; /* Message length. */ 2021534c382SMartin Schwidefsky 2031534c382SMartin Schwidefsky void *private; /* ap driver private pointer. */ 204a6a5d73aSFelix Beck unsigned int special:1; /* Used for special commands. */ 20554a8f561SHolger Dengler /* receive is called from tasklet context */ 20654a8f561SHolger Dengler void (*receive)(struct ap_device *, struct ap_message *, 20754a8f561SHolger Dengler struct ap_message *); 2081534c382SMartin Schwidefsky }; 2091534c382SMartin Schwidefsky 21075014550SHolger Dengler struct ap_config_info { 21175014550SHolger Dengler unsigned int special_command:1; 21275014550SHolger Dengler unsigned int ap_extended:1; 21375014550SHolger Dengler unsigned char reserved1:6; 21475014550SHolger Dengler unsigned char reserved2[15]; 21575014550SHolger Dengler unsigned int apm[8]; /* AP ID mask */ 21675014550SHolger Dengler unsigned int aqm[8]; /* AP queue mask */ 21775014550SHolger Dengler unsigned int adm[8]; /* AP domain mask */ 21875014550SHolger Dengler unsigned char reserved4[16]; 21975014550SHolger Dengler } __packed; 22075014550SHolger Dengler 2211534c382SMartin Schwidefsky #define AP_DEVICE(dt) \ 2221534c382SMartin Schwidefsky .dev_type=(dt), \ 2231534c382SMartin Schwidefsky .match_flags=AP_DEVICE_ID_MATCH_DEVICE_TYPE, 2241534c382SMartin Schwidefsky 225468ffddfSFelix Beck /** 226468ffddfSFelix Beck * ap_init_message() - Initialize ap_message. 227468ffddfSFelix Beck * Initialize a message before using. Otherwise this might result in 228468ffddfSFelix Beck * unexpected behaviour. 229468ffddfSFelix Beck */ 230468ffddfSFelix Beck static inline void ap_init_message(struct ap_message *ap_msg) 231468ffddfSFelix Beck { 232468ffddfSFelix Beck ap_msg->psmid = 0; 233468ffddfSFelix Beck ap_msg->length = 0; 234a6a5d73aSFelix Beck ap_msg->special = 0; 23554a8f561SHolger Dengler ap_msg->receive = NULL; 236468ffddfSFelix Beck } 237468ffddfSFelix Beck 2381749a81dSFelix Beck /* 2391534c382SMartin Schwidefsky * Note: don't use ap_send/ap_recv after using ap_queue_message 2401534c382SMartin Schwidefsky * for the first time. Otherwise the ap message queue will get 2411534c382SMartin Schwidefsky * confused. 2421534c382SMartin Schwidefsky */ 2431534c382SMartin Schwidefsky int ap_send(ap_qid_t, unsigned long long, void *, size_t); 2441534c382SMartin Schwidefsky int ap_recv(ap_qid_t, unsigned long long *, void *, size_t); 2451534c382SMartin Schwidefsky 2461534c382SMartin Schwidefsky void ap_queue_message(struct ap_device *ap_dev, struct ap_message *ap_msg); 2471534c382SMartin Schwidefsky void ap_cancel_message(struct ap_device *ap_dev, struct ap_message *ap_msg); 2481534c382SMartin Schwidefsky void ap_flush_queue(struct ap_device *ap_dev); 249dabecb29SHolger Dengler void ap_bus_force_rescan(void); 2501534c382SMartin Schwidefsky 2511534c382SMartin Schwidefsky int ap_module_init(void); 2521534c382SMartin Schwidefsky void ap_module_exit(void); 2531534c382SMartin Schwidefsky 2541534c382SMartin Schwidefsky #endif /* _AP_BUS_H_ */ 255