phy.c 67 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117
  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 "timers.h"
  60. #include "probe_roms.h"
  61. /* Maximum arbitration wait time in micro-seconds */
  62. #define SCIC_SDS_PHY_MAX_ARBITRATION_WAIT_TIME (700)
  63. enum sas_linkrate sci_phy_linkrate(struct scic_sds_phy *sci_phy)
  64. {
  65. return sci_phy->max_negotiated_speed;
  66. }
  67. /*
  68. * *****************************************************************************
  69. * * SCIC SDS PHY Internal Methods
  70. * ***************************************************************************** */
  71. /**
  72. * This method will initialize the phy transport layer registers
  73. * @sci_phy:
  74. * @transport_layer_registers
  75. *
  76. * enum sci_status
  77. */
  78. static enum sci_status scic_sds_phy_transport_layer_initialization(
  79. struct scic_sds_phy *sci_phy,
  80. struct scu_transport_layer_registers __iomem *transport_layer_registers)
  81. {
  82. u32 tl_control;
  83. sci_phy->transport_layer_registers = transport_layer_registers;
  84. writel(SCIC_SDS_REMOTE_NODE_CONTEXT_INVALID_INDEX,
  85. &sci_phy->transport_layer_registers->stp_rni);
  86. /*
  87. * Hardware team recommends that we enable the STP prefetch for all
  88. * transports
  89. */
  90. tl_control = readl(&sci_phy->transport_layer_registers->control);
  91. tl_control |= SCU_TLCR_GEN_BIT(STP_WRITE_DATA_PREFETCH);
  92. writel(tl_control, &sci_phy->transport_layer_registers->control);
  93. return SCI_SUCCESS;
  94. }
  95. /**
  96. * This method will initialize the phy link layer registers
  97. * @sci_phy:
  98. * @link_layer_registers:
  99. *
  100. * enum sci_status
  101. */
  102. static enum sci_status
  103. scic_sds_phy_link_layer_initialization(struct scic_sds_phy *sci_phy,
  104. struct scu_link_layer_registers __iomem *link_layer_registers)
  105. {
  106. struct scic_sds_controller *scic =
  107. sci_phy->owning_port->owning_controller;
  108. int phy_idx = sci_phy->phy_index;
  109. struct sci_phy_user_params *phy_user =
  110. &scic->user_parameters.sds1.phys[phy_idx];
  111. struct sci_phy_oem_params *phy_oem =
  112. &scic->oem_parameters.sds1.phys[phy_idx];
  113. u32 phy_configuration;
  114. struct scic_phy_cap phy_cap;
  115. u32 parity_check = 0;
  116. u32 parity_count = 0;
  117. u32 llctl, link_rate;
  118. u32 clksm_value = 0;
  119. sci_phy->link_layer_registers = link_layer_registers;
  120. /* Set our IDENTIFY frame data */
  121. #define SCI_END_DEVICE 0x01
  122. writel(SCU_SAS_TIID_GEN_BIT(SMP_INITIATOR) |
  123. SCU_SAS_TIID_GEN_BIT(SSP_INITIATOR) |
  124. SCU_SAS_TIID_GEN_BIT(STP_INITIATOR) |
  125. SCU_SAS_TIID_GEN_BIT(DA_SATA_HOST) |
  126. SCU_SAS_TIID_GEN_VAL(DEVICE_TYPE, SCI_END_DEVICE),
  127. &sci_phy->link_layer_registers->transmit_identification);
  128. /* Write the device SAS Address */
  129. writel(0xFEDCBA98,
  130. &sci_phy->link_layer_registers->sas_device_name_high);
  131. writel(phy_idx, &sci_phy->link_layer_registers->sas_device_name_low);
  132. /* Write the source SAS Address */
  133. writel(phy_oem->sas_address.high,
  134. &sci_phy->link_layer_registers->source_sas_address_high);
  135. writel(phy_oem->sas_address.low,
  136. &sci_phy->link_layer_registers->source_sas_address_low);
  137. /* Clear and Set the PHY Identifier */
  138. writel(0, &sci_phy->link_layer_registers->identify_frame_phy_id);
  139. writel(SCU_SAS_TIPID_GEN_VALUE(ID, phy_idx),
  140. &sci_phy->link_layer_registers->identify_frame_phy_id);
  141. /* Change the initial state of the phy configuration register */
  142. phy_configuration =
  143. readl(&sci_phy->link_layer_registers->phy_configuration);
  144. /* Hold OOB state machine in reset */
  145. phy_configuration |= SCU_SAS_PCFG_GEN_BIT(OOB_RESET);
  146. writel(phy_configuration,
  147. &sci_phy->link_layer_registers->phy_configuration);
  148. /* Configure the SNW capabilities */
  149. phy_cap.all = 0;
  150. phy_cap.start = 1;
  151. phy_cap.gen3_no_ssc = 1;
  152. phy_cap.gen2_no_ssc = 1;
  153. phy_cap.gen1_no_ssc = 1;
  154. if (scic->oem_parameters.sds1.controller.do_enable_ssc == true) {
  155. phy_cap.gen3_ssc = 1;
  156. phy_cap.gen2_ssc = 1;
  157. phy_cap.gen1_ssc = 1;
  158. }
  159. /*
  160. * The SAS specification indicates that the phy_capabilities that
  161. * are transmitted shall have an even parity. Calculate the parity. */
  162. parity_check = phy_cap.all;
  163. while (parity_check != 0) {
  164. if (parity_check & 0x1)
  165. parity_count++;
  166. parity_check >>= 1;
  167. }
  168. /*
  169. * If parity indicates there are an odd number of bits set, then
  170. * set the parity bit to 1 in the phy capabilities. */
  171. if ((parity_count % 2) != 0)
  172. phy_cap.parity = 1;
  173. writel(phy_cap.all, &sci_phy->link_layer_registers->phy_capabilities);
  174. /* Set the enable spinup period but disable the ability to send
  175. * notify enable spinup
  176. */
  177. writel(SCU_ENSPINUP_GEN_VAL(COUNT,
  178. phy_user->notify_enable_spin_up_insertion_frequency),
  179. &sci_phy->link_layer_registers->notify_enable_spinup_control);
  180. /* Write the ALIGN Insertion Ferequency for connected phy and
  181. * inpendent of connected state
  182. */
  183. clksm_value = SCU_ALIGN_INSERTION_FREQUENCY_GEN_VAL(CONNECTED,
  184. phy_user->in_connection_align_insertion_frequency);
  185. clksm_value |= SCU_ALIGN_INSERTION_FREQUENCY_GEN_VAL(GENERAL,
  186. phy_user->align_insertion_frequency);
  187. writel(clksm_value, &sci_phy->link_layer_registers->clock_skew_management);
  188. /* @todo Provide a way to write this register correctly */
  189. writel(0x02108421,
  190. &sci_phy->link_layer_registers->afe_lookup_table_control);
  191. llctl = SCU_SAS_LLCTL_GEN_VAL(NO_OUTBOUND_TASK_TIMEOUT,
  192. (u8)scic->user_parameters.sds1.no_outbound_task_timeout);
  193. switch(phy_user->max_speed_generation) {
  194. case SCIC_SDS_PARM_GEN3_SPEED:
  195. link_rate = SCU_SAS_LINK_LAYER_CONTROL_MAX_LINK_RATE_GEN3;
  196. break;
  197. case SCIC_SDS_PARM_GEN2_SPEED:
  198. link_rate = SCU_SAS_LINK_LAYER_CONTROL_MAX_LINK_RATE_GEN2;
  199. break;
  200. default:
  201. link_rate = SCU_SAS_LINK_LAYER_CONTROL_MAX_LINK_RATE_GEN1;
  202. break;
  203. }
  204. llctl |= SCU_SAS_LLCTL_GEN_VAL(MAX_LINK_RATE, link_rate);
  205. writel(llctl, &sci_phy->link_layer_registers->link_layer_control);
  206. if (is_a0() || is_a2()) {
  207. /* Program the max ARB time for the PHY to 700us so we inter-operate with
  208. * the PMC expander which shuts down PHYs if the expander PHY generates too
  209. * many breaks. This time value will guarantee that the initiator PHY will
  210. * generate the break.
  211. */
  212. writel(SCIC_SDS_PHY_MAX_ARBITRATION_WAIT_TIME,
  213. &sci_phy->link_layer_registers->maximum_arbitration_wait_timer_timeout);
  214. }
  215. /*
  216. * Set the link layer hang detection to 500ms (0x1F4) from its default
  217. * value of 128ms. Max value is 511 ms.
  218. */
  219. writel(0x1F4, &sci_phy->link_layer_registers->link_layer_hang_detection_timeout);
  220. /* We can exit the initial state to the stopped state */
  221. sci_base_state_machine_change_state(&sci_phy->state_machine,
  222. SCI_BASE_PHY_STATE_STOPPED);
  223. return SCI_SUCCESS;
  224. }
  225. /**
  226. * This function will handle the sata SIGNATURE FIS timeout condition. It will
  227. * restart the starting substate machine since we dont know what has actually
  228. * happening.
  229. */
  230. static void scic_sds_phy_sata_timeout(void *phy)
  231. {
  232. struct scic_sds_phy *sci_phy = phy;
  233. dev_dbg(sciphy_to_dev(sci_phy),
  234. "%s: SCIC SDS Phy 0x%p did not receive signature fis before "
  235. "timeout.\n",
  236. __func__,
  237. sci_phy);
  238. sci_base_state_machine_change_state(&sci_phy->state_machine,
  239. SCI_BASE_PHY_STATE_STARTING);
  240. }
  241. /**
  242. * This method returns the port currently containing this phy. If the phy is
  243. * currently contained by the dummy port, then the phy is considered to not
  244. * be part of a port.
  245. * @sci_phy: This parameter specifies the phy for which to retrieve the
  246. * containing port.
  247. *
  248. * This method returns a handle to a port that contains the supplied phy.
  249. * NULL This value is returned if the phy is not part of a real
  250. * port (i.e. it's contained in the dummy port). !NULL All other
  251. * values indicate a handle/pointer to the port containing the phy.
  252. */
  253. struct scic_sds_port *scic_sds_phy_get_port(
  254. struct scic_sds_phy *sci_phy)
  255. {
  256. if (scic_sds_port_get_index(sci_phy->owning_port) == SCIC_SDS_DUMMY_PORT)
  257. return NULL;
  258. return sci_phy->owning_port;
  259. }
  260. /**
  261. * This method will assign a port to the phy object.
  262. * @out]: sci_phy This parameter specifies the phy for which to assign a port
  263. * object.
  264. *
  265. *
  266. */
  267. void scic_sds_phy_set_port(
  268. struct scic_sds_phy *sci_phy,
  269. struct scic_sds_port *sci_port)
  270. {
  271. sci_phy->owning_port = sci_port;
  272. if (sci_phy->bcn_received_while_port_unassigned) {
  273. sci_phy->bcn_received_while_port_unassigned = false;
  274. scic_sds_port_broadcast_change_received(sci_phy->owning_port, sci_phy);
  275. }
  276. }
  277. /**
  278. * This method will initialize the constructed phy
  279. * @sci_phy:
  280. * @link_layer_registers:
  281. *
  282. * enum sci_status
  283. */
  284. enum sci_status scic_sds_phy_initialize(
  285. struct scic_sds_phy *sci_phy,
  286. struct scu_transport_layer_registers __iomem *transport_layer_registers,
  287. struct scu_link_layer_registers __iomem *link_layer_registers)
  288. {
  289. struct scic_sds_controller *scic = scic_sds_phy_get_controller(sci_phy);
  290. struct isci_host *ihost = scic_to_ihost(scic);
  291. /* Create the SIGNATURE FIS Timeout timer for this phy */
  292. sci_phy->sata_timeout_timer =
  293. isci_timer_create(
  294. ihost,
  295. sci_phy,
  296. scic_sds_phy_sata_timeout);
  297. /* Perfrom the initialization of the TL hardware */
  298. scic_sds_phy_transport_layer_initialization(
  299. sci_phy,
  300. transport_layer_registers);
  301. /* Perofrm the initialization of the PE hardware */
  302. scic_sds_phy_link_layer_initialization(sci_phy, link_layer_registers);
  303. /*
  304. * There is nothing that needs to be done in this state just
  305. * transition to the stopped state. */
  306. sci_base_state_machine_change_state(&sci_phy->state_machine,
  307. SCI_BASE_PHY_STATE_STOPPED);
  308. return SCI_SUCCESS;
  309. }
  310. /**
  311. * This method assigns the direct attached device ID for this phy.
  312. *
  313. * @sci_phy The phy for which the direct attached device id is to
  314. * be assigned.
  315. * @device_id The direct attached device ID to assign to the phy.
  316. * This will either be the RNi for the device or an invalid RNi if there
  317. * is no current device assigned to the phy.
  318. */
  319. void scic_sds_phy_setup_transport(
  320. struct scic_sds_phy *sci_phy,
  321. u32 device_id)
  322. {
  323. u32 tl_control;
  324. writel(device_id, &sci_phy->transport_layer_registers->stp_rni);
  325. /*
  326. * The read should guarantee that the first write gets posted
  327. * before the next write
  328. */
  329. tl_control = readl(&sci_phy->transport_layer_registers->control);
  330. tl_control |= SCU_TLCR_GEN_BIT(CLEAR_TCI_NCQ_MAPPING_TABLE);
  331. writel(tl_control, &sci_phy->transport_layer_registers->control);
  332. }
  333. /**
  334. *
  335. * @sci_phy: The phy object to be suspended.
  336. *
  337. * This function will perform the register reads/writes to suspend the SCU
  338. * hardware protocol engine. none
  339. */
  340. static void scic_sds_phy_suspend(
  341. 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. scic_sds_phy_setup_transport(
  350. sci_phy,
  351. SCIC_SDS_REMOTE_NODE_CONTEXT_INVALID_INDEX);
  352. }
  353. void scic_sds_phy_resume(struct scic_sds_phy *sci_phy)
  354. {
  355. u32 scu_sas_pcfg_value;
  356. scu_sas_pcfg_value =
  357. readl(&sci_phy->link_layer_registers->phy_configuration);
  358. scu_sas_pcfg_value &= ~SCU_SAS_PCFG_GEN_BIT(SUSPEND_PROTOCOL_ENGINE);
  359. writel(scu_sas_pcfg_value,
  360. &sci_phy->link_layer_registers->phy_configuration);
  361. }
  362. void scic_sds_phy_get_sas_address(struct scic_sds_phy *sci_phy,
  363. struct sci_sas_address *sas_address)
  364. {
  365. sas_address->high = readl(&sci_phy->link_layer_registers->source_sas_address_high);
  366. sas_address->low = readl(&sci_phy->link_layer_registers->source_sas_address_low);
  367. }
  368. void scic_sds_phy_get_attached_sas_address(struct scic_sds_phy *sci_phy,
  369. struct sci_sas_address *sas_address)
  370. {
  371. struct sas_identify_frame *iaf;
  372. struct isci_phy *iphy = sci_phy_to_iphy(sci_phy);
  373. iaf = &iphy->frame_rcvd.iaf;
  374. memcpy(sas_address, iaf->sas_addr, SAS_ADDR_SIZE);
  375. }
  376. void scic_sds_phy_get_protocols(struct scic_sds_phy *sci_phy,
  377. struct scic_phy_proto *protocols)
  378. {
  379. protocols->all =
  380. (u16)(readl(&sci_phy->
  381. link_layer_registers->transmit_identification) &
  382. 0x0000FFFF);
  383. }
  384. enum sci_status scic_sds_phy_start(struct scic_sds_phy *sci_phy)
  385. {
  386. struct scic_sds_controller *scic = sci_phy->owning_port->owning_controller;
  387. enum scic_sds_phy_states state = sci_phy->state_machine.current_state_id;
  388. struct isci_host *ihost = scic_to_ihost(scic);
  389. if (state != SCI_BASE_PHY_STATE_STOPPED) {
  390. dev_dbg(sciphy_to_dev(sci_phy),
  391. "%s: in wrong state: %d\n", __func__, state);
  392. return SCI_FAILURE_INVALID_STATE;
  393. }
  394. /* Create the SIGNATURE FIS Timeout timer for this phy */
  395. sci_phy->sata_timeout_timer = isci_timer_create(ihost, sci_phy,
  396. scic_sds_phy_sata_timeout);
  397. if (sci_phy->sata_timeout_timer)
  398. sci_base_state_machine_change_state(&sci_phy->state_machine,
  399. SCI_BASE_PHY_STATE_STARTING);
  400. return SCI_SUCCESS;
  401. }
  402. enum sci_status scic_sds_phy_stop(struct scic_sds_phy *sci_phy)
  403. {
  404. enum scic_sds_phy_states state = sci_phy->state_machine.current_state_id;
  405. switch (state) {
  406. case SCIC_SDS_PHY_STARTING_SUBSTATE_INITIAL:
  407. case SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_OSSP_EN:
  408. case SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_SPEED_EN:
  409. case SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_POWER:
  410. case SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_POWER:
  411. case SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_PHY_EN:
  412. case SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_SPEED_EN:
  413. case SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF:
  414. case SCIC_SDS_PHY_STARTING_SUBSTATE_FINAL:
  415. case SCI_BASE_PHY_STATE_READY:
  416. break;
  417. default:
  418. dev_dbg(sciphy_to_dev(sci_phy),
  419. "%s: in wrong state: %d\n", __func__, state);
  420. return SCI_FAILURE_INVALID_STATE;
  421. }
  422. sci_base_state_machine_change_state(&sci_phy->state_machine,
  423. SCI_BASE_PHY_STATE_STOPPED);
  424. return SCI_SUCCESS;
  425. }
  426. enum sci_status scic_sds_phy_reset(struct scic_sds_phy *sci_phy)
  427. {
  428. enum scic_sds_phy_states state = sci_phy->state_machine.current_state_id;
  429. if (state != SCI_BASE_PHY_STATE_READY) {
  430. dev_dbg(sciphy_to_dev(sci_phy),
  431. "%s: in wrong state: %d\n", __func__, state);
  432. return SCI_FAILURE_INVALID_STATE;
  433. }
  434. sci_base_state_machine_change_state(&sci_phy->state_machine,
  435. SCI_BASE_PHY_STATE_RESETTING);
  436. return SCI_SUCCESS;
  437. }
  438. /**
  439. * This method will process the event code received.
  440. * @sci_phy:
  441. * @event_code:
  442. *
  443. * enum sci_status
  444. */
  445. enum sci_status scic_sds_phy_event_handler(
  446. struct scic_sds_phy *sci_phy,
  447. u32 event_code)
  448. {
  449. return sci_phy->state_handlers->event_handler(sci_phy, event_code);
  450. }
  451. enum sci_status scic_sds_phy_frame_handler(struct scic_sds_phy *sci_phy,
  452. u32 frame_index)
  453. {
  454. enum scic_sds_phy_states state = sci_phy->state_machine.current_state_id;
  455. struct scic_sds_controller *scic = sci_phy->owning_port->owning_controller;
  456. enum sci_status result;
  457. switch (state) {
  458. case SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_IAF_UF: {
  459. u32 *frame_words;
  460. struct sas_identify_frame iaf;
  461. struct isci_phy *iphy = sci_phy_to_iphy(sci_phy);
  462. result = scic_sds_unsolicited_frame_control_get_header(&scic->uf_control,
  463. frame_index,
  464. (void **)&frame_words);
  465. if (result != SCI_SUCCESS)
  466. return result;
  467. sci_swab32_cpy(&iaf, frame_words, sizeof(iaf) / sizeof(u32));
  468. if (iaf.frame_type == 0) {
  469. u32 state;
  470. memcpy(&iphy->frame_rcvd.iaf, &iaf, sizeof(iaf));
  471. if (iaf.smp_tport) {
  472. /* We got the IAF for an expander PHY go to the final
  473. * state since there are no power requirements for
  474. * expander phys.
  475. */
  476. state = SCIC_SDS_PHY_STARTING_SUBSTATE_FINAL;
  477. } else {
  478. /* We got the IAF we can now go to the await spinup
  479. * semaphore state
  480. */
  481. state = SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_POWER;
  482. }
  483. sci_base_state_machine_change_state(&sci_phy->state_machine,
  484. state);
  485. result = SCI_SUCCESS;
  486. } else
  487. dev_warn(sciphy_to_dev(sci_phy),
  488. "%s: PHY starting substate machine received "
  489. "unexpected frame id %x\n",
  490. __func__, frame_index);
  491. scic_sds_controller_release_frame(scic, frame_index);
  492. return result;
  493. }
  494. case SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF: {
  495. struct dev_to_host_fis *frame_header;
  496. u32 *fis_frame_data;
  497. struct isci_phy *iphy = sci_phy_to_iphy(sci_phy);
  498. result = scic_sds_unsolicited_frame_control_get_header(
  499. &(scic_sds_phy_get_controller(sci_phy)->uf_control),
  500. frame_index,
  501. (void **)&frame_header);
  502. if (result != SCI_SUCCESS)
  503. return result;
  504. if ((frame_header->fis_type == FIS_REGD2H) &&
  505. !(frame_header->status & ATA_BUSY)) {
  506. scic_sds_unsolicited_frame_control_get_buffer(&scic->uf_control,
  507. frame_index,
  508. (void **)&fis_frame_data);
  509. scic_sds_controller_copy_sata_response(&iphy->frame_rcvd.fis,
  510. frame_header,
  511. fis_frame_data);
  512. /* got IAF we can now go to the await spinup semaphore state */
  513. sci_base_state_machine_change_state(&sci_phy->state_machine,
  514. SCIC_SDS_PHY_STARTING_SUBSTATE_FINAL);
  515. result = SCI_SUCCESS;
  516. } else
  517. dev_warn(sciphy_to_dev(sci_phy),
  518. "%s: PHY starting substate machine received "
  519. "unexpected frame id %x\n",
  520. __func__, frame_index);
  521. /* Regardless of the result we are done with this frame with it */
  522. scic_sds_controller_release_frame(scic, frame_index);
  523. return result;
  524. }
  525. default:
  526. dev_dbg(sciphy_to_dev(sci_phy),
  527. "%s: in wrong state: %d\n", __func__, state);
  528. return SCI_FAILURE_INVALID_STATE;
  529. }
  530. }
  531. /**
  532. * This method will give the phy permission to consume power
  533. * @sci_phy:
  534. *
  535. * enum sci_status
  536. */
  537. enum sci_status scic_sds_phy_consume_power_handler(
  538. struct scic_sds_phy *sci_phy)
  539. {
  540. return sci_phy->state_handlers->consume_power_handler(sci_phy);
  541. }
  542. /*
  543. * *****************************************************************************
  544. * * SCIC SDS PHY HELPER FUNCTIONS
  545. * ***************************************************************************** */
  546. /**
  547. *
  548. * @sci_phy: The phy object that received SAS PHY DETECTED.
  549. *
  550. * This method continues the link training for the phy as if it were a SAS PHY
  551. * instead of a SATA PHY. This is done because the completion queue had a SAS
  552. * PHY DETECTED event when the state machine was expecting a SATA PHY event.
  553. * none
  554. */
  555. static void scic_sds_phy_start_sas_link_training(
  556. struct scic_sds_phy *sci_phy)
  557. {
  558. u32 phy_control;
  559. phy_control =
  560. readl(&sci_phy->link_layer_registers->phy_configuration);
  561. phy_control |= SCU_SAS_PCFG_GEN_BIT(SATA_SPINUP_HOLD);
  562. writel(phy_control,
  563. &sci_phy->link_layer_registers->phy_configuration);
  564. sci_base_state_machine_change_state(
  565. &sci_phy->state_machine,
  566. SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_SPEED_EN
  567. );
  568. sci_phy->protocol = SCIC_SDS_PHY_PROTOCOL_SAS;
  569. }
  570. /**
  571. *
  572. * @sci_phy: The phy object that received a SATA SPINUP HOLD event
  573. *
  574. * This method continues the link training for the phy as if it were a SATA PHY
  575. * instead of a SAS PHY. This is done because the completion queue had a SATA
  576. * SPINUP HOLD event when the state machine was expecting a SAS PHY event. none
  577. */
  578. static void scic_sds_phy_start_sata_link_training(
  579. struct scic_sds_phy *sci_phy)
  580. {
  581. sci_base_state_machine_change_state(
  582. &sci_phy->state_machine,
  583. SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_POWER
  584. );
  585. sci_phy->protocol = SCIC_SDS_PHY_PROTOCOL_SATA;
  586. }
  587. /**
  588. * scic_sds_phy_complete_link_training - perform processing common to
  589. * all protocols upon completion of link training.
  590. * @sci_phy: This parameter specifies the phy object for which link training
  591. * has completed.
  592. * @max_link_rate: This parameter specifies the maximum link rate to be
  593. * associated with this phy.
  594. * @next_state: This parameter specifies the next state for the phy's starting
  595. * sub-state machine.
  596. *
  597. */
  598. static void scic_sds_phy_complete_link_training(
  599. struct scic_sds_phy *sci_phy,
  600. enum sas_linkrate max_link_rate,
  601. u32 next_state)
  602. {
  603. sci_phy->max_negotiated_speed = max_link_rate;
  604. sci_base_state_machine_change_state(&sci_phy->state_machine,
  605. next_state);
  606. }
  607. static void scic_sds_phy_restart_starting_state(
  608. struct scic_sds_phy *sci_phy)
  609. {
  610. /* Re-enter the base state machine starting state */
  611. sci_base_state_machine_change_state(&sci_phy->state_machine,
  612. SCI_BASE_PHY_STATE_STARTING);
  613. }
  614. /**
  615. *
  616. * @phy: This struct scic_sds_phy object which has received an event.
  617. * @event_code: This is the event code which the phy object is to decode.
  618. *
  619. * This method is called when an event notification is received for the phy
  620. * object when in the state SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SPEED_EN. -
  621. * decode the event - sas phy detected causes a state transition to the wait
  622. * for speed event notification. - any other events log a warning message and
  623. * set a failure status enum sci_status SCI_SUCCESS on any valid event notification
  624. * SCI_FAILURE on any unexpected event notifation
  625. */
  626. static enum sci_status scic_sds_phy_starting_substate_await_ossp_event_handler(
  627. struct scic_sds_phy *sci_phy,
  628. u32 event_code)
  629. {
  630. u32 result = SCI_SUCCESS;
  631. switch (scu_get_event_code(event_code)) {
  632. case SCU_EVENT_SAS_PHY_DETECTED:
  633. scic_sds_phy_start_sas_link_training(sci_phy);
  634. sci_phy->is_in_link_training = true;
  635. break;
  636. case SCU_EVENT_SATA_SPINUP_HOLD:
  637. scic_sds_phy_start_sata_link_training(sci_phy);
  638. sci_phy->is_in_link_training = true;
  639. break;
  640. default:
  641. dev_dbg(sciphy_to_dev(sci_phy),
  642. "%s: PHY starting substate machine received "
  643. "unexpected event_code %x\n",
  644. __func__,
  645. event_code);
  646. result = SCI_FAILURE;
  647. break;
  648. }
  649. return result;
  650. }
  651. /**
  652. *
  653. * @phy: This struct scic_sds_phy object which has received an event.
  654. * @event_code: This is the event code which the phy object is to decode.
  655. *
  656. * This method is called when an event notification is received for the phy
  657. * object when in the state SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SPEED_EN. -
  658. * decode the event - sas phy detected returns us back to this state. - speed
  659. * event detected causes a state transition to the wait for iaf. - identify
  660. * timeout is an un-expected event and the state machine is restarted. - link
  661. * failure events restart the starting state machine - any other events log a
  662. * warning message and set a failure status enum sci_status SCI_SUCCESS on any valid
  663. * event notification SCI_FAILURE on any unexpected event notifation
  664. */
  665. static enum sci_status scic_sds_phy_starting_substate_await_sas_phy_speed_event_handler(
  666. struct scic_sds_phy *sci_phy,
  667. u32 event_code)
  668. {
  669. u32 result = SCI_SUCCESS;
  670. switch (scu_get_event_code(event_code)) {
  671. case SCU_EVENT_SAS_PHY_DETECTED:
  672. /*
  673. * Why is this being reported again by the controller?
  674. * We would re-enter this state so just stay here */
  675. break;
  676. case SCU_EVENT_SAS_15:
  677. case SCU_EVENT_SAS_15_SSC:
  678. scic_sds_phy_complete_link_training(
  679. sci_phy,
  680. SAS_LINK_RATE_1_5_GBPS,
  681. SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_IAF_UF);
  682. break;
  683. case SCU_EVENT_SAS_30:
  684. case SCU_EVENT_SAS_30_SSC:
  685. scic_sds_phy_complete_link_training(
  686. sci_phy,
  687. SAS_LINK_RATE_3_0_GBPS,
  688. SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_IAF_UF);
  689. break;
  690. case SCU_EVENT_SAS_60:
  691. case SCU_EVENT_SAS_60_SSC:
  692. scic_sds_phy_complete_link_training(
  693. sci_phy,
  694. SAS_LINK_RATE_6_0_GBPS,
  695. SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_IAF_UF);
  696. break;
  697. case SCU_EVENT_SATA_SPINUP_HOLD:
  698. /*
  699. * We were doing SAS PHY link training and received a SATA PHY event
  700. * continue OOB/SN as if this were a SATA PHY */
  701. scic_sds_phy_start_sata_link_training(sci_phy);
  702. break;
  703. case SCU_EVENT_LINK_FAILURE:
  704. /* Link failure change state back to the starting state */
  705. scic_sds_phy_restart_starting_state(sci_phy);
  706. break;
  707. default:
  708. dev_warn(sciphy_to_dev(sci_phy),
  709. "%s: PHY starting substate machine received "
  710. "unexpected event_code %x\n",
  711. __func__,
  712. event_code);
  713. result = SCI_FAILURE;
  714. break;
  715. }
  716. return result;
  717. }
  718. /**
  719. *
  720. * @phy: This struct scic_sds_phy object which has received an event.
  721. * @event_code: This is the event code which the phy object is to decode.
  722. *
  723. * This method is called when an event notification is received for the phy
  724. * object when in the state SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_IAF_UF. -
  725. * decode the event - sas phy detected event backs up the state machine to the
  726. * await speed notification. - identify timeout is an un-expected event and the
  727. * state machine is restarted. - link failure events restart the starting state
  728. * machine - any other events log a warning message and set a failure status
  729. * enum sci_status SCI_SUCCESS on any valid event notification SCI_FAILURE on any
  730. * unexpected event notifation
  731. */
  732. static enum sci_status scic_sds_phy_starting_substate_await_iaf_uf_event_handler(
  733. struct scic_sds_phy *sci_phy,
  734. u32 event_code)
  735. {
  736. u32 result = SCI_SUCCESS;
  737. switch (scu_get_event_code(event_code)) {
  738. case SCU_EVENT_SAS_PHY_DETECTED:
  739. /* Backup the state machine */
  740. scic_sds_phy_start_sas_link_training(sci_phy);
  741. break;
  742. case SCU_EVENT_SATA_SPINUP_HOLD:
  743. /*
  744. * We were doing SAS PHY link training and received a SATA PHY event
  745. * continue OOB/SN as if this were a SATA PHY */
  746. scic_sds_phy_start_sata_link_training(sci_phy);
  747. break;
  748. case SCU_EVENT_RECEIVED_IDENTIFY_TIMEOUT:
  749. case SCU_EVENT_LINK_FAILURE:
  750. case SCU_EVENT_HARD_RESET_RECEIVED:
  751. /* Start the oob/sn state machine over again */
  752. scic_sds_phy_restart_starting_state(sci_phy);
  753. break;
  754. default:
  755. dev_warn(sciphy_to_dev(sci_phy),
  756. "%s: PHY starting substate machine received "
  757. "unexpected event_code %x\n",
  758. __func__,
  759. event_code);
  760. result = SCI_FAILURE;
  761. break;
  762. }
  763. return result;
  764. }
  765. /**
  766. *
  767. * @phy: This struct scic_sds_phy object which has received an event.
  768. * @event_code: This is the event code which the phy object is to decode.
  769. *
  770. * This method is called when an event notification is received for the phy
  771. * object when in the state SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_POWER. -
  772. * decode the event - link failure events restart the starting state machine -
  773. * any other events log a warning message and set a failure status enum sci_status
  774. * SCI_SUCCESS on a link failure event SCI_FAILURE on any unexpected event
  775. * notifation
  776. */
  777. static enum sci_status scic_sds_phy_starting_substate_await_sas_power_event_handler(
  778. struct scic_sds_phy *sci_phy,
  779. u32 event_code)
  780. {
  781. u32 result = SCI_SUCCESS;
  782. switch (scu_get_event_code(event_code)) {
  783. case SCU_EVENT_LINK_FAILURE:
  784. /* Link failure change state back to the starting state */
  785. scic_sds_phy_restart_starting_state(sci_phy);
  786. break;
  787. default:
  788. dev_warn(sciphy_to_dev(sci_phy),
  789. "%s: PHY starting substate machine received unexpected "
  790. "event_code %x\n",
  791. __func__,
  792. event_code);
  793. result = SCI_FAILURE;
  794. break;
  795. }
  796. return result;
  797. }
  798. /**
  799. *
  800. * @phy: This struct scic_sds_phy object which has received an event.
  801. * @event_code: This is the event code which the phy object is to decode.
  802. *
  803. * This method is called when an event notification is received for the phy
  804. * object when in the state SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_POWER. -
  805. * decode the event - link failure events restart the starting state machine -
  806. * sata spinup hold events are ignored since they are expected - any other
  807. * events log a warning message and set a failure status enum sci_status SCI_SUCCESS
  808. * on a link failure event SCI_FAILURE on any unexpected event notifation
  809. */
  810. static enum sci_status scic_sds_phy_starting_substate_await_sata_power_event_handler(
  811. struct scic_sds_phy *sci_phy,
  812. u32 event_code)
  813. {
  814. u32 result = SCI_SUCCESS;
  815. switch (scu_get_event_code(event_code)) {
  816. case SCU_EVENT_LINK_FAILURE:
  817. /* Link failure change state back to the starting state */
  818. scic_sds_phy_restart_starting_state(sci_phy);
  819. break;
  820. case SCU_EVENT_SATA_SPINUP_HOLD:
  821. /* These events are received every 10ms and are expected while in this state */
  822. break;
  823. case SCU_EVENT_SAS_PHY_DETECTED:
  824. /*
  825. * There has been a change in the phy type before OOB/SN for the
  826. * SATA finished start down the SAS link traning path. */
  827. scic_sds_phy_start_sas_link_training(sci_phy);
  828. break;
  829. default:
  830. dev_warn(sciphy_to_dev(sci_phy),
  831. "%s: PHY starting substate machine received "
  832. "unexpected event_code %x\n",
  833. __func__,
  834. event_code);
  835. result = SCI_FAILURE;
  836. break;
  837. }
  838. return result;
  839. }
  840. /**
  841. * scic_sds_phy_starting_substate_await_sata_phy_event_handler -
  842. * @phy: This struct scic_sds_phy object which has received an event.
  843. * @event_code: This is the event code which the phy object is to decode.
  844. *
  845. * This method is called when an event notification is received for the phy
  846. * object when in the state SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_PHY_EN. -
  847. * decode the event - link failure events restart the starting state machine -
  848. * sata spinup hold events are ignored since they are expected - sata phy
  849. * detected event change to the wait speed event - any other events log a
  850. * warning message and set a failure status enum sci_status SCI_SUCCESS on a link
  851. * failure event SCI_FAILURE on any unexpected event notifation
  852. */
  853. static enum sci_status scic_sds_phy_starting_substate_await_sata_phy_event_handler(
  854. struct scic_sds_phy *sci_phy, u32 event_code)
  855. {
  856. u32 result = SCI_SUCCESS;
  857. switch (scu_get_event_code(event_code)) {
  858. case SCU_EVENT_LINK_FAILURE:
  859. /* Link failure change state back to the starting state */
  860. scic_sds_phy_restart_starting_state(sci_phy);
  861. break;
  862. case SCU_EVENT_SATA_SPINUP_HOLD:
  863. /* These events might be received since we dont know how many may be in
  864. * the completion queue while waiting for power
  865. */
  866. break;
  867. case SCU_EVENT_SATA_PHY_DETECTED:
  868. sci_phy->protocol = SCIC_SDS_PHY_PROTOCOL_SATA;
  869. /* We have received the SATA PHY notification change state */
  870. sci_base_state_machine_change_state(&sci_phy->state_machine,
  871. SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_SPEED_EN);
  872. break;
  873. case SCU_EVENT_SAS_PHY_DETECTED:
  874. /* There has been a change in the phy type before OOB/SN for the
  875. * SATA finished start down the SAS link traning path.
  876. */
  877. scic_sds_phy_start_sas_link_training(sci_phy);
  878. break;
  879. default:
  880. dev_warn(sciphy_to_dev(sci_phy),
  881. "%s: PHY starting substate machine received "
  882. "unexpected event_code %x\n",
  883. __func__,
  884. event_code);
  885. result = SCI_FAILURE;
  886. break;
  887. }
  888. return result;
  889. }
  890. /**
  891. *
  892. * @phy: This struct scic_sds_phy object which has received an event.
  893. * @event_code: This is the event code which the phy object is to decode.
  894. *
  895. * This method is called when an event notification is received for the phy
  896. * object when in the state SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_SPEED_EN.
  897. * - decode the event - sata phy detected returns us back to this state. -
  898. * speed event detected causes a state transition to the wait for signature. -
  899. * link failure events restart the starting state machine - any other events
  900. * log a warning message and set a failure status enum sci_status SCI_SUCCESS on any
  901. * valid event notification SCI_FAILURE on any unexpected event notifation
  902. */
  903. static enum sci_status scic_sds_phy_starting_substate_await_sata_speed_event_handler(
  904. struct scic_sds_phy *sci_phy,
  905. u32 event_code)
  906. {
  907. u32 result = SCI_SUCCESS;
  908. switch (scu_get_event_code(event_code)) {
  909. case SCU_EVENT_SATA_PHY_DETECTED:
  910. /*
  911. * The hardware reports multiple SATA PHY detected events
  912. * ignore the extras */
  913. break;
  914. case SCU_EVENT_SATA_15:
  915. case SCU_EVENT_SATA_15_SSC:
  916. scic_sds_phy_complete_link_training(
  917. sci_phy,
  918. SAS_LINK_RATE_1_5_GBPS,
  919. SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF);
  920. break;
  921. case SCU_EVENT_SATA_30:
  922. case SCU_EVENT_SATA_30_SSC:
  923. scic_sds_phy_complete_link_training(
  924. sci_phy,
  925. SAS_LINK_RATE_3_0_GBPS,
  926. SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF);
  927. break;
  928. case SCU_EVENT_SATA_60:
  929. case SCU_EVENT_SATA_60_SSC:
  930. scic_sds_phy_complete_link_training(
  931. sci_phy,
  932. SAS_LINK_RATE_6_0_GBPS,
  933. SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF);
  934. break;
  935. case SCU_EVENT_LINK_FAILURE:
  936. /* Link failure change state back to the starting state */
  937. scic_sds_phy_restart_starting_state(sci_phy);
  938. break;
  939. case SCU_EVENT_SAS_PHY_DETECTED:
  940. /*
  941. * There has been a change in the phy type before OOB/SN for the
  942. * SATA finished start down the SAS link traning path. */
  943. scic_sds_phy_start_sas_link_training(sci_phy);
  944. break;
  945. default:
  946. dev_warn(sciphy_to_dev(sci_phy),
  947. "%s: PHY starting substate machine received "
  948. "unexpected event_code %x\n",
  949. __func__,
  950. event_code);
  951. result = SCI_FAILURE;
  952. break;
  953. }
  954. return result;
  955. }
  956. /**
  957. * scic_sds_phy_starting_substate_await_sig_fis_event_handler -
  958. * @phy: This struct scic_sds_phy object which has received an event.
  959. * @event_code: This is the event code which the phy object is to decode.
  960. *
  961. * This method is called when an event notification is received for the phy
  962. * object when in the state SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF. -
  963. * decode the event - sas phy detected event backs up the state machine to the
  964. * await speed notification. - identify timeout is an un-expected event and the
  965. * state machine is restarted. - link failure events restart the starting state
  966. * machine - any other events log a warning message and set a failure status
  967. * enum sci_status SCI_SUCCESS on any valid event notification SCI_FAILURE on any
  968. * unexpected event notifation
  969. */
  970. static enum sci_status scic_sds_phy_starting_substate_await_sig_fis_event_handler(
  971. struct scic_sds_phy *sci_phy, u32 event_code)
  972. {
  973. u32 result = SCI_SUCCESS;
  974. switch (scu_get_event_code(event_code)) {
  975. case SCU_EVENT_SATA_PHY_DETECTED:
  976. /* Backup the state machine */
  977. sci_base_state_machine_change_state(&sci_phy->state_machine,
  978. SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_SPEED_EN);
  979. break;
  980. case SCU_EVENT_LINK_FAILURE:
  981. /* Link failure change state back to the starting state */
  982. scic_sds_phy_restart_starting_state(sci_phy);
  983. break;
  984. default:
  985. dev_warn(sciphy_to_dev(sci_phy),
  986. "%s: PHY starting substate machine received "
  987. "unexpected event_code %x\n",
  988. __func__,
  989. event_code);
  990. result = SCI_FAILURE;
  991. break;
  992. }
  993. return result;
  994. }
  995. /*
  996. * This method is called by the struct scic_sds_controller when the phy object is
  997. * granted power. - The notify enable spinups are turned on for this phy object
  998. * - The phy state machine is transitioned to the
  999. * SCIC_SDS_PHY_STARTING_SUBSTATE_FINAL. enum sci_status SCI_SUCCESS
  1000. */
  1001. static enum sci_status scic_sds_phy_starting_substate_await_sas_power_consume_power_handler(
  1002. struct scic_sds_phy *sci_phy)
  1003. {
  1004. u32 enable_spinup;
  1005. enable_spinup = readl(&sci_phy->link_layer_registers->notify_enable_spinup_control);
  1006. enable_spinup |= SCU_ENSPINUP_GEN_BIT(ENABLE);
  1007. writel(enable_spinup, &sci_phy->link_layer_registers->notify_enable_spinup_control);
  1008. /* Change state to the final state this substate machine has run to completion */
  1009. sci_base_state_machine_change_state(&sci_phy->state_machine,
  1010. SCIC_SDS_PHY_STARTING_SUBSTATE_FINAL);
  1011. return SCI_SUCCESS;
  1012. }
  1013. /*
  1014. * This method is called by the struct scic_sds_controller when the phy object is
  1015. * granted power. - The phy state machine is transitioned to the
  1016. * SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_PHY_EN. enum sci_status SCI_SUCCESS
  1017. */
  1018. static enum sci_status scic_sds_phy_starting_substate_await_sata_power_consume_power_handler(
  1019. struct scic_sds_phy *sci_phy)
  1020. {
  1021. u32 scu_sas_pcfg_value;
  1022. /* Release the spinup hold state and reset the OOB state machine */
  1023. scu_sas_pcfg_value =
  1024. readl(&sci_phy->link_layer_registers->phy_configuration);
  1025. scu_sas_pcfg_value &=
  1026. ~(SCU_SAS_PCFG_GEN_BIT(SATA_SPINUP_HOLD) | SCU_SAS_PCFG_GEN_BIT(OOB_ENABLE));
  1027. scu_sas_pcfg_value |= SCU_SAS_PCFG_GEN_BIT(OOB_RESET);
  1028. writel(scu_sas_pcfg_value,
  1029. &sci_phy->link_layer_registers->phy_configuration);
  1030. /* Now restart the OOB operation */
  1031. scu_sas_pcfg_value &= ~SCU_SAS_PCFG_GEN_BIT(OOB_RESET);
  1032. scu_sas_pcfg_value |= SCU_SAS_PCFG_GEN_BIT(OOB_ENABLE);
  1033. writel(scu_sas_pcfg_value,
  1034. &sci_phy->link_layer_registers->phy_configuration);
  1035. /* Change state to the final state this substate machine has run to completion */
  1036. sci_base_state_machine_change_state(&sci_phy->state_machine,
  1037. SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_PHY_EN);
  1038. return SCI_SUCCESS;
  1039. }
  1040. static enum sci_status default_phy_handler(struct scic_sds_phy *sci_phy,
  1041. const char *func)
  1042. {
  1043. dev_dbg(sciphy_to_dev(sci_phy),
  1044. "%s: in wrong state: %d\n", func,
  1045. sci_base_state_machine_get_state(&sci_phy->state_machine));
  1046. return SCI_FAILURE_INVALID_STATE;
  1047. }
  1048. static enum sci_status
  1049. scic_sds_phy_default_event_handler(struct scic_sds_phy *sci_phy,
  1050. u32 event_code)
  1051. {
  1052. return default_phy_handler(sci_phy, __func__);
  1053. }
  1054. static enum sci_status
  1055. scic_sds_phy_default_consume_power_handler(struct scic_sds_phy *sci_phy)
  1056. {
  1057. return default_phy_handler(sci_phy, __func__);
  1058. }
  1059. /**
  1060. * scic_sds_phy_ready_state_event_handler -
  1061. * @phy: This is the struct scic_sds_phy object which has received the event.
  1062. *
  1063. * This method request the struct scic_sds_phy handle the received event. The only
  1064. * event that we are interested in while in the ready state is the link failure
  1065. * event. - decoded event is a link failure - transition the struct scic_sds_phy back
  1066. * to the SCI_BASE_PHY_STATE_STARTING state. - any other event received will
  1067. * report a warning message enum sci_status SCI_SUCCESS if the event received is a
  1068. * link failure SCI_FAILURE_INVALID_STATE for any other event received.
  1069. */
  1070. static enum sci_status scic_sds_phy_ready_state_event_handler(struct scic_sds_phy *sci_phy,
  1071. u32 event_code)
  1072. {
  1073. enum sci_status result = SCI_FAILURE;
  1074. switch (scu_get_event_code(event_code)) {
  1075. case SCU_EVENT_LINK_FAILURE:
  1076. /* Link failure change state back to the starting state */
  1077. sci_base_state_machine_change_state(&sci_phy->state_machine,
  1078. SCI_BASE_PHY_STATE_STARTING);
  1079. result = SCI_SUCCESS;
  1080. break;
  1081. case SCU_EVENT_BROADCAST_CHANGE:
  1082. /* Broadcast change received. Notify the port. */
  1083. if (scic_sds_phy_get_port(sci_phy) != NULL)
  1084. scic_sds_port_broadcast_change_received(sci_phy->owning_port, sci_phy);
  1085. else
  1086. sci_phy->bcn_received_while_port_unassigned = true;
  1087. break;
  1088. default:
  1089. dev_warn(sciphy_to_dev(sci_phy),
  1090. "%sP SCIC PHY 0x%p ready state machine received "
  1091. "unexpected event_code %x\n",
  1092. __func__, sci_phy, event_code);
  1093. result = SCI_FAILURE_INVALID_STATE;
  1094. break;
  1095. }
  1096. return result;
  1097. }
  1098. static enum sci_status scic_sds_phy_resetting_state_event_handler(struct scic_sds_phy *sci_phy,
  1099. u32 event_code)
  1100. {
  1101. enum sci_status result = SCI_FAILURE;
  1102. switch (scu_get_event_code(event_code)) {
  1103. case SCU_EVENT_HARD_RESET_TRANSMITTED:
  1104. /* Link failure change state back to the starting state */
  1105. sci_base_state_machine_change_state(&sci_phy->state_machine,
  1106. SCI_BASE_PHY_STATE_STARTING);
  1107. result = SCI_SUCCESS;
  1108. break;
  1109. default:
  1110. dev_warn(sciphy_to_dev(sci_phy),
  1111. "%s: SCIC PHY 0x%p resetting state machine received "
  1112. "unexpected event_code %x\n",
  1113. __func__, sci_phy, event_code);
  1114. result = SCI_FAILURE_INVALID_STATE;
  1115. break;
  1116. }
  1117. return result;
  1118. }
  1119. /* --------------------------------------------------------------------------- */
  1120. static const struct scic_sds_phy_state_handler scic_sds_phy_state_handler_table[] = {
  1121. [SCI_BASE_PHY_STATE_INITIAL] = {
  1122. .event_handler = scic_sds_phy_default_event_handler,
  1123. .consume_power_handler = scic_sds_phy_default_consume_power_handler
  1124. },
  1125. [SCI_BASE_PHY_STATE_STOPPED] = {
  1126. .event_handler = scic_sds_phy_default_event_handler,
  1127. .consume_power_handler = scic_sds_phy_default_consume_power_handler
  1128. },
  1129. [SCI_BASE_PHY_STATE_STARTING] = {
  1130. .event_handler = scic_sds_phy_default_event_handler,
  1131. .consume_power_handler = scic_sds_phy_default_consume_power_handler
  1132. },
  1133. [SCIC_SDS_PHY_STARTING_SUBSTATE_INITIAL] = {
  1134. .event_handler = scic_sds_phy_default_event_handler,
  1135. .consume_power_handler = scic_sds_phy_default_consume_power_handler
  1136. },
  1137. [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_OSSP_EN] = {
  1138. .event_handler = scic_sds_phy_starting_substate_await_ossp_event_handler,
  1139. .consume_power_handler = scic_sds_phy_default_consume_power_handler
  1140. },
  1141. [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_SPEED_EN] = {
  1142. .event_handler = scic_sds_phy_starting_substate_await_sas_phy_speed_event_handler,
  1143. .consume_power_handler = scic_sds_phy_default_consume_power_handler
  1144. },
  1145. [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_IAF_UF] = {
  1146. .event_handler = scic_sds_phy_starting_substate_await_iaf_uf_event_handler,
  1147. .consume_power_handler = scic_sds_phy_default_consume_power_handler
  1148. },
  1149. [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_POWER] = {
  1150. .event_handler = scic_sds_phy_starting_substate_await_sas_power_event_handler,
  1151. .consume_power_handler = scic_sds_phy_starting_substate_await_sas_power_consume_power_handler
  1152. },
  1153. [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_POWER] = {
  1154. .event_handler = scic_sds_phy_starting_substate_await_sata_power_event_handler,
  1155. .consume_power_handler = scic_sds_phy_starting_substate_await_sata_power_consume_power_handler
  1156. },
  1157. [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_PHY_EN] = {
  1158. .event_handler = scic_sds_phy_starting_substate_await_sata_phy_event_handler,
  1159. .consume_power_handler = scic_sds_phy_default_consume_power_handler
  1160. },
  1161. [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_SPEED_EN] = {
  1162. .event_handler = scic_sds_phy_starting_substate_await_sata_speed_event_handler,
  1163. .consume_power_handler = scic_sds_phy_default_consume_power_handler
  1164. },
  1165. [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF] = {
  1166. .event_handler = scic_sds_phy_starting_substate_await_sig_fis_event_handler,
  1167. .consume_power_handler = scic_sds_phy_default_consume_power_handler
  1168. },
  1169. [SCIC_SDS_PHY_STARTING_SUBSTATE_FINAL] = {
  1170. .event_handler = scic_sds_phy_default_event_handler,
  1171. .consume_power_handler = scic_sds_phy_default_consume_power_handler
  1172. },
  1173. [SCI_BASE_PHY_STATE_READY] = {
  1174. .event_handler = scic_sds_phy_ready_state_event_handler,
  1175. .consume_power_handler = scic_sds_phy_default_consume_power_handler
  1176. },
  1177. [SCI_BASE_PHY_STATE_RESETTING] = {
  1178. .event_handler = scic_sds_phy_resetting_state_event_handler,
  1179. .consume_power_handler = scic_sds_phy_default_consume_power_handler
  1180. },
  1181. [SCI_BASE_PHY_STATE_FINAL] = {
  1182. .event_handler = scic_sds_phy_default_event_handler,
  1183. .consume_power_handler = scic_sds_phy_default_consume_power_handler
  1184. }
  1185. };
  1186. /*
  1187. * ****************************************************************************
  1188. * * PHY STARTING SUBSTATE METHODS
  1189. * **************************************************************************** */
  1190. /**
  1191. * scic_sds_phy_starting_initial_substate_enter -
  1192. * @object: This is the object which is cast to a struct scic_sds_phy object.
  1193. *
  1194. * This method will perform the actions required by the struct scic_sds_phy on
  1195. * entering the SCIC_SDS_PHY_STARTING_SUBSTATE_INITIAL. - The initial state
  1196. * handlers are put in place for the struct scic_sds_phy object. - The state is
  1197. * changed to the wait phy type event notification. none
  1198. */
  1199. static void scic_sds_phy_starting_initial_substate_enter(void *object)
  1200. {
  1201. struct scic_sds_phy *sci_phy = object;
  1202. scic_sds_phy_set_base_state_handlers(
  1203. sci_phy, SCIC_SDS_PHY_STARTING_SUBSTATE_INITIAL);
  1204. /* This is just an temporary state go off to the starting state */
  1205. sci_base_state_machine_change_state(&sci_phy->state_machine,
  1206. SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_OSSP_EN);
  1207. }
  1208. /**
  1209. *
  1210. * @object: This is the object which is cast to a struct scic_sds_phy object.
  1211. *
  1212. * This method will perform the actions required by the struct scic_sds_phy on
  1213. * entering the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_PHY_TYPE_EN. - Set the
  1214. * struct scic_sds_phy object state handlers for this state. none
  1215. */
  1216. static void scic_sds_phy_starting_await_ossp_en_substate_enter(void *object)
  1217. {
  1218. struct scic_sds_phy *sci_phy = object;
  1219. scic_sds_phy_set_base_state_handlers(
  1220. sci_phy, SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_OSSP_EN
  1221. );
  1222. }
  1223. /**
  1224. *
  1225. * @object: This is the object which is cast to a struct scic_sds_phy object.
  1226. *
  1227. * This method will perform the actions required by the struct scic_sds_phy on
  1228. * entering the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SPEED_EN. - Set the
  1229. * struct scic_sds_phy object state handlers for this state. none
  1230. */
  1231. static void scic_sds_phy_starting_await_sas_speed_en_substate_enter(
  1232. void *object)
  1233. {
  1234. struct scic_sds_phy *sci_phy = object;
  1235. scic_sds_phy_set_base_state_handlers(
  1236. sci_phy, SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_SPEED_EN
  1237. );
  1238. }
  1239. /**
  1240. *
  1241. * @object: This is the object which is cast to a struct scic_sds_phy object.
  1242. *
  1243. * This method will perform the actions required by the struct scic_sds_phy on
  1244. * entering the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_IAF_UF. - Set the
  1245. * struct scic_sds_phy object state handlers for this state. none
  1246. */
  1247. static void scic_sds_phy_starting_await_iaf_uf_substate_enter(void *object)
  1248. {
  1249. struct scic_sds_phy *sci_phy = object;
  1250. scic_sds_phy_set_base_state_handlers(
  1251. sci_phy, SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_IAF_UF
  1252. );
  1253. }
  1254. /**
  1255. *
  1256. * @object: This is the object which is cast to a struct scic_sds_phy object.
  1257. *
  1258. * This method will perform the actions required by the struct scic_sds_phy on
  1259. * entering the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_POWER. - Set the
  1260. * struct scic_sds_phy object state handlers for this state. - Add this phy object to
  1261. * the power control queue none
  1262. */
  1263. static void scic_sds_phy_starting_await_sas_power_substate_enter(void *object)
  1264. {
  1265. struct scic_sds_phy *sci_phy = object;
  1266. scic_sds_phy_set_base_state_handlers(
  1267. sci_phy, SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_POWER
  1268. );
  1269. scic_sds_controller_power_control_queue_insert(
  1270. scic_sds_phy_get_controller(sci_phy),
  1271. sci_phy
  1272. );
  1273. }
  1274. /**
  1275. *
  1276. * @object: This is the object which is cast to a struct scic_sds_phy object.
  1277. *
  1278. * This method will perform the actions required by the struct scic_sds_phy on exiting
  1279. * the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_POWER. - Remove the
  1280. * struct scic_sds_phy object from the power control queue. none
  1281. */
  1282. static void scic_sds_phy_starting_await_sas_power_substate_exit(void *object)
  1283. {
  1284. struct scic_sds_phy *sci_phy = object;
  1285. scic_sds_controller_power_control_queue_remove(
  1286. scic_sds_phy_get_controller(sci_phy), sci_phy
  1287. );
  1288. }
  1289. /**
  1290. *
  1291. * @object: This is the object which is cast to a struct scic_sds_phy object.
  1292. *
  1293. * This method will perform the actions required by the struct scic_sds_phy on
  1294. * entering the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_POWER. - Set the
  1295. * struct scic_sds_phy object state handlers for this state. - Add this phy object to
  1296. * the power control queue none
  1297. */
  1298. static void scic_sds_phy_starting_await_sata_power_substate_enter(void *object)
  1299. {
  1300. struct scic_sds_phy *sci_phy = object;
  1301. scic_sds_phy_set_base_state_handlers(
  1302. sci_phy, SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_POWER
  1303. );
  1304. scic_sds_controller_power_control_queue_insert(
  1305. scic_sds_phy_get_controller(sci_phy),
  1306. sci_phy
  1307. );
  1308. }
  1309. /**
  1310. *
  1311. * @object: This is the object which is cast to a struct scic_sds_phy object.
  1312. *
  1313. * This method will perform the actions required by the struct scic_sds_phy on exiting
  1314. * the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_POWER. - Remove the
  1315. * struct scic_sds_phy object from the power control queue. none
  1316. */
  1317. static void scic_sds_phy_starting_await_sata_power_substate_exit(void *object)
  1318. {
  1319. struct scic_sds_phy *sci_phy = object;
  1320. scic_sds_controller_power_control_queue_remove(
  1321. scic_sds_phy_get_controller(sci_phy),
  1322. sci_phy
  1323. );
  1324. }
  1325. /**
  1326. *
  1327. * @object: This is the object which is cast to a struct scic_sds_phy object.
  1328. *
  1329. * This function will perform the actions required by the struct scic_sds_phy on
  1330. * entering the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_PHY_EN. - Set the
  1331. * struct scic_sds_phy object state handlers for this state. none
  1332. */
  1333. static void scic_sds_phy_starting_await_sata_phy_substate_enter(void *object)
  1334. {
  1335. struct scic_sds_phy *sci_phy = object;
  1336. scic_sds_phy_set_base_state_handlers(
  1337. sci_phy,
  1338. SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_PHY_EN);
  1339. isci_timer_start(sci_phy->sata_timeout_timer,
  1340. SCIC_SDS_SATA_LINK_TRAINING_TIMEOUT);
  1341. }
  1342. /**
  1343. *
  1344. * @object: This is the object which is cast to a struct scic_sds_phy object.
  1345. *
  1346. * This method will perform the actions required by the struct scic_sds_phy
  1347. * on exiting
  1348. * the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_SPEED_EN. - stop the timer
  1349. * that was started on entry to await sata phy event notification none
  1350. */
  1351. static inline void scic_sds_phy_starting_await_sata_phy_substate_exit(
  1352. void *object)
  1353. {
  1354. struct scic_sds_phy *sci_phy = object;
  1355. isci_timer_stop(sci_phy->sata_timeout_timer);
  1356. }
  1357. /**
  1358. *
  1359. * @object: This is the object which is cast to a struct scic_sds_phy object.
  1360. *
  1361. * This method will perform the actions required by the struct scic_sds_phy on
  1362. * entering the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_SPEED_EN. - Set the
  1363. * struct scic_sds_phy object state handlers for this state. none
  1364. */
  1365. static void scic_sds_phy_starting_await_sata_speed_substate_enter(void *object)
  1366. {
  1367. struct scic_sds_phy *sci_phy = object;
  1368. scic_sds_phy_set_base_state_handlers(
  1369. sci_phy,
  1370. SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_SPEED_EN);
  1371. isci_timer_start(sci_phy->sata_timeout_timer,
  1372. SCIC_SDS_SATA_LINK_TRAINING_TIMEOUT);
  1373. }
  1374. /**
  1375. *
  1376. * @object: This is the object which is cast to a struct scic_sds_phy object.
  1377. *
  1378. * This function will perform the actions required by the
  1379. * struct scic_sds_phy on exiting
  1380. * the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_SPEED_EN. - stop the timer
  1381. * that was started on entry to await sata phy event notification none
  1382. */
  1383. static inline void scic_sds_phy_starting_await_sata_speed_substate_exit(
  1384. void *object)
  1385. {
  1386. struct scic_sds_phy *sci_phy = object;
  1387. isci_timer_stop(sci_phy->sata_timeout_timer);
  1388. }
  1389. /**
  1390. *
  1391. * @object: This is the object which is cast to a struct scic_sds_phy object.
  1392. *
  1393. * This function will perform the actions required by the struct scic_sds_phy on
  1394. * entering the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF. - Set the
  1395. * struct scic_sds_phy object state handlers for this state.
  1396. * - Start the SIGNATURE FIS
  1397. * timeout timer none
  1398. */
  1399. static void scic_sds_phy_starting_await_sig_fis_uf_substate_enter(void *object)
  1400. {
  1401. bool continue_to_ready_state;
  1402. struct scic_sds_phy *sci_phy = object;
  1403. scic_sds_phy_set_base_state_handlers(
  1404. sci_phy,
  1405. SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF);
  1406. continue_to_ready_state = scic_sds_port_link_detected(
  1407. sci_phy->owning_port,
  1408. sci_phy);
  1409. if (continue_to_ready_state) {
  1410. /*
  1411. * Clear the PE suspend condition so we can actually
  1412. * receive SIG FIS
  1413. * The hardware will not respond to the XRDY until the PE
  1414. * suspend condition is cleared.
  1415. */
  1416. scic_sds_phy_resume(sci_phy);
  1417. isci_timer_start(sci_phy->sata_timeout_timer,
  1418. SCIC_SDS_SIGNATURE_FIS_TIMEOUT);
  1419. } else
  1420. sci_phy->is_in_link_training = false;
  1421. }
  1422. /**
  1423. *
  1424. * @object: This is the object which is cast to a struct scic_sds_phy object.
  1425. *
  1426. * This function will perform the actions required by the
  1427. * struct scic_sds_phy on exiting
  1428. * the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF. - Stop the SIGNATURE
  1429. * FIS timeout timer. none
  1430. */
  1431. static inline void scic_sds_phy_starting_await_sig_fis_uf_substate_exit(
  1432. void *object)
  1433. {
  1434. struct scic_sds_phy *sci_phy = object;
  1435. isci_timer_stop(sci_phy->sata_timeout_timer);
  1436. }
  1437. /**
  1438. *
  1439. * @object: This is the object which is cast to a struct scic_sds_phy object.
  1440. *
  1441. * This method will perform the actions required by the struct scic_sds_phy on
  1442. * entering the SCIC_SDS_PHY_STARTING_SUBSTATE_FINAL. - Set the struct scic_sds_phy
  1443. * object state handlers for this state. - Change base state machine to the
  1444. * ready state. none
  1445. */
  1446. static void scic_sds_phy_starting_final_substate_enter(void *object)
  1447. {
  1448. struct scic_sds_phy *sci_phy = object;
  1449. scic_sds_phy_set_base_state_handlers(sci_phy,
  1450. SCIC_SDS_PHY_STARTING_SUBSTATE_FINAL);
  1451. /* State machine has run to completion so exit out and change
  1452. * the base state machine to the ready state
  1453. */
  1454. sci_base_state_machine_change_state(&sci_phy->state_machine,
  1455. SCI_BASE_PHY_STATE_READY);
  1456. }
  1457. /*
  1458. * ****************************************************************************
  1459. * * PHY STATE PRIVATE METHODS
  1460. * **************************************************************************** */
  1461. /**
  1462. *
  1463. * @sci_phy: This is the struct scic_sds_phy object to stop.
  1464. *
  1465. * This method will stop the struct scic_sds_phy object. This does not reset the
  1466. * protocol engine it just suspends it and places it in a state where it will
  1467. * not cause the end device to power up. none
  1468. */
  1469. static void scu_link_layer_stop_protocol_engine(
  1470. struct scic_sds_phy *sci_phy)
  1471. {
  1472. u32 scu_sas_pcfg_value;
  1473. u32 enable_spinup_value;
  1474. /* Suspend the protocol engine and place it in a sata spinup hold state */
  1475. scu_sas_pcfg_value =
  1476. readl(&sci_phy->link_layer_registers->phy_configuration);
  1477. scu_sas_pcfg_value |=
  1478. (SCU_SAS_PCFG_GEN_BIT(OOB_RESET) |
  1479. SCU_SAS_PCFG_GEN_BIT(SUSPEND_PROTOCOL_ENGINE) |
  1480. SCU_SAS_PCFG_GEN_BIT(SATA_SPINUP_HOLD));
  1481. writel(scu_sas_pcfg_value,
  1482. &sci_phy->link_layer_registers->phy_configuration);
  1483. /* Disable the notify enable spinup primitives */
  1484. enable_spinup_value = readl(&sci_phy->link_layer_registers->notify_enable_spinup_control);
  1485. enable_spinup_value &= ~SCU_ENSPINUP_GEN_BIT(ENABLE);
  1486. writel(enable_spinup_value, &sci_phy->link_layer_registers->notify_enable_spinup_control);
  1487. }
  1488. /**
  1489. *
  1490. *
  1491. * This method will start the OOB/SN state machine for this struct scic_sds_phy object.
  1492. */
  1493. static void scu_link_layer_start_oob(
  1494. struct scic_sds_phy *sci_phy)
  1495. {
  1496. u32 scu_sas_pcfg_value;
  1497. scu_sas_pcfg_value =
  1498. readl(&sci_phy->link_layer_registers->phy_configuration);
  1499. scu_sas_pcfg_value |= SCU_SAS_PCFG_GEN_BIT(OOB_ENABLE);
  1500. scu_sas_pcfg_value &=
  1501. ~(SCU_SAS_PCFG_GEN_BIT(OOB_RESET) |
  1502. SCU_SAS_PCFG_GEN_BIT(HARD_RESET));
  1503. writel(scu_sas_pcfg_value,
  1504. &sci_phy->link_layer_registers->phy_configuration);
  1505. }
  1506. /**
  1507. *
  1508. *
  1509. * This method will transmit a hard reset request on the specified phy. The SCU
  1510. * hardware requires that we reset the OOB state machine and set the hard reset
  1511. * bit in the phy configuration register. We then must start OOB over with the
  1512. * hard reset bit set.
  1513. */
  1514. static void scu_link_layer_tx_hard_reset(
  1515. struct scic_sds_phy *sci_phy)
  1516. {
  1517. u32 phy_configuration_value;
  1518. /*
  1519. * SAS Phys must wait for the HARD_RESET_TX event notification to transition
  1520. * to the starting state. */
  1521. phy_configuration_value =
  1522. readl(&sci_phy->link_layer_registers->phy_configuration);
  1523. phy_configuration_value |=
  1524. (SCU_SAS_PCFG_GEN_BIT(HARD_RESET) |
  1525. SCU_SAS_PCFG_GEN_BIT(OOB_RESET));
  1526. writel(phy_configuration_value,
  1527. &sci_phy->link_layer_registers->phy_configuration);
  1528. /* Now take the OOB state machine out of reset */
  1529. phy_configuration_value |= SCU_SAS_PCFG_GEN_BIT(OOB_ENABLE);
  1530. phy_configuration_value &= ~SCU_SAS_PCFG_GEN_BIT(OOB_RESET);
  1531. writel(phy_configuration_value,
  1532. &sci_phy->link_layer_registers->phy_configuration);
  1533. }
  1534. /*
  1535. * ****************************************************************************
  1536. * * PHY BASE STATE METHODS
  1537. * **************************************************************************** */
  1538. /**
  1539. *
  1540. * @object: This is the object which is cast to a struct scic_sds_phy object.
  1541. *
  1542. * This method will perform the actions required by the struct scic_sds_phy on
  1543. * entering the SCI_BASE_PHY_STATE_INITIAL. - This function sets the state
  1544. * handlers for the phy object base state machine initial state. none
  1545. */
  1546. static void scic_sds_phy_initial_state_enter(void *object)
  1547. {
  1548. struct scic_sds_phy *sci_phy = object;
  1549. scic_sds_phy_set_base_state_handlers(sci_phy, SCI_BASE_PHY_STATE_INITIAL);
  1550. }
  1551. /**
  1552. *
  1553. * @object: This is the object which is cast to a struct scic_sds_phy object.
  1554. *
  1555. * This function will perform the actions required by the struct scic_sds_phy on
  1556. * entering the SCI_BASE_PHY_STATE_INITIAL. - This function sets the state
  1557. * handlers for the phy object base state machine initial state. - The SCU
  1558. * hardware is requested to stop the protocol engine. none
  1559. */
  1560. static void scic_sds_phy_stopped_state_enter(void *object)
  1561. {
  1562. struct scic_sds_phy *sci_phy = object;
  1563. struct scic_sds_controller *scic = scic_sds_phy_get_controller(sci_phy);
  1564. struct isci_host *ihost = scic_to_ihost(scic);
  1565. /*
  1566. * @todo We need to get to the controller to place this PE in a
  1567. * reset state
  1568. */
  1569. scic_sds_phy_set_base_state_handlers(sci_phy,
  1570. SCI_BASE_PHY_STATE_STOPPED);
  1571. if (sci_phy->sata_timeout_timer != NULL) {
  1572. isci_del_timer(ihost, sci_phy->sata_timeout_timer);
  1573. sci_phy->sata_timeout_timer = NULL;
  1574. }
  1575. scu_link_layer_stop_protocol_engine(sci_phy);
  1576. if (sci_phy->state_machine.previous_state_id !=
  1577. SCI_BASE_PHY_STATE_INITIAL)
  1578. scic_sds_controller_link_down(
  1579. scic_sds_phy_get_controller(sci_phy),
  1580. scic_sds_phy_get_port(sci_phy),
  1581. sci_phy);
  1582. }
  1583. /**
  1584. *
  1585. * @object: This is the object which is cast to a struct scic_sds_phy object.
  1586. *
  1587. * This method will perform the actions required by the struct scic_sds_phy on
  1588. * entering the SCI_BASE_PHY_STATE_STARTING. - This function sets the state
  1589. * handlers for the phy object base state machine starting state. - The SCU
  1590. * hardware is requested to start OOB/SN on this protocl engine. - The phy
  1591. * starting substate machine is started. - If the previous state was the ready
  1592. * state then the struct scic_sds_controller is informed that the phy has gone link
  1593. * down. none
  1594. */
  1595. static void scic_sds_phy_starting_state_enter(void *object)
  1596. {
  1597. struct scic_sds_phy *sci_phy = object;
  1598. scic_sds_phy_set_base_state_handlers(sci_phy, SCI_BASE_PHY_STATE_STARTING);
  1599. scu_link_layer_stop_protocol_engine(sci_phy);
  1600. scu_link_layer_start_oob(sci_phy);
  1601. /* We don't know what kind of phy we are going to be just yet */
  1602. sci_phy->protocol = SCIC_SDS_PHY_PROTOCOL_UNKNOWN;
  1603. sci_phy->bcn_received_while_port_unassigned = false;
  1604. if (sci_phy->state_machine.previous_state_id
  1605. == SCI_BASE_PHY_STATE_READY) {
  1606. scic_sds_controller_link_down(
  1607. scic_sds_phy_get_controller(sci_phy),
  1608. scic_sds_phy_get_port(sci_phy),
  1609. sci_phy
  1610. );
  1611. }
  1612. sci_base_state_machine_change_state(&sci_phy->state_machine,
  1613. SCIC_SDS_PHY_STARTING_SUBSTATE_INITIAL);
  1614. }
  1615. /**
  1616. *
  1617. * @object: This is the object which is cast to a struct scic_sds_phy object.
  1618. *
  1619. * This method will perform the actions required by the struct scic_sds_phy on
  1620. * entering the SCI_BASE_PHY_STATE_READY. - This function sets the state
  1621. * handlers for the phy object base state machine ready state. - The SCU
  1622. * hardware protocol engine is resumed. - The struct scic_sds_controller is informed
  1623. * that the phy object has gone link up. none
  1624. */
  1625. static void scic_sds_phy_ready_state_enter(void *object)
  1626. {
  1627. struct scic_sds_phy *sci_phy = object;
  1628. scic_sds_phy_set_base_state_handlers(sci_phy, SCI_BASE_PHY_STATE_READY);
  1629. scic_sds_controller_link_up(
  1630. scic_sds_phy_get_controller(sci_phy),
  1631. scic_sds_phy_get_port(sci_phy),
  1632. sci_phy
  1633. );
  1634. }
  1635. /**
  1636. *
  1637. * @object: This is the object which is cast to a struct scic_sds_phy object.
  1638. *
  1639. * This method will perform the actions required by the struct scic_sds_phy on exiting
  1640. * the SCI_BASE_PHY_STATE_INITIAL. This function suspends the SCU hardware
  1641. * protocol engine represented by this struct scic_sds_phy object. none
  1642. */
  1643. static void scic_sds_phy_ready_state_exit(void *object)
  1644. {
  1645. struct scic_sds_phy *sci_phy = object;
  1646. scic_sds_phy_suspend(sci_phy);
  1647. }
  1648. /**
  1649. *
  1650. * @object: This is the object which is cast to a struct scic_sds_phy object.
  1651. *
  1652. * This method will perform the actions required by the struct scic_sds_phy on
  1653. * entering the SCI_BASE_PHY_STATE_RESETTING. - This function sets the state
  1654. * handlers for the phy object base state machine resetting state. none
  1655. */
  1656. static void scic_sds_phy_resetting_state_enter(void *object)
  1657. {
  1658. struct scic_sds_phy *sci_phy = object;
  1659. scic_sds_phy_set_base_state_handlers(sci_phy, SCI_BASE_PHY_STATE_RESETTING);
  1660. /*
  1661. * The phy is being reset, therefore deactivate it from the port.
  1662. * In the resetting state we don't notify the user regarding
  1663. * link up and link down notifications. */
  1664. scic_sds_port_deactivate_phy(sci_phy->owning_port, sci_phy, false);
  1665. if (sci_phy->protocol == SCIC_SDS_PHY_PROTOCOL_SAS) {
  1666. scu_link_layer_tx_hard_reset(sci_phy);
  1667. } else {
  1668. /*
  1669. * The SCU does not need to have a discrete reset state so
  1670. * just go back to the starting state.
  1671. */
  1672. sci_base_state_machine_change_state(
  1673. &sci_phy->state_machine,
  1674. SCI_BASE_PHY_STATE_STARTING);
  1675. }
  1676. }
  1677. /**
  1678. *
  1679. * @object: This is the object which is cast to a struct scic_sds_phy object.
  1680. *
  1681. * This method will perform the actions required by the struct scic_sds_phy on
  1682. * entering the SCI_BASE_PHY_STATE_FINAL. - This function sets the state
  1683. * handlers for the phy object base state machine final state. none
  1684. */
  1685. static void scic_sds_phy_final_state_enter(void *object)
  1686. {
  1687. struct scic_sds_phy *sci_phy = object;
  1688. scic_sds_phy_set_base_state_handlers(sci_phy, SCI_BASE_PHY_STATE_FINAL);
  1689. /* Nothing to do here */
  1690. }
  1691. /* --------------------------------------------------------------------------- */
  1692. static const struct sci_base_state scic_sds_phy_state_table[] = {
  1693. [SCI_BASE_PHY_STATE_INITIAL] = {
  1694. .enter_state = scic_sds_phy_initial_state_enter,
  1695. },
  1696. [SCI_BASE_PHY_STATE_STOPPED] = {
  1697. .enter_state = scic_sds_phy_stopped_state_enter,
  1698. },
  1699. [SCI_BASE_PHY_STATE_STARTING] = {
  1700. .enter_state = scic_sds_phy_starting_state_enter,
  1701. },
  1702. [SCIC_SDS_PHY_STARTING_SUBSTATE_INITIAL] = {
  1703. .enter_state = scic_sds_phy_starting_initial_substate_enter,
  1704. },
  1705. [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_OSSP_EN] = {
  1706. .enter_state = scic_sds_phy_starting_await_ossp_en_substate_enter,
  1707. },
  1708. [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_SPEED_EN] = {
  1709. .enter_state = scic_sds_phy_starting_await_sas_speed_en_substate_enter,
  1710. },
  1711. [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_IAF_UF] = {
  1712. .enter_state = scic_sds_phy_starting_await_iaf_uf_substate_enter,
  1713. },
  1714. [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_POWER] = {
  1715. .enter_state = scic_sds_phy_starting_await_sas_power_substate_enter,
  1716. .exit_state = scic_sds_phy_starting_await_sas_power_substate_exit,
  1717. },
  1718. [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_POWER] = {
  1719. .enter_state = scic_sds_phy_starting_await_sata_power_substate_enter,
  1720. .exit_state = scic_sds_phy_starting_await_sata_power_substate_exit
  1721. },
  1722. [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_PHY_EN] = {
  1723. .enter_state = scic_sds_phy_starting_await_sata_phy_substate_enter,
  1724. .exit_state = scic_sds_phy_starting_await_sata_phy_substate_exit
  1725. },
  1726. [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_SPEED_EN] = {
  1727. .enter_state = scic_sds_phy_starting_await_sata_speed_substate_enter,
  1728. .exit_state = scic_sds_phy_starting_await_sata_speed_substate_exit
  1729. },
  1730. [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF] = {
  1731. .enter_state = scic_sds_phy_starting_await_sig_fis_uf_substate_enter,
  1732. .exit_state = scic_sds_phy_starting_await_sig_fis_uf_substate_exit
  1733. },
  1734. [SCIC_SDS_PHY_STARTING_SUBSTATE_FINAL] = {
  1735. .enter_state = scic_sds_phy_starting_final_substate_enter,
  1736. },
  1737. [SCI_BASE_PHY_STATE_READY] = {
  1738. .enter_state = scic_sds_phy_ready_state_enter,
  1739. .exit_state = scic_sds_phy_ready_state_exit,
  1740. },
  1741. [SCI_BASE_PHY_STATE_RESETTING] = {
  1742. .enter_state = scic_sds_phy_resetting_state_enter,
  1743. },
  1744. [SCI_BASE_PHY_STATE_FINAL] = {
  1745. .enter_state = scic_sds_phy_final_state_enter,
  1746. },
  1747. };
  1748. void scic_sds_phy_construct(struct scic_sds_phy *sci_phy,
  1749. struct scic_sds_port *owning_port, u8 phy_index)
  1750. {
  1751. sci_base_state_machine_construct(&sci_phy->state_machine,
  1752. sci_phy,
  1753. scic_sds_phy_state_table,
  1754. SCI_BASE_PHY_STATE_INITIAL);
  1755. sci_base_state_machine_start(&sci_phy->state_machine);
  1756. /* Copy the rest of the input data to our locals */
  1757. sci_phy->owning_port = owning_port;
  1758. sci_phy->phy_index = phy_index;
  1759. sci_phy->bcn_received_while_port_unassigned = false;
  1760. sci_phy->protocol = SCIC_SDS_PHY_PROTOCOL_UNKNOWN;
  1761. sci_phy->link_layer_registers = NULL;
  1762. sci_phy->max_negotiated_speed = SAS_LINK_RATE_UNKNOWN;
  1763. sci_phy->sata_timeout_timer = NULL;
  1764. }
  1765. void isci_phy_init(struct isci_phy *iphy, struct isci_host *ihost, int index)
  1766. {
  1767. union scic_oem_parameters oem;
  1768. u64 sci_sas_addr;
  1769. __be64 sas_addr;
  1770. scic_oem_parameters_get(&ihost->sci, &oem);
  1771. sci_sas_addr = oem.sds1.phys[index].sas_address.high;
  1772. sci_sas_addr <<= 32;
  1773. sci_sas_addr |= oem.sds1.phys[index].sas_address.low;
  1774. sas_addr = cpu_to_be64(sci_sas_addr);
  1775. memcpy(iphy->sas_addr, &sas_addr, sizeof(sas_addr));
  1776. iphy->isci_port = NULL;
  1777. iphy->sas_phy.enabled = 0;
  1778. iphy->sas_phy.id = index;
  1779. iphy->sas_phy.sas_addr = &iphy->sas_addr[0];
  1780. iphy->sas_phy.frame_rcvd = (u8 *)&iphy->frame_rcvd;
  1781. iphy->sas_phy.ha = &ihost->sas_ha;
  1782. iphy->sas_phy.lldd_phy = iphy;
  1783. iphy->sas_phy.enabled = 1;
  1784. iphy->sas_phy.class = SAS;
  1785. iphy->sas_phy.iproto = SAS_PROTOCOL_ALL;
  1786. iphy->sas_phy.tproto = 0;
  1787. iphy->sas_phy.type = PHY_TYPE_PHYSICAL;
  1788. iphy->sas_phy.role = PHY_ROLE_INITIATOR;
  1789. iphy->sas_phy.oob_mode = OOB_NOT_CONNECTED;
  1790. iphy->sas_phy.linkrate = SAS_LINK_RATE_UNKNOWN;
  1791. memset(&iphy->frame_rcvd, 0, sizeof(iphy->frame_rcvd));
  1792. }
  1793. /**
  1794. * isci_phy_control() - This function is one of the SAS Domain Template
  1795. * functions. This is a phy management function.
  1796. * @phy: This parameter specifies the sphy being controlled.
  1797. * @func: This parameter specifies the phy control function being invoked.
  1798. * @buf: This parameter is specific to the phy function being invoked.
  1799. *
  1800. * status, zero indicates success.
  1801. */
  1802. int isci_phy_control(struct asd_sas_phy *sas_phy,
  1803. enum phy_func func,
  1804. void *buf)
  1805. {
  1806. int ret = 0;
  1807. struct isci_phy *iphy = sas_phy->lldd_phy;
  1808. struct isci_port *iport = iphy->isci_port;
  1809. struct isci_host *ihost = sas_phy->ha->lldd_ha;
  1810. unsigned long flags;
  1811. dev_dbg(&ihost->pdev->dev,
  1812. "%s: phy %p; func %d; buf %p; isci phy %p, port %p\n",
  1813. __func__, sas_phy, func, buf, iphy, iport);
  1814. switch (func) {
  1815. case PHY_FUNC_DISABLE:
  1816. spin_lock_irqsave(&ihost->scic_lock, flags);
  1817. scic_sds_phy_stop(&iphy->sci);
  1818. spin_unlock_irqrestore(&ihost->scic_lock, flags);
  1819. break;
  1820. case PHY_FUNC_LINK_RESET:
  1821. spin_lock_irqsave(&ihost->scic_lock, flags);
  1822. scic_sds_phy_stop(&iphy->sci);
  1823. scic_sds_phy_start(&iphy->sci);
  1824. spin_unlock_irqrestore(&ihost->scic_lock, flags);
  1825. break;
  1826. case PHY_FUNC_HARD_RESET:
  1827. if (!iport)
  1828. return -ENODEV;
  1829. /* Perform the port reset. */
  1830. ret = isci_port_perform_hard_reset(ihost, iport, iphy);
  1831. break;
  1832. default:
  1833. dev_dbg(&ihost->pdev->dev,
  1834. "%s: phy %p; func %d NOT IMPLEMENTED!\n",
  1835. __func__, sas_phy, func);
  1836. ret = -ENOSYS;
  1837. break;
  1838. }
  1839. return ret;
  1840. }