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. */ 351534c382SMartin Schwidefsky #define AP_MAX_RESET 90 /* Maximum number of resets. */ 3691f3e3eaSIngo Tuchscherer #define AP_RESET_TIMEOUT (HZ*0.7) /* Time in ticks for reset timeouts. */ 371534c382SMartin Schwidefsky #define AP_CONFIG_TIME 30 /* Time in seconds between AP bus rescans. */ 381534c382SMartin Schwidefsky #define AP_POLL_TIME 1 /* Time in ticks between receive polls. */ 391534c382SMartin Schwidefsky 401534c382SMartin Schwidefsky extern int ap_domain_index; 411534c382SMartin Schwidefsky 421534c382SMartin Schwidefsky /** 431534c382SMartin Schwidefsky * The ap_qid_t identifier of an ap queue. It contains a 441534c382SMartin Schwidefsky * 6 bit device index and a 4 bit queue index (domain). 451534c382SMartin Schwidefsky */ 461534c382SMartin Schwidefsky typedef unsigned int ap_qid_t; 471534c382SMartin Schwidefsky 48170387a8SIngo Tuchscherer #define AP_MKQID(_device, _queue) (((_device) & 63) << 8 | ((_queue) & 255)) 491534c382SMartin Schwidefsky #define AP_QID_DEVICE(_qid) (((_qid) >> 8) & 63) 50170387a8SIngo Tuchscherer #define AP_QID_QUEUE(_qid) ((_qid) & 255) 511534c382SMartin Schwidefsky 521534c382SMartin Schwidefsky /** 531749a81dSFelix Beck * structy ap_queue_status - Holds the AP queue status. 541749a81dSFelix Beck * @queue_empty: Shows if queue is empty 551749a81dSFelix Beck * @replies_waiting: Waiting replies 561749a81dSFelix Beck * @queue_full: Is 1 if the queue is full 571749a81dSFelix Beck * @pad: A 4 bit pad 581749a81dSFelix Beck * @int_enabled: Shows if interrupts are enabled for the AP 591749a81dSFelix Beck * @response_conde: Holds the 8 bit response code 601749a81dSFelix Beck * @pad2: A 16 bit pad 611749a81dSFelix Beck * 621534c382SMartin Schwidefsky * The ap queue status word is returned by all three AP functions 631534c382SMartin Schwidefsky * (PQAP, NQAP and DQAP). There's a set of flags in the first 641534c382SMartin Schwidefsky * byte, followed by a 1 byte response code. 651534c382SMartin Schwidefsky */ 661534c382SMartin Schwidefsky struct ap_queue_status { 671534c382SMartin Schwidefsky unsigned int queue_empty : 1; 681534c382SMartin Schwidefsky unsigned int replies_waiting : 1; 691534c382SMartin Schwidefsky unsigned int queue_full : 1; 70cb17a636SFelix Beck unsigned int pad1 : 4; 71cb17a636SFelix Beck unsigned int int_enabled : 1; 721534c382SMartin Schwidefsky unsigned int response_code : 8; 731534c382SMartin Schwidefsky unsigned int pad2 : 16; 746bed05bcSHolger Dengler } __packed; 756bed05bcSHolger Dengler 766bed05bcSHolger Dengler #define AP_QUEUE_STATUS_INVALID \ 776bed05bcSHolger Dengler { 1, 1, 1, 0xF, 1, 0xFF, 0xFFFF } 786bed05bcSHolger Dengler 796bed05bcSHolger Dengler static inline 806bed05bcSHolger Dengler int ap_queue_status_invalid_test(struct ap_queue_status *status) 816bed05bcSHolger Dengler { 826bed05bcSHolger Dengler struct ap_queue_status invalid = AP_QUEUE_STATUS_INVALID; 836bed05bcSHolger Dengler return !(memcmp(status, &invalid, sizeof(struct ap_queue_status))); 846bed05bcSHolger Dengler } 856bed05bcSHolger Dengler 8675014550SHolger Dengler #define AP_MAX_BITS 31 8775014550SHolger Dengler static inline int ap_test_bit(unsigned int *ptr, unsigned int nr) 886bed05bcSHolger Dengler { 8975014550SHolger Dengler if (nr > AP_MAX_BITS) 906bed05bcSHolger Dengler return 0; 9175014550SHolger Dengler return (*ptr & (0x80000000u >> nr)) != 0; 926bed05bcSHolger Dengler } 931534c382SMartin Schwidefsky 941534c382SMartin Schwidefsky #define AP_RESPONSE_NORMAL 0x00 951534c382SMartin Schwidefsky #define AP_RESPONSE_Q_NOT_AVAIL 0x01 961534c382SMartin Schwidefsky #define AP_RESPONSE_RESET_IN_PROGRESS 0x02 971534c382SMartin Schwidefsky #define AP_RESPONSE_DECONFIGURED 0x03 981534c382SMartin Schwidefsky #define AP_RESPONSE_CHECKSTOPPED 0x04 991534c382SMartin Schwidefsky #define AP_RESPONSE_BUSY 0x05 100cb17a636SFelix Beck #define AP_RESPONSE_INVALID_ADDRESS 0x06 101cb17a636SFelix Beck #define AP_RESPONSE_OTHERWISE_CHANGED 0x07 1021534c382SMartin Schwidefsky #define AP_RESPONSE_Q_FULL 0x10 1031534c382SMartin Schwidefsky #define AP_RESPONSE_NO_PENDING_REPLY 0x10 1041534c382SMartin Schwidefsky #define AP_RESPONSE_INDEX_TOO_BIG 0x11 1051534c382SMartin Schwidefsky #define AP_RESPONSE_NO_FIRST_PART 0x13 1061534c382SMartin Schwidefsky #define AP_RESPONSE_MESSAGE_TOO_BIG 0x15 107a6a5d73aSFelix Beck #define AP_RESPONSE_REQ_FAC_NOT_INST 0x16 1081534c382SMartin Schwidefsky 1091749a81dSFelix Beck /* 1101534c382SMartin Schwidefsky * Known device types 1111534c382SMartin Schwidefsky */ 1121534c382SMartin Schwidefsky #define AP_DEVICE_TYPE_PCICC 3 1131534c382SMartin Schwidefsky #define AP_DEVICE_TYPE_PCICA 4 1141534c382SMartin Schwidefsky #define AP_DEVICE_TYPE_PCIXCC 5 1151534c382SMartin Schwidefsky #define AP_DEVICE_TYPE_CEX2A 6 1161534c382SMartin Schwidefsky #define AP_DEVICE_TYPE_CEX2C 7 117ffda4f71SFelix Beck #define AP_DEVICE_TYPE_CEX3A 8 118ffda4f71SFelix Beck #define AP_DEVICE_TYPE_CEX3C 9 1191e2076f4SHolger Dengler #define AP_DEVICE_TYPE_CEX4 10 1201534c382SMartin Schwidefsky 1211749a81dSFelix Beck /* 122b26bd941SHolger Dengler * Known function facilities 123b26bd941SHolger Dengler */ 124b26bd941SHolger Dengler #define AP_FUNC_MEX4K 1 125b26bd941SHolger Dengler #define AP_FUNC_CRT4K 2 126b26bd941SHolger Dengler #define AP_FUNC_COPRO 3 127b26bd941SHolger Dengler #define AP_FUNC_ACCEL 4 12891f3e3eaSIngo Tuchscherer #define AP_FUNC_EP11 5 12991f3e3eaSIngo Tuchscherer #define AP_FUNC_APXA 6 130b26bd941SHolger Dengler 131b26bd941SHolger Dengler /* 132af512ed0SRalph Wuerthner * AP reset flag states 133af512ed0SRalph Wuerthner */ 134af512ed0SRalph Wuerthner #define AP_RESET_IGNORE 0 /* request timeout will be ignored */ 135af512ed0SRalph Wuerthner #define AP_RESET_ARMED 1 /* request timeout timer is active */ 136af512ed0SRalph Wuerthner #define AP_RESET_DO 2 /* AP reset required */ 137af512ed0SRalph Wuerthner 1381534c382SMartin Schwidefsky struct ap_device; 1391534c382SMartin Schwidefsky struct ap_message; 1401534c382SMartin Schwidefsky 1411534c382SMartin Schwidefsky struct ap_driver { 1421534c382SMartin Schwidefsky struct device_driver driver; 1431534c382SMartin Schwidefsky struct ap_device_id *ids; 1441534c382SMartin Schwidefsky 1451534c382SMartin Schwidefsky int (*probe)(struct ap_device *); 1461534c382SMartin Schwidefsky void (*remove)(struct ap_device *); 147af512ed0SRalph Wuerthner int request_timeout; /* request timeout in jiffies */ 1481534c382SMartin Schwidefsky }; 1491534c382SMartin Schwidefsky 1501534c382SMartin Schwidefsky #define to_ap_drv(x) container_of((x), struct ap_driver, driver) 1511534c382SMartin Schwidefsky 1521534c382SMartin Schwidefsky int ap_driver_register(struct ap_driver *, struct module *, char *); 1531534c382SMartin Schwidefsky void ap_driver_unregister(struct ap_driver *); 1541534c382SMartin Schwidefsky 1551534c382SMartin Schwidefsky struct ap_device { 1561534c382SMartin Schwidefsky struct device device; 1571534c382SMartin Schwidefsky struct ap_driver *drv; /* Pointer to AP device driver. */ 1581534c382SMartin Schwidefsky spinlock_t lock; /* Per device lock. */ 159cf352ce0SRalph Wuerthner struct list_head list; /* private list of all AP devices. */ 1601534c382SMartin Schwidefsky 1611534c382SMartin Schwidefsky ap_qid_t qid; /* AP queue id. */ 1621534c382SMartin Schwidefsky int queue_depth; /* AP queue depth.*/ 1631534c382SMartin Schwidefsky int device_type; /* AP device type. */ 16442f4dd61SIngo Tuchscherer int raw_hwtype; /* AP raw hardware type. */ 165b26bd941SHolger Dengler unsigned int functions; /* AP device function bitfield. */ 1661534c382SMartin Schwidefsky int unregistered; /* marks AP device as unregistered */ 167af512ed0SRalph Wuerthner struct timer_list timeout; /* Timer for request timeouts. */ 168af512ed0SRalph Wuerthner int reset; /* Reset required after req. timeout. */ 1691534c382SMartin Schwidefsky 1701534c382SMartin Schwidefsky int queue_count; /* # messages currently on AP queue. */ 1711534c382SMartin Schwidefsky 1721534c382SMartin Schwidefsky struct list_head pendingq; /* List of message sent to AP queue. */ 1731534c382SMartin Schwidefsky int pendingq_count; /* # requests on pendingq list. */ 1741534c382SMartin Schwidefsky struct list_head requestq; /* List of message yet to be sent. */ 1751534c382SMartin Schwidefsky int requestq_count; /* # requests on requestq list. */ 1761534c382SMartin Schwidefsky int total_request_count; /* # requests ever for this AP device. */ 1771534c382SMartin Schwidefsky 1781534c382SMartin Schwidefsky struct ap_message *reply; /* Per device reply message. */ 1791534c382SMartin Schwidefsky 1801534c382SMartin Schwidefsky void *private; /* ap driver private pointer. */ 1811534c382SMartin Schwidefsky }; 1821534c382SMartin Schwidefsky 1831534c382SMartin Schwidefsky #define to_ap_dev(x) container_of((x), struct ap_device, device) 1841534c382SMartin Schwidefsky 1851534c382SMartin Schwidefsky struct ap_message { 1861534c382SMartin Schwidefsky struct list_head list; /* Request queueing. */ 1871534c382SMartin Schwidefsky unsigned long long psmid; /* Message id. */ 1881534c382SMartin Schwidefsky void *message; /* Pointer to message buffer. */ 1891534c382SMartin Schwidefsky size_t length; /* Message length. */ 1901534c382SMartin Schwidefsky 1911534c382SMartin Schwidefsky void *private; /* ap driver private pointer. */ 192a6a5d73aSFelix Beck unsigned int special:1; /* Used for special commands. */ 19354a8f561SHolger Dengler /* receive is called from tasklet context */ 19454a8f561SHolger Dengler void (*receive)(struct ap_device *, struct ap_message *, 19554a8f561SHolger Dengler struct ap_message *); 1961534c382SMartin Schwidefsky }; 1971534c382SMartin Schwidefsky 19875014550SHolger Dengler struct ap_config_info { 19975014550SHolger Dengler unsigned int special_command:1; 20075014550SHolger Dengler unsigned int ap_extended:1; 20175014550SHolger Dengler unsigned char reserved1:6; 20275014550SHolger Dengler unsigned char reserved2[15]; 20375014550SHolger Dengler unsigned int apm[8]; /* AP ID mask */ 20475014550SHolger Dengler unsigned int aqm[8]; /* AP queue mask */ 20575014550SHolger Dengler unsigned int adm[8]; /* AP domain mask */ 20675014550SHolger Dengler unsigned char reserved4[16]; 20775014550SHolger Dengler } __packed; 20875014550SHolger Dengler 2091534c382SMartin Schwidefsky #define AP_DEVICE(dt) \ 2101534c382SMartin Schwidefsky .dev_type=(dt), \ 2111534c382SMartin Schwidefsky .match_flags=AP_DEVICE_ID_MATCH_DEVICE_TYPE, 2121534c382SMartin Schwidefsky 213468ffddfSFelix Beck /** 214468ffddfSFelix Beck * ap_init_message() - Initialize ap_message. 215468ffddfSFelix Beck * Initialize a message before using. Otherwise this might result in 216468ffddfSFelix Beck * unexpected behaviour. 217468ffddfSFelix Beck */ 218468ffddfSFelix Beck static inline void ap_init_message(struct ap_message *ap_msg) 219468ffddfSFelix Beck { 220468ffddfSFelix Beck ap_msg->psmid = 0; 221468ffddfSFelix Beck ap_msg->length = 0; 222a6a5d73aSFelix Beck ap_msg->special = 0; 22354a8f561SHolger Dengler ap_msg->receive = NULL; 224468ffddfSFelix Beck } 225468ffddfSFelix Beck 2261749a81dSFelix Beck /* 2271534c382SMartin Schwidefsky * Note: don't use ap_send/ap_recv after using ap_queue_message 2281534c382SMartin Schwidefsky * for the first time. Otherwise the ap message queue will get 2291534c382SMartin Schwidefsky * confused. 2301534c382SMartin Schwidefsky */ 2311534c382SMartin Schwidefsky int ap_send(ap_qid_t, unsigned long long, void *, size_t); 2321534c382SMartin Schwidefsky int ap_recv(ap_qid_t, unsigned long long *, void *, size_t); 2331534c382SMartin Schwidefsky 2341534c382SMartin Schwidefsky void ap_queue_message(struct ap_device *ap_dev, struct ap_message *ap_msg); 2351534c382SMartin Schwidefsky void ap_cancel_message(struct ap_device *ap_dev, struct ap_message *ap_msg); 2361534c382SMartin Schwidefsky void ap_flush_queue(struct ap_device *ap_dev); 237dabecb29SHolger Dengler void ap_bus_force_rescan(void); 2381534c382SMartin Schwidefsky 2391534c382SMartin Schwidefsky int ap_module_init(void); 2401534c382SMartin Schwidefsky void ap_module_exit(void); 2411534c382SMartin Schwidefsky 2421534c382SMartin Schwidefsky #endif /* _AP_BUS_H_ */ 243