zfcp_erp.c 47 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706
  1. /*
  2. * zfcp device driver
  3. *
  4. * Error Recovery Procedures (ERP).
  5. *
  6. * Copyright IBM Corporation 2002, 2008
  7. */
  8. #include "zfcp_ext.h"
  9. #define ZFCP_MAX_ERPS 3
  10. enum zfcp_erp_act_flags {
  11. ZFCP_STATUS_ERP_TIMEDOUT = 0x10000000,
  12. ZFCP_STATUS_ERP_CLOSE_ONLY = 0x01000000,
  13. ZFCP_STATUS_ERP_DISMISSING = 0x00100000,
  14. ZFCP_STATUS_ERP_DISMISSED = 0x00200000,
  15. ZFCP_STATUS_ERP_LOWMEM = 0x00400000,
  16. };
  17. enum zfcp_erp_steps {
  18. ZFCP_ERP_STEP_UNINITIALIZED = 0x0000,
  19. ZFCP_ERP_STEP_FSF_XCONFIG = 0x0001,
  20. ZFCP_ERP_STEP_PHYS_PORT_CLOSING = 0x0010,
  21. ZFCP_ERP_STEP_PORT_CLOSING = 0x0100,
  22. ZFCP_ERP_STEP_NAMESERVER_LOOKUP = 0x0400,
  23. ZFCP_ERP_STEP_PORT_OPENING = 0x0800,
  24. ZFCP_ERP_STEP_UNIT_CLOSING = 0x1000,
  25. ZFCP_ERP_STEP_UNIT_OPENING = 0x2000,
  26. };
  27. enum zfcp_erp_act_type {
  28. ZFCP_ERP_ACTION_REOPEN_UNIT = 1,
  29. ZFCP_ERP_ACTION_REOPEN_PORT = 2,
  30. ZFCP_ERP_ACTION_REOPEN_PORT_FORCED = 3,
  31. ZFCP_ERP_ACTION_REOPEN_ADAPTER = 4,
  32. };
  33. enum zfcp_erp_act_state {
  34. ZFCP_ERP_ACTION_RUNNING = 1,
  35. ZFCP_ERP_ACTION_READY = 2,
  36. };
  37. enum zfcp_erp_act_result {
  38. ZFCP_ERP_SUCCEEDED = 0,
  39. ZFCP_ERP_FAILED = 1,
  40. ZFCP_ERP_CONTINUES = 2,
  41. ZFCP_ERP_EXIT = 3,
  42. ZFCP_ERP_DISMISSED = 4,
  43. ZFCP_ERP_NOMEM = 5,
  44. };
  45. static void zfcp_erp_adapter_block(struct zfcp_adapter *adapter, int mask)
  46. {
  47. zfcp_erp_modify_adapter_status(adapter, 15, NULL,
  48. ZFCP_STATUS_COMMON_UNBLOCKED | mask,
  49. ZFCP_CLEAR);
  50. }
  51. static int zfcp_erp_action_exists(struct zfcp_erp_action *act)
  52. {
  53. struct zfcp_erp_action *curr_act;
  54. list_for_each_entry(curr_act, &act->adapter->erp_running_head, list)
  55. if (act == curr_act)
  56. return ZFCP_ERP_ACTION_RUNNING;
  57. return 0;
  58. }
  59. static void zfcp_erp_action_ready(struct zfcp_erp_action *act)
  60. {
  61. struct zfcp_adapter *adapter = act->adapter;
  62. list_move(&act->list, &act->adapter->erp_ready_head);
  63. zfcp_rec_dbf_event_action(146, act);
  64. up(&adapter->erp_ready_sem);
  65. zfcp_rec_dbf_event_thread(2, adapter);
  66. }
  67. static void zfcp_erp_action_dismiss(struct zfcp_erp_action *act)
  68. {
  69. act->status |= ZFCP_STATUS_ERP_DISMISSED;
  70. if (zfcp_erp_action_exists(act) == ZFCP_ERP_ACTION_RUNNING)
  71. zfcp_erp_action_ready(act);
  72. }
  73. static void zfcp_erp_action_dismiss_unit(struct zfcp_unit *unit)
  74. {
  75. if (atomic_read(&unit->status) & ZFCP_STATUS_COMMON_ERP_INUSE)
  76. zfcp_erp_action_dismiss(&unit->erp_action);
  77. }
  78. static void zfcp_erp_action_dismiss_port(struct zfcp_port *port)
  79. {
  80. struct zfcp_unit *unit;
  81. if (atomic_read(&port->status) & ZFCP_STATUS_COMMON_ERP_INUSE)
  82. zfcp_erp_action_dismiss(&port->erp_action);
  83. else
  84. list_for_each_entry(unit, &port->unit_list_head, list)
  85. zfcp_erp_action_dismiss_unit(unit);
  86. }
  87. static void zfcp_erp_action_dismiss_adapter(struct zfcp_adapter *adapter)
  88. {
  89. struct zfcp_port *port;
  90. if (atomic_read(&adapter->status) & ZFCP_STATUS_COMMON_ERP_INUSE)
  91. zfcp_erp_action_dismiss(&adapter->erp_action);
  92. else
  93. list_for_each_entry(port, &adapter->port_list_head, list)
  94. zfcp_erp_action_dismiss_port(port);
  95. }
  96. static int zfcp_erp_required_act(int want, struct zfcp_adapter *adapter,
  97. struct zfcp_port *port,
  98. struct zfcp_unit *unit)
  99. {
  100. int need = want;
  101. int u_status, p_status, a_status;
  102. switch (want) {
  103. case ZFCP_ERP_ACTION_REOPEN_UNIT:
  104. u_status = atomic_read(&unit->status);
  105. if (u_status & ZFCP_STATUS_COMMON_ERP_INUSE)
  106. return 0;
  107. p_status = atomic_read(&port->status);
  108. if (!(p_status & ZFCP_STATUS_COMMON_RUNNING) ||
  109. p_status & ZFCP_STATUS_COMMON_ERP_FAILED)
  110. return 0;
  111. if (!(p_status & ZFCP_STATUS_COMMON_UNBLOCKED))
  112. need = ZFCP_ERP_ACTION_REOPEN_PORT;
  113. /* fall through */
  114. case ZFCP_ERP_ACTION_REOPEN_PORT:
  115. case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
  116. p_status = atomic_read(&port->status);
  117. if (p_status & ZFCP_STATUS_COMMON_ERP_INUSE)
  118. return 0;
  119. a_status = atomic_read(&adapter->status);
  120. if (!(a_status & ZFCP_STATUS_COMMON_RUNNING) ||
  121. a_status & ZFCP_STATUS_COMMON_ERP_FAILED)
  122. return 0;
  123. if (!(a_status & ZFCP_STATUS_COMMON_UNBLOCKED))
  124. need = ZFCP_ERP_ACTION_REOPEN_ADAPTER;
  125. /* fall through */
  126. case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
  127. a_status = atomic_read(&adapter->status);
  128. if (a_status & ZFCP_STATUS_COMMON_ERP_INUSE)
  129. return 0;
  130. }
  131. return need;
  132. }
  133. static struct zfcp_erp_action *zfcp_erp_setup_act(int need,
  134. struct zfcp_adapter *adapter,
  135. struct zfcp_port *port,
  136. struct zfcp_unit *unit)
  137. {
  138. struct zfcp_erp_action *erp_action;
  139. u32 status = 0;
  140. switch (need) {
  141. case ZFCP_ERP_ACTION_REOPEN_UNIT:
  142. zfcp_unit_get(unit);
  143. atomic_set_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &unit->status);
  144. erp_action = &unit->erp_action;
  145. if (!(atomic_read(&unit->status) & ZFCP_STATUS_COMMON_RUNNING))
  146. status = ZFCP_STATUS_ERP_CLOSE_ONLY;
  147. break;
  148. case ZFCP_ERP_ACTION_REOPEN_PORT:
  149. case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
  150. zfcp_port_get(port);
  151. zfcp_erp_action_dismiss_port(port);
  152. atomic_set_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &port->status);
  153. erp_action = &port->erp_action;
  154. if (!(atomic_read(&port->status) & ZFCP_STATUS_COMMON_RUNNING))
  155. status = ZFCP_STATUS_ERP_CLOSE_ONLY;
  156. break;
  157. case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
  158. zfcp_adapter_get(adapter);
  159. zfcp_erp_action_dismiss_adapter(adapter);
  160. atomic_set_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &adapter->status);
  161. erp_action = &adapter->erp_action;
  162. if (!(atomic_read(&adapter->status) &
  163. ZFCP_STATUS_COMMON_RUNNING))
  164. status = ZFCP_STATUS_ERP_CLOSE_ONLY;
  165. break;
  166. default:
  167. return NULL;
  168. }
  169. memset(erp_action, 0, sizeof(struct zfcp_erp_action));
  170. erp_action->adapter = adapter;
  171. erp_action->port = port;
  172. erp_action->unit = unit;
  173. erp_action->action = need;
  174. erp_action->status = status;
  175. return erp_action;
  176. }
  177. static int zfcp_erp_action_enqueue(int want, struct zfcp_adapter *adapter,
  178. struct zfcp_port *port,
  179. struct zfcp_unit *unit, u8 id, void *ref)
  180. {
  181. int retval = 1, need;
  182. struct zfcp_erp_action *act = NULL;
  183. if (!(atomic_read(&adapter->status) &
  184. ZFCP_STATUS_ADAPTER_ERP_THREAD_UP))
  185. return -EIO;
  186. need = zfcp_erp_required_act(want, adapter, port, unit);
  187. if (!need)
  188. goto out;
  189. atomic_set_mask(ZFCP_STATUS_ADAPTER_ERP_PENDING, &adapter->status);
  190. act = zfcp_erp_setup_act(need, adapter, port, unit);
  191. if (!act)
  192. goto out;
  193. ++adapter->erp_total_count;
  194. list_add_tail(&act->list, &adapter->erp_ready_head);
  195. up(&adapter->erp_ready_sem);
  196. zfcp_rec_dbf_event_thread(1, adapter);
  197. retval = 0;
  198. out:
  199. zfcp_rec_dbf_event_trigger(id, ref, want, need, act,
  200. adapter, port, unit);
  201. return retval;
  202. }
  203. static int _zfcp_erp_adapter_reopen(struct zfcp_adapter *adapter,
  204. int clear_mask, u8 id, void *ref)
  205. {
  206. zfcp_erp_adapter_block(adapter, clear_mask);
  207. /* ensure propagation of failed status to new devices */
  208. if (atomic_read(&adapter->status) & ZFCP_STATUS_COMMON_ERP_FAILED) {
  209. zfcp_erp_adapter_failed(adapter, 13, NULL);
  210. return -EIO;
  211. }
  212. return zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_ADAPTER,
  213. adapter, NULL, NULL, id, ref);
  214. }
  215. /**
  216. * zfcp_erp_adapter_reopen - Reopen adapter.
  217. * @adapter: Adapter to reopen.
  218. * @clear: Status flags to clear.
  219. * @id: Id for debug trace event.
  220. * @ref: Reference for debug trace event.
  221. */
  222. void zfcp_erp_adapter_reopen(struct zfcp_adapter *adapter, int clear,
  223. u8 id, void *ref)
  224. {
  225. unsigned long flags;
  226. read_lock_irqsave(&zfcp_data.config_lock, flags);
  227. write_lock(&adapter->erp_lock);
  228. _zfcp_erp_adapter_reopen(adapter, clear, id, ref);
  229. write_unlock(&adapter->erp_lock);
  230. read_unlock_irqrestore(&zfcp_data.config_lock, flags);
  231. }
  232. /**
  233. * zfcp_erp_adapter_shutdown - Shutdown adapter.
  234. * @adapter: Adapter to shut down.
  235. * @clear: Status flags to clear.
  236. * @id: Id for debug trace event.
  237. * @ref: Reference for debug trace event.
  238. */
  239. void zfcp_erp_adapter_shutdown(struct zfcp_adapter *adapter, int clear,
  240. u8 id, void *ref)
  241. {
  242. int flags = ZFCP_STATUS_COMMON_RUNNING | ZFCP_STATUS_COMMON_ERP_FAILED;
  243. zfcp_erp_adapter_reopen(adapter, clear | flags, id, ref);
  244. }
  245. /**
  246. * zfcp_erp_port_shutdown - Shutdown port
  247. * @port: Port to shut down.
  248. * @clear: Status flags to clear.
  249. * @id: Id for debug trace event.
  250. * @ref: Reference for debug trace event.
  251. */
  252. void zfcp_erp_port_shutdown(struct zfcp_port *port, int clear, u8 id, void *ref)
  253. {
  254. int flags = ZFCP_STATUS_COMMON_RUNNING | ZFCP_STATUS_COMMON_ERP_FAILED;
  255. zfcp_erp_port_reopen(port, clear | flags, id, ref);
  256. }
  257. /**
  258. * zfcp_erp_unit_shutdown - Shutdown unit
  259. * @unit: Unit to shut down.
  260. * @clear: Status flags to clear.
  261. * @id: Id for debug trace event.
  262. * @ref: Reference for debug trace event.
  263. */
  264. void zfcp_erp_unit_shutdown(struct zfcp_unit *unit, int clear, u8 id, void *ref)
  265. {
  266. int flags = ZFCP_STATUS_COMMON_RUNNING | ZFCP_STATUS_COMMON_ERP_FAILED;
  267. zfcp_erp_unit_reopen(unit, clear | flags, id, ref);
  268. }
  269. static void zfcp_erp_port_block(struct zfcp_port *port, int clear)
  270. {
  271. zfcp_erp_modify_port_status(port, 17, NULL,
  272. ZFCP_STATUS_COMMON_UNBLOCKED | clear,
  273. ZFCP_CLEAR);
  274. }
  275. static void _zfcp_erp_port_forced_reopen(struct zfcp_port *port,
  276. int clear, u8 id, void *ref)
  277. {
  278. zfcp_erp_port_block(port, clear);
  279. if (atomic_read(&port->status) & ZFCP_STATUS_COMMON_ERP_FAILED)
  280. return;
  281. zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_PORT_FORCED,
  282. port->adapter, port, NULL, id, ref);
  283. }
  284. /**
  285. * zfcp_erp_port_forced_reopen - Forced close of port and open again
  286. * @port: Port to force close and to reopen.
  287. * @id: Id for debug trace event.
  288. * @ref: Reference for debug trace event.
  289. */
  290. void zfcp_erp_port_forced_reopen(struct zfcp_port *port, int clear, u8 id,
  291. void *ref)
  292. {
  293. unsigned long flags;
  294. struct zfcp_adapter *adapter = port->adapter;
  295. read_lock_irqsave(&zfcp_data.config_lock, flags);
  296. write_lock(&adapter->erp_lock);
  297. _zfcp_erp_port_forced_reopen(port, clear, id, ref);
  298. write_unlock(&adapter->erp_lock);
  299. read_unlock_irqrestore(&zfcp_data.config_lock, flags);
  300. }
  301. static int _zfcp_erp_port_reopen(struct zfcp_port *port, int clear, u8 id,
  302. void *ref)
  303. {
  304. zfcp_erp_port_block(port, clear);
  305. if (atomic_read(&port->status) & ZFCP_STATUS_COMMON_ERP_FAILED) {
  306. /* ensure propagation of failed status to new devices */
  307. zfcp_erp_port_failed(port, 14, NULL);
  308. return -EIO;
  309. }
  310. return zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_PORT,
  311. port->adapter, port, NULL, id, ref);
  312. }
  313. /**
  314. * zfcp_erp_port_reopen - trigger remote port recovery
  315. * @port: port to recover
  316. * @clear_mask: flags in port status to be cleared
  317. *
  318. * Returns 0 if recovery has been triggered, < 0 if not.
  319. */
  320. int zfcp_erp_port_reopen(struct zfcp_port *port, int clear, u8 id, void *ref)
  321. {
  322. unsigned long flags;
  323. int retval;
  324. struct zfcp_adapter *adapter = port->adapter;
  325. read_lock_irqsave(&zfcp_data.config_lock, flags);
  326. write_lock(&adapter->erp_lock);
  327. retval = _zfcp_erp_port_reopen(port, clear, id, ref);
  328. write_unlock(&adapter->erp_lock);
  329. read_unlock_irqrestore(&zfcp_data.config_lock, flags);
  330. return retval;
  331. }
  332. static void zfcp_erp_unit_block(struct zfcp_unit *unit, int clear_mask)
  333. {
  334. zfcp_erp_modify_unit_status(unit, 19, NULL,
  335. ZFCP_STATUS_COMMON_UNBLOCKED | clear_mask,
  336. ZFCP_CLEAR);
  337. }
  338. static void _zfcp_erp_unit_reopen(struct zfcp_unit *unit, int clear, u8 id,
  339. void *ref)
  340. {
  341. struct zfcp_adapter *adapter = unit->port->adapter;
  342. zfcp_erp_unit_block(unit, clear);
  343. if (atomic_read(&unit->status) & ZFCP_STATUS_COMMON_ERP_FAILED)
  344. return;
  345. zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_UNIT,
  346. adapter, unit->port, unit, id, ref);
  347. }
  348. /**
  349. * zfcp_erp_unit_reopen - initiate reopen of a unit
  350. * @unit: unit to be reopened
  351. * @clear_mask: specifies flags in unit status to be cleared
  352. * Return: 0 on success, < 0 on error
  353. */
  354. void zfcp_erp_unit_reopen(struct zfcp_unit *unit, int clear, u8 id, void *ref)
  355. {
  356. unsigned long flags;
  357. struct zfcp_port *port = unit->port;
  358. struct zfcp_adapter *adapter = port->adapter;
  359. read_lock_irqsave(&zfcp_data.config_lock, flags);
  360. write_lock(&adapter->erp_lock);
  361. _zfcp_erp_unit_reopen(unit, clear, id, ref);
  362. write_unlock(&adapter->erp_lock);
  363. read_unlock_irqrestore(&zfcp_data.config_lock, flags);
  364. }
  365. static int status_change_set(unsigned long mask, atomic_t *status)
  366. {
  367. return (atomic_read(status) ^ mask) & mask;
  368. }
  369. static int status_change_clear(unsigned long mask, atomic_t *status)
  370. {
  371. return atomic_read(status) & mask;
  372. }
  373. static void zfcp_erp_adapter_unblock(struct zfcp_adapter *adapter)
  374. {
  375. if (status_change_set(ZFCP_STATUS_COMMON_UNBLOCKED, &adapter->status))
  376. zfcp_rec_dbf_event_adapter(16, NULL, adapter);
  377. atomic_set_mask(ZFCP_STATUS_COMMON_UNBLOCKED, &adapter->status);
  378. }
  379. static void zfcp_erp_port_unblock(struct zfcp_port *port)
  380. {
  381. if (status_change_set(ZFCP_STATUS_COMMON_UNBLOCKED, &port->status))
  382. zfcp_rec_dbf_event_port(18, NULL, port);
  383. atomic_set_mask(ZFCP_STATUS_COMMON_UNBLOCKED, &port->status);
  384. }
  385. static void zfcp_erp_unit_unblock(struct zfcp_unit *unit)
  386. {
  387. if (status_change_set(ZFCP_STATUS_COMMON_UNBLOCKED, &unit->status))
  388. zfcp_rec_dbf_event_unit(20, NULL, unit);
  389. atomic_set_mask(ZFCP_STATUS_COMMON_UNBLOCKED, &unit->status);
  390. }
  391. static void zfcp_erp_action_to_running(struct zfcp_erp_action *erp_action)
  392. {
  393. list_move(&erp_action->list, &erp_action->adapter->erp_running_head);
  394. zfcp_rec_dbf_event_action(145, erp_action);
  395. }
  396. static void zfcp_erp_strategy_check_fsfreq(struct zfcp_erp_action *act)
  397. {
  398. struct zfcp_adapter *adapter = act->adapter;
  399. if (!act->fsf_req)
  400. return;
  401. spin_lock(&adapter->req_list_lock);
  402. if (zfcp_reqlist_find_safe(adapter, act->fsf_req) &&
  403. act->fsf_req->erp_action == act) {
  404. if (act->status & (ZFCP_STATUS_ERP_DISMISSED |
  405. ZFCP_STATUS_ERP_TIMEDOUT)) {
  406. act->fsf_req->status |= ZFCP_STATUS_FSFREQ_DISMISSED;
  407. zfcp_rec_dbf_event_action(142, act);
  408. }
  409. if (act->status & ZFCP_STATUS_ERP_TIMEDOUT)
  410. zfcp_rec_dbf_event_action(143, act);
  411. if (act->fsf_req->status & (ZFCP_STATUS_FSFREQ_COMPLETED |
  412. ZFCP_STATUS_FSFREQ_DISMISSED))
  413. act->fsf_req = NULL;
  414. } else
  415. act->fsf_req = NULL;
  416. spin_unlock(&adapter->req_list_lock);
  417. }
  418. /**
  419. * zfcp_erp_notify - Trigger ERP action.
  420. * @erp_action: ERP action to continue.
  421. * @set_mask: ERP action status flags to set.
  422. */
  423. void zfcp_erp_notify(struct zfcp_erp_action *erp_action, unsigned long set_mask)
  424. {
  425. struct zfcp_adapter *adapter = erp_action->adapter;
  426. unsigned long flags;
  427. write_lock_irqsave(&adapter->erp_lock, flags);
  428. if (zfcp_erp_action_exists(erp_action) == ZFCP_ERP_ACTION_RUNNING) {
  429. erp_action->status |= set_mask;
  430. zfcp_erp_action_ready(erp_action);
  431. }
  432. write_unlock_irqrestore(&adapter->erp_lock, flags);
  433. }
  434. /**
  435. * zfcp_erp_timeout_handler - Trigger ERP action from timed out ERP request
  436. * @data: ERP action (from timer data)
  437. */
  438. void zfcp_erp_timeout_handler(unsigned long data)
  439. {
  440. struct zfcp_erp_action *act = (struct zfcp_erp_action *) data;
  441. zfcp_erp_notify(act, ZFCP_STATUS_ERP_TIMEDOUT);
  442. }
  443. static void zfcp_erp_memwait_handler(unsigned long data)
  444. {
  445. zfcp_erp_notify((struct zfcp_erp_action *)data, 0);
  446. }
  447. static void zfcp_erp_strategy_memwait(struct zfcp_erp_action *erp_action)
  448. {
  449. init_timer(&erp_action->timer);
  450. erp_action->timer.function = zfcp_erp_memwait_handler;
  451. erp_action->timer.data = (unsigned long) erp_action;
  452. erp_action->timer.expires = jiffies + HZ;
  453. add_timer(&erp_action->timer);
  454. }
  455. static void _zfcp_erp_port_reopen_all(struct zfcp_adapter *adapter,
  456. int clear, u8 id, void *ref)
  457. {
  458. struct zfcp_port *port;
  459. list_for_each_entry(port, &adapter->port_list_head, list)
  460. _zfcp_erp_port_reopen(port, clear, id, ref);
  461. }
  462. static void _zfcp_erp_unit_reopen_all(struct zfcp_port *port, int clear, u8 id,
  463. void *ref)
  464. {
  465. struct zfcp_unit *unit;
  466. list_for_each_entry(unit, &port->unit_list_head, list)
  467. _zfcp_erp_unit_reopen(unit, clear, id, ref);
  468. }
  469. static void zfcp_erp_strategy_followup_actions(struct zfcp_erp_action *act)
  470. {
  471. struct zfcp_adapter *adapter = act->adapter;
  472. struct zfcp_port *port = act->port;
  473. struct zfcp_unit *unit = act->unit;
  474. u32 status = act->status;
  475. /* initiate follow-up actions depending on success of finished action */
  476. switch (act->action) {
  477. case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
  478. if (status == ZFCP_ERP_SUCCEEDED)
  479. _zfcp_erp_port_reopen_all(adapter, 0, 70, NULL);
  480. else
  481. _zfcp_erp_adapter_reopen(adapter, 0, 71, NULL);
  482. break;
  483. case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
  484. if (status == ZFCP_ERP_SUCCEEDED)
  485. _zfcp_erp_port_reopen(port, 0, 72, NULL);
  486. else
  487. _zfcp_erp_adapter_reopen(adapter, 0, 73, NULL);
  488. break;
  489. case ZFCP_ERP_ACTION_REOPEN_PORT:
  490. if (status == ZFCP_ERP_SUCCEEDED)
  491. _zfcp_erp_unit_reopen_all(port, 0, 74, NULL);
  492. else
  493. _zfcp_erp_port_forced_reopen(port, 0, 75, NULL);
  494. break;
  495. case ZFCP_ERP_ACTION_REOPEN_UNIT:
  496. if (status != ZFCP_ERP_SUCCEEDED)
  497. _zfcp_erp_port_reopen(unit->port, 0, 76, NULL);
  498. break;
  499. }
  500. }
  501. static void zfcp_erp_wakeup(struct zfcp_adapter *adapter)
  502. {
  503. unsigned long flags;
  504. read_lock_irqsave(&zfcp_data.config_lock, flags);
  505. read_lock(&adapter->erp_lock);
  506. if (list_empty(&adapter->erp_ready_head) &&
  507. list_empty(&adapter->erp_running_head)) {
  508. atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_PENDING,
  509. &adapter->status);
  510. wake_up(&adapter->erp_done_wqh);
  511. }
  512. read_unlock(&adapter->erp_lock);
  513. read_unlock_irqrestore(&zfcp_data.config_lock, flags);
  514. }
  515. static int zfcp_erp_adapter_strategy_open_qdio(struct zfcp_erp_action *act)
  516. {
  517. if (zfcp_qdio_open(act->adapter))
  518. return ZFCP_ERP_FAILED;
  519. init_waitqueue_head(&act->adapter->request_wq);
  520. atomic_set_mask(ZFCP_STATUS_ADAPTER_QDIOUP, &act->adapter->status);
  521. return ZFCP_ERP_SUCCEEDED;
  522. }
  523. static void zfcp_erp_enqueue_ptp_port(struct zfcp_adapter *adapter)
  524. {
  525. struct zfcp_port *port;
  526. port = zfcp_port_enqueue(adapter, adapter->peer_wwpn, 0,
  527. adapter->peer_d_id);
  528. if (IS_ERR(port)) /* error or port already attached */
  529. return;
  530. _zfcp_erp_port_reopen(port, 0, 150, NULL);
  531. }
  532. static int zfcp_erp_adapter_strat_fsf_xconf(struct zfcp_erp_action *erp_action)
  533. {
  534. int retries;
  535. int sleep = 1;
  536. struct zfcp_adapter *adapter = erp_action->adapter;
  537. atomic_clear_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK, &adapter->status);
  538. for (retries = 7; retries; retries--) {
  539. atomic_clear_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
  540. &adapter->status);
  541. write_lock_irq(&adapter->erp_lock);
  542. zfcp_erp_action_to_running(erp_action);
  543. write_unlock_irq(&adapter->erp_lock);
  544. if (zfcp_fsf_exchange_config_data(erp_action)) {
  545. atomic_clear_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
  546. &adapter->status);
  547. return ZFCP_ERP_FAILED;
  548. }
  549. zfcp_rec_dbf_event_thread_lock(6, adapter);
  550. down(&adapter->erp_ready_sem);
  551. zfcp_rec_dbf_event_thread_lock(7, adapter);
  552. if (erp_action->status & ZFCP_STATUS_ERP_TIMEDOUT)
  553. break;
  554. if (!(atomic_read(&adapter->status) &
  555. ZFCP_STATUS_ADAPTER_HOST_CON_INIT))
  556. break;
  557. ssleep(sleep);
  558. sleep *= 2;
  559. }
  560. atomic_clear_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
  561. &adapter->status);
  562. if (!(atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_XCONFIG_OK))
  563. return ZFCP_ERP_FAILED;
  564. if (fc_host_port_type(adapter->scsi_host) == FC_PORTTYPE_PTP)
  565. zfcp_erp_enqueue_ptp_port(adapter);
  566. return ZFCP_ERP_SUCCEEDED;
  567. }
  568. static int zfcp_erp_adapter_strategy_open_fsf_xport(struct zfcp_erp_action *act)
  569. {
  570. int ret;
  571. struct zfcp_adapter *adapter = act->adapter;
  572. write_lock_irq(&adapter->erp_lock);
  573. zfcp_erp_action_to_running(act);
  574. write_unlock_irq(&adapter->erp_lock);
  575. ret = zfcp_fsf_exchange_port_data(act);
  576. if (ret == -EOPNOTSUPP)
  577. return ZFCP_ERP_SUCCEEDED;
  578. if (ret)
  579. return ZFCP_ERP_FAILED;
  580. zfcp_rec_dbf_event_thread_lock(8, adapter);
  581. down(&adapter->erp_ready_sem);
  582. zfcp_rec_dbf_event_thread_lock(9, adapter);
  583. if (act->status & ZFCP_STATUS_ERP_TIMEDOUT)
  584. return ZFCP_ERP_FAILED;
  585. return ZFCP_ERP_SUCCEEDED;
  586. }
  587. static int zfcp_erp_adapter_strategy_open_fsf(struct zfcp_erp_action *act)
  588. {
  589. if (zfcp_erp_adapter_strat_fsf_xconf(act) == ZFCP_ERP_FAILED)
  590. return ZFCP_ERP_FAILED;
  591. if (zfcp_erp_adapter_strategy_open_fsf_xport(act) == ZFCP_ERP_FAILED)
  592. return ZFCP_ERP_FAILED;
  593. atomic_set(&act->adapter->stat_miss, 16);
  594. if (zfcp_status_read_refill(act->adapter))
  595. return ZFCP_ERP_FAILED;
  596. return ZFCP_ERP_SUCCEEDED;
  597. }
  598. static int zfcp_erp_adapter_strategy_generic(struct zfcp_erp_action *act,
  599. int close)
  600. {
  601. int retval = ZFCP_ERP_SUCCEEDED;
  602. struct zfcp_adapter *adapter = act->adapter;
  603. if (close)
  604. goto close_only;
  605. retval = zfcp_erp_adapter_strategy_open_qdio(act);
  606. if (retval != ZFCP_ERP_SUCCEEDED)
  607. goto failed_qdio;
  608. retval = zfcp_erp_adapter_strategy_open_fsf(act);
  609. if (retval != ZFCP_ERP_SUCCEEDED)
  610. goto failed_openfcp;
  611. atomic_set_mask(ZFCP_STATUS_COMMON_OPEN, &act->adapter->status);
  612. schedule_work(&act->adapter->scan_work);
  613. return ZFCP_ERP_SUCCEEDED;
  614. close_only:
  615. atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN,
  616. &act->adapter->status);
  617. failed_openfcp:
  618. /* close queues to ensure that buffers are not accessed by adapter */
  619. zfcp_qdio_close(adapter);
  620. zfcp_fsf_req_dismiss_all(adapter);
  621. adapter->fsf_req_seq_no = 0;
  622. /* all ports and units are closed */
  623. zfcp_erp_modify_adapter_status(adapter, 24, NULL,
  624. ZFCP_STATUS_COMMON_OPEN, ZFCP_CLEAR);
  625. failed_qdio:
  626. atomic_clear_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK |
  627. ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED,
  628. &act->adapter->status);
  629. return retval;
  630. }
  631. static int zfcp_erp_adapter_strategy(struct zfcp_erp_action *act)
  632. {
  633. int retval;
  634. zfcp_erp_adapter_strategy_generic(act, 1); /* close */
  635. if (act->status & ZFCP_STATUS_ERP_CLOSE_ONLY)
  636. return ZFCP_ERP_EXIT;
  637. retval = zfcp_erp_adapter_strategy_generic(act, 0); /* open */
  638. if (retval == ZFCP_ERP_FAILED)
  639. ssleep(8);
  640. return retval;
  641. }
  642. static int zfcp_erp_port_forced_strategy_close(struct zfcp_erp_action *act)
  643. {
  644. int retval;
  645. retval = zfcp_fsf_close_physical_port(act);
  646. if (retval == -ENOMEM)
  647. return ZFCP_ERP_NOMEM;
  648. act->step = ZFCP_ERP_STEP_PHYS_PORT_CLOSING;
  649. if (retval)
  650. return ZFCP_ERP_FAILED;
  651. return ZFCP_ERP_CONTINUES;
  652. }
  653. static void zfcp_erp_port_strategy_clearstati(struct zfcp_port *port)
  654. {
  655. atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
  656. ZFCP_STATUS_PORT_PHYS_CLOSING |
  657. ZFCP_STATUS_PORT_INVALID_WWPN,
  658. &port->status);
  659. }
  660. static int zfcp_erp_port_forced_strategy(struct zfcp_erp_action *erp_action)
  661. {
  662. struct zfcp_port *port = erp_action->port;
  663. int status = atomic_read(&port->status);
  664. switch (erp_action->step) {
  665. case ZFCP_ERP_STEP_UNINITIALIZED:
  666. zfcp_erp_port_strategy_clearstati(port);
  667. if ((status & ZFCP_STATUS_PORT_PHYS_OPEN) &&
  668. (status & ZFCP_STATUS_COMMON_OPEN))
  669. return zfcp_erp_port_forced_strategy_close(erp_action);
  670. else
  671. return ZFCP_ERP_FAILED;
  672. case ZFCP_ERP_STEP_PHYS_PORT_CLOSING:
  673. if (status & ZFCP_STATUS_PORT_PHYS_OPEN)
  674. return ZFCP_ERP_SUCCEEDED;
  675. }
  676. return ZFCP_ERP_FAILED;
  677. }
  678. static int zfcp_erp_port_strategy_close(struct zfcp_erp_action *erp_action)
  679. {
  680. int retval;
  681. retval = zfcp_fsf_close_port(erp_action);
  682. if (retval == -ENOMEM)
  683. return ZFCP_ERP_NOMEM;
  684. erp_action->step = ZFCP_ERP_STEP_PORT_CLOSING;
  685. if (retval)
  686. return ZFCP_ERP_FAILED;
  687. return ZFCP_ERP_CONTINUES;
  688. }
  689. static int zfcp_erp_port_strategy_open_port(struct zfcp_erp_action *erp_action)
  690. {
  691. int retval;
  692. retval = zfcp_fsf_open_port(erp_action);
  693. if (retval == -ENOMEM)
  694. return ZFCP_ERP_NOMEM;
  695. erp_action->step = ZFCP_ERP_STEP_PORT_OPENING;
  696. if (retval)
  697. return ZFCP_ERP_FAILED;
  698. return ZFCP_ERP_CONTINUES;
  699. }
  700. static int zfcp_erp_open_ptp_port(struct zfcp_erp_action *act)
  701. {
  702. struct zfcp_adapter *adapter = act->adapter;
  703. struct zfcp_port *port = act->port;
  704. if (port->wwpn != adapter->peer_wwpn) {
  705. zfcp_erp_port_failed(port, 25, NULL);
  706. return ZFCP_ERP_FAILED;
  707. }
  708. port->d_id = adapter->peer_d_id;
  709. atomic_set_mask(ZFCP_STATUS_PORT_DID_DID, &port->status);
  710. return zfcp_erp_port_strategy_open_port(act);
  711. }
  712. void zfcp_erp_port_strategy_open_lookup(struct work_struct *work)
  713. {
  714. int retval;
  715. struct zfcp_port *port = container_of(work, struct zfcp_port,
  716. gid_pn_work);
  717. retval = zfcp_fc_ns_gid_pn(&port->erp_action);
  718. if (retval == -ENOMEM)
  719. zfcp_erp_notify(&port->erp_action, ZFCP_ERP_NOMEM);
  720. port->erp_action.step = ZFCP_ERP_STEP_NAMESERVER_LOOKUP;
  721. if (retval)
  722. zfcp_erp_notify(&port->erp_action, ZFCP_ERP_FAILED);
  723. }
  724. static int zfcp_erp_port_strategy_open_common(struct zfcp_erp_action *act)
  725. {
  726. struct zfcp_adapter *adapter = act->adapter;
  727. struct zfcp_port *port = act->port;
  728. int p_status = atomic_read(&port->status);
  729. switch (act->step) {
  730. case ZFCP_ERP_STEP_UNINITIALIZED:
  731. case ZFCP_ERP_STEP_PHYS_PORT_CLOSING:
  732. case ZFCP_ERP_STEP_PORT_CLOSING:
  733. if (fc_host_port_type(adapter->scsi_host) == FC_PORTTYPE_PTP)
  734. return zfcp_erp_open_ptp_port(act);
  735. if (!(p_status & ZFCP_STATUS_PORT_DID_DID)) {
  736. queue_work(zfcp_data.work_queue, &port->gid_pn_work);
  737. return ZFCP_ERP_CONTINUES;
  738. }
  739. case ZFCP_ERP_STEP_NAMESERVER_LOOKUP:
  740. if (!(p_status & ZFCP_STATUS_PORT_DID_DID)) {
  741. if (p_status & (ZFCP_STATUS_PORT_INVALID_WWPN)) {
  742. zfcp_erp_port_failed(port, 26, NULL);
  743. return ZFCP_ERP_EXIT;
  744. }
  745. return ZFCP_ERP_FAILED;
  746. }
  747. return zfcp_erp_port_strategy_open_port(act);
  748. case ZFCP_ERP_STEP_PORT_OPENING:
  749. /* D_ID might have changed during open */
  750. if (p_status & ZFCP_STATUS_COMMON_OPEN) {
  751. if (p_status & ZFCP_STATUS_PORT_DID_DID)
  752. return ZFCP_ERP_SUCCEEDED;
  753. else {
  754. act->step = ZFCP_ERP_STEP_PORT_CLOSING;
  755. return ZFCP_ERP_CONTINUES;
  756. }
  757. /* fall through otherwise */
  758. }
  759. }
  760. return ZFCP_ERP_FAILED;
  761. }
  762. static int zfcp_erp_port_strategy(struct zfcp_erp_action *erp_action)
  763. {
  764. struct zfcp_port *port = erp_action->port;
  765. if (atomic_read(&port->status) & ZFCP_STATUS_COMMON_NOESC)
  766. goto close_init_done;
  767. switch (erp_action->step) {
  768. case ZFCP_ERP_STEP_UNINITIALIZED:
  769. zfcp_erp_port_strategy_clearstati(port);
  770. if (atomic_read(&port->status) & ZFCP_STATUS_COMMON_OPEN)
  771. return zfcp_erp_port_strategy_close(erp_action);
  772. break;
  773. case ZFCP_ERP_STEP_PORT_CLOSING:
  774. if (atomic_read(&port->status) & ZFCP_STATUS_COMMON_OPEN)
  775. return ZFCP_ERP_FAILED;
  776. break;
  777. }
  778. close_init_done:
  779. if (erp_action->status & ZFCP_STATUS_ERP_CLOSE_ONLY)
  780. return ZFCP_ERP_EXIT;
  781. return zfcp_erp_port_strategy_open_common(erp_action);
  782. }
  783. static void zfcp_erp_unit_strategy_clearstati(struct zfcp_unit *unit)
  784. {
  785. atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
  786. ZFCP_STATUS_UNIT_SHARED |
  787. ZFCP_STATUS_UNIT_READONLY,
  788. &unit->status);
  789. }
  790. static int zfcp_erp_unit_strategy_close(struct zfcp_erp_action *erp_action)
  791. {
  792. int retval = zfcp_fsf_close_unit(erp_action);
  793. if (retval == -ENOMEM)
  794. return ZFCP_ERP_NOMEM;
  795. erp_action->step = ZFCP_ERP_STEP_UNIT_CLOSING;
  796. if (retval)
  797. return ZFCP_ERP_FAILED;
  798. return ZFCP_ERP_CONTINUES;
  799. }
  800. static int zfcp_erp_unit_strategy_open(struct zfcp_erp_action *erp_action)
  801. {
  802. int retval = zfcp_fsf_open_unit(erp_action);
  803. if (retval == -ENOMEM)
  804. return ZFCP_ERP_NOMEM;
  805. erp_action->step = ZFCP_ERP_STEP_UNIT_OPENING;
  806. if (retval)
  807. return ZFCP_ERP_FAILED;
  808. return ZFCP_ERP_CONTINUES;
  809. }
  810. static int zfcp_erp_unit_strategy(struct zfcp_erp_action *erp_action)
  811. {
  812. struct zfcp_unit *unit = erp_action->unit;
  813. switch (erp_action->step) {
  814. case ZFCP_ERP_STEP_UNINITIALIZED:
  815. zfcp_erp_unit_strategy_clearstati(unit);
  816. if (atomic_read(&unit->status) & ZFCP_STATUS_COMMON_OPEN)
  817. return zfcp_erp_unit_strategy_close(erp_action);
  818. /* already closed, fall through */
  819. case ZFCP_ERP_STEP_UNIT_CLOSING:
  820. if (atomic_read(&unit->status) & ZFCP_STATUS_COMMON_OPEN)
  821. return ZFCP_ERP_FAILED;
  822. if (erp_action->status & ZFCP_STATUS_ERP_CLOSE_ONLY)
  823. return ZFCP_ERP_EXIT;
  824. return zfcp_erp_unit_strategy_open(erp_action);
  825. case ZFCP_ERP_STEP_UNIT_OPENING:
  826. if (atomic_read(&unit->status) & ZFCP_STATUS_COMMON_OPEN)
  827. return ZFCP_ERP_SUCCEEDED;
  828. }
  829. return ZFCP_ERP_FAILED;
  830. }
  831. static int zfcp_erp_strategy_check_unit(struct zfcp_unit *unit, int result)
  832. {
  833. switch (result) {
  834. case ZFCP_ERP_SUCCEEDED :
  835. atomic_set(&unit->erp_counter, 0);
  836. zfcp_erp_unit_unblock(unit);
  837. break;
  838. case ZFCP_ERP_FAILED :
  839. atomic_inc(&unit->erp_counter);
  840. if (atomic_read(&unit->erp_counter) > ZFCP_MAX_ERPS) {
  841. dev_err(&unit->port->adapter->ccw_device->dev,
  842. "ERP failed for unit 0x%016Lx on "
  843. "port 0x%016Lx\n",
  844. (unsigned long long)unit->fcp_lun,
  845. (unsigned long long)unit->port->wwpn);
  846. zfcp_erp_unit_failed(unit, 21, NULL);
  847. }
  848. break;
  849. }
  850. if (atomic_read(&unit->status) & ZFCP_STATUS_COMMON_ERP_FAILED) {
  851. zfcp_erp_unit_block(unit, 0);
  852. result = ZFCP_ERP_EXIT;
  853. }
  854. return result;
  855. }
  856. static int zfcp_erp_strategy_check_port(struct zfcp_port *port, int result)
  857. {
  858. switch (result) {
  859. case ZFCP_ERP_SUCCEEDED :
  860. atomic_set(&port->erp_counter, 0);
  861. zfcp_erp_port_unblock(port);
  862. break;
  863. case ZFCP_ERP_FAILED :
  864. if (atomic_read(&port->status) & ZFCP_STATUS_COMMON_NOESC) {
  865. zfcp_erp_port_block(port, 0);
  866. result = ZFCP_ERP_EXIT;
  867. }
  868. atomic_inc(&port->erp_counter);
  869. if (atomic_read(&port->erp_counter) > ZFCP_MAX_ERPS) {
  870. dev_err(&port->adapter->ccw_device->dev,
  871. "ERP failed for remote port 0x%016Lx\n",
  872. (unsigned long long)port->wwpn);
  873. zfcp_erp_port_failed(port, 22, NULL);
  874. }
  875. break;
  876. }
  877. if (atomic_read(&port->status) & ZFCP_STATUS_COMMON_ERP_FAILED) {
  878. zfcp_erp_port_block(port, 0);
  879. result = ZFCP_ERP_EXIT;
  880. }
  881. return result;
  882. }
  883. static int zfcp_erp_strategy_check_adapter(struct zfcp_adapter *adapter,
  884. int result)
  885. {
  886. switch (result) {
  887. case ZFCP_ERP_SUCCEEDED :
  888. atomic_set(&adapter->erp_counter, 0);
  889. zfcp_erp_adapter_unblock(adapter);
  890. break;
  891. case ZFCP_ERP_FAILED :
  892. atomic_inc(&adapter->erp_counter);
  893. if (atomic_read(&adapter->erp_counter) > ZFCP_MAX_ERPS) {
  894. dev_err(&adapter->ccw_device->dev,
  895. "ERP cannot recover an error "
  896. "on the FCP device\n");
  897. zfcp_erp_adapter_failed(adapter, 23, NULL);
  898. }
  899. break;
  900. }
  901. if (atomic_read(&adapter->status) & ZFCP_STATUS_COMMON_ERP_FAILED) {
  902. zfcp_erp_adapter_block(adapter, 0);
  903. result = ZFCP_ERP_EXIT;
  904. }
  905. return result;
  906. }
  907. static int zfcp_erp_strategy_check_target(struct zfcp_erp_action *erp_action,
  908. int result)
  909. {
  910. struct zfcp_adapter *adapter = erp_action->adapter;
  911. struct zfcp_port *port = erp_action->port;
  912. struct zfcp_unit *unit = erp_action->unit;
  913. switch (erp_action->action) {
  914. case ZFCP_ERP_ACTION_REOPEN_UNIT:
  915. result = zfcp_erp_strategy_check_unit(unit, result);
  916. break;
  917. case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
  918. case ZFCP_ERP_ACTION_REOPEN_PORT:
  919. result = zfcp_erp_strategy_check_port(port, result);
  920. break;
  921. case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
  922. result = zfcp_erp_strategy_check_adapter(adapter, result);
  923. break;
  924. }
  925. return result;
  926. }
  927. static int zfcp_erp_strat_change_det(atomic_t *target_status, u32 erp_status)
  928. {
  929. int status = atomic_read(target_status);
  930. if ((status & ZFCP_STATUS_COMMON_RUNNING) &&
  931. (erp_status & ZFCP_STATUS_ERP_CLOSE_ONLY))
  932. return 1; /* take it online */
  933. if (!(status & ZFCP_STATUS_COMMON_RUNNING) &&
  934. !(erp_status & ZFCP_STATUS_ERP_CLOSE_ONLY))
  935. return 1; /* take it offline */
  936. return 0;
  937. }
  938. static int zfcp_erp_strategy_statechange(struct zfcp_erp_action *act, int ret)
  939. {
  940. int action = act->action;
  941. struct zfcp_adapter *adapter = act->adapter;
  942. struct zfcp_port *port = act->port;
  943. struct zfcp_unit *unit = act->unit;
  944. u32 erp_status = act->status;
  945. switch (action) {
  946. case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
  947. if (zfcp_erp_strat_change_det(&adapter->status, erp_status)) {
  948. _zfcp_erp_adapter_reopen(adapter,
  949. ZFCP_STATUS_COMMON_ERP_FAILED,
  950. 67, NULL);
  951. return ZFCP_ERP_EXIT;
  952. }
  953. break;
  954. case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
  955. case ZFCP_ERP_ACTION_REOPEN_PORT:
  956. if (zfcp_erp_strat_change_det(&port->status, erp_status)) {
  957. _zfcp_erp_port_reopen(port,
  958. ZFCP_STATUS_COMMON_ERP_FAILED,
  959. 68, NULL);
  960. return ZFCP_ERP_EXIT;
  961. }
  962. break;
  963. case ZFCP_ERP_ACTION_REOPEN_UNIT:
  964. if (zfcp_erp_strat_change_det(&unit->status, erp_status)) {
  965. _zfcp_erp_unit_reopen(unit,
  966. ZFCP_STATUS_COMMON_ERP_FAILED,
  967. 69, NULL);
  968. return ZFCP_ERP_EXIT;
  969. }
  970. break;
  971. }
  972. return ret;
  973. }
  974. static void zfcp_erp_action_dequeue(struct zfcp_erp_action *erp_action)
  975. {
  976. struct zfcp_adapter *adapter = erp_action->adapter;
  977. adapter->erp_total_count--;
  978. if (erp_action->status & ZFCP_STATUS_ERP_LOWMEM) {
  979. adapter->erp_low_mem_count--;
  980. erp_action->status &= ~ZFCP_STATUS_ERP_LOWMEM;
  981. }
  982. list_del(&erp_action->list);
  983. zfcp_rec_dbf_event_action(144, erp_action);
  984. switch (erp_action->action) {
  985. case ZFCP_ERP_ACTION_REOPEN_UNIT:
  986. atomic_clear_mask(ZFCP_STATUS_COMMON_ERP_INUSE,
  987. &erp_action->unit->status);
  988. break;
  989. case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
  990. case ZFCP_ERP_ACTION_REOPEN_PORT:
  991. atomic_clear_mask(ZFCP_STATUS_COMMON_ERP_INUSE,
  992. &erp_action->port->status);
  993. break;
  994. case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
  995. atomic_clear_mask(ZFCP_STATUS_COMMON_ERP_INUSE,
  996. &erp_action->adapter->status);
  997. break;
  998. }
  999. }
  1000. struct zfcp_erp_add_work {
  1001. struct zfcp_unit *unit;
  1002. struct work_struct work;
  1003. };
  1004. static void zfcp_erp_scsi_scan(struct work_struct *work)
  1005. {
  1006. struct zfcp_erp_add_work *p =
  1007. container_of(work, struct zfcp_erp_add_work, work);
  1008. struct zfcp_unit *unit = p->unit;
  1009. struct fc_rport *rport = unit->port->rport;
  1010. scsi_scan_target(&rport->dev, 0, rport->scsi_target_id,
  1011. scsilun_to_int((struct scsi_lun *)&unit->fcp_lun), 0);
  1012. atomic_clear_mask(ZFCP_STATUS_UNIT_SCSI_WORK_PENDING, &unit->status);
  1013. zfcp_unit_put(unit);
  1014. kfree(p);
  1015. }
  1016. static void zfcp_erp_schedule_work(struct zfcp_unit *unit)
  1017. {
  1018. struct zfcp_erp_add_work *p;
  1019. p = kzalloc(sizeof(*p), GFP_KERNEL);
  1020. if (!p) {
  1021. dev_err(&unit->port->adapter->ccw_device->dev,
  1022. "Registering unit 0x%016Lx on port 0x%016Lx failed\n",
  1023. (unsigned long long)unit->fcp_lun,
  1024. (unsigned long long)unit->port->wwpn);
  1025. return;
  1026. }
  1027. zfcp_unit_get(unit);
  1028. atomic_set_mask(ZFCP_STATUS_UNIT_SCSI_WORK_PENDING, &unit->status);
  1029. INIT_WORK(&p->work, zfcp_erp_scsi_scan);
  1030. p->unit = unit;
  1031. queue_work(zfcp_data.work_queue, &p->work);
  1032. }
  1033. static void zfcp_erp_rport_register(struct zfcp_port *port)
  1034. {
  1035. struct fc_rport_identifiers ids;
  1036. ids.node_name = port->wwnn;
  1037. ids.port_name = port->wwpn;
  1038. ids.port_id = port->d_id;
  1039. ids.roles = FC_RPORT_ROLE_FCP_TARGET;
  1040. port->rport = fc_remote_port_add(port->adapter->scsi_host, 0, &ids);
  1041. if (!port->rport) {
  1042. dev_err(&port->adapter->ccw_device->dev,
  1043. "Registering port 0x%016Lx failed\n",
  1044. (unsigned long long)port->wwpn);
  1045. return;
  1046. }
  1047. scsi_target_unblock(&port->rport->dev);
  1048. port->rport->maxframe_size = port->maxframe_size;
  1049. port->rport->supported_classes = port->supported_classes;
  1050. }
  1051. static void zfcp_erp_rports_del(struct zfcp_adapter *adapter)
  1052. {
  1053. struct zfcp_port *port;
  1054. list_for_each_entry(port, &adapter->port_list_head, list) {
  1055. if (!port->rport)
  1056. continue;
  1057. fc_remote_port_delete(port->rport);
  1058. port->rport = NULL;
  1059. }
  1060. }
  1061. static void zfcp_erp_action_cleanup(struct zfcp_erp_action *act, int result)
  1062. {
  1063. struct zfcp_adapter *adapter = act->adapter;
  1064. struct zfcp_port *port = act->port;
  1065. struct zfcp_unit *unit = act->unit;
  1066. switch (act->action) {
  1067. case ZFCP_ERP_ACTION_REOPEN_UNIT:
  1068. if ((result == ZFCP_ERP_SUCCEEDED) &&
  1069. !unit->device && port->rport) {
  1070. atomic_set_mask(ZFCP_STATUS_UNIT_REGISTERED,
  1071. &unit->status);
  1072. if (!(atomic_read(&unit->status) &
  1073. ZFCP_STATUS_UNIT_SCSI_WORK_PENDING))
  1074. zfcp_erp_schedule_work(unit);
  1075. }
  1076. zfcp_unit_put(unit);
  1077. break;
  1078. case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
  1079. case ZFCP_ERP_ACTION_REOPEN_PORT:
  1080. if (atomic_read(&port->status) & ZFCP_STATUS_PORT_NO_WWPN) {
  1081. zfcp_port_put(port);
  1082. return;
  1083. }
  1084. if ((result == ZFCP_ERP_SUCCEEDED) && !port->rport)
  1085. zfcp_erp_rport_register(port);
  1086. if ((result != ZFCP_ERP_SUCCEEDED) && port->rport) {
  1087. fc_remote_port_delete(port->rport);
  1088. port->rport = NULL;
  1089. }
  1090. zfcp_port_put(port);
  1091. break;
  1092. case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
  1093. if (result != ZFCP_ERP_SUCCEEDED)
  1094. zfcp_erp_rports_del(adapter);
  1095. zfcp_adapter_put(adapter);
  1096. break;
  1097. }
  1098. }
  1099. static int zfcp_erp_strategy_do_action(struct zfcp_erp_action *erp_action)
  1100. {
  1101. switch (erp_action->action) {
  1102. case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
  1103. return zfcp_erp_adapter_strategy(erp_action);
  1104. case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
  1105. return zfcp_erp_port_forced_strategy(erp_action);
  1106. case ZFCP_ERP_ACTION_REOPEN_PORT:
  1107. return zfcp_erp_port_strategy(erp_action);
  1108. case ZFCP_ERP_ACTION_REOPEN_UNIT:
  1109. return zfcp_erp_unit_strategy(erp_action);
  1110. }
  1111. return ZFCP_ERP_FAILED;
  1112. }
  1113. static int zfcp_erp_strategy(struct zfcp_erp_action *erp_action)
  1114. {
  1115. int retval;
  1116. struct zfcp_adapter *adapter = erp_action->adapter;
  1117. unsigned long flags;
  1118. read_lock_irqsave(&zfcp_data.config_lock, flags);
  1119. write_lock(&adapter->erp_lock);
  1120. zfcp_erp_strategy_check_fsfreq(erp_action);
  1121. if (erp_action->status & ZFCP_STATUS_ERP_DISMISSED) {
  1122. zfcp_erp_action_dequeue(erp_action);
  1123. retval = ZFCP_ERP_DISMISSED;
  1124. goto unlock;
  1125. }
  1126. zfcp_erp_action_to_running(erp_action);
  1127. /* no lock to allow for blocking operations */
  1128. write_unlock(&adapter->erp_lock);
  1129. read_unlock_irqrestore(&zfcp_data.config_lock, flags);
  1130. retval = zfcp_erp_strategy_do_action(erp_action);
  1131. read_lock_irqsave(&zfcp_data.config_lock, flags);
  1132. write_lock(&adapter->erp_lock);
  1133. if (erp_action->status & ZFCP_STATUS_ERP_DISMISSED)
  1134. retval = ZFCP_ERP_CONTINUES;
  1135. switch (retval) {
  1136. case ZFCP_ERP_NOMEM:
  1137. if (!(erp_action->status & ZFCP_STATUS_ERP_LOWMEM)) {
  1138. ++adapter->erp_low_mem_count;
  1139. erp_action->status |= ZFCP_STATUS_ERP_LOWMEM;
  1140. }
  1141. if (adapter->erp_total_count == adapter->erp_low_mem_count)
  1142. _zfcp_erp_adapter_reopen(adapter, 0, 66, NULL);
  1143. else {
  1144. zfcp_erp_strategy_memwait(erp_action);
  1145. retval = ZFCP_ERP_CONTINUES;
  1146. }
  1147. goto unlock;
  1148. case ZFCP_ERP_CONTINUES:
  1149. if (erp_action->status & ZFCP_STATUS_ERP_LOWMEM) {
  1150. --adapter->erp_low_mem_count;
  1151. erp_action->status &= ~ZFCP_STATUS_ERP_LOWMEM;
  1152. }
  1153. goto unlock;
  1154. }
  1155. retval = zfcp_erp_strategy_check_target(erp_action, retval);
  1156. zfcp_erp_action_dequeue(erp_action);
  1157. retval = zfcp_erp_strategy_statechange(erp_action, retval);
  1158. if (retval == ZFCP_ERP_EXIT)
  1159. goto unlock;
  1160. zfcp_erp_strategy_followup_actions(erp_action);
  1161. unlock:
  1162. write_unlock(&adapter->erp_lock);
  1163. read_unlock_irqrestore(&zfcp_data.config_lock, flags);
  1164. if (retval != ZFCP_ERP_CONTINUES)
  1165. zfcp_erp_action_cleanup(erp_action, retval);
  1166. return retval;
  1167. }
  1168. static int zfcp_erp_thread(void *data)
  1169. {
  1170. struct zfcp_adapter *adapter = (struct zfcp_adapter *) data;
  1171. struct list_head *next;
  1172. struct zfcp_erp_action *act;
  1173. unsigned long flags;
  1174. daemonize("zfcperp%s", adapter->ccw_device->dev.bus_id);
  1175. /* Block all signals */
  1176. siginitsetinv(&current->blocked, 0);
  1177. atomic_set_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP, &adapter->status);
  1178. wake_up(&adapter->erp_thread_wqh);
  1179. while (!(atomic_read(&adapter->status) &
  1180. ZFCP_STATUS_ADAPTER_ERP_THREAD_KILL)) {
  1181. write_lock_irqsave(&adapter->erp_lock, flags);
  1182. next = adapter->erp_ready_head.next;
  1183. write_unlock_irqrestore(&adapter->erp_lock, flags);
  1184. if (next != &adapter->erp_ready_head) {
  1185. act = list_entry(next, struct zfcp_erp_action, list);
  1186. /* there is more to come after dismission, no notify */
  1187. if (zfcp_erp_strategy(act) != ZFCP_ERP_DISMISSED)
  1188. zfcp_erp_wakeup(adapter);
  1189. }
  1190. zfcp_rec_dbf_event_thread(4, adapter);
  1191. down_interruptible(&adapter->erp_ready_sem);
  1192. zfcp_rec_dbf_event_thread(5, adapter);
  1193. }
  1194. atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP, &adapter->status);
  1195. wake_up(&adapter->erp_thread_wqh);
  1196. return 0;
  1197. }
  1198. /**
  1199. * zfcp_erp_thread_setup - Start ERP thread for adapter
  1200. * @adapter: Adapter to start the ERP thread for
  1201. *
  1202. * Returns 0 on success or error code from kernel_thread()
  1203. */
  1204. int zfcp_erp_thread_setup(struct zfcp_adapter *adapter)
  1205. {
  1206. int retval;
  1207. atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP, &adapter->status);
  1208. retval = kernel_thread(zfcp_erp_thread, adapter, SIGCHLD);
  1209. if (retval < 0) {
  1210. dev_err(&adapter->ccw_device->dev,
  1211. "Creating an ERP thread for the FCP device failed.\n");
  1212. return retval;
  1213. }
  1214. wait_event(adapter->erp_thread_wqh,
  1215. atomic_read(&adapter->status) &
  1216. ZFCP_STATUS_ADAPTER_ERP_THREAD_UP);
  1217. return 0;
  1218. }
  1219. /**
  1220. * zfcp_erp_thread_kill - Stop ERP thread.
  1221. * @adapter: Adapter where the ERP thread should be stopped.
  1222. *
  1223. * The caller of this routine ensures that the specified adapter has
  1224. * been shut down and that this operation has been completed. Thus,
  1225. * there are no pending erp_actions which would need to be handled
  1226. * here.
  1227. */
  1228. void zfcp_erp_thread_kill(struct zfcp_adapter *adapter)
  1229. {
  1230. atomic_set_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_KILL, &adapter->status);
  1231. up(&adapter->erp_ready_sem);
  1232. zfcp_rec_dbf_event_thread_lock(2, adapter);
  1233. wait_event(adapter->erp_thread_wqh,
  1234. !(atomic_read(&adapter->status) &
  1235. ZFCP_STATUS_ADAPTER_ERP_THREAD_UP));
  1236. atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_KILL,
  1237. &adapter->status);
  1238. }
  1239. /**
  1240. * zfcp_erp_adapter_failed - Set adapter status to failed.
  1241. * @adapter: Failed adapter.
  1242. * @id: Event id for debug trace.
  1243. * @ref: Reference for debug trace.
  1244. */
  1245. void zfcp_erp_adapter_failed(struct zfcp_adapter *adapter, u8 id, void *ref)
  1246. {
  1247. zfcp_erp_modify_adapter_status(adapter, id, ref,
  1248. ZFCP_STATUS_COMMON_ERP_FAILED, ZFCP_SET);
  1249. }
  1250. /**
  1251. * zfcp_erp_port_failed - Set port status to failed.
  1252. * @port: Failed port.
  1253. * @id: Event id for debug trace.
  1254. * @ref: Reference for debug trace.
  1255. */
  1256. void zfcp_erp_port_failed(struct zfcp_port *port, u8 id, void *ref)
  1257. {
  1258. zfcp_erp_modify_port_status(port, id, ref,
  1259. ZFCP_STATUS_COMMON_ERP_FAILED, ZFCP_SET);
  1260. }
  1261. /**
  1262. * zfcp_erp_unit_failed - Set unit status to failed.
  1263. * @unit: Failed unit.
  1264. * @id: Event id for debug trace.
  1265. * @ref: Reference for debug trace.
  1266. */
  1267. void zfcp_erp_unit_failed(struct zfcp_unit *unit, u8 id, void *ref)
  1268. {
  1269. zfcp_erp_modify_unit_status(unit, id, ref,
  1270. ZFCP_STATUS_COMMON_ERP_FAILED, ZFCP_SET);
  1271. }
  1272. /**
  1273. * zfcp_erp_wait - wait for completion of error recovery on an adapter
  1274. * @adapter: adapter for which to wait for completion of its error recovery
  1275. */
  1276. void zfcp_erp_wait(struct zfcp_adapter *adapter)
  1277. {
  1278. wait_event(adapter->erp_done_wqh,
  1279. !(atomic_read(&adapter->status) &
  1280. ZFCP_STATUS_ADAPTER_ERP_PENDING));
  1281. }
  1282. /**
  1283. * zfcp_erp_modify_adapter_status - change adapter status bits
  1284. * @adapter: adapter to change the status
  1285. * @id: id for the debug trace
  1286. * @ref: reference for the debug trace
  1287. * @mask: status bits to change
  1288. * @set_or_clear: ZFCP_SET or ZFCP_CLEAR
  1289. *
  1290. * Changes in common status bits are propagated to attached ports and units.
  1291. */
  1292. void zfcp_erp_modify_adapter_status(struct zfcp_adapter *adapter, u8 id,
  1293. void *ref, u32 mask, int set_or_clear)
  1294. {
  1295. struct zfcp_port *port;
  1296. u32 common_mask = mask & ZFCP_COMMON_FLAGS;
  1297. if (set_or_clear == ZFCP_SET) {
  1298. if (status_change_set(mask, &adapter->status))
  1299. zfcp_rec_dbf_event_adapter(id, ref, adapter);
  1300. atomic_set_mask(mask, &adapter->status);
  1301. } else {
  1302. if (status_change_clear(mask, &adapter->status))
  1303. zfcp_rec_dbf_event_adapter(id, ref, adapter);
  1304. atomic_clear_mask(mask, &adapter->status);
  1305. if (mask & ZFCP_STATUS_COMMON_ERP_FAILED)
  1306. atomic_set(&adapter->erp_counter, 0);
  1307. }
  1308. if (common_mask)
  1309. list_for_each_entry(port, &adapter->port_list_head, list)
  1310. zfcp_erp_modify_port_status(port, id, ref, common_mask,
  1311. set_or_clear);
  1312. }
  1313. /**
  1314. * zfcp_erp_modify_port_status - change port status bits
  1315. * @port: port to change the status bits
  1316. * @id: id for the debug trace
  1317. * @ref: reference for the debug trace
  1318. * @mask: status bits to change
  1319. * @set_or_clear: ZFCP_SET or ZFCP_CLEAR
  1320. *
  1321. * Changes in common status bits are propagated to attached units.
  1322. */
  1323. void zfcp_erp_modify_port_status(struct zfcp_port *port, u8 id, void *ref,
  1324. u32 mask, int set_or_clear)
  1325. {
  1326. struct zfcp_unit *unit;
  1327. u32 common_mask = mask & ZFCP_COMMON_FLAGS;
  1328. if (set_or_clear == ZFCP_SET) {
  1329. if (status_change_set(mask, &port->status))
  1330. zfcp_rec_dbf_event_port(id, ref, port);
  1331. atomic_set_mask(mask, &port->status);
  1332. } else {
  1333. if (status_change_clear(mask, &port->status))
  1334. zfcp_rec_dbf_event_port(id, ref, port);
  1335. atomic_clear_mask(mask, &port->status);
  1336. if (mask & ZFCP_STATUS_COMMON_ERP_FAILED)
  1337. atomic_set(&port->erp_counter, 0);
  1338. }
  1339. if (common_mask)
  1340. list_for_each_entry(unit, &port->unit_list_head, list)
  1341. zfcp_erp_modify_unit_status(unit, id, ref, common_mask,
  1342. set_or_clear);
  1343. }
  1344. /**
  1345. * zfcp_erp_modify_unit_status - change unit status bits
  1346. * @unit: unit to change the status bits
  1347. * @id: id for the debug trace
  1348. * @ref: reference for the debug trace
  1349. * @mask: status bits to change
  1350. * @set_or_clear: ZFCP_SET or ZFCP_CLEAR
  1351. */
  1352. void zfcp_erp_modify_unit_status(struct zfcp_unit *unit, u8 id, void *ref,
  1353. u32 mask, int set_or_clear)
  1354. {
  1355. if (set_or_clear == ZFCP_SET) {
  1356. if (status_change_set(mask, &unit->status))
  1357. zfcp_rec_dbf_event_unit(id, ref, unit);
  1358. atomic_set_mask(mask, &unit->status);
  1359. } else {
  1360. if (status_change_clear(mask, &unit->status))
  1361. zfcp_rec_dbf_event_unit(id, ref, unit);
  1362. atomic_clear_mask(mask, &unit->status);
  1363. if (mask & ZFCP_STATUS_COMMON_ERP_FAILED) {
  1364. atomic_set(&unit->erp_counter, 0);
  1365. }
  1366. }
  1367. }
  1368. /**
  1369. * zfcp_erp_port_boxed - Mark port as "boxed" and start ERP
  1370. * @port: The "boxed" port.
  1371. * @id: The debug trace id.
  1372. * @id: Reference for the debug trace.
  1373. */
  1374. void zfcp_erp_port_boxed(struct zfcp_port *port, u8 id, void *ref)
  1375. {
  1376. unsigned long flags;
  1377. read_lock_irqsave(&zfcp_data.config_lock, flags);
  1378. zfcp_erp_modify_port_status(port, id, ref,
  1379. ZFCP_STATUS_COMMON_ACCESS_BOXED, ZFCP_SET);
  1380. read_unlock_irqrestore(&zfcp_data.config_lock, flags);
  1381. zfcp_erp_port_reopen(port, ZFCP_STATUS_COMMON_ERP_FAILED, id, ref);
  1382. }
  1383. /**
  1384. * zfcp_erp_unit_boxed - Mark unit as "boxed" and start ERP
  1385. * @port: The "boxed" unit.
  1386. * @id: The debug trace id.
  1387. * @id: Reference for the debug trace.
  1388. */
  1389. void zfcp_erp_unit_boxed(struct zfcp_unit *unit, u8 id, void *ref)
  1390. {
  1391. zfcp_erp_modify_unit_status(unit, id, ref,
  1392. ZFCP_STATUS_COMMON_ACCESS_BOXED, ZFCP_SET);
  1393. zfcp_erp_unit_reopen(unit, ZFCP_STATUS_COMMON_ERP_FAILED, id, ref);
  1394. }
  1395. /**
  1396. * zfcp_erp_port_access_denied - Adapter denied access to port.
  1397. * @port: port where access has been denied
  1398. * @id: id for debug trace
  1399. * @ref: reference for debug trace
  1400. *
  1401. * Since the adapter has denied access, stop using the port and the
  1402. * attached units.
  1403. */
  1404. void zfcp_erp_port_access_denied(struct zfcp_port *port, u8 id, void *ref)
  1405. {
  1406. unsigned long flags;
  1407. read_lock_irqsave(&zfcp_data.config_lock, flags);
  1408. zfcp_erp_modify_port_status(port, id, ref,
  1409. ZFCP_STATUS_COMMON_ERP_FAILED |
  1410. ZFCP_STATUS_COMMON_ACCESS_DENIED, ZFCP_SET);
  1411. read_unlock_irqrestore(&zfcp_data.config_lock, flags);
  1412. }
  1413. /**
  1414. * zfcp_erp_unit_access_denied - Adapter denied access to unit.
  1415. * @unit: unit where access has been denied
  1416. * @id: id for debug trace
  1417. * @ref: reference for debug trace
  1418. *
  1419. * Since the adapter has denied access, stop using the unit.
  1420. */
  1421. void zfcp_erp_unit_access_denied(struct zfcp_unit *unit, u8 id, void *ref)
  1422. {
  1423. zfcp_erp_modify_unit_status(unit, id, ref,
  1424. ZFCP_STATUS_COMMON_ERP_FAILED |
  1425. ZFCP_STATUS_COMMON_ACCESS_DENIED, ZFCP_SET);
  1426. }
  1427. static void zfcp_erp_unit_access_changed(struct zfcp_unit *unit, u8 id,
  1428. void *ref)
  1429. {
  1430. int status = atomic_read(&unit->status);
  1431. if (!(status & (ZFCP_STATUS_COMMON_ACCESS_DENIED |
  1432. ZFCP_STATUS_COMMON_ACCESS_BOXED)))
  1433. return;
  1434. zfcp_erp_unit_reopen(unit, ZFCP_STATUS_COMMON_ERP_FAILED, id, ref);
  1435. }
  1436. static void zfcp_erp_port_access_changed(struct zfcp_port *port, u8 id,
  1437. void *ref)
  1438. {
  1439. struct zfcp_unit *unit;
  1440. int status = atomic_read(&port->status);
  1441. if (!(status & (ZFCP_STATUS_COMMON_ACCESS_DENIED |
  1442. ZFCP_STATUS_COMMON_ACCESS_BOXED))) {
  1443. list_for_each_entry(unit, &port->unit_list_head, list)
  1444. zfcp_erp_unit_access_changed(unit, id, ref);
  1445. return;
  1446. }
  1447. zfcp_erp_port_reopen(port, ZFCP_STATUS_COMMON_ERP_FAILED, id, ref);
  1448. }
  1449. /**
  1450. * zfcp_erp_adapter_access_changed - Process change in adapter ACT
  1451. * @adapter: Adapter where the Access Control Table (ACT) changed
  1452. * @id: Id for debug trace
  1453. * @ref: Reference for debug trace
  1454. */
  1455. void zfcp_erp_adapter_access_changed(struct zfcp_adapter *adapter, u8 id,
  1456. void *ref)
  1457. {
  1458. struct zfcp_port *port;
  1459. unsigned long flags;
  1460. if (adapter->connection_features & FSF_FEATURE_NPIV_MODE)
  1461. return;
  1462. read_lock_irqsave(&zfcp_data.config_lock, flags);
  1463. list_for_each_entry(port, &adapter->port_list_head, list)
  1464. zfcp_erp_port_access_changed(port, id, ref);
  1465. read_unlock_irqrestore(&zfcp_data.config_lock, flags);
  1466. }