phy.c 43 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394
  1. /*
  2. * This file is provided under a dual BSD/GPLv2 license. When using or
  3. * redistributing this file, you may do so under either license.
  4. *
  5. * GPL LICENSE SUMMARY
  6. *
  7. * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of version 2 of the GNU General Public License as
  11. * published by the Free Software Foundation.
  12. *
  13. * This program is distributed in the hope that it will be useful, but
  14. * WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
  21. * The full GNU General Public License is included in this distribution
  22. * in the file called LICENSE.GPL.
  23. *
  24. * BSD LICENSE
  25. *
  26. * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
  27. * All rights reserved.
  28. *
  29. * Redistribution and use in source and binary forms, with or without
  30. * modification, are permitted provided that the following conditions
  31. * are met:
  32. *
  33. * * Redistributions of source code must retain the above copyright
  34. * notice, this list of conditions and the following disclaimer.
  35. * * Redistributions in binary form must reproduce the above copyright
  36. * notice, this list of conditions and the following disclaimer in
  37. * the documentation and/or other materials provided with the
  38. * distribution.
  39. * * Neither the name of Intel Corporation nor the names of its
  40. * contributors may be used to endorse or promote products derived
  41. * from this software without specific prior written permission.
  42. *
  43. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  44. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  45. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  46. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  47. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  48. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  49. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  50. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  51. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  52. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  53. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  54. */
  55. #include "isci.h"
  56. #include "host.h"
  57. #include "phy.h"
  58. #include "scu_event_codes.h"
  59. #include "probe_roms.h"
  60. /* Maximum arbitration wait time in micro-seconds */
  61. #define SCIC_SDS_PHY_MAX_ARBITRATION_WAIT_TIME (700)
  62. enum sas_linkrate sci_phy_linkrate(struct scic_sds_phy *sci_phy)
  63. {
  64. return sci_phy->max_negotiated_speed;
  65. }
  66. /*
  67. * *****************************************************************************
  68. * * SCIC SDS PHY Internal Methods
  69. * ***************************************************************************** */
  70. /**
  71. * This method will initialize the phy transport layer registers
  72. * @sci_phy:
  73. * @transport_layer_registers
  74. *
  75. * enum sci_status
  76. */
  77. static enum sci_status scic_sds_phy_transport_layer_initialization(
  78. struct scic_sds_phy *sci_phy,
  79. struct scu_transport_layer_registers __iomem *transport_layer_registers)
  80. {
  81. u32 tl_control;
  82. sci_phy->transport_layer_registers = transport_layer_registers;
  83. writel(SCIC_SDS_REMOTE_NODE_CONTEXT_INVALID_INDEX,
  84. &sci_phy->transport_layer_registers->stp_rni);
  85. /*
  86. * Hardware team recommends that we enable the STP prefetch for all
  87. * transports
  88. */
  89. tl_control = readl(&sci_phy->transport_layer_registers->control);
  90. tl_control |= SCU_TLCR_GEN_BIT(STP_WRITE_DATA_PREFETCH);
  91. writel(tl_control, &sci_phy->transport_layer_registers->control);
  92. return SCI_SUCCESS;
  93. }
  94. /**
  95. * This method will initialize the phy link layer registers
  96. * @sci_phy:
  97. * @link_layer_registers:
  98. *
  99. * enum sci_status
  100. */
  101. static enum sci_status
  102. scic_sds_phy_link_layer_initialization(struct scic_sds_phy *sci_phy,
  103. struct scu_link_layer_registers __iomem *link_layer_registers)
  104. {
  105. struct scic_sds_controller *scic =
  106. sci_phy->owning_port->owning_controller;
  107. int phy_idx = sci_phy->phy_index;
  108. struct sci_phy_user_params *phy_user =
  109. &scic->user_parameters.sds1.phys[phy_idx];
  110. struct sci_phy_oem_params *phy_oem =
  111. &scic->oem_parameters.sds1.phys[phy_idx];
  112. u32 phy_configuration;
  113. struct scic_phy_cap phy_cap;
  114. u32 parity_check = 0;
  115. u32 parity_count = 0;
  116. u32 llctl, link_rate;
  117. u32 clksm_value = 0;
  118. sci_phy->link_layer_registers = link_layer_registers;
  119. /* Set our IDENTIFY frame data */
  120. #define SCI_END_DEVICE 0x01
  121. writel(SCU_SAS_TIID_GEN_BIT(SMP_INITIATOR) |
  122. SCU_SAS_TIID_GEN_BIT(SSP_INITIATOR) |
  123. SCU_SAS_TIID_GEN_BIT(STP_INITIATOR) |
  124. SCU_SAS_TIID_GEN_BIT(DA_SATA_HOST) |
  125. SCU_SAS_TIID_GEN_VAL(DEVICE_TYPE, SCI_END_DEVICE),
  126. &sci_phy->link_layer_registers->transmit_identification);
  127. /* Write the device SAS Address */
  128. writel(0xFEDCBA98,
  129. &sci_phy->link_layer_registers->sas_device_name_high);
  130. writel(phy_idx, &sci_phy->link_layer_registers->sas_device_name_low);
  131. /* Write the source SAS Address */
  132. writel(phy_oem->sas_address.high,
  133. &sci_phy->link_layer_registers->source_sas_address_high);
  134. writel(phy_oem->sas_address.low,
  135. &sci_phy->link_layer_registers->source_sas_address_low);
  136. /* Clear and Set the PHY Identifier */
  137. writel(0, &sci_phy->link_layer_registers->identify_frame_phy_id);
  138. writel(SCU_SAS_TIPID_GEN_VALUE(ID, phy_idx),
  139. &sci_phy->link_layer_registers->identify_frame_phy_id);
  140. /* Change the initial state of the phy configuration register */
  141. phy_configuration =
  142. readl(&sci_phy->link_layer_registers->phy_configuration);
  143. /* Hold OOB state machine in reset */
  144. phy_configuration |= SCU_SAS_PCFG_GEN_BIT(OOB_RESET);
  145. writel(phy_configuration,
  146. &sci_phy->link_layer_registers->phy_configuration);
  147. /* Configure the SNW capabilities */
  148. phy_cap.all = 0;
  149. phy_cap.start = 1;
  150. phy_cap.gen3_no_ssc = 1;
  151. phy_cap.gen2_no_ssc = 1;
  152. phy_cap.gen1_no_ssc = 1;
  153. if (scic->oem_parameters.sds1.controller.do_enable_ssc == true) {
  154. phy_cap.gen3_ssc = 1;
  155. phy_cap.gen2_ssc = 1;
  156. phy_cap.gen1_ssc = 1;
  157. }
  158. /*
  159. * The SAS specification indicates that the phy_capabilities that
  160. * are transmitted shall have an even parity. Calculate the parity. */
  161. parity_check = phy_cap.all;
  162. while (parity_check != 0) {
  163. if (parity_check & 0x1)
  164. parity_count++;
  165. parity_check >>= 1;
  166. }
  167. /*
  168. * If parity indicates there are an odd number of bits set, then
  169. * set the parity bit to 1 in the phy capabilities. */
  170. if ((parity_count % 2) != 0)
  171. phy_cap.parity = 1;
  172. writel(phy_cap.all, &sci_phy->link_layer_registers->phy_capabilities);
  173. /* Set the enable spinup period but disable the ability to send
  174. * notify enable spinup
  175. */
  176. writel(SCU_ENSPINUP_GEN_VAL(COUNT,
  177. phy_user->notify_enable_spin_up_insertion_frequency),
  178. &sci_phy->link_layer_registers->notify_enable_spinup_control);
  179. /* Write the ALIGN Insertion Ferequency for connected phy and
  180. * inpendent of connected state
  181. */
  182. clksm_value = SCU_ALIGN_INSERTION_FREQUENCY_GEN_VAL(CONNECTED,
  183. phy_user->in_connection_align_insertion_frequency);
  184. clksm_value |= SCU_ALIGN_INSERTION_FREQUENCY_GEN_VAL(GENERAL,
  185. phy_user->align_insertion_frequency);
  186. writel(clksm_value, &sci_phy->link_layer_registers->clock_skew_management);
  187. /* @todo Provide a way to write this register correctly */
  188. writel(0x02108421,
  189. &sci_phy->link_layer_registers->afe_lookup_table_control);
  190. llctl = SCU_SAS_LLCTL_GEN_VAL(NO_OUTBOUND_TASK_TIMEOUT,
  191. (u8)scic->user_parameters.sds1.no_outbound_task_timeout);
  192. switch(phy_user->max_speed_generation) {
  193. case SCIC_SDS_PARM_GEN3_SPEED:
  194. link_rate = SCU_SAS_LINK_LAYER_CONTROL_MAX_LINK_RATE_GEN3;
  195. break;
  196. case SCIC_SDS_PARM_GEN2_SPEED:
  197. link_rate = SCU_SAS_LINK_LAYER_CONTROL_MAX_LINK_RATE_GEN2;
  198. break;
  199. default:
  200. link_rate = SCU_SAS_LINK_LAYER_CONTROL_MAX_LINK_RATE_GEN1;
  201. break;
  202. }
  203. llctl |= SCU_SAS_LLCTL_GEN_VAL(MAX_LINK_RATE, link_rate);
  204. writel(llctl, &sci_phy->link_layer_registers->link_layer_control);
  205. if (is_a0() || is_a2()) {
  206. /* Program the max ARB time for the PHY to 700us so we inter-operate with
  207. * the PMC expander which shuts down PHYs if the expander PHY generates too
  208. * many breaks. This time value will guarantee that the initiator PHY will
  209. * generate the break.
  210. */
  211. writel(SCIC_SDS_PHY_MAX_ARBITRATION_WAIT_TIME,
  212. &sci_phy->link_layer_registers->maximum_arbitration_wait_timer_timeout);
  213. }
  214. /* Disable link layer hang detection, rely on the OS timeout for I/O timeouts. */
  215. writel(0, &sci_phy->link_layer_registers->link_layer_hang_detection_timeout);
  216. /* We can exit the initial state to the stopped state */
  217. sci_change_state(&sci_phy->sm, SCI_PHY_STOPPED);
  218. return SCI_SUCCESS;
  219. }
  220. static void phy_sata_timeout(unsigned long data)
  221. {
  222. struct sci_timer *tmr = (struct sci_timer *)data;
  223. struct scic_sds_phy *sci_phy = container_of(tmr, typeof(*sci_phy), sata_timer);
  224. struct isci_host *ihost = scic_to_ihost(sci_phy->owning_port->owning_controller);
  225. unsigned long flags;
  226. spin_lock_irqsave(&ihost->scic_lock, flags);
  227. if (tmr->cancel)
  228. goto done;
  229. dev_dbg(sciphy_to_dev(sci_phy),
  230. "%s: SCIC SDS Phy 0x%p did not receive signature fis before "
  231. "timeout.\n",
  232. __func__,
  233. sci_phy);
  234. sci_change_state(&sci_phy->sm, SCI_PHY_STARTING);
  235. done:
  236. spin_unlock_irqrestore(&ihost->scic_lock, flags);
  237. }
  238. /**
  239. * This method returns the port currently containing this phy. If the phy is
  240. * currently contained by the dummy port, then the phy is considered to not
  241. * be part of a port.
  242. * @sci_phy: This parameter specifies the phy for which to retrieve the
  243. * containing port.
  244. *
  245. * This method returns a handle to a port that contains the supplied phy.
  246. * NULL This value is returned if the phy is not part of a real
  247. * port (i.e. it's contained in the dummy port). !NULL All other
  248. * values indicate a handle/pointer to the port containing the phy.
  249. */
  250. struct scic_sds_port *phy_get_non_dummy_port(
  251. struct scic_sds_phy *sci_phy)
  252. {
  253. if (scic_sds_port_get_index(sci_phy->owning_port) == SCIC_SDS_DUMMY_PORT)
  254. return NULL;
  255. return sci_phy->owning_port;
  256. }
  257. /**
  258. * This method will assign a port to the phy object.
  259. * @out]: sci_phy This parameter specifies the phy for which to assign a port
  260. * object.
  261. *
  262. *
  263. */
  264. void scic_sds_phy_set_port(
  265. struct scic_sds_phy *sci_phy,
  266. struct scic_sds_port *sci_port)
  267. {
  268. sci_phy->owning_port = sci_port;
  269. if (sci_phy->bcn_received_while_port_unassigned) {
  270. sci_phy->bcn_received_while_port_unassigned = false;
  271. scic_sds_port_broadcast_change_received(sci_phy->owning_port, sci_phy);
  272. }
  273. }
  274. /**
  275. * This method will initialize the constructed phy
  276. * @sci_phy:
  277. * @link_layer_registers:
  278. *
  279. * enum sci_status
  280. */
  281. enum sci_status scic_sds_phy_initialize(
  282. struct scic_sds_phy *sci_phy,
  283. struct scu_transport_layer_registers __iomem *transport_layer_registers,
  284. struct scu_link_layer_registers __iomem *link_layer_registers)
  285. {
  286. /* Perfrom the initialization of the TL hardware */
  287. scic_sds_phy_transport_layer_initialization(
  288. sci_phy,
  289. transport_layer_registers);
  290. /* Perofrm the initialization of the PE hardware */
  291. scic_sds_phy_link_layer_initialization(sci_phy, link_layer_registers);
  292. /*
  293. * There is nothing that needs to be done in this state just
  294. * transition to the stopped state. */
  295. sci_change_state(&sci_phy->sm, SCI_PHY_STOPPED);
  296. return SCI_SUCCESS;
  297. }
  298. /**
  299. * This method assigns the direct attached device ID for this phy.
  300. *
  301. * @sci_phy The phy for which the direct attached device id is to
  302. * be assigned.
  303. * @device_id The direct attached device ID to assign to the phy.
  304. * This will either be the RNi for the device or an invalid RNi if there
  305. * is no current device assigned to the phy.
  306. */
  307. void scic_sds_phy_setup_transport(
  308. struct scic_sds_phy *sci_phy,
  309. u32 device_id)
  310. {
  311. u32 tl_control;
  312. writel(device_id, &sci_phy->transport_layer_registers->stp_rni);
  313. /*
  314. * The read should guarantee that the first write gets posted
  315. * before the next write
  316. */
  317. tl_control = readl(&sci_phy->transport_layer_registers->control);
  318. tl_control |= SCU_TLCR_GEN_BIT(CLEAR_TCI_NCQ_MAPPING_TABLE);
  319. writel(tl_control, &sci_phy->transport_layer_registers->control);
  320. }
  321. /**
  322. *
  323. * @sci_phy: The phy object to be suspended.
  324. *
  325. * This function will perform the register reads/writes to suspend the SCU
  326. * hardware protocol engine. none
  327. */
  328. static void scic_sds_phy_suspend(
  329. struct scic_sds_phy *sci_phy)
  330. {
  331. u32 scu_sas_pcfg_value;
  332. scu_sas_pcfg_value =
  333. readl(&sci_phy->link_layer_registers->phy_configuration);
  334. scu_sas_pcfg_value |= SCU_SAS_PCFG_GEN_BIT(SUSPEND_PROTOCOL_ENGINE);
  335. writel(scu_sas_pcfg_value,
  336. &sci_phy->link_layer_registers->phy_configuration);
  337. scic_sds_phy_setup_transport(
  338. sci_phy,
  339. SCIC_SDS_REMOTE_NODE_CONTEXT_INVALID_INDEX);
  340. }
  341. void scic_sds_phy_resume(struct scic_sds_phy *sci_phy)
  342. {
  343. u32 scu_sas_pcfg_value;
  344. scu_sas_pcfg_value =
  345. readl(&sci_phy->link_layer_registers->phy_configuration);
  346. scu_sas_pcfg_value &= ~SCU_SAS_PCFG_GEN_BIT(SUSPEND_PROTOCOL_ENGINE);
  347. writel(scu_sas_pcfg_value,
  348. &sci_phy->link_layer_registers->phy_configuration);
  349. }
  350. void scic_sds_phy_get_sas_address(struct scic_sds_phy *sci_phy,
  351. struct sci_sas_address *sas_address)
  352. {
  353. sas_address->high = readl(&sci_phy->link_layer_registers->source_sas_address_high);
  354. sas_address->low = readl(&sci_phy->link_layer_registers->source_sas_address_low);
  355. }
  356. void scic_sds_phy_get_attached_sas_address(struct scic_sds_phy *sci_phy,
  357. struct sci_sas_address *sas_address)
  358. {
  359. struct sas_identify_frame *iaf;
  360. struct isci_phy *iphy = sci_phy_to_iphy(sci_phy);
  361. iaf = &iphy->frame_rcvd.iaf;
  362. memcpy(sas_address, iaf->sas_addr, SAS_ADDR_SIZE);
  363. }
  364. void scic_sds_phy_get_protocols(struct scic_sds_phy *sci_phy,
  365. struct scic_phy_proto *protocols)
  366. {
  367. protocols->all =
  368. (u16)(readl(&sci_phy->
  369. link_layer_registers->transmit_identification) &
  370. 0x0000FFFF);
  371. }
  372. enum sci_status scic_sds_phy_start(struct scic_sds_phy *sci_phy)
  373. {
  374. enum scic_sds_phy_states state = sci_phy->sm.current_state_id;
  375. if (state != SCI_PHY_STOPPED) {
  376. dev_dbg(sciphy_to_dev(sci_phy),
  377. "%s: in wrong state: %d\n", __func__, state);
  378. return SCI_FAILURE_INVALID_STATE;
  379. }
  380. sci_change_state(&sci_phy->sm, SCI_PHY_STARTING);
  381. return SCI_SUCCESS;
  382. }
  383. enum sci_status scic_sds_phy_stop(struct scic_sds_phy *sci_phy)
  384. {
  385. enum scic_sds_phy_states state = sci_phy->sm.current_state_id;
  386. switch (state) {
  387. case SCI_PHY_SUB_INITIAL:
  388. case SCI_PHY_SUB_AWAIT_OSSP_EN:
  389. case SCI_PHY_SUB_AWAIT_SAS_SPEED_EN:
  390. case SCI_PHY_SUB_AWAIT_SAS_POWER:
  391. case SCI_PHY_SUB_AWAIT_SATA_POWER:
  392. case SCI_PHY_SUB_AWAIT_SATA_PHY_EN:
  393. case SCI_PHY_SUB_AWAIT_SATA_SPEED_EN:
  394. case SCI_PHY_SUB_AWAIT_SIG_FIS_UF:
  395. case SCI_PHY_SUB_FINAL:
  396. case SCI_PHY_READY:
  397. break;
  398. default:
  399. dev_dbg(sciphy_to_dev(sci_phy),
  400. "%s: in wrong state: %d\n", __func__, state);
  401. return SCI_FAILURE_INVALID_STATE;
  402. }
  403. sci_change_state(&sci_phy->sm, SCI_PHY_STOPPED);
  404. return SCI_SUCCESS;
  405. }
  406. enum sci_status scic_sds_phy_reset(struct scic_sds_phy *sci_phy)
  407. {
  408. enum scic_sds_phy_states state = sci_phy->sm.current_state_id;
  409. if (state != SCI_PHY_READY) {
  410. dev_dbg(sciphy_to_dev(sci_phy),
  411. "%s: in wrong state: %d\n", __func__, state);
  412. return SCI_FAILURE_INVALID_STATE;
  413. }
  414. sci_change_state(&sci_phy->sm, SCI_PHY_RESETTING);
  415. return SCI_SUCCESS;
  416. }
  417. enum sci_status scic_sds_phy_consume_power_handler(struct scic_sds_phy *sci_phy)
  418. {
  419. enum scic_sds_phy_states state = sci_phy->sm.current_state_id;
  420. switch (state) {
  421. case SCI_PHY_SUB_AWAIT_SAS_POWER: {
  422. u32 enable_spinup;
  423. enable_spinup = readl(&sci_phy->link_layer_registers->notify_enable_spinup_control);
  424. enable_spinup |= SCU_ENSPINUP_GEN_BIT(ENABLE);
  425. writel(enable_spinup, &sci_phy->link_layer_registers->notify_enable_spinup_control);
  426. /* Change state to the final state this substate machine has run to completion */
  427. sci_change_state(&sci_phy->sm, SCI_PHY_SUB_FINAL);
  428. return SCI_SUCCESS;
  429. }
  430. case SCI_PHY_SUB_AWAIT_SATA_POWER: {
  431. u32 scu_sas_pcfg_value;
  432. /* Release the spinup hold state and reset the OOB state machine */
  433. scu_sas_pcfg_value =
  434. readl(&sci_phy->link_layer_registers->phy_configuration);
  435. scu_sas_pcfg_value &=
  436. ~(SCU_SAS_PCFG_GEN_BIT(SATA_SPINUP_HOLD) | SCU_SAS_PCFG_GEN_BIT(OOB_ENABLE));
  437. scu_sas_pcfg_value |= SCU_SAS_PCFG_GEN_BIT(OOB_RESET);
  438. writel(scu_sas_pcfg_value,
  439. &sci_phy->link_layer_registers->phy_configuration);
  440. /* Now restart the OOB operation */
  441. scu_sas_pcfg_value &= ~SCU_SAS_PCFG_GEN_BIT(OOB_RESET);
  442. scu_sas_pcfg_value |= SCU_SAS_PCFG_GEN_BIT(OOB_ENABLE);
  443. writel(scu_sas_pcfg_value,
  444. &sci_phy->link_layer_registers->phy_configuration);
  445. /* Change state to the final state this substate machine has run to completion */
  446. sci_change_state(&sci_phy->sm, SCI_PHY_SUB_AWAIT_SATA_PHY_EN);
  447. return SCI_SUCCESS;
  448. }
  449. default:
  450. dev_dbg(sciphy_to_dev(sci_phy),
  451. "%s: in wrong state: %d\n", __func__, state);
  452. return SCI_FAILURE_INVALID_STATE;
  453. }
  454. }
  455. /*
  456. * *****************************************************************************
  457. * * SCIC SDS PHY HELPER FUNCTIONS
  458. * ***************************************************************************** */
  459. /**
  460. *
  461. * @sci_phy: The phy object that received SAS PHY DETECTED.
  462. *
  463. * This method continues the link training for the phy as if it were a SAS PHY
  464. * instead of a SATA PHY. This is done because the completion queue had a SAS
  465. * PHY DETECTED event when the state machine was expecting a SATA PHY event.
  466. * none
  467. */
  468. static void scic_sds_phy_start_sas_link_training(
  469. struct scic_sds_phy *sci_phy)
  470. {
  471. u32 phy_control;
  472. phy_control =
  473. readl(&sci_phy->link_layer_registers->phy_configuration);
  474. phy_control |= SCU_SAS_PCFG_GEN_BIT(SATA_SPINUP_HOLD);
  475. writel(phy_control,
  476. &sci_phy->link_layer_registers->phy_configuration);
  477. sci_change_state(&sci_phy->sm, SCI_PHY_SUB_AWAIT_SAS_SPEED_EN);
  478. sci_phy->protocol = SCIC_SDS_PHY_PROTOCOL_SAS;
  479. }
  480. /**
  481. *
  482. * @sci_phy: The phy object that received a SATA SPINUP HOLD event
  483. *
  484. * This method continues the link training for the phy as if it were a SATA PHY
  485. * instead of a SAS PHY. This is done because the completion queue had a SATA
  486. * SPINUP HOLD event when the state machine was expecting a SAS PHY event. none
  487. */
  488. static void scic_sds_phy_start_sata_link_training(
  489. struct scic_sds_phy *sci_phy)
  490. {
  491. sci_change_state(&sci_phy->sm, SCI_PHY_SUB_AWAIT_SATA_POWER);
  492. sci_phy->protocol = SCIC_SDS_PHY_PROTOCOL_SATA;
  493. }
  494. /**
  495. * scic_sds_phy_complete_link_training - perform processing common to
  496. * all protocols upon completion of link training.
  497. * @sci_phy: This parameter specifies the phy object for which link training
  498. * has completed.
  499. * @max_link_rate: This parameter specifies the maximum link rate to be
  500. * associated with this phy.
  501. * @next_state: This parameter specifies the next state for the phy's starting
  502. * sub-state machine.
  503. *
  504. */
  505. static void scic_sds_phy_complete_link_training(
  506. struct scic_sds_phy *sci_phy,
  507. enum sas_linkrate max_link_rate,
  508. u32 next_state)
  509. {
  510. sci_phy->max_negotiated_speed = max_link_rate;
  511. sci_change_state(&sci_phy->sm, next_state);
  512. }
  513. enum sci_status scic_sds_phy_event_handler(struct scic_sds_phy *sci_phy,
  514. u32 event_code)
  515. {
  516. enum scic_sds_phy_states state = sci_phy->sm.current_state_id;
  517. switch (state) {
  518. case SCI_PHY_SUB_AWAIT_OSSP_EN:
  519. switch (scu_get_event_code(event_code)) {
  520. case SCU_EVENT_SAS_PHY_DETECTED:
  521. scic_sds_phy_start_sas_link_training(sci_phy);
  522. sci_phy->is_in_link_training = true;
  523. break;
  524. case SCU_EVENT_SATA_SPINUP_HOLD:
  525. scic_sds_phy_start_sata_link_training(sci_phy);
  526. sci_phy->is_in_link_training = true;
  527. break;
  528. default:
  529. dev_dbg(sciphy_to_dev(sci_phy),
  530. "%s: PHY starting substate machine received "
  531. "unexpected event_code %x\n",
  532. __func__,
  533. event_code);
  534. return SCI_FAILURE;
  535. }
  536. return SCI_SUCCESS;
  537. case SCI_PHY_SUB_AWAIT_SAS_SPEED_EN:
  538. switch (scu_get_event_code(event_code)) {
  539. case SCU_EVENT_SAS_PHY_DETECTED:
  540. /*
  541. * Why is this being reported again by the controller?
  542. * We would re-enter this state so just stay here */
  543. break;
  544. case SCU_EVENT_SAS_15:
  545. case SCU_EVENT_SAS_15_SSC:
  546. scic_sds_phy_complete_link_training(
  547. sci_phy,
  548. SAS_LINK_RATE_1_5_GBPS,
  549. SCI_PHY_SUB_AWAIT_IAF_UF);
  550. break;
  551. case SCU_EVENT_SAS_30:
  552. case SCU_EVENT_SAS_30_SSC:
  553. scic_sds_phy_complete_link_training(
  554. sci_phy,
  555. SAS_LINK_RATE_3_0_GBPS,
  556. SCI_PHY_SUB_AWAIT_IAF_UF);
  557. break;
  558. case SCU_EVENT_SAS_60:
  559. case SCU_EVENT_SAS_60_SSC:
  560. scic_sds_phy_complete_link_training(
  561. sci_phy,
  562. SAS_LINK_RATE_6_0_GBPS,
  563. SCI_PHY_SUB_AWAIT_IAF_UF);
  564. break;
  565. case SCU_EVENT_SATA_SPINUP_HOLD:
  566. /*
  567. * We were doing SAS PHY link training and received a SATA PHY event
  568. * continue OOB/SN as if this were a SATA PHY */
  569. scic_sds_phy_start_sata_link_training(sci_phy);
  570. break;
  571. case SCU_EVENT_LINK_FAILURE:
  572. /* Link failure change state back to the starting state */
  573. sci_change_state(&sci_phy->sm, SCI_PHY_STARTING);
  574. break;
  575. default:
  576. dev_warn(sciphy_to_dev(sci_phy),
  577. "%s: PHY starting substate machine received "
  578. "unexpected event_code %x\n",
  579. __func__, event_code);
  580. return SCI_FAILURE;
  581. break;
  582. }
  583. return SCI_SUCCESS;
  584. case SCI_PHY_SUB_AWAIT_IAF_UF:
  585. switch (scu_get_event_code(event_code)) {
  586. case SCU_EVENT_SAS_PHY_DETECTED:
  587. /* Backup the state machine */
  588. scic_sds_phy_start_sas_link_training(sci_phy);
  589. break;
  590. case SCU_EVENT_SATA_SPINUP_HOLD:
  591. /* We were doing SAS PHY link training and received a
  592. * SATA PHY event continue OOB/SN as if this were a
  593. * SATA PHY
  594. */
  595. scic_sds_phy_start_sata_link_training(sci_phy);
  596. break;
  597. case SCU_EVENT_RECEIVED_IDENTIFY_TIMEOUT:
  598. case SCU_EVENT_LINK_FAILURE:
  599. case SCU_EVENT_HARD_RESET_RECEIVED:
  600. /* Start the oob/sn state machine over again */
  601. sci_change_state(&sci_phy->sm, SCI_PHY_STARTING);
  602. break;
  603. default:
  604. dev_warn(sciphy_to_dev(sci_phy),
  605. "%s: PHY starting substate machine received "
  606. "unexpected event_code %x\n",
  607. __func__, event_code);
  608. return SCI_FAILURE;
  609. }
  610. return SCI_SUCCESS;
  611. case SCI_PHY_SUB_AWAIT_SAS_POWER:
  612. switch (scu_get_event_code(event_code)) {
  613. case SCU_EVENT_LINK_FAILURE:
  614. /* Link failure change state back to the starting state */
  615. sci_change_state(&sci_phy->sm, SCI_PHY_STARTING);
  616. break;
  617. default:
  618. dev_warn(sciphy_to_dev(sci_phy),
  619. "%s: PHY starting substate machine received unexpected "
  620. "event_code %x\n",
  621. __func__,
  622. event_code);
  623. return SCI_FAILURE;
  624. }
  625. return SCI_SUCCESS;
  626. case SCI_PHY_SUB_AWAIT_SATA_POWER:
  627. switch (scu_get_event_code(event_code)) {
  628. case SCU_EVENT_LINK_FAILURE:
  629. /* Link failure change state back to the starting state */
  630. sci_change_state(&sci_phy->sm, SCI_PHY_STARTING);
  631. break;
  632. case SCU_EVENT_SATA_SPINUP_HOLD:
  633. /* These events are received every 10ms and are
  634. * expected while in this state
  635. */
  636. break;
  637. case SCU_EVENT_SAS_PHY_DETECTED:
  638. /* There has been a change in the phy type before OOB/SN for the
  639. * SATA finished start down the SAS link traning path.
  640. */
  641. scic_sds_phy_start_sas_link_training(sci_phy);
  642. break;
  643. default:
  644. dev_warn(sciphy_to_dev(sci_phy),
  645. "%s: PHY starting substate machine received "
  646. "unexpected event_code %x\n",
  647. __func__, event_code);
  648. return SCI_FAILURE;
  649. }
  650. return SCI_SUCCESS;
  651. case SCI_PHY_SUB_AWAIT_SATA_PHY_EN:
  652. switch (scu_get_event_code(event_code)) {
  653. case SCU_EVENT_LINK_FAILURE:
  654. /* Link failure change state back to the starting state */
  655. sci_change_state(&sci_phy->sm, SCI_PHY_STARTING);
  656. break;
  657. case SCU_EVENT_SATA_SPINUP_HOLD:
  658. /* These events might be received since we dont know how many may be in
  659. * the completion queue while waiting for power
  660. */
  661. break;
  662. case SCU_EVENT_SATA_PHY_DETECTED:
  663. sci_phy->protocol = SCIC_SDS_PHY_PROTOCOL_SATA;
  664. /* We have received the SATA PHY notification change state */
  665. sci_change_state(&sci_phy->sm, SCI_PHY_SUB_AWAIT_SATA_SPEED_EN);
  666. break;
  667. case SCU_EVENT_SAS_PHY_DETECTED:
  668. /* There has been a change in the phy type before OOB/SN for the
  669. * SATA finished start down the SAS link traning path.
  670. */
  671. scic_sds_phy_start_sas_link_training(sci_phy);
  672. break;
  673. default:
  674. dev_warn(sciphy_to_dev(sci_phy),
  675. "%s: PHY starting substate machine received "
  676. "unexpected event_code %x\n",
  677. __func__,
  678. event_code);
  679. return SCI_FAILURE;;
  680. }
  681. return SCI_SUCCESS;
  682. case SCI_PHY_SUB_AWAIT_SATA_SPEED_EN:
  683. switch (scu_get_event_code(event_code)) {
  684. case SCU_EVENT_SATA_PHY_DETECTED:
  685. /*
  686. * The hardware reports multiple SATA PHY detected events
  687. * ignore the extras */
  688. break;
  689. case SCU_EVENT_SATA_15:
  690. case SCU_EVENT_SATA_15_SSC:
  691. scic_sds_phy_complete_link_training(
  692. sci_phy,
  693. SAS_LINK_RATE_1_5_GBPS,
  694. SCI_PHY_SUB_AWAIT_SIG_FIS_UF);
  695. break;
  696. case SCU_EVENT_SATA_30:
  697. case SCU_EVENT_SATA_30_SSC:
  698. scic_sds_phy_complete_link_training(
  699. sci_phy,
  700. SAS_LINK_RATE_3_0_GBPS,
  701. SCI_PHY_SUB_AWAIT_SIG_FIS_UF);
  702. break;
  703. case SCU_EVENT_SATA_60:
  704. case SCU_EVENT_SATA_60_SSC:
  705. scic_sds_phy_complete_link_training(
  706. sci_phy,
  707. SAS_LINK_RATE_6_0_GBPS,
  708. SCI_PHY_SUB_AWAIT_SIG_FIS_UF);
  709. break;
  710. case SCU_EVENT_LINK_FAILURE:
  711. /* Link failure change state back to the starting state */
  712. sci_change_state(&sci_phy->sm, SCI_PHY_STARTING);
  713. break;
  714. case SCU_EVENT_SAS_PHY_DETECTED:
  715. /*
  716. * There has been a change in the phy type before OOB/SN for the
  717. * SATA finished start down the SAS link traning path. */
  718. scic_sds_phy_start_sas_link_training(sci_phy);
  719. break;
  720. default:
  721. dev_warn(sciphy_to_dev(sci_phy),
  722. "%s: PHY starting substate machine received "
  723. "unexpected event_code %x\n",
  724. __func__, event_code);
  725. return SCI_FAILURE;
  726. }
  727. return SCI_SUCCESS;
  728. case SCI_PHY_SUB_AWAIT_SIG_FIS_UF:
  729. switch (scu_get_event_code(event_code)) {
  730. case SCU_EVENT_SATA_PHY_DETECTED:
  731. /* Backup the state machine */
  732. sci_change_state(&sci_phy->sm, SCI_PHY_SUB_AWAIT_SATA_SPEED_EN);
  733. break;
  734. case SCU_EVENT_LINK_FAILURE:
  735. /* Link failure change state back to the starting state */
  736. sci_change_state(&sci_phy->sm, SCI_PHY_STARTING);
  737. break;
  738. default:
  739. dev_warn(sciphy_to_dev(sci_phy),
  740. "%s: PHY starting substate machine received "
  741. "unexpected event_code %x\n",
  742. __func__,
  743. event_code);
  744. return SCI_FAILURE;
  745. }
  746. return SCI_SUCCESS;
  747. case SCI_PHY_READY:
  748. switch (scu_get_event_code(event_code)) {
  749. case SCU_EVENT_LINK_FAILURE:
  750. /* Link failure change state back to the starting state */
  751. sci_change_state(&sci_phy->sm, SCI_PHY_STARTING);
  752. break;
  753. case SCU_EVENT_BROADCAST_CHANGE:
  754. /* Broadcast change received. Notify the port. */
  755. if (phy_get_non_dummy_port(sci_phy) != NULL)
  756. scic_sds_port_broadcast_change_received(sci_phy->owning_port, sci_phy);
  757. else
  758. sci_phy->bcn_received_while_port_unassigned = true;
  759. break;
  760. default:
  761. dev_warn(sciphy_to_dev(sci_phy),
  762. "%sP SCIC PHY 0x%p ready state machine received "
  763. "unexpected event_code %x\n",
  764. __func__, sci_phy, event_code);
  765. return SCI_FAILURE_INVALID_STATE;
  766. }
  767. return SCI_SUCCESS;
  768. case SCI_PHY_RESETTING:
  769. switch (scu_get_event_code(event_code)) {
  770. case SCU_EVENT_HARD_RESET_TRANSMITTED:
  771. /* Link failure change state back to the starting state */
  772. sci_change_state(&sci_phy->sm, SCI_PHY_STARTING);
  773. break;
  774. default:
  775. dev_warn(sciphy_to_dev(sci_phy),
  776. "%s: SCIC PHY 0x%p resetting state machine received "
  777. "unexpected event_code %x\n",
  778. __func__, sci_phy, event_code);
  779. return SCI_FAILURE_INVALID_STATE;
  780. break;
  781. }
  782. return SCI_SUCCESS;
  783. default:
  784. dev_dbg(sciphy_to_dev(sci_phy),
  785. "%s: in wrong state: %d\n", __func__, state);
  786. return SCI_FAILURE_INVALID_STATE;
  787. }
  788. }
  789. enum sci_status scic_sds_phy_frame_handler(struct scic_sds_phy *sci_phy,
  790. u32 frame_index)
  791. {
  792. enum scic_sds_phy_states state = sci_phy->sm.current_state_id;
  793. struct scic_sds_controller *scic = sci_phy->owning_port->owning_controller;
  794. enum sci_status result;
  795. switch (state) {
  796. case SCI_PHY_SUB_AWAIT_IAF_UF: {
  797. u32 *frame_words;
  798. struct sas_identify_frame iaf;
  799. struct isci_phy *iphy = sci_phy_to_iphy(sci_phy);
  800. result = scic_sds_unsolicited_frame_control_get_header(&scic->uf_control,
  801. frame_index,
  802. (void **)&frame_words);
  803. if (result != SCI_SUCCESS)
  804. return result;
  805. sci_swab32_cpy(&iaf, frame_words, sizeof(iaf) / sizeof(u32));
  806. if (iaf.frame_type == 0) {
  807. u32 state;
  808. memcpy(&iphy->frame_rcvd.iaf, &iaf, sizeof(iaf));
  809. if (iaf.smp_tport) {
  810. /* We got the IAF for an expander PHY go to the final
  811. * state since there are no power requirements for
  812. * expander phys.
  813. */
  814. state = SCI_PHY_SUB_FINAL;
  815. } else {
  816. /* We got the IAF we can now go to the await spinup
  817. * semaphore state
  818. */
  819. state = SCI_PHY_SUB_AWAIT_SAS_POWER;
  820. }
  821. sci_change_state(&sci_phy->sm, state);
  822. result = SCI_SUCCESS;
  823. } else
  824. dev_warn(sciphy_to_dev(sci_phy),
  825. "%s: PHY starting substate machine received "
  826. "unexpected frame id %x\n",
  827. __func__, frame_index);
  828. scic_sds_controller_release_frame(scic, frame_index);
  829. return result;
  830. }
  831. case SCI_PHY_SUB_AWAIT_SIG_FIS_UF: {
  832. struct dev_to_host_fis *frame_header;
  833. u32 *fis_frame_data;
  834. struct isci_phy *iphy = sci_phy_to_iphy(sci_phy);
  835. result = scic_sds_unsolicited_frame_control_get_header(
  836. &(scic_sds_phy_get_controller(sci_phy)->uf_control),
  837. frame_index,
  838. (void **)&frame_header);
  839. if (result != SCI_SUCCESS)
  840. return result;
  841. if ((frame_header->fis_type == FIS_REGD2H) &&
  842. !(frame_header->status & ATA_BUSY)) {
  843. scic_sds_unsolicited_frame_control_get_buffer(&scic->uf_control,
  844. frame_index,
  845. (void **)&fis_frame_data);
  846. scic_sds_controller_copy_sata_response(&iphy->frame_rcvd.fis,
  847. frame_header,
  848. fis_frame_data);
  849. /* got IAF we can now go to the await spinup semaphore state */
  850. sci_change_state(&sci_phy->sm, SCI_PHY_SUB_FINAL);
  851. result = SCI_SUCCESS;
  852. } else
  853. dev_warn(sciphy_to_dev(sci_phy),
  854. "%s: PHY starting substate machine received "
  855. "unexpected frame id %x\n",
  856. __func__, frame_index);
  857. /* Regardless of the result we are done with this frame with it */
  858. scic_sds_controller_release_frame(scic, frame_index);
  859. return result;
  860. }
  861. default:
  862. dev_dbg(sciphy_to_dev(sci_phy),
  863. "%s: in wrong state: %d\n", __func__, state);
  864. return SCI_FAILURE_INVALID_STATE;
  865. }
  866. }
  867. static void scic_sds_phy_starting_initial_substate_enter(struct sci_base_state_machine *sm)
  868. {
  869. struct scic_sds_phy *sci_phy = container_of(sm, typeof(*sci_phy), sm);
  870. /* This is just an temporary state go off to the starting state */
  871. sci_change_state(&sci_phy->sm, SCI_PHY_SUB_AWAIT_OSSP_EN);
  872. }
  873. static void scic_sds_phy_starting_await_sas_power_substate_enter(struct sci_base_state_machine *sm)
  874. {
  875. struct scic_sds_phy *sci_phy = container_of(sm, typeof(*sci_phy), sm);
  876. struct scic_sds_controller *scic = sci_phy->owning_port->owning_controller;
  877. scic_sds_controller_power_control_queue_insert(scic, sci_phy);
  878. }
  879. static void scic_sds_phy_starting_await_sas_power_substate_exit(struct sci_base_state_machine *sm)
  880. {
  881. struct scic_sds_phy *sci_phy = container_of(sm, typeof(*sci_phy), sm);
  882. struct scic_sds_controller *scic = sci_phy->owning_port->owning_controller;
  883. scic_sds_controller_power_control_queue_remove(scic, sci_phy);
  884. }
  885. static void scic_sds_phy_starting_await_sata_power_substate_enter(struct sci_base_state_machine *sm)
  886. {
  887. struct scic_sds_phy *sci_phy = container_of(sm, typeof(*sci_phy), sm);
  888. struct scic_sds_controller *scic = sci_phy->owning_port->owning_controller;
  889. scic_sds_controller_power_control_queue_insert(scic, sci_phy);
  890. }
  891. static void scic_sds_phy_starting_await_sata_power_substate_exit(struct sci_base_state_machine *sm)
  892. {
  893. struct scic_sds_phy *sci_phy = container_of(sm, typeof(*sci_phy), sm);
  894. struct scic_sds_controller *scic = sci_phy->owning_port->owning_controller;
  895. scic_sds_controller_power_control_queue_remove(scic, sci_phy);
  896. }
  897. static void scic_sds_phy_starting_await_sata_phy_substate_enter(struct sci_base_state_machine *sm)
  898. {
  899. struct scic_sds_phy *sci_phy = container_of(sm, typeof(*sci_phy), sm);
  900. sci_mod_timer(&sci_phy->sata_timer, SCIC_SDS_SATA_LINK_TRAINING_TIMEOUT);
  901. }
  902. static void scic_sds_phy_starting_await_sata_phy_substate_exit(struct sci_base_state_machine *sm)
  903. {
  904. struct scic_sds_phy *sci_phy = container_of(sm, typeof(*sci_phy), sm);
  905. sci_del_timer(&sci_phy->sata_timer);
  906. }
  907. static void scic_sds_phy_starting_await_sata_speed_substate_enter(struct sci_base_state_machine *sm)
  908. {
  909. struct scic_sds_phy *sci_phy = container_of(sm, typeof(*sci_phy), sm);
  910. sci_mod_timer(&sci_phy->sata_timer, SCIC_SDS_SATA_LINK_TRAINING_TIMEOUT);
  911. }
  912. static void scic_sds_phy_starting_await_sata_speed_substate_exit(struct sci_base_state_machine *sm)
  913. {
  914. struct scic_sds_phy *sci_phy = container_of(sm, typeof(*sci_phy), sm);
  915. sci_del_timer(&sci_phy->sata_timer);
  916. }
  917. static void scic_sds_phy_starting_await_sig_fis_uf_substate_enter(struct sci_base_state_machine *sm)
  918. {
  919. struct scic_sds_phy *sci_phy = container_of(sm, typeof(*sci_phy), sm);
  920. if (scic_sds_port_link_detected(sci_phy->owning_port, sci_phy)) {
  921. /*
  922. * Clear the PE suspend condition so we can actually
  923. * receive SIG FIS
  924. * The hardware will not respond to the XRDY until the PE
  925. * suspend condition is cleared.
  926. */
  927. scic_sds_phy_resume(sci_phy);
  928. sci_mod_timer(&sci_phy->sata_timer,
  929. SCIC_SDS_SIGNATURE_FIS_TIMEOUT);
  930. } else
  931. sci_phy->is_in_link_training = false;
  932. }
  933. static void scic_sds_phy_starting_await_sig_fis_uf_substate_exit(struct sci_base_state_machine *sm)
  934. {
  935. struct scic_sds_phy *sci_phy = container_of(sm, typeof(*sci_phy), sm);
  936. sci_del_timer(&sci_phy->sata_timer);
  937. }
  938. static void scic_sds_phy_starting_final_substate_enter(struct sci_base_state_machine *sm)
  939. {
  940. struct scic_sds_phy *sci_phy = container_of(sm, typeof(*sci_phy), sm);
  941. /* State machine has run to completion so exit out and change
  942. * the base state machine to the ready state
  943. */
  944. sci_change_state(&sci_phy->sm, SCI_PHY_READY);
  945. }
  946. /**
  947. *
  948. * @sci_phy: This is the struct scic_sds_phy object to stop.
  949. *
  950. * This method will stop the struct scic_sds_phy object. This does not reset the
  951. * protocol engine it just suspends it and places it in a state where it will
  952. * not cause the end device to power up. none
  953. */
  954. static void scu_link_layer_stop_protocol_engine(
  955. struct scic_sds_phy *sci_phy)
  956. {
  957. u32 scu_sas_pcfg_value;
  958. u32 enable_spinup_value;
  959. /* Suspend the protocol engine and place it in a sata spinup hold state */
  960. scu_sas_pcfg_value =
  961. readl(&sci_phy->link_layer_registers->phy_configuration);
  962. scu_sas_pcfg_value |=
  963. (SCU_SAS_PCFG_GEN_BIT(OOB_RESET) |
  964. SCU_SAS_PCFG_GEN_BIT(SUSPEND_PROTOCOL_ENGINE) |
  965. SCU_SAS_PCFG_GEN_BIT(SATA_SPINUP_HOLD));
  966. writel(scu_sas_pcfg_value,
  967. &sci_phy->link_layer_registers->phy_configuration);
  968. /* Disable the notify enable spinup primitives */
  969. enable_spinup_value = readl(&sci_phy->link_layer_registers->notify_enable_spinup_control);
  970. enable_spinup_value &= ~SCU_ENSPINUP_GEN_BIT(ENABLE);
  971. writel(enable_spinup_value, &sci_phy->link_layer_registers->notify_enable_spinup_control);
  972. }
  973. /**
  974. *
  975. *
  976. * This method will start the OOB/SN state machine for this struct scic_sds_phy object.
  977. */
  978. static void scu_link_layer_start_oob(
  979. struct scic_sds_phy *sci_phy)
  980. {
  981. u32 scu_sas_pcfg_value;
  982. scu_sas_pcfg_value =
  983. readl(&sci_phy->link_layer_registers->phy_configuration);
  984. scu_sas_pcfg_value |= SCU_SAS_PCFG_GEN_BIT(OOB_ENABLE);
  985. scu_sas_pcfg_value &=
  986. ~(SCU_SAS_PCFG_GEN_BIT(OOB_RESET) |
  987. SCU_SAS_PCFG_GEN_BIT(HARD_RESET));
  988. writel(scu_sas_pcfg_value,
  989. &sci_phy->link_layer_registers->phy_configuration);
  990. }
  991. /**
  992. *
  993. *
  994. * This method will transmit a hard reset request on the specified phy. The SCU
  995. * hardware requires that we reset the OOB state machine and set the hard reset
  996. * bit in the phy configuration register. We then must start OOB over with the
  997. * hard reset bit set.
  998. */
  999. static void scu_link_layer_tx_hard_reset(
  1000. struct scic_sds_phy *sci_phy)
  1001. {
  1002. u32 phy_configuration_value;
  1003. /*
  1004. * SAS Phys must wait for the HARD_RESET_TX event notification to transition
  1005. * to the starting state. */
  1006. phy_configuration_value =
  1007. readl(&sci_phy->link_layer_registers->phy_configuration);
  1008. phy_configuration_value |=
  1009. (SCU_SAS_PCFG_GEN_BIT(HARD_RESET) |
  1010. SCU_SAS_PCFG_GEN_BIT(OOB_RESET));
  1011. writel(phy_configuration_value,
  1012. &sci_phy->link_layer_registers->phy_configuration);
  1013. /* Now take the OOB state machine out of reset */
  1014. phy_configuration_value |= SCU_SAS_PCFG_GEN_BIT(OOB_ENABLE);
  1015. phy_configuration_value &= ~SCU_SAS_PCFG_GEN_BIT(OOB_RESET);
  1016. writel(phy_configuration_value,
  1017. &sci_phy->link_layer_registers->phy_configuration);
  1018. }
  1019. static void scic_sds_phy_stopped_state_enter(struct sci_base_state_machine *sm)
  1020. {
  1021. struct scic_sds_phy *sci_phy = container_of(sm, typeof(*sci_phy), sm);
  1022. /*
  1023. * @todo We need to get to the controller to place this PE in a
  1024. * reset state
  1025. */
  1026. sci_del_timer(&sci_phy->sata_timer);
  1027. scu_link_layer_stop_protocol_engine(sci_phy);
  1028. if (sci_phy->sm.previous_state_id != SCI_PHY_INITIAL)
  1029. scic_sds_controller_link_down(scic_sds_phy_get_controller(sci_phy),
  1030. phy_get_non_dummy_port(sci_phy),
  1031. sci_phy);
  1032. }
  1033. static void scic_sds_phy_starting_state_enter(struct sci_base_state_machine *sm)
  1034. {
  1035. struct scic_sds_phy *sci_phy = container_of(sm, typeof(*sci_phy), sm);
  1036. scu_link_layer_stop_protocol_engine(sci_phy);
  1037. scu_link_layer_start_oob(sci_phy);
  1038. /* We don't know what kind of phy we are going to be just yet */
  1039. sci_phy->protocol = SCIC_SDS_PHY_PROTOCOL_UNKNOWN;
  1040. sci_phy->bcn_received_while_port_unassigned = false;
  1041. if (sci_phy->sm.previous_state_id == SCI_PHY_READY)
  1042. scic_sds_controller_link_down(scic_sds_phy_get_controller(sci_phy),
  1043. phy_get_non_dummy_port(sci_phy),
  1044. sci_phy);
  1045. sci_change_state(&sci_phy->sm, SCI_PHY_SUB_INITIAL);
  1046. }
  1047. static void scic_sds_phy_ready_state_enter(struct sci_base_state_machine *sm)
  1048. {
  1049. struct scic_sds_phy *sci_phy = container_of(sm, typeof(*sci_phy), sm);
  1050. scic_sds_controller_link_up(scic_sds_phy_get_controller(sci_phy),
  1051. phy_get_non_dummy_port(sci_phy),
  1052. sci_phy);
  1053. }
  1054. static void scic_sds_phy_ready_state_exit(struct sci_base_state_machine *sm)
  1055. {
  1056. struct scic_sds_phy *sci_phy = container_of(sm, typeof(*sci_phy), sm);
  1057. scic_sds_phy_suspend(sci_phy);
  1058. }
  1059. static void scic_sds_phy_resetting_state_enter(struct sci_base_state_machine *sm)
  1060. {
  1061. struct scic_sds_phy *sci_phy = container_of(sm, typeof(*sci_phy), sm);
  1062. /* The phy is being reset, therefore deactivate it from the port. In
  1063. * the resetting state we don't notify the user regarding link up and
  1064. * link down notifications
  1065. */
  1066. scic_sds_port_deactivate_phy(sci_phy->owning_port, sci_phy, false);
  1067. if (sci_phy->protocol == SCIC_SDS_PHY_PROTOCOL_SAS) {
  1068. scu_link_layer_tx_hard_reset(sci_phy);
  1069. } else {
  1070. /* The SCU does not need to have a discrete reset state so
  1071. * just go back to the starting state.
  1072. */
  1073. sci_change_state(&sci_phy->sm, SCI_PHY_STARTING);
  1074. }
  1075. }
  1076. static const struct sci_base_state scic_sds_phy_state_table[] = {
  1077. [SCI_PHY_INITIAL] = { },
  1078. [SCI_PHY_STOPPED] = {
  1079. .enter_state = scic_sds_phy_stopped_state_enter,
  1080. },
  1081. [SCI_PHY_STARTING] = {
  1082. .enter_state = scic_sds_phy_starting_state_enter,
  1083. },
  1084. [SCI_PHY_SUB_INITIAL] = {
  1085. .enter_state = scic_sds_phy_starting_initial_substate_enter,
  1086. },
  1087. [SCI_PHY_SUB_AWAIT_OSSP_EN] = { },
  1088. [SCI_PHY_SUB_AWAIT_SAS_SPEED_EN] = { },
  1089. [SCI_PHY_SUB_AWAIT_IAF_UF] = { },
  1090. [SCI_PHY_SUB_AWAIT_SAS_POWER] = {
  1091. .enter_state = scic_sds_phy_starting_await_sas_power_substate_enter,
  1092. .exit_state = scic_sds_phy_starting_await_sas_power_substate_exit,
  1093. },
  1094. [SCI_PHY_SUB_AWAIT_SATA_POWER] = {
  1095. .enter_state = scic_sds_phy_starting_await_sata_power_substate_enter,
  1096. .exit_state = scic_sds_phy_starting_await_sata_power_substate_exit
  1097. },
  1098. [SCI_PHY_SUB_AWAIT_SATA_PHY_EN] = {
  1099. .enter_state = scic_sds_phy_starting_await_sata_phy_substate_enter,
  1100. .exit_state = scic_sds_phy_starting_await_sata_phy_substate_exit
  1101. },
  1102. [SCI_PHY_SUB_AWAIT_SATA_SPEED_EN] = {
  1103. .enter_state = scic_sds_phy_starting_await_sata_speed_substate_enter,
  1104. .exit_state = scic_sds_phy_starting_await_sata_speed_substate_exit
  1105. },
  1106. [SCI_PHY_SUB_AWAIT_SIG_FIS_UF] = {
  1107. .enter_state = scic_sds_phy_starting_await_sig_fis_uf_substate_enter,
  1108. .exit_state = scic_sds_phy_starting_await_sig_fis_uf_substate_exit
  1109. },
  1110. [SCI_PHY_SUB_FINAL] = {
  1111. .enter_state = scic_sds_phy_starting_final_substate_enter,
  1112. },
  1113. [SCI_PHY_READY] = {
  1114. .enter_state = scic_sds_phy_ready_state_enter,
  1115. .exit_state = scic_sds_phy_ready_state_exit,
  1116. },
  1117. [SCI_PHY_RESETTING] = {
  1118. .enter_state = scic_sds_phy_resetting_state_enter,
  1119. },
  1120. [SCI_PHY_FINAL] = { },
  1121. };
  1122. void scic_sds_phy_construct(struct scic_sds_phy *sci_phy,
  1123. struct scic_sds_port *owning_port, u8 phy_index)
  1124. {
  1125. sci_init_sm(&sci_phy->sm, scic_sds_phy_state_table, SCI_PHY_INITIAL);
  1126. /* Copy the rest of the input data to our locals */
  1127. sci_phy->owning_port = owning_port;
  1128. sci_phy->phy_index = phy_index;
  1129. sci_phy->bcn_received_while_port_unassigned = false;
  1130. sci_phy->protocol = SCIC_SDS_PHY_PROTOCOL_UNKNOWN;
  1131. sci_phy->link_layer_registers = NULL;
  1132. sci_phy->max_negotiated_speed = SAS_LINK_RATE_UNKNOWN;
  1133. /* Create the SIGNATURE FIS Timeout timer for this phy */
  1134. sci_init_timer(&sci_phy->sata_timer, phy_sata_timeout);
  1135. }
  1136. void isci_phy_init(struct isci_phy *iphy, struct isci_host *ihost, int index)
  1137. {
  1138. union scic_oem_parameters oem;
  1139. u64 sci_sas_addr;
  1140. __be64 sas_addr;
  1141. scic_oem_parameters_get(&ihost->sci, &oem);
  1142. sci_sas_addr = oem.sds1.phys[index].sas_address.high;
  1143. sci_sas_addr <<= 32;
  1144. sci_sas_addr |= oem.sds1.phys[index].sas_address.low;
  1145. sas_addr = cpu_to_be64(sci_sas_addr);
  1146. memcpy(iphy->sas_addr, &sas_addr, sizeof(sas_addr));
  1147. iphy->isci_port = NULL;
  1148. iphy->sas_phy.enabled = 0;
  1149. iphy->sas_phy.id = index;
  1150. iphy->sas_phy.sas_addr = &iphy->sas_addr[0];
  1151. iphy->sas_phy.frame_rcvd = (u8 *)&iphy->frame_rcvd;
  1152. iphy->sas_phy.ha = &ihost->sas_ha;
  1153. iphy->sas_phy.lldd_phy = iphy;
  1154. iphy->sas_phy.enabled = 1;
  1155. iphy->sas_phy.class = SAS;
  1156. iphy->sas_phy.iproto = SAS_PROTOCOL_ALL;
  1157. iphy->sas_phy.tproto = 0;
  1158. iphy->sas_phy.type = PHY_TYPE_PHYSICAL;
  1159. iphy->sas_phy.role = PHY_ROLE_INITIATOR;
  1160. iphy->sas_phy.oob_mode = OOB_NOT_CONNECTED;
  1161. iphy->sas_phy.linkrate = SAS_LINK_RATE_UNKNOWN;
  1162. memset(&iphy->frame_rcvd, 0, sizeof(iphy->frame_rcvd));
  1163. }
  1164. /**
  1165. * isci_phy_control() - This function is one of the SAS Domain Template
  1166. * functions. This is a phy management function.
  1167. * @phy: This parameter specifies the sphy being controlled.
  1168. * @func: This parameter specifies the phy control function being invoked.
  1169. * @buf: This parameter is specific to the phy function being invoked.
  1170. *
  1171. * status, zero indicates success.
  1172. */
  1173. int isci_phy_control(struct asd_sas_phy *sas_phy,
  1174. enum phy_func func,
  1175. void *buf)
  1176. {
  1177. int ret = 0;
  1178. struct isci_phy *iphy = sas_phy->lldd_phy;
  1179. struct isci_port *iport = iphy->isci_port;
  1180. struct isci_host *ihost = sas_phy->ha->lldd_ha;
  1181. unsigned long flags;
  1182. dev_dbg(&ihost->pdev->dev,
  1183. "%s: phy %p; func %d; buf %p; isci phy %p, port %p\n",
  1184. __func__, sas_phy, func, buf, iphy, iport);
  1185. switch (func) {
  1186. case PHY_FUNC_DISABLE:
  1187. spin_lock_irqsave(&ihost->scic_lock, flags);
  1188. scic_sds_phy_stop(&iphy->sci);
  1189. spin_unlock_irqrestore(&ihost->scic_lock, flags);
  1190. break;
  1191. case PHY_FUNC_LINK_RESET:
  1192. spin_lock_irqsave(&ihost->scic_lock, flags);
  1193. scic_sds_phy_stop(&iphy->sci);
  1194. scic_sds_phy_start(&iphy->sci);
  1195. spin_unlock_irqrestore(&ihost->scic_lock, flags);
  1196. break;
  1197. case PHY_FUNC_HARD_RESET:
  1198. if (!iport)
  1199. return -ENODEV;
  1200. /* Perform the port reset. */
  1201. ret = isci_port_perform_hard_reset(ihost, iport, iphy);
  1202. break;
  1203. default:
  1204. dev_dbg(&ihost->pdev->dev,
  1205. "%s: phy %p; func %d NOT IMPLEMENTED!\n",
  1206. __func__, sas_phy, func);
  1207. ret = -ENOSYS;
  1208. break;
  1209. }
  1210. return ret;
  1211. }