zfcp_erp.c 47 KB

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