0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054
0055 #ifndef _SCI_HOST_H_
0056 #define _SCI_HOST_H_
0057
0058 #include <scsi/sas_ata.h>
0059 #include "remote_device.h"
0060 #include "phy.h"
0061 #include "isci.h"
0062 #include "remote_node_table.h"
0063 #include "registers.h"
0064 #include "unsolicited_frame_control.h"
0065 #include "probe_roms.h"
0066
0067 struct isci_request;
0068 struct scu_task_context;
0069
0070
0071
0072
0073
0074
0075
0076
0077 struct sci_power_control {
0078
0079
0080
0081
0082 bool timer_started;
0083
0084
0085
0086
0087 struct sci_timer timer;
0088
0089
0090
0091
0092
0093 u8 phys_waiting;
0094
0095
0096
0097
0098 u8 phys_granted_power;
0099
0100
0101
0102
0103
0104 struct isci_phy *requesters[SCI_MAX_PHYS];
0105
0106 };
0107
0108 struct sci_port_configuration_agent;
0109 typedef void (*port_config_fn)(struct isci_host *,
0110 struct sci_port_configuration_agent *,
0111 struct isci_port *, struct isci_phy *);
0112 bool is_port_config_apc(struct isci_host *ihost);
0113 bool is_controller_start_complete(struct isci_host *ihost);
0114
0115 struct sci_port_configuration_agent {
0116 u16 phy_configured_mask;
0117 u16 phy_ready_mask;
0118 struct {
0119 u8 min_index;
0120 u8 max_index;
0121 } phy_valid_port_range[SCI_MAX_PHYS];
0122 bool timer_pending;
0123 port_config_fn link_up_handler;
0124 port_config_fn link_down_handler;
0125 struct sci_timer timer;
0126 };
0127
0128
0129
0130
0131
0132
0133
0134
0135
0136
0137
0138
0139
0140
0141
0142
0143
0144
0145
0146
0147
0148
0149 struct isci_host {
0150 struct sci_base_state_machine sm;
0151
0152 struct sci_timer timer;
0153
0154 struct sci_user_parameters user_parameters;
0155
0156 struct sci_oem_params oem_parameters;
0157 struct sci_port_configuration_agent port_agent;
0158 struct isci_remote_device *device_table[SCI_MAX_REMOTE_DEVICES];
0159 struct sci_remote_node_table available_remote_nodes;
0160 struct sci_power_control power_control;
0161 u8 io_request_sequence[SCI_MAX_IO_REQUESTS];
0162 struct scu_task_context *task_context_table;
0163 dma_addr_t tc_dma;
0164 union scu_remote_node_context *remote_node_context_table;
0165 dma_addr_t rnc_dma;
0166 u32 *completion_queue;
0167 dma_addr_t cq_dma;
0168 u32 completion_queue_get;
0169 u32 logical_port_entries;
0170 u32 remote_node_entries;
0171 u32 task_context_entries;
0172 void *ufi_buf;
0173 dma_addr_t ufi_dma;
0174 struct sci_unsolicited_frame_control uf_control;
0175
0176
0177 struct sci_timer phy_timer;
0178
0179 bool phy_startup_timer_pending;
0180 u32 next_phy_to_start;
0181
0182 u8 invalid_phy_mask;
0183
0184
0185 u16 interrupt_coalesce_number;
0186 u32 interrupt_coalesce_timeout;
0187 struct smu_registers __iomem *smu_registers;
0188 struct scu_registers __iomem *scu_registers;
0189
0190 u16 tci_head;
0191 u16 tci_tail;
0192 u16 tci_pool[SCI_MAX_IO_REQUESTS];
0193
0194 int id;
0195 struct isci_phy phys[SCI_MAX_PHYS];
0196 struct isci_port ports[SCI_MAX_PORTS + 1];
0197 struct asd_sas_port sas_ports[SCI_MAX_PORTS];
0198 struct sas_ha_struct sas_ha;
0199
0200 struct pci_dev *pdev;
0201 #define IHOST_START_PENDING 0
0202 #define IHOST_STOP_PENDING 1
0203 #define IHOST_IRQ_ENABLED 2
0204 unsigned long flags;
0205 wait_queue_head_t eventq;
0206 struct tasklet_struct completion_tasklet;
0207 spinlock_t scic_lock;
0208 struct isci_request *reqs[SCI_MAX_IO_REQUESTS];
0209 struct isci_remote_device devices[SCI_MAX_REMOTE_DEVICES];
0210 };
0211
0212
0213
0214
0215
0216 enum sci_controller_states {
0217
0218
0219
0220 SCIC_INITIAL = 0,
0221
0222
0223
0224
0225
0226
0227
0228
0229 SCIC_RESET,
0230
0231
0232
0233
0234
0235
0236
0237 SCIC_INITIALIZING,
0238
0239
0240
0241
0242
0243
0244 SCIC_INITIALIZED,
0245
0246
0247
0248
0249
0250
0251 SCIC_STARTING,
0252
0253
0254
0255
0256
0257
0258 SCIC_READY,
0259
0260
0261
0262
0263
0264
0265
0266
0267
0268
0269 SCIC_RESETTING,
0270
0271
0272
0273
0274
0275
0276
0277 SCIC_STOPPING,
0278
0279
0280
0281
0282
0283
0284
0285
0286
0287 SCIC_FAILED,
0288 };
0289
0290
0291
0292
0293
0294
0295 #define SCI_MAX_MSIX_INT (SCI_NUM_MSI_X_INT*SCI_MAX_CONTROLLERS)
0296
0297 struct isci_pci_info {
0298 struct isci_host *hosts[SCI_MAX_CONTROLLERS];
0299 struct isci_orom *orom;
0300 };
0301
0302 static inline struct isci_pci_info *to_pci_info(struct pci_dev *pdev)
0303 {
0304 return pci_get_drvdata(pdev);
0305 }
0306
0307 static inline struct Scsi_Host *to_shost(struct isci_host *ihost)
0308 {
0309 return ihost->sas_ha.core.shost;
0310 }
0311
0312 #define for_each_isci_host(id, ihost, pdev) \
0313 for (id = 0; id < SCI_MAX_CONTROLLERS && \
0314 (ihost = to_pci_info(pdev)->hosts[id]); id++)
0315
0316 static inline void wait_for_start(struct isci_host *ihost)
0317 {
0318 wait_event(ihost->eventq, !test_bit(IHOST_START_PENDING, &ihost->flags));
0319 }
0320
0321 static inline void wait_for_stop(struct isci_host *ihost)
0322 {
0323 wait_event(ihost->eventq, !test_bit(IHOST_STOP_PENDING, &ihost->flags));
0324 }
0325
0326 static inline void wait_for_device_start(struct isci_host *ihost, struct isci_remote_device *idev)
0327 {
0328 wait_event(ihost->eventq, !test_bit(IDEV_START_PENDING, &idev->flags));
0329 }
0330
0331 static inline void wait_for_device_stop(struct isci_host *ihost, struct isci_remote_device *idev)
0332 {
0333 wait_event(ihost->eventq, !test_bit(IDEV_STOP_PENDING, &idev->flags));
0334 }
0335
0336 static inline struct isci_host *dev_to_ihost(struct domain_device *dev)
0337 {
0338 return dev->port->ha->lldd_ha;
0339 }
0340
0341 static inline struct isci_host *idev_to_ihost(struct isci_remote_device *idev)
0342 {
0343 return dev_to_ihost(idev->domain_dev);
0344 }
0345
0346
0347 #define ISCI_PEG 0
0348
0349
0350 #define ISCI_TAG(seq, tci) (((u16) (seq)) << 12 | tci)
0351
0352
0353 #define ISCI_TAG_SEQ(tag) (((tag) >> 12) & (SCI_MAX_SEQ-1))
0354 #define ISCI_TAG_TCI(tag) ((tag) & (SCI_MAX_IO_REQUESTS-1))
0355
0356
0357 #define ISCI_COALESCE_BASE 9
0358
0359
0360 static inline int sci_remote_device_node_count(struct isci_remote_device *idev)
0361 {
0362 struct domain_device *dev = idev->domain_dev;
0363
0364 if (dev_is_sata(dev) && dev->parent)
0365 return SCU_STP_REMOTE_NODE_COUNT;
0366 return SCU_SSP_REMOTE_NODE_COUNT;
0367 }
0368
0369
0370
0371
0372
0373
0374
0375
0376 #define sci_controller_clear_invalid_phy(controller, phy) \
0377 ((controller)->invalid_phy_mask &= ~(1 << (phy)->phy_index))
0378
0379 static inline struct device *scirdev_to_dev(struct isci_remote_device *idev)
0380 {
0381 if (!idev || !idev->isci_port || !idev->isci_port->isci_host)
0382 return NULL;
0383
0384 return &idev->isci_port->isci_host->pdev->dev;
0385 }
0386
0387 static inline bool is_a2(struct pci_dev *pdev)
0388 {
0389 if (pdev->revision < 4)
0390 return true;
0391 return false;
0392 }
0393
0394 static inline bool is_b0(struct pci_dev *pdev)
0395 {
0396 if (pdev->revision == 4)
0397 return true;
0398 return false;
0399 }
0400
0401 static inline bool is_c0(struct pci_dev *pdev)
0402 {
0403 if (pdev->revision == 5)
0404 return true;
0405 return false;
0406 }
0407
0408 static inline bool is_c1(struct pci_dev *pdev)
0409 {
0410 if (pdev->revision >= 6)
0411 return true;
0412 return false;
0413 }
0414
0415 enum cable_selections {
0416 short_cable = 0,
0417 long_cable = 1,
0418 medium_cable = 2,
0419 undefined_cable = 3
0420 };
0421
0422 #define CABLE_OVERRIDE_DISABLED (0x10000)
0423
0424 static inline int is_cable_select_overridden(void)
0425 {
0426 return cable_selection_override < CABLE_OVERRIDE_DISABLED;
0427 }
0428
0429 enum cable_selections decode_cable_selection(struct isci_host *ihost, int phy);
0430 void validate_cable_selections(struct isci_host *ihost);
0431 char *lookup_cable_names(enum cable_selections);
0432
0433
0434
0435
0436
0437
0438 #define SGPIO_HW_CONTROL 0x00000443
0439
0440 static inline int isci_gpio_count(struct isci_host *ihost)
0441 {
0442 return ARRAY_SIZE(ihost->scu_registers->peg0.sgpio.output_data_select);
0443 }
0444
0445 void sci_controller_post_request(struct isci_host *ihost,
0446 u32 request);
0447 void sci_controller_release_frame(struct isci_host *ihost,
0448 u32 frame_index);
0449 void sci_controller_copy_sata_response(void *response_buffer,
0450 void *frame_header,
0451 void *frame_buffer);
0452 enum sci_status sci_controller_allocate_remote_node_context(struct isci_host *ihost,
0453 struct isci_remote_device *idev,
0454 u16 *node_id);
0455 void sci_controller_free_remote_node_context(
0456 struct isci_host *ihost,
0457 struct isci_remote_device *idev,
0458 u16 node_id);
0459
0460 struct isci_request *sci_request_by_tag(struct isci_host *ihost, u16 io_tag);
0461 void sci_controller_power_control_queue_insert(struct isci_host *ihost,
0462 struct isci_phy *iphy);
0463 void sci_controller_power_control_queue_remove(struct isci_host *ihost,
0464 struct isci_phy *iphy);
0465 void sci_controller_link_up(struct isci_host *ihost, struct isci_port *iport,
0466 struct isci_phy *iphy);
0467 void sci_controller_link_down(struct isci_host *ihost, struct isci_port *iport,
0468 struct isci_phy *iphy);
0469 void sci_controller_remote_device_stopped(struct isci_host *ihost,
0470 struct isci_remote_device *idev);
0471
0472 enum sci_status sci_controller_continue_io(struct isci_request *ireq);
0473 int isci_host_scan_finished(struct Scsi_Host *, unsigned long);
0474 void isci_host_start(struct Scsi_Host *);
0475 u16 isci_alloc_tag(struct isci_host *ihost);
0476 enum sci_status isci_free_tag(struct isci_host *ihost, u16 io_tag);
0477 void isci_tci_free(struct isci_host *ihost, u16 tci);
0478 void ireq_done(struct isci_host *ihost, struct isci_request *ireq, struct sas_task *task);
0479
0480 int isci_host_init(struct isci_host *);
0481 void isci_host_completion_routine(unsigned long data);
0482 void isci_host_deinit(struct isci_host *);
0483 void sci_controller_disable_interrupts(struct isci_host *ihost);
0484 bool sci_controller_has_remote_devices_stopping(struct isci_host *ihost);
0485 void sci_controller_transition_to_ready(struct isci_host *ihost, enum sci_status status);
0486
0487 enum sci_status sci_controller_start_io(
0488 struct isci_host *ihost,
0489 struct isci_remote_device *idev,
0490 struct isci_request *ireq);
0491
0492 enum sci_status sci_controller_start_task(
0493 struct isci_host *ihost,
0494 struct isci_remote_device *idev,
0495 struct isci_request *ireq);
0496
0497 enum sci_status sci_controller_terminate_request(
0498 struct isci_host *ihost,
0499 struct isci_remote_device *idev,
0500 struct isci_request *ireq);
0501
0502 enum sci_status sci_controller_complete_io(
0503 struct isci_host *ihost,
0504 struct isci_remote_device *idev,
0505 struct isci_request *ireq);
0506
0507 void sci_port_configuration_agent_construct(
0508 struct sci_port_configuration_agent *port_agent);
0509
0510 enum sci_status sci_port_configuration_agent_initialize(
0511 struct isci_host *ihost,
0512 struct sci_port_configuration_agent *port_agent);
0513
0514 int isci_gpio_write(struct sas_ha_struct *, u8 reg_type, u8 reg_index,
0515 u8 reg_count, u8 *write_data);
0516 #endif