zfcp_erp.c 50 KB

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