phy.c 43 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397
  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. /*
  215. * Set the link layer hang detection to 500ms (0x1F4) from its default
  216. * value of 128ms. Max value is 511 ms.
  217. */
  218. writel(0x1F4, &sci_phy->link_layer_registers->link_layer_hang_detection_timeout);
  219. /* We can exit the initial state to the stopped state */
  220. sci_change_state(&sci_phy->sm, SCI_PHY_STOPPED);
  221. return SCI_SUCCESS;
  222. }
  223. static void phy_sata_timeout(unsigned long data)
  224. {
  225. struct sci_timer *tmr = (struct sci_timer *)data;
  226. struct scic_sds_phy *sci_phy = container_of(tmr, typeof(*sci_phy), sata_timer);
  227. struct isci_host *ihost = scic_to_ihost(sci_phy->owning_port->owning_controller);
  228. unsigned long flags;
  229. spin_lock_irqsave(&ihost->scic_lock, flags);
  230. if (tmr->cancel)
  231. goto done;
  232. dev_dbg(sciphy_to_dev(sci_phy),
  233. "%s: SCIC SDS Phy 0x%p did not receive signature fis before "
  234. "timeout.\n",
  235. __func__,
  236. sci_phy);
  237. sci_change_state(&sci_phy->sm, SCI_PHY_STARTING);
  238. done:
  239. spin_unlock_irqrestore(&ihost->scic_lock, flags);
  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 *phy_get_non_dummy_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. /* Perfrom the initialization of the TL hardware */
  290. scic_sds_phy_transport_layer_initialization(
  291. sci_phy,
  292. transport_layer_registers);
  293. /* Perofrm the initialization of the PE hardware */
  294. scic_sds_phy_link_layer_initialization(sci_phy, link_layer_registers);
  295. /*
  296. * There is nothing that needs to be done in this state just
  297. * transition to the stopped state. */
  298. sci_change_state(&sci_phy->sm, SCI_PHY_STOPPED);
  299. return SCI_SUCCESS;
  300. }
  301. /**
  302. * This method assigns the direct attached device ID for this phy.
  303. *
  304. * @sci_phy The phy for which the direct attached device id is to
  305. * be assigned.
  306. * @device_id The direct attached device ID to assign to the phy.
  307. * This will either be the RNi for the device or an invalid RNi if there
  308. * is no current device assigned to the phy.
  309. */
  310. void scic_sds_phy_setup_transport(
  311. struct scic_sds_phy *sci_phy,
  312. u32 device_id)
  313. {
  314. u32 tl_control;
  315. writel(device_id, &sci_phy->transport_layer_registers->stp_rni);
  316. /*
  317. * The read should guarantee that the first write gets posted
  318. * before the next write
  319. */
  320. tl_control = readl(&sci_phy->transport_layer_registers->control);
  321. tl_control |= SCU_TLCR_GEN_BIT(CLEAR_TCI_NCQ_MAPPING_TABLE);
  322. writel(tl_control, &sci_phy->transport_layer_registers->control);
  323. }
  324. /**
  325. *
  326. * @sci_phy: The phy object to be suspended.
  327. *
  328. * This function will perform the register reads/writes to suspend the SCU
  329. * hardware protocol engine. none
  330. */
  331. static void scic_sds_phy_suspend(
  332. struct scic_sds_phy *sci_phy)
  333. {
  334. u32 scu_sas_pcfg_value;
  335. scu_sas_pcfg_value =
  336. readl(&sci_phy->link_layer_registers->phy_configuration);
  337. scu_sas_pcfg_value |= SCU_SAS_PCFG_GEN_BIT(SUSPEND_PROTOCOL_ENGINE);
  338. writel(scu_sas_pcfg_value,
  339. &sci_phy->link_layer_registers->phy_configuration);
  340. scic_sds_phy_setup_transport(
  341. sci_phy,
  342. SCIC_SDS_REMOTE_NODE_CONTEXT_INVALID_INDEX);
  343. }
  344. void scic_sds_phy_resume(struct scic_sds_phy *sci_phy)
  345. {
  346. u32 scu_sas_pcfg_value;
  347. scu_sas_pcfg_value =
  348. readl(&sci_phy->link_layer_registers->phy_configuration);
  349. scu_sas_pcfg_value &= ~SCU_SAS_PCFG_GEN_BIT(SUSPEND_PROTOCOL_ENGINE);
  350. writel(scu_sas_pcfg_value,
  351. &sci_phy->link_layer_registers->phy_configuration);
  352. }
  353. void scic_sds_phy_get_sas_address(struct scic_sds_phy *sci_phy,
  354. struct sci_sas_address *sas_address)
  355. {
  356. sas_address->high = readl(&sci_phy->link_layer_registers->source_sas_address_high);
  357. sas_address->low = readl(&sci_phy->link_layer_registers->source_sas_address_low);
  358. }
  359. void scic_sds_phy_get_attached_sas_address(struct scic_sds_phy *sci_phy,
  360. struct sci_sas_address *sas_address)
  361. {
  362. struct sas_identify_frame *iaf;
  363. struct isci_phy *iphy = sci_phy_to_iphy(sci_phy);
  364. iaf = &iphy->frame_rcvd.iaf;
  365. memcpy(sas_address, iaf->sas_addr, SAS_ADDR_SIZE);
  366. }
  367. void scic_sds_phy_get_protocols(struct scic_sds_phy *sci_phy,
  368. struct scic_phy_proto *protocols)
  369. {
  370. protocols->all =
  371. (u16)(readl(&sci_phy->
  372. link_layer_registers->transmit_identification) &
  373. 0x0000FFFF);
  374. }
  375. enum sci_status scic_sds_phy_start(struct scic_sds_phy *sci_phy)
  376. {
  377. enum scic_sds_phy_states state = sci_phy->sm.current_state_id;
  378. if (state != SCI_PHY_STOPPED) {
  379. dev_dbg(sciphy_to_dev(sci_phy),
  380. "%s: in wrong state: %d\n", __func__, state);
  381. return SCI_FAILURE_INVALID_STATE;
  382. }
  383. sci_change_state(&sci_phy->sm, SCI_PHY_STARTING);
  384. return SCI_SUCCESS;
  385. }
  386. enum sci_status scic_sds_phy_stop(struct scic_sds_phy *sci_phy)
  387. {
  388. enum scic_sds_phy_states state = sci_phy->sm.current_state_id;
  389. switch (state) {
  390. case SCI_PHY_SUB_INITIAL:
  391. case SCI_PHY_SUB_AWAIT_OSSP_EN:
  392. case SCI_PHY_SUB_AWAIT_SAS_SPEED_EN:
  393. case SCI_PHY_SUB_AWAIT_SAS_POWER:
  394. case SCI_PHY_SUB_AWAIT_SATA_POWER:
  395. case SCI_PHY_SUB_AWAIT_SATA_PHY_EN:
  396. case SCI_PHY_SUB_AWAIT_SATA_SPEED_EN:
  397. case SCI_PHY_SUB_AWAIT_SIG_FIS_UF:
  398. case SCI_PHY_SUB_FINAL:
  399. case SCI_PHY_READY:
  400. break;
  401. default:
  402. dev_dbg(sciphy_to_dev(sci_phy),
  403. "%s: in wrong state: %d\n", __func__, state);
  404. return SCI_FAILURE_INVALID_STATE;
  405. }
  406. sci_change_state(&sci_phy->sm, SCI_PHY_STOPPED);
  407. return SCI_SUCCESS;
  408. }
  409. enum sci_status scic_sds_phy_reset(struct scic_sds_phy *sci_phy)
  410. {
  411. enum scic_sds_phy_states state = sci_phy->sm.current_state_id;
  412. if (state != SCI_PHY_READY) {
  413. dev_dbg(sciphy_to_dev(sci_phy),
  414. "%s: in wrong state: %d\n", __func__, state);
  415. return SCI_FAILURE_INVALID_STATE;
  416. }
  417. sci_change_state(&sci_phy->sm, SCI_PHY_RESETTING);
  418. return SCI_SUCCESS;
  419. }
  420. enum sci_status scic_sds_phy_consume_power_handler(struct scic_sds_phy *sci_phy)
  421. {
  422. enum scic_sds_phy_states state = sci_phy->sm.current_state_id;
  423. switch (state) {
  424. case SCI_PHY_SUB_AWAIT_SAS_POWER: {
  425. u32 enable_spinup;
  426. enable_spinup = readl(&sci_phy->link_layer_registers->notify_enable_spinup_control);
  427. enable_spinup |= SCU_ENSPINUP_GEN_BIT(ENABLE);
  428. writel(enable_spinup, &sci_phy->link_layer_registers->notify_enable_spinup_control);
  429. /* Change state to the final state this substate machine has run to completion */
  430. sci_change_state(&sci_phy->sm, SCI_PHY_SUB_FINAL);
  431. return SCI_SUCCESS;
  432. }
  433. case SCI_PHY_SUB_AWAIT_SATA_POWER: {
  434. u32 scu_sas_pcfg_value;
  435. /* Release the spinup hold state and reset the OOB state machine */
  436. scu_sas_pcfg_value =
  437. readl(&sci_phy->link_layer_registers->phy_configuration);
  438. scu_sas_pcfg_value &=
  439. ~(SCU_SAS_PCFG_GEN_BIT(SATA_SPINUP_HOLD) | SCU_SAS_PCFG_GEN_BIT(OOB_ENABLE));
  440. scu_sas_pcfg_value |= SCU_SAS_PCFG_GEN_BIT(OOB_RESET);
  441. writel(scu_sas_pcfg_value,
  442. &sci_phy->link_layer_registers->phy_configuration);
  443. /* Now restart the OOB operation */
  444. scu_sas_pcfg_value &= ~SCU_SAS_PCFG_GEN_BIT(OOB_RESET);
  445. scu_sas_pcfg_value |= SCU_SAS_PCFG_GEN_BIT(OOB_ENABLE);
  446. writel(scu_sas_pcfg_value,
  447. &sci_phy->link_layer_registers->phy_configuration);
  448. /* Change state to the final state this substate machine has run to completion */
  449. sci_change_state(&sci_phy->sm, SCI_PHY_SUB_AWAIT_SATA_PHY_EN);
  450. return SCI_SUCCESS;
  451. }
  452. default:
  453. dev_dbg(sciphy_to_dev(sci_phy),
  454. "%s: in wrong state: %d\n", __func__, state);
  455. return SCI_FAILURE_INVALID_STATE;
  456. }
  457. }
  458. /*
  459. * *****************************************************************************
  460. * * SCIC SDS PHY HELPER FUNCTIONS
  461. * ***************************************************************************** */
  462. /**
  463. *
  464. * @sci_phy: The phy object that received SAS PHY DETECTED.
  465. *
  466. * This method continues the link training for the phy as if it were a SAS PHY
  467. * instead of a SATA PHY. This is done because the completion queue had a SAS
  468. * PHY DETECTED event when the state machine was expecting a SATA PHY event.
  469. * none
  470. */
  471. static void scic_sds_phy_start_sas_link_training(
  472. struct scic_sds_phy *sci_phy)
  473. {
  474. u32 phy_control;
  475. phy_control =
  476. readl(&sci_phy->link_layer_registers->phy_configuration);
  477. phy_control |= SCU_SAS_PCFG_GEN_BIT(SATA_SPINUP_HOLD);
  478. writel(phy_control,
  479. &sci_phy->link_layer_registers->phy_configuration);
  480. sci_change_state(&sci_phy->sm, SCI_PHY_SUB_AWAIT_SAS_SPEED_EN);
  481. sci_phy->protocol = SCIC_SDS_PHY_PROTOCOL_SAS;
  482. }
  483. /**
  484. *
  485. * @sci_phy: The phy object that received a SATA SPINUP HOLD event
  486. *
  487. * This method continues the link training for the phy as if it were a SATA PHY
  488. * instead of a SAS PHY. This is done because the completion queue had a SATA
  489. * SPINUP HOLD event when the state machine was expecting a SAS PHY event. none
  490. */
  491. static void scic_sds_phy_start_sata_link_training(
  492. struct scic_sds_phy *sci_phy)
  493. {
  494. sci_change_state(&sci_phy->sm, SCI_PHY_SUB_AWAIT_SATA_POWER);
  495. sci_phy->protocol = SCIC_SDS_PHY_PROTOCOL_SATA;
  496. }
  497. /**
  498. * scic_sds_phy_complete_link_training - perform processing common to
  499. * all protocols upon completion of link training.
  500. * @sci_phy: This parameter specifies the phy object for which link training
  501. * has completed.
  502. * @max_link_rate: This parameter specifies the maximum link rate to be
  503. * associated with this phy.
  504. * @next_state: This parameter specifies the next state for the phy's starting
  505. * sub-state machine.
  506. *
  507. */
  508. static void scic_sds_phy_complete_link_training(
  509. struct scic_sds_phy *sci_phy,
  510. enum sas_linkrate max_link_rate,
  511. u32 next_state)
  512. {
  513. sci_phy->max_negotiated_speed = max_link_rate;
  514. sci_change_state(&sci_phy->sm, next_state);
  515. }
  516. enum sci_status scic_sds_phy_event_handler(struct scic_sds_phy *sci_phy,
  517. u32 event_code)
  518. {
  519. enum scic_sds_phy_states state = sci_phy->sm.current_state_id;
  520. switch (state) {
  521. case SCI_PHY_SUB_AWAIT_OSSP_EN:
  522. switch (scu_get_event_code(event_code)) {
  523. case SCU_EVENT_SAS_PHY_DETECTED:
  524. scic_sds_phy_start_sas_link_training(sci_phy);
  525. sci_phy->is_in_link_training = true;
  526. break;
  527. case SCU_EVENT_SATA_SPINUP_HOLD:
  528. scic_sds_phy_start_sata_link_training(sci_phy);
  529. sci_phy->is_in_link_training = true;
  530. break;
  531. default:
  532. dev_dbg(sciphy_to_dev(sci_phy),
  533. "%s: PHY starting substate machine received "
  534. "unexpected event_code %x\n",
  535. __func__,
  536. event_code);
  537. return SCI_FAILURE;
  538. }
  539. return SCI_SUCCESS;
  540. case SCI_PHY_SUB_AWAIT_SAS_SPEED_EN:
  541. switch (scu_get_event_code(event_code)) {
  542. case SCU_EVENT_SAS_PHY_DETECTED:
  543. /*
  544. * Why is this being reported again by the controller?
  545. * We would re-enter this state so just stay here */
  546. break;
  547. case SCU_EVENT_SAS_15:
  548. case SCU_EVENT_SAS_15_SSC:
  549. scic_sds_phy_complete_link_training(
  550. sci_phy,
  551. SAS_LINK_RATE_1_5_GBPS,
  552. SCI_PHY_SUB_AWAIT_IAF_UF);
  553. break;
  554. case SCU_EVENT_SAS_30:
  555. case SCU_EVENT_SAS_30_SSC:
  556. scic_sds_phy_complete_link_training(
  557. sci_phy,
  558. SAS_LINK_RATE_3_0_GBPS,
  559. SCI_PHY_SUB_AWAIT_IAF_UF);
  560. break;
  561. case SCU_EVENT_SAS_60:
  562. case SCU_EVENT_SAS_60_SSC:
  563. scic_sds_phy_complete_link_training(
  564. sci_phy,
  565. SAS_LINK_RATE_6_0_GBPS,
  566. SCI_PHY_SUB_AWAIT_IAF_UF);
  567. break;
  568. case SCU_EVENT_SATA_SPINUP_HOLD:
  569. /*
  570. * We were doing SAS PHY link training and received a SATA PHY event
  571. * continue OOB/SN as if this were a SATA PHY */
  572. scic_sds_phy_start_sata_link_training(sci_phy);
  573. break;
  574. case SCU_EVENT_LINK_FAILURE:
  575. /* Link failure change state back to the starting state */
  576. sci_change_state(&sci_phy->sm, SCI_PHY_STARTING);
  577. break;
  578. default:
  579. dev_warn(sciphy_to_dev(sci_phy),
  580. "%s: PHY starting substate machine received "
  581. "unexpected event_code %x\n",
  582. __func__, event_code);
  583. return SCI_FAILURE;
  584. break;
  585. }
  586. return SCI_SUCCESS;
  587. case SCI_PHY_SUB_AWAIT_IAF_UF:
  588. switch (scu_get_event_code(event_code)) {
  589. case SCU_EVENT_SAS_PHY_DETECTED:
  590. /* Backup the state machine */
  591. scic_sds_phy_start_sas_link_training(sci_phy);
  592. break;
  593. case SCU_EVENT_SATA_SPINUP_HOLD:
  594. /* We were doing SAS PHY link training and received a
  595. * SATA PHY event continue OOB/SN as if this were a
  596. * SATA PHY
  597. */
  598. scic_sds_phy_start_sata_link_training(sci_phy);
  599. break;
  600. case SCU_EVENT_RECEIVED_IDENTIFY_TIMEOUT:
  601. case SCU_EVENT_LINK_FAILURE:
  602. case SCU_EVENT_HARD_RESET_RECEIVED:
  603. /* Start the oob/sn state machine over again */
  604. sci_change_state(&sci_phy->sm, SCI_PHY_STARTING);
  605. break;
  606. default:
  607. dev_warn(sciphy_to_dev(sci_phy),
  608. "%s: PHY starting substate machine received "
  609. "unexpected event_code %x\n",
  610. __func__, event_code);
  611. return SCI_FAILURE;
  612. }
  613. return SCI_SUCCESS;
  614. case SCI_PHY_SUB_AWAIT_SAS_POWER:
  615. switch (scu_get_event_code(event_code)) {
  616. case SCU_EVENT_LINK_FAILURE:
  617. /* Link failure change state back to the starting state */
  618. sci_change_state(&sci_phy->sm, SCI_PHY_STARTING);
  619. break;
  620. default:
  621. dev_warn(sciphy_to_dev(sci_phy),
  622. "%s: PHY starting substate machine received unexpected "
  623. "event_code %x\n",
  624. __func__,
  625. event_code);
  626. return SCI_FAILURE;
  627. }
  628. return SCI_SUCCESS;
  629. case SCI_PHY_SUB_AWAIT_SATA_POWER:
  630. switch (scu_get_event_code(event_code)) {
  631. case SCU_EVENT_LINK_FAILURE:
  632. /* Link failure change state back to the starting state */
  633. sci_change_state(&sci_phy->sm, SCI_PHY_STARTING);
  634. break;
  635. case SCU_EVENT_SATA_SPINUP_HOLD:
  636. /* These events are received every 10ms and are
  637. * expected while in this state
  638. */
  639. break;
  640. case SCU_EVENT_SAS_PHY_DETECTED:
  641. /* There has been a change in the phy type before OOB/SN for the
  642. * SATA finished start down the SAS link traning path.
  643. */
  644. scic_sds_phy_start_sas_link_training(sci_phy);
  645. break;
  646. default:
  647. dev_warn(sciphy_to_dev(sci_phy),
  648. "%s: PHY starting substate machine received "
  649. "unexpected event_code %x\n",
  650. __func__, event_code);
  651. return SCI_FAILURE;
  652. }
  653. return SCI_SUCCESS;
  654. case SCI_PHY_SUB_AWAIT_SATA_PHY_EN:
  655. switch (scu_get_event_code(event_code)) {
  656. case SCU_EVENT_LINK_FAILURE:
  657. /* Link failure change state back to the starting state */
  658. sci_change_state(&sci_phy->sm, SCI_PHY_STARTING);
  659. break;
  660. case SCU_EVENT_SATA_SPINUP_HOLD:
  661. /* These events might be received since we dont know how many may be in
  662. * the completion queue while waiting for power
  663. */
  664. break;
  665. case SCU_EVENT_SATA_PHY_DETECTED:
  666. sci_phy->protocol = SCIC_SDS_PHY_PROTOCOL_SATA;
  667. /* We have received the SATA PHY notification change state */
  668. sci_change_state(&sci_phy->sm, SCI_PHY_SUB_AWAIT_SATA_SPEED_EN);
  669. break;
  670. case SCU_EVENT_SAS_PHY_DETECTED:
  671. /* There has been a change in the phy type before OOB/SN for the
  672. * SATA finished start down the SAS link traning path.
  673. */
  674. scic_sds_phy_start_sas_link_training(sci_phy);
  675. break;
  676. default:
  677. dev_warn(sciphy_to_dev(sci_phy),
  678. "%s: PHY starting substate machine received "
  679. "unexpected event_code %x\n",
  680. __func__,
  681. event_code);
  682. return SCI_FAILURE;;
  683. }
  684. return SCI_SUCCESS;
  685. case SCI_PHY_SUB_AWAIT_SATA_SPEED_EN:
  686. switch (scu_get_event_code(event_code)) {
  687. case SCU_EVENT_SATA_PHY_DETECTED:
  688. /*
  689. * The hardware reports multiple SATA PHY detected events
  690. * ignore the extras */
  691. break;
  692. case SCU_EVENT_SATA_15:
  693. case SCU_EVENT_SATA_15_SSC:
  694. scic_sds_phy_complete_link_training(
  695. sci_phy,
  696. SAS_LINK_RATE_1_5_GBPS,
  697. SCI_PHY_SUB_AWAIT_SIG_FIS_UF);
  698. break;
  699. case SCU_EVENT_SATA_30:
  700. case SCU_EVENT_SATA_30_SSC:
  701. scic_sds_phy_complete_link_training(
  702. sci_phy,
  703. SAS_LINK_RATE_3_0_GBPS,
  704. SCI_PHY_SUB_AWAIT_SIG_FIS_UF);
  705. break;
  706. case SCU_EVENT_SATA_60:
  707. case SCU_EVENT_SATA_60_SSC:
  708. scic_sds_phy_complete_link_training(
  709. sci_phy,
  710. SAS_LINK_RATE_6_0_GBPS,
  711. SCI_PHY_SUB_AWAIT_SIG_FIS_UF);
  712. break;
  713. case SCU_EVENT_LINK_FAILURE:
  714. /* Link failure change state back to the starting state */
  715. sci_change_state(&sci_phy->sm, SCI_PHY_STARTING);
  716. break;
  717. case SCU_EVENT_SAS_PHY_DETECTED:
  718. /*
  719. * There has been a change in the phy type before OOB/SN for the
  720. * SATA finished start down the SAS link traning path. */
  721. scic_sds_phy_start_sas_link_training(sci_phy);
  722. break;
  723. default:
  724. dev_warn(sciphy_to_dev(sci_phy),
  725. "%s: PHY starting substate machine received "
  726. "unexpected event_code %x\n",
  727. __func__, event_code);
  728. return SCI_FAILURE;
  729. }
  730. return SCI_SUCCESS;
  731. case SCI_PHY_SUB_AWAIT_SIG_FIS_UF:
  732. switch (scu_get_event_code(event_code)) {
  733. case SCU_EVENT_SATA_PHY_DETECTED:
  734. /* Backup the state machine */
  735. sci_change_state(&sci_phy->sm, SCI_PHY_SUB_AWAIT_SATA_SPEED_EN);
  736. break;
  737. case SCU_EVENT_LINK_FAILURE:
  738. /* Link failure change state back to the starting state */
  739. sci_change_state(&sci_phy->sm, SCI_PHY_STARTING);
  740. break;
  741. default:
  742. dev_warn(sciphy_to_dev(sci_phy),
  743. "%s: PHY starting substate machine received "
  744. "unexpected event_code %x\n",
  745. __func__,
  746. event_code);
  747. return SCI_FAILURE;
  748. }
  749. return SCI_SUCCESS;
  750. case SCI_PHY_READY:
  751. switch (scu_get_event_code(event_code)) {
  752. case SCU_EVENT_LINK_FAILURE:
  753. /* Link failure change state back to the starting state */
  754. sci_change_state(&sci_phy->sm, SCI_PHY_STARTING);
  755. break;
  756. case SCU_EVENT_BROADCAST_CHANGE:
  757. /* Broadcast change received. Notify the port. */
  758. if (phy_get_non_dummy_port(sci_phy) != NULL)
  759. scic_sds_port_broadcast_change_received(sci_phy->owning_port, sci_phy);
  760. else
  761. sci_phy->bcn_received_while_port_unassigned = true;
  762. break;
  763. default:
  764. dev_warn(sciphy_to_dev(sci_phy),
  765. "%sP SCIC PHY 0x%p ready state machine received "
  766. "unexpected event_code %x\n",
  767. __func__, sci_phy, event_code);
  768. return SCI_FAILURE_INVALID_STATE;
  769. }
  770. return SCI_SUCCESS;
  771. case SCI_PHY_RESETTING:
  772. switch (scu_get_event_code(event_code)) {
  773. case SCU_EVENT_HARD_RESET_TRANSMITTED:
  774. /* Link failure change state back to the starting state */
  775. sci_change_state(&sci_phy->sm, SCI_PHY_STARTING);
  776. break;
  777. default:
  778. dev_warn(sciphy_to_dev(sci_phy),
  779. "%s: SCIC PHY 0x%p resetting state machine received "
  780. "unexpected event_code %x\n",
  781. __func__, sci_phy, event_code);
  782. return SCI_FAILURE_INVALID_STATE;
  783. break;
  784. }
  785. return SCI_SUCCESS;
  786. default:
  787. dev_dbg(sciphy_to_dev(sci_phy),
  788. "%s: in wrong state: %d\n", __func__, state);
  789. return SCI_FAILURE_INVALID_STATE;
  790. }
  791. }
  792. enum sci_status scic_sds_phy_frame_handler(struct scic_sds_phy *sci_phy,
  793. u32 frame_index)
  794. {
  795. enum scic_sds_phy_states state = sci_phy->sm.current_state_id;
  796. struct scic_sds_controller *scic = sci_phy->owning_port->owning_controller;
  797. enum sci_status result;
  798. switch (state) {
  799. case SCI_PHY_SUB_AWAIT_IAF_UF: {
  800. u32 *frame_words;
  801. struct sas_identify_frame iaf;
  802. struct isci_phy *iphy = sci_phy_to_iphy(sci_phy);
  803. result = scic_sds_unsolicited_frame_control_get_header(&scic->uf_control,
  804. frame_index,
  805. (void **)&frame_words);
  806. if (result != SCI_SUCCESS)
  807. return result;
  808. sci_swab32_cpy(&iaf, frame_words, sizeof(iaf) / sizeof(u32));
  809. if (iaf.frame_type == 0) {
  810. u32 state;
  811. memcpy(&iphy->frame_rcvd.iaf, &iaf, sizeof(iaf));
  812. if (iaf.smp_tport) {
  813. /* We got the IAF for an expander PHY go to the final
  814. * state since there are no power requirements for
  815. * expander phys.
  816. */
  817. state = SCI_PHY_SUB_FINAL;
  818. } else {
  819. /* We got the IAF we can now go to the await spinup
  820. * semaphore state
  821. */
  822. state = SCI_PHY_SUB_AWAIT_SAS_POWER;
  823. }
  824. sci_change_state(&sci_phy->sm, state);
  825. result = SCI_SUCCESS;
  826. } else
  827. dev_warn(sciphy_to_dev(sci_phy),
  828. "%s: PHY starting substate machine received "
  829. "unexpected frame id %x\n",
  830. __func__, frame_index);
  831. scic_sds_controller_release_frame(scic, frame_index);
  832. return result;
  833. }
  834. case SCI_PHY_SUB_AWAIT_SIG_FIS_UF: {
  835. struct dev_to_host_fis *frame_header;
  836. u32 *fis_frame_data;
  837. struct isci_phy *iphy = sci_phy_to_iphy(sci_phy);
  838. result = scic_sds_unsolicited_frame_control_get_header(
  839. &(scic_sds_phy_get_controller(sci_phy)->uf_control),
  840. frame_index,
  841. (void **)&frame_header);
  842. if (result != SCI_SUCCESS)
  843. return result;
  844. if ((frame_header->fis_type == FIS_REGD2H) &&
  845. !(frame_header->status & ATA_BUSY)) {
  846. scic_sds_unsolicited_frame_control_get_buffer(&scic->uf_control,
  847. frame_index,
  848. (void **)&fis_frame_data);
  849. scic_sds_controller_copy_sata_response(&iphy->frame_rcvd.fis,
  850. frame_header,
  851. fis_frame_data);
  852. /* got IAF we can now go to the await spinup semaphore state */
  853. sci_change_state(&sci_phy->sm, SCI_PHY_SUB_FINAL);
  854. result = SCI_SUCCESS;
  855. } else
  856. dev_warn(sciphy_to_dev(sci_phy),
  857. "%s: PHY starting substate machine received "
  858. "unexpected frame id %x\n",
  859. __func__, frame_index);
  860. /* Regardless of the result we are done with this frame with it */
  861. scic_sds_controller_release_frame(scic, frame_index);
  862. return result;
  863. }
  864. default:
  865. dev_dbg(sciphy_to_dev(sci_phy),
  866. "%s: in wrong state: %d\n", __func__, state);
  867. return SCI_FAILURE_INVALID_STATE;
  868. }
  869. }
  870. static void scic_sds_phy_starting_initial_substate_enter(struct sci_base_state_machine *sm)
  871. {
  872. struct scic_sds_phy *sci_phy = container_of(sm, typeof(*sci_phy), sm);
  873. /* This is just an temporary state go off to the starting state */
  874. sci_change_state(&sci_phy->sm, SCI_PHY_SUB_AWAIT_OSSP_EN);
  875. }
  876. static void scic_sds_phy_starting_await_sas_power_substate_enter(struct sci_base_state_machine *sm)
  877. {
  878. struct scic_sds_phy *sci_phy = container_of(sm, typeof(*sci_phy), sm);
  879. struct scic_sds_controller *scic = sci_phy->owning_port->owning_controller;
  880. scic_sds_controller_power_control_queue_insert(scic, sci_phy);
  881. }
  882. static void scic_sds_phy_starting_await_sas_power_substate_exit(struct sci_base_state_machine *sm)
  883. {
  884. struct scic_sds_phy *sci_phy = container_of(sm, typeof(*sci_phy), sm);
  885. struct scic_sds_controller *scic = sci_phy->owning_port->owning_controller;
  886. scic_sds_controller_power_control_queue_remove(scic, sci_phy);
  887. }
  888. static void scic_sds_phy_starting_await_sata_power_substate_enter(struct sci_base_state_machine *sm)
  889. {
  890. struct scic_sds_phy *sci_phy = container_of(sm, typeof(*sci_phy), sm);
  891. struct scic_sds_controller *scic = sci_phy->owning_port->owning_controller;
  892. scic_sds_controller_power_control_queue_insert(scic, sci_phy);
  893. }
  894. static void scic_sds_phy_starting_await_sata_power_substate_exit(struct sci_base_state_machine *sm)
  895. {
  896. struct scic_sds_phy *sci_phy = container_of(sm, typeof(*sci_phy), sm);
  897. struct scic_sds_controller *scic = sci_phy->owning_port->owning_controller;
  898. scic_sds_controller_power_control_queue_remove(scic, sci_phy);
  899. }
  900. static void scic_sds_phy_starting_await_sata_phy_substate_enter(struct sci_base_state_machine *sm)
  901. {
  902. struct scic_sds_phy *sci_phy = container_of(sm, typeof(*sci_phy), sm);
  903. sci_mod_timer(&sci_phy->sata_timer, SCIC_SDS_SATA_LINK_TRAINING_TIMEOUT);
  904. }
  905. static void scic_sds_phy_starting_await_sata_phy_substate_exit(struct sci_base_state_machine *sm)
  906. {
  907. struct scic_sds_phy *sci_phy = container_of(sm, typeof(*sci_phy), sm);
  908. sci_del_timer(&sci_phy->sata_timer);
  909. }
  910. static void scic_sds_phy_starting_await_sata_speed_substate_enter(struct sci_base_state_machine *sm)
  911. {
  912. struct scic_sds_phy *sci_phy = container_of(sm, typeof(*sci_phy), sm);
  913. sci_mod_timer(&sci_phy->sata_timer, SCIC_SDS_SATA_LINK_TRAINING_TIMEOUT);
  914. }
  915. static void scic_sds_phy_starting_await_sata_speed_substate_exit(struct sci_base_state_machine *sm)
  916. {
  917. struct scic_sds_phy *sci_phy = container_of(sm, typeof(*sci_phy), sm);
  918. sci_del_timer(&sci_phy->sata_timer);
  919. }
  920. static void scic_sds_phy_starting_await_sig_fis_uf_substate_enter(struct sci_base_state_machine *sm)
  921. {
  922. struct scic_sds_phy *sci_phy = container_of(sm, typeof(*sci_phy), sm);
  923. if (scic_sds_port_link_detected(sci_phy->owning_port, sci_phy)) {
  924. /*
  925. * Clear the PE suspend condition so we can actually
  926. * receive SIG FIS
  927. * The hardware will not respond to the XRDY until the PE
  928. * suspend condition is cleared.
  929. */
  930. scic_sds_phy_resume(sci_phy);
  931. sci_mod_timer(&sci_phy->sata_timer,
  932. SCIC_SDS_SIGNATURE_FIS_TIMEOUT);
  933. } else
  934. sci_phy->is_in_link_training = false;
  935. }
  936. static void scic_sds_phy_starting_await_sig_fis_uf_substate_exit(struct sci_base_state_machine *sm)
  937. {
  938. struct scic_sds_phy *sci_phy = container_of(sm, typeof(*sci_phy), sm);
  939. sci_del_timer(&sci_phy->sata_timer);
  940. }
  941. static void scic_sds_phy_starting_final_substate_enter(struct sci_base_state_machine *sm)
  942. {
  943. struct scic_sds_phy *sci_phy = container_of(sm, typeof(*sci_phy), sm);
  944. /* State machine has run to completion so exit out and change
  945. * the base state machine to the ready state
  946. */
  947. sci_change_state(&sci_phy->sm, SCI_PHY_READY);
  948. }
  949. /**
  950. *
  951. * @sci_phy: This is the struct scic_sds_phy object to stop.
  952. *
  953. * This method will stop the struct scic_sds_phy object. This does not reset the
  954. * protocol engine it just suspends it and places it in a state where it will
  955. * not cause the end device to power up. none
  956. */
  957. static void scu_link_layer_stop_protocol_engine(
  958. struct scic_sds_phy *sci_phy)
  959. {
  960. u32 scu_sas_pcfg_value;
  961. u32 enable_spinup_value;
  962. /* Suspend the protocol engine and place it in a sata spinup hold state */
  963. scu_sas_pcfg_value =
  964. readl(&sci_phy->link_layer_registers->phy_configuration);
  965. scu_sas_pcfg_value |=
  966. (SCU_SAS_PCFG_GEN_BIT(OOB_RESET) |
  967. SCU_SAS_PCFG_GEN_BIT(SUSPEND_PROTOCOL_ENGINE) |
  968. SCU_SAS_PCFG_GEN_BIT(SATA_SPINUP_HOLD));
  969. writel(scu_sas_pcfg_value,
  970. &sci_phy->link_layer_registers->phy_configuration);
  971. /* Disable the notify enable spinup primitives */
  972. enable_spinup_value = readl(&sci_phy->link_layer_registers->notify_enable_spinup_control);
  973. enable_spinup_value &= ~SCU_ENSPINUP_GEN_BIT(ENABLE);
  974. writel(enable_spinup_value, &sci_phy->link_layer_registers->notify_enable_spinup_control);
  975. }
  976. /**
  977. *
  978. *
  979. * This method will start the OOB/SN state machine for this struct scic_sds_phy object.
  980. */
  981. static void scu_link_layer_start_oob(
  982. struct scic_sds_phy *sci_phy)
  983. {
  984. u32 scu_sas_pcfg_value;
  985. scu_sas_pcfg_value =
  986. readl(&sci_phy->link_layer_registers->phy_configuration);
  987. scu_sas_pcfg_value |= SCU_SAS_PCFG_GEN_BIT(OOB_ENABLE);
  988. scu_sas_pcfg_value &=
  989. ~(SCU_SAS_PCFG_GEN_BIT(OOB_RESET) |
  990. SCU_SAS_PCFG_GEN_BIT(HARD_RESET));
  991. writel(scu_sas_pcfg_value,
  992. &sci_phy->link_layer_registers->phy_configuration);
  993. }
  994. /**
  995. *
  996. *
  997. * This method will transmit a hard reset request on the specified phy. The SCU
  998. * hardware requires that we reset the OOB state machine and set the hard reset
  999. * bit in the phy configuration register. We then must start OOB over with the
  1000. * hard reset bit set.
  1001. */
  1002. static void scu_link_layer_tx_hard_reset(
  1003. struct scic_sds_phy *sci_phy)
  1004. {
  1005. u32 phy_configuration_value;
  1006. /*
  1007. * SAS Phys must wait for the HARD_RESET_TX event notification to transition
  1008. * to the starting state. */
  1009. phy_configuration_value =
  1010. readl(&sci_phy->link_layer_registers->phy_configuration);
  1011. phy_configuration_value |=
  1012. (SCU_SAS_PCFG_GEN_BIT(HARD_RESET) |
  1013. SCU_SAS_PCFG_GEN_BIT(OOB_RESET));
  1014. writel(phy_configuration_value,
  1015. &sci_phy->link_layer_registers->phy_configuration);
  1016. /* Now take the OOB state machine out of reset */
  1017. phy_configuration_value |= SCU_SAS_PCFG_GEN_BIT(OOB_ENABLE);
  1018. phy_configuration_value &= ~SCU_SAS_PCFG_GEN_BIT(OOB_RESET);
  1019. writel(phy_configuration_value,
  1020. &sci_phy->link_layer_registers->phy_configuration);
  1021. }
  1022. static void scic_sds_phy_stopped_state_enter(struct sci_base_state_machine *sm)
  1023. {
  1024. struct scic_sds_phy *sci_phy = container_of(sm, typeof(*sci_phy), sm);
  1025. /*
  1026. * @todo We need to get to the controller to place this PE in a
  1027. * reset state
  1028. */
  1029. sci_del_timer(&sci_phy->sata_timer);
  1030. scu_link_layer_stop_protocol_engine(sci_phy);
  1031. if (sci_phy->sm.previous_state_id != SCI_PHY_INITIAL)
  1032. scic_sds_controller_link_down(scic_sds_phy_get_controller(sci_phy),
  1033. phy_get_non_dummy_port(sci_phy),
  1034. sci_phy);
  1035. }
  1036. static void scic_sds_phy_starting_state_enter(struct sci_base_state_machine *sm)
  1037. {
  1038. struct scic_sds_phy *sci_phy = container_of(sm, typeof(*sci_phy), sm);
  1039. scu_link_layer_stop_protocol_engine(sci_phy);
  1040. scu_link_layer_start_oob(sci_phy);
  1041. /* We don't know what kind of phy we are going to be just yet */
  1042. sci_phy->protocol = SCIC_SDS_PHY_PROTOCOL_UNKNOWN;
  1043. sci_phy->bcn_received_while_port_unassigned = false;
  1044. if (sci_phy->sm.previous_state_id == SCI_PHY_READY)
  1045. scic_sds_controller_link_down(scic_sds_phy_get_controller(sci_phy),
  1046. phy_get_non_dummy_port(sci_phy),
  1047. sci_phy);
  1048. sci_change_state(&sci_phy->sm, SCI_PHY_SUB_INITIAL);
  1049. }
  1050. static void scic_sds_phy_ready_state_enter(struct sci_base_state_machine *sm)
  1051. {
  1052. struct scic_sds_phy *sci_phy = container_of(sm, typeof(*sci_phy), sm);
  1053. scic_sds_controller_link_up(scic_sds_phy_get_controller(sci_phy),
  1054. phy_get_non_dummy_port(sci_phy),
  1055. sci_phy);
  1056. }
  1057. static void scic_sds_phy_ready_state_exit(struct sci_base_state_machine *sm)
  1058. {
  1059. struct scic_sds_phy *sci_phy = container_of(sm, typeof(*sci_phy), sm);
  1060. scic_sds_phy_suspend(sci_phy);
  1061. }
  1062. static void scic_sds_phy_resetting_state_enter(struct sci_base_state_machine *sm)
  1063. {
  1064. struct scic_sds_phy *sci_phy = container_of(sm, typeof(*sci_phy), sm);
  1065. /* The phy is being reset, therefore deactivate it from the port. In
  1066. * the resetting state we don't notify the user regarding link up and
  1067. * link down notifications
  1068. */
  1069. scic_sds_port_deactivate_phy(sci_phy->owning_port, sci_phy, false);
  1070. if (sci_phy->protocol == SCIC_SDS_PHY_PROTOCOL_SAS) {
  1071. scu_link_layer_tx_hard_reset(sci_phy);
  1072. } else {
  1073. /* The SCU does not need to have a discrete reset state so
  1074. * just go back to the starting state.
  1075. */
  1076. sci_change_state(&sci_phy->sm, SCI_PHY_STARTING);
  1077. }
  1078. }
  1079. static const struct sci_base_state scic_sds_phy_state_table[] = {
  1080. [SCI_PHY_INITIAL] = { },
  1081. [SCI_PHY_STOPPED] = {
  1082. .enter_state = scic_sds_phy_stopped_state_enter,
  1083. },
  1084. [SCI_PHY_STARTING] = {
  1085. .enter_state = scic_sds_phy_starting_state_enter,
  1086. },
  1087. [SCI_PHY_SUB_INITIAL] = {
  1088. .enter_state = scic_sds_phy_starting_initial_substate_enter,
  1089. },
  1090. [SCI_PHY_SUB_AWAIT_OSSP_EN] = { },
  1091. [SCI_PHY_SUB_AWAIT_SAS_SPEED_EN] = { },
  1092. [SCI_PHY_SUB_AWAIT_IAF_UF] = { },
  1093. [SCI_PHY_SUB_AWAIT_SAS_POWER] = {
  1094. .enter_state = scic_sds_phy_starting_await_sas_power_substate_enter,
  1095. .exit_state = scic_sds_phy_starting_await_sas_power_substate_exit,
  1096. },
  1097. [SCI_PHY_SUB_AWAIT_SATA_POWER] = {
  1098. .enter_state = scic_sds_phy_starting_await_sata_power_substate_enter,
  1099. .exit_state = scic_sds_phy_starting_await_sata_power_substate_exit
  1100. },
  1101. [SCI_PHY_SUB_AWAIT_SATA_PHY_EN] = {
  1102. .enter_state = scic_sds_phy_starting_await_sata_phy_substate_enter,
  1103. .exit_state = scic_sds_phy_starting_await_sata_phy_substate_exit
  1104. },
  1105. [SCI_PHY_SUB_AWAIT_SATA_SPEED_EN] = {
  1106. .enter_state = scic_sds_phy_starting_await_sata_speed_substate_enter,
  1107. .exit_state = scic_sds_phy_starting_await_sata_speed_substate_exit
  1108. },
  1109. [SCI_PHY_SUB_AWAIT_SIG_FIS_UF] = {
  1110. .enter_state = scic_sds_phy_starting_await_sig_fis_uf_substate_enter,
  1111. .exit_state = scic_sds_phy_starting_await_sig_fis_uf_substate_exit
  1112. },
  1113. [SCI_PHY_SUB_FINAL] = {
  1114. .enter_state = scic_sds_phy_starting_final_substate_enter,
  1115. },
  1116. [SCI_PHY_READY] = {
  1117. .enter_state = scic_sds_phy_ready_state_enter,
  1118. .exit_state = scic_sds_phy_ready_state_exit,
  1119. },
  1120. [SCI_PHY_RESETTING] = {
  1121. .enter_state = scic_sds_phy_resetting_state_enter,
  1122. },
  1123. [SCI_PHY_FINAL] = { },
  1124. };
  1125. void scic_sds_phy_construct(struct scic_sds_phy *sci_phy,
  1126. struct scic_sds_port *owning_port, u8 phy_index)
  1127. {
  1128. sci_init_sm(&sci_phy->sm, scic_sds_phy_state_table, SCI_PHY_INITIAL);
  1129. /* Copy the rest of the input data to our locals */
  1130. sci_phy->owning_port = owning_port;
  1131. sci_phy->phy_index = phy_index;
  1132. sci_phy->bcn_received_while_port_unassigned = false;
  1133. sci_phy->protocol = SCIC_SDS_PHY_PROTOCOL_UNKNOWN;
  1134. sci_phy->link_layer_registers = NULL;
  1135. sci_phy->max_negotiated_speed = SAS_LINK_RATE_UNKNOWN;
  1136. /* Create the SIGNATURE FIS Timeout timer for this phy */
  1137. sci_init_timer(&sci_phy->sata_timer, phy_sata_timeout);
  1138. }
  1139. void isci_phy_init(struct isci_phy *iphy, struct isci_host *ihost, int index)
  1140. {
  1141. union scic_oem_parameters oem;
  1142. u64 sci_sas_addr;
  1143. __be64 sas_addr;
  1144. scic_oem_parameters_get(&ihost->sci, &oem);
  1145. sci_sas_addr = oem.sds1.phys[index].sas_address.high;
  1146. sci_sas_addr <<= 32;
  1147. sci_sas_addr |= oem.sds1.phys[index].sas_address.low;
  1148. sas_addr = cpu_to_be64(sci_sas_addr);
  1149. memcpy(iphy->sas_addr, &sas_addr, sizeof(sas_addr));
  1150. iphy->isci_port = NULL;
  1151. iphy->sas_phy.enabled = 0;
  1152. iphy->sas_phy.id = index;
  1153. iphy->sas_phy.sas_addr = &iphy->sas_addr[0];
  1154. iphy->sas_phy.frame_rcvd = (u8 *)&iphy->frame_rcvd;
  1155. iphy->sas_phy.ha = &ihost->sas_ha;
  1156. iphy->sas_phy.lldd_phy = iphy;
  1157. iphy->sas_phy.enabled = 1;
  1158. iphy->sas_phy.class = SAS;
  1159. iphy->sas_phy.iproto = SAS_PROTOCOL_ALL;
  1160. iphy->sas_phy.tproto = 0;
  1161. iphy->sas_phy.type = PHY_TYPE_PHYSICAL;
  1162. iphy->sas_phy.role = PHY_ROLE_INITIATOR;
  1163. iphy->sas_phy.oob_mode = OOB_NOT_CONNECTED;
  1164. iphy->sas_phy.linkrate = SAS_LINK_RATE_UNKNOWN;
  1165. memset(&iphy->frame_rcvd, 0, sizeof(iphy->frame_rcvd));
  1166. }
  1167. /**
  1168. * isci_phy_control() - This function is one of the SAS Domain Template
  1169. * functions. This is a phy management function.
  1170. * @phy: This parameter specifies the sphy being controlled.
  1171. * @func: This parameter specifies the phy control function being invoked.
  1172. * @buf: This parameter is specific to the phy function being invoked.
  1173. *
  1174. * status, zero indicates success.
  1175. */
  1176. int isci_phy_control(struct asd_sas_phy *sas_phy,
  1177. enum phy_func func,
  1178. void *buf)
  1179. {
  1180. int ret = 0;
  1181. struct isci_phy *iphy = sas_phy->lldd_phy;
  1182. struct isci_port *iport = iphy->isci_port;
  1183. struct isci_host *ihost = sas_phy->ha->lldd_ha;
  1184. unsigned long flags;
  1185. dev_dbg(&ihost->pdev->dev,
  1186. "%s: phy %p; func %d; buf %p; isci phy %p, port %p\n",
  1187. __func__, sas_phy, func, buf, iphy, iport);
  1188. switch (func) {
  1189. case PHY_FUNC_DISABLE:
  1190. spin_lock_irqsave(&ihost->scic_lock, flags);
  1191. scic_sds_phy_stop(&iphy->sci);
  1192. spin_unlock_irqrestore(&ihost->scic_lock, flags);
  1193. break;
  1194. case PHY_FUNC_LINK_RESET:
  1195. spin_lock_irqsave(&ihost->scic_lock, flags);
  1196. scic_sds_phy_stop(&iphy->sci);
  1197. scic_sds_phy_start(&iphy->sci);
  1198. spin_unlock_irqrestore(&ihost->scic_lock, flags);
  1199. break;
  1200. case PHY_FUNC_HARD_RESET:
  1201. if (!iport)
  1202. return -ENODEV;
  1203. /* Perform the port reset. */
  1204. ret = isci_port_perform_hard_reset(ihost, iport, iphy);
  1205. break;
  1206. default:
  1207. dev_dbg(&ihost->pdev->dev,
  1208. "%s: phy %p; func %d NOT IMPLEMENTED!\n",
  1209. __func__, sas_phy, func);
  1210. ret = -ENOSYS;
  1211. break;
  1212. }
  1213. return ret;
  1214. }