blob: e2d880a5f391535cc9fb37f1bac604ac6280c401 [file] [log] [blame]
Thomas Gleixner65c85c82019-06-01 10:08:26 +02001// SPDX-License-Identifier: GPL-2.0-only
James Bottomley2908d772006-08-29 09:22:51 -05002/*
3 * Aic94xx SAS/SATA driver SCB management.
4 *
5 * Copyright (C) 2005 Adaptec, Inc. All rights reserved.
6 * Copyright (C) 2005 Luben Tuikov <luben_tuikov@adaptec.com>
James Bottomley2908d772006-08-29 09:22:51 -05007 */
8
Tejun Heo5a0e3ad2010-03-24 17:04:11 +09009#include <linux/gfp.h>
Darrick J. Wongfe4a36c2006-10-30 15:18:56 -080010#include <scsi/scsi_host.h>
James Bottomley2908d772006-08-29 09:22:51 -050011
12#include "aic94xx.h"
13#include "aic94xx_reg.h"
14#include "aic94xx_hwi.h"
15#include "aic94xx_seq.h"
16
17#include "aic94xx_dump.h"
18
19/* ---------- EMPTY SCB ---------- */
20
21#define DL_PHY_MASK 7
22#define BYTES_DMAED 0
23#define PRIMITIVE_RECVD 0x08
24#define PHY_EVENT 0x10
25#define LINK_RESET_ERROR 0x18
26#define TIMER_EVENT 0x20
27#define REQ_TASK_ABORT 0xF0
28#define REQ_DEVICE_RESET 0xF1
29#define SIGNAL_NCQ_ERROR 0xF2
30#define CLEAR_NCQ_ERROR 0xF3
31
32#define PHY_EVENTS_STATUS (CURRENT_LOSS_OF_SIGNAL | CURRENT_OOB_DONE \
33 | CURRENT_SPINUP_HOLD | CURRENT_GTO_TIMEOUT \
34 | CURRENT_OOB_ERROR)
35
Adrian Bunk81e56de2008-03-28 14:48:34 -070036static void get_lrate_mode(struct asd_phy *phy, u8 oob_mode)
James Bottomley2908d772006-08-29 09:22:51 -050037{
James Bottomleya01e70e2006-09-06 19:28:07 -050038 struct sas_phy *sas_phy = phy->sas_phy.phy;
39
James Bottomley2908d772006-08-29 09:22:51 -050040 switch (oob_mode & 7) {
41 case PHY_SPEED_60:
42 /* FIXME: sas transport class doesn't have this */
James Bottomley88edf742006-09-06 17:36:13 -050043 phy->sas_phy.linkrate = SAS_LINK_RATE_6_0_GBPS;
James Bottomley2908d772006-08-29 09:22:51 -050044 phy->sas_phy.phy->negotiated_linkrate = SAS_LINK_RATE_6_0_GBPS;
45 break;
46 case PHY_SPEED_30:
James Bottomley88edf742006-09-06 17:36:13 -050047 phy->sas_phy.linkrate = SAS_LINK_RATE_3_0_GBPS;
James Bottomley2908d772006-08-29 09:22:51 -050048 phy->sas_phy.phy->negotiated_linkrate = SAS_LINK_RATE_3_0_GBPS;
49 break;
50 case PHY_SPEED_15:
James Bottomley88edf742006-09-06 17:36:13 -050051 phy->sas_phy.linkrate = SAS_LINK_RATE_1_5_GBPS;
James Bottomley2908d772006-08-29 09:22:51 -050052 phy->sas_phy.phy->negotiated_linkrate = SAS_LINK_RATE_1_5_GBPS;
53 break;
54 }
James Bottomleya01e70e2006-09-06 19:28:07 -050055 sas_phy->negotiated_linkrate = phy->sas_phy.linkrate;
56 sas_phy->maximum_linkrate_hw = SAS_LINK_RATE_3_0_GBPS;
57 sas_phy->minimum_linkrate_hw = SAS_LINK_RATE_1_5_GBPS;
58 sas_phy->maximum_linkrate = phy->phy_desc->max_sas_lrate;
59 sas_phy->minimum_linkrate = phy->phy_desc->min_sas_lrate;
60
James Bottomley2908d772006-08-29 09:22:51 -050061 if (oob_mode & SAS_MODE)
62 phy->sas_phy.oob_mode = SAS_OOB_MODE;
63 else if (oob_mode & SATA_MODE)
64 phy->sas_phy.oob_mode = SATA_OOB_MODE;
65}
66
Adrian Bunk81e56de2008-03-28 14:48:34 -070067static void asd_phy_event_tasklet(struct asd_ascb *ascb,
James Bottomley2908d772006-08-29 09:22:51 -050068 struct done_list_struct *dl)
69{
70 struct asd_ha_struct *asd_ha = ascb->ha;
71 struct sas_ha_struct *sas_ha = &asd_ha->sas_ha;
72 int phy_id = dl->status_block[0] & DL_PHY_MASK;
73 struct asd_phy *phy = &asd_ha->phys[phy_id];
74
75 u8 oob_status = dl->status_block[1] & PHY_EVENTS_STATUS;
76 u8 oob_mode = dl->status_block[2];
77
78 switch (oob_status) {
79 case CURRENT_LOSS_OF_SIGNAL:
80 /* directly attached device was removed */
81 ASD_DPRINTK("phy%d: device unplugged\n", phy_id);
82 asd_turn_led(asd_ha, phy_id, 0);
83 sas_phy_disconnected(&phy->sas_phy);
84 sas_ha->notify_phy_event(&phy->sas_phy, PHYE_LOSS_OF_SIGNAL);
85 break;
86 case CURRENT_OOB_DONE:
87 /* hot plugged device */
88 asd_turn_led(asd_ha, phy_id, 1);
89 get_lrate_mode(phy, oob_mode);
90 ASD_DPRINTK("phy%d device plugged: lrate:0x%x, proto:0x%x\n",
91 phy_id, phy->sas_phy.linkrate, phy->sas_phy.iproto);
92 sas_ha->notify_phy_event(&phy->sas_phy, PHYE_OOB_DONE);
93 break;
94 case CURRENT_SPINUP_HOLD:
95 /* hot plug SATA, no COMWAKE sent */
96 asd_turn_led(asd_ha, phy_id, 1);
97 sas_ha->notify_phy_event(&phy->sas_phy, PHYE_SPINUP_HOLD);
98 break;
99 case CURRENT_GTO_TIMEOUT:
100 case CURRENT_OOB_ERROR:
101 ASD_DPRINTK("phy%d error while OOB: oob status:0x%x\n", phy_id,
102 dl->status_block[1]);
103 asd_turn_led(asd_ha, phy_id, 0);
104 sas_phy_disconnected(&phy->sas_phy);
105 sas_ha->notify_phy_event(&phy->sas_phy, PHYE_OOB_ERROR);
106 break;
107 }
108}
109
110/* If phys are enabled sparsely, this will do the right thing. */
Adrian Bunk81e56de2008-03-28 14:48:34 -0700111static unsigned ord_phy(struct asd_ha_struct *asd_ha, struct asd_phy *phy)
James Bottomley2908d772006-08-29 09:22:51 -0500112{
113 u8 enabled_mask = asd_ha->hw_prof.enabled_phys;
114 int i, k = 0;
115
116 for_each_phy(enabled_mask, enabled_mask, i) {
117 if (&asd_ha->phys[i] == phy)
118 return k;
119 k++;
120 }
121 return 0;
122}
123
124/**
125 * asd_get_attached_sas_addr -- extract/generate attached SAS address
Lee Jonesd2e510502020-07-13 08:59:45 +0100126 * @phy: pointer to asd_phy
127 * @sas_addr: pointer to buffer where the SAS address is to be written
James Bottomley2908d772006-08-29 09:22:51 -0500128 *
129 * This function extracts the SAS address from an IDENTIFY frame
130 * received. If OOB is SATA, then a SAS address is generated from the
131 * HA tables.
132 *
133 * LOCKING: the frame_rcvd_lock needs to be held since this parses the frame
134 * buffer.
135 */
Adrian Bunk81e56de2008-03-28 14:48:34 -0700136static void asd_get_attached_sas_addr(struct asd_phy *phy, u8 *sas_addr)
James Bottomley2908d772006-08-29 09:22:51 -0500137{
138 if (phy->sas_phy.frame_rcvd[0] == 0x34
139 && phy->sas_phy.oob_mode == SATA_OOB_MODE) {
140 struct asd_ha_struct *asd_ha = phy->sas_phy.ha->lldd_ha;
141 /* FIS device-to-host */
142 u64 addr = be64_to_cpu(*(__be64 *)phy->phy_desc->sas_addr);
143
144 addr += asd_ha->hw_prof.sata_name_base + ord_phy(asd_ha, phy);
145 *(__be64 *)sas_addr = cpu_to_be64(addr);
146 } else {
147 struct sas_identify_frame *idframe =
148 (void *) phy->sas_phy.frame_rcvd;
149 memcpy(sas_addr, idframe->sas_addr, SAS_ADDR_SIZE);
150 }
151}
152
malahal@us.ibm.com3f048102006-10-04 17:28:37 -0700153static void asd_form_port(struct asd_ha_struct *asd_ha, struct asd_phy *phy)
154{
155 int i;
156 struct asd_port *free_port = NULL;
157 struct asd_port *port;
158 struct asd_sas_phy *sas_phy = &phy->sas_phy;
159 unsigned long flags;
160
161 spin_lock_irqsave(&asd_ha->asd_ports_lock, flags);
162 if (!phy->asd_port) {
163 for (i = 0; i < ASD_MAX_PHYS; i++) {
164 port = &asd_ha->asd_ports[i];
165
166 /* Check for wide port */
167 if (port->num_phys > 0 &&
168 memcmp(port->sas_addr, sas_phy->sas_addr,
169 SAS_ADDR_SIZE) == 0 &&
170 memcmp(port->attached_sas_addr,
171 sas_phy->attached_sas_addr,
172 SAS_ADDR_SIZE) == 0) {
173 break;
174 }
175
176 /* Find a free port */
177 if (port->num_phys == 0 && free_port == NULL) {
178 free_port = port;
179 }
180 }
181
182 /* Use a free port if this doesn't form a wide port */
183 if (i >= ASD_MAX_PHYS) {
184 port = free_port;
185 BUG_ON(!port);
186 memcpy(port->sas_addr, sas_phy->sas_addr,
187 SAS_ADDR_SIZE);
188 memcpy(port->attached_sas_addr,
189 sas_phy->attached_sas_addr,
190 SAS_ADDR_SIZE);
191 }
192 port->num_phys++;
193 port->phy_mask |= (1U << sas_phy->id);
194 phy->asd_port = port;
195 }
196 ASD_DPRINTK("%s: updating phy_mask 0x%x for phy%d\n",
Harvey Harrisoncadbd4a2008-07-03 23:47:27 -0700197 __func__, phy->asd_port->phy_mask, sas_phy->id);
malahal@us.ibm.com3f048102006-10-04 17:28:37 -0700198 asd_update_port_links(asd_ha, phy);
199 spin_unlock_irqrestore(&asd_ha->asd_ports_lock, flags);
200}
201
202static void asd_deform_port(struct asd_ha_struct *asd_ha, struct asd_phy *phy)
203{
204 struct asd_port *port = phy->asd_port;
205 struct asd_sas_phy *sas_phy = &phy->sas_phy;
206 unsigned long flags;
207
208 spin_lock_irqsave(&asd_ha->asd_ports_lock, flags);
209 if (port) {
210 port->num_phys--;
211 port->phy_mask &= ~(1U << sas_phy->id);
212 phy->asd_port = NULL;
213 }
214 spin_unlock_irqrestore(&asd_ha->asd_ports_lock, flags);
215}
216
Adrian Bunk81e56de2008-03-28 14:48:34 -0700217static void asd_bytes_dmaed_tasklet(struct asd_ascb *ascb,
218 struct done_list_struct *dl,
219 int edb_id, int phy_id)
James Bottomley2908d772006-08-29 09:22:51 -0500220{
221 unsigned long flags;
222 int edb_el = edb_id + ascb->edb_index;
223 struct asd_dma_tok *edb = ascb->ha->seq.edb_arr[edb_el];
224 struct asd_phy *phy = &ascb->ha->phys[phy_id];
225 struct sas_ha_struct *sas_ha = phy->sas_phy.ha;
226 u16 size = ((dl->status_block[3] & 7) << 8) | dl->status_block[2];
227
228 size = min(size, (u16) sizeof(phy->frame_rcvd));
229
230 spin_lock_irqsave(&phy->sas_phy.frame_rcvd_lock, flags);
231 memcpy(phy->sas_phy.frame_rcvd, edb->vaddr, size);
232 phy->sas_phy.frame_rcvd_size = size;
233 asd_get_attached_sas_addr(phy, phy->sas_phy.attached_sas_addr);
234 spin_unlock_irqrestore(&phy->sas_phy.frame_rcvd_lock, flags);
235 asd_dump_frame_rcvd(phy, dl);
malahal@us.ibm.com3f048102006-10-04 17:28:37 -0700236 asd_form_port(ascb->ha, phy);
James Bottomley2908d772006-08-29 09:22:51 -0500237 sas_ha->notify_port_event(&phy->sas_phy, PORTE_BYTES_DMAED);
238}
239
Adrian Bunk81e56de2008-03-28 14:48:34 -0700240static void asd_link_reset_err_tasklet(struct asd_ascb *ascb,
241 struct done_list_struct *dl,
242 int phy_id)
James Bottomley2908d772006-08-29 09:22:51 -0500243{
244 struct asd_ha_struct *asd_ha = ascb->ha;
245 struct sas_ha_struct *sas_ha = &asd_ha->sas_ha;
246 struct asd_sas_phy *sas_phy = sas_ha->sas_phy[phy_id];
malahal@us.ibm.com3f048102006-10-04 17:28:37 -0700247 struct asd_phy *phy = &asd_ha->phys[phy_id];
James Bottomley2908d772006-08-29 09:22:51 -0500248 u8 lr_error = dl->status_block[1];
249 u8 retries_left = dl->status_block[2];
250
251 switch (lr_error) {
252 case 0:
253 ASD_DPRINTK("phy%d: Receive ID timer expired\n", phy_id);
254 break;
255 case 1:
256 ASD_DPRINTK("phy%d: Loss of signal\n", phy_id);
257 break;
258 case 2:
259 ASD_DPRINTK("phy%d: Loss of dword sync\n", phy_id);
260 break;
261 case 3:
262 ASD_DPRINTK("phy%d: Receive FIS timeout\n", phy_id);
263 break;
264 default:
265 ASD_DPRINTK("phy%d: unknown link reset error code: 0x%x\n",
266 phy_id, lr_error);
267 break;
268 }
269
270 asd_turn_led(asd_ha, phy_id, 0);
271 sas_phy_disconnected(sas_phy);
malahal@us.ibm.com3f048102006-10-04 17:28:37 -0700272 asd_deform_port(asd_ha, phy);
James Bottomley2908d772006-08-29 09:22:51 -0500273 sas_ha->notify_port_event(sas_phy, PORTE_LINK_RESET_ERR);
274
275 if (retries_left == 0) {
276 int num = 1;
277 struct asd_ascb *cp = asd_ascb_alloc_list(ascb->ha, &num,
278 GFP_ATOMIC);
279 if (!cp) {
Harvey Harrisoncadbd4a2008-07-03 23:47:27 -0700280 asd_printk("%s: out of memory\n", __func__);
James Bottomley2908d772006-08-29 09:22:51 -0500281 goto out;
282 }
283 ASD_DPRINTK("phy%d: retries:0 performing link reset seq\n",
284 phy_id);
285 asd_build_control_phy(cp, phy_id, ENABLE_PHY);
286 if (asd_post_ascb_list(ascb->ha, cp, 1) != 0)
287 asd_ascb_free(cp);
288 }
289out:
290 ;
291}
292
Adrian Bunk81e56de2008-03-28 14:48:34 -0700293static void asd_primitive_rcvd_tasklet(struct asd_ascb *ascb,
294 struct done_list_struct *dl,
295 int phy_id)
James Bottomley2908d772006-08-29 09:22:51 -0500296{
297 unsigned long flags;
298 struct sas_ha_struct *sas_ha = &ascb->ha->sas_ha;
299 struct asd_sas_phy *sas_phy = sas_ha->sas_phy[phy_id];
malahal@us.ibm.com3f048102006-10-04 17:28:37 -0700300 struct asd_ha_struct *asd_ha = ascb->ha;
301 struct asd_phy *phy = &asd_ha->phys[phy_id];
James Bottomley2908d772006-08-29 09:22:51 -0500302 u8 reg = dl->status_block[1];
303 u32 cont = dl->status_block[2] << ((reg & 3)*8);
304
305 reg &= ~3;
306 switch (reg) {
307 case LmPRMSTAT0BYTE0:
308 switch (cont) {
309 case LmBROADCH:
310 case LmBROADRVCH0:
311 case LmBROADRVCH1:
312 case LmBROADSES:
313 ASD_DPRINTK("phy%d: BROADCAST change received:%d\n",
314 phy_id, cont);
315 spin_lock_irqsave(&sas_phy->sas_prim_lock, flags);
316 sas_phy->sas_prim = ffs(cont);
317 spin_unlock_irqrestore(&sas_phy->sas_prim_lock, flags);
318 sas_ha->notify_port_event(sas_phy,PORTE_BROADCAST_RCVD);
319 break;
320
321 case LmUNKNOWNP:
322 ASD_DPRINTK("phy%d: unknown BREAK\n", phy_id);
323 break;
324
325 default:
326 ASD_DPRINTK("phy%d: primitive reg:0x%x, cont:0x%04x\n",
327 phy_id, reg, cont);
328 break;
329 }
330 break;
331 case LmPRMSTAT1BYTE0:
332 switch (cont) {
333 case LmHARDRST:
334 ASD_DPRINTK("phy%d: HARD_RESET primitive rcvd\n",
335 phy_id);
336 /* The sequencer disables all phys on that port.
337 * We have to re-enable the phys ourselves. */
malahal@us.ibm.com3f048102006-10-04 17:28:37 -0700338 asd_deform_port(asd_ha, phy);
James Bottomley2908d772006-08-29 09:22:51 -0500339 sas_ha->notify_port_event(sas_phy, PORTE_HARD_RESET);
340 break;
341
342 default:
343 ASD_DPRINTK("phy%d: primitive reg:0x%x, cont:0x%04x\n",
344 phy_id, reg, cont);
345 break;
346 }
347 break;
348 default:
349 ASD_DPRINTK("unknown primitive register:0x%x\n",
350 dl->status_block[1]);
351 break;
352 }
353}
354
355/**
356 * asd_invalidate_edb -- invalidate an EDB and if necessary post the ESCB
357 * @ascb: pointer to Empty SCB
358 * @edb_id: index [0,6] to the empty data buffer which is to be invalidated
359 *
360 * After an EDB has been invalidated, if all EDBs in this ESCB have been
361 * invalidated, the ESCB is posted back to the sequencer.
362 * Context is tasklet/IRQ.
363 */
364void asd_invalidate_edb(struct asd_ascb *ascb, int edb_id)
365{
366 struct asd_seq_data *seq = &ascb->ha->seq;
367 struct empty_scb *escb = &ascb->scb->escb;
368 struct sg_el *eb = &escb->eb[edb_id];
369 struct asd_dma_tok *edb = seq->edb_arr[ascb->edb_index + edb_id];
370
371 memset(edb->vaddr, 0, ASD_EDB_SIZE);
372 eb->flags |= ELEMENT_NOT_VALID;
373 escb->num_valid--;
374
375 if (escb->num_valid == 0) {
376 int i;
377 /* ASD_DPRINTK("reposting escb: vaddr: 0x%p, "
378 "dma_handle: 0x%08llx, next: 0x%08llx, "
379 "index:%d, opcode:0x%02x\n",
380 ascb->dma_scb.vaddr,
381 (u64)ascb->dma_scb.dma_handle,
382 le64_to_cpu(ascb->scb->header.next_scb),
383 le16_to_cpu(ascb->scb->header.index),
384 ascb->scb->header.opcode);
385 */
386 escb->num_valid = ASD_EDBS_PER_SCB;
387 for (i = 0; i < ASD_EDBS_PER_SCB; i++)
388 escb->eb[i].flags = 0;
389 if (!list_empty(&ascb->list))
390 list_del_init(&ascb->list);
391 i = asd_post_escb_list(ascb->ha, ascb, 1);
392 if (i)
393 asd_printk("couldn't post escb, err:%d\n", i);
394 }
395}
396
397static void escb_tasklet_complete(struct asd_ascb *ascb,
398 struct done_list_struct *dl)
399{
400 struct asd_ha_struct *asd_ha = ascb->ha;
401 struct sas_ha_struct *sas_ha = &asd_ha->sas_ha;
402 int edb = (dl->opcode & DL_PHY_MASK) - 1; /* [0xc1,0xc7] -> [0,6] */
403 u8 sb_opcode = dl->status_block[0];
404 int phy_id = sb_opcode & DL_PHY_MASK;
405 struct asd_sas_phy *sas_phy = sas_ha->sas_phy[phy_id];
malahal@us.ibm.com3f048102006-10-04 17:28:37 -0700406 struct asd_phy *phy = &asd_ha->phys[phy_id];
James Bottomley2908d772006-08-29 09:22:51 -0500407
408 if (edb > 6 || edb < 0) {
409 ASD_DPRINTK("edb is 0x%x! dl->opcode is 0x%x\n",
410 edb, dl->opcode);
411 ASD_DPRINTK("sb_opcode : 0x%x, phy_id: 0x%x\n",
412 sb_opcode, phy_id);
413 ASD_DPRINTK("escb: vaddr: 0x%p, "
414 "dma_handle: 0x%llx, next: 0x%llx, "
415 "index:%d, opcode:0x%02x\n",
416 ascb->dma_scb.vaddr,
417 (unsigned long long)ascb->dma_scb.dma_handle,
418 (unsigned long long)
419 le64_to_cpu(ascb->scb->header.next_scb),
420 le16_to_cpu(ascb->scb->header.index),
421 ascb->scb->header.opcode);
422 }
423
Darrick J. Wongfe4a36c2006-10-30 15:18:56 -0800424 /* Catch these before we mask off the sb_opcode bits */
425 switch (sb_opcode) {
426 case REQ_TASK_ABORT: {
427 struct asd_ascb *a, *b;
428 u16 tc_abort;
Darrick J. Wong3cd041f2007-01-11 14:15:23 -0800429 struct domain_device *failed_dev = NULL;
Darrick J. Wongfe4a36c2006-10-30 15:18:56 -0800430
431 ASD_DPRINTK("%s: REQ_TASK_ABORT, reason=0x%X\n",
Harvey Harrisoncadbd4a2008-07-03 23:47:27 -0700432 __func__, dl->status_block[3]);
Darrick J. Wongfe4a36c2006-10-30 15:18:56 -0800433
Darrick J. Wong3cd041f2007-01-11 14:15:23 -0800434 /*
435 * Find the task that caused the abort and abort it first.
436 * The sequencer won't put anything on the done list until
437 * that happens.
438 */
439 tc_abort = *((u16*)(&dl->status_block[1]));
440 tc_abort = le16_to_cpu(tc_abort);
441
442 list_for_each_entry_safe(a, b, &asd_ha->seq.pend_q, list) {
James Bottomleycb84e2d2008-02-15 09:28:43 -0600443 struct sas_task *task = a->uldd_task;
Darrick J. Wong3cd041f2007-01-11 14:15:23 -0800444
James Bottomleycb84e2d2008-02-15 09:28:43 -0600445 if (a->tc_index != tc_abort)
446 continue;
447
448 if (task) {
Darrick J. Wong3cd041f2007-01-11 14:15:23 -0800449 failed_dev = task->dev;
450 sas_task_abort(task);
James Bottomleycb84e2d2008-02-15 09:28:43 -0600451 } else {
452 ASD_DPRINTK("R_T_A for non TASK scb 0x%x\n",
453 a->scb->header.opcode);
Darrick J. Wongfe4a36c2006-10-30 15:18:56 -0800454 }
James Bottomleycb84e2d2008-02-15 09:28:43 -0600455 break;
Darrick J. Wong3cd041f2007-01-11 14:15:23 -0800456 }
457
458 if (!failed_dev) {
459 ASD_DPRINTK("%s: Can't find task (tc=%d) to abort!\n",
Harvey Harrisoncadbd4a2008-07-03 23:47:27 -0700460 __func__, tc_abort);
Darrick J. Wong3cd041f2007-01-11 14:15:23 -0800461 goto out;
462 }
463
464 /*
465 * Now abort everything else for that device (hba?) so
466 * that the EH will wake up and do something.
467 */
468 list_for_each_entry_safe(a, b, &asd_ha->seq.pend_q, list) {
James Bottomleycb84e2d2008-02-15 09:28:43 -0600469 struct sas_task *task = a->uldd_task;
Darrick J. Wong3cd041f2007-01-11 14:15:23 -0800470
471 if (task &&
472 task->dev == failed_dev &&
473 a->tc_index != tc_abort)
474 sas_task_abort(task);
475 }
476
Darrick J. Wongfe4a36c2006-10-30 15:18:56 -0800477 goto out;
478 }
479 case REQ_DEVICE_RESET: {
Darrick J. Wongdea22212006-11-07 17:28:55 -0800480 struct asd_ascb *a;
Darrick J. Wongfe4a36c2006-10-30 15:18:56 -0800481 u16 conn_handle;
Darrick J. Wong3cd041f2007-01-11 14:15:23 -0800482 unsigned long flags;
483 struct sas_task *last_dev_task = NULL;
Darrick J. Wongfe4a36c2006-10-30 15:18:56 -0800484
485 conn_handle = *((u16*)(&dl->status_block[1]));
486 conn_handle = le16_to_cpu(conn_handle);
487
Harvey Harrisoncadbd4a2008-07-03 23:47:27 -0700488 ASD_DPRINTK("%s: REQ_DEVICE_RESET, reason=0x%X\n", __func__,
Darrick J. Wongfe4a36c2006-10-30 15:18:56 -0800489 dl->status_block[3]);
490
Darrick J. Wong3cd041f2007-01-11 14:15:23 -0800491 /* Find the last pending task for the device... */
Darrick J. Wongdea22212006-11-07 17:28:55 -0800492 list_for_each_entry(a, &asd_ha->seq.pend_q, list) {
Darrick J. Wongfe4a36c2006-10-30 15:18:56 -0800493 u16 x;
Darrick J. Wong3cd041f2007-01-11 14:15:23 -0800494 struct domain_device *dev;
495 struct sas_task *task = a->uldd_task;
Darrick J. Wongfe4a36c2006-10-30 15:18:56 -0800496
Darrick J. Wongdea22212006-11-07 17:28:55 -0800497 if (!task)
498 continue;
499 dev = task->dev;
500
James Bottomleye138a5d2006-11-22 11:54:15 -0600501 x = (unsigned long)dev->lldd_dev;
Darrick J. Wong3cd041f2007-01-11 14:15:23 -0800502 if (x == conn_handle)
503 last_dev_task = task;
Darrick J. Wongfe4a36c2006-10-30 15:18:56 -0800504 }
505
Darrick J. Wong3cd041f2007-01-11 14:15:23 -0800506 if (!last_dev_task) {
507 ASD_DPRINTK("%s: Device reset for idle device %d?\n",
Harvey Harrisoncadbd4a2008-07-03 23:47:27 -0700508 __func__, conn_handle);
Darrick J. Wongdea22212006-11-07 17:28:55 -0800509 goto out;
510 }
Darrick J. Wong3cd041f2007-01-11 14:15:23 -0800511
512 /* ...and set the reset flag */
513 spin_lock_irqsave(&last_dev_task->task_state_lock, flags);
514 last_dev_task->task_state_flags |= SAS_TASK_NEED_DEV_RESET;
515 spin_unlock_irqrestore(&last_dev_task->task_state_lock, flags);
516
517 /* Kill all pending tasks for the device */
518 list_for_each_entry(a, &asd_ha->seq.pend_q, list) {
519 u16 x;
520 struct domain_device *dev;
521 struct sas_task *task = a->uldd_task;
522
523 if (!task)
524 continue;
525 dev = task->dev;
526
527 x = (unsigned long)dev->lldd_dev;
528 if (x == conn_handle)
529 sas_task_abort(task);
530 }
531
Darrick J. Wongfe4a36c2006-10-30 15:18:56 -0800532 goto out;
533 }
534 case SIGNAL_NCQ_ERROR:
Harvey Harrisoncadbd4a2008-07-03 23:47:27 -0700535 ASD_DPRINTK("%s: SIGNAL_NCQ_ERROR\n", __func__);
Darrick J. Wongfe4a36c2006-10-30 15:18:56 -0800536 goto out;
537 case CLEAR_NCQ_ERROR:
Harvey Harrisoncadbd4a2008-07-03 23:47:27 -0700538 ASD_DPRINTK("%s: CLEAR_NCQ_ERROR\n", __func__);
Darrick J. Wongfe4a36c2006-10-30 15:18:56 -0800539 goto out;
540 }
541
James Bottomley2908d772006-08-29 09:22:51 -0500542 sb_opcode &= ~DL_PHY_MASK;
543
544 switch (sb_opcode) {
545 case BYTES_DMAED:
Harvey Harrisoncadbd4a2008-07-03 23:47:27 -0700546 ASD_DPRINTK("%s: phy%d: BYTES_DMAED\n", __func__, phy_id);
James Bottomley2908d772006-08-29 09:22:51 -0500547 asd_bytes_dmaed_tasklet(ascb, dl, edb, phy_id);
548 break;
549 case PRIMITIVE_RECVD:
Harvey Harrisoncadbd4a2008-07-03 23:47:27 -0700550 ASD_DPRINTK("%s: phy%d: PRIMITIVE_RECVD\n", __func__,
James Bottomley2908d772006-08-29 09:22:51 -0500551 phy_id);
552 asd_primitive_rcvd_tasklet(ascb, dl, phy_id);
553 break;
554 case PHY_EVENT:
Harvey Harrisoncadbd4a2008-07-03 23:47:27 -0700555 ASD_DPRINTK("%s: phy%d: PHY_EVENT\n", __func__, phy_id);
James Bottomley2908d772006-08-29 09:22:51 -0500556 asd_phy_event_tasklet(ascb, dl);
557 break;
558 case LINK_RESET_ERROR:
Harvey Harrisoncadbd4a2008-07-03 23:47:27 -0700559 ASD_DPRINTK("%s: phy%d: LINK_RESET_ERROR\n", __func__,
James Bottomley2908d772006-08-29 09:22:51 -0500560 phy_id);
561 asd_link_reset_err_tasklet(ascb, dl, phy_id);
562 break;
563 case TIMER_EVENT:
564 ASD_DPRINTK("%s: phy%d: TIMER_EVENT, lost dw sync\n",
Harvey Harrisoncadbd4a2008-07-03 23:47:27 -0700565 __func__, phy_id);
James Bottomley2908d772006-08-29 09:22:51 -0500566 asd_turn_led(asd_ha, phy_id, 0);
567 /* the device is gone */
568 sas_phy_disconnected(sas_phy);
malahal@us.ibm.com3f048102006-10-04 17:28:37 -0700569 asd_deform_port(asd_ha, phy);
James Bottomley2908d772006-08-29 09:22:51 -0500570 sas_ha->notify_port_event(sas_phy, PORTE_TIMER_EVENT);
571 break;
James Bottomley2908d772006-08-29 09:22:51 -0500572 default:
Harvey Harrisoncadbd4a2008-07-03 23:47:27 -0700573 ASD_DPRINTK("%s: phy%d: unknown event:0x%x\n", __func__,
James Bottomley2908d772006-08-29 09:22:51 -0500574 phy_id, sb_opcode);
575 ASD_DPRINTK("edb is 0x%x! dl->opcode is 0x%x\n",
576 edb, dl->opcode);
577 ASD_DPRINTK("sb_opcode : 0x%x, phy_id: 0x%x\n",
578 sb_opcode, phy_id);
579 ASD_DPRINTK("escb: vaddr: 0x%p, "
580 "dma_handle: 0x%llx, next: 0x%llx, "
581 "index:%d, opcode:0x%02x\n",
582 ascb->dma_scb.vaddr,
583 (unsigned long long)ascb->dma_scb.dma_handle,
584 (unsigned long long)
585 le64_to_cpu(ascb->scb->header.next_scb),
586 le16_to_cpu(ascb->scb->header.index),
587 ascb->scb->header.opcode);
588
589 break;
590 }
Darrick J. Wongfe4a36c2006-10-30 15:18:56 -0800591out:
James Bottomley2908d772006-08-29 09:22:51 -0500592 asd_invalidate_edb(ascb, edb);
593}
594
595int asd_init_post_escbs(struct asd_ha_struct *asd_ha)
596{
597 struct asd_seq_data *seq = &asd_ha->seq;
598 int i;
599
600 for (i = 0; i < seq->num_escbs; i++)
601 seq->escb_arr[i]->tasklet_complete = escb_tasklet_complete;
602
603 ASD_DPRINTK("posting %d escbs\n", i);
604 return asd_post_escb_list(asd_ha, seq->escb_arr[0], seq->num_escbs);
605}
606
607/* ---------- CONTROL PHY ---------- */
608
609#define CONTROL_PHY_STATUS (CURRENT_DEVICE_PRESENT | CURRENT_OOB_DONE \
610 | CURRENT_SPINUP_HOLD | CURRENT_GTO_TIMEOUT \
611 | CURRENT_OOB_ERROR)
612
613/**
614 * control_phy_tasklet_complete -- tasklet complete for CONTROL PHY ascb
615 * @ascb: pointer to an ascb
616 * @dl: pointer to the done list entry
617 *
618 * This function completes a CONTROL PHY scb and frees the ascb.
619 * A note on LEDs:
620 * - an LED blinks if there is IO though it,
621 * - if a device is connected to the LED, it is lit,
622 * - if no device is connected to the LED, is is dimmed (off).
623 */
624static void control_phy_tasklet_complete(struct asd_ascb *ascb,
625 struct done_list_struct *dl)
626{
627 struct asd_ha_struct *asd_ha = ascb->ha;
628 struct scb *scb = ascb->scb;
629 struct control_phy *control_phy = &scb->control_phy;
630 u8 phy_id = control_phy->phy_id;
631 struct asd_phy *phy = &ascb->ha->phys[phy_id];
632
633 u8 status = dl->status_block[0];
634 u8 oob_status = dl->status_block[1];
635 u8 oob_mode = dl->status_block[2];
636 /* u8 oob_signals= dl->status_block[3]; */
637
638 if (status != 0) {
639 ASD_DPRINTK("%s: phy%d status block opcode:0x%x\n",
Harvey Harrisoncadbd4a2008-07-03 23:47:27 -0700640 __func__, phy_id, status);
James Bottomley2908d772006-08-29 09:22:51 -0500641 goto out;
642 }
643
644 switch (control_phy->sub_func) {
645 case DISABLE_PHY:
646 asd_ha->hw_prof.enabled_phys &= ~(1 << phy_id);
647 asd_turn_led(asd_ha, phy_id, 0);
648 asd_control_led(asd_ha, phy_id, 0);
Harvey Harrisoncadbd4a2008-07-03 23:47:27 -0700649 ASD_DPRINTK("%s: disable phy%d\n", __func__, phy_id);
James Bottomley2908d772006-08-29 09:22:51 -0500650 break;
651
652 case ENABLE_PHY:
653 asd_control_led(asd_ha, phy_id, 1);
654 if (oob_status & CURRENT_OOB_DONE) {
655 asd_ha->hw_prof.enabled_phys |= (1 << phy_id);
656 get_lrate_mode(phy, oob_mode);
657 asd_turn_led(asd_ha, phy_id, 1);
658 ASD_DPRINTK("%s: phy%d, lrate:0x%x, proto:0x%x\n",
Harvey Harrisoncadbd4a2008-07-03 23:47:27 -0700659 __func__, phy_id,phy->sas_phy.linkrate,
James Bottomley2908d772006-08-29 09:22:51 -0500660 phy->sas_phy.iproto);
661 } else if (oob_status & CURRENT_SPINUP_HOLD) {
662 asd_ha->hw_prof.enabled_phys |= (1 << phy_id);
663 asd_turn_led(asd_ha, phy_id, 1);
Harvey Harrisoncadbd4a2008-07-03 23:47:27 -0700664 ASD_DPRINTK("%s: phy%d, spinup hold\n", __func__,
James Bottomley2908d772006-08-29 09:22:51 -0500665 phy_id);
666 } else if (oob_status & CURRENT_ERR_MASK) {
667 asd_turn_led(asd_ha, phy_id, 0);
668 ASD_DPRINTK("%s: phy%d: error: oob status:0x%02x\n",
Harvey Harrisoncadbd4a2008-07-03 23:47:27 -0700669 __func__, phy_id, oob_status);
James Bottomley2908d772006-08-29 09:22:51 -0500670 } else if (oob_status & (CURRENT_HOT_PLUG_CNCT
671 | CURRENT_DEVICE_PRESENT)) {
672 asd_ha->hw_prof.enabled_phys |= (1 << phy_id);
673 asd_turn_led(asd_ha, phy_id, 1);
674 ASD_DPRINTK("%s: phy%d: hot plug or device present\n",
Harvey Harrisoncadbd4a2008-07-03 23:47:27 -0700675 __func__, phy_id);
James Bottomley2908d772006-08-29 09:22:51 -0500676 } else {
677 asd_ha->hw_prof.enabled_phys |= (1 << phy_id);
678 asd_turn_led(asd_ha, phy_id, 0);
679 ASD_DPRINTK("%s: phy%d: no device present: "
680 "oob_status:0x%x\n",
Harvey Harrisoncadbd4a2008-07-03 23:47:27 -0700681 __func__, phy_id, oob_status);
James Bottomley2908d772006-08-29 09:22:51 -0500682 }
683 break;
684 case RELEASE_SPINUP_HOLD:
685 case PHY_NO_OP:
686 case EXECUTE_HARD_RESET:
Harvey Harrisoncadbd4a2008-07-03 23:47:27 -0700687 ASD_DPRINTK("%s: phy%d: sub_func:0x%x\n", __func__,
James Bottomley2908d772006-08-29 09:22:51 -0500688 phy_id, control_phy->sub_func);
689 /* XXX finish */
690 break;
691 default:
Harvey Harrisoncadbd4a2008-07-03 23:47:27 -0700692 ASD_DPRINTK("%s: phy%d: sub_func:0x%x?\n", __func__,
James Bottomley2908d772006-08-29 09:22:51 -0500693 phy_id, control_phy->sub_func);
694 break;
695 }
696out:
697 asd_ascb_free(ascb);
698}
699
Adrian Bunk81e56de2008-03-28 14:48:34 -0700700static void set_speed_mask(u8 *speed_mask, struct asd_phy_desc *pd)
James Bottomley2908d772006-08-29 09:22:51 -0500701{
702 /* disable all speeds, then enable defaults */
703 *speed_mask = SAS_SPEED_60_DIS | SAS_SPEED_30_DIS | SAS_SPEED_15_DIS
704 | SATA_SPEED_30_DIS | SATA_SPEED_15_DIS;
705
706 switch (pd->max_sas_lrate) {
James Bottomley88edf742006-09-06 17:36:13 -0500707 case SAS_LINK_RATE_6_0_GBPS:
James Bottomley2908d772006-08-29 09:22:51 -0500708 *speed_mask &= ~SAS_SPEED_60_DIS;
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -0500709 fallthrough;
James Bottomley2908d772006-08-29 09:22:51 -0500710 default:
James Bottomley88edf742006-09-06 17:36:13 -0500711 case SAS_LINK_RATE_3_0_GBPS:
James Bottomley2908d772006-08-29 09:22:51 -0500712 *speed_mask &= ~SAS_SPEED_30_DIS;
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -0500713 fallthrough;
James Bottomley88edf742006-09-06 17:36:13 -0500714 case SAS_LINK_RATE_1_5_GBPS:
James Bottomley2908d772006-08-29 09:22:51 -0500715 *speed_mask &= ~SAS_SPEED_15_DIS;
716 }
717
718 switch (pd->min_sas_lrate) {
James Bottomley88edf742006-09-06 17:36:13 -0500719 case SAS_LINK_RATE_6_0_GBPS:
James Bottomley2908d772006-08-29 09:22:51 -0500720 *speed_mask |= SAS_SPEED_30_DIS;
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -0500721 fallthrough;
James Bottomley88edf742006-09-06 17:36:13 -0500722 case SAS_LINK_RATE_3_0_GBPS:
James Bottomley2908d772006-08-29 09:22:51 -0500723 *speed_mask |= SAS_SPEED_15_DIS;
724 default:
James Bottomley88edf742006-09-06 17:36:13 -0500725 case SAS_LINK_RATE_1_5_GBPS:
James Bottomley2908d772006-08-29 09:22:51 -0500726 /* nothing to do */
727 ;
728 }
729
730 switch (pd->max_sata_lrate) {
James Bottomley88edf742006-09-06 17:36:13 -0500731 case SAS_LINK_RATE_3_0_GBPS:
James Bottomley2908d772006-08-29 09:22:51 -0500732 *speed_mask &= ~SATA_SPEED_30_DIS;
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -0500733 fallthrough;
James Bottomley2908d772006-08-29 09:22:51 -0500734 default:
James Bottomley88edf742006-09-06 17:36:13 -0500735 case SAS_LINK_RATE_1_5_GBPS:
James Bottomley2908d772006-08-29 09:22:51 -0500736 *speed_mask &= ~SATA_SPEED_15_DIS;
737 }
738
739 switch (pd->min_sata_lrate) {
James Bottomley88edf742006-09-06 17:36:13 -0500740 case SAS_LINK_RATE_3_0_GBPS:
James Bottomley2908d772006-08-29 09:22:51 -0500741 *speed_mask |= SATA_SPEED_15_DIS;
742 default:
James Bottomley88edf742006-09-06 17:36:13 -0500743 case SAS_LINK_RATE_1_5_GBPS:
James Bottomley2908d772006-08-29 09:22:51 -0500744 /* nothing to do */
745 ;
746 }
747}
748
749/**
750 * asd_build_control_phy -- build a CONTROL PHY SCB
751 * @ascb: pointer to an ascb
752 * @phy_id: phy id to control, integer
753 * @subfunc: subfunction, what to actually to do the phy
754 *
755 * This function builds a CONTROL PHY scb. No allocation of any kind
756 * is performed. @ascb is allocated with the list function.
757 * The caller can override the ascb->tasklet_complete to point
758 * to its own callback function. It must call asd_ascb_free()
759 * at its tasklet complete function.
760 * See the default implementation.
761 */
762void asd_build_control_phy(struct asd_ascb *ascb, int phy_id, u8 subfunc)
763{
764 struct asd_phy *phy = &ascb->ha->phys[phy_id];
765 struct scb *scb = ascb->scb;
766 struct control_phy *control_phy = &scb->control_phy;
767
768 scb->header.opcode = CONTROL_PHY;
769 control_phy->phy_id = (u8) phy_id;
770 control_phy->sub_func = subfunc;
771
772 switch (subfunc) {
773 case EXECUTE_HARD_RESET: /* 0x81 */
774 case ENABLE_PHY: /* 0x01 */
775 /* decide hot plug delay */
776 control_phy->hot_plug_delay = HOTPLUG_DELAY_TIMEOUT;
777
778 /* decide speed mask */
779 set_speed_mask(&control_phy->speed_mask, phy->phy_desc);
780
781 /* initiator port settings are in the hi nibble */
782 if (phy->sas_phy.role == PHY_ROLE_INITIATOR)
Darrick J. Wong5929faf2007-11-05 11:51:17 -0800783 control_phy->port_type = SAS_PROTOCOL_ALL << 4;
James Bottomley2908d772006-08-29 09:22:51 -0500784 else if (phy->sas_phy.role == PHY_ROLE_TARGET)
Darrick J. Wong5929faf2007-11-05 11:51:17 -0800785 control_phy->port_type = SAS_PROTOCOL_ALL;
James Bottomley2908d772006-08-29 09:22:51 -0500786 else
787 control_phy->port_type =
Darrick J. Wong5929faf2007-11-05 11:51:17 -0800788 (SAS_PROTOCOL_ALL << 4) | SAS_PROTOCOL_ALL;
James Bottomley2908d772006-08-29 09:22:51 -0500789
790 /* link reset retries, this should be nominal */
791 control_phy->link_reset_retries = 10;
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -0500792 fallthrough;
James Bottomley2908d772006-08-29 09:22:51 -0500793
794 case RELEASE_SPINUP_HOLD: /* 0x02 */
795 /* decide the func_mask */
796 control_phy->func_mask = FUNCTION_MASK_DEFAULT;
797 if (phy->phy_desc->flags & ASD_SATA_SPINUP_HOLD)
798 control_phy->func_mask &= ~SPINUP_HOLD_DIS;
799 else
800 control_phy->func_mask |= SPINUP_HOLD_DIS;
801 }
802
803 control_phy->conn_handle = cpu_to_le16(0xFFFF);
804
805 ascb->tasklet_complete = control_phy_tasklet_complete;
806}
807
808/* ---------- INITIATE LINK ADM TASK ---------- */
809
Adrian Bunk81e56de2008-03-28 14:48:34 -0700810#if 0
811
James Bottomley2908d772006-08-29 09:22:51 -0500812static void link_adm_tasklet_complete(struct asd_ascb *ascb,
813 struct done_list_struct *dl)
814{
815 u8 opcode = dl->opcode;
816 struct initiate_link_adm *link_adm = &ascb->scb->link_adm;
817 u8 phy_id = link_adm->phy_id;
818
819 if (opcode != TC_NO_ERROR) {
820 asd_printk("phy%d: link adm task 0x%x completed with error "
821 "0x%x\n", phy_id, link_adm->sub_func, opcode);
822 }
823 ASD_DPRINTK("phy%d: link adm task 0x%x: 0x%x\n",
824 phy_id, link_adm->sub_func, opcode);
825
826 asd_ascb_free(ascb);
827}
828
829void asd_build_initiate_link_adm_task(struct asd_ascb *ascb, int phy_id,
830 u8 subfunc)
831{
832 struct scb *scb = ascb->scb;
833 struct initiate_link_adm *link_adm = &scb->link_adm;
834
835 scb->header.opcode = INITIATE_LINK_ADM_TASK;
836
837 link_adm->phy_id = phy_id;
838 link_adm->sub_func = subfunc;
839 link_adm->conn_handle = cpu_to_le16(0xFFFF);
840
841 ascb->tasklet_complete = link_adm_tasklet_complete;
842}
843
Adrian Bunk81e56de2008-03-28 14:48:34 -0700844#endif /* 0 */
845
James Bottomley2908d772006-08-29 09:22:51 -0500846/* ---------- SCB timer ---------- */
847
848/**
849 * asd_ascb_timedout -- called when a pending SCB's timer has expired
Lee Jonesd2e510502020-07-13 08:59:45 +0100850 * @t: Timer context used to fetch the SCB
James Bottomley2908d772006-08-29 09:22:51 -0500851 *
852 * This is the default timeout function which does the most necessary.
853 * Upper layers can implement their own timeout function, say to free
854 * resources they have with this SCB, and then call this one at the
855 * end of their timeout function. To do this, one should initialize
Kees Cook30199be2017-10-11 15:53:34 -0700856 * the ascb->timer.{function, expires} prior to calling the post
Andrea Gelmini8d814962010-10-16 15:19:24 +0200857 * function. The timer is started by the post function.
James Bottomley2908d772006-08-29 09:22:51 -0500858 */
Kees Cook30199be2017-10-11 15:53:34 -0700859void asd_ascb_timedout(struct timer_list *t)
James Bottomley2908d772006-08-29 09:22:51 -0500860{
Kees Cook30199be2017-10-11 15:53:34 -0700861 struct asd_ascb *ascb = from_timer(ascb, t, timer);
James Bottomley2908d772006-08-29 09:22:51 -0500862 struct asd_seq_data *seq = &ascb->ha->seq;
863 unsigned long flags;
864
865 ASD_DPRINTK("scb:0x%x timed out\n", ascb->scb->header.opcode);
866
867 spin_lock_irqsave(&seq->pend_q_lock, flags);
868 seq->pending--;
869 list_del_init(&ascb->list);
870 spin_unlock_irqrestore(&seq->pend_q_lock, flags);
871
872 asd_ascb_free(ascb);
873}
874
875/* ---------- CONTROL PHY ---------- */
876
877/* Given the spec value, return a driver value. */
878static const int phy_func_table[] = {
879 [PHY_FUNC_NOP] = PHY_NO_OP,
880 [PHY_FUNC_LINK_RESET] = ENABLE_PHY,
881 [PHY_FUNC_HARD_RESET] = EXECUTE_HARD_RESET,
882 [PHY_FUNC_DISABLE] = DISABLE_PHY,
883 [PHY_FUNC_RELEASE_SPINUP_HOLD] = RELEASE_SPINUP_HOLD,
884};
885
James Bottomleya01e70e2006-09-06 19:28:07 -0500886int asd_control_phy(struct asd_sas_phy *phy, enum phy_func func, void *arg)
James Bottomley2908d772006-08-29 09:22:51 -0500887{
888 struct asd_ha_struct *asd_ha = phy->ha->lldd_ha;
James Bottomleya01e70e2006-09-06 19:28:07 -0500889 struct asd_phy_desc *pd = asd_ha->phys[phy->id].phy_desc;
James Bottomley2908d772006-08-29 09:22:51 -0500890 struct asd_ascb *ascb;
James Bottomleya01e70e2006-09-06 19:28:07 -0500891 struct sas_phy_linkrates *rates;
James Bottomley2908d772006-08-29 09:22:51 -0500892 int res = 1;
893
James Bottomleya01e70e2006-09-06 19:28:07 -0500894 switch (func) {
895 case PHY_FUNC_CLEAR_ERROR_LOG:
Dan Williamsac013ed12011-09-28 18:48:02 -0700896 case PHY_FUNC_GET_EVENTS:
James Bottomley2908d772006-08-29 09:22:51 -0500897 return -ENOSYS;
James Bottomleya01e70e2006-09-06 19:28:07 -0500898 case PHY_FUNC_SET_LINK_RATE:
899 rates = arg;
900 if (rates->minimum_linkrate) {
901 pd->min_sas_lrate = rates->minimum_linkrate;
902 pd->min_sata_lrate = rates->minimum_linkrate;
903 }
904 if (rates->maximum_linkrate) {
905 pd->max_sas_lrate = rates->maximum_linkrate;
906 pd->max_sata_lrate = rates->maximum_linkrate;
907 }
908 func = PHY_FUNC_LINK_RESET;
909 break;
910 default:
911 break;
912 }
James Bottomley2908d772006-08-29 09:22:51 -0500913
914 ascb = asd_ascb_alloc_list(asd_ha, &res, GFP_KERNEL);
915 if (!ascb)
916 return -ENOMEM;
917
918 asd_build_control_phy(ascb, phy->id, phy_func_table[func]);
919 res = asd_post_ascb_list(asd_ha, ascb , 1);
920 if (res)
921 asd_ascb_free(ascb);
922
923 return res;
924}