12908d778SJames Bottomley /* 22908d778SJames Bottomley * SAS host prototypes and structures header file 32908d778SJames Bottomley * 42908d778SJames Bottomley * Copyright (C) 2005 Adaptec, Inc. All rights reserved. 52908d778SJames Bottomley * Copyright (C) 2005 Luben Tuikov <luben_tuikov@adaptec.com> 62908d778SJames Bottomley * 72908d778SJames Bottomley * This file is licensed under GPLv2. 82908d778SJames Bottomley * 92908d778SJames Bottomley * This program is free software; you can redistribute it and/or 102908d778SJames Bottomley * modify it under the terms of the GNU General Public License as 112908d778SJames Bottomley * published by the Free Software Foundation; either version 2 of the 122908d778SJames Bottomley * License, or (at your option) any later version. 132908d778SJames Bottomley * 142908d778SJames Bottomley * This program is distributed in the hope that it will be useful, but 152908d778SJames Bottomley * WITHOUT ANY WARRANTY; without even the implied warranty of 162908d778SJames Bottomley * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 172908d778SJames Bottomley * General Public License for more details. 182908d778SJames Bottomley * 192908d778SJames Bottomley * You should have received a copy of the GNU General Public License 202908d778SJames Bottomley * along with this program; if not, write to the Free Software 212908d778SJames Bottomley * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 222908d778SJames Bottomley * USA 232908d778SJames Bottomley * 242908d778SJames Bottomley */ 252908d778SJames Bottomley 262908d778SJames Bottomley #ifndef _LIBSAS_H_ 272908d778SJames Bottomley #define _LIBSAS_H_ 282908d778SJames Bottomley 292908d778SJames Bottomley 302908d778SJames Bottomley #include <linux/timer.h> 312908d778SJames Bottomley #include <linux/pci.h> 322908d778SJames Bottomley #include <scsi/sas.h> 332908d778SJames Bottomley #include <linux/list.h> 342908d778SJames Bottomley #include <asm/semaphore.h> 352908d778SJames Bottomley #include <scsi/scsi_device.h> 362908d778SJames Bottomley #include <scsi/scsi_cmnd.h> 372908d778SJames Bottomley #include <scsi/scsi_transport_sas.h> 384195bdbeSDave Jones #include <asm/scatterlist.h> 392908d778SJames Bottomley 402908d778SJames Bottomley struct block_device; 412908d778SJames Bottomley 422908d778SJames Bottomley enum sas_class { 432908d778SJames Bottomley SAS, 442908d778SJames Bottomley EXPANDER 452908d778SJames Bottomley }; 462908d778SJames Bottomley 472908d778SJames Bottomley enum sas_phy_role { 482908d778SJames Bottomley PHY_ROLE_NONE = 0, 492908d778SJames Bottomley PHY_ROLE_TARGET = 0x40, 502908d778SJames Bottomley PHY_ROLE_INITIATOR = 0x80, 512908d778SJames Bottomley }; 522908d778SJames Bottomley 532908d778SJames Bottomley enum sas_phy_type { 542908d778SJames Bottomley PHY_TYPE_PHYSICAL, 552908d778SJames Bottomley PHY_TYPE_VIRTUAL 562908d778SJames Bottomley }; 572908d778SJames Bottomley 582908d778SJames Bottomley /* The events are mnemonically described in sas_dump.c 592908d778SJames Bottomley * so when updating/adding events here, please also 602908d778SJames Bottomley * update the other file too. 612908d778SJames Bottomley */ 622908d778SJames Bottomley enum ha_event { 632908d778SJames Bottomley HAE_RESET = 0U, 642908d778SJames Bottomley HA_NUM_EVENTS = 1, 652908d778SJames Bottomley }; 662908d778SJames Bottomley 672908d778SJames Bottomley enum port_event { 682908d778SJames Bottomley PORTE_BYTES_DMAED = 0U, 692908d778SJames Bottomley PORTE_BROADCAST_RCVD = 1, 702908d778SJames Bottomley PORTE_LINK_RESET_ERR = 2, 712908d778SJames Bottomley PORTE_TIMER_EVENT = 3, 722908d778SJames Bottomley PORTE_HARD_RESET = 4, 732908d778SJames Bottomley PORT_NUM_EVENTS = 5, 742908d778SJames Bottomley }; 752908d778SJames Bottomley 762908d778SJames Bottomley enum phy_event { 772908d778SJames Bottomley PHYE_LOSS_OF_SIGNAL = 0U, 782908d778SJames Bottomley PHYE_OOB_DONE = 1, 792908d778SJames Bottomley PHYE_OOB_ERROR = 2, 802908d778SJames Bottomley PHYE_SPINUP_HOLD = 3, /* hot plug SATA, no COMWAKE sent */ 812908d778SJames Bottomley PHY_NUM_EVENTS = 4, 822908d778SJames Bottomley }; 832908d778SJames Bottomley 842908d778SJames Bottomley enum discover_event { 852908d778SJames Bottomley DISCE_DISCOVER_DOMAIN = 0U, 862908d778SJames Bottomley DISCE_REVALIDATE_DOMAIN = 1, 872908d778SJames Bottomley DISCE_PORT_GONE = 2, 882908d778SJames Bottomley DISC_NUM_EVENTS = 3, 892908d778SJames Bottomley }; 902908d778SJames Bottomley 912908d778SJames Bottomley /* ---------- Expander Devices ---------- */ 922908d778SJames Bottomley 932908d778SJames Bottomley #define ETASK 0xFA 942908d778SJames Bottomley 952908d778SJames Bottomley #define to_dom_device(_obj) container_of(_obj, struct domain_device, dev_obj) 962908d778SJames Bottomley #define to_dev_attr(_attr) container_of(_attr, struct domain_dev_attribute,\ 972908d778SJames Bottomley attr) 982908d778SJames Bottomley 992908d778SJames Bottomley enum routing_attribute { 1002908d778SJames Bottomley DIRECT_ROUTING, 1012908d778SJames Bottomley SUBTRACTIVE_ROUTING, 1022908d778SJames Bottomley TABLE_ROUTING, 1032908d778SJames Bottomley }; 1042908d778SJames Bottomley 1052908d778SJames Bottomley enum ex_phy_state { 1062908d778SJames Bottomley PHY_EMPTY, 1072908d778SJames Bottomley PHY_VACANT, 1082908d778SJames Bottomley PHY_NOT_PRESENT, 1092908d778SJames Bottomley PHY_DEVICE_DISCOVERED 1102908d778SJames Bottomley }; 1112908d778SJames Bottomley 1122908d778SJames Bottomley struct ex_phy { 1132908d778SJames Bottomley int phy_id; 1142908d778SJames Bottomley 1152908d778SJames Bottomley enum ex_phy_state phy_state; 1162908d778SJames Bottomley 1172908d778SJames Bottomley enum sas_dev_type attached_dev_type; 11888edf746SJames Bottomley enum sas_linkrate linkrate; 1192908d778SJames Bottomley 1202908d778SJames Bottomley u8 attached_sata_host:1; 1212908d778SJames Bottomley u8 attached_sata_dev:1; 1222908d778SJames Bottomley u8 attached_sata_ps:1; 1232908d778SJames Bottomley 1242908d778SJames Bottomley enum sas_proto attached_tproto; 1252908d778SJames Bottomley enum sas_proto attached_iproto; 1262908d778SJames Bottomley 1272908d778SJames Bottomley u8 attached_sas_addr[SAS_ADDR_SIZE]; 1282908d778SJames Bottomley u8 attached_phy_id; 1292908d778SJames Bottomley 1302908d778SJames Bottomley u8 phy_change_count; 1312908d778SJames Bottomley enum routing_attribute routing_attr; 1322908d778SJames Bottomley u8 virtual:1; 1332908d778SJames Bottomley 1342908d778SJames Bottomley int last_da_index; 1352908d778SJames Bottomley 1362908d778SJames Bottomley struct sas_phy *phy; 1372908d778SJames Bottomley struct sas_port *port; 1382908d778SJames Bottomley }; 1392908d778SJames Bottomley 1402908d778SJames Bottomley struct expander_device { 1412908d778SJames Bottomley struct list_head children; 1422908d778SJames Bottomley 1432908d778SJames Bottomley u16 ex_change_count; 1442908d778SJames Bottomley u16 max_route_indexes; 1452908d778SJames Bottomley u8 num_phys; 1462908d778SJames Bottomley u8 configuring:1; 1472908d778SJames Bottomley u8 conf_route_table:1; 1482908d778SJames Bottomley u8 enclosure_logical_id[8]; 1492908d778SJames Bottomley 1502908d778SJames Bottomley struct ex_phy *ex_phy; 1512908d778SJames Bottomley struct sas_port *parent_port; 1522908d778SJames Bottomley }; 1532908d778SJames Bottomley 1542908d778SJames Bottomley /* ---------- SATA device ---------- */ 1552908d778SJames Bottomley enum ata_command_set { 1562908d778SJames Bottomley ATA_COMMAND_SET = 0, 1572908d778SJames Bottomley ATAPI_COMMAND_SET = 1, 1582908d778SJames Bottomley }; 1592908d778SJames Bottomley 1602908d778SJames Bottomley struct sata_device { 1612908d778SJames Bottomley enum ata_command_set command_set; 1622908d778SJames Bottomley struct smp_resp rps_resp; /* report_phy_sata_resp */ 1632908d778SJames Bottomley __le16 *identify_device; 1642908d778SJames Bottomley __le16 *identify_packet_device; 1652908d778SJames Bottomley 1662908d778SJames Bottomley u8 port_no; /* port number, if this is a PM (Port) */ 1672908d778SJames Bottomley struct list_head children; /* PM Ports if this is a PM */ 1682908d778SJames Bottomley }; 1692908d778SJames Bottomley 1702908d778SJames Bottomley /* ---------- Domain device ---------- */ 1712908d778SJames Bottomley struct domain_device { 1722908d778SJames Bottomley enum sas_dev_type dev_type; 1732908d778SJames Bottomley 17488edf746SJames Bottomley enum sas_linkrate linkrate; 17588edf746SJames Bottomley enum sas_linkrate min_linkrate; 17688edf746SJames Bottomley enum sas_linkrate max_linkrate; 1772908d778SJames Bottomley 1782908d778SJames Bottomley int pathways; 1792908d778SJames Bottomley 1802908d778SJames Bottomley struct domain_device *parent; 1812908d778SJames Bottomley struct list_head siblings; /* devices on the same level */ 1822908d778SJames Bottomley struct asd_sas_port *port; /* shortcut to root of the tree */ 1832908d778SJames Bottomley 1842908d778SJames Bottomley struct list_head dev_list_node; 1852908d778SJames Bottomley 1862908d778SJames Bottomley enum sas_proto iproto; 1872908d778SJames Bottomley enum sas_proto tproto; 1882908d778SJames Bottomley 1892908d778SJames Bottomley struct sas_rphy *rphy; 1902908d778SJames Bottomley 1912908d778SJames Bottomley u8 sas_addr[SAS_ADDR_SIZE]; 1922908d778SJames Bottomley u8 hashed_sas_addr[HASHED_SAS_ADDR_SIZE]; 1932908d778SJames Bottomley 1942908d778SJames Bottomley u8 frame_rcvd[32]; 1952908d778SJames Bottomley 1962908d778SJames Bottomley union { 1972908d778SJames Bottomley struct expander_device ex_dev; 1982908d778SJames Bottomley struct sata_device sata_dev; /* STP & directly attached */ 1992908d778SJames Bottomley }; 2002908d778SJames Bottomley 2012908d778SJames Bottomley void *lldd_dev; 2022908d778SJames Bottomley }; 2032908d778SJames Bottomley 204c4028958SDavid Howells struct sas_discovery_event { 205c4028958SDavid Howells struct work_struct work; 206c4028958SDavid Howells struct asd_sas_port *port; 207c4028958SDavid Howells }; 208c4028958SDavid Howells 2092908d778SJames Bottomley struct sas_discovery { 2102908d778SJames Bottomley spinlock_t disc_event_lock; 211c4028958SDavid Howells struct sas_discovery_event disc_work[DISC_NUM_EVENTS]; 2122908d778SJames Bottomley unsigned long pending; 2132908d778SJames Bottomley u8 fanout_sas_addr[8]; 2142908d778SJames Bottomley u8 eeds_a[8]; 2152908d778SJames Bottomley u8 eeds_b[8]; 2162908d778SJames Bottomley int max_level; 2172908d778SJames Bottomley }; 2182908d778SJames Bottomley 2192908d778SJames Bottomley 2202908d778SJames Bottomley /* The port struct is Class:RW, driver:RO */ 2212908d778SJames Bottomley struct asd_sas_port { 2222908d778SJames Bottomley /* private: */ 2232908d778SJames Bottomley struct completion port_gone_completion; 2242908d778SJames Bottomley 2252908d778SJames Bottomley struct sas_discovery disc; 2262908d778SJames Bottomley struct domain_device *port_dev; 2272908d778SJames Bottomley spinlock_t dev_list_lock; 2282908d778SJames Bottomley struct list_head dev_list; 22988edf746SJames Bottomley enum sas_linkrate linkrate; 2302908d778SJames Bottomley 2312908d778SJames Bottomley struct sas_phy *phy; 2322908d778SJames Bottomley struct work_struct work; 2332908d778SJames Bottomley 2342908d778SJames Bottomley /* public: */ 2352908d778SJames Bottomley int id; 2362908d778SJames Bottomley 2372908d778SJames Bottomley enum sas_class class; 2382908d778SJames Bottomley u8 sas_addr[SAS_ADDR_SIZE]; 2392908d778SJames Bottomley u8 attached_sas_addr[SAS_ADDR_SIZE]; 2402908d778SJames Bottomley enum sas_proto iproto; 2412908d778SJames Bottomley enum sas_proto tproto; 2422908d778SJames Bottomley 2432908d778SJames Bottomley enum sas_oob_mode oob_mode; 2442908d778SJames Bottomley 2452908d778SJames Bottomley spinlock_t phy_list_lock; 2462908d778SJames Bottomley struct list_head phy_list; 2472908d778SJames Bottomley int num_phys; 2482908d778SJames Bottomley u32 phy_mask; 2492908d778SJames Bottomley 2502908d778SJames Bottomley struct sas_ha_struct *ha; 2512908d778SJames Bottomley 2522908d778SJames Bottomley struct sas_port *port; 2532908d778SJames Bottomley 2542908d778SJames Bottomley void *lldd_port; /* not touched by the sas class code */ 2552908d778SJames Bottomley }; 2562908d778SJames Bottomley 257c4028958SDavid Howells struct asd_sas_event { 258c4028958SDavid Howells struct work_struct work; 259c4028958SDavid Howells struct asd_sas_phy *phy; 260c4028958SDavid Howells }; 261c4028958SDavid Howells 2622908d778SJames Bottomley /* The phy pretty much is controlled by the LLDD. 2632908d778SJames Bottomley * The class only reads those fields. 2642908d778SJames Bottomley */ 2652908d778SJames Bottomley struct asd_sas_phy { 2662908d778SJames Bottomley /* private: */ 2672908d778SJames Bottomley /* protected by ha->event_lock */ 268c4028958SDavid Howells struct asd_sas_event port_events[PORT_NUM_EVENTS]; 269c4028958SDavid Howells struct asd_sas_event phy_events[PHY_NUM_EVENTS]; 2702908d778SJames Bottomley 2712908d778SJames Bottomley unsigned long port_events_pending; 2722908d778SJames Bottomley unsigned long phy_events_pending; 2732908d778SJames Bottomley 2742908d778SJames Bottomley int error; 2752908d778SJames Bottomley 2762908d778SJames Bottomley struct sas_phy *phy; 2772908d778SJames Bottomley 2782908d778SJames Bottomley /* public: */ 2792908d778SJames Bottomley /* The following are class:RO, driver:R/W */ 2802908d778SJames Bottomley int enabled; /* must be set */ 2812908d778SJames Bottomley 2822908d778SJames Bottomley int id; /* must be set */ 2832908d778SJames Bottomley enum sas_class class; 2842908d778SJames Bottomley enum sas_proto iproto; 2852908d778SJames Bottomley enum sas_proto tproto; 2862908d778SJames Bottomley 2872908d778SJames Bottomley enum sas_phy_type type; 2882908d778SJames Bottomley enum sas_phy_role role; 2892908d778SJames Bottomley enum sas_oob_mode oob_mode; 29088edf746SJames Bottomley enum sas_linkrate linkrate; 2912908d778SJames Bottomley 2922908d778SJames Bottomley u8 *sas_addr; /* must be set */ 2932908d778SJames Bottomley u8 attached_sas_addr[SAS_ADDR_SIZE]; /* class:RO, driver: R/W */ 2942908d778SJames Bottomley 2952908d778SJames Bottomley spinlock_t frame_rcvd_lock; 2962908d778SJames Bottomley u8 *frame_rcvd; /* must be set */ 2972908d778SJames Bottomley int frame_rcvd_size; 2982908d778SJames Bottomley 2992908d778SJames Bottomley spinlock_t sas_prim_lock; 3002908d778SJames Bottomley u32 sas_prim; 3012908d778SJames Bottomley 3022908d778SJames Bottomley struct list_head port_phy_el; /* driver:RO */ 3032908d778SJames Bottomley struct asd_sas_port *port; /* Class:RW, driver: RO */ 3042908d778SJames Bottomley 3052908d778SJames Bottomley struct sas_ha_struct *ha; /* may be set; the class sets it anyway */ 3062908d778SJames Bottomley 3072908d778SJames Bottomley void *lldd_phy; /* not touched by the sas_class_code */ 3082908d778SJames Bottomley }; 3092908d778SJames Bottomley 3102908d778SJames Bottomley struct scsi_core { 3112908d778SJames Bottomley struct Scsi_Host *shost; 3122908d778SJames Bottomley 3132908d778SJames Bottomley spinlock_t task_queue_lock; 3142908d778SJames Bottomley struct list_head task_queue; 3152908d778SJames Bottomley int task_queue_size; 3162908d778SJames Bottomley 3172908d778SJames Bottomley struct semaphore queue_thread_sema; 3182908d778SJames Bottomley int queue_thread_kill; 3192908d778SJames Bottomley }; 3202908d778SJames Bottomley 321c4028958SDavid Howells struct sas_ha_event { 322c4028958SDavid Howells struct work_struct work; 323c4028958SDavid Howells struct sas_ha_struct *ha; 324c4028958SDavid Howells }; 325c4028958SDavid Howells 3262908d778SJames Bottomley struct sas_ha_struct { 3272908d778SJames Bottomley /* private: */ 3282908d778SJames Bottomley spinlock_t event_lock; 329c4028958SDavid Howells struct sas_ha_event ha_events[HA_NUM_EVENTS]; 3302908d778SJames Bottomley unsigned long pending; 3312908d778SJames Bottomley 3322908d778SJames Bottomley struct scsi_core core; 3332908d778SJames Bottomley 3342908d778SJames Bottomley /* public: */ 3352908d778SJames Bottomley char *sas_ha_name; 3362908d778SJames Bottomley struct pci_dev *pcidev; /* should be set */ 3372908d778SJames Bottomley struct module *lldd_module; /* should be set */ 3382908d778SJames Bottomley 3392908d778SJames Bottomley u8 *sas_addr; /* must be set */ 3402908d778SJames Bottomley u8 hashed_sas_addr[HASHED_SAS_ADDR_SIZE]; 3412908d778SJames Bottomley 3422908d778SJames Bottomley spinlock_t phy_port_lock; 3432908d778SJames Bottomley struct asd_sas_phy **sas_phy; /* array of valid pointers, must be set */ 3442908d778SJames Bottomley struct asd_sas_port **sas_port; /* array of valid pointers, must be set */ 3452908d778SJames Bottomley int num_phys; /* must be set, gt 0, static */ 3462908d778SJames Bottomley 3472908d778SJames Bottomley /* The class calls this to send a task for execution. */ 3482908d778SJames Bottomley int lldd_max_execute_num; 3492908d778SJames Bottomley int lldd_queue_size; 3502908d778SJames Bottomley 3512908d778SJames Bottomley /* LLDD calls these to notify the class of an event. */ 3522908d778SJames Bottomley void (*notify_ha_event)(struct sas_ha_struct *, enum ha_event); 3532908d778SJames Bottomley void (*notify_port_event)(struct asd_sas_phy *, enum port_event); 3542908d778SJames Bottomley void (*notify_phy_event)(struct asd_sas_phy *, enum phy_event); 3552908d778SJames Bottomley 3562908d778SJames Bottomley void *lldd_ha; /* not touched by sas class code */ 357f456393eSDarrick J. Wong 358f456393eSDarrick J. Wong struct list_head eh_done_q; 3592908d778SJames Bottomley }; 3602908d778SJames Bottomley 3612908d778SJames Bottomley #define SHOST_TO_SAS_HA(_shost) (*(struct sas_ha_struct **)(_shost)->hostdata) 3622908d778SJames Bottomley 3632908d778SJames Bottomley static inline struct domain_device * 3642908d778SJames Bottomley starget_to_domain_dev(struct scsi_target *starget) { 3652908d778SJames Bottomley return starget->hostdata; 3662908d778SJames Bottomley } 3672908d778SJames Bottomley 3682908d778SJames Bottomley static inline struct domain_device * 3692908d778SJames Bottomley sdev_to_domain_dev(struct scsi_device *sdev) { 3702908d778SJames Bottomley return starget_to_domain_dev(sdev->sdev_target); 3712908d778SJames Bottomley } 3722908d778SJames Bottomley 3732908d778SJames Bottomley static inline struct domain_device * 3742908d778SJames Bottomley cmd_to_domain_dev(struct scsi_cmnd *cmd) 3752908d778SJames Bottomley { 3762908d778SJames Bottomley return sdev_to_domain_dev(cmd->device); 3772908d778SJames Bottomley } 3782908d778SJames Bottomley 3792908d778SJames Bottomley void sas_hash_addr(u8 *hashed, const u8 *sas_addr); 3802908d778SJames Bottomley 3812908d778SJames Bottomley /* Before calling a notify event, LLDD should use this function 3822908d778SJames Bottomley * when the link is severed (possibly from its tasklet). 3832908d778SJames Bottomley * The idea is that the Class only reads those, while the LLDD, 3842908d778SJames Bottomley * can R/W these (thus avoiding a race). 3852908d778SJames Bottomley */ 3862908d778SJames Bottomley static inline void sas_phy_disconnected(struct asd_sas_phy *phy) 3872908d778SJames Bottomley { 3882908d778SJames Bottomley phy->oob_mode = OOB_NOT_CONNECTED; 38988edf746SJames Bottomley phy->linkrate = SAS_LINK_RATE_UNKNOWN; 3902908d778SJames Bottomley } 3912908d778SJames Bottomley 3922908d778SJames Bottomley /* ---------- Tasks ---------- */ 3932908d778SJames Bottomley /* 3942908d778SJames Bottomley service_response | SAS_TASK_COMPLETE | SAS_TASK_UNDELIVERED | 3952908d778SJames Bottomley exec_status | | | 3962908d778SJames Bottomley ---------------------+---------------------+-----------------------+ 3972908d778SJames Bottomley SAM_... | X | | 3982908d778SJames Bottomley DEV_NO_RESPONSE | X | X | 3992908d778SJames Bottomley INTERRUPTED | X | | 4002908d778SJames Bottomley QUEUE_FULL | | X | 4012908d778SJames Bottomley DEVICE_UNKNOWN | | X | 4022908d778SJames Bottomley SG_ERR | | X | 4032908d778SJames Bottomley ---------------------+---------------------+-----------------------+ 4042908d778SJames Bottomley */ 4052908d778SJames Bottomley 4062908d778SJames Bottomley enum service_response { 4072908d778SJames Bottomley SAS_TASK_COMPLETE, 4082908d778SJames Bottomley SAS_TASK_UNDELIVERED = -1, 4092908d778SJames Bottomley }; 4102908d778SJames Bottomley 4112908d778SJames Bottomley enum exec_status { 4122908d778SJames Bottomley SAM_GOOD = 0, 4132908d778SJames Bottomley SAM_CHECK_COND = 2, 4142908d778SJames Bottomley SAM_COND_MET = 4, 4152908d778SJames Bottomley SAM_BUSY = 8, 4162908d778SJames Bottomley SAM_INTERMEDIATE = 0x10, 4172908d778SJames Bottomley SAM_IM_COND_MET = 0x12, 4182908d778SJames Bottomley SAM_RESV_CONFLICT= 0x14, 4192908d778SJames Bottomley SAM_TASK_SET_FULL= 0x28, 4202908d778SJames Bottomley SAM_ACA_ACTIVE = 0x30, 4212908d778SJames Bottomley SAM_TASK_ABORTED = 0x40, 4222908d778SJames Bottomley 4232908d778SJames Bottomley SAS_DEV_NO_RESPONSE = 0x80, 4242908d778SJames Bottomley SAS_DATA_UNDERRUN, 4252908d778SJames Bottomley SAS_DATA_OVERRUN, 4262908d778SJames Bottomley SAS_INTERRUPTED, 4272908d778SJames Bottomley SAS_QUEUE_FULL, 4282908d778SJames Bottomley SAS_DEVICE_UNKNOWN, 4292908d778SJames Bottomley SAS_SG_ERR, 4302908d778SJames Bottomley SAS_OPEN_REJECT, 4312908d778SJames Bottomley SAS_OPEN_TO, 4322908d778SJames Bottomley SAS_PROTO_RESPONSE, 4332908d778SJames Bottomley SAS_PHY_DOWN, 4342908d778SJames Bottomley SAS_NAK_R_ERR, 4352908d778SJames Bottomley SAS_PENDING, 4362908d778SJames Bottomley SAS_ABORTED_TASK, 4372908d778SJames Bottomley }; 4382908d778SJames Bottomley 4392908d778SJames Bottomley /* When a task finishes with a response, the LLDD examines the 4402908d778SJames Bottomley * response: 4412908d778SJames Bottomley * - For an ATA task task_status_struct::stat is set to 4422908d778SJames Bottomley * SAS_PROTO_RESPONSE, and the task_status_struct::buf is set to the 4432908d778SJames Bottomley * contents of struct ata_task_resp. 4442908d778SJames Bottomley * - For SSP tasks, if no data is present or status/TMF response 4452908d778SJames Bottomley * is valid, task_status_struct::stat is set. If data is present 4462908d778SJames Bottomley * (SENSE data), the LLDD copies up to SAS_STATUS_BUF_SIZE, sets 4472908d778SJames Bottomley * task_status_struct::buf_valid_size, and task_status_struct::stat is 4482908d778SJames Bottomley * set to SAM_CHECK_COND. 4492908d778SJames Bottomley * 4502908d778SJames Bottomley * "buf" has format SCSI Sense for SSP task, or struct ata_task_resp 4512908d778SJames Bottomley * for ATA task. 4522908d778SJames Bottomley * 4532908d778SJames Bottomley * "frame_len" is the total frame length, which could be more or less 4542908d778SJames Bottomley * than actually copied. 4552908d778SJames Bottomley * 4562908d778SJames Bottomley * Tasks ending with response, always set the residual field. 4572908d778SJames Bottomley */ 4582908d778SJames Bottomley struct ata_task_resp { 4592908d778SJames Bottomley u16 frame_len; 4602908d778SJames Bottomley u8 ending_fis[24]; /* dev to host or data-in */ 4612908d778SJames Bottomley u32 sstatus; 4622908d778SJames Bottomley u32 serror; 4632908d778SJames Bottomley u32 scontrol; 4642908d778SJames Bottomley u32 sactive; 4652908d778SJames Bottomley }; 4662908d778SJames Bottomley 4672908d778SJames Bottomley #define SAS_STATUS_BUF_SIZE 96 4682908d778SJames Bottomley 4692908d778SJames Bottomley struct task_status_struct { 4702908d778SJames Bottomley enum service_response resp; 4712908d778SJames Bottomley enum exec_status stat; 4722908d778SJames Bottomley int buf_valid_size; 4732908d778SJames Bottomley 4742908d778SJames Bottomley u8 buf[SAS_STATUS_BUF_SIZE]; 4752908d778SJames Bottomley 4762908d778SJames Bottomley u32 residual; 4772908d778SJames Bottomley enum sas_open_rej_reason open_rej_reason; 4782908d778SJames Bottomley }; 4792908d778SJames Bottomley 4802908d778SJames Bottomley /* ATA and ATAPI task queuable to a SAS LLDD. 4812908d778SJames Bottomley */ 4822908d778SJames Bottomley struct sas_ata_task { 4832908d778SJames Bottomley struct host_to_dev_fis fis; 4842908d778SJames Bottomley u8 atapi_packet[16]; /* 0 if not ATAPI task */ 4852908d778SJames Bottomley 4862908d778SJames Bottomley u8 retry_count; /* hardware retry, should be > 0 */ 4872908d778SJames Bottomley 4882908d778SJames Bottomley u8 dma_xfer:1; /* PIO:0 or DMA:1 */ 4892908d778SJames Bottomley u8 use_ncq:1; 4902908d778SJames Bottomley u8 set_affil_pol:1; 4912908d778SJames Bottomley u8 stp_affil_pol:1; 4922908d778SJames Bottomley 4932908d778SJames Bottomley u8 device_control_reg_update:1; 4942908d778SJames Bottomley }; 4952908d778SJames Bottomley 4962908d778SJames Bottomley struct sas_smp_task { 4972908d778SJames Bottomley struct scatterlist smp_req; 4982908d778SJames Bottomley struct scatterlist smp_resp; 4992908d778SJames Bottomley }; 5002908d778SJames Bottomley 5012908d778SJames Bottomley enum task_attribute { 5022908d778SJames Bottomley TASK_ATTR_SIMPLE = 0, 5032908d778SJames Bottomley TASK_ATTR_HOQ = 1, 5042908d778SJames Bottomley TASK_ATTR_ORDERED= 2, 5052908d778SJames Bottomley TASK_ATTR_ACA = 4, 5062908d778SJames Bottomley }; 5072908d778SJames Bottomley 5082908d778SJames Bottomley struct sas_ssp_task { 5092908d778SJames Bottomley u8 retry_count; /* hardware retry, should be > 0 */ 5102908d778SJames Bottomley 5112908d778SJames Bottomley u8 LUN[8]; 5122908d778SJames Bottomley u8 enable_first_burst:1; 5132908d778SJames Bottomley enum task_attribute task_attr; 5142908d778SJames Bottomley u8 task_prio; 5152908d778SJames Bottomley u8 cdb[16]; 5162908d778SJames Bottomley }; 5172908d778SJames Bottomley 5182908d778SJames Bottomley struct sas_task { 5192908d778SJames Bottomley struct domain_device *dev; 5202908d778SJames Bottomley struct list_head list; 5212908d778SJames Bottomley 5222908d778SJames Bottomley spinlock_t task_state_lock; 5232908d778SJames Bottomley unsigned task_state_flags; 5242908d778SJames Bottomley 5252908d778SJames Bottomley enum sas_proto task_proto; 5262908d778SJames Bottomley 5272908d778SJames Bottomley /* Used by the discovery code. */ 5282908d778SJames Bottomley struct timer_list timer; 5292908d778SJames Bottomley struct completion completion; 5302908d778SJames Bottomley 5312908d778SJames Bottomley union { 5322908d778SJames Bottomley struct sas_ata_task ata_task; 5332908d778SJames Bottomley struct sas_smp_task smp_task; 5342908d778SJames Bottomley struct sas_ssp_task ssp_task; 5352908d778SJames Bottomley }; 5362908d778SJames Bottomley 5372908d778SJames Bottomley struct scatterlist *scatter; 5382908d778SJames Bottomley int num_scatter; 5392908d778SJames Bottomley u32 total_xfer_len; 5402908d778SJames Bottomley u8 data_dir:2; /* Use PCI_DMA_... */ 5412908d778SJames Bottomley 5422908d778SJames Bottomley struct task_status_struct task_status; 5432908d778SJames Bottomley void (*task_done)(struct sas_task *); 5442908d778SJames Bottomley 5452908d778SJames Bottomley void *lldd_task; /* for use by LLDDs */ 5462908d778SJames Bottomley void *uldd_task; 54779a5eb60SDarrick J. Wong 54879a5eb60SDarrick J. Wong struct work_struct abort_work; 5492908d778SJames Bottomley }; 5502908d778SJames Bottomley 5512908d778SJames Bottomley 5522908d778SJames Bottomley 5532908d778SJames Bottomley #define SAS_TASK_STATE_PENDING 1 5542908d778SJames Bottomley #define SAS_TASK_STATE_DONE 2 5552908d778SJames Bottomley #define SAS_TASK_STATE_ABORTED 4 556f456393eSDarrick J. Wong #define SAS_TASK_INITIATOR_ABORTED 8 5572908d778SJames Bottomley 5583cc27547SAl Viro static inline struct sas_task *sas_alloc_task(gfp_t flags) 5592908d778SJames Bottomley { 560e18b890bSChristoph Lameter extern struct kmem_cache *sas_task_cache; 5612908d778SJames Bottomley struct sas_task *task = kmem_cache_alloc(sas_task_cache, flags); 5622908d778SJames Bottomley 5632908d778SJames Bottomley if (task) { 5642908d778SJames Bottomley memset(task, 0, sizeof(*task)); 5652908d778SJames Bottomley INIT_LIST_HEAD(&task->list); 5662908d778SJames Bottomley spin_lock_init(&task->task_state_lock); 5672908d778SJames Bottomley task->task_state_flags = SAS_TASK_STATE_PENDING; 5682908d778SJames Bottomley init_timer(&task->timer); 5692908d778SJames Bottomley init_completion(&task->completion); 5702908d778SJames Bottomley } 5712908d778SJames Bottomley 5722908d778SJames Bottomley return task; 5732908d778SJames Bottomley } 5742908d778SJames Bottomley 5752908d778SJames Bottomley static inline void sas_free_task(struct sas_task *task) 5762908d778SJames Bottomley { 5772908d778SJames Bottomley if (task) { 578e18b890bSChristoph Lameter extern struct kmem_cache *sas_task_cache; 5792908d778SJames Bottomley BUG_ON(!list_empty(&task->list)); 5802908d778SJames Bottomley kmem_cache_free(sas_task_cache, task); 5812908d778SJames Bottomley } 5822908d778SJames Bottomley } 5832908d778SJames Bottomley 5842908d778SJames Bottomley struct sas_domain_function_template { 5852908d778SJames Bottomley /* The class calls these to notify the LLDD of an event. */ 5862908d778SJames Bottomley void (*lldd_port_formed)(struct asd_sas_phy *); 5872908d778SJames Bottomley void (*lldd_port_deformed)(struct asd_sas_phy *); 5882908d778SJames Bottomley 5892908d778SJames Bottomley /* The class calls these when a device is found or gone. */ 5902908d778SJames Bottomley int (*lldd_dev_found)(struct domain_device *); 5912908d778SJames Bottomley void (*lldd_dev_gone)(struct domain_device *); 5922908d778SJames Bottomley 5932908d778SJames Bottomley int (*lldd_execute_task)(struct sas_task *, int num, 5943cc27547SAl Viro gfp_t gfp_flags); 5952908d778SJames Bottomley 5962908d778SJames Bottomley /* Task Management Functions. Must be called from process context. */ 5972908d778SJames Bottomley int (*lldd_abort_task)(struct sas_task *); 5982908d778SJames Bottomley int (*lldd_abort_task_set)(struct domain_device *, u8 *lun); 5992908d778SJames Bottomley int (*lldd_clear_aca)(struct domain_device *, u8 *lun); 6002908d778SJames Bottomley int (*lldd_clear_task_set)(struct domain_device *, u8 *lun); 6012908d778SJames Bottomley int (*lldd_I_T_nexus_reset)(struct domain_device *); 6022908d778SJames Bottomley int (*lldd_lu_reset)(struct domain_device *, u8 *lun); 6032908d778SJames Bottomley int (*lldd_query_task)(struct sas_task *); 6042908d778SJames Bottomley 6052908d778SJames Bottomley /* Port and Adapter management */ 6062908d778SJames Bottomley int (*lldd_clear_nexus_port)(struct asd_sas_port *); 6072908d778SJames Bottomley int (*lldd_clear_nexus_ha)(struct sas_ha_struct *); 6082908d778SJames Bottomley 6092908d778SJames Bottomley /* Phy management */ 610a01e70e5SJames Bottomley int (*lldd_control_phy)(struct asd_sas_phy *, enum phy_func, void *); 6112908d778SJames Bottomley }; 6122908d778SJames Bottomley 6132908d778SJames Bottomley extern int sas_register_ha(struct sas_ha_struct *); 6142908d778SJames Bottomley extern int sas_unregister_ha(struct sas_ha_struct *); 6152908d778SJames Bottomley 616dea22214SDarrick J. Wong int sas_phy_reset(struct sas_phy *phy, int hard_reset); 6172908d778SJames Bottomley extern int sas_queuecommand(struct scsi_cmnd *, 6182908d778SJames Bottomley void (*scsi_done)(struct scsi_cmnd *)); 6192908d778SJames Bottomley extern int sas_target_alloc(struct scsi_target *); 6202908d778SJames Bottomley extern int sas_slave_alloc(struct scsi_device *); 6212908d778SJames Bottomley extern int sas_slave_configure(struct scsi_device *); 6222908d778SJames Bottomley extern void sas_slave_destroy(struct scsi_device *); 6232908d778SJames Bottomley extern int sas_change_queue_depth(struct scsi_device *, int new_depth); 6242908d778SJames Bottomley extern int sas_change_queue_type(struct scsi_device *, int qt); 6252908d778SJames Bottomley extern int sas_bios_param(struct scsi_device *, 6262908d778SJames Bottomley struct block_device *, 6272908d778SJames Bottomley sector_t capacity, int *hsc); 6282908d778SJames Bottomley extern struct scsi_transport_template * 6292908d778SJames Bottomley sas_domain_attach_transport(struct sas_domain_function_template *); 6302908d778SJames Bottomley extern void sas_domain_release_transport(struct scsi_transport_template *); 6312908d778SJames Bottomley 6322908d778SJames Bottomley int sas_discover_root_expander(struct domain_device *); 6332908d778SJames Bottomley 6342908d778SJames Bottomley void sas_init_ex_attr(void); 6352908d778SJames Bottomley 6362908d778SJames Bottomley int sas_ex_revalidate_domain(struct domain_device *); 6372908d778SJames Bottomley 6382908d778SJames Bottomley void sas_unregister_domain_devices(struct asd_sas_port *port); 6392908d778SJames Bottomley void sas_init_disc(struct sas_discovery *disc, struct asd_sas_port *); 6402908d778SJames Bottomley int sas_discover_event(struct asd_sas_port *, enum discover_event ev); 6412908d778SJames Bottomley 6422908d778SJames Bottomley int sas_discover_sata(struct domain_device *); 6432908d778SJames Bottomley int sas_discover_end_dev(struct domain_device *); 6442908d778SJames Bottomley 6452908d778SJames Bottomley void sas_unregister_dev(struct domain_device *); 6462908d778SJames Bottomley 6472908d778SJames Bottomley void sas_init_dev(struct domain_device *); 6482908d778SJames Bottomley 64906328b4fSDavid Howells void sas_task_abort(struct work_struct *); 65079a5eb60SDarrick J. Wong 6512908d778SJames Bottomley #endif /* _SASLIB_H_ */ 652